From 1de995ae9911fdc3ce609a8c8f84e023531ea6bc Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Wed, 7 Jul 2021 12:14:12 -0700 Subject: Options to clean/simplify convex hull generated from mesh Clean: remove duplicate and interior vertices (uses Bullet algorithm) Simplify: modify the geometry for further simplification (uses VHACD algorithm) In the editor, single convex hull now uses the clean option. Added a new editor entry to create a simplified convex hull, can be useful for creating convex hull from highly tessellated triangle meshes. --- modules/vhacd/register_types.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/vhacd/register_types.cpp b/modules/vhacd/register_types.cpp index daad39bdfb..3d7aaee921 100644 --- a/modules/vhacd/register_types.cpp +++ b/modules/vhacd/register_types.cpp @@ -32,7 +32,7 @@ #include "scene/resources/mesh.h" #include "thirdparty/vhacd/public/VHACD.h" -static Vector> convex_decompose(const Vector &p_faces) { +static Vector> convex_decompose(const Vector &p_faces, int p_max_convex_hulls = -1) { Vector vertices; vertices.resize(p_faces.size() * 9); Vector indices; @@ -47,8 +47,12 @@ static Vector> convex_decompose(const Vector &p_faces) { } } - VHACD::IVHACD *decomposer = VHACD::CreateVHACD(); VHACD::IVHACD::Parameters params; + if (p_max_convex_hulls > 0) { + params.m_maxConvexHulls = p_max_convex_hulls; + } + + VHACD::IVHACD *decomposer = VHACD::CreateVHACD(); decomposer->Compute(vertices.ptr(), vertices.size() / 3, indices.ptr(), indices.size() / 3, params); int hull_count = decomposer->GetNConvexHulls(); -- cgit v1.2.3