View Full Version : Instancing multiple objects with one emitter in differing ratios.
01-11-2011, 08:12 PM
I have particles from one emitter goaled to a mesh. Instanced to these particles are a set of objects (2) randomly distributed through the use of an expression. This all works great. What I need to do now is figure out how to distribute these objects in a 7:3 ratio over this mesh but still in a random fashion. So if there are 100 particles being emitted and replaced with geometry, 70 of those have to be object A while the remaining 30 have to be object B. So while both objects are distributed randomly, it is obvious that there is a greater concentration of object A than object B spread across this mesh. Any suggestions on how this can be done?
Thank you in advance for any help or tips you can give me.
01-12-2011, 12:44 PM
You could use an If statement to set the objectId ratio.
Though an exact 70/30 split will not be guaranteed.
Someone with a little more expression experience might be able to refine this.
But something like this will get you started;
(FYI: this would be a particle creation expression)
$numRand = rand (1);
if ($numRand <= .7)
particleShape.objectId = 1;
particleShape.objectId = 2;
One way to make an exact 70/30 split would be to use particleId for the if statement variable...but depending on how you created your particles they might not be distributed nicely. Using your example of 100 particles...
if (particleShape.particleId <= 70)
01-12-2011, 01:47 PM
Thanks for the help animatedfox. I am a little bit embarrassed to have to write this but the objectId, how do I find this out? I am new at this (expressions) and I have had a great deal of help on any previous expression work I have done so I am trying to understand the components more clearly.
01-13-2011, 12:56 PM
Especially for only your second one posted...I have seen much sillier second questions.
particleShape.objectId is just the name of the attribute that I was using to drive the Object Index value for the instancer. You could be using another attribute name...
No less effective, but some would find it less intuitive.
Alright, you said that you have already instanced your geo onto your particles, so just check what the name of the attribute you are using to randomly drive the Object Index. To do that, select the particle and open the attribute editor (CTL+a). Now open the "Instancer (Geometry Replacement)" section of the particleShape. This is where you can change the settings for your instancer...in your case we are looking in the General Options section for what attribute is driving "Object Index".
You should just be able to use expression I posted by replacing the section of your expression that was setting this value before.
If you post your creation expression here, we could show you exactly how to change it.
***If you go it on your own...just note that I made a little error in the values that I posted in my expression...For two objects you should be setting your particleShape.objectId to 0 and 1 not 1 and 2...***
01-14-2011, 01:15 PM
Thanks again. I will have to take a closer look at this next week at which point perhaps I can bug you again. I really appreciate your thorough responses. Very helpful.
01-18-2011, 02:13 PM
This is the expression I was using previously:
So it gave me distribution of my objects in a random fashion but the same random fashion everytime. Maybe this information changes things.
01-18-2011, 03:18 PM
Your post made me look over my original post and I realized it might not be working right...or is it?
I think you need an extra attribute to hold the random number...maybe...or just seed it with the particleId. No time to try it out...but maybe on this will help.
Create two float PP attributes...numRand and objectId.
numRand will hold the random number.
objectId will drive the instancer objectId.
Also using the particleId to seed each rand.
$seed = particleShape1.particleId;
particleShape1.numRand = rand (1);
if (particleShape1.numRand <= .7)
particleShape1.objectId = 0;
particleShape1.objectId = 1;
Does this help?
Does it work?
01-18-2011, 03:36 PM
It has not been working, I thought posting my expression might help. Though, due to the fact that I am a huge noob, I may be doing something incorrectly. I will try this new approach out and see if I can get that to work. I really appreciate the help, you have been extremely quick to reply and determined to help me figure this out so thank you.
01-18-2011, 03:41 PM
I just tested the updated expression and it works fine on my end...that original one i posted was garbage...my apologies.
Just create those Per Particle float attributes and drop that expression in as you creation expression.
You should be all good.
01-18-2011, 03:41 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-2015, Jelsoft Enterprises Ltd.