From c86fea11dc593287394d9d8c4ff727de23a841dd Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 24 Jan 2008 01:35:34 +0000 Subject: [PATCH] use btHullShape/btConvexHull to reduce vertices in a convex hull. Perhaps we always use this, to avoid convex objects with too many vertices...? --- .../ConvexDecompositionDemo.cpp | 41 ++++++++++++++++--- Demos/OpenGL/GL_ShapeDrawer.cpp | 6 +-- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp index a0d1fa55b..6ec0f46aa 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp @@ -21,7 +21,7 @@ subject to the following restrictions: #include "LinearMath/btQuickprof.h" #include "LinearMath/btIDebugDraw.h" #include "LinearMath/btGeometryUtil.h" - +#include "BulletCollision/CollisionShapes/btShapeHull.h" //#define USE_PARALLEL_DISPATCHER 1 #ifdef USE_PARALLEL_DISPATCHER @@ -143,7 +143,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) btVector3 localScaling(6.f,6.f,6.f); //export data to .obj - printf("ConvexResult\n"); + printf("ConvexResult. "); if (mOutputFile) { fprintf(mOutputFile,"## Hull Piece %d with %d vertices and %d triangles.\r\n", mHullCount, result.mHullVcount, result.mHullTcount ); @@ -284,7 +284,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) btVector3 localScaling(6.f,6.f,6.f); - for (int i=0;iaddTriangle(vertex0,vertex1,vertex2); } - btCollisionShape* convexShape = new btConvexTriangleMeshShape(trimesh); + + btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh); + + printf("old numTriangles= %d\n",wo.mTriCount); + printf("old numIndices = %d\n",wo.mTriCount*3); + printf("old numVertices = %d\n",wo.mVertexCount); + + printf("reducing vertices by creating a convex hull\n"); + + //create a hull approximation + btShapeHull* hull = new btShapeHull(tmpConvexShape); + btScalar margin = tmpConvexShape->getMargin(); + hull->buildHull(margin); + tmpConvexShape->setUserPointer(hull); + + + printf("new numTriangles = %d\n", hull->numTriangles ()); + printf("new numIndices = %d\n", hull->numIndices ()); + printf("new numVertices = %d\n", hull->numVertices ()); + + btConvexHullShape* convexShape = new btConvexHullShape(); + for (i=0;inumVertices();i++) + { + convexShape->addPoint(btPoint3(hull->getVertexPointer()[i])); + } + + delete tmpConvexShape; + delete hull; + + + m_collisionShapes.push_back(convexShape); float mass = 1.f; @@ -337,7 +368,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) unsigned int maxv = 16; float skinWidth = 0.0; - printf("WavefrontObj num triangles read %i",tcount); + printf("WavefrontObj num triangles read %i\n",tcount); ConvexDecomposition::DecompDesc desc; desc.mVcount = wo.mVertexCount; desc.mVertices = wo.mVertices; diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp index ab0549eaa..df14dca1f 100644 --- a/Demos/OpenGL/GL_ShapeDrawer.cpp +++ b/Demos/OpenGL/GL_ShapeDrawer.cpp @@ -476,9 +476,9 @@ void GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape* shape, cons convexShape->setUserPointer(hull); - printf("numTriangles = %d\n", hull->numTriangles ()); - printf("numIndices = %d\n", hull->numIndices ()); - printf("numVertices = %d\n", hull->numVertices ()); + // printf("numTriangles = %d\n", hull->numTriangles ()); + // printf("numIndices = %d\n", hull->numIndices ()); + // printf("numVertices = %d\n", hull->numVertices ()); }