fix VCM cull-face behaviour for 'rect'

This commit is contained in:
MihailRis 2026-11-21 21:50:39 +03:00
parent 1d1174e344
commit 14c53c6149

View file

@ -193,46 +193,37 @@ static void perform_rect(const xmlelement& root, ModelBuilder& builder) {
std::string texture = root.attr("texture", "$0").getText(); std::string texture = root.attr("texture", "$0").getText();
glm::vec3 normal; glm::vec3 normal;
glm::vec3 backNormal;
if (root.has("normal")) { if (root.has("normal")) {
normal = root.attr("normal").asVec3(); normal = root.attr("normal").asVec3();
backNormal = normal;
} else { } else {
normal = glm::cross(glm::normalize(right), glm::normalize(up)); 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(); auto cullFace = root.attr("cull-face", "back").getText();
if (cullFace == "front") { if (cullFace != "front") {
normal *= -1.0f;
} else if (cullFace == "off") {
builder.addRect( builder.addRect(
texture, texture, shading, center, right * 0.5f, up * 0.5f, normal, region
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;
} }
if (cullFace == "front" || cullFace == "off") {
builder.addRect( builder.addRect(
texture, texture,
shading, shading,
from + right * 0.5f + up * 0.5f, center,
right * 0.5f, right * -0.5f,
up * 0.5f, up * 0.5f,
normal, backNormal,
region backRegion
); );
} }
}
static void perform_triangle(const xmlelement& root, ModelBuilder& builder) { static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {
auto pointA = root.attr("a").asVec3(); auto pointA = root.attr("a").asVec3();