Skip to content

Commit ca1feae

Browse files
committed
[geometry] some bug fixes and improvements to simplification
1 parent 28ae266 commit ca1feae

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

runtime/Core/GeometryProcessing.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,15 @@ namespace spartan::geometry_processing
345345

346346
// loop until the current triangle count is less than or equal to the target triangle count
347347
std::vector<uint32_t> indices_simplified(index_count);
348-
uint32_t iteration_count = 0;
349348
while (current_triangle_count > triangle_target)
350349
{
351350
float threshold = 1.0f - reduction;
352351
size_t target_index_count = static_cast<size_t>(index_count * threshold);
353-
354-
index_count = meshopt_simplify(
352+
353+
if (target_index_count < 3)
354+
break;
355+
356+
size_t index_count_new = meshopt_simplify(
355357
indices_simplified.data(),
356358
indices.data(),
357359
index_count,
@@ -361,16 +363,16 @@ namespace spartan::geometry_processing
361363
target_index_count,
362364
error
363365
);
364-
366+
367+
// break if meshopt_simplify can't simplify further
368+
if (index_count_new == index_count)
369+
break;
370+
371+
index_count = index_count_new;
365372
indices.assign(indices_simplified.begin(), indices_simplified.begin() + index_count);
366373
current_triangle_count = index_count / 3;
367374
reduction = fmodf(reduction + 0.1f, 1.0f);
368375
error = fmodf(error + 0.1f, 1.0f);
369-
370-
// break if meshopt_simplify gives up
371-
iteration_count++;
372-
if (iteration_count > 10)
373-
break;
374376
}
375377
}
376378

runtime/World/Components/PhysicsBody.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ namespace spartan
946946
// create a btBvhTriangleMeshShape using the index-vertex array
947947
btBvhTriangleMeshShape* shape_triangle_mesh = new btBvhTriangleMeshShape(
948948
index_vertex_array,
949-
true // BVH for optimized collisions
949+
true // bvh for optimized collisions
950950
);
951951

952952
// we only need to set the scale as the rotation and position is set set in btMotionState

0 commit comments

Comments
 (0)