MCPcopy Create free account
hub / github.com/assimp/assimp / Material

Method Material

code/AssetLib/FBX/FBXMaterial.cpp:65–135  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

63
64// ------------------------------------------------------------------------------------------------
65Material::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 }

Callers

nothing calls this directly

Calls 9

ParseTokenAsIntFunction · 0.85
ParseTokenAsStringFunction · 0.85
DOMWarningFunction · 0.85
GetPropertyTableFunction · 0.85
IDClass · 0.85
SourceObjectMethod · 0.80
fillTextureMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected