Hello,
I am trying to create a TriangleIndexVertexArray Object from Object3D for GImpactMeshShape (JBullet intergration). How do I get the IndexBuffer? The below code works for BvhTriangleMeshShape but GImpactMeshShape throws IndexOutOfBoundsException. calculating the indexBuffer is the problem. Please help.
private static TriangleIndexVertexArray createIndexVertexArray(Object3D obj) {
RigidObject ro = RigidObjectManager.getInstance().getRigidObject(obj.getName());
int numTriangles = obj.getMesh().getTriangleCount();
int numVertices = obj.getMesh().getVertexCount();
// int numVertices = obj.getMesh().getUniqueVertexCount();
//4 represents Byte size of Integer
ByteBuffer indexBuffer = BufferUtils.createByteBuffer(numVertices * 4).order(ByteOrder.nativeOrder());
for (int i=0; i<numTriangles; i++) {
indexBuffer.putInt(i);
indexBuffer.putInt(i);
indexBuffer.putInt(i);
}
ByteBuffer vertexBuffer = BufferUtils.createByteBuffer(numVertices * 4).order(ByteOrder.nativeOrder());
vertexBuffer.clear();
SimpleVector[] vertices = ro.getvController().getSourceMesh();
for (int i = 0; i < vertices.length; i++) {
vertexBuffer.putFloat(vertices[i].x);
vertexBuffer.putFloat(vertices[i].y);
vertexBuffer.putFloat(vertices[i].z);
}
vertexBuffer.rewind();
indexBuffer.rewind();
TriangleIndexVertexArray vertexArray = new TriangleIndexVertexArray(numTriangles, indexBuffer, 3*4, obj.getMesh().getVertexCount(), vertexBuffer, 3*4);
return vertexArray;
}
Thanks.