Communitygithub.com

Blender 動畫製作

使用 Python 在 Blender 中建立並控制動畫。包括關鍵幀物件與骨骼變換、建立 IK/FK 骨架、為面部表情製作形狀鍵動畫、編輯 F-Curve 控制時間、在 NLA 編輯器中疊加動作,以及利用驅動器實現表達式驅動 — 全部可透過終端機腳本化操作。

Blender 動畫製作 是什麼?

此技能為開發者提供一套完整的 Python API,用於在 Blender 中自動化角色動畫與物件動畫。它支援多個主要平台,包括 Claude Code、Cursor 和 Codex,讓使用者能夠直接從終端機或 AI 代理程式驅動動畫工作流程。技能涵蓋關鍵幀變換(位置、旋轉、縮放及自訂屬性)、透過貝茲曲線與循環修改器控制 F-Curve 插值、建立骨架與 IK/FK 約束系統、為面部動畫製作形狀鍵動畫、在 NLA 編輯器中分層疊加動作,以及利用驅動器實現基於表達式的自動化(例如使用 `sin(frame * 0.1) * 2` 或讀取其他物件變換來驅動位置、縮放或形狀鍵數值)。提供的範例包括彈跳球(擠壓與拉伸動畫)與 IK 手臂(抓取動畫),涵蓋完整的動畫管道。此技能對於需要精準時間與機械式或程式化動作的 3D 動畫工作(例如遊戲資產綁定、角色行走循環與程序化動作設計)特別有價值。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/TerminalSkills/skills/blender-animation

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Blender 動畫製作 是做什麼的?

概述

使用 Python 在 Blender 中建立並控制動畫。包括關鍵幀物件與骨骼變換、建立 IK/FK 骨架、為面部表情製作形狀鍵動畫、編輯 F-Curve 控制時間、在 NLA 編輯器中疊加動作,以及利用驅動器實現表達式驅動 — 全部可透過終端機腳本化操作。

指令

1. 關鍵幀物件屬性

import bpy

obj = bpy.data.objects["Cube"]
# 在多個影格處設定位置關鍵幀
for loc, frame in [((0,0,0), 1), ((5,0,3), 30), ((5,4,0), 60)]:
    obj.location = loc
    obj.keyframe_insert(data_path="location", frame=frame)

# 同樣適用於 rotation_euler、scale、單一軸向 (index=2 表示 Z)、自訂屬性
obj.rotation_euler = (0, 0, 3.14159)
obj.keyframe_insert(data_path="rotation_euler", frame=60)
obj.scale = (2, 2, 2)
obj.keyframe_insert(data_path="scale", frame=60)
obj["intensity"] = 1.0  # 自訂屬性
obj.keyframe_insert(data_path='["intensity"]', frame=30)
bpy.context.scene.frame_start, bpy.context.scene.frame_end = 1, 60

2. 控制 F-Curve 插值與修改器

import bpy

action = bpy.data.objects["Cube"].animation_data.action
for fcurve in action.fcurves:
    for kp in fcurve.keyframe_points:
        kp.interpolation = 'BEZIER'  # CONSTANT, LINEAR, BEZIER, SINE, EXPO, BOUNCE, ELASTIC
        kp.easing = 'EASE_IN_OUT'   # AUTO, EASE_IN, EASE_OUT, EASE_IN_OUT
    # 循環修改器使動畫重複播放
    mod = fcurve.modifiers.new(type='CYCLES')
    mod.mode_before = 'REPEAT'       # NONE, REPEAT, REPEAT_OFFSET, MIRROR
    mod.mode_after = 'REPEAT'

# 為特定頻道加入噪聲
z_curve = action.fcurves.find("location", index=2)  # Z 位置
if z_curve:
    noise = z_curve.modifiers.new(type='NOISE')
    noise.strength, noise.scale = 0.3, 5.0

3. 建立骨架與骨骼

import bpy

arm_data = bpy.data.armatures.new("Rig")
arm_obj = bpy.data.objects.new("Rig", arm_data)
bpy.context.collection.objects.link(arm_obj)
bpy.context.view_layer.objects.active = arm_obj
bpy.ops.object.mode_set(mode='EDIT')
# (名稱,頭部,尾部,父骨骼名稱,是否連接)
bone_defs = [
    ("Spine",      (0,0,1.0),   (0,0,1.4),   None,       False),
    ("Chest",      (0,0,1.4),   (0,0,1.8),   "Spine",    False),
    ("UpperArm.L", (0.2,0,1.7), (0.5,0,1.4), "Chest",    False),
    ("Forearm.L",  (0.5,0,1.4), (0.8,0,1.1), "UpperArm.L", True),
    ("Thigh.L",    (0.1,0,1.0), (0.1,0,0.5), "Spine",    False),
    ("Shin.L",     (0.1,0,0.5), (0.1,0,0.05),"Thigh.L",  True),
]
for name, head, tail, parent, connected in bone_defs:
    b = arm_data.edit_bones.new(name)
    b.head, b.tail = head, tail
    if parent:
        b.parent = arm_data.edit_bones[parent]
        b.use_connect = connected

