From 372c4ef9c1cc9b8ae1a6a6e5c69d2fbb5f56a3e2 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 4 May 2016 13:01:06 -0700 Subject: [PATCH] Add btConvexHullShape::optimizeConvexHull method, it automatically removes vertices that are not on the convex hull. It uses the btConvexHullComputer for this. --- .../CollisionShapes/btConvexHullShape.cpp | 17 +++++++++++++---- .../CollisionShapes/btConvexHullShape.h | 5 ++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp index 0623e351a..c1aa6ca46 100644 --- a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp +++ b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp @@ -22,6 +22,8 @@ subject to the following restrictions: #include "LinearMath/btQuaternion.h" #include "LinearMath/btSerializer.h" +#include "btConvexPolyhedron.h" +#include "LinearMath/btConvexHullComputer.h" btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape () { @@ -121,10 +123,17 @@ btVector3 btConvexHullShape::localGetSupportingVertex(const btVector3& vec)const } - - - - +void btConvexHullShape::optimizeConvexHull() +{ + btConvexHullComputer conv; + conv.compute(&m_unscaledPoints[0].getX(), sizeof(btVector3),m_unscaledPoints.size(),0.f,0.f); + int numVerts = conv.vertices.size(); + m_unscaledPoints.resize(0); + for (int i=0;i