rig-parts 1.71.0 → 1.71.1
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/docs/AUTHORING.md +4 -2
- package/package.json +1 -1
- package/src/assemble.ts +62 -8
- package/src/build.ts +1 -0
- package/src/config.ts +425 -18
- package/src/rig.ts +223 -32
- package/src/turn.ts +35 -5
package/docs/AUTHORING.md
CHANGED
|
@@ -136,7 +136,7 @@ read by no CPU stage).
|
|
|
136
136
|
| `motion.animations_from` | rig; check (named; read for folds) | optional, never proposed (issue #183): a path, relative to the config file's directory, to a file in rig-c's motion-spec shape, `{"spec": "rigc-motion/1", "animations": {"<name>": {"duration": …, "tracks": [...]}, …}}` — an expression, a gesture, anything beside the idle. On every `rig` and `build` each of its animations is written into `rig/motion.json` after `idle`, as read: nothing added, re-keyed or judged here (except `derive` keys on `turn`/`tilt`, issue #436, and `{"t": …, "set": "<name>" \| null}` keys on slot `"attachment"` tracks, issue #473, which expand to `"v": "<set>_<slot>"` or `"v": null` when the set hides the slot, or `"v": "<slot>"` for `null`, refused with `CONFIG_SET_COVERS_SLOT` when the set is undeclared or does not cover the track's slot), and each is rigc's to accept or refuse at the rig stage's gate, in rigc's words. It may name what `motion.json` already holds — the bones `bones` declares, the easings `shut` and `open`, the groups `eyes` and `brows` when the blink writes them — and nothing else from the file reaches it. The loader refuses, every problem at once: no such file or one that cannot be read (`CONFIG_FILE_PRESENT`), text that is not JSON (`CONFIG_IS_JSON`), a file that is not an object, a `spec` other than `"rigc-motion/1"`, an `animations` that is not a table of objects (`CONFIG_FIELD_TYPE`), any other key — rig-c's `easings`, `groups`, `setup`, `physics`, `mix`, `archetype` and `cut` included, which would be read and not written (`CONFIG_KEY_KNOWN`), an animation named `idle` (`CONFIG_ANIMATION_NAME_FREE`), and a key written twice in one object of the file, which JSON would fold into its last value without a word (`CONFIG_KEY_UNIQUE`). `check` names the others on one line (`beside the idle: …`) and reads each for folds, with the idle — `ANIMATIONS_DO_NOT_FOLD` (§7, issues #320, #333); every other bar reads the idle. Absent, `motion.json` holds the idle alone, byte for byte as before, and `check` reads that idle for folds |
|
|
137
137
|
| `constraints` | rig (handed to rig-c as `rig.json`'s `constraints`); `compare` and the coverage lines (roles) | **authored**, optional; `propose` writes none, but with `--cloth` (issue #364), where it writes the recipe's physics and swing transforms (*Recipe: cloth and hair that answer the world*, below). A list of constraints in **rig-c's own rig-spec shape** (`RigConstraint`: `ik`, `transform`, `path`, `physics`, `slider` — rig-c's `src/rig.ts` documents every field), in the order rigc applies them. The loader checks only what this package owns: each entry is an object with a `type` rigc names (`CONFIG_CONSTRAINT_TYPE_KNOWN`) and a non-empty `name`, unique within its kind as rigc finds constraints (`CONFIG_CONSTRAINT_NAME_UNIQUE`; an ik and a transform may share one); every bone it names — `bones`, an ik's `target`, a transform's `source`, a physics or slider constraint's `bone` — is a bone `bones` declares, a chain link as `<chain><i>` (`CONFIG_NAME_RESOLVES`); the bone a constraint follows does not sit under a bone it drives (`CONFIG_CONSTRAINT_TARGET_DETACHED`). Every other field (`mix`, `softness`, `properties`, a path's `slot`, a slider's `animation`) and every value is rigc's to accept or refuse at the rig stage's gate, in rigc's words (`RIG_RIGC_GREEN`) — an ik's `bones` as a shape too: from rig-c 2.15.0 rigc refuses an ik over more than two bones, or over a pair whose second bone is not the first's child (issue #103; this loader refused both itself until then). A note and an `x-` record may ride on an entry; the rig stage leaves them out of what it hands rigc. Under the default `--idle-keys ctl` a two-bone ik whose child link the idle keys is split by that link's control, and rigc refuses the pair: run `rig --idle-keys direct` or `build --idle-keys direct` (the rig stage adds that sentence, naming the flag on the command that ran, to rigc's line; `build` forwards it to its rig stage, issue #95). Each bone a constraint follows is declared to rigc as `invariants.detached` from every bone it drives, which rigc's gate rule `A25` checks |
|
|
138
138
|
| `stops` | rig (handed to rig-c as `rig.json`'s `stops`, and moves slots, mesh weights and child bones on stopped links onto `<link>_d`); `propose --from-config` (`LINT stop on <chain> …`) | **authored**, optional (issues #404, #447): `[{chain, links?, against, at, inward, outward, lower?: {inward, outward}}]` — rig-c's leg stops (`RigStop`, rig-c 2.56.0, `rig-c/src/stop.ts`). `chain` is a chain `bones` declares (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `links`, optional, is a non-empty list of links of that chain (`CONFIG_NAME_RESOLVES`, `CONFIG_FIELD_TYPE`), or absent for every link of `chain` in chain order; `against` is a bone `bones` declares, a chain link as `<chain><i>` (`CONFIG_NAME_RESOLVES`, `RIG_NAME_RESOLVES`); `at` is `[x, y]` in `against`'s local space, as rig-c's stop takes it (`CONFIG_FIELD_TYPE`): since each chain link (`leg_r0`, `leg_r1`) is turned to point along its segment (`+x` from origin to next link or tip, `+y` 90° counter-clockwise in Spine world), `at: [d, n]` sits `d` px from `against`'s origin toward its end and `n` px perpendicular to it; `inward`, `outward` and `lower.inward`, `lower.outward` are finite numbers (`CONFIG_FIELD_TYPE`). Every other stop rule — non-negative bounds, each stopped link written by a constraint, `against` not under the stopped chain, the aim not degenerate, `\|rest\| + outward <= 180°` (`RIG_STOP_BOUNDS`) — is rigc's to accept or refuse at the rig stage's gate, in rigc's words (`RIG_RIGC_GREEN`). **Rising-limb / prone geometry (issue #447):** rig-c's `expandStops` aims `<chain>_rest` from `links[0]`'s setup origin at `<chain>_touch` (`at` in `against`'s local frame) and clamps `<link>_d` inside `[rest − inward, rest + outward]`; Spine wraps rotation at `±180°`, so `\|rest\| + outward <= 180°` is required (`RIG_STOP_BOUNDS`). Whenever `<chain>_touch` lies **above** `links[0]`'s root in rig pixels (`ty < y0`, i.e. higher Spine `y` — e.g. stopping a hanging cloth chain against a rising shin `leg_<s1>` in a prone or kneeling pose where the knee sits below `links[0]` and the ankle above it, so positive `at[0]` walks upward along the shin past `links[0]`'s root), `rest` lands in the upper half-plane (`\|rest\| > 90°`) and `\|rest\| + outward` exceeds `180°`. Stop against the descending thigh (`leg_<s0>`), set `links` to start at a link whose root sits above `<chain>_touch`, or omit the stop when the rising shin sits outside the hanging chain's sweep; `propose --from-config` prints `LINT stop on <chain> …` with the exact coordinates and angles when `<chain>_touch` lies above `links[0]`'s root or `\|rest\| + outward > 180°`. For every stopped link `<link>`, the rig stage moves any slot on `<link>`, any mesh weight on `<link>`, and any bone whose parent is `<link>` (a branched cloth tree's branches hanging from `<trunk_last>`, before `--idle-keys ctl` adds `<bone>_ctl` and before `turn` adds `turn_<part>_<bone>`) onto `<link>_d`, the drawn link bone rig-c's `expandStops` creates at `<link>`'s setup frame to carry the clamped rotation. Absent, `rig.json` carries no `stops` and no byte of any output moves |
|
|
139
|
-
| `turn` | rig (adds the turn control or 2.5D head-turn producer) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected, or **authored** for 2.5D depth-sampled head turns (issue #763): `{pivot?, depths?, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}, roles?, counter?, grid?, unitDepths?, body?}`. When `roles` is declared (`{<part>: "surface" \| "unit" \| "rear"}`, issue #763; `CONFIG_TURN_ROLE_UNKNOWN`, `CONFIG_TURN_SURFACE_REQUIRED`, `CONFIG_TURN_SURFACE_REGION`), the rig stage runs the 2.5D depth-sampled head-turn producer: it edge-extends each turn-bound part's depth sheet across its transparent border and semi-transparent fringe from the nearest fully opaque (`alpha === 255`) texel before `PAD = 4` clamping (`padTurnDepthSheet`, `DEPTH_SILHOUETTE_SIZE_MISMATCH`), promotes `"surface"` regions to `generator: {kind: "grid", cols, rows, depth}` (`grid`: `[cols, rows]` or `{<part>: [cols, rows]}`, default `[13, 16]`, bounded at `<= 2,400` triangles per slot and `<= 4,000` total, `RIG_TURN_GRID_BUDGET`, `RIG_TURN_SURFACE_DEPTH_REQUIRED`, `RIG_TURN_SHARED_DEPTH_SCALE`), emits `faceshift` and `rear_shift` under `head` (`CONFIG_TURN_HEAD_BONE`, `RIG_TURN_HEAD_BONE`), `<part>_surface` under `faceshift`, and `yaw_dial` and `pitch_dial` under `root` (`CONFIG_TURN_BONE_FREE`, `RIG_TURN_NAME_FREE`), re-parents `"unit"` and `"rear"` bones and mesh weights to `faceshift` and `rear_shift`, samples each `"unit"` bone's depth from the `"surface"` depth sheet at its rest position (or reads `unitDepths.<part>`, `RIG_TURN_UNIT_DEPTH_REQUIRED`), enforces ear occlusion (`ear_r`/`ear_l` drawn before `"surface"` in `assemble.plan`, `CONFIG_TURN_EAR_DRAW_ORDER`, and behind the cheek surface, `RIG_TURN_EAR_DEPTH_BEHIND_CHEEK`), and writes `turn` and `tilt` `derive` tracks (`pivot` default `55` rig px, `counter` default `0.1` in `[0, 1]`, `CONFIG_TURN_COUNTER_RANGE`). `depths` holds, per part, the See-through layer's `depth_median` the part came from (larger = further back), read from the run the part was assembled from; a `painting:` patch has none and is not carried. A rider (issue #271) — a part from an `eyewhite`, `irides`, `eyelash`, `eyebrow`, `nose` or `mouth` layer — is drafted at the `face` part's depth, 0.001 nearer when parts.json draws it after the face and 0.001 further when before: See-through makes no depth of its own for the eye group (it cuts them from one depth map of the combined eyes) and clamps nose and mouth to the face's median − 0.001, and the two runs' own medians for these layers disagreed by up to 0.47 and swapped their order against the face. Every other layer — ears, headwear and earwear included — keeps its own median, unless it rides another part's bone. With no `face` part, or more than one, the riders keep their own and a note says so. A rider by bone (issue #535) — a part every *ownable* bone of which (a chain link, or a bone no other bone hangs from; `head`, `chest` and any bone with a child are shared and never count on their own) is *hosted* by another carried part, the host of a bone being the carried part that binds it (its region's bone; a mesh's `segments`, `contour` and `auto` regions' bones) with the most `opaque_px`, the earlier in parts.json on a tie, and which hosts no bone itself — is drafted at its host's depth, 0.001 nearer when drawn after the host and 0.001 further when before, and a note names the host, the bones and its own median: a pin, clip or ornament on the back hair's links travels with the back hair, not with its own layer's depth. `propose` reads the proposal's own `bones`, `meshes` and `regions`; the face riders are read by their tag first and never by their bones. A part bound to two hosts' bones rides neither and a note says so. In the rig stage, an authored depth on a rider by bone whose fraction differs from its host's by more than 0.1 of the dial (`TURN_RIDER_APART`, a share of `pivot − nearest`) is refused (`CONFIG_TURN_RIDER_DEPTH`); the host is read off `parts.json`'s `opaque_px`, so the config loader cannot see it. One note lists each part's depth and where it came from; a carrier the other run places more than 10 % of `pivot − nearest` away gets a note naming both values and the run read — the two runs are not reconciled. `pivot` is the depth that stays put; `propose` drafts the mean of the parts' depths weighted by `opaque_px`, the one depth at which the painted pixels' centroid does not slide under the dial. The rig stage adds a bone `turn` under `root` at its origin that nothing keys — its local x is the dial, in rig px — and carries each part by `(pivot − depth) / (pivot − nearest depth)` of it: the nearest part all of it, a part behind the pivot the other way, a part at the pivot not at all. Each part rides leaf twins (`turn_<part>_<bone>`, an identity child of every bone its slot and weights bind) moved by one `transform` constraint (`turn_<part>`, after the config's own); the idle's keys, the `<bone>_ctl` controls and a physics constraint stay on the bones, and the dial moves none of them. Optional `deform` (`Partial<FaceDeformFractions>`, issue #436) overrides the Set B ×2.5 face surface deformation table (`FACE_DEFORM_FRACTIONS`, checked against `FACE_DEFORM_RANGES` by `CONFIG_TURN_DEFORM_RANGE`); when `applyFaceSurfaceDeform` runs on a rig whose `motion` carries `tilt` or `turn` slider `derive` keys, it requires `config.turn` (`CONFIG_TURN_REQUIRED`, issue #478; `propose --full`/`--head` drafts it), promotes `face` on `head` (or `turn_face_head` when `turn` is declared) to the uneven 5×5 grid mesh, keys `face`, `hair_front` and `hair_back` deform timelines and ear/topknot tracks from `evalPitchFaceSurface` and `evalYawFaceSurface`, and samples the same deform field across each `features` member's rest span (`featRx = (24 / 106) · W`, `featRy = (12 / 128) · H`) with its depth fraction `z / zRef` as the field's angle input and chord foreshortening (`scalex` narrowing on the leading side and widening on the trailing side, `scaley` on pitch) so every feature's bounding box stays inside the deformed face plate across the rated band (issue #468). On yaw (`issue #479`), `evalYawFaceSurface` evaluates a **cylinder projection** (`cylinderYawDx`: `Δx(x, θ, R) = R · (sin(clamp(arcsin(clamp(x / R, −1, 1)) − θ, −π/2, π/2)) − clamp(x / R, −1, 1))`) of radius `R` (`turnSurfaceRadius`: `turn.surface.radius ?? turn.radius ?? turn.head.radius`, positive rig px checked by `CONFIG_FIELD_TYPE`, defaulting to half the face plate's opaque width `W / 2`) tapered by a cubic Hermite outline weight (`wOutline = 1` for `\|ux\| <= 0.7`, reaching `0` at `\|ux\| = 1.0`) so features slide across a fixed outline (`iris` shift within `±2%` of `cylinderYawDx`), the trailing cheek strip widens (`>= 1.54×` at `±15°`), and the leading jaw edge holds fixed (`0 px` shift) unless explicit horizontal `turn.deform` overrides (`turn_mid_x`, `turn_lead_compress_x`, `turn_trail_shift_x`) request the flat yaw table. On yaw (`issue #478`), `applyFaceSurfaceDeform` also derives a **head-only pivot** (`headTurnPivot`: `turn.head.pivot` when authored, otherwise the `opaque_px`-weighted mean of `depths[part]` across the head parts `DEFAULT_HEAD_TURN_PARTS` — `face`, `hair_front`, `hair_back`, `ear_r`, `ear_l`, `hairpin` — from `parts.json`, falling back to `turn.pivot`) so a forward torso or arm in `turn.depths` does not pull the head's rotation axis in front of `face`: `hair_back` (`depth_median > headPivot`, negative `headTurnFraction`) and `hairpin` behind `headPivot` translate opposite to the face's turn (`dx = s · turn_face_center_x · W · (headPivot − depth) / (headPivot − nearestHeadDepth)`), emerging on the trailing side to compensate for the leading-cheek foreshortening and keeping the combined head silhouette width near-constant across `±15°` without any same-sign `turn_hair_back_cheek_x` term. Optional `band` (`number` or `{yaw?, pitch?}`, positive degrees, issue #472) declares the rig's rated face turn band (default `FACE_RATED_BAND`: `yaw <= 15°`, `pitch <= 12°`); declaring a `turn.band` or a `motion.animations_from` `turn`/`tilt` `derive.degrees` above `±15°` yaw or `±12°` pitch without an `assemble.alternates` entry that replaces `face` is refused (`CONFIG_FACE_BAND_EXCEEDED`), and on a single-plate rig `applyFaceSurfaceDeform` adds self-targeting transform constraints `yaw_clamp` (`[-15, 15]`) and `pitch_clamp` (`[-12, 12]`) ahead of the slider constraints so driving `yaw` or `pitch` beyond the rated band clamps at the boundary. At rest: with `turn` declared, no pixel differs by more than 1 level at dial 0 (not byte-identical; the cause is float noise in the identity child bones, and the constraints add nothing); without `turn`, byte-identical. Neither `pivot` nor `depths` has a default (`CONFIG_FIELD_PRESENT`); `pivot` and `head.pivot` must lie behind the nearest part (`CONFIG_TURN_PIVOT_BEHIND_NEAREST`). Absent, no control is added and no byte of any output moves |
|
|
139
|
+
| `turn` | rig (adds the turn control or 2.5D head-turn producer) | **proposed** only with `propose --full`/`--head` (issue #251), then corrected, or **authored** for 2.5D depth-sampled head turns (issue #763): `{pivot?, depths?, deform?, band?, radius?, surface?: {radius?}, head?: {pivot?, radius?}, roles?, counter?, grid?, unitDepths?, body?}`. When `roles` is declared (`{<part>: "surface" \| "unit" \| "rear"}`, issue #763; `CONFIG_TURN_ROLE_UNKNOWN`, `CONFIG_TURN_SURFACE_REQUIRED`, `CONFIG_TURN_SURFACE_REGION`, `CONFIG_TURN_UNIT_MESH_BONES`), the rig stage runs the 2.5D depth-sampled head-turn producer: it edge-extends each turn-bound part's depth sheet across its transparent border and semi-transparent fringe from the nearest fully opaque (`alpha === 255`) texel before `PAD = 4` clamping (`padTurnDepthSheet`, `DEPTH_SILHOUETTE_SIZE_MISMATCH`), promotes `"surface"` regions to `generator: {kind: "grid", cols, rows, depth}` (`grid`: `[cols, rows]` or `{<part>: [cols, rows]}`, default `[13, 16]`, bounded at `<= 2,400` triangles per slot and `<= 4,000` total, `RIG_TURN_GRID_BUDGET`, `RIG_TURN_SURFACE_DEPTH_REQUIRED`, `RIG_TURN_SHARED_DEPTH_SCALE`), emits `faceshift` and `rear_shift` under `head` (`CONFIG_TURN_HEAD_BONE`, `RIG_TURN_HEAD_BONE`), `<part>_surface` and `<part>_unit` under `faceshift`, and `yaw_dial` and `pitch_dial` under `root` (`CONFIG_TURN_BONE_FREE`, `RIG_TURN_NAME_FREE`), re-parents `"unit"` region bones and `"rear"` bones and mesh weights to `faceshift` and `rear_shift` (while `"unit"` mesh parts receive their own `<part>_unit` carrier under `faceshift`, rebind direct `"head"` weights to `<part>_unit`, reparent bound chain roots to `<part>_unit` while keeping chain skinning weights intact, and key `<part>_unit` in `turn_units`, #790), samples each `"unit"` bone's depth from the `"surface"` depth sheet at its rest position (or reads `unitDepths.<part>`, `RIG_TURN_UNIT_DEPTH_REQUIRED`), enforces ear occlusion (`ear_r`/`ear_l` drawn before `"surface"` in `assemble.plan`, `CONFIG_TURN_EAR_DRAW_ORDER`, and behind the cheek surface, `RIG_TURN_EAR_DEPTH_BEHIND_CHEEK`), and writes `turn` and `tilt` `derive` tracks (`pivot` default `55` rig px, `counter` default `0.1` in `[0, 1]`, `CONFIG_TURN_COUNTER_RANGE`). `depths` holds, per part, the See-through layer's `depth_median` the part came from (larger = further back), read from the run the part was assembled from; a `painting:` patch has none and is not carried. A rider (issue #271) — a part from an `eyewhite`, `irides`, `eyelash`, `eyebrow`, `nose` or `mouth` layer — is drafted at the `face` part's depth, 0.001 nearer when parts.json draws it after the face and 0.001 further when before: See-through makes no depth of its own for the eye group (it cuts them from one depth map of the combined eyes) and clamps nose and mouth to the face's median − 0.001, and the two runs' own medians for these layers disagreed by up to 0.47 and swapped their order against the face. Every other layer — ears, headwear and earwear included — keeps its own median, unless it rides another part's bone. With no `face` part, or more than one, the riders keep their own and a note says so. A rider by bone (issue #535) — a part every *ownable* bone of which (a chain link, or a bone no other bone hangs from; `head`, `chest` and any bone with a child are shared and never count on their own) is *hosted* by another carried part, the host of a bone being the carried part that binds it (its region's bone; a mesh's `segments`, `contour` and `auto` regions' bones) with the most `opaque_px`, the earlier in parts.json on a tie, and which hosts no bone itself — is drafted at its host's depth, 0.001 nearer when drawn after the host and 0.001 further when before, and a note names the host, the bones and its own median: a pin, clip or ornament on the back hair's links travels with the back hair, not with its own layer's depth. `propose` reads the proposal's own `bones`, `meshes` and `regions`; the face riders are read by their tag first and never by their bones. A part bound to two hosts' bones rides neither and a note says so. In the rig stage, an authored depth on a rider by bone whose fraction differs from its host's by more than 0.1 of the dial (`TURN_RIDER_APART`, a share of `pivot − nearest`) is refused (`CONFIG_TURN_RIDER_DEPTH`); the host is read off `parts.json`'s `opaque_px`, so the config loader cannot see it. One note lists each part's depth and where it came from; a carrier the other run places more than 10 % of `pivot − nearest` away gets a note naming both values and the run read — the two runs are not reconciled. `pivot` is the depth that stays put; `propose` drafts the mean of the parts' depths weighted by `opaque_px`, the one depth at which the painted pixels' centroid does not slide under the dial. The rig stage adds a bone `turn` under `root` at its origin that nothing keys — its local x is the dial, in rig px — and carries each part by `(pivot − depth) / (pivot − nearest depth)` of it: the nearest part all of it, a part behind the pivot the other way, a part at the pivot not at all. Each part rides leaf twins (`turn_<part>_<bone>`, an identity child of every bone its slot and weights bind) moved by one `transform` constraint (`turn_<part>`, after the config's own); the idle's keys, the `<bone>_ctl` controls and a physics constraint stay on the bones, and the dial moves none of them. Optional `deform` (`Partial<FaceDeformFractions>`, issue #436) overrides the Set B ×2.5 face surface deformation table (`FACE_DEFORM_FRACTIONS`, checked against `FACE_DEFORM_RANGES` by `CONFIG_TURN_DEFORM_RANGE`); when `applyFaceSurfaceDeform` runs on a rig whose `motion` carries `tilt` or `turn` slider `derive` keys, it requires `config.turn` (`CONFIG_TURN_REQUIRED`, issue #478; `propose --full`/`--head` drafts it), promotes `face` on `head` (or `turn_face_head` when `turn` is declared) to the uneven 5×5 grid mesh, keys `face`, `hair_front` and `hair_back` deform timelines and ear/topknot tracks from `evalPitchFaceSurface` and `evalYawFaceSurface`, and samples the same deform field across each `features` member's rest span (`featRx = (24 / 106) · W`, `featRy = (12 / 128) · H`) with its depth fraction `z / zRef` as the field's angle input and chord foreshortening (`scalex` narrowing on the leading side and widening on the trailing side, `scaley` on pitch) so every feature's bounding box stays inside the deformed face plate across the rated band (issue #468). On yaw (`issue #479`), `evalYawFaceSurface` evaluates a **cylinder projection** (`cylinderYawDx`: `Δx(x, θ, R) = R · (sin(clamp(arcsin(clamp(x / R, −1, 1)) − θ, −π/2, π/2)) − clamp(x / R, −1, 1))`) of radius `R` (`turnSurfaceRadius`: `turn.surface.radius ?? turn.radius ?? turn.head.radius`, positive rig px checked by `CONFIG_FIELD_TYPE`, defaulting to half the face plate's opaque width `W / 2`) tapered by a cubic Hermite outline weight (`wOutline = 1` for `\|ux\| <= 0.7`, reaching `0` at `\|ux\| = 1.0`) so features slide across a fixed outline (`iris` shift within `±2%` of `cylinderYawDx`), the trailing cheek strip widens (`>= 1.54×` at `±15°`), and the leading jaw edge holds fixed (`0 px` shift) unless explicit horizontal `turn.deform` overrides (`turn_mid_x`, `turn_lead_compress_x`, `turn_trail_shift_x`) request the flat yaw table. On yaw (`issue #478`), `applyFaceSurfaceDeform` also derives a **head-only pivot** (`headTurnPivot`: `turn.head.pivot` when authored, otherwise the `opaque_px`-weighted mean of `depths[part]` across the head parts `DEFAULT_HEAD_TURN_PARTS` — `face`, `hair_front`, `hair_back`, `ear_r`, `ear_l`, `hairpin` — from `parts.json`, falling back to `turn.pivot`) so a forward torso or arm in `turn.depths` does not pull the head's rotation axis in front of `face`: `hair_back` (`depth_median > headPivot`, negative `headTurnFraction`) and `hairpin` behind `headPivot` translate opposite to the face's turn (`dx = s · turn_face_center_x · W · (headPivot − depth) / (headPivot − nearestHeadDepth)`), emerging on the trailing side to compensate for the leading-cheek foreshortening and keeping the combined head silhouette width near-constant across `±15°` without any same-sign `turn_hair_back_cheek_x` term. Optional `band` (`number` or `{yaw?, pitch?}`, positive degrees, issue #472) declares the rig's rated face turn band (default `FACE_RATED_BAND`: `yaw <= 15°`, `pitch <= 12°`); declaring a `turn.band` or a `motion.animations_from` `turn`/`tilt` `derive.degrees` above `±15°` yaw or `±12°` pitch without an `assemble.alternates` entry that replaces `face` is refused (`CONFIG_FACE_BAND_EXCEEDED`), and on a single-plate rig `applyFaceSurfaceDeform` adds self-targeting transform constraints `yaw_clamp` (`[-15, 15]`) and `pitch_clamp` (`[-12, 12]`) ahead of the slider constraints so driving `yaw` or `pitch` beyond the rated band clamps at the boundary. At rest: with `turn` declared, no pixel differs by more than 1 level at dial 0 (not byte-identical; the cause is float noise in the identity child bones, and the constraints add nothing); without `turn`, byte-identical. Neither `pivot` nor `depths` has a default (`CONFIG_FIELD_PRESENT`); `pivot` and `head.pivot` must lie behind the nearest part (`CONFIG_TURN_PIVOT_BEHIND_NEAREST`). Absent, no control is added and no byte of any output moves |
|
|
140
140
|
| `scene` | assemble (the recomposite, its holes and the figure's mask); check, through `parts.json`'s `scene` block (`RECOMPOSITE_HOLES`, the seam) | **authored**, optional; `propose` writes none (issue #242). `{}` declares the painting a scene: the figure and its surroundings in one image, See-through's full run holding only the figure. With it, `assemble` reads the recomposite figures, the hole list and the `uncovered:` lines inside the figure — the rig pixels where any full-run layer's alpha is above 8 (`OPAQUE_ALPHA_ABOVE`, the cut every layer's painted pixels are read by) — each line starting `inside the figure (config.scene: …, <n> of <m> rig px)`; writes that figure as `figure_rig.png` (white on black) beside the recomposite, and a `scene` block in `parts.json`; flags error pixels on the error map inside it only (outside, the painting grey); and `check` leaves out of the seam every frame pixel whose composite sample reaches the painting's outermost row or column, saying how many (`seam_border` in `check.json`, and on the seam line). It takes no field: the figure and its threshold are derived. A key in it other than a record or an annotation is `CONFIG_KEY_KNOWN`. Absent, no byte of any output moves |
|
|
141
141
|
| `cloth` | `propose --cloth` only; no other stage reads it, so it moves no byte of any build | **authored**, optional (issue #364): one recipe per tag, `{"bottomwear": {…}, "back hair": {…}, "front hair": {…}}`, each `{chains, links, wind, gravity, split?, length_ratio?, strength?, damping?, alternate_damping?, translate?, swing?, part?, influence?}`. `influence` (issue #518) — `{across, max, shape, radius?}`: the parts this recipe meshes are drafted in the influence mode (`meshes.<part>.influence` above) at their lattice's cell, with `across`, `max` and `shape` as declared (each required — the reading behind the radius did not vary them) and `radius` as declared or, absent, drafted as the farthest vertex's distance plus 3 cells (the `influence.radius` row); without it the parts keep their lattice. `chains` — trees across the piece (for `back hair`, per side of the eye axis), a whole number, 1 or more; `links` — links from root to tip on every path, 1 or more; `split` — `{at, into}`: the first `at` links are the trunk, which forks into `into` (2 or more) branches; `at` below `links` (`CONFIG_CLOTH_SPLIT_BEFORE_TIP`); `length_ratio` — a path's last link over its first, above 0, default 0.5; `strength` — `{trunk, branch, edge}`, each above 0 and below the spring's stability bound (`CONFIG_CLOTH_SPRING_STABLE`), default 100 / 100 / 50; `damping` — in [0, 1], absent: rig-c's default; `alternate_damping` — the odd trees' damping, in [0, 1], beside `damping` and different from it (`CONFIG_CLOTH_ALTERNATE_DIFFERS`); `wind`, `gravity` — `[root, tip]`, each 0 or more, tip at or above root (`CONFIG_CLOTH_RESPONSE_GROWS_TO_TIP`); `translate` — the x and y mix of a dangling end's flutter, above 0 and at most 1; `swing` — `bottomwear` only, `{scales}`, one positive scale per tree (`CONFIG_CLOTH_SWING_SCALE_PER_TREE`); `part` — `bottomwear` only (`CONFIG_CLOTH_PART_ON_BOTTOMWEAR`), a non-empty part or cut-piece name: the `topwear` part that holds a skirt See-through returned inside it (a dress), or its skirt piece cut by `assemble.cuts`, which takes the skirt's trees (issue #402, *A skirt inside topwear* below; the part is checked by `propose`, `PROPOSE_CLOTH_PART`). The two defaults are the recipe's own, measured on its synthetic fixture (the recipe below). The recipe below says what each field drafts. The config written: `propose --cloth <config.json> --write-config <out.json>` (issue #537) writes this config's own text back with the sections the recipe drafts spliced in — `meshes.<part>` and `regions.<part>`, and `bones`, `constraints` and `motion.tracks` entry by entry by name (issue #552) — and every other byte as read; `--from <previous config>` (issue #571) takes an entry equal to the previous recipe's draft as the recipe's (*The config written*, under the recipe below) |
|
|
142
142
|
| `proposed_rig_scale` | assemble, rig, build, `propose --from-config`/`--compare` | **proposed** by `propose` (issue #354): `parts.json`'s `scale_rig_per_source`, the `assemble.rig_scale` the rig sections (`bones`, `meshes`, `limbs`, `motion`) were drafted at. Held equal to `assemble.rig_scale` when present (`CONFIG_PROPOSED_RIG_SCALE`; 0, negative or not a number: `CONFIG_FIELD_TYPE`). Absent on a hand-authored config, where no byte of any output moves |
|
|
@@ -4514,6 +4514,7 @@ and stay absent).
|
|
|
4514
4514
|
| <a id="CONFIG_TURN_ROLE_UNKNOWN"></a>`CONFIG_TURN_ROLE_UNKNOWN` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) is not `"surface"`, `"unit"` or `"rear"` | declare `"surface"`, `"unit"` or `"rear"` |
|
|
4515
4515
|
| <a id="CONFIG_TURN_SURFACE_REQUIRED"></a>`CONFIG_TURN_SURFACE_REQUIRED` | `config.turn.roles` (or `config.turn.body.roles`) declares no `"surface"` part | declare at least one part as `"surface"` |
|
|
4516
4516
|
| <a id="CONFIG_TURN_SURFACE_REGION"></a>`CONFIG_TURN_SURFACE_REGION` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) declares `"surface"` for a part that is also in `config.meshes` | attach `"surface"` parts in `config.regions` (so the rig stage promotes them to depth-backed grid meshes on `<part>_surface`), or give the mesh part role `"unit"` or `"rear"` |
|
|
4517
|
+
| <a id="CONFIG_TURN_UNIT_MESH_BONES"></a>`CONFIG_TURN_UNIT_MESH_BONES` | `config.turn.roles.<part>` (or `config.turn.body.roles.<part>`) declares `"unit"` for a mesh part in `config.meshes` that binds a bone outside the `"head"` subtree (or outside the torso carrier subtree for `turn.body`), or shares a bound bone or chain with another `"unit"` mesh part, so its bones cannot be moved under `<part>_unit` (#790) | bind each `"unit"` mesh only to `"head"` and its own child bones or chains under `"head"` (or to the torso root bone and its own non-head descendants for `turn.body`), or give the part role `"rear"` |
|
|
4517
4518
|
| <a id="CONFIG_TURN_EAR_DRAW_ORDER"></a>`CONFIG_TURN_EAR_DRAW_ORDER` | an ear part in `config.turn.roles` is drawn after a `"surface"` part in `assemble.plan` | place `ear_r` and `ear_l` before `face` in `assemble.plan` so the turning cheek occludes the far ear |
|
|
4518
4519
|
| <a id="CONFIG_TURN_HEAD_BONE"></a>`CONFIG_TURN_HEAD_BONE` | `config.turn.roles` is declared without a single bone `"head"` in `config.bones`, or `config.turn.body` without a single bone `"chest"` / `"hip"` (or its declared `bone`) | declare `"head"` (or the body turn root bone) as a single bone in `config.bones` |
|
|
4519
4520
|
| <a id="CONFIG_TURN_SLIDER_NAME_FREE"></a>`CONFIG_TURN_SLIDER_NAME_FREE` | `config.turn.body.slider` (or the default `"body_yaw_dial"`) collides with a head turn dial (`"yaw"`, `"pitch"`, `"yaw_dial"`, `"pitch_dial"`) or an existing slider constraint in `config.constraints` (#787) | choose a distinct slider name in `config.turn.body.slider` |
|
|
@@ -5569,7 +5570,8 @@ controls, and `config.turn.body` (#787) extends the same 2.5D turn pipeline to
|
|
|
5569
5570
|
torso/body parts under an independent `body_yaw_dial` (or `turn.body.slider`)
|
|
5570
5571
|
dial; see [`CONFIG_TURN_ROLE_UNKNOWN`](#CONFIG_TURN_ROLE_UNKNOWN),
|
|
5571
5572
|
[`CONFIG_TURN_SURFACE_REQUIRED`](#CONFIG_TURN_SURFACE_REQUIRED),
|
|
5572
|
-
[`CONFIG_TURN_SURFACE_REGION`](#CONFIG_TURN_SURFACE_REGION)
|
|
5573
|
+
[`CONFIG_TURN_SURFACE_REGION`](#CONFIG_TURN_SURFACE_REGION),
|
|
5574
|
+
[`CONFIG_TURN_UNIT_MESH_BONES`](#CONFIG_TURN_UNIT_MESH_BONES) and
|
|
5573
5575
|
[`CONFIG_TURN_SLIDER_NAME_FREE`](#CONFIG_TURN_SLIDER_NAME_FREE).
|
|
5574
5576
|
Authored weighted body meshes not named in `config.turn.body.roles` are unchanged and do not consume depth sheets. Measurement sheets are not packed
|
|
5575
5577
|
art. An authored `parts.json` depth reference remains an active standalone
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-parts",
|
|
3
|
-
"version": "1.71.
|
|
3
|
+
"version": "1.71.1",
|
|
4
4
|
"description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/assemble.ts
CHANGED
|
@@ -101,7 +101,7 @@ import { bindDepthRun, copyDepthMaterial, registerDepthRun, transportPartDepth,
|
|
|
101
101
|
* Pure: no clock, no randomness, no file access. The CLI reads and writes.
|
|
102
102
|
*/
|
|
103
103
|
import { sourceLimbTarget, nearestTargetPart } from './limbownership.ts';
|
|
104
|
-
import { type ArmSplit, type BoneEntry, type CharacterConfig, type ControlSkeleton, controlSkeletonOf, type Cut, type EarlyConfig, type Extend, type Limb, type Patch, type PlanEntry, type Run, type SeeThrough } from './config.ts';
|
|
104
|
+
import { type ArmSplit, type BoneEntry, type CharacterConfig, type ConfigConstraint, type ControlSkeleton, controlSkeletonOf, type Cut, type EarlyConfig, type Extend, type Limb, type MeshSpec, type Patch, type PlanEntry, type RegionSpec, type Run, type SeeThrough, turnMovingPartPair, type TurnSpec } from './config.ts';
|
|
105
105
|
import { PartsError, type Problem, refuseIfAny } from './errors.ts';
|
|
106
106
|
import { CORE_ALPHA, figuresPhrase, implausibleRules, type Layer, type LayerFigures, layerFigures, type LayerSet, NEAR_WHITE_MIN, OPAQUE_ALPHA_ABOVE, ruleSummary } from './layers.ts';
|
|
107
107
|
import { padToSquare, squarePad } from './inputs.ts';
|
|
@@ -398,6 +398,8 @@ export interface AssembleInput {
|
|
|
398
398
|
limbUnderCover?: boolean;
|
|
399
399
|
/** Issue #637: `source` is the pre-fix test mutant that skips source-transparent cap ownership; stages use target. */
|
|
400
400
|
capOwnership?: 'target' | 'source';
|
|
401
|
+
/** Issue #791: pairs of parts a turn moves relative to each other, whose fringe and seam colour stay untouched. */
|
|
402
|
+
turnMovingPair?: ((a: string, b: string) => boolean) | null;
|
|
401
403
|
}
|
|
402
404
|
|
|
403
405
|
/**
|
|
@@ -2791,7 +2793,15 @@ function keepArtWhole(part: PlacedPart, cleared: Cleared[], holderAt: (q: number
|
|
|
2791
2793
|
* hold the pixel after it); and every pixel at alpha >= `CORE_ALPHA`, which
|
|
2792
2794
|
* is the seam override's.
|
|
2793
2795
|
*/
|
|
2794
|
-
export function pushBackFringe(
|
|
2796
|
+
export function pushBackFringe(
|
|
2797
|
+
parts: PlacedPart[],
|
|
2798
|
+
srcr: Raster,
|
|
2799
|
+
rule: SeamRule,
|
|
2800
|
+
silhouette: Mask | null,
|
|
2801
|
+
feathered: ReadonlyArray<Mask | null> | null = null,
|
|
2802
|
+
keep: ReadonlyArray<Mask | null> | null = null,
|
|
2803
|
+
turnMovingPair: ((a: string, b: string) => boolean) | null = null,
|
|
2804
|
+
): FringePushed[][] {
|
|
2795
2805
|
const { width: W } = srcr;
|
|
2796
2806
|
const { holder, cand } = seamCandidates(parts, srcr, rule, silhouette);
|
|
2797
2807
|
const at = (i: number, d: number): number => {
|
|
@@ -2810,6 +2820,7 @@ export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule
|
|
|
2810
2820
|
if (cand[d] === 0 || !shows(d)) continue;
|
|
2811
2821
|
for (let i = holder[d] + 1; i < parts.length; i++) {
|
|
2812
2822
|
if (feathered?.[i]?.data[d] === 1 || keep?.[i]?.data[d] === 1) continue;
|
|
2823
|
+
if (turnMovingPair !== null && turnMovingPair(parts[i].record.name, parts[holder[d]].record.name)) continue;
|
|
2813
2824
|
const s = at(i, d);
|
|
2814
2825
|
if (s < 0) continue;
|
|
2815
2826
|
const img = parts[i].image.data;
|
|
@@ -2820,7 +2831,8 @@ export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule
|
|
|
2820
2831
|
}
|
|
2821
2832
|
parts.forEach((part, i) => keepArtWhole(part, cleared[i], (q) => {
|
|
2822
2833
|
const d = (part.record.y + Math.floor(q / part.record.w)) * W + part.record.x + (q % part.record.w);
|
|
2823
|
-
|
|
2834
|
+
const h = holder[d];
|
|
2835
|
+
return h >= 0 && turnMovingPair !== null && turnMovingPair(part.record.name, parts[h].record.name) ? -1 : h;
|
|
2824
2836
|
}));
|
|
2825
2837
|
const counts: Array<Map<number, number>> = parts.map(() => new Map());
|
|
2826
2838
|
cleared.forEach((list, i) => {
|
|
@@ -2855,16 +2867,48 @@ export function pushBackFringe(parts: PlacedPart[], srcr: Raster, rule: SeamRule
|
|
|
2855
2867
|
* under a subset set's actual cover instead of recolouring it to the painting.
|
|
2856
2868
|
* (`assemble_parts.py` `main`, "5. seam override".)
|
|
2857
2869
|
*/
|
|
2858
|
-
export function seamOverride(
|
|
2870
|
+
export function seamOverride(
|
|
2871
|
+
parts: PlacedPart[],
|
|
2872
|
+
srcr: Raster,
|
|
2873
|
+
rule: SeamRule,
|
|
2874
|
+
silhouette: Mask | null,
|
|
2875
|
+
keep: ReadonlyArray<Mask | null> | null = null,
|
|
2876
|
+
turnMovingPair: ((a: string, b: string) => boolean) | null = null,
|
|
2877
|
+
): void {
|
|
2859
2878
|
const { width: W } = srcr;
|
|
2860
2879
|
const { top, cand } = seamCandidates(parts, srcr, rule, silhouette);
|
|
2880
|
+
const r = (CORE_KERNEL - 1) >> 1;
|
|
2861
2881
|
parts.forEach(({ record: p, image }, i) => {
|
|
2882
|
+
const movingPeers =
|
|
2883
|
+
turnMovingPair === null
|
|
2884
|
+
? []
|
|
2885
|
+
: parts.map((_, j) => j).filter((j) => j !== i && turnMovingPair(p.name, parts[j].record.name));
|
|
2862
2886
|
let n = 0;
|
|
2863
2887
|
for (let y = 0; y < p.h; y++) {
|
|
2864
2888
|
for (let x = 0; x < p.w; x++) {
|
|
2865
|
-
const
|
|
2889
|
+
const rx = p.x + x;
|
|
2890
|
+
const ry = p.y + y;
|
|
2891
|
+
const d = ry * W + rx;
|
|
2866
2892
|
const s = (y * p.w + x) * 4;
|
|
2867
2893
|
if (keep?.[i]?.data[d] === 1 || cand[d] === 0 || top[d] !== i || image.data[s + 3] < CORE_ALPHA) continue;
|
|
2894
|
+
if (
|
|
2895
|
+
movingPeers.some((j) => {
|
|
2896
|
+
const pj = parts[j].record;
|
|
2897
|
+
const imgJ = parts[j].image.data;
|
|
2898
|
+
const x0 = Math.max(pj.x, rx - r);
|
|
2899
|
+
const x1 = Math.min(pj.x + pj.w - 1, rx + r);
|
|
2900
|
+
const y0 = Math.max(pj.y, ry - r);
|
|
2901
|
+
const y1 = Math.min(pj.y + pj.h - 1, ry + r);
|
|
2902
|
+
for (let ny = y0; ny <= y1; ny++) {
|
|
2903
|
+
for (let nx = x0; nx <= x1; nx++) {
|
|
2904
|
+
if (imgJ[((ny - pj.y) * pj.w + (nx - pj.x)) * 4 + 3] > 0) return true;
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
return false;
|
|
2908
|
+
})
|
|
2909
|
+
) {
|
|
2910
|
+
continue;
|
|
2911
|
+
}
|
|
2868
2912
|
image.data[s] = srcr.data[d * 4];
|
|
2869
2913
|
image.data[s + 1] = srcr.data[d * 4 + 1];
|
|
2870
2914
|
image.data[s + 2] = srcr.data[d * 4 + 2];
|
|
@@ -4999,7 +5043,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
4999
5043
|
});
|
|
5000
5044
|
const featheredInOrder: Array<Mask | null> = order.map((d) => ('patch' in d ? null : (pieceAt(d).b.feathered ?? null)));
|
|
5001
5045
|
const keepInOrder = order.map((d) => ('limb' in d ? limbKeep[d.limb] : null));
|
|
5002
|
-
const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, featheredInOrder, keepInOrder);
|
|
5046
|
+
const pushedBy = pushBackFringe(stack, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, featheredInOrder, keepInOrder, input.turnMovingPair ?? null);
|
|
5003
5047
|
// Issue #255: a part's drift refusals in a body, and who holds the body in the draw order (the push-back clears
|
|
5004
5048
|
// only fringe below CORE_ALPHA, and the seam override only recolours, so the holders read here are final).
|
|
5005
5049
|
const holderAt = new Int32Array(W * H).fill(-1);
|
|
@@ -5123,7 +5167,7 @@ export function assemble(input: AssembleInput): AssembleResult {
|
|
|
5123
5167
|
for (const p of placed) if (p.record.depth !== undefined && artFiles.has(p.record.depth.image)) refuseIfAny([{ code: 'DEPTH_SHEET_UNAMBIGUOUS', object: p.record.depth.image, detail: 'collides with a part artwork filename; choose noncolliding part names before sheet emission' }]);
|
|
5124
5168
|
|
|
5125
5169
|
|
|
5126
|
-
seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder);
|
|
5170
|
+
seamOverride(placed, srcr, seamRule, seamRule === 'silhouette' ? silhouette : null, keepInOrder, input.turnMovingPair ?? null);
|
|
5127
5171
|
const can = recomposite(placed, W, H);
|
|
5128
5172
|
// Issue #242: on a scene painting the figure is read off the full run, and every recomposite figure inside it.
|
|
5129
5173
|
const inside = input.scene === true ? sceneFigure([...rig.entries()].filter(([k]) => k.startsWith('full:')).map(([, r]) => r), W, H) : null;
|
|
@@ -5923,7 +5967,14 @@ function unplannedNotes(
|
|
|
5923
5967
|
* full-loader config, where it is optional.
|
|
5924
5968
|
*/
|
|
5925
5969
|
export function stageFields(
|
|
5926
|
-
cfg: Pick<CharacterConfig, 'seethrough' | 'assemble' | 'scene' | 'motion_seams'> & {
|
|
5970
|
+
cfg: Pick<CharacterConfig, 'seethrough' | 'assemble' | 'scene' | 'motion_seams'> & {
|
|
5971
|
+
limbs?: Record<string, Limb>;
|
|
5972
|
+
bones?: BoneEntry[];
|
|
5973
|
+
meshes?: Record<string, MeshSpec>;
|
|
5974
|
+
regions?: Record<string, RegionSpec>;
|
|
5975
|
+
constraints?: ConfigConstraint[];
|
|
5976
|
+
turn?: TurnSpec;
|
|
5977
|
+
},
|
|
5927
5978
|
single: { w: number; h: number } | null = null,
|
|
5928
5979
|
): {
|
|
5929
5980
|
resolution: number;
|
|
@@ -5941,6 +5992,7 @@ export function stageFields(
|
|
|
5941
5992
|
armSplit?: ArmSplit;
|
|
5942
5993
|
keySkeleton?: ControlSkeleton;
|
|
5943
5994
|
headFaceUnderfill?: boolean;
|
|
5995
|
+
turnMovingPair?: (a: string, b: string) => boolean;
|
|
5944
5996
|
} {
|
|
5945
5997
|
const problems: Problem[] = [];
|
|
5946
5998
|
if (cfg.seethrough === undefined) {
|
|
@@ -5952,6 +6004,7 @@ export function stageFields(
|
|
|
5952
6004
|
refuseIfAny(problems);
|
|
5953
6005
|
const st = cfg.seethrough as SeeThrough;
|
|
5954
6006
|
const keySkeleton = controlSkeletonOf(cfg);
|
|
6007
|
+
const turnMovingPair = turnMovingPartPair(cfg);
|
|
5955
6008
|
return {
|
|
5956
6009
|
resolution: st.resolution,
|
|
5957
6010
|
headBox: single !== null ? singleRunHeadBox(single.w, single.h, st.resolution) : (st.head_box as [number, number, number, number]),
|
|
@@ -5959,6 +6012,7 @@ export function stageFields(
|
|
|
5959
6012
|
...(st.arm_split === undefined ? {} : { armSplit: st.arm_split }),
|
|
5960
6013
|
...(keySkeleton === undefined ? {} : { keySkeleton }),
|
|
5961
6014
|
...(cfg.assemble.head_face_underfill === undefined ? {} : { headFaceUnderfill: cfg.assemble.head_face_underfill }),
|
|
6015
|
+
...(turnMovingPair === null ? {} : { turnMovingPair }),
|
|
5962
6016
|
rigScale: cfg.assemble.rig_scale,
|
|
5963
6017
|
plan: cfg.assemble.plan,
|
|
5964
6018
|
extend: cfg.assemble.extend_below_crop ?? [],
|
package/src/build.ts
CHANGED
|
@@ -659,6 +659,7 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
|
|
|
659
659
|
...(fields.scene === undefined ? {} : { scene: fields.scene }),
|
|
660
660
|
...(fields.armSplit !== undefined && altPlan.some((e) => e[1] === 'full' && (e[2] === 'handwear-r' || e[2] === 'handwear-l')) ? { armSplit: fields.armSplit } : {}),
|
|
661
661
|
...(fields.headFaceUnderfill === undefined ? {} : { headFaceUnderfill: fields.headFaceUnderfill }),
|
|
662
|
+
...(fields.turnMovingPair === undefined ? {} : { turnMovingPair: fields.turnMovingPair }),
|
|
662
663
|
seamRule: input.seam,
|
|
663
664
|
projectRule: input.project,
|
|
664
665
|
...(altExclude.length === 0 ? {} : { exclude: altExclude }),
|
package/src/config.ts
CHANGED
|
@@ -99,7 +99,8 @@ import { edgeLength } from './length.ts';
|
|
|
99
99
|
import { setFocusProblems } from './setfocus.ts';
|
|
100
100
|
import { isSkeletonName, KEYPOINT_NAMES, type KeypointName, type PosePoints, scaledPoints, SKELETON_NAMES, type SkeletonName } from './skeleton.ts';
|
|
101
101
|
import { acceptedTagNames, AUTHOR_LABEL_RULE, AUTHOR_PREFIX, readLayerTag } from './tags.ts';
|
|
102
|
-
import { BODY_REAR_SHIFT_BONE, BODY_YAW_DIAL_BONE,
|
|
102
|
+
import { BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE, BODY_YAW_DIAL_BONE, EAR_DEPTH_RANGE, FACESHIFT_BONE, FACE_DEFORM_FRACTIONS, FACE_DEFORM_RANGES, FACE_RATED_PITCH_BAND, FACE_RATED_YAW_BAND, type FaceDeformKey, PITCH_DIAL_BONE, REAR_SHIFT_BONE, TURN_BONE, TURN_ROLES, type TurnRole, type TurnSpec, YAW_DIAL_BONE, turnNearest, turnSurfaceBone, turnUnitBone } from './turn.ts';
|
|
103
|
+
export type { TurnSpec };
|
|
103
104
|
import { FLOOR_FORMS, type FloorForm, type MeshInfluences } from './weights.ts';
|
|
104
105
|
|
|
105
106
|
export type Point = [number, number];
|
|
@@ -791,30 +792,244 @@ export interface PartBinding {
|
|
|
791
792
|
*/
|
|
792
793
|
export function partBoundBones(b: PartBinding): Map<string, string[]> {
|
|
793
794
|
const chains = new Map<string, string[]>();
|
|
794
|
-
for (const e of b.bones)
|
|
795
|
+
for (const e of Array.isArray(b.bones) ? b.bones : []) {
|
|
796
|
+
if (isPlainObject(e) && 'chain' in e && typeof e.chain === 'string' && Array.isArray(e.points)) {
|
|
797
|
+
chains.set(e.chain, e.points.map((_, k) => `${e.chain}${k}`));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
795
800
|
const out = new Map<string, string[]>();
|
|
796
801
|
const bind = (part: string, bone: string): void => {
|
|
797
802
|
const list = out.get(part) ?? [];
|
|
798
803
|
if (!list.includes(bone)) list.push(bone);
|
|
799
804
|
out.set(part, list);
|
|
800
805
|
};
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
if (
|
|
805
|
-
|
|
806
|
+
if (isPlainObject(b.meshes)) {
|
|
807
|
+
for (const [part, m] of Object.entries(b.meshes)) {
|
|
808
|
+
if (isRecordKey(part) || !isPlainObject(m)) continue;
|
|
809
|
+
if ('explicit' in m && isPlainObject(m.explicit)) {
|
|
810
|
+
const addWeights = (ws: Json): void => {
|
|
811
|
+
if (!Array.isArray(ws)) return;
|
|
812
|
+
for (const row of ws) {
|
|
813
|
+
if (!Array.isArray(row)) continue;
|
|
814
|
+
for (const w of row) {
|
|
815
|
+
if (isPlainObject(w) && typeof w.bone === 'string') bind(part, w.bone);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
if (Array.isArray(m.explicit.islands)) {
|
|
820
|
+
for (const isl of m.explicit.islands) {
|
|
821
|
+
if (isPlainObject(isl)) addWeights(isl.weights);
|
|
822
|
+
}
|
|
823
|
+
const seg0 =
|
|
824
|
+
Array.isArray(m.segments) && m.segments.length > 0
|
|
825
|
+
? typeof m.segments[0] === 'string'
|
|
826
|
+
? m.segments[0]
|
|
827
|
+
: Array.isArray(m.segments[0]) && typeof m.segments[0][0] === 'string'
|
|
828
|
+
? m.segments[0][0]
|
|
829
|
+
: undefined
|
|
830
|
+
: undefined;
|
|
831
|
+
for (const isl of m.explicit.islands) {
|
|
832
|
+
if (!isPlainObject(isl)) continue;
|
|
833
|
+
const bName = typeof isl.bone === 'string' ? isl.bone : seg0;
|
|
834
|
+
if (bName !== undefined) bind(part, bName);
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
addWeights(m.explicit.weights);
|
|
838
|
+
}
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (Array.isArray(m.segments)) {
|
|
842
|
+
for (const sg of m.segments) {
|
|
843
|
+
if (typeof sg === 'string') {
|
|
844
|
+
for (const l of chains.get(sg) ?? [sg]) bind(part, l);
|
|
845
|
+
} else if (Array.isArray(sg) && typeof sg[0] === 'string') {
|
|
846
|
+
bind(part, sg[0]);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
if ('contour' in m && isPlainObject(m.contour)) {
|
|
851
|
+
if (Array.isArray(m.contour.regions)) {
|
|
852
|
+
for (const rg of m.contour.regions) {
|
|
853
|
+
if (isPlainObject(rg) && typeof rg.bone === 'string') bind(part, rg.bone);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
if (isPlainObject(m.contour.bust)) {
|
|
857
|
+
bind(part, typeof m.contour.bust.bone_r === 'string' ? m.contour.bust.bone_r : DEFAULT_BUST_BONE_R);
|
|
858
|
+
bind(part, typeof m.contour.bust.bone_l === 'string' ? m.contour.bust.bone_l : DEFAULT_BUST_BONE_L);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
if ('auto' in m && isPlainObject(m.auto) && Array.isArray(m.auto.regions)) {
|
|
862
|
+
for (const rg of m.auto.regions) {
|
|
863
|
+
if (isPlainObject(rg) && typeof rg.bone === 'string') bind(part, rg.bone);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
806
866
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
867
|
+
}
|
|
868
|
+
if (isPlainObject(b.regions)) {
|
|
869
|
+
for (const [part, region] of Object.entries(b.regions)) {
|
|
870
|
+
if (isRecordKey(part)) continue;
|
|
871
|
+
const bone = rawRegionBone(region);
|
|
872
|
+
if (typeof bone === 'string') bind(part, bone);
|
|
810
873
|
}
|
|
811
|
-
if ('contour' in m) for (const rg of contourRegionsOf(m.contour)) bind(part, rg.bone);
|
|
812
|
-
if ('auto' in m) for (const rg of m.auto.regions ?? []) if (weightsABone(rg)) bind(part, rg.bone);
|
|
813
874
|
}
|
|
814
|
-
for (const [part, region] of Object.entries(b.regions)) bind(part, regionBone(region));
|
|
815
875
|
return out;
|
|
816
876
|
}
|
|
817
877
|
|
|
878
|
+
/**
|
|
879
|
+
* Issue #791: whether a turn moves two parts relative to each other — two parts
|
|
880
|
+
* with different turn roles or carriers (`config.turn.roles`,
|
|
881
|
+
* `config.turn.body.roles`, `config.turn.depths`), or a part with a physics
|
|
882
|
+
* chain (`config.constraints` with `type: "physics"`) over another part.
|
|
883
|
+
* Returns null when `config.turn` is absent, so a rig without a turn block is
|
|
884
|
+
* untouched.
|
|
885
|
+
*/
|
|
886
|
+
export function turnMovingPartPair(
|
|
887
|
+
cfg: {
|
|
888
|
+
assemble?: CharacterConfig['assemble'];
|
|
889
|
+
turn?: TurnSpec;
|
|
890
|
+
bones?: BoneEntry[];
|
|
891
|
+
meshes?: Record<string, MeshSpec>;
|
|
892
|
+
regions?: Record<string, RegionSpec>;
|
|
893
|
+
limbs?: Record<string, Limb>;
|
|
894
|
+
constraints?: ConfigConstraint[];
|
|
895
|
+
},
|
|
896
|
+
): ((a: string, b: string) => boolean) | null {
|
|
897
|
+
const turn = cfg.turn;
|
|
898
|
+
if (!isPlainObject(turn)) return null;
|
|
899
|
+
|
|
900
|
+
const sourceOf = new Map<string, string>();
|
|
901
|
+
for (const c of cfg.assemble?.cuts ?? []) {
|
|
902
|
+
if (isPlainObject(c) && typeof c.into === 'string' && typeof c.from === 'string') sourceOf.set(c.into, c.from);
|
|
903
|
+
}
|
|
904
|
+
if (isPlainObject(cfg.limbs)) {
|
|
905
|
+
for (const limb of Object.values(cfg.limbs)) {
|
|
906
|
+
if (!isPlainObject(limb) || !Array.isArray(limb.segments)) continue;
|
|
907
|
+
for (const sg of limb.segments) {
|
|
908
|
+
if (!isPlainObject(sg) || typeof sg.part !== 'string' || typeof sg.from !== 'string') continue;
|
|
909
|
+
sourceOf.set(sg.part, sg.from);
|
|
910
|
+
if (isPlainObject(sg.hybrid) && typeof sg.hybrid.part === 'string') sourceOf.set(sg.hybrid.part, sg.from);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
const baseName = (p: string): string => {
|
|
915
|
+
let cur = p;
|
|
916
|
+
const seen = new Set<string>();
|
|
917
|
+
while (sourceOf.has(cur) && !seen.has(cur)) {
|
|
918
|
+
seen.add(cur);
|
|
919
|
+
cur = sourceOf.get(cur) as string;
|
|
920
|
+
}
|
|
921
|
+
return cur;
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
const boneEntries = Array.isArray(cfg.bones) ? cfg.bones.filter(isPlainObject) : [];
|
|
925
|
+
const parentOf = new Map<string, string>();
|
|
926
|
+
for (const e of boneEntries) {
|
|
927
|
+
if ('chain' in e && typeof e.chain === 'string' && Array.isArray(e.points)) {
|
|
928
|
+
e.points.forEach((_, k) => parentOf.set(`${e.chain}${k}`, k === 0 ? e.parent : `${e.chain}${k - 1}`));
|
|
929
|
+
} else if ('name' in e && typeof e.name === 'string' && typeof e.parent === 'string') {
|
|
930
|
+
parentOf.set(e.name, e.parent);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
const physicsBones = new Set<string>();
|
|
934
|
+
if (Array.isArray(cfg.constraints)) {
|
|
935
|
+
for (const c of cfg.constraints) {
|
|
936
|
+
if (isPlainObject(c) && c.type === 'physics' && typeof c.bone === 'string') physicsBones.add(c.bone);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
for (const b of parentOf.keys()) {
|
|
940
|
+
let cur: string | undefined = b;
|
|
941
|
+
const seen = new Set<string>();
|
|
942
|
+
while (cur !== undefined && !seen.has(cur)) {
|
|
943
|
+
if (physicsBones.has(cur)) {
|
|
944
|
+
physicsBones.add(b);
|
|
945
|
+
break;
|
|
946
|
+
}
|
|
947
|
+
seen.add(cur);
|
|
948
|
+
cur = parentOf.get(cur);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
const meshParts = isPlainObject(cfg.meshes)
|
|
953
|
+
? new Set(Object.keys(cfg.meshes).filter((k) => !isRecordKey(k)))
|
|
954
|
+
: new Set<string>();
|
|
955
|
+
const isMeshPart = (p: string): boolean => meshParts.has(p) || meshParts.has(baseName(p));
|
|
956
|
+
|
|
957
|
+
const bound =
|
|
958
|
+
isPlainObject(cfg.meshes) || isPlainObject(cfg.regions)
|
|
959
|
+
? partBoundBones({
|
|
960
|
+
bones: boneEntries as BoneEntry[],
|
|
961
|
+
meshes: isPlainObject(cfg.meshes) ? (cfg.meshes as Record<string, MeshSpec>) : {},
|
|
962
|
+
regions: isPlainObject(cfg.regions) ? (cfg.regions as Record<string, RegionSpec>) : {},
|
|
963
|
+
})
|
|
964
|
+
: new Map<string, string[]>();
|
|
965
|
+
if (isPlainObject(cfg.limbs)) {
|
|
966
|
+
for (const limb of Object.values(cfg.limbs)) {
|
|
967
|
+
if (!isPlainObject(limb) || !Array.isArray(limb.segments)) continue;
|
|
968
|
+
for (const sg of limb.segments) {
|
|
969
|
+
if (!isPlainObject(sg) || typeof sg.part !== 'string' || typeof sg.bone !== 'string') continue;
|
|
970
|
+
if (!bound.has(sg.part)) bound.set(sg.part, [sg.bone]);
|
|
971
|
+
if (isPlainObject(sg.hybrid) && typeof sg.hybrid.part === 'string' && !bound.has(sg.hybrid.part)) {
|
|
972
|
+
bound.set(sg.hybrid.part, [sg.bone]);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
const bonesOf = (p: string): readonly string[] => bound.get(p) ?? bound.get(baseName(p)) ?? [];
|
|
978
|
+
const sameNonEmptyBones = (a: readonly string[], b: readonly string[]): boolean =>
|
|
979
|
+
a.length > 0 && a.length === b.length && a.every((x, i) => x === b[i]);
|
|
980
|
+
|
|
981
|
+
const roleGroups: Array<{ roles: Readonly<Record<string, TurnRole>>; unitDepths?: Readonly<Record<string, number>> }> = [];
|
|
982
|
+
if (isPlainObject(turn.roles)) {
|
|
983
|
+
roleGroups.push({
|
|
984
|
+
roles: turn.roles as Readonly<Record<string, TurnRole>>,
|
|
985
|
+
...(isPlainObject(turn.unitDepths) ? { unitDepths: turn.unitDepths as Readonly<Record<string, number>> } : {}),
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
if (isPlainObject(turn.body) && isPlainObject(turn.body.roles)) {
|
|
989
|
+
roleGroups.push({
|
|
990
|
+
roles: turn.body.roles as Readonly<Record<string, TurnRole>>,
|
|
991
|
+
...(isPlainObject(turn.body.unitDepths) ? { unitDepths: turn.body.unitDepths as Readonly<Record<string, number>> } : {}),
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
const depths = isPlainObject(turn.depths) ? (turn.depths as Readonly<Record<string, number>>) : null;
|
|
995
|
+
const pivot = typeof turn.pivot === 'number' && Number.isFinite(turn.pivot) ? turn.pivot : null;
|
|
996
|
+
|
|
997
|
+
return (a: string, b: string): boolean => {
|
|
998
|
+
if (a === b) return false;
|
|
999
|
+
const bA = bonesOf(a);
|
|
1000
|
+
const bB = bonesOf(b);
|
|
1001
|
+
const hasPhysA = bA.some((x) => physicsBones.has(x));
|
|
1002
|
+
const hasPhysB = bB.some((x) => physicsBones.has(x));
|
|
1003
|
+
if ((hasPhysA || hasPhysB) && !(bA.length === 1 && sameNonEmptyBones(bA, bB))) return true;
|
|
1004
|
+
|
|
1005
|
+
for (const g of roleGroups) {
|
|
1006
|
+
const rA = g.roles[a] ?? g.roles[baseName(a)];
|
|
1007
|
+
const rB = g.roles[b] ?? g.roles[baseName(b)];
|
|
1008
|
+
if (rA === undefined && rB === undefined) continue;
|
|
1009
|
+
if (rA !== rB) return true;
|
|
1010
|
+
if (rA === 'surface') return true;
|
|
1011
|
+
if (rA === 'unit' && (isMeshPart(a) || isMeshPart(b) || !sameNonEmptyBones(bA, bB))) return true;
|
|
1012
|
+
const ud = g.unitDepths;
|
|
1013
|
+
if (ud !== undefined) {
|
|
1014
|
+
const dA = ud[a] ?? ud[baseName(a)] ?? (bA.length === 1 ? ud[bA[0]] : undefined);
|
|
1015
|
+
const dB = ud[b] ?? ud[baseName(b)] ?? (bB.length === 1 ? ud[bB[0]] : undefined);
|
|
1016
|
+
if (dA !== dB) return true;
|
|
1017
|
+
}
|
|
1018
|
+
if ((bA.length > 0 || bB.length > 0) && !sameNonEmptyBones(bA, bB)) return true;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (depths !== null) {
|
|
1022
|
+
const rawA = depths[a] ?? depths[baseName(a)];
|
|
1023
|
+
const rawB = depths[b] ?? depths[baseName(b)];
|
|
1024
|
+
const effA = typeof rawA === 'number' && Number.isFinite(rawA) && rawA !== pivot ? rawA : null;
|
|
1025
|
+
const effB = typeof rawB === 'number' && Number.isFinite(rawB) && rawB !== pivot ? rawB : null;
|
|
1026
|
+
if (effA !== effB) return true;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
return false;
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
818
1033
|
/**
|
|
819
1034
|
* The bones a part can own (issue #535): every chain link, and every bone no
|
|
820
1035
|
* other bone hangs from. A trunk bone — `head`, `chest`, anything with a child —
|
|
@@ -1410,6 +1625,12 @@ export interface AssembleConfig {
|
|
|
1410
1625
|
/** Issue #349: read with `bones` (the joints are the bones' origins) when present. */
|
|
1411
1626
|
limbs?: Record<string, Limb>;
|
|
1412
1627
|
bones?: BoneEntry[];
|
|
1628
|
+
/** Issue #791: read with `turn` so `assemble` leaves moving pairs' fringes and seams alone. */
|
|
1629
|
+
meshes?: Record<string, MeshSpec>;
|
|
1630
|
+
regions?: Record<string, RegionSpec>;
|
|
1631
|
+
constraints?: ConfigConstraint[];
|
|
1632
|
+
motion?: Motion;
|
|
1633
|
+
turn?: TurnSpec;
|
|
1413
1634
|
motion_seams?: MotionSeamDeclaration[];
|
|
1414
1635
|
/** Issue #354: the `rig_scale` `propose` drafted the rig sections at, held equal to `assemble.rig_scale` when present. */
|
|
1415
1636
|
proposed_rig_scale?: number;
|
|
@@ -1488,10 +1709,25 @@ function parseEarlyConfigFrom(raw: Json, door: EarlyDoor, base: string | null):
|
|
|
1488
1709
|
if (isPlainObject(t.assemble) && 'alternates' in t.assemble) {
|
|
1489
1710
|
checkAlternates(c, t.assemble.alternates, made, limbs, names?.bones ?? null, names?.chains ?? null, t.regions, t.meshes);
|
|
1490
1711
|
}
|
|
1712
|
+
const output = new Set([...made.parts.filter(n => !limbs?.consumed.has(n)), ...made.patches, ...made.cuts, ...(limbs?.parts.keys() ?? [])]);
|
|
1491
1713
|
if ('motion_seams' in t) {
|
|
1492
|
-
const output = new Set([...made.parts.filter(n => !limbs?.consumed.has(n)), ...made.patches, ...made.cuts, ...(limbs?.parts.keys() ?? [])]);
|
|
1493
1714
|
c.problems.push(...motionSeamProblems(t.motion_seams, output, 'config.motion_seams', 'CONFIG_MOTION_SEAM'));
|
|
1494
1715
|
}
|
|
1716
|
+
if ('turn' in t) {
|
|
1717
|
+
if ('bones' in t && names === null) names = checkBones(c, t.bones);
|
|
1718
|
+
const attached = 'meshes' in t || 'regions' in t ? attachedParts(t.meshes, t.regions) : output;
|
|
1719
|
+
const hasAltFace = hasAlternateFaceSet(t.assemble, [...made.parts, ...made.cuts]);
|
|
1720
|
+
const declaredSliders = new Set<string>();
|
|
1721
|
+
if (Array.isArray(t.constraints)) {
|
|
1722
|
+
for (const entry of t.constraints) {
|
|
1723
|
+
if (isPlainObject(entry) && entry.type === 'slider' && typeof entry.name === 'string' && entry.name.length > 0) {
|
|
1724
|
+
declaredSliders.add(entry.name);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
const meshParts = isPlainObject(t.meshes) ? new Set(Object.keys(t.meshes).filter((k) => !isRecordKey(k))) : new Set<string>();
|
|
1729
|
+
checkTurn(c, t.turn, attached, names?.bones ?? new Set(['root', 'head', 'chest', 'hip']), hasAltFace, made.parts, declaredSliders, meshParts);
|
|
1730
|
+
}
|
|
1495
1731
|
}
|
|
1496
1732
|
if ('cloth' in t) checkCloth(c, t.cloth);
|
|
1497
1733
|
const pose = base === null ? null : poseBeside(c, t.generation, base);
|
|
@@ -1706,7 +1942,7 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
1706
1942
|
}
|
|
1707
1943
|
}
|
|
1708
1944
|
const meshParts = isPlainObject(t.meshes) ? new Set(Object.keys(t.meshes).filter((k) => !isRecordKey(k))) : new Set<string>();
|
|
1709
|
-
if ('turn' in t) checkTurn(c, t.turn, attached, names.bones, hasAltFace, parts, declaredSliders, meshParts);
|
|
1945
|
+
if ('turn' in t) checkTurn(c, t.turn, attached, names.bones, hasAltFace, parts, declaredSliders, meshParts, t.meshes, names.chains, names.parents);
|
|
1710
1946
|
if ('scene' in t) checkScene(c, t.scene);
|
|
1711
1947
|
if ('cloth' in t) checkCloth(c, t.cloth);
|
|
1712
1948
|
if ('requirements' in t && c.string('config.requirements', t.requirements) && base !== null) checkRequirementsFile(c, resolve(base, t.requirements));
|
|
@@ -4401,8 +4637,97 @@ function checkTurn(
|
|
|
4401
4637
|
parts: readonly string[] = [],
|
|
4402
4638
|
declaredSliders: ReadonlySet<string> = new Set(),
|
|
4403
4639
|
meshParts: ReadonlySet<string> = new Set(),
|
|
4640
|
+
rawMeshes: Json = undefined,
|
|
4641
|
+
chains: ReadonlyMap<string, number> = new Map(),
|
|
4642
|
+
parents: ReadonlyMap<string, string> = new Map(),
|
|
4404
4643
|
): void {
|
|
4405
4644
|
const at = 'config.turn';
|
|
4645
|
+
const meshBoundBones = (part: string): string[] => {
|
|
4646
|
+
if (!isPlainObject(rawMeshes) || !isPlainObject(rawMeshes[part])) return [];
|
|
4647
|
+
const m = rawMeshes[part] as Record<string, Json>;
|
|
4648
|
+
const out: string[] = [];
|
|
4649
|
+
const add = (rawBone: string): void => {
|
|
4650
|
+
const b = rawBone.endsWith('_d') && bones.has(rawBone.slice(0, -2)) ? rawBone.slice(0, -2) : rawBone;
|
|
4651
|
+
if (bones.has(b) && !out.includes(b)) out.push(b);
|
|
4652
|
+
};
|
|
4653
|
+
if (Array.isArray(m.segments)) {
|
|
4654
|
+
for (const s of m.segments) {
|
|
4655
|
+
if (typeof s === 'string') {
|
|
4656
|
+
const linkCount = chains.get(s);
|
|
4657
|
+
if (linkCount !== undefined) {
|
|
4658
|
+
for (let lk = 0; lk < linkCount; lk++) add(`${s}${lk}`);
|
|
4659
|
+
} else {
|
|
4660
|
+
add(s);
|
|
4661
|
+
}
|
|
4662
|
+
} else if (Array.isArray(s) && typeof s[0] === 'string') {
|
|
4663
|
+
add(s[0]);
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
if (isPlainObject(m.contour)) {
|
|
4668
|
+
if (Array.isArray(m.contour.regions)) {
|
|
4669
|
+
for (const rg of m.contour.regions) {
|
|
4670
|
+
if (isPlainObject(rg) && typeof rg.bone === 'string') add(rg.bone);
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
if (isPlainObject(m.contour.bust)) {
|
|
4674
|
+
add(typeof m.contour.bust.bone_r === 'string' ? m.contour.bust.bone_r : DEFAULT_BUST_BONE_R);
|
|
4675
|
+
add(typeof m.contour.bust.bone_l === 'string' ? m.contour.bust.bone_l : DEFAULT_BUST_BONE_L);
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
if (isPlainObject(m.auto) && Array.isArray(m.auto.regions)) {
|
|
4679
|
+
for (const rg of m.auto.regions) {
|
|
4680
|
+
if (isPlainObject(rg) && typeof rg.bone === 'string') add(rg.bone);
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4683
|
+
if (isPlainObject(m.explicit)) {
|
|
4684
|
+
const addWeights = (ws: Json): void => {
|
|
4685
|
+
if (!Array.isArray(ws)) return;
|
|
4686
|
+
for (const row of ws) {
|
|
4687
|
+
if (!Array.isArray(row)) continue;
|
|
4688
|
+
for (const w of row) {
|
|
4689
|
+
if (isPlainObject(w) && typeof w.bone === 'string') add(w.bone);
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
};
|
|
4693
|
+
addWeights(m.explicit.weights);
|
|
4694
|
+
if (Array.isArray(m.explicit.islands)) {
|
|
4695
|
+
for (const isl of m.explicit.islands) {
|
|
4696
|
+
if (isPlainObject(isl)) addWeights(isl.weights);
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
return out;
|
|
4701
|
+
};
|
|
4702
|
+
const headSubtreeRoot = (boneName: string): string | null => {
|
|
4703
|
+
if (boneName === 'head') return 'head';
|
|
4704
|
+
let cur: string | undefined = boneName;
|
|
4705
|
+
const seen = new Set<string>();
|
|
4706
|
+
while (cur !== undefined && !seen.has(cur)) {
|
|
4707
|
+
seen.add(cur);
|
|
4708
|
+
const p = parents.get(cur);
|
|
4709
|
+
if (p === 'head') return cur;
|
|
4710
|
+
cur = p;
|
|
4711
|
+
}
|
|
4712
|
+
return null;
|
|
4713
|
+
};
|
|
4714
|
+
const canCarryHeadUnitBone = (boneName: string): boolean => headSubtreeRoot(boneName) !== null;
|
|
4715
|
+
const bodySubtreeRoot = (boneName: string, torsoRoots: ReadonlySet<string>, headExclusion: ReadonlySet<string>): string | null => {
|
|
4716
|
+
if (headExclusion.has(boneName)) return null;
|
|
4717
|
+
if (torsoRoots.has(boneName)) return boneName;
|
|
4718
|
+
let cur: string | undefined = boneName;
|
|
4719
|
+
const seen = new Set<string>();
|
|
4720
|
+
while (cur !== undefined && !seen.has(cur)) {
|
|
4721
|
+
seen.add(cur);
|
|
4722
|
+
const p = parents.get(cur);
|
|
4723
|
+
if (p === undefined || headExclusion.has(p)) return null;
|
|
4724
|
+
if (torsoRoots.has(p)) return !torsoRoots.has(cur) && !headExclusion.has(cur) ? cur : null;
|
|
4725
|
+
cur = p;
|
|
4726
|
+
}
|
|
4727
|
+
return null;
|
|
4728
|
+
};
|
|
4729
|
+
const canCarryBodyUnitBone = (boneName: string, torsoRoots: ReadonlySet<string>, headExclusion: ReadonlySet<string>): boolean =>
|
|
4730
|
+
bodySubtreeRoot(boneName, torsoRoots, headExclusion) !== null;
|
|
4406
4731
|
const hasRoles = isPlainObject(v) && 'roles' in v;
|
|
4407
4732
|
const hasBody = isPlainObject(v) && 'body' in v;
|
|
4408
4733
|
const hasDepths = isPlainObject(v) && 'depths' in v;
|
|
@@ -4460,7 +4785,9 @@ function checkTurn(
|
|
|
4460
4785
|
c.fail('CONFIG_FIELD_TYPE', `${at}.roles`, `is ${show(r)}; a non-empty object of part name -> ("surface" | "unit" | "rear") is required`);
|
|
4461
4786
|
} else {
|
|
4462
4787
|
const surfaceParts: string[] = [];
|
|
4788
|
+
const unitMeshParts: string[] = [];
|
|
4463
4789
|
const earParts: string[] = [];
|
|
4790
|
+
const headUnitRootOwner = new Map<string, { part: string; bone: string }>();
|
|
4464
4791
|
for (const [part, role] of Object.entries(r)) {
|
|
4465
4792
|
if (isRecordKey(part)) continue;
|
|
4466
4793
|
if (!attached.has(part)) {
|
|
@@ -4479,7 +4806,46 @@ function checkTurn(
|
|
|
4479
4806
|
}
|
|
4480
4807
|
surfaceParts.push(part);
|
|
4481
4808
|
}
|
|
4482
|
-
if (role === 'unit'
|
|
4809
|
+
if (role === 'unit') {
|
|
4810
|
+
if (part === 'ear_r' || part === 'ear_l') earParts.push(part);
|
|
4811
|
+
if (meshParts.has(part)) {
|
|
4812
|
+
unitMeshParts.push(part);
|
|
4813
|
+
if (bones.has('head')) {
|
|
4814
|
+
const bound = meshBoundBones(part);
|
|
4815
|
+
const uncarried = bound.filter((b) => !canCarryHeadUnitBone(b));
|
|
4816
|
+
if (bound.length > 0 && uncarried.length > 0) {
|
|
4817
|
+
c.fail(
|
|
4818
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
4819
|
+
`${at}.roles.${part}`,
|
|
4820
|
+
`declares "${part}" as "unit", and config.meshes.${part} binds bone(s) ${uncarried.map((b) => `"${b}"`).join(', ')} outside the "head" subtree, which cannot be carried by "${turnUnitBone(part)}" under "${FACESHIFT_BONE}"; bind a head "unit" mesh only to "head" or bones and chains under "head"`,
|
|
4821
|
+
);
|
|
4822
|
+
}
|
|
4823
|
+
const reportedRoots = new Set<string>();
|
|
4824
|
+
for (const b of bound) {
|
|
4825
|
+
if (b === 'head') continue;
|
|
4826
|
+
const rootBone = headSubtreeRoot(b);
|
|
4827
|
+
if (rootBone === null) continue;
|
|
4828
|
+
const owner = headUnitRootOwner.get(rootBone);
|
|
4829
|
+
if (owner !== undefined && owner.part !== part) {
|
|
4830
|
+
if (!reportedRoots.has(rootBone)) {
|
|
4831
|
+
reportedRoots.add(rootBone);
|
|
4832
|
+
const sharedDetail =
|
|
4833
|
+
owner.bone === b
|
|
4834
|
+
? `bone "${b}"${b === rootBone ? '' : ` (under "${rootBone}")`}`
|
|
4835
|
+
: `chain root "${rootBone}" ("${owner.part}" binds "${owner.bone}", "${part}" binds "${b}")`;
|
|
4836
|
+
c.fail(
|
|
4837
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
4838
|
+
`${at}.roles.${part}`,
|
|
4839
|
+
`declares "${part}" as "unit", and config.meshes.${part} shares ${sharedDetail} with "unit" mesh "${owner.part}" (${at}.roles.${owner.part}); each "unit" mesh reparents its bound chain root under its own "<part>_unit" carrier, so two "unit" meshes cannot share a bone or chain under "head"`,
|
|
4840
|
+
);
|
|
4841
|
+
}
|
|
4842
|
+
} else if (owner === undefined) {
|
|
4843
|
+
headUnitRootOwner.set(rootBone, { part, bone: b });
|
|
4844
|
+
}
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4483
4849
|
}
|
|
4484
4850
|
}
|
|
4485
4851
|
if (surfaceParts.length === 0) {
|
|
@@ -4501,7 +4867,7 @@ function checkTurn(
|
|
|
4501
4867
|
if (!bones.has('head')) {
|
|
4502
4868
|
c.fail('CONFIG_TURN_HEAD_BONE', `${at}.roles`, 'requires a declared "head" bone in config.bones to parent the 2.5D turn carriers');
|
|
4503
4869
|
}
|
|
4504
|
-
for (const reserved of [FACESHIFT_BONE, REAR_SHIFT_BONE, ...surfaceParts.map(turnSurfaceBone)]) {
|
|
4870
|
+
for (const reserved of [FACESHIFT_BONE, REAR_SHIFT_BONE, ...surfaceParts.map(turnSurfaceBone), ...unitMeshParts.map(turnUnitBone)]) {
|
|
4505
4871
|
if (bones.has(reserved)) {
|
|
4506
4872
|
c.fail('CONFIG_TURN_BONE_FREE', `bone "${reserved}"`, `is a carrier bone the rig stage adds under head for config.turn.roles, and config.bones already declares a bone of that name; rename it`);
|
|
4507
4873
|
}
|
|
@@ -4556,6 +4922,11 @@ function checkTurn(
|
|
|
4556
4922
|
c.fail('CONFIG_FIELD_TYPE', `${bAt}.roles`, `is ${show(br)}; a non-empty object of part name -> ("surface" | "unit" | "rear") is required`);
|
|
4557
4923
|
} else {
|
|
4558
4924
|
const bodySurfaceParts: string[] = [];
|
|
4925
|
+
const bodyUnitMeshParts: string[] = [];
|
|
4926
|
+
const bodyRoot = typeof bo.bone === 'string' && bones.has(bo.bone) ? bo.bone : bones.has('chest') ? 'chest' : 'hip';
|
|
4927
|
+
const torsoRoots = new Set<string>([bodyRoot, 'chest', 'hip']);
|
|
4928
|
+
const headExclusion = new Set<string>(['head', 'neck']);
|
|
4929
|
+
const bodyUnitRootOwner = new Map<string, { part: string; bone: string }>();
|
|
4559
4930
|
for (const [part, role] of Object.entries(br)) {
|
|
4560
4931
|
if (isRecordKey(part)) continue;
|
|
4561
4932
|
if (!attached.has(part)) {
|
|
@@ -4572,12 +4943,48 @@ function checkTurn(
|
|
|
4572
4943
|
);
|
|
4573
4944
|
}
|
|
4574
4945
|
bodySurfaceParts.push(part);
|
|
4946
|
+
} else if (role === 'unit' && meshParts.has(part)) {
|
|
4947
|
+
bodyUnitMeshParts.push(part);
|
|
4948
|
+
if (bones.has(bodyRoot)) {
|
|
4949
|
+
const bound = meshBoundBones(part);
|
|
4950
|
+
const uncarried = bound.filter((b) => !canCarryBodyUnitBone(b, torsoRoots, headExclusion));
|
|
4951
|
+
if (bound.length > 0 && uncarried.length > 0) {
|
|
4952
|
+
c.fail(
|
|
4953
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
4954
|
+
`${bAt}.roles.${part}`,
|
|
4955
|
+
`declares "${part}" as "unit", and config.meshes.${part} binds bone(s) ${uncarried.map((b) => `"${b}"`).join(', ')} outside the "${bodyRoot}" torso subtree, which cannot be carried by "${turnUnitBone(part)}" under "${BODYSHIFT_BONE}"; bind a body "unit" mesh only to the torso root or bones and chains under it`,
|
|
4956
|
+
);
|
|
4957
|
+
}
|
|
4958
|
+
const reportedRoots = new Set<string>();
|
|
4959
|
+
for (const b of bound) {
|
|
4960
|
+
if (torsoRoots.has(b)) continue;
|
|
4961
|
+
const rootBone = bodySubtreeRoot(b, torsoRoots, headExclusion);
|
|
4962
|
+
if (rootBone === null) continue;
|
|
4963
|
+
const owner = bodyUnitRootOwner.get(rootBone);
|
|
4964
|
+
if (owner !== undefined && owner.part !== part) {
|
|
4965
|
+
if (!reportedRoots.has(rootBone)) {
|
|
4966
|
+
reportedRoots.add(rootBone);
|
|
4967
|
+
const sharedDetail =
|
|
4968
|
+
owner.bone === b
|
|
4969
|
+
? `bone "${b}"${b === rootBone ? '' : ` (under "${rootBone}")`}`
|
|
4970
|
+
: `chain root "${rootBone}" ("${owner.part}" binds "${owner.bone}", "${part}" binds "${b}")`;
|
|
4971
|
+
c.fail(
|
|
4972
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
4973
|
+
`${bAt}.roles.${part}`,
|
|
4974
|
+
`declares "${part}" as "unit", and config.meshes.${part} shares ${sharedDetail} with "unit" mesh "${owner.part}" (${bAt}.roles.${owner.part}); each "unit" mesh reparents its bound chain root under its own "<part>_unit" carrier, so two "unit" meshes cannot share a bone or chain under "${bodyRoot}"`,
|
|
4975
|
+
);
|
|
4976
|
+
}
|
|
4977
|
+
} else if (owner === undefined) {
|
|
4978
|
+
bodyUnitRootOwner.set(rootBone, { part, bone: b });
|
|
4979
|
+
}
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4575
4982
|
}
|
|
4576
4983
|
}
|
|
4577
4984
|
if (bodySurfaceParts.length === 0) {
|
|
4578
4985
|
c.fail('CONFIG_TURN_SURFACE_REQUIRED', `${bAt}.roles`, 'declares no part with role "surface"; at least one surface part is required for 2.5D body turn');
|
|
4579
4986
|
}
|
|
4580
|
-
for (const reserved of [BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE, ...bodySurfaceParts.map(turnSurfaceBone)]) {
|
|
4987
|
+
for (const reserved of [BODYSHIFT_BONE, BODY_REAR_SHIFT_BONE, ...bodySurfaceParts.map(turnSurfaceBone), ...bodyUnitMeshParts.map(turnUnitBone)]) {
|
|
4581
4988
|
if (bones.has(reserved)) {
|
|
4582
4989
|
c.fail('CONFIG_TURN_BONE_FREE', `bone "${reserved}"`, `is a carrier bone the rig stage adds for config.turn.body.roles, and config.bones already declares a bone of that name; rename it`);
|
|
4583
4990
|
}
|
package/src/rig.ts
CHANGED
|
@@ -187,7 +187,7 @@ import { alphaAbove, crop, pad, type Raster } from './raster/index.ts';
|
|
|
187
187
|
import { pyRound } from './round.ts';
|
|
188
188
|
import { boneHeat, type HeatDust, heatInfluences, HEAT_LIMITS, heatRow, type HeatRow, latticeSilhouette, tracedSilhouette } from './heat.ts';
|
|
189
189
|
import type { PosePoints } from './skeleton.ts';
|
|
190
|
-
import { applyFaceSurfaceDeform, BODY_REAR_SHIFT_BONE, BODY_YAW_DIAL_BONE, BODYSHIFT_BONE, buildDepth25DTurn, FACE_RATED_BAND, FACESHIFT_BONE, PITCH_DIAL_BONE, REAR_SHIFT_BONE, resolveTurnGrid, TURN_BONE, TURN_CARRIER_TAG, TURN_GRID_MAX_TRIANGLES_PER_SLOT, TURN_GRID_MAX_TRIANGLES_TOTAL, TURN_PLACES, TURN_RIDER_APART, TURN_RIDER_TAGS, turnRiderDepth, type TurnRole, type TurnSpec, turnConstraintName, turnFractions, turnNearest, turnSurfaceBone, turnTwin, YAW_DIAL_BONE } from './turn.ts';
|
|
190
|
+
import { applyFaceSurfaceDeform, BODY_REAR_SHIFT_BONE, BODY_YAW_DIAL_BONE, BODYSHIFT_BONE, buildDepth25DTurn, FACE_RATED_BAND, FACESHIFT_BONE, PITCH_DIAL_BONE, REAR_SHIFT_BONE, resolveTurnGrid, TURN_BONE, TURN_CARRIER_TAG, TURN_GRID_MAX_TRIANGLES_PER_SLOT, TURN_GRID_MAX_TRIANGLES_TOTAL, TURN_PLACES, TURN_RIDER_APART, TURN_RIDER_TAGS, turnRiderDepth, type TurnRole, type TurnSpec, turnConstraintName, turnFractions, turnNearest, turnSurfaceBone, turnTwin, turnUnitBone, YAW_DIAL_BONE } from './turn.ts';
|
|
191
191
|
import { DISTANCE_EXPONENT, type FloorForm, type Influence, influences, type InfluenceLimits, type MeshInfluences, meshLimits, type Segment } from './weights.ts';
|
|
192
192
|
|
|
193
193
|
/** Transparent pixels added round every part image — the reference's `PAD`. */
|
|
@@ -3128,7 +3128,12 @@ export function buildWaistPairSource(
|
|
|
3128
3128
|
const headTransform = world.get('head') as BoneTransform;
|
|
3129
3129
|
const headTurnDeg = turn.get('head') ?? 0;
|
|
3130
3130
|
const surfBones: RigBone[] = [];
|
|
3131
|
+
const unitMeshBones: RigBone[] = [];
|
|
3131
3132
|
for (const p of parts.parts) {
|
|
3133
|
+
if (roles[p.name] === 'unit' && cfg.meshes[p.name] !== undefined) {
|
|
3134
|
+
unitMeshBones.push({ name: turnUnitBone(p.name), parent: FACESHIFT_BONE, x: 0, y: 0 });
|
|
3135
|
+
continue;
|
|
3136
|
+
}
|
|
3132
3137
|
if (roles[p.name] !== 'surface') continue;
|
|
3133
3138
|
const [cols, rows] = resolveTurnGrid(cfg.turn, p.name);
|
|
3134
3139
|
totalGridTriangles += 2 * (cols - 1) * (rows - 1);
|
|
@@ -3149,6 +3154,7 @@ export function buildWaistPairSource(
|
|
|
3149
3154
|
{ name: FACESHIFT_BONE, parent: 'head', x: 0, y: 0 },
|
|
3150
3155
|
...(hasRear ? [{ name: REAR_SHIFT_BONE, parent: 'head', x: 0, y: 0 }] : []),
|
|
3151
3156
|
...surfBones,
|
|
3157
|
+
...unitMeshBones,
|
|
3152
3158
|
];
|
|
3153
3159
|
bones.splice(headIdx + 1, 0, ...carriers);
|
|
3154
3160
|
const existingNames = new Set(bones.map((b) => b.name));
|
|
@@ -3156,7 +3162,14 @@ export function buildWaistPairSource(
|
|
|
3156
3162
|
if (!existingNames.has(PITCH_DIAL_BONE)) bones.push({ name: PITCH_DIAL_BONE, parent: ROOT_BONE, x: 0, y: 0 });
|
|
3157
3163
|
|
|
3158
3164
|
const boneByName = new Map(bones.map((b) => [b.name, b]));
|
|
3165
|
+
const headCarriers = new Set<string>(carriers.map((b) => b.name));
|
|
3166
|
+
const assertNotHeadTurnCarrier = (boneName: string, targetParent: string): void => {
|
|
3167
|
+
if (headCarriers.has(boneName)) {
|
|
3168
|
+
throw new Error(`turn invariant violated: turn carrier "${boneName}" must never be reparented (target "${targetParent}")`);
|
|
3169
|
+
}
|
|
3170
|
+
};
|
|
3159
3171
|
const reparentFromHead = (boneName: string, targetParent: string): void => {
|
|
3172
|
+
assertNotHeadTurnCarrier(boneName, targetParent);
|
|
3160
3173
|
const b = boneByName.get(boneName);
|
|
3161
3174
|
if (b !== undefined && b.parent === 'head') b.parent = targetParent;
|
|
3162
3175
|
};
|
|
@@ -3168,25 +3181,100 @@ export function buildWaistPairSource(
|
|
|
3168
3181
|
if (stillSl.bone === 'head') stillSl.bone = carrierBone;
|
|
3169
3182
|
else reparentFromHead(stillSl.bone, carrierBone);
|
|
3170
3183
|
}
|
|
3171
|
-
const
|
|
3172
|
-
|
|
3173
|
-
if (
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3184
|
+
for (const slotEntry of finalSlots) {
|
|
3185
|
+
if (slotEntry.name !== part && !slotEntry.name.startsWith(`${part}__island`)) continue;
|
|
3186
|
+
if (slotEntry.bone === 'head') slotEntry.bone = carrierBone;
|
|
3187
|
+
const atts = skin[slotEntry.name] ?? {};
|
|
3188
|
+
for (const att of Object.values(atts)) {
|
|
3189
|
+
if (!('type' in att) || att.weights === undefined) continue;
|
|
3190
|
+
for (const row of att.weights) {
|
|
3191
|
+
for (const w of row) {
|
|
3192
|
+
if (w.bone === 'head') {
|
|
3193
|
+
w.bone = carrierBone;
|
|
3194
|
+
} else {
|
|
3195
|
+
let cur = boneByName.get(w.bone);
|
|
3196
|
+
while (cur !== undefined && cur.parent !== undefined && cur.parent !== 'head' && !headCarriers.has(cur.parent)) {
|
|
3197
|
+
cur = boneByName.get(cur.parent);
|
|
3198
|
+
}
|
|
3199
|
+
if (cur !== undefined && cur.parent === 'head') {
|
|
3200
|
+
assertNotHeadTurnCarrier(cur.name, carrierBone);
|
|
3201
|
+
cur.parent = carrierBone;
|
|
3202
|
+
}
|
|
3182
3203
|
}
|
|
3183
|
-
if (cur !== undefined && cur.parent === 'head') cur.parent = carrierBone;
|
|
3184
3204
|
}
|
|
3185
3205
|
}
|
|
3186
3206
|
}
|
|
3187
3207
|
}
|
|
3188
3208
|
};
|
|
3189
3209
|
|
|
3210
|
+
const headUnitRootOwner = new Map<string, { part: string; bone: string; rootLabel: string }>();
|
|
3211
|
+
const rebindUnitMeshToHeadCarrier = (part: string): void => {
|
|
3212
|
+
const unitBone = turnUnitBone(part);
|
|
3213
|
+
const bound: string[] = [];
|
|
3214
|
+
const addBound = (bName: string): void => {
|
|
3215
|
+
if (!bound.includes(bName)) bound.push(bName);
|
|
3216
|
+
};
|
|
3217
|
+
for (const sl of finalSlots) {
|
|
3218
|
+
if (sl.name !== part && !sl.name.startsWith(`${part}__island`)) continue;
|
|
3219
|
+
const atts = skin[sl.name] ?? {};
|
|
3220
|
+
let hasWeights = false;
|
|
3221
|
+
for (const att of Object.values(atts)) {
|
|
3222
|
+
if ('type' in att && att.weights !== undefined && att.weights.length > 0) {
|
|
3223
|
+
hasWeights = true;
|
|
3224
|
+
for (const row of att.weights) {
|
|
3225
|
+
for (const w of row) addBound(w.bone);
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
if (!hasWeights) addBound(sl.bone);
|
|
3230
|
+
}
|
|
3231
|
+
const stillSl = slotByName.get(`${part}${STILL_SUFFIX}`);
|
|
3232
|
+
if (stillSl !== undefined) addBound(stillSl.bone);
|
|
3233
|
+
const uncarried: string[] = [];
|
|
3234
|
+
const sharedRoots = new Set<string>();
|
|
3235
|
+
let hasShared = false;
|
|
3236
|
+
for (const bName of bound) {
|
|
3237
|
+
if (bName === 'head' || bName === unitBone) continue;
|
|
3238
|
+
let cur = boneByName.get(bName);
|
|
3239
|
+
while (cur !== undefined && cur.parent !== undefined && cur.parent !== 'head' && !headCarriers.has(cur.parent)) {
|
|
3240
|
+
cur = boneByName.get(cur.parent);
|
|
3241
|
+
}
|
|
3242
|
+
if (cur === undefined || cur.parent === undefined || (cur.parent !== 'head' && !headCarriers.has(cur.parent)) || headCarriers.has(cur.name)) {
|
|
3243
|
+
uncarried.push(bName);
|
|
3244
|
+
continue;
|
|
3245
|
+
}
|
|
3246
|
+
const rootLabel = cur.name.endsWith(CONTROL_SUFFIX) ? cur.name.slice(0, -CONTROL_SUFFIX.length) : cur.name;
|
|
3247
|
+
const owner = headUnitRootOwner.get(cur.name);
|
|
3248
|
+
if (owner !== undefined && owner.part !== part) {
|
|
3249
|
+
hasShared = true;
|
|
3250
|
+
if (!sharedRoots.has(cur.name)) {
|
|
3251
|
+
sharedRoots.add(cur.name);
|
|
3252
|
+
const sharedDetail =
|
|
3253
|
+
owner.bone === bName
|
|
3254
|
+
? `bone "${bName}"${bName === owner.rootLabel ? '' : ` (under "${owner.rootLabel}")`}`
|
|
3255
|
+
: `chain root "${owner.rootLabel}" ("${owner.part}" binds "${owner.bone}", "${part}" binds "${bName}")`;
|
|
3256
|
+
fail(
|
|
3257
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
3258
|
+
`config.turn.roles.${part}`,
|
|
3259
|
+
`declares "${part}" as "unit", and config.meshes.${part} shares ${sharedDetail} with "unit" mesh "${owner.part}" (config.turn.roles.${owner.part}); each "unit" mesh reparents its bound chain root under its own "<part>_unit" carrier, so two "unit" meshes cannot share a bone or chain under "head"`,
|
|
3260
|
+
);
|
|
3261
|
+
}
|
|
3262
|
+
} else if (owner === undefined) {
|
|
3263
|
+
headUnitRootOwner.set(cur.name, { part, bone: bName, rootLabel });
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
if (uncarried.length > 0) {
|
|
3267
|
+
fail(
|
|
3268
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
3269
|
+
`config.turn.roles.${part}`,
|
|
3270
|
+
`declares "${part}" as "unit", and config.meshes.${part} binds bone(s) ${uncarried.map((b) => `"${b}"`).join(', ')} outside the "head" subtree, which cannot be carried by "${unitBone}" under "${FACESHIFT_BONE}"; bind a head "unit" mesh only to "head" or bones and chains under "head"`,
|
|
3271
|
+
);
|
|
3272
|
+
return;
|
|
3273
|
+
}
|
|
3274
|
+
if (hasShared) return;
|
|
3275
|
+
rebindPartToCarrier(part, unitBone);
|
|
3276
|
+
};
|
|
3277
|
+
|
|
3190
3278
|
for (const [part, role] of Object.entries(roles)) {
|
|
3191
3279
|
if (role === 'unit') {
|
|
3192
3280
|
if (cfg.regions[part] !== undefined) {
|
|
@@ -3200,7 +3288,7 @@ export function buildWaistPairSource(
|
|
|
3200
3288
|
const st = stills[part];
|
|
3201
3289
|
if (st !== undefined) reparentFromHead(st.bone, FACESHIFT_BONE);
|
|
3202
3290
|
} else if (cfg.meshes[part] !== undefined) {
|
|
3203
|
-
|
|
3291
|
+
rebindUnitMeshToHeadCarrier(part);
|
|
3204
3292
|
}
|
|
3205
3293
|
} else if (role === 'rear' && hasRear) {
|
|
3206
3294
|
if (cfg.regions[part] !== undefined) {
|
|
@@ -3230,7 +3318,12 @@ export function buildWaistPairSource(
|
|
|
3230
3318
|
const bodyTransform = world.get(bodyRoot) as BoneTransform;
|
|
3231
3319
|
const bodyTurnDeg = turn.get(bodyRoot) ?? 0;
|
|
3232
3320
|
const surfBones: RigBone[] = [];
|
|
3321
|
+
const unitMeshBones: RigBone[] = [];
|
|
3233
3322
|
for (const p of parts.parts) {
|
|
3323
|
+
if (bodyRoles[p.name] === 'unit' && cfg.meshes[p.name] !== undefined) {
|
|
3324
|
+
unitMeshBones.push({ name: turnUnitBone(p.name), parent: BODYSHIFT_BONE, x: 0, y: 0 });
|
|
3325
|
+
continue;
|
|
3326
|
+
}
|
|
3234
3327
|
if (bodyRoles[p.name] !== 'surface') continue;
|
|
3235
3328
|
const [cols, rows] = resolveTurnGrid(bodySpec, p.name, cfg.turn);
|
|
3236
3329
|
totalGridTriangles += 2 * (cols - 1) * (rows - 1);
|
|
@@ -3251,6 +3344,7 @@ export function buildWaistPairSource(
|
|
|
3251
3344
|
{ name: BODYSHIFT_BONE, parent: bodyRoot, x: 0, y: 0 },
|
|
3252
3345
|
...(hasRear ? [{ name: BODY_REAR_SHIFT_BONE, parent: bodyRoot, x: 0, y: 0 }] : []),
|
|
3253
3346
|
...surfBones,
|
|
3347
|
+
...unitMeshBones,
|
|
3254
3348
|
];
|
|
3255
3349
|
bones.splice(bodyIdx + 1, 0, ...carriers);
|
|
3256
3350
|
const bodyDialBone = bodySpec.slider ?? BODY_YAW_DIAL_BONE;
|
|
@@ -3259,21 +3353,29 @@ export function buildWaistPairSource(
|
|
|
3259
3353
|
}
|
|
3260
3354
|
|
|
3261
3355
|
const boneByName = new Map(bones.map((b) => [b.name, b]));
|
|
3356
|
+
const bodyCarriers = new Set<string>(carriers.map((b) => b.name));
|
|
3357
|
+
const assertNotBodyTurnCarrier = (boneName: string, targetParent: string): void => {
|
|
3358
|
+
if (bodyCarriers.has(boneName)) {
|
|
3359
|
+
throw new Error(`turn invariant violated: turn carrier "${boneName}" must never be reparented (target "${targetParent}")`);
|
|
3360
|
+
}
|
|
3361
|
+
};
|
|
3262
3362
|
const torsoRoots = new Set<string>([bodyRoot, 'chest', 'hip', `${bodyRoot}${CONTROL_SUFFIX}`, `chest${CONTROL_SUFFIX}`, `hip${CONTROL_SUFFIX}`]);
|
|
3263
3363
|
const headExclusion = new Set<string>(['head', `head${CONTROL_SUFFIX}`, 'neck', `neck${CONTROL_SUFFIX}`, FACESHIFT_BONE, REAR_SHIFT_BONE]);
|
|
3264
3364
|
const reparentFromTorso = (boneName: string, targetParent: string): void => {
|
|
3365
|
+
assertNotBodyTurnCarrier(boneName, targetParent);
|
|
3265
3366
|
if (torsoRoots.has(boneName) || headExclusion.has(boneName)) return;
|
|
3266
3367
|
let cur = boneByName.get(boneName);
|
|
3267
3368
|
while (
|
|
3268
3369
|
cur !== undefined &&
|
|
3269
3370
|
cur.parent !== undefined &&
|
|
3270
3371
|
!torsoRoots.has(cur.parent) &&
|
|
3271
|
-
cur.parent
|
|
3372
|
+
!bodyCarriers.has(cur.parent) &&
|
|
3272
3373
|
!headExclusion.has(cur.parent)
|
|
3273
3374
|
) {
|
|
3274
3375
|
cur = boneByName.get(cur.parent);
|
|
3275
3376
|
}
|
|
3276
3377
|
if (cur !== undefined && cur.parent !== undefined && torsoRoots.has(cur.parent) && !torsoRoots.has(cur.name) && !headExclusion.has(cur.name)) {
|
|
3378
|
+
assertNotBodyTurnCarrier(cur.name, targetParent);
|
|
3277
3379
|
const oldParent = cur.parent;
|
|
3278
3380
|
if (oldParent !== bodyRoot) {
|
|
3279
3381
|
const oldTr = world.get(oldParent);
|
|
@@ -3295,30 +3397,119 @@ export function buildWaistPairSource(
|
|
|
3295
3397
|
if (torsoRoots.has(stillSl.bone)) stillSl.bone = carrierBone;
|
|
3296
3398
|
else reparentFromTorso(stillSl.bone, carrierBone);
|
|
3297
3399
|
}
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3300
|
-
if (
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
|
|
3400
|
+
for (const slotEntry of finalSlots) {
|
|
3401
|
+
if (slotEntry.name !== part && !slotEntry.name.startsWith(`${part}__island`)) continue;
|
|
3402
|
+
if (torsoRoots.has(slotEntry.bone)) slotEntry.bone = carrierBone;
|
|
3403
|
+
const atts = skin[slotEntry.name] ?? {};
|
|
3404
|
+
for (const att of Object.values(atts)) {
|
|
3405
|
+
if (!('type' in att) || att.weights === undefined) continue;
|
|
3406
|
+
for (const row of att.weights) {
|
|
3407
|
+
for (const w of row) {
|
|
3408
|
+
if (torsoRoots.has(w.bone)) {
|
|
3409
|
+
if (w.bone !== bodyRoot) {
|
|
3410
|
+
const oldTr = world.get(w.bone);
|
|
3411
|
+
if (oldTr !== undefined) {
|
|
3412
|
+
const [wx, wy] = toWorld(oldTr, w.x, w.y);
|
|
3413
|
+
const [lx, ly] = toBoneLocal(bodyTransform, wx, wy);
|
|
3414
|
+
w.x = places(lx);
|
|
3415
|
+
w.y = places(ly);
|
|
3416
|
+
}
|
|
3311
3417
|
}
|
|
3418
|
+
w.bone = carrierBone;
|
|
3419
|
+
} else {
|
|
3420
|
+
reparentFromTorso(w.bone, carrierBone);
|
|
3312
3421
|
}
|
|
3313
|
-
w.bone = carrierBone;
|
|
3314
|
-
} else {
|
|
3315
|
-
reparentFromTorso(w.bone, carrierBone);
|
|
3316
3422
|
}
|
|
3317
3423
|
}
|
|
3318
3424
|
}
|
|
3319
3425
|
}
|
|
3320
3426
|
};
|
|
3321
3427
|
|
|
3428
|
+
const bodyUnitRootOwner = new Map<string, { part: string; bone: string; rootLabel: string }>();
|
|
3429
|
+
const rebindBodyUnitMeshToCarrier = (part: string): void => {
|
|
3430
|
+
const unitBone = turnUnitBone(part);
|
|
3431
|
+
const bound: string[] = [];
|
|
3432
|
+
const addBound = (bName: string): void => {
|
|
3433
|
+
if (!bound.includes(bName)) bound.push(bName);
|
|
3434
|
+
};
|
|
3435
|
+
for (const sl of finalSlots) {
|
|
3436
|
+
if (sl.name !== part && !sl.name.startsWith(`${part}__island`)) continue;
|
|
3437
|
+
const atts = skin[sl.name] ?? {};
|
|
3438
|
+
let hasWeights = false;
|
|
3439
|
+
for (const att of Object.values(atts)) {
|
|
3440
|
+
if ('type' in att && att.weights !== undefined && att.weights.length > 0) {
|
|
3441
|
+
hasWeights = true;
|
|
3442
|
+
for (const row of att.weights) {
|
|
3443
|
+
for (const w of row) addBound(w.bone);
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
if (!hasWeights) addBound(sl.bone);
|
|
3448
|
+
}
|
|
3449
|
+
const stillSl = slotByName.get(`${part}${STILL_SUFFIX}`);
|
|
3450
|
+
if (stillSl !== undefined) addBound(stillSl.bone);
|
|
3451
|
+
const uncarried: string[] = [];
|
|
3452
|
+
const sharedRoots = new Set<string>();
|
|
3453
|
+
let hasShared = false;
|
|
3454
|
+
for (const bName of bound) {
|
|
3455
|
+
if (headExclusion.has(bName)) {
|
|
3456
|
+
uncarried.push(bName);
|
|
3457
|
+
continue;
|
|
3458
|
+
}
|
|
3459
|
+
if (torsoRoots.has(bName) || bName === unitBone) continue;
|
|
3460
|
+
let cur = boneByName.get(bName);
|
|
3461
|
+
while (
|
|
3462
|
+
cur !== undefined &&
|
|
3463
|
+
cur.parent !== undefined &&
|
|
3464
|
+
!torsoRoots.has(cur.parent) &&
|
|
3465
|
+
!bodyCarriers.has(cur.parent) &&
|
|
3466
|
+
!headExclusion.has(cur.parent)
|
|
3467
|
+
) {
|
|
3468
|
+
cur = boneByName.get(cur.parent);
|
|
3469
|
+
}
|
|
3470
|
+
if (
|
|
3471
|
+
cur === undefined ||
|
|
3472
|
+
cur.parent === undefined ||
|
|
3473
|
+
(!torsoRoots.has(cur.parent) && !bodyCarriers.has(cur.parent)) ||
|
|
3474
|
+
torsoRoots.has(cur.name) ||
|
|
3475
|
+
headExclusion.has(cur.name) ||
|
|
3476
|
+
bodyCarriers.has(cur.name)
|
|
3477
|
+
) {
|
|
3478
|
+
uncarried.push(bName);
|
|
3479
|
+
continue;
|
|
3480
|
+
}
|
|
3481
|
+
const rootLabel = cur.name.endsWith(CONTROL_SUFFIX) ? cur.name.slice(0, -CONTROL_SUFFIX.length) : cur.name;
|
|
3482
|
+
const owner = bodyUnitRootOwner.get(cur.name);
|
|
3483
|
+
if (owner !== undefined && owner.part !== part) {
|
|
3484
|
+
hasShared = true;
|
|
3485
|
+
if (!sharedRoots.has(cur.name)) {
|
|
3486
|
+
sharedRoots.add(cur.name);
|
|
3487
|
+
const sharedDetail =
|
|
3488
|
+
owner.bone === bName
|
|
3489
|
+
? `bone "${bName}"${bName === owner.rootLabel ? '' : ` (under "${owner.rootLabel}")`}`
|
|
3490
|
+
: `chain root "${owner.rootLabel}" ("${owner.part}" binds "${owner.bone}", "${part}" binds "${bName}")`;
|
|
3491
|
+
fail(
|
|
3492
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
3493
|
+
`config.turn.body.roles.${part}`,
|
|
3494
|
+
`declares "${part}" as "unit", and config.meshes.${part} shares ${sharedDetail} with "unit" mesh "${owner.part}" (config.turn.body.roles.${owner.part}); each "unit" mesh reparents its bound chain root under its own "<part>_unit" carrier, so two "unit" meshes cannot share a bone or chain under "${bodyRoot}"`,
|
|
3495
|
+
);
|
|
3496
|
+
}
|
|
3497
|
+
} else if (owner === undefined) {
|
|
3498
|
+
bodyUnitRootOwner.set(cur.name, { part, bone: bName, rootLabel });
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
if (uncarried.length > 0) {
|
|
3502
|
+
fail(
|
|
3503
|
+
'CONFIG_TURN_UNIT_MESH_BONES',
|
|
3504
|
+
`config.turn.body.roles.${part}`,
|
|
3505
|
+
`declares "${part}" as "unit", and config.meshes.${part} binds bone(s) ${uncarried.map((b) => `"${b}"`).join(', ')} outside the "${bodyRoot}" torso subtree, which cannot be carried by "${unitBone}" under "${BODYSHIFT_BONE}"; bind a body "unit" mesh only to the torso root or bones and chains under it`,
|
|
3506
|
+
);
|
|
3507
|
+
return;
|
|
3508
|
+
}
|
|
3509
|
+
if (hasShared) return;
|
|
3510
|
+
rebindBodyPartToCarrier(part, unitBone);
|
|
3511
|
+
};
|
|
3512
|
+
|
|
3322
3513
|
for (const [part, role] of Object.entries(bodyRoles)) {
|
|
3323
3514
|
if (role === 'unit') {
|
|
3324
3515
|
if (cfg.regions[part] !== undefined) {
|
|
@@ -3345,7 +3536,7 @@ export function buildWaistPairSource(
|
|
|
3345
3536
|
const st = stills[part];
|
|
3346
3537
|
if (st !== undefined) reparentFromTorso(st.bone, BODYSHIFT_BONE);
|
|
3347
3538
|
} else if (cfg.meshes[part] !== undefined) {
|
|
3348
|
-
|
|
3539
|
+
rebindBodyUnitMeshToCarrier(part);
|
|
3349
3540
|
}
|
|
3350
3541
|
} else if (role === 'rear' && hasRear) {
|
|
3351
3542
|
if (cfg.regions[part] !== undefined) {
|
package/src/turn.ts
CHANGED
|
@@ -245,6 +245,11 @@ export function turnSurfaceBone(part: string): string {
|
|
|
245
245
|
return `${part}_surface`;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
/** The carrier bone that carries a 2.5D `'unit'` mesh part (`<part>_unit`) under `faceshift` / `bodyshift` (#790). */
|
|
249
|
+
export function turnUnitBone(part: string): string {
|
|
250
|
+
return `${part}_unit`;
|
|
251
|
+
}
|
|
252
|
+
|
|
248
253
|
/** Optional 2.5D body-yaw turn block under `config.turn.body` (#787). */
|
|
249
254
|
export interface TurnBodySpec {
|
|
250
255
|
pivot?: number;
|
|
@@ -1596,10 +1601,16 @@ function buildDepth25DTurnGroup(
|
|
|
1596
1601
|
for (const [part, role] of Object.entries(roles)) {
|
|
1597
1602
|
if (role !== 'unit') continue;
|
|
1598
1603
|
const regSpec = opts.regions[part];
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1604
|
+
let baseBone: string | undefined;
|
|
1605
|
+
let candidateBones: string[] = [];
|
|
1606
|
+
if (regSpec !== undefined) {
|
|
1607
|
+
baseBone = typeof regSpec === 'string' ? regSpec : regSpec.bone;
|
|
1608
|
+
const stillBone = opts.stills[part]?.bone;
|
|
1609
|
+
candidateBones = [baseBone, ...(stillBone === undefined ? [] : [stillBone])].filter((b) => carrierChildren.has(b));
|
|
1610
|
+
} else {
|
|
1611
|
+
const uBone = turnUnitBone(part);
|
|
1612
|
+
if (carrierChildren.has(uBone)) candidateBones = [uBone];
|
|
1613
|
+
}
|
|
1603
1614
|
if (candidateBones.length === 0) continue;
|
|
1604
1615
|
|
|
1605
1616
|
for (const bName of candidateBones) {
|
|
@@ -1611,7 +1622,26 @@ function buildDepth25DTurnGroup(
|
|
|
1611
1622
|
} else if (typeof explicitBoneDepth === 'number' && Number.isFinite(explicitBoneDepth)) {
|
|
1612
1623
|
resolved = explicitBoneDepth;
|
|
1613
1624
|
} else if (primarySurface !== undefined) {
|
|
1614
|
-
|
|
1625
|
+
let pt: readonly [number, number] | undefined =
|
|
1626
|
+
opts.boneLandmarks.get(bName) ??
|
|
1627
|
+
(baseBone === undefined ? undefined : opts.boneLandmarks.get(baseBone));
|
|
1628
|
+
if (pt === undefined && regSpec === undefined) {
|
|
1629
|
+
const childPts: Array<readonly [number, number]> = [];
|
|
1630
|
+
for (const child of rig.bones) {
|
|
1631
|
+
if (child.parent !== bName) continue;
|
|
1632
|
+
const bare = child.name.endsWith('_ctl') ? child.name.slice(0, -4) : child.name;
|
|
1633
|
+
const cp = opts.boneLandmarks.get(child.name) ?? opts.boneLandmarks.get(bare);
|
|
1634
|
+
if (cp !== undefined) childPts.push(cp);
|
|
1635
|
+
}
|
|
1636
|
+
if (childPts.length > 0) {
|
|
1637
|
+
const sx = childPts.reduce((acc, p) => acc + p[0], 0) / childPts.length;
|
|
1638
|
+
const sy = childPts.reduce((acc, p) => acc + p[1], 0) / childPts.length;
|
|
1639
|
+
pt = [sx, sy];
|
|
1640
|
+
} else {
|
|
1641
|
+
const partRec = partMap.get(part);
|
|
1642
|
+
if (partRec !== undefined) pt = [partRec.x + partRec.w / 2, partRec.y + partRec.h / 2];
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1615
1645
|
if (pt !== undefined) {
|
|
1616
1646
|
const { rec, ext, zRef } = primarySurface;
|
|
1617
1647
|
const padX = Math.floor((ext.width - rec.w) / 2);
|