bpy.ops.object.mode_set(mode='OBJECT')

4. 為骨骼設定約束

import bpy

arm_obj = bpy.data.objects["Rig"]
bpy.context.view_layer.objects.active = arm_obj
bpy.ops.object.mode_set(mode='POSE')
# IK — 使用空物件作為目標,chain_count 限制受影響的骨骼數量
ik = arm_obj.pose.bones["Forearm.L"].constraints.new('IK')
ik.target = bpy.data.objects["IK_Target"]
ik.pole_target = bpy.data.objects["IK_Pole"]
ik.chain_count = 2

# 複製旋轉 — 鏡像另一物件的旋轉
cr = arm_obj.pose.bones["Chest"].constraints.new('COPY_ROTATION')
cr.target = bpy.data.objects["ChestCtrl"]
# 其他類型:LIMIT_ROTATION, DAMPED_TRACK, STRETCH_TO, COPY_LOCATION, TRACK_TO

bpy.ops.object.mode_set(mode='OBJECT')

5. 為骨骼姿態設定關鍵幀

import bpy, math

arm_obj = bpy.data.objects["Rig"]
bpy.context.view_layer.objects.active = arm_obj
bpy.ops.object.mode_set(mode='POSE')
if not arm_obj.animation_data:
    arm_obj.animation_data_create()
action = bpy.data.actions.new("WalkCycle")
arm_obj.animation_data.action = action

# 大腿擺動關鍵幀:後擺 → 中立 → 前擺
thigh = arm_obj.pose.bones["Thigh.L"]
for angle, frame in [(-30, 1), (0, 13), (30, 25)]:
    thigh.rotation_euler = (math.radians(angle), 0, 0)
    thigh.keyframe_insert(data_path="rotation_euler", frame=frame)

bpy.ops.object.mode_set(mode='OBJECT')

6. 建立並製作形狀鍵動畫

import bpy

obj = bpy.data.objects["Head"]
mesh = obj.data
if not mesh.shape_keys:  # 先需建立 Basis 鍵
    obj.shape_key_add(name="Basis", from_mix=False)

smile = obj.shape_key_add(name="Smile", from_mix=False)
for i, vert in enumerate(smile.data):
    if i in [42, 43, 56, 57]:  # 嘴角頂點
        vert.co.z += 0.02

# 形狀鍵值動畫 (0.0 → 1.0 → 0.0)
sk = mesh.shape_keys.key_blocks["Smile"]
for val, frame in [(0.0, 1), (1.0, 15), (0.0, 30)]:
    sk.value = val
    sk.keyframe_insert(data_path="value", frame=frame)

7. 使用 NLA 編輯器疊加動作

import bpy

arm_obj = bpy.data.objects["Rig"]
if not arm_obj.animation_data:
    arm_obj.animation_data_create()
# 將動作以 NLA 片段形式推送到獨立軌道
 track1 = arm_obj.animation_data.nla_tracks.new()
track1.name = "Walk"
strip1 = track1.strips.new("Walk", start=1, action=bpy.data.actions["WalkCycle"])
strip1.repeat = 4                    # 循環 4 次
strip1.blend_type = 'REPLACE'        # REPLACE, COMBINE, ADD, SUBTRACT, MULTIPLY

track2 = arm_obj.animation_data.nla_tracks.new()
track2.name = "Wave"
strip2 = track2.strips.new("Wave", start=25, action=bpy.data.actions["WaveHand"])
strip2.blend_type = 'COMBINE'        # 在走路動作之上混合
strip2.influence = 0.8               # 部分混合

arm_obj.animation_data.action = None  # 清除作用中動作,使 NLA 接管

8. 新增驅動器以實現表達式動畫

import bpy

driver = bpy.data.objects["Cube"].driver_add("location", 2).driver  # 驅動 Z 位置
driver.type = 'SCRIPTED'
driver.expression = "sin(frame * 0.1) * 2"
# 新增變數讀取另一物件的變換
var = driver.variables.new()
var.name = "ctrl"
var.type = 'TRANSFORMS'
var.targets[0].id = bpy.data.objects["Controller"]
var.targets[0].transform_type = 'LOC_X'
var.targets[0].transform_space = 'WORLD_SPACE'
driver.expression = "ctrl * 3"  # 也可透過 sk.driver_add("value") 應用於形狀鍵

範例

範例 1:彈跳球(擠壓與拉伸)

使用者請求:「讓一個球以擠壓與拉伸的效果彈跳」

