Expressions And Time

Hello

I posted this in the animation section of the forum. But I think this section is more appropriate for this kind of request.

I'm trying to query an attribute at a user given time in an expression to add lag to the transformation.
The main purpose is to keep everything interactive.
Here's an example of a non interactive expression:

CODE
joint2.rotateX = getAttr -t (frame-5) joint1.rotateX;

The problem is that I need to scrub in the timeline before I can see the result...

Joojaa(da man) told me there was a workaround for this:
QUOTE(Joojaa)
Expressions arent mel but they do parse and execute them it however needs a connection is need to trigger it And a output MUST be affected, this is easy to fool. all you need is to read a input for change and put a output in between and after you can do whatever you wish and it gets executed every time you change the input.

Is it possible to give me a little step by step example of this please?

Thx in advance

Yesd yes but you dont understand that only satisfies the 1 part of the condition. Theres no use of asking the value at a different time untill it CHANGED at that different time. But yes.

do something like (didnt test should work):

$val=joint1.rotateX;
joint2.rotateX = getAttr -t (frame-5) joint1.rotateX;
joint1.visibility=$val+10000000;

Anyway dont use this getAttr foir this if you can. sicne the data IS possible to cache. It dont actually matter ifd you use the cached or not. Since chacnging the alue doenst change past. If you do then you usde a duplicate data structure so not to pollute the workspace your in.

See what happens is:

you have a value, you change value maya marks it for update, cheks what something is in the past, you set key -> past changes. so if you want to see the past dynamically at the change YOU ALSO NEED TO UPDATE THE PAST IN THAT CHANGE.

Mostly however you DO NOT EVER NEVER UNDER ANY CIRCUMSTANCE want to use getAttr -t in a expression. No matter how wondeful it sounds because the past is NOT known at the time of update. And you really dont want it to hence you use a separate data structure for that.

Also you DO NOT WANT to work outsdie the dg, you can but im not taking any blame what your maya grinds into a halt. Because its unclear for meya what the sequence of evaluation should be. Also it makes certain thisng hard to animate since you MIGHT NOT knwo what will happen in advance.

Thanks a lot.

Breaking the rules will probably generate more problems than it will solve.

I also tried to use a timeCache node. But it isn't interactive either.

Animators would like to see the result of what they are doing interactively. Even if attributes are queried at a different time than the current time. Since it's not possible(with simple operations), we'll animate the lag manually.

I guess the developpers had good reasons not to process everything interactively. Still think this shortcomming is one to put on the features wishlist... (it's not an issue at all for all other 3Dappz I know). It's the 1st time I can't find a descent workaround for an issue in Maya. (frrrustrrrating)

Im not going to tell you how to do this outright, my price is you understanding what it is you are doing to maya. This is very critical maya functionality. You can either accept how maya works or make your life a misery.

QUOTE
(it's not an issue at all for all other 3Dappz I know)

yes but then wed loose mayas arbitrary controll architecture. Wich is the reason we use maya.

QUOTE(ljilekor @ 02/11/08, 12:06 PM) [snapback]280901[/snapback]
I guess the developpers had good reasons not to process everything interactively.

It is possible to do but you have to understand how may works (and when to update). if you dont then you can never pull this one off without understanding the problem.

see maya works on netwrok of connections this i what makes maya so flexible and fast. So a anim curve is connected to your animated attribute etc etc like this.

-> =connection
X> =disabled connection

CODE
anim curve->node

now the reason why asking for the data when you modify the node is futile is because once you move the object maya does what is essentially this:
CODE
anim curve X> manipulator ->node

Now why the hell would they do it like this? Well simply put otherwise the node would be immovable (data set and dirty would cause maya to re-evalueate the anim curve). Now since data moves downstream and since the manipulator data is always clean (actually maya fetches data down up but only becase up down sends dirtyness signals). Now nothing has changed in the enim curve while you moved the node because it dont know what happens.

This leads to a brilliant maya feature, doing manipulation on simple network is allways extremely fast, and you can at any time omit keying your state by just changing time.

Now then why you simply cannot ask for the other time of the anim curve node. Because truly MAYA does not know it yet as no information has changed in the past as nothing is committed yet. Only the local frame has changed not the past.

when you use the setkey command maya fetches the current value in the target slot of and puts it in to the anim curve node. Now this data is available AFTER the key has been set. but your movemen hapopens before. Now what you propose looks something like this.

CODE
+-> anim curve X> node--+
+-----------------------+

Now it doesn't take a rocket scientist to see why this is bad. What would eventually happen is that maya keys EVERY SINGLE frame. Secondly maya would allways spend the extra time to update keyframes wich is a quite heavy operation en masse. Which would kill your performance. (to clarify the above looks like this runtime)

CODE
time -> anim curve -> node-> anim curve

Now you can actually do this however you need to do a bit of massive engineering here. You need to start thinking in a bit larger scale or shall i say time (to be honest i wouldnt do this in mel, but i have in the past and it works). To separate thinking let us first define 3 distinct time zones the animatr experiences:

  • gui time
  • manipulation time
  • time change time
  • Now the problem is that as far as mayas concerned manipulation time and time change time are one and the same thing (playback time). Now the bad news is that no Script job runs playback time, they are on purpose restricted to gui time only. In fact if you are a programmer and think what script jobs are used for youd be supprised to hear that they are only usefull in keeping guis up to date outside playback. And thus often not what you think they are.

    This means you need BOTH a scriptJob and a expression for EVERYTHING you want to listen to. Now then what the hell does the scriptjob do? Well it monitors whats selected, and uses that to enable the expressions one at time when playback mode is initiated, and swithces undo inactive, but not time slider change (to this end you need to mdify the gui hooks). Now the expression does in pseudocode this:

    get value with expression language syntax (expressions arent mel) and assigns it to variable.
    sets key of the drivien keyframe list
    gets the value (yes now you can read it)
    uses expression syntax to set a dummy affected net value to a return value thats NOT static eg the variable you asked

    now it doesnt work properly, since you just lost undo so what the scriptjob needs to d comming out is to once more key the values and possily time change. And now it works. But yes youll probably end up with problems when bach rendering if yoru not careful.

    This said:

    theres a easier way, instead of keying back in time key out to another curve that has a offset time this makes for a more manageable system.

    CODE
    time ---------------->plusminus (-5)------------+ (time)
    implicit time->anim curve X> manipulator-> node +> curve 2 -> node 2

    Now this has the benfit that you don't need to bacupdate anim curve as the date is forward cahced in node 1 and you don't need to have the scriptjob as yu can just allways push the data with local undo off. A second very good thing si that the expression can be deleted piror to render and jsut fed a copy of original curve wich meake sfor less debug in batch mode. Its also faster for maya to evaluate, but prominently it cannot break the same way as the above.