Building a ConvexHull out of an XNA ModelMeshPart
Posted: Tue Aug 02, 2011 5:46 pm
Hi,
I'm trying to build a convex hull using the data from a ModelMeshPart. I am taking the Model and for each part of the Model, generate a convex hull. So far, i have done this:
For some odd reason, the computed origin is offset in the X dimension by 0.5, even though the model I am generating this from is totally symmetrical (i modelled half of the vehicle and then mirrored all the geometry) and is centered around the origin, which leads me to believe that I'm only getting half the vertices.
This causes a problem when I try to use the ConvexHull on a vehicle, as it crushes all the suspension on one side and the vehicle tips over.
I'm trying to build a convex hull using the data from a ModelMeshPart. I am taking the Model and for each part of the Model, generate a convex hull. So far, i have done this:
Code: Select all
public ConvexHullShape getConvexHull()
{
if (this.convex_hull == null)
{
List<Vector3> verts = new List<Vector3>(1000);
foreach (var i in this.renderable_mesh.MeshParts)
{
Vector3[] lulz;
lulz = new Vector3[i.NumVertices];
i.VertexBuffer.GetData<Vector3>(lulz, i.VertexOffset, i.NumVertices);
foreach (var point in lulz)
{
verts.Add(point);
}
}
Vector3 computed_origin;
this.convex_hull = new ConvexHullShape(verts, out computed_origin);
}
return this.convex_hull;
}
This causes a problem when I try to use the ConvexHull on a vehicle, as it crushes all the suspension on one side and the vehicle tips over.