Today's code snippet might prove useful to anyone who works with the PhysX SDK. This code has been compiled and tested with PhysX 2.8.3 but should work with earlier versions of the SDK with little or no modification.
In any PhysX application simply include the header file 'PhysX2Obj.h' and invoke the single method 'exportPhysX2Obj'.
You pass in a pointer to the scene you wish to export, the file name to save it as, and a bool indicating whether or not you want to export the data in world space or object space.
If you select world space, you will simply get one large Wavefront OBJ file with all of the static geometry in your game level. You can then import this Wavefront OBJ into 3D Studio Max or other tools for testing purposes.
If you select object space, it will export all of the geometry in object space and annotate the file, with comments, indicating where each object should be instantiated in the world.
Some of you might be familiar with my previous work on NxuStream; which is an XML file format that allows one to capture the state of a PhysX SDK scene. However, that format required a large code base and could only be used in the context of the PhysX SDK.
This tool is not a complete 'core dump' like NxuStream was; instead it is used primarily to export the gross game level geometry of an application so that it can be reviewed or debugged in another application.
I have set up a Google Code page to host this code snippet. You can find it here:
http://code.google.com/p/physx2obj/
You can also download the source directly using these two links. However, the Google Code project will always be the most current copy.
PhysX2Obj.cpp
PhysX2Obj.h
Tomorrow I am going to write a code snippet 'Obj2PhysX' which will read one of these object files, either in world space or object space, and instantiate it on the PhysX SDK. The code will be written in a generic enough fashion that you can also instantiate the data through some other API if you prefer.