@@ -50,9 +50,8 @@ class Material {
50
50
* vector has vector<string>, because embedded textures are saved with pairs, first element is the index, second element is the model file itself.
51
51
*/
52
52
53
- // FIXME
54
- // std::vector<std::vector<std::string>>* textureNames = nullptr;
55
- std::vector<std::string> ambientTextureNames, diffuseTextureNames, specularTextureNames, normalTextureNames, opacityTextureNames;
53
+
54
+ std::shared_ptr<std::vector<std::vector<std::string>>> textureNames = nullptr ;
56
55
57
56
friend struct std ::hash<Material>;
58
57
std::shared_ptr<TextureAsset> ambientTexture = nullptr ;
@@ -315,81 +314,75 @@ class Material {
315
314
template <class Archive >
316
315
void save (Archive & archive) const {
317
316
318
- std::vector<std::string> ambientTextureNames, diffuseTextureNames, specularTextureNames, normalTextureNames, opacityTextureNames ;
317
+ std::shared_ptr<std:: vector<std::vector<std:: string>>> textureNames = std::make_shared<std::vector<std::vector<std::string>>>( 5 ) ;
319
318
320
319
if (ambientTexture != nullptr ) {
321
- ambientTextureNames = ambientTexture->getName ();
320
+ (*textureNames)[ 0 ] = ambientTexture->getName ();
322
321
};
323
322
if (diffuseTexture != nullptr ) {
324
- diffuseTextureNames = diffuseTexture->getName ();
323
+ (*textureNames)[ 1 ] = diffuseTexture->getName ();
325
324
};
326
325
if (specularTexture != nullptr ) {
327
- specularTextureNames = specularTexture->getName ();
326
+ (*textureNames)[ 2 ] = specularTexture->getName ();
328
327
};
329
328
if (normalTexture != nullptr ) {
330
- normalTextureNames = normalTexture->getName ();
329
+ (*textureNames)[ 3 ] = normalTexture->getName ();
331
330
};
332
331
if (opacityTexture != nullptr ) {
333
- opacityTextureNames = opacityTexture->getName ();
332
+ (*textureNames)[ 4 ] = opacityTexture->getName ();
334
333
};
335
334
336
335
archive (name, specularExponent, maps, ambientColor, diffuseColor, specularColor, isAmbientMap, isDiffuseMap, isSpecularMap, isNormalMap, isOpacityMap, refractionIndex,
337
- ambientTextureNames, diffuseTextureNames, specularTextureNames, normalTextureNames, opacityTextureNames );
336
+ textureNames );
338
337
}
339
338
340
339
template <class Archive >
341
340
void load (Archive & archive) {
342
341
343
- archive (name, specularExponent, maps, ambientColor, diffuseColor, specularColor, isAmbientMap, isDiffuseMap, isSpecularMap, isNormalMap, isOpacityMap, refractionIndex
344
- ,ambientTextureNames, diffuseTextureNames, specularTextureNames, normalTextureNames, opacityTextureNames );
342
+ archive (name, specularExponent, maps, ambientColor, diffuseColor, specularColor, isAmbientMap, isDiffuseMap, isSpecularMap, isNormalMap, isOpacityMap, refractionIndex,
343
+ textureNames );
345
344
}
346
345
347
346
void afterLoad (AssetManager* assetManager) {
348
347
this ->assetManager = assetManager;
349
- if (!ambientTextureNames.empty ()) {
350
- if (ambientTextureNames.size () > 1 ) {
351
- this ->setAmbientTexture (ambientTextureNames[0 ], &ambientTextureNames[1 ]);
352
- } else {
353
- this ->setAmbientTexture (ambientTextureNames[0 ]);
348
+ if (textureNames != nullptr ) {
349
+ if (!(*textureNames)[0 ].empty ()) {
350
+ if ((*textureNames)[0 ].size () > 1 ) {
351
+ this ->setAmbientTexture ((*textureNames)[0 ][0 ], &(*textureNames)[0 ][1 ]);
352
+ } else {
353
+ this ->setAmbientTexture ((*textureNames)[0 ][0 ]);
354
+ }
354
355
}
355
- ambientTextureNames.clear ();
356
- }
357
-
358
- if (!diffuseTextureNames.empty ()) {
359
- if (diffuseTextureNames.size () > 1 ) {
360
- this ->setDiffuseTexture (diffuseTextureNames[0 ], &diffuseTextureNames[1 ]);
361
- } else {
362
- this ->setDiffuseTexture (diffuseTextureNames[0 ]);
356
+ if (!(*textureNames)[1 ].empty ()) {
357
+ if ((*textureNames)[1 ].size () > 1 ) {
358
+ this ->setDiffuseTexture ((*textureNames)[1 ][0 ], &(*textureNames)[1 ][1 ]);
359
+ } else {
360
+ this ->setDiffuseTexture ((*textureNames)[1 ][0 ]);
361
+ }
363
362
}
364
- diffuseTextureNames.clear ();
365
- }
366
-
367
- if (!specularTextureNames.empty ()) {
368
- if (specularTextureNames.size () > 1 ) {
369
- this ->setSpecularTexture (specularTextureNames[0 ], &specularTextureNames[1 ]);
370
- } else {
371
- this ->setSpecularTexture (specularTextureNames[0 ]);
363
+ if (!(*textureNames)[2 ].empty ()) {
364
+ if ((*textureNames)[2 ].size () > 1 ) {
365
+ this ->setSpecularTexture ((*textureNames)[2 ][0 ], &(*textureNames)[2 ][1 ]);
366
+ } else {
367
+ this ->setSpecularTexture ((*textureNames)[2 ][0 ]);
368
+ }
372
369
}
373
- specularTextureNames.clear ();
374
- }
375
-
376
- if (!normalTextureNames.empty ()) {
377
- if (normalTextureNames.size () > 1 ) {
378
- this ->setNormalTexture (normalTextureNames[0 ], &normalTextureNames[1 ]);
379
- } else {
380
- this ->setNormalTexture (normalTextureNames[0 ]);
370
+ if (!(*textureNames)[3 ].empty ()) {
371
+ if ((*textureNames)[3 ].size () > 1 ) {
372
+ this ->setNormalTexture ((*textureNames)[3 ][0 ], &(*textureNames)[3 ][1 ]);
373
+ } else {
374
+ this ->setNormalTexture ((*textureNames)[3 ][0 ]);
375
+ }
381
376
}
382
- normalTextureNames.clear ();
383
- }
384
-
385
- if (!opacityTextureNames.empty ()) {
386
- if (opacityTextureNames.size () > 1 ) {
387
- this ->setOpacityTexture (opacityTextureNames[0 ], &opacityTextureNames[1 ]);
388
- } else {
389
- this ->setOpacityTexture (opacityTextureNames[0 ]);
377
+ if (!(*textureNames)[4 ].empty ()) {
378
+ if ((*textureNames)[4 ].size () > 1 ) {
379
+ this ->setOpacityTexture ((*textureNames)[4 ][0 ], &(*textureNames)[4 ][1 ]);
380
+ } else {
381
+ this ->setOpacityTexture ((*textureNames)[4 ][0 ]);
382
+ }
390
383
}
391
- opacityTextureNames.clear ();
392
384
}
385
+ this ->textureNames = nullptr ;
393
386
}
394
387
#endif
395
388
};
0 commit comments