- fbx: Objects now carry their ID.

pull/14/head
Alexander Gessler 2012-07-03 19:36:38 +02:00
parent 8a12b179a6
commit effcaf066a
4 changed files with 40 additions and 19 deletions

View File

@ -363,9 +363,10 @@ boost::shared_ptr<const PropertyTable> GetPropertyTable(const Document& doc,
using namespace Util; using namespace Util;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
LazyObject::LazyObject(const Element& element, const Document& doc) LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc)
: doc(doc) : doc(doc)
, element(element) , element(element)
, id(id)
{ {
} }
@ -401,17 +402,22 @@ const Object* LazyObject::Get()
DOMError(err,&element); DOMError(err,&element);
} }
// XXX prevent recursive calls
// this needs to be relatively fast since it happens a lot, // this needs to be relatively fast since it happens a lot,
// so avoid constructing strings all the time. // so avoid constructing strings all the time.
const char* obtype = key.begin(); const char* obtype = key.begin();
const size_t length = static_cast<size_t>(key.end()-key.begin()); const size_t length = static_cast<size_t>(key.end()-key.begin());
if (!strncmp(obtype,"Geometry",length)) { if (!strncmp(obtype,"Geometry",length)) {
if (!strcmp(classtag.c_str(),"Mesh")) { if (!strcmp(classtag.c_str(),"Mesh")) {
object.reset(new MeshGeometry(element,name,doc.Settings())); object.reset(new MeshGeometry(id,element,name,doc.Settings()));
} }
} }
else if (!strncmp(obtype,"Material",length)) { else if (!strncmp(obtype,"Material",length)) {
object.reset(new Material(element,doc,name)); object.reset(new Material(id,element,doc,name));
}
else if (!strncmp(obtype,"Texture",length)) {
object.reset(new Texture(id,element,doc,name));
} }
if (!object.get()) { if (!object.get()) {
@ -422,9 +428,10 @@ const Object* LazyObject::Get()
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Object::Object(const Element& element, const std::string& name) Object::Object(uint64_t id, const Element& element, const std::string& name)
: element(element) : element(element)
, name(name) , name(name)
, id(id)
{ {
} }
@ -437,8 +444,8 @@ Object::~Object()
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Geometry::Geometry(const Element& element, const std::string& name) Geometry::Geometry(uint64_t id, const Element& element, const std::string& name)
: Object(element,name) : Object(id, element,name)
{ {
} }
@ -498,7 +505,7 @@ void Document::ReadObjects()
DOMError(err,el.second); DOMError(err,el.second);
} }
objects[id] = new LazyObject(*el.second, *this); objects[id] = new LazyObject(id, *el.second, *this);
// DEBUG - evaluate all objects // DEBUG - evaluate all objects
const Object* o = objects[id]->Get(); const Object* o = objects[id]->Get();
} }

View File

@ -66,7 +66,7 @@ class LazyObject
{ {
public: public:
LazyObject(const Element& element, const Document& doc); LazyObject(uint64_t id, const Element& element, const Document& doc);
~LazyObject(); ~LazyObject();
public: public:
@ -79,11 +79,17 @@ public:
return ob ? dynamic_cast<T*>(ob) : NULL; return ob ? dynamic_cast<T*>(ob) : NULL;
} }
uint64_t ID() const {
return id;
}
private: private:
const Document& doc; const Document& doc;
const Element& element; const Element& element;
boost::scoped_ptr<const Object> object; boost::scoped_ptr<const Object> object;
const uint64_t id;
}; };
@ -93,7 +99,7 @@ class Object
{ {
public: public:
Object(const Element& element, const std::string& name); Object(uint64_t id, const Element& element, const std::string& name);
virtual ~Object(); virtual ~Object();
public: public:
@ -106,9 +112,14 @@ public:
return name; return name;
} }
uint64_t ID() const {
return id;
}
protected: protected:
const Element& element; const Element& element;
const std::string name; const std::string name;
const uint64_t id;
}; };
@ -119,7 +130,7 @@ class Texture : public Object
{ {
public: public:
Texture(const Element& element, const Document& doc, const std::string& name); Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name);
~Texture(); ~Texture();
public: public:
@ -181,7 +192,7 @@ class Material : public Object
{ {
public: public:
Material(const Element& element, const Document& doc, const std::string& name); Material(uint64_t id, const Element& element, const Document& doc, const std::string& name);
~Material(); ~Material();
public: public:
@ -218,7 +229,7 @@ class Geometry : public Object
{ {
public: public:
Geometry(const Element& element, const std::string& name); Geometry(uint64_t id, const Element& element, const std::string& name);
~Geometry(); ~Geometry();
}; };
@ -229,7 +240,7 @@ class MeshGeometry : public Geometry
public: public:
MeshGeometry(const Element& element, const std::string& name, const ImportSettings& settings); MeshGeometry(uint64_t id, const Element& element, const std::string& name, const ImportSettings& settings);
~MeshGeometry(); ~MeshGeometry();
public: public:

View File

@ -58,8 +58,8 @@ namespace FBX {
using namespace Util; using namespace Util;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Material::Material(const Element& element, const Document& doc, const std::string& name) Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name)
: Object(element,name) : Object(id,element,name)
{ {
const Scope& sc = GetRequiredScope(element); const Scope& sc = GetRequiredScope(element);
@ -92,6 +92,9 @@ Material::Material(const Element& element, const Document& doc, const std::strin
} }
props = GetPropertyTable(doc,templateName,element,sc); props = GetPropertyTable(doc,templateName,element,sc);
// resolve texture links
doc.GetConnectionsByDestinationSequenced(ID());
} }
@ -102,8 +105,8 @@ Material::~Material()
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Texture::Texture(const Element& element, const Document& doc, const std::string& name) Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name)
: Object(element,name) : Object(id,element,name)
, uvScaling(1.0f,1.0f) , uvScaling(1.0f,1.0f)
{ {
const Scope& sc = GetRequiredScope(element); const Scope& sc = GetRequiredScope(element);

View File

@ -58,8 +58,8 @@ namespace FBX {
using namespace Util; using namespace Util;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
MeshGeometry::MeshGeometry(const Element& element, const std::string& name, const ImportSettings& settings) MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::string& name, const ImportSettings& settings)
: Geometry(element,name) : Geometry(id, element,name)
{ {
const Scope* sc = element.Compound(); const Scope* sc = element.Compound();
if (!sc) { if (!sc) {