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

Function FillMaterial

code/AssetLib/IFC/IFCMaterial.cpp:70–127  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

68
69// ------------------------------------------------------------------------------------------------
70static void FillMaterial(aiMaterial* mat,const IFC::Schema_2x3::IfcSurfaceStyle* surf,ConversionData& conv) {
71 aiString name;
72 name.Set((surf->Name? surf->Name.Get() : "IfcSurfaceStyle_Unnamed"));
73 mat->AddProperty(&name,AI_MATKEY_NAME);
74
75 // now see which kinds of surface information are present
76 for (const std::shared_ptr<const IFC::Schema_2x3::IfcSurfaceStyleElementSelect> &sel2 : surf->Styles) {
77 if (const IFC::Schema_2x3::IfcSurfaceStyleShading* shade = sel2->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyleShading>(conv.db)) {
78 aiColor4D col_base,col;
79
80 ConvertColor(col_base, shade->SurfaceColour);
81 mat->AddProperty(&col_base,1, AI_MATKEY_COLOR_DIFFUSE);
82
83 if (const IFC::Schema_2x3::IfcSurfaceStyleRendering* ren = shade->ToPtr<IFC::Schema_2x3::IfcSurfaceStyleRendering>()) {
84
85 if (ren->Transparency) {
86 const float t = 1.f-static_cast<float>(ren->Transparency.Get());
87 mat->AddProperty(&t,1, AI_MATKEY_OPACITY);
88 }
89
90 if (ren->DiffuseColour) {
91 ConvertColor(col, *ren->DiffuseColour.Get(),conv,&col_base);
92 mat->AddProperty(&col,1, AI_MATKEY_COLOR_DIFFUSE);
93 }
94
95 if (ren->SpecularColour) {
96 ConvertColor(col, *ren->SpecularColour.Get(),conv,&col_base);
97 mat->AddProperty(&col,1, AI_MATKEY_COLOR_SPECULAR);
98 }
99
100 if (ren->TransmissionColour) {
101 ConvertColor(col, *ren->TransmissionColour.Get(),conv,&col_base);
102 mat->AddProperty(&col,1, AI_MATKEY_COLOR_TRANSPARENT);
103 }
104
105 if (ren->ReflectionColour) {
106 ConvertColor(col, *ren->ReflectionColour.Get(),conv,&col_base);
107 mat->AddProperty(&col,1, AI_MATKEY_COLOR_REFLECTIVE);
108 }
109
110 const int shading = (ren->SpecularHighlight && ren->SpecularColour)?ConvertShadingMode(ren->ReflectanceMethod):static_cast<int>(aiShadingMode_Gouraud);
111 mat->AddProperty(&shading,1, AI_MATKEY_SHADING_MODEL);
112
113 if (ren->SpecularHighlight) {
114 if(const ::Assimp::STEP::EXPRESS::REAL* rt = ren->SpecularHighlight.Get()->ToPtr<::Assimp::STEP::EXPRESS::REAL>()) {
115 // at this point we don't distinguish between the two distinct ways of
116 // specifying highlight intensities. leave this to the user.
117 const float e = static_cast<float>(*rt);
118 mat->AddProperty(&e,1,AI_MATKEY_SHININESS);
119 }
120 else {
121 IFCImporter::LogWarn("unexpected type error, SpecularHighlight should be a REAL");
122 }
123 }
124 }
125 }
126 }
127}

Callers 1

ProcessMaterialsFunction · 0.85

Calls 5

ConvertColorFunction · 0.85
ConvertShadingModeFunction · 0.85
SetMethod · 0.45
GetMethod · 0.45
AddPropertyMethod · 0.45

Tested by

no test coverage detected