[ODE] Large physics worlds - let autodisable handle it,
or create a sliding window of physical activity?
nearaz at gmail.com
Thu Apr 21 09:13:17 MST 2005
> I don't see why simulating "everything" would be that much more
> expensive -- you won't be running physics for disabled bodies;
> only collision testing, and you can make it so that disabled bodies
> don't collide with other disabled bodies (using the masks).
I'd say be careful with that, especially if you use native ODE colliders.
I had a situation recently where there would be ~200 dynamic things
(bodies+geoms), and thousands of geom-only things (one terrain, and
lots of boxes for the stuff on the terrain).
Now, I obviously don't need to collide static-vs-static. AFAIK, ODE
doesn't have an optimized space-vs-space collider, so putting all
dynamic stuff into space A, static stuff into space B and colliding
A-vs-B and B-vs-B wasn't an option.
If everything would be put into single space, using right
category/collide masks, then quite much of the time is spent just
traversing the space (or in hash space case, rehashing everything),
when in end there are just a couple of collisions.
The physics wasn't an issue, as autodisable takes care of that with
the right parameters.
What I ended up was: put all static geoms into one "static space". Put
all dynamic stuff into "dynamic space". Now, each physics object
periodically "caches in" the static geoms around itself: eg. it
queries all static geoms around itself at some radius R. When the
object has moved for some amount, or sufficient time has passed, it
caches in the geoms again. All the cached-in geoms are checked for the
last time they were needed, if they are not needed for "quite long",
they are removed from dynamic space.
This way, the thousands of static geoms sit only in static space. I
never collide that space, only make small area queries into it. The
dynamic space only contains the dynamic stuff and some "relevant"
nearby static geoms.
One note: in ODE, for the static geom I had to use quadtree, because
it's the only one that can efficiently perform one shot queries. Hash
space needs to rehash everything before collision; and space-vs-geom
implementation in it is really unoptimized. For the dynamic space, I
used sweep-and-prune one.
In the end, going from initial naive approach to this "cache in
relevant geoms" reduced collision/physics times from 10ms (at 10Hz,
i.e. 100ms total in one second) to something like 0.03ms (i.e. 0.3ms
in one second), when there's no action at all. In the first case, all
the time was just for the collision that produced zero contacts!
Aras 'NeARAZ' Pranckevicius
http://nesnausk.org/nearaz | http://nearaz.blogspot.com
More information about the ODE