How to easein easeout for eqlinear() ?

   1541   6   0
User Avatar
Member
620 posts
Joined: Nov. 2013
Offline
Hi,

How to ease in, ease out for qlinear() interpolation animation?

Thanks!
User Avatar
Member
8539 posts
Joined: July 2007
Offline
as the name suggests it's just linear, AFAIK there is no equivalent quaternion interpolation function to TCB or TCBS functions in other DCCs like in MAX or XSI
there is an RFE for it #79013, but feel free to submit one too
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
122 posts
Joined: June 2019
Offline
hi
In that case you probably need to implement custom interpolation. It’s actually a very interesting question but I would suggest doing that kind of thing in chops.

If you really want easing in expressions you can try something like that:

start_rotation = [0, 0, 0]
end_rotation = [0, 0, 0]

def ease_in_out_cubic(t):
    x = (4 * t * t * t) if t < 0.5 else ((t - 1) * (2 * t - 2) * (2 * t - 2) + 1)
    return x

def qlinear_ease():
   
    component_map = {"x":0, "y":1, "z":2}

    local_time = float(hou.expandString("$LT"))
    start_time = float(hou.expandString("$IT"))
    end_time = float(hou.expandString("$OT"))
    
    param_name = hou.expandString("$CH")
    param_component = param_name[-1:]
    
    normalized_time = hou.hmath.fit(local_time, start_time, end_time, 0, 1)
    
    start_rotation[component_map[param_component]] = float(hou.expandString("$IV"))
    end_rotation[component_map[param_component]] = float(hou.expandString("$OV"))
       
    start_orientation = hou.Quaternion()
    start_orientation.setToEulerRotates(start_rotation)
    end_orientation = hou.Quaternion()
    end_orientation.setToEulerRotates(end_rotation)
    
    time_with_easing = ease_in_out_cubic(normalized_time)
    current_orientation = start_orientation.slerp(end_orientation, time_with_easing)
    
    current_rotation = current_orientation.extractEulerRotates()
    
    return current_rotation[component_map[param_component]]

Just put it in a session module and paste qlinear_ease() to the channel (considering python is an expression language for node). But this code is pretty hacky so I wouldn't use it in real project.

I also attached the sample scene.
Image Not Found


However it’s not an actual smooth interpolation of quaternions, it’s basically just a remapping of slerp factor. So you have just smooth start and stop between keyframes. For real spherical splines you should use something like SQUAD (https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf) but again - I don’t think it’s possible in expressions

Attachments:
rot_test.hipnc (198.7 KB)

User Avatar
Member
7759 posts
Joined: Sept. 2011
Offline
elovikov
However it’s not an actual smooth interpolation of quaternions, it’s basically just a remapping of slerp factor. So you have just smooth start and stop between keyframes. For real spherical splines you should use something like SQUAD (https://www.cs.cmu.edu/~kiranb/animation/p245-shoemake.pdf) but again - I don’t think it’s possible in expressions
Attachments:

Have you gotten squad to work? I tried to implement one in VEX that takes an array of quats, but I never got it to output anything approaching smooth.
I was following the microsoft notes, but I must have made a mistake somewhere

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb281656(v=vs.85)
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb281657(v=vs.85)
User Avatar
Member
8539 posts
Joined: July 2007
Offline
jsmack
Have you gotten squad to work?
in VEX you can potentially use slerp(qs[], weights[])
but again for animation interpolation function I'd prefer TCB or TCBS controls, so that it's continuous and tweakable for animators
Edited by tamte - Feb. 24, 2020 18:05:22
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
122 posts
Joined: June 2019
Offline
jsmack
Have you gotten squad to work? I tried to implement one in VEX that takes an array of quats, but I never got it to output anything approaching smooth.
I was following the microsoft notes, but I must have made a mistake somewhere

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb281656(v=vs.85)
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb281657(v=vs.85)

I know, it can be tricky as vex doesnt have all the necessary functions. You need quaternion log, exp and also custom slerp which doesn't take the shortest path. Also you have to keep in mind that vex doesn't support custom operators so you can't just multiply quats as you can see sometimes in other languages. I mean you can it just means per-component multiplication.

I found this library very useful for implementation: https://github.com/CesiumGS/cesium/blob/master/Source/Core/Quaternion.js [github.com]

I've attached a simple scene with example of using squad on quats array (also wrangles code: https://pastebin.com/ee98C17W) The DirectX SquadSetup equivalent would be get_squad_control() that calculates control point for specifed keyframe. With this setup you just have to calculate these points for each key and then interpolate between them with qsquad() providing 2 keys and 2 corresponding controls.

Attachments:
squad.hipnc (227.8 KB)

User Avatar
Member
122 posts
Joined: June 2019
Offline
tamte
in VEX you can potentially use slerp(qs[], weights[])
but again for animation interpolation function I'd prefer TCB or TCBS controls, so that it's continuous and tweakable for animators

Yeah, this squad thing is more useful for procedural animations. It's just something that I'm working on)
and actually I think tcb rotation controllers based on something similar under the hood
  • Quick Links