From 18b2aebcb1187e499c285001ea96ed2d8d2c5af5 Mon Sep 17 00:00:00 2001 From: acgessler Date: Sat, 23 Jun 2012 03:36:55 +0200 Subject: [PATCH] - FBX importer: basic interface and importer skeleton. Start tokenizer and parser. --- code/FBXCompileConfig.h | 66 + code/FBXImporter.cpp | 158 ++ code/FBXImporter.h | 118 ++ code/FBXParser.cpp | 123 ++ code/FBXParser.h | 174 +++ code/FBXTokenizer.cpp | 130 ++ code/FBXTokenizer.h | 129 ++ code/ImporterRegistry.cpp | 6 + workspaces/vc9/assimp.vcproj | 2628 +++++++++++++++++----------------- 9 files changed, 2234 insertions(+), 1298 deletions(-) create mode 100644 code/FBXCompileConfig.h create mode 100644 code/FBXImporter.cpp create mode 100644 code/FBXImporter.h create mode 100644 code/FBXParser.cpp create mode 100644 code/FBXParser.h create mode 100644 code/FBXTokenizer.cpp create mode 100644 code/FBXTokenizer.h diff --git a/code/FBXCompileConfig.h b/code/FBXCompileConfig.h new file mode 100644 index 000000000..ea7efaddf --- /dev/null +++ b/code/FBXCompileConfig.h @@ -0,0 +1,66 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXCompileConfig.h + * @brief FBX importer compile-time switches + */ +#ifndef INCLUDED_AI_FBX_COMPILECONFIG_H +#define INCLUDED_AI_FBX_COMPILECONFIG_H + +// +#if _MSC_VER > 1500 || (defined __GNUC___) +# define ASSIMP_FBX_USE_UNORDERED_MULTIMAP +# else +# define fbx_unordered_map map +# define fbx_unordered_multimap multimap +#endif + +#ifdef ASSIMP_FBX_USE_UNORDERED_MULTIMAP +# include +# if _MSC_VER > 1600 +# define fbx_unordered_map unordered_map +# define fbx_unordered_multimap unordered_multimap +# else +# define fbx_unordered_map tr1::unordered_map +# define fbx_unordered_multimap tr1::unordered_multimap +# endif +#endif + +#endif diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp new file mode 100644 index 000000000..c8ee45cc2 --- /dev/null +++ b/code/FBXImporter.cpp @@ -0,0 +1,158 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXImporter.cpp + * @brief Implementation of the FBX importer. + */ +#include "AssimpPCH.h" + +#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER + +#include +#include + + +#include "FBXImporter.h" + +#include "FBXTokenizer.h" +#include "FBXParser.h" + +#include "StreamReader.h" +#include "MemoryIOWrapper.h" + +namespace Assimp { + template<> const std::string LogFunctions::log_prefix = "FBX: "; +} + +using namespace Assimp; +using namespace Assimp::Formatter; +using namespace Assimp::FBX; + +namespace { +static const aiImporterDesc desc = { + "Autodesk FBX Importer", + "", + "", + "", + aiImporterFlags_SupportTextFlavour, + 0, + 0, + 0, + 0, + "fbx" +}; +} + +// ------------------------------------------------------------------------------------------------ +// Constructor to be privately used by #Importer +FBXImporter::FBXImporter() +{} + +// ------------------------------------------------------------------------------------------------ +// Destructor, private as well +FBXImporter::~FBXImporter() +{ +} + +// ------------------------------------------------------------------------------------------------ +// Returns whether the class can handle the format of the given file. +bool FBXImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const +{ + const std::string& extension = GetExtension(pFile); + if (extension == "fbx") { + return true; + } + + else if ((!extension.length() || checkSig) && pIOHandler) { + // at least ascii FBX files usually have a 'FBX' somewhere in their head + const char* tokens[] = {"FBX"}; + return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1); + } + return false; +} + +// ------------------------------------------------------------------------------------------------ +// List all extensions handled by this loader +const aiImporterDesc* FBXImporter::GetInfo () const +{ + return &desc; +} + + +// ------------------------------------------------------------------------------------------------ +// Setup configuration properties for the loader +void FBXImporter::SetupProperties(const Importer* pImp) +{ + // no tweakables yet +} + + +// ------------------------------------------------------------------------------------------------ +// Imports the given file into the given scene structure. +void FBXImporter::InternReadFile( const std::string& pFile, + aiScene* pScene, IOSystem* pIOHandler) +{ + boost::scoped_ptr stream(pIOHandler->Open(pFile,"rb")); + if (!stream) { + ThrowException("Could not open file for reading"); + } + + // read entire file into memory - no streaming for this, fbx + // files can grow large, but the assimp output data structure + // then becomes very large, too. Assimp doesn't support + // streaming for its output data structures so the net win with + // streaming input data would be very low. + std::vector contents; + contents.resize(stream->FileSize()); + + stream->Read(&*contents.begin(),contents.size(),1); + const char* const begin = &*contents.begin(); + + // broadphase tokenizing pass in which we identify the core + // syntax elements of FBX (brackets, commas, key:value mappings) + TokenList tokens; + Tokenize(tokens,begin); + + // use this information to construct a very rudimentary + // parse-tree representing the FBX scope structure + Parser parser(tokens); +} + +#endif // !ASSIMP_BUILD_NO_FBX_IMPORTER diff --git a/code/FBXImporter.h b/code/FBXImporter.h new file mode 100644 index 000000000..e0d771f23 --- /dev/null +++ b/code/FBXImporter.h @@ -0,0 +1,118 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXImporter.h + * @brief Declaration of the FBX main importer class + */ +#ifndef INCLUDED_AI_FBX_IMPORTER_H +#define INCLUDED_AI_FBX_IMPORTER_H + +#include "BaseImporter.h" +#include "LogAux.h" + +namespace Assimp { + + // TinyFormatter.h + namespace Formatter { + template class basic_formatter; + typedef class basic_formatter< char, std::char_traits, std::allocator > format; + } + + +// ------------------------------------------------------------------------------------------- +/** Load the Autodesk FBX file format. + + See http://en.wikipedia.org/wiki/FBX +*/ +// ------------------------------------------------------------------------------------------- +class FBXImporter : public BaseImporter, public LogFunctions +{ +public: + FBXImporter(); + ~FBXImporter(); + + +public: + + // -------------------- + bool CanRead( const std::string& pFile, + IOSystem* pIOHandler, + bool checkSig + ) const; + +protected: + + // -------------------- + const aiImporterDesc* GetInfo () const; + + // -------------------- + void SetupProperties(const Importer* pImp); + + // -------------------- + void InternReadFile( const std::string& pFile, + aiScene* pScene, + IOSystem* pIOHandler + ); + +private: + + +public: + + + // loader settings, publicly accessible via their corresponding AI_CONFIG constants + struct Settings + { + Settings() + + {} + + }; + + +private: + + Settings settings; + +}; // !class FBXImporter + +} // end of namespace Assimp +#endif // !INCLUDED_AI_FBX_IMPORTER_H + diff --git a/code/FBXParser.cpp b/code/FBXParser.cpp new file mode 100644 index 000000000..dab4ebbe4 --- /dev/null +++ b/code/FBXParser.cpp @@ -0,0 +1,123 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXParser.cpp + * @brief Implementation of the FBX parser and the rudimentary DOM that we use + */ +#include "AssimpPCH.h" + +#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER + +#include "FBXTokenizer.h" +#include "FBXParser.h" + +using namespace Assimp; +using namespace Assimp::FBX; + +namespace Assimp { + template<> const std::string LogFunctions::log_prefix = "FBX-Parse: "; +} + +// ------------------------------------------------------------------------------------------------ +Element::Element(Parser& parser) +{ +} + +// ------------------------------------------------------------------------------------------------ +Element::~Element() +{ +} + +// ------------------------------------------------------------------------------------------------ +Scope::Scope(Parser& parser) +{ + TokenPtr t = parser.GetNextToken(); + if (t->Type() != TokenType_OPEN_BRACKET) { + parser.ThrowException("Expected open bracket"); + } + + // XXX parse members +} + +// ------------------------------------------------------------------------------------------------ +Scope::~Scope() +{ +} + + +// ------------------------------------------------------------------------------------------------ +Parser::Parser (const TokenList& tokens) +: tokens(tokens) +, cursor(tokens.begin()) +{ + root = boost::scoped_ptr(new Scope(*this)); +} + + +// ------------------------------------------------------------------------------------------------ +Parser::~Parser() +{ +} + + +// ------------------------------------------------------------------------------------------------ +TokenPtr Parser::GetNextToken() +{ + if (cursor == tokens.end()) { + return TokenPtr(NULL); + } + + return *cursor++; +} + + +// ------------------------------------------------------------------------------------------------ +TokenPtr Parser::PeekNextToken() +{ + if (cursor == tokens.end()) { + return TokenPtr(NULL); + } + + return *cursor; +} + + +#endif + diff --git a/code/FBXParser.h b/code/FBXParser.h new file mode 100644 index 000000000..06093cfc5 --- /dev/null +++ b/code/FBXParser.h @@ -0,0 +1,174 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXParser.h + * @brief FBX parsing code + */ +#ifndef INCLUDED_AI_FBX_PARSER_H +#define INCLUDED_AI_FBX_PARSER_H + +#include +#include +#include + +#include + +#include "LogAux.h" + +#include "FBXCompileConfig.h" +#include "FBXTokenizer.h" + +namespace Assimp { +namespace FBX { + + class Scope; + class Parser; + class Element; + + // should actually use 0x's unique_ptr for some of those + typedef std::vector< boost::shared_ptr > ScopeList; + typedef std::fbx_unordered_multimap< std::string, boost::shared_ptr > ElementMap; + + + +/** FBX data entity that consists of a key:value tuple. + * + * Example: + * @verbatim + * AnimationCurve: 23, "AnimCurve::", "" { + * [..] + * } + * @endverbatim + * + * As can be seen in this sample, elements can contain nested #Scope + * as their trailing member. **/ +class Element +{ +public: + + Element(Parser& parser); + ~Element(); + +public: + + const std::string& Key() const { + return key; + } + + const TokenList& Tokens() const { + return tokens; + } + +private: + + std::string key; + TokenList tokens; + boost::shared_ptr compound; +}; + + + +/** FBX data entity that consists of a 'scope', a collection + * of not necessarily unique #Element instances. + * + * Example: + * @verbatim + * GlobalSettings: { + * Version: 1000 + * Properties70: + * [...] + * } + * @endverbatim */ +class Scope +{ + +public: + + Scope(Parser& parser); + ~Scope(); + +public: + + const ElementMap& Elements() const { + return elements; + } + +private: + + ElementMap elements; +}; + + +/** FBX parsing class, takes a list of input tokens and generates a hierarchy + * of nested #Scope instances, representing the fbx DOM.*/ +class Parser : public LogFunctions +{ +public: + + Parser (const TokenList& tokens); + ~Parser(); + +public: + + const Scope& GetRootScope() const { + return *root.get(); + } + +private: + + friend class Scope; + friend class Element; + + TokenPtr GetNextToken(); + TokenPtr PeekNextToken(); + +private: + + const TokenList& tokens; + + TokenList::const_iterator cursor; + boost::scoped_ptr root; +}; + + +} // ! FBX +} // ! Assimp + +#endif // ! INCLUDED_AI_FBX_PARSER_H diff --git a/code/FBXTokenizer.cpp b/code/FBXTokenizer.cpp new file mode 100644 index 000000000..f210c2da6 --- /dev/null +++ b/code/FBXTokenizer.cpp @@ -0,0 +1,130 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXTokenizer.cpp + * @brief Implementation of the FBX broadphase lexer + */ +#include "AssimpPCH.h" + +#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER + +#include "FBXTokenizer.h" +#include "ParsingUtils.h" + +namespace Assimp { +namespace FBX { + +// ------------------------------------------------------------------------------------------------ +Token::Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column) + : sbegin(sbegin) + , send(send) + , type(type) + , line(line) + , column(column) +{ + ai_assert(sbegin); + ai_assert(send); +} + + +// ------------------------------------------------------------------------------------------------ +Token::~Token() +{ +} + + +// ------------------------------------------------------------------------------------------------ +void Tokenize(TokenList& output_tokens, const char* input) +{ + ai_assert(input); + + // line and column numbers numbers are one-based + unsigned int line = 1; + unsigned int column = 1; + + bool comment = false; + + for (const char* cur = input;*cur;++cur,++column) { + const char c = *cur; + + if (IsLineEnd(c)) { + comment = false; + + column = 0; + ++line; + + continue; + } + + if(comment) { + continue; + } + + switch(c) + { + case ';': + comment = true; + continue; + + case '{': + output_tokens.push_back(boost::make_shared(cur,cur+1,TokenType_OPEN_BRACKET,line,column)); + break; + + case '}': + output_tokens.push_back(boost::make_shared(cur,cur+1,TokenType_CLOSE_BRACKET,line,column)); + break; + + case ',': + output_tokens.push_back(boost::make_shared(cur,cur+1,TokenType_COMMA,line,column)); + break; + } + + + if (IsSpaceOrNewLine(c)) { + // + } + // XXX parse key and data elements + } +} + +} // !FBX +} // !Assimp + +#endif diff --git a/code/FBXTokenizer.h b/code/FBXTokenizer.h new file mode 100644 index 000000000..e37210c7c --- /dev/null +++ b/code/FBXTokenizer.h @@ -0,0 +1,129 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2012, assimp team +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/** @file FBXTokenizer.h + * @brief FBX lexer + */ +#ifndef INCLUDED_AI_FBX_TOKENIZER_H +#define INCLUDED_AI_FBX_TOKENIZER_H + +#include + +#include "FBXCompileConfig.h" + +namespace Assimp { +namespace FBX { + +/** Rough classification for text FBX tokens used for constructing the + * basic scope hierarchy. */ +enum TokenType +{ + // { + TokenType_OPEN_BRACKET = 0, + + // } + TokenType_CLOSE_BRACKET, + + // '"blablubb"', '2', '*14' - very general token class, + // further processing happens at a later stage. + TokenType_DATA, + + // , + TokenType_COMMA, + + // blubb: + TokenType_KEY +}; + + +/** Represents a single token in a FBX file. Tokens are + * classified by the #TokenType enumerated types. + * + * Offers iterator protocol. Tokens are immutable. */ +class Token +{ + +public: + + Token(const char* sbegin, const char* send, TokenType type, unsigned int line, unsigned int column); + ~Token(); + +public: + + const char* begin() const { + return sbegin; + } + + const char* end() const { + return send; + } + + TokenType Type() const { + return type; + } + +private: + + const char* const sbegin; + const char* const send; + const TokenType type; + + const unsigned int line, column; +}; + + +typedef boost::shared_ptr TokenPtr; +typedef std::vector< boost::shared_ptr > TokenList; + + +/** Main FBX tokenizer function. Transform input buffer into a list of preprocessed tokens. + * + * Skips over comments and generates line and column numbers. + * + * @param output_tokens Receives a list of all tokens in the input data. + * @param input_buffer Textual input buffer to be processed, 0-terminated. */ +void Tokenize(TokenList& output_tokens, const char* input); + + +} // ! FBX +} // ! Assimp + +#endif // ! INCLUDED_AI_FBX_PARSER_H + diff --git a/code/ImporterRegistry.cpp b/code/ImporterRegistry.cpp index 480a32ec8..b894afba6 100644 --- a/code/ImporterRegistry.cpp +++ b/code/ImporterRegistry.cpp @@ -166,6 +166,9 @@ corresponding preprocessor flag to selectively disable formats. #ifndef ASSIMP_BUILD_NO_XGL_IMPORTER # include "XGLLoader.h" #endif +#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER +# include "FBXImporter.h" +#endif namespace Assimp { @@ -291,6 +294,9 @@ void GetImporterInstanceList(std::vector< BaseImporter* >& out) #if ( !defined ASSIMP_BUILD_NO_XGL_IMPORTER ) out.push_back( new XGLImporter() ); #endif +#if ( !defined ASSIMP_BUILD_NO_FBX_IMPORTER ) + out.push_back( new FBXImporter() ); +#endif } } diff --git a/workspaces/vc9/assimp.vcproj b/workspaces/vc9/assimp.vcproj index 5a1b92338..bd781cef5 100644 --- a/workspaces/vc9/assimp.vcproj +++ b/workspaces/vc9/assimp.vcproj @@ -1,7 +1,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - @@ -2219,14 +2243,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2251,6 +2267,22 @@ UsePrecompiledHeader="0" /> + + + + + + @@ -2385,14 +2417,6 @@ PrecompiledHeaderThrough="AssimpPCH.h" /> - - - @@ -2420,14 +2444,6 @@ PrecompiledHeaderThrough="AssimpPCH.h" /> - - - @@ -2455,6 +2471,22 @@ PrecompiledHeaderThrough="AssimpPCH.h" /> + + + + + + @@ -2762,14 +2794,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2778,14 +2802,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2794,14 +2810,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2810,14 +2818,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2826,14 +2826,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2842,14 +2834,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2859,7 +2843,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -2922,14 +2946,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2938,14 +2954,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2954,14 +2962,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2970,14 +2970,6 @@ UsePrecompiledHeader="0" /> - - - @@ -2986,14 +2978,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3003,7 +2987,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3054,14 +3078,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3070,14 +3086,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3086,14 +3094,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3102,14 +3102,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3118,14 +3110,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3135,7 +3119,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3194,14 +3218,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3210,14 +3226,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3226,14 +3234,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3242,14 +3242,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3258,14 +3250,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3275,7 +3259,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3334,14 +3358,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3350,14 +3366,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3366,14 +3374,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3382,14 +3382,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3398,14 +3390,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3415,7 +3399,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3470,14 +3494,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3486,14 +3502,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3502,14 +3510,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3518,14 +3518,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3534,14 +3526,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3551,7 +3535,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3606,14 +3630,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3622,14 +3638,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3638,14 +3646,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3654,14 +3654,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3670,14 +3662,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3687,7 +3671,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3742,14 +3766,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3758,14 +3774,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3774,14 +3782,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3790,14 +3790,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3806,14 +3798,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3823,7 +3807,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -3890,14 +3914,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3906,14 +3922,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3922,14 +3930,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3938,14 +3938,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3954,14 +3946,6 @@ UsePrecompiledHeader="0" /> - - - @@ -3971,7 +3955,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4030,14 +4054,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4046,14 +4062,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4062,14 +4070,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4078,14 +4078,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4094,14 +4086,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4111,7 +4095,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4170,14 +4194,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4186,14 +4202,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4202,14 +4210,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4218,14 +4218,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4234,14 +4226,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4251,7 +4235,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4306,14 +4330,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4322,14 +4338,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4338,14 +4346,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4354,14 +4354,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4370,14 +4362,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4387,7 +4371,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4446,14 +4470,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4462,14 +4478,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4478,14 +4486,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4494,14 +4494,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4510,14 +4502,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4527,7 +4511,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4582,14 +4606,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4598,14 +4614,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4614,14 +4622,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4630,14 +4630,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4646,14 +4638,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4663,7 +4647,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4718,14 +4742,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4734,14 +4750,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4750,14 +4758,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4766,14 +4766,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4782,14 +4774,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4799,7 +4783,7 @@ /> + + + + + + + + + + + + + + + + + + - - - @@ -4862,14 +4886,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4878,14 +4894,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4894,14 +4902,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4910,14 +4910,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4926,14 +4918,6 @@ UsePrecompiledHeader="0" /> - - - @@ -4943,7 +4927,7 @@ /> + + + + + + + + + + + + + + + + + +