rig-parts 2.58.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 +2 -0
- package/cli.ts +145 -4
- package/docs/AUTHORING.md +163 -39
- package/docs/DEPTH.md +114 -29
- package/docs/STABILITY.md +65 -5
- package/package.json +2 -2
- package/src/config.ts +12 -8
- package/src/depthmaps.ts +14 -4
- package/src/depthworkflow.ts +322 -7
- package/src/localweights.ts +20 -12
- package/src/modelarray.ts +206 -0
- package/src/neckdraft.ts +3 -3
- package/src/rig.ts +61 -38
- package/src/turn.ts +86 -18
package/README.md
CHANGED
|
@@ -277,7 +277,9 @@ 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) |
|
|
282
|
+
| `depth-map` | [Convert a NumPy array to a depth or normals map](docs/DEPTH.md#convert-a-numpy-array) |
|
|
281
283
|
| `depth-bind` | [Bind a depth map to its prepared input](docs/DEPTH.md#3-bind-every-map-to-its-prepared-input) |
|
|
282
284
|
| `depth-apply` | [Apply depth maps to the parts as depth sheets](docs/DEPTH.md#4-apply-the-maps-as-depth-sheets) |
|
|
283
285
|
| `edited-part` | [Record an edited part receipt](docs/AUTHORING.md#edited-rig-space-parts-assembleedited_parts-issue-1278) |
|
package/cli.ts
CHANGED
|
@@ -3,7 +3,9 @@ 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
|
+
import { depthMapFail } from './src/depthmaps.ts';
|
|
8
|
+
import { modelArrayMap, serializeModelArrayMap } from './src/modelarray.ts';
|
|
7
9
|
import { externalReceipt } from './src/externalreceipt.ts';
|
|
8
10
|
import { BUST_LANDMARKS_ACT_SCHEMA, BUST_LANDMARKS_COMMENT_ACT_SCHEMA, BUST_LANDMARKS_PROVENANCE_SPEC, BUST_LANDMARKS_PROVENANCE_SUFFIX, BUST_POINT_SHAPE_FIELDS, bustShapeClause, type BustSidecar, effectiveBustShape, planBustLandmarks, readBustSidecar, stageBustLandmarks, stageReplacements, type StagedBustLandmarks } from './src/bustlandmarks.ts';
|
|
9
11
|
import { writeEditedPart } from './tools/edited-part-cli.ts';
|
|
@@ -21,7 +23,7 @@ import { writeEditedPart } from './tools/edited-part-cli.ts';
|
|
|
21
23
|
*/
|
|
22
24
|
import { spawnSync } from 'node:child_process';
|
|
23
25
|
import { runBuildProcess, processRigcRunner as rigcRunner } from './tools/build-process.ts';
|
|
24
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { existsSync, linkSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
25
27
|
import { tmpdir } from 'node:os';
|
|
26
28
|
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
27
29
|
import { DEFAULT_PROJECT_RULE, DEFAULT_SEAM_RULE, headGarmentOverlaps, headGarmentWarning, HOLES_LISTED, PROJECT_RULES, type ProjectRule, proposeFields, proposePlan, proposeSinglePlan, SEAM_RULES, type SeamRule } from './src/assemble.ts';
|
|
@@ -34,7 +36,7 @@ import { coreCfg, DEFAULT_GROW_PX, runForeground } from './src/plate.ts';
|
|
|
34
36
|
import { type CharacterConfig, loadClothConfig, loadConfig, loadEarlyConfig, loadPaintConfig } from './src/config.ts';
|
|
35
37
|
import { type ConfigWritePatch, onlyMissingAttachments } from './src/configwrite.ts';
|
|
36
38
|
import { configWriteLines, type ConfigWriteTarget, readConfigWriteTarget, separateConfigWriteTarget, stageConfigWrite, type StagedConfigWrite } from './tools/configwrite.ts';
|
|
37
|
-
import { failLine, guidePointer, PartsError, type Problem } from './src/errors.ts';
|
|
39
|
+
import { failLine, guidePointer, PartsError, type Problem, problemLine } from './src/errors.ts';
|
|
38
40
|
import { GUIDE_DOC, type GuideAnswer, guideRule, guideSection } from './src/guide.ts';
|
|
39
41
|
import { proposeHeadBox, type Box } from './src/headbox.ts';
|
|
40
42
|
import { headCropPreflight, headCropPreflightLines } from './src/headcroppreflight.ts';
|
|
@@ -51,7 +53,7 @@ import { chainsLeftBehind, clothConfigEdits, editPaths, plainCount, previousCoun
|
|
|
51
53
|
import { INPUT_CHECK_FILE, INPUT_CHECK_SPEC, PROVENANCE_FILE, REMESH_SPEC, remeshStage } from './src/remesh.ts';
|
|
52
54
|
import { RETUNE_FILE, RETUNE_SPEC, retuneStage } from './src/retune.ts';
|
|
53
55
|
import { checkPainting, DEFAULT_PAINTING_FORM, isPaintingForm, PAINTING_FORMS, paintingFormOf } from './src/paintcheck.ts';
|
|
54
|
-
import { readPng, writePng } from './src/raster/png.ts';
|
|
56
|
+
import { decodePngBytes, readPng, writePng } from './src/raster/png.ts';
|
|
55
57
|
import { REQUIREMENTS_SENTENCE } from './src/requirements.ts';
|
|
56
58
|
import { composeStage, IMAGE_SEP, PLATE, PROVENANCES, SCENE_REPORT_FILE, SCENE_REPORT_SPEC, SCENE_SPEC } from './src/scene.ts';
|
|
57
59
|
import { buildSheet, defaultCaption, type Tile, tilesFrom } from './src/sheet.ts';
|
|
@@ -100,6 +102,17 @@ usage:
|
|
|
100
102
|
Write per-part inference PNGs on neutral gray, upscaled and padded as
|
|
101
103
|
declared, plus a source-hashed manifest. No model is bundled or called.
|
|
102
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
|
+
|
|
110
|
+
rig-parts depth-map --array <file.npy> --input <prepared.png> --kind <depth|normals>
|
|
111
|
+
--part <name> --out <map.json> [--padding LEFT,TOP,RIGHT,BOTTOM]
|
|
112
|
+
Convert little-endian float32/float64 C-order NumPy values to rig-parts-map/1.
|
|
113
|
+
Crop declared array padding before integer box pooling to the prepared PNG
|
|
114
|
+
size. Normalize signed XYZ normals after pooling. Print the depth-bind command.
|
|
115
|
+
|
|
103
116
|
rig-parts depth-bind --map <numeric-map.json> --input <prepared.png> --part <name>
|
|
104
117
|
Write <map>.binding.json with both file hashes; never overwrite a receipt.
|
|
105
118
|
Attests the current files, not that inference used this input.
|
|
@@ -1260,8 +1273,10 @@ const TAKES = {
|
|
|
1260
1273
|
'bust-landmarks': { valued: ['--from-act', '--parts', '--config', '--out'], switches: ['--write-config', '--help'] },
|
|
1261
1274
|
'diff-components': { valued: ['--stack', '--painting', '--parts', '--figure', '--floor', '--threshold', '--out', '--verify'], switches: ['--owners', '--help'] },
|
|
1262
1275
|
'diff-drafts': { valued: ['--left', '--right', '--out'], switches: ['--help'] },
|
|
1276
|
+
'depth-map': { valued: ['--array', '--input', '--kind', '--part', '--out', '--padding'], switches: ['--help'] },
|
|
1263
1277
|
'depth-bind': { valued: ['--map', '--input', '--part'], switches: ['--help'] },
|
|
1264
1278
|
'depth-prepare': { valued: ['--parts', '--config', '--out'], switches: ['--help'] },
|
|
1279
|
+
'depth-place': { valued: ['--parts', '--config', '--rig-config', '--out'], switches: ['--check-turn', '--help'] },
|
|
1265
1280
|
'depth-apply': { valued: ['--parts', '--manifest', '--config', '--rig-config', '--out', '--groups'], switches: ['--help'] },
|
|
1266
1281
|
layers: { valued: ['--export', '--template', '--canvas', '--full', '--source', '--config'], switches: ['--help'] },
|
|
1267
1282
|
sheet: { valued: ['--source', '--layers', '--out', '--cell', '--cols'], switches: ['--help'] },
|
|
@@ -2950,6 +2965,60 @@ function cmdBustLandmarks(args: string[]): number {
|
|
|
2950
2965
|
} catch (error) { return printRefusal(error); }
|
|
2951
2966
|
}
|
|
2952
2967
|
|
|
2968
|
+
function readDepthMapInput(file: string): Uint8Array {
|
|
2969
|
+
try {
|
|
2970
|
+
if (!statSync(file).isFile()) throw new Error('found a nonregular file');
|
|
2971
|
+
return readFileSync(file);
|
|
2972
|
+
} catch (error) {
|
|
2973
|
+
return depthMapFail('DEPTH_INPUT_PRESENT', JSON.stringify(file),
|
|
2974
|
+
`read failed (${JSON.stringify(error instanceof Error ? error.message : String(error))}); required a readable regular file`);
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
function writeDepthMapFile(out: string, contents: string): void {
|
|
2979
|
+
try {
|
|
2980
|
+
const stage = mkdtempSync(join(realpathSync(dirname(out)), '.depth-map-'));
|
|
2981
|
+
try {
|
|
2982
|
+
const candidate = join(stage, 'map.json');
|
|
2983
|
+
writeFileSync(candidate, contents, { flag: 'wx' });
|
|
2984
|
+
// Publish complete bytes exclusively, including when two writers race for --out.
|
|
2985
|
+
linkSync(candidate, out);
|
|
2986
|
+
} finally {
|
|
2987
|
+
rmSync(stage, { recursive: true, force: true });
|
|
2988
|
+
}
|
|
2989
|
+
} catch (error) {
|
|
2990
|
+
const code = error !== null && typeof error === 'object' && 'code' in error ? String(error.code) : 'unknown error';
|
|
2991
|
+
return depthMapFail('DEPTH_OUTPUT_EMPTY', JSON.stringify(out),
|
|
2992
|
+
`map write failed (${code}); required an absent output file in a writable directory`);
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
function cmdDepthMap(args: string[]): number {
|
|
2997
|
+
const f = flags(args, 'depth-map', ['--array', '--input', '--kind', '--part', '--out']);
|
|
2998
|
+
if (typeof f === 'string') return usage(f);
|
|
2999
|
+
const array = f.get('--array')!, input = f.get('--input')!, part = f.get('--part')!, out = f.get('--out')!;
|
|
3000
|
+
try {
|
|
3001
|
+
// Match depth-bind's accepted part names so the printed command can use the same name.
|
|
3002
|
+
if (!part || part.startsWith('.') || /[\\/]/.test(part) || part.includes('\0')) {
|
|
3003
|
+
return depthMapFail('DEPTH_MAP_BINDING', 'depth-map --part',
|
|
3004
|
+
`found ${JSON.stringify(part)}; required a nonempty plain part filename accepted by depth-bind`);
|
|
3005
|
+
}
|
|
3006
|
+
const raw = readDepthMapInput(array), png = readDepthMapInput(input);
|
|
3007
|
+
let image: ReturnType<typeof decodePngBytes>;
|
|
3008
|
+
try { image = decodePngBytes(png, JSON.stringify(input)); }
|
|
3009
|
+
catch (error) {
|
|
3010
|
+
return depthMapFail('DEPTH_INPUT_PRESENT', JSON.stringify(input),
|
|
3011
|
+
`decode failed (${JSON.stringify(error instanceof Error ? error.message : String(error))}); required a decodable prepared PNG`);
|
|
3012
|
+
}
|
|
3013
|
+
const map = modelArrayMap(raw, image, f.get('--kind')!, f.get('--padding'), JSON.stringify(array));
|
|
3014
|
+
writeDepthMapFile(out, serializeModelArrayMap(map));
|
|
3015
|
+
const quote = (value: string): string => "'" + value.replaceAll("'", "'\"'\"'") + "'";
|
|
3016
|
+
console.log(`depth-map: wrote ${JSON.stringify(out)} (${map.width}x${map.height}, ${map.channels} channel(s))`);
|
|
3017
|
+
console.log(`rig-parts depth-bind --map ${quote(out)} --input ${quote(input)} --part ${quote(part)}`);
|
|
3018
|
+
return EXIT_OK;
|
|
3019
|
+
} catch (error) { return printRefusal(error); }
|
|
3020
|
+
}
|
|
3021
|
+
|
|
2953
3022
|
function cmdDepthBind(args: string[]): number {
|
|
2954
3023
|
const f = flags(args, 'depth-bind', ['--map', '--input', '--part']);
|
|
2955
3024
|
if (typeof f === 'string') return usage(f);
|
|
@@ -2975,6 +3044,76 @@ function cmdDepthApply(args: string[]): number {
|
|
|
2975
3044
|
} catch (error) { return printRefusal(error); }
|
|
2976
3045
|
}
|
|
2977
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
|
+
|
|
2978
3117
|
function main(argv: string[]): number | Promise<number> {
|
|
2979
3118
|
const [command, ...rest] = argv;
|
|
2980
3119
|
if (command === undefined || command === '--help' || command === '-h' || command === 'help') {
|
|
@@ -2991,6 +3130,8 @@ function main(argv: string[]): number | Promise<number> {
|
|
|
2991
3130
|
if (command === 'diff-drafts') return cmdDiffDrafts(rest);
|
|
2992
3131
|
if (command === 'layers') return cmdLayers(rest);
|
|
2993
3132
|
if (command === 'depth-prepare') return cmdDepthPrepare(rest);
|
|
3133
|
+
if (command === 'depth-map') return cmdDepthMap(rest);
|
|
3134
|
+
if (command === 'depth-place') return cmdDepthPlace(rest);
|
|
2994
3135
|
if (command === 'edited-part') return cmdEditedPart(rest);
|
|
2995
3136
|
if (command === 'external-receipt') return cmdExternalReceipt(rest);
|
|
2996
3137
|
if (command === 'bust-landmarks') return cmdBustLandmarks(rest);
|