- 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;
// ------------------------------------------------------------------------------------------------
LazyObject::LazyObject(const Element& element, const Document& doc)
LazyObject::LazyObject(uint64_t id, const Element& element, const Document& doc)
: doc(doc)
, element(element)
, id(id)
{
}
@ -401,17 +402,22 @@ const Object* LazyObject::Get()
DOMError(err,&element);
}
// XXX prevent recursive calls
// this needs to be relatively fast since it happens a lot,
// so avoid constructing strings all the time.
const char* obtype = key.begin();
const size_t length = static_cast<size_t>(key.end()-key.begin());
if (!strncmp(obtype,"Geometry",length)) {
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)) {
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()) {
@ -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)
, name(name)
, id(id)
{
}
@ -437,8 +444,8 @@ Object::~Object()
// ------------------------------------------------------------------------------------------------
Geometry::Geometry(const Element& element, const std::string& name)
: Object(element,name)
Geometry::Geometry(uint64_t id, const Element& element, const std::string& name)
: Object(id, element,name)
{
}
@ -498,7 +505,7 @@ void Document::ReadObjects()
DOMError(err,el.second);
}
objects[id] = new LazyObject(*el.second, *this);
objects[id] = new LazyObject(id, *el.second, *this);
// DEBUG - evaluate all objects
const Object* o = objects[id]->Get();
}

View File

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

View File

@ -58,8 +58,8 @@ namespace FBX {
using namespace Util;
// ------------------------------------------------------------------------------------------------
Material::Material(const Element& element, const Document& doc, const std::string& name)
: Object(element,name)
Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name)
: Object(id,element,name)
{
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);
// resolve texture links
doc.GetConnectionsByDestinationSequenced(ID());
}
@ -102,8 +105,8 @@ Material::~Material()
// ------------------------------------------------------------------------------------------------
Texture::Texture(const Element& element, const Document& doc, const std::string& name)
: Object(element,name)
Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name)
: Object(id,element,name)
, uvScaling(1.0f,1.0f)
{
const Scope& sc = GetRequiredScope(element);

View File

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