agent-manifesto-kit 1.6.0 → 1.7.0
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/README.md +38 -0
- package/collection/NOTICE.md +8 -0
- package/collection/skills/astro-preview/SKILL.md +60 -0
- package/collection/skills/kimodo-motion/SKILL.md +101 -0
- package/collection/skills/kimodo-motion/agents/openai.yaml +4 -0
- package/collection/skills/kimodo-motion/patches/kimodo-cpp-keyposes.patch +398 -0
- package/collection/skills/kimodo-motion/scripts/kimodo_motion.py +459 -0
- package/collection/skills/kimodo-motion/scripts/kimodo_retarget.py +280 -0
- package/collection/skills/kimodo-motion/tests/blender_roundtrip.py +105 -0
- package/collection/skills/kimodo-motion/tests/test_kimodo_motion.py +183 -0
- package/collection/skills/self-reflection/SKILL.md +121 -0
- package/collection/skills/self-reflection/agents/openai.yaml +4 -0
- package/collection/skills/self-reflection/assets/report-template.json +8 -0
- package/collection/skills/self-reflection/assets/report.html +64 -0
- package/collection/skills/self-reflection/references/report-format.md +42 -0
- package/collection/skills/self-reflection/scripts/export_claude.py +59 -0
- package/collection/skills/self-reflection/scripts/reflect.py +320 -0
- package/collection/skills/self-reflection/scripts/report.py +322 -0
- package/collection/skills/self-reflection/tests/test_export_claude.py +83 -0
- package/collection/skills/self-reflection/tests/test_reflect.py +189 -0
- package/collection/skills/self-reflection/tests/test_report.py +250 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,18 @@ The [Blender bundle](collection/bundles/blender-3d/README.md) includes Quick, St
|
|
|
86
86
|
Production workflows, compact create/fix handoffs and per-phase usage records. Start with
|
|
87
87
|
`blender-asset`; animation and export checks are optional additions to the selected profile.
|
|
88
88
|
|
|
89
|
+
Use the local Astro Preview application for project asset previews:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
agentkit sync astro-preview --provider claude,codex
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The [Astro Preview skill](collection/skills/astro-preview/SKILL.md) covers stable preview links,
|
|
96
|
+
linked model animations, image differences, audio A/B and local HTML/Vite profiles.
|
|
97
|
+
Supply the application's checkout once through
|
|
98
|
+
`ASTRO_PREVIEW_DIR` or project context. The skill reuses its local server and catalog;
|
|
99
|
+
Agentkit installs the instructions, while the application is installed separately.
|
|
100
|
+
|
|
89
101
|
Get retro suggestions after significant sessions (optional Stop-hook nudge for both tools):
|
|
90
102
|
|
|
91
103
|
```bash
|
|
@@ -93,6 +105,32 @@ agentkit sync session-retro --provider claude,codex
|
|
|
93
105
|
python3 .claude/skills/session-retro/scripts/install_hooks.py
|
|
94
106
|
```
|
|
95
107
|
|
|
108
|
+
Review new portions of Codex session history with persistent checkpoints and an offline HTML report history:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
agentkit sync self-reflection --provider claude,codex
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The [Self Reflection skill](collection/skills/self-reflection/SKILL.md) includes Python helpers,
|
|
115
|
+
tests and report templates. It reviews instructions and delegation, carries open episodes and
|
|
116
|
+
recommendations between runs, and keeps logs and review state local. Requires Python 3.10+
|
|
117
|
+
on macOS/Linux. Both providers can run it; the input format remains Codex JSONL, not native
|
|
118
|
+
Claude transcripts. Unlike the single-session `session-retro` digest above, it incrementally
|
|
119
|
+
reviews project history and publishes a cumulative report with a date/time selector.
|
|
120
|
+
The bundled Claude exporter also supports an explicitly chosen project or global install.
|
|
121
|
+
|
|
122
|
+
Generate humanoid clips locally with NVIDIA Kimodo, starting and ending in a rig's own poses:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
agentkit sync kimodo-motion --provider claude,codex
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
The [Kimodo Motion skill](collection/skills/kimodo-motion/SKILL.md) ships a patch that adds key-pose
|
|
129
|
+
constraints (upstream Kimodo's constraints JSON) to the native kimodo.cpp build, Python helpers for
|
|
130
|
+
generation, key-pose error gates, frame sheets and residual easing, and Blender scripts that turn a
|
|
131
|
+
Mixamo-named rig's pose into a key pose and bake takes back onto the rig. kimodo.cpp, its models and
|
|
132
|
+
Blender are installed separately; `KIMODO_ROOT` and `BLENDER` point at them.
|
|
133
|
+
|
|
96
134
|
Adopt a single skill for Codex:
|
|
97
135
|
|
|
98
136
|
```bash
|
package/collection/NOTICE.md
CHANGED
|
@@ -34,3 +34,11 @@ This collection contains skills and agents derived in part from third-party open
|
|
|
34
34
|
- **Source:** `meta-tags-optimizer` skill by Aaron He Zhu — https://github.com/aaron-he-zhu/seo-geo-claude-skills/tree/main/build/meta-tags-optimizer
|
|
35
35
|
- **License:** Apache License 2.0
|
|
36
36
|
- **Nature of derivation:** Concept, length budgets, and tag-set coverage (title / meta description / Open Graph / Twitter Card / supporting tags) adapted from the upstream skill. Upstream coupling to `memory/content/`, `memory/hot-cache.md`, `memory/open-loops.md`, the CORE-EEAT alignment check, the cross-skill "next step" routing to `schema-markup-generator`, and the multi-language preset list are not carried over. Procedure, safety constraints, and output contract are rewritten for this collection's single-file skill format.
|
|
37
|
+
|
|
38
|
+
## kimodo-motion
|
|
39
|
+
|
|
40
|
+
- **Sources:**
|
|
41
|
+
- kimodo.cpp by the LocalAI team — https://github.com/localai-org/kimodo.cpp (commit `ed8a931`): the key-pose patch modifies its sources; the SOMA30 joint names, parents and offsets in `scripts/kimodo_motion.py` are copied from its `scripts/export_glb.py`.
|
|
42
|
+
- Kimodo by NVIDIA — https://github.com/nv-tlabs/kimodo: the constraints JSON format and the full-body/end-effector conditioning the patch follows; the skeleton definitions kimodo.cpp copied.
|
|
43
|
+
- **License:** Apache License 2.0 (kimodo.cpp and NVIDIA Kimodo code). Model weights are not included; they carry the NVIDIA Open Model License and the Meta Llama 3 Community License.
|
|
44
|
+
- **Nature of derivation:** The patch adds key-pose constraint input to kimodo.cpp's native generator. Generation helpers, gates, residual easing, sheets and the Blender scripts are original to this collection.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: astro-preview
|
|
3
|
+
description: Open and verify local project assets in Astro Preview when a user needs browser previews of images, sound, Blender/3D models, animations, local HTML/Vite or comparison analysis. Use the existing viewer rather than creating a project-specific preview app.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Scope
|
|
7
|
+
|
|
8
|
+
Prepare a local Astro Preview workspace for the requested assets, open the relevant viewer, and report the observed result. Building or changing Astro Preview itself is outside this workflow.
|
|
9
|
+
|
|
10
|
+
## Prerequisites
|
|
11
|
+
|
|
12
|
+
- Astro Preview is a local TypeScript server and browser application. The consumer supplies its checkout path as `ASTRO_PREVIEW_DIR` or in project context; do not assume a personal filesystem path or a published npm package.
|
|
13
|
+
- Use the checkout's `README.md` as the tool documentation. Resolve a clickable local link to that file when reporting setup. Install [Node.js](https://nodejs.org/en/download) matching the checkout's `package.json` engine, then run `npm --prefix "$ASTRO_PREVIEW_DIR" install` once if dependencies are absent.
|
|
14
|
+
- Verify the checkout with `node "$ASTRO_PREVIEW_DIR/bin/viewer.mjs" --help` and confirm it identifies Astro Preview. If the checkout cannot be located, request its path and halt setup; do not substitute another viewer silently.
|
|
15
|
+
- For Vite profiles, the selected project needs its own installed [Vite](https://vite.dev/guide/) and dependencies. Follow that project's package manager and dependency versions; if installation is needed, use its documented install command. Verify with the project-local `node node_modules/vite/bin/vite.js --version` from the Vite directory (or the package manager's local binary equivalent). Astro Preview never installs packages or runs arbitrary shell commands.
|
|
16
|
+
- Native GLB/glTF previews need no Blender. `.blend`, OBJ and FBX conversion require [Blender](https://www.blender.org/download/) on macOS, at the default application path or via `VIEWER_BLENDER`. Verify the configured executable with `--version` before conversion. Other formats can still be previewed when Blender is absent.
|
|
17
|
+
|
|
18
|
+
## Procedure
|
|
19
|
+
|
|
20
|
+
Apply the boundaries below throughout these steps; halt only the affected operation when a prerequisite or authorization is missing.
|
|
21
|
+
|
|
22
|
+
1. Locate the actual output files and select the smallest useful project roots. Prefer generated asset folders over registering the entire repository. Keep the project name stable and use absolute paths.
|
|
23
|
+
2. Reuse a running Astro Preview instance if its page loads and it uses the intended catalog. Otherwise run `npm --prefix "$ASTRO_PREVIEW_DIR" run dev` in a managed terminal, then open `http://127.0.0.1:4174`. For an existing build use `npm --prefix "$ASTRO_PREVIEW_DIR" start`. Respect configured `VIEWER_PORT` and use the exact loopback address. Record the process handle and stop only a process this task started when it is no longer needed.
|
|
24
|
+
3. Register the named project idempotently:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
node "$ASTRO_PREVIEW_DIR/bin/viewer.mjs" project add "Project name" --root /absolute/outputs --root /absolute/references --json
|
|
28
|
+
node "$ASTRO_PREVIEW_DIR/bin/viewer.mjs" project show "Project name" --json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
CLI and server must share `VIEWER_DATA_DIR` when it is configured. Existing roots remain; do not remove them merely to match the example. For reading operations, use a listed project ID if a name is ambiguous. If named-root registration encounters duplicate names, halt that operation and request a unique name or explicit selection through the viewer; IDs are not accepted in place of the name by `project add --root`. Listing or scanning is available through `project list`, `asset list` and `project scan` with `--json`. After CLI registration or other catalog changes, reload or navigate the viewer page before selecting the project; an already open empty catalog does not subscribe to project updates.
|
|
32
|
+
4. Generate a stable viewer link when useful:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
node "$ASTRO_PREVIEW_DIR/bin/viewer.mjs" open "project-id" "asset-id-a" "asset-id-b" --layout 2 --json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Open the returned URL with the browser tool. Omit assets/layout for a project link. `--json` emits the URL without launching a browser; it does not start the server. Assets accept IDs or unambiguous root-relative paths. Use Copy preview link for the current ordered layout, including comparisons across projects. Links require the same local catalog; they capture project/assets/layout, not full camera, assembly or playback state. If a stale ID/path fails, inspect the current catalog and report the missing asset rather than inventing an ID.
|
|
39
|
+
5. Open the project's explorer or gallery and choose the relevant files. Use image zoom/pan for screenshots, waveform/playback/seek/loop for sound, and model camera/wireframe/parts/animation controls for 3D. Use 2–6 comparison slots for models, images or sound, including assets from different projects; linked cameras apply to 3D. Compatible animation libraries and assembly controls preview rigs/parts without modifying their sources. For requested motion comparisons where playable clips are available, select a playable clip in each model slot, then enable Linked animations for shared time/play/pause/seek/speed/loop; each slot keeps its local clip selection. Use Front/Rear/Left/Right/Top, Skeleton and Bounds for inspection. Verify that playback advances in every relevant slot; incompatible clips remain unavailable.
|
|
40
|
+
6. For exactly two sound assets use Audio A/B and verify switching at the current position. RMS matching attenuates the louder PCM recording; silent inputs cannot be matched. For exactly two same-size images use Pixel difference: first frame/page, up to 8 MP, visible RGBA comparison with alpha-weighted RGB. Report changed-pixel count/percentage and the heatmap.
|
|
41
|
+
7. For requested HTML/Vite web apps use Project previews: reuse the intended profile or add one with an authorized root, HTML entry file or Vite directory, then Start and Open preview. HTML uses a separate capability-protected local origin. Stable viewer links never start profiles. Stop only a runtime this task started when it is no longer needed. If Vite is absent, halt that launch and continue supported previews.
|
|
42
|
+
8. After generating or changing assets, wait for live refresh and verify the changed viewer. Use Refresh for exports that preserve size/mtime. Verify the real browser result with the available browser tool: rendered image/model or HTML/Vite page, loaded clip, or audio playback state and duration. A successful API response or screenshot alone does not prove sound is audible or animation plays; report what was actually checked. Preserve useful workspace tabs and view state for the user.
|
|
43
|
+
|
|
44
|
+
## Boundaries
|
|
45
|
+
|
|
46
|
+
- Previewing and registering folders authorizes local catalog/cache changes. Asset viewers keep source assets read-only. Reviews decisions, comments, archive and deletion write review state/media; perform those only when explicitly requested.
|
|
47
|
+
- Starting Vite executes the project's config/plugins on the host: they can write caches/files or use networking. Launch only the user's intended trusted project; this is not sandboxed Blender or Reviews HTML. Vite’s resource port uses its own dev-server access controls rather than Astro Preview’s API/capability session. The viewer controls its own runtime process, not arbitrary existing project processes.
|
|
48
|
+
- Keep the server on loopback. Do not upload assets, publish the app or replace a user's running process as part of opening a preview.
|
|
49
|
+
- GLB/glTF preserve rigs, morphs and clips; their external dependencies must remain inside configured roots. Add an intended sibling asset root when authorized; do not weaken path validation or fetch remote model dependencies.
|
|
50
|
+
- Sound codecs depend on the browser. GIF/multipage images display the first frame/page. Video and unsupported formats have no interactive viewer; compressed glTF needing Draco/meshopt/Basis decoders is unsupported. Report a relevant limitation and continue with supported assets; Astro Preview's cache-only Blender conversion is part of previewing; exporting converted assets outside its cache requires a separate user request.
|
|
51
|
+
- Data uses Astro Preview's own catalog, separate from Astro Pilot. Do not claim imported projects or reduced memory usage unless verified.
|
|
52
|
+
|
|
53
|
+
## Output Contract
|
|
54
|
+
|
|
55
|
+
Emit `Skill: astro-preview - output below`, then state:
|
|
56
|
+
|
|
57
|
+
- Viewer URL and whether the server was reused or started.
|
|
58
|
+
- Registered project name/ID and roots.
|
|
59
|
+
- Assets/view mode, optional profile/runtime URL, and observed rendering, playback or comparison metrics.
|
|
60
|
+
- Relevant limitations, missing prerequisites or unverified playback/rendering.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kimodo-motion
|
|
3
|
+
description: Generate humanoid animation clips locally with NVIDIA Kimodo (native kimodo.cpp build) from a text prompt, optionally starting and ending in given poses (key-pose constraints taken from a rig's existing clips), check them numerically and visually on Kimodo's own skeleton, and retarget them onto a Mixamo-named Blender rig. Use when a clip nobody provides is needed (a draw, a gesture, a transition between two existing poses); not for editing captured clips or for finger animation.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Kimodo Motion
|
|
7
|
+
|
|
8
|
+
## Scope
|
|
9
|
+
|
|
10
|
+
- Text-to-motion takes on Kimodo's SOMA30 skeleton, several seeds per prompt, with optional start/end key poses
|
|
11
|
+
taken from a rig's own clips, so a take starts and ends where the neighbouring clips do (no cut/settle/blend).
|
|
12
|
+
- Numeric gates (key-pose error), frame sheets for a reviewer, a bake onto a Mixamo-named rig with a direction check.
|
|
13
|
+
- Out of scope: fingers and props (Kimodo has neither), mid-clip keys (the patch reads `end-effector` keys on any
|
|
14
|
+
frame; `generate` keys only the ends), root2d paths (not supported), engine integration, loop clips.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
- [kimodo.cpp](https://github.com/localai-org/kimodo.cpp) at `ed8a931` (Apache-2.0) with
|
|
19
|
+
`<skill>/patches/kimodo-cpp-keyposes.patch` (`git apply`). It adds `kmd-generate ... --constraints FILE`, which reads
|
|
20
|
+
upstream Kimodo's constraints JSON (`fullbody`, `end-effector`, `left/right-hand/foot`). Build (C++23, CMake 3.25+;
|
|
21
|
+
verified CPU-only on macOS, Vulkan per its README on Linux):
|
|
22
|
+
`cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DKIMODO_ENABLE_VULKAN=OFF -DKIMODO_BUILD_TESTS=OFF && cmake --build
|
|
23
|
+
build --target kmd-generate`. Verify: `build/kmd-generate` prints a usage line with `--constraints`.
|
|
24
|
+
- Models: `scripts/download_gguf_weights.sh --output "$PWD" --model soma-rp-v1.1` (needs the `hf` CLI). Keep the
|
|
25
|
+
NVIDIA Open Model License and Meta Llama 3 notices. Verify: `ls "$KIMODO_ROOT"/models/*.gguf` shows the
|
|
26
|
+
motion and text files the defaults (or `KIMODO_MOTION_GGUF` / `KIMODO_TEXT_GGUF`) name.
|
|
27
|
+
- Environment: `KIMODO_ROOT` (that checkout); `KIMODO_GENERATE`, `KIMODO_MOTION_GGUF`, `KIMODO_TEXT_GGUF` when they
|
|
28
|
+
differ from the defaults in `<skill>/scripts/kimodo_motion.py` (relative to `KIMODO_ROOT` or absolute);
|
|
29
|
+
optional `KIMODO_EXPORT_GLB` (its `scripts/export_glb.py`: a skeleton GLB per take).
|
|
30
|
+
- [Python 3.10+](https://www.python.org/downloads/), standard library; sheets need Pillow
|
|
31
|
+
(`python3 -m pip install Pillow`, verify `python3 -c "import PIL"`).
|
|
32
|
+
- Key poses and retargeting: [Blender](https://www.blender.org/download/) 4.x/5.x, `BLENDER` = its executable.
|
|
33
|
+
Verify: `"$BLENDER" -b --factory-startup --version`, then `BLENDER=... python3 -m unittest discover -s
|
|
34
|
+
<skill>/tests -v` (the round trip skips without `BLENDER`).
|
|
35
|
+
|
|
36
|
+
## Inputs
|
|
37
|
+
|
|
38
|
+
- Prompt, length `F` in frames (30 fps), seeds (3-4), output dir; for key poses: the rig `.blend` (one armature,
|
|
39
|
+
Mixamo names with prefix `mixamorig:` unless `--prefix` says otherwise, facing -Y) and the clips whose poses start
|
|
40
|
+
and end the take (action-only `.blend` files, with a frame).
|
|
41
|
+
|
|
42
|
+
## Procedure
|
|
43
|
+
|
|
44
|
+
`<skill>` is this skill's installed folder; commands run from the consumer project.
|
|
45
|
+
|
|
46
|
+
1. Spec before generating: the prompt (one short sentence of what the body does; wording about the end state made
|
|
47
|
+
takes start in it), `F`, seeds, start/end poses, acceptance (the gates below, the content a reviewer must see).
|
|
48
|
+
2. Key poses: `python3 <skill>/scripts/kimodo_motion.py keypose --rig RIG.blend start=IDLE.blend end=HOLD.blend
|
|
49
|
+
--out POSES.json [--prefix P]`. It inverts the retarget's bone map and rest alignment and fails above 3 deg on
|
|
50
|
+
any mapped bone's direction. It moves the root so the lower toe stands at Kimodo's toe height (`--toe-y`,
|
|
51
|
+
0.015 m). Regenerate the poses whenever a source clip is re-baked.
|
|
52
|
+
3. Generate: `python3 <skill>/scripts/kimodo_motion.py generate --prompt "..." --frames F --seeds 1,2,3,4 --start
|
|
53
|
+
POSES.json:start --end POSES.json:end --out DIR --name k1`. Defaults:
|
|
54
|
+
- each key is held 3 frames (`--hold`): a single key let the take leave a still pose at full speed;
|
|
55
|
+
- hands and feet keep their turn (`end-effector`; `--no-effectors` turns it off): positions alone left the
|
|
56
|
+
hands 24-39 deg off;
|
|
57
|
+
- the model's residual on its keys (about 19 mm mean, up to about 5 cm at finger ends) is eased out over 0.3 s
|
|
58
|
+
(`--post`) as an offset, not a blend toward the static key (that moved joints 14-20 cm mid-motion). The
|
|
59
|
+
model's own take stays in `raw/`.
|
|
60
|
+
4. Numeric gates, per take, in `keypose_error.json`:
|
|
61
|
+
- the model's own take: mean joint error at most 30 mm on every key frame (`check DIR/k1_s1 --model` re-runs it);
|
|
62
|
+
- after post: at most 5 mm on any joint (`check DIR/k1_s1` re-runs it);
|
|
63
|
+
- known-bad: the same prompt and `F` without `--start/--end` (`--name k1n --seeds 1`) must FAIL
|
|
64
|
+
`check DIR/k1n_s1 --model --constraints DIR/k1_s1/constraints.json` (measured: 79-289 mm). If it passes, the
|
|
65
|
+
gate is broken: stop.
|
|
66
|
+
5. Sheets for a fresh-context reviewer or the user, never the agent that generated the takes:
|
|
67
|
+
- phases: `sheet DIR/k1_s* DIR/k1_s1/raw DIR/k1n_s1 --keys DIR/k1_s1/constraints.json --out phases.png`;
|
|
68
|
+
- every frame of both junctions: `--span 0:10` and `--span F-11:F-1` (75 frames: `64:74`).
|
|
69
|
+
Ask for: start and end on the grey keys, pops where a hold releases, and whether the motion reads as the prompt.
|
|
70
|
+
Drop takes that do something else (a seed that does the end action first keeps doing it). Take at most two
|
|
71
|
+
rounds of new seeds or prompts; after that, ask the user. Mark the chosen take in `provenance.json` (`used_as`).
|
|
72
|
+
6. Retarget the chosen take: `"$BLENDER" -b RIG.blend --factory-startup --python-exit-code 1 --python
|
|
73
|
+
<skill>/scripts/kimodo_retarget.py -- retarget --clip NAME=DIR/k1_s3 --out CLIPS.glb --report report.json
|
|
74
|
+
[--prefix P]`. Every mapped bone's world turn is copied and only the hips move. Above 3 deg on any bone's
|
|
75
|
+
direction it writes the report and no GLB. Fingers, props and contact fixes belong to the consumer project.
|
|
76
|
+
`stats` gives the right hand's closest approach to the hip, for draw or reach clips.
|
|
77
|
+
|
|
78
|
+
## Boundaries
|
|
79
|
+
|
|
80
|
+
- Write takes into new dirs (`generate` refuses existing ones). Keep `provenance.json` (seed, command, keys) for
|
|
81
|
+
AI-content disclosure. Models, licences and machine paths stay outside the skill.
|
|
82
|
+
- Where a hold releases, the residual offset can add a one-frame step of about 2 cm. Measure the largest per-frame
|
|
83
|
+
joint step in the junction strips against `raw/` and report it. Do not hide it.
|
|
84
|
+
|
|
85
|
+
## Stop Conditions
|
|
86
|
+
|
|
87
|
+
- `kmd-generate` lacks `--constraints` (unpatched build) or a model file is missing: stop and report.
|
|
88
|
+
- `keypose` or `retarget` fails its direction gate, or reports missing bones: the rig's names, prefix or rest differ
|
|
89
|
+
from the map. Stop; do not loosen the 3 deg tolerance.
|
|
90
|
+
- The known-bad passes the model gate, every take fails it, or all takes are rejected after two rounds: report the
|
|
91
|
+
numbers and sheets to the user.
|
|
92
|
+
|
|
93
|
+
## Output Contract
|
|
94
|
+
|
|
95
|
+
Skill: kimodo-motion - output below
|
|
96
|
+
|
|
97
|
+
| Take | Model mean / max (mm) | After post max (mm) | Post move (mm) | Hold-release step vs raw (mm/frame) | Content verdict | Use |
|
|
98
|
+
| --- | --- | --- | --- | --- | --- | --- |
|
|
99
|
+
|
|
100
|
+
Followed by: the poses file, the take dirs, the known-bad result, the sheet paths, the reviewer's verdict, and the
|
|
101
|
+
retarget report (worst direction per clip) when baked.
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
diff --git a/README.md b/README.md
|
|
2
|
+
index d048b43..b3b6821 100644
|
|
3
|
+
--- a/README.md
|
|
4
|
+
+++ b/README.md
|
|
5
|
+
@@ -24,9 +24,14 @@ default; set `KIMODO_TEXT_LAYER_CHUNK=1..32` to tune VRAM use.
|
|
6
|
+
Included: checked GGUF loading, safetensors conversion, DDIM sampling, C/C++
|
|
7
|
+
APIs, conditioned multi-prompt transitions, CPU/Vulkan parity tests,
|
|
8
|
+
skeleton-only GLB export, selective LLM2Vec quantisation, divergence reporting,
|
|
9
|
+
-and local generation/comparison viewers. General constraint input, 77-joint
|
|
10
|
+
-SOMA expansion, skinned-mesh GLB export, and motion-denoiser quantisation are
|
|
11
|
+
-not implemented yet.
|
|
12
|
+
+and local generation/comparison viewers. Key poses: upstream's constraints
|
|
13
|
+
+JSON types `fullbody`, `end-effector` and `left/right-hand/foot`
|
|
14
|
+
+(30-joint axis-angle `local_joints_rot`, `root_positions`, optional
|
|
15
|
+
+`smooth_root_2d`) through `kmd-generate ... --constraints FILE` and
|
|
16
|
+
+`model::generate_text_keyposes`; the constraint CFG weight is
|
|
17
|
+
+`KIMODO_CONSTRAINT_CFG` (default 2). Root 2D and SOMA77 constraints, upstream's motion-correction post-processing, 77-joint SOMA
|
|
18
|
+
+expansion, skinned-mesh GLB export, and motion-denoiser quantisation are not
|
|
19
|
+
+implemented yet.
|
|
20
|
+
|
|
21
|
+
## Build and test on Linux
|
|
22
|
+
|
|
23
|
+
diff --git a/include/kimodo/kimodo.hpp b/include/kimodo/kimodo.hpp
|
|
24
|
+
index e774e5a..9dc5077 100644
|
|
25
|
+
--- a/include/kimodo/kimodo.hpp
|
|
26
|
+
+++ b/include/kimodo/kimodo.hpp
|
|
27
|
+
@@ -27,6 +27,22 @@ struct prompt_segment {
|
|
28
|
+
unsigned frames = 0;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
+// One upstream key-pose constraint on a frame: every joint's local rotation
|
|
32
|
+
+// as axis-angle radians [joints*3] and the root (hips) position [3] in
|
|
33
|
+
+// metres, Y up, XZ relative to the canonical origin. As upstream, every key
|
|
34
|
+
+// holds the root height, path and heading; `fullbody` (no end_effectors)
|
|
35
|
+
+// adds every joint's FK position, not rotations; `end-effector` (names
|
|
36
|
+
+// LeftHand, RightHand, LeftFoot, RightFoot, Hips; SOMA30 only) adds each
|
|
37
|
+
+// chain's positions and its first joint's global rotation.
|
|
38
|
+
+struct pose_key {
|
|
39
|
+
+ unsigned frame = 0;
|
|
40
|
+
+ std::vector<float> local_axis_angle;
|
|
41
|
+
+ std::array<float, 3> root_position{};
|
|
42
|
+
+ bool has_smooth_root_2d = false;
|
|
43
|
+
+ std::array<float, 2> smooth_root_2d{}; // [x, z]; default: the root's x, z
|
|
44
|
+
+ std::vector<std::string> end_effectors;
|
|
45
|
+
+};
|
|
46
|
+
+
|
|
47
|
+
class KIMODO_API model {
|
|
48
|
+
public:
|
|
49
|
+
static std::expected<std::unique_ptr<model>, std::string> load(
|
|
50
|
+
@@ -38,6 +54,12 @@ public:
|
|
51
|
+
std::expected<motion_data, std::string> generate_text(
|
|
52
|
+
std::string_view utf8_prompt, unsigned frames, unsigned steps, std::uint64_t seed,
|
|
53
|
+
float text_cfg, float constraint_cfg) const;
|
|
54
|
+
+ // Text plus key poses (separated CFG, constraint row as upstream).
|
|
55
|
+
+ // The first heading is the frame-0 key's heading, else 0 (facing +Z).
|
|
56
|
+
+ std::expected<motion_data, std::string> generate_text_keyposes(
|
|
57
|
+
+ std::string_view utf8_prompt, std::span<const pose_key> keys,
|
|
58
|
+
+ unsigned frames, unsigned steps, std::uint64_t seed,
|
|
59
|
+
+ float text_cfg, float constraint_cfg) const;
|
|
60
|
+
std::expected<motion_data, std::string> generate_text_sequence(
|
|
61
|
+
std::span<const prompt_segment> segments, unsigned transition_frames,
|
|
62
|
+
unsigned steps, std::uint64_t seed, float text_cfg, float constraint_cfg) const;
|
|
63
|
+
diff --git a/src/denoiser.hpp b/src/denoiser.hpp
|
|
64
|
+
index 8749607..0c0ac11 100644
|
|
65
|
+
--- a/src/denoiser.hpp
|
|
66
|
+
+++ b/src/denoiser.hpp
|
|
67
|
+
@@ -8,6 +8,7 @@
|
|
68
|
+
|
|
69
|
+
namespace kimodo::detail {
|
|
70
|
+
class ggml_motion_weights;
|
|
71
|
+
+struct skeleton_spec;
|
|
72
|
+
|
|
73
|
+
// One sequence segment with an already-encoded text condition and caller-
|
|
74
|
+
// supplied initial noise. Continuation noise includes its transition prefix.
|
|
75
|
+
@@ -70,6 +71,16 @@ std::expected<std::vector<float>, std::string> sample_motion_sequence_from_noise
|
|
76
|
+
const ggml_motion_weights &weights, std::span<const sampled_sequence_segment> segments,
|
|
77
|
+
unsigned transition_frames, unsigned steps, float text_weight, float constraint_weight);
|
|
78
|
+
|
|
79
|
+
+// Upstream Full-body/EndEffectorConstraintSet + KimodoMotionRep.create_conditions
|
|
80
|
+
+// for one key pose: local axis-angle rotations [J*3] and the root position go
|
|
81
|
+
+// through FK into the raw (unnormalized) feature row [motion_dim]; the mask
|
|
82
|
+
+// gains the smooth root and heading, the positions of `positions` (empty:
|
|
83
|
+
+// every joint; GLOBAL: subtract the frame's final smooth root x/z after all
|
|
84
|
+
+// its keys) and the global 6D rotations of `rotations`. Returns the heading.
|
|
85
|
+
+float pose_condition(const skeleton_spec &skeleton, std::span<const float> local_axis_angle,
|
|
86
|
+
+ const float root[3], const float *smooth_root_2d, std::span<const unsigned> positions,
|
|
87
|
+
+ std::span<const unsigned> rotations, float *value, float *mask);
|
|
88
|
+
+
|
|
89
|
+
// Build the exact condition consumed by the next `_multiprompt` DDIM run.
|
|
90
|
+
// Exposed for the raw fixture test as well as the runtime orchestrator.
|
|
91
|
+
std::expected<sequence_transition, std::string> prepare_sequence_transition(
|
|
92
|
+
diff --git a/src/generate.cpp b/src/generate.cpp
|
|
93
|
+
index 132f88e..c3d3632 100644
|
|
94
|
+
--- a/src/generate.cpp
|
|
95
|
+
+++ b/src/generate.cpp
|
|
96
|
+
@@ -35,6 +35,132 @@ std::vector<std::string> split_fields(const std::string &line) {
|
|
97
|
+
return fields;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
+// Just enough JSON for upstream's constraints file (`kimodo --constraints`):
|
|
101
|
+
+// a list of objects with numbers, strings and nested lists.
|
|
102
|
+
+struct json {
|
|
103
|
+
+ enum kind_t { null, number, string, array, object } kind = null;
|
|
104
|
+
+ double num = 0;
|
|
105
|
+
+ std::string str;
|
|
106
|
+
+ std::vector<json> items;
|
|
107
|
+
+ std::vector<std::pair<std::string, json>> fields;
|
|
108
|
+
+ const json *get(std::string_view key) const {
|
|
109
|
+
+ for (const auto &[name, value] : fields) if (name == key) return &value;
|
|
110
|
+
+ return nullptr;
|
|
111
|
+
+ }
|
|
112
|
+
+};
|
|
113
|
+
+
|
|
114
|
+
+struct json_parser {
|
|
115
|
+
+ std::string_view text;
|
|
116
|
+
+ size_t at = 0;
|
|
117
|
+
+ void space() { while (at < text.size() && std::isspace(static_cast<unsigned char>(text[at]))) ++at; }
|
|
118
|
+
+ [[noreturn]] void fail(const char *what) { throw std::runtime_error("constraints JSON: " + std::string(what) + " at byte " + std::to_string(at)); }
|
|
119
|
+
+ bool eat(char c) { space(); if (at < text.size() && text[at] == c) { ++at; return true; } return false; }
|
|
120
|
+
+ std::string string() {
|
|
121
|
+
+ if (!eat('"')) fail("expected a string");
|
|
122
|
+
+ std::string out;
|
|
123
|
+
+ while (at < text.size() && text[at] != '"') { if (text[at] == '\\') ++at; if (at < text.size()) out += text[at++]; }
|
|
124
|
+
+ if (!eat('"')) fail("unterminated string");
|
|
125
|
+
+ return out;
|
|
126
|
+
+ }
|
|
127
|
+
+ json value() {
|
|
128
|
+
+ space();
|
|
129
|
+
+ json v;
|
|
130
|
+
+ if (at >= text.size()) fail("unexpected end");
|
|
131
|
+
+ const char c = text[at];
|
|
132
|
+
+ if (c == '{') {
|
|
133
|
+
+ ++at; v.kind = json::object;
|
|
134
|
+
+ if (eat('}')) return v;
|
|
135
|
+
+ do { auto key = string(); if (!eat(':')) fail("expected ':'"); v.fields.emplace_back(key, value()); } while (eat(','));
|
|
136
|
+
+ if (!eat('}')) fail("expected '}'");
|
|
137
|
+
+ } else if (c == '[') {
|
|
138
|
+
+ ++at; v.kind = json::array;
|
|
139
|
+
+ if (eat(']')) return v;
|
|
140
|
+
+ do v.items.push_back(value()); while (eat(','));
|
|
141
|
+
+ if (!eat(']')) fail("expected ']'");
|
|
142
|
+
+ } else if (c == '"') {
|
|
143
|
+
+ v.kind = json::string; v.str = string();
|
|
144
|
+
+ } else if (text.substr(at, 4) == "null") {
|
|
145
|
+
+ at += 4;
|
|
146
|
+
+ } else {
|
|
147
|
+
+ const std::string rest(text.substr(at, 64));
|
|
148
|
+
+ size_t used = 0;
|
|
149
|
+
+ try { v.num = std::stod(rest, &used); } catch (const std::exception &) { fail("expected a value"); }
|
|
150
|
+
+ v.kind = json::number; at += used;
|
|
151
|
+
+ }
|
|
152
|
+
+ return v;
|
|
153
|
+
+ }
|
|
154
|
+
+};
|
|
155
|
+
+
|
|
156
|
+
+std::vector<float> numbers(const json *value, const char *name) {
|
|
157
|
+
+ if (!value) throw std::runtime_error(std::string("constraint lacks ") + name);
|
|
158
|
+
+ std::vector<float> out;
|
|
159
|
+
+ auto walk = [&](auto &self, const json &v) -> void {
|
|
160
|
+
+ if (v.kind == json::number) out.push_back(static_cast<float>(v.num));
|
|
161
|
+
+ else if (v.kind == json::array) for (const auto &item : v.items) self(self, item);
|
|
162
|
+
+ else throw std::runtime_error(std::string("constraint field ") + name + " must hold numbers");
|
|
163
|
+
+ };
|
|
164
|
+
+ walk(walk, *value);
|
|
165
|
+
+ return out;
|
|
166
|
+
+}
|
|
167
|
+
+
|
|
168
|
+
+// Upstream key-pose entries: `fullbody`, `end-effector` (joint_names) and its
|
|
169
|
+
+// shorthands left-hand/right-hand/left-foot/right-foot, each with
|
|
170
|
+
+// frame_indices [T], local_joints_rot [T,J,3] axis-angle, root_positions [T,3]
|
|
171
|
+
+// and optional smooth_root_2d [T,2] (root2d is not read yet). The joint count
|
|
172
|
+
+// comes from the data; the model checks it against its skeleton.
|
|
173
|
+
+std::vector<kimodo::pose_key> read_keyposes(const std::filesystem::path &path) {
|
|
174
|
+
+ std::ifstream file(path);
|
|
175
|
+
+ const std::string text{std::istreambuf_iterator<char>(file), {}};
|
|
176
|
+
+ if (!file && text.empty()) throw std::runtime_error("cannot read constraints " + path.string());
|
|
177
|
+
+ json_parser parser{text};
|
|
178
|
+
+ const json root = parser.value();
|
|
179
|
+
+ if (root.kind != json::array) throw std::runtime_error("constraints JSON must be a list");
|
|
180
|
+
+ std::vector<kimodo::pose_key> keys;
|
|
181
|
+
+ for (const auto &item : root.items) {
|
|
182
|
+
+ const json *type = item.get("type");
|
|
183
|
+
+ const std::string kind = type ? type->str : std::string();
|
|
184
|
+
+ std::vector<std::string> end_effectors;
|
|
185
|
+
+ if (kind == "left-hand") end_effectors = {"LeftHand"};
|
|
186
|
+
+ else if (kind == "right-hand") end_effectors = {"RightHand"};
|
|
187
|
+
+ else if (kind == "left-foot") end_effectors = {"LeftFoot"};
|
|
188
|
+
+ else if (kind == "right-foot") end_effectors = {"RightFoot"};
|
|
189
|
+
+ else if (kind == "end-effector") {
|
|
190
|
+
+ const json *names = item.get("joint_names");
|
|
191
|
+
+ if (!names || names->kind != json::array || names->items.empty()) throw std::runtime_error("end-effector lacks joint_names");
|
|
192
|
+
+ for (const auto &name : names->items) end_effectors.push_back(name.str);
|
|
193
|
+
+ } else if (kind != "fullbody")
|
|
194
|
+
+ throw std::runtime_error("unsupported constraint type '" + kind + "' (fullbody, end-effector, left/right-hand/foot)");
|
|
195
|
+
+ const auto frames = numbers(item.get("frame_indices"), "frame_indices");
|
|
196
|
+
+ const auto rotations = numbers(item.get("local_joints_rot"), "local_joints_rot");
|
|
197
|
+
+ const auto roots = numbers(item.get("root_positions"), "root_positions");
|
|
198
|
+
+ const json *smooth = item.get("smooth_root_2d");
|
|
199
|
+
+ const auto smooth_values = smooth && smooth->kind != json::null ? numbers(smooth, "smooth_root_2d") : std::vector<float>{};
|
|
200
|
+
+ const size_t count = frames.size();
|
|
201
|
+
+ if (!count || rotations.size() % (count*3)) throw std::runtime_error("local_joints_rot must be [T,J,3]");
|
|
202
|
+
+ const size_t joints = rotations.size() / (count*3);
|
|
203
|
+
+ if (roots.size() != count*3 || (!smooth_values.empty() && smooth_values.size() != count*2))
|
|
204
|
+
+ throw std::runtime_error("root_positions / smooth_root_2d do not match frame_indices");
|
|
205
|
+
+ for (size_t t = 0; t < count; ++t) {
|
|
206
|
+
+ if (frames[t] < 0) throw std::runtime_error("negative frame index");
|
|
207
|
+
+ kimodo::pose_key key;
|
|
208
|
+
+ key.frame = static_cast<unsigned>(frames[t]);
|
|
209
|
+
+ key.end_effectors = end_effectors;
|
|
210
|
+
+ key.local_axis_angle.assign(rotations.begin() + static_cast<std::ptrdiff_t>(t*joints*3),
|
|
211
|
+
+ rotations.begin() + static_cast<std::ptrdiff_t>((t+1)*joints*3));
|
|
212
|
+
+ key.root_position = {roots[t*3], roots[t*3+1], roots[t*3+2]};
|
|
213
|
+
+ if (!smooth_values.empty()) { key.has_smooth_root_2d = true; key.smooth_root_2d = {smooth_values[t*2], smooth_values[t*2+1]}; }
|
|
214
|
+
+ keys.push_back(std::move(key));
|
|
215
|
+
+ }
|
|
216
|
+
+ }
|
|
217
|
+
+ return keys;
|
|
218
|
+
+}
|
|
219
|
+
+
|
|
220
|
+
+// Constraint CFG weight for key poses: KIMODO_CONSTRAINT_CFG, default 2 as upstream.
|
|
221
|
+
+float constraint_cfg() {
|
|
222
|
+
+ const char *value = std::getenv("KIMODO_CONSTRAINT_CFG");
|
|
223
|
+
+ return value ? std::stof(value) : 2.F;
|
|
224
|
+
+}
|
|
225
|
+
+
|
|
226
|
+
std::string protocol_error(std::string message) {
|
|
227
|
+
for (char &c : message) if (c == '\n' || c == '\r' || c == '\t') c = ' ';
|
|
228
|
+
return message;
|
|
229
|
+
@@ -91,8 +217,9 @@ int main(int argc, char **argv) try {
|
|
230
|
+
std::cout << "generated " << motion->frames << " frames with " << motion->joints << " joints\n";
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
- if (argc != 8) {
|
|
234
|
+
- std::cerr << "usage: " << argv[0] << " MOTION.gguf TEXT_BUNDLE PROMPT.txt FRAMES STEPS SEED OUTPUT_DIR\n"
|
|
235
|
+
+ const bool keyposes = argc == 10 && std::string_view(argv[8]) == "--constraints";
|
|
236
|
+
+ if (argc != 8 && !keyposes) {
|
|
237
|
+
+ std::cerr << "usage: " << argv[0] << " MOTION.gguf TEXT_BUNDLE PROMPT.txt FRAMES STEPS SEED OUTPUT_DIR [--constraints CONSTRAINTS.json]\n"
|
|
238
|
+
<< " or: " << argv[0] << " MOTION.gguf TEXT_BUNDLE --sequence TRANSITION STEPS SEED OUTPUT_DIR FRAME PROMPT.txt [FRAME PROMPT.txt ...]\n";
|
|
239
|
+
return 2;
|
|
240
|
+
}
|
|
241
|
+
@@ -104,7 +231,9 @@ int main(int argc, char **argv) try {
|
|
242
|
+
const auto seed = static_cast<std::uint64_t>(std::stoull(argv[6]));
|
|
243
|
+
auto model = kimodo::model::load(argv[1], argv[2]);
|
|
244
|
+
if (!model) throw std::runtime_error(model.error());
|
|
245
|
+
- auto motion = (*model)->generate_text(prompt, frames, steps, seed, 2.F, 2.F);
|
|
246
|
+
+ auto motion = keyposes
|
|
247
|
+
+ ? (*model)->generate_text_keyposes(prompt, read_keyposes(argv[9]), frames, steps, seed, 2.F, constraint_cfg())
|
|
248
|
+
+ : (*model)->generate_text(prompt, frames, steps, seed, 2.F, 2.F);
|
|
249
|
+
if (!motion) throw std::runtime_error(motion.error());
|
|
250
|
+
write_motion(argv[7], *motion);
|
|
251
|
+
std::cout << "generated " << motion->frames << " frames with " << motion->joints << " joints\n";
|
|
252
|
+
diff --git a/src/model.cpp b/src/model.cpp
|
|
253
|
+
index 91d2ec0..4f42b56 100644
|
|
254
|
+
--- a/src/model.cpp
|
|
255
|
+
+++ b/src/model.cpp
|
|
256
|
+
@@ -117,6 +117,98 @@ std::expected<motion_data, std::string> model::generate_embedding(
|
|
257
|
+
#endif
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
+std::expected<motion_data, std::string> model::generate_text_keyposes(
|
|
261
|
+
+ std::string_view utf8_prompt, std::span<const pose_key> keys, unsigned frames, unsigned steps,
|
|
262
|
+
+ std::uint64_t seed, float text_cfg, float constraint_cfg) const {
|
|
263
|
+
+#ifdef KIMODO_HAVE_GGML
|
|
264
|
+
+ if (!impl_->text) return std::unexpected("model was loaded without a native text bundle");
|
|
265
|
+
+ if (frames < 2 || frames > 10000) return std::unexpected("frames must be in 2..10000");
|
|
266
|
+
+ if (steps == 0 || steps > 1000) return std::unexpected("diffusion_steps must be in 1..1000");
|
|
267
|
+
+ if (!std::isfinite(text_cfg) || !std::isfinite(constraint_cfg)) return std::unexpected("CFG weights must be finite");
|
|
268
|
+
+ const auto &s = *impl_->skeleton;
|
|
269
|
+
+ const size_t D = s.motion_dim(), J = s.joints(), body = s.body_dim();
|
|
270
|
+
+ for (const auto &key : keys) {
|
|
271
|
+
+ if (key.frame >= frames) return std::unexpected("key pose frame outside the clip");
|
|
272
|
+
+ if (key.local_axis_angle.size() != J*3)
|
|
273
|
+
+ return std::unexpected("key pose needs " + std::to_string(J) + " joint rotations");
|
|
274
|
+
+ for (float v : key.local_axis_angle) if (!std::isfinite(v)) return std::unexpected("key pose rotation is not finite");
|
|
275
|
+
+ for (float v : key.root_position) if (!std::isfinite(v)) return std::unexpected("key pose root is not finite");
|
|
276
|
+
+ if (!key.end_effectors.empty() && s.key != "soma30") return std::unexpected("end-effector keys need the SOMA30 model");
|
|
277
|
+
+ }
|
|
278
|
+
+ // upstream SOMASkeleton30.expand_joint_names: chain positions, the chain's first joint rotated
|
|
279
|
+
+ auto chains = [&](const pose_key &key, std::vector<unsigned> &positions, std::vector<unsigned> &rotations) -> std::expected<void, std::string> {
|
|
280
|
+
+ for (const auto &name : key.end_effectors) {
|
|
281
|
+
+ std::vector<std::string_view> chain;
|
|
282
|
+
+ if (name == "LeftHand") chain = {"LeftHand", "LeftHandMiddleEnd"};
|
|
283
|
+
+ else if (name == "RightHand") chain = {"RightHand", "RightHandMiddleEnd"};
|
|
284
|
+
+ else if (name == "LeftFoot") chain = {"LeftFoot", "LeftToeBase"};
|
|
285
|
+
+ else if (name == "RightFoot") chain = {"RightFoot", "RightToeBase"};
|
|
286
|
+
+ else if (name == "Hips") chain = {"Hips"};
|
|
287
|
+
+ else return std::unexpected("unknown end effector " + name);
|
|
288
|
+
+ for (size_t i = 0; i < chain.size(); ++i) {
|
|
289
|
+
+ const auto found = std::find(s.names.begin(), s.names.end(), chain[i]);
|
|
290
|
+
+ const auto joint = static_cast<unsigned>(found - s.names.begin());
|
|
291
|
+
+ positions.push_back(joint);
|
|
292
|
+
+ if (!i) rotations.push_back(joint);
|
|
293
|
+
+ }
|
|
294
|
+
+ positions.push_back(0);
|
|
295
|
+
+ }
|
|
296
|
+
+ return {};
|
|
297
|
+
+ };
|
|
298
|
+
+ auto embedding = impl_->text->encode(utf8_prompt);
|
|
299
|
+
+ if (!embedding) return std::unexpected(embedding.error());
|
|
300
|
+
+ const std::lock_guard inference_lock(impl_->inference_mutex);
|
|
301
|
+
+ if (!impl_->weights) {
|
|
302
|
+
+ auto loaded = detail::ggml_motion_weights::load(impl_->motion_path);
|
|
303
|
+
+ if (!loaded) return std::unexpected(loaded.error());
|
|
304
|
+
+ impl_->weights = std::move(*loaded);
|
|
305
|
+
+ }
|
|
306
|
+
+ auto gm=impl_->weights->f32_values("stats.global_root.mean"), gs=impl_->weights->f32_values("stats.global_root.std");
|
|
307
|
+
+ auto bm=impl_->weights->f32_values("stats.body.mean"), bs=impl_->weights->f32_values("stats.body.std");
|
|
308
|
+
+ if (!gm || !gs || !bm || !bs) return std::unexpected("motion GGUF lacks normalization statistics");
|
|
309
|
+
+ // Upstream normalizes the whole observed tensor; only masked cells reach
|
|
310
|
+
+ // the constraint branch (x*(1-mask) + observed*mask), so zeros elsewhere.
|
|
311
|
+
+ std::vector<float> observed(frames*D, 0.F), mask(frames*D, 0.F);
|
|
312
|
+
+ float heading = 0.F;
|
|
313
|
+
+ // Keys on one frame merge their masks (a fullbody and an end-effector key of
|
|
314
|
+
+ // the same pose); each frame is normalized once.
|
|
315
|
+
+ std::vector<bool> keyed(frames, false);
|
|
316
|
+
+ for (const auto &key : keys) {
|
|
317
|
+
+ std::vector<unsigned> positions, rotations;
|
|
318
|
+
+ if (auto expanded = chains(key, positions, rotations); !expanded) return std::unexpected(expanded.error());
|
|
319
|
+
+ if (key.end_effectors.empty()) positions.clear();
|
|
320
|
+
+ const float angle = detail::pose_condition(s, key.local_axis_angle, key.root_position.data(),
|
|
321
|
+
+ key.has_smooth_root_2d ? key.smooth_root_2d.data() : nullptr, positions, rotations,
|
|
322
|
+
+ observed.data()+key.frame*D, mask.data()+key.frame*D);
|
|
323
|
+
+ if (key.frame == 0) heading = angle;
|
|
324
|
+
+ keyed[key.frame] = true;
|
|
325
|
+
+ }
|
|
326
|
+
+ for (unsigned frame = 0; frame < frames; ++frame) {
|
|
327
|
+
+ if (!keyed[frame]) continue;
|
|
328
|
+
+ float *row = observed.data()+frame*D; const float *row_mask = mask.data()+frame*D;
|
|
329
|
+
+ for (size_t j=0; j<J; ++j) if (row_mask[5+j*3] > 0.F) { row[5+j*3] -= row[0]; row[7+j*3] -= row[2]; }
|
|
330
|
+
+ for (size_t d=0; d<5; ++d) row[d]=(row[d]-(*gm)[d])/std::sqrt((*gs)[d]*(*gs)[d]+1.e-5F);
|
|
331
|
+
+ for (size_t d=0; d<body; ++d) row[5+d]=(row[5+d]-(*bm)[d])/std::sqrt((*bs)[d]*(*bs)[d]+1.e-5F);
|
|
332
|
+
+ for (size_t d=0; d<D; ++d) row[d]*=row_mask[d];
|
|
333
|
+
+ }
|
|
334
|
+
+ std::mt19937_64 rng(seed);
|
|
335
|
+
+ std::normal_distribution<float> normal(0.f, 1.f);
|
|
336
|
+
+ std::vector<float> noise(static_cast<size_t>(frames)*D);
|
|
337
|
+
+ for (float &value : noise) value = normal(rng);
|
|
338
|
+
+ auto sampled = detail::sample_motion_from_noise_conditioned(*impl_->weights, noise, *embedding, observed, mask,
|
|
339
|
+
+ heading, frames, steps, text_cfg, constraint_cfg);
|
|
340
|
+
+ if (!sampled) return std::unexpected(sampled.error());
|
|
341
|
+
+ auto decoded = detail::decode_motion(*sampled, frames, s, *gm, *gs, *bm, *bs);
|
|
342
|
+
+ if (!decoded) return std::unexpected(decoded.error());
|
|
343
|
+
+ motion_data result; result.frames=frames; result.joints=static_cast<unsigned>(J);
|
|
344
|
+
+ result.local_rotations_xyzw=std::move(decoded->local_xyzw); result.root_positions=std::move(decoded->root_positions);
|
|
345
|
+
+ return result;
|
|
346
|
+
+#else
|
|
347
|
+
+ (void) utf8_prompt; (void) keys; (void) frames; (void) steps; (void) seed; (void) text_cfg; (void) constraint_cfg;
|
|
348
|
+
+ return std::unexpected("Kimodo was built without GGML support");
|
|
349
|
+
+#endif
|
|
350
|
+
+}
|
|
351
|
+
+
|
|
352
|
+
std::expected<motion_data, std::string> model::generate_text_sequence(
|
|
353
|
+
std::span<const prompt_segment> segments, unsigned transition_frames,
|
|
354
|
+
unsigned steps, std::uint64_t seed, float text_cfg, float constraint_cfg) const {
|
|
355
|
+
diff --git a/src/sequence.cpp b/src/sequence.cpp
|
|
356
|
+
index 6dbf6da..3ff5d8b 100644
|
|
357
|
+
--- a/src/sequence.cpp
|
|
358
|
+
+++ b/src/sequence.cpp
|
|
359
|
+
@@ -34,6 +34,39 @@ float condition_row(const float *raw, const skeleton_spec &s, float *value) {
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
+float pose_condition(const skeleton_spec &s, std::span<const float> axis_angle,
|
|
364
|
+
+ const float root[3], const float *smooth_root_2d, std::span<const unsigned> positions,
|
|
365
|
+
+ std::span<const unsigned> rotations, float *value, float *mask) {
|
|
366
|
+
+ const size_t J=s.joints(),rotation_begin=5+3*J;
|
|
367
|
+
+ std::vector<mat> global(J);
|
|
368
|
+
+ std::vector<std::array<float,3>> posed(J);
|
|
369
|
+
+ for(size_t j=0;j<J;++j){
|
|
370
|
+
+ const double x=axis_angle[j*3],y=axis_angle[j*3+1],z=axis_angle[j*3+2],angle=std::sqrt(x*x+y*y+z*z);
|
|
371
|
+
+ mat local{{1,0,0,0,1,0,0,0,1}};
|
|
372
|
+
+ if(angle>1e-12){const double c=std::cos(angle),si=std::sin(angle),t=1-c,a=x/angle,b=y/angle,d=z/angle;
|
|
373
|
+
+ local={{t*a*a+c,t*a*b-si*d,t*a*d+si*b,t*a*b+si*d,t*b*b+c,t*b*d-si*a,t*a*d-si*b,t*b*d+si*a,t*d*d+c}};}
|
|
374
|
+
+ const int parent=s.parents[j];
|
|
375
|
+
+ if(parent<0){global[j]=local;posed[j]={root[0],root[1],root[2]};continue;}
|
|
376
|
+
+ global[j]=mul(global[static_cast<size_t>(parent)],local);
|
|
377
|
+
+ float offset[3];rotate(global[static_cast<size_t>(parent)],s.offsets[j],offset);
|
|
378
|
+
+ for(int k=0;k<3;++k)posed[j][k]=posed[static_cast<size_t>(parent)][k]+offset[k];
|
|
379
|
+
+ }
|
|
380
|
+
+ const auto right=s.hips[0],left=s.hips[1];
|
|
381
|
+
+ const float angle=std::atan2(posed[right][2]-posed[left][2],-(posed[right][0]-posed[left][0]));
|
|
382
|
+
+ // Smooth root x/z default to the pelvis; y is the pelvis height. Only this
|
|
383
|
+
+ // key's features are written: another key on the same frame (the other
|
|
384
|
+
+ // hand) keeps its own. Positions stay global here; the caller subtracts
|
|
385
|
+
+ // the frame's final smooth root x/z (create_conditions after merging).
|
|
386
|
+
+ const float sx=smooth_root_2d?smooth_root_2d[0]:root[0],sz=smooth_root_2d?smooth_root_2d[1]:root[2];
|
|
387
|
+
+ value[0]=sx;value[1]=root[1];value[2]=sz;value[3]=std::cos(angle);value[4]=std::sin(angle);
|
|
388
|
+
+ std::fill(mask,mask+5,1.F);
|
|
389
|
+
+ auto position=[&](size_t j){value[5+j*3]=posed[j][0];value[6+j*3]=posed[j][1];value[7+j*3]=posed[j][2];std::fill(mask+5+j*3,mask+8+j*3,1.F);};
|
|
390
|
+
+ if(positions.empty())for(size_t j=0;j<J;++j)position(j);
|
|
391
|
+
+ for(unsigned j:positions)position(j);
|
|
392
|
+
+ for(unsigned j:rotations){for(int d=0;d<6;++d)value[rotation_begin+j*6+static_cast<size_t>(d)]=static_cast<float>(global[j].v[(d%3)*3+d/3]);std::fill(mask+rotation_begin+j*6,mask+rotation_begin+j*6+6,1.F);}
|
|
393
|
+
+ return angle;
|
|
394
|
+
+}
|
|
395
|
+
+
|
|
396
|
+
std::expected<sequence_transition, std::string> prepare_sequence_transition(
|
|
397
|
+
const ggml_motion_weights &weights, std::span<const float> previous,
|
|
398
|
+
std::size_t continuation_frames, unsigned transition_frames) {
|