import bpy

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.mesh.primitive_uv_sphere_add(radius=0.5, location=(0, 0, 3))
ball = bpy.context.active_object
ball.name = "BouncingBall"

keyframes = [  # (影格, z_pos, scale_x, scale_y, scale_z)
    (1,  3.0, 1.0, 1.0, 1.0),    (12, 0.5, 1.0, 1.0, 1.0),     # 落下
    (15, 0.3, 1.3, 1.3, 0.6),    (18, 0.5, 0.85, 0.85, 1.2),   # 擠壓 + 拉伸
    (30, 2.2, 1.0, 1.0, 1.0),    (42, 0.5, 1.0, 1.0, 1.0),     # 最高點 + 第二次落下
    (45, 0.3, 1.2, 1.2, 0.7),    (55, 1.5, 1.0, 1.0, 1.0),     # 較小彈跳
    (62, 0.5, 1.0, 1.0, 1.0),                                    # 回穩
]
for frame, z, sx, sy, sz in keyframes:
    ball.location = (0, 0, z)
    ball.keyframe_insert(data_path="location", frame=frame)
    ball.scale = (sx, sy, sz)
    ball.keyframe_insert(data_path="scale", frame=frame)

for fc in ball.animation_data.action.fcurves:
    for kp in fc.keyframe_points:
        kp.interpolation = 'BEZIER'

bpy.context.scene.frame_end = 62
bpy.ops.wm.save_as_mainfile(filepath="/tmp/bouncing_ball.blend")

範例 2:使用 IK 手臂抓取物體

使用者請求:「建立一個帶 IK 的簡單手臂骨架,並讓它動畫去抓一個立方體」

import bpy

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

arm_data = bpy.data.armatures.new("ArmRig")
arm_obj = bpy.data.objects.new("ArmRig", arm_data)
bpy.context.collection.objects.link(arm_obj)
bpy.context.view_layer.objects.active = arm_obj
bpy.ops.object.mode_set(mode='EDIT')
prev = None
for name, head, tail in [("UpperArm",(0,0,1.5),(0.6,0,1.5)),
                          ("Forearm",(0.6,0,1.5),(1.2,0,1.5)),
                          ("Hand",(1.2,0,1.5),(1.4,0,1.5))]:
    b = arm_data.edit_bones.new(name)
    b.head, b.tail = head, tail
    if prev: b.parent, b.use_connect = prev, True
    prev = b
bpy.ops.object.mode_set(mode='OBJECT')

# IK 目標 + 約束
bpy.ops.object.empty_add(type='PLAIN_AXES', location=(1.2, 0, 1.5))
ik_target = bpy.context.active_object
ik_target.name = "IK_Hand"
bpy.context.view_layer.objects.active = arm_obj
bpy.ops.object.mode_set(mode='POSE')
ik = arm_obj.pose.bones["Hand"].constraints.new('IK')
ik.target, ik.chain_count = ik_target, 3
bpy.ops.object.mode_set(mode='OBJECT')

# 讓 IK 目標動畫朝向立方體
bpy.ops.mesh.primitive_cube_add(size=0.3, location=(1.5, 0.5, 1.0))
for loc, frame in [((1.2,0,1.5),1), ((1.5,0.5,1.0),30), ((1.5,0.5,1.3),50)]:
    ik_target.location = loc
    ik_target.keyframe_insert(data_path="location", frame=frame)
for fc in ik_target.animation_data.action.fcurves:
    for kp in fc.keyframe_points:
        kp.interpolation, kp.easing = 'BEZIER', 'EASE_IN_OUT'
bpy.context.scene.frame_end = 50
bpy.ops.wm.save_as_mainfile(filepath="/tmp/arm_grab.blend")

準則

  • data_path 必須完全符合 RNA 路徑:"location"、"rotation_euler"、"scale"、'["custom_prop"]'。
  • 骨架工作流程:編輯模式處理骨骼(edit_bones),姿態模式處理約束與關鍵幀(pose.bones)。
  • 使用 IK 時,以空物件作為目標。chain_count=0 會解算整條鏈到根骨骼。
  • 形狀鍵需要先有一個「Basis」鍵。透過 key_blocks["Name"].value(0.0 到 1.0)設定動畫。
  • 插值模式:CONSTANT 用於靜止/步進、LINEAR 用於機械式、BEZIER 配合緩動用於有機動作。
  • 將 animation_data.action = None 以讓 NLA 片段驅動 — 作用中動作會覆蓋 NLA。
  • 對於行走循環,為一個步幅設定關鍵幀,然後使用 Cycles F-Curve 修改器或 NLA 重複來循環。
  • 在匯出前使用 bpy.ops.nla.bake() 烘焙約束/驅動器 — 其他軟體無法讀取它們。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能