From cd9a855ae6066ba1f0cad8d43ef13151a2941c72 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 17 Jun 2024 13:27:43 -0700 Subject: [PATCH] Parse voxel resolution SDF param when decomposing meshes (#2445) Signed-off-by: Ian Chen --- src/Util.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Util.cc b/src/Util.cc index e9cb2406f0..c73ac54dbc 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -891,20 +891,24 @@ const common::Mesh *optimizeMesh(const sdf::Mesh &_meshSdf, auto &meshManager = *common::MeshManager::Instance(); std::size_t maxConvexHulls = 16u; + std::size_t voxelResolution = 200000u; + if (_meshSdf.ConvexDecomposition()) + { + // limit max number of convex hulls to generate + maxConvexHulls = _meshSdf.ConvexDecomposition()->MaxConvexHulls(); + voxelResolution = _meshSdf.ConvexDecomposition()->VoxelResolution(); + } if (_meshSdf.Optimization() == sdf::MeshOptimization::CONVEX_HULL) { /// create 1 convex hull for the whole submesh maxConvexHulls = 1u; } - else if (_meshSdf.ConvexDecomposition()) - { - // limit max number of convex hulls to generate - maxConvexHulls = _meshSdf.ConvexDecomposition()->MaxConvexHulls(); - } + // Check if MeshManager contains the decomposed mesh already. If not // add it to the MeshManager so we do not need to decompose it again. const std::string convexMeshName = - _mesh.Name() + "_CONVEX_" + std::to_string(maxConvexHulls); + _mesh.Name() + "_" + _meshSdf.Submesh() + "_CONVEX_" + + std::to_string(maxConvexHulls) + "_" + std::to_string(voxelResolution); auto *optimizedMesh = meshManager.MeshByName(convexMeshName); if (!optimizedMesh) { @@ -916,7 +920,7 @@ const common::Mesh *optimizeMesh(const sdf::Mesh &_meshSdf, auto mergedSubmesh = mergedMesh->SubMeshByIndex(0u).lock(); std::vector decomposed = gz::common::MeshManager::ConvexDecomposition( - *mergedSubmesh.get(), maxConvexHulls); + *mergedSubmesh.get(), maxConvexHulls, voxelResolution); gzdbg << "Optimizing mesh (" << _meshSdf.OptimizationStr() << "): " << _mesh.Name() << std::endl; // Create decomposed mesh and add it to MeshManager