IrrPhysx 0.2 - Nvidia Physx 2.8.1 wrapper
Thank you for this informations.
The samples in the 'Trainingprograms' folder are very well for the great principles.
The differences between the versions 2.7.x and versions x 2.8. are often not so important,
and the transposition of codes is relatively simple in most cases.
I even managed to adapt all my codes version 2.3.1 to version 2.8.1 without real problem and without much efforts.
The samples in the 'Trainingprograms' folder are very well for the great principles.
The differences between the versions 2.7.x and versions x 2.8. are often not so important,
and the transposition of codes is relatively simple in most cases.
I even managed to adapt all my codes version 2.3.1 to version 2.8.1 without real problem and without much efforts.
Strength and wisdom.
Admin of the http://www.irrlicht.fr and dad of N3xtD.
Sorry for my poor English.
Admin of the http://www.irrlicht.fr and dad of N3xtD.
Sorry for my poor English.
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
FMX can also answer pretty much every question asked about this i should think as we're always chatting about it
Indeed he's right it just works out the box, just like IrrAI really, that's why i made it, i saw other attempts which required Irrlicht to be edited or parts of the Irrlicht source to be copied but most people round here probably don't want to be messing around with stuff like that so i'm not doing any irrlicht editing!
I said that 0.2 would be out last week but apparently i lied.... should be out this week though, if i can limit my time playing Bioshock a bit....
Indeed he's right it just works out the box, just like IrrAI really, that's why i made it, i saw other attempts which required Irrlicht to be edited or parts of the Irrlicht source to be copied but most people round here probably don't want to be messing around with stuff like that so i'm not doing any irrlicht editing!
I said that 0.2 would be out last week but apparently i lied.... should be out this week though, if i can limit my time playing Bioshock a bit....
thx.. excelent wrapper,
This and IrrNewt , are the best Phys wrappers ever...!!!
Thx....
This and IrrNewt , are the best Phys wrappers ever...!!!
Thx....
Last edited by link3rn3l on Fri Nov 14, 2008 9:54 pm, edited 1 time in total.
Bennu (Best 2d and 3D dev-tool)
http://bennupack.blogspot.com
Pixtudio (Best 2D development tool)
http://pixtudiopack.blogspot.com
Bennu3D(3D Libs for bennu)
http://3dm8ee.blogspot.com/
Colombian Developers - Blog:
http://coldev.blogspot.com/
http://bennupack.blogspot.com
Pixtudio (Best 2D development tool)
http://pixtudiopack.blogspot.com
Bennu3D(3D Libs for bennu)
http://3dm8ee.blogspot.com/
Colombian Developers - Blog:
http://coldev.blogspot.com/
Righto! 0.2 is up now! Seee the first post for download links and more info on the examples.
below is a changelog / some release notes. I've put important bits that i'd like some feedback on in bold, the rest of it might be a bit much to wade through
Added IPhysxManager::setGravity(vec) which allows you to change the gravity at any points
Fixed up some inaccuracies in the heightfield. Basically Physx likes to use signed shorts for its heightmap data whereas Irrlicht likes using floats... obviously that's not hugely compatible so I put in a multiplier to the height values (100) to fake a float to 2 decimal places which is then divided out by Physx later on which produces a very good approximation.
The crashing cloth example seems to have been fixed... at least with the meshes i'm using... I'm using a mesh created in Milkshape3D which is just a flat plane of 6x6. That results in no exit crash but using an 8x8 grid does... very bizarre.. must be a memory bug somewhere. I can still make the cloth example crash if I create around 100 tearable meshes but that could just be down to running out of memory or something... it appears to crash in PhysxCore.dll, I shall investigate further!
Added ConvexMesh and TriangleMesh support, check out the Mesh Example to see those in action.
Added IClothPhysxObject for better/more sensible access to Cloth functions. Hence moved attachToObject & applyWindToCloth from IPhysxManager. There's also lots of other cool new functions in there to check out.
If you make a static compound object (multishape bounding box with 0 density) this is apparently bad for performance and you're warned in the console. instead use a triangle mesh object
Added IPhysxMesh which changes IPhysxManager::createCloth() (used in tri/convex meshes also). Basically these meshes have to be 'cooked' (rearranged into a Physx friendly format) before creating an object and this can take a fair bit of time (just long enough to not be good to do whilst running your game) and so we do it once for each mesh and then reuse that cooked mesh when creating objects.
renamed the old createBox/createCloth etc functions to createBoxObject/createClothObject to not conflict with createConvexMesh etc
Added tearable param to createClothObject to set the cloth to tearable. You also have to have created the cloth IPhysxMesh as tearable but that doesn't mean your IClothPhysxObject has to be tearable if you don't want it to be so you can use the same IPhysxMesh for the same pieces of cloth with one cloth object being tearable and one not.
Added capsule object support (see MultiShape Example)
Added raycasting functions. IPhysxManager::raycastAllObjects(line3df) && IPhysxManager::raycastClosestObject(line3df). first return array of objects hit, latter returns only the first object hit (see Raycast Example). Note that cloths are not included in these raycasts but can be raycasted individually via IClothPhysxObject.
Added SSceneDesc parameter to createPhysxManager and resetScene(). this allows you to setup the Physx scene with some useful parameters. currently the params just optimise scene queries such as raycasting, you probably won't really need to use them unless your performance becomes poor from lots of raycasting.
Changed multishapeboundingboxobject function to multishapeobject and allowed not only boxes but sphere and capsule shapes to be created (updated Multishape example)
Heightfield example shows a new type of heightfield creation now as well, check the first post for info on this. Note that rotation doesn't work nicely on the ITerrainSceneNode type... gona work on that more for 0.3, should be ok for now, heightmaps aren't normally rotated much anyway and you can line them up manually if need be! (note that the function now takes the terrain node rather than its parameters, this should reduce API breakage with the hopeful fix for rotation)
for the addition of capsule objects i've created a VERY simple capsule scene node which is just a butchered sphere scene node bascially. It has bad lighting (due to the normals being created as if it were a sphere) and the texture mapping is all wrong around the midsection, but what the hell.. it does the trick for the examples and if you need a better solution then you can use meshes created in a modelling program or improve upon my capsule scene node.
added IPhysxObject::setLinear/AngularVelocity() & ::setLinear/AngularDamping() (check the docs for notes on how this affects the object if it's a cloth object)
All the examples now have a param editor so you change the gravity and other parameters easily. the default gravity of -9.81f doesn't look at all realistic in the examples, try -60 , or even a positive number! make sure you use a negative for conventional style gravity of downwards! within IrrPhysx you can have 3D gravity but in the param editor i'm just letting you change it on the Y axis. press Q to release the mouse from controlling the camera so that you can change the values. Note that increased gravity seems to give worse performance in certain situations... probably due to harsher forces being computed. I'm going to investigate other options for getting realistic looking gravity effects.
The second terrain creation is bit messed up on edge in the example.. i'll fix it in time hopefully... if any one has ideas as to why it might be happening then speak up!
I've added a parameter to createPhysxManager() to disable hardware usage. This is useful for a game's server and client running on the same machine and you'd want to let the client use the hardware so you can set the server to not use the hardware as the first application to try to use the hardware will get access and lock all others out.
I've pointed this out in the examples and probably in this thread before but you shouldn't add objects during the simulation. The contact callback is called during simulation as the contacts are detected so you shouldn't add objects from within the contact callback. You're allowed to remove objects during the simulation because i've buffered the removal of objects if a simulation is in process so that they get removed upon the start of the next simulation rather than during it.
Right, that's about it i think, let me know if there's any problems!
[ADDITIONAL]
Here's some stuff about the game example i forgot to mention:
The game example shows you how to read the current scene and create physx objects from the nodes, so it's good if you're using .irr files. In the example i've used the node's ID in IrrEdit to specify the density of the physx object and i've tagged the name with '(Cloth)', '(Trimesh)' or '(Convex)' to dictate object type to create and included 'Flag' in an objects name marked with '(Cloth)' to make it wave in the wind.
XXX_physx.ms3d meshes are loaded and used for some physx objects instead of the render mesh and then later removed as they are no longer necessary after the objects are created. Note that these meshes don't have any textures on them as they're not for rendering so the texture cache doesn't get bogged down with any unecessary textures. For convex meshes we don't really need a physx version as it just takes the vertices and forms a convex shape around it (a shape that completely encloses the verts using minimal polygons) so doesn't care about the mesh's complexity.
I've got a simplistic physx mesh cache implemented, i'm leaving this up to you to handle to give the best flexibility but providing this simple mesh cache for those who aren't the best coders! note that all cloth meshes are created tearable you can then decide whether to make the actual cloth object created using the mesh tearable or not (still uses 3x memory though so you might want to change the mesh cache from creating all cloths tearable).
Do people agree that the physx mesh cache should be left up to the user like this? Or should i sort of nick IMeshCache from Irrlicht and implement one within IrrPhysx? I guess i could do that fairly easily...
press R to reset the scene, this shows you how you can wipe out the scene and reload a new one for a different level
ote that you can't shoot the floor beneath you as you hit the camera sphere (press V to see it). i'll add features to do masking on objects when raycasting later.
Note also that you can't see the impact effect on parts of the house (window and door frame) due to the physx mesh version not enclosing those parts of the render mesh so the mesh is rendered over the impact effect. basically anything you'd want to be shot would have to be enclosed so you could make the mesh bigger to enclose it all or more complex to enclose the necessary bits.
Shooting the flag tears it at the intersected vertex and also adds a bit of velocity to make it appear like it's been shot.
below is a changelog / some release notes. I've put important bits that i'd like some feedback on in bold, the rest of it might be a bit much to wade through
Added IPhysxManager::setGravity(vec) which allows you to change the gravity at any points
Fixed up some inaccuracies in the heightfield. Basically Physx likes to use signed shorts for its heightmap data whereas Irrlicht likes using floats... obviously that's not hugely compatible so I put in a multiplier to the height values (100) to fake a float to 2 decimal places which is then divided out by Physx later on which produces a very good approximation.
The crashing cloth example seems to have been fixed... at least with the meshes i'm using... I'm using a mesh created in Milkshape3D which is just a flat plane of 6x6. That results in no exit crash but using an 8x8 grid does... very bizarre.. must be a memory bug somewhere. I can still make the cloth example crash if I create around 100 tearable meshes but that could just be down to running out of memory or something... it appears to crash in PhysxCore.dll, I shall investigate further!
Added ConvexMesh and TriangleMesh support, check out the Mesh Example to see those in action.
Added IClothPhysxObject for better/more sensible access to Cloth functions. Hence moved attachToObject & applyWindToCloth from IPhysxManager. There's also lots of other cool new functions in there to check out.
If you make a static compound object (multishape bounding box with 0 density) this is apparently bad for performance and you're warned in the console. instead use a triangle mesh object
Added IPhysxMesh which changes IPhysxManager::createCloth() (used in tri/convex meshes also). Basically these meshes have to be 'cooked' (rearranged into a Physx friendly format) before creating an object and this can take a fair bit of time (just long enough to not be good to do whilst running your game) and so we do it once for each mesh and then reuse that cooked mesh when creating objects.
renamed the old createBox/createCloth etc functions to createBoxObject/createClothObject to not conflict with createConvexMesh etc
Added tearable param to createClothObject to set the cloth to tearable. You also have to have created the cloth IPhysxMesh as tearable but that doesn't mean your IClothPhysxObject has to be tearable if you don't want it to be so you can use the same IPhysxMesh for the same pieces of cloth with one cloth object being tearable and one not.
Added capsule object support (see MultiShape Example)
Added raycasting functions. IPhysxManager::raycastAllObjects(line3df) && IPhysxManager::raycastClosestObject(line3df). first return array of objects hit, latter returns only the first object hit (see Raycast Example). Note that cloths are not included in these raycasts but can be raycasted individually via IClothPhysxObject.
Added SSceneDesc parameter to createPhysxManager and resetScene(). this allows you to setup the Physx scene with some useful parameters. currently the params just optimise scene queries such as raycasting, you probably won't really need to use them unless your performance becomes poor from lots of raycasting.
Changed multishapeboundingboxobject function to multishapeobject and allowed not only boxes but sphere and capsule shapes to be created (updated Multishape example)
Heightfield example shows a new type of heightfield creation now as well, check the first post for info on this. Note that rotation doesn't work nicely on the ITerrainSceneNode type... gona work on that more for 0.3, should be ok for now, heightmaps aren't normally rotated much anyway and you can line them up manually if need be! (note that the function now takes the terrain node rather than its parameters, this should reduce API breakage with the hopeful fix for rotation)
for the addition of capsule objects i've created a VERY simple capsule scene node which is just a butchered sphere scene node bascially. It has bad lighting (due to the normals being created as if it were a sphere) and the texture mapping is all wrong around the midsection, but what the hell.. it does the trick for the examples and if you need a better solution then you can use meshes created in a modelling program or improve upon my capsule scene node.
added IPhysxObject::setLinear/AngularVelocity() & ::setLinear/AngularDamping() (check the docs for notes on how this affects the object if it's a cloth object)
All the examples now have a param editor so you change the gravity and other parameters easily. the default gravity of -9.81f doesn't look at all realistic in the examples, try -60 , or even a positive number! make sure you use a negative for conventional style gravity of downwards! within IrrPhysx you can have 3D gravity but in the param editor i'm just letting you change it on the Y axis. press Q to release the mouse from controlling the camera so that you can change the values. Note that increased gravity seems to give worse performance in certain situations... probably due to harsher forces being computed. I'm going to investigate other options for getting realistic looking gravity effects.
The second terrain creation is bit messed up on edge in the example.. i'll fix it in time hopefully... if any one has ideas as to why it might be happening then speak up!
I've added a parameter to createPhysxManager() to disable hardware usage. This is useful for a game's server and client running on the same machine and you'd want to let the client use the hardware so you can set the server to not use the hardware as the first application to try to use the hardware will get access and lock all others out.
I've pointed this out in the examples and probably in this thread before but you shouldn't add objects during the simulation. The contact callback is called during simulation as the contacts are detected so you shouldn't add objects from within the contact callback. You're allowed to remove objects during the simulation because i've buffered the removal of objects if a simulation is in process so that they get removed upon the start of the next simulation rather than during it.
Right, that's about it i think, let me know if there's any problems!
[ADDITIONAL]
Here's some stuff about the game example i forgot to mention:
The game example shows you how to read the current scene and create physx objects from the nodes, so it's good if you're using .irr files. In the example i've used the node's ID in IrrEdit to specify the density of the physx object and i've tagged the name with '(Cloth)', '(Trimesh)' or '(Convex)' to dictate object type to create and included 'Flag' in an objects name marked with '(Cloth)' to make it wave in the wind.
XXX_physx.ms3d meshes are loaded and used for some physx objects instead of the render mesh and then later removed as they are no longer necessary after the objects are created. Note that these meshes don't have any textures on them as they're not for rendering so the texture cache doesn't get bogged down with any unecessary textures. For convex meshes we don't really need a physx version as it just takes the vertices and forms a convex shape around it (a shape that completely encloses the verts using minimal polygons) so doesn't care about the mesh's complexity.
I've got a simplistic physx mesh cache implemented, i'm leaving this up to you to handle to give the best flexibility but providing this simple mesh cache for those who aren't the best coders! note that all cloth meshes are created tearable you can then decide whether to make the actual cloth object created using the mesh tearable or not (still uses 3x memory though so you might want to change the mesh cache from creating all cloths tearable).
Do people agree that the physx mesh cache should be left up to the user like this? Or should i sort of nick IMeshCache from Irrlicht and implement one within IrrPhysx? I guess i could do that fairly easily...
press R to reset the scene, this shows you how you can wipe out the scene and reload a new one for a different level
ote that you can't shoot the floor beneath you as you hit the camera sphere (press V to see it). i'll add features to do masking on objects when raycasting later.
Note also that you can't see the impact effect on parts of the house (window and door frame) due to the physx mesh version not enclosing those parts of the render mesh so the mesh is rendered over the impact effect. basically anything you'd want to be shot would have to be enclosed so you could make the mesh bigger to enclose it all or more complex to enclose the necessary bits.
Shooting the flag tears it at the intersected vertex and also adds a bit of velocity to make it appear like it's been shot.
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
Intersting.. hadn't thought of doing that! I'll try it out...
Incidentally the density and masses of all the objects isn't exactly right... some of them are ok but some aren't realistic (like the tables) so they need tweaking a fair bit but i don't really have the time to spend doing that unfortunately! I'll give it a go though to try and get it behaving as well as possible!
Incidentally the density and masses of all the objects isn't exactly right... some of them are ok but some aren't realistic (like the tables) so they need tweaking a fair bit but i don't really have the time to spend doing that unfortunately! I'll give it a go though to try and get it behaving as well as possible!
-
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
Btw, one reason the default gravity of -9.8 looks odd is because PhysX by default uses a 1 unit = 1 meter scale for it's calculations. When used in something like the traditional Quake 3 level, where 1 meter is somewhere between 16 to 32 units, then things will look like they are falling in slow motion.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Jallen
there are plenty of samples which come with the SDK, with clear comments and aims. The documentation file is also very good.
you could also try the Training-Programme mentioned by tmyke (a few posts above); you will need to download an old version of the sdk to get it though, because they don't provide it anymore (link again: http://developer.download.nvidia.com/Ph ... K_Core.exe )
Dark_Kilauea
I swear i tried using 1 unit = 1 meter the first time I ever used PhysX, and gravity just didn't seem to behave as you'd expect it to.
Setting Mass/Densities is another problem because there seems to be a serious range limitation.
According to the PhysX SDK, they suggest using units consistent with Newtonian physics equations (kg, m, seconds, etc) but don't actually say anywhere "1 meter = 1 physx unit" so its still debatable.
there are plenty of samples which come with the SDK, with clear comments and aims. The documentation file is also very good.
you could also try the Training-Programme mentioned by tmyke (a few posts above); you will need to download an old version of the sdk to get it though, because they don't provide it anymore (link again: http://developer.download.nvidia.com/Ph ... K_Core.exe )
Dark_Kilauea
I swear i tried using 1 unit = 1 meter the first time I ever used PhysX, and gravity just didn't seem to behave as you'd expect it to.
Setting Mass/Densities is another problem because there seems to be a serious range limitation.
According to the PhysX SDK, they suggest using units consistent with Newtonian physics equations (kg, m, seconds, etc) but don't actually say anywhere "1 meter = 1 physx unit" so its still debatable.
For reference, I have the latest system software (08.09.04) and 0.1 worked just fine (haven't tried 0.2 yet). My system software probably came from my last nvidia display driver install (since I have a PhysX-capable 3d card).It turns out that the latest system software doesn't actually work with 2.8.1
BTW Does anyone know if you have to do anything special to use display card-accelerated physx? I've assumed up-to-now that it's automatic, but I haven't really looked into it yet...
Irrlicht Demos: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=45781
The application decides automatically if hardware acceleration can be used, but the code has to be compiled to allow hardware-simulation to be enabled in the first-place.
I think there's a flag which needs to be set during the PhysX scene initilisation to enable it; not sure if there's anything else (different) that needs to be done.
not sure either if threading has to be taken into consideration.
(not sure about a lot of things actually )
but AFAIK the SDK demo's are NOT enabled to use hardware by default, so you're going to have to edit and recompile them to see any performance gain.
JP, could you look into adding some-sort of system into irrPhysX to allow (easy) toggling of hardware-accelleration?
IMO it *should* be enabled by default, otherwise it wont get used even if it is available.
I think there's a flag which needs to be set during the PhysX scene initilisation to enable it; not sure if there's anything else (different) that needs to be done.
not sure either if threading has to be taken into consideration.
(not sure about a lot of things actually )
but AFAIK the SDK demo's are NOT enabled to use hardware by default, so you're going to have to edit and recompile them to see any performance gain.
JP, could you look into adding some-sort of system into irrPhysX to allow (easy) toggling of hardware-accelleration?
IMO it *should* be enabled by default, otherwise it wont get used even if it is available.
Looks like I'm already getting hw acceleration by default in the 0.2 demos. If I run the boxes example I get the message "PhysX accelerator hardware found, simulation will be done in hardware" in the console. Nice.fmx wrote:The application decides automatically if hardware acceleration can be used, but the code has to be compiled to allow hardware-simulation to be enabled in the first-place.
I think there's a flag which needs to be set during the PhysX scene initilisation to enable it; not sure if there's anything else (different) that needs to be done.
not sure either if threading has to be taken into consideration.
(not sure about a lot of things actually )
but AFAIK the SDK demo's are NOT enabled to use hardware by default, so you're going to have to edit and recompile them to see any performance gain.
JP, could you look into adding some-sort of system into irrPhysX to allow (easy) toggling of hardware-accelleration?
IMO it *should* be enabled by default, otherwise it wont get used even if it is available.
BTW The game example crashes for me. I'll make a debug build and see what's wrong...
Irrlicht Demos: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=45781
sorry JP i'm not able to run your demo as i'm running ubuntu now.
My company: http://www.kloena.com
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info
My blog: http://www.zhieng.com
My co-working space: http://www.deskspace.info