Skip to content

Commit

Permalink
[geometry] some bug fixes and improvements to simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Jan 12, 2025
1 parent b3a5381 commit 63a0fa0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions runtime/Core/GeometryProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@ namespace spartan::geometry_processing

// loop until the current triangle count is less than or equal to the target triangle count
std::vector<uint32_t> indices_simplified(index_count);
uint32_t iteration_count = 0;
while (current_triangle_count > triangle_target)
{
float threshold = 1.0f - reduction;
size_t target_index_count = static_cast<size_t>(index_count * threshold);

index_count = meshopt_simplify(

if (target_index_count < 3)
break;

size_t index_count_new = meshopt_simplify(
indices_simplified.data(),
indices.data(),
index_count,
Expand All @@ -361,16 +363,16 @@ namespace spartan::geometry_processing
target_index_count,
error
);


// break if meshopt_simplify can't simplify further
if (index_count_new == index_count)
break;

index_count = index_count_new;
indices.assign(indices_simplified.begin(), indices_simplified.begin() + index_count);
current_triangle_count = index_count / 3;
reduction = fmodf(reduction + 0.1f, 1.0f);
error = fmodf(error + 0.1f, 1.0f);

// break if meshopt_simplify gives up
iteration_count++;
if (iteration_count > 10)
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/World/Components/PhysicsBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ namespace spartan
// create a btBvhTriangleMeshShape using the index-vertex array
btBvhTriangleMeshShape* shape_triangle_mesh = new btBvhTriangleMeshShape(
index_vertex_array,
true // BVH for optimized collisions
true // bvh for optimized collisions
);

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

0 comments on commit 63a0fa0

Please sign in to comment.