PDA

View Full Version : Telling a script when to occur


ajk48n
04-24-2003, 06:13 PM
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.

alesmav
04-24-2003, 06:15 PM
Hmm... have you tried IF condition?

ALES

ajk48n
04-24-2003, 06:32 PM
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.

dwalden74
04-24-2003, 06:37 PM
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 :p .

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.

:beer:
David

ajk48n
04-24-2003, 07:10 PM
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.

CaptainSam
04-24-2003, 08:50 PM
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;}
}

X-Tender
04-24-2003, 08:57 PM
or try to use expressions for the ball :o ..

Buexe
04-24-2003, 09:00 PM
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

mark_wilkins
04-24-2003, 09:21 PM
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

dwalden74
04-25-2003, 09:47 AM
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.

:beer:
David

mark_wilkins
04-25-2003, 09:49 AM
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

dwalden74
04-25-2003, 10:14 AM
Yeah, Mark, thatīs what I was referring to, more of a scripting approach that an expression.

:beer:
David

larryvm
04-25-2003, 07:41 PM
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

CGTalk Moderation
01-15-2006, 12:00 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.