From 895855434f60f84a8e7dfc05e3ffd9f5b542d1c6 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 2 May 2025 18:42:12 +0300 Subject: [PATCH] fix custom models instancing for different blocks --- src/frontend/ContentGfxCache.cpp | 20 +++++++++----------- src/graphics/render/ModelsGenerator.cpp | 7 +++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/frontend/ContentGfxCache.cpp b/src/frontend/ContentGfxCache.cpp index 31199a90..412a3f63 100644 --- a/src/frontend/ContentGfxCache.cpp +++ b/src/frontend/ContentGfxCache.cpp @@ -37,17 +37,15 @@ void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) { } if (def.model.type == BlockModelType::CUSTOM) { auto model = assets.require(def.model.name); - // temporary dirty fix tbh - if (def.model.name.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); - } + + 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); } } } diff --git a/src/graphics/render/ModelsGenerator.cpp b/src/graphics/render/ModelsGenerator.cpp index 44c77418..ccaffa0d 100644 --- a/src/graphics/render/ModelsGenerator.cpp +++ b/src/graphics/render/ModelsGenerator.cpp @@ -62,14 +62,17 @@ void ModelsGenerator::prepare(Content& content, Assets& assets) { ); def->model.name = def->name + ".model"; } else { - auto model = assets.get(def->model.name); - if (model) { + auto srcModel = assets.get(def->model.name); + if (srcModel) { + auto model = std::make_unique(*srcModel); for (auto& mesh : model->meshes) { if (mesh.texture.length() && mesh.texture[0] == '$') { int index = std::stoll(mesh.texture.substr(1)); mesh.texture = "blocks:" + def->textureFaces[index]; } } + def->model.name = name + ".model"; + assets.store(std::move(model), def->model.name); } } }