vrshoot
diff libs/assimp/FBXImporter.cpp @ 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/FBXImporter.cpp Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,189 @@ 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 FBXImporter.cpp 1.45 + * @brief Implementation of the FBX importer. 1.46 + */ 1.47 +#include "AssimpPCH.h" 1.48 + 1.49 +#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER 1.50 + 1.51 +#include <exception> 1.52 +#include <iterator> 1.53 +#include <boost/tuple/tuple.hpp> 1.54 + 1.55 +#include "FBXImporter.h" 1.56 + 1.57 +#include "FBXTokenizer.h" 1.58 +#include "FBXParser.h" 1.59 +#include "FBXUtil.h" 1.60 +#include "FBXDocument.h" 1.61 +#include "FBXConverter.h" 1.62 + 1.63 +#include "StreamReader.h" 1.64 +#include "MemoryIOWrapper.h" 1.65 + 1.66 +namespace Assimp { 1.67 + template<> const std::string LogFunctions<FBXImporter>::log_prefix = "FBX: "; 1.68 +} 1.69 + 1.70 +using namespace Assimp; 1.71 +using namespace Assimp::Formatter; 1.72 +using namespace Assimp::FBX; 1.73 + 1.74 +namespace { 1.75 +static const aiImporterDesc desc = { 1.76 + "Autodesk FBX Importer", 1.77 + "", 1.78 + "", 1.79 + "", 1.80 + aiImporterFlags_SupportTextFlavour, 1.81 + 0, 1.82 + 0, 1.83 + 0, 1.84 + 0, 1.85 + "fbx" 1.86 +}; 1.87 +} 1.88 + 1.89 +// ------------------------------------------------------------------------------------------------ 1.90 +// Constructor to be privately used by #Importer 1.91 +FBXImporter::FBXImporter() 1.92 +{} 1.93 + 1.94 +// ------------------------------------------------------------------------------------------------ 1.95 +// Destructor, private as well 1.96 +FBXImporter::~FBXImporter() 1.97 +{ 1.98 +} 1.99 + 1.100 +// ------------------------------------------------------------------------------------------------ 1.101 +// Returns whether the class can handle the format of the given file. 1.102 +bool FBXImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const 1.103 +{ 1.104 + const std::string& extension = GetExtension(pFile); 1.105 + if (extension == "fbx") { 1.106 + return true; 1.107 + } 1.108 + 1.109 + else if ((!extension.length() || checkSig) && pIOHandler) { 1.110 + // at least ascii FBX files usually have a 'FBX' somewhere in their head 1.111 + const char* tokens[] = {"FBX"}; 1.112 + return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1); 1.113 + } 1.114 + return false; 1.115 +} 1.116 + 1.117 +// ------------------------------------------------------------------------------------------------ 1.118 +// List all extensions handled by this loader 1.119 +const aiImporterDesc* FBXImporter::GetInfo () const 1.120 +{ 1.121 + return &desc; 1.122 +} 1.123 + 1.124 + 1.125 +// ------------------------------------------------------------------------------------------------ 1.126 +// Setup configuration properties for the loader 1.127 +void FBXImporter::SetupProperties(const Importer* pImp) 1.128 +{ 1.129 + settings.readAllLayers = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_GEOMETRY_LAYERS, true); 1.130 + settings.readAllMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ALL_MATERIALS, false); 1.131 + settings.readMaterials = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_MATERIALS, true); 1.132 + settings.readCameras = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, true); 1.133 + settings.readLights = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, true); 1.134 + settings.readAnimations = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ANIMATIONS, true); 1.135 + settings.strictMode = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_STRICT_MODE, false); 1.136 + settings.preservePivots = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, true); 1.137 + settings.optimizeEmptyAnimationCurves = pImp->GetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true); 1.138 +} 1.139 + 1.140 + 1.141 +// ------------------------------------------------------------------------------------------------ 1.142 +// Imports the given file into the given scene structure. 1.143 +void FBXImporter::InternReadFile( const std::string& pFile, 1.144 + aiScene* pScene, IOSystem* pIOHandler) 1.145 +{ 1.146 + boost::scoped_ptr<IOStream> stream(pIOHandler->Open(pFile,"rb")); 1.147 + if (!stream) { 1.148 + ThrowException("Could not open file for reading"); 1.149 + } 1.150 + 1.151 + // read entire file into memory - no streaming for this, fbx 1.152 + // files can grow large, but the assimp output data structure 1.153 + // then becomes very large, too. Assimp doesn't support 1.154 + // streaming for its output data structures so the net win with 1.155 + // streaming input data would be very low. 1.156 + std::vector<char> contents; 1.157 + contents.resize(stream->FileSize()); 1.158 + 1.159 + stream->Read(&*contents.begin(),contents.size(),1); 1.160 + const char* const begin = &*contents.begin(); 1.161 + 1.162 + // broadphase tokenizing pass in which we identify the core 1.163 + // syntax elements of FBX (brackets, commas, key:value mappings) 1.164 + TokenList tokens; 1.165 + try { 1.166 + 1.167 + bool is_binary = false; 1.168 + if (!strncmp(begin,"Kaydara FBX Binary",18)) { 1.169 + is_binary = true; 1.170 + TokenizeBinary(tokens,begin,contents.size()); 1.171 + } 1.172 + else { 1.173 + Tokenize(tokens,begin); 1.174 + } 1.175 + 1.176 + // use this information to construct a very rudimentary 1.177 + // parse-tree representing the FBX scope structure 1.178 + Parser parser(tokens, is_binary); 1.179 + 1.180 + // take the raw parse-tree and convert it to a FBX DOM 1.181 + Document doc(parser,settings); 1.182 + 1.183 + // convert the FBX DOM to aiScene 1.184 + ConvertToAssimpScene(pScene,doc); 1.185 + } 1.186 + catch(std::exception&) { 1.187 + std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>()); 1.188 + throw; 1.189 + } 1.190 +} 1.191 + 1.192 +#endif // !ASSIMP_BUILD_NO_FBX_IMPORTER