Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

CH20b: the body's skin is graded to the head at the collar. raea clothes wear takes --head HEAD_DIR: the body it dresses takes the head's neck colour, and each vertex under the collar the colour the head's own skin has above it (head.json's ring colours, evened round the ring), easing into the neck colour 8 cm down, as vertex colours on body.glb (engine/cli/src/grade.ts, plain byte arrays so the native raea runs it). Measured on the first head: the step across the collar at the front from 8 levels of 255 to under 1, 1 to 4 round the rest.

shinyobjectz71b354007f6f
diff --git a/docs/character.feature b/docs/character.feature
index 79b85393..22ff19ac 100644
--- a/docs/character.feature
+++ b/docs/character.feature
@@ -405,6 +405,23 @@ Feature: The character SDK as one system: SOMA bodies, Kimodo motion, generated
# and the head's ears, which the face session is rebuilding.
Then a generated head is drawn on SOMA's body as a part, joined at the collar
+ @done
+ Scenario: CH20b. The body's skin is graded to the head at the collar
+ # 11-15. Measured first (sheet3d compositions/seam_check.tsx: the headless body at rest with the head as a
+ # part, lit evenly, seen close from the front, both sides and the back, the collar on the middle row): the
+ # body, built in the head's neck colour, stood 8 levels of 255 lighter than the head's skin across the
+ # collar at the front, 1 to 3 at the sides and back, and the line showed. `raea clothes wear ... --head
+ # HEAD_DIR` (engine/cli/src/grade.ts) now writes the join into the body it dresses: the skin takes the
+ # head's neck colour, and each vertex under the collar takes the colour the head's own skin has above it
+ # (head.json's ring colours, evened over five round the ring: one texel a vertex drew streaks), easing into
+ # the neck colour 8 cm down, as vertex colours on body.glb. The step at the front is under 1 level, 1 to 4
+ # round the rest. Left: the head's own strip above the collar repeats one texel a column (its ring takes
+ # its nearest rim vertex's place in the picture), the neck's outline stops flaring for 2 cm above the
+ # collar, and the body's skin has none of the head's fine detail.
+ Given a headless body and the head joined to its collar
+ Then the body dressed with that head named has its skin in the head's neck colour, graded to the head's
+ own skin at the collar, and no step of colour shows across the join
+
Scenario: CH21. Hair
# Agreed with the face session 11-15. sdk/body/src/cloth.ts already moves hair and clothes that follow
# skin. Hair cards are the face session's working choice, pending its tests; strand hair stays a reference
diff --git a/docs/manual/reference/cli/clothes.md b/docs/manual/reference/cli/clothes.md
index 8acbd623..f476c384 100644
--- a/docs/manual/reference/cli/clothes.md
+++ b/docs/manual/reference/cli/clothes.md
@@ -12,7 +12,7 @@ Clothes for SOMA's body from words: make has an image model (flux_2_pro, one pic
## Usage
```sh
-raea clothes [make NAME "WHAT IT IS, AS WORN" [--over UNDER[,UNDER...]] [--max-cents N] | remeasure NAME | cover NAME --parts PART[:SHARE],... --colour #RRGGBB [--stand MM] [--over UNDER] | wear OUT_DIR GARMENT... [--body DIR]] (clothes for SOMA's body from words: make has an image model (flux_2_pro, one picture a view, at most N cents each, 10 unless said) dress SOMA's grey mannequin from the front, back, left and right, then measures the pictures onto SOMA's own vertices as assets/clothes/NAME.json, its pictures in assets/clothes/NAME/; --over draws it over garments already made (innermost first), as the next layer, a garment made by procedure drawn on the mannequin first; remeasure measures a garment again from its kept pictures (after raea's measuring changed), nothing drawn or paid for; cover makes one by procedure in the same file, no picture: the skin of the parts named (hips, waist, torso, chest, neck, head, upperArm, foreArm, hand, thigh, shin, foot, toes; a limb's SHARE is how far along it from its top), in one colour, MM off the skin (6 unless said); wear puts garments on a body, innermost first (each GARMENT a name or its .json): OUT_DIR/NAME.glb each, with OUT_DIR/body.glb the body without the skin wholly under cloth; --body DIR another SOMA body folder (a headless one for a head part); alone, the project's garments. The first use fetches SOMA's body (NVlabs/SOMA-X, Apache-2.0) into raea's models folder and needs Blender: raea setup blender)
+raea clothes [make NAME "WHAT IT IS, AS WORN" [--over UNDER[,UNDER...]] [--max-cents N] | remeasure NAME | cover NAME --parts PART[:SHARE],... --colour #RRGGBB [--stand MM] [--over UNDER] | wear OUT_DIR GARMENT... [--body DIR] [--head HEAD_DIR]] (clothes for SOMA's body from words: make has an image model (flux_2_pro, one picture a view, at most N cents each, 10 unless said) dress SOMA's grey mannequin from the front, back, left and right, then measures the pictures onto SOMA's own vertices as assets/clothes/NAME.json, its pictures in assets/clothes/NAME/; --over draws it over garments already made (innermost first), as the next layer, a garment made by procedure drawn on the mannequin first; remeasure measures a garment again from its kept pictures (after raea's measuring changed), nothing drawn or paid for; cover makes one by procedure in the same file, no picture: the skin of the parts named (hips, waist, torso, chest, neck, head, upperArm, foreArm, hand, thigh, shin, foot, toes; a limb's SHARE is how far along it from its top), in one colour, MM off the skin (6 unless said); wear puts garments on a body, innermost first (each GARMENT a name or its .json): OUT_DIR/NAME.glb each, with OUT_DIR/body.glb the body without the skin wholly under cloth; --body DIR another SOMA body folder (a headless one for a head part); --head HEAD_DIR the head that joins it (head.json), whose skin the body's is graded to at the collar; alone, the project's garments. The first use fetches SOMA's body (NVlabs/SOMA-X, Apache-2.0) into raea's models folder and needs Blender: raea setup blender)
```
Headless: it needs nothing running and opens no window. Takes any number of arguments besides its flags.
@@ -23,6 +23,7 @@ Headless: it needs nothing running and opens no window. Takes any number of argu
| --- | --- | --- |
| `--body` | `DIR` | With `wear`: dress this SOMA body folder (body.glb, skeleton.json) instead of SOMA's own, such as a headless body that a generated head joins at the collar. |
| `--colour` | `#RRGGBB` | With `cover`: the garment's one colour. |
+| `--head` | `HEAD_DIR` | With `wear`: the head folder (head.json, head.glb) that joins a headless body at the collar. The body's skin takes the head's neck colour and is graded to the head's own skin just under the collar, so no step of colour shows at the join. |
| `--max-cents` | `N` | With `make`: the most one of the four pictures may cost, in cents (10 unless said). |
| `--over` | `UNDER` | With `make`: draw the garment over garments already made, innermost first, comma-separated, as the next layer. With `cover`: lay it over one garment, a layer's thickness off it. |
| `--parts` | `PART` | With `cover`: the body's parts the garment covers, comma-separated; a limb takes a share, how far along it from its top (`foreArm:0.5` is the half nearest the elbow). |
diff --git a/engine/cli/conformance/clothes.test.ts b/engine/cli/conformance/clothes.test.ts
index 0ca4e200..97b56d71 100644
--- a/engine/cli/conformance/clothes.test.ts
+++ b/engine/cli/conformance/clothes.test.ts
@@ -37,6 +37,7 @@ describe("raea clothes", () => {
test("wear sends the folder, the garments innermost first and the body", () => {
const { ops } = run(["wear", "assets/characters/dressed", "tee-jeans", "bomber", "--body", "assets/characters/soma-headless"]);
expect(ops).toEqual([{ op: "wear", out: "assets/characters/dressed", garments: ["tee-jeans", "bomber"], body: "assets/characters/soma-headless" }]);
+ expect(run(["wear", "out", "tee", "--body", "headless", "--head", "assets/characters/heads/real"]).ops[0]).toMatchObject({ body: "headless", head: "assets/characters/heads/real" });
});
test("what doesn't fit is said before anything is drawn", () => {
diff --git a/engine/cli/conformance/grade.test.ts b/engine/cli/conformance/grade.test.ts
new file mode 100644
index 00000000..ac5bdfd6
--- /dev/null
+++ b/engine/cli/conformance/grade.test.ts
@@ -0,0 +1,38 @@
+// A headless body's skin graded to its head at the collar (engine/cli/src/grade.ts, docs/character.feature CH20b): a
+// vertex at the collar takes the ring's colour above it, one a fade's length down keeps the neck colour.
+import { expect, test } from "bun:test";
+import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { gradeToHead } from "../src/grade";
+
+test("a body's skin takes the head's colours at the collar and its neck colour below", () => {
+ const dir = mkdtempSync(join(tmpdir(), "grade-"));
+ // three vertices: at the collar in front, at the collar behind, and 10 cm under the collar in front
+ const pos = Buffer.alloc(36);
+ [[0, 1.5, 0.05], [0, 1.5, -0.05], [0, 1.4, 0.05]].flat().forEach((v, i) => pos.writeFloatLE(v, i * 4));
+ const gltf = { asset: { version: "2.0" }, buffers: [{ byteLength: 36 }], bufferViews: [{ buffer: 0, byteOffset: 0, byteLength: 36 }],
+ accessors: [{ bufferView: 0, componentType: 5126, count: 3, type: "VEC3" }], materials: [{ name: "skin", pbrMetallicRoughness: { baseColorFactor: [1, 1, 1, 1] } }],
+ meshes: [{ primitives: [{ attributes: { POSITION: 0 }, material: 0 }] }] };
+ let json = Buffer.from(JSON.stringify(gltf));
+ json = Buffer.concat([json, Buffer.alloc((4 - (json.length % 4)) % 4, 0x20)]);
+ const h = Buffer.alloc(20), bh = Buffer.alloc(8);
+ h.write("glTF", 0, "latin1"); h.writeUInt32LE(2, 4); h.writeUInt32LE(28 + json.length + 36, 8); h.writeUInt32LE(json.length, 12); h.write("JSON", 16, "latin1");
+ bh.writeUInt32LE(36, 0); bh.write("BIN\0", 4, "latin1");
+ writeFileSync(join(dir, "body.glb"), Buffer.concat([h, json, bh, pos]));
+ // a ring of eight: the front half one colour, the back half another; the neck colour between
+ const ring = Array.from({ length: 8 }, (_, k) => [0.05 * Math.sin((k / 8) * 2 * Math.PI), 1.5, 0.05 * Math.cos((k / 8) * 2 * Math.PI)]);
+ const front = (k: number) => Math.cos((k / 8) * 2 * Math.PI) > 0.5, back = (k: number) => Math.cos((k / 8) * 2 * Math.PI) < -0.5;
+ writeFileSync(join(dir, "head.json"), JSON.stringify({ neck_colour_srgb: [0.5, 0.5, 0.5], collar_ring: { positions: ring },
+ collar: { ring_colours_srgb: ring.map((_, k) => (front(k) ? [0.6, 0.5, 0.5] : back(k) ? [0.4, 0.5, 0.5] : [0.5, 0.5, 0.5])) } }));
+ expect(gradeToHead(join(dir, "body.glb"), join(dir, "head.json"))).toContain("3 vertices");
+ const b = readFileSync(join(dir, "body.glb")), n = b.readUInt32LE(12), g = JSON.parse(b.subarray(20, 20 + n).toString("utf8"));
+ const bin = b.subarray(28 + n), a = g.accessors[g.meshes[0].primitives[0].attributes.COLOR_0], at = g.bufferViews[a.bufferView].byteOffset;
+ const red = (i: number) => bin.readFloatLE(at + i * 16);
+ expect(a.type).toBe("VEC4");
+ expect(red(0)).toBeGreaterThan(1.1); // the front of the collar: redder than the neck colour
+ expect(red(1)).toBeLessThan(0.9); // the back: less red
+ expect(red(2)).toBeCloseTo(1, 5); // a fade's length down: the neck colour itself
+ expect(g.materials[0].pbrMetallicRoughness.baseColorFactor[0]).toBeCloseTo(0.5 ** 2.2, 5);
+ expect(() => gradeToHead(join(dir, "body.glb"), join(dir, "body.glb"))).toThrow();
+});
diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs
index 9af1e515..4ffb3348 100644
--- a/engine/cli/src/cli.rs
+++ b/engine/cli/src/cli.rs
@@ -135,7 +135,7 @@ pub fn run(args: &[String]) -> R<String> {
let usage = format!("{usage}\n raea library [new NAME [--cloud] | add LIBRARY PATH | files LIBRARY | tag SHA TAGS | status | scan ...] | raea library search \"WORDS\" [--library LIBRARY] [--kind KIND] [--limit N] [--sound] (the person's libraries in the raea app: folders and drives indexed on this machine, searched by meaning; a folder an agent adds waits for the person's yes)");
let usage = format!("{usage}\n raea show FILE... [--title T] [--ask LINE] [--project P] [--replaces ITEM] [--as NAME] [--role ROLE] [--inbox NAME] [--open] | raea show --question Q --choice A --choice B [STILL...] | raea show [--title T] --question Q [--preview FILE] --choice A [--preview FILE] --choice B ... [--question Q2] ... | raea show --on ITEM [--working ID] [--ask TEXT] [--status S] [--states S1,S2] [--sign N --clip FILE --render HASH] [--done ID] [--note LINE] [--sub NAME] (shown in the raea app as an item the person can use and answer, posted quietly with a notice, the window left where they are unless --open: stills (several, a storyboard), a video, a sound, a NAME.script.ts or .md, a .tsx (an interactive artifact; a project's composition opens in its editor), or questions, all of them one item, each question and choice with a --preview to play or read while answering (a still, a video, a sound, a script or .md; after a --choice that choice's, else the question's); what they send comes to ~/.raea/inbox/INBOX.jsonl; their edit comments are tasks: --working ID as you start one (each --ask with it one ask you read it as, for the person to correct; --status and --states where the note and each ask stand: to restate, to check, failing, to sign, passing, signed; --sign N --clip FILE --render HASH a clip under ask N for them to sign; a note closes when they retire it, never with --done), --done ID when it's settled, or with the version that settles it, FILE --replaces ITEM --done ID; never open media in Preview while the app is installed)");
// clothes for SOMA's body from words (docs/character.feature CH45): engine/cli/src/clothes.ts and wardrobe.ts
- let usage = format!("{usage}\n raea clothes [make NAME \"WHAT IT IS, AS WORN\" [--over UNDER[,UNDER...]] [--max-cents N] | remeasure NAME | cover NAME --parts PART[:SHARE],... --colour #RRGGBB [--stand MM] [--over UNDER] | wear OUT_DIR GARMENT... [--body DIR]] (clothes for SOMA's body from words: make has an image model (flux_2_pro, one picture a view, at most N cents each, 10 unless said) dress SOMA's grey mannequin from the front, back, left and right, then measures the pictures onto SOMA's own vertices as assets/clothes/NAME.json, its pictures in assets/clothes/NAME/; --over draws it over garments already made (innermost first), as the next layer, a garment made by procedure drawn on the mannequin first; remeasure measures a garment again from its kept pictures (after raea's measuring changed), nothing drawn or paid for; cover makes one by procedure in the same file, no picture: the skin of the parts named (hips, waist, torso, chest, neck, head, upperArm, foreArm, hand, thigh, shin, foot, toes; a limb's SHARE is how far along it from its top), in one colour, MM off the skin (6 unless said); wear puts garments on a body, innermost first (each GARMENT a name or its .json): OUT_DIR/NAME.glb each, with OUT_DIR/body.glb the body without the skin wholly under cloth; --body DIR another SOMA body folder (a headless one for a head part); alone, the project's garments. The first use fetches SOMA's body (NVlabs/SOMA-X, Apache-2.0) into raea's models folder and needs Blender: raea setup blender)");
+ let usage = format!("{usage}\n raea clothes [make NAME \"WHAT IT IS, AS WORN\" [--over UNDER[,UNDER...]] [--max-cents N] | remeasure NAME | cover NAME --parts PART[:SHARE],... --colour #RRGGBB [--stand MM] [--over UNDER] | wear OUT_DIR GARMENT... [--body DIR] [--head HEAD_DIR]] (clothes for SOMA's body from words: make has an image model (flux_2_pro, one picture a view, at most N cents each, 10 unless said) dress SOMA's grey mannequin from the front, back, left and right, then measures the pictures onto SOMA's own vertices as assets/clothes/NAME.json, its pictures in assets/clothes/NAME/; --over draws it over garments already made (innermost first), as the next layer, a garment made by procedure drawn on the mannequin first; remeasure measures a garment again from its kept pictures (after raea's measuring changed), nothing drawn or paid for; cover makes one by procedure in the same file, no picture: the skin of the parts named (hips, waist, torso, chest, neck, head, upperArm, foreArm, hand, thigh, shin, foot, toes; a limb's SHARE is how far along it from its top), in one colour, MM off the skin (6 unless said); wear puts garments on a body, innermost first (each GARMENT a name or its .json): OUT_DIR/NAME.glb each, with OUT_DIR/body.glb the body without the skin wholly under cloth; --body DIR another SOMA body folder (a headless one for a head part); --head HEAD_DIR the head that joins it (head.json), whose skin the body's is graded to at the collar; alone, the project's garments. The first use fetches SOMA's body (NVlabs/SOMA-X, Apache-2.0) into raea's models folder and needs Blender: raea setup blender)");
// a workspace's files and specs (docs/projects.feature), listed under render's usage like library
let usage = format!("{usage}\n raea spec FILE.ts [--as brief|script|taste|plan|controller] (a spec's default export as JSON, checked against its schema: brief.ts, script.ts, taste.ts, plan.ts, controllers/ID.ts)\n raea workspace init [NAME] [--layout LAYOUT] | raea workspace adopt DIR [--name NAME] | raea workspace [--json] (a workspace: a git repo of projects and controllers under raea.root, ~/Documents/raea unless git config says)\n raea project new NAME [--storage inline|submodule] | raea project split NAME [--remote URL] | raea project join NAME | raea project [--json] (a project in the workspace: its folder, brief.ts, media/, out/; split and join keep its history)\n raea controller ls [--json] | raea controller get PATH [--json] | raea controller set PATH VALUE [--project] [--by NAME] | raea controller write FILE.ts [--by NAME] | raea controller rm ID [--by NAME] (the workspace's controllers, controllers/ID.ts; PATH is controller.group.field; every change a commit)\n raea check EDIT.tsx --quick [--shape S] [--platform P] [--taste T] [-o check.json] (three stills of a composition checked for text: clipped, cramped, safe areas, sizes; about a second)\n raea hook [claude|codex|gemini|kimi] (every agent's tool hooks, which raea skills install adds: before a shell command, media opened in the Mac's viewer while the raea app is installed is stopped once for raea show (the same command again goes through); after a save, the quick check on a composition)\n raea next [DIR] (the two or three useful next steps for the project, from its brief, compositions, renders and checks)\n raea doctor [--fix] [DIR] (what doesn't match this raea: old brief files, an older workspace format, an agent's skill from another version)\n raea app run|check|bundle APP.tsx [--target web|native] [--size WxH] [--script steps.json] [--png DIR] [-o App.app] (a TSX app on @raea/ui: its window, the headless check, a Mac app; web is Blitz on Bevy, native is Rune; the app's `export const app` sets the target, web when it doesn't; raea rune ... is --target native)\n {}\n {}\n {}\n {}\n {}", skill::USAGE, tools::blender::USAGE, raea_app_engines::godot::USAGE, raea_app_engines::shot::USAGE, raea_app_engines::round::USAGE);
let (export_game, capcut, scene, physics, splat) = (raea_app_game::USAGE, raea_app_capcut::USAGE, export::SCENE_USAGE, motion::physics::USAGE, tools::splat::USAGE);
diff --git a/engine/cli/src/clothes.ts b/engine/cli/src/clothes.ts
index 1e58ffdd..24227a30 100644
--- a/engine/cli/src/clothes.ts
+++ b/engine/cli/src/clothes.ts
@@ -12,7 +12,7 @@ export const CLOTHES_USAGE = `raea clothes (the project's garments: assets/clo
raea clothes make NAME "WHAT IT IS, AS WORN" [--over UNDER[,UNDER...]] [--max-cents N] (drawn over the garments named; N: the most one picture may cost, 10 unless said)
raea clothes remeasure NAME (measured again from its kept pictures, after raea's measuring changed: nothing drawn or paid for)
raea clothes cover NAME --parts PART[:SHARE],... --colour #RRGGBB [--stand MM] [--over UNDER] (by procedure, no picture: ${PARTS.join(", ")}; a limb's share is how far along it from its top, foreArm:0.5)
-raea clothes wear OUT_DIR GARMENT... [--body DIR] (GARMENT: a garment's name or its .json, innermost first; DIR: a SOMA body folder, SOMA's own unless said)
+raea clothes wear OUT_DIR GARMENT... [--body DIR] [--head HEAD_DIR] (GARMENT: a garment's name or its .json, innermost first; DIR: a SOMA body folder, SOMA's own unless said; HEAD_DIR: the head that joins a headless body, whose skin the body's is graded to at the collar)
`;
const flagOf = (args: string[], name: string) => {
@@ -65,8 +65,8 @@ export function clothesVerb(ask: Ask, args: string[]): string {
}
case "wear": {
const [out, ...garments] = plain(rest);
- if (!out || !garments.length) throw new Error(`raea clothes wear OUT_DIR GARMENT... [--body DIR]\n${CLOTHES_USAGE}`);
- return q("wear", { out, garments, body: flagOf(rest, "--body") }).said;
+ if (!out || !garments.length) throw new Error(`raea clothes wear OUT_DIR GARMENT... [--body DIR] [--head HEAD_DIR]\n${CLOTHES_USAGE}`);
+ return q("wear", { out, garments, body: flagOf(rest, "--body"), head: flagOf(rest, "--head") }).said;
}
default:
throw new Error(CLOTHES_USAGE);
diff --git a/engine/cli/src/grade.ts b/engine/cli/src/grade.ts
new file mode 100644
index 00000000..ca18e332
--- /dev/null
+++ b/engine/cli/src/grade.ts
@@ -0,0 +1,76 @@
+// A headless body's skin graded to the head that joins it (docs/character.feature CH20): the body's skin takes the
+// head's neck colour, and just under the collar each vertex takes the colour the head's own skin has above it there
+// (head.json's collar.ring_colours_srgb, one for each vertex of the ring, evened round the ring), easing into the
+// neck colour over `fade` metres down. The colours are written into body.glb as vertex colours (COLOR_0, which
+// multiplies the material's colour), so the body needs no picture and the join needs no weld. Measured on the first
+// head (compositions/seam_check.tsx in the sheet3d project): the step across the collar at the front went from 8
+// levels of 255 to under 1.
+import { readFileSync, writeFileSync } from "node:fs";
+
+type Vec3 = [number, number, number];
+interface HeadJson { neck_colour_srgb?: number[]; collar_ring?: { positions?: Vec3[] }; collar?: { ring_colours_srgb?: number[][] } }
+interface Gltf {
+ accessors: { bufferView: number; byteOffset?: number; componentType: number; count: number; type: string }[];
+ bufferViews: { buffer: number; byteOffset?: number; byteLength: number; byteStride?: number; target?: number }[];
+ buffers: { byteLength: number }[];
+ materials?: { name?: string; pbrMetallicRoughness?: { baseColorFactor?: number[] } }[];
+ meshes: { primitives: { attributes: Record<string, number>; material?: number }[] }[];
+}
+
+const linear = (c: number[]): Vec3 => [c[0] ** 2.2, c[1] ** 2.2, c[2] ** 2.2];
+const near = (a: number, b: number) => Math.abs(((a - b + 3 * Math.PI) % (2 * Math.PI)) - Math.PI);
+
+/** body.glb at `glb` graded to the head whose head.json is at `head`, in place; what was done, in a line */
+export function gradeToHead(glb: string, head: string, fade = 0.08): string {
+ const h = JSON.parse(readFileSync(head, "utf8")) as HeadJson;
+ const ring = h.collar_ring?.positions, cols = h.collar?.ring_colours_srgb, tone = h.neck_colour_srgb;
+ if (!ring?.length || !cols || cols.length !== ring.length || !tone) throw new Error(`${head}: no collar ring with its colours and no neck colour: the head was not joined to a body's collar`);
+ // (bytes read through a DataView: the native raea's readFileSync gives a plain Uint8Array, not Node's Buffer)
+ const b = new Uint8Array(readFileSync(glb)), dv = new DataView(b.buffer, b.byteOffset, b.byteLength), n = dv.getUint32(12, true);
+ const g = JSON.parse(new TextDecoder().decode(b.subarray(20, 20 + n))) as Gltf;
+ const at0 = 20 + n + 8, len0 = dv.getUint32(20 + n, true), f32 = (o: number) => dv.getFloat32(at0 + o, true);
+ const mid = ring.reduce((s, p) => [s[0] + p[0] / ring.length, s[1] + p[1] / ring.length, s[2] + p[2] / ring.length], [0, 0, 0]);
+ // the ring's colours by their angle round the neck, each the mean of itself and two neighbours on each side (one
+ // texel's colour a vertex, carried down the neck, drew streaks)
+ const lin = cols.map(linear), k = ring.length;
+ const even = lin.map((_, i) => [0, 1, 2].map((c) => [-2, -1, 0, 1, 2].reduce((s, d) => s + lin[(i + d + k) % k][c], 0) / 5) as Vec3);
+ const angle = ring.map((p) => Math.atan2(p[0] - mid[0], p[2] - mid[2]));
+ const t = linear(tone);
+ const added: Uint8Array[] = [];
+ let at = len0 + ((4 - (len0 % 4)) % 4), graded = 0;
+ for (const mesh of g.meshes) for (const p of mesh.primitives) {
+ if (g.materials?.[p.material ?? -1]?.name !== "skin" || p.attributes.POSITION === undefined) continue;
+ const a = g.accessors[p.attributes.POSITION], v = g.bufferViews[a.bufferView], from = (v.byteOffset ?? 0) + (a.byteOffset ?? 0), step = v.byteStride ?? 12;
+ const out = new Float32Array(a.count * 4);
+ for (let i = 0; i < a.count; i++) {
+ const x = f32(from + i * step), y = f32(from + i * step + 4), z = f32(from + i * step + 8);
+ const u = Math.min(1, Math.max(0, mid[1] - y) / fade), w = u * u * (3 - 2 * u), ang = Math.atan2(x - mid[0], z - mid[2]);
+ let best = 0;
+ for (let r = 1; r < k; r++) if (near(angle[r], ang) < near(angle[best], ang)) best = r;
+ for (let c = 0; c < 3; c++) out[i * 4 + c] = (even[best][c] * (1 - w) + t[c] * w) / t[c];
+ out[i * 4 + 3] = 1;
+ }
+ g.bufferViews.push({ buffer: 0, byteOffset: at, byteLength: out.byteLength, target: 34962 });
+ g.accessors.push({ bufferView: g.bufferViews.length - 1, componentType: 5126, count: a.count, type: "VEC4" });
+ p.attributes.COLOR_0 = g.accessors.length - 1;
+ const m = g.materials![p.material!];
+ m.pbrMetallicRoughness = { ...m.pbrMetallicRoughness, baseColorFactor: [...t, 1] };
+ added.push(new Uint8Array(out.buffer));
+ at += out.byteLength;
+ graded += a.count;
+ }
+ if (!graded) throw new Error(`${glb}: no mesh with a material named "skin" to grade`);
+ g.buffers[0].byteLength = at;
+ const text = new TextEncoder().encode(JSON.stringify(g)), jlen = text.length + ((4 - (text.length % 4)) % 4);
+ // the file again: its header, the JSON padded with spaces to four bytes, the buffer with the colours after it
+ const file = new Uint8Array(12 + 8 + jlen + 8 + at), w = new DataView(file.buffer);
+ const tag = (o: number, t4: string) => [...t4].forEach((ch, i) => (file[o + i] = ch.charCodeAt(0)));
+ tag(0, "glTF"); w.setUint32(4, 2, true); w.setUint32(8, file.length, true);
+ w.setUint32(12, jlen, true); tag(16, "JSON"); file.fill(0x20, 20, 20 + jlen); file.set(text, 20);
+ w.setUint32(20 + jlen, at, true); tag(24 + jlen, "BIN\0");
+ file.set(b.subarray(at0, at0 + len0), 28 + jlen);
+ let o = 28 + jlen + len0 + ((4 - (len0 % 4)) % 4);
+ for (const c of added) { file.set(c, o); o += c.length; }
+ writeFileSync(glb, file);
+ return `the skin graded to the head at the collar: ${graded} vertices, the neck colour ${tone.map((c) => c.toFixed(3)).join(", ")}, eased over ${Math.round(fade * 100)} cm`;
+}
diff --git a/engine/cli/src/wardrobe.ts b/engine/cli/src/wardrobe.ts
index 02e9415f..e35cbed4 100644
--- a/engine/cli/src/wardrobe.ts
+++ b/engine/cli/src/wardrobe.ts
@@ -8,6 +8,7 @@ import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { basename, dirname, isAbsolute, join, relative } from "node:path";
+import { gradeToHead } from "./grade";
type Env = Record<string, string | undefined>;
type Said = { said: string };
@@ -185,7 +186,7 @@ function cover(raea: string, cwd: string, env: Env, a: { name: string; parts: st
return { said: [...s.made, ...said, `${relative(cwd, file)}. raea clothes wear assets/characters/NAME ${a.over ? `${a.over} ` : ""}${a.name} puts it on SOMA's body.`].join("\n") + "\n" };
}
-function wear(raea: string, cwd: string, env: Env, a: { out: string; garments: string[]; body?: string }): Said {
+function wear(raea: string, cwd: string, env: Env, a: { out: string; garments: string[]; body?: string; head?: string }): Said {
const at = (p: string) => (isAbsolute(p) ? p : join(cwd, p));
const files = a.garments.map((g) => (g.endsWith(".json") ? at(g) : join(cwd, "assets/clothes", `${g}.json`)));
for (const f of files) if (!existsSync(f)) throw new Error(`no garment ${relative(cwd, f)}: raea clothes lists the ones made`);
@@ -198,6 +199,12 @@ function wear(raea: string, cwd: string, env: Env, a: { out: string; garments: s
const said = blender(raea, env, "garment.py", ["wear", join(body, "body.glb"), s.rig, out, ...files]);
// the dressed body is a body folder of its own: its skeleton, its joints' stand-in and a headless body's collar
for (const f of ["skeleton.json", "joint.glb", "collar.json"]) if (existsSync(join(body, f))) copyFileSync(join(body, f), join(out, f));
+ // a head that joins the body at the collar: the body's skin graded to the head's (grade.ts)
+ if (a.head) {
+ const json = join(at(a.head), "head.json");
+ if (!existsSync(json)) throw new Error(`${a.head}: not a head folder (no head.json)`);
+ said.push(gradeToHead(join(out, "body.glb"), json));
+ }
const served = relative(join(cwd, "assets"), out);
const use = served.startsWith("..")
? ""