rig-parts 2.59.0 → 2.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/cli.ts +79 -2
- package/docs/AUTHORING.md +105 -18
- package/docs/DEPTH.md +40 -7
- package/docs/STABILITY.md +29 -1
- package/package.json +1 -1
- package/src/config.ts +12 -8
- package/src/depthworkflow.ts +292 -6
- package/src/localweights.ts +20 -12
- package/src/rig.ts +6 -2
package/README.md
CHANGED
|
@@ -277,6 +277,7 @@ Command details and config saving are in the [command reference](docs/AUTHORING.
|
|
|
277
277
|
| `check-parts` | [Check assembled parts' integrity and write a report](docs/AUTHORING.md#check-parts) |
|
|
278
278
|
| `diff-components` | [List every place the stacked parts differ from the painting](docs/AUTHORING.md#whole-figure-difference-inventory) |
|
|
279
279
|
| `diff-drafts` | [Compare two assemble outputs](docs/AUTHORING.md#command-reference) |
|
|
280
|
+
| `depth-place` | [Place body parts from a whole-painting depth map](docs/DEPTH.md#optional-place-body-parts-from-a-whole-painting-map) |
|
|
280
281
|
| `depth-prepare` | [Write one depth-model input image per part](docs/DEPTH.md#1-prepare-one-inference-image-per-part) |
|
|
281
282
|
| `depth-map` | [Convert a NumPy array to a depth or normals map](docs/DEPTH.md#convert-a-numpy-array) |
|
|
282
283
|
| `depth-bind` | [Bind a depth map to its prepared input](docs/DEPTH.md#3-bind-every-map-to-its-prepared-input) |
|
package/cli.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { assemblyChangeDetail, assemblyConfigChanges } from './src/assembly-read
|
|
|
3
3
|
import { diffComponentsCommand } from './src/diffcomponents.ts';
|
|
4
4
|
import { DIFF_DRAFTS_SPEC, diffDraftsCommand } from './src/diffdrafts.ts';
|
|
5
5
|
import { applyTakenLayers } from './src/takelayers.ts';
|
|
6
|
-
import { applyDepth, bindDepthMap, prepareDepth } from './src/depthworkflow.ts';
|
|
6
|
+
import { applyDepth, bindDepthMap, type DepthPlacementTurnCheck, prepareDepth, stageDepthPlacement } from './src/depthworkflow.ts';
|
|
7
7
|
import { depthMapFail } from './src/depthmaps.ts';
|
|
8
8
|
import { modelArrayMap, serializeModelArrayMap } from './src/modelarray.ts';
|
|
9
9
|
import { externalReceipt } from './src/externalreceipt.ts';
|
|
@@ -36,7 +36,7 @@ import { coreCfg, DEFAULT_GROW_PX, runForeground } from './src/plate.ts';
|
|
|
36
36
|
import { type CharacterConfig, loadClothConfig, loadConfig, loadEarlyConfig, loadPaintConfig } from './src/config.ts';
|
|
37
37
|
import { type ConfigWritePatch, onlyMissingAttachments } from './src/configwrite.ts';
|
|
38
38
|
import { configWriteLines, type ConfigWriteTarget, readConfigWriteTarget, separateConfigWriteTarget, stageConfigWrite, type StagedConfigWrite } from './tools/configwrite.ts';
|
|
39
|
-
import { failLine, guidePointer, PartsError, type Problem } from './src/errors.ts';
|
|
39
|
+
import { failLine, guidePointer, PartsError, type Problem, problemLine } from './src/errors.ts';
|
|
40
40
|
import { GUIDE_DOC, type GuideAnswer, guideRule, guideSection } from './src/guide.ts';
|
|
41
41
|
import { proposeHeadBox, type Box } from './src/headbox.ts';
|
|
42
42
|
import { headCropPreflight, headCropPreflightLines } from './src/headcroppreflight.ts';
|
|
@@ -102,6 +102,11 @@ usage:
|
|
|
102
102
|
Write per-part inference PNGs on neutral gray, upscaled and padded as
|
|
103
103
|
declared, plus a source-hashed manifest. No model is bundled or called.
|
|
104
104
|
|
|
105
|
+
rig-parts depth-place --parts <assembled-dir> --config <depth-recipe.json> --rig-config <config.json> --out <empty-dir> [--check-turn]
|
|
106
|
+
Place body parts using a painting-frame depth map and declared polarity,
|
|
107
|
+
scale and anchor. Write recipe.json, config.json and depth-place-report.json.
|
|
108
|
+
--check-turn applies the placed recipe and runs the rig gate in scratch.
|
|
109
|
+
|
|
105
110
|
rig-parts depth-map --array <file.npy> --input <prepared.png> --kind <depth|normals>
|
|
106
111
|
--part <name> --out <map.json> [--padding LEFT,TOP,RIGHT,BOTTOM]
|
|
107
112
|
Convert little-endian float32/float64 C-order NumPy values to rig-parts-map/1.
|
|
@@ -1271,6 +1276,7 @@ const TAKES = {
|
|
|
1271
1276
|
'depth-map': { valued: ['--array', '--input', '--kind', '--part', '--out', '--padding'], switches: ['--help'] },
|
|
1272
1277
|
'depth-bind': { valued: ['--map', '--input', '--part'], switches: ['--help'] },
|
|
1273
1278
|
'depth-prepare': { valued: ['--parts', '--config', '--out'], switches: ['--help'] },
|
|
1279
|
+
'depth-place': { valued: ['--parts', '--config', '--rig-config', '--out'], switches: ['--check-turn', '--help'] },
|
|
1274
1280
|
'depth-apply': { valued: ['--parts', '--manifest', '--config', '--rig-config', '--out', '--groups'], switches: ['--help'] },
|
|
1275
1281
|
layers: { valued: ['--export', '--template', '--canvas', '--full', '--source', '--config'], switches: ['--help'] },
|
|
1276
1282
|
sheet: { valued: ['--source', '--layers', '--out', '--cell', '--cols'], switches: ['--help'] },
|
|
@@ -3038,6 +3044,76 @@ function cmdDepthApply(args: string[]): number {
|
|
|
3038
3044
|
} catch (error) { return printRefusal(error); }
|
|
3039
3045
|
}
|
|
3040
3046
|
|
|
3047
|
+
function depthPlaceTurnCheck(parts: string, scratch: string, placed: { recipe: string; config: string }): DepthPlacementTurnCheck {
|
|
3048
|
+
const config = placed.recipe, rigConfig = placed.config;
|
|
3049
|
+
const prepared = join(scratch, 'prepared'), applied = join(scratch, 'applied');
|
|
3050
|
+
let stage: 'prepare' | 'apply' | 'rig' = 'prepare';
|
|
3051
|
+
type WindingFinding = Extract<DepthPlacementTurnCheck, { status: 'refused' }>['winding'][number];
|
|
3052
|
+
const findings = new Map<string, WindingFinding>();
|
|
3053
|
+
try {
|
|
3054
|
+
prepareDepth({ parts, config, out: prepared });
|
|
3055
|
+
stage = 'apply';
|
|
3056
|
+
applyDepth({ parts, config, rigConfig, manifest: join(prepared, 'manifest.json'), out: applied }, () => {});
|
|
3057
|
+
stage = 'rig';
|
|
3058
|
+
const bin = findRigc(import.meta.dir, process.env.PATH ?? '');
|
|
3059
|
+
const configPath = join(applied, 'config.json');
|
|
3060
|
+
const { meshes } = loadConfig(configPath);
|
|
3061
|
+
rigStage({ config: configPath, parts: applied, out: join(scratch, 'rig') }, rigcRunner(bin), join(scratch, 'gate'), line => {
|
|
3062
|
+
const address = /^\s*FAIL\s+(A39_DEFORM_KEEPS_TRIANGLE_WINDING): animation "([^"]+)"(?: \(applied by slider "([^"]+)", not played on a track\))? deform ([^/]+)\/(\S+) (.+)$/.exec(line);
|
|
3063
|
+
if (address === null) return;
|
|
3064
|
+
const [, rule, animation, frame, slot, attachment, detail] = address;
|
|
3065
|
+
const witness = /^(?:BETWEEN )?key (\d+) \(t=[^)]+\)(?: and key (\d+) \(t=[^)]+\), [^:]+)?: (\d+) of (\d+) triangle\(s\) reverse winding\b/.exec(detail);
|
|
3066
|
+
if (witness === null) return;
|
|
3067
|
+
const [, key, endKey, reversed, triangles] = witness;
|
|
3068
|
+
const owners = Object.keys(meshes).filter(part => slot.startsWith(`${part}__island`));
|
|
3069
|
+
const part = !Object.hasOwn(meshes, slot) && owners.length === 1 ? owners[0] : slot;
|
|
3070
|
+
findings.set(line.trim(), {
|
|
3071
|
+
rule, animation, part, attachment, key: Number(key),
|
|
3072
|
+
...(endKey === undefined ? {} : { endKey: Number(endKey) }),
|
|
3073
|
+
reversedTriangles: Number(reversed), triangles: Number(triangles),
|
|
3074
|
+
...(frame === undefined ? {} : { frame }),
|
|
3075
|
+
});
|
|
3076
|
+
});
|
|
3077
|
+
return { status: 'built' };
|
|
3078
|
+
} catch (error) {
|
|
3079
|
+
if (!(error instanceof PartsError)) throw error;
|
|
3080
|
+
const problems = error.problems.map(({ code, object, detail }) => ({ code, object: object.replaceAll(scratch, '<scratch>'), detail: detail.replaceAll(scratch, '<scratch>') }));
|
|
3081
|
+
return { status: 'refused', stage, problems, winding: [...findings.values()] };
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
function cmdDepthPlace(args: string[]): number {
|
|
3086
|
+
const checks = args.filter(arg => arg === '--check-turn').length;
|
|
3087
|
+
if (checks > 1) return usage('--check-turn is given twice');
|
|
3088
|
+
const f = flags(args.filter(arg => arg !== '--check-turn'), 'depth-place', ['--parts', '--config', '--rig-config', '--out']);
|
|
3089
|
+
if (typeof f === 'string') return usage(f);
|
|
3090
|
+
try {
|
|
3091
|
+
const input = { parts: f.get('--parts')!, config: f.get('--config')!, rigConfig: f.get('--rig-config')!, out: f.get('--out')! };
|
|
3092
|
+
const placement = stageDepthPlacement(input);
|
|
3093
|
+
if (checks === 0) placement.write(input.out);
|
|
3094
|
+
else {
|
|
3095
|
+
const scratch = realpathSync(mkdtempSync(join(tmpdir(), 'rig-parts-depth-place-')));
|
|
3096
|
+
try {
|
|
3097
|
+
const placed = placement.write(join(scratch, 'placed'));
|
|
3098
|
+
const check = depthPlaceTurnCheck(input.parts, scratch, placed);
|
|
3099
|
+
placement.write(input.out, check);
|
|
3100
|
+
console.log(`depth-place: turn check ${check.status}`);
|
|
3101
|
+
if (check.status === 'refused') for (const problem of check.problems) {
|
|
3102
|
+
console.log(`depth-place: turn check ${problemLine(problem)}${guidePointer(problem.code)}`);
|
|
3103
|
+
}
|
|
3104
|
+
} finally { rmSync(scratch, { recursive: true, force: true }); }
|
|
3105
|
+
}
|
|
3106
|
+
const { anchor, near, pivot, scale, parts } = placement.report;
|
|
3107
|
+
console.log(`depth-place: anchor=${anchor} near=${near} scale=${scale} pivot=${pivot}`);
|
|
3108
|
+
for (const row of parts) {
|
|
3109
|
+
const round = row.round === undefined ? '' : ` roundScale=${row.round.scale} sections=${row.round.sections} IQR=${JSON.stringify(row.round.iqr)}`;
|
|
3110
|
+
console.log(`depth-place: ${row.part} visible=${row.visibleCount} fraction=${row.visibleFraction} mapMedian=${row.rawMedian} rigMedian=${row.rigMedian} impliedReliefScale=${row.reliefRatio}${round}`);
|
|
3111
|
+
}
|
|
3112
|
+
console.log('depth-place: wrote recipe.json, config.json and depth-place-report.json');
|
|
3113
|
+
return EXIT_OK;
|
|
3114
|
+
} catch (error) { return printRefusal(error); }
|
|
3115
|
+
}
|
|
3116
|
+
|
|
3041
3117
|
function main(argv: string[]): number | Promise<number> {
|
|
3042
3118
|
const [command, ...rest] = argv;
|
|
3043
3119
|
if (command === undefined || command === '--help' || command === '-h' || command === 'help') {
|
|
@@ -3055,6 +3131,7 @@ function main(argv: string[]): number | Promise<number> {
|
|
|
3055
3131
|
if (command === 'layers') return cmdLayers(rest);
|
|
3056
3132
|
if (command === 'depth-prepare') return cmdDepthPrepare(rest);
|
|
3057
3133
|
if (command === 'depth-map') return cmdDepthMap(rest);
|
|
3134
|
+
if (command === 'depth-place') return cmdDepthPlace(rest);
|
|
3058
3135
|
if (command === 'edited-part') return cmdEditedPart(rest);
|
|
3059
3136
|
if (command === 'external-receipt') return cmdExternalReceipt(rest);
|
|
3060
3137
|
if (command === 'bust-landmarks') return cmdBustLandmarks(rest);
|
package/docs/AUTHORING.md
CHANGED
|
@@ -198,7 +198,7 @@ read by no CPU stage).
|
|
|
198
198
|
| `bones` | rig; `propose --from-config` | **proposed** by `propose`, then corrected. A single bone `{name, parent, at, tip?}` or a chain `{chain, parent, points, tip, link_inherit?}` whose links are named `<chain>0 … <chain>n`. Parents come before children. In `rig.json` each link is **turned along its chain** — `rotation` is the direction from its origin to the next link's (the last link's to `tip`) and `length` that distance (issue #73), so a physics constraint added downstream finds a lever; under `--idle-keys ctl` the link's `<link>_ctl` carries the turn and the length and the link sits at local rotation 0 beneath it. A single bone with a `tip` is turned the same way, towards its tip, with that distance as its length (issue #239); a tip on the bone's own origin is refused (`RIG_TIP_DISTINCT`). The five face bones `eye_r`, `eye_l`, `brow_r`, `brow_l` and `mouth` (by name, when one has no tip of its own) are turned to the eye line — the line through the origins of `eye_r` and `eye_l` as `bones` writes them, read image-left to image-right, drawn when parts.json holds both an `eyewhite-r` and an `eyewhite-l` part — so the blink's `scaley` squashes across the eye line on a tilted head; move an eye bone and the line moves with it. With one eyewhite or none, or an eye bone missing, the rig stage's `face axis:` line says so and they keep the page's axes. A bone under a face bone keeps the face's axis. With the line, `rig.json` also declares `invariants.axes` — one entry, `"face"`, through `eye_r` and `eye_l`, holding the turned face bones (and their controls) — so rig-c's gate holds the build to the line; the line is the one rigc draws through the same two bones, so the tolerance is only the float floor — the largest gap the emitted (float32) bones have to it, rounded up to 6 places plus one 6-place unit — and the `face axis:` line prints it. With the line the rig stage also adds `head_up` (issue #250): a slotless bone under `head`, at head's origin, turned to the eye line + 90 degrees and as long as the eye midpoint lies from head's origin along that axis — the head's frame, which a rule that needs it reads; `head` keeps its own frame, so no key on it or under it changes meaning, and a config bone of that name is refused (`RIG_HEAD_UP_NAME_FREE`). A face bone with its own `tip` is held too (issue #258), in a second entry, `"face_tips"`, when its tip lies along the line within whole-pixel rounding — a tip written in whole pixels sits at most sqrt(2)/2 px off the point of the line it stands for, so its direction may sit up to asin((sqrt(2)/2) / length) degrees off — with its tolerance measured the same way; a tip further off is the bone's own axis, and the `face axis:` line names it with its gap and that bound. A failure is rig-c's `A51_BONES_LIE_ALONG_THEIR_DECLARED_AXIS` line, which names the bone and the fix (rig-c's `docs/AUTHORING.md` §3.7 and §5.2); with no line no entry is written and A51 reports SKIP. Every region on a turned bone is turned back, so the setup pose does not move. Any other single bone keeps world rotation 0; one whose parent is a link is turned back upright. A single bone may declare `inherit` (issue #348): what it takes from its parent's transform, one of rig-c's own mode names exactly as rig-c's table spells them — `normal`, `onlyTranslation`, `noRotationOrReflection`, `noScale`, `noScaleOrReflection` (rig-c's `RigBone.inherit`) — written to that bone in `rig.json` as declared; any other spelling, `"NoScale"` included (the runtime would fold its first letter; nothing here folds or maps), is refused (`CONFIG_BONE_INHERIT`), and a chain takes no `inherit` (`CONFIG_KEY_KNOWN`). A chain may instead declare `link_inherit` (issue #369), an object mapping its own expanded link names to those same modes, for example `"link_inherit": {"leg_r1": "noScale"}`. Only the named link changes; omitted links inherit normally. A key outside this chain is `CONFIG_NAME_RESOLVES`, with this chain's valid link names in the detail; a non-object or non-string mode is `CONFIG_FIELD_TYPE`, and another mode spelling is `CONFIG_BONE_INHERIT`. The mode is forwarded to the expanded link, or to its control under `--idle-keys ctl`, by the same rule as a single bone. This is an authored opt-in: `propose` does not add it. Its setup rotation is the turn from where rig-c's own poser puts the bone with no rotation of its own under that mode, so it still stands upright (or along its tip) at the setup pose. Where the idle gives the bone a `<bone>_ctl`, the mode goes on the control: the control is the bone the parent's rotation reaches, and the bone under it inherits normally, so the idle's keys moved onto the control still turn it. A foot that does not take its shin's rotation (`noRotationOrReflection` or `onlyTranslation`) keeps its shoe level while the leg is posed (`FEET_STAY_LEVEL`, §7); which mode is the author's. `noScale` keeps a shin or shoe's shape under a scaled parent but still takes the parent's rotation: a shoe that must also stay level needs a separate rotation constraint, for example a transform constraint from an unrotated bone. This does not change the proposed feet's existing inheritance or `FEET_STAY_LEVEL` default. An automatic mesh weighted through a bone with a mode other than `normal` gets no derived amplitude (its row names the bone) and no residual envelope (rig-c's `SKINNING_RANGE_UNSUPPORTED`). Absent, `rig.json` carries no `inherit` and no byte moves |
|
|
199
199
|
| `meshes.<part>` | rig | **proposed**, then corrected. Generated modes below; `explicit` transfers an accepted mesh (see “An accepted mesh”). Exactly one mode is allowed. `grid` (the lattice: cell size, px — what `propose` writes for non-torso parts: by default one spacing for the figure, round(H / 37) rig px with H the height of every part's box together, a part whose tenth of its short side is already coarser keeping that, and under `propose --grid-rule part` the reference's tenth of the part's short side clamped to 5..36, issue #265), `contour` (the outline mode, authored or drafted for the chest carrier; the next row and "A contour mesh" below) or `auto` (the automatic mode, authored; "An automatic mesh" below) — two, or none, is `CONFIG_MESH_MODE`. In distance-generated modes: `r` (added to every distance before weighting: `w = 1/(d + r)²`), `segments` (a chain name, a bone name with a `tip`, or `[bone, [x0,y0], [x1,y1]]`), and, **authored**, optional, `exponent` (issue #161): a number above 0 that replaces the 2 in that rule, `w = 1/(d + r)^exponent` — a larger one hands each vertex more fully to its nearest bone; absent is 2 and changes no byte, a value that is not a number above 0 is `CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`, and a declared one is echoed as `exponent` in the mesh's `mesh_report.json` row; the exponent is the distance rule's, so declared beside `rule: "heat"` it is refused (`CONFIG_FIELD_TYPE` at `meshes.<part>.exponent`). The segment list is the one authored decision about a layer: which bones may pull it. The slot's bone is the first segment's. Optional `rule` (issue #161): `"distance"` — the rule above, and what an absent `rule` means (every byte is the same) — or `"heat"`, bone heat over the part's own silhouette, in every mode: the lattice's art (alpha above 8, less any island a declared `stray` left out) with holes filled, or for `contour` and `auto` the silhouette their outline is traced from (that mode's art — alpha above 8 for `contour`, alpha 1 and above for `auto` — less any island a declared `stray` left out, holes filled, grown by its `margin`); each bound bone's sources are the silhouette pixels whose centre lies within 0.75 px of its segment (a pixel two bones reach goes to the nearer, a tie to the first listed), held at 1 for that bone and 0 for the others; the field is solved by row-major Gauss–Seidel over-relaxation to a sweep change under 1e-7 within 20000 sweeps; a vertex reads the nearest silhouette pixel and takes the same cap and floor (and `regions`) as the distance rule; `r` is not read. The mesh's `mesh_report.json` row gains `heat` (the constants, each bone's sources and sweeps, the residual). Any other value is `CONFIG_FIELD_TYPE`; a bound bone with no source pixel is `RIG_HEAT_BONE_SOURCE`, an island no bone has a source in `RIG_HEAT_ISLAND_SOURCE`, a solve past its sweep bound `RIG_HEAT_CONVERGED` — none is weighted 0. The rule is chosen per mesh, so `RIG_HEAT_BONE_SOURCE` names three remedies: move the segment onto the art, take the bone out of `segments`, or keep this part on the distance rule — the one to take when the bone anchors the part from outside its art (a torso bone under a neck), since the first moves a bone another part placed and the second drops the anchor (issue #303). On a lattice, `RIG_HEAT_ISLAND_SOURCE` on an island that is dust — at most 4 px and at most 0.1 % of the part's art px, `mesh-draft`'s line — names `meshes.<part>.stray` and the figure that leaves it out, with the value declared; an island above that line keeps the segment remedy, a real piece being a real authoring question. In every mode the mesh's `mesh_report.json` row's `bones` names the bones the emitted model binds for the attachment — the sorted set its weights in the written `rig.json` name, so a `turn` twin (`turn_<part>_<bone>`) or a stopped link's `<link>_d` where those rebind it, never the segment bone it stands for — the same list in every mode, `remesh --delta`'s included (issue #536) Optional `gather: false` keeps an exclusively bound non-segment limb rider at its authored draw position (issue #680); its binding and mesh geometry are unchanged. Remove the key for normal gathering; a non-rider is refused as `RIG_GATHER_RIDER`. `propose` drafts the chest-holding topwear as `contour` instead (issue #986), using the figure tolerance and spacing described below. For a one-layer figure it drafts `trunk_chest` as contour. Other garments keep their existing modes. |
|
|
200
200
|
| `meshes.<part>.influence` | rig | **authored**, optional (issue #378), a mode beside `grid`, `contour` and `auto`: `{cell, radius, across, max, shape, hold_tip?}`, every field but `hold_tip` required, none defaulted. rig-c's `segments` lattice over the part at `cell` px, each vertex pulled by every link of the mesh's `segments` within `radius` px of it — a pull that falls to exactly 0 at `radius` (`shape` `"linear"` or `"smooth"`), across the `segments` entries or only within the nearest one (`across`), the strongest `max` kept. The lattice and the shares are computed by rig-c's own promised functions (`buildSegmentsLattice`, `segmentDistance`, `influenceShares`), so the rule is rig-c's (its AUTHORING §3.4.7), and the mesh is written with explicit weights like every other mode. `radius` is a length on this part: the rig stage measures the farthest lattice vertex's distance to its nearest link and refuses a radius at or under it (`RIG_INFLUENCE_REACH`), naming the distance. `propose --cloth` drafts it when a recipe declares `influence` and no `radius` (issue #518): the farthest vertex's distance plus 3 of the part's lattice cells, printed on a `LINT` line with both figures. Measured on the cloth fixture and the public `wind` example (#513: 8 covered parts, `render --folds` with the physics on under wind and a hip sway of 8° and 30°): a radius just above the floor folds **more** than the lattice (one skirt went from 0 to 55 folded frames), and a larger one is **not** safer (one fringe folded again at about 3–4× its farthest distance); +2 to +6 cells read 0 on every part, +2 at the edge. That reading counted folds only; read against `check` as well (the rig as built, under the wind schedule +1 → −1 → calm, `build --environment`, the three covered `wind` parts at the same number of cells), the window that holds is **+2 to +3 cells**, and +4 is the ceiling: `wind` `bottomwear`'s `CHECK_TIP_OVER_ROOT` ratio is 1.898 on the lattice, 1.801 at +2 cells, 1.590 at +3 and **1.471 at +4**, under the floor 1.4725, so the build fails there, and 1.351 at +6 (#513, rig-parts 1.52.0, rigc 2.60.0; the lattice, +3 and +4 read again on rig-parts 1.54.0, rigc 2.60.0, the same figures, #599). The drafted +3 sits in that window, one cell under the ceiling (no radius between +3 and +4 was read), and the window is a hypothesis until a third subject — each edge rests on one part — so state `radius` in the recipe to keep your own. `r`, `exponent`, `rule`, `influences`, `stray` and `ribs` belong to the distance rule or another mode and are refused beside it (`CONFIG_INFLUENCE_MODE`). `hold_tip` (issue #615) — `true` only, or absent: the pulled shares are smoothed by the lattice's held-fork passes (the cloth recipe's `split.hold_tip` sentence below: four passes of 1-ring mesh-edge averaging, self weight 0.5, floor 0.005) capped at the declared `max`, so no vertex binds more than `max` bones; absent, the shares are rig-c's as pulled and every byte is the one written before the field existed (`false`, a second spelling of absent, is `CONFIG_FIELD_TYPE`). The mesh's `mesh_report.json` row echoes it in `influence`. `propose --cloth` writes it, with `max` raised to at least 8 (the lattice's smoothing cap), on the parts a recipe with `influence` and `split.hold_tip: true` meshes; the rig stage reads it off the mesh and never the recipe. Measured on `wind` `bottomwear` and the cloth fixture's skirt under a 60° hip sway (#615, `render --folds`, physics on): `wind` `bottomwear` folds 41 frames as drafted before the field (max 6) and **0** with `hold_tip` and max 8, against its lattice's 5; with `hold_tip` at max 6 it reads 23, and at max 8 without `hold_tip` 3; the fixture skirt (recipe given `split.hold_tip`) reads 20 before and 0 with it, against its lattice's 0, and 0 at max 8 without it. So the raised `max` carries most of the gap and the smoothing the rest on `wind` (rig-parts 1.54.0, rigc 2.60.0; a split skirt without `hold_tip` is not smoothed and reads its 44 as before). For cloth and hair that should bend as one surface across its chains |
|
|
201
|
-
| `meshes.<part>.contour` | rig | **authored or proposed**, optional (issue #84): `{tolerance, margin, spacing, maxEdge?, budget?, stray?, bridges?, regions?, bust?}`. `tolerance` — rig-c's Douglas–Peucker tolerance on the traced outline, px, 0 or more; `margin` — how far the silhouette grows before it is traced, px: 0, or 1 or more (a pixel joins when its centre lies within `margin` of an art pixel's centre; a value above 0 and below 1 adds nothing and is refused, `CONFIG_FIELD_TYPE`); `spacing` — the background interior spacing, px, above 0; `maxEdge` (issue #265) — the longest outline edge, px, above 0: every simplified edge longer than it is cut into `ceil(length / maxEdge)` equal pieces, each cut point on the 1/256 px grid, before any region or rib touches the outline (absent: nothing is cut, and no byte moves; under 2/256 px the rig stage refuses it, `CONTOUR_PARAMETER`, because two cut points could snap together); the row echoes it in `params` and counts the points it added in `contour.outlineCut`, both only when declared; `budget` — the most vertices the mesh may have (refused above it, nothing thinned); `stray` — the largest island, in art pixels, that may be left out of the mesh (absent: none is); `bridges` (issue #326) — `true`, its one value: islands are read in this order — **dust first** (those `stray` leaves out), **then faint islands** (every pixel's alpha under 64, a quarter of full opacity: left out the same way, their pixels kept in the image but not meshed, so not drawn, and named in the row's `contour.bridges.faint` with their px, brightest alpha and box), **then every visible island is meshed and bridged, whatever the bridge costs** — overdraw is reported, never a reason to drop art; the largest island, or a tie for it, is never left out, faint or not: dropping it would draft the part without its art, and a part whose main body is faint is a question about the layer, which the plan and the author own, not one for the mesh — and the pieces are joined into the one outline rig-c takes by bridges — the kept islands, holes filled, grow together by `margin`, so islands closer than about twice the margin are one grown silhouette, traced as one; each silhouette is traced, simplified, capped, refined and triangulated as a one-island mesh is; then, starting from the silhouette with the most art, the nearest pair of a vertex on the joined outline and one on a silhouette still apart whose quad holds (wound as the mesh, crossing no outline, holding no other vertex, one closed outline after) is joined by that quad, two triangles over no art, until none is apart. Coverage and overshoot read the silhouettes' triangles; a bridge's area is in `meshArea` and in the row's `contour.bridges` (`islands`, `units`, and per join `unit`, `span` — its two crossing edges, px — `area`, `vertices`, `pair`; and `faint`, only when an island was left out as faint), and the row's `params` echoes `bridges`, both only when declared; `art_coverage` counts a faint island's pixels as art not covered. Absent, a second island is refused as below and no byte moves; on one island it writes the mesh the undeclared entry writes. Any other value is `CONFIG_FIELD_TYPE`; beside `ribs` it is `CONTOUR_PARAMETER` (a rib runs across one outline); a join no pair makes is `CONTOUR_BRIDGE`. A bridge stretches with whatever pulls its two ends apart, so it belongs on a part whose pieces ride one bone — the only case `mesh-draft` drafts; a bridge adds no vertex (issue #570): its four corners, `contour.bridges.joins[].vertices`, are outline vertices of the two silhouettes it joins, and they are weighted as every vertex of the mesh is, by distance to every bone the mesh's `segments` name — no step of the weighting reads which island a vertex lies on, so where two islands ride two bones (two legs in one `legwear` on `leg_r` and `leg_l`) each island's vertices, the corners among them, take weight from the other island's bones too (selftest `CW100`: on its fixture the left island's two corners each take 0.35821 from the right island's bone, and none of its vertices less than 0.30431), and a part whose pieces must not pull each other is split into one part per piece; `regions` — local deformation regions, each `{name, shape, bone, spacing, band, cover?}` with `shape` `"circle"` (`cx, cy, r`) or `"polygon"` (`points`, 3 or more): `bone` is the region's control bone (any bone `bones` declares), `spacing` the interior spacing inside the region and its band, `band` the width the bone's weight falls across
|
|
201
|
+
| `meshes.<part>.contour` | rig | **authored or proposed**, optional (issue #84): `{tolerance, margin, spacing, maxEdge?, budget?, stray?, bridges?, regions?, bust?}`. `tolerance` — rig-c's Douglas–Peucker tolerance on the traced outline, px, 0 or more; `margin` — how far the silhouette grows before it is traced, px: 0, or 1 or more (a pixel joins when its centre lies within `margin` of an art pixel's centre; a value above 0 and below 1 adds nothing and is refused, `CONFIG_FIELD_TYPE`); `spacing` — the background interior spacing, px, above 0; `maxEdge` (issue #265) — the longest outline edge, px, above 0: every simplified edge longer than it is cut into `ceil(length / maxEdge)` equal pieces, each cut point on the 1/256 px grid, before any region or rib touches the outline (absent: nothing is cut, and no byte moves; under 2/256 px the rig stage refuses it, `CONTOUR_PARAMETER`, because two cut points could snap together); the row echoes it in `params` and counts the points it added in `contour.outlineCut`, both only when declared; `budget` — the most vertices the mesh may have (refused above it, nothing thinned); `stray` — the largest island, in art pixels, that may be left out of the mesh (absent: none is); `bridges` (issue #326) — `true`, its one value: islands are read in this order — **dust first** (those `stray` leaves out), **then faint islands** (every pixel's alpha under 64, a quarter of full opacity: left out the same way, their pixels kept in the image but not meshed, so not drawn, and named in the row's `contour.bridges.faint` with their px, brightest alpha and box), **then every visible island is meshed and bridged, whatever the bridge costs** — overdraw is reported, never a reason to drop art; the largest island, or a tie for it, is never left out, faint or not: dropping it would draft the part without its art, and a part whose main body is faint is a question about the layer, which the plan and the author own, not one for the mesh — and the pieces are joined into the one outline rig-c takes by bridges — the kept islands, holes filled, grow together by `margin`, so islands closer than about twice the margin are one grown silhouette, traced as one; each silhouette is traced, simplified, capped, refined and triangulated as a one-island mesh is; then, starting from the silhouette with the most art, the nearest pair of a vertex on the joined outline and one on a silhouette still apart whose quad holds (wound as the mesh, crossing no outline, holding no other vertex, one closed outline after) is joined by that quad, two triangles over no art, until none is apart. Coverage and overshoot read the silhouettes' triangles; a bridge's area is in `meshArea` and in the row's `contour.bridges` (`islands`, `units`, and per join `unit`, `span` — its two crossing edges, px — `area`, `vertices`, `pair`; and `faint`, only when an island was left out as faint), and the row's `params` echoes `bridges`, both only when declared; `art_coverage` counts a faint island's pixels as art not covered. Absent, a second island is refused as below and no byte moves; on one island it writes the mesh the undeclared entry writes. Any other value is `CONFIG_FIELD_TYPE`; beside `ribs` it is `CONTOUR_PARAMETER` (a rib runs across one outline); a join no pair makes is `CONTOUR_BRIDGE`. A bridge stretches with whatever pulls its two ends apart, so it belongs on a part whose pieces ride one bone — the only case `mesh-draft` drafts; a bridge adds no vertex (issue #570): its four corners, `contour.bridges.joins[].vertices`, are outline vertices of the two silhouettes it joins, and they are weighted as every vertex of the mesh is, by distance to every bone the mesh's `segments` name — no step of the weighting reads which island a vertex lies on, so where two islands ride two bones (two legs in one `legwear` on `leg_r` and `leg_l`) each island's vertices, the corners among them, take weight from the other island's bones too (selftest `CW100`: on its fixture the left island's two corners each take 0.35821 from the right island's bone, and none of its vertices less than 0.30431), and a part whose pieces must not pull each other is split into one part per piece; `regions` — local deformation regions, each `{name, shape, bone, spacing, band, cover?, falloff?}` with `shape` `"circle"` (`cx, cy, r`) or `"polygon"` (`points`, 3 or more): `bone` is the region's control bone (any bone `bones` declares), `spacing` the interior spacing inside the region and its band, `band` the width the bone's weight falls across. The default eases the outer half of the band. Set `falloff: "linear"` to retain the prior weights (issue #1578). See [A contour mesh](#a-contour-mesh-meshespartcontour-issue-84). Optional `cover` (issue #1548; non-empty part name, `CONFIG_FIELD_TYPE` otherwise; never drafted by `propose`), on a 2.5D turn `"surface"` part whose region `bone` lies in the other turn group's subtree, names the `"surface"` part in that other group (`turn.roles` for head, `turn.body.roles` for body) whose extended depth sheet supplies the region's other-group depth once at `bone`'s setup position (`g · D(z_cover)` across the band, with full-opacity `alpha === 255` support required on `cover`'s art at `bone`'s setup position, `RIG_TURN_BAND_COVER_SUPPORT`; declaring `cover` on a non-surface part, on a bone in the part's own turn group or outside both turn subtrees, or naming an undeclared, non-`"surface"` or sheetless part is `CONFIG_TURN_BAND_COVER`; absent, the band reads the part's own sheet and no byte moves). Every length and position is **rig px**, like every other in the config; the part image is the rig less `(x − 4, y − 4)` (its box less the pad), a translation, so a length is the same number in both. A region's `cx`, `cy`, `r`, `band` and `points` are multiples of 1/256 px (`CONFIG_FIELD_TYPE` otherwise); region names are unique per mesh (`CONFIG_REGION_NAME_UNIQUE`). `bust` (issue #475) — `{apex_r, apex_l, cleavage, alpha?: 0.22, clearance?: 3.8, bone_r?: "boob_r", bone_l?: "boob_l", spacing?: 14}`: derives the two circular regions `bust_r` and `bust_l` from the three rig-px landmarks `apex_r`, `apex_l` and `cleavage` (multiples of 1/256 px, `CONFIG_FIELD_TYPE` otherwise; projecting the torso midline `neck → chest → hip` onto `apex_r → apex_l` misses the cleavage by 14–93 px across all five calibrated 3/4-yaw characters, so all three points are required). With `d_s = \|cleavage − apex_s\|` and `D = \|apex_r − apex_l\|`, each side `s ∈ {r, l}` is placed at `cx = apex_s[0]`, `cy = apex_s[1]` with outer radius `R_s = round(d_s − clearance)`, core radius `r_s = round(alpha × R_s)` and `band_s = R_s − r_s` (`alpha` = 0.22, `clearance` = 3.8 px, `spacing` = 14 px, `bone_r` = `"boob_r"`, `bone_l` = `"boob_l"` by default, reproducing the five calibrated example characters within `<= 6 px`, max `\|ΔR\| = 5 px`, max `\|Δr\| = 3 px`). Refused when `clearance <= 0`, `R_r + R_l >= D`, a derived `r_s <= 0`, or a derived `band_s < 0` (`CONFIG_BUST_CLEARANCE`), when `bone_r` or `bone_l` is not declared in `bones` (`CONFIG_NAME_RESOLVES`), or when `contour.regions` also names `bust_r` or `bust_l` (`CONFIG_REGION_NAME_UNIQUE`). Both `propose` and `rig` read `contour.bust` through `contourRegionsOf` (`deriveBustRegions`), and the derived pair keeps its linear falloff. To write the same circles directly in `contour.regions`, set `falloff: "linear"` on both entries. The alpha threshold is not a field: art is alpha above 8, the lattice's and `check`'s Short outline edges amplify a cap or floor step in the vertex weights; the recorded grid, contour, bust and continuous-cut comparison is in "The weight cut" below. |
|
|
202
202
|
| `meshes.<part>.ribs` | rig | **authored**, optional (issue #188), in the `contour` and `auto` modes: `{<chain>: {stations}, …}`, each key a chain this mesh's `segments` name. Each link of the chain gets a row of vertices across the part at its origin and at `stations` points evenly between its origin and its end (`stations`, a whole number, 0 or more, required; a chain of L links carries L × (stations + 1) ribs), each rib a row of vertices across the part, kept as a row of locked edges; the rule is "Ribs along a chain" under "A contour mesh". Absent places none and changes no byte. Refused: a lattice mesh with ribs (`CONFIG_RIBS_MODE` — its vertices are its grid's corners), a key that is not one of the mesh's chains (`CONFIG_NAME_RESOLVES`), an object naming no chain or a `stations` that is not a whole number from 0 (`CONFIG_FIELD_TYPE`); at the rig stage `CONTOUR_RIB_ART`, `CONTOUR_RIB_LINK`, `CONTOUR_RIB_CROSSING`, `CONTOUR_RIB_EDGE` (the contour refusals). The mesh's `mesh_report.json` row gains `ribs` — the declaration, the ribs placed and the vertices they hold — and its contour report (the source's, in `auto`) lists each rib's vertices |
|
|
203
203
|
| `meshes.<part>.influences` | rig | **authored or proposed**, optional (issue #284), in the `grid` and `contour` modes: `{maxInfluences?, floor?}`, at least one. `maxInfluences` — the most bones that pull one vertex, a whole number 1 or more, or `null`, no cap (every bone the mesh's `segments` name; `null` is the config's spelling of a bound declared absent, as in `maxOvershoot` and `weightJump`); absent is 4. `floor` — `"cut"` (the capped shares normalised, any under 0.03 dropped, the rest normalised again; what an absent `floor` means) or `"continuous"` (0.03 subtracted from every capped share, those at or below 0 dropped, the rest normalised again, so a bone fades out of a vertex instead of leaving it in one step). Absent, the mesh is weighted at 4 and the cut and every byte is the one written before the field existed; declared, it applies under either `rule`, and is echoed as `influences` in the mesh's `mesh_report.json` row. `propose` writes `{maxInfluences: null, floor: "continuous"}` only on a newly drafted contour torso whose segments name a chain or its links, with a note explaining the short-outline-edge weight step (issues #986, #991). Other drafts and authored contour entries retain their policy, and `mesh-draft` carries a lattice's declaration to the contour candidate it drafts. A cap that is not a whole number 1 or more or `null` (the string `"none"` included), another `floor`, or an object naming neither is `CONFIG_FIELD_TYPE`; a vertex the declared cut leaves with no bone is `RIG_INFLUENCES_KEPT`; beside `auto` it is `CONFIG_INFLUENCES_MODE` (that mode's cap and floor are `auto.influences`). What each setting trades is "The weight cut" below |
|
|
204
204
|
| `meshes.<part>.stray` | rig | **authored**, optional (issue #303), in the `grid` mode: the largest island, in art pixels, that may be left out of the lattice — the contour mode's `contour.stray`, with the same meaning, over the same islands (the 4-connected islands of the art, alpha above 8): every island of `stray` art px or fewer is cleared from the art the lattice and, under `rule: "heat"`, its silhouette are built over, except an island as large as the largest, which is never left out (two equal largest pieces both stay). Unlike the contour mode an island above the figure is not refused — the lattice bridges every island it keeps, as it always has. An island that sits in a cell the lattice keeps for other art leaves the lattice unchanged: there `stray` changes only the silhouette `rule: "heat"` reads, and gives back no triangle (demo `bottomwear`'s 2 px island, in the cell kept for the hem's tip, is that case). Absent, nothing is left out and every byte is the one written before the field existed; a figure that leaves nothing out changes no byte of `rig.json` or `motion.json`. The part's image is not touched: a pixel left out stays in it, and is drawn only where a cell kept for other art happens to cover it; `art_coverage` is over all the art, the islands left out included. Declared, the mesh's `mesh_report.json` row echoes `stray` and adds `stray_cleared` (`islands`, `pixels`, `art_pixels`, after `influences`), and the rig stage's mesh line ends `stray <n> left out <i> island(s), <p> of <a> art px`. A value that is not a whole number from 0 is `CONFIG_FIELD_TYPE`; beside `contour` or `auto` it is `CONFIG_STRAY_MODE` (those modes state it in `contour.stray` and `auto.source.stray`). `propose` and `mesh-draft` never write it |
|
|
@@ -2500,18 +2500,29 @@ depth sheet or generated key, and adds no winding validator. Lattice meshes,
|
|
|
2500
2500
|
head turns, unrelated animations and attachments absent from the generated
|
|
2501
2501
|
body-turn deform get no contour/body-turn advice.
|
|
2502
2502
|
|
|
2503
|
-
**Weights.**
|
|
2504
|
-
`
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
`
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2503
|
+
**Weights.** The nominal share `g` is 1 inside or on the region, `1 − d/band` at a
|
|
2504
|
+
distance `0 < d < band`, and 0 at or past the outer edge. With `band: 0`, the share
|
|
2505
|
+
steps directly from 1 to 0. The endpoints are decided exactly on the 1/256 px grid.
|
|
2506
|
+
Two regions with `g > 0` at the same vertex are refused before weighting.
|
|
2507
|
+
|
|
2508
|
+
By default, a region listed in `contour.regions` uses `4g²(1 − g)` for
|
|
2509
|
+
`0 < g < 0.5` and uses `g` everywhere else (issue #1578). The cubic starts at
|
|
2510
|
+
the outer edge with zero slope and meets the inner half with matching value
|
|
2511
|
+
and slope. Set `falloff: "linear"` on a declared contour region to use `g`
|
|
2512
|
+
throughout the band and recover its old weights. Other explicit values are
|
|
2513
|
+
`CONFIG_FIELD_TYPE`. Regions derived from `contour.bust` and automatic mesh
|
|
2514
|
+
regions keep their linear weighting. Zero-width bands still use a hard edge.
|
|
2515
|
+
|
|
2516
|
+
With selected region share `w_region`, the segment bones split `1 − w_region`
|
|
2517
|
+
in the same proportions as the lattice (`w = 1/(d + r)²`, at most 4 bones, a
|
|
2518
|
+
0.03 floor before scaling). If the region bone is also a segment bone, its
|
|
2519
|
+
single entry takes `w_region + (1 − w_region)·share`. If the region adds a bone
|
|
2520
|
+
to a full set of segment shares, the lightest segment bone is dropped and the
|
|
2521
|
+
remaining segment shares are renormalized before scaling. At a reached vertex,
|
|
2522
|
+
the weights are rounded to 5 places and entries rounding to 0 are dropped.
|
|
2523
|
+
The heaviest entry absorbs the rounding remainder so the weights sum to 1
|
|
2524
|
+
(`src/localweights.ts`, `roundShares` in `src/rig.ts`). A vertex outside the
|
|
2525
|
+
support uses the lattice's weighting and rounding. A region's bone counts
|
|
2515
2526
|
as a mesh bone, so an idle key on it moves to `<bone>_ctl` under `--idle-keys ctl` like a
|
|
2516
2527
|
segment bone's.
|
|
2517
2528
|
|
|
@@ -2680,7 +2691,8 @@ unreduced source on the rig's idle and passes the author's bounds (step 4). The
|
|
|
2680
2691
|
joined to the outside only at a corner counts as outside and a source spanning it is refused
|
|
2681
2692
|
here (`CONTOUR_OVERSHOOT`, "the background flooded 8-connected"), with the number rig-c would
|
|
2682
2693
|
read, rather than by rig-c's admission after the call. The row's `source.contour` says so
|
|
2683
|
-
(`fitConnectivity: 8`); the contour mode keeps its 4-connected reading and writes no such key.
|
|
2694
|
+
(`fitConnectivity: 8`); the contour mode keeps its 4-connected reading and writes no such key.
|
|
2695
|
+
The source blends segment shares with the linear region falloff under the author's
|
|
2684
2696
|
`influences`, with no 0.03 floor unless the author writes one.
|
|
2685
2697
|
2. **The call** — rig-c's `reduceMesh` (`@rig-c/core/mesh`, 2.28.x) refines inside the declared
|
|
2686
2698
|
regions, then removes vertices while every declared bound still holds. Every number it is
|
|
@@ -2860,7 +2872,7 @@ wall time goes to standard error, not into the table).
|
|
|
2860
2872
|
| `minArtSamples` | the fewest art pixels a raster row is taken over, 1 or more |
|
|
2861
2873
|
| `motion` | **required**: `maxLocalDeformation` (rig px, 0 or more — how far the reduced mesh may carry any art pixel from where its source carries it, at any frame); optional `maxStretch` / `minStretch` (ratios; absent, the rows are reported and not gated); optional `deformMayFold` (absent is **false**: a triangle that turns over refuses the part; true declares the slot in `invariants.deformMayFold` and lists every fold instead); optional `gradation` (px per px, 0 or more, or `null`; the author's G for `MQ_ALLOCATION_CONTRAST`, never derived — absent or `null`, the contrast reads `not-measurable` naming it; see *The allocation rows* below); optional `selection` (`{ "policy": "multi-interval", "maxProbes": <whole number, 1 or more> }`; absent, the acceptance loop is the bisection — see *The multi-interval selection* above); optional `residual` (`{ "maxResidual": <px, 0 or more> }`; absent, nothing is sent — see *The skinning residual as a per-step veto* above) |
|
|
2862
2874
|
| `protect` | optional; each field optional: `hull` (true keeps every source outline vertex; absent is **false**, the default agreed for this mode), `vertices` and `edges` (source vertex indices and pairs that must survive), `regionBoundaries` (region names whose outline vertices must survive), `weightJump` (an L1 weight difference above which a source edge is kept; absent is none), `influences` (bones never pruned from a vertex; every region's bone is added) |
|
|
2863
|
-
| `regions` | optional, each `{name, shape, bone?, band?, maxEdgeLength, transition, grade, minArtSamples}` with `shape` `"circle"` (`cx, cy, r`) or `"polygon"` (`points`): `bone` and `band`
|
|
2875
|
+
| `regions` | optional, each `{name, shape, bone?, band?, maxEdgeLength, transition, grade, minArtSamples}` with `shape` `"circle"` (`cx, cy, r`) or `"polygon"` (`points`): `bone` and `band` declare the control bone and its linear weight falloff (rig px, multiples of 1/256 px), written together (the region weights its bone and asks for density) or not at all (density only, issue #155; one without the other is refused by name). Automatic regions reject `falloff` as `CONFIG_KEY_KNOWN`. `maxEdgeLength` is L0, the longest an edge meeting the region may be, px; outside it, across `transition` px, the bound relaxes as `L0 + grade·d`; `transition` 0 is a hard edge; `minArtSamples` is the region's own sample floor |
|
|
2864
2876
|
| `boundaryRuns` | optional, `{ maxVertices }`, a whole number 2 or more, no default: each removal pass first tries to replace a run of 2 to `maxVertices` consecutive source-hull vertices with one chord, as one step held to every declared row (below) |
|
|
2865
2877
|
| `retriangulate` | optional, `"delaunay"`: once the reduction ends, the kept vertices are re-triangulated by Delaunay flips, taken whole only when every declared row still passes (below) |
|
|
2866
2878
|
| `removalOrder` | optional, `"deformation-load"`: the single removals are tried in ascending predicted load instead of ascending source index (below) |
|
|
@@ -10071,7 +10083,7 @@ by `rig`, so their output requires no alternate compiler or dependency pin.
|
|
|
10071
10083
|
| rule | refused input | remedy |
|
|
10072
10084
|
| --- | --- | --- |
|
|
10073
10085
|
| <a id="DEPTH_RECIPE"></a>`DEPTH_RECIPE` | unknown, absent or wrongly typed recipe field, group, source or frame | use the documented explicit recipe schema; no guessed field |
|
|
10074
|
-
| <a id="DEPTH_RECIPE_NUMBER"></a>`DEPTH_RECIPE_NUMBER` | missing
|
|
10086
|
+
| <a id="DEPTH_RECIPE_NUMBER"></a>`DEPTH_RECIPE_NUMBER` | missing or nonfinite median, relief, group scale or pivot, or prepare number. Also covers invalid ranges, invalid integers and invalid numeric `place.pivot` | declare numbers in the documented units and range, or use `"anchor"` for the placement pivot |
|
|
10075
10087
|
| <a id="DEPTH_INPUT_PRESENT"></a>`DEPTH_INPUT_PRESENT` | declared input missing or not a file, or `depth-map` input unreadable or prepared PNG undecodable | restore the named readable input file in its expected format |
|
|
10076
10088
|
| <a id="DEPTH_INPUT_JSON"></a>`DEPTH_INPUT_JSON` | malformed numeric or configuration JSON | write valid finite JSON |
|
|
10077
10089
|
| <a id="DEPTH_PART_RESOLVES"></a>`DEPTH_PART_RESOLVES` | selected or cleared name absent from parts.json | use the assembled part name |
|
|
@@ -10087,17 +10099,92 @@ by `rig`, so their output requires no alternate compiler or dependency pin.
|
|
|
10087
10099
|
| <a id="DEPTH_ARRAY_NONFINITE"></a>`DEPTH_ARRAY_NONFINITE` | retained raw depth pixel contains `NaN` or an infinity | export finite depth values at the named raw pixel |
|
|
10088
10100
|
| <a id="DEPTH_ARRAY_NORMAL"></a>`DEPTH_ARRAY_NORMAL` | retained raw normal is zero or nonfinite, or a pooled normal cancels to zero | export finite nonzero signed XYZ normals in image axes and inspect the named raw or output pixel |
|
|
10089
10101
|
| <a id="DEPTH_MAP_FORMAT"></a>`DEPTH_MAP_FORMAT` | wrong numeric schema, channels, shape, count, unknown field or nonfinite element | provide the declared float JSON map, not a preview |
|
|
10090
|
-
| <a id="DEPTH_MAP_SIZE"></a>`DEPTH_MAP_SIZE` | map dimensions differ from its explicit frame | use the registered part, enlarged art or padded input grid |
|
|
10102
|
+
| <a id="DEPTH_MAP_SIZE"></a>`DEPTH_MAP_SIZE` | map dimensions differ from its explicit frame | use the registered part, enlarged art or padded input grid for a per-part map, or `parts.json`'s `rig_size` for a placement map |
|
|
10091
10103
|
| <a id="DEPTH_MAP_SUPPORT"></a>`DEPTH_MAP_SUPPORT` | no alpha>=128 support | provide a supported part |
|
|
10092
10104
|
| <a id="DEPTH_MAP_SPREAD"></a>`DEPTH_MAP_SPREAD` | p5=p95 with nonzero relief | supply a nonflat map or declare relief 0 |
|
|
10093
10105
|
| <a id="DEPTH_APPLY_CLIPPED"></a>`DEPTH_APPLY_CLIPPED` | a pixel with original alpha >= 128 has pre-encoding depth `z <= 0` or `z >= zScale` | use the reported minimum median for each low-clipped part and the reported minimum group scale for upper clipping. The rig checks the head and body role sets separately, so if a surface belongs to both, use the larger required `zScale` in both groups. Recompute the group scale after median edits if the maximum changes, then prepare again. |
|
|
10094
10106
|
| <a id="DEPTH_NORMAL_ISLANDS"></a>`DEPTH_NORMAL_ISLANDS` | zero/multiple connected components at native or integration resolution | scalar source, or a larger registered normal input that preserves one island |
|
|
10095
10107
|
| <a id="DEPTH_NORMAL_VECTOR"></a>`DEPTH_NORMAL_VECTOR` | a sampled support normal is zero | provide nonzero signed XYZ normals |
|
|
10096
10108
|
| <a id="DEPTH_NORMAL_CONVEXITY"></a>`DEPTH_NORMAL_CONVEXITY` | core/rim or its convexity sign is unresolved | larger closed convex mask or scalar source |
|
|
10097
|
-
| <a id="DEPTH_GROUP_BINDING"></a>`DEPTH_GROUP_BINDING` | part outside declared turn roles, mixed retained near/zScale, or filename collision | register exact roles and one shared scale/polarity, replace/clear conflicting sheets, use distinct names |
|
|
10109
|
+
| <a id="DEPTH_GROUP_BINDING"></a>`DEPTH_GROUP_BINDING` | part outside declared turn roles, including a placed body part absent from `turn.body.roles`, mixed retained near/zScale, or filename collision | register exact roles and one shared scale/polarity, replace/clear conflicting sheets, use distinct names |
|
|
10098
10110
|
| <a id="DEPTH_GROUP_SELECTION"></a>`DEPTH_GROUP_SELECTION` | `depth-apply --groups` with an empty list, a group the recipe does not declare, or a group named twice | name each group to apply once, from the recipe's `groups` |
|
|
10099
10111
|
| <a id="DEPTH_GROUP_LEFT_OUT"></a>`DEPTH_GROUP_LEFT_OUT` | `depth-apply --groups` leaves a group out while the rig config declares that group's turn (`turn.body`; `turn.roles` or `turn.depths` for head) | remove that turn block from the rig config, or name the group in `--groups` |
|
|
10100
10112
|
| <a id="DEPTH_AUTHORED_UNIT_CONFLICT"></a>`DEPTH_AUTHORED_UNIT_CONFLICT` | a selected part already records `provenance.depth.kind: "authored-unit"`; adding scalar depth would make its two representations conflict | retain the authored unit or supply an explicitly reassembled scalar-compatible input; apply never replaces the provenance automatically |
|
|
10113
|
+
| <a id="DEPTH_PLACE_NEAR"></a>`DEPTH_PLACE_NEAR` | `place.near` is missing or invalid | declare `black` for low raw values near or `white` for high raw values near |
|
|
10114
|
+
| <a id="DEPTH_PLACE_SCALE"></a>`DEPTH_PLACE_SCALE` | `place.scale` is missing, nonfinite or nonpositive, or a placed median or implied relief overflows | use the available anchor evidence to declare a finite positive scale in rig pixels per model unit that keeps placement values finite |
|
|
10115
|
+
| <a id="DEPTH_PLACE_GROUP"></a>`DEPTH_PLACE_GROUP` | missing `groups.body` in the recipe or missing 2.5D `turn.body` in the rig config | declare both body blocks and register the placement parts under the body's turn roles |
|
|
10116
|
+
| <a id="DEPTH_PLACE_ANCHOR"></a>`DEPTH_PLACE_ANCHOR` | `place.anchor` is missing or fails to name the first body turn surface | name the first `surface` in `turn.body.roles` and declare its body recipe median |
|
|
10117
|
+
| <a id="DEPTH_PLACE_OCCLUDED"></a>`DEPTH_PLACE_OCCLUDED` | a body recipe part or `turn.body` unit has zero visible pixels at alpha >= 128 in the assembled draw order | make the part visible in the assembled art or remove it from placement |
|
|
10118
|
+
| <a id="DEPTH_PLACE_ROUND"></a>`DEPTH_PLACE_ROUND` | invalid `place.round`, a name outside the placement set, no measurable section, or a nonpositive fitted slope | list unique body recipe parts or body units with measurable round sections and check the declared polarity and depth profile |
|
|
10119
|
+
|
|
10120
|
+
### Place body depth from a whole-painting map (#1570)
|
|
10121
|
+
|
|
10122
|
+
Run `depth-place` on the assembled parts before preparing the recipe you will
|
|
10123
|
+
apply. Add the optional `place` object to `rig-parts-depth/1` and declare
|
|
10124
|
+
`groups.body` and the matching `turn.body` in the rig config.
|
|
10125
|
+
|
|
10126
|
+
```sh
|
|
10127
|
+
rig-parts depth-place --parts assembled --config depth-recipe.json --rig-config config.json --out placed --check-turn
|
|
10128
|
+
```
|
|
10129
|
+
|
|
10130
|
+
| `place` field | contract |
|
|
10131
|
+
| --- | --- |
|
|
10132
|
+
| `map` | Required. A one-channel `rig-parts-map/1` on the assembled painting grid (`parts.json`'s `rig_size`), resolved relative to the recipe. |
|
|
10133
|
+
| `near` | Required. `black` means low raw values are near. `white` means high raw values are near. This is the painting map's polarity. `groups.body.near` controls the encoding of the per-part sheets. |
|
|
10134
|
+
| `scale` | Required. A finite positive value in rig pixels per model unit. The refusal for a missing scale prints the available anchor evidence. |
|
|
10135
|
+
| `anchor` | Required. The body turn's first `surface`, with a median already declared in `parts`. |
|
|
10136
|
+
| `round` | Optional. An array of unique body recipe part or body unit names for round-limb scale evidence. |
|
|
10137
|
+
| `pivot` | Optional. Omit it or use `"anchor"` to write `0`, the offset at the reference depth. Supply a finite number to write that explicit offset in rig pixels. |
|
|
10138
|
+
|
|
10139
|
+
At each painting pixel, the last drawn part with alpha at least 128 owns the
|
|
10140
|
+
sample. Every assembled part participates in occlusion. Each body recipe part
|
|
10141
|
+
and body turn unit must have at least one visible pixel. Its raw median uses
|
|
10142
|
+
those visible samples. The command also refuses missing recipe parts, body
|
|
10143
|
+
units or `clear` entries, mismatched map dimensions, and round parts without
|
|
10144
|
+
measurable sections or with a nonpositive fitted slope.
|
|
10145
|
+
|
|
10146
|
+
With raw medians `m` and `mAnchor`, declared anchor median `zAnchor` and
|
|
10147
|
+
scale `k`, the resulting rig depth is `zAnchor + sign * (m - mAnchor) * k`,
|
|
10148
|
+
with `sign = -1` for `black` and `+1` for `white`. The anchor retains its
|
|
10149
|
+
declared median. Placed unit depths are world rig `z` in
|
|
10150
|
+
`turn.body.unitDepths`. A unit can use just the painting map, with no per-part
|
|
10151
|
+
map declaration. The body carrier projects an explicit unit depth as
|
|
10152
|
+
`pivot + z - zRef`, with `zRef` from the first body surface (#1577).
|
|
10153
|
+
|
|
10154
|
+
The output directory receives `recipe.json`, `config.json` and
|
|
10155
|
+
`depth-place-report.json`. The placed recipe supplies the body medians and
|
|
10156
|
+
the resolved group pivot, which the config also records. Any existing `groups.body.unitDepths` override
|
|
10157
|
+
also carries the placed unit values, so applying the recipe preserves them.
|
|
10158
|
+
Relief remains declared per part, and the body's sheet `zScale` remains a
|
|
10159
|
+
separate authored value. Relative map and config references are rebased to the
|
|
10160
|
+
output directory. Prepare with `placed/recipe.json` to bind its bytes, then
|
|
10161
|
+
apply with the new preparation manifest and `placed/config.json`. If placement
|
|
10162
|
+
changes a declared assembly input, apply's `ASSEMBLY_CONFIG_STALE` refusal names
|
|
10163
|
+
the change and requires reassembly with the placed config.
|
|
10164
|
+
|
|
10165
|
+
`depth-place-report.json` has `spec: "rig-parts-depth-place-report/1"`, `near`,
|
|
10166
|
+
`scale`, `anchor`, `pivot` and `parts`. The rows follow `parts.json` draw order
|
|
10167
|
+
and carry `part`, `group`, `visibleCount`, `visibleFraction` (visible pixels
|
|
10168
|
+
divided by alpha >= 128 pixels), `rawMedian`, `rawP5`, `rawP95`, `rigMedian`,
|
|
10169
|
+
`reliefRatio` (declared relief divided by `rawP95 - rawP5`, or `null` when
|
|
10170
|
+
unavailable) and `impliedRelief` (`(rawP95 - rawP5) * scale`, or `null` for a
|
|
10171
|
+
unit without a recipe entry). An optional
|
|
10172
|
+
`round` row field carries `sections`, `invertedSections`, `scale` (median fit)
|
|
10173
|
+
and `iqr` (the 25th and 75th percentiles of the section scales). The fit
|
|
10174
|
+
uses the full supported silhouette for its principal axis and section widths
|
|
10175
|
+
and the visible samples for regression. For a missing or invalid declared
|
|
10176
|
+
scale, the refusal includes the available evidence by part.
|
|
10177
|
+
|
|
10178
|
+
With `--check-turn`, the command runs prepare, apply and `rig` with the real
|
|
10179
|
+
Core gate in scratch space at the declared turn range and adds `turnCheck`
|
|
10180
|
+
to the report. The check object has `status: "built"` on success.
|
|
10181
|
+
With `status: "refused"` it also has `stage` (`prepare`, `apply` or `rig`),
|
|
10182
|
+
`problems` (each with `code`, `object` and `detail`) and `winding`. Available
|
|
10183
|
+
`A39_DEFORM_KEEPS_TRIANGLE_WINDING` findings carry `rule`, `animation`,
|
|
10184
|
+
`part`, `attachment`, `key`, `reversedTriangles` and `triangles`, with `endKey`
|
|
10185
|
+
for an interval and `frame` when a slider is named. A named check refusal
|
|
10186
|
+
still lets successful placement write its files and exit `0`. Adjust the
|
|
10187
|
+
declarations and check the new candidate with the same gate.
|
|
10101
10188
|
|
|
10102
10189
|
### Unit depth precedence
|
|
10103
10190
|
|
package/docs/DEPTH.md
CHANGED
|
@@ -41,10 +41,11 @@ use. Three things we learned the hard way are built into that path:
|
|
|
41
41
|
convexity (the middle of a face is nearer than its rim). That integration is
|
|
42
42
|
for the face only: it breaks on anything with an occlusion edge, like hair
|
|
43
43
|
strands or a collar.
|
|
44
|
-
- **
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
- **Placement and relief have separate controls.** The `median` sets where
|
|
45
|
+
a part sits and its `relief` sets the depth of its own shape, both in rig
|
|
46
|
+
pixels. Author both directly, or use a whole-painting map to
|
|
47
|
+
[place body medians](#optional-place-body-parts-from-a-whole-painting-map)
|
|
48
|
+
with a scale you declare. Relief is always authored separately.
|
|
48
49
|
|
|
49
50
|
Surfaces in one turn group share one depth reference: the first surface's
|
|
50
51
|
opaque-art median, preferring the face in a head group. With both eye landmarks,
|
|
@@ -78,9 +79,9 @@ measures depth discontinuity, not composite visibility.
|
|
|
78
79
|
See-through, the layer decomposition this package reads, also writes a per-layer
|
|
79
80
|
depth sheet, and a config can register those directly (`config.depth`,
|
|
80
81
|
[Per-layer depth sheets](AUTHORING.md#per-layer-depth-sheets-773)). In
|
|
81
|
-
side-by-side review, per-part maps from a depth model read better by eye
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
side-by-side review, per-part maps from a depth model read better by eye for
|
|
83
|
+
local shape. A whole-painting map can supply the relative placement of those
|
|
84
|
+
parts before you use per-part maps to shape them.
|
|
84
85
|
|
|
85
86
|
## The steps, and what you will see
|
|
86
87
|
|
|
@@ -92,6 +93,38 @@ as one piece, `rear` for what sits behind the head. A body group is declared
|
|
|
92
93
|
the same way under `turn.body.roles`. The roles, the dials and the grid the
|
|
93
94
|
surfaces are built on are in [AUTHORING §3, the `turn` row](AUTHORING.md#3-configjson-field-by-field).
|
|
94
95
|
|
|
96
|
+
### Optional: Place body parts from a whole-painting map
|
|
97
|
+
|
|
98
|
+
Use `depth-place` if you have a scalar map for the whole painting and want to
|
|
99
|
+
place assembled body parts relative to one another. Supply a one-channel
|
|
100
|
+
`rig-parts-map/1` on the assembled painting grid (`parts.json`'s `rig_size`)
|
|
101
|
+
and add `place` to the depth recipe. Set `place.near` to `black` when low raw
|
|
102
|
+
values mean near or `white` when high values mean near. Nearer samples produce
|
|
103
|
+
larger rig `z`.
|
|
104
|
+
Declare a positive `place.scale` in rig pixels per model unit and name the
|
|
105
|
+
first body surface as `place.anchor`. That surface keeps its declared median.
|
|
106
|
+
The default pivot is at the anchor depth, with an offset of `0` from the turn's
|
|
107
|
+
reference. A numeric `place.pivot` supplies an explicit offset in rig pixels.
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
rig-parts depth-place --parts assembled --config depth.json --rig-config config.json --out placed --check-turn
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The command writes `placed/recipe.json`, `placed/config.json` and
|
|
114
|
+
`placed/depth-place-report.json`. Use the placed recipe in steps 1 and 4 and the
|
|
115
|
+
placed config in step 4. Each median comes from the pixels where that part is
|
|
116
|
+
visible in the assembled draw order. The report shows the visible pixel count
|
|
117
|
+
and fraction and the scales implied by declared reliefs and optional round
|
|
118
|
+
parts. If you omit the scale, the refusal prints the available evidence so you
|
|
119
|
+
can choose one explicitly.
|
|
120
|
+
|
|
121
|
+
`--check-turn` prepares and applies the placed recipe in scratch space and runs
|
|
122
|
+
the real rig gate. Read `turnCheck` in the report for `built` or a named refusal
|
|
123
|
+
and any available triangle-winding findings. If placement succeeds, a named check
|
|
124
|
+
refusal still leaves the three placement files and exits `0`. The usual rig
|
|
125
|
+
gate still decides whether the turn can build. See the
|
|
126
|
+
[placement fields and refusals](AUTHORING.md#place-body-depth-from-a-whole-painting-map-1570).
|
|
127
|
+
|
|
95
128
|
### 1. Prepare one inference image per part
|
|
96
129
|
|
|
97
130
|
Write a small recipe — a separate JSON file, not a field on the character
|
package/docs/STABILITY.md
CHANGED
|
@@ -578,6 +578,7 @@ and do not certify visibility. See the
|
|
|
578
578
|
| `external-receipt` | `--kind` (mask), `--file`, `--painting`, `--producer`, `--out`; or `--verify`; or `--help` (`-h`) |
|
|
579
579
|
| `diff-components` | `--stack`, `--painting`, `--parts`, `--floor`; optional `--threshold`, `--figure`, `--owners`, `--help` (`-h`); exactly one of `--out`, `--verify` (issues #1005, #1291; exhaustive native error inventory, `rig-parts-diff-components/1` by default and `rig-parts-diff-components/2` with `--owners`, and byte-bound reader for both) |
|
|
580
580
|
| `diff-drafts` | `--left`, `--right`, `--out`; optional `--help` (`-h`) (issue #1369; draft-to-draft assemble comparison, `rig-parts-draft-diff/1`) |
|
|
581
|
+
| `depth-place` | `--parts`, `--config`, `--rig-config`, `--out`; optional `--check-turn`, `--help` (`-h`) (issue #1570) |
|
|
581
582
|
| `depth-prepare` | `--parts`, `--config`, `--out`; optional `--help` (`-h`) (issue #897; separate numeric-depth recipe) |
|
|
582
583
|
| `depth-map` | `--array`, `--input`, `--kind` (`depth` or `normals`), `--part`, `--out`; optional `--padding` (`LEFT,TOP,RIGHT,BOTTOM`), `--help` (`-h`) (issue #1573; NumPy array to input-frame numeric map) |
|
|
583
584
|
| `depth-bind` | `--map`, `--input`, `--part`; optional `--help` (`-h`) (issue #1284; exclusive receipt creation from current file bytes) |
|
|
@@ -756,7 +757,7 @@ part name, `[i]` an entry of a list):
|
|
|
756
757
|
- **meshes.<part>.influences** — optional, at least one: `maxInfluences` (a whole number, 1 or more, or null for no cap), `floor` ("cut" or "continuous")
|
|
757
758
|
- **meshes.<part>.ribs.<chain>** — required: `stations`
|
|
758
759
|
- **meshes.<part>.contour** — required: `tolerance`, `margin`, `spacing`; optional: `maxEdge`, `budget`, `stray`, `bridges`, `regions`, `bust`
|
|
759
|
-
- **meshes.<part>.contour.regions[i]** — required: `name`, `shape`, `bone`, `spacing`, `band`, and `cx`, `cy`, `r` for a circle or `points` for a polygon; optional: `cover`
|
|
760
|
+
- **meshes.<part>.contour.regions[i]** — required: `name`, `shape`, `bone`, `spacing`, `band`, and `cx`, `cy`, `r` for a circle or `points` for a polygon; optional: `cover`, `falloff`
|
|
760
761
|
- **meshes.<part>.contour.bust** — required: `apex_r`, `apex_l`, `cleavage`; optional: `alpha`, `clearance`, `bone_r`, `bone_l`, `spacing` (issue #475)
|
|
761
762
|
- **meshes.<part>.auto** — required: `source`, `sourceBounds`, `targets`, `influences`, `budget`, `minArtSamples`, `motion`; optional: `protect`, `regions`, the three Stage B opt-ins `boundaryRuns`, `retriangulate`, `removalOrder`, and `stimulus`
|
|
762
763
|
- **meshes.<part>.auto.source** — required: `tolerance`, `margin`, `spacing`; optional: `stray`
|
|
@@ -1711,6 +1712,19 @@ against. The public examples' `expected/` files are this package's own snapshots
|
|
|
1711
1712
|
`tools/regenerate_examples.ts` writes them on Linux, and CI rebuilds the fetched
|
|
1712
1713
|
examples and compares the files whole with its `--check` (issue #1439).
|
|
1713
1714
|
|
|
1715
|
+
### Contour band weights (issue #1578)
|
|
1716
|
+
|
|
1717
|
+
With the default falloff, a region listed in `contour.regions` applies
|
|
1718
|
+
`4g²(1 − g)` to its nominal linear share `g` for `0 < g < 0.5`. An upgrade can
|
|
1719
|
+
change written weights and downstream output bytes. Geometric support and
|
|
1720
|
+
overlap refusals use the original `g`. The inner half of the band, zero-width
|
|
1721
|
+
bands, influence limits and rounding keep their prior behavior. A declared
|
|
1722
|
+
contour region accepts `falloff: "linear"` to recover its previous weights
|
|
1723
|
+
byte for byte. Other values are `CONFIG_FIELD_TYPE`. The circles derived
|
|
1724
|
+
from `contour.bust` and automatic mesh regions keep the prior linear ramp.
|
|
1725
|
+
An automatic region or a `contour.bust` block rejects `falloff` as
|
|
1726
|
+
`CONFIG_KEY_KNOWN`.
|
|
1727
|
+
|
|
1714
1728
|
### Opt-in hybrid provenance (issue #399)
|
|
1715
1729
|
|
|
1716
1730
|
A lower rigid limb piece may carry `limb.hybrid` instead of `limb.cap`:
|
|
@@ -2230,6 +2244,20 @@ byte-identical; an empty receipt list applies no replacement.
|
|
|
2230
2244
|
|
|
2231
2245
|
## Provider-map depth stages (#897)
|
|
2232
2246
|
|
|
2247
|
+
`depth-place` (#1570) accepts an optional `place` block on `rig-parts-depth/1`.
|
|
2248
|
+
The command requires the block, a body turn, and an absent or empty output
|
|
2249
|
+
directory. It emits `recipe.json`, `config.json` and `depth-place-report.json`
|
|
2250
|
+
(`rig-parts-depth-place-report/1`).
|
|
2251
|
+
Placement uses the declared polarity and a positive, explicit scale in rig
|
|
2252
|
+
pixels per model unit. It writes body placement medians and world rig `z` for
|
|
2253
|
+
body units, preserves declared reliefs and `zScale`, and resolves the body pivot
|
|
2254
|
+
to an offset from the reference depth. See the
|
|
2255
|
+
[placement contract](AUTHORING.md#place-body-depth-from-a-whole-painting-map-1570).
|
|
2256
|
+
With `--check-turn`, preparation, application and the real rig gate run in
|
|
2257
|
+
scratch space and the report adds `turnCheck`. It records any named check
|
|
2258
|
+
refusal. Successful placement emits its three files and exits `0` in either
|
|
2259
|
+
check outcome.
|
|
2260
|
+
|
|
2233
2261
|
The opt-in `depth-prepare` and `depth-apply` commands accept the separate
|
|
2234
2262
|
`rig-parts-depth/1` recipe and finite floating-point `rig-parts-map/1` JSON.
|
|
2235
2263
|
Prepared provenance is `rig-parts-depth-inputs/1`; application writes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rig-parts",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.60.0",
|
|
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
|
"exports": {
|
package/src/config.ts
CHANGED
|
@@ -628,13 +628,14 @@ export function contourRegionsOf(spec: ContourSpec): ContourRegionSpec[] {
|
|
|
628
628
|
/**
|
|
629
629
|
* A local deformation region: a shape in rig px, a control bone, the spacing
|
|
630
630
|
* the mesh is refined at inside it and its band, and the band the bone's
|
|
631
|
-
* weight falls across
|
|
632
|
-
*
|
|
633
|
-
*
|
|
631
|
+
* weight falls across. `falloff: 'linear'` keeps the nominal linear share
|
|
632
|
+
* throughout the band. By default contour weighting eases its outer half.
|
|
633
|
+
* Every coordinate and length is a multiple of 1/256 px: the nominal share's
|
|
634
|
+
* 0 and 1 are decided exactly on that grid.
|
|
634
635
|
*/
|
|
635
636
|
export type ContourRegionSpec =
|
|
636
|
-
| { name: string; shape: 'circle'; cx: number; cy: number; r: number; spacing: number; band: number; bone: string; cover?: string }
|
|
637
|
-
| { name: string; shape: 'polygon'; points: Point[]; spacing: number; band: number; bone: string; cover?: string };
|
|
637
|
+
| { name: string; shape: 'circle'; cx: number; cy: number; r: number; spacing: number; band: number; bone: string; cover?: string; falloff?: 'linear' }
|
|
638
|
+
| { name: string; shape: 'polygon'; points: Point[]; spacing: number; band: number; bone: string; cover?: string; falloff?: 'linear' };
|
|
638
639
|
|
|
639
640
|
/**
|
|
640
641
|
* One mesh in the automatic mode (issue #126, item 2): the contour mesh over
|
|
@@ -795,8 +796,8 @@ export interface ArtFitBoundsSpec {
|
|
|
795
796
|
* A region of the automatic mode, in one of two forms (issue #155).
|
|
796
797
|
*
|
|
797
798
|
* - **Weight and density** ({@link AutoWeightRegionSpec}): a shape and a
|
|
798
|
-
* control bone as a contour region has them, the bone's weight
|
|
799
|
-
*
|
|
799
|
+
* control bone as a contour region has them, the bone's linear weight
|
|
800
|
+
* `band` (`src/localweights.ts`), and the density rig-c holds the
|
|
800
801
|
* mesh to (§5 of its contract): every edge meeting the region at most
|
|
801
802
|
* `maxEdgeLength` px (L0), relaxing as `L0 + grade·d` across `transition` px
|
|
802
803
|
* outside it, and the region's art sample floor (P9).
|
|
@@ -3875,7 +3876,7 @@ function checkContour(c: Check, at: string, v: Json, bones: Set<string>): void {
|
|
|
3875
3876
|
const rat = `${at}.regions[${i}]`;
|
|
3876
3877
|
const shape = typeof rv === 'object' && rv !== null && !Array.isArray(rv) ? (rv as Record<string, Json>).shape : undefined;
|
|
3877
3878
|
const own = shape === 'circle' ? ['cx', 'cy', 'r'] : shape === 'polygon' ? ['points'] : [];
|
|
3878
|
-
const r = c.object(rat, rv, ['name', 'shape', 'bone', 'spacing', 'band', ...own], ['cover']);
|
|
3879
|
+
const r = c.object(rat, rv, ['name', 'shape', 'bone', 'spacing', 'band', ...own], ['cover', 'falloff']);
|
|
3879
3880
|
if (r === null) return;
|
|
3880
3881
|
if ('shape' in r && own.length === 0) c.fail('CONFIG_FIELD_TYPE', `${rat}.shape`, `is ${show(r.shape)}; "circle" (with cx, cy, r) or "polygon" (with points) is required`);
|
|
3881
3882
|
if ('name' in r && c.string(`${rat}.name`, r.name)) {
|
|
@@ -3888,6 +3889,9 @@ function checkContour(c: Check, at: string, v: Json, bones: Set<string>): void {
|
|
|
3888
3889
|
if ('cover' in r && (typeof r.cover !== 'string' || r.cover.length === 0)) {
|
|
3889
3890
|
c.fail('CONFIG_FIELD_TYPE', `${rat}.cover`, `is ${show(r.cover)}; a non-empty part name is required`);
|
|
3890
3891
|
}
|
|
3892
|
+
if ('falloff' in r && r.falloff !== 'linear') {
|
|
3893
|
+
c.fail('CONFIG_FIELD_TYPE', `${rat}.falloff`, `is ${show(r.falloff)}; "linear" is required for the legacy ramp, or leave falloff out to ease the outer half of the band`);
|
|
3894
|
+
}
|
|
3891
3895
|
if ('spacing' in r) c.number(`${rat}.spacing`, r.spacing, 'positive');
|
|
3892
3896
|
if ('band' in r) onGrid(`${rat}.band`, r.band, 'non-negative');
|
|
3893
3897
|
if (shape === 'circle') {
|
package/src/depthworkflow.ts
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
6
|
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
7
|
-
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
8
8
|
import { refuseStaleAssembly } from './assembly-reading.ts';
|
|
9
9
|
import { PartsError, type Problem } from './errors.ts';
|
|
10
10
|
import { loadConfigAndAnimations, parseConfig } from './config.ts';
|
|
11
11
|
import { relocateConfigReferences } from './configrelocation.ts';
|
|
12
12
|
import { depthReading, readSourceDepth } from './depthsheets.ts';
|
|
13
13
|
import { readEditorReceipts } from './editreceipt.ts';
|
|
14
|
-
import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
|
|
14
|
+
import { alphaSupport, depthMapFail as fail, floatBox, integrateNormals, mapQuantile, mapToSheet, readNumericMap, type NumericMap } from './depthmaps.ts';
|
|
15
15
|
import { depthImageReference, partImageReference, readParts } from './parts.ts';
|
|
16
|
-
import { readPartSet } from './propose.ts';
|
|
16
|
+
import { readPartSet, type PartSet } from './propose.ts';
|
|
17
17
|
import { decodePngBytes, encodePngBytes } from './raster/png.ts';
|
|
18
18
|
import { resize } from './raster/resize.ts';
|
|
19
19
|
import { connectedComponents } from './raster/components.ts';
|
|
@@ -23,7 +23,8 @@ type Obj = Record<string, unknown>;
|
|
|
23
23
|
interface PrepareOptions { longSide: number; paddingFraction: number; padding: number }
|
|
24
24
|
interface Group { median?: never; near: 'black' | 'white'; zScale: number; pivot: number; unitDepths?: Record<string, number> }
|
|
25
25
|
interface PartMap { map: string; source: 'depth' | 'normals'; frame: 'part' | 'upscaled' | 'input'; group: string; median: number; relief: number }
|
|
26
|
-
|
|
26
|
+
interface Placement { map: string; near: Group['near']; scale: number; anchor: string; pivot?: 'anchor' | number; round?: string[] }
|
|
27
|
+
export interface DepthRecipe { spec: 'rig-parts-depth/1'; prepare: PrepareOptions; groups: Record<string, Group>; parts: Record<string, PartMap>; clear: string[]; place?: Placement }
|
|
27
28
|
interface PreparedPart { part: string; crop: number[]; sourceSha256: string; input: string; inputSha256: string; size: number[]; upscaled: number[]; upscale: number; padding: number; inputSize: number[] }
|
|
28
29
|
interface Prepared { spec: 'rig-parts-depth-inputs/1'; partsSha256: string; recipeSha256: string; background: number; alpha: number; parts: PreparedPart[] }
|
|
29
30
|
const hash = (bytes: Uint8Array | string): string => createHash('sha256').update(bytes).digest('hex');
|
|
@@ -57,7 +58,14 @@ function plain(name: string, at: string): void {
|
|
|
57
58
|
if (!name || name.startsWith('.') || /[\\/]/.test(name) || name.includes('\0')) fail('DEPTH_RECIPE', at, `name "${name}" is not a plain part filename`);
|
|
58
59
|
}
|
|
59
60
|
export function parseDepthRecipe(raw: unknown): DepthRecipe {
|
|
60
|
-
const
|
|
61
|
+
const { recipe, place } = readDepthRecipe(raw);
|
|
62
|
+
if (place === undefined) return recipe;
|
|
63
|
+
const { scale } = place;
|
|
64
|
+
if (!isPlacementScale(scale)) throw new PartsError([placementScaleProblem(scale)]);
|
|
65
|
+
return { ...recipe, place: { ...place, scale } };
|
|
66
|
+
}
|
|
67
|
+
function readDepthRecipe(raw: unknown): { recipe: DepthRecipe; place?: Omit<Placement, 'scale'> & { scale: unknown } } {
|
|
68
|
+
const o = object(raw, 'depth recipe'); keys(o, ['spec', 'prepare', 'groups', 'parts', 'clear', 'place'], 'depth recipe');
|
|
61
69
|
if (o.spec !== 'rig-parts-depth/1') fail('DEPTH_RECIPE', 'spec', 'requires rig-parts-depth/1');
|
|
62
70
|
const p = object(o.prepare, 'prepare'); keys(p, ['longSide', 'paddingFraction', 'padding'], 'prepare');
|
|
63
71
|
const prepare = { longSide: number(p.longSide, 'prepare.longSide', 1), paddingFraction: number(p.paddingFraction, 'prepare.paddingFraction', 0), padding: number(p.padding, 'prepare.padding', 0) };
|
|
@@ -83,7 +91,27 @@ export function parseDepthRecipe(raw: unknown): DepthRecipe {
|
|
|
83
91
|
if (!Object.keys(parts).length) fail('DEPTH_RECIPE', 'parts', 'requires at least one named part');
|
|
84
92
|
if (!Array.isArray(o.clear) || !o.clear.every(n => typeof n === 'string') || new Set(o.clear).size !== o.clear.length) fail('DEPTH_RECIPE', 'clear', 'requires an explicit array of unique part names, [] when none; no sheet is dropped implicitly');
|
|
85
93
|
for (const name of o.clear as string[]) { plain(name, 'clear'); if (Object.hasOwn(parts, name)) fail('DEPTH_RECIPE', `clear.${name}`, 'also has a new map; choose clear or apply'); }
|
|
86
|
-
|
|
94
|
+
const recipe: DepthRecipe = { spec: 'rig-parts-depth/1', prepare, groups, parts, clear: o.clear as string[] };
|
|
95
|
+
if (o.place === undefined) return { recipe };
|
|
96
|
+
const at = 'place', place = object(o.place, at);
|
|
97
|
+
keys(place, ['map', 'near', 'scale', 'anchor', 'pivot', 'round'], at);
|
|
98
|
+
if (typeof place.map !== 'string' || !place.map.trim()) return fail('DEPTH_RECIPE', 'place.map', 'requires a numeric JSON map in the painting frame');
|
|
99
|
+
if (place.near !== 'black' && place.near !== 'white') return fail('DEPTH_PLACE_NEAR', 'place.near', `is ${bindingFound(place.near)}; declare black or white for the painting map`);
|
|
100
|
+
if (typeof place.anchor !== 'string' || !place.anchor) return fail('DEPTH_PLACE_ANCHOR', 'place.anchor', 'requires the name of the body turn\'s first surface');
|
|
101
|
+
plain(place.anchor, 'place.anchor');
|
|
102
|
+
const pivot = place.pivot === undefined || place.pivot === 'anchor' ? place.pivot : number(place.pivot, 'place.pivot', -Infinity);
|
|
103
|
+
const round = place.round;
|
|
104
|
+
if (round !== undefined && (!Array.isArray(round) || !round.every(n => typeof n === 'string') || new Set(round).size !== round.length)) {
|
|
105
|
+
return fail('DEPTH_PLACE_ROUND', 'place.round', 'requires an array of unique recipe part names');
|
|
106
|
+
}
|
|
107
|
+
return { recipe, place: { map: place.map, near: place.near, scale: place.scale, anchor: place.anchor,
|
|
108
|
+
...(pivot === undefined ? {} : { pivot }), ...(round === undefined ? {} : { round }) } };
|
|
109
|
+
}
|
|
110
|
+
function isPlacementScale(raw: unknown): raw is number {
|
|
111
|
+
return typeof raw === 'number' && Number.isFinite(raw) && raw > 0;
|
|
112
|
+
}
|
|
113
|
+
function placementScaleProblem(raw: unknown): Problem {
|
|
114
|
+
return { code: 'DEPTH_PLACE_SCALE', object: 'place.scale', detail: `is ${bindingFound(raw)}; declare a finite number > 0 (rig px per map unit)` };
|
|
87
115
|
}
|
|
88
116
|
function emptyOutput(out: string, inputs: readonly string[]): void {
|
|
89
117
|
const canonical = (p: string): string => existsSync(p) ? realpathSync(p) : resolve(canonical(dirname(resolve(p))), basename(p));
|
|
@@ -122,6 +150,264 @@ export function prepareDepth(input: { parts: string; config: string; out: string
|
|
|
122
150
|
writeFileSync(join(input.out, 'manifest.json'), text(manifest));
|
|
123
151
|
return manifest;
|
|
124
152
|
}
|
|
153
|
+
|
|
154
|
+
type RoundPlacement = {
|
|
155
|
+
sections: number;
|
|
156
|
+
invertedSections: number;
|
|
157
|
+
scale: number | null;
|
|
158
|
+
iqr: [number, number] | null;
|
|
159
|
+
};
|
|
160
|
+
interface PlacementSample {
|
|
161
|
+
part: string;
|
|
162
|
+
group: 'body';
|
|
163
|
+
visibleCount: number;
|
|
164
|
+
visibleFraction: number;
|
|
165
|
+
rawMedian: number;
|
|
166
|
+
rawP5: number;
|
|
167
|
+
rawP95: number;
|
|
168
|
+
reliefRatio: number | null;
|
|
169
|
+
round?: RoundPlacement;
|
|
170
|
+
}
|
|
171
|
+
export type DepthPlacementTurnCheck = { status: 'built' } | {
|
|
172
|
+
status: 'refused';
|
|
173
|
+
stage: 'prepare' | 'apply' | 'rig';
|
|
174
|
+
problems: readonly Problem[];
|
|
175
|
+
winding: readonly {
|
|
176
|
+
rule: string; animation: string; part: string; attachment: string; key: number;
|
|
177
|
+
endKey?: number; reversedTriangles: number; triangles: number; frame?: string;
|
|
178
|
+
}[];
|
|
179
|
+
};
|
|
180
|
+
export interface DepthPlacementReport {
|
|
181
|
+
spec: 'rig-parts-depth-place-report/1';
|
|
182
|
+
near: Placement['near'];
|
|
183
|
+
scale: number;
|
|
184
|
+
anchor: string;
|
|
185
|
+
pivot: number;
|
|
186
|
+
parts: Array<PlacementSample & { rigMedian: number; impliedRelief: number | null }>;
|
|
187
|
+
turnCheck?: DepthPlacementTurnCheck;
|
|
188
|
+
}
|
|
189
|
+
type DepthPlacementInput = { parts: string; config: string; rigConfig: string; out: string };
|
|
190
|
+
|
|
191
|
+
/** The projection uses the full silhouette for its axis and section widths,
|
|
192
|
+
* and only pixels owned by this part for its regression ordinates. */
|
|
193
|
+
function roundPlacement(support: readonly number[], artWidth: number, valueAt: (i: number) => number | undefined, near: Placement['near']): RoundPlacement {
|
|
194
|
+
let sx = 0, sy = 0;
|
|
195
|
+
for (const i of support) { sx += i % artWidth; sy += Math.floor(i / artWidth); }
|
|
196
|
+
const cx = sx / support.length, cy = sy / support.length;
|
|
197
|
+
let xx = 0, xy = 0, yy = 0;
|
|
198
|
+
for (const i of support) {
|
|
199
|
+
const x = i % artWidth - cx, y = Math.floor(i / artWidth) - cy;
|
|
200
|
+
xx += x * x; xy += x * y; yy += y * y;
|
|
201
|
+
}
|
|
202
|
+
if (xx === yy && xy === 0) return { sections: 0, invertedSections: 0, scale: null, iqr: null };
|
|
203
|
+
const angle = Math.atan2(2 * xy, xx - yy) / 2;
|
|
204
|
+
const [c, s] = xy === 0 ? (xx > yy ? [1, 0] : [0, 1]) : [Math.cos(angle), Math.sin(angle)];
|
|
205
|
+
const points = support.map(i => {
|
|
206
|
+
const x = i % artWidth - cx, y = Math.floor(i / artWidth) - cy;
|
|
207
|
+
return { i, along: x * c + y * s, across: -x * s + y * c };
|
|
208
|
+
});
|
|
209
|
+
const start = points.reduce((min, p) => Math.min(min, p.along), Infinity);
|
|
210
|
+
const bands = new Map<number, { lo: number; hi: number; visible: Array<{ across: number; value: number }> }>();
|
|
211
|
+
for (const { i, along, across } of points) {
|
|
212
|
+
const k = Math.floor((along - start) / 4);
|
|
213
|
+
let band = bands.get(k);
|
|
214
|
+
if (band === undefined) { band = { lo: across, hi: across, visible: [] }; bands.set(k, band); }
|
|
215
|
+
band.lo = Math.min(band.lo, across);
|
|
216
|
+
band.hi = Math.max(band.hi, across);
|
|
217
|
+
const value = valueAt(i);
|
|
218
|
+
if (value !== undefined) band.visible.push({ across, value: near === 'black' ? value : -value });
|
|
219
|
+
}
|
|
220
|
+
const scales: number[] = [];
|
|
221
|
+
let invertedSections = 0;
|
|
222
|
+
for (const { lo, hi, visible } of bands.values()) {
|
|
223
|
+
const r = (hi - lo) / 2, center = (hi + lo) / 2;
|
|
224
|
+
if (r === 0) continue;
|
|
225
|
+
const samples = visible.flatMap(({ across, value }) => {
|
|
226
|
+
const v = Math.abs(across - center);
|
|
227
|
+
if (v > 0.8 * r) return [];
|
|
228
|
+
// Rationalized r - sqrt(r*r - v*v) keeps shallow sagitta samples distinct.
|
|
229
|
+
return [{ g: v * v / (r + Math.sqrt(r * r - v * v)), value }];
|
|
230
|
+
});
|
|
231
|
+
if (samples.length < 2 || samples.every(({ g }) => g === samples[0].g)) continue;
|
|
232
|
+
const baseline = samples[0].value;
|
|
233
|
+
let sumG = 0, sumZ = 0;
|
|
234
|
+
for (const { g, value } of samples) { sumG += g; sumZ += value - baseline; }
|
|
235
|
+
const meanG = sumG / samples.length, meanZ = sumZ / samples.length;
|
|
236
|
+
let variance = 0, covariance = 0;
|
|
237
|
+
for (const { g, value } of samples) {
|
|
238
|
+
variance += (g - meanG) ** 2;
|
|
239
|
+
covariance += (g - meanG) * (value - baseline - meanZ);
|
|
240
|
+
}
|
|
241
|
+
if (variance === 0) continue;
|
|
242
|
+
const slope = covariance / variance, scale = 1 / slope;
|
|
243
|
+
if (!Number.isFinite(slope) || (slope > 0 && !Number.isFinite(scale))) {
|
|
244
|
+
return fail('DEPTH_MAP_FORMAT', 'place.map', 'round-section regression overflows; provide representable raw depths');
|
|
245
|
+
}
|
|
246
|
+
if (slope <= 0) invertedSections++;
|
|
247
|
+
else scales.push(scale);
|
|
248
|
+
}
|
|
249
|
+
scales.sort((a, b) => a - b);
|
|
250
|
+
return { sections: scales.length + invertedSections, invertedSections,
|
|
251
|
+
scale: scales.length === 0 ? null : mapQuantile(scales, 0.5),
|
|
252
|
+
iqr: scales.length === 0 ? null : [mapQuantile(scales, 0.25), mapQuantile(scales, 0.75)] };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function placementSamples(set: PartSet, map: NumericMap, reliefs: ReadonlyMap<string, number>, place: Omit<Placement, 'scale'>, selected: ReadonlySet<string>): PlacementSample[] {
|
|
256
|
+
const roundNames = new Set(place.round);
|
|
257
|
+
// Iterate front-to-back so a pixel can be claimed only once, including by
|
|
258
|
+
// layers not selected for placement. Scan the stored crop, in rig pixels.
|
|
259
|
+
const claimed = new Uint8Array(map.data.length);
|
|
260
|
+
const rows: PlacementSample[] = [], problems: Problem[] = [];
|
|
261
|
+
for (const p of [...set.recs].reverse()) {
|
|
262
|
+
const art = set.images.get(p.name)!;
|
|
263
|
+
const support = alphaSupport(art), values: number[] = [], roundSupport: number[] = [];
|
|
264
|
+
const roundValues = roundNames.has(p.name) ? new Map<number, number>() : undefined;
|
|
265
|
+
const measure = selected.has(p.name);
|
|
266
|
+
let supportCount = 0;
|
|
267
|
+
for (let y = 0; y < p.h; y++) for (let x = 0; x < p.w; x++) {
|
|
268
|
+
const local = y * p.w + x;
|
|
269
|
+
if (!support[local]) continue;
|
|
270
|
+
if (roundValues !== undefined) roundSupport.push(local);
|
|
271
|
+
if (measure) supportCount++;
|
|
272
|
+
const pixel = (p.y + y) * map.width + p.x + x;
|
|
273
|
+
if (claimed[pixel]) continue;
|
|
274
|
+
claimed[pixel] = 1;
|
|
275
|
+
if (measure) values.push(map.data[pixel]);
|
|
276
|
+
roundValues?.set(local, map.data[pixel]);
|
|
277
|
+
}
|
|
278
|
+
if (!measure) continue;
|
|
279
|
+
if (values.length === 0) {
|
|
280
|
+
problems.push({ code: 'DEPTH_PLACE_OCCLUDED', object: `part "${p.name}"`,
|
|
281
|
+
detail: `has no visible pixels (0 of ${supportCount} with alpha>=128); at least one topmost pixel is required for a median` });
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
values.sort((a, b) => a - b);
|
|
285
|
+
const constant = values[0] === values[values.length - 1] ? values[0] : undefined;
|
|
286
|
+
const rawMedian = constant ?? mapQuantile(values, 0.5);
|
|
287
|
+
const rawP5 = constant ?? mapQuantile(values, 0.05), rawP95 = constant ?? mapQuantile(values, 0.95);
|
|
288
|
+
const span = rawP95 - rawP5, relief = reliefs.get(p.name);
|
|
289
|
+
const ratio = relief === undefined || span <= 0 ? null : relief / span;
|
|
290
|
+
if (!Number.isFinite(span)) return fail('DEPTH_MAP_FORMAT', `part "${p.name}"`, 'visible p5-p95 span overflows; provide representable raw depths');
|
|
291
|
+
rows.push({ part: p.name, group: 'body', visibleCount: values.length,
|
|
292
|
+
visibleFraction: values.length / supportCount, rawMedian, rawP5, rawP95, reliefRatio: Number.isFinite(ratio) ? ratio : null,
|
|
293
|
+
...(roundValues === undefined ? {} : { round: roundPlacement(roundSupport, p.w, i => roundValues.get(i), place.near) }) });
|
|
294
|
+
}
|
|
295
|
+
if (problems.length) throw new PartsError(problems);
|
|
296
|
+
return rows.reverse();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function checkPlacementScale(scale: unknown, samples: readonly PlacementSample[], reliefs: ReadonlyMap<string, number>): number {
|
|
300
|
+
const problems: Problem[] = [];
|
|
301
|
+
const validScale = isPlacementScale(scale) ? scale : undefined;
|
|
302
|
+
if (validScale === undefined) {
|
|
303
|
+
problems.push(placementScaleProblem(scale));
|
|
304
|
+
for (const { part, reliefRatio, rawP5, rawP95, round } of samples) {
|
|
305
|
+
const relief = !reliefs.has(part) ? 'unavailable (no body recipe relief)'
|
|
306
|
+
: reliefRatio === null ? `unavailable (p5=${rawP5}, p95=${rawP95})` : String(reliefRatio);
|
|
307
|
+
const fit = round === undefined ? '' : `; implied round scale for "${part}" = ${round.scale ?? 'unavailable'}, IQR=${round.iqr?.join('..') ?? 'unavailable'}, sections=${round.sections}`;
|
|
308
|
+
problems.push({ code: 'DEPTH_PLACE_SCALE', object: 'place.scale', detail: `implied relief ratio for "${part}" = ${relief}${fit}` });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
for (const { part, round } of samples) {
|
|
312
|
+
if (round === undefined) continue;
|
|
313
|
+
if (round.sections === 0) problems.push({ code: 'DEPTH_PLACE_ROUND', object: `part "${part}"`, detail: 'has 0 measurable round sections; visible samples at distinct sagittae are required on a resolved principal axis' });
|
|
314
|
+
else if (round.invertedSections > 0) problems.push({ code: 'DEPTH_PLACE_ROUND', object: `part "${part}"`,
|
|
315
|
+
detail: `${round.invertedSections} of ${round.sections} fitted sections (fraction ${round.invertedSections / round.sections}) have a non-positive slope; required edges farther than the centre under place.near` });
|
|
316
|
+
}
|
|
317
|
+
if (validScale === undefined || problems.length) throw new PartsError(problems);
|
|
318
|
+
return validScale;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Validate once, then write paths relative to each chosen destination. */
|
|
322
|
+
export function stageDepthPlacement(input: DepthPlacementInput): {
|
|
323
|
+
report: DepthPlacementReport;
|
|
324
|
+
write(out: string, turnCheck?: DepthPlacementTurnCheck): { recipe: string; config: string };
|
|
325
|
+
} {
|
|
326
|
+
const recipeDir = dirname(resolve(input.config)), configDir = dirname(resolve(input.rigConfig));
|
|
327
|
+
const { recipe, place } = readDepthRecipe(readJson(input.config));
|
|
328
|
+
if (place === undefined) return fail('DEPTH_RECIPE', 'place', 'is absent; declare the painting map, near, scale and anchor');
|
|
329
|
+
const mapFile = resolve(recipeDir, place.map);
|
|
330
|
+
const maps = Object.values(recipe.parts).flatMap(p => { const file = resolve(recipeDir, p.map); return [file, file + '.binding.json']; });
|
|
331
|
+
const sources = [resolve(input.parts), resolve(input.config), resolve(input.rigConfig), mapFile, ...maps];
|
|
332
|
+
emptyOutput(input.out, sources);
|
|
333
|
+
const set = readPartSet(input.parts), names = new Set(set.recs.map(p => p.name));
|
|
334
|
+
const missing = [...Object.keys(recipe.parts), ...recipe.clear].filter(name => !names.has(name));
|
|
335
|
+
if (missing.length) throw new PartsError(missing.map(name => ({ code: 'DEPTH_PART_RESOLVES', object: name, detail: 'names no assembled part; use exact parts.json names' })));
|
|
336
|
+
const map = readNumericMap(readJson(mapFile), 'place.map');
|
|
337
|
+
if (map.channels !== 1) return fail('DEPTH_MAP_FORMAT', 'place.map', 'requires a single scalar depth channel');
|
|
338
|
+
if (map.width !== set.W || map.height !== set.H) {
|
|
339
|
+
return fail('DEPTH_MAP_SIZE', 'place.map', `is ${map.width}x${map.height}; painting frame (parts.json rig_size) requires ${set.W}x${set.H}`);
|
|
340
|
+
}
|
|
341
|
+
const raw = object(readJson(input.rigConfig), 'rig config');
|
|
342
|
+
const config = parseConfig(raw), body = config.turn?.body;
|
|
343
|
+
if (body === undefined || !Object.hasOwn(recipe.groups, 'body')) {
|
|
344
|
+
return fail('DEPTH_PLACE_GROUP', 'config.turn.body', 'requires a declared 2.5D body turn and a body depth recipe group');
|
|
345
|
+
}
|
|
346
|
+
const firstSurface = Object.entries(body.roles).find(([, role]) => role === 'surface')?.[0];
|
|
347
|
+
if (firstSurface !== place.anchor || !Object.hasOwn(recipe.parts, place.anchor) || recipe.parts[place.anchor].group !== 'body') {
|
|
348
|
+
return fail('DEPTH_PLACE_ANCHOR', 'place.anchor', `names "${place.anchor}"; required the first body surface (${JSON.stringify(firstSurface)}) declared in recipe.parts for the body group`);
|
|
349
|
+
}
|
|
350
|
+
const reliefs = new Map(Object.entries(recipe.parts).filter(([, p]) => p.group === 'body').map(([name, p]) => [name, p.relief]));
|
|
351
|
+
const selected = new Set(reliefs.keys());
|
|
352
|
+
const groupProblems = [...selected].filter(part => !Object.hasOwn(body.roles, part)).map(part => ({
|
|
353
|
+
code: 'DEPTH_GROUP_BINDING', object: part, detail: 'declares the body group; register the part in config.turn.body.roles',
|
|
354
|
+
}));
|
|
355
|
+
for (const [part, role] of Object.entries(body.roles)) if (role === 'unit') {
|
|
356
|
+
selected.add(part);
|
|
357
|
+
if (!names.has(part)) groupProblems.push({
|
|
358
|
+
code: 'DEPTH_PART_RESOLVES', object: part, detail: 'is declared as a body turn unit but names no assembled part; use exact parts.json names',
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
for (const part of place.round ?? []) if (!selected.has(part)) groupProblems.push({
|
|
362
|
+
code: 'DEPTH_PLACE_ROUND', object: `place.round, part ${JSON.stringify(part)}`, detail: 'must resolve to a body recipe part or a body turn unit',
|
|
363
|
+
});
|
|
364
|
+
if (groupProblems.length) throw new PartsError(groupProblems);
|
|
365
|
+
const samples = placementSamples(set, map, reliefs, place, selected);
|
|
366
|
+
const scale = checkPlacementScale(place.scale, samples, reliefs);
|
|
367
|
+
const anchorMedian = samples.find(p => p.part === place.anchor)!.rawMedian;
|
|
368
|
+
const anchorZ = recipe.parts[place.anchor].median, sign = place.near === 'white' ? 1 : -1;
|
|
369
|
+
const pivot = typeof place.pivot === 'number' ? place.pivot : 0;
|
|
370
|
+
const parts = samples.map(({ rawMedian, rawP5, rawP95, ...sample }) => {
|
|
371
|
+
const rigMedian = sample.part === place.anchor ? anchorZ : anchorZ + sign * ((rawMedian - anchorMedian) * scale);
|
|
372
|
+
const impliedRelief = reliefs.has(sample.part) ? (rawP95 - rawP5) * scale : null;
|
|
373
|
+
if (!Number.isFinite(rigMedian) || (impliedRelief !== null && !Number.isFinite(impliedRelief))) return fail('DEPTH_PLACE_SCALE', `part "${sample.part}"`, 'placed median or implied relief overflows; declare a representable scale and anchor median');
|
|
374
|
+
return { ...sample, rawMedian, rawP5, rawP95, rigMedian, impliedRelief };
|
|
375
|
+
});
|
|
376
|
+
const bodyGroup = recipe.groups.body;
|
|
377
|
+
const unitRows = parts.filter(({ part }) => body.roles[part] === 'unit');
|
|
378
|
+
const turn = object(raw.turn, 'config.turn'), rawBody = object(turn.body, 'config.turn.body');
|
|
379
|
+
rawBody.pivot = pivot;
|
|
380
|
+
bodyGroup.pivot = pivot;
|
|
381
|
+
if (unitRows.length) {
|
|
382
|
+
// The body producer projects these world depths against the first surface.
|
|
383
|
+
const unitDepths = { ...(body.unitDepths ?? config.turn?.unitDepths), ...bodyGroup.unitDepths,
|
|
384
|
+
...Object.fromEntries(unitRows.map(({ part, rigMedian }) => [part, rigMedian])) };
|
|
385
|
+
rawBody.unitDepths = unitDepths;
|
|
386
|
+
// depth-apply applies a recipe's authored override after reading the rig config.
|
|
387
|
+
if (bodyGroup.unitDepths !== undefined) bodyGroup.unitDepths = unitDepths;
|
|
388
|
+
}
|
|
389
|
+
for (const { part, rigMedian } of parts) if (reliefs.has(part)) recipe.parts[part].median = rigMedian;
|
|
390
|
+
recipe.place = { ...place, scale };
|
|
391
|
+
parseConfig(raw);
|
|
392
|
+
const report: DepthPlacementReport = { spec: 'rig-parts-depth-place-report/1', near: place.near, scale, anchor: place.anchor, pivot, parts };
|
|
393
|
+
return { report, write(out, turnCheck) {
|
|
394
|
+
const dir = resolve(out);
|
|
395
|
+
emptyOutput(dir, sources);
|
|
396
|
+
const relocated = structuredClone(raw), placedRecipe = structuredClone(recipe);
|
|
397
|
+
relocateConfigReferences(relocated, configDir, dir, 'relative');
|
|
398
|
+
const mapAt = (path: string): string => isAbsolute(path) ? path : relative(dir, resolve(recipeDir, path));
|
|
399
|
+
for (const p of Object.values(placedRecipe.parts)) p.map = mapAt(p.map);
|
|
400
|
+
placedRecipe.place!.map = mapAt(place.map);
|
|
401
|
+
const paths = { recipe: join(dir, 'recipe.json'), config: join(dir, 'config.json') };
|
|
402
|
+
const reportJson = text(turnCheck === undefined ? report : { ...report, turnCheck });
|
|
403
|
+
mkdirSync(dir, { recursive: true });
|
|
404
|
+
writeFileSync(paths.recipe, text(placedRecipe), { flag: 'wx' });
|
|
405
|
+
writeFileSync(paths.config, text(relocated), { flag: 'wx' });
|
|
406
|
+
writeFileSync(join(dir, 'depth-place-report.json'), reportJson, { flag: 'wx' });
|
|
407
|
+
return paths;
|
|
408
|
+
} };
|
|
409
|
+
}
|
|
410
|
+
|
|
125
411
|
function registeredMap(map: NumericMap, p: PreparedPart, frame: PartMap['frame'], at: string): NumericMap {
|
|
126
412
|
const [w, h] = frame === 'part' ? p.size : frame === 'input' ? p.inputSize : p.upscaled;
|
|
127
413
|
if (map.width !== w || map.height !== h) return fail('DEPTH_MAP_SIZE', at, `is ${map.width}x${map.height}; declared ${frame} frame is ${w}x${h}`);
|
package/src/localweights.ts
CHANGED
|
@@ -6,15 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* ## The falloff, as a definition
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* The nominal linear share is
|
|
10
10
|
*
|
|
11
11
|
* g = 1 inside the region (its boundary included)
|
|
12
12
|
* g = 1 − d / band at a distance d from the region, 0 < d < band
|
|
13
13
|
* g = 0 at d ≥ band (for band 0: everywhere outside)
|
|
14
14
|
*
|
|
15
15
|
* where d is the Euclidean distance to the circle (|p − c| − r) or to the
|
|
16
|
-
* nearest point of the polygon's edges.
|
|
17
|
-
* no smoothstep, no tuned curve. The two decisions that are not a value in
|
|
16
|
+
* nearest point of the polygon's edges. The two decisions that are not a value in
|
|
18
17
|
* between — "inside" (g = 1) and "at or past the band" (g = 0) — are made
|
|
19
18
|
* EXACTLY: every region number is a multiple of 1/256 px (the config loader
|
|
20
19
|
* refuses anything else) and every vertex this package writes is too
|
|
@@ -23,7 +22,11 @@
|
|
|
23
22
|
* inside by the crossing rule on integer orientations, its distance to an edge
|
|
24
23
|
* compared squared in `BigInt`. Only a value strictly in between is computed
|
|
25
24
|
* in doubles (`Math.sqrt` and the reference's segment arithmetic), and it is
|
|
26
|
-
* clamped to [0, 1].
|
|
25
|
+
* clamped to [0, 1]. Contour weighting applies `4 * g * g * (1 - g)` for
|
|
26
|
+
* `0 < g < 0.5` after the overlap check (issue #1578). The cubic reaches the
|
|
27
|
+
* cutoff with zero slope and meets the inner half at the same value and slope.
|
|
28
|
+
* Declaring `falloff: 'linear'` keeps the nominal share throughout the band,
|
|
29
|
+
* as automatic weighting does.
|
|
27
30
|
*
|
|
28
31
|
* ## The vertex's weights (see {@link localInfluences})
|
|
29
32
|
*
|
|
@@ -44,8 +47,8 @@
|
|
|
44
47
|
* lightest bone (its last) is dropped and the rest renormalised before the
|
|
45
48
|
* scaling, so g itself is never cut. **The floor:** the minimum weight is
|
|
46
49
|
* applied inside `S` (as today) and not again to the scaled shares — a
|
|
47
|
-
* share (1 − g)·S(b) under 0.03 is the
|
|
48
|
-
*
|
|
50
|
+
* share (1 − g)·S(b) under 0.03 is part of the blend, and dropping it would
|
|
51
|
+
* put a step into the ramp.
|
|
49
52
|
* The rounding: see `roundShares` in `src/rig.ts`.
|
|
50
53
|
*
|
|
51
54
|
* ## Overlapping regions
|
|
@@ -63,7 +66,7 @@
|
|
|
63
66
|
* between vertices are not refused, and there the mesh interpolates between
|
|
64
67
|
* vertices that each hold one region.
|
|
65
68
|
*/
|
|
66
|
-
import type { Point } from './config.ts';
|
|
69
|
+
import type { ContourRegionSpec, Point } from './config.ts';
|
|
67
70
|
import { GRID } from './contour.ts';
|
|
68
71
|
import { DEFAULT_LIMITS, DISTANCE_EXPONENT, type Influence, influences, type InfluenceLimits, type Segment, segmentDistance } from './weights.ts';
|
|
69
72
|
|
|
@@ -121,8 +124,8 @@ function insideRing(px: number, py: number, xs: readonly number[], ys: readonly
|
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
/**
|
|
124
|
-
* The
|
|
125
|
-
*
|
|
127
|
+
* The nominal linear share at `p` (same frame as the region), used to decide
|
|
128
|
+
* support. `p` must be on the 1/256 px grid. See the module header for
|
|
126
129
|
* which decisions are exact.
|
|
127
130
|
*/
|
|
128
131
|
export function regionWeight(p: Point, reg: WeightRegion): number {
|
|
@@ -167,6 +170,7 @@ export interface LocalInfluence {
|
|
|
167
170
|
influences: Influence[];
|
|
168
171
|
/** The region that reached the vertex (g > 0), by index, or -1. */
|
|
169
172
|
region: number;
|
|
173
|
+
/** The unrounded region share used in the blend. */
|
|
170
174
|
g: number;
|
|
171
175
|
}
|
|
172
176
|
|
|
@@ -175,7 +179,9 @@ export interface LocalInfluence {
|
|
|
175
179
|
* given, is `S` from another rule — bone heat's shares at the vertex
|
|
176
180
|
* (`src/heat.ts`, issue #161), already capped and floored by `limits` — and
|
|
177
181
|
* the regions apply to it exactly as to the distance rule's. Returns the
|
|
178
|
-
* overlap
|
|
182
|
+
* nominal overlap when two regions both reach the vertex. With `context`
|
|
183
|
+
* set to `contour`, the chosen region's outer half is eased by default.
|
|
184
|
+
* Order: with no
|
|
179
185
|
* region, `S`'s own order; with a region, the region's bone first, then `S`'s
|
|
180
186
|
* bones in `S`'s order.
|
|
181
187
|
*/
|
|
@@ -183,10 +189,11 @@ export function localInfluences(
|
|
|
183
189
|
p: Point,
|
|
184
190
|
segments: readonly Segment[],
|
|
185
191
|
r: number,
|
|
186
|
-
regions: readonly WeightRegion[],
|
|
192
|
+
regions: readonly (WeightRegion & Pick<ContourRegionSpec, 'falloff'>)[],
|
|
187
193
|
limits: InfluenceLimits = DEFAULT_LIMITS,
|
|
188
194
|
exponent: number = DISTANCE_EXPONENT,
|
|
189
195
|
shares?: Influence[],
|
|
196
|
+
context?: 'contour',
|
|
190
197
|
): LocalInfluence | RegionOverlap {
|
|
191
198
|
let region = -1;
|
|
192
199
|
let g = 0;
|
|
@@ -199,7 +206,8 @@ export function localInfluences(
|
|
|
199
206
|
}
|
|
200
207
|
const S = shares ?? influences(p, segments, r, limits, exponent);
|
|
201
208
|
if (region < 0) return { influences: S, region, g: 0 };
|
|
202
|
-
const bone = regions[region]
|
|
209
|
+
const { bone, falloff } = regions[region];
|
|
210
|
+
if (context === 'contour' && falloff !== 'linear' && g < 0.5) g = 4 * g * g * (1 - g);
|
|
203
211
|
if (g >= 1) return { influences: [{ bone, weight: 1 }], region, g };
|
|
204
212
|
let base = S;
|
|
205
213
|
if (!S.some((e) => e.bone === bone) && S.length >= limits.maxInfluences) {
|
package/src/rig.ts
CHANGED
|
@@ -2118,6 +2118,11 @@ export function buildWaistPairSource(
|
|
|
2118
2118
|
const w = img.width;
|
|
2119
2119
|
const h = img.height;
|
|
2120
2120
|
const regions = contourRegionsOf(spec);
|
|
2121
|
+
const explicitRegions = spec.regions?.length ?? 0;
|
|
2122
|
+
// The shorthand appends its derived circles, which keep the legacy ramp.
|
|
2123
|
+
const weightRegions = spec.bust === undefined ? regions : regions.map((rg, index) =>
|
|
2124
|
+
index < explicitRegions ? rg : { ...rg, falloff: 'linear' as const },
|
|
2125
|
+
);
|
|
2121
2126
|
const ribs = chainRibs(ribSpec.segments, ribSpec.ribs, ox, oy);
|
|
2122
2127
|
const cm = rigContour(p, img, spec, ribs);
|
|
2123
2128
|
if (Array.isArray(cm)) {
|
|
@@ -2147,7 +2152,7 @@ export function buildWaistPairSource(
|
|
|
2147
2152
|
const wx = vx + ox;
|
|
2148
2153
|
const wy = vy + oy;
|
|
2149
2154
|
const vSegs = segsAt(wy);
|
|
2150
|
-
const li = localInfluences([wx, wy], vSegs, r,
|
|
2155
|
+
const li = localInfluences([wx, wy], vSegs, r, weightRegions, limits, exponent ?? DISTANCE_EXPONENT, heat === null ? undefined : heatInfluences(heat, [vx, vy], limits), 'contour');
|
|
2151
2156
|
if ('first' in li) {
|
|
2152
2157
|
if (!overlapped) {
|
|
2153
2158
|
let bustHint = '';
|
|
@@ -2205,7 +2210,6 @@ export function buildWaistPairSource(
|
|
|
2205
2210
|
for (const [x, y] of cm.vertices) uvs.push(pyRound(x / w, 6), pyRound(y / h, 6));
|
|
2206
2211
|
const bones = new Set(segs.map((s) => s.bone));
|
|
2207
2212
|
for (const rg of regions) bones.add(rg.bone);
|
|
2208
|
-
const explicitRegions = spec.regions?.length ?? 0;
|
|
2209
2213
|
if (explicitRegions > 0) {
|
|
2210
2214
|
contourRegionSummaries.set(
|
|
2211
2215
|
p.name,
|