From 14c53c6149d2f7bd2c230817e363d0381db1dc9d Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 21 Nov 2026 21:50:39 +0300 Subject: [PATCH] fix VCM cull-face behaviour for 'rect' --- src/coders/vcm.cpp | 49 +++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index c4323f4ba..698645599 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -193,45 +193,36 @@ static void perform_rect(const xmlelement& root, ModelBuilder& builder) { std::string texture = root.attr("texture", "$0").getText(); glm::vec3 normal; + glm::vec3 backNormal; if (root.has("normal")) { normal = root.attr("normal").asVec3(); + backNormal = normal; } else { normal = glm::cross(glm::normalize(right), glm::normalize(up)); + backNormal = -normal; } + glm::vec3 center = from + right * 0.5f + up * 0.5f; + UVRegion backRegion = region; + std::swap(backRegion.u1, backRegion.u2); + auto cullFace = root.attr("cull-face", "back").getText(); - if (cullFace == "front") { - normal *= -1.0f; - } else if (cullFace == "off") { + if (cullFace != "front") { builder.addRect( - texture, - shading, - from + right * 0.5f + up * 0.5f, - right * 0.5f, - up * 0.5f, - normal, - region + texture, shading, center, right * 0.5f, up * 0.5f, normal, region + ); + } + if (cullFace == "front" || cullFace == "off") { + builder.addRect( + texture, + shading, + center, + right * -0.5f, + up * 0.5f, + backNormal, + backRegion ); - builder.addRect( - texture, - shading, - from + right * 0.5f + up * 0.5f, - right * -0.5f, - up * -0.5f, - -normal, - region - ); - return; } - builder.addRect( - texture, - shading, - from + right * 0.5f + up * 0.5f, - right * 0.5f, - up * 0.5f, - normal, - region - ); } static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {