Procedural generation of collision polyset.

A couples of days ago, I had a problem with CollisionHandlerPusher. The sliding near corners was weird. [url]CollisionHandlerPusher and sliding against walls.]

After many tests and a lot of debugging, I figured out what my problem was:

  • If I read the collision solid from the egg file, or if I create a CollisionBox, then the pusher works perfectly and I slide gracefully against the surface.
  • If I create a bunch of CollisionPolygons myself, then the pusher is confused because each polygon is now a separate object: corners are a mess.

In short: 20 quads are not equivalent to one Polyset.

I want to do what base.loader does when there’s a { Polyset } in the egg file. But I want to do it myself at runtime.

The reason for that is that I generate my dungeon procedurally, and I want the simplest collision shape I can get. I want to build one big collision polyset for my level.

I have already written the code that gives me all the coordinates of the vertice I need for my shape. What I need now is to build a mesh, and ask panda to use it for collision.

How can I do that in python?

You can use the EggData classes to construct an egg file structure in code (without actually generating the .egg syntax), use setCollideFlags on the relevant EggGroup, and then let the loader load that structure.

I don’t think the egg loader does any magical coalescing of polygons, though. Perhaps the only difference between the CollisionPolygon objects you are creating yourself, and those created by the egg loader, is that the egg loader adds them all to the same CollisionNode?

Still, if you have a bunch of side-by-side polygons, I’m not surprised that collisions are a mess. Actually, I’m surprised that it’s not really a mess if you go through the egg loader.


My problem was with the normals indeed. Those of the vertices (the faces are ok).

When I ask Panda to create a box, it’s not equivalent to 6 quads because the normals of the box point away from the center, while the normals of the quads are, well, normal to the quad.

When my normals are consistent, then Panda’s collision engine is fairly happy. I to see a tiny bit of jitter in some cases, but I’m pretty sure it’s my fault.

So it’s working ! I am now having a huge amount of polygons to collide against, but I don’t need to simplify them because they’re really not the bottleneck in my application.