OgrePhysX - added destruction + Demo

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

OgrePhysX - added destruction + Demo

Post by Caphalor »

0.4 Update:
  • - included w0rm's MeshSplitter Tool (with his permission ;-))
    - added experimental destruction support (see this thread)
    - added destruction demo
    - fixed project file settings, see README
OgrePhysX 0.4 is only compatible with PhysX 3.1. I removed the old OgrePhysX versions.
I also added a binary Destruction Demo (Windows).

Download source archieve, including w0rms Mesh Splitter Tool.
Download binary destruction demo (Windows) and binary MeshSplitter Tool.


===============================================================================

I wrote a small PhysX wrapper and decided to share it, maybe somebody will find it useful. :)

Features:
- PhysX initialisation
- bind scene nodes or other "PointRenderable" implementations to actors
- mesh cooking
- raycasting
- destructible objects

I will probably implement more features in the future, but the main idea is to keep the wrapper small and simple.

The attached zip file contains the library and a small demo. You need PhysX 3.1 to use OgrePhysX.

Some example code:

Initialisation

Code: Select all

#include "OgrePhysX.h"

class MyGame
{
	...
	Ogre::SceneManager *mOgreSceneMgr;
	OgrePhysX::Scene *mPhysXScene;
}

//...
OgrePhysX::World::getSingleton().init();
OgrePhysX::World::getSingleton().setupOgreFramelistener();

mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main", mOgreSceneMgr);	
//...

Binding a node to an actor

Code: Select all

Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity *ent = mSceneMgr->createEntity("Cube", "cube.mesh");
node->attachObject(ent);

//create physical actor
OgrePhysX::Actor<PxRigidDynamic> actor = mPhysXScene->createRigidDynamic(ent, 50);

//setup binding
mPhysXScene->createRenderedActorBinding(actor, new OgrePhysX::NodeRenderable(node));

actor.setGlobalPosition(Ogre::Vector3(0, 20, 10));

Static actors / cooking PhysX meshes

Code: Select all

Ogre::Entity *ent = mSceneMgr->createEntity("Cube", "cube.mesh");
Actor<PxRigidStatic> actor = mPhysXScene->createRigidStatic(ent);

And finally, a screenshot:
Image
Last edited by Caphalor on Sat Jan 07, 2012 12:00 am, edited 5 times in total.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
talklittle
Gnoblar
Posts: 1
Joined: Wed Jan 13, 2010 3:11 am

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by talklittle »

Wow- thanks very much for this. Your sample code makes it look extremely easy to use! I'd been wanting something like this for my next project, something in between a full physics library and the Minimal Ogre Collision lib (http://www.ogre3d.org/forums/viewtopic.php?t=45267). So I will probably be incorporating this wrapper. Kudos.
neoranga974
Kobold
Posts: 25
Joined: Tue Apr 28, 2009 3:17 pm

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by neoranga974 »

Hi,

Interesting, nxOgre is definitely too complicated and incomplete.
avengre
Halfling
Posts: 83
Joined: Fri Nov 11, 2005 6:27 am
Location: Lancaster, PA
x 1
Contact:

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by avengre »

Any chance this still exists? I get a bad url.
User avatar
buckED
Greenskin
Posts: 133
Joined: Fri Feb 15, 2008 9:51 pm

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by buckED »

The downlaod works just fine for me.

Thanks by the way, Caphalor.
Many of life's failures are people who did not realize how close they were to success when they gave up.

~ Thomas Edison ~
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by jacmoe »

It's odd that the google code project gives a bad url - I guess he deleted it.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Caphalor »

I merged the code into my main project (but it's still a seperate dll), because there was little interest here. I don't know how up-to-date the code in the zip archive is, if you experience problems using it I can upload a new zip package. I didn't change much though.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
fruki
Gnoblar
Posts: 10
Joined: Sat Oct 09, 2010 9:24 pm

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by fruki »

Any demos regarding ragdoll? :)
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Caphalor »

I received two PMs concerning OgrePhysX and I decided to post a small update.

OgrePhysX 0.2
- mesh cooker now merges redundant vertices (credit goes to Benedikt, who is not registered in this forum)
- convex mesh cooking
- some minor fixes
- Ogre 1.8 support
- Visual Studio 2010 project files
Last edited by Caphalor on Sat Jan 07, 2012 12:01 am, edited 1 time in total.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
psx
Gnoblar
Posts: 15
Joined: Thu May 14, 2009 10:35 am

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by psx »

