PDA

View Full Version : Particle .position attribute returning wrong value in expression


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

apoc519
01-06-2006, 08:34 PM
For the velocity problem you're adding velocity to itself every frame PLUS you're adding the sin and cos. I think what you probably want is just

float $velX = sin(Flow_particleShape.age*2);
float $velY = $vel.y;
float $velZ = cos(Flow_particleShape.age*2);

I think it should also be in the runtime BEFORE dynamics. That might be the cause of the other problem.


Maybe you should consider doing this another way. You would have far more control if you just lofted a few circles into a cylinder. Then you can animate the circles for more interesting shapes.

Make the resulting nurbs cylinder a goal for the particles. Create a goalU and GoalV attribute for the particles and use runtime expressions like
goalU = time;
goalV = age;

so they go in circles up the cylinder until they die.

I've tried this setup with the fluid idea you're attempting and it worked really well. Look at my demo reel to see the results

davidstop
01-07-2006, 12:54 AM
Thanks for the reply Paul, actually I was using your demo reel as a reference for what I wanted to achieve :) I'll get cracking with your suggested method, thanks for the tip!

CGTalk Moderation
01-07-2006, 12:54 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.