PDA

View Full Version : Particle Instance emit random geometry?


avillabon
02-04-2009, 02:48 PM
Hi Everyone!

I an using particle instancing within maya. Lets say i have 6 cubes with different textures and i want them to be emitted randomly but NOT cycling. What i would like to do is when a particle spawns i want it to select one of the cubes ramdomly. I'm sure i've done this before but i just cant remember the how!

Alex

avillabon
02-04-2009, 03:18 PM
nevermind! i found this thread and this does it!

http://forums.cgsociety.org/showthread.php?f=86&t=579848&highlight=particle+instance

Alex

azshall
02-04-2009, 05:51 PM
however many objects you have in your instance list (say 10, which would be index 0-9) you would create a custom float PP attribute called something like indexPP and give it a creation expression of indexPP = rand(0,9); ... then in the instancer section of the particle shape node change the index dropdown to reflect this new custom attribute.

azshall
02-04-2009, 06:46 PM
forgot to say.

good to see you on here Alex, how've you been doing since Gnomon?

DJ_
02-05-2009, 01:39 PM
however many objects you have in your instance list (say 10, which would be index 0-9) you would create a custom float PP attribute called something like indexPP and give it a creation expression of indexPP = rand(0,9); ... then in the instancer section of the particle shape node change the index dropdown to reflect this new custom attribute.

Sorry for being an arse trying to correct you, but when Maya converts floats into int, it always rounds the number down. So if you have 10 objects with indexes 0-9, if you make a indexPP = rand(0,9) to randomly pick one of those, you will only get the index 9 when the random number generates exactly the number 9 (if it is 8.999 it will round it down to 8) so you will get very few of the last index. Normally when I have 10 objects of index 0-9, I make my indexPP = rand(0,10). that way I get a fairly even distribution of all objects.

Wick3dParticle
02-05-2009, 05:41 PM
Sorry for being an arse trying to correct you, but when Maya converts floats into int, it always rounds the number down. So if you have 10 objects with indexes 0-9, if you make a indexPP = rand(0,9) to randomly pick one of those, you will only get the index 9 when the random number generates exactly the number 9 (if it is 8.999 it will round it down to 8) so you will get very few of the last index. Normally when I have 10 objects of index 0-9, I make my indexPP = rand(0,10). that way I get a fairly even distribution of all objects.

But if your rand value draws a 10, it will have no object to index and therefore just use the highest index value available. So instead of having all the other object appear so slightly more than that last one if you were to use 9.9, you will have one object appear more than the rest...which can lead to looking a bit more odd. So I would use rand(0,9.9) or 9.999 like stated in that older post.

~Ilan

azshall
02-05-2009, 06:33 PM
heh.

I guess, if you're using items in an index that are very notably different and you can tell when one isn't used then I guess thats a problem. Generally when I'm instancing random debris its little rocks and bits and I really don't care if 1 or 2 get missed because you never notice the difference after motion blur and everything else going on. However, the second post is not a bad tip.

I guess if you REALLY cared all that much you could pull this trick out of the bag and call it done, not worrying about the round up/down.

indexPP = (int) rand(9);

...Ilan, tell Orloff and Saker that Seth says hi :)

DJ_
02-06-2009, 07:50 AM
Yeah, you guys are right. I'm still only a noob in scripting.

CGTalk Moderation
02-06-2009, 07:50 AM
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.