Page 1 of 29

IrrPhysx 0.2 - Nvidia Physx 2.8.1 wrapper

Posted: Mon Oct 27, 2008 3:41 pm
by JP
Image

Website
Forum

Having used Physx on PS3 and got rather cosy with it I decided that it would be my physics engine of choice on PC too. I noticed that there weren't really any 'easy' to use wrappers/integrations with Irrlicht (there were tutorials and other ones which seemed to require rather large changes and code duplication) so I thought I'd have a go at writing a simple to use wrapper.

So the idea of this wrapper is to completely abstract away the Physx SDK from the user so they needn't get down and dirty with it. Instead they just have to use my simple interface. This should prove pretty useful for people not used to physics engines and external libraries but may not be so useful for people wanting to get really ambitious with their physics, at least not in its current state.

So what do you need to develop with IrrPhysx? First off you need IrrPhysx itself (dur!), which is compiled with Irrlicht 1.4.2 and Nvidia Physx 2.8.1, so you'll need those two as well. When developing Physx applications you also need to install the Physx system software. It turns out that the latest system software doesn't actually work with 2.8.1, it just complains about CUDA DLL errors when you try and run a Physx application. FMX informed me that system software 8.06.12 is the best one to go for, seems to do the trick!

It might also be a good idea to read the Physx EULA to be sure of any restrictions/requirements of using Physx.

Image

Anyway, here's the download!
IrrPhysx 0.2 SDK for Irrlicht 1.4.2 ( 12mb )
IrrPhysx 0.2 SDK for Irrlicht 1.5 ( 12mb )

IrrPhysx 0.2 Game Example for Irrlicht 1.4.2 ( 3mb )
IrrPhysx 0.2 Game Example for Irrlicht 1.5 ( 3mb )

I've used MSVC 2008 to compile the code but I reckon i've set it up properly to not require the MSVC redistibutables so it should work fine on 'any' PC. If you're just running Physx applications you don't actually need the Physx system software, that's just for developing, but you will require a small installation. For this I reckon the supplied Physx game installer should do the trick, be a guinea pig for me and let me know if there's any problems!


The following example is provided above, seperate from the SDK

[New]Game Example:

Image

This example shows you how to use IrrPhysx in a hopefully sensible way, read through the source and comments to understand the advice and feel free to post questions if you don't understand something.

This example will be updated along with each new version of IrrPhysx. At the moment the 'character controller' is just a sphere which isn't the best way of controlling characters in Physx but i've not got round to wrapping up the character controller stuff yet, that will come soon, when it does i'll update this example to show how to use it.

In the example you can move around, knock objects over, shoot objects, jump, throw spheres and then shoot them to cause explosions.


The SDK contains the source for both the library and the examples, documentation in .CHM form and the following examples....

[New]Mesh Example:

Image

This example shows you how to create convex mesh objects (an object which encloses a shape in a convex manner) and triangle mesh objects (a static object made from the triangles of a mesh).


[New]Explosion Example:

Image

This example shows you how to create explosions with IrrPhysx. The explosion is like an expanding sphere and anything within the sphere has the force of the explosion applied to it.


[New]Raycast Example:

Image

This example shows you how to do raycasting, similarly to the Irrlicht collision tutorial.

The intersection point of the raycast is shown with the billboard and a blue line also shows the normal of the surface which was hit.


[Updated]Boxes Example:

Image

This example shows you how to simple create some boxes and then knock them around... kinda like the 'Hello World' of physics engines I guess!

The large box which is present on start-up is a static box which has been created by passing a density of 0 (a density that is bigger than 0 will result in a box being moveable).

[Update] The box created by pressing W is now created with random dimensions between 1 and 10.... ground breaking.... :lol:


[Updated]Heightfield Example:

Image

This example shows how to make some terrain, it reproduces the terrain produced by ITerrainSceneNode. I apologise for the horrific lighting on the terrain... it doesn't seem to be behaving properly but I can't really be bothered to keep picking away at it! :lol:

[Update] There's now a second way of creating heightfields. This new version just takes an s16 array of height values which means you can now create heightfields from sources which aren't ITerrainSceneNodes. The example now shows how to use this function to create a heightfield from a Milkshape3D-created heightfield mesh.


[Updated]Multi-Shape Example:

Image

This example shows how you can make more complex shapes than a simple box, by using the boxes as building blocks. It takes the individual mesh buffers of a model and makes a bounding box and keeps them all joined together. As you may be able to see from the picture, each of the table's individual sections has a different texture, this is to force each section to be put into a different mesh buffer so that it's easy to form bounding boxes around the pieces.

At this point I shall point out that when creating physics objects for your game you should rarely use the mesh data of the models that you use for rendering. When rendering you want uber-next-gen kewl looking models so they're much higher poly than is needed for physics calculations. So for this reason you should create a hugely lower poly version of your model to use for physics calculations and this is what the multi-coloured table can be thought of as. You wouldn't want to render it as 5 different mesh buffers or have 5 textures for it when 1 would suffice so once you'd created the table physics object with this model it could be removed and you could load a much nicer looking table for the actual rendering.

A slight problem in this example is if you create two multi-shape objects on top of each other they can become joined together and start jiggling around frantically. This shouldn't really happen in a game as you'd ensure you weren't creating objects on top of each other but it can happen in the example as you have free reign over quickly creating objects in the same place.

[Update] The example now shows you how to create capsule objects,. Pressing K creates a randomly sized capsule for you. The previous example had a 'double box' object you could create by pressing W, this has now been changed to an object constructed from a box, a sphere and a capsule.


[Updated]Cloth Example:

Image

This example shows how to create cloth objects. Unfortunately a bug appeared at some point during development which means that if you create a flag in the example and then exit it will crash on device->drop(). I haven't been able to track down the reason for the crash but will obviously continue to do so! You can also create a cloth version of good ol' Sydney and knock her about a bit. She will have internal pressure so be kinda like a bag of air, it's not actually that easy to see in the example.. she's not the best mesh to use to show off this, but there you go!

I'll point out that the flag cloth is actually created from a hill plane mesh and as such it is one-sided. So this means it's only lit from one side and with backface culling off it looks the same from both sides so if it gets knocked around so that it's facing away from the light then both sides are black. This is just a limitation of single-sided meshes!

I shall also point out that currently in Physx, cloth collision is done on a per-vertex basis rather than per-triangle. So this means that the cloth can sometimes penetrate surfaces and cloths will often be able to occupy the same space as each other (try creating two sydneys in quick succession and you'll see they don't actually collide with each other in any way as their vertices sort of end up missing each other). It does seem, though, that triangle collision detection will be available in a future release of Physx.

Another thing to note about cloth is that if you want to use internal pressure on them then the mesh must be completely enclosed so have to holes in it that the air could leak out of. Also when creating cloth from a mesh the entire mesh should be joined otherwise it will fall apart when the simulation is run. You may notice that i've removed Sydney's fringe as this was modelled seperately to her body and so would fall off her head. And another thing is that currently only the first mesh buffer is used when creating the cloth object, I suppose this won't actually change because otherwise the seperate mesh buffers would fall apart from each other anyway.

[Update] You can now create tearable cloth in this example. Pressing T will create a tearable cloth attached to the green static box and the cloth will have a small box attached to it which will then fall down and cause the cloth to tear.

The tearing does look a bit ugly, this is because of the low poly count in the cloth mesh. Tearing just rips the vertices apart so if you have a higher poly count you're more likely to get nicer looking tearing!


Contact Report Example:

Image

This example shows you how you can use a callback function to be informed about object collisions. Within the little 'arena' you can create a load of random spheres and when they hit each other they will magically fizzle out of existence. Magic!


Thanks go to Dark_Kilauea for his useful little grid scene node.

Posted: Mon Oct 27, 2008 5:42 pm
by Virion
this is awesome. :)

Posted: Mon Oct 27, 2008 5:48 pm
by Halifax
Wow, great work JP. Now you have two amazing Irrlicht middleware projects!

Posted: Mon Oct 27, 2008 5:50 pm
by RedDragCZ
Wow, it looks really incredible.
Since I read you are planning somethin like this I couldn't wait to see it .. and now it is even much more better than what I was awaiting. Big thanks to you! :)

