- 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.

pull/14/head
Alexander Gessler 2012-06-28 19:16:14 +02:00
parent 6c985b9960
commit 05bc8ab684
6 changed files with 101 additions and 24 deletions

View File

@ -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<unsigned int>& 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<size_t>(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<unsigned int>& 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();
}

View File

@ -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<const Object> 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;
};

View File

@ -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

View File

@ -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<Token>());

View File

@ -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
@ -94,22 +96,9 @@ protected:
private:
public:
// loader settings, publicly accessible via their corresponding AI_CONFIG constants
struct Settings
{
Settings()
{}
};
private:
Settings settings;
FBX::ImportSettings settings;
}; // !class FBXImporter

View File

@ -2075,6 +2075,10 @@
RelativePath="..\..\code\FBXImporter.h"
>
</File>
<File
RelativePath="..\..\code\FBXImportSettings.h"
>
</File>
<File
RelativePath="..\..\code\FBXParser.cpp"
>