Optimising Collision Shapes by reducing poly count automatically?

So as some of you already know I’m making a game that uses bullet physics and a system of assembling spaceships from modules. This poses a problem as obviously, the ship’s collision shape cannot be predefined. This is the result I get by using:


This still preserves all geometries and just makes a hundred collisionshapes which isn’t ideal. There are a ton of polygons that could be joined together. I had an idea to use GeometryBatchFactory optimisation to reduce the mesh, but it seems to be a bit too effective, making it a rectangle. Nevertheless I still use this for enemy ships atm, since the alternative equals 0 fps.


What I’m looking for is something like the “decimate” command in blender, basicly reducing the poly and vertex count while still preserving much of the shape. If only HullCollisionShape worked on nodes, instead of just geometries. I still haven’t researched this 100%, but any tips and tricks you guys know would be much appreciated.

If each of those blocks is a separate geometry then that’s kind of problem number 1. That’s horrible for a dozen reasons.

But really physics engines aren’t directly designed to handle these cases so you’re probably going to have to roll up your sleeves and get hot-and-heavy with the math.

You can make a HullCollisionShape by supplying either a batched mesh or all points as a float array.


I know, I cri evrytiem.

Hey that sounds like it’d work pretty well, I’ll try it out.

If you don’t need to have ships intersecting, hull shape is the best performance you can easily get.

Still having enemy ships with burte force collision shapes, should only reduce performance when the bounding boxes overlap, else it should not make a difference. (if you do not raytrace often)

@Empire_Phoenix Well the physics doesn’t have any performace issues when stuff isn’t intersecting, but there are a lot of moments when you’ll be brushing against free floating blocks which can drop framerate a little if your ship is large and in collision range of like 10 blocks at the same time. Colliding with ships is uncomparably worse, dropping to under 20 fps with very large ships (unless given the large rectangle mesh when it doesn’t impact performance at all).

@normen Welp I tried the BatchNode and SimpleBatchNode, and further optimised by just attaching Box meshes where modules are, but the geometries still appear to stick around and not join:

Note that this is still using CollisionShapeFactory.createBoxShape() since the batched node doesn’t seem to have any batched geometry I can get to, even with extending classes. So if I cannot get to the batched mesh itself (seems private) and am unable to pass it to the HullCollisionShape as a parameter. If I try getting its children all I get are seperate geometries, which are of zero use to me. Is there any way I can get

[quote=“normen, post:3, topic:33780”]
a batched mesh
[/quote] from a batched node?
I gave the manual gathering of vertices a go, but I’m not sure how to get the indexes right and nothing except the first module’s mesh shows.

GeometryBatchFactory, not BatchNode


I see. facepalm

Now this is what I wanted. Puuurfect.

@normen you never fail to amaze me :smiley: