From 7e41439e1ac4116e6d32b046923ab13e3cd20706 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 14 Oct 2026 00:38:38 +0300 Subject: [PATCH] fix: model-primitives texture regions are broken --- src/graphics/render/ModelsGenerator.cpp | 43 +++++++++++++++++++------ 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/graphics/render/ModelsGenerator.cpp b/src/graphics/render/ModelsGenerator.cpp index da82680bb..531cc1c84 100644 --- a/src/graphics/render/ModelsGenerator.cpp +++ b/src/graphics/render/ModelsGenerator.cpp @@ -8,6 +8,22 @@ #include "debug/Logger.hpp" #include "core_defs.hpp" +inline constexpr uint FACE_WEST = FACE_MX; +inline constexpr uint FACE_EAST = FACE_PX; +inline constexpr uint FACE_BOTTOM = FACE_MY; +inline constexpr uint FACE_TOP = FACE_PY; +inline constexpr uint FACE_SOUTH = FACE_MZ; +inline constexpr uint FACE_NORTH = FACE_PZ; + +inline constexpr std::array LEGACY_CUSTOM_MODEL_TEXTURE_ORDER = { + FACE_WEST, + FACE_EAST, + FACE_BOTTOM, + FACE_TOP, + FACE_SOUTH, + FACE_NORTH, +}; + static debug::Logger logger("models-generator"); static void configure_textures( @@ -49,6 +65,21 @@ static inline UVRegion get_region_for( return texreg.region; } +static inline void map_legacy_box_textures( + const std::vector& modelTextures, + size_t offset, + UVRegion (&boxtexfaces)[6], + const Assets& assets +) { + for (size_t i = 0; i < 6; ++i) { + const auto legacyFace = LEGACY_CUSTOM_MODEL_TEXTURE_ORDER[i]; + boxtexfaces[legacyFace] = get_region_for(modelTextures[offset + i], assets); + } + boxtexfaces[FACE_TOP].scale(glm::vec2(-1, 1)); + boxtexfaces[FACE_EAST].scale(glm::vec2(-1, 1)); + boxtexfaces[FACE_NORTH].scale(glm::vec2(-1, 1)); +} + void ModelsGenerator::prepareModel( Assets& assets, const Block& def, Variant& variant, uint8_t variantId ) { @@ -120,16 +151,8 @@ model::Model ModelsGenerator::fromCustom( for (size_t i = 0; i < modelBoxes.size(); i++) { auto& mesh = model.addMesh("blocks:"); mesh.shading = lighting; - UVRegion boxtexfaces[6] = { - get_region_for(modelTextures[i * 6 + 5], assets), - get_region_for(modelTextures[i * 6 + 4], assets), - get_region_for(modelTextures[i * 6 + 3], assets), - get_region_for(modelTextures[i * 6 + 2], assets), - get_region_for(modelTextures[i * 6 + 1], assets), - get_region_for(modelTextures[i * 6 + 0], assets) - }; - boxtexfaces[2].scale(glm::vec2(-1)); - boxtexfaces[5].scale(glm::vec2(-1, 1)); + UVRegion boxtexfaces[6] = {}; + map_legacy_box_textures(modelTextures, i * 6, boxtexfaces, assets); bool enabled[6] {1,1,1,1,1,1}; mesh.addBox(