mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add 'cull-face' parameter to tri and rect primitives
This commit is contained in:
parent
77b9de3464
commit
d0cc59ad3a
1 changed files with 36 additions and 0 deletions
|
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue