@openbone/mcp 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bridge.d.ts +2 -2
- package/dist/bridge.js +8 -1
- package/dist/export.d.ts +5 -1
- package/dist/export.js +11 -6
- package/dist/guide.d.ts +1 -1
- package/dist/guide.js +5 -1
- package/dist/render.d.ts +7 -0
- package/dist/render.js +57 -6
- package/dist/server.js +34 -2
- package/dist/tools-extra.js +3 -0
- package/package.json +7 -7
package/dist/bridge.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { type WebSocket } from "ws";
|
|
|
4
4
|
import type { ProjectSession } from "./session.js";
|
|
5
5
|
export interface BridgeFile {
|
|
6
6
|
src: string;
|
|
7
|
-
kind: "image" | "audio";
|
|
7
|
+
kind: "image" | "audio" | "font";
|
|
8
8
|
mime: string;
|
|
9
9
|
base64: string;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Files the document refers to by a relative path that `sent` (src → modification time) hasn't had yet, or that
|
|
13
|
-
* changed on disk since. Only image and
|
|
13
|
+
* changed on disk since. Only image, audio and font files, read from `baseDir`. Missing files are skipped.
|
|
14
14
|
*/
|
|
15
15
|
export declare function pendingFiles(doc: OpenBoneDocument, baseDir: string, sent: Map<string, number>): BridgeFile[];
|
|
16
16
|
export declare function startBridge(session: ProjectSession, port: number, log: (m: string) => void): import("ws").Server<typeof WebSocket, typeof IncomingMessage>;
|
package/dist/bridge.js
CHANGED
|
@@ -17,6 +17,10 @@ import { isLocalRequest } from "./local-only.js";
|
|
|
17
17
|
* server sends the file's bytes ("files"), and the editor shows and plays them from memory.
|
|
18
18
|
*/
|
|
19
19
|
const MEDIA = {
|
|
20
|
+
ttf: { kind: "font", mime: "font/ttf" },
|
|
21
|
+
otf: { kind: "font", mime: "font/otf" },
|
|
22
|
+
woff: { kind: "font", mime: "font/woff" },
|
|
23
|
+
woff2: { kind: "font", mime: "font/woff2" },
|
|
20
24
|
png: { kind: "image", mime: "image/png" },
|
|
21
25
|
jpg: { kind: "image", mime: "image/jpeg" },
|
|
22
26
|
jpeg: { kind: "image", mime: "image/jpeg" },
|
|
@@ -31,7 +35,7 @@ const MEDIA = {
|
|
|
31
35
|
};
|
|
32
36
|
/**
|
|
33
37
|
* Files the document refers to by a relative path that `sent` (src → modification time) hasn't had yet, or that
|
|
34
|
-
* changed on disk since. Only image and
|
|
38
|
+
* changed on disk since. Only image, audio and font files, read from `baseDir`. Missing files are skipped.
|
|
35
39
|
*/
|
|
36
40
|
export function pendingFiles(doc, baseDir, sent) {
|
|
37
41
|
const srcs = new Set();
|
|
@@ -41,6 +45,9 @@ export function pendingFiles(doc, baseDir, sent) {
|
|
|
41
45
|
for (const a of doc.audio?.assets ?? [])
|
|
42
46
|
if (a.src)
|
|
43
47
|
srcs.add(a.src);
|
|
48
|
+
for (const f of doc.fonts ?? [])
|
|
49
|
+
if (f.src)
|
|
50
|
+
srcs.add(f.src);
|
|
44
51
|
const out = [];
|
|
45
52
|
for (const src of srcs) {
|
|
46
53
|
if (/^(data:|https?:|blob:)/i.test(src))
|
package/dist/export.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export interface ExportRequest {
|
|
|
40
40
|
time?: number;
|
|
41
41
|
engine?: SheetEngine;
|
|
42
42
|
singleFile?: boolean;
|
|
43
|
+
/** web: player display (defaults: contain, clipped, auto in full screen). */
|
|
44
|
+
fit?: "contain" | "cover" | "auto" | "none";
|
|
45
|
+
clip?: boolean;
|
|
46
|
+
fullscreenFit?: "auto" | "cover" | "contain" | "none" | "same";
|
|
43
47
|
minify?: boolean;
|
|
44
48
|
binary?: boolean;
|
|
45
49
|
/** avi/mov/mp4/webm: include the sound the run plays (default true). */
|
|
@@ -78,7 +82,7 @@ audioOut?: TimedMixCommand[]): Promise<Frame[]>;
|
|
|
78
82
|
export declare function jpegOf(f: Frame, bg: string, quality?: number): Uint8Array;
|
|
79
83
|
/** Bytes of a document asset src (data: URI or a path relative to the project). */
|
|
80
84
|
export declare function assetBytes(session: ProjectSession, src: string): Promise<Buffer>;
|
|
81
|
-
/** Copy of a document with every image, atlas page and
|
|
85
|
+
/** Copy of a document with every image, atlas page, audio and font file embedded as data: URIs (self-contained exports). */
|
|
82
86
|
export declare function embedAssets(session: ProjectSession, d: OpenBoneDocument): Promise<OpenBoneDocument>;
|
|
83
87
|
/** Pack a (runtime) document's images into atlas pages with the dialog's settings; returns a packed copy and any warnings. */
|
|
84
88
|
export declare function packDocument(session: ProjectSession, d: OpenBoneDocument, o?: AtlasExportOptions): Promise<{
|
package/dist/export.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { createCanvas } from "@napi-rs/canvas";
|
|
4
|
-
import { animationDuration, applyOp, exportDocument, serialize, serializeBinary } from "@openbone/core";
|
|
4
|
+
import { FONT_MIME, animationDuration, applyOp, exportDocument, serialize, serializeBinary } from "@openbone/core";
|
|
5
5
|
import { buildSpriteSheets, createZip, encodeApng, encodeAviMjpeg, encodeGif, encodeMovMjpeg, encodePng, encodePsd, atlasExportFiles, floatToPcm, mixAudioCommands, enginePackZip, webIndexHtml, webPackZip, } from "@openbone/export";
|
|
6
6
|
import { CanvasRenderer, atlasBuildOptions, describeAtlas } from "@openbone/render-canvas";
|
|
7
7
|
import { OpenBoneInstance } from "@openbone/runtime";
|
|
8
8
|
import { decodeAudio, encodeVideoFfmpeg, findFfmpeg } from "./media.js";
|
|
9
|
-
import { loadImages, packAtlasFull, packAtlasScales, useSkin } from "./render.js";
|
|
9
|
+
import { loadImages, packAtlasFull, packAtlasScales, useSkin, withRenderFonts } from "./render.js";
|
|
10
10
|
/**
|
|
11
11
|
* Every export format, headless: the one code path behind the MCP `export_file` tool and `openbone export`, using
|
|
12
12
|
* the same encoders, atlas packer and runtime-data export as the editor's Export dialog.
|
|
@@ -16,8 +16,8 @@ export const EXPORT_FORMATS = ["obone", "json", "obonb", "atlas", "png", "jpeg",
|
|
|
16
16
|
export async function renderFrames(session, req, scriptHost,
|
|
17
17
|
/** Filled with the audio commands the run emits, with their time (for the sound track of a video). */
|
|
18
18
|
audioOut) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const images = await loadImages(session, session.doc);
|
|
20
|
+
const doc = withRenderFonts(session.doc);
|
|
21
21
|
const w = Math.max(1, Math.round(doc.width * req.scale));
|
|
22
22
|
const h = Math.max(1, Math.round(doc.height * req.scale));
|
|
23
23
|
const canvas = createCanvas(w, h);
|
|
@@ -83,7 +83,7 @@ export function jpegOf(f, bg, quality = 90) {
|
|
|
83
83
|
g.drawImage(tmp, 0, 0);
|
|
84
84
|
return new Uint8Array(c.toBuffer("image/jpeg", quality));
|
|
85
85
|
}
|
|
86
|
-
const MIME = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", wav: "audio/wav", mp3: "audio/mpeg", ogg: "audio/ogg" };
|
|
86
|
+
const MIME = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", webp: "image/webp", gif: "image/gif", wav: "audio/wav", mp3: "audio/mpeg", ogg: "audio/ogg", ...FONT_MIME };
|
|
87
87
|
/** Bytes of a document asset src (data: URI or a path relative to the project). */
|
|
88
88
|
export async function assetBytes(session, src) {
|
|
89
89
|
if (src.startsWith("data:"))
|
|
@@ -92,7 +92,7 @@ export async function assetBytes(session, src) {
|
|
|
92
92
|
return Buffer.from(await (await fetch(src)).arrayBuffer());
|
|
93
93
|
return readFile(path.isAbsolute(src) ? src : path.join(session.baseDir, src));
|
|
94
94
|
}
|
|
95
|
-
/** Copy of a document with every image, atlas page and
|
|
95
|
+
/** Copy of a document with every image, atlas page, audio and font file embedded as data: URIs (self-contained exports). */
|
|
96
96
|
export async function embedAssets(session, d) {
|
|
97
97
|
const out = structuredClone(d);
|
|
98
98
|
const embed = async (src) => {
|
|
@@ -108,6 +108,8 @@ export async function embedAssets(session, d) {
|
|
|
108
108
|
p.src = await embed(p.src);
|
|
109
109
|
for (const a of out.audio?.assets ?? [])
|
|
110
110
|
a.src = await embed(a.src);
|
|
111
|
+
for (const f of out.fonts ?? [])
|
|
112
|
+
f.src = await embed(f.src);
|
|
111
113
|
return out;
|
|
112
114
|
}
|
|
113
115
|
/** Pack a (runtime) document's images into atlas pages with the dialog's settings; returns a packed copy and any warnings. */
|
|
@@ -235,6 +237,9 @@ export async function exportFile(session, a, scriptHost) {
|
|
|
235
237
|
width: d.width,
|
|
236
238
|
height: d.height,
|
|
237
239
|
background: a.transparent ? "transparent" : undefined,
|
|
240
|
+
fit: a.fit,
|
|
241
|
+
clip: a.clip,
|
|
242
|
+
fullscreenFit: a.fullscreenFit,
|
|
238
243
|
inputs: sm?.inputs.map((i) => ({ name: i.name, type: i.type })) ?? [],
|
|
239
244
|
hasScripts,
|
|
240
245
|
hasAudio: !!d.audio?.assets.length,
|
package/dist/guide.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const GUIDE = "# OpenBone authoring guide (for agents)\n\nCoordinate system: skeleton space is y-UP, rotations in degrees counter-clockwise. The skeleton origin (0,0)\nsits at (originX, originY) pixels in the artboard (artboard pixels are y-down). Default artboard 800x600,\norigin (400,450) \u2014 so y=0 is near the bottom, positive y goes up.\n\nEverything can be referenced by **name or id**. Every edit tool validates its input and returns ids.\n\n## Typical workflow\n1. new_project {name, path} (autosaves to path) \u2014 or open_project.\n2. Rig: add_bone (parent defaults to root; x/y/rotation are LOCAL to the parent). A bone points along its local +x.\n E.g. an upright torso: add_bone {name:\"torso\", y:100, rotation:90, length:120}.\n Children of a rotated parent use the parent's frame: a head on top of that torso is add_bone {name:\"head\", parent:\"torso\", x:120}.\n3. Visuals: add_slot {bone} then add_shape (no art needed) or import_image + add_region / add_mesh.\n Art prep: process_image {input, out, ops:[...], importAs | replace} keys out flat backgrounds (keyColor), cuts an object\n out by comparing with a painted-out copy (differenceMatte), trims, crops, resizes, flips and feathers edges; its \"box\"\n says where the result sat in the input picture, so a layer cut from a full scene can be placed exactly where it was.\n Attachments are positioned in the slot BONE's local frame (x along the bone).\n Draw order = slot order (first is back). Use update_slot {index} to reorder.\n4. Deformation: add_mesh {cols, rows} (or trace_mesh on a region) then auto_weights {bones:[...]} so the mesh bends with bones.\n trace_mesh on a mesh re-traces it in place and rebinds the same bones (tolerance 1\u20132 for detailed edges such as feet).\n set_weights_in_area {slot, attachment, area:{yMax:...} | polygon, influences, blend} pins every vertex in an area\n to bones (e.g. everything below the knees to the legs bone) without listing vertex indices.\n5. Constraints (solved every frame in one list; default order IK, transform, path, physics \u2014 set_constraint_order\n {constraints:[every constraint, first applied first]} changes it, [] restores the default):\n add_ik_constraint {bones:[\"thigh\",\"shin\"], target:\"foot-target\"} (target must not be a child of the chain);\n optional softness (2-bone), stretch, compress (1-bone).\n add_transform_constraint {bones, target, mixRotate, mixTranslate, mixScale, mixShear, local?, relative?}.\n Path: add_path {slot, anchors:[x0,y0,x1,y1,...]} (smooth bezier in the slot bone's frame; bind it to control bones\n with auto_weights or set_weights so moving them bends it), then add_path_constraint {bones:[parent..child], target:slot,\n positionMode:\"fixed\"|\"percent\", spacingMode:\"length\"|\"fixed\"|\"percent\"|\"proportional\", rotateMode:\"tangent\"|\"chain\"|\"chainScale\"}.\n Physics: add_physics_constraint {bone, inertia, strength, damping, mass, gravity, wind, mix} per bone (parent first)\n for hair/cloth/tails. It simulates over time, so check it with render_gif rather than a single frame.\n Physics gravity/wind and IK softness scale with the skeleton's size relative to set_document {referenceScale} (default 100 %).\n6. Animate: create_animation {name}, then set_keys with absolute values:\n set_keys {animation:\"walk\", target:\"bone\", id:\"thigh\", property:\"rotation\", keys:[{time:0,value:-20},{time:0.5,value:20,curve:\"easeInOut\"},{time:1,value:-20}]}\n Properties: bone rotation|x|y|scaleX|scaleY|shearX|shearY|inherit (stepped string: normal|onlyTranslation|noRotation|noScale), slot color (\"#rrggbbaa\") | dark (two-colour tint \"#rrggbb\") | attachment (name or null),\n ik mix|softness, transform mix|mixRotate|mixTranslate|mixScale|mixShear, path position|spacing|mixRotate|mixX|mixY,\n physics mix|inertia|strength|damping|mass|gravity|wind, deform offsets (mesh or path), sequence frame (with attachment), drawOrder. Curves: linear, stepped, easeIn, easeOut, easeInOut, backOut or [cx1,cy1,cx2,cy2].\n set_keys merges into the timeline; pass replace:true to set the whole timeline (e.g. when redoing a motion path).\n Loop cleanly by making the last key equal the first. add_event_key fires events (footsteps, sounds).\n7. Interactivity (Rive-style): create_state_machine \u2192 add_input (bool/number/trigger) \u2192 add_state {animation}\n (first state = entry) \u2192 add_transition {from, to, conditions:[{input, op, value}], duration, exitTime}.\n Transition with no conditions waits for the source animation to finish (exitTime 1).\n from:\"@any\" fires from any state. blend1d states blend animations by a number input.\n Pointer: add_bounding_box on a slot, then add_listener {slot, event:\"click\"|\"down\"|\"up\"|\"enter\"|\"exit\"|\"move\", actions:[...]}.\n Staged flows: add_state {..., loop:false, onComplete:\"next\"} plays once then moves on (its own transitions can still interrupt).\n Live data: add_input {type:\"string\"} or number inputs; add_text {slot, text:\"{multiplier:0.00}x\", size, weight, color, outline}\n shows inputs (number patterns: 0.00, #,##0, +0, 0%); add_binding {input, target:\"bone\"|\"slot\"|\"ik\"|..., object, property,\n inMin, inMax, outMin, outMax} drives a property from a number input every frame (slot color takes hex outMin/outMax).\n simulate_state_machine / render_frame steps accept setInputs with strings too.\n Scripts: add_script {code} + attach_script. Script API (global ob): ob.input(n), ob.setInput(n,v), ob.fire(n),\n ob.emit(event,{int,float,string}), ob.bone(n), ob.setBone(n,{rotation,...}) (per-frame override), ob.slot(n,{color,attachment}),\n ob.pointer(), ob.time(), ob.log(...). Hooks: onStart(), onUpdate(dt), onEvent(e), onPointer(p), or named fns for runScript actions.\n8. Particles: add_particles {slot, preset:\"fire\"|\"smoke\"|\"sparks\"|\"confetti\"|\"exhaust\"|\"coins\", ...overrides} emits from the\n slot bone (rotation = emission direction in the bone's frame, e.g. -90 for exhaust under an upright rocket bone; space\n \"world\" leaves trails). update_particles changes settings. Key it with set_keys {target:\"particles\", id:slot,\n property:\"emitting\" (true/false) | \"rate\"}. State machines: set_state_emitter {state, slot, emitting} and listener actions\n {type:\"setEmitter\", slot, emitting} / {type:\"emitParticles\", slot, count}. Seeded and deterministic; check with render_gif.\n9. Skins (outfits): the first skin is the default skin, shared by all. add_skin {name}, then either pass skin:\"<name>\" to\n add_shape/add_region/... or copy_attachment {slot, attachment, toSkin} and update_attachment {..., skin} to override a\n default attachment under the same name. rename_skin, duplicate_skin, delete_skin manage them; render_frame {skin} previews one.\n Skin bones/constraints: add_to_skin {skin, bones?, constraints?} makes them skin-only (active only while a skin listing\n them is set; inactive bones and their children aren't posed and their slots aren't drawn); remove_from_skin undoes it.\n10. Audio: import_audio {path} (or add_audio {name, src:data:/path, duration}) creates an asset and a same-named sound on the\n sfx bus. Play it with add_audio_key {animation, sound, time, volume?, rate?, loop?}, set_event_sound {event, sound} (plays\n whenever the event fires), set_state_sound {stateMachine, state, sound, on:\"enter\"|\"exit\", action:\"play\"|\"stop\"} or a\n listener action {type:\"playSound\", sound} / {type:\"stopSound\", sound, fade?}. Mute buttons: give a bool input the bus it\n mutes (add_input / update_input {mutes:\"music\"|\"sfx\"|... or \"master\" for everything}), then a listener {type:\"setMute\",\n bus:\"music\", muted:\"toggle\"} (or toggleInput on that input; not both) and a slot color binding to show the state. The\n app embedding the animation mutes it the same way (setInput(\"musicOff\", true), or player.setBusMuted(\"music\", true)).\n Looping sounds stop when their state or\n animation ends. Mix with update_sound {volume, rate, loop, fadeIn, fadeOut, bus}, add_bus/update_bus {volume, muted},\n set_audio_mix {master, muted}. simulate_state_machine lists the audio commands.\n11. Sprite sequences (frame-by-frame, e.g. fire or explosions): add_image for each frame (or one sheet image), then\n add_sequence {slot, frames:[\"fire_0001\",\"fire_0002\",...], fps, mode:\"loop\"|\"once\"|\"pingPong\"|\"holdLast\", offset}\n or add_sequence {slot, grid:{image:\"sheet\", cols, rows}}. Bind input (a number input) to pick the frame from a state\n machine, or set_keys target:\"sequence\" {id:slot, attachment, property:\"frame\"}. set_sequence_frames replaces/reorders frames.\n12. Check your work: render_frame (returns a PNG; bones are drawn as blue wedges) and simulate_state_machine (text log of\n state changes/events). render_gif for motion. get_summary for an outline, validate for problems.\n\nTips: keep bones' length meaningful (used by IK and auto weights). Use update_* tools to fix mistakes, undo to revert.\n";
|
|
1
|
+
export declare const GUIDE = "# OpenBone authoring guide (for agents)\n\nCoordinate system: skeleton space is y-UP, rotations in degrees counter-clockwise. The skeleton origin (0,0)\nsits at (originX, originY) pixels in the artboard (artboard pixels are y-down). Default artboard 800x600,\norigin (400,450) \u2014 so y=0 is near the bottom, positive y goes up.\n\nEverything can be referenced by **name or id**. Every edit tool validates its input and returns ids.\n\n## Typical workflow\n1. new_project {name, path} (autosaves to path) \u2014 or open_project.\n2. Rig: add_bone (parent defaults to root; x/y/rotation are LOCAL to the parent). A bone points along its local +x.\n E.g. an upright torso: add_bone {name:\"torso\", y:100, rotation:90, length:120}.\n Children of a rotated parent use the parent's frame: a head on top of that torso is add_bone {name:\"head\", parent:\"torso\", x:120}.\n3. Visuals: add_slot {bone} then add_shape (no art needed) or import_image + add_region / add_mesh.\n Art prep: process_image {input, out, ops:[...], importAs | replace} keys out flat backgrounds (keyColor), cuts an object\n out by comparing with a painted-out copy (differenceMatte), trims, crops, resizes, flips and feathers edges; its \"box\"\n says where the result sat in the input picture, so a layer cut from a full scene can be placed exactly where it was.\n Attachments are positioned in the slot BONE's local frame (x along the bone).\n Draw order = slot order (first is back). Use update_slot {index} to reorder.\n4. Deformation: add_mesh {cols, rows} (or trace_mesh on a region) then auto_weights {bones:[...]} so the mesh bends with bones.\n trace_mesh on a mesh re-traces it in place and rebinds the same bones (tolerance 1\u20132 for detailed edges such as feet).\n set_weights_in_area {slot, attachment, area:{yMax:...} | polygon, influences, blend} pins every vertex in an area\n to bones (e.g. everything below the knees to the legs bone) without listing vertex indices.\n5. Constraints (solved every frame in one list; default order IK, transform, path, physics \u2014 set_constraint_order\n {constraints:[every constraint, first applied first]} changes it, [] restores the default):\n add_ik_constraint {bones:[\"thigh\",\"shin\"], target:\"foot-target\"} (target must not be a child of the chain);\n optional softness (2-bone), stretch, compress (1-bone).\n add_transform_constraint {bones, target, mixRotate, mixTranslate, mixScale, mixShear, local?, relative?}.\n Path: add_path {slot, anchors:[x0,y0,x1,y1,...]} (smooth bezier in the slot bone's frame; bind it to control bones\n with auto_weights or set_weights so moving them bends it), then add_path_constraint {bones:[parent..child], target:slot,\n positionMode:\"fixed\"|\"percent\", spacingMode:\"length\"|\"fixed\"|\"percent\"|\"proportional\", rotateMode:\"tangent\"|\"chain\"|\"chainScale\"}.\n Physics: add_physics_constraint {bone, inertia, strength, damping, mass, gravity, wind, mix} per bone (parent first)\n for hair/cloth/tails. It simulates over time, so check it with render_gif rather than a single frame.\n Physics gravity/wind and IK softness scale with the skeleton's size relative to set_document {referenceScale} (default 100 %).\n6. Animate: create_animation {name}, then set_keys with absolute values:\n set_keys {animation:\"walk\", target:\"bone\", id:\"thigh\", property:\"rotation\", keys:[{time:0,value:-20},{time:0.5,value:20,curve:\"easeInOut\"},{time:1,value:-20}]}\n Properties: bone rotation|x|y|scaleX|scaleY|shearX|shearY|inherit (stepped string: normal|onlyTranslation|noRotation|noScale), slot color (\"#rrggbbaa\") | dark (two-colour tint \"#rrggbb\") | attachment (name or null),\n ik mix|softness, transform mix|mixRotate|mixTranslate|mixScale|mixShear, path position|spacing|mixRotate|mixX|mixY,\n physics mix|inertia|strength|damping|mass|gravity|wind, deform offsets (mesh or path), sequence frame (with attachment), drawOrder. Curves: linear, stepped, easeIn, easeOut, easeInOut, backOut or [cx1,cy1,cx2,cy2].\n set_keys merges into the timeline; pass replace:true to set the whole timeline (e.g. when redoing a motion path).\n Loop cleanly by making the last key equal the first. add_event_key fires events (footsteps, sounds).\n7. Interactivity (Rive-style): create_state_machine \u2192 add_input (bool/number/trigger) \u2192 add_state {animation}\n (first state = entry) \u2192 add_transition {from, to, conditions:[{input, op, value}], duration, exitTime}.\n Transition with no conditions waits for the source animation to finish (exitTime 1).\n from:\"@any\" fires from any state. blend1d states blend animations by a number input.\n Pointer: add_bounding_box on a slot, then add_listener {slot, event:\"click\"|\"down\"|\"up\"|\"enter\"|\"exit\"|\"move\", actions:[...]}.\n Staged flows: add_state {..., loop:false, onComplete:\"next\"} plays once then moves on (its own transitions can still interrupt).\n Live data: add_input {type:\"string\"} or number inputs; add_text {slot, text:\"{multiplier:0.00}x\", size, weight, color, outline}\n shows inputs (number patterns: 0.00, #,##0, +0, 0%); add_binding {input, target:\"bone\"|\"slot\"|\"ik\"|..., object, property,\n inMin, inMax, outMin, outMax} drives a property from a number input every frame (slot color takes hex outMin/outMax).\n simulate_state_machine / render_frame steps accept setInputs with strings too.\n Scripts: add_script {code} + attach_script. Script API (global ob): ob.input(n), ob.setInput(n,v), ob.fire(n),\n ob.emit(event,{int,float,string}), ob.bone(n), ob.setBone(n,{rotation,...}) (per-frame override), ob.slot(n,{color,attachment}),\n ob.pointer(), ob.time(), ob.log(...). Hooks: onStart(), onUpdate(dt), onEvent(e), onPointer(p), or named fns for runScript actions.\n8. Particles: add_particles {slot, preset:\"fire\"|\"smoke\"|\"sparks\"|\"confetti\"|\"exhaust\"|\"coins\", ...overrides} emits from the\n slot bone (rotation = emission direction in the bone's frame, e.g. -90 for exhaust under an upright rocket bone; space\n \"world\" leaves trails). update_particles changes settings. Key it with set_keys {target:\"particles\", id:slot,\n property:\"emitting\" (true/false) | \"rate\"}. State machines: set_state_emitter {state, slot, emitting} and listener actions\n {type:\"setEmitter\", slot, emitting} / {type:\"emitParticles\", slot, count}. Seeded and deterministic; check with render_gif.\n9. Skins (outfits): the first skin is the default skin, shared by all. add_skin {name}, then either pass skin:\"<name>\" to\n add_shape/add_region/... or copy_attachment {slot, attachment, toSkin} and update_attachment {..., skin} to override a\n default attachment under the same name. rename_skin, duplicate_skin, delete_skin manage them; render_frame {skin} previews one.\n Skin bones/constraints: add_to_skin {skin, bones?, constraints?} makes them skin-only (active only while a skin listing\n them is set; inactive bones and their children aren't posed and their slots aren't drawn); remove_from_skin undoes it.\n10. Audio: import_audio {path} (or add_audio {name, src:data:/path, duration}) creates an asset and a same-named sound on the\n sfx bus. Play it with add_audio_key {animation, sound, time, volume?, rate?, loop?}, set_event_sound {event, sound} (plays\n whenever the event fires), set_state_sound {stateMachine, state, sound, on:\"enter\"|\"exit\", action:\"play\"|\"stop\"} or a\n listener action {type:\"playSound\", sound} / {type:\"stopSound\", sound, fade?}. Mute buttons: give a bool input the bus it\n mutes (add_input / update_input {mutes:\"music\"|\"sfx\"|... or \"master\" for everything}), then a listener {type:\"setMute\",\n bus:\"music\", muted:\"toggle\"} (or toggleInput on that input; not both) and a slot color binding to show the state. The\n app embedding the animation mutes it the same way (setInput(\"musicOff\", true), or player.setBusMuted(\"music\", true)).\n Looping sounds stop when their state or\n animation ends. Mix with update_sound {volume, rate, loop, fadeIn, fadeOut, bus}, add_bus/update_bus {volume, muted},\n set_audio_mix {master, muted}. simulate_state_machine lists the audio commands. A sound that should play whenever a\n trigger fires belongs on the state it enters (set_state_sound), not only on the button's listener: code and page\n buttons fire triggers without clicking the art (validate warns about this).\n Fonts: import_font {path} adds a TTF/OTF as a document font (family read from the file). Texts whose font list names\n that family (\"Noto Serif JP, serif\") use it everywhere (editor, renders, every runtime) instead of whatever is installed.\n11. Sprite sequences (frame-by-frame, e.g. fire or explosions): add_image for each frame (or one sheet image), then\n add_sequence {slot, frames:[\"fire_0001\",\"fire_0002\",...], fps, mode:\"loop\"|\"once\"|\"pingPong\"|\"holdLast\", offset}\n or add_sequence {slot, grid:{image:\"sheet\", cols, rows}}. Bind input (a number input) to pick the frame from a state\n machine, or set_keys target:\"sequence\" {id:slot, attachment, property:\"frame\"}. set_sequence_frames replaces/reorders frames.\n12. Check your work: render_frame (returns a PNG; bones are drawn as blue wedges) and simulate_state_machine (text log of\n state changes/events). render_gif for motion. get_summary for an outline, validate for problems.\n\nTips: keep bones' length meaningful (used by IK and auto weights). Use update_* tools to fix mistakes, undo to revert.\n";
|
package/dist/guide.js
CHANGED
|
@@ -71,7 +71,11 @@ Everything can be referenced by **name or id**. Every edit tool validates its in
|
|
|
71
71
|
app embedding the animation mutes it the same way (setInput("musicOff", true), or player.setBusMuted("music", true)).
|
|
72
72
|
Looping sounds stop when their state or
|
|
73
73
|
animation ends. Mix with update_sound {volume, rate, loop, fadeIn, fadeOut, bus}, add_bus/update_bus {volume, muted},
|
|
74
|
-
set_audio_mix {master, muted}. simulate_state_machine lists the audio commands.
|
|
74
|
+
set_audio_mix {master, muted}. simulate_state_machine lists the audio commands. A sound that should play whenever a
|
|
75
|
+
trigger fires belongs on the state it enters (set_state_sound), not only on the button's listener: code and page
|
|
76
|
+
buttons fire triggers without clicking the art (validate warns about this).
|
|
77
|
+
Fonts: import_font {path} adds a TTF/OTF as a document font (family read from the file). Texts whose font list names
|
|
78
|
+
that family ("Noto Serif JP, serif") use it everywhere (editor, renders, every runtime) instead of whatever is installed.
|
|
75
79
|
11. Sprite sequences (frame-by-frame, e.g. fire or explosions): add_image for each frame (or one sheet image), then
|
|
76
80
|
add_sequence {slot, frames:["fire_0001","fire_0002",...], fps, mode:"loop"|"once"|"pingPong"|"holdLast", offset}
|
|
77
81
|
or add_sequence {slot, grid:{image:"sheet", cols, rows}}. Bind input (a number input) to pick the frame from a state
|
package/dist/render.d.ts
CHANGED
|
@@ -30,6 +30,13 @@ export interface RenderRequest extends PoseRequest {
|
|
|
30
30
|
wireframe?: boolean;
|
|
31
31
|
background?: string | null;
|
|
32
32
|
}
|
|
33
|
+
/** Register the document's fonts so server-side renders (render_frame, GIF and video exports) draw text with them. */
|
|
34
|
+
export declare function loadFonts(session: Pick<ProjectSession, "readImageSrc">, doc: OpenBoneDocument): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* The document as server renders draw it: each text whose font list leads (CSS order, installed families included)
|
|
37
|
+
* to a document font starts with that exact face's registered name. The document itself is not changed.
|
|
38
|
+
*/
|
|
39
|
+
export declare function withRenderFonts(doc: OpenBoneDocument): OpenBoneDocument;
|
|
33
40
|
export declare function loadImages(session: Pick<ProjectSession, "readImageSrc">, doc: OpenBoneDocument): Promise<Map<string, Image>>;
|
|
34
41
|
export declare function useSkin(inst: OpenBoneInstance, skin?: string): void;
|
|
35
42
|
/** Build a posed instance for the request. Returns logs from state machine simulation. */
|
package/dist/render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createCanvas } from "@napi-rs/canvas";
|
|
1
|
+
import { GlobalFonts, createCanvas } from "@napi-rs/canvas";
|
|
2
2
|
import { decodeImage } from "./image-load.js";
|
|
3
|
-
import { textureAssets } from "@openbone/core";
|
|
3
|
+
import { cloneDocument, pickDocumentFont, textureAssets } from "@openbone/core";
|
|
4
4
|
import { encodePng } from "@openbone/export";
|
|
5
5
|
import { CanvasRenderer, buildAtlas, buildAtlasScales } from "@openbone/render-canvas";
|
|
6
6
|
import { OpenBoneInstance } from "@openbone/runtime";
|
|
@@ -10,7 +10,58 @@ import * as gifenc from "gifenc";
|
|
|
10
10
|
// (the functions are named exports, and `default` is the encoder alone). Take them from whichever has them.
|
|
11
11
|
const gifNs = gifenc;
|
|
12
12
|
const { GIFEncoder, applyPalette, quantize } = (typeof gifNs.GIFEncoder === "function" ? gifNs : gifNs.default);
|
|
13
|
+
/** Font files registered with @napi-rs/canvas, by alias, so a render can draw text in them. */
|
|
14
|
+
const registeredFonts = new Set();
|
|
15
|
+
/**
|
|
16
|
+
* Each document font is registered under its own name: with several faces under one family, Skia doesn't pick the
|
|
17
|
+
* nearest weight (a 600 text skipped the 400 and 700 faces), so renders name the face the matching rule picked.
|
|
18
|
+
*/
|
|
19
|
+
const faceAlias = (f) => `OpenBone face ${f.id} ${f.src.length}`;
|
|
20
|
+
/** Register the document's fonts so server-side renders (render_frame, GIF and video exports) draw text with them. */
|
|
21
|
+
export async function loadFonts(session, doc) {
|
|
22
|
+
for (const f of doc.fonts ?? []) {
|
|
23
|
+
const alias = faceAlias(f);
|
|
24
|
+
if (registeredFonts.has(alias))
|
|
25
|
+
continue;
|
|
26
|
+
try {
|
|
27
|
+
// readImageSrc hands data: and http(s) sources back as they are (the image decoder takes them): fetch the bytes.
|
|
28
|
+
const src = await session.readImageSrc(f.src);
|
|
29
|
+
const bytes = typeof src !== "string" ? src
|
|
30
|
+
: src.startsWith("data:") ? Buffer.from(src.slice(src.indexOf(",") + 1), "base64")
|
|
31
|
+
: Buffer.from(await (await fetch(src)).arrayBuffer());
|
|
32
|
+
if (GlobalFonts.register(bytes, alias))
|
|
33
|
+
registeredFonts.add(alias);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
/* unreadable font: installed fonts apply */
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The document as server renders draw it: each text whose font list leads (CSS order, installed families included)
|
|
42
|
+
* to a document font starts with that exact face's registered name. The document itself is not changed.
|
|
43
|
+
*/
|
|
44
|
+
export function withRenderFonts(doc) {
|
|
45
|
+
if (!doc.fonts?.length)
|
|
46
|
+
return doc;
|
|
47
|
+
const out = cloneDocument(doc);
|
|
48
|
+
const installed = (family) => GlobalFonts.has(family);
|
|
49
|
+
for (const skin of out.skeleton.skins)
|
|
50
|
+
for (const atts of Object.values(skin.attachments))
|
|
51
|
+
for (const a of Object.values(atts)) {
|
|
52
|
+
if (a.type !== "text")
|
|
53
|
+
continue;
|
|
54
|
+
const face = pickDocumentFont(out, a.font, a.weight, false, installed);
|
|
55
|
+
if (face && registeredFonts.has(faceAlias(face))) {
|
|
56
|
+
a.font = `"${faceAlias(face)}", ${a.font}`;
|
|
57
|
+
// Skia only uses a face whose weight is the one asked for: ask for the face the rule picked.
|
|
58
|
+
a.weight = face.weight ?? 400;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
13
63
|
export async function loadImages(session, doc) {
|
|
64
|
+
await loadFonts(session, doc);
|
|
14
65
|
const map = new Map();
|
|
15
66
|
// Atlas pages and loose images, keyed by id (the renderers ask for page ids when images are packed).
|
|
16
67
|
for (const img of textureAssets(doc)) {
|
|
@@ -85,8 +136,8 @@ export function pose(doc, req, scriptHost) {
|
|
|
85
136
|
return { inst, log };
|
|
86
137
|
}
|
|
87
138
|
export async function renderPng(session, req, scriptHost) {
|
|
88
|
-
const
|
|
89
|
-
const
|
|
139
|
+
const images = await loadImages(session, session.doc);
|
|
140
|
+
const doc = withRenderFonts(session.doc);
|
|
90
141
|
const { inst, log } = pose(doc, req, scriptHost);
|
|
91
142
|
const scale = req.scale ?? 1;
|
|
92
143
|
const canvas = createCanvas(Math.max(1, Math.round(doc.width * scale)), Math.max(1, Math.round(doc.height * scale)));
|
|
@@ -128,8 +179,8 @@ export function contactSheet(frameW, frameH, count, cols = 3, rows = 2) {
|
|
|
128
179
|
export async function renderGif(session, req, scriptHost,
|
|
129
180
|
/** Called with each rendered frame (e.g. to build a preview); the canvas is reused, so copy what you need. */
|
|
130
181
|
onFrame) {
|
|
131
|
-
const
|
|
132
|
-
const
|
|
182
|
+
const images = await loadImages(session, session.doc);
|
|
183
|
+
const doc = withRenderFonts(session.doc);
|
|
133
184
|
const scale = req.scale ?? 0.5;
|
|
134
185
|
const w = Math.max(1, Math.round(doc.width * scale));
|
|
135
186
|
const h = Math.max(1, Math.round(doc.height * scale));
|
package/dist/server.js
CHANGED
|
@@ -3,7 +3,7 @@ import { decodeImage } from "./image-load.js";
|
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
-
import { isTrimmed, registry, serialize, summarize, validate } from "@openbone/core";
|
|
6
|
+
import { FONT_MIME, fontNameFromFile, isTrimmed, readFontMeta, registry, serialize, summarize, validate } from "@openbone/core";
|
|
7
7
|
import { createQuickJsHost } from "@openbone/scripting";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { GUIDE } from "./guide.js";
|
|
@@ -30,7 +30,7 @@ export function createServer(opts = {}) {
|
|
|
30
30
|
const session = opts.session ?? new ProjectSession();
|
|
31
31
|
let host = opts.scriptHost;
|
|
32
32
|
const scriptHost = async () => (host ??= await createQuickJsHost({ timeoutMs: 50 }));
|
|
33
|
-
const server = new McpServer({ name: "openbone", version: "0.4.
|
|
33
|
+
const server = new McpServer({ name: "openbone", version: "0.4.2" }, {
|
|
34
34
|
instructions: "OpenBone: 2D skeletal animation + interactive state machines. Read the openbone://guide resource (or call get_guide) first. Start with new_project or open_project; edit with the add_*/update_*/set_keys tools; verify with render_frame and simulate_state_machine.",
|
|
35
35
|
});
|
|
36
36
|
// ---------- Generated edit tools (one per core op) ----------
|
|
@@ -147,6 +147,38 @@ export function createServer(opts = {}) {
|
|
|
147
147
|
return fail(e);
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
|
+
server.registerTool("import_font", {
|
|
151
|
+
description: "Import a font file (TTF/OTF; WOFF/WOFF2 work on the web only) from disk as a font asset. Its family, weight and style are read from the file unless given. Texts whose font list names that family draw with it in the editor, render_frame, exports and every runtime, before installed fonts, so text looks the same everywhere. Stored as a path relative to the project file, or embedded when `embed` is true or the project is unsaved.",
|
|
152
|
+
inputSchema: {
|
|
153
|
+
path: z.string(),
|
|
154
|
+
family: z.string().optional().describe("Family name texts use (default: the family in the file)"),
|
|
155
|
+
weight: z.number().int().min(100).max(1000).optional(),
|
|
156
|
+
style: z.enum(["normal", "italic"]).optional(),
|
|
157
|
+
name: z.string().optional(),
|
|
158
|
+
embed: z.boolean().default(false),
|
|
159
|
+
},
|
|
160
|
+
}, async (a) => {
|
|
161
|
+
try {
|
|
162
|
+
const abs = path.resolve(a.path);
|
|
163
|
+
const buf = await readFile(abs);
|
|
164
|
+
const ext = path.extname(abs).slice(1).toLowerCase();
|
|
165
|
+
const meta = readFontMeta(new Uint8Array(buf));
|
|
166
|
+
const src = a.embed || !session.filePath ? `data:${FONT_MIME[ext] ?? "font/otf"};base64,${buf.toString("base64")}` : path.relative(session.baseDir, abs).split(path.sep).join("/");
|
|
167
|
+
const family = a.family ?? meta?.family ?? fontNameFromFile(abs);
|
|
168
|
+
const result = session.store.apply("addFont", {
|
|
169
|
+
name: a.name ?? fontNameFromFile(abs),
|
|
170
|
+
family,
|
|
171
|
+
src,
|
|
172
|
+
weight: a.weight ?? meta?.weight ?? 400,
|
|
173
|
+
style: a.style ?? meta?.style ?? "normal",
|
|
174
|
+
});
|
|
175
|
+
await session.maybeAutosave();
|
|
176
|
+
return text({ ok: true, ...result, family, hint: `Use it with update_attachment … font: "${family}, serif" (or add_text font).` });
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
return fail(e);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
150
182
|
server.registerTool("import_audio", {
|
|
151
183
|
description: "Import a WAV/MP3/OGG/FLAC file from disk (its duration is read from the file) as an audio asset plus a sound of the same name (on the sfx bus unless `bus` is given). Stored as a path relative to the project file, or embedded when `embed` is true or the project is unsaved. Then play it with add_audio_key, set_event_sound, set_state_sound or a playSound listener action.",
|
|
152
184
|
inputSchema: {
|
package/dist/tools-extra.js
CHANGED
|
@@ -72,6 +72,9 @@ export function registerExtraTools(server, session, scriptHost) {
|
|
|
72
72
|
engine: z.enum(["unity", "godot", "flutter", "generic"]).default("generic"),
|
|
73
73
|
singleFile: z.boolean().default(false).describe("web: one HTML file (works from file://)"),
|
|
74
74
|
minify: z.boolean().default(true).describe("web: minified player"),
|
|
75
|
+
fit: z.enum(["contain", "cover", "auto", "none"]).optional().describe("web: how the artboard fits the player (default contain)"),
|
|
76
|
+
clip: z.boolean().optional().describe("web: false draws past the artboard's edges (default: clipped to the artboard)"),
|
|
77
|
+
fullscreenFit: z.enum(["auto", "cover", "contain", "none", "same"]).optional().describe("web: fit while full screen (default auto)"),
|
|
75
78
|
binary: z.boolean().optional().describe("web: animation as .obonb (default true); atlas: runtime data as .obonb instead of .json (default false)"),
|
|
76
79
|
pack: z.boolean().default(false).describe("json/obonb/web: pack images into an embedded texture atlas"),
|
|
77
80
|
audio: z.boolean().default(true).describe("avi/mov/mp4/webm: include the sound the run plays (WAV decodes always; MP3/OGG/FLAC and the mp4/webm encoders need ffmpeg on the PATH)"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbone/mcp",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "MCP server for OpenBone: let AI agents rig, animate and wire up interactive skeletal animations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openbone",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"gifenc": "^1.0.3",
|
|
53
53
|
"ws": "^8.18.0",
|
|
54
54
|
"zod": "^4.1.0",
|
|
55
|
-
"@openbone/
|
|
56
|
-
"@openbone/
|
|
57
|
-
"@openbone/
|
|
58
|
-
"@openbone/
|
|
59
|
-
"@openbone/
|
|
60
|
-
"@openbone/
|
|
55
|
+
"@openbone/core": "0.4.2",
|
|
56
|
+
"@openbone/export": "0.4.2",
|
|
57
|
+
"@openbone/player": "0.4.2",
|
|
58
|
+
"@openbone/render-canvas": "0.4.2",
|
|
59
|
+
"@openbone/runtime": "0.4.2",
|
|
60
|
+
"@openbone/scripting": "0.4.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/ws": "^8.18.1"
|