View Full Version : Random Particle Instancing
douwvn 03-05-2008, 12:09 PM Can someone please stear me in the right direction here. I want to write a script that randomly instance objects (from a list) for each particle generated.
Thanx
|
|
T1ckL35
03-05-2008, 07:28 PM
I've done that recently using the following method:
1) add all your objects to the particle instancer
2) write a creation expression that does the following (changing the 'particleName' and 'particleNameShape1' bits with the relevant names of the particle object you are using).
// get list of instanced objects from a particle object called particleName
$myTempVar = `particleInstancer -q -obj "particleName"`;
// get the number in that list
int $myTempSize = size($myTempVar);
// get a random number from the number in the list
int $vInnerRand = rand(0, $myTempSize);
// set the indexPP of the current particle to be the random number from the list
particleNameShape1.indexPP = $vInnerRand;
I've ripped the code out from my traffic animation tool (bTraffic - http://www.youtube.com/watch?v=SWKTDtvggWU) which instances objects from a list and then randomly selects and assigns them to particles. It goes a little further and adds groups of instanced objects that can be set as a percentage of a total but I'm sure that if you grasp the code above then you'll be able to do a similar thing.
Hope it helps :)
Simon
douwvn
03-06-2008, 05:31 AM
Thank you. It helps, ALOT!
It's people like you that makes this industry so special to be apart of.
Keep well :)
parnurzeal
03-06-2008, 08:41 AM
I'm beginner with this. Could you tell me how to do it step by step,please?
what is "particleNameShape1"?
and how to add "particle" to the list?
T1ckL35
03-06-2008, 10:14 PM
no probs douwvn, I'm actually about to try and get into the industry starting this week (just finished a course) ;)
parnurzeal - learn about the basics of creating particle systems and then if you look in the help at commands/commands python things should start making a little sense. Once you're a little familiar there then come back to the commands listed here and start experimenting :)
Simon
parnurzeal
03-07-2008, 04:10 AM
:) Thank you very much. I'll try.
douwvn
03-10-2008, 12:53 PM
Hi t1ck135
I quickly ran through your script and found that I don't get an indexPP per particle atribute under the particleNameShape that I'm using. Is there another name for it or should I creat one? I'm using Maya 2008.
Thanx
T1ckL35
03-10-2008, 02:31 PM
Hi douwvn,
Yep your right :)
apologies that I missed out the attribute and assigning it to the instancer.
// first add the attribute called indexPP
addAttr -shortName "indexPP" -dataType "doubleArray" "yourParticleNameShape";
// Now add an instancer and set the objectIndex (id) to use the indexPP attribute
particleInstancer -name "yourNewInstancerName" -objectIndex "indexPP" "yourParticleNameShape"
Alternatively you can add these using the UI.
1) ParticleShape attributes -> Add Dynamic Attributes -> General -> add your settings here
(I think you need to use float as the type to set it as per particle)
2) Select the geometry to instance
3) Add an instancer (Particle -> Instancer Replacement)
4) Select the new instancer and in its attributes go to Instancer (Geometry Replacement)
5) Set Instancer Nodes to your new instancer
6) Set 'General Options -> ObjectIndex' to indexPP
Hope this helps :)
Simon
CGTalk Moderation
03-10-2008, 02:31 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.