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,45 +193,36 @@ 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, if (cullFace == "front" || cullFace == "off") {
up * 0.5f, builder.addRect(
normal, texture,
region 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) { static void perform_triangle(const xmlelement& root, ModelBuilder& builder) {