Small addition for directly creating MeshShapes


This alternative constructor simply provides the ability to directly create MeshShapes.

Usefull for, when you generate procedually Meshshapes, that are only used for collision, since it saves copying the whole buffer.

I use this for efficiently sharing a 256mb vertexbuffer, between different indexbuffers, that only need to use part of it.

If I would do this via the generic Mesh interface I would end up with multiple copies of it. This way I’m able to update that buffer efficiently so that if only one vertex changes apart from a recreation of the native object the buffercopy can be skipped. Of course this comes at the price of handeling multithreading acces to the buffers and similar stuff manually.

As far as I see noone will be influrenced by this when using the higher level abstraction, however it allows advanced users to directly acces the lower level.

Works for both jbullet and bullet.

/** This is targeted for advanced uses, consider using new MeshCollisionShape(Mesh m) instead; */ public MeshCollisionShape(final ByteBuffer indexBuffer, final ByteBuffer vertexbuffer) { this.createCollisionMesh(indexBuffer, vertexbuffer); }
public void createCollisionMesh(final ByteBuffer indexBuffer, final ByteBuffer vertexbuffer) {
	this.triangleIndexBase = indexBuffer;
	this.vertexBase = vertexbuffer;
	this.numVertices = this.vertexBase.capacity() / 4;
	this.vertexStride = 12;
	this.numTriangles = this.triangleIndexBase.capacity() / 4 / 3;
	this.triangleIndexStride = 12;


@EmpirePhoenix: What is the format of those buffers? Why are they both ByteBuffers?

The first is using ints and the second 3*Floats. They are ByteBuffers, because the fields they hook into are bytebuffers, and I wanted to keep everything else as it was, because if I would change the whole class it would be way harder to determine if this breaks anything else, while this way it does not change ANY existing code.



  • Basic mesh collision shape

  • @author normenhansen


    public class MeshCollisionShape extends CollisionShape {

    protected int numVertices, numTriangles, vertexStride, triangleIndexStride;

    protected ByteBuffer triangleIndexBase, vertexBase;

    protected long meshId = 0;


@Normen: what do you think? Can this be added? Is there any requirement for the buffers being native vs. array-based?

@Momoko_Fan said:
@Normen: what do you think? Can this be added? Is there any requirement for the buffers being native vs. array-based?

Idk, you were the one adding the cleaned mesh stuff. I was always proposing to re-use and share the data. Since the functionality of this feature here would change I am a bit hesitant to add it right away. Generally I have no objections though. For now you can extend the Object if you want to do this.