Complex UV Layout in Maya
Over the last couple of years UV layout in Maya has changed for the better. In this course we're going to be taking a look at some of those changes as we UV map an entire character
# 1 18-02-2015 , 09:42 PM
Registered User
Join Date: Feb 2015
Posts: 3

How to control the ratio of nParticle instances

Hi,

I've been using nParticle instances to create a scene with multiple objects in a crowded environment. However, I am unable to figure out how to control the amount of instanced molecules that are emitted. Any help will be much appreciated.

Here is my creation expression thus far:

$i = rand(0,101);
if($i > 50) nParticleShape1.indexpp = 0;
if($i < 50) nParticleShape1.indexpp = 1;
if($i < 30) nParticleShape1.indexpp = 2;
if($i < 10) nParticleShape1.indexpp = 3;
if($i < 2) nParticleShape1.indexpp = 4;

When I have just the first 3 statements, the expression works fine but the more I add, the more unpredictable results I get. I am certain the answer is in the way that I am writing the script but haven't been able to figure it out. Ideally I would like to have a range of values (i.e. 10 > i < 50) but when I tried using the following: if($i < 50) && ($i >30) nParticleShape1.indexpp = 1; I get a syntax error.

Thanks

# 2 19-02-2015 , 12:37 AM
EduSciVis-er
Join Date: Dec 2005
Location: Toronto
Posts: 3,374
You're very close. You want something like

if ($i >= 30 && $i < 50) ...
if ($i >= 10 && $i < 30) ...

# 3 21-02-2015 , 04:27 AM
Registered User
Join Date: Feb 2015
Posts: 3
That helped solve my syntax errors but I noticed a few other problems as well.

1) The objects don't seem to be emitting in the right proportions after checking the numeric object values.

2) the instancer is ignoring objects 2 and 4. This is not an error with the object geometry because if I move the objects levels up and down in the instancer (i.e. my sphere becomes object 2 and my cube is now object 3) the objects do appear - I can see the cube that was originally object 2.

Here's my updated creation expression:
int $i = rand(0,101);
if($i > 50) nParticleShape1.indexpp = 0;
if($i >= 40 && $i < 50) nParticleShape1.indexpp = 1;
if($i >= 30 && $i < 40) nParticleShape1.indexpp = 2;
if($i >= 20 && $i < 30) nParticleShape1.indexpp = 3;
if($i >= 10 && $i < 20) nParticleShape1.indexpp = 4;
if($i >= 8 && $i < 10) nParticleShape1.indexpp = 5;
if($i < 8) nParticleShape1.indexpp = 6;

At this point I've started to just create separate emitters to get the desired effect.

# 4 26-02-2015 , 04:19 PM
Registered User
Join Date: Feb 2015
Posts: 3
Update: It turned out to be a simple error in the way I set up my dynamics attribute. When I changed the attribute from vector + per particle attribute to float + per particle attribute everything started to work as intended.

I also had to change my creation expression to reflect that by writing float instead of int:

float $i = rand(0,101);
if($i > 50) nParticleShape1.indexpp = 0;
if($i >= 40 && $i < 50) nParticleShape1.indexpp = 1;
if($i >= 30 && $i < 40) nParticleShape1.indexpp = 2;
if($i >= 20 && $i < 30) nParticleShape1.indexpp = 3;
if($i >= 10 && $i < 20) nParticleShape1.indexpp = 4;
if($i >= 8 && $i < 10) nParticleShape1.indexpp = 5;
if($i < 8) nParticleShape1.indexpp = 6;

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads