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

Function ProcessMaterials

code/AssetLib/IFC/IFCMaterial.cpp:130–194  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

128
129// ------------------------------------------------------------------------------------------------
130unsigned int ProcessMaterials(uint64_t id, unsigned int prevMatId, ConversionData& conv, bool forceDefaultMat) {
131 STEP::DB::RefMapRange range = conv.db.GetRefs().equal_range(id);
132 for(;range.first != range.second; ++range.first) {
133 if(const IFC::Schema_2x3::IfcStyledItem* const styled = conv.db.GetObject((*range.first).second)->ToPtr<IFC::Schema_2x3::IfcStyledItem>()) {
134 for(const IFC::Schema_2x3::IfcPresentationStyleAssignment& as : styled->Styles) {
135 for (const std::shared_ptr<const IFC::Schema_2x3::IfcPresentationStyleSelect> &sel : as.Styles) {
136
137 if( const IFC::Schema_2x3::IfcSurfaceStyle* const surf = sel->ResolveSelectPtr<IFC::Schema_2x3::IfcSurfaceStyle>(conv.db) ) {
138 // try to satisfy from cache
139 ConversionData::MaterialCache::iterator mit = conv.cached_materials.find(surf);
140 if( mit != conv.cached_materials.end() )
141 return mit->second;
142
143 // not found, create new material
144 const std::string side = static_cast<std::string>(surf->Side);
145 if( side != "BOTH" ) {
146 IFCImporter::LogWarn("ignoring surface side marker on IFC::IfcSurfaceStyle: ", side);
147 }
148
149 std::unique_ptr<aiMaterial> mat(new aiMaterial());
150
151 FillMaterial(mat.get(), surf, conv);
152
153 conv.materials.push_back(mat.release());
154 unsigned int matindex = static_cast<unsigned int>(conv.materials.size() - 1);
155 conv.cached_materials[surf] = matindex;
156 return matindex;
157 }
158 }
159 }
160 }
161 }
162
163 // no local material defined. If there's global one, use that instead
164 if ( prevMatId != std::numeric_limits<uint32_t>::max() ) {
165 return prevMatId;
166 }
167
168 // we're still here - create an default material if required, or simply fail otherwise
169 if ( !forceDefaultMat ) {
170 return std::numeric_limits<uint32_t>::max();
171 }
172
173 aiString name;
174 name.Set("<IFCDefault>");
175
176 // look if there's already a default material with this base color
177 for( size_t a = 0; a < conv.materials.size(); ++a ) {
178 aiString mname;
179 conv.materials[a]->Get(AI_MATKEY_NAME, mname);
180 if ( name == mname ) {
181 return ( unsigned int )a;
182 }
183 }
184
185 // we're here, yet - no default material with suitable color available. Generate one
186 std::unique_ptr<aiMaterial> mat(new aiMaterial());
187 mat->AddProperty(&name,AI_MATKEY_NAME);

Callers 3

ProcessMappedItemFunction · 0.85

Calls 12

FillMaterialFunction · 0.85
aiColor4DClass · 0.85
maxFunction · 0.50
GetObjectMethod · 0.45
endMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45
releaseMethod · 0.45
sizeMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45
AddPropertyMethod · 0.45

Tested by

no test coverage detected