vrshoot
diff 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 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/FBXParser.h Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,246 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file FBXParser.h 1.45 + * @brief FBX parsing code 1.46 + */ 1.47 +#ifndef INCLUDED_AI_FBX_PARSER_H 1.48 +#define INCLUDED_AI_FBX_PARSER_H 1.49 + 1.50 +#include <vector> 1.51 +#include <map> 1.52 +#include <string> 1.53 +#include <utility> 1.54 + 1.55 +#include <boost/shared_ptr.hpp> 1.56 + 1.57 +#include "LogAux.h" 1.58 + 1.59 +#include "FBXCompileConfig.h" 1.60 +#include "FBXTokenizer.h" 1.61 + 1.62 +namespace Assimp { 1.63 +namespace FBX { 1.64 + 1.65 + class Scope; 1.66 + class Parser; 1.67 + class Element; 1.68 + 1.69 + // XXX should use C++11's unique_ptr - but assimp's need to keep working with 03 1.70 + typedef std::vector< Scope* > ScopeList; 1.71 + typedef std::fbx_unordered_multimap< std::string, Element* > ElementMap; 1.72 + 1.73 + typedef std::pair<ElementMap::const_iterator,ElementMap::const_iterator> ElementCollection; 1.74 + 1.75 +# define new_Scope new Scope 1.76 +# define new_Element new Element 1.77 + 1.78 + 1.79 +/** FBX data entity that consists of a key:value tuple. 1.80 + * 1.81 + * Example: 1.82 + * @verbatim 1.83 + * AnimationCurve: 23, "AnimCurve::", "" { 1.84 + * [..] 1.85 + * } 1.86 + * @endverbatim 1.87 + * 1.88 + * As can be seen in this sample, elements can contain nested #Scope 1.89 + * as their trailing member. **/ 1.90 +class Element 1.91 +{ 1.92 +public: 1.93 + 1.94 + Element(const Token& key_token, Parser& parser); 1.95 + ~Element(); 1.96 + 1.97 +public: 1.98 + 1.99 + const Scope* Compound() const { 1.100 + return compound.get(); 1.101 + } 1.102 + 1.103 + const Token& KeyToken() const { 1.104 + return key_token; 1.105 + } 1.106 + 1.107 + const TokenList& Tokens() const { 1.108 + return tokens; 1.109 + } 1.110 + 1.111 +private: 1.112 + 1.113 + const Token& key_token; 1.114 + TokenList tokens; 1.115 + boost::scoped_ptr<Scope> compound; 1.116 +}; 1.117 + 1.118 + 1.119 + 1.120 +/** FBX data entity that consists of a 'scope', a collection 1.121 + * of not necessarily unique #Element instances. 1.122 + * 1.123 + * Example: 1.124 + * @verbatim 1.125 + * GlobalSettings: { 1.126 + * Version: 1000 1.127 + * Properties70: 1.128 + * [...] 1.129 + * } 1.130 + * @endverbatim */ 1.131 +class Scope 1.132 +{ 1.133 + 1.134 +public: 1.135 + 1.136 + Scope(Parser& parser, bool topLevel = false); 1.137 + ~Scope(); 1.138 + 1.139 +public: 1.140 + 1.141 + const Element* operator[] (const std::string& index) const { 1.142 + ElementMap::const_iterator it = elements.find(index); 1.143 + return it == elements.end() ? NULL : (*it).second; 1.144 + } 1.145 + 1.146 + ElementCollection GetCollection(const std::string& index) const { 1.147 + return elements.equal_range(index); 1.148 + } 1.149 + 1.150 + const ElementMap& Elements() const { 1.151 + return elements; 1.152 + } 1.153 + 1.154 +private: 1.155 + 1.156 + ElementMap elements; 1.157 +}; 1.158 + 1.159 + 1.160 +/** FBX parsing class, takes a list of input tokens and generates a hierarchy 1.161 + * of nested #Scope instances, representing the fbx DOM.*/ 1.162 +class Parser 1.163 +{ 1.164 +public: 1.165 + 1.166 + /** Parse given a token list. Does not take ownership of the tokens - 1.167 + * the objects must persist during the entire parser lifetime */ 1.168 + Parser (const TokenList& tokens,bool is_binary); 1.169 + ~Parser(); 1.170 + 1.171 +public: 1.172 + 1.173 + const Scope& GetRootScope() const { 1.174 + return *root.get(); 1.175 + } 1.176 + 1.177 + 1.178 + bool IsBinary() const { 1.179 + return is_binary; 1.180 + } 1.181 + 1.182 +private: 1.183 + 1.184 + friend class Scope; 1.185 + friend class Element; 1.186 + 1.187 + TokenPtr AdvanceToNextToken(); 1.188 + 1.189 + TokenPtr LastToken() const; 1.190 + TokenPtr CurrentToken() const; 1.191 + 1.192 + 1.193 + 1.194 +private: 1.195 + 1.196 + const TokenList& tokens; 1.197 + 1.198 + TokenPtr last, current; 1.199 + TokenList::const_iterator cursor; 1.200 + boost::scoped_ptr<Scope> root; 1.201 + 1.202 + const bool is_binary; 1.203 +}; 1.204 + 1.205 + 1.206 +/* token parsing - this happens when building the DOM out of the parse-tree*/ 1.207 +uint64_t ParseTokenAsID(const Token& t, const char*& err_out); 1.208 +size_t ParseTokenAsDim(const Token& t, const char*& err_out); 1.209 + 1.210 +float ParseTokenAsFloat(const Token& t, const char*& err_out); 1.211 +int ParseTokenAsInt(const Token& t, const char*& err_out); 1.212 +std::string ParseTokenAsString(const Token& t, const char*& err_out); 1.213 + 1.214 + 1.215 +/* wrapper around ParseTokenAsXXX() with DOMError handling */ 1.216 +uint64_t ParseTokenAsID(const Token& t); 1.217 +size_t ParseTokenAsDim(const Token& t); 1.218 +float ParseTokenAsFloat(const Token& t); 1.219 +int ParseTokenAsInt(const Token& t); 1.220 +std::string ParseTokenAsString(const Token& t); 1.221 + 1.222 +/* read data arrays */ 1.223 +void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el); 1.224 +void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el); 1.225 +void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el); 1.226 +void ParseVectorDataArray(std::vector<int>& out, const Element& el); 1.227 +void ParseVectorDataArray(std::vector<float>& out, const Element& el); 1.228 +void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el); 1.229 +void ParseVectorDataArray(std::vector<uint64_t>& out, const Element& e); 1.230 + 1.231 + 1.232 + 1.233 +// extract a required element from a scope, abort if the element cannot be found 1.234 +const Element& GetRequiredElement(const Scope& sc, const std::string& index, const Element* element = NULL); 1.235 + 1.236 +// extract required compound scope 1.237 +const Scope& GetRequiredScope(const Element& el); 1.238 +// get token at a particular index 1.239 +const Token& GetRequiredToken(const Element& el, unsigned int index); 1.240 + 1.241 + 1.242 + 1.243 +// read a 4x4 matrix from an array of 16 floats 1.244 +aiMatrix4x4 ReadMatrix(const Element& element); 1.245 + 1.246 +} // ! FBX 1.247 +} // ! Assimp 1.248 + 1.249 +#endif // ! INCLUDED_AI_FBX_PARSER_H