What I actually found is PhysX does not need any wrapper.
PhysX interface is straightforward and easy to use.
Its like .. creating wrapper around OGRE.
You just dont need that.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by betajaen »

I beg to differ.

PhysX is a harsh beast sometimes. There are plenty of things that need wrapping; cloth, soft bodies, cooking interface, debug visualization, etc.. I suppose they could be left out, but every time a person wants cloth; they'll have to write cloth binding code. I think it's best for everyone to use a standardised and well tested code than everyone rolling their own.
Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France
x 17

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Nodrev »

Very useful for lot of people I guess, nice and simple design, just a little remark, your source code really lacks of documentation, which could be really useful to PhysX beginners (which it's not my case :roll:) to understand how it works internally.
Its like .. creating wrapper around OGRE.
You just dont need that.
Ha ha, so fun, it makes me laugh a lot... before I start to cry! If only beginners do not fall in this trap all the times... It would save me lot of time in my actual work.
Trust me, a Ogre centered framework (I mean, a framework with Ogre's plugins for physics, sound, etc inside Ogre) is not the best way to do, when your project increase, you lost lot of time to make everything work together... but I'm a bit off-subject...

Anyway, this kind of little lib is perfect for a small project!
psx
Gnoblar
Posts: 15
Joined: Thu May 14, 2009 10:35 am

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by psx »

There are plenty of things that need wrapping; cloth, soft bodies, cooking interface, debug visualization, etc..
Hmm.. You're right.

I'm in the middle of a project now, which includes PhysX.

I think, I can get away with some utility functions.
But we'll see. Maybe I will end with wrapping.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Caphalor »

Very useful for lot of people I guess, nice and simple design, just a little remark, your source code really lacks of documentation, which could be really useful to PhysX beginners
I am sorry, but I wrote OgrePhysX mainly for myself and I don't have time to write a documentation. If you want support and documentation use NxOgre.
What I actually found is PhysX does not need any wrapper.
I think this is true to some degree. For example joints and the character controller are not wrapped in OgrePhysX, because I use them directly in my engine. But as betajaen said there are things that everybody needs who uses Ogre together with PhysX.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
User avatar
Roman
Halfling
Posts: 92
Joined: Sun Nov 02, 2008 3:49 pm
Location: Germany

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Roman »

Excellent work! I will try it out. Does it also run or can it be used/compiled on Linux with the old available PhysX version (v2.8.1 AFAIK) and the new PhysX release for Mac OS X?
Campi
Gnoblar
Posts: 14
Joined: Mon Feb 16, 2009 5:19 am
Location: Cuba

Re: OgrePhysX - a simple Ogre-PhysX binding

Post by Campi »

Hello
I have the same question that Roman. Is possible to use this wrapper in linux? and which version of PhysiX need to be used?
Anyone ??
THE SKY IS THE LIMIT!!!
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

PhysX 3

Post by Caphalor »

Sorry that I did not answer, I haven't read the forums for a while.
I use Windows and Visual Studio, so all I can say is: Download the PhysX Linux SDK and try it out.

I recently ported OgrePhysX to PhysX 3 and rewrote a lot of code. It is even less code now, because I removed some things like the contact listener.
Some guidelines/Notes:
  • You create Ogre and PhysX objects (nodes, entities, actors...), and you destroy them. OgrePhysX only synchronises Ogre with PhysX.
  • OgrePhysX has factory methods for some PhysX objects and an Actor class, but this is only syntactic sugar. You can also create the PhysX actors manually if you want.
  • There is a class "Ragdoll", but it only synchronises bone actors with bones and does not create actors or joints. There is no out-of-the-box ragdoll support yet.
  • The zip package only contains a project file for Visual Studio 2010 (it works for VS 11 developer preview too) and in addition to that OgrePhysX uses C++0x keywords (auto for iterators and nullptr).
  • In order to compile you probably have to change the include directories, I recommend editing PhysXIncludes.props using a text editor or the Visual Studio Property manager.
Now some code!

Initialisation

Code: Select all

OgrePhysX::World::getSingleton().init();

mPhysXScene = OgrePhysX::World::getSingleton().addScene("Main");  //you can also pass a PxSceneDesc here
Mainloop
Using a frame listener:

Code: Select all

OgrePhysX::World::getSingleton().setupOgreFramelistener();
Using a custom main loop:

Code: Select all

OgrePhysX::World::getSingleton().simulate(time);
OgrePhysX::World::getSingleton().syncRenderables();
Ogre::Root::getSingleton().renderOneFrame();
Inside simulate, OgrePhysX uses a fixed timestep to advance the simulation, so when time is higher than the timestep multiple steps are performed. Using a SimulationListener (see Scene::setSimulationListener) you can get notifications when OgrePhysX invokes PhysX each timestep (onSimulate is called between PxScene::simulate and PxScene::fetchResults, so you can do stuff while PhysX is working).
I use seperate threads for physics and rendering. Inside the physics loop I call simulate and inside the rendering loop I call syncRenderables.

Dynamic Actors

Code: Select all

OgrePhysX::Actor<PxRigidDynamic> actor =
   mPhysXScene->createRigidDynamic((OgrePhysX::Geometry::convexMeshGeometry(entity->getMesh())), myDensity);

OgrePhysX::PointRenderable *renderable =
   new OgrePhysX::NodeRenderable(myOgreNode);   //any class implementing PointRenderable is suitable
OgrePhysX::RenderedActorBinding *renderBinding =
   Main::Instance().GetPhysXScene()->createRenderedActorBinding(actor, renderable);

//Later: Destruction. Make sure to delete the renderable binding first.
mPhysXScene->destroyRenderedActorBinding(renderBinding);
delete renderable;
mPhysXScene->removeActor(actor);
Static Actors

Code: Select all

OgrePhysX::Actor<PxRigidStatic> actor =
   mPhysXScene->createRigidStatic(entity->getMesh());

//Later
mPhysXScene->removeActor(actor);
Of course this is only a quick overview and not a documentation.
Please tell me if you find any bugs, I didn't test everything (for example I don't use NodeRenderables or the FrameListener).
Feel free to extract parts of the code if you don't want to use the full library. I hope it will be useful! :-)

Edit: This only works for PhysX 3.0. For the current PhysX 3.1 see the first post.
Last edited by Caphalor on Sat Jan 07, 2012 12:02 am, edited 3 times in total.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
User avatar
betajaen
OGRE Moderator
OGRE Moderator
Posts: 3447
Joined: Mon Jul 18, 2005 4:15 pm
Location: Wales, UK
x 58
Contact:

Re: OgrePhysX - now for PhysX 3

Post by betajaen »

Awesome!

I'm glad there is a PhysX 3 wrapper for Ogre now.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: OgrePhysX - now for PhysX 3

Post by Mind Calamity »

<un-quote-ified>

Someone may upgrade NxOgre eventually ;)

