Telling a script when to occur

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
  04 April 2003
Telling a script when to occur

This is a two part question. Let's say I have a ball bouncing, and I want a script to execute whenever the ball has reached the height of it's bounce.

First, how do I find out when then tangent of the y-position curve in the graph editor is equal to 0. This wouldn't just work for when the tangent of a key is 0, but would need to be when the tangent of any point on the curve is 0.

Second, when this occurs, how would I get a script to execute then. I'm not quite sure if this is even possible with MEL, or if it would have to be written into a plug-in.

Thanks for any help.
 
  04 April 2003
Hmm... have you tried IF condition?

ALES
 
  04 April 2003
Unfortunately, if I run a MEL statement that has an IF statement it will only check the one time that I execute it. I don't know any way through MEL to make something keep checking through the animation.

Allthough, now that I think about it, I guess I could have the command search through every frame to see if the condition is ever met.

However, I would still like to know if there is a better way.
 
  04 April 2003
Quote: how do I find out when then tangent of the y-position curve in the graph editor is equal to 0


The keyTangent MEL command let´s you read/write tangency info at a specific keyframe, but not at any non-keyed frame. You could, however, get the animCurve value at any given time, then using some basic math formulas you can then calculate the tangency of the curve. Consult a math book for that though .

Quote: when this occurs, how would I get a script to execute then


Two options: either with an expression, or with a script node. Look at the Maya docs for more info on these.


David
 
  04 April 2003
Thanks a lot.

It's too bad you can't read the tangent of a curve when it's not on a keyframe though, especially since spline curves default to going past the value of a keyframe if you have 2 keyframes near each other.

I know how to do the math for it, I was just wondering if there was any explicit MEL command for it.

Thanks again for the help.
 
  04 April 2003
How about using a scriptJob.

pseudo code (dont remember exactly how to write this):


scriptJob -event AttributeChanged node.attr command;

global proc command()
{
if (`getAttr node.attr `==666)
{do command;}
}
__________________
CaptainSam
 
  04 April 2003
or try to use expressions for the ball :o ..
__________________
| xt_textureStudio | xt_prefabLibrary |xt_normalis | Get it @ Fuchtelworld V.3 |
 
  04 April 2003
Shouldn`t an expression do the job since it can tell when the ball reaches a certain height/value and then executes whatever mel command/script you like?
0.2 cent
buexe
 
  04 April 2003
hmm.

Well, one way to do it is to write an expression that grabs the translation value from a previous frame using getAttr. However, I personally don't like using getAttr in expressions and I can't help but think that most of the time there's another way to do what you're really trying to do.

Another alternative is to make a new attribute, then hand-key that attribute so that it has a particular value on the frames where you want your script to run, then use an if statement in the expression. If you had a tremendous number of bouncing balls you could easily script the keying of this attribute so that your workflow would look like this:

1) Animate (or simulate) balls bouncing.

2) Run a script as a post-process that keys the custom attribute to 1 on frames where your script should run and 0 where it should not.

3) Play back the scene, which would include an expression that would do whatever when the keyed custom attribute was 1 and would do nothing when it's 0.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
  04 April 2003
Quote: It's too bad you can't read the tangent of a curve when it's not on a keyframe though


Well, what you could do is set a temporary keyframe at the given time by using `setKeyframe -insert`. This will add a key such that the shape of the current curve is not modified. Then use `keyTangent` command to read the tangent info. Then just delete this key when you´re finished. Sounds like it could work.


David
 
  04 April 2003
I'd only do that if you're doing something like I suggest where you use a MEL postprocess -- if you start keying stuff in expressions, watch out! It'll be dog slow!

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
  04 April 2003
Yeah, Mark, that´s what I was referring to, more of a scripting approach that an expression.


David
 
  04 April 2003
you can make it adding two new attributes in the ball, one call previousY and store the position in the frame before, the other call up and be a boolean
and store if the boll is going up.

this could be done in a script or in a expresion
you get the frame when the ball begin to go down

and in pseudo code


if frame()<>1
{
velocity=currentpositionY-previosY

if velocity<0 and up==true
{
call the script
}


if velocity>0
{
up=true
}
else
{
up=false
}
}
previousY=currentY
__________________
larry@larryvizoso3d.com

Last edited by larryvm : 04 April 2003 at 11:55 AM.
 
  01 January 2006
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 02:02 AM.


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