I am currently in the process of adapting GeometryBatchFactoty.makesBatches for my personal needs. One of these adaptations is to be able to batch RigidBodyControls together into the new batch. My process for doing so is quite simple: for all geometries being batched that have a rigid body control, take the debug shape from that control and add it to a list. Then once all the debug shapes have been gathered, merge the geometries into a new mesh that will be used as the new collision shape for the rigid body in the batch. Here is the code being used for this:
Mesh physicsMesh = new Mesh();
List<Geometry> physicsShapes = new ArrayList<>();
for(Geometry geom: batchData.getGeometries()){
if(geom.getControl(RigidBodyControl.class) != null){
// This geometry as physics, take the collision shape and create a debug shape out of it
Spatial debugShape = DebugShapeFactory.getDebugShape(geom.getControl(RigidBodyControl.class).getCollisionShape());
debugShape.setLocalTransform(geom.getLocalTransform());
// Take the debug shape and add it to our list
if(debugShape instanceof Node){
// Its possible if the collision shape was of Compound type that the debug shape is a node
for(Spatial child: ((Node)debugShape).getChildren()){
physicsShapes.add((Geometry) child);
}
}else{
physicsShapes.add((Geometry) debugShape);
}
}
}
mergeGeometries(physicsShapes, physicsMesh);
newRigidBodyControl.setCollisionShape(new MeshCollisionShape(physicsMesh));
newRigidBodyControl.setApplyPhysicsLocal(true);
Now the code above works and the geometries are batched together. However when checking the debug shape in game, there doesn’t seem to be anything there. After using GeometryBatchFactory.printMesh, I was able to find that all debug geometries generated using DebugShapeFactory.getDebugShape don’t have any index buffers, only position buffers. This was confirmed when I checked the methods that we’re being called to create the debug shape:
public static Mesh getDebugMesh(CollisionShape shape) {
Mesh mesh = new Mesh();
mesh = new Mesh();
DebugMeshCallback callback = new DebugMeshCallback();
getVertices(shape.getObjectId(), callback);
mesh.setBuffer(Type.Position, 3, callback.getVertices());
mesh.getFloatBuffer(Type.Position).clear();
return mesh;
}
So when I batch the shapes together and then print that mesh, this is what I get for the index bufer:
Index:
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
[0, 0, 0]
Note that they’re 6 [0, 0, 0] and they’re 6 debug shapes being merged together (coincidence?)
So now I’m not sure what to do. Is this a misunderstanding from my part? Or is there something I’m not doing that I should be doing? One more question that popped in my head was: if they’re no index buffers in the debug meshes, how am I able to even see those shapes properly? Because if I create a debug shape and attach it to the scene, I can clearly see it. But if I do the same thing with the debug shape batch, I can’t see anything.