vrshoot
view libs/assimp/FBXImporter.cpp @ 2:334d17aed7de
visual studio project files
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 02 Feb 2014 18:36:38 +0200 |
parents | |
children |
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file FBXImporter.cpp
42 * @brief Implementation of the FBX importer.
43 */
44 #include "AssimpPCH.h"
46 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
48 #include <exception>
49 #include <iterator>
50 #include <boost/tuple/tuple.hpp>
52 #include "FBXImporter.h"
54 #include "FBXTokenizer.h"
55 #include "FBXParser.h"
56 #include "FBXUtil.h"
57 #include "FBXDocument.h"
58 #include "FBXConverter.h"
60 #include "StreamReader.h"
61 #include "MemoryIOWrapper.h"
63 namespace Assimp {
64 template<> const std::string LogFunctions<FBXImporter>::log_prefix = "FBX: ";
65 }
67 using namespace Assimp;
68 using namespace Assimp::Formatter;
69 using namespace Assimp::FBX;
71 namespace {
72 static const aiImporterDesc desc = {
73 "Autodesk FBX Importer",
74 "",
75 "",
76 "",
77 aiImporterFlags_SupportTextFlavour,
78 0,
79 0,
80 0,
81 0,
82 "fbx"
83 };
84 }
86 // ------------------------------------------------------------------------------------------------
87 // Constructor to be privately used by #Importer
88 FBXImporter::FBXImporter()
89 {}
91 // ------------------------------------------------------------------------------------------------
92 // Destructor, private as well
93 FBXImporter::~FBXImporter()
94 {
95 }
97 // ------------------------------------------------------------------------------------------------
98 // Returns whether the class can handle the format of the given file.
99 bool FBXImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
100 {
101 const std::string& extension = GetExtension(pFile);
102 if (extension == "fbx") {
103 return true;
104 }
106 else if ((!extension.length() || checkSig) && pIOHandler) {
107 // at least ascii FBX files usually have a 'FBX' somewhere in their head
108 const char* tokens[] = {"FBX"};
109 return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
110 }
111 return false;
112 }
114 // ------------------------------------------------------------------------------------------------
115 // List all extensions handled by this loader
116 const aiImporterDesc* FBXImporter::GetInfo () const
117 {
118 return &desc;
119 }
122 // ------------------------------------------------------------------------------------------------
123 // Setup configuration properties for the loader
124 void FBXImporter::SetupProperties(const Importer* pImp)
125 {
126 settings.readAllLayers = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_GEOMETRY_LAYERS, true);
127 settings.readAllMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_MATERIALS, false);
128 settings.readMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_MATERIALS, true);
129 settings.readCameras = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, true);
130 settings.readLights = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, true);
131 settings.readAnimations = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ANIMATIONS, true);
132 settings.strictMode = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_STRICT_MODE, false);
133 settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true);
134 settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true);
135 }
138 // ------------------------------------------------------------------------------------------------
139 // Imports the given file into the given scene structure.
140 void FBXImporter::InternReadFile( const std::string& pFile,
141 aiScene* pScene, IOSystem* pIOHandler)
142 {
143 boost::scoped_ptr<IOStream> stream(pIOHandler->Open(pFile,"rb"));
144 if (!stream) {
145 ThrowException("Could not open file for reading");
146 }
148 // read entire file into memory - no streaming for this, fbx
149 // files can grow large, but the assimp output data structure
150 // then becomes very large, too. Assimp doesn't support
151 // streaming for its output data structures so the net win with
152 // streaming input data would be very low.
153 std::vector<char> contents;
154 contents.resize(stream->FileSize());
156 stream->Read(&*contents.begin(),contents.size(),1);
157 const char* const begin = &*contents.begin();
159 // broadphase tokenizing pass in which we identify the core
160 // syntax elements of FBX (brackets, commas, key:value mappings)
161 TokenList tokens;
162 try {
164 bool is_binary = false;
165 if (!strncmp(begin,"Kaydara FBX Binary",18)) {
166 is_binary = true;
167 TokenizeBinary(tokens,begin,contents.size());
168 }
169 else {
170 Tokenize(tokens,begin);
171 }
173 // use this information to construct a very rudimentary
174 // parse-tree representing the FBX scope structure
175 Parser parser(tokens, is_binary);
177 // take the raw parse-tree and convert it to a FBX DOM
178 Document doc(parser,settings);
180 // convert the FBX DOM to aiScene
181 ConvertToAssimpScene(pScene,doc);
182 }
183 catch(std::exception&) {
184 std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
185 throw;
186 }
187 }
189 #endif // !ASSIMP_BUILD_NO_FBX_IMPORTER