PDA

View Full Version : Averaging a vector number within certain frames


brjig
02-12-2009, 08:30 PM
OKay

soo im having this problem and been trying to figure it out for the past couple days, but im stuck and nothing seems to work.

soo i have a vector number which is the worldPosition of a particle.

this particle is moving in the world

and what I did was that the shader is gonna take the worldPosition and base its color on the worldPosition.

now I have this script.

vector $pos = particel1.position

userVector1PP = <<$pos.x,$pos.y,$pos,z>>

now the problem is is that the particle is changing color every frame, because at every frame the particle changes in the world position

so i changed the script

missileSmokeShape.userVector1PP = <<(sin($pos.x)),(sin($pos.y)),(sin($pos.z))>>

thinking that the sin function, will smooth it out, but it didnt make a difference.


Now what I want to do is that so we have the particles world position, but instead I want it to take the position every # of frames and it smoothes it out.
example
frame 1 its at (1,1,1) and at frame 10 its (2,1,2) and at frame 20 its (3,2,2)

so it will take those numbers and get the average, then, it will take the average of the next 10 frames, and then smoothly change the numbers.

but it doesnt need to be every 10 frames, it can be a set number of frames specified.

Please
ive been trying to figure this out for a couple days, I checked the mel command, but all I got was the equivalent line, but that doesnt return a value, and the floatEq but that doesnt return a value either.

any and all help would be appreciated.

The thing is that with every frame the number changing, and in turn the color changing every frame, it doesnt look right.

brjig
02-13-2009, 06:16 PM
is there anyone out there that can help me?

BigRoyNL
02-14-2009, 08:35 AM
What you could do is make an 'update' every *say* ten frames which saves one value.

You could use an iteration like X getting one bigger every frame, but when at 10 it goes back to zero and at zero it saves the value. So it skip the saving of the value every frame but once a ten frames. For a 'blur' between a ten frame values.. you must have played at least 10 frames before this could work.

It saves the value of frame zero. Then at frame 10 saves the 'second value'. Then at frame 20 overwrite the first value. Frame 30 overwrite second value. Frame 40 overwrite first value. It's smart to overwrite it like this, because otherwise at a frame 5000 you'd have saved a lot of values which fills up your cache (I think!).

You'd need one counter going to TEN (let's say X)
and another counter going to TWENTY (let's say Y)
With these two values you'll be able to write an if statement or do while statement or something like that to get the value and choose which to overwrite.

For the blurring you need another value that uses the Y value to blur between the first saved value. This is posible because
Y = 0 -> You use the FIRST value which is saved
Y = 10 -> You totally use the SECOND value (this is also where the first value get overwritten. This should be going on unnoticed, because now it's the full color of the 'second' value.
Y = 20 -> You use the FIRST value which is saved

This is just a thought, haven't put this into practice anywhere.. but I do think this SHOULD work and it should be possible to do!

Hope you are advanced with scripting to work this out.

Roy

PS.
EDIT: Now I'm thinking I'm mistaking. You should be able to do it with only a '20' frame counter. (actually a 19 frame counter, so 20 is actually the first frame again. Otherwise you'd have a still because frame 20 IS frame zero. Then make every frame zero write to first value, every tenth write to second value) This starts working also after ten frames. Because there are already two values present after 10 frames. You'd need an 'checking statement' to check if there are 'two values' present otherwise maya would give a warning that you are trying to use an unexisting value (before the first ten frames, because then you've only one value yet saved.)

BigRoyNL
02-14-2009, 10:19 AM
Something like this put in an expression would update the X every frame, save the first and second value every 'twentieth frame' with the second value a 'ten frames offset'. So every ten frames a value gets saved which can be blended.

This does nothing exciting except for the saving, the blending and some calculations. Hope this gets your head around the way I was thinking about this setup. But it works, if i'm correct.

int $x;

// IF LOWER OR EQUAL TO FRAME ZERO RESTART CALCULATIONS AND SET X AS ZERO. FRAME ZERO IS START.
if (frame <= 0) {$x = 0;}
int $firstValue;
int $secondValue;

// FOR TESTING PURPOSES A STRANGE VALUE
$testValue = (cos(time+1*0.24)+0.1);

if ($x == 0) {$firstValue = $testValue;};
if ($x == 10) {$secondValue = $testValue;};
if ($x <= 10) { $blendValue = ($firstValue*(1-($x/10)) + $secondValue*($x/10)); }
if ($x > 10) { $blendValue = ($firstValue*(($x/10)-1) + $secondValue*(1-(($x/10)-1))); }

$x = ($x + 1);
if ($x>=20) {$x=0;};

brjig
02-16-2009, 02:59 AM
THanks alot man
this looks like what I need
but im not a coder, so I have to go thru the whole script line by line and figure it out what each does, and from there just manipulate it to do what I want it to do.

again thanks alot




------------------------------------------------------------------------------------------

alright
I got it to work

sooo


i wrote notes down on the expressions
anyone who wants it can check it out

but here is basically what i did

first made the arrow point in the direction its travelling

soo create a float PP and in both creation and before and after dynamics,
say the custom pp = particle velocity;

and then in the instancing attribute the AimDirection - choose the custom array you made.


to make the arrow keep pointing in the direction it was moving when it hit the land or whatever

first create a collision event
then in the explression editor for the particle write


if (particleShape1.event == 0)
{
particleShape1.arrowDirection = particleShape1.velocity;
}
if (particleShape1.event == 1)
{
//Do nothing, the if statement already did its job
}


okay noow if you have irregular looking land, not flat, when the arrow hits the land it will move and slide no matter what the friction is, and usually arrows dont slide land when it punctures it.


soo

craeate a vector array PP (2 of them)
one pPositon
one wPosition

one is used to hold in the particle position when it hits the ground
and the other is used to make the particle stay in that area after its hit


heres the script i used.



// get the worldPosition of the particle per frame per particlel
particleShape1.pPosition = particleShape1.worldPosition;

// so when the collision event equals to 1, then take the worldPosition and store it
if (particleShape1.event == 1)
{
particleShape1.wPosition = particleShape1.pPosition;
}

//if the collision event is greater than one, since every frame the event number goes up 1 a frame
//get the wPosition which we got in the previous line and tell maya that the particle position equals
//to the wPosition it was when the event counter was 1, so initial hit
if (particleShape1.event > 1)
{
particleShape1.position = particleShape1.wPosition;
}




and then test it out
it should work


here is the file tho
to check it out

CGTalk Moderation
02-16-2009, 02:59 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.