vrshoot

annotate libs/assimp/FBXParser.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file FBXParser.h
nuclear@0 42 * @brief FBX parsing code
nuclear@0 43 */
nuclear@0 44 #ifndef INCLUDED_AI_FBX_PARSER_H
nuclear@0 45 #define INCLUDED_AI_FBX_PARSER_H
nuclear@0 46
nuclear@0 47 #include <vector>
nuclear@0 48 #include <map>
nuclear@0 49 #include <string>
nuclear@0 50 #include <utility>
nuclear@0 51
nuclear@0 52 #include <boost/shared_ptr.hpp>
nuclear@0 53
nuclear@0 54 #include "LogAux.h"
nuclear@0 55
nuclear@0 56 #include "FBXCompileConfig.h"
nuclear@0 57 #include "FBXTokenizer.h"
nuclear@0 58
nuclear@0 59 namespace Assimp {
nuclear@0 60 namespace FBX {
nuclear@0 61
nuclear@0 62 class Scope;
nuclear@0 63 class Parser;
nuclear@0 64 class Element;
nuclear@0 65
nuclear@0 66 // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03
nuclear@0 67 typedef std::vector< Scope* > ScopeList;
nuclear@0 68 typedef std::fbx_unordered_multimap< std::string, Element* > ElementMap;
nuclear@0 69
nuclear@0 70 typedef std::pair<ElementMap::const_iterator,ElementMap::const_iterator> ElementCollection;
nuclear@0 71
nuclear@0 72 # define new_Scope new Scope
nuclear@0 73 # define new_Element new Element
nuclear@0 74
nuclear@0 75
nuclear@0 76 /** FBX data entity that consists of a key:value tuple.
nuclear@0 77 *
nuclear@0 78 * Example:
nuclear@0 79 * @verbatim
nuclear@0 80 * AnimationCurve: 23, "AnimCurve::", "" {
nuclear@0 81 * [..]
nuclear@0 82 * }
nuclear@0 83 * @endverbatim
nuclear@0 84 *
nuclear@0 85 * As can be seen in this sample, elements can contain nested #Scope
nuclear@0 86 * as their trailing member. **/
nuclear@0 87 class Element
nuclear@0 88 {
nuclear@0 89 public:
nuclear@0 90
nuclear@0 91 Element(const Token& key_token, Parser& parser);
nuclear@0 92 ~Element();
nuclear@0 93
nuclear@0 94 public:
nuclear@0 95
nuclear@0 96 const Scope* Compound() const {
nuclear@0 97 return compound.get();
nuclear@0 98 }
nuclear@0 99
nuclear@0 100 const Token& KeyToken() const {
nuclear@0 101 return key_token;
nuclear@0 102 }
nuclear@0 103
nuclear@0 104 const TokenList& Tokens() const {
nuclear@0 105 return tokens;
nuclear@0 106 }
nuclear@0 107
nuclear@0 108 private:
nuclear@0 109
nuclear@0 110 const Token& key_token;
nuclear@0 111 TokenList tokens;
nuclear@0 112 boost::scoped_ptr<Scope> compound;
nuclear@0 113 };
nuclear@0 114
nuclear@0 115
nuclear@0 116
nuclear@0 117 /** FBX data entity that consists of a 'scope', a collection
nuclear@0 118 * of not necessarily unique #Element instances.
nuclear@0 119 *
nuclear@0 120 * Example:
nuclear@0 121 * @verbatim
nuclear@0 122 * GlobalSettings: {
nuclear@0 123 * Version: 1000
nuclear@0 124 * Properties70:
nuclear@0 125 * [...]
nuclear@0 126 * }
nuclear@0 127 * @endverbatim */
nuclear@0 128 class Scope
nuclear@0 129 {
nuclear@0 130
nuclear@0 131 public:
nuclear@0 132
nuclear@0 133 Scope(Parser& parser, bool topLevel = false);
nuclear@0 134 ~Scope();
nuclear@0 135
nuclear@0 136 public:
nuclear@0 137
nuclear@0 138 const Element* operator[] (const std::string& index) const {
nuclear@0 139 ElementMap::const_iterator it = elements.find(index);
nuclear@0 140 return it == elements.end() ? NULL : (*it).second;
nuclear@0 141 }
nuclear@0 142
nuclear@0 143 ElementCollection GetCollection(const std::string& index) const {
nuclear@0 144 return elements.equal_range(index);
nuclear@0 145 }
nuclear@0 146
nuclear@0 147 const ElementMap& Elements() const {
nuclear@0 148 return elements;
nuclear@0 149 }
nuclear@0 150
nuclear@0 151 private:
nuclear@0 152
nuclear@0 153 ElementMap elements;
nuclear@0 154 };
nuclear@0 155
nuclear@0 156
nuclear@0 157 /** FBX parsing class, takes a list of input tokens and generates a hierarchy
nuclear@0 158 * of nested #Scope instances, representing the fbx DOM.*/
nuclear@0 159 class Parser
nuclear@0 160 {
nuclear@0 161 public:
nuclear@0 162
nuclear@0 163 /** Parse given a token list. Does not take ownership of the tokens -
nuclear@0 164 * the objects must persist during the entire parser lifetime */
nuclear@0 165 Parser (const TokenList& tokens,bool is_binary);
nuclear@0 166 ~Parser();
nuclear@0 167
nuclear@0 168 public:
nuclear@0 169
nuclear@0 170 const Scope& GetRootScope() const {
nuclear@0 171 return *root.get();
nuclear@0 172 }
nuclear@0 173
nuclear@0 174
nuclear@0 175 bool IsBinary() const {
nuclear@0 176 return is_binary;
nuclear@0 177 }
nuclear@0 178
nuclear@0 179 private:
nuclear@0 180
nuclear@0 181 friend class Scope;
nuclear@0 182 friend class Element;
nuclear@0 183
nuclear@0 184 TokenPtr AdvanceToNextToken();
nuclear@0 185
nuclear@0 186 TokenPtr LastToken() const;
nuclear@0 187 TokenPtr CurrentToken() const;
nuclear@0 188
nuclear@0 189
nuclear@0 190
nuclear@0 191 private:
nuclear@0 192
nuclear@0 193 const TokenList& tokens;
nuclear@0 194
nuclear@0 195 TokenPtr last, current;
nuclear@0 196 TokenList::const_iterator cursor;
nuclear@0 197 boost::scoped_ptr<Scope> root;
nuclear@0 198
nuclear@0 199 const bool is_binary;
nuclear@0 200 };
nuclear@0 201
nuclear@0 202
nuclear@0 203 /* token parsing - this happens when building the DOM out of the parse-tree*/
nuclear@0 204 uint64_t ParseTokenAsID(const Token& t, const char*& err_out);
nuclear@0 205 size_t ParseTokenAsDim(const Token& t, const char*& err_out);
nuclear@0 206
nuclear@0 207 float ParseTokenAsFloat(const Token& t, const char*& err_out);
nuclear@0 208 int ParseTokenAsInt(const Token& t, const char*& err_out);
nuclear@0 209 std::string ParseTokenAsString(const Token& t, const char*& err_out);
nuclear@0 210
nuclear@0 211
nuclear@0 212 /* wrapper around ParseTokenAsXXX() with DOMError handling */
nuclear@0 213 uint64_t ParseTokenAsID(const Token& t);
nuclear@0 214 size_t ParseTokenAsDim(const Token& t);
nuclear@0 215 float ParseTokenAsFloat(const Token& t);
nuclear@0 216 int ParseTokenAsInt(const Token& t);
nuclear@0 217 std::string ParseTokenAsString(const Token& t);
nuclear@0 218
nuclear@0 219 /* read data arrays */
nuclear@0 220 void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el);
nuclear@0 221 void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el);
nuclear@0 222 void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el);
nuclear@0 223 void ParseVectorDataArray(std::vector<int>& out, const Element& el);
nuclear@0 224 void ParseVectorDataArray(std::vector<float>& out, const Element& el);
nuclear@0 225 void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el);
nuclear@0 226 void ParseVectorDataArray(std::vector<uint64_t>& out, const Element& e);
nuclear@0 227
nuclear@0 228
nuclear@0 229
nuclear@0 230 // extract a required element from a scope, abort if the element cannot be found
nuclear@0 231 const Element& GetRequiredElement(const Scope& sc, const std::string& index, const Element* element = NULL);
nuclear@0 232
nuclear@0 233 // extract required compound scope
nuclear@0 234 const Scope& GetRequiredScope(const Element& el);
nuclear@0 235 // get token at a particular index
nuclear@0 236 const Token& GetRequiredToken(const Element& el, unsigned int index);
nuclear@0 237
nuclear@0 238
nuclear@0 239
nuclear@0 240 // read a 4x4 matrix from an array of 16 floats
nuclear@0 241 aiMatrix4x4 ReadMatrix(const Element& element);
nuclear@0 242
nuclear@0 243 } // ! FBX
nuclear@0 244 } // ! Assimp
nuclear@0 245
nuclear@0 246 #endif // ! INCLUDED_AI_FBX_PARSER_H