diff --git a/code/FBXDocument.h b/code/FBXDocument.h index 51a3de448..2cd5cd16e 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -184,7 +184,7 @@ private: }; -typedef std::fbx_unordered_map TextureMap; +typedef std::fbx_unordered_map TextureMap; /** DOM class for generic FBX materials */ diff --git a/code/FBXMaterial.cpp b/code/FBXMaterial.cpp index 56bef45d4..eb14bb3af 100644 --- a/code/FBXMaterial.cpp +++ b/code/FBXMaterial.cpp @@ -94,7 +94,33 @@ Material::Material(uint64_t id, const Element& element, const Document& doc, con props = GetPropertyTable(doc,templateName,element,sc); // resolve texture links - doc.GetConnectionsByDestinationSequenced(ID()); + const std::vector conns = doc.GetConnectionsByDestinationSequenced(ID()); + BOOST_FOREACH(const Connection* con, conns) { + + // texture link to properties, not objects + if (!con->PropertyName().length()) { + continue; + } + + const Object* const ob = con->SourceObject(); + if(!ob) { + DOMWarning("failed to read source object for texture link, ignoring",&element); + continue; + } + + const Texture* const tex = dynamic_cast(ob); + if(!tex) { + DOMWarning("source object for texture link is not a texture, ignoring",&element); + continue; + } + + const std::string& prop = con->PropertyName(); + if (textures.find(prop) != textures.end()) { + DOMWarning("duplicate texture link: " + prop,&element); + } + + textures[prop] = tex; + } }