From d0cc59ad3ad2d7348ed82e4cd560fc9684150a1a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 25 Sep 2026 20:37:24 +0300 Subject: [PATCH] add 'cull-face' parameter to `tri` and `rect` primitives --- src/coders/vcm.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/coders/vcm.cpp b/src/coders/vcm.cpp index 42a503477..a1ca758de 100644 --- a/src/coders/vcm.cpp +++ b/src/coders/vcm.cpp @@ -198,6 +198,31 @@ static void perform_rect(const xmlelement& root, ModelBuilder& builder) { } else { normal = glm::cross(glm::normalize(right), glm::normalize(up)); } + + auto cullFace = root.attr("cull-face", "back").getText(); + if (cullFace == "front") { + normal *= -1.0f; + } else if (cullFace == "off") { + builder.addRect( + texture, + shading, + from + right * 0.5f + up * 0.5f, + right * 0.5f, + up * 0.5f, + normal, + region + ); + builder.addRect( + texture, + shading, + from + right * 0.5f + up * 0.5f, + right * -0.5f, + up * -0.5f, + -normal, + region + ); + return; + } builder.addRect( texture, shading, @@ -246,6 +271,17 @@ static void perform_triangle(const xmlelement& root, ModelBuilder& builder) { } std::string texture = root.attr("texture", "$0").getText(); + + auto cullFace = root.attr("cull-face", "back").getText(); + if (cullFace == "front") { + std::swap(pointB, pointC); + std::swap(uvs[1], uvs[2]); + normal *= -1.0f; + } else if (cullFace == "off") { + builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]); + builder.addTriangle(texture, shading, pointA, pointC, pointB, -normal, uvs[0], uvs[2], uvs[1]); + return; + } builder.addTriangle(texture, shading, pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]); }