panda3d icon indicating copy to clipboard operation
panda3d copied to clipboard

Fast -into-mesh collision shapes

Open Schwarzbaer opened this issue 4 years ago • 5 comments

I'm colliding against visible/arbitrary geometry a lot, which is slooow. I would appreciate a more efficient collision solid; Even a static one would be very helpful.

Schwarzbaer avatar Dec 11 '20 18:12 Schwarzbaer

If you're not using it already, there is the "CollisionPolygon" class, which provides collision with arbitrary geometry.

Aside from building these up yourself, you can define a collision-mesh composed of these in a 3D modelling program (or your egg file) by applying "Collide" tags with the "polyset" value. In this way you can define custom collision-geometry specific to a given model.

Otherwise, there are a variety of collision-solids that you could use to approximate your shapes (as described here).

Is there something specific that you have in mind that's not covered by the above?

ArsThaumaturgis avatar Dec 12 '20 07:12 ArsThaumaturgis

In Panda, the concept of visible geometry for a collision is misleading. In fact, there is a concept of the form of collision, how you do it is up to you. You can use the geometry you are visualizing, or any other simplified geometry.

Answer @ArsThaumaturgis is exhaustive.

serkkz avatar Dec 12 '20 12:12 serkkz

CollisionPolygon objects are great for levels, which have large flat surfaces. However, I think it performs poorly for shapes with many small triangles, because there are then many separate solids that need to be tested at the same time.

I think that there might be a merit to having a CollisionTriangleMesh shape to handle those types of meshes more efficiently. However, it should be a method of last resort, because triangles are not very reliable for collision.

rdb avatar Dec 12 '20 12:12 rdb

I think that for many non-level purposes, it's not uncommon that the object's form can be approximated with primitives. This tends, I think, to be rather more efficient, while the disparity in form tends to not be all that noticeable.

That said, I could indeed see a new "CollisionTriangleMesh" shape being potentially useful in some cases!

ArsThaumaturgis avatar Dec 12 '20 12:12 ArsThaumaturgis

I suspect that the problem is primarily in the setup of the geometry.

The basic process and problem is that every object needs to be checked against every other objects that it could collide with.

That problem needs n**2 calculations for n objects. That's bad. It gets very expensive very quickly.

To reduce the problem, panda provides several tools (and uses some tricks):

  • collision bit mask separates objects that only "some" can collide with "some others"
  • (I assume panda does it / rdb made a thing) that forms "clusters". Collisions are then calculated for big bounding boxes around the clusters and inside each cluster.
  • "stock" collision shapes like the sphere, can use simplified calculations compared to a regular mesh. The mesh has N faces the more the better for smoothness. But each face needs to be calculated whether it collides or not. (bad) The collision shape is only defined by the point and a radius. (good)

For cases where you have big levels, like landscapes, they should be "chunked". More chunks = less faces the player can collide with per chunk = less computation.

Finally for cases where you have really detailed visual meshes and you should create simpler shapes from them. Fortunately those algorithms are well described:

https://www.cs.cmu.edu/~./garland/Papers/quadrics.pdf

also maybe try the "remesh" modifier in blender.

Doesn't mean the collision code in panda can't be improved, but it's probably easier to optimize the setup of your geometry.

BMaxV avatar Apr 22 '23 18:04 BMaxV