That someone may or may not be you :)

Converting/Updating code is not as hard as writing code from the ground up, so it wouldn't be a tough task for most people here on the forums.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
Sapd
Gnoblar
Posts: 15
Joined: Fri Sep 09, 2011 3:19 pm

Re: OgrePhysX - now for PhysX 3

Post by Sapd »

Is this also compatible for PhysX 3.1?
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: OgrePhysX - now for PhysX 3

Post by Mind Calamity »

@Sapd:

Well I read in the release notes of PhysX 3.1 that some API changes have been made, and files have been renamed, so I think you might need to do a bit of re-factoring to get it working.

Personally I haven't used OgrePhysX, as I use NxOgre myself, but it shouldn't be that hard to update it to work with the new version of PhysX, as the code of OgrePhysX is not that big it should be a piece of cake if you have minimal programming knowledge (or maybe experience counts more in this case).

<Slightly off-topic>On the NxOgre side, a mountain of re-factoring would need to be done and probably some code changes in order to get it working with PhysX 3.x, it shouldn't be much of a problem, but would require a good amount of time to get it done. </SO-T>
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Re: OgrePhysX - now for PhysX 3

Post by Caphalor »

I ported OgrePhysX to PhysX 3.1 (this does not work with 3.0).
If you want to use it you probably have to build the physx extensions in debug mode because of this problem: http://forum-archive.developer.nvidia.c ... topic=6835

