add 'cull-face' parameter to tri and rect primitives

This commit is contained in:
MihailRis 2026-09-25 20:37:24 +03:00
parent 77b9de3464
commit d0cc59ad3a

View file

@ -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]);
}