Connect Fluids To Particles

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Connect Fluids To Particles as PDF for free.

More details

  • Words: 483
  • Pages: 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 int int

$xres = $res[0]; $yres = $res[1]; $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 ;

$fluidvel[2]

// set that velocity for the current voxel setfluidattr -at "velocity" -vv $fluidvel[0] $fluidvel[1] -xi $vx -yi $vy -zi $vz $fluid; $sampdens

$fluid`;

$transfdens

= `getfluidattr -at "density" -xi $vx -yi $vy -zi $vz = ($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; } }}

}

Related Documents

Connect Fluids To Particles
November 2019 15
Connect
June 2020 17
Connect
October 2019 26
Connect To Database
May 2020 6
Fluids
November 2019 56
Fluids)
November 2019 53