@rig-c/parts 1.50.0 → 1.52.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 +52 -7
- package/docs/AUTHORING.md +152 -24
- package/docs/PAINTING.md +27 -2
- package/docs/STABILITY.md +5 -4
- package/package.json +1 -1
- package/src/assemble.ts +185 -7
- package/src/build.ts +30 -8
- package/src/check.ts +130 -10
- package/src/clothconfig.ts +67 -13
- package/src/config.ts +25 -9
- package/src/meshstats.ts +57 -0
- package/src/parts.ts +37 -5
package/src/clothconfig.ts
CHANGED
|
@@ -39,6 +39,8 @@ function canon(v: unknown): string {
|
|
|
39
39
|
/** One edit `--write-config` makes, with the words the write line prints for it. */
|
|
40
40
|
export interface ClothEdit extends ConfigEdit {
|
|
41
41
|
label: string;
|
|
42
|
+
/** Issue #571: the input's entry was the previous recipe's draft (`--from`), and only that made it the recipe's. */
|
|
43
|
+
previous?: true;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
@@ -95,31 +97,44 @@ function shown(v: unknown): string {
|
|
|
95
97
|
* - removed (P present, D absent — the recipe replaced a plain chain with its trees): `I` equal to `P` is removed;
|
|
96
98
|
* - every other input entry is kept, bytes and order;
|
|
97
99
|
* - an owned or removed `I` that is none of those — changed by hand — is a conflict, as is a name the input states twice.
|
|
100
|
+
*
|
|
101
|
+
* With `V`, the previous recipe's draft (`previous`, issue #571 — `--from`; null without it): `I` equal to `V` is the
|
|
102
|
+
* recipe's as `I` equal to `P` is — an owned name is replaced, and a name in `V` and not in `D` is removed — and a
|
|
103
|
+
* conflict is an `I` equal to none of `D`, `P` and `V`, its first differing field read against `V` where `V` holds the
|
|
104
|
+
* name. Without `previous` every rule, and every word of the refusal, is the one above.
|
|
98
105
|
*/
|
|
99
|
-
function entryEdits(path: readonly string[], identity: (e: unknown) => string | null, drafted: readonly unknown[], plain: readonly unknown[], input: readonly unknown[], conflicts: Problem[]): ClothEdit[] {
|
|
106
|
+
function entryEdits(path: readonly string[], identity: (e: unknown) => string | null, drafted: readonly unknown[], plain: readonly unknown[], input: readonly unknown[], conflicts: Problem[], previous: readonly unknown[] | null): ClothEdit[] {
|
|
100
107
|
const section = path.join('.');
|
|
101
108
|
const D = byName(drafted, identity, 'drafted', section);
|
|
102
109
|
const P = byName(plain, identity, 'plain', section);
|
|
110
|
+
const V = previous === null ? null : byName(previous, identity, 'previous', section);
|
|
103
111
|
const keys = input.map(identity);
|
|
104
112
|
const where = new Map<string, number[]>();
|
|
105
113
|
keys.forEach((k, i) => {
|
|
106
114
|
if (k !== null) where.set(k, [...(where.get(k) ?? []), i]);
|
|
107
115
|
});
|
|
108
116
|
const owned = [...D.keys()].filter((k) => !P.has(k) || canon(P.get(k)) !== canon(D.get(k)));
|
|
109
|
-
const removed = [...P.keys()].filter((k) => !D.has(k));
|
|
117
|
+
const removed = [...P.keys(), ...(V === null ? [] : [...V.keys()].filter((k) => !P.has(k)))].filter((k) => !D.has(k));
|
|
110
118
|
const replace: string[] = [];
|
|
111
119
|
const remove: string[] = [];
|
|
120
|
+
const vouched = new Set<string>();
|
|
112
121
|
const conflict = (k: string, i: number, drafts: boolean): void => {
|
|
113
122
|
const author = input[i];
|
|
114
|
-
const
|
|
123
|
+
const prev = V !== null && V.has(k) ? V.get(k) : undefined;
|
|
124
|
+
const field = firstField(author, prev !== undefined ? prev : P.has(k) ? P.get(k) : D.get(k));
|
|
115
125
|
const fieldOf = (e: unknown, f: string): string => (isPlain(e) && e[f] !== undefined ? `${f} ${shown(e[f])}` : `no ${f}`);
|
|
116
126
|
const held = field === null ? `the entry ${shown(author)}` : fieldOf(author, field);
|
|
117
127
|
const draft = D.get(k);
|
|
118
128
|
const draftSays = !drafts ? 'the draft removes the entry (the recipe drafts that part afresh)' : field === null ? `the draft writes ${shown(draft)}` : `the draft writes ${fieldOf(draft, field)}`;
|
|
129
|
+
// Issue #571: with --from, the entry equals none of the three drafts; the field is read against the previous recipe's, the draft a person edited from.
|
|
130
|
+
const says =
|
|
131
|
+
V === null
|
|
132
|
+
? `it holds ${held} where ${draftSays}`
|
|
133
|
+
: `it equals neither the draft, the draft without the recipe, nor the previous recipe's draft: it holds ${held} where ${prev === undefined ? 'the previous recipe\'s draft has no such entry' : `the previous recipe's draft writes ${field === null ? shown(prev) : fieldOf(prev, field)}`} and ${draftSays}`;
|
|
119
134
|
conflicts.push({
|
|
120
135
|
code: 'PROPOSE_WRITE_CONFIG_CONFLICT',
|
|
121
136
|
object: `config.${section}[${i}] "${k}"`,
|
|
122
|
-
detail: `${section} entry "${k}" is the recipe's, and it was changed by hand:
|
|
137
|
+
detail: `${section} entry "${k}" is the recipe's, and it was changed by hand: ${says}, so the write would drop the hand edit; take the draft by removing the hand edit (or the entry), or leave the recipe out for that part (its config.cloth block)`,
|
|
123
138
|
});
|
|
124
139
|
};
|
|
125
140
|
for (const k of [...owned, ...removed]) {
|
|
@@ -134,19 +149,27 @@ function entryEdits(path: readonly string[], identity: (e: unknown) => string |
|
|
|
134
149
|
}
|
|
135
150
|
if (at.length === 0) continue;
|
|
136
151
|
const I = canon(input[at[0]]);
|
|
152
|
+
const isPrevious = V !== null && V.has(k) && I === canon(V.get(k));
|
|
137
153
|
if (D.has(k)) {
|
|
138
154
|
if (I === canon(D.get(k))) continue;
|
|
139
155
|
if (P.has(k) && I === canon(P.get(k))) replace.push(k);
|
|
140
|
-
else
|
|
141
|
-
|
|
142
|
-
|
|
156
|
+
else if (isPrevious) {
|
|
157
|
+
replace.push(k);
|
|
158
|
+
vouched.add(k);
|
|
159
|
+
} else conflict(k, at[0], true);
|
|
160
|
+
} else if (P.has(k) && I === canon(P.get(k))) remove.push(k);
|
|
161
|
+
else if (isPrevious) {
|
|
162
|
+
remove.push(k);
|
|
163
|
+
vouched.add(k);
|
|
164
|
+
} else conflict(k, at[0], false);
|
|
143
165
|
}
|
|
166
|
+
const mark = (k: string): { previous?: true } => (vouched.has(k) ? { previous: true } : {});
|
|
144
167
|
const edits: ClothEdit[] = [];
|
|
145
168
|
const work = [...keys];
|
|
146
|
-
for (const k of replace) edits.push({ path: [...path, work.indexOf(k)], value: D.get(k), label: `${section}["${k}"] replaced
|
|
169
|
+
for (const k of replace) edits.push({ path: [...path, work.indexOf(k)], value: D.get(k), label: `${section}["${k}"] replaced`, ...mark(k) });
|
|
147
170
|
for (const k of remove) {
|
|
148
171
|
const i = work.indexOf(k);
|
|
149
|
-
edits.push({ path: [...path, i], value: undefined, label: `${section}["${k}"] removed
|
|
172
|
+
edits.push({ path: [...path, i], value: undefined, label: `${section}["${k}"] removed`, ...mark(k) });
|
|
150
173
|
work.splice(i, 1);
|
|
151
174
|
}
|
|
152
175
|
const order = [...D.keys()];
|
|
@@ -174,27 +197,53 @@ function entryEdits(path: readonly string[], identity: (e: unknown) => string |
|
|
|
174
197
|
* the input holds it as an array, and any other section, or one the input lacks, whole. Every conflict is collected and
|
|
175
198
|
* refused in one throw, `PROPOSE_WRITE_CONFIG_CONFLICT`, before anything is written.
|
|
176
199
|
*
|
|
200
|
+
* `previous` (issue #571, `propose --write-config --from <config>`) is the same parts drafted a third time, with the
|
|
201
|
+
* recipe of the config the recipe is changed from: an array entry equal to its draft is the recipe's ({@link entryEdits}),
|
|
202
|
+
* and an array section the two drafts agree at is read entry by entry where the previous draft differs from them. An
|
|
203
|
+
* object entry (`meshes.<part>`, `regions.<part>`) the recipe drafts is replaced whole already, so `previous` changes
|
|
204
|
+
* nothing there. Null — no `--from` — is the writer before #571, rule for rule and byte for byte.
|
|
205
|
+
*
|
|
177
206
|
* `whole` is the selftest's mutant only (issue #552): `bones`, `constraints` and `motion.tracks` replaced whole, as
|
|
178
207
|
* the #537 writer did; no flag or environment reaches it.
|
|
179
208
|
*/
|
|
180
|
-
export function clothConfigEdits(drafted: Proposal, plain: Proposal, input: unknown, whole = false): ClothEdit[] {
|
|
209
|
+
export function clothConfigEdits(drafted: Proposal, plain: Proposal, input: unknown, whole = false, previous: Proposal | null = null): ClothEdit[] {
|
|
181
210
|
const edits: ClothEdit[] = [];
|
|
182
211
|
const conflicts: Problem[] = [];
|
|
183
212
|
const d = JSON.parse(JSON.stringify(drafted)) as Record<string, unknown>;
|
|
184
213
|
const p = JSON.parse(JSON.stringify(plain)) as Record<string, unknown>;
|
|
214
|
+
const v = previous === null || whole ? null : (JSON.parse(JSON.stringify(previous)) as Record<string, unknown>);
|
|
215
|
+
const arrayOf = (path: readonly string[]): (typeof ARRAY_SECTIONS)[number] | undefined => (whole ? undefined : ARRAY_SECTIONS.find((x) => x.path.join('.') === path.join('.')));
|
|
216
|
+
const prevAt = (path: readonly string[]): unknown[] | null => {
|
|
217
|
+
if (v === null) return null;
|
|
218
|
+
const c = valueAt(v, path);
|
|
219
|
+
return Array.isArray(c) ? c : [];
|
|
220
|
+
};
|
|
185
221
|
const one = (path: readonly string[], a: unknown, b: unknown): void => {
|
|
186
|
-
const s =
|
|
222
|
+
const s = arrayOf(path);
|
|
187
223
|
const mine = valueAt(input, path);
|
|
188
|
-
if (s !== undefined && Array.isArray(b) && (a === undefined || Array.isArray(a)) && Array.isArray(mine)) edits.push(...entryEdits(path, s.identity, b, Array.isArray(a) ? a : [], mine, conflicts));
|
|
224
|
+
if (s !== undefined && Array.isArray(b) && (a === undefined || Array.isArray(a)) && Array.isArray(mine)) edits.push(...entryEdits(path, s.identity, b, Array.isArray(a) ? a : [], mine, conflicts, prevAt(path)));
|
|
189
225
|
else edits.push({ path, value: b, label: path.join('.') });
|
|
190
226
|
};
|
|
227
|
+
// Issue #571: an array section the two drafts agree at, where the previous draft differs — its entries the previous recipe drafted and this one does not.
|
|
228
|
+
const prevOnly = (path: readonly string[], b: unknown): void => {
|
|
229
|
+
const s = arrayOf(path);
|
|
230
|
+
const mine = valueAt(input, path);
|
|
231
|
+
const c = valueAt(v, path);
|
|
232
|
+
if (v === null || s === undefined || !Array.isArray(b) || !Array.isArray(mine) || canon(c) === canon(b)) return;
|
|
233
|
+
edits.push(...entryEdits(path, s.identity, b, b, mine, conflicts, prevAt(path)));
|
|
234
|
+
};
|
|
191
235
|
for (const section of PROPOSAL_CONFIG_SECTIONS) {
|
|
192
236
|
const a = p[section];
|
|
193
237
|
const b = d[section];
|
|
194
|
-
if (JSON.stringify(a) === JSON.stringify(b))
|
|
238
|
+
if (JSON.stringify(a) === JSON.stringify(b)) {
|
|
239
|
+
if (isPlain(b)) for (const k of Object.keys(b)) prevOnly([section, k], b[k]);
|
|
240
|
+
else prevOnly([section], b);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
195
243
|
if (isPlain(a) && isPlain(b)) {
|
|
196
244
|
for (const k of [...Object.keys(b), ...Object.keys(a).filter((k) => !(k in b))]) {
|
|
197
245
|
if (JSON.stringify(a[k]) !== JSON.stringify(b[k])) one([section, k], a[k], b[k]);
|
|
246
|
+
else prevOnly([section, k], b[k]);
|
|
198
247
|
}
|
|
199
248
|
} else one([section], a, b);
|
|
200
249
|
}
|
|
@@ -221,6 +270,11 @@ export function writtenClothConfig(where: string, text: string, edits: readonly
|
|
|
221
270
|
return r.text;
|
|
222
271
|
}
|
|
223
272
|
|
|
273
|
+
/** Issue #571: how many edits the previous recipe's draft vouched for — an entry that equalled it, and only it. */
|
|
274
|
+
export function previousCount(edits: readonly ClothEdit[]): number {
|
|
275
|
+
return edits.filter((e) => e.previous === true).length;
|
|
276
|
+
}
|
|
277
|
+
|
|
224
278
|
/** What each edit names, in order: what the write line prints. */
|
|
225
279
|
export function editPaths(edits: readonly ClothEdit[]): string[] {
|
|
226
280
|
return edits.map((e) => e.label);
|
package/src/config.ts
CHANGED
|
@@ -213,7 +213,9 @@ export interface Patch {
|
|
|
213
213
|
* `draw` places a patch. What the config alone cannot know — whether the
|
|
214
214
|
* polygon lies inside the rig, takes any of the layer's art, or overlaps
|
|
215
215
|
* another cut of the same part — the assemble stage refuses
|
|
216
|
-
* (`ASSEMBLE_CUT_INSIDE`, `ASSEMBLE_CUT_PIXELS`, `ASSEMBLE_CUT_OVERLAP`)
|
|
216
|
+
* (`ASSEMBLE_CUT_INSIDE`, `ASSEMBLE_CUT_PIXELS`, `ASSEMBLE_CUT_OVERLAP`), and,
|
|
217
|
+
* for a `from` a limb takes (issue #564), whether the polygon takes a pixel a
|
|
218
|
+
* segment of the limb holds (`ASSEMBLE_CUT_CROSSES_LIMB`).
|
|
217
219
|
*/
|
|
218
220
|
export interface Cut {
|
|
219
221
|
from: string;
|
|
@@ -1537,7 +1539,7 @@ function parseConfigFrom(raw: Json, base: string | null): { config: CharacterCon
|
|
|
1537
1539
|
if ('cloth' in t) checkCloth(c, t.cloth);
|
|
1538
1540
|
if ('requirements' in t && c.string('config.requirements', t.requirements) && base !== null) checkRequirementsFile(c, resolve(base, t.requirements));
|
|
1539
1541
|
const from = isPlainObject(t.motion) ? t.motion.animations_from : undefined;
|
|
1540
|
-
const animations = base !== null && typeof from === 'string' && from !== '' ? readAnimationsFrom(c,
|
|
1542
|
+
const animations = base !== null && typeof from === 'string' && from !== '' ? readAnimationsFrom(c, base, from) : null;
|
|
1541
1543
|
if (animations !== null) {
|
|
1542
1544
|
checkFaceAnimationBand(c, animations, hasAltFace, t.turn, attached);
|
|
1543
1545
|
checkAnimationSetKeys(c, animations, t.assemble, new Set<string>([...parts, ...patches, ...cuts, ...(limbs?.parts.keys() ?? [])]));
|
|
@@ -1592,13 +1594,18 @@ function checkRequirementsFile(c: Check, file: string): void {
|
|
|
1592
1594
|
* Read the file `motion.animations_from` names (issue #183) and vouch for what
|
|
1593
1595
|
* merging its animations beside the idle needs, every problem collected in `c`:
|
|
1594
1596
|
*
|
|
1595
|
-
* - `CONFIG_FILE_PRESENT`: no such file, or a file that cannot be read.
|
|
1597
|
+
* - `CONFIG_FILE_PRESENT`: no such file, or a file that cannot be read. The
|
|
1598
|
+
* line names the path as typed, the config's directory it was resolved
|
|
1599
|
+
* against and what that gave (issue #569): the path is read beside the
|
|
1600
|
+
* config, not in the working directory, and a reader who cannot see the
|
|
1601
|
+
* disk needs all three to tell which was wrong.
|
|
1596
1602
|
* - `CONFIG_IS_JSON`: the text does not parse.
|
|
1597
1603
|
* - `CONFIG_FIELD_TYPE`: the file is not an object, its `spec` is not
|
|
1598
1604
|
* "rigc-motion/1", its `animations` is not an object, or an animation in it
|
|
1599
1605
|
* is not one. `CONFIG_KEY_KNOWN` / `CONFIG_FIELD_PRESENT`: a key besides
|
|
1600
1606
|
* `spec` and `animations` (and the annotation and record doors), or one of
|
|
1601
|
-
* the two absent
|
|
1607
|
+
* the two absent; an absent `spec` is told the line to write and the whole
|
|
1608
|
+
* file's shape (issue #569), from {@link ANIMATIONS_FROM_SPEC}. rig-c's `easings`, `groups`, `setup`, `physics` and `mix`
|
|
1602
1609
|
* are refused rather than dropped: `motion.json`'s own are this package's,
|
|
1603
1610
|
* and a table read and not written would be a value lost without a word.
|
|
1604
1611
|
* - `CONFIG_ANIMATION_NAME_FREE`: an animation named `idle`, the one the
|
|
@@ -1609,18 +1616,21 @@ function checkRequirementsFile(c: Check, file: string): void {
|
|
|
1609
1616
|
*
|
|
1610
1617
|
* Returns the animations when this file added no problem, else null.
|
|
1611
1618
|
*/
|
|
1612
|
-
function readAnimationsFrom(c: Check,
|
|
1619
|
+
function readAnimationsFrom(c: Check, base: string, from: string): AnimationsFrom | null {
|
|
1613
1620
|
const field = 'config.motion.animations_from';
|
|
1614
|
-
const
|
|
1621
|
+
const file = resolve(base, from);
|
|
1622
|
+
const form = `{"spec": "${ANIMATIONS_FROM_SPEC}", "animations": {"<name>": {"duration": …, "tracks": [...]}}}`;
|
|
1623
|
+
const shape = `a file in rig-c's motion-spec shape, ${form}, its path relative to the config's directory`;
|
|
1624
|
+
const where = `names ${JSON.stringify(from)}, resolved against the config's directory ${base} (not the working directory) to ${file}`;
|
|
1615
1625
|
if (!existsSync(file) || !statSync(file).isFile()) {
|
|
1616
|
-
c.fail('CONFIG_FILE_PRESENT', field,
|
|
1626
|
+
c.fail('CONFIG_FILE_PRESENT', field, `${where}, which is no such file; ${shape} is required`);
|
|
1617
1627
|
return null;
|
|
1618
1628
|
}
|
|
1619
1629
|
let text: string;
|
|
1620
1630
|
try {
|
|
1621
1631
|
text = readFileSync(file, 'utf8');
|
|
1622
1632
|
} catch (err) {
|
|
1623
|
-
c.fail('CONFIG_FILE_PRESENT', field,
|
|
1633
|
+
c.fail('CONFIG_FILE_PRESENT', field, `${where}, which cannot be read: ${(err as Error).message}; ${shape} is required`);
|
|
1624
1634
|
return null;
|
|
1625
1635
|
}
|
|
1626
1636
|
let raw: Json;
|
|
@@ -1643,7 +1653,13 @@ function readAnimationsFrom(c: Check, file: string): AnimationsFrom | null {
|
|
|
1643
1653
|
`names "${r.key}" ${r.count === 2 ? 'twice' : `${r.count} times`}; each key once is required — JSON keeps only the last, so ${r.at === 'animations' ? 'every animation of that name but the last' : 'every value but the last'} would be dropped without a word`,
|
|
1644
1654
|
);
|
|
1645
1655
|
}
|
|
1646
|
-
|
|
1656
|
+
// Both keys are required; `c.object` is given them as optional so an absent
|
|
1657
|
+
// `spec` can be told the line to write, in the order `c.object` names them.
|
|
1658
|
+
const o = c.object(at, raw, [], ['spec', 'animations']);
|
|
1659
|
+
if (o !== null && !('spec' in o)) {
|
|
1660
|
+
c.fail('CONFIG_FIELD_PRESENT', `${at}.spec`, `is absent and required: write "spec": "${ANIMATIONS_FROM_SPEC}" beside "animations", the motion-spec version motion.json states — the whole file is ${form}`);
|
|
1661
|
+
}
|
|
1662
|
+
if (o !== null && !('animations' in o)) c.fail('CONFIG_FIELD_PRESENT', `${at}.animations`, 'is absent and required');
|
|
1647
1663
|
if (o !== null && 'spec' in o && o.spec !== ANIMATIONS_FROM_SPEC) {
|
|
1648
1664
|
c.fail('CONFIG_FIELD_TYPE', `${at}.spec`, `is ${show(o.spec)}; "${ANIMATIONS_FROM_SPEC}" is required, the motion-spec version motion.json states`);
|
|
1649
1665
|
}
|
package/src/meshstats.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mesh-stats` (issue #566): the vertices and triangles of every mesh a config states, against an assembled parts
|
|
3
|
+
* directory, before a build.
|
|
4
|
+
*
|
|
5
|
+
* It is the rig stage without rigc: the same inputs ({@link readRigInputs}) through the same `buildRig`, whose
|
|
6
|
+
* `meshReport` rows are what `rig/mesh_report.json` is written from. Nothing triangulates a second time, so a count
|
|
7
|
+
* printed here is the count the rig stage writes for the same config and parts — with one exception, which the line
|
|
8
|
+
* says: an `auto` part whose motion gate refuses the full reduction is replayed by the rig stage to an earlier
|
|
9
|
+
* accepted step (`rigStage`, `src/autoreplay.ts`), and that search runs rigc, so it does not run here. A problem
|
|
10
|
+
* `buildRig` refuses is the build's own refusal, by the same name. Nothing is written: no skeleton data leaves memory,
|
|
11
|
+
* no image, no report; rigc's gate is the gate of the commands that emit, and this one emits nothing.
|
|
12
|
+
*/
|
|
13
|
+
import { readRigInputs } from './build.ts';
|
|
14
|
+
import { buildRig, DEFAULT_IDLE_KEYS, type MeshReport } from './rig.ts';
|
|
15
|
+
|
|
16
|
+
/** One mesh's counts, as the rig stage's `mesh_report.json` row holds them; `mode` is `lattice` for a `grid` entry, whose row carries no mode. */
|
|
17
|
+
export interface MeshStatsRow {
|
|
18
|
+
part: string;
|
|
19
|
+
mode: 'lattice' | 'contour' | 'auto' | 'influence';
|
|
20
|
+
vertices: number;
|
|
21
|
+
triangles: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The counts of each row of a mesh report, in its order (parts.json's, the order the rig stage writes). */
|
|
25
|
+
export function meshStatsRows(report: readonly MeshReport[]): MeshStatsRow[] {
|
|
26
|
+
return report.map((m) => ({ part: m.part, mode: 'mode' in m ? m.mode : 'lattice', vertices: m.vertices, triangles: m.triangles }));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What `auto` adds to its line: the count is the reduction's, before the motion gate that may replay it. */
|
|
30
|
+
export const AUTO_BEFORE_GATE = "the reduction's result; when rigc's motion gate refuses it, the rig stage replays an earlier accepted step, which this command does not run";
|
|
31
|
+
|
|
32
|
+
/** The printed lines: one per mesh, then the total. No budget line: the tree holds no triangle budget. */
|
|
33
|
+
export function meshStatsLines(rows: readonly MeshStatsRow[]): string[] {
|
|
34
|
+
const out = rows.map((r) => `mesh-stats: ${r.part} — ${r.mode} ${r.vertices} vertices, ${r.triangles} triangles${r.mode === 'auto' ? ` (${AUTO_BEFORE_GATE})` : ''}`);
|
|
35
|
+
const total = rows.reduce((n, r) => n + r.triangles, 0);
|
|
36
|
+
out.push(`mesh-stats: total ${total} triangles over ${rows.length} mesh(es)`);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface MeshStatsInput {
|
|
41
|
+
/** The config, as `rig --config` reads it. */
|
|
42
|
+
config: string;
|
|
43
|
+
/** The directory holding parts.json and parts/<name>.png, as `rig --parts` reads it. */
|
|
44
|
+
parts: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The counts of every mesh `buildRig` makes from the config and the parts, printed through `log`. The idle's keys
|
|
49
|
+
* go where `rig` puts them by default (`ctl`): where they go moves no vertex and no triangle, since a control bone
|
|
50
|
+
* stands at its bone's origin and no mesh is weighted to it. Throws the rig stage's own `PartsError` on a refusal.
|
|
51
|
+
*/
|
|
52
|
+
export function meshStatsStage(input: MeshStatsInput, log: (line: string) => void): MeshStatsRow[] {
|
|
53
|
+
const { cfg, parts, images } = readRigInputs(input.config, input.parts);
|
|
54
|
+
const rows = meshStatsRows(buildRig(cfg, parts, images, undefined, DEFAULT_IDLE_KEYS).meshReport);
|
|
55
|
+
for (const l of meshStatsLines(rows)) log(l);
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
package/src/parts.ts
CHANGED
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
* cut from, which shares its `from`. The record is in draw order, and a piece
|
|
43
43
|
* drawn `"back"` comes before its base, so order cannot say which of two parts
|
|
44
44
|
* sharing a layer is the piece; this field does. A `parts.json` written before
|
|
45
|
-
* 1.6.0 has none, and still reads.
|
|
45
|
+
* 1.6.0 has none, and still reads. A piece cut from a part a limb took
|
|
46
|
+
* (issue #564) names that part, which is not written itself: its base is the
|
|
47
|
+
* limb segments whose `limb.of` it is, with the same `from`. `limb`, written only on a part a
|
|
46
48
|
* `config.limbs` segment made (issue #349), names the limb, the segment's
|
|
47
49
|
* index (0 the upper), the part it was cut from (`of`), the one bone it rides
|
|
48
50
|
* and, below a joint, the joint, its declared `range` when there is one
|
|
@@ -152,11 +154,21 @@ export interface CapRecord {
|
|
|
152
154
|
/** Issue #359: with `image_px`, the hidden-art layer the cap's image came from (`<run>:<layer>:hidden`), when it came from one rather than the config's cap file. */
|
|
153
155
|
image_layer?: string;
|
|
154
156
|
missing_px: number;
|
|
157
|
+
/**
|
|
158
|
+
* Issue #557, written only when `missing_px` is above 0: the missing pixels
|
|
159
|
+
* — the disc's on the upper side of the cut that no layer of the limb gives
|
|
160
|
+
* — by side of the limb's axis at the joint line, `left` where a pixel
|
|
161
|
+
* centre's offset across the axis (`jointOffsets` in `src/limbs.ts`) is 0 or
|
|
162
|
+
* above (the side toward smaller x when the limb hangs down the rig) and
|
|
163
|
+
* `right` the other; the two add up to `missing_px`. A full cap writes no key.
|
|
164
|
+
*/
|
|
165
|
+
short_px?: { left: number; right: number };
|
|
155
166
|
/**
|
|
156
167
|
* Issue #360, written only under the segment's `cap_shape: "disc"`: the
|
|
157
168
|
* shape; the cap's pixels taken from the upper segment's art where the
|
|
158
169
|
* lower's layer had none (`upper_px`). `radius` is then the half-width about the
|
|
159
|
-
* joint, at most half of `width`.
|
|
170
|
+
* joint, at most half of `width`. Issue #557: without the shape the half-disc
|
|
171
|
+
* takes them too, and `upper_px` is written there only when above 0.
|
|
160
172
|
*/
|
|
161
173
|
shape?: 'disc';
|
|
162
174
|
upper_px?: number;
|
|
@@ -197,6 +209,7 @@ const CAP_KEYS = [
|
|
|
197
209
|
'image_px',
|
|
198
210
|
'image_layer',
|
|
199
211
|
'missing_px',
|
|
212
|
+
'short_px',
|
|
200
213
|
'shape',
|
|
201
214
|
'upper_px',
|
|
202
215
|
'edge',
|
|
@@ -552,6 +565,14 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
552
565
|
// single plan part behind it; the config loader refuses one).
|
|
553
566
|
const recs = o.parts.filter((p): p is Record<string, unknown> => typeof p === 'object' && p !== null && !Array.isArray(p));
|
|
554
567
|
const byName = new Map<unknown, Record<string, unknown>>(recs.map((r) => [r.name, r]));
|
|
568
|
+
// Issue #564: a plan part a limb took is not written itself; its segments are, each naming it (`limb.of`) with its layer.
|
|
569
|
+
const limbOf = new Map<string, Record<string, unknown>>();
|
|
570
|
+
for (const r of recs) {
|
|
571
|
+
const l = r[LIMB_KEY];
|
|
572
|
+
if (typeof l !== 'object' || l === null || Array.isArray(l)) continue;
|
|
573
|
+
const of = (l as Record<string, unknown>).of;
|
|
574
|
+
if (typeof of === 'string' && !limbOf.has(of)) limbOf.set(of, r);
|
|
575
|
+
}
|
|
555
576
|
for (const r of recs) {
|
|
556
577
|
if (!(CUT_FROM_KEY in r)) continue;
|
|
557
578
|
const object = `part "${String(r.name)}" field "${CUT_FROM_KEY}"`;
|
|
@@ -561,7 +582,10 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
561
582
|
continue;
|
|
562
583
|
}
|
|
563
584
|
const b = byName.get(base);
|
|
564
|
-
|
|
585
|
+
const seg = b === undefined ? limbOf.get(base) : undefined;
|
|
586
|
+
if (seg !== undefined) {
|
|
587
|
+
if (seg.from !== r.from) fail('PARTS_CUT_FROM_KNOWN', object, `names "${base}", which limb segment "${String(seg.name)}" was cut from, with from ${show(seg.from)}; this piece's is ${show(r.from)}, and a piece shares its base's layer`);
|
|
588
|
+
} else if (b === undefined) fail('PARTS_CUT_FROM_KNOWN', object, `names "${base}", which is no part of this file and no limb segment's "of"; the plan part the cut took this piece from is required`);
|
|
565
589
|
else if (base === r.name) fail('PARTS_CUT_FROM_KNOWN', object, `names the piece itself; the plan part the cut took it from is required`);
|
|
566
590
|
else if (CUT_FROM_KEY in b) fail('PARTS_CUT_FROM_KNOWN', object, `names "${base}", which is itself a piece (cut from ${show(b[CUT_FROM_KEY])}); a plan part is required, as a cut of a cut has no single layer behind it`);
|
|
567
591
|
else if (b.from !== r.from) fail('PARTS_CUT_FROM_KNOWN', object, `names "${base}", whose from is ${show(b.from)}; this piece's is ${show(r.from)}, and a piece shares its base's layer`);
|
|
@@ -609,7 +633,9 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
609
633
|
(!('image_px' in co) || isCount(co.image_px)) &&
|
|
610
634
|
(!('image_layer' in co) || ('image_px' in co && typeof co.image_layer === 'string' && co.image_layer !== '')) &&
|
|
611
635
|
// Issue #360: a disc cap carries its count, a feathered edge its band and count, and neither carries them alone.
|
|
612
|
-
('shape' in co ? co.shape === 'disc' && isCount(co.upper_px) : !('upper_px' in co)) &&
|
|
636
|
+
('shape' in co ? co.shape === 'disc' && isCount(co.upper_px) : !('upper_px' in co) || (isCount(co.upper_px) && co.upper_px > 0)) &&
|
|
637
|
+
// Issue #557: the shortfall by side, when written, adds up to the missing pixels, and is never written for none.
|
|
638
|
+
(!('short_px' in co) || shortSides(co.short_px, co.missing_px)) &&
|
|
613
639
|
('edge' in co ? co.edge === 'feather' && typeof co.feather_radius === 'number' && Number.isFinite(co.feather_radius) && co.feather_radius >= 0 && isCount(co.feathered_px) : !('feather_radius' in co) && !('feathered_px' in co)) &&
|
|
614
640
|
// Issue #360 (item 14): a placed cut carries its band, line and counts, the line inside the band; none of them rides alone.
|
|
615
641
|
('cut_band' in co
|
|
@@ -628,7 +654,7 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
628
654
|
fail(
|
|
629
655
|
'PARTS_FIELD_TYPE',
|
|
630
656
|
`${object} "cap"`,
|
|
631
|
-
`is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, shape? ("disc", with upper_px), edge? ("feather", with feather_radius and feathered_px), cut_band? (with cut_offset inside the band, cut_at, cut_crossed at most joint_crossed, band_px, stroke_luma_max? 0..255)} is required`,
|
|
657
|
+
`is ${show(c)}; {at: [x, y], width, radius, box: [x, y, w, h], layer_px, image_px?, image_layer? (with image_px), missing_px, short_px? ({left, right}, adding up to missing_px, above 0), shape? ("disc", with upper_px; without it upper_px? above 0), edge? ("feather", with feather_radius and feathered_px), cut_band? (with cut_offset inside the band, cut_at, cut_crossed at most joint_crossed, band_px, stroke_luma_max? 0..255)} is required`,
|
|
632
658
|
);
|
|
633
659
|
}
|
|
634
660
|
}
|
|
@@ -659,6 +685,12 @@ function checkParts(raw: unknown, path: string): PartsFile {
|
|
|
659
685
|
}
|
|
660
686
|
|
|
661
687
|
const isCount = (v: unknown): v is number => Number.isInteger(v) && (v as number) >= 0;
|
|
688
|
+
/** Issue #557: a cap's `short_px` — `{left, right}`, two counts and no other key, adding up to `missing`, above 0. */
|
|
689
|
+
function shortSides(v: unknown, missing: unknown): boolean {
|
|
690
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v)) return false;
|
|
691
|
+
const o = v as Record<string, unknown>;
|
|
692
|
+
return Object.keys(o).sort().join(',') === 'left,right' && isCount(o.left) && isCount(o.right) && o.left + o.right === missing && o.left + o.right > 0;
|
|
693
|
+
}
|
|
662
694
|
|
|
663
695
|
/**
|
|
664
696
|
* The `single_run_pad` block (issue #366): every key known and present, each
|