@rig-c/parts 2.49.1 → 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/README.md +1 -0
- package/cli.ts +245 -11
- package/docs/AUTHORING.md +274 -66
- package/docs/STABILITY.md +116 -18
- package/package.json +3 -2
- package/src/behindseams.ts +164 -11
- package/src/build.ts +2 -0
- package/src/bustlandmarks.ts +656 -0
- package/src/check.ts +306 -52
- package/src/checkrow.ts +1 -0
- package/src/cloth-targets.json +10 -0
- package/src/config.ts +50 -43
- package/src/configwrite.ts +132 -13
- 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/configwrite.ts
CHANGED
|
@@ -17,6 +17,10 @@ import { PartsError } from './errors.ts';
|
|
|
17
17
|
import { parseConfig, parseEarlyConfig, parseProposalSections } from './config.ts';
|
|
18
18
|
import type { ConfigEdit } from './meshdraft.ts';
|
|
19
19
|
|
|
20
|
+
/** Required point fields and optional shape fields of `meshes.<part>.contour.bust`, in the shorthand order `src/config.ts` validates (issues #475, #1428). */
|
|
21
|
+
const BUST_LANDMARK_FIELDS = ['apex_r', 'apex_l', 'cleavage'] as const;
|
|
22
|
+
export const BUST_SHAPE_FIELDS = ['alpha', 'clearance', 'bone_r', 'bone_l', 'spacing'] as const;
|
|
23
|
+
|
|
20
24
|
export type ConfigJson = null | boolean | number | string | ConfigJson[] | ConfigObject;
|
|
21
25
|
export interface ConfigObject { [key: string]: ConfigJson }
|
|
22
26
|
export type ConfigWritePatch =
|
|
@@ -24,9 +28,45 @@ export type ConfigWritePatch =
|
|
|
24
28
|
| { kind: 'neck-unit'; config: CharacterConfig }
|
|
25
29
|
| { kind: 'head-box'; head_box: HeadBoxProposal['head_box'] }
|
|
26
30
|
| { kind: 'assemble-plan'; plan: PlanProposal['plan']; extend_below_crop: PlanProposal['extend_below_crop'] }
|
|
27
|
-
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS }
|
|
31
|
+
| { kind: 'proposal'; proposal: Proposal; sections: typeof PROPOSAL_CONFIG_SECTIONS; bustShape?: PendingBustShape }
|
|
28
32
|
/** Issues #671/#679: add unattached, resolvable entries; append skip explanations to the proposal's notes for the caller to print. */
|
|
29
|
-
| { kind: 'proposal-missing'; proposal: Proposal; parts: ReadonlyArray<{ name: string; from: string }> }
|
|
33
|
+
| { kind: 'proposal-missing'; proposal: Proposal; parts: ReadonlyArray<{ name: string; from: string }> }
|
|
34
|
+
/** `bust-landmarks --write-config` (issue #1382): set or remove named shape fields of one part's existing
|
|
35
|
+
* `meshes.<part>.contour.bust`; a field with no value is removed, every other key is kept where it is. */
|
|
36
|
+
| { kind: 'bust-shape'; part: string; fields: ReadonlyArray<{ key: BustShapeKey; value?: number | string }> }
|
|
37
|
+
/** The chest-only write on a sampled body-turn neck config (issue #1436): one carrier's `contour.bust` points (null
|
|
38
|
+
* removes the bust) and the `boob_r` / `boob_l` bones, every other entry kept where it is. The carrier's previous
|
|
39
|
+
* shape fields stay, and a pending reviewed shape takes their place, in the shorthand's key order. */
|
|
40
|
+
| { kind: 'bust'; part: string; bust: { apex_r: readonly number[]; apex_l: readonly number[]; cleavage: readonly number[] } | null; bones: ReadonlyArray<{ name: string; parent: string; at: readonly number[] }>; bustShape?: PendingBustShape };
|
|
41
|
+
/** The `contour.bust` fields the landmarks file does not carry, the only ones a `bust-shape` patch writes. */
|
|
42
|
+
export type BustShapeKey = (typeof BUST_SHAPE_FIELDS)[number];
|
|
43
|
+
/** A reviewed shape `bust-landmarks` left pending in its sidecar (issue #1382): `propose --write-config` writes it
|
|
44
|
+
* onto the drafted chest carrier's `contour.bust`, after the three points, in the shorthand's key order. */
|
|
45
|
+
/**
|
|
46
|
+
* The parts `--only-missing` (issue #671) leaves alone, each with what attaches it in the destination config: a
|
|
47
|
+
* `meshes` or `regions` entry, a limb's segment source, or an assemble patch. The `proposal-missing` write skips
|
|
48
|
+
* exactly these, and `propose` reads the same map (issue #1441's review) so a carrier it skips is not checked
|
|
49
|
+
* against the shape its config entry declares.
|
|
50
|
+
*/
|
|
51
|
+
export function onlyMissingAttachments(config: unknown): Map<string, string> {
|
|
52
|
+
const attachments = new Map<string, string>();
|
|
53
|
+
if (!object(config)) return attachments;
|
|
54
|
+
for (const section of ['meshes', 'regions'] as const) {
|
|
55
|
+
const entries = config[section];
|
|
56
|
+
if (object(entries)) for (const part of Object.keys(entries)) attachments.set(part, field(`config.${section}`, part));
|
|
57
|
+
}
|
|
58
|
+
if (object(config.limbs)) for (const [limb, spec] of Object.entries(config.limbs)) {
|
|
59
|
+
if (object(spec) && Array.isArray(spec.segments)) for (const segment of spec.segments) {
|
|
60
|
+
if (object(segment) && typeof segment.from === 'string') attachments.set(segment.from, `${field('config.limbs', limb)} (source cut into its segment parts)`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (object(config.assemble) && Array.isArray(config.assemble.patches)) for (const patch of config.assemble.patches) {
|
|
64
|
+
if (object(patch) && typeof patch.name === 'string') attachments.set(patch.name, 'config.assemble.patches (a patch is always a region)');
|
|
65
|
+
}
|
|
66
|
+
return attachments;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface PendingBustShape { part: string; fields: Partial<Record<BustShapeKey, number | string>> }
|
|
30
70
|
export interface ConfigWriteChange {
|
|
31
71
|
path: string;
|
|
32
72
|
kind: 'added' | 'replaced' | 'removed';
|
|
@@ -148,6 +188,38 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch, recei
|
|
|
148
188
|
if (patch.proposal[key] !== undefined) {
|
|
149
189
|
const previous = config[key];
|
|
150
190
|
config[key] = clone(patch.proposal[key], `proposal.${key}`);
|
|
191
|
+
if (key === 'meshes' && (object(previous) || patch.bustShape !== undefined) && object(config.meshes)) {
|
|
192
|
+
const carriers: string[] = [];
|
|
193
|
+
for (const [part, mesh] of Object.entries(config.meshes)) {
|
|
194
|
+
if (!object(mesh) || !object(mesh.contour) || !object(mesh.contour.bust)) continue;
|
|
195
|
+
carriers.push(part);
|
|
196
|
+
const draftedBust = mesh.contour.bust;
|
|
197
|
+
const prevMesh = object(previous) && own(previous, part) ? previous[part] : undefined;
|
|
198
|
+
const prevBust = object(prevMesh) && object(prevMesh.contour) && object(prevMesh.contour.bust) ? prevMesh.contour.bust : null;
|
|
199
|
+
const mergedBust: ConfigObject = {};
|
|
200
|
+
for (const k of BUST_LANDMARK_FIELDS) if (own(draftedBust, k)) mergedBust[k] = draftedBust[k];
|
|
201
|
+
// A pending reviewed shape (issue #1382) is the act's value for its fields; the rest keep what the config declares.
|
|
202
|
+
const pending = patch.bustShape?.part === part ? patch.bustShape.fields : undefined;
|
|
203
|
+
for (const k of BUST_SHAPE_FIELDS) {
|
|
204
|
+
const value = pending?.[k];
|
|
205
|
+
if (value !== undefined) mergedBust[k] = value;
|
|
206
|
+
else if (prevBust !== null && own(prevBust, k)) mergedBust[k] = prevBust[k];
|
|
207
|
+
}
|
|
208
|
+
mesh.contour.bust = mergedBust;
|
|
209
|
+
}
|
|
210
|
+
for (const [oldPart, prevMesh] of Object.entries(object(previous) ? previous : {})) {
|
|
211
|
+
if (carriers.includes(oldPart) || !object(prevMesh) || !object(prevMesh.contour) || !object(prevMesh.contour.bust)) continue;
|
|
212
|
+
const prevBust = prevMesh.contour.bust;
|
|
213
|
+
const dropped = BUST_SHAPE_FIELDS.filter((k) => own(prevBust, k));
|
|
214
|
+
if (dropped.length === 0) continue;
|
|
215
|
+
if (Array.isArray(patch.proposal.notes) && patch.proposal.notes.some((n) => n.startsWith(`${oldPart}: contour bust omitted for the declared reason: `))) continue;
|
|
216
|
+
const why = carriers.length > 0 ? `chest carrier is now ${carriers.join(', ')}` : `${oldPart} is no longer the chest carrier`;
|
|
217
|
+
const line = `${oldPart}: contour.bust shape field(s) ${dropped.join(', ')} dropped — ${why}`;
|
|
218
|
+
if (Array.isArray(patch.proposal.notes) && !Object.isFrozen(patch.proposal.notes) && !patch.proposal.notes.includes(line)) {
|
|
219
|
+
patch.proposal.notes.push(line);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
151
223
|
if (!equal(previous, config[key])) edits.push({ path: [key], value: config[key] });
|
|
152
224
|
}
|
|
153
225
|
}
|
|
@@ -156,19 +228,10 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch, recei
|
|
|
156
228
|
case 'proposal-missing': {
|
|
157
229
|
// Read attachment ownership from the destination, even without --keypoints. A limb's source is consumed;
|
|
158
230
|
// the loader requires regions for its segment parts instead. Patches are always regions.
|
|
159
|
-
const attachments = new Map<string, string>();
|
|
160
231
|
for (const section of ['meshes', 'regions'] as const) {
|
|
161
232
|
if (config[section] !== undefined && !object(config[section])) return refuse(`config.${section}`, 'is not an object; an object of part entries is required before an entry is added to it');
|
|
162
|
-
if (object(config[section])) for (const part of Object.keys(config[section])) attachments.set(part, field(`config.${section}`, part));
|
|
163
|
-
}
|
|
164
|
-
if (object(config.limbs)) for (const [limb, spec] of Object.entries(config.limbs)) {
|
|
165
|
-
if (object(spec) && Array.isArray(spec.segments)) for (const segment of spec.segments) {
|
|
166
|
-
if (object(segment) && typeof segment.from === 'string') attachments.set(segment.from, `${field('config.limbs', limb)} (source cut into its segment parts)`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (object(config.assemble) && Array.isArray(config.assemble.patches)) for (const patch of config.assemble.patches) {
|
|
170
|
-
if (object(patch) && typeof patch.name === 'string') attachments.set(patch.name, 'config.assemble.patches (a patch is always a region)');
|
|
171
233
|
}
|
|
234
|
+
const attachments = onlyMissingAttachments(config);
|
|
172
235
|
// This mode appends diagnostics to the proposal's existing notes output, never to the destination config.
|
|
173
236
|
const note = (part: string, why: string): void => {
|
|
174
237
|
const line = `--only-missing: skipped part "${part}" — ${why}; no entry or plan row added`;
|
|
@@ -231,7 +294,63 @@ export function mergeConfigProposal(raw: unknown, patch: ConfigWritePatch, recei
|
|
|
231
294
|
}
|
|
232
295
|
return { config, changes: added, edits };
|
|
233
296
|
}
|
|
234
|
-
|
|
297
|
+
case 'bust-shape': {
|
|
298
|
+
const at = `${field('config.meshes', patch.part)}.contour.bust`;
|
|
299
|
+
const meshes = config.meshes;
|
|
300
|
+
const mesh = object(meshes) && own(meshes, patch.part) ? meshes[patch.part] : undefined;
|
|
301
|
+
const contour = object(mesh) ? mesh.contour : undefined;
|
|
302
|
+
const bust = object(contour) ? contour.bust : undefined;
|
|
303
|
+
if (!object(contour) || !object(bust)) return refuse(at, 'is absent or not an object; an existing contour.bust is required before its shape fields are written');
|
|
304
|
+
const next = clone(bust, at) as ConfigObject;
|
|
305
|
+
for (const { key, value } of patch.fields) {
|
|
306
|
+
if (value === undefined) delete next[key];
|
|
307
|
+
else next[key] = value;
|
|
308
|
+
}
|
|
309
|
+
contour.bust = next;
|
|
310
|
+
// This patch owns the one bust object, never the mesh or its other contour fields.
|
|
311
|
+
if (!equal(bust as ConfigObject, next)) edits.push({ path: ['meshes', patch.part, 'contour', 'bust'], value: next });
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case 'bust': {
|
|
315
|
+
const at = `${field('config.meshes', patch.part)}.contour`;
|
|
316
|
+
const meshes = config.meshes;
|
|
317
|
+
const mesh = object(meshes) && own(meshes, patch.part) ? meshes[patch.part] : undefined;
|
|
318
|
+
const contour = object(mesh) ? mesh.contour : undefined;
|
|
319
|
+
if (!object(contour)) return refuse(at, 'is absent or not an object; the chest carrier must already be a contour mesh before its contour.bust is written');
|
|
320
|
+
if (!Array.isArray(config.bones)) return refuse('config.bones', 'is not an array; the bones list is required before the bust bones are written');
|
|
321
|
+
const prevBust = object(contour.bust) ? contour.bust : null;
|
|
322
|
+
if (patch.bust === null) delete contour.bust;
|
|
323
|
+
else {
|
|
324
|
+
const merged: ConfigObject = {};
|
|
325
|
+
for (const k of BUST_LANDMARK_FIELDS) merged[k] = clone(patch.bust[k], `bust.${k}`);
|
|
326
|
+
const pending = patch.bustShape?.part === patch.part ? patch.bustShape.fields : undefined;
|
|
327
|
+
for (const k of BUST_SHAPE_FIELDS) {
|
|
328
|
+
const value = pending?.[k];
|
|
329
|
+
if (value !== undefined) merged[k] = value;
|
|
330
|
+
else if (prevBust !== null && own(prevBust, k)) merged[k] = prevBust[k];
|
|
331
|
+
}
|
|
332
|
+
contour.bust = merged;
|
|
333
|
+
}
|
|
334
|
+
// The bust bones: replaced where they stand, appended where new (the proposer's order), removed with the bust.
|
|
335
|
+
const bones = config.bones;
|
|
336
|
+
const index = (name: string): number => bones.findIndex((b) => object(b) && b.name === name);
|
|
337
|
+
for (const name of ['boob_r', 'boob_l']) {
|
|
338
|
+
if (patch.bones.some((b) => b.name === name)) continue;
|
|
339
|
+
const i = index(name);
|
|
340
|
+
if (i >= 0) bones.splice(i, 1);
|
|
341
|
+
}
|
|
342
|
+
for (const bone of patch.bones) {
|
|
343
|
+
const value = clone(bone, `bust.bones.${bone.name}`);
|
|
344
|
+
const i = index(bone.name);
|
|
345
|
+
if (i >= 0) bones[i] = value;
|
|
346
|
+
else bones.push(value);
|
|
347
|
+
}
|
|
348
|
+
// This patch owns the bones list's two entries and the carrier's contour.bust, never another section.
|
|
349
|
+
if (!equal(before.bones, config.bones)) edits.push({ path: ['bones'], value: config.bones });
|
|
350
|
+
if (!equal(((before.meshes as ConfigObject)[patch.part] as ConfigObject).contour, contour)) edits.push({ path: ['meshes', patch.part, 'contour'], value: contour });
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
default: return refuse('write-config', 'has no supported operation; edited-part-receipt, neck-unit, head-box, assemble-plan, proposal, proposal-missing, bust-shape or bust is required');
|
|
235
354
|
}
|
|
236
355
|
return { config, changes: changes(before, config), edits };
|
|
237
356
|
}
|
package/src/instruments.ts
CHANGED
|
@@ -1141,7 +1141,7 @@ export function crossingOf(art: ArtMask, stage: StageBox, frames: ReadonlyArray<
|
|
|
1141
1141
|
// Distance from a world point to the nearest pixel outside the region: rings of pixels around the one holding it.
|
|
1142
1142
|
const depthAt = (x: number, y: number): number => {
|
|
1143
1143
|
const u0 = Math.floor(x - stage.x);
|
|
1144
|
-
const v0 = Math.floor(
|
|
1144
|
+
const v0 = Math.floor(cropToSpineY(y - stage.y, H));
|
|
1145
1145
|
let best = Infinity;
|
|
1146
1146
|
for (let r = 0; r - 1 < best; r++) {
|
|
1147
1147
|
for (let v = v0 - r; v <= v0 + r; v++) {
|
|
@@ -1188,7 +1188,7 @@ export function crossingOf(art: ArtMask, stage: StageBox, frames: ReadonlyArray<
|
|
|
1188
1188
|
by1 = Math.max(by1, poly[q + 1]);
|
|
1189
1189
|
}
|
|
1190
1190
|
for (let u = Math.floor(bx0 - stage.x); u <= Math.floor(bx1 - stage.x); u++) {
|
|
1191
|
-
for (let v = Math.floor(
|
|
1191
|
+
for (let v = Math.floor(cropToSpineY(by1 - stage.y, H)); v <= Math.floor(cropToSpineY(by0 - stage.y, H)); v++) {
|
|
1192
1192
|
if (!inR(u, v)) continue;
|
|
1193
1193
|
const sx0 = stage.x + u;
|
|
1194
1194
|
const sy1 = stage.y + cropToSpineY(v, H);
|
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}`)]
|