I’m currently exploring JBullet and would like to load OBJ files as RigidBody instances. However, I have found surprisingly little documentation on this.
Is there somewhere I should be looking besides the JBullet and Bullet documentation?
While the object seems to fall properly, it doesn’t seem to collide with the StaticPlaneShape instance I added to the world.
This is the code that I have currently, but I have absolutely no clue if this code even works (I ran it and there were no errors, but that doesn’t really mean much)
// world is the instance of DynamicsWorld, and points is a list of Vector3f instances (JOML)
TriangleIndexVertexArray geometry = new TriangleIndexVertexArray();
IndexedMesh mesh = new IndexedMesh();
mesh.numTriangles = points.size() / 3;
ByteBuffer indices = BufferUtils.createByteBuffer(points.size() * 4);
IntBuffer intIndices = indices.asIntBuffer();
for (int idx = 0; idx < points.size(); idx++) {
intIndices.put(idx);
}
intIndices.flip();
mesh.triangleIndexBase = indices;
mesh.triangleIndexStride = 3 * 4;
mesh.numVertices = points.size();
ByteBuffer points = BufferUtils.createByteBuffer(this.points.size() * 4 * 3);
FloatBuffer floatPoints = points.asFloatBuffer();
this.points.forEach(point -> {
floatPoints.put(new float[] { point.x, point.y, point.z });
});
floatPoints.flip();
mesh.vertexBase = points;
mesh.vertexStride = 3 * 4;
geometry.addIndexedMesh(mesh);
body = new RigidBody(mass, new DefaultMotionState(), new BvhTriangleMeshShape(geometry, true));
world.addRigidBody(body);