Вы находитесь на странице: 1из 2

// define the particle to emit from

// and the fluid-container to emit into


string $particle = "particleshape1";
string $fluid = "fluidshape5";

// variable definitions

int $i, $vx, $vy, $vz;


float $pos[], $partdens[], $partvel[], $sampdens[], $fluidvel[], $transfdens,
$particlecol[], $transcolor[];
float $px, $py, $pz;
vector $voxel;

// get the resolution of the fluid-container and the current particle-count


float $res[] = `getattr ($fluid + ".resolution")`;
int $pcount = `particle -ct -q $particle`;

int $xres = $res[0];


int $yres = $res[1];
int $zres = $res[2];

for ($i = 0; $i< $pcount; $i++){

// retrieve coordinates for every particle


$pos = `getparticleattr -at position ($particle + ".pt[" + $i + "]")`;

// retrieve rgbpp-attribute aka color of every particle


$particlecol = `getparticleattr -at rgbpp ($particle + ".pt[" + $i + "]")`;
$transcolor[0] = $particlecol[0];
$transcolor[1] = $particlecol[1];
$transcolor[2] = $particlecol[2];

// get eventpp-attribute to check if particle has collided yet


float $evpp[] = `getparticleattr -at eventpp ($particle + ".pt[" + $i +
"]")`;

// retrieve the voxel which we have to emit into


$px = $pos[0];
$py = $pos[1];
$pz = $pos[2];
$voxel = `fluidvoxelinfo -voxel $px $py $pz fluid1`;

$vx = $voxel.x;
$vy = $voxel.y;
$vz = $voxel.z;

// has the particle collided yet?


if ($evpp[0] >= 1){

// is the particle actually inside the fluid-container?


if($vx < $xres && $vx > 0 && $vy < $yres && $vy > 0 && $vz < $zres &&
$vz>0){

// retrieve the per-particle density-attribute


$partdens = `getparticleattr -at densitypp ($particle + ".pt["
+ $i + "]")`;
// does the particle have enough densitypp left? if not, kill it!
if($partdens[0] <.001){
select ($particle + ".pt["+$i +"]");
setparticleattr -at lifespanpp -fv 0;
}
// else, emit its density and color into the fluid-container at the
specific voxel-coordinates
else{
// retrieve the current velocity of the particle and of the voxel
$partvel = `getparticleattr -at velocity ($particle +
".pt[" + $i + "]")`;
$fluidvel = `getfluidattr -at "velocity" -xi $vx -yi $vy -zi
$vz $fluid`;

// distribute evenly between the velocities of the particle and


the voxel
// same goes for the density further below
$fluidvel[0] = ($fluidvel[0]+$partvel[0]) / 2 ;
$fluidvel[1] = ($fluidvel[1]+$partvel[1]) / 2 ;
$fluidvel[2] = ($fluidvel[2]+$partvel[2]) / 2 ;

// set that velocity for the current voxel


setfluidattr -at "velocity" -vv $fluidvel[0] $fluidvel[1]
$fluidvel[2] -xi $vx -yi $vy -zi $vz $fluid;

$sampdens = `getfluidattr -at "density" -xi $vx -yi $vy -zi $vz
$fluid`;
$transfdens = ($partdens[0]- $sampdens[0])/2;

// emit the density into the current voxel


setfluidattr -at "density" -ad -fv $transfdens -xi $vx -yi $vy
-zi $vz $fluid;

// emit the color (rgbpp of the particle) into the current voxel
setfluidattr -at "color" -ad -vv $transcolor[0] $transcolor[1]
$transcolor[2] -xi $vx -yi $vy -zi $vz $fluid;

// reduce the particle's densitypp by the amount that was just


emitted
$transfdens = $partdens[0]-$transfdens;
select ($particle + ".pt[" + $i +"]");
setparticleattr -at densitypp -fv $transfdens;
select -cl;
}
}
}}

Вам также может понравиться