Game Development Community

PhysX and Mega Terrains in TGEA1.7

by Taylor Petrick · in Torque Game Engine Advanced · 05/22/2008 (11:58 pm) · 3 replies

I've successfully implemented the TGEA 1.7 PhysX resource. The PhysX objects work fine on interiors and legacy terrain, but always fall right through MegaTerrains. Does anyone have any ideas on why this would be occuring?

#1
05/28/2008 (10:34 am)
You're going to have to handle MegaTerrains specially. You have a couple of choices. You can leave the code that's there and use it, and merely make it look for the MegaTerrain group and then handle each TerrainBlock individually like it does a single one, or you can rewrite the stuff for terrain some to be much better. Basically you'll want to look into cooking in the PhysX docs, and particularly TriangleMesh cooking. Basically what you need to do is go through all the vertices and pack them how PhysX wants them, and then set up a TriangleMeshShape and such to use them, and call the cooking routines (IIRC, the cooking lib isn't used in that resource, but I could be wrong).

It's probably either just failing to find the terrain altogether (might be looking for a single one or a particular name), or only creating a collision object for the single terrain. To find out for sure you should set up your PhysX loading stuff to be able to connect to the PhysX Remote Debugger. If you want to do anything serious with PhysX you're going to need to look at the debugger sooner or later.

Also, to simplify things, if I were you I'd get rid of the sNxActor struct completely. It was just some sort of hack to avoid getting writelock errors (the physics scene has been locked for simulation, so you can't delete actors). It's much easier to just keep a couple of Vectors<> (of NxActor pointers) around that keep track of actors/joints that need to be freed when the simulation is writable again (look in the docs to find the functions you need to check the writable state).
#2
05/28/2008 (11:02 am)
Yeah, thing is I'm not too great of a coder. I'll look into the first choice. I think I remember seeing a spot that did a check for a LegacyTerrain block, and if there wasn't on present a console error was printed. That error appears in my log, so I guess PhysX isn't finding the terrain.
#3
05/28/2008 (11:37 am)
That's probably it. I imagine it was using the old technique of looking for a particular name or whatever, assuming there would be only one TerrainBlock. Easiest way you're going to be able to do it is to just have it try to find the MegaTerrain group, then you can just have it do everything it does for the single TerrainBlock as is for each one in the group (you can iterate over it I believe).