How to integrate 3D Studio with Nvidia PhysX?
I had to write a project that will have some PhysX functionality. At first I wanted to use some 3DS model and animate it using PhysX. After spending some time on googling I realized that there are lots of questions on how to combine 3DS and physx and relatively little anwsers, so I decided to write a about it. This post presents a simple way with an explanation on how to combine 3DS and PhysX. I am covering rigid body only, so in case you want to create clothing or soft body, you have to perform research on your own and It would be good to publish your results as a comment to this post.
First of all, download PhysX plugin for 3DS Max from NVidia website and install it. Then, download some kind of 3DS model that you’re going to play with. See the video below I have recorded for you and try following it to see how do I create a PhysX mesh out of 3DS model.
In order to start I selected the model’s part I want to export to PhysX and clicked PhysX->Rigid Bodies->Select As Dynamic Body from the 3DS menu. Then you’ll have to define the mesh what is the most important part in this tutorial.
There following options you can set while creating a PhysX mesh from 3DS model:
This options describe the way the PhysX mesh will be generated. It can be convex (convex hull of your model), sphere (the smallest sphere that covers the model), ellipsoid, custom and combined etc. Personally I advice you to use composite way of creating PhysX mesh with appropriate parameters “split levels” and “max vertices”. See the gallery of screenshots below to see the difference between the options. The blue wireframe is the PhysX mesh that will be exported.
You can switch to the mesh view from the properties menu you have available within 3DS . Modify property window and then Modifier List->PhysX RBody. You should have displayed PhysX Rigid body somewhere at the tree list control. Now you can play with some different options to get known with the PhysX 3DS export plugin.
At the end you should export your mesh so that it would be visible for PhysX. Therefore click PhysX->Export PhysX Scene. You can also try validating the model, but is not necessary. You can choose export format. Personally I highly recommend using plain xml text file, despite the drawbacks of text file describing geometry because the Nvidia PhysX plugin is a little bit buggy and you can have control over the exported content. It seems that the PhysX export plugin has been developed in .NET. The exported file does not exist in invariant .NET culture, this means, if you don’t have English OS (your floating numbers are not ‘.’ separated) you have to convert your system separator to ‘.’. Mine system is Polish and floating separating char is ‘,’ , so I opened it with Notepad++ and exchanged all separators in a file with a dot ‘.’. PhysX reads only ‘.’ separated values, so please do it, because this is a bug from Nvidia and your model won’t be read otherwise. You can test your model in PhysX viewer.
How to use it in your code and how to create your own PhysX mesh browser in OpenGL?
I have prepared a simple model browser that has been written in C++ and OpenGL. It’s based on Nvidia example – SampleSceneExport. You have to load your previously defined model just the same Nvidia has done it in theirs example. There are some sample models that you can easily load to PhysX GL scene and download either with sourcecode or executable. The models are: teapot, torus, and penguin that can bee seen in the video above.