2021-11-18 14:58:01 +00:00
|
|
|
#include "material.h"
|
|
|
|
#include "image_forever.h"
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
void initializeMaterialTexturesFromSnapshot(const dust3d::Snapshot& snapshot,
|
|
|
|
const dust3d::Uuid& materialId,
|
|
|
|
MaterialTextures& materialTextures,
|
|
|
|
float& tileScale)
|
2021-11-18 14:58:01 +00:00
|
|
|
{
|
|
|
|
auto materialIdString = materialId.toString();
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& materialItem : snapshot.materials) {
|
2021-11-18 14:58:01 +00:00
|
|
|
if (materialIdString != dust3d::String::valueOrEmpty(materialItem.first, "id"))
|
|
|
|
continue;
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& layer : materialItem.second) {
|
2021-11-18 14:58:01 +00:00
|
|
|
//FIXME: Only support one layer currently
|
|
|
|
auto findTileScale = layer.first.find("tileScale");
|
|
|
|
if (findTileScale != layer.first.end())
|
|
|
|
tileScale = dust3d::String::toFloat(findTileScale->second);
|
2022-10-18 09:35:04 +00:00
|
|
|
for (const auto& mapItem : layer.second) {
|
2021-11-18 14:58:01 +00:00
|
|
|
auto textureType = dust3d::TextureTypeFromString(dust3d::String::valueOrEmpty(mapItem, "for").c_str());
|
|
|
|
if (textureType != dust3d::TextureType::None) {
|
|
|
|
int index = (int)textureType - 1;
|
|
|
|
if (index >= 0 && index < (int)dust3d::TextureType::Count - 1) {
|
|
|
|
if ("imageId" == dust3d::String::valueOrEmpty(mapItem, "linkDataType")) {
|
|
|
|
auto imageIdString = dust3d::String::valueOrEmpty(mapItem, "linkData");
|
|
|
|
materialTextures.textureImages[index] = ImageForever::get(dust3d::Uuid(imageIdString));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|