原文作者:伍沁憬



创建表达式:

nParticleShape1.instanceindex=floor(rand(0,23));

nParticleShape1.goalPositionPP=sphrand(10);

nParticleShape1.tubulencerotation=rand(0,1);

nParticleShape1.velPP=rand(30,100);

nParticleShape1.escobjdis=rand(0,10);

nParticleShape1.goalU=nParticleShape1.parentU;

nParticleShape1.goalV=nParticleShape1.parentV;


运行表达式:

float $tx= getAttr goalobject.tx`;

float $ty= getAttr goalobject.ty`;

float $tz= getAttr goalobject.tz`;

vector $goal=<<$tx,$ty,$tz>>;

float $rotationdecaydistance= 3;/////定义运动物体离目标多近 后 随机转向开始衰减

float $vel = nParticleShape1.velPP/100 * 0.001 * ((noise(time/2+nParticleShape1.particleId*50)+1)*0.5+0.5); ////定义物体的基础速率 为每个粒子分配不一样的速率

$goal=$goal + nParticleShape1.goalPositionPP;

vector $directint=$goal - nParticleShape1.worldPosition;

vector $normaldirection=unit($directint);

vector $particleposition=nParticleShape1.worldPosition;

float $rotationdecay ;

nParticleShape1.distancePP=mag(<<$particleposition.x,$particleposition.y,$particleposition.z>>-<<$goal.x,$goal.y,$goal.z>>);

if ( nParticleShape1.distancePP < $rotationdecaydistance){

$rotationdecay=1 - smoothstep(0,$rotationdecaydistance,nParticleShape1.distancePP);

}

else{

$rotationdecay=1;

}

nParticleShape1.tempfloat=noise(time/10*nParticleShape1.RandRotation*nParticleShape1.tubulencerotation+nParticleShape1.particleId*5000)*$rotationdecay*0.5;///获取一个均匀变化的随机数,该数字并且可以被外部属性所控制

float $u=$normaldirection.x; //获取方向变量U

float $v=$normaldirection.z;//获取方向变量V

float $offsetU=($u+nParticleShape1.tempfloat) *  $vel ;

float $offsetV=($v+nParticleShape1.tempfloat) *  $vel  * -1 ;

////添加避开物体范围

vector $escdirection;

float $escvel;

float $esctx= getAttr escobject.tx`;

float $escty=`getAttr escobject.ty`;

float $esctz= getAttr escobject.tz`;

vector $esc=<<$esctx,$escty,$esctz>>;

float $escdis= mag(<<$particleposition.x,$particleposition.y,$particleposition.z>>-<<$esc.x,$esc.y,$esc.z>>);

if ($escdis < 20 ){

$escvel= (1 - smoothstep(0,10+nParticleShape1.escobjdis,$escdis))*0.03;

$escdirection= unit(nParticleShape1.worldPosition - $esc);

$offsetU += $escdirection.x * $escvel ;

$offsetV -= $escdirection.z * $escvel ;

}

nParticleShape1.goalU += $offsetU;

nParticleShape1.goalV += $offsetV;

////////////////////替代物体交替变换/////////////////////

nParticleShape1.instanceindex += mag(nParticleShape1.velocity)/1.5; ///该数值应该和物体运动速度进行关联

if (nParticleShape1.instanceindex > 22){

nParticleShape1.instanceindex = 0;





,Maya安装,Maya技巧