Saturday, 5 January 2013

particle to fluid script


vector $vWPos = worldPosition;
int $iIndices[] = `fluidVoxelInfo -cb -v ($vWPos.x) ($vWPos.y) ($vWPos.z) fluidShape1`;
if(size($iIndices) > 0)
{
float $fFluidVel[] = `getFluidAttr -at "velocity" -xi $iIndices[0] -yi $iIndices[1] -zi $iIndices[2] fluidShape1`;
vector $vFluidVel = <<$fFluidVel[0], $fFluidVel[1], $fFluidVel[2]>>;

vector $vWVel = worldVelocity;
vector $vNewVel = $vFluidVel * drag + $vWVel * (1 - drag);

velocity = $vNewVel;
}


add "drag" as a float scalar attrib to particleshape..
change fluidShape1 to whichever fluid

stolen from super old cgtalk thread.

10-15-2007, 03:37 PM
If you write a particle expression that evaluates the fluid velocity at the particle location (using fluidVoxelInfo and getFluidAttr) then you can apply the fluid velocity to the particle in the manner of an airfield(or drag). Such an expression would simply blend the current particle velocity with the fluid velocity:
v = fv * drag + v * (1-drag)
One could get fancier by basing the amount of drag on the particle mass(less drag for heavier particles).