mottosso / cmdx

Fast and persistent subset of maya.cmds
https://mottosso.com/cmdx
BSD 2-Clause "Simplified" License
193 stars 36 forks source link

AnimCurve class functionality is limited #19

Open monkeez opened 4 years ago

monkeez commented 4 years ago

I noticed that cmdx.AnimCurve is limited in what it can do. I was going to add some functionality but wanted to check with you first if you had any thoughts?

mottosso commented 4 years ago

No immediate thoughts, other than wanting to enable passing a dictionary instead of the Maya-esque times and values arguments.

mycurve.addKeys({
  1: 0,
  5: 1.24,
  12: 0
})

Oh, and the current method keys doesn't sound like the verb it is meant to be used as. Should probably be addKeys. Maybe it would also be nice with some kind of direct animation of a plug.

# psuedo
mynode["tx"] << cmdx.AnimCurve({1: 0.0, 10: 5.0, 20: 0.0})

What did you have in mind?

monkeez commented 4 years ago

Yeah, the keys method did confuse me at first so I'm all for making it addKeys.

One thing I wanted to try was supporting undo/redo via the oma.MAnimCurveChange class.

Then also adding some of the other useful functions and properties found in MFnAnimCurve.

mottosso commented 4 years ago

Sounds good to me, authoring animation via Python in Maya is a pain so anything cmdx can would be a plus.

monkeez commented 4 years ago

Thinking on your example of

​# psuedo​
​mynode​[​"tx"​] ​<<​ ​cmdx​.​AnimCurve​({​1​: ​0.0​, ​10​: ​5.0​, ​20​: ​0.0​})

I'm not sure this would work as AnimCurve wouldn't know what type to create (TL, TA, TU, etc.). Unless I'm not thinking of something?

Maybe when you set an attribute that's a dict it could create and connect an AnimCurve:

​# psuedo​
​mynode​[​"tx"​] ​= {​1​: ​0.0​, ​10​: ​5.0​, ​20​: ​0.0​}

Unless that would be considered too "magical", any thoughts?

mottosso commented 4 years ago

I'm not sure this would work as AnimCurve wouldn't know what type to create (TL, TA, TU, etc.). Unless I'm not thinking of something?

We could solve that I think by looking at the attribute type, like if it's a linear or angular attribute, and pick a curve type to match.

Maybe when you set an attribute that's a dict it could create and connect an AnimCurve:

That's not a bad idea! Looks like when you set a single value, except you're setting multiple. And maybe if you set a list..

mynode​[​"tx"​] = [0.0, 5.0, 0.0]

It would resort to using the index - i.e. 0, 1, 2 - as the time. Except oh, no. That wouldn't play nice with setting array values, like ["t"]. But dictionaries are unused, so there's room for that.

An alternative I thought of, to make it a little less magical and readable to the non-cmdx'er would be..

mynode["tx"].animate({1: 0.0, 10: 5.0, 20: 0.0})
monkeez commented 4 years ago

With the animate method lists could also be supported for setting by index:

​mynode​[​"tx"​].​animate​([0.0​, ​5.0​, 0.0​])

I suppose if we really wanted to support list and dict animation via assignment we could do something like this:

​mynode​[​"tx"​] = cmdx.Keys({​1​: ​0.0​, ​10​: ​5.0​, ​20​: ​0.0​})
# or
​mynode​[​"tx"​] = cmdx.Keys([​0.0​, ​​5.0​, ​​0.0​])

Keys could accept other options like interpolation:

mynode​[​"tx"​] = cmdx.Keys({​1​: ​0.0​, ​10​: ​5.0​, ​20​: ​0.0​}, interpolation=cmdx.Linear)

Just an idea, I'm happy to start off the the animate method though.

mottosso commented 4 years ago

Also a good idea, nice one. :)

How about we start with .animate, which would also get called whenever a dict is passed straight to a plug? Similar to how .write is called whenever you pass a regular value. Then we can take both of those for a spin and get a feel for it.