fix custom block models

This commit is contained in:
MihailRis
2024-11-07 07:27:29 +03:00
parent bbadaf7a19
commit 86b5f5d82b
2 changed files with 19 additions and 3 deletions
+18 -2
View File
@@ -11,6 +11,8 @@
#include "maths/UVRegion.hpp"
#include "voxels/Block.hpp"
#include <iostream>
ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
: content(content) {
auto indices = content->getIndices();
@@ -29,8 +31,22 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
}
}
if (def->model == BlockModel::custom) {
models[def->rt.id] =
assets->require<model::Model>(def->modelName);
auto model = assets->require<model::Model>(def->modelName);
// temporary dirty fix tbh
if (def->modelName.find(':') == std::string::npos) {
for (auto& mesh : model.meshes) {
size_t pos = mesh.texture.find(':');
if (pos == std::string::npos) {
continue;
}
if (auto region = atlas->getIf(mesh.texture.substr(pos+1))) {
for (auto& vertex : mesh.vertices) {
vertex.uv = region->apply(vertex.uv);
}
}
}
}
models[def->rt.id] = std::move(model);
}
}
}