John Ratcliff's Code Suppository

A place where I insert my code into the anus of the Internet.

 

Tuesday, February 23, 2010

PhysX Rocket for 2.8.3


The physics demo application, PhysX Rocket, has not been officially released in some time.  However, I frequently get questions from people who still enjoy playing with it as a tinker toy.  It can also be useful as a physics scripting application.

Overall, Rocket is really showing its age.  It is very crufty, especially in terms of the source code.

However, if you want a copy to play with, here is the link.  It is simply a ZIP file.  It does not have an installer, and does not include source code.

www.amillionpixels.us/rocket.zip

NvCoreDump : Easily perform an NxuStream XML compatible core dump with PhysX 2.8.3


NvCoreDump is a windows 32 bit DLL which allows any PhysX 2.8.3 based project to perform an NxuStream XML compatible core dump in a single function call.

Rather than including all of the NxuStream source code in your application, instead you can simply demand load this tiny DLL and save it out.  The value, purpose, and benefit is to take simply add the ability to export the contents of the current PhysX SDK in any application by simply adding this tiny code snippet and the DLL.

This project is hosted on Google Code at the following location:

https://code.google.com/p/nvcoredump/

Simply add the source files 'NvCoreDump.h' and 'NvCoreDump.cpp' into your project.  Next add the DLL 'NvCoreDump283.dll' to your binary/executable directory.

Somewhere in your project, typically when someone types a command at the console, simply call the method 'nvCoreDump' passing a pointer to the 2.8.3 PhysX SDK and a string pointer of the file name you want it saved as.

The file will be saved in XML format as NxuStream.  NxuStream is a reflective object model representation of all of the internal data of the PhysX SDK, including scenes, meshes, constraints, clothing, and even fluids.

PhysX2Obj : Convert Physics Scenes into a Wavefront OBJ file


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.