@rig-c/parts 2.50.0 → 2.51.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/cli.ts +122 -11
- package/docs/AUTHORING.md +112 -55
- package/docs/STABILITY.md +60 -16
- package/package.json +3 -2
- package/src/build.ts +2 -0
- package/src/bustlandmarks.ts +64 -8
- package/src/check.ts +55 -26
- package/src/checkrow.ts +1 -0
- package/src/cloth-targets.json +10 -0
- package/src/config.ts +50 -43
- package/src/configwrite.ts +70 -12
- package/src/instruments.ts +2 -2
- package/src/outputpaths.ts +24 -0
- package/src/physicscontrib.ts +311 -0
- package/src/propose.ts +30 -22
package/src/outputpaths.ts
CHANGED
|
@@ -23,6 +23,30 @@ export function diagnosticSegment(name: string, suffix = ''): string {
|
|
|
23
23
|
return segment;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Why `dir`, a folder name another tool recorded, is not one safe path segment
|
|
28
|
+
* Parts can join under its own output as it is, or `null` when it is (issue
|
|
29
|
+
* #1367). Safe is the alphabet `diagnosticSegment` emits — `[A-Za-z0-9_@+.-]`
|
|
30
|
+
* and its escape character `~` — with no final `.` (so neither `.` nor `..`),
|
|
31
|
+
* no Windows device basename before the first dot, and 1 to 255 characters.
|
|
32
|
+
* rig-c's render records every frame-set folder in that alphabet from
|
|
33
|
+
* rig-c/core#1744 on; nothing here maps or repairs the value.
|
|
34
|
+
*/
|
|
35
|
+
export function unsafeSegmentReason(dir: unknown): string | null {
|
|
36
|
+
if (typeof dir !== 'string') return dir === undefined ? 'is absent' : `is ${dir === null ? 'null' : typeof dir}, not a string`;
|
|
37
|
+
if (dir.length === 0) return 'is empty';
|
|
38
|
+
if (/^[\\/]/.test(dir)) return 'is an absolute path';
|
|
39
|
+
if (dir === '.' || dir === '..' || /(?:^|[\\/])\.\.?(?:[\\/]|$)/.test(dir)) return 'holds a dot segment';
|
|
40
|
+
if (/[\\/]/.test(dir)) return 'holds a path separator';
|
|
41
|
+
let unit = 0;
|
|
42
|
+
while (unit < dir.length && /^[A-Za-z0-9_@+.~-]$/.test(dir[unit])) unit++;
|
|
43
|
+
if (unit < dir.length) return `holds ${JSON.stringify(dir[unit])} (U+${dir.charCodeAt(unit).toString(16).padStart(4, '0')}) outside [A-Za-z0-9_@+.~-]`;
|
|
44
|
+
if (dir.endsWith('.')) return 'ends with "."';
|
|
45
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(dir)) return 'is a Windows device name before its first dot';
|
|
46
|
+
if (dir.length > 255) return `is ${dir.length} characters`;
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
26
50
|
/** Validate the entire sibling scope before a caller creates any of its paths. */
|
|
27
51
|
export function diagnosticSiblings(names: readonly { name: string; suffix?: string }[], scope: string): string[] {
|
|
28
52
|
const seen = new Map<string, { name: string; folder: string }>();
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PHYSICS_CONTRIBUTES` (issue #1320): whether physics moves a part at all, read on the idle — **a report, never a
|
|
3
|
+
* bar**. The compiled build is posed twice over the idle's frames, once with physics stepping and once with the
|
|
4
|
+
* poser's physics off (spine-core's `Physics.none`, rig-c's `physicsMode: 'off'`); the same compile, the same frames,
|
|
5
|
+
* the same declarations. It is not the spec with its physics constraints stripped and built again, which is what
|
|
6
|
+
* `loop` and the physics-off side of `ANIMATIONS_DO_NOT_FOLD` read.
|
|
7
|
+
*
|
|
8
|
+
* Why it exists: `TIP_OVER_ROOT` certifies that a part's lower band travels further than its upper band against the
|
|
9
|
+
* bone it hangs from, which ordinary carrier motion does with physics off (issue #1318), so a PASS there says nothing
|
|
10
|
+
* about physics. This line measures the contribution itself: for every part under a physics constraint, each vertex
|
|
11
|
+
* of a triangle that holds the part's art, its travel from frame 0 with physics on less its travel from frame 0 with
|
|
12
|
+
* physics off, at the same frame:
|
|
13
|
+
*
|
|
14
|
+
* r_f(v) = (on_f(v) − on_0(v)) − (off_f(v) − off_0(v)), |r| = sqrt(dx² + dy²), rig px
|
|
15
|
+
*
|
|
16
|
+
* read as the largest |r| over those vertices on each frame 1..N−1, and over frames as its max, p95 (nearest rank)
|
|
17
|
+
* and mean. Measured for issue #1320 on the public examples (15 builds): a part no physics constraint reaches reads
|
|
18
|
+
* exactly 0, and so does a physics part whose constraints take up nothing (`inertia` 0 with no wind or gravity),
|
|
19
|
+
* while every part physics moves reads above 0 (the smallest shipped one 0.0244 rig px). The line therefore draws
|
|
20
|
+
* one edge, the definition's own: a part under physics that reads exactly 0 is a `WARN` — physics does nothing to it.
|
|
21
|
+
* There is no visibility bar; how much is enough is the author's to say. The verdict does not move: the line adds no
|
|
22
|
+
* problem, and `check: PASS` stays PASS.
|
|
23
|
+
*
|
|
24
|
+
* "Under physics" is read off rig.json and motion.json: a part bound to a bone a physics constraint drives, to a
|
|
25
|
+
* descendant of one, or to a bone a transform constraint drives from such a bone (and its descendants).
|
|
26
|
+
*/
|
|
27
|
+
import { type CheckRowLabels, checkRow } from './checkrow.ts';
|
|
28
|
+
import { cropToSpineY } from './coords.ts';
|
|
29
|
+
import { edgeLength } from './length.ts';
|
|
30
|
+
import type { PlacedArt } from './requirements.ts';
|
|
31
|
+
import type { StageBox } from './check.ts';
|
|
32
|
+
import { readFileSync } from 'node:fs';
|
|
33
|
+
import { join } from 'node:path';
|
|
34
|
+
|
|
35
|
+
export const PHYSICS_CONTRIBUTES_LINE = 'PHYSICS_CONTRIBUTES';
|
|
36
|
+
|
|
37
|
+
/** What the line poses "off" as, written into the line. */
|
|
38
|
+
export const PHYSICS_OFF_TEXT = "the same compiled build posed with the poser's physics off (spine-core Physics.none, rig-c physicsMode 'off') over the same frames — not the rig spec with its physics constraints stripped and built again";
|
|
39
|
+
|
|
40
|
+
/** Which points the residual reads, written into the line. */
|
|
41
|
+
export const PHYSICS_POINTS_TEXT = 'every vertex of a rest triangle that holds a pixel centre of the part\'s art (alpha above the mesh threshold); per frame the largest residual over them, frames 1..N-1';
|
|
42
|
+
|
|
43
|
+
/** The fields that make physics move a part, as the warning names them; no value is prescribed. */
|
|
44
|
+
export const PHYSICS_LEVERS_TEXT = "physics moves a part through its constraints' inertia (how much of its carrier's motion it takes up), wind and gravity (a force from the world) and mix, and only while something moves its carrier or the world pushes it";
|
|
45
|
+
|
|
46
|
+
/** A physics constraint as the line reads it off rig.json and motion.json. */
|
|
47
|
+
export interface PhysicsDecl {
|
|
48
|
+
name: string;
|
|
49
|
+
bone: string;
|
|
50
|
+
/** True when the constraint declares a nonzero `wind` or `gravity`: it answers a force from the world. */
|
|
51
|
+
force: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** One part's row: its figures, or why it was not measured. */
|
|
55
|
+
export type PhysicsContributionRow = CheckRowLabels & {
|
|
56
|
+
part: string;
|
|
57
|
+
/** The physics constraints the part is under, in declaration order. */
|
|
58
|
+
constraints: string[];
|
|
59
|
+
/** Of those, the ones that declare wind or gravity: external force is present on them. */
|
|
60
|
+
external_force: string[];
|
|
61
|
+
} & (
|
|
62
|
+
| {
|
|
63
|
+
vertices: number;
|
|
64
|
+
frames_read: number;
|
|
65
|
+
max_rig_px: number;
|
|
66
|
+
p95_rig_px: number;
|
|
67
|
+
mean_rig_px: number;
|
|
68
|
+
/** `max_rig_px` over the part's box diagonal, four significant figures. */
|
|
69
|
+
max_of_diagonal: number;
|
|
70
|
+
/** Whether the unrounded max is above 0; false is the warning. */
|
|
71
|
+
moves: boolean;
|
|
72
|
+
}
|
|
73
|
+
| { unmeasured: string }
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export interface PhysicsContributionLine {
|
|
77
|
+
status: 'WARN' | 'CLEAR' | 'SKIP';
|
|
78
|
+
reason?: string;
|
|
79
|
+
off: string;
|
|
80
|
+
points: string;
|
|
81
|
+
world: string;
|
|
82
|
+
poser: string;
|
|
83
|
+
fps: number;
|
|
84
|
+
frames: number;
|
|
85
|
+
warnings: number;
|
|
86
|
+
rows: PhysicsContributionRow[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isRecord(v: unknown): v is Record<string, unknown> {
|
|
90
|
+
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function hasForce(c: Record<string, unknown>): boolean {
|
|
94
|
+
return (typeof c.wind === 'number' && c.wind !== 0) || (typeof c.gravity === 'number' && c.gravity !== 0);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The physics constraints of rig.json's `constraints` and motion.json's `physics` table, in that order. */
|
|
98
|
+
export function physicsDecls(rig: Record<string, unknown>, motion: Record<string, unknown>): PhysicsDecl[] {
|
|
99
|
+
const out: PhysicsDecl[] = [];
|
|
100
|
+
for (const c of Array.isArray(rig.constraints) ? rig.constraints : []) {
|
|
101
|
+
if (isRecord(c) && c.type === 'physics' && typeof c.name === 'string' && typeof c.bone === 'string') out.push({ name: c.name, bone: c.bone, force: hasForce(c) });
|
|
102
|
+
}
|
|
103
|
+
if (isRecord(motion.physics)) {
|
|
104
|
+
for (const [name, e] of Object.entries(motion.physics)) if (isRecord(e) && typeof e.bone === 'string') out.push({ name, bone: e.bone, force: hasForce(e) });
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Every bone a physics constraint reaches, with the constraints that reach it: the constraint's own bone, every
|
|
111
|
+
* descendant, and every bone a transform constraint drives from a reached source bone (and its descendants), read
|
|
112
|
+
* to a fixpoint.
|
|
113
|
+
*/
|
|
114
|
+
export function physicsReach(rig: Record<string, unknown>, decls: readonly PhysicsDecl[]): Map<string, Set<string>> {
|
|
115
|
+
const bones = (Array.isArray(rig.bones) ? rig.bones : []).filter(isRecord).filter((b) => typeof b.name === 'string');
|
|
116
|
+
const reach = new Map<string, Set<string>>();
|
|
117
|
+
const add = (bone: string, names: Iterable<string>): boolean => {
|
|
118
|
+
const set = reach.get(bone) ?? new Set<string>();
|
|
119
|
+
const before = set.size;
|
|
120
|
+
for (const n of names) set.add(n);
|
|
121
|
+
reach.set(bone, set);
|
|
122
|
+
return set.size !== before;
|
|
123
|
+
};
|
|
124
|
+
for (const d of decls) add(d.bone, [d.name]);
|
|
125
|
+
const transforms = (Array.isArray(rig.constraints) ? rig.constraints : []).filter(isRecord).filter((c) => c.type === 'transform' && typeof c.source === 'string');
|
|
126
|
+
for (let changed = true; changed;) {
|
|
127
|
+
changed = false;
|
|
128
|
+
for (const b of bones) {
|
|
129
|
+
const p = typeof b.parent === 'string' ? reach.get(b.parent) : undefined;
|
|
130
|
+
if (p !== undefined && add(String(b.name), p)) changed = true;
|
|
131
|
+
}
|
|
132
|
+
for (const t of transforms) {
|
|
133
|
+
const s = reach.get(String(t.source));
|
|
134
|
+
if (s === undefined) continue;
|
|
135
|
+
for (const target of Array.isArray(t.bones) ? t.bones : []) if (typeof target === 'string' && add(target, s)) changed = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return reach;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The constraints a part is under, by the bones it is bound to, in declaration order; empty when none. */
|
|
142
|
+
export function partConstraints(bound: ReadonlySet<string>, reach: ReadonlyMap<string, ReadonlySet<string>>, decls: readonly PhysicsDecl[]): PhysicsDecl[] {
|
|
143
|
+
const names = new Set<string>();
|
|
144
|
+
for (const b of bound) for (const n of reach.get(b) ?? []) names.add(n);
|
|
145
|
+
return decls.filter((d) => names.has(d.name));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The vertices of the rest triangles that hold at least one pixel centre of the art, ascending. `rest` is the
|
|
149
|
+
* attachment's rest vertices in the world (y up), `art` the part's art on the stage (crop px, y down).
|
|
150
|
+
*/
|
|
151
|
+
export function artVertices(rest: readonly number[], triangles: readonly number[], art: PlacedArt, stage: StageBox): number[] {
|
|
152
|
+
const H = stage.height;
|
|
153
|
+
const held = new Set<number>();
|
|
154
|
+
for (let t = 0; t + 2 < triangles.length; t += 3) {
|
|
155
|
+
const i = triangles[t], j = triangles[t + 1], k = triangles[t + 2];
|
|
156
|
+
const x0 = rest[2 * i], y0 = rest[2 * i + 1];
|
|
157
|
+
const ex1 = rest[2 * j] - x0, ey1 = rest[2 * j + 1] - y0, ex2 = rest[2 * k] - x0, ey2 = rest[2 * k + 1] - y0;
|
|
158
|
+
const det = ex1 * ey2 - ex2 * ey1;
|
|
159
|
+
if (det === 0) continue;
|
|
160
|
+
const xs = [x0, rest[2 * j], rest[2 * k]], ys = [y0, rest[2 * j + 1], rest[2 * k + 1]];
|
|
161
|
+
// Crop column X has its centre at world x stage.x + X + 0.5; crop row Y at world y stage.y + cropToSpineY(Y + 0.5, H).
|
|
162
|
+
const X0 = Math.max(art.x, Math.floor(Math.min(...xs) - stage.x - 0.5));
|
|
163
|
+
const X1 = Math.min(art.x + art.width - 1, Math.ceil(Math.max(...xs) - stage.x - 0.5));
|
|
164
|
+
const Y0 = Math.max(art.y, Math.floor(cropToSpineY(Math.max(...ys) - stage.y, H) - 0.5));
|
|
165
|
+
const Y1 = Math.min(art.y + art.height - 1, Math.ceil(cropToSpineY(Math.min(...ys) - stage.y, H) - 0.5));
|
|
166
|
+
let found = false;
|
|
167
|
+
for (let Y = Y0; Y <= Y1 && !found; Y++) {
|
|
168
|
+
for (let X = X0; X <= X1; X++) {
|
|
169
|
+
if (art.data[(Y - art.y) * art.width + (X - art.x)] !== 1) continue;
|
|
170
|
+
const dx = stage.x + X + 0.5 - x0, dy = stage.y + cropToSpineY(Y + 0.5, H) - y0;
|
|
171
|
+
const l1 = (dx * ey2 - ex2 * dy) / det, l2 = (ex1 * dy - dx * ey1) / det;
|
|
172
|
+
if (l1 >= 0 && l2 >= 0 && l1 + l2 <= 1) {
|
|
173
|
+
found = true;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (found) held.add(i).add(j).add(k);
|
|
179
|
+
}
|
|
180
|
+
return [...held].sort((a, b) => a - b);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** The residual's figures over frames 1..N−1 from the two series of posed vertices (null where the slot shows another attachment or nothing). */
|
|
184
|
+
export function residualFigures(on: ReadonlyArray<readonly number[] | null>, off: ReadonlyArray<readonly number[] | null>, vertices: readonly number[]): { frames_read: number; max: number; p95: number; mean: number } | null {
|
|
185
|
+
const a0 = on[0], b0 = off[0];
|
|
186
|
+
if (a0 === null || b0 === null || a0 === undefined || b0 === undefined) return null;
|
|
187
|
+
const per: number[] = [];
|
|
188
|
+
for (let f = 1; f < Math.min(on.length, off.length); f++) {
|
|
189
|
+
const a = on[f], b = off[f];
|
|
190
|
+
if (a === null || b === null) continue;
|
|
191
|
+
let m = 0;
|
|
192
|
+
for (const v of vertices) {
|
|
193
|
+
const dx = (a[2 * v] - a0[2 * v]) - (b[2 * v] - b0[2 * v]);
|
|
194
|
+
const dy = (a[2 * v + 1] - a0[2 * v + 1]) - (b[2 * v + 1] - b0[2 * v + 1]);
|
|
195
|
+
m = Math.max(m, edgeLength(dx, dy));
|
|
196
|
+
}
|
|
197
|
+
per.push(m);
|
|
198
|
+
}
|
|
199
|
+
if (per.length === 0) return { frames_read: 0, max: 0, p95: 0, mean: 0 };
|
|
200
|
+
const sorted = [...per].sort((x, y) => x - y);
|
|
201
|
+
return { frames_read: per.length, max: sorted[sorted.length - 1], p95: sorted[Math.ceil(0.95 * sorted.length) - 1], mean: per.reduce((s, x) => s + x, 0) / per.length };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Python's `round(x, 3)`, the line's precision for rig px. */
|
|
205
|
+
function round3(x: number): number {
|
|
206
|
+
return Number(x.toFixed(3));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Four significant figures, keeping a small fraction's size. */
|
|
210
|
+
function sig4(x: number): number {
|
|
211
|
+
return x === 0 ? 0 : Number(x.toPrecision(4));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** One measured row. `figures` null is a part whose slot shows nothing on frame 0. */
|
|
215
|
+
export function physicsRow(part: string, decls: readonly PhysicsDecl[], diagonal: number, vertices: number, figures: { frames_read: number; max: number; p95: number; mean: number } | null, unmeasured?: string): PhysicsContributionRow {
|
|
216
|
+
const head = { part, constraints: decls.map((d) => d.name), external_force: decls.filter((d) => d.force).map((d) => d.name) };
|
|
217
|
+
if (figures === null || unmeasured !== undefined) return { ...checkRow('PHYSICS_CONTRIBUTES.rows', 'part', false, [part]), ...head, unmeasured: unmeasured ?? 'its slot shows no attachment on idle frame 0' };
|
|
218
|
+
const moves = figures.max > 0;
|
|
219
|
+
return {
|
|
220
|
+
...checkRow('PHYSICS_CONTRIBUTES.rows', 'part', !moves, [part]),
|
|
221
|
+
...head,
|
|
222
|
+
vertices,
|
|
223
|
+
frames_read: figures.frames_read,
|
|
224
|
+
max_rig_px: round3(figures.max),
|
|
225
|
+
p95_rig_px: round3(figures.p95),
|
|
226
|
+
mean_rig_px: round3(figures.mean),
|
|
227
|
+
max_of_diagonal: sig4(diagonal > 0 ? figures.max / diagonal : 0),
|
|
228
|
+
moves,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** The line from its rows: WARN when a part under physics reads exactly 0, CLEAR when none does, SKIP with the reason. */
|
|
233
|
+
export function physicsLine(rows: PhysicsContributionRow[], fps: number, frames: number, poser: string, world: string, reason?: string): PhysicsContributionLine {
|
|
234
|
+
const warnings = rows.filter((r) => 'moves' in r && !r.moves).length;
|
|
235
|
+
return {
|
|
236
|
+
status: reason !== undefined ? 'SKIP' : warnings > 0 ? 'WARN' : 'CLEAR',
|
|
237
|
+
...(reason === undefined ? {} : { reason }),
|
|
238
|
+
off: PHYSICS_OFF_TEXT,
|
|
239
|
+
points: PHYSICS_POINTS_TEXT,
|
|
240
|
+
world,
|
|
241
|
+
poser,
|
|
242
|
+
fps,
|
|
243
|
+
frames,
|
|
244
|
+
warnings,
|
|
245
|
+
rows,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** One warning as the console prints it. */
|
|
250
|
+
export function physicsWarnText(r: PhysicsContributionRow): string {
|
|
251
|
+
const frames = 'frames_read' in r ? r.frames_read : 0;
|
|
252
|
+
const vertices = 'vertices' in r ? r.vertices : 0;
|
|
253
|
+
const force = r.external_force.length === 0 ? '' : `; external force is declared on ${r.external_force.map((n) => `"${n}"`).join(', ')}`;
|
|
254
|
+
return `WARN ${PHYSICS_CONTRIBUTES_LINE}: part "${r.part}" is under physics constraint(s) ${r.constraints.map((n) => `"${n}"`).join(', ')} and reads 0 over ${frames} frame(s): none of its ${vertices} art vertices is moved by physics on the idle${force}; ${PHYSICS_LEVERS_TEXT}`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The line as the console prints it: the status and what was read, then one WARN line per part that reads 0. A SKIP prints its reason alone. */
|
|
258
|
+
export function physicsLines(line: PhysicsContributionLine): string[] {
|
|
259
|
+
if (line.status === 'SKIP') return [`${PHYSICS_CONTRIBUTES_LINE}: SKIP — ${String(line.reason)}`];
|
|
260
|
+
const forced = line.rows.filter((r) => r.external_force.length > 0).length;
|
|
261
|
+
const read = `${line.rows.length} part(s) under physics posed with physics on and off (${line.frames} frame(s) at ${line.fps} fps, ${line.poser} poser, ${line.world})${forced === 0 ? '' : `, ${forced} of them under a constraint that declares wind or gravity`}`;
|
|
262
|
+
return [
|
|
263
|
+
`${PHYSICS_CONTRIBUTES_LINE}: ${line.status} — ${read}: ${line.warnings} of them read 0 — ${line.warnings} warning(s), never a bar; off is ${line.off}`,
|
|
264
|
+
...line.rows.filter((r) => 'moves' in r && !r.moves).map(physicsWarnText),
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** What {@link measurePhysicsContribution} reads for one part: its box, its art on the stage, the bones it is bound to and its rest triangles. */
|
|
269
|
+
export interface PhysicsPartInput {
|
|
270
|
+
name: string;
|
|
271
|
+
w: number;
|
|
272
|
+
h: number;
|
|
273
|
+
art: () => PlacedArt;
|
|
274
|
+
bound: ReadonlySet<string>;
|
|
275
|
+
rest: { vertices: readonly number[]; triangles: readonly number[] } | undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type Renderer = typeof import('@rig-c/core/render-shared');
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The line on a packed build (`<build>/skeleton.json` and `.atlas`): the idle posed twice through rig-c's read facade,
|
|
282
|
+
* physics on and physics off, at `fps`, under rig-c's default environment; one row per part under physics. Null
|
|
283
|
+
* figures — a rig with no physics constraint — are the caller's SKIP.
|
|
284
|
+
*/
|
|
285
|
+
export function measurePhysicsContribution(api: Renderer, build: string, rig: Record<string, unknown>, motion: Record<string, unknown>, parts: readonly PhysicsPartInput[], stage: StageBox, fps: number): PhysicsContributionLine {
|
|
286
|
+
const world = "rig-c's default environment";
|
|
287
|
+
const decls = physicsDecls(rig, motion);
|
|
288
|
+
if (decls.length === 0) return physicsLine([], fps, 0, 'none', world, "the rig declares no physics constraint (rig.json's constraints, motion.json's physics), so no part is under physics");
|
|
289
|
+
const reach = physicsReach(rig, decls);
|
|
290
|
+
const under = parts.map((p) => ({ p, decls: partConstraints(p.bound, reach, decls) })).filter((x) => x.decls.length > 0);
|
|
291
|
+
if (under.length === 0) return physicsLine([], fps, 0, 'none', world, `no part is bound to a bone the rig's ${decls.length} physics constraint(s) reach`);
|
|
292
|
+
const skeleton = join(build, 'skeleton.json'), atlas = join(build, 'skeleton.atlas');
|
|
293
|
+
const candidate = api.loadCandidate({ skeletonText: readFileSync(skeleton, 'utf8'), atlasText: readFileSync(atlas, 'utf8'), atlasDir: build, label: PHYSICS_CONTRIBUTES_LINE }, { skeleton, atlas }, undefined);
|
|
294
|
+
const on = api.throughPoser(candidate.choice, (p) => api.sampleAnimation(p, 'idle', fps, { geometry: true }));
|
|
295
|
+
const off = api.throughPoser(candidate.choice, (p) => api.sampleAnimation(p, 'idle', fps, { geometry: true, physicsMode: 'off' }));
|
|
296
|
+
const series = (frames: typeof on.value, slot: string): Array<number[] | null> => {
|
|
297
|
+
const first = frames[0]?.attachments?.find((a) => a.slot === slot)?.attachment;
|
|
298
|
+
return frames.map((f) => {
|
|
299
|
+
const a = f.attachments?.find((x) => x.slot === slot);
|
|
300
|
+
return a === undefined || a.attachment !== first ? null : a.vertices;
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
const rows = under.map(({ p, decls: ds }) => {
|
|
304
|
+
if (p.rest === undefined) return physicsRow(p.name, ds, 0, 0, null, 'its slot shows no attachment in the idle geometry');
|
|
305
|
+
const vs = artVertices(p.rest.vertices, p.rest.triangles, p.art(), stage);
|
|
306
|
+
const a = series(on.value, p.name), b = series(off.value, p.name);
|
|
307
|
+
if (a[0] !== null && a[0].length !== p.rest.vertices.length) return physicsRow(p.name, ds, 0, 0, null, `its posed attachment has ${a[0].length / 2} vertices and its rest ${p.rest.vertices.length / 2}`);
|
|
308
|
+
return physicsRow(p.name, ds, edgeLength(p.w, p.h), vs.length, residualFigures(a, b, vs));
|
|
309
|
+
});
|
|
310
|
+
return physicsLine(rows, fps, on.value.length, on.poser, world);
|
|
311
|
+
}
|
package/src/propose.ts
CHANGED
|
@@ -1409,6 +1409,34 @@ const SIDES = [
|
|
|
1409
1409
|
export interface BustDraft {
|
|
1410
1410
|
landmarks?: { apex_r: Point; apex_l: Point; cleavage?: Point };
|
|
1411
1411
|
noBust?: string;
|
|
1412
|
+
/** Where a cleavage the caller derived came from (issue #1436), said in the torso's note in place of "declared". */
|
|
1413
|
+
cleavageFrom?: string;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* The cleavage a landmarks file without one gets: the crossing of the apex segment and the neck-to-hip midline,
|
|
1418
|
+
* on the 1/256-px contour grid. #475's clearance identity requires it on the apex segment, between the two apices;
|
|
1419
|
+
* a midline that crosses it nowhere inside is refused by name. The proposer calls it with its drafted neck and hip;
|
|
1420
|
+
* the chest-only write (issue #1436) with the config's own.
|
|
1421
|
+
*/
|
|
1422
|
+
export function bustCleavage(apex_r: Point, apex_l: Point, neckAt: Point, hip: Point): Point {
|
|
1423
|
+
const apexDeltaX = apex_l[0] - apex_r[0];
|
|
1424
|
+
const apexDeltaY = apex_l[1] - apex_r[1];
|
|
1425
|
+
const midlineDeltaX = hip[0] - neckAt[0];
|
|
1426
|
+
const midlineDeltaY = hip[1] - neckAt[1];
|
|
1427
|
+
const cross = apexDeltaX * midlineDeltaY - apexDeltaY * midlineDeltaX;
|
|
1428
|
+
const share = ((neckAt[0] - apex_r[0]) * midlineDeltaY - (neckAt[1] - apex_r[1]) * midlineDeltaX) / cross;
|
|
1429
|
+
if (!Number.isFinite(share) || share <= 0 || share >= 1) {
|
|
1430
|
+
throw new PartsError([{
|
|
1431
|
+
code: 'PROPOSE_BUST_INPUT', object: 'landmarks.cleavage',
|
|
1432
|
+
detail: `the neck-to-hip midline ${fmtAt(neckAt)} -> ${fmtAt(hip)} has no unique crossing inside apex_r ${fmtAt(apex_r)} -> apex_l ${fmtAt(apex_l)}. Declare cleavage explicitly or place the apices on opposite sides of the torso midline`,
|
|
1433
|
+
}]);
|
|
1434
|
+
}
|
|
1435
|
+
// Derived coordinates use the same fixed-point grid the contour config reader requires.
|
|
1436
|
+
return [
|
|
1437
|
+
pyRound((apex_r[0] + share * apexDeltaX) * GRID) / GRID,
|
|
1438
|
+
pyRound((apex_r[1] + share * apexDeltaY) * GRID) / GRID,
|
|
1439
|
+
];
|
|
1412
1440
|
}
|
|
1413
1441
|
|
|
1414
1442
|
/** Read only the declared landmark fields. Geometry is checked by checkProposal's config reader. */
|
|
@@ -3655,27 +3683,7 @@ export function proposeWithBasis(
|
|
|
3655
3683
|
detail: 'needs a declared bust: give --bust-landmarks <file> or --no-bust "<reason>"' }]);
|
|
3656
3684
|
} else {
|
|
3657
3685
|
const { apex_r, apex_l } = bust.landmarks;
|
|
3658
|
-
|
|
3659
|
-
if (cleavage === undefined) {
|
|
3660
|
-
// #475's clearance identity requires cleavage on the apex segment, between the two apices.
|
|
3661
|
-
const apexDeltaX = apex_l[0] - apex_r[0];
|
|
3662
|
-
const apexDeltaY = apex_l[1] - apex_r[1];
|
|
3663
|
-
const midlineDeltaX = hip[0] - neckAt[0];
|
|
3664
|
-
const midlineDeltaY = hip[1] - neckAt[1];
|
|
3665
|
-
const cross = apexDeltaX * midlineDeltaY - apexDeltaY * midlineDeltaX;
|
|
3666
|
-
const share = ((neckAt[0] - apex_r[0]) * midlineDeltaY - (neckAt[1] - apex_r[1]) * midlineDeltaX) / cross;
|
|
3667
|
-
if (!Number.isFinite(share) || share <= 0 || share >= 1) {
|
|
3668
|
-
throw new PartsError([{
|
|
3669
|
-
code: 'PROPOSE_BUST_INPUT', object: 'landmarks.cleavage',
|
|
3670
|
-
detail: `the neck-to-hip midline ${fmtAt(neckAt)} -> ${fmtAt(hip)} has no unique crossing inside apex_r ${fmtAt(apex_r)} -> apex_l ${fmtAt(apex_l)}. Declare cleavage explicitly or place the apices on opposite sides of the torso midline`,
|
|
3671
|
-
}]);
|
|
3672
|
-
}
|
|
3673
|
-
// Derived coordinates use the same fixed-point grid the contour config reader requires.
|
|
3674
|
-
cleavage = [
|
|
3675
|
-
pyRound((apex_r[0] + share * apexDeltaX) * GRID) / GRID,
|
|
3676
|
-
pyRound((apex_r[1] + share * apexDeltaY) * GRID) / GRID,
|
|
3677
|
-
];
|
|
3678
|
-
}
|
|
3686
|
+
const cleavage = bust.landmarks.cleavage ?? bustCleavage(apex_r, apex_l, neckAt, hip);
|
|
3679
3687
|
const landmarks: ContourBustSpec = { apex_r, apex_l, cleavage };
|
|
3680
3688
|
contour.bust = landmarks;
|
|
3681
3689
|
for (const side of ['r', 'l'] as const) {
|
|
@@ -3687,7 +3695,7 @@ export function proposeWithBasis(
|
|
|
3687
3695
|
parts: [source.name], bones: ['chest'],
|
|
3688
3696
|
}), tip: null });
|
|
3689
3697
|
}
|
|
3690
|
-
notes.push(`${torsoName}: contour.bust from declared apex_r/apex_l. Cleavage ${bust.landmarks.cleavage === undefined ? 'derived at the apex segment crossing of the neck-to-hip midline' : 'declared'}. Bones boob_r/boob_l are parented to chest`);
|
|
3698
|
+
notes.push(`${torsoName}: contour.bust from declared apex_r/apex_l. Cleavage ${bust.landmarks.cleavage === undefined ? 'derived at the apex segment crossing of the neck-to-hip midline' : bust.cleavageFrom ?? 'declared'}. Bones boob_r/boob_l are parented to chest`);
|
|
3691
3699
|
}
|
|
3692
3700
|
const chains = new Set(bones.flatMap(b => 'chain' in b
|
|
3693
3701
|
? [b.chain, ...b.points.map((_, index) => `${b.chain}${index}`)]
|