Pārlūkot izejas kodu

- fbx: read texture -> material connections.

Alexander Gessler 13 gadi atpakaļ
vecāks
revīzija
a0c45f9190
2 mainītis faili ar 28 papildinājumiem un 2 dzēšanām
  1. 1 1
      code/FBXDocument.h
  2. 27 1
      code/FBXMaterial.cpp

+ 1 - 1
code/FBXDocument.h

@@ -184,7 +184,7 @@ private:
 };
 
 
-typedef std::fbx_unordered_map<std::string,Texture*> TextureMap;
+typedef std::fbx_unordered_map<std::string, const Texture*> TextureMap;
 
 
 /** DOM class for generic FBX materials */

+ 27 - 1
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<const Connection*> 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<const Texture*>(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;
+	}
 }