From 05bc8ab68461a338337df226f6629088cc7990e3 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Thu, 28 Jun 2012 19:16:14 +0200 Subject: [PATCH] - fbx: add ImportSettings to keep track of fbx-specific import settings. The settings are generated by the importer instance and injected into parser and DOM. --- code/FBXDocument.cpp | 17 ++++++--- code/FBXDocument.h | 14 +++++-- code/FBXImportSettings.h | 71 ++++++++++++++++++++++++++++++++++++ code/FBXImporter.cpp | 2 +- code/FBXImporter.h | 17 ++------- workspaces/vc9/assimp.vcproj | 4 ++ 6 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 code/FBXImportSettings.h diff --git a/code/FBXDocument.cpp b/code/FBXDocument.cpp index 0886edc3c..eb606573f 100644 --- a/code/FBXDocument.cpp +++ b/code/FBXDocument.cpp @@ -49,6 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "FBXDocument.h" #include "FBXUtil.h" #include "FBXImporter.h" +#include "FBXImportSettings.h" namespace Assimp { namespace FBX { @@ -307,8 +308,9 @@ void ReadVectorDataArray(std::vector& out, const Element& el) // ------------------------------------------------------------------------------------------------ -LazyObject::LazyObject(const Element& element) -: element(element) +LazyObject::LazyObject(const Element& element, const ImportSettings& settings) +: settings(settings) +, element(element) { } @@ -350,7 +352,7 @@ const Object* LazyObject::Get() if (!strncmp(obtype,"Geometry",static_cast(key.end()-key.begin()))) { if (!strcmp(classtag.c_str(),"Mesh")) { - object = new MeshGeometry(element,name); + object = new MeshGeometry(element,name,settings); } } @@ -389,7 +391,7 @@ Geometry::~Geometry() } // ------------------------------------------------------------------------------------------------ -MeshGeometry::MeshGeometry(const Element& element, const std::string& name) +MeshGeometry::MeshGeometry(const Element& element, const std::string& name, const ImportSettings& settings) : Geometry(element,name) { const Scope* sc = element.Compound(); @@ -456,6 +458,8 @@ MeshGeometry::MeshGeometry(const Element& element, const std::string& name) mappings[mapping_offsets[absi] + mapping_counts[absi]++] = cursor; } + if(settings.readAllLayers) + // ignore all but the first layer, but warn about any further layers for (ElementMap::const_iterator it = Layer.first; it != Layer.second; ++it) { const TokenList& tokens = (*it).second->Tokens(); @@ -784,8 +788,9 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector& materials_ // ------------------------------------------------------------------------------------------------ -Document::Document(const Parser& parser) +Document::Document(const Parser& parser, const ImportSettings& settings) : parser(parser) +, settings(settings) { const Scope& sc = parser.GetRootScope(); @@ -811,7 +816,7 @@ Document::Document(const Parser& parser) DOMError(err,el.second); } - objects[id] = new LazyObject(*el.second); + objects[id] = new LazyObject(*el.second, settings); // DEBUG - evaluate all objects const Object* o = objects[id]->Get(); } diff --git a/code/FBXDocument.h b/code/FBXDocument.h index cddbfd99d..4496330b5 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -53,6 +53,7 @@ namespace FBX { class Parser; class Object; + struct ImportSettings; /** Represents a delay-parsed FBX objects. Many objects in the scene @@ -62,7 +63,7 @@ class LazyObject { public: - LazyObject(const Element& element); + LazyObject(const Element& element, const ImportSettings& settings); ~LazyObject(); public: @@ -77,6 +78,7 @@ public: private: + const ImportSettings& settings; const Element& element; boost::scoped_ptr object; }; @@ -115,7 +117,7 @@ class MeshGeometry : public Geometry public: - MeshGeometry(const Element& element, const std::string& name); + MeshGeometry(const Element& element, const std::string& name, const ImportSettings& settings); ~MeshGeometry(); public: @@ -232,7 +234,7 @@ class Document { public: - Document(const Parser& parser); + Document(const Parser& parser, const ImportSettings& settings); ~Document(); public: @@ -241,8 +243,14 @@ public: return objects; } + const ImportSettings& Settings() const { + return settings; + } + private: + const ImportSettings& settings; + ObjectMap objects; const Parser& parser; }; diff --git a/code/FBXImportSettings.h b/code/FBXImportSettings.h new file mode 100644 index 000000000..f2a567916 --- /dev/null +++ b/code/FBXImportSettings.h @@ -0,0 +1,71 @@ +/* +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 FBXImportSettings.h + * @brief FBX importer runtime configuration + */ +#ifndef INCLUDED_AI_FBX_IMPORTSETTINGS_H +#define INCLUDED_AI_FBX_IMPORTSETTINGS_H + +namespace Assimp { +namespace FBX { + +/** FBX import settings, parts of which are publicly accessible via their corresponding AI_CONFIG constants */ +struct ImportSettings +{ + ImportSettings() + : readAllLayers(true) + {} + + /** specifies whether all geometry layers are read and scanned for + * usable data channels. The FBX spec indicates that many readers + * will only read the first channel and that this is in some way + * the recommended way- in reality, however, it happens a lot that + * vertex data is spread among multiple layers. The default + * value for this option is true.*/ + bool readAllLayers; +}; + + +} // !FBX +} // !Assimp + +#endif + diff --git a/code/FBXImporter.cpp b/code/FBXImporter.cpp index 3a8193509..9335cd5f7 100644 --- a/code/FBXImporter.cpp +++ b/code/FBXImporter.cpp @@ -158,7 +158,7 @@ void FBXImporter::InternReadFile( const std::string& pFile, Parser parser(tokens); // take the raw parse-tree and convert it to a FBX DOM - Document doc(parser); + Document doc(parser,settings); } catch(...) { std::for_each(tokens.begin(),tokens.end(),Util::delete_fun()); diff --git a/code/FBXImporter.h b/code/FBXImporter.h index e0d771f23..635411397 100644 --- a/code/FBXImporter.h +++ b/code/FBXImporter.h @@ -47,6 +47,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "BaseImporter.h" #include "LogAux.h" +#include "FBXImportSettings.h" + namespace Assimp { // TinyFormatter.h @@ -93,23 +95,10 @@ protected: private: - -public: - - - // loader settings, publicly accessible via their corresponding AI_CONFIG constants - struct Settings - { - Settings() - - {} - - }; - private: - Settings settings; + FBX::ImportSettings settings; }; // !class FBXImporter diff --git a/workspaces/vc9/assimp.vcproj b/workspaces/vc9/assimp.vcproj index 5d9f46437..278014925 100644 --- a/workspaces/vc9/assimp.vcproj +++ b/workspaces/vc9/assimp.vcproj @@ -2075,6 +2075,10 @@ RelativePath="..\..\code\FBXImporter.h" > + +