Edit: The latest version is 0.4, see first post.
Last edited by Caphalor on Sat Jan 07, 2012 12:03 am, edited 2 times in total.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
shadoslayer
Gnoblar
Posts: 3
Joined: Fri Oct 21, 2011 10:58 pm

Re: OgrePhysX - now for PhysX 3

Post by shadoslayer »

When i tried to compile the project, I got so many ambiguities that the compiler exited early. they were all between physx classes and ogrephysx classes by the same names. relatively new to C++, so how do I keep this from happening?
shadoslayer
Gnoblar
Posts: 3
Joined: Fri Oct 21, 2011 10:58 pm

Re: OgrePhysX - now for PhysX 3

Post by shadoslayer »

I gave up trying to use the 3.1 wrapper. how would i go about 'installing' the 3.0 wrapper sdk? i tried adding it to my solution. when I try to compile, i get a bunch of confusing errors:

Code: Select all

3>Scene.obj : error LNK2019: unresolved external symbol "public: void __thiscall OgrePhysX::World::syncRenderables(void)" (?syncRenderables@World@OgrePhysX@@QAEXXZ) referenced in function "public: virtual bool __thiscall OgrePhysX::World::OgreFrameListener::frameStarted(struct Ogre::FrameEvent const &)" (?frameStarted@OgreFrameListener@World@OgrePhysX@@UAE_NABUFrameEvent@Ogre@@@Z)
3>Scene.obj : error LNK2019: unresolved external symbol "public: void __thiscall OgrePhysX::World::simulate(float)" (?simulate@World@OgrePhysX@@QAEXM@Z) referenced in function "public: virtual bool __thiscall OgrePhysX::World::OgreFrameListener::frameStarted(struct Ogre::FrameEvent const &)" (?frameStarted@OgreFrameListener@World@OgrePhysX@@UAE_NABUFrameEvent@Ogre@@@Z)
3>Scene.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall OgrePhysX::NodeRenderable::setTransform(class Ogre::Vector3 &,class Ogre::Quaternion &)" (?setTransform@NodeRenderable@OgrePhysX@@UAEXAAVVector3@Ogre@@AAVQuaternion@4@@Z)
3>Scene.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall OgrePhysX::NodeRenderable::~NodeRenderable(void)" (??1NodeRenderable@OgrePhysX@@UAE@XZ) referenced in function "public: virtual void * __thiscall OgrePhysX::NodeRenderable::`scalar deleting destructor'(unsigned int)" (??_GNodeRenderable@OgrePhysX@@UAEPAXI@Z)
3>Scene.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall OgrePhysX::Ragdoll::sync(void)" (?sync@Ragdoll@OgrePhysX@@UAEXXZ)
3>Scene.obj : error LNK2019: unresolved external symbol "private: virtual __thiscall OgrePhysX::Ragdoll::~Ragdoll(void)" (??1Ragdoll@OgrePhysX@@EAE@XZ) referenced in function "private: virtual void * __thiscall OgrePhysX::Ragdoll::`scalar deleting destructor'(unsigned int)" (??_GRagdoll@OgrePhysX@@EAEPAXI@Z)
on top of this, when I tried compiling the wrapper on it's own, it seems to get to the end, and it generates .dll's and .lib's, but it gives me the following errors:

Code: Select all

1>  OgrePhysX.vcxproj -> (Path to OgrePhysx)\..\..\lib\OgrePhysX_d.dll
1>  The system cannot find the path specified.
1>          0 file(s) copied.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "copy ..\..\lib\OgrePhysX_d.dll ..\..\bin\
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: :VCEnd" exited with code 1.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Re: OgrePhysX - now for PhysX 3

Post by Caphalor »

I am sorry that you experience so many problems!

You can fix the second problem easily: Just remove the post build event.
Project Properties -> Build Events -> Post-Build Step

When linking OgrePhysX to your project, did you add OgrePhysX.lib (Release) and OgrePhysX_d.lib (Debug) as input librarys in your project settings? You can also add the OgrePhysX code directly to your project (it isn't very much) if you want.

Are you sure that you compiled the 3.1 wrapper against PhysX 3.1? It does not work with 3.0.
Image
Generated with vBaum - voxel based procedural geometry generator with python interface.
Post Reply