I have a problem with JBullet mesh collsion. Everything works fine when I create a mesh from my object without scaling, but the problem starts when I want to scale the object. I also tried scaling in Blender, but it has the same problem. Here is my code for creating a mesh from an object:
int numtriangles = mesh.vertices.length / 3;
int numverts = mesh.vertices.length;
ByteBuffer indexBuffer = BufferUtils.createByteBuffer(numverts * 3 * 4).order(ByteOrder.nativeOrder());
indexBuffer.clear();
for(int i=0;i<numtriangles;i++) {
indexBuffer.putInt(i);
indexBuffer.putInt(i);
indexBuffer.putInt(i);
}
ByteBuffer geometry = BufferUtils.createByteBuffer(numtriangles * 3 * 4).order(ByteOrder.nativeOrder());
geometry.clear();
for(int i=0;i<numtriangles;i++) {
geometry.putFloat(mesh.vertices[i].getPos().x);
geometry.putFloat(mesh.vertices[i].getPos().y);
geometry.putFloat(mesh.vertices[i].getPos().z);
}
geometry.rewind();
indexBuffer.rewind();
TriangleIndexVertexArray trimesh = new TriangleIndexVertexArray(numtriangles, indexBuffer, 3 * 4, numtriangles, geometry, 3 * 4);
BvhTriangleMeshShape shape = new BvhTriangleMeshShape(trimesh,true);
return shape;
My scaling was something like this:
for(int i = 0; i < vertices.length; i++) {
Vertex acc = vertices[i];
Vector3 pos = acc.getPos();
pos.x *= scale.x;
pos.y *= scale.y;
pos.z *= scale.z;
acc.setPos(pos);
Vector2 tex_coord = acc.getTexCords();
tex_coord.x *= scale.x;
tex_coord.y *= scale.z;
acc.setTexCords(tex_coord);
vertices[i] = acc;
}
The problem is when I scale the object, it no longer collides with other objects.