You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Foundry Nuke Python中给缩放动画添加弹跳效果

给Nuke缩放动画添加峰值弹跳效果的两种方案

方案1:直接新增关键帧实现(无需表达式,最易调整)

弹跳效果本质是在缩放达到峰值1后,先小幅超过峰值,再回落至1,不需要修改原有_animate函数逻辑,仅调整调用时传入的参数即可:

animated = self._animate(
            content,
            (0, first),
            (1, self.animation_duration - 1),
            # 新增入场弹跳关键帧:1.1是弹跳幅度,可自行调整,时间间隔越大弹跳速度越慢
            (1.1, self.animation_duration + 1),
            (1, self.animation_duration + 3),
            # 退场前的弹跳关键帧,不需要可以直接删除
            (1, last - self.animation_duration - 3),
            (1.1, last - self.animation_duration - 1),
            (1, last - self.animation_duration),
            (0, last - 1),
        )

补充说明:关键帧添加完成后可以在Nuke的曲线编辑器里把关键帧插值调整为缓入缓出,效果会更自然。

方案2:使用scale表达式实现(适合批量调整弹跳参数)

如果需要灵活控制弹跳的衰减、频率等属性,可以给scale参数添加表达式,不需要新增大量关键帧,修改_animate函数如下:

def _animate(self, node: nuke.Node, peak_in_frame: int, peak_out_frame: int, *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)
    
    # 弹跳表达式:0.1为最大弹跳幅度、30为弹跳频率、0.5为衰减速度,都可自行调整
    bounce_expr = f"""
    in_bounce = 0.1*sin((frame - {peak_in_frame})*30)*exp(-max(0, frame - {peak_in_frame})*0.5);
    out_bounce = 0.1*sin(({peak_out_frame} - frame)*30)*exp(-max(0, {peak_out_frame} - frame)*0.5);
    value + in_bounce + out_bounce
    """
    scale.setExpression(bounce_expr)
    return result

调用时传入入场和退场的峰值帧即可:

animated = self._animate(
            content,
            self.animation_duration - 1, # 入场峰值帧
            last - self.animation_duration, # 退场峰值帧
            (0, first),
            (1, self.animation_duration - 1),
            (1, last - self.animation_duration),
            (0, last - 1),
        )

内容的提问来源于stack exchange,提问作者shpindler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 22:09:04