@@ -179,17 +179,17 @@ namespace {
179179 }
180180}
181181
182- void T3DM::parseMaterial (const fs::path &gltfBasePath, int i, int j, Model &model, cgltf_primitive *prim) {
183- model.material .uuid = j * 1000 + i;
182+ T3DM::Material T3DM::parseMaterial (const fs::path &gltfBasePath, cgltf_primitive *prim) {
183+
184+ Material material{};
184185 if (prim->material ->name ) {
185- model.material .uuid = stringHash (prim->material ->name );
186- model.material .name = prim->material ->name ;
186+ material.name = prim->material ->name ;
187187 }
188188 // printf(" Material: %s\n", prim->material->name);
189189
190- if (config.ignoreMaterials ) {
190+ if (config.ignoreMaterials || material. name . empty () ) {
191191 printf (" Ignoring material\n " );
192- return ;
192+ return material ;
193193 }
194194
195195 if (prim->material ->extras .data == nullptr ) {
@@ -219,23 +219,23 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
219219 auto cc2 = readCCFromJson (f3dData[" combiner2" ]);
220220 bool is2Cycle = true ;
221221
222- model. material .drawFlags = DrawFlags::DEPTH;
223- model. material .blendColor [3 ] = 128 ; // default in case cutout is used
222+ material.drawFlags = DrawFlags::DEPTH;
223+ material.blendColor [3 ] = 128 ; // default in case cutout is used
224224
225- model. material .setPrimColor = false ;
225+ material.setPrimColor = false ;
226226 if (f3dData.contains (" set_prim" )) {
227- model. material .setPrimColor = f3dData[" set_prim" ].get <uint32_t >() != 0 ;
228- readColor (f3dData[" prim_color" ], model. material .primColor );
227+ material.setPrimColor = f3dData[" set_prim" ].get <uint32_t >() != 0 ;
228+ readColor (f3dData[" prim_color" ], material.primColor );
229229 }
230230
231231 if (f3dData.contains (" set_env" )) {
232- model. material .setEnvColor = f3dData[" set_env" ].get <uint32_t >() != 0 ;
233- readColor (f3dData[" env_color" ], model. material .envColor );
232+ material.setEnvColor = f3dData[" set_env" ].get <uint32_t >() != 0 ;
233+ readColor (f3dData[" env_color" ], material.envColor );
234234 }
235235
236236 if (f3dData.contains (" set_blend" )) {
237- model. material .setBlendColor = f3dData[" set_blend" ].get <uint32_t >() != 0 ;
238- readColor (f3dData[" blend_color" ], model. material .blendColor );
237+ material.setBlendColor = f3dData[" set_blend" ].get <uint32_t >() != 0 ;
238+ readColor (f3dData[" blend_color" ], material.blendColor );
239239 }
240240
241241 if (f3dData.contains (" rdp_settings" ))
@@ -244,13 +244,13 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
244244 is2Cycle = rdpSettings[" g_mdsft_cycletype" ].get <uint32_t >() != 0 ;
245245
246246 if (rdpSettings[" g_cull_back" ].get <uint32_t >() != 0 ) {
247- model. material .drawFlags |= DrawFlags::CULL_BACK;
247+ material.drawFlags |= DrawFlags::CULL_BACK;
248248 }
249249 if (rdpSettings[" g_cull_front" ].get <uint32_t >() != 0 ) {
250- model. material .drawFlags |= DrawFlags::CULL_FRONT;
250+ material.drawFlags |= DrawFlags::CULL_FRONT;
251251 }
252252
253- model. material .fogMode = rdpSettings[" g_fog" ].get <uint32_t >() + 1 ;
253+ material.fogMode = rdpSettings[" g_fog" ].get <uint32_t >() + 1 ;
254254
255255 uint32_t texFilter = rdpSettings[" g_mdsft_text_filt" ].get <uint32_t >() & 0b11 ;
256256 uint64_t textFilterMap[3 ] = {
@@ -260,10 +260,10 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
260260 };
261261 otherModeValue |= textFilterMap[texFilter];
262262
263- model. material .uvFilterAdjust = texFilter != 0 ;
263+ material.uvFilterAdjust = texFilter != 0 ;
264264
265265 uint32_t texGen = rdpSettings[" g_tex_gen" ].get <uint32_t >();
266- model. material .vertexFxFunc = (texGen != 0 ) ? UvGenFunc::SPHERE : UvGenFunc::NONE;
266+ material.vertexFxFunc = (texGen != 0 ) ? UvGenFunc::SPHERE : UvGenFunc::NONE;
267267
268268 /* uint32_t alphaComp = rdpSettings["g_mdsft_alpha_compare"].get<uint32_t>();
269269 if(alphaComp == 1) {
@@ -288,7 +288,7 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
288288 otherModeValue |= RDP::SOM::BLALPHA_CVG_X_CC | RDP::SOM::BLALPHA_CVG;
289289 }*/
290290
291- model. material .blendMode = is2Cycle ? blenderMode2 : blenderMode1;
291+ material.blendMode = is2Cycle ? blenderMode2 : blenderMode1;
292292
293293 } else {
294294 // if no render mode is set, we need to check the draw layer
@@ -300,46 +300,46 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
300300 if (layerOOT > layerSM64) {
301301 switch (layerOOT) {
302302 default : // has only 3 distinct layers:
303- case 0 : model. material .blendMode = RDP::BLEND::NONE; break ; // Opaque
304- case 1 : model. material .blendMode = RDP::BLEND::MULTIPLY; break ; // Transparent
303+ case 0 : material.blendMode = RDP::BLEND::NONE; break ; // Opaque
304+ case 1 : material.blendMode = RDP::BLEND::MULTIPLY; break ; // Transparent
305305 case 2 :
306- model. material .blendMode = RDP::BLEND::NONE;
306+ material.blendMode = RDP::BLEND::NONE;
307307 otherModeValue |= RDP::SOM::ALPHA_COMPARE;
308308 break ; // Overlay
309309 }
310310 } else {
311311 // has multiple layers with variants (e.g. intersecting) ignore the finer details here:
312312 if (layerSM64 <= 1 ) {
313- model. material .blendMode = RDP::BLEND::NONE;
313+ material.blendMode = RDP::BLEND::NONE;
314314 } else if (layerSM64 <= 4 ) {
315- model. material .blendMode = RDP::BLEND::NONE;
315+ material.blendMode = RDP::BLEND::NONE;
316316 otherModeValue |= RDP::SOM::ALPHA_COMPARE;
317317 } else {
318- model. material .blendMode = RDP::BLEND::MULTIPLY;
318+ material.blendMode = RDP::BLEND::MULTIPLY;
319319 }
320320 }
321321 }
322322 }
323323
324- if (model. material .fogMode == FogMode::ACTIVE || isUsingShade (cc1) || (is2Cycle && isUsingShade (cc2))) {
325- model. material .drawFlags |= DrawFlags::SHADED;
324+ if (material.fogMode == FogMode::ACTIVE || isUsingShade (cc1) || (is2Cycle && isUsingShade (cc2))) {
325+ material.drawFlags |= DrawFlags::SHADED;
326326 }
327327
328328 if (isCCUsingTexture (cc1) || (is2Cycle && isCCUsingTexture (cc2))) {
329- model. material .drawFlags |= DrawFlags::TEXTURED;
329+ material.drawFlags |= DrawFlags::TEXTURED;
330330
331- if (f3dData.contains (" tex0" ))readMaterialFromJson (model. material .texA , f3dData[" tex0" ], gltfBasePath);
332- if (f3dData.contains (" tex1" ))readMaterialFromJson (model. material .texB , f3dData[" tex1" ], gltfBasePath);
331+ if (f3dData.contains (" tex0" ))readMaterialFromJson (material.texA , f3dData[" tex0" ], gltfBasePath);
332+ if (f3dData.contains (" tex1" ))readMaterialFromJson (material.texB , f3dData[" tex1" ], gltfBasePath);
333333 }
334334
335335 if (is2Cycle) {
336- model. material .colorCombiner = RDPQ_COMBINER_2PASS |
336+ material.colorCombiner = RDPQ_COMBINER_2PASS |
337337 rdpq_2cyc_comb2a_rgb (cc1.a , cc1.b , cc1.c , cc1.d ) |
338338 rdpq_2cyc_comb2a_alpha (cc1.aAlpha , cc1.bAlpha , cc1.cAlpha , cc1.dAlpha ) |
339339 rdpq_2cyc_comb2b_rgb (cc2.a , cc2.b , cc2.c , cc2.d ) |
340340 rdpq_2cyc_comb2b_alpha (cc2.aAlpha , cc2.bAlpha , cc2.cAlpha , cc2.dAlpha );
341341 } else {
342- model. material .colorCombiner =
342+ material.colorCombiner =
343343 rdpq_1cyc_comb_rgb (cc1.a , cc1.b , cc1.c , cc1.d ) |
344344 rdpq_1cyc_comb_alpha (cc1.aAlpha , cc1.bAlpha , cc1.cAlpha , cc1.dAlpha );
345345 }
@@ -348,6 +348,7 @@ void T3DM::parseMaterial(const fs::path &gltfBasePath, int i, int j, Model &mode
348348 printf (" No Fast64 Material data found!\n " );
349349 }
350350
351- model.material .otherModeValue = otherModeValue;
352- model.material .otherModeMask = otherModeMask;
351+ material.otherModeValue = otherModeValue;
352+ material.otherModeMask = otherModeMask;
353+ return material;
353354}
0 commit comments