@rig-c/parts 1.66.0 → 1.68.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 +22 -3
- package/cli.ts +10 -1
- package/docs/AUTHORING.md +128 -14
- package/docs/MIGRATION.md +30 -1
- package/docs/STABILITY.md +95 -4
- package/package.json +2 -2
- package/skills/rig-parts/SKILL.md +1 -1
- package/src/assemble.ts +63 -13
- package/src/automotion.ts +21 -1
- package/src/build.ts +40 -6
- package/src/check.ts +104 -2
- package/src/comfy/seethrough.ts +7 -2
- package/src/config.ts +143 -12
- package/src/depthsheets.ts +418 -0
- package/src/layers.ts +24 -12
- package/src/limblayout.ts +2 -2
- package/src/limbslots.ts +1 -1
- package/src/motion.ts +4 -1
- package/src/motionseampose.ts +117 -0
- package/src/motionseams.ts +91 -0
- package/src/parts.ts +17 -4
- package/src/propose.ts +14 -8
- package/src/rig.ts +290 -26
- package/src/turn.ts +444 -6
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Posed-axis evidence from one stock seam render, never sampled source keys. */
|
|
2
|
+
import type { GeometryFile, GeometryFrame } from 'rig-c/render';
|
|
3
|
+
import type { FrameSet } from './check.ts';
|
|
4
|
+
import { PartsError } from './errors.ts';
|
|
5
|
+
|
|
6
|
+
// Stock rig-c 2.69 geometry header, also exported by rig-c/render. render-shared
|
|
7
|
+
// does not expose its constants; avoid loading the optional Spine side for a header read.
|
|
8
|
+
export const SEAM_GEOMETRY_COORDINATES = 'spine world, y up, world units';
|
|
9
|
+
const SEAM_GEOMETRY_SPEC: GeometryFile['spec'] = 'rigc-geometry/1';
|
|
10
|
+
|
|
11
|
+
export interface SeamMatrix {
|
|
12
|
+
a: number; b: number; c: number; d: number;
|
|
13
|
+
worldX: number; worldY: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SeamJointPose {
|
|
16
|
+
bone: string;
|
|
17
|
+
parent: string | null;
|
|
18
|
+
world_x_axis_degrees: number | null;
|
|
19
|
+
parent_relative_setup_axis_delta_degrees_mod360: number | null;
|
|
20
|
+
static_range: [number, number] | null;
|
|
21
|
+
comparison: 'axis-modulo-360' | 'unavailable';
|
|
22
|
+
reason?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SeamPoseAtWorst {
|
|
25
|
+
index: number;
|
|
26
|
+
time: number;
|
|
27
|
+
joints: SeamJointPose[];
|
|
28
|
+
}
|
|
29
|
+
const record = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
30
|
+
const fail = (detail: string): never => { throw new PartsError([{ code: 'CHECK_GEOMETRY_FILE', object: 'motion seam pose', detail }]); };
|
|
31
|
+
const wrap = (degrees: number): number => ((degrees + 180) % 360 + 360) % 360 - 180;
|
|
32
|
+
const angle = (a: number, c: number): number => Math.atan2(c, a) * 180 / Math.PI;
|
|
33
|
+
const inverseProduct = (p: SeamMatrix, c: SeamMatrix): SeamMatrix | null => {
|
|
34
|
+
const det = p.a * p.d - p.b * p.c;
|
|
35
|
+
if (det === 0 || !Number.isFinite(det)) return null;
|
|
36
|
+
const a = (p.d * c.a - p.b * c.c) / det, b = (p.d * c.b - p.b * c.d) / det;
|
|
37
|
+
const x = (-p.c * c.a + p.a * c.c) / det, d = (-p.c * c.b + p.a * c.d) / det;
|
|
38
|
+
return { a, b, c: x, d, worldX: 0, worldY: 0 };
|
|
39
|
+
};
|
|
40
|
+
const regular = (m: SeamMatrix): boolean => {
|
|
41
|
+
const x2 = m.a * m.a + m.c * m.c, y2 = m.b * m.b + m.d * m.d;
|
|
42
|
+
// Floating-point arithmetic slack only, relative to the two axis lengths.
|
|
43
|
+
return x2 > 0 && y2 > 0 && m.a * m.d - m.b * m.c > 0 &&
|
|
44
|
+
Math.abs(m.a * m.b + m.c * m.d) <= 64 * Number.EPSILON * Math.sqrt(x2 * y2);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** World axes remain evidence even when local-range equivalence is unavailable. */
|
|
48
|
+
export function seamJointPose(bone: string, parent: string | null, inherit: string, setup: SeamMatrix, posed: SeamMatrix,
|
|
49
|
+
parentSetup: SeamMatrix | null, parentPosed: SeamMatrix | null, range: [number, number] | null, rangeReason?: string): SeamJointPose {
|
|
50
|
+
const out: SeamJointPose = { bone, parent, world_x_axis_degrees: posed.a === 0 && posed.c === 0 ? null : angle(posed.a, posed.c),
|
|
51
|
+
parent_relative_setup_axis_delta_degrees_mod360: null, static_range: range, comparison: 'unavailable' };
|
|
52
|
+
if (inherit !== 'normal') return { ...out, reason: `inherit ${inherit}: parent-relative local-range comparison unavailable` };
|
|
53
|
+
if (parent === null || parentSetup === null || parentPosed === null) return { ...out, reason: 'no parent frame for a local-range comparison' };
|
|
54
|
+
const rest = inverseProduct(parentSetup, setup), frame = inverseProduct(parentPosed, posed);
|
|
55
|
+
if (rest === null || frame === null || !regular(rest) || !regular(frame) || !regular(parentSetup) || !regular(parentPosed)) return { ...out, reason: 'singular, reflected, sheared or degenerate axes: local-range comparison unavailable' };
|
|
56
|
+
const delta = wrap(angle(frame.a, frame.c) - angle(rest.a, rest.c));
|
|
57
|
+
out.parent_relative_setup_axis_delta_degrees_mod360 = delta;
|
|
58
|
+
if (range === null) return { ...out, reason: rangeReason ?? 'no declared static range; relative axis delta is modulo 360' };
|
|
59
|
+
if (range[0] <= -180 || range[1] >= 180 || Math.abs(delta) === 180) return { ...out, reason: 'ambiguous winding against static range; relative axis delta is modulo 360' };
|
|
60
|
+
// This is explicitly an axis comparison modulo 360, never an unwrapped local key or a new gate.
|
|
61
|
+
return { ...out, comparison: 'axis-modulo-360', reason: 'normal unsheared axes; modulo 360 only, winding not certified' };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Identical declarations share one range; conflicting declarations remain explicitly ambiguous. */
|
|
65
|
+
export function seamStaticRange(ranges: readonly [number, number][]): { range: [number, number] | null; rangeReason?: string } {
|
|
66
|
+
const unique = [...new Map(ranges.map(range => [JSON.stringify(range), range])).values()];
|
|
67
|
+
return unique.length <= 1 ? { range: unique[0] ?? null }
|
|
68
|
+
: { range: null, rangeReason: `ambiguous declared static ranges ${unique.map(range => JSON.stringify(range)).join(', ')}; no local-range comparison` };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type SeamFrameCohort = Pick<FrameSet, 'animation' | 'fps' | 'viewport'> & { frames: readonly Pick<GeometryFrame, 'index'>[] };
|
|
72
|
+
export interface SeamPoseJoint {
|
|
73
|
+
bone: string;
|
|
74
|
+
parent: string | null;
|
|
75
|
+
inherit: string;
|
|
76
|
+
range: [number, number] | null;
|
|
77
|
+
rangeReason?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Bind stock coordinates, source parent identities and the complete real PNG frame cohort. */
|
|
81
|
+
export function seamPoseFrame(geometry: unknown, animation: string, index: number, time: number, cohort: SeamFrameCohort,
|
|
82
|
+
joints: readonly SeamPoseJoint[]): SeamPoseAtWorst {
|
|
83
|
+
if (!record(geometry) || geometry.spec !== SEAM_GEOMETRY_SPEC || geometry.animation !== animation || cohort.animation !== animation ||
|
|
84
|
+
geometry.fps !== cohort.fps || !record(geometry.viewport) || !Array.isArray(geometry.frames) || !record(geometry.setup)) return fail('same-animation stock geometry with matching fps, viewport, setup and frames required');
|
|
85
|
+
if (geometry.coordinates !== SEAM_GEOMETRY_COORDINATES) return fail(`coordinates must be ${JSON.stringify(SEAM_GEOMETRY_COORDINATES)}; found ${JSON.stringify(geometry.coordinates)}`);
|
|
86
|
+
const viewport = cohort.viewport;
|
|
87
|
+
for (const key of ['x', 'y', 'width', 'height', 'scale', 'pixelWidth', 'pixelHeight'] as const) {
|
|
88
|
+
if (typeof viewport[key] !== 'number' || !Number.isFinite(viewport[key]) || geometry.viewport[key] !== viewport[key]) return fail(`viewport ${key} differs from frames.json or is not finite`);
|
|
89
|
+
}
|
|
90
|
+
const roster = Array.isArray(geometry.bones) ? geometry.bones.filter(record) : [];
|
|
91
|
+
if (!Array.isArray(geometry.bones) || roster.length !== geometry.bones.length || roster.some(b => typeof b.name !== 'string' || (b.parent !== null && typeof b.parent !== 'string')) ||
|
|
92
|
+
new Set(roster.map(b => b.name)).size !== roster.length) return fail('bone/parent roster requires unique names and explicit string/null parents');
|
|
93
|
+
const declared = new Map<string, GeometryFile['bones'][number]>(roster.map(b => [String(b.name), { name: String(b.name), parent: b.parent as string | null }]));
|
|
94
|
+
for (const b of declared.values()) if (b.parent !== null && !declared.has(b.parent)) return fail(`bone/parent roster: parent "${b.parent}" of "${b.name}" is missing`);
|
|
95
|
+
for (const j of joints) {
|
|
96
|
+
if (!declared.has(j.bone) || declared.get(j.bone)?.parent !== j.parent || (j.parent !== null && !declared.has(j.parent))) return fail(`bone/parent roster for "${j.bone}" disagrees with source parent ${JSON.stringify(j.parent)}`);
|
|
97
|
+
}
|
|
98
|
+
const frames = geometry.frames.filter(record);
|
|
99
|
+
if (frames.length !== geometry.frames.length || frames.some(f => !Number.isSafeInteger(f.index) || Number(f.index) < 0 || typeof f.time !== 'number' || !Number.isFinite(f.time) || f.time < 0) || new Set(frames.map(f => f.index)).size !== frames.length) return fail('frame cohort requires unique integer indices and finite actual times');
|
|
100
|
+
if (frames.length !== cohort.frames.length || frames.some((f, i) => f.index !== cohort.frames[i].index)) return fail('frame cohort differs from the actual PNG frame set (including unselected frames)');
|
|
101
|
+
const frame = frames.find(f => f.index === index);
|
|
102
|
+
if (!Number.isSafeInteger(index) || !Number.isFinite(time) || frame === undefined || frame.time !== time) return fail(`frame ${index}: raw seam and geometry frame/time differ`);
|
|
103
|
+
const matrix = (rows: unknown, name: string): SeamMatrix => {
|
|
104
|
+
const matches = Array.isArray(rows) ? rows.filter(r => record(r) && r.name === name) : [];
|
|
105
|
+
const row = matches[0];
|
|
106
|
+
if (matches.length !== 1 || !record(row) || ['a','b','c','d','worldX','worldY'].some(k => typeof row[k] !== 'number' || !Number.isFinite(row[k]))) return fail(`bone "${name}": one matrix with six finite numbers required`);
|
|
107
|
+
return { a: Number(row.a), b: Number(row.b), c: Number(row.c), d: Number(row.d), worldX: Number(row.worldX), worldY: Number(row.worldY) };
|
|
108
|
+
};
|
|
109
|
+
const required = new Set(joints.flatMap(j => j.parent === null ? [j.bone] : [j.bone, j.parent]));
|
|
110
|
+
for (const name of required) {
|
|
111
|
+
matrix(geometry.setup.bones, name);
|
|
112
|
+
for (const f of frames) matrix(f.bones, name);
|
|
113
|
+
}
|
|
114
|
+
const setupBones = geometry.setup.bones;
|
|
115
|
+
return { index, time, joints: joints.map(j => seamJointPose(j.bone, j.parent, j.inherit, matrix(setupBones, j.bone), matrix(frame.bones, j.bone),
|
|
116
|
+
j.parent === null ? null : matrix(setupBones, j.parent), j.parent === null ? null : matrix(frame.bones, j.parent), j.range, j.rangeReason)) };
|
|
117
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** Explicit motion observations; no automatic declaration in check. */
|
|
2
|
+
import type { BoneEntry, CharacterConfig, Segment } from './config.ts';
|
|
3
|
+
import type { Problem } from './errors.ts';
|
|
4
|
+
import { tagOf, type PartRecord } from './parts.ts';
|
|
5
|
+
|
|
6
|
+
export interface MotionSeamDeclaration {
|
|
7
|
+
part: string;
|
|
8
|
+
neighbour: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Both readers share shape, name, self-pair and unordered uniqueness rules. */
|
|
12
|
+
export function motionSeamProblems(value: unknown, names: ReadonlySet<string>, at: string, code: string): Problem[] {
|
|
13
|
+
const problems: Problem[] = [];
|
|
14
|
+
const bad = (object: string, detail: string): void => { problems.push({ code, object, detail }); };
|
|
15
|
+
if (!Array.isArray(value)) {
|
|
16
|
+
bad(at, 'requires an array of {part, neighbour} declarations');
|
|
17
|
+
return problems;
|
|
18
|
+
}
|
|
19
|
+
const seen = new Set<string>();
|
|
20
|
+
value.forEach((row: unknown, i) => {
|
|
21
|
+
const object = `${at}[${i}]`;
|
|
22
|
+
if (typeof row !== 'object' || row === null || Array.isArray(row)) { bad(object, 'requires {part, neighbour}'); return; }
|
|
23
|
+
const r = row as Record<string, unknown>;
|
|
24
|
+
for (const key of Object.keys(r)) if (key !== 'part' && key !== 'neighbour') bad(`${object}.${key}`, 'is unknown; only part and neighbour are read');
|
|
25
|
+
for (const key of ['part', 'neighbour']) {
|
|
26
|
+
if (typeof r[key] !== 'string' || r[key] === '') bad(`${object}.${key}`, 'requires a nonempty output part name');
|
|
27
|
+
else if (!names.has(r[key])) bad(`${object}.${key}`, `names "${r[key]}", which is no output part; known: ${[...names].join(', ')}`);
|
|
28
|
+
}
|
|
29
|
+
if (typeof r.part !== 'string' || typeof r.neighbour !== 'string') return;
|
|
30
|
+
if (r.part === r.neighbour) bad(object, `names "${r.part}" on both sides; two different parts are required`);
|
|
31
|
+
const key = JSON.stringify([r.part, r.neighbour].sort());
|
|
32
|
+
if (seen.has(key)) bad(object, 'duplicates an earlier pair, including reversed order; declare each unordered pair once');
|
|
33
|
+
seen.add(key);
|
|
34
|
+
});
|
|
35
|
+
return problems;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Expand only declared links; a miss has no inferred parent. */
|
|
39
|
+
export function motionSeamParents(bones: readonly BoneEntry[]): Map<string, string> {
|
|
40
|
+
const parents = new Map<string, string>();
|
|
41
|
+
for (const bone of bones) {
|
|
42
|
+
if ('name' in bone) parents.set(bone.name, bone.parent);
|
|
43
|
+
else bone.points.forEach((_, i) => parents.set(`${bone.chain}${i}`, i === 0 ? bone.parent : `${bone.chain}${i - 1}`));
|
|
44
|
+
}
|
|
45
|
+
return parents;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Source-bound declaration generator, also callable on a frozen handed config.
|
|
50
|
+
* A non-limb topwear mesh has exactly two single-bone carriers, a named parent
|
|
51
|
+
* and child. Every handwear carrier is strictly below the same nearest member
|
|
52
|
+
* of that pair, either parent or child, and none is a trunk carrier itself.
|
|
53
|
+
* This proves the declared binding structure, not positive
|
|
54
|
+
* compiled vertex weights or alpha overlap (the stock seam reader observes that).
|
|
55
|
+
* No motion keys, thresholds, part spelling or nearest geometry select a pair.
|
|
56
|
+
*/
|
|
57
|
+
export function draftMotionSeams(config: Pick<CharacterConfig, 'bones' | 'meshes' | 'regions' | 'limbs'>, parts: readonly Pick<PartRecord, 'name' | 'from' | 'limb'>[]): MotionSeamDeclaration[] {
|
|
58
|
+
const parents = motionSeamParents(config.bones);
|
|
59
|
+
const singles = new Set(config.bones.flatMap(b => 'name' in b ? [b.name] : []));
|
|
60
|
+
const chains = new Map(config.bones.flatMap(b => 'chain' in b ? [[b.chain, b.points.map((_, i) => `${b.chain}${i}`)] as const] : []));
|
|
61
|
+
const bound = (part: string): string[] => {
|
|
62
|
+
const mesh = config.meshes[part];
|
|
63
|
+
if (mesh !== undefined && 'segments' in mesh) return [...new Set(mesh.segments.flatMap((s: Segment) => typeof s === 'string' ? chains.get(s) ?? [s] : [s[0]]))];
|
|
64
|
+
const region = config.regions[part];
|
|
65
|
+
return region === undefined ? [] : [typeof region === 'string' ? region : region.bone];
|
|
66
|
+
};
|
|
67
|
+
const consumed = new Set(Object.values(config.limbs ?? {}).flatMap(l => l.segments.map(s => s.from)));
|
|
68
|
+
const out: MotionSeamDeclaration[] = [];
|
|
69
|
+
for (const body of parts) {
|
|
70
|
+
if (body.limb !== undefined || consumed.has(body.name) || tagOf(body.from) !== 'topwear' || config.meshes[body.name] === undefined) continue;
|
|
71
|
+
const trunk = bound(body.name);
|
|
72
|
+
if (trunk.length !== 2 || !trunk.every(b => singles.has(b))) continue;
|
|
73
|
+
const child = trunk.find(b => parents.get(b) === trunk.find(other => other !== b));
|
|
74
|
+
if (child === undefined) continue;
|
|
75
|
+
for (const sleeve of parts) {
|
|
76
|
+
if (sleeve.limb !== undefined || consumed.has(sleeve.name) || !['handwear-r', 'handwear-l'].includes(tagOf(sleeve.from) ?? '')) continue;
|
|
77
|
+
const carriers = bound(sleeve.name);
|
|
78
|
+
const nearestTrunk = (bone: string): string | undefined => {
|
|
79
|
+
const seen = new Set<string>();
|
|
80
|
+
for (let b: string | undefined = parents.get(bone); b !== undefined && !seen.has(b); b = parents.get(b)) {
|
|
81
|
+
if (trunk.includes(b)) return b;
|
|
82
|
+
seen.add(b);
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
};
|
|
86
|
+
const carrierTrunk = carriers.length === 0 ? undefined : nearestTrunk(carriers[0]);
|
|
87
|
+
if (carrierTrunk !== undefined && carriers.every(b => parents.has(b) && !trunk.includes(b) && nearestTrunk(b) === carrierTrunk)) out.push({ part: body.name, neighbour: sleeve.name });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out;
|
|
91
|
+
}
|
package/src/parts.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { partDepthProblems, type PartDepthReference } from './depthsheets.ts';
|
|
1
2
|
/**
|
|
2
3
|
* The output contract of the assemble stage: `parts.json`, one record per
|
|
3
4
|
* part, beside `parts/<name>.png`.
|
|
@@ -85,6 +86,7 @@
|
|
|
85
86
|
* a later stage. The writer's key order is fixed, so two runs over the same
|
|
86
87
|
* inputs write the same bytes.
|
|
87
88
|
*/
|
|
89
|
+
import { motionSeamProblems, type MotionSeamDeclaration } from './motionseams.ts';
|
|
88
90
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
89
91
|
import { type Problem, refuseIfAny } from './errors.ts';
|
|
90
92
|
import { KEYPOINT_NAMES, type PosePoints } from './skeleton.ts';
|
|
@@ -93,6 +95,8 @@ import { edgeLength } from './length.ts';
|
|
|
93
95
|
import { recordedFocusProblems } from './setfocus.ts';
|
|
94
96
|
|
|
95
97
|
export interface PartRecord {
|
|
98
|
+
/** Optional #773 input reference; production geometry does not consume it yet. */
|
|
99
|
+
depth?: PartDepthReference;
|
|
96
100
|
name: string;
|
|
97
101
|
from: string;
|
|
98
102
|
/**
|
|
@@ -355,6 +359,8 @@ export interface PartsFile {
|
|
|
355
359
|
scale_rig_per_source: number;
|
|
356
360
|
parts: PartRecord[];
|
|
357
361
|
ghost_px: Record<string, number>;
|
|
362
|
+
/** Explicit observations only; check never regenerates a removed declaration. */
|
|
363
|
+
motion_seams?: MotionSeamDeclaration[];
|
|
358
364
|
/** Absent in a `parts.json` the reference wrote; `assemble` always writes it. */
|
|
359
365
|
recomposite?: RecompositeRecord;
|
|
360
366
|
/** Written only under `config.scene` (issue #242): the recomposite was read inside this figure; absent otherwise. */
|
|
@@ -397,8 +403,8 @@ export interface SceneRecord {
|
|
|
397
403
|
figure_mask: string;
|
|
398
404
|
}
|
|
399
405
|
|
|
400
|
-
const TOP_KEYS = ['rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'single_run_pad', 'alternates'] as const;
|
|
401
|
-
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'alternates');
|
|
406
|
+
const TOP_KEYS = ['rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'single_run_pad', 'alternates', 'motion_seams'] as const;
|
|
407
|
+
const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'alternates' && k !== 'motion_seams');
|
|
402
408
|
export const SINGLE_RUN_PAD_KEYS = ['file_size', 'side', 'left', 'top'] as const;
|
|
403
409
|
export const SCENE_KEYS = ['figure_alpha_above', 'figure_px', 'figure_mask'] as const;
|
|
404
410
|
export const RECOMPOSITE_KEYS = ['mean_abs', 'within_limit', 'within_share', 'error_limit', 'error_px', 'covered_alpha', 'uncovered_error_px', 'hole_count', 'holes_listed', 'holes'] as const;
|
|
@@ -424,6 +430,7 @@ export const PART_KEYS = [
|
|
|
424
430
|
'seam_override_px',
|
|
425
431
|
'fringe_pushed_back',
|
|
426
432
|
'limb',
|
|
433
|
+
'depth',
|
|
427
434
|
] as const;
|
|
428
435
|
/** The one part field that is not a count: a list of `{part, px}`, written only when it is not empty. */
|
|
429
436
|
const FRINGE_KEY = 'fringe_pushed_back';
|
|
@@ -431,10 +438,10 @@ const FRINGE_KEY = 'fringe_pushed_back';
|
|
|
431
438
|
const CUT_FROM_KEY = 'cut_from';
|
|
432
439
|
/** The one part field that is a record of its own: a limb segment's provenance (issue #349), written only on one. */
|
|
433
440
|
const LIMB_KEY = 'limb';
|
|
434
|
-
const COUNT_KEYS = PART_KEYS.slice(2).filter((k) => k !== FRINGE_KEY && k !== CUT_FROM_KEY && k !== LIMB_KEY) as ReadonlyArray<(typeof PART_KEYS)[number]>;
|
|
441
|
+
const COUNT_KEYS = PART_KEYS.slice(2).filter((k) => k !== FRINGE_KEY && k !== CUT_FROM_KEY && k !== LIMB_KEY && k !== 'depth') as ReadonlyArray<(typeof PART_KEYS)[number]>;
|
|
435
442
|
/** The port's own counts: all three or none (none = a record the reference wrote). */
|
|
436
443
|
export const VISIBILITY_KEYS = ['visible_px', 'occluded_px', 'visible_not_projected_px'] as const;
|
|
437
|
-
const REQUIRED_KEYS = PART_KEYS.filter((k) => !(VISIBILITY_KEYS as readonly string[]).includes(k) && k !== FRINGE_KEY && k !== CUT_FROM_KEY && k !== LIMB_KEY);
|
|
444
|
+
const REQUIRED_KEYS = PART_KEYS.filter((k) => !(VISIBILITY_KEYS as readonly string[]).includes(k) && k !== FRINGE_KEY && k !== CUT_FROM_KEY && k !== LIMB_KEY && k !== 'depth');
|
|
438
445
|
|
|
439
446
|
/** Where a part came from: a See-through run and a v3 tag or an author-made layer's `author:<label>` (issue #256), or the painting itself for a patch. */
|
|
440
447
|
export type From = { run: 'full' | 'head'; tag: string } | { run: 'painting'; patch: string };
|
|
@@ -475,6 +482,7 @@ export function serializeParts(file: PartsFile): string {
|
|
|
475
482
|
rig_size: file.rig_size,
|
|
476
483
|
scale_rig_per_source: file.scale_rig_per_source,
|
|
477
484
|
parts: serializePartList(file.parts),
|
|
485
|
+
...(file.motion_seams === undefined ? {} : { motion_seams: file.motion_seams.map(({ part, neighbour }) => ({ part, neighbour })) }),
|
|
478
486
|
ghost_px: Object.fromEntries(Object.keys(file.ghost_px).sort().map((k) => [k, file.ghost_px[k]])),
|
|
479
487
|
...(file.recomposite === undefined ? {} : { recomposite: serializeRecomposite(file.recomposite) }),
|
|
480
488
|
...(file.scene === undefined ? {} : { scene: Object.fromEntries(SCENE_KEYS.map((k) => [k, (file.scene as SceneRecord)[k]])) }),
|
|
@@ -568,6 +576,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
568
576
|
return;
|
|
569
577
|
}
|
|
570
578
|
const r = p as Record<string, unknown>;
|
|
579
|
+
if ('depth' in r) problems.push(...partDepthProblems(r.depth, `${path} part depth`));
|
|
571
580
|
const label = typeof r.name === 'string' ? `part "${r.name}"` : at;
|
|
572
581
|
for (const k of Object.keys(r)) if (!(PART_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${label} key "${k}"`, `is not a part field; known: ${PART_KEYS.join(', ')}`);
|
|
573
582
|
for (const k of REQUIRED_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${label} field "${k}"`, 'is absent and required');
|
|
@@ -663,6 +672,10 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
663
672
|
}
|
|
664
673
|
}
|
|
665
674
|
if (Array.isArray(o.parts)) checkLimbRecords(o.parts, '', fail);
|
|
675
|
+
if ('motion_seams' in o) {
|
|
676
|
+
const names = new Set((Array.isArray(o.parts) ? o.parts : []).flatMap(p => typeof p === 'object' && p !== null && typeof p.name === 'string' ? [p.name] : []));
|
|
677
|
+
problems.push(...motionSeamProblems(o.motion_seams, names, `${path} motion_seams`, 'PARTS_MOTION_SEAM'));
|
|
678
|
+
}
|
|
666
679
|
if ('scene' in o) {
|
|
667
680
|
const sc = o.scene;
|
|
668
681
|
if (typeof sc !== 'object' || sc === null || Array.isArray(sc)) fail('PARTS_FIELD_TYPE', `${path} field "scene"`, `is ${show(sc)}; an object is required`);
|
package/src/propose.ts
CHANGED
|
@@ -147,6 +147,8 @@ import { type Mask, newMask, newRaster, type Raster } from './raster/types.ts';
|
|
|
147
147
|
import { npMean, npMedian, npPercentile, pyFixed, pyInt, pyIntList, pyRepr, pyRound, pyStrList } from './pyfmt.ts';
|
|
148
148
|
import type { JointState, RigJoint, RigJoints } from './keypoints.ts';
|
|
149
149
|
import { IDLE_FPS } from './motion.ts';
|
|
150
|
+
import { draftMotionSeams, type MotionSeamDeclaration } from './motionseams.ts';
|
|
151
|
+
export { draftMotionSeams } from './motionseams.ts';
|
|
150
152
|
import { FORK_SMOOTH_MAX_INFLUENCES, influenceFarthest } from './rig.ts';
|
|
151
153
|
import { type Segment as WeightSegment } from './weights.ts';
|
|
152
154
|
import { pyRound as roundTo } from './round.ts';
|
|
@@ -278,6 +280,8 @@ export interface Proposal {
|
|
|
278
280
|
regions: Record<string, string>;
|
|
279
281
|
/** Only under `--keypoints`, where an arm or a leg is drafted from its joints (issue #349): absent otherwise, so a proposal without one is the one written before it. */
|
|
280
282
|
limbs?: Record<string, Limb>;
|
|
283
|
+
/** Source-bound torso/sleeve observations, written only when the structure resolves. */
|
|
284
|
+
motion_seams?: MotionSeamDeclaration[];
|
|
281
285
|
motion: {
|
|
282
286
|
duration: number;
|
|
283
287
|
tracks: Array<ProposedSingleTrack | ProposedChainTrack>;
|
|
@@ -287,7 +291,7 @@ export interface Proposal {
|
|
|
287
291
|
/** Only with `propose --cloth` (issue #364, `src/cloth.ts`): the physics (and a skirt swing's transforms) of the trees it drafted; absent otherwise, so a proposal without it is the one written before it. */
|
|
288
292
|
constraints?: ConfigConstraint[];
|
|
289
293
|
/** Only with `propose --full`/`--head` (issue #251, {@link draftTurn}); absent otherwise, so a proposal without them is the one written before it. */
|
|
290
|
-
turn?: TurnSpec;
|
|
294
|
+
turn?: TurnSpec & { pivot: number; depths: Record<string, number> };
|
|
291
295
|
/** The `assemble.rig_scale` (`parts.json`'s `scale_rig_per_source`) its coordinates were drafted at (issue #354). */
|
|
292
296
|
proposed_rig_scale: number;
|
|
293
297
|
notes: string[];
|
|
@@ -304,7 +308,7 @@ export interface Proposal {
|
|
|
304
308
|
* {@link Proposal} key it does not hold, and the selftest's `TY18` holds every
|
|
305
309
|
* paste sentence in the documents to it.
|
|
306
310
|
*/
|
|
307
|
-
export const PROPOSAL_CONFIG_SECTIONS = ['bones', 'meshes', 'regions', 'limbs', 'motion', 'constraints', 'turn', 'proposed_rig_scale'] as const satisfies ReadonlyArray<Exclude<keyof Proposal, 'notes'>>;
|
|
311
|
+
export const PROPOSAL_CONFIG_SECTIONS = ['bones', 'meshes', 'regions', 'limbs', 'motion', 'constraints', 'turn', 'motion_seams', 'proposed_rig_scale'] as const satisfies ReadonlyArray<Exclude<keyof Proposal, 'notes'>>;
|
|
308
312
|
|
|
309
313
|
/** A {@link Proposal} key that is neither `notes` nor in {@link PROPOSAL_CONFIG_SECTIONS}; `never` while the list is whole. */
|
|
310
314
|
type UnlistedProposalSection = Exclude<keyof Proposal, 'notes' | (typeof PROPOSAL_CONFIG_SECTIONS)[number]>;
|
|
@@ -520,7 +524,7 @@ export type TurnRuns = Partial<Record<'full' | 'head', LayerSet>>;
|
|
|
520
524
|
* each carrier the other run places more than {@link TURN_RUN_APART} of the
|
|
521
525
|
* span away.
|
|
522
526
|
*/
|
|
523
|
-
export function draftTurn(P: PartSet, runs: TurnRuns, binds?: PartBinding): { turn: TurnSpec | null; notes: string[] } {
|
|
527
|
+
export function draftTurn(P: PartSet, runs: TurnRuns, binds?: PartBinding): { turn: (TurnSpec & { pivot: number; depths: Record<string, number> }) | null; notes: string[] } {
|
|
524
528
|
P = P.beforeLimbs();
|
|
525
529
|
const problems: Problem[] = [];
|
|
526
530
|
const read: Array<{ part: string; run: 'full' | 'head'; tag: string; base: string | null; own: number; area: number; order: number; piece: boolean }> = [];
|
|
@@ -611,7 +615,7 @@ export function draftTurn(P: PartSet, runs: TurnRuns, binds?: PartBinding): { tu
|
|
|
611
615
|
notes.push(`turn: every carried part lies at depth ${nearest.depth}, so none is nearer than the pivot and no turn control is drafted`);
|
|
612
616
|
return { turn: null, notes };
|
|
613
617
|
}
|
|
614
|
-
const turn
|
|
618
|
+
const turn = { pivot, depths };
|
|
615
619
|
const fr = turnFractions(turn, rows.map((r) => r.part));
|
|
616
620
|
notes.push(
|
|
617
621
|
`turn: control "${TURN_BONE}" under root, keyed by nothing — its x is the dial. Pivot depth ${pivot}: the mean of the ${rows.length} carried parts' depths weighted by opaque_px, the one depth at which the painted pixels' centroid does not slide (correct it in turn.pivot). ` +
|
|
@@ -647,7 +651,7 @@ export const TURN_DEPTH_CAVEAT: readonly string[] = [
|
|
|
647
651
|
];
|
|
648
652
|
|
|
649
653
|
/** The proposal with `turn` written after `motion` and `notes` extended; the proposal itself when `turn` is null. */
|
|
650
|
-
export function withTurn(p: Proposal, draft: { turn: TurnSpec | null; notes: string[] }): Proposal {
|
|
654
|
+
export function withTurn(p: Proposal, draft: { turn: (TurnSpec & { pivot: number; depths: Record<string, number> }) | null; notes: string[] }): Proposal {
|
|
651
655
|
// Issue #349: a part a limb takes is not made; each of its limb parts carries its depth instead.
|
|
652
656
|
let turn = draft.turn;
|
|
653
657
|
if (turn !== null && p.limbs !== undefined) {
|
|
@@ -659,9 +663,9 @@ export function withTurn(p: Proposal, draft: { turn: TurnSpec | null; notes: str
|
|
|
659
663
|
if (parts === undefined) depths[part] = d;
|
|
660
664
|
else for (const q of parts) depths[q] = d;
|
|
661
665
|
}
|
|
662
|
-
turn = { pivot: turn.pivot, depths };
|
|
666
|
+
turn = { ...turn, pivot: turn.pivot, depths };
|
|
663
667
|
}
|
|
664
|
-
return { bones: p.bones, meshes: p.meshes, regions: p.regions, ...(p.limbs === undefined ? {} : { limbs: p.limbs }), motion: p.motion, ...(p.constraints === undefined ? {} : { constraints: p.constraints }), ...(turn === null ? {} : { turn }), proposed_rig_scale: p.proposed_rig_scale, notes: [...p.notes, ...draft.notes] };
|
|
668
|
+
return { bones: p.bones, meshes: p.meshes, regions: p.regions, ...(p.limbs === undefined ? {} : { limbs: p.limbs }), ...(p.motion_seams === undefined ? {} : { motion_seams: p.motion_seams }), motion: p.motion, ...(p.constraints === undefined ? {} : { constraints: p.constraints }), ...(turn === null ? {} : { turn }), proposed_rig_scale: p.proposed_rig_scale, notes: [...p.notes, ...draft.notes] };
|
|
665
669
|
}
|
|
666
670
|
|
|
667
671
|
// ---------------------------------------------------------------------------
|
|
@@ -3493,8 +3497,10 @@ export function proposeWithBasis(
|
|
|
3493
3497
|
meshes[name] = { influence: { cell, radius, across: decl.across, max, shape: decl.shape, ...(held ? { hold_tip: true as const } : {}) }, segments };
|
|
3494
3498
|
}
|
|
3495
3499
|
const constrained = clothConstraints.length === 0 ? {} : { constraints: clothConstraints };
|
|
3500
|
+
const motionSeams = draftMotionSeams({ bones, meshes, regions, ...drafted }, P.recs);
|
|
3501
|
+
const observed = motionSeams.length === 0 ? {} : { motion_seams: motionSeams };
|
|
3496
3502
|
return {
|
|
3497
|
-
proposal: draftPassingChainSigns(P, { bones, meshes, regions, ...drafted, motion: blink === undefined ? { duration: IDLE_SECONDS, tracks: idleTracks } : { duration: IDLE_SECONDS, tracks: idleTracks, blink }, ...constrained, proposed_rig_scale: P.rigScale, notes }),
|
|
3503
|
+
proposal: draftPassingChainSigns(P, { bones, meshes, regions, ...drafted, ...observed, motion: blink === undefined ? { duration: IDLE_SECONDS, tracks: idleTracks } : { duration: IDLE_SECONDS, tracks: idleTracks, blink }, ...constrained, proposed_rig_scale: P.rigScale, notes }),
|
|
3498
3504
|
basis: { frame, bones: records },
|
|
3499
3505
|
draftLint: [...jointsOffArt, ...radii],
|
|
3500
3506
|
};
|