Help on accessing particles that are in a certain partition of space

Hello everybody!

I am working on a team building a game and we recently switched from a ‘homebrew’ physic simulation to physx. We are currently developing for Windows using VS2010 and physx 3.3.1 .

I spent a few days now converting all the physic simulation stuff to physx and i am now stuck on a problem i can not find a solution or if there is a solution to this at all.

What i need is this: In the game certain areas are defined as special partitions in space. Particles are not affected by this areas but i need to know IF a particle is inside this area. If a particle is inside this area, other bodies can rest on top of it. So i need to know if a body collides with a particle that is inside a special area.

I could do it brute force and check every particle on every step, but this would mean a huge performance hit.

So is there a way to check for a specified particle system if any particles are inside a predefined area?

I hope its somehow clear what i am looking for :)

Thanks to everyone in advance!

You would need

  1. A trigger shape( along with the onTrigger callback ) for the area and create a filter to allow only
    interaction between particles and the trigger.

  2. A shape representative of the same area/region that initially have filtering off for all bodies, but turned on once #1 happens. With the filter off, collision between the shape and other bodies will be ‘ignored’, but once a filter is created for the shape representing the area and all collideable( is this a word ? ) bodies, then collision detection and response will take place as usual.

Hope that helps.

Hi!

Thanks a lot! That sounds almost exactly like what i need!

I will try this and report on the result :)

Hey there!

I spent some time trying to figure out how the trigger shapes work, but i just can not get it to work…

Let me show you what i have at the moment, maybe i am just stupid again…

First i need a place where i can catch the onTrigger events, so i made a helper class ( the onTrigger function just does some output to the console so i could see when it is triggered, but heres just the declaration ):

class PhysxCallbackInterface : public physx::PxSimulationEventCallback {
	public:
		virtual void onTrigger(physx::PxTriggerPair* pairs, physx::PxU32 count);
};

I added a member variable to my class that handles the physx stuff:

PhysxCallbackInterface* m_pCallbackInterface;

An then i added this to my scene description:

sceneDesc.simulationEventCallback = m_pCallbackInterface;

I also defined a filter (at least i hope that i did ;) ) :

PxFilterFlags FilterShader (	
	PxFilterObjectAttributes attributes0, PxFilterData filterData0, 
	PxFilterObjectAttributes attributes1, PxFilterData filterData1,
	PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize)
{
	pairFlags = PxPairFlag::eCONTACT_DEFAULT;	
	return PxFilterFlag::eDEFAULT;
}

and then set it to the scene description:

sceneDesc.filterShader = FilterShader;

In my understanding (and i just assume is hooribly wrong, mainly because i just cant get much information from the so called documentation or the samples… :/ ) this should now trigger the onTrigger event whenever something hits a shape with these definitions:

newActorShape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false);
newActorShape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true);

Do you have an idea what is wrong with my approach?

Thank you in advance!

Hi,

Is there no trigger example in the samples or snippets? I’ll take a look.

–Mike

Have a look at SnippetNestedScene in the PhysX-3.3.2 Snippets collection. In NestedScene.h you will find the trigger callback exmaple:
void onTrigger(PxTriggerPair* pairs, PxU32 count)
{
for(PxU32 i=0; i < count; i++)
{
// ignore pairs when shapes have been deleted
if (pairs[i].status & PxPairFlag::eNOTIFY_TOUCH_LOST)
{
//we’re not allowed to make changes in the callback, so save it for later
removalQueue.push_back(pairs[i].otherActor);
}

	}

}

Hello and thank you for the answer.

I had been sick for a week now so i could not answer earlier.

At the moment my problem is not in the onTrigger callback function itself. It just never gets called. I set it to do some debug output and i tried setting a breakpoint inside it but it is never reached.

My error must be eralier in the process.

And i tried to figure out how this works from the examples (mostly the submarine example) but i just cant figure out how it realy works.

Oh and i cant find the SnippedNestedScene. Its not on the documentation website and in my SDK folder in the snippets folder i cant find it either.

:/

Just a quick update, i found the SnippetNestedScene, it is exclusive to 3.3.2 and was not present in my 3.3.1 folder!

[Edit]
And another update. The Snippet is way more informative as the older stuff, i managed to trigger something … Now i just have to tweak it… Still not sure if i understand the whole filter stuff…

Ok, i can reliably trigger things when rigid objects collide with my trigger object. The onTrigger function is called when that happens.

But if a particle collides with a trigger, then onTrigger function is not called. I can see in the filter that the contact or possible contact is reported but it never calls the onTrigger callback…

this is my filter shader:

PxFilterFlags CustomFilterShader(
	PxFilterObjectAttributes attributes0,
	PxFilterData filterData0, 
	PxFilterObjectAttributes attributes1,
	PxFilterData filterData1,
	PxPairFlags& pairFlags,
	const void* constantBlock,
	PxU32 constantBlockSize)
{
	PX_UNUSED(constantBlock);
	PX_UNUSED(constantBlockSize);

	if(PxFilterObjectIsTrigger(attributes0) || PxFilterObjectIsTrigger(attributes1))
	{
		
		if ( filterData0.word3 == 1 || filterData1.word3 == 1 ) { //One of the objects in the pair is a particle
			pairFlags = PxPairFlag::eTRIGGER_DEFAULT;
			return PxFilterFlags();
		} else {
			pairFlags = PxPairFlag::eTRIGGER_DEFAULT;
			return PxFilterFlags();
		}
	}

	pairFlags = PxPairFlag::eCONTACT_DEFAULT;

	return PxFilterFlags();
}