FBXImporter: some refactorings to increase readability.

pull/814/head
Kim Kulling 2016-03-03 18:38:50 +01:00
parent 26fba14aaf
commit 53370d0d31
6 changed files with 29 additions and 32 deletions

View File

@ -54,13 +54,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "StringComparison.h" #include "StringComparison.h"
#include "../include/assimp/scene.h" #include "../include/assimp/scene.h"
#include <iterator>
#include <sstream>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <vector>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <iterator>
#include <sstream>
#include <vector>
namespace Assimp { namespace Assimp {
namespace FBX { namespace FBX {
@ -79,8 +79,9 @@ using namespace Util;
class Converter class Converter
{ {
public: public:
/**
/** the different parts that make up the final local transformation of a fbx node */ * The different parts that make up the final local transformation of a fbx-node
*/
enum TransformationComp enum TransformationComp
{ {
TransformationComp_Translation = 0, TransformationComp_Translation = 0,
@ -102,7 +103,6 @@ public:
}; };
public: public:
Converter(aiScene* out, const Document& doc) Converter(aiScene* out, const Document& doc)
: defaultMaterialIndex() : defaultMaterialIndex()
, out(out) , out(out)
@ -858,7 +858,7 @@ private:
} }
} }
// faster codepath, just copy the data // faster code-path, just copy the data
temp.push_back(ConvertMeshSingleMaterial(mesh, model, node_global_transform)); temp.push_back(ConvertMeshSingleMaterial(mesh, model, node_global_transform));
return temp; return temp;
} }
@ -961,7 +961,8 @@ private:
} }
if(binormals) { if(binormals) {
ai_assert(tangents.size() == vertices.size() && binormals->size() == vertices.size()); ai_assert( tangents.size() == vertices.size() );
ai_assert( binormals->size() == vertices.size() );
out_mesh->mTangents = new aiVector3D[vertices.size()]; out_mesh->mTangents = new aiVector3D[vertices.size()];
std::copy(tangents.begin(),tangents.end(),out_mesh->mTangents); std::copy(tangents.begin(),tangents.end(),out_mesh->mTangents);
@ -1216,10 +1217,12 @@ private:
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
/** - if materialIndex == NO_MATERIAL_SEPARATION, materials are not taken into /**
* account when determining which weights to include. * - if materialIndex == NO_MATERIAL_SEPARATION, materials are not taken into
* account when determining which weights to include.
* - outputVertStartIndices is only used when a material index is specified, it gives for * - outputVertStartIndices is only used when a material index is specified, it gives for
* each output vertex the DOM index it maps to. */ * each output vertex the DOM index it maps to.
*/
void ConvertWeights(aiMesh* out, const Model& model, const MeshGeometry& geo, void ConvertWeights(aiMesh* out, const Model& model, const MeshGeometry& geo,
const aiMatrix4x4& node_global_transform = aiMatrix4x4(), const aiMatrix4x4& node_global_transform = aiMatrix4x4(),
unsigned int materialIndex = NO_MATERIAL_SEPARATION, unsigned int materialIndex = NO_MATERIAL_SEPARATION,

View File

@ -51,15 +51,14 @@ namespace FBX {
class Document; class Document;
/**
/** Convert a FBX #Document to #aiScene * Convert a FBX #Document to #aiScene
* @param out Empty scene to be populated * @param out Empty scene to be populated
* @param doc Parsed FBX document */ * @param doc Parsed FBX document
*/
void ConvertToAssimpScene(aiScene* out, const Document& doc); void ConvertToAssimpScene(aiScene* out, const Document& doc);
} }
} }
#endif // INCLUDED_AI_FBX_CONVERTER_H
#endif

View File

@ -86,7 +86,8 @@ static const aiImporterDesc desc = {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructor to be privately used by #Importer // Constructor to be privately used by #Importer
FBXImporter::FBXImporter() FBXImporter::FBXImporter()
{} {
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor, private as well // Destructor, private as well
@ -104,7 +105,7 @@ bool FBXImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
} }
else if ((!extension.length() || checkSig) && pIOHandler) { else if ((!extension.length() || checkSig) && pIOHandler) {
// at least ascii FBX files usually have a 'FBX' somewhere in their head // at least ASCII-FBX files usually have a 'FBX' somewhere in their head
const char* tokens[] = {"fbx"}; const char* tokens[] = {"fbx"};
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1); return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
} }

View File

@ -56,7 +56,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
namespace FBX { namespace FBX {
using namespace Util; using namespace Util;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Model::Model(uint64_t id, const Element& element, const Document& doc, const std::string& name) Model::Model(uint64_t id, const Element& element, const Document& doc, const std::string& name)

View File

@ -58,7 +58,8 @@ namespace FBX {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
NodeAttribute::NodeAttribute(uint64_t id, const Element& element, const Document& doc, const std::string& name) NodeAttribute::NodeAttribute(uint64_t id, const Element& element, const Document& doc, const std::string& name)
: Object(id,element,name) : Object(id,element,name)
, props()
{ {
const Scope& sc = GetRequiredScope(element); const Scope& sc = GetRequiredScope(element);

View File

@ -65,15 +65,12 @@ namespace FBX {
class Property class Property
{ {
protected: protected:
Property(); Property();
public: public:
virtual ~Property(); virtual ~Property();
public: public:
template <typename T> template <typename T>
const T* As() const { const T* As() const {
return dynamic_cast<const T*>(this); return dynamic_cast<const T*>(this);
@ -85,14 +82,12 @@ template<typename T>
class TypedProperty : public Property class TypedProperty : public Property
{ {
public: public:
explicit TypedProperty(const T& value) explicit TypedProperty(const T& value)
: value(value) : value(value)
{ {
} }
public: public:
const T& Value() const { const T& Value() const {
return value; return value;
} }
@ -106,19 +101,18 @@ typedef std::fbx_unordered_map<std::string,boost::shared_ptr<Property> > DirectP
typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap; typedef std::fbx_unordered_map<std::string,const Property*> PropertyMap;
typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap; typedef std::fbx_unordered_map<std::string,const Element*> LazyPropertyMap;
/** Represents a property table as can be found in the newer FBX files (Properties60, Properties70)*/ /**
* Represents a property table as can be found in the newer FBX files (Properties60, Properties70)
*/
class PropertyTable class PropertyTable
{ {
public: public:
// in-memory property table with no source element // in-memory property table with no source element
PropertyTable(); PropertyTable();
PropertyTable(const Element& element, boost::shared_ptr<const PropertyTable> templateProps); PropertyTable(const Element& element, boost::shared_ptr<const PropertyTable> templateProps);
~PropertyTable(); ~PropertyTable();
public: public:
const Property* Get(const std::string& name) const; const Property* Get(const std::string& name) const;
// PropertyTable's need not be coupled with FBX elements so this can be NULL // PropertyTable's need not be coupled with FBX elements so this can be NULL
@ -133,7 +127,6 @@ public:
DirectPropertyMap GetUnparsedProperties() const; DirectPropertyMap GetUnparsedProperties() const;
private: private:
LazyPropertyMap lazyProps; LazyPropertyMap lazyProps;
mutable PropertyMap props; mutable PropertyMap props;
const boost::shared_ptr<const PropertyTable> templateProps; const boost::shared_ptr<const PropertyTable> templateProps;
@ -187,4 +180,4 @@ inline T PropertyGet(const PropertyTable& in, const std::string& name,
} //! FBX } //! FBX
} //! Assimp } //! Assimp
#endif // #endif // INCLUDED_AI_FBX_PROPERTIES_H