From 5339d9154e788ee32dd41e15e911768734e96adb Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Tue, 12 May 2026 01:26:50 -0700 Subject: [PATCH] Ensure faces for meshes are correctly oriented. This is in preparation for a future CL that will disable backface culling. PiperOrigin-RevId: 914136370 Change-Id: Ie8db1268faaa306c3f3356efc5e1305d791cf525 --- .../filament/compat/model_objects.cc | 12 ++++++------ src/experimental/filament/filament/builtins.cc | 16 ++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/experimental/filament/compat/model_objects.cc b/src/experimental/filament/compat/model_objects.cc index a619e73d..dfd7d644 100644 --- a/src/experimental/filament/compat/model_objects.cc +++ b/src/experimental/filament/compat/model_objects.cc @@ -254,17 +254,17 @@ static void FillHeightFieldBuffer(MeshBuilder& builder, const mjModel* model, // Build the front edge. for (int col = 0; col < ncol - 1; ++col) { const float3 a = get_pos(0, col); - const float3 b = get_pos(0, col + 1); - const float3 c = {b.x, b.y, -sz[3]}; - const float3 d = {a.x, a.y, -sz[3]}; + const float3 b = {a.x, a.y, -sz[3]}; + const float3 d = get_pos(0, col + 1); + const float3 c = {d.x, d.y, -sz[3]}; append_quad(a, b, c, d); } // Build the back edge. for (int col = 0; col < ncol - 1; ++col) { const float3 a = get_pos(nrow - 1, col + 1); - const float3 b = get_pos(nrow - 1, col); - const float3 c = {b.x, b.y, -sz[3]}; - const float3 d = {a.x, a.y, -sz[3]}; + const float3 b = {a.x, a.y, -sz[3]}; + const float3 d = get_pos(nrow - 1, col); + const float3 c = {d.x, d.y, -sz[3]}; append_quad(a, b, c, d); } // Build the base. We use the visualization quality as the size rather than diff --git a/src/experimental/filament/filament/builtins.cc b/src/experimental/filament/filament/builtins.cc index b18e28e5..98a14296 100644 --- a/src/experimental/filament/filament/builtins.cc +++ b/src/experimental/filament/filament/builtins.cc @@ -153,7 +153,7 @@ class PlaneBuilder : public BuiltinBuilder { const int i1 = base_idx + 1; const int i2 = base_idx + num_quads_per_axis + 2; const int i3 = base_idx + num_quads_per_axis + 1; - AppendQuadIndices(indices_, i0, i1, i2, i3); + AppendQuadIndices(indices_, i0, i3, i2, i1); } } @@ -268,7 +268,11 @@ class BoxBuilder : public BuiltinBuilder { const int i1 = base_idx + 1; const int i2 = base_idx + num_quads_per_axis_ + 2; const int i3 = base_idx + num_quads_per_axis_ + 1; - AppendQuadIndices(indices_, i0, i1, i2, i3); + if (i == 2 || i == 1 || i == 4) { + AppendQuadIndices(indices_, i0, i3, i2, i1); + } else { + AppendQuadIndices(indices_, i0, i1, i2, i3); + } } } } @@ -326,7 +330,7 @@ class TubeBuilder : public BuiltinBuilder { const int i1 = base_idx + 1; const int i2 = (base_idx + num_stacks + 2) % num_vertices; const int i3 = (base_idx + num_stacks + 1) % num_vertices; - AppendQuadIndices(indices_, i0, i1, i2, i3); + AppendQuadIndices(indices_, i0, i3, i2, i1); } } @@ -494,8 +498,8 @@ class SphereBuilder : public BuiltinBuilder { for (int lon = 0; lon < num_slices; ++lon) { const int next = lon < (num_slices - 1) ? lon + 1 : 0; indices_.push_back(kNorthPoleIndex); - indices_.push_back(row_start + next); indices_.push_back(row_start + lon); + indices_.push_back(row_start + next); } // Latitudinal triangle strips. @@ -519,8 +523,8 @@ class SphereBuilder : public BuiltinBuilder { for (int lon = 0; lon < num_slices; ++lon) { const int adjacent = lon < (num_slices - 1) ? lon + 1 : 0; indices_.push_back(kSouthPoleIndex); - indices_.push_back(row_start + lon); indices_.push_back(row_start + adjacent); + indices_.push_back(row_start + lon); } SetBounds({-1, -1, -1}, {1, 1, 1}); @@ -585,8 +589,8 @@ class DomeBuilder : public BuiltinBuilder { for (int lon = 0; lon < num_slices; ++lon) { const int next = lon < (num_slices - 1) ? lon + 1 : 0; indices_.push_back(kPoleIndex); - indices_.push_back(row_start + next); indices_.push_back(row_start + lon); + indices_.push_back(row_start + next); } // Latitudinal quad strips. The first "stack" was handled above, so we