Btw, under what license you are releasing it? I haven't found it anywhere ..

Posted: Mon Oct 27, 2008 6:12 pm
by night_hawk
Awesome! Let's see how you handle stuff in PhysX.

As for the cloth exit issue, I had that too. Stood 3 days to try to fix it, to no avail.

Posted: Mon Oct 27, 2008 7:01 pm
by JP
Thanks for the kind comments guys :D

The project is obviously still in its early days i think i've only been working on it about a week whilst at work. There's still lots of functionality to add in! I'll be working on a little demo app next i think which will show how to use the library properly in a game situation rather than just in the examples.

RedDragCZ, the licence is, and probably has to be, a free for all. I'll try to remember to put a proper licence in there though i might have to figure out how to word it properly seeing as it uses Physx which might alter things a bit, i don't know! But anyway, it'll always be free to use, though still tied by the Physx EULA which should be closely looked at and followed. It would be nice if you put some credit in your project if you use it, just say somewhere that it uses IrrPhysx so the name gets out there and my worldwide fame will grow :twisted:

Halifax, i'm loving the irrlicht middleware, it's great fun working with Irrlicht again, i got a bit out of touch whilst making my PS3 graphics engine but having struggled through that so much it's so nice to be back with irrlicht and its feature set and i've decided to definitely use it for my up coming PC project which is in the planning stage... gonna plan it properly and make sure the development goes well! Basically IrrPhysx is a little something for that which again can be shared with the community!

night_hawk... you fill me with such confidence i might as well not bother trying to fix this bug! :lol: It's bizarre... if i make the flag cloth from a sydney mesh it works fine, no crash. If i make it from a hill plane mesh or an identically created mesh from milkshape it crashes.. if i make it from a mesh which is a 'cut down' version of sydney to look a bit like a hill plane mesh then it works.... So it's definitely something to do with the mesh... somehow... but it's not the fact that the mesh is loaded, it's the fact it's used within IrrPhysx... it's horrible... There must be some simple solution so i'll keep plugging away at it!

Posted: Mon Oct 27, 2008 7:55 pm
by MasterGod
WoW JP, you never cease to amaze me..
Wow..

Posted: Mon Oct 27, 2008 8:23 pm
by frostysnowman
This is cool. I have made my own private Irrlicht + PhysX framework that's working pretty well, so I don't think I'll use this- but I will certainly check it out anyway! Is there Character Controller support in this release?

Posted: Mon Oct 27, 2008 8:32 pm
by Seven
frostysnowman wrote:This is cool. I have made my own private Irrlicht + PhysX framework that's working pretty well, so I don't think I'll use this- but I will certainly check it out anyway! Is there Character Controller support in this release?
ditto......and i cannot get the controlelr class to work properly so any examples would be fantastic!

Posted: Mon Oct 27, 2008 8:39 pm
by frostysnowman
I got the character controller in PhysX to work with Irrlicht, so if you need any help JP you can ask. I just wanted to see how you did it (if you did it).

Posted: Mon Oct 27, 2008 8:39 pm
by twilight17
brilliant. :shock:

Posted: Mon Oct 27, 2008 9:43 pm
by Dark_Kilauea
Nice job JP, I'll have to play around with this someday.

One note, does it support connecting to the PhysX Visual Debugger tool?

Posted: Mon Oct 27, 2008 11:16 pm
by fmx
I just noticed you mentioned me :P

for anyone else having problems with CUDA errors using the latest PhysX System-Software, just revert to the older SystemSoftware as pointed out in the first post.

really great stuff tho, should encourage more people to try PhysX!
:D

Posted: Tue Oct 28, 2008 8:22 am
by JP
No character control support in this version, there's still lots of things to do, but there certainly will be in the future! I got the character controllers working pretty well on PS3 so the code should work just the same on PC. Obviously i'll just have to find a nice way to wrap it up.

Physx Visual Debugger is not something i've actually looked at yet but i'll look into it as i'm sure it's damned useful and being able to use it would be great!

Posted: Tue Oct 28, 2008 2:36 pm
by trivtn
Nice!,thank JP. I can't wait.