davidstop
01-06-2006, 07:21 PM
Hello there, I'm having some trouble with my expression so I thought I'd see if anyone could help. I've put this in the MEL forum too, hopefully thats not to cheeky :)
I'm trying to create a tornado. The shape of the tornado is created with particles, and then the position of the particles is used to fill the fluid container. The fluid also inherits their velocity, so I can render out a twisting fluid.
To create the motion of the particles I have edited a flow curve, so that they rotate around the curve as well as move along it. For the fluid, the position and velocity of each particle is taken and put into the corresponding voxel in the container. The expressions are runtime after dynamics.
// Runtime after dynamics script for curve flow particles. Causes rotation around curve.
vector $pos = Flow_particleShape.position;
vector $vel = Flow_particleShape.velocity;
// use sin and cos to add circular motion
float $posX = $pos.x + sin(Flow_particleShape.age*2);
float $posY = $pos.y;
float $posZ = $pos.z + cos(Flow_particleShape.age*2);
//do same for velocity
float $velX = $vel.x + sin(Flow_particleShape.age*2);
float $velY = $vel.y;
float $velZ = $vel.z + cos(Flow_particleShape.age*2);
//assign values
Flow_particleShape.position = << $posX, $posY, $posZ >>;
Flow_particleShape.velocity = << $velX, $velY, $velZ >>;
////////////////////////////////////////////////////////////////////////////////////////////////
//Runtime after dynamics. Emits fluid from particle positions.
cycleCheck -e off; //turns off annoying error message
if(fluid1.seedFluid){
float $partiPos[3] = Flow_particleShape.worldPosition; //stores world coordinates of particle
float $partiVel[3] = Flow_particleShape.velocity;
int $fluidIndex[3] = {-1,-1,-1}; //initialise voxel index to something that wont occur normally
//set fluid index to voxel coords if within bounds
$fluidIndex = `fluidVoxelInfo -cb -v $partiPos[0] $partiPos[1] $partiPos[2] fluidShape1`;
setFluidAttr -at "density" -ad -fv 0.01 -xi $fluidIndex[0] -yi $fluidIndex[1] -zi $fluidIndex[2] fluidShape1; //add density to fluidindex
setFluidAttr -at "velocity" -vv $partiVel[0] $partiVel[1] $partiVel[2] -xi $fluidIndex[0] -yi $fluidIndex[1] -zi $fluidIndex[2] fluidShape1;
setFluidAttr -at "density" -fv 0 -xi 0 -yi 0 -zi 0 fluidShape1; //Clear bottom corner voxel bug
}
The positioning part of the expression works OK, and so does the seeding of the fluid part, but not when I put them together. Whats happening is somehow the fluid is being seeded in the position of the particles on the original flow curve, before my rotation was added. The hardware particles can still be seen to rotate in the viewport.
On a separate note, the particles have the wrong velocity, seeming pretty much random. I want it to be in a circling motion around the curve, basically what the particles are actually doing. I have tried subtracting the particle postions at the beginning and end of the expression but with no luck.
I've attached a scene file in case you fancy a poke about. I know its a rather big post, but I'd be thankful for any help
I'm trying to create a tornado. The shape of the tornado is created with particles, and then the position of the particles is used to fill the fluid container. The fluid also inherits their velocity, so I can render out a twisting fluid.
To create the motion of the particles I have edited a flow curve, so that they rotate around the curve as well as move along it. For the fluid, the position and velocity of each particle is taken and put into the corresponding voxel in the container. The expressions are runtime after dynamics.
// Runtime after dynamics script for curve flow particles. Causes rotation around curve.
vector $pos = Flow_particleShape.position;
vector $vel = Flow_particleShape.velocity;
// use sin and cos to add circular motion
float $posX = $pos.x + sin(Flow_particleShape.age*2);
float $posY = $pos.y;
float $posZ = $pos.z + cos(Flow_particleShape.age*2);
//do same for velocity
float $velX = $vel.x + sin(Flow_particleShape.age*2);
float $velY = $vel.y;
float $velZ = $vel.z + cos(Flow_particleShape.age*2);
//assign values
Flow_particleShape.position = << $posX, $posY, $posZ >>;
Flow_particleShape.velocity = << $velX, $velY, $velZ >>;
////////////////////////////////////////////////////////////////////////////////////////////////
//Runtime after dynamics. Emits fluid from particle positions.
cycleCheck -e off; //turns off annoying error message
if(fluid1.seedFluid){
float $partiPos[3] = Flow_particleShape.worldPosition; //stores world coordinates of particle
float $partiVel[3] = Flow_particleShape.velocity;
int $fluidIndex[3] = {-1,-1,-1}; //initialise voxel index to something that wont occur normally
//set fluid index to voxel coords if within bounds
$fluidIndex = `fluidVoxelInfo -cb -v $partiPos[0] $partiPos[1] $partiPos[2] fluidShape1`;
setFluidAttr -at "density" -ad -fv 0.01 -xi $fluidIndex[0] -yi $fluidIndex[1] -zi $fluidIndex[2] fluidShape1; //add density to fluidindex
setFluidAttr -at "velocity" -vv $partiVel[0] $partiVel[1] $partiVel[2] -xi $fluidIndex[0] -yi $fluidIndex[1] -zi $fluidIndex[2] fluidShape1;
setFluidAttr -at "density" -fv 0 -xi 0 -yi 0 -zi 0 fluidShape1; //Clear bottom corner voxel bug
}
The positioning part of the expression works OK, and so does the seeding of the fluid part, but not when I put them together. Whats happening is somehow the fluid is being seeded in the position of the particles on the original flow curve, before my rotation was added. The hardware particles can still be seen to rotate in the viewport.
On a separate note, the particles have the wrong velocity, seeming pretty much random. I want it to be in a circling motion around the curve, basically what the particles are actually doing. I have tried subtracting the particle postions at the beginning and end of the expression but with no luck.
I've attached a scene file in case you fancy a poke about. I know its a rather big post, but I'd be thankful for any help
