PARTICLE EXPRESSION

 

 

PARTICLE SELECTING THE COLLISION OBJECT FACE

 

          If you want that mesh deform on particle collision example in snow or mud surface. This is simple way to do with collisionComponentId. Collision ComponentId gives the face number of the collision object.  Then you can select that poly face, and using xform command can deform it. Let’s see the expression:

int $cFace = particleShape1.collisionComponentId
if($cFace>0)
{
            select -add pPlane1.f[$cFace];
            //xform -r -t 0 -0.01 0 pPlane1.f[$cFace];
}

 

Download :       Playblast           Scene file

 

 

PARTICLE COLOR CHANGE ON COLLISION

 

          This is simple expression; my friend asked me that whether it’s possible for single particle color change on collision without using the collision event editor. Here the expression:

CREATION

particleShape1.rgbPP=<<1,1,1>>;

RUNTIME BEFORE DYNAMICS

int $gIndx=particleShape1.collisionGeometryIndex;

if($gIndx ==0)
particleShape1.rgbPP=<<1,0,0>>;
if($gIndx ==1)
particleShape1.rgbPP=<<0,1,0>>;
if($gIndx ==2)
particleShape1.rgbPP=<<0,0,1>>;
if($gIndx ==3)
particleShape1.rgbPP=<<1,0,1>>;

Download :       Playblast           Scene file

 

TEXTURE BASED LIFESPAN

 

          Texture based lifespan works by killing particle, based on alpha value in the map with using coloratpoint command. First enable nearestPointOnMesh in plugin window then apply it to mesh object (to apply select mesh and type in mel script editor nearestPointOnMesh). By assigning per particle position attribute vector value to nearestPointOnMesh inPosition then you will get the result of U,V parameter of mesh, with that you can get the result of alpha value on U,V parameter in the texture map using colorAtPoint command.   Look at the expression:

RUNTIME BEFORE DYNAMICS:

vector $pos =particleShape1.position;

setAttr nearestPointOnMesh1.inPositionX ($pos.x);
setAttr nearestPointOnMesh1.inPositionY ($pos.y);
setAttr nearestPointOnMesh1.inPositionZ ($pos.z);

float $u = `getAttr nearestPointOnMesh1.parameterU`;
float $v = `getAttr nearestPointOnMesh1.parameterV`;

vector $c = `colorAtPoint -u $u -v $v -o A ramp1`;

particleShape1.lifespanPP = ($c*particleShape1.LifeMulti)+.2;

 

 

Download :       Playblast           Scene file

 

 

Texture Based Particle Goal

 

          This objective is particles where ever colliding in white area are sticking and where ever colliding in black area are bounce.  Texture based particle goal works similar way in previous one. It’s checking whether if alpha map value is 1 and goalPP value is 1 otherwise goalPP value is 0. That’s it.... let see the code:

RUNTIME BEFORE DYNAMICS

float $a[];
float $cTime = particleShape1.collisionTime;

if ($cTime !=-1)
{
            vector $cPos = particleShape1.collisionWorldPosition;

            setAttr npoMesh.inPositionX ($cPos.x);
            setAttr npoMesh.inPositionY ($cPos.y);
            setAttr npoMesh.inPositionZ ($cPos.z);

            float $u = `getAttr npoMesh.parameterU`;
            float $v = `getAttr npoMesh.parameterV`;
           
            $a = `colorAtPoint -o A -u $u -v $v file1`;

}

Download :       Playblast           Scene file

 

 

TextureBaseParticleRamp

 

          This can be done by texture emission attributes in emitter properties but its working only on surface emitter.  This is also same concept except we need RGB value instead of Alpha value in colorAtPoint.  Then we can directly assign to rgbPP attribute.

Creation:

vector $pos =particleShape1.position;

setAttr nearestPointOnMesh1.inPositionX ($pos.x);
setAttr nearestPointOnMesh1.inPositionY ($pos.y);
setAttr nearestPointOnMesh1.inPositionZ ($pos.z);

float $u = `getAttr nearestPointOnMesh1.parameterU`;
float $v = `getAttr nearestPointOnMesh1.parameterV`;

vector $color = `colorAtPoint -u $u -v $v -o RGB ramp1`;

particleShape1.rgbPP = <<$color.x, $color.y, $color.z>>;

Download :       Playblast           Scene file

 

      if($a[0] > 0.75)
            {
                        //print $a;
                        particleShape1.goalU = particleShape1.collisionU;
                        particleShape1.goalV = particleShape1.collisionV;
                        particleShape1.goalPP = 1;
                        particleShape1.lifespan=10;
            }
}
clear $a;

 

PARTICLE COLOR CHANGE ON OBJECT COLLISION

 

          In some case particles are emitted in the surface with goal like this image.  If you need to change only collision particle color.   Using collisionU, collisionV attribute you can get the result.  This is the expression:

RUNTIME BEFORE DYNAMICS:

if(nParticleShape1.collisionTime !=0)
{
if(nParticleShape1.collisionU> -1 ||
      nParticleShape1.collisionV>-1)
nParticleShape1.rgbPP=<<0,1,0>>;
}

Download :       Playblast           Scene file

 

| Page 1 | Page 2 |