Fix #123918: STL exporter does not reverse faces for mirrored objects

Old python STL exporter, as well as other exporters like OBJ,
reverse the face order when object being exported has odd number
of negative scales in the matrix. The C++ STL exporter was lacking
that, resulting in the exported object looking "inside out".

The extra branch inside triangle export inner loop has no measurable
performance impact, probably because it is entirely predictable.

Pull Request: https://projects.blender.org/blender/blender/pulls/124219
This commit is contained in:
Aras Pranckevicius 2024-07-05 11:08:22 +02:00 committed by Aras Pranckevicius
parent 23021fab74
commit b238df312d
2 changed files with 6 additions and 2 deletions

@ -122,13 +122,17 @@ void export_frame(Depsgraph *depsgraph,
mul_v3_m3v3(xform[3], axes_transform, obj_eval->object_to_world().location());
xform[3][3] = obj_eval->object_to_world()[3][3];
const bool mirrored = is_negative_m4(xform);
/* Write triangles. */
const Span<float3> positions = mesh->vert_positions();
const Span<int> corner_verts = mesh->corner_verts();
for (const int3 &tri : mesh->corner_tris()) {
PackedTriangle data{};
for (int i = 0; i < 3; i++) {
float3 pos = positions[corner_verts[tri[i]]];
/* Reverse face order for mirrored objects. */
int idx = mirrored ? 2 - i : i;
float3 pos = positions[corner_verts[tri[idx]]];
mul_m4_v3(xform, pos);
pos *= global_scale;
data.vertices[i] = pos;

@ -1 +1 @@
Subproject commit 218087daf891d3eefd7ac2c66eb05f117f4510bd
Subproject commit 181a40d6c972c591996c49588d18d6154b9fbc6a