How to add a number per a frame?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  05 May 2007
How to add a number per a frame?

How would I write a script that would add the value of one attribute to another attribute per every frame?

Like say I have a value of 1 for an attribute and I want to add 0.5 to it every frame.
So the first frame the attribute value is 1.5
the second is 2
the third is 2.5, etc.

I know how to script it to add it once and change as the attributes change, but now how to get it to continuously add it.
 
  05 May 2007
For a script you could look for a scriptJob solution. But it sounds like an expression for that attribute would work better for you. Just use something like:

if (frame == 0 )
pSphere1.translateX = 0;

pSphere1.translateX = pSphere1.translateX + 0.2;

You'd need the if (frame == 0 ) to reset your attribute to initial value. This will add 0.2 to translate X attribute each time the expression is executed, that is when frame changes. Thus this will also increment translateX if you'll scroll the time slider backwards. If that's an undesired behavior you could go with a "formula" like solution:

pSphere1.translateX = frame*0.2;

Which is the same as saying, for each new frame, add 0.2 to the translateX of the sphere.

Hope that helps
__________________
Diffusion Curves

Wip

 
  05 May 2007
Er, yeah, I did mean expression (it's all scripting in my head).

That's pretty close to what I want, but not quite. I need to be able to maintain the initial position that it starts off it is part of it, and the other part is I need the ability to rewind the thing. Here, I wrote out an explination of what I'm trying to do but then answered my own question by writting it out so never posted it. This is just the one part I'm trying to figure out still, but should help shed some light on the math I need back.

Let me know if this makes sense, because half way through this switched from an explination for a post to more my personal notes of what I need.


So I'm animating particles flowing down a curve using Maya curve flow effect.
My goal is to be able to adjust the speed of the particles flowing along it in animation.
The issue I run into now is when I animate the speed, by adjusting the lifeSpan of the particles, they backtrack back down the curve when I turn up the Lifespan to slow down the particles, and jump forward when I turn down the lifespan to speed them up. (Their life span is how long they take to get across the curve. A lifespan of one second will take one second or 30 frames to get from the begining to the end of the curve.)
This is best how I understand the curve flow is built, at least for the speed and follow of the curve.
When created Maya places locators evenly spaced out across the curve. The particles use those locators as goals to travel to.
Each one of those locators is pluged into a color ramp. The translate vectors are pluged into the rgb value of the ramp. When a particle is born, using it's age normalized, it runs a value of 0 to 1 across the ramp, 0 being the top of the ramp, 1 being the bottom. As it travels across the ramp it's hitting those locator values to go hit as goals. I beleive the ramp allows those vectors to be blended between each other to allow a smooth transition from goal to goal. In short, the lifespan of the particle is equivilant to the length of the ramp. The ramp has the locators spaced out across it, which are spaced out across the curve.

So from particle birth to particle death (lifespan) is the time range.
Time range is equivillant to the ramp.
The length of the ramp is equivillant to the length of the curve.
a life span of 1 is 1 second of life, which is 30 frames. That means it takes 30 even steps across the length of the curve.
If we're on frame 15 at this point, that's 50% of the ramp.
But, if we change the lifespan up to 2 at this point, and we're still on frame 15, we're now only at 25% of the lifespan, and thus 25% of the ramp.
The error that occurs now is the particle backtracks to be at the 25% mark of the ramp rather than staying at 50% and meerly adjusting the amount of steps it needs to take the rest of the way down the ramp.

Lifespan is run through the age normalized attribute. What ever the lifespan is age normalized will convert that range to a value between 0 and 1

So what I need is a script or equation that keeps track of the percentage the particle has traveled and doesn't let it go under that percentage.
It has to be made a way that the values of the range of the lifespan can gradualy change as well.

So maybe what I need is one attribute that just has the percentage the particle is currently at.

if the life span is 1, we're one frame 15, that means we're at a normalized age of 0.5 Hold on to 0.5
at a lifespan of 1, the percentage step we count up every frame is 0.0333333 or 1/30.

Now, if we want to slow down the particles, and up the lifespan to 2, lets ignore the percentage that would currently put the particles at but count the steps left it needs to take for that speed.
1/60 = 0.0166667
So now we could add 0.016667 every frame to our attribute that we have and that should add one every frame to give us the right speed.

How do we make a mel script that adds a number per a frame?
 
  05 May 2007
I've anything, could somebody remind me what == and += mean again? I can't find any documentation that says, but I know I've read it some where before.
 
  05 May 2007
if(frame == 0)
This means, if "frame" is equal to zero.

$value += 0.2
this is shorthand for $value = $value + 0.2.
 
  05 May 2007
Originally Posted by Evil The Cat: How would I write a script that would add the value of one attribute to another attribute per every frame?

Like say I have a value of 1 for an attribute and I want to add 0.5 to it every frame.
So the first frame the attribute value is 1.5
the second is 2
the third is 2.5, etc.

I know how to script it to add it once and change as the attributes change, but now how to get it to continuously add it.


it seems as easy as this :
$value = 1 + (frame/2);
 
  05 May 2007
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:55 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.