------------------------------------------------------------------------------------------------
| 63 | |
| 64 | // ------------------------------------------------------------------------------------------------ |
| 65 | Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name) : |
| 66 | Object(id,element,name) { |
| 67 | const Scope& sc = GetRequiredScope(element); |
| 68 | |
| 69 | const Element* const ShadingModel = sc["ShadingModel"]; |
| 70 | const Element* const MultiLayer = sc["MultiLayer"]; |
| 71 | |
| 72 | if(MultiLayer) { |
| 73 | multilayer = !!ParseTokenAsInt(GetRequiredToken(*MultiLayer,0)); |
| 74 | } |
| 75 | |
| 76 | if(ShadingModel) { |
| 77 | shading = ParseTokenAsString(GetRequiredToken(*ShadingModel,0)); |
| 78 | } else { |
| 79 | DOMWarning("shading mode not specified, assuming phong",&element); |
| 80 | shading = "phong"; |
| 81 | } |
| 82 | |
| 83 | // lower-case shading because Blender (for example) writes "Phong" |
| 84 | for (size_t i = 0; i < shading.length(); ++i) { |
| 85 | shading[i] = static_cast<char>(tolower(static_cast<unsigned char>(shading[i]))); |
| 86 | } |
| 87 | std::string templateName; |
| 88 | if(shading == "phong") { |
| 89 | templateName = "Material.FbxSurfacePhong"; |
| 90 | } else if(shading == "lambert") { |
| 91 | templateName = "Material.FbxSurfaceLambert"; |
| 92 | } else { |
| 93 | DOMWarning("shading mode not recognized: " + shading,&element); |
| 94 | } |
| 95 | |
| 96 | props = GetPropertyTable(doc,templateName,element,sc); |
| 97 | |
| 98 | // resolve texture links |
| 99 | const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID()); |
| 100 | for(const Connection* con : conns) { |
| 101 | // texture link to properties, not objects |
| 102 | if ( 0 == con->PropertyName().length()) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | const Object* const ob = con->SourceObject(); |
| 107 | if(nullptr == ob) { |
| 108 | DOMWarning("failed to read source object for texture link, ignoring",&element); |
| 109 | continue; |
| 110 | } |
| 111 | |
| 112 | const Texture* const tex = dynamic_cast<const Texture*>(ob); |
| 113 | if(nullptr == tex) { |
| 114 | const LayeredTexture* const layeredTexture = dynamic_cast<const LayeredTexture*>(ob); |
| 115 | if(!layeredTexture) { |
| 116 | DOMWarning("source object for texture link is not a texture or layered texture, ignoring",&element); |
| 117 | continue; |
| 118 | } |
| 119 | const std::string& prop = con->PropertyName(); |
| 120 | if (layeredTextures.find(prop) != layeredTextures.end()) { |
| 121 | DOMWarning("duplicate layered texture link: " + prop,&element); |
| 122 | } |
nothing calls this directly
no test coverage detected