CharAI 角色動畫引擎 是做什麼的?
CharAI 是一個 2D 角色動畫引擎。你編寫一份 .char 腳本(誰、做什麼、何時)和一個皮膚檔案(人物的長相);引擎會提供骨架、動作、頭髮和服裝物理、嘴形同步以及接觸效果。它只繪製人物:沒有場景、沒有 3D、僅限側面。所有命令都在引擎資料夾(包含此檔案的資料夾)中執行。
設定(三個命令)
node --version # v18 或更高
node tools/check.cjs examples/hello.char # 最後一行: OK: 0 errors, N warning(s). Wrote examples\hello.html
node tools/sheet.cjs examples/hello.char hello.png --n=8 # 最後一行: ... 8 frames of 8s (no page errors)
如果第二個命令輸出 OK: 且第三個命令成功寫入 PNG,即表示設定成功。Sheet、render、export 和 cast 需要 puppeteer-core 以及 Chrome 或 Edge(MP4 還需要 ffmpeg);僅在第三個命令因 puppeteer 失敗時,才執行一次 npm install。檢查工具不需要任何依賴。
選擇你的任務
| 使用者說 | 請這樣做 |
|---|---|
| "製作一個 10 秒的女孩揮手影片" | 編寫一部影片 |
| "一個留鬍子的胖廚師","一個拄著拐杖的老人" | 繪製一個角色 |
| "讓他做個側手翻","她應該掩面" | 添加一個動作(先執行 ls actions/) |
| "他們擁抱","遞給我一條麵包" | 編寫一部影片(使用 pair 和 prop 呼叫) |
| "把角色放在我的頁面上","MP4","透明影片" | 嵌入或匯出 |
編寫一部影片
- 挑選演員。皮膚:
tess、kai;在examples/skins/中:tot(學步兒)、baker、captain、duchess、gramps、skye、vera。道具:ball box chair door lantern loaf thorn。 - 建立
films/<name>/film.char。將你使用的任何皮膚複製到films/<name>/skins/。 - 編寫頁首,然後是時間行(如下)。從
examples/skill-demo.char開始。 - 檢查:
node tools/check.cjs films/<name> --timeline。成功:最後一行OK: 0 errors。修復每個 ERROR;閱讀每個 WARNING。--timeline會印出+n的實際結束時間。 - 查看:
node tools/sheet.cjs films/<name> sheet.png --n=12,然後開啟sheet.png。成功:每個演員都可見,沒有人重疊,結尾卡片顯示。 - 渲染:
node tools/render.cjs films/<name> out.mp4 --fps=24。成功:wrote out.mp4: N frames。
examples/skill-demo.char:
film "Fresh loaf" 14s # 標題、長度
stage width=1400 ground=600 scale=60 # 空舞台:沒有場景
actor Baker = skin baker at 700 facing left
actor Tot = skin tot at 150
prop loaf at 850 # 一個道具放在 x=850 處
0.0 cam: cut(to=500, zoom=1.4) # 絕對時間
0.0 Baker: mood(happy), idle() # 兩個通道,一行
0.0 Tot: face(happy)
0.5 Tot: run(to=420)
0.5 Baker: say("Hello, little one!", for=1.8) # 根據文字進行嘴形同步
0.5 caption: "Hello, little one!", by=Baker, for=1.8 # 對話泡泡
+0 Baker: give(with=Tot, prop=loaf, speed=2.5) # 配對動作:一行驅動雙方
+0 Tot: face(proud)
2.0 cam: frame(on=Tot+Baker, over=1.2) # 特寫兩者
+0.5 Tot: wave() # 在 Tot 上一行結束後 0.5 秒
9.5 cam: home(over=1.0) # 離開特寫
9.5 cam: pan(to=600, over=1.0)
11.6 card: "Fresh loaf" # 結尾卡片
語法
每行一個陳述句;# 開始註解;名稱區分大小寫。
| 頁首行 | 意義 |
|---|---|
film "Title" 12s | 第一行:標題、長度 |
stage width=2400 ground=600 scale=68 | 空舞台(顯示預設值);scale = 每個頭部高度的像素數 |
set hillside [dusk] | 場景;變體 day dawn dusk night |
actor N = skin S at X [facing left] [scale=1] | 一個人物。X = 像素、錨點或名稱 |
puppet N = bird at X | 動物:bird bear lamb |
prop K [as N] [at X] | 物件;沒有 at 時,會在首次被握住時出現 |
時間行:<time> <target>: call(args), call(args)。時間是絕對秒數 (4.5) 或 +n = 在相同目標的上一行結束後 n 秒。一個目標的行必須按時間順序前進。目標:演員或木偶名稱、cam、caption、card、wind、clock。參數:位置參數 (wave(both)) 或 key=value;文字在 "引號" 中。
通道:同一行上的呼叫同時開始,並且必須使用不同的通道。演員通道:body(一次一個;用 +0 開始下一行 body)、arms、face、mood、look、say;除了 body 之外,所有通道都可以在行走時並行執行。攝影機通道:pos (pan follow cut)、zoom、shake、fade、frame (frame home)。
| 分組 | 呼叫(必要參數優先) |
|---|---|
| 移動 | walk(to, speed=1) run(to, speed=1, end=stop|skid) sneak(to) enter(from=left) jump(to, height=1) turn() bounce(times=3) |
| 姿勢 | idle() stand() kneel() crouch() sit(on=0) recoil() |
| 手勢 | wave(hand=near|far|both) point(at, for=1.5) reach(at, for=1.2) cheer() bow() shrug() clap(times=4) dance() |
| 情緒 | mood(name, strength=1) neutral happy sad angry scared tired proud shy; face(mood, strength=1) 添加 excited surprised determined |
| 臉部、說話 | look(at=front) 名稱或 up down front back;nod();say("text", for=0, beats=0) |
| 配對 | hug(with) handshake(with) highfive(with) pat(with) shove(with) give(with, prop) throwto(with, prop);speed= 或 for= 設定持續時間 |
| 道具 | pickup(prop) putdown() hold(prop, how=front|up|side) drop() sit(on=chair) knock(on=door) |
| 攝影機 | cam: pan(to, over=1.5) follow(target) cut(to, zoom=0) zoom(to, over=1) shake(amount=8) fade(dir=out|in) frame(on, top=head, bottom=thigh, x=0.35) home() |
| 文字 | caption: "text", for=3, by=Name, at=top caption: clear card: "text", for=0, sub="..." |
| 世界 | wind: gust(amount=1, over=1.5) wind: blow(amount=0.3) |
frame 的層級:head chin chest waist hip thigh knee feet。完整表格:docs/AUTHORING.md。
繪製一個角色
一個角色就是一個皮膚檔案:在 mannequin 身體上疊加一些數字和幾個 SVG 路徑。
- 將模板複製到
films/<film>/skins/mia.js。檔案名稱、name和 key 是相同的單字。 - 根據表格設定
build和motion。暫時不要繪製任何東西。 - 檢查:
node tools/skincheck.cjs films/<film>/skins/mia.js。成功:OK: 0 errors, 0 warnings。 - 查看:
node tools/cast.cjs films/<film>/skins/mia.js mia.png,開啟mia.png:六個姿勢(站立、行走、跑步、跳躍、揮手、坐下)的完整人物。 - 按此順序一次添加一項,並在每次添加後重複步驟 3 和 4:調色板(
suit= 主要服裝顏色,否則在脖子、肩膀、臀部會顯示灰色)、僅在生成頭部錯誤時添加頭部、頭髮(hide: ['hair'],你自己的路徑或鏈條)、衣服、配件。 - 如果你繪製自己的頭部,也要提供
swaps.mouth(最少open、closed)。鬍子是位於 y 0.32 以下parts.head中的獨立路徑。測試:node tools/say.cjs shapes.png --skin=mia --shapes。
| 人物 | build | motion |
|---|---|---|
| 學步兒 | { heads: 2.3 } | { age: 'baby', energy: 0.8, weight: 0.2 } |
| 兒童 | { heads: 3.5 } | { age: 'child', energy: 0.8 } |
| 成人 | { heads: 7 } | { weight: 0.4, energy: 0.6 } |
| 肥胖成人 | { heads: 5.6, belly: 0.55, chest: 1.05, waist: 1.0, hips: 0.98, seat: 0.1, arm: 0.17, leg: 0.3 } | { weight: 0.9, energy: 0.35 } |
| 高瘦成人 | { heads: 8, chest: 0.72, waist: 0.52, hips: 0.78, arm: 0.1, leg: 0.16 } | { weight: 0.1, energy: 0.5 } |
| 長者 | { heads: 6.6, belly: 0.14, arm: 0.11, leg: 0.19 } | { age: 'elder', posture: 0.7, energy: 0.3 } |
範圍:heads 2.2 到 8;arm 0.05 到 0.3;leg 0.1 到 0.45;chest、waist、hips 0.35 到 1.3;belly 0 到 0.7。路徑單位:一個頭部高度,面向右側,+y 向上。用數值修復身體問題,而不是用衣服。此皮膚通過 skincheck:
// mia.js: 一個穿著藍綠色連衣裙、綁著馬尾的高個子女人
(function (g) {
(g.CharSkins = g.CharSkins || {}).mia = { name: 'mia', extends: 'mannequin', // 一個完整的人
build: { heads: 6.5 }, // 以頭部高度為單位的身高
motion: { weight: 0.3, energy: 0.6 }, // 0 輕盈..1 沉重;0 疲倦..1 充滿活力
palette: { skin: '#d9a07a', hair: '#2b1d16', shoe: '#3a2a2a', suit: '#2f6f6a', dress: '#2f6f6a' },
parts: {
torso: { cover: [0.3, 1.1], fill: 'dress' }, // 上身緊身胸衣;到臀線為止
skirt: { skirt: true, length: 0.5, flare: 0.2, fill: 'dress' }, // 臀部以下:裙子
arm: { cover: [0, 0.3], flat: 'end', fill: 'dress' } // 手臂的前 30%
},
chains: { // 擺動的鏈條
pony: { bone: 'head', at: [-0.45, 0.8], rest: 190, seg: [0.25, 0.22],
width: [0.15, 0.13, 0.04], fill: 'hair', layer: 'back', stiff: 0.35 } // width: seg + 1 個數字
} };
})(typeof self !== 'undefined' ? self : this);
每個 fill 都是一個調色板名稱或 '#rrggbb'。swap 僅用於 parts.head;服裝使用 cover 或 skirt;保持 outline、springs、grip、handZ 不變。
添加一個動作
- 執行
ls actions/;將最接近的檔案複製到films/<film>/actions/<name>.js(或actions/<name>.js)。 - 編寫 2 到 4 個關鍵影格;
t是秒,必須遞增。使用地標(['chin', 0.05, 0.05]= 向前、以頭部高度為單位向上),而不是原始角度,這樣一個檔案就能適用於學步兒和高個男人。 - 檢查:
node tools/actioncheck.cjs actions/<name>.js。成功:OK: 0 errors, 0 warning(s)。 - 查看:
node tools/action.cjs <name> out.png --skin=tot,baker,vera(為影片自己的動作添加--film=<film>)。成功:三個角色上都有合理的姿勢。 - 使用它:在影片中寫
2.0 Mia: <name>()。
actions/ponder.js(通過 actioncheck):
(function (g) { (g.CharActions = g.CharActions || {}).ponder = { // key = 檔案名稱
channel: 'arms', // 'arms' = 在身體上方的手勢;'body' = 整個身體
doc: '手托下巴並緩慢點頭(hold = 保持在下巴處的秒數)',
args: { hold: 1 }, // 腳本:Mia: ponder(hold=2)
face: 'determined', // 播放時的情緒表情
contact: true, // 手有意識地觸碰頭部
keys: [
{ t: 0.4, handNear: 'chin', hands: 'relaxed', head: 8 }, // 手到下巴,頭部向下傾斜
{ t: 0.8, handNear: ['chin', 0.05, 0.05], head: 12 },
{ t: 1.2, handNear: 'chin', head: 4, hold: true }, // hold: true = 要讀取的姿勢
] };
})(typeof self !== 'undefined' ? self : this);
地標:top forehead eye mouth chin ear backhead neck chest belly hip back seat knee ground front up out down wall wallHigh wallLow。配對檔案(pair: true,角色 a 和 b):docs/PAIRS.md。所有關鍵影格欄位:docs/ACTIONS.md。
嵌入或匯出
| 目標 | 命令或程式碼片段 |
|---|---|
| 網頁 | node tools/build.cjs,然後 <script src="dist/char.js"></script><char-stage width="1280" height="720" skins="skins/kai.js" autoplay loop><script type="text/plain">film "x" 4s ...</script></char-stage> |
| 頁面控制的時鐘 | const m = Char.mount(el, { script, skins: CharSkins, width: 1280, height: 720 }); m.seek(t);(先載入皮膚檔案) |
| MP4 | node tools/render.cjs films/<name> out.mp4 --fps=24 |
| 透明 WebM | node tools/export.cjs films/<name> out.webm --format=webm --fps=30 |
| ProRes 4444 | node tools/export.cjs films/<name> out.mov --format=mov |
| PNG 序列 | node tools/export.cjs films/<name> frames --format=png |
| 動畫 SVG | node tools/svgloop.cjs films/<name> out.svg --fps=10 --crop=0,360,1280,360 |
| 音軌 | node tools/render.cjs films/<name> out.mp4 --audio=voice.wav |
透明輸出需要一個空舞台的影片(set 行會繪製場景)。將主機的地面線保持在腳本的 ground= 處。Remotion、HyperFrames 和 GSAP 程式碼片段未經測試:docs/HOSTS.md。
在說完成之前進行檢查
-
node tools/check.cjs輸出OK: 0 errors,並且已閱讀每個警告。 - 你已開啟 sheet PNG(影片)或 cast PNG(皮膚)並查看過。
- 沒有演員在表演時超出畫面。
- 在配對動作之後,沒有人站在另一個人裡面。
- 最後一行在影片長度之前結束(
--timeline),且長度符合要求。 - 皮膚通過
skincheck,動作通過actioncheck;編輯src/後,node --test tests/*.cjs通過。
當檢查失敗時
| 訊息(縮寫) | 修正方法 |
|---|---|
Tot has no action 'wallk'. Did you mean 'walk'? | 使用建議的名稱;訊息列出了所有有效的名稱。 |
this starts at 7.00s but the film is 6s long | 在 film 行中增加長度,或將該行提前。 |
Tot's walk from line 5 runs until 6.79s, but this line starts run at 2.00s and cuts it short | 以 +0(或在 6.8 秒)開始該行。 |
unknown skin 'zed'. Available skins: ... | 將皮膚檔案複製到 films/<name>/skins/ 或修正名稱。 |
unknown target 'Bob'. Did you mean 'Tot'? | 宣告 actor Bob = skin ... at ... 或修正名稱。 |
Tot is outside the frame ... Pan the camera to Tot first | 在該行之前添加 cam: follow(Tot) 或 cam: pan(to=Tot)。 |
Kai: walk(to=5000) is off the stage; the stage is 1400 wide. Write a place from 0 to 1400, for example walk(to=1400). | 將 to= 移到舞台內(或加寬 stage width=)。 |
Kai: hug needs a partner. Write hug(with=Tess). Actors it could be: Tess. | 為每個配對動作(hug、handshake、give...)添加 with=<actor>。 |
say: the text must be in quotes, got hello. Write: 1 Kai: say("hello") | 將 say、caption 和 card 的文字放在 "引號" 中。 |
Tess: face: 'happyy' is not a face name. Nearest valid name is 'happy', so write face(happy). Valid: neutral, happy, ... | 使用列出的名稱;mood(...) 也一樣。 |
colour 'teal' is not in the palette | 將 teal: '#rrggbb' 添加到皮膚的 palette 中。 |
'pinky' is not a landmark(actioncheck) | 使用上面列表中的一個地標。 |
警告不會使檢查失敗,但 camera wants x=5000 but stops at x=760 表示腳本有問題;planted foot slides 達 3 到 13 像素是已知情況。
限制與已知問題
...
[為翻譯而截斷]