A Python wrapper for PhysX 2.8.1

What is this?

This is a distribution of a wrapper for the PhysX game physics API by NVIDIA.
It is designed for version 2.8.1 of the SDK, and will build and load with the
May 2008 PhysX runtime. Note that the September/October 2008 PhysX runtime
that is CUDA accelerated will NOT run on most machines (this is a "feature"
of that runtime, not just of this wrapper). This is Windows only, but chances
are good that you could get it to build on Linux with the NVIDIA PhysX SDK
for Linux.

There is also experimental support for .NET, by generating C# files and dlls.
Use the build_dotnet.bat file to build for .NET. This support was added on
May 2, 2009.

The distribution is built using SWIG, and as such requires some machinations
to use properly. For example, the physx module has a global SDK instance,
which is called "physx.cvar.sdk" -- the "cvar" is a wrapper for a C global.

Rather than give the modules proper names (physx.physics, etc), I had to
give them underscore names, because of what appears to be a limitation in
SWIG. Or I just don't know how to use it right. In releases after 2008-10-08,
docstring support is included (yay!).

Now, what's cool about this distribution? First of all, it is totally non-
intrusive. You can build this without changing any NVIDIA headers at all! This
is quite important, because the NVIDIA sources have a EULA that you can't use
for redistribution. It's also useful, because it should be easy to keep it up
to date for newer versions of the PhysX SDK.

Second, it's quick to maintain. Literally, I've never used SWIG before in my
life, and this wrapper took about 6 hours to put together one late October
evening, with some additional improvements over the next few days.
This is a feature, because I don't mind releasing the hack into the public
domain. That's right! The code, and the Windows binaries, are all released
into the public domain by the author, me! (I don't know if Microsoft wants to
keep the rights to whatever loader code is embedded in the DLLs, and I don't
know what license the generated SWIG code is under, but the stuff I wrote is
totally free for any use. Have fun!)

Third, there are a few simple helper functions included. These mostly have to
do with converting to/from tuples/sequences for the NxVec3, NxQuat, NxMat33
and NxMat34 classes, supporting float array as a type (see newFloatArray())
without using ctypes, and finally supporting all flavors of ShapeDesc, even
when the SWIG argument resolver seems to not understand up-casts (see
NxActorDesc.addShapeDesc())

There is a small test program which uses Panda3D to render two cubes falling
onto a plane and rolling off each other. It proves that this approach at
least works and is usable, although I'd have to see something bigger built
before I'd consider the system release quality. To run it, make sure that the
Panda3D python is first in your path, and run:

python pandatest.py

You should see a gray window with two cubes on the right hand side, falling
down onto each other.

Finally, if you want to build the integration yourself, you can do so with
Microsoft Visual Studio. Make sure you've executed VCVARS32.BAT so that the
compiler/linker are in the path, then just type "build" to built it using
the included batch file (no makefile, sorry!) Alternatively, you can clean
the directory of temprary files using "clean.bat" or you can build just one
of the wrappers by doing "build foundation," "build physx" or "build physics."
There is also a wrapper for PhysX cooking, but I have no idea whether it
works.

For more information, please see my web site:

http://www.enchantedage.com/python-physx

Jon Watte, October 8 2008

AttachmentSize
physx_swig_python_20090502.zip994.32 KB
physx_swig_dotnet_20090502.zip802.78 KB
physx_headers_20091029.zip3.15 KB

Comments

jwatte's picture

FWIW: I tried this again with

FWIW: I tried this again with SWIG 2.0.3, Visual Studio 2010 SP1, and Python 2.7 for Windows, and it still works fine! I'm a little bit surprised, even, because two years ought to lead to some kind of bit rot, but no problem that I've discovered so far. (Apart from updating the hard-coded paths in the build.bat script).

Java build

Hi,
i am a physics student and i really need a Java version of Physx. I would use python (actually i am a python coder) but for my tasks it's to slow :(

I tried to use the build.bat file and tried to adapt it to work in linux but i couldn't get it to build a java port.

Can someone help me?

Thanks,
Thomas

jwatte's picture

I haven't tried it at all on

I haven't tried it at all on Linux, and I'm not generally a Java fan, so I'm probably not the right person to ask. If anyone else is able, feel free to chime in!

Re-build the program

I'm trying to rebuild your program for my version and got stuck because the file "physx.h" cannot be found. Did I miss something or did you forget to include this header file in the package? Thank you.

jwatte's picture

I downloaded the Python

I downloaded the Python example, unzipped into an empty folder, set PYTHON_INCLUDE and PYTHON_LIB, and ran "build.bat" and it worked for me.
I have no idea why, though, because those headers are only in my regular build directory, which is not in the normal include path...
I've attached the headers in a zip file.

Collision events callback ?

Is that also handled ?

Also buildable for .net/C#

I just tried this wrapper for .NET/C#, by updating the build.bat file, and it seemed to work alright. I guess you could do the same thing to get PhysX for Java, etc.

Python Example is not working!!!!

Hi,
I've known python for couple of years. I tried everything to make your python example to work but NO SUCCESS. It runs correctly and it shows me a window but one second later the whole program crashes.
I tried to locate the error and I found that when the program try to load the model it will crash.

Just wondering if you know this problem.

Memphis

jwatte's picture

It works fine for me. When

It works fine for me. When you say it crashes, do you get a message?
Is there an exception that you can attach to with a debugger and get a stack trace?
Have you re-built from scratch for your version of Python, or are you using pre-built binaries?
Are you sure that the headers/version of Python the libraries are built for match the version of Python you have installed?
This goes for requirements like PyOGL or PyGame or whatever as well.