Page 2 of 4

Re: OgrePhysX - now for PhysX 3

Posted: Wed Nov 02, 2011 10:47 am
by wilsonwing
Hi, Caphalor
Just want to say thank you for such a great wrapper.
It has good framwork and nice code, easy to understand.
It took me from beginner of PhysX to now learn more about it.
OgrePhysX wrapper helps a lot, THANKS!

Re: OgrePhysX - now for PhysX 3

Posted: Sat Dec 17, 2011 4:55 am
by HumberGamer66
Hey I was wondering if someone could create a demo project using the newest version of OgrePhysX, or if there is a demo from the newest version of the OgrePhysX can someone while point me to it?

I've tried porting the original Demo from OgrePhysX_0.2 version, but the createActor function isn't in the newest version to create a plane.

Would using the create function work?


Thanks for the help.

Re: OgrePhysX - now for PhysX 3

Posted: Sat Dec 17, 2011 8:40 pm
by Caphalor
Hi,
it is called createRigidStatic/createRigidDynamic now, see my sample code for 0.3. For the plane you could use:

Code: Select all

OgrePhysX::Actor<PxRigidDynamic> actor =
   mPhysXScene->createRigidStatic((OgrePhysX::Geometry::boxGeometry(Ogre::Vector3(1000, 1, 1000));
Edit: Sorry, the code I posted here would create a dynamic "plane", that was probably not what you wanted. I updated the code.

Re: OgrePhysX - added destruction + Demo

Posted: Sat Jan 07, 2012 12:06 am
by Caphalor
Image

0.4 Update:
  • - included w0rm's MeshSplitter Tool (with his permission ;-)) (see this thread)
    - added experimental destruction support
    - 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.

Re: OgrePhysX - added destruction + Demo

Posted: Sat Jan 07, 2012 1:35 am
by Alexiss
Awesome ! Shouldn't this be in Showcase ?

Anyway, great stuff

Re: OgrePhysX - added destruction + Demo

Posted: Mon Jan 09, 2012 1:02 pm
by cin
Are you plan to go on PhysX 3.2?

Re: OgrePhysX - added destruction + Demo

Posted: Mon Jan 09, 2012 4:44 pm
by Caphalor
@Alexiss: Thanks! I already posted the screenshot in w0rm's thread in showcase.

@cin
Yes, but only if they don't change the interface completely again. :x
But it is still beta as far as I know.

Re: OgrePhysX - added destruction + Demo

Posted: Tue Jan 17, 2012 7:19 am
by Mind Calamity
Hey guys, any character controller example for PhysX3 ? I searched and I couldn't find (I did look at the tutorial on the PhysX Support Site though, it seemed kind of messed up and is for PhysX 2.x).

So if anyone could provide me with an example (or point me to somewhere where I can find one) before I figure it out myself I'd be very grateful.

Also, I believe a ragdoll example would be very interesting too (not only for me of course).

------------------

Update: I found that the North Pole sample included a character controller ( :roll: ). I'll try to implement it and share the experience...

Re: OgrePhysX - added destruction + Demo

Posted: Tue Jan 17, 2012 9:11 pm
by Mind Calamity
OK - I think this might not be the place to ask for help, but I'm gonna give it a shot anyway.

I have this in my code to create a character:

Code: Select all

	physx::PxCapsuleControllerDesc cDesc;
	cDesc.material		= &Engine::PhysicsSystem::getSingleton().getDefaultMaterial();
	cDesc.position		= PxExtendedVec3(mBodyNode->getPosition().x, mBodyNode->getPosition().y, mBodyNode->getPosition().z);
	cDesc.height		= mBody->getBoundingBox().getSize().y;
	cDesc.radius		= mBody->getBoundingRadius();
	cDesc.slopeLimit	= 0.0f;
	cDesc.contactOffset	= 0.1f;
	cDesc.stepOffset	= 0.02f;
	cDesc.callback		= this;
	std::cout << "Description created...\n";
	mControllerManager = PxCreateControllerManager(Engine::PhysicsSystem::getSingleton().getWorld()->getPxPhysics()->getFoundation());
	std::cout << "Controller manager created...\n";
	mPhysicalController = static_cast<physx::PxCapsuleController*>(
		mControllerManager->createController(
			Engine::PhysicsSystem::getSingleton().getWorld()->getPxPhysicsRef(),
			Engine::PhysicsSystem::getSingleton().getScene()->getPxScene(),
			cDesc
		));
	std::cout << "Capsule controller created...\n";
	// remove controller shape from scene query for standup overlap test
	physx::PxRigidDynamic* actor = mPhysicalController->getActor();
	std::cout << "Actor created...\n";
	if(actor)
	{
		if(actor->getNbShapes())
		{
			std::cout << "Setting flags...\n";
			physx::PxShape* ctrlShape;
			actor->getShapes(&ctrlShape,1);
			ctrlShape->setFlag(physx::PxShapeFlag::eSCENE_QUERY_SHAPE,false);
		}
		else
			throw Ogre::Exception(Ogre::Exception::ERR_INTERNAL_ERROR, "Character actor has no shape.", "Character.cpp(75)");
	}
	else
		throw Ogre::Exception(Ogre::Exception::ERR_INTERNAL_ERROR, "Character actor could not be created.", "Character.cpp(75)");
And this:

Code: Select all

mControllerManager = PxCreateControllerManager(Engine::PhysicsSystem::getSingleton().getWorld()->getPxPhysics()->getFoundation());
Is causing an unresolved external symbol link error:

Code: Select all

2>Character.obj : error LNK2001: unresolved external symbol _PxCreateControllerManager
I tried adding "#define PX_PHYSX_CHARACTER_STATIC_LIB" as suggested in a thread on the NVIDIA forums, but to no avail, so do you guys know anything about this ?

Here's my corresponding thread on the NVIDIA forums

Re: OgrePhysX - added destruction + Demo

Posted: Wed Jan 18, 2012 11:47 pm
by Caphalor
Sorry I can't help, because I don't use the PhysX character system. I use a rigid dynamic with a special inertia tensor (setMassSpaceInertiaTensor(PxVec3(0,1,0)) and I handle stairs manually using sweeps. This has the advantage that the character gets pushed around by moving objects (for example moving platforms - we thought about doing a small 3D first person jump'n' run with moving platforms but dropped the idea).

@Mind Calamity: I will post some code here this weekend, I don't have time at the moment.

Re: OgrePhysX - added destruction + Demo

Posted: Thu Jan 19, 2012 2:41 am
by Mind Calamity
Caphalor wrote:Sorry I can't help, because I don't use the PhysX character system. I use a rigid dynamic with a special inertia tensor (setMassSpaceInertiaTensor(PxVec3(0,1,0)) and I handle stairs manually using sweeps. This has the advantage that the character gets pushed around by moving objects (for example moving platforms - we thought about doing a small 3D first person jump'n' run with moving platforms but dropped the idea).
Oh, I'm very new to PhysX, so, do you mind sharing some code on that character system ?

I really have no idea where to start, and I'd like to have my character be pushed around by moving objects too.

Re: OgrePhysX - added destruction + Demo

Posted: Sat Jan 21, 2012 2:22 pm
by Caphalor
Here are some code snippets. It uses OgrePhysX but you can easily port it to plain PhysX.

Actor initialisation:

Code: Select all

		PxMaterial *mat = &OgrePhysX::World::getSingleton().getDefaultMaterial();

		mActor = Main::Instance().GetPhysXScene()->createRigidDynamic(
			 PxBoxGeometry(mDimensions.x*0.5f, mDimensions.y*0.5f, mDimensions.z*0.5f),
			mDensity,
			*mat,
			PxTransform(PxVec3(0, mDimensions.y*0.5f, 0))); 

		mActor.getFirstShape()->setSimulationFilterData(PhysXFilterData::Instance().Character);
		mActor.getFirstShape()->setQueryFilterData(PhysXFilterData::Instance().Character);

		mActor.getPxActor()->userData = mOwnerGO.lock().get();

		mActor.getPxActor()->setMassSpaceInertiaTensor(PxVec3(0,1,0));
		mActor.getPxActor()->setSolverIterationCounts(8);
Frame update:

Code: Select all

			Ogre::Vector3 finalDir = Ogre::Vector3(0,0,0);
			Ogre::Vector3 userDir = playerOrientation * mDirection;

			if (mActor.getPxActor()->isSleeping())
				mActor.getPxActor()->wakeUp();		//Gravity fix

			Ogre::Vector3 playerHalfSize = mDimensions * 0.5f;

			PxTransform transform(OgrePhysX::toPx(playerPosition), OgrePhysX::toPx(playerOrientation));
			transform.p.y += playerHalfSize.y;

			//sweep filter data - only check against shapes with filter data DYNAMICBODY or STATICBODY 
			PxSceneQueryFilterData filterData;
			filterData.data.word0 = CollisionGroups::DYNAMICBODY|CollisionGroups::STATICBODY;
			filterData.flags = PxSceneQueryFilterFlag::eDYNAMIC|PxSceneQueryFilterFlag::eSTATIC;

			//stair maxStepHeight
			float maxStepHeight = 0.6f;
			PxVec3 currPos = OgrePhysX::Convert::toPx(owner->GetGlobalPosition());

			//feet capsule
			PxBoxGeometry feetVolume(playerHalfSize.x, maxStepHeight*0.5f, playerHalfSize.z);

			//body capsule
			float bodyHeight = mDimensions.y-maxStepHeight;
			PxBoxGeometry bodyVolume(playerHalfSize.x, bodyHeight*0.5f, playerHalfSize.z);

			PxVec3 sweepDirection = OgrePhysX::toPx(userDir);
			float userDirLength = sweepDirection.normalize();

			/*
			We perform two sweeps:
			 O    ==> bodyHit?
			 |    ==> bodyHit?
			/ \   ==> feetHit?

			If there are no hits character can walk in the desired direction.
			If there is a feetHit but no bodyHit player can climb stairs (we add an y-Offset).
			If there is a bodyHit the player can not move.
			*/
			PxSweepHit sweepHit;
			transform.p.y = owner->GetGlobalPosition().y + maxStepHeight + bodyHeight*0.5f;
			bool bodyHit = Main::Instance().GetPhysXScene()->getPxScene()->sweepSingle(bodyVolume, transform, sweepDirection, time*userDirLength, PxSceneQueryFlags(), sweepHit, filterData); 				
			transform.p.y = owner->GetGlobalPosition().y + maxStepHeight*0.5f;	
			bool feetHit = Main::Instance().GetPhysXScene()->getPxScene()->sweepSingle(feetVolume, transform, sweepDirection, time*userDirLength, PxSceneQueryFlags(), sweepHit, filterData); 

			if (!bodyHit)
			{
				finalDir += userDir;	//add player movement
				if (feetHit) 
					finalDir += Ogre::Vector3(0,3,0); //climb stairs
			}

			if (finalDir != Ogre::Vector3(0,0,0))
				mActor.getPxActor()->setGlobalPose(PxTransform(currPos + OgrePhysX::Convert::toPx(finalDir*time)));

I don't know how you handle collision and scene query filtering, here is my system.
Header:

Code: Select all

enum CollisionGroups
	{
		DYNAMICBODY = 1,
		STATICBODY = 2,
		CHARACTER = 4,
		BONE = 8,	
		INTERN = 16		//no collision (for example AI meshes)
	};

	class DllExport PhysXFilterData
	{
	public:
		PhysXFilterData();

		PxFilterData DynamicBody;
		PxFilterData StaticBody;		
		PxFilterData Character;
		PxFilterData Bone;
		PxFilterData Intern;

		//Singleton
		static PhysXFilterData& Instance();
	};

	//PhysX simulation filter shader function
	DllExport PxFilterFlags PhysXSimulationFilterShader (	
		PxFilterObjectAttributes attributes0,
		PxFilterData filterData0, 
		PxFilterObjectAttributes attributes1,
		PxFilterData filterData1,
		PxPairFlags& pairFlags,
		const void* constantBlock,
		PxU32 constantBlockSize);
Source:

Code: Select all

	
PhysXFilterData& PhysXFilterData::Instance()
	{
		static PhysXFilterData TheOneAndOnly;
		return TheOneAndOnly;
	};

	PhysXFilterData::PhysXFilterData()
	{
		DynamicBody.word0 = CollisionGroups::DYNAMICBODY;
		DynamicBody.word1 = ~0;
		DynamicBody.word2 = ~0;

		StaticBody.word0 = CollisionGroups::STATICBODY;
		StaticBody.word1 = ~0;
		StaticBody.word2 = ~0;

		Character.word0 = CollisionGroups::CHARACTER;
		Character.word1 = ~0;
		Character.word2 = ~0;

		Bone.word0 = CollisionGroups::BONE;
		Bone.word1 = CollisionGroups::DYNAMICBODY | CollisionGroups::STATICBODY;
		Bone.word2 = CollisionGroups::DYNAMICBODY | CollisionGroups::STATICBODY;

		Intern.word0 = CollisionGroups::INTERN;
		Intern.word1 = 0;
		Intern.word2 = 0;
	}

	PxFilterFlags PhysXSimulationFilterShader (	
		PxFilterObjectAttributes attributes0,
		PxFilterData filterData0, 
		PxFilterObjectAttributes attributes1,
		PxFilterData filterData1,
		PxPairFlags& pairFlags,
		const void* constantBlock,
		PxU32 constantBlockSize)
	{
		// let triggers through
		if(PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1))
		{
			pairFlags = PxPairFlag::eTRIGGER_DEFAULT;
			return PxFilterFlags();
		}

		//word0 stores the group id, word1 a bitmask that determines for which groups collision is enabled.
		if (filterData0.word0 & filterData1.word1 && filterData1.word0 & filterData0.word1)
		{
			pairFlags = PxPairFlag::eCONTACT_DEFAULT;

			//word2 is a bitmask that determines for which groups contact notification is enabled.
			if ((filterData0.word0 & filterData1.word2 && filterData1.word0 & filterData0.word2))
			{
				pairFlags = pairFlags	| PxPairFlag::eNOTIFY_TOUCH_FOUND
										| PxPairFlag::eNOTIFY_CONTACT_POINTS
										| PxPairFlag::eNOTIFY_CONTACT_POINTS
										| PxPairFlag::eNOTIFY_CONTACT_FORCES
										| PxPairFlag::eNOTIFY_CONTACT_FORCE_PER_POINT
										| PxPairFlag::eNOTIFY_CONTACT_FEATURE_INDICES_PER_POINT;
			}

			return PxFilterFlags();
		}
		else return PxFilterFlag::eSUPPRESS;		//no collision
	}
You have to set the simulation filter shader during PhysX initialisation:

Code: Select all

sceneDesc.filterShader = &PhysXSimulationFilterShader;
If you use this system, don't forget to setup the simulation and query filter data for every actor you create (or there will be no collision).
For example for regular dynamic actors:

Code: Select all

		mActor.getFirstShape()->setSimulationFilterData(PhysXFilterData::Instance().DynamicBody);
		mActor.getFirstShape()->setQueryFilterData(PhysXFilterData::Instance().DynamicBody);
(Of course you have to set this for all shapes, but my actors only have one shape).

Re: OgrePhysX - added destruction + Demo

Posted: Tue Jan 24, 2012 7:04 pm
by Mind Calamity
Thank you very much for the code snippets, I managed to get my character controller to work, now the problem is I want to use a capsule instead of a box, because for some reason the box approach doesn't seem to climb stairs (the feetHit boolean is never set to true).

So I tried it with a capsule, and now it seems that the capsules are created horizontally, which is weird IMO, this shouldn't be the default behavior, should it ?

I know it's not related to OgrePhysX I'm just hoping I could get some answers faster here.

Code: Select all

	mActor = Engine::PhysicsSystem::getSingleton().getScene()->createRigidDynamic(
		PxCapsuleGeometry(3, mDimensions.y/2.0),//PxBoxGeometry(mDimensions.x*0.5f, mDimensions.y*0.5f, mDimensions.z*0.5f),
		mDensity,
		*mat,
		PxTransform(PxVec3(0, mDimensions.y*0.5f, 0))); 
It's basically the same code that you gave me, just that I adapted it to work with my engine. The getScene() function of my Physics System returns a OgrePhysX::Scene pointer (obviously).

Here's a screenshot of the PVD:

Image

Re: OgrePhysX - added destruction + Demo

Posted: Tue Jan 24, 2012 8:12 pm
by duststorm
This is very nice.
I was wondering, could you post a movie clip to show it in action, as a screenshot doesn't really do it much justice.

Re: OgrePhysX - added destruction + Demo

Posted: Fri Feb 03, 2012 1:35 pm
by Caphalor
@duststorm: Here is an older video: http://www.youtube.com/watch?v=BJnUfCIZjmg&hd=1 (turn off the sound, it's a bit loud)
If you use Windows (first post), you can also download the binary demo (tell me if it doesn't work!)
Thank you very much for the code snippets, I managed to get my character controller to work, now the problem is I want to use a capsule instead of a box, because for some reason the box approach doesn't seem to climb stairs (the feetHit boolean is never set to true).
The reason is probably the query filtering. Are you sure that your filtering setup (setQueryFilterData and so on) is correct?
So I tried it with a capsule, and now it seems that the capsules are created horizontally, which is weird IMO, this shouldn't be the default behavior, should it ?
I think this is the normal behaviour- try to specify a local shape transform.
I had to to the same with the PlaneShape in the demo:

Code: Select all

		//PhyX plane geometry always has the normal (1, 0, 0), so we have to rotate the plane shape in order to create a plane with a normal (0, 1, 0)
		OgrePhysX::Actor<physx::PxRigidStatic> ground = mPhysXScene->createRigidStatic(PxPlaneGeometry(), physx::PxTransform(physx::PxQuat(Ogre::Math::PI/2, physx::PxVec3(0,0,1))));
I know it's not related to OgrePhysX I'm just hoping I could get some answers faster here.
No problem and sorry for the late answer. :cry:

OT:
111 Posts!
And thanks for the kudos @all. :-)

Re: OgrePhysX - added destruction + Demo

Posted: Sun Feb 19, 2012 5:02 pm
by workmanaquarious
Youo wouldnt happen to have you dependicies folder uploaded?

Re: OgrePhysX - added destruction + Demo

Posted: Mon Feb 20, 2012 5:41 pm
by maxdelphi
excelent, thanks for share your project, but how install it?, where are the guide?, what contain enviroment variable "OGRE_HOME", "PHYSX_DIR" and "PHYSX_LIB". i think OGRE_HOME contains "C:\OgreSDK\etc..."..

need your help, need a guide thanks, and where are the SVN or google code?? thasnks

Re: OgrePhysX - added destruction + Demo

Posted: Mon Feb 20, 2012 10:12 pm
by Caphalor
README wrote:Used environmental variables:
OGRE_HOME (source directory, for example C:\Ogre\OgreMain\)
OGRE_LIB (Ogre library directory, for example C:\OgreBuild\lib\)
PHYSX_DIR (PhysX directory, for example C:\PhysX\SDKs\)
There is no seperate SVN for OgrePhysX because it is part of my main project (game engine + editor). But I don't work on that at the moment, because I have to write my bachelor thesis (not Ogre related :-().

@workmanaquarious What dependencies do you mean? Ogre? PhysX? I won't do that because I don't know whether it is legal to upload the PhysX SDK. It is free, download it from the official site.

Re: OgrePhysX - added destruction + Demo

Posted: Mon Feb 20, 2012 10:52 pm
by maxdelphi
thanks, i speak spanish and not much english, sorry for my language, and yes i will download SDK from official website...

now, Will you continue building OgrePhysic?, can i use ogrephysic as wrapper between ogre and physx for my game?, if answer is yes, can i use Cloth, Fluid, ForceField... and all features of physX?...thanks :P

Re: OgrePhysX - added destruction + Demo

Posted: Mon Feb 20, 2012 11:35 pm
by Caphalor
No, cloth and fluids are not wrapped yet, but of course you can also use PhysX directly when using OgrePhysX. See the PhysX samples and documentation. I don't think that I will add these features in the near future.
PhysX3 has no forcefields any more, so you have to apply the forces manually.
You should have a look at NxOgre, it is only compatible with PhysX 2.8 but far more feature complete and stable. I don't know whether it supports cloth or fluids though.

Re: OgrePhysX - added destruction + Demo

Posted: Thu Mar 08, 2012 12:23 am
by workmanaquarious
When are you planning on adding softbody support?

Re: OgrePhysX - added destruction + Demo

Posted: Sat Mar 24, 2012 5:50 pm
by workmanaquarious
Im just having fun coverting all your "autos" so i can use your code in 2008 :)

Re: OgrePhysX - added destruction + Demo

Posted: Wed Apr 25, 2012 1:51 pm
by Dark_Butcher
hi,

I use OgrePhysx in my project to have destructible object. But I use Ogre 1.7.2
to use MeshSplitter, I needed of re - compile with Ogre 1.7.2

But the probleme, my mesh have no texture.

have you an idea of why?


sorry for my bad english

Re: OgrePhysX - added destruction + Demo

Posted: Fri Jun 01, 2012 11:04 pm
by Xplodwild
Did anyone manage to build heightfield from Ogre::Terrain with this?
I want to port my code from NxOgre to this, but I can't find something similar to NxOgre's ManualHeightField.

Re: OgrePhysX - added destruction + Demo

Posted: Wed Jun 13, 2012 9:06 pm
by Shtuka
Has anyone managed to update OgrePhysX to PhysX 3.2.0?