nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2012, assimp team nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file FBXParser.h nuclear@0: * @brief FBX parsing code nuclear@0: */ nuclear@0: #ifndef INCLUDED_AI_FBX_PARSER_H nuclear@0: #define INCLUDED_AI_FBX_PARSER_H nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: #include nuclear@0: nuclear@0: #include "LogAux.h" nuclear@0: nuclear@0: #include "FBXCompileConfig.h" nuclear@0: #include "FBXTokenizer.h" nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace FBX { nuclear@0: nuclear@0: class Scope; nuclear@0: class Parser; nuclear@0: class Element; nuclear@0: nuclear@0: // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03 nuclear@0: typedef std::vector< Scope* > ScopeList; nuclear@0: typedef std::fbx_unordered_multimap< std::string, Element* > ElementMap; nuclear@0: nuclear@0: typedef std::pair ElementCollection; nuclear@0: nuclear@0: # define new_Scope new Scope nuclear@0: # define new_Element new Element nuclear@0: nuclear@0: nuclear@0: /** FBX data entity that consists of a key:value tuple. nuclear@0: * nuclear@0: * Example: nuclear@0: * @verbatim nuclear@0: * AnimationCurve: 23, "AnimCurve::", "" { nuclear@0: * [..] nuclear@0: * } nuclear@0: * @endverbatim nuclear@0: * nuclear@0: * As can be seen in this sample, elements can contain nested #Scope nuclear@0: * as their trailing member. **/ nuclear@0: class Element nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: Element(const Token& key_token, Parser& parser); nuclear@0: ~Element(); nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: const Scope* Compound() const { nuclear@0: return compound.get(); nuclear@0: } nuclear@0: nuclear@0: const Token& KeyToken() const { nuclear@0: return key_token; nuclear@0: } nuclear@0: nuclear@0: const TokenList& Tokens() const { nuclear@0: return tokens; nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: const Token& key_token; nuclear@0: TokenList tokens; nuclear@0: boost::scoped_ptr compound; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: nuclear@0: /** FBX data entity that consists of a 'scope', a collection nuclear@0: * of not necessarily unique #Element instances. nuclear@0: * nuclear@0: * Example: nuclear@0: * @verbatim nuclear@0: * GlobalSettings: { nuclear@0: * Version: 1000 nuclear@0: * Properties70: nuclear@0: * [...] nuclear@0: * } nuclear@0: * @endverbatim */ nuclear@0: class Scope nuclear@0: { nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: Scope(Parser& parser, bool topLevel = false); nuclear@0: ~Scope(); nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: const Element* operator[] (const std::string& index) const { nuclear@0: ElementMap::const_iterator it = elements.find(index); nuclear@0: return it == elements.end() ? NULL : (*it).second; nuclear@0: } nuclear@0: nuclear@0: ElementCollection GetCollection(const std::string& index) const { nuclear@0: return elements.equal_range(index); nuclear@0: } nuclear@0: nuclear@0: const ElementMap& Elements() const { nuclear@0: return elements; nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: ElementMap elements; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: /** FBX parsing class, takes a list of input tokens and generates a hierarchy nuclear@0: * of nested #Scope instances, representing the fbx DOM.*/ nuclear@0: class Parser nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: /** Parse given a token list. Does not take ownership of the tokens - nuclear@0: * the objects must persist during the entire parser lifetime */ nuclear@0: Parser (const TokenList& tokens,bool is_binary); nuclear@0: ~Parser(); nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: const Scope& GetRootScope() const { nuclear@0: return *root.get(); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: bool IsBinary() const { nuclear@0: return is_binary; nuclear@0: } nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: friend class Scope; nuclear@0: friend class Element; nuclear@0: nuclear@0: TokenPtr AdvanceToNextToken(); nuclear@0: nuclear@0: TokenPtr LastToken() const; nuclear@0: TokenPtr CurrentToken() const; nuclear@0: nuclear@0: nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: const TokenList& tokens; nuclear@0: nuclear@0: TokenPtr last, current; nuclear@0: TokenList::const_iterator cursor; nuclear@0: boost::scoped_ptr root; nuclear@0: nuclear@0: const bool is_binary; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: /* token parsing - this happens when building the DOM out of the parse-tree*/ nuclear@0: uint64_t ParseTokenAsID(const Token& t, const char*& err_out); nuclear@0: size_t ParseTokenAsDim(const Token& t, const char*& err_out); nuclear@0: nuclear@0: float ParseTokenAsFloat(const Token& t, const char*& err_out); nuclear@0: int ParseTokenAsInt(const Token& t, const char*& err_out); nuclear@0: std::string ParseTokenAsString(const Token& t, const char*& err_out); nuclear@0: nuclear@0: nuclear@0: /* wrapper around ParseTokenAsXXX() with DOMError handling */ nuclear@0: uint64_t ParseTokenAsID(const Token& t); nuclear@0: size_t ParseTokenAsDim(const Token& t); nuclear@0: float ParseTokenAsFloat(const Token& t); nuclear@0: int ParseTokenAsInt(const Token& t); nuclear@0: std::string ParseTokenAsString(const Token& t); nuclear@0: nuclear@0: /* read data arrays */ nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& el); nuclear@0: void ParseVectorDataArray(std::vector& out, const Element& e); nuclear@0: nuclear@0: nuclear@0: nuclear@0: // extract a required element from a scope, abort if the element cannot be found nuclear@0: const Element& GetRequiredElement(const Scope& sc, const std::string& index, const Element* element = NULL); nuclear@0: nuclear@0: // extract required compound scope nuclear@0: const Scope& GetRequiredScope(const Element& el); nuclear@0: // get token at a particular index nuclear@0: const Token& GetRequiredToken(const Element& el, unsigned int index); nuclear@0: nuclear@0: nuclear@0: nuclear@0: // read a 4x4 matrix from an array of 16 floats nuclear@0: aiMatrix4x4 ReadMatrix(const Element& element); nuclear@0: nuclear@0: } // ! FBX nuclear@0: } // ! Assimp nuclear@0: nuclear@0: #endif // ! INCLUDED_AI_FBX_PARSER_H