Finding the trimesh of a convex hull object

Post Reply
k2smith
Posts: 1
Joined: Thu May 05, 2016 7:48 pm

Finding the trimesh of a convex hull object

Post by k2smith »

Is there a way of pulling the trimesh composing the hull out of a btConvexHullShape object without using a btShapeHull? I'm trying to calculate the volume of an object (to set mass by density), which is not too difficult once the trimeshes of the faces are known.

However, all the online help says to get this decomposition through a btShapeHull object - but when I do that it approximates the convex hull, and this leads to systematic biases in the volume (e.g., a unit cube is calculated to have a volume of 1.227).

Any help for calculating the trimesh directly from the shape (or vector of vertices) would be appreciated! Thanks!
cameron
Posts: 2
Joined: Fri May 06, 2016 9:18 pm

Re: Finding the trimesh of a convex hull object

Post by cameron »

I think btConvexHullComputer would be one approach
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Finding the trimesh of a convex hull object

Post by Erwin Coumans »

The btConvexHullShape doesn't maintain mesh information by default, only vertices.

You can generate mesh information using the btConvexHullShape::initializePolyhedralFeatures
and then use btConvexHullShape::getConvexPolyhedron to get access to the triangles etc.
(see bullet3\src\BulletCollision\CollisionShapes\btConvexPolyhedron.h how to access this data)

This will use the btConvexHullComputer internally. You can also do this by yourself, given some vertices:
#include "LinearMath/btConvexHullComputer.h"

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<numVerts;i++)
{
m_unscaledPoints.push_back(conv.vertices);
}
}


In addition, usually it is best to remove internal vertices, using btConvexHullShape::optimizeConvexHull method.
Thanks,
Erwin
Post Reply