Collision model from GeometryBatchFactory

Hi there,

I’m having some (probably easily solved) issues with MeshCollisionShape and the GeometryBatchFactory. My game level is made out of many 3d tiles which are chosesn by a random level generator. I figured a good way to simplify the collisions would be to run all the tiles through the batch factory before using them as a MeshCollisionShape.



My problem is one of types - I don’t know how to get the mesh from the spatial that is output by the GeometryBatchFactory. I see how to get a mesh from a Geometry object, but not how to get one from (or convert to) from the output spatial.



It’s probably a really simple thing that I’m overlooking, but better to ask now than be stuck for another several hours :slight_smile:

Cast the Spatial to a Geometry if it is one.

I tried that at first, but got an exception - apparently it’s a node. Am I using the batch factory wrongly? I pass it the node with all the loaded collision models attached to optimize:



[java]this.collisionmodel = GeometryBatchFactory.optimize(this.collision);



Geometry model = (Geometry) this.collisionmodel;[/java]

No, I guess you have different materials, so it cannot combine sll of the meshes, check the sub geometries which are probably there.

Hmm… all the models have the same material (since they are collision meshes I assigned a generated material so I could see them if need-be).



I checked the children of the output from the batch factory, and it still has 25 of them, the same number as before it was used. Not entirely sure what’s going on.



EDIT: I remembered reading somewhere that when you clone an object, the mateiral is cloned with it. I re-assigned the material to the objects after they were added to the group node, and it correctly batched them into one object. I’ll see if the casting works now.



EDIT 2: Nope, but getting its single child works a treat, thanks for the assistance!