PDA

View Full Version : Particle collision basic question


johnchuang
04-30-2008, 03:50 AM
Hi,all. I'm a newbie learning maya dynamics .
I'm trying to make sort of rains ,but have some problems. I need the particles collide with 3 different objects with different behaviors. Let's say some particles collide with object A then die instantly; some particles hits object B and emit new ones ; the last particles hits object C then bounce and die; AND certain particles only interactive with certain object .

Maybe I'm not clear enough. For short :
Is it possible that one particle node have different effects on different collision objects? And how?

I do know there is a Particle Collision Events menu , but I don't know how to distinguish different collision rely on that .Maybe use particlePP and some expressions? I just can't figure it out.
Any and all helps will be greatly appreciated! Thank you!

BadG3r
04-30-2008, 12:38 PM
The easiest thing would be to create 3 different particle shapes and then use the collision event editor with the settings you described.

In case you really need it to be a single particle shape, however, look up the collision and event command in the docs. add some if statements maybe regarding the particle id and off you go...

drGonzo
05-01-2008, 03:07 PM
I thought this was an interesting one, so I gave it a whirl.

The key to your success is an extremely obscure attr called collisionGeometryIndex (not mentioned in the docs), which provides you with an index of the pieces of geo the particles collide with. (Can be seen in the partShape AE under collision attrs)

Say you want the particles to go red when they collide with object1 and blue when they hit object 2:
int $idx = particleShape1.collisionGeometryIndex;
if( $idx != -1 )
{
if ($idx ==1)
particleShape1.rgbPP = <<1,0,0>>;
if ($idx ==2)
particleShape1.rgbPP = <<0,0,1>>;

}

It gets even more interesting if you want to extract the geo name from that. Thanks to Rob Pieke for the tip:

int $idx = particleShape1.collisionGeometryIndex;
if( $idx != -1 )
{
string $geoC[] = `listConnections particleShape1.collisionGeometry[$idx]`;
string $shape[] = `listConnections ( $geoC[0] + ".localGeometry" )`;
print( $shape[0] + "\n");
}

johnchuang
05-02-2008, 04:32 PM
Hi,BadG3r, thank you for reply! I really need single particleShape ,and I guess scripting is the only way I can access that.Thank you very much!

drGonzo, thank you for the codes above and your time! That's the very thing I need (If there is no other way. I think particleFlow in 3dsMax do a better job when triggering certain events.) Also I find that if I use collisionEvent I should use some sorta different syntax like I post below:
global proc test(string $partName, int $partId, string $ColName)
{
float $index[] = `getParticleAttr -at "collisionGeometryIndex" ($partName + ".pt[" + $partId + "]" )`;
if( $index[0] != -1 )
{
if ($index[0]==0)
{
select ($partName + ".pt[" + $partId + "]" );
setParticleAttr -vv 1 0 0 -at rgbPP;
}
if ($index[0]==1)
{
select ($partName + ".pt[" + $partId + "]" );
setParticleAttr -vv 0 0 1 -at rgbPP;
}
}
}

It's really confused me for a long time!:banghead: Damn it!
Anyway , drGonzo ,thank you so much! I think I may do some further stuff from what I've learned .


PS: collisionGeometryIndex is a PP attr ,which should be added before using it. I've tried hours before figuer it out.For anyone with the same problem ,hope this helps.

:thumbsup:

drGonzo
05-02-2008, 06:12 PM
Also I find that if I use collisionEvent I should use some sorta different syntax like I post below:

I think you are confusing MEL scripts and expressions. The code you wrote (with things like getPartAttr), is something you would use in a MEL script, but NOT in an expression.
In expressions you have direct access to attributes like event and rgbPP - and you should use that direct access at all times.
Have a look here:
file:///C:/Program%20Files/Autodesk/Maya2008/docs/Maya2008/en_US/wwhelp/wwhimpl/common/html/wwhelp.htm?context=General&file=Differences_between_expression_and_MEL_syntax.html

PS: collisionGeometryIndex is a PP attr ,which should be added before using it. I've tried hours before figuer it out.For anyone with the same problem ,hope this helps.

Sorry about that, I should have explicetely mentioned that. So yeah, you can add it by hitting the general button and adding it as a particle PP attr. It's in the list under the particle tab.

johnchuang
05-03-2008, 02:42 AM
Hi,drGonzo! What realy confused me is that I can't put expressions in Expression Editor but mel when using collision event. I guess I can't access PP attr using regular expressions on particleShape node,and also getParticleAttr should be used rather than getAttr.
Well, since using PP expression on collisionGeometryIndex under particlePP Attr works fine ,and using collision event with mel also do the job, then what's the difference between them ? Which one is faster and more reliable? I've really no experience about this .Thanks!

drGonzo
05-03-2008, 02:18 PM
Hi,drGonzo! What realy confused me is that I can't put expressions in Expression Editor but mel when using collision event.
The event attribute is just like any other PP attr - so you can access its data directly from the expression editor. To create it, you need to create a collision event (particles > collision event) without any settings. just hit the create event button. You can then set your particles to numeric and type in event in the attr name, just to be sure its there.

Once it is there, you can do stuff like this:
(note the direct access to the event attr, no need for getpartAttr)
if (particleShape1.event != 0)
{
print ("Particle " + particleShape1.particleId + " just did collision " + particleShape1.event + "\n");
if (particleShape1.event == 2) //if the particle collides for the 2nd time, turn it red
particleShape1.rgbPP = <<1, 0, 0>>;

}

You can also store PP attrs in variables for conformity:


int $hit = particleShape1.event;

if ($hit != 0)
{
print ("Particle " + particleShape1.particleId + "just did collision " + $hit + "\n");
if ($hit == 2) //if the particle collides for the 2nd time, turn it red
particleShape1.rgbPP = <<1, 0, 0>>;

}

I guess I can't access PP attr using regular expressions on particleShape node,and also getParticleAttr should be used rather than getAttr.

When working with PP collision attr (be it event or collisionGeometryIndex) there is no need to write normal (ie non-PP) expressions to part nodes. However, if you would need this, you would indeed need to use getPartAttr


Well, since using PP expression on collisionGeometryIndex under particlePP Attr works fine ,and using collision event with mel also do the job, then what's the difference between them ? Which one is faster and more reliable? I've really no experience about this .Thanks!
PP expressions will be the fastest and in this case, the only feasable solution.

johnchuang
05-03-2008, 04:03 PM
Thank you so much! You really help me out.Thank you! :thumbsup:

CGTalk Moderation
05-03-2008, 04:03 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.