[SOLVED] Decreasing amount of vertices for a collision cloud

I’m using JBullet for physics and collision, and I got meshes to work but I have a question. How would I decrease the amount of vertices that get put into the collision mesh, without deforming the shape, for performance reasons? I wouldn’t need 1000 vertices for a collision, maybe 100. For example I am using the blender monkey which has 1,980 vertices, and I want less than 100. How would I do it?

This is the code I use to put vertices into the collision mesh:

ObjectArrayList<Vector3f> vertices = new ObjectArrayList<Vector3f>();
float[] verts = Renderer.vaolist.get(vaoListId).vertices;
for(int i = 0; i < verts.length; i+=3) {
    vertices.add(new Vector3f(verts[i],verts[i+1],verts[i+2]));
}

CollisionShape shape = new ConvexHullShape(vertices);

The easiest way would probably be to generate a low-poly version of your mesh externally and just load in that mesh instead.

Is there a way to do it programmatically? I would rather do that than have to make 2 meshes for each entity, but if there is no other way then I will do it.

Yes, you’d need to implement some sort of Level of Detail (LOD) algorithm though. Quick internet search gave me this.

I’ve never implemented lod stuff so I’m not going to be of much help. Like theagentd said the easiest way is to just make a low res model. There really isn’t a way, that I know of, to get around deformations in the (test) mesh though.

I don’t think anyone can implement a good algorithm for reducing the number of vertices in a mesh while retaining its shape somewhat in a reasonable time frame. If it’s not a strict requirement, you should try to avoid it since it’ll take lots of time.

Alright, thanks guys.