Large worlds, triangle meshes, paging

nargil

05-08-2009 08:54:25

TriangleMeshes are a pain in the ass killing the framerate. What should I do with far away actors ? Completly delete them has a big con: you need to recreate them later, which takes some time for triangle meshes. What's the right solution ? A second physx loading thread ? Is it possible to use threads with physx ?

betajaen

05-08-2009 11:25:44

There are a two ways I can think of to help things along;

1. Freeze the Actor and Disable Collisions for them.

You can't delete static actors in a Scene, PhysX will moan like a baby. So the alternate is to freeze any dynamic actors (via the flags), kill any momentum it has and blanket every Actor far way with a NX_AF_DISABLE_COLLISION flag.

2. Divide your World into separate Scenes

Say 5x5 grid each scene covering several KM between them; you may need to make some modifications to NxOgre so each created actor has an offset (i.e. a parent scene node that each Body's node is belongs to).

Then you can have total control over those scenes. Turning off simulation to them completely, or even deleting them.

The tricky part is moving things between scenes. It isn't difficult but you do need to check every frame, and recreate the new actor in the scene and delete the old one roughly at the same time; this includes characters, cloth and anything else. But you could speed things up by having a "safety buffer" on the edges that will pre-create any actors if they are in the buffer which is only a few metres long, whilst the actor is moving along the buffer into the new scene. PhysX has already created the new duplicate Actor which is disabled, once the moving Actor has entered the new Scene, all you have to do is transfer the pose, linear/angular momentum and set the scene node to visible, and delete the old one.



I like #2 the best, it's hard work and a bit tricky to implement. But with 25 Scenes you can have massive worlds (think 25 * 2000) instead of a boring 2000 actor one.

Yep, PhysX has an awesome threading interface. Pity I don't understand C++ threads that well, so never implemented it properly.

nargil

05-08-2009 11:55:28

You can't delete static actors in a Scene, PhysX will moan like a baby. :))) I do that all the time in my editor :P Move them, delete, and so on. PhysX cries in the console, but who cares if it works ? ;>

AD1. The difference between 1000 static triangle meshes with disabled and enabled collision is 8 fps (50 vs 42)
AD2. Thanks for the suggestion. I'd had to rewrite my scene structure with loading / saving. I don't feel like doing it now. I'm going to queue the physx paging for a later time.

betajaen

05-08-2009 12:11:29

It moans for a reason.

Let's picture it this way. You'll never think the Earth will disppear from underneath you? So you make assumptions that it will always be there, you'll never tie down a wheelbarrow, or keep a rope tied to your best friend so he won't drift way.

Neither does PhysX. So the event that it does disappear, it doesn't notice - until you do. Which is a bit late then and completely ruins the illusion of actual physics happening.