CollisionShape is overriden

Hey Guys,
I have the following problem: I have some static objects (100 chairs) for which I don’t need some complex collision shape but only a box shape.

What I do now is:

CollisionShape box = CollisionShapeFactory.createBoxShape(spa);
spa.addControl(new RigidBodyControl(box, 0f));

Afterwards I have a general “new RigidBodyControl()” on the “Scene”, to add all the walls, stairs and such.
For some reason this already drastically improved performance (less cpu stress).

If I now enable the physics debug view I still see some complex shape. I thought the “general” shape would create a CompoundShape and add those previously manually created objects but it doesn’t.

Why would it? It does create a compound shape but that is as “complicated” as the single shapes its comprised of.

Yeah but it seem’d to recreate existing shapes for children.
I’ve found out something different, though.

The above code does not improve perfomance. I made all NPCs static in the same commit, which was the perfomance improve, but I guess this is just because the physics were faster than the vsync, so it’s just a race condition.

What does createBoxShape() exactly do? could it create several sub shapes? I expected it to be one huge cube with the dimensions of my spatial.
Is there a way to get those “half-extents” btw?

createBoxShape is recursive, yes. And all of these methods just take the scenegraph you give to them and create a collision shape for it, its just a helper method, not magic. You can just create collision shapes manually btw. Half-extents are just a vector from the center of the box to a corner.

But they could check if the spatial already has a PhysicsControl and then simply merge the CollissionShapes? (Or does it and I simply do something wrong?)

This is a problem for me if I have more complex spatials (blender models). The only way I could think of is iterating over each Vertex and then take the one which is the farest away from the center.
Since the SceneComposer needs to perform that task aswell, I wonder if there is some helper method?

It doesn’t, as I said its a simple helper method to create a collision shape for a graph. Such a method shouldn’t simply remove PhysicsControls the user added. (Which it would have to if it was to use its collision shapes and add it to a new PhysicsControl in a compound shape). The code isn’t complicated, just make your own helper method that does whatever you want (which I intended to imply by saying that you can just create collision shapes yourself and are not bound to the CollisionShapeFactory).

The BoundingBox of a spatial has this information, thats what createBoxShape uses.

Okay fine,
For the BoundingBox:
I can’t assume each BoundingVolume to be a BoudingBox I guess?
So could I use bv.distanceToEdge(bv.getCenter());? Which edge would be chosen then?

And how can I merge different meshes (recursively all meshes of that Node)?
I read about appending the buffers, but it would be easier to have some Mesh.combine() :slight_smile:

You are aware that you can look at the source of every jME class by just right-clicking it in the code editor?

I didn’t know. I actually always googled and then found some google code stuff.^^

By investigating, I guess it’s:

GeometryBatchFactory.gatherGeoms(spatial, list);
GeometryBatchFactory.mergeGeometries(list, myMesh);