shpindler
shpindler

Reputation: 387

How to create bounce animation in Foundry Nuke Python?

I have a scale animation from 0 to 1 and then from 1 to 0:

def _animate(self, node: nuke.Node, *args: (int, int)) -> nuke.Node:
    result = nuke.nodes.Transform(inputs=[node])

    result["center"].setValue(result.width() / 2, 0)
    result["center"].setValue(result.height() / 2, 1)

    scale = result["scale"]
    scale.setAnimated()
    for value, time in args:
        scale.setValue(value, time=time)

    return result


def apply(self, bg_file_path: str, content_file_path: str, dst: str) -> None:
    ...
    animated = self._animate(
                content,
                (0, first),
                (1, self.animation_duration - 1),
                (1, last - self.animation_duration),
                (0, last - 1),
            )
    ...

How to add bouncing on max value - 1? I guess I should use set expression on scale as well.

Upvotes: 0

Views: 269

Answers (1)

tk421storm
tk421storm

Reputation: 373

You'd want to be setting keyframes (probably in a sin curve-ish), then use python to set your tangents - I've never done it, but checking out the docs, once you've got your keyframe obj:

https://learn.foundry.com/nuke/developers/105/pythonreference/nuke.AnimationKey-class.html

You'd want to set the keyframe tangents as they reach the ground to "LINEAR", and when the ball reaches its apex, set the tangents to "SMOOTH".

Might be helpful to do it manually once in the GUI, see what curves look the best, then write the code to mimic.

Upvotes: 0

Related Questions