@rig-c/review 0.22.0 → 0.24.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 +9 -2
- package/docs/PANELS.md +1 -1
- package/package.json +2 -1
- package/skills/rig-review/SKILL.md +89 -0
- package/src/applied-blocks.ts +506 -4
- package/web/animation-inspection.ts +17 -7
- package/web/chest-editor.ts +3 -0
- package/web/compare-picked-tools.ts +102 -11
- package/web/index.html +1 -1
- package/web/main.ts +89 -14
- package/web/mesh-editor.ts +12 -8
- package/web/rebuild-client.ts +17 -0
- package/web/retarget-panel.ts +2 -1
- package/web/styles.css +6 -3
package/src/applied-blocks.ts
CHANGED
|
@@ -9,12 +9,79 @@
|
|
|
9
9
|
* physics or bones `rig` patch, a remesh, a regions, delta or retarget record, or none — marks nothing in either block.
|
|
10
10
|
* A pending op is applied when the block's applied ops hold an op with the same op, path, value and name.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
APPLIED_ANIMATION_SCHEMA,
|
|
14
|
+
APPLIED_DELTA_SCHEMA,
|
|
15
|
+
APPLIED_PATCH_SCHEMA,
|
|
16
|
+
APPLIED_RETARGET_SCHEMA,
|
|
17
|
+
} from './applied-context.ts';
|
|
18
|
+
import { parsePointer, type PatchOp } from './config-patch.ts';
|
|
19
|
+
|
|
20
|
+
export const APPLIED_REGIONS_SCHEMA = 'rig-review-applied/1';
|
|
14
21
|
|
|
15
22
|
export type AppliedBlock = 'cuts' | 'cloth';
|
|
16
23
|
export const APPLIED_BLOCKS: readonly AppliedBlock[] = ['cuts', 'cloth'];
|
|
17
24
|
|
|
25
|
+
export type AppliedPatchPanel = 'cuts' | 'cloth' | 'physics' | 'bones' | 'idle' | 'rig-fields';
|
|
26
|
+
export const APPLIED_PATCH_PANELS: readonly AppliedPatchPanel[] = [
|
|
27
|
+
'cuts',
|
|
28
|
+
'cloth',
|
|
29
|
+
'physics',
|
|
30
|
+
'bones',
|
|
31
|
+
'idle',
|
|
32
|
+
'rig-fields',
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
export type RebuildPanelKind =
|
|
36
|
+
| 'chest'
|
|
37
|
+
| 'mesh-edit'
|
|
38
|
+
| 'mesh'
|
|
39
|
+
| 'bones'
|
|
40
|
+
| 'rig-fields'
|
|
41
|
+
| 'cuts'
|
|
42
|
+
| 'cloth'
|
|
43
|
+
| 'physics'
|
|
44
|
+
| 'idle'
|
|
45
|
+
| 'retarget'
|
|
46
|
+
| 'animation';
|
|
47
|
+
|
|
48
|
+
export const REBUILD_PANEL_KINDS: readonly RebuildPanelKind[] = [
|
|
49
|
+
'chest',
|
|
50
|
+
'mesh-edit',
|
|
51
|
+
'mesh',
|
|
52
|
+
'bones',
|
|
53
|
+
'rig-fields',
|
|
54
|
+
'cuts',
|
|
55
|
+
'cloth',
|
|
56
|
+
'physics',
|
|
57
|
+
'idle',
|
|
58
|
+
'retarget',
|
|
59
|
+
'animation',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
export interface RebuildHandoffContext {
|
|
63
|
+
constraints?: readonly unknown[] | null;
|
|
64
|
+
bones?: readonly unknown[] | null;
|
|
65
|
+
fields?: Record<string, unknown> | null;
|
|
66
|
+
cuts?: { config?: Record<string, unknown> | null } | null;
|
|
67
|
+
idle?:
|
|
68
|
+
| {
|
|
69
|
+
tracks?: readonly unknown[] | null;
|
|
70
|
+
blink?: Record<string, unknown> | null;
|
|
71
|
+
source?: { available: boolean; source?: { tracks?: readonly unknown[] | null; blink?: unknown } };
|
|
72
|
+
}
|
|
73
|
+
| null;
|
|
74
|
+
cloth?: { recipes?: Record<string, unknown> | null } | null;
|
|
75
|
+
meshes?: Record<string, unknown> | null;
|
|
76
|
+
animations?: { text?: string | null } | null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface AppliedStageOwner {
|
|
80
|
+
panel: RebuildPanelKind;
|
|
81
|
+
part?: string;
|
|
82
|
+
summary: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
18
85
|
/** The record op each block owns. */
|
|
19
86
|
const BLOCK_OP: Record<AppliedBlock, string> = { cuts: 'build', cloth: 'cloth' };
|
|
20
87
|
|
|
@@ -23,6 +90,38 @@ const isObject = (v: unknown): v is Record<string, unknown> => !!v && typeof v =
|
|
|
23
90
|
/** One op's identity for the applied mark: op, path, value and name. */
|
|
24
91
|
export const opKey = (o: PatchOp): string => JSON.stringify([o.op, o.path, o.value ?? null, o.name ?? null]);
|
|
25
92
|
|
|
93
|
+
/** Which patch panel a single `ConfigPatch` operation belongs to, or null when the pointer is outside every known panel. */
|
|
94
|
+
export function patchOpPanel(recordOp: unknown, op: PatchOp): AppliedPatchPanel | 'mesh' | null {
|
|
95
|
+
if (!isObject(op) || typeof op.path !== 'string') return null;
|
|
96
|
+
let tokens: string[];
|
|
97
|
+
try {
|
|
98
|
+
tokens = parsePointer(op.path);
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!tokens.length) return null;
|
|
103
|
+
if (recordOp === 'cloth') return tokens[0] === 'cloth' ? 'cloth' : null;
|
|
104
|
+
if (recordOp === 'build') {
|
|
105
|
+
return tokens[0] === 'assemble' || tokens[0] === 'limbs' || tokens[0] === 'joints' ? 'cuts' : null;
|
|
106
|
+
}
|
|
107
|
+
if (recordOp === 'remesh') return tokens[0] === 'meshes' && typeof tokens[1] === 'string' && tokens[1].length > 0 ? 'mesh' : null;
|
|
108
|
+
if (recordOp === 'rig' || recordOp === 'retune' || recordOp === undefined) {
|
|
109
|
+
if (tokens[0] === 'constraints') return 'physics';
|
|
110
|
+
if (tokens[0] === 'bones' && (tokens[2] === 'at' || tokens[2] === 'points' || tokens[2] === 'tip')) return 'bones';
|
|
111
|
+
if (tokens[0] === 'motion' && (tokens[1] === 'tracks' || (tokens[1] === 'blink' && tokens[2] !== 'still'))) return 'idle';
|
|
112
|
+
if (
|
|
113
|
+
tokens[0] === 'regions' ||
|
|
114
|
+
tokens[0] === 'stops' ||
|
|
115
|
+
tokens[0] === 'turn' ||
|
|
116
|
+
(tokens[0] === 'motion' && tokens[1] === 'blink' && tokens[2] === 'still') ||
|
|
117
|
+
(tokens[0] === 'bones' && (tokens[2] === 'inherit' || tokens[2] === 'link_inherit'))
|
|
118
|
+
) {
|
|
119
|
+
return 'rig-fields';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
26
125
|
/** The block a record belongs to, or null when it marks nothing in the Cuts or Cloth block. */
|
|
27
126
|
export function recordBlock(record: unknown): AppliedBlock | null {
|
|
28
127
|
if (!isObject(record) || record.schema !== APPLIED_PATCH_SCHEMA) return null;
|
|
@@ -35,11 +134,35 @@ export function appliedBlockOps(record: unknown): Record<AppliedBlock, PatchOp[]
|
|
|
35
134
|
const block = recordBlock(record);
|
|
36
135
|
if (!block) return out;
|
|
37
136
|
const patch = (record as Record<string, unknown>).patch;
|
|
38
|
-
const ops = isObject(patch) && Array.isArray(patch.ops) ? patch.ops as PatchOp[] : [];
|
|
137
|
+
const ops = isObject(patch) && Array.isArray(patch.ops) ? (patch.ops as PatchOp[]) : [];
|
|
39
138
|
out[block] = ops.map(o => ({ ...o }));
|
|
40
139
|
return out;
|
|
41
140
|
}
|
|
42
141
|
|
|
142
|
+
/**
|
|
143
|
+
* #250: the stage record's applied ops across all six patch-producing panels (`cuts`, `cloth`, `physics`, `bones`,
|
|
144
|
+
* `idle`, `rig-fields`). When another panel's Apply replaces the stage record, superseded panels receive `[]` so their
|
|
145
|
+
* items stop reading as `applied` while keeping their in-panel edits intact.
|
|
146
|
+
*/
|
|
147
|
+
export function appliedPanelOps(record: unknown): Record<AppliedPatchPanel, PatchOp[]> {
|
|
148
|
+
const out: Record<AppliedPatchPanel, PatchOp[]> = {
|
|
149
|
+
cuts: [],
|
|
150
|
+
cloth: [],
|
|
151
|
+
physics: [],
|
|
152
|
+
bones: [],
|
|
153
|
+
idle: [],
|
|
154
|
+
'rig-fields': [],
|
|
155
|
+
};
|
|
156
|
+
if (!isObject(record) || record.schema !== APPLIED_PATCH_SCHEMA) return out;
|
|
157
|
+
const patch = record.patch;
|
|
158
|
+
const ops = isObject(patch) && Array.isArray(patch.ops) ? (patch.ops as PatchOp[]) : [];
|
|
159
|
+
for (const op of ops) {
|
|
160
|
+
const panel = patchOpPanel(record.op, op);
|
|
161
|
+
if (panel && panel !== 'mesh') out[panel].push({ ...op });
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
43
166
|
/** Whether a pending item (the ops it sends) is applied: it sends at least one op and every one is in `applied`. */
|
|
44
167
|
export function itemApplied(itemOps: readonly PatchOp[], applied: readonly PatchOp[]): boolean {
|
|
45
168
|
if (!itemOps.length || !applied.length) return false;
|
|
@@ -48,7 +171,8 @@ export function itemApplied(itemOps: readonly PatchOp[], applied: readonly Patch
|
|
|
48
171
|
}
|
|
49
172
|
|
|
50
173
|
/** The stage's identity for a readout: the applied record's build id, or null on the inspected build. */
|
|
51
|
-
const stageId = (record: unknown): string | null =>
|
|
174
|
+
const stageId = (record: unknown): string | null =>
|
|
175
|
+
isObject(record) && typeof record.buildId === 'string' ? record.buildId : null;
|
|
52
176
|
|
|
53
177
|
/**
|
|
54
178
|
* #186: the blocks whose result readout goes stale when the stage changes from `previous` to `next` — every block the
|
|
@@ -60,3 +184,381 @@ export function staleReadouts(previous: unknown, next: unknown): AppliedBlock[]
|
|
|
60
184
|
const owner = recordBlock(next);
|
|
61
185
|
return APPLIED_BLOCKS.filter(b => b !== owner);
|
|
62
186
|
}
|
|
187
|
+
|
|
188
|
+
function walkTokens(root: unknown, tokens: readonly string[]): unknown {
|
|
189
|
+
let cur: unknown = root;
|
|
190
|
+
for (const token of tokens) {
|
|
191
|
+
if (Array.isArray(cur)) {
|
|
192
|
+
const idx = Number(token);
|
|
193
|
+
if (!Number.isInteger(idx) || idx < 0 || idx >= cur.length) return undefined;
|
|
194
|
+
cur = cur[idx];
|
|
195
|
+
} else if (isObject(cur) && Object.hasOwn(cur, token)) {
|
|
196
|
+
cur = cur[token];
|
|
197
|
+
} else {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return cur;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function lookupHandoffValue(handoff: RebuildHandoffContext | null | undefined, tokens: readonly string[]): unknown {
|
|
205
|
+
if (!handoff || !tokens.length) return undefined;
|
|
206
|
+
if (isObject(handoff.cuts?.config)) {
|
|
207
|
+
const fromConfig = walkTokens(handoff.cuts.config, tokens);
|
|
208
|
+
if (fromConfig !== undefined) return fromConfig;
|
|
209
|
+
}
|
|
210
|
+
if (tokens[0] === 'constraints' && Array.isArray(handoff.constraints)) {
|
|
211
|
+
return walkTokens(handoff.constraints, tokens.slice(1));
|
|
212
|
+
}
|
|
213
|
+
if (tokens[0] === 'bones' && Array.isArray(handoff.bones)) {
|
|
214
|
+
return walkTokens(handoff.bones, tokens.slice(1));
|
|
215
|
+
}
|
|
216
|
+
if (tokens[0] === 'meshes' && isObject(handoff.meshes)) {
|
|
217
|
+
return walkTokens(handoff.meshes, tokens.slice(1));
|
|
218
|
+
}
|
|
219
|
+
if (tokens[0] === 'cloth' && isObject(handoff.cloth?.recipes)) {
|
|
220
|
+
return walkTokens(handoff.cloth.recipes, tokens.slice(1));
|
|
221
|
+
}
|
|
222
|
+
if (tokens[0] === 'motion' && tokens[1] === 'tracks') {
|
|
223
|
+
const tracks = Array.isArray(handoff.idle?.tracks)
|
|
224
|
+
? handoff.idle!.tracks
|
|
225
|
+
: handoff.idle?.source?.available && Array.isArray(handoff.idle.source.source?.tracks)
|
|
226
|
+
? handoff.idle.source.source.tracks
|
|
227
|
+
: null;
|
|
228
|
+
if (tracks) return walkTokens(tracks, tokens.slice(2));
|
|
229
|
+
}
|
|
230
|
+
if (tokens[0] === 'motion' && tokens[1] === 'blink') {
|
|
231
|
+
const blink = isObject(handoff.idle?.blink)
|
|
232
|
+
? handoff.idle!.blink
|
|
233
|
+
: handoff.idle?.source?.available && isObject(handoff.idle.source.source?.blink)
|
|
234
|
+
? handoff.idle.source.source.blink
|
|
235
|
+
: null;
|
|
236
|
+
if (blink) return walkTokens(blink, tokens.slice(2));
|
|
237
|
+
}
|
|
238
|
+
if (isObject(handoff.fields)) {
|
|
239
|
+
return walkTokens(handoff.fields, tokens);
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function formatShortValue(v: unknown): string {
|
|
245
|
+
if (typeof v === 'number' || typeof v === 'boolean' || v === null) return String(v);
|
|
246
|
+
if (typeof v === 'string') return v.length > 24 ? `${JSON.stringify(v.slice(0, 21))}…` : JSON.stringify(v);
|
|
247
|
+
if (Array.isArray(v)) {
|
|
248
|
+
const text = `[${v.map(x => (typeof x === 'number' ? String(x) : JSON.stringify(x))).join(', ')}]`;
|
|
249
|
+
return text.length > 36 ? `${text.slice(0, 33)}…]` : text;
|
|
250
|
+
}
|
|
251
|
+
const text = JSON.stringify(v);
|
|
252
|
+
return text && text.length > 36 ? `${text.slice(0, 33)}…` : String(text);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function formatTransition(label: string, op: PatchOp, from: unknown): string {
|
|
256
|
+
if (op.op === 'remove') return `${label} removed`;
|
|
257
|
+
const toText = formatShortValue(op.value);
|
|
258
|
+
if (from !== undefined) return `${label} ${formatShortValue(from)} → ${toText}`;
|
|
259
|
+
return `${label} → ${toText}`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function summarizeList(items: readonly string[], max = 2): string {
|
|
263
|
+
if (items.length <= max) return items.join(', ');
|
|
264
|
+
return `${items.slice(0, max).join(', ')} (+${items.length - max} more)`;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const refuseDropStatement = (detail: string): never => {
|
|
268
|
+
throw new Error(`APPLIED_DROP_STATEMENT_UNAVAILABLE: ${detail}`);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* #250: derives the owning panel and plain-words summary for the stage's current applied record.
|
|
273
|
+
* Returns `null` when nothing is applied (`null` / `undefined`). Refuses by name (`APPLIED_DROP_STATEMENT_UNAVAILABLE`)
|
|
274
|
+
* when the record has an unknown schema or lacks the fields needed to state what will be dropped.
|
|
275
|
+
*/
|
|
276
|
+
export function describeAppliedRecord(
|
|
277
|
+
record: unknown,
|
|
278
|
+
handoff?: RebuildHandoffContext | null,
|
|
279
|
+
): AppliedStageOwner | null {
|
|
280
|
+
if (record === null || record === undefined) return null;
|
|
281
|
+
if (!isObject(record) || typeof record.schema !== 'string') {
|
|
282
|
+
return refuseDropStatement('stage record is not a schema-tagged object');
|
|
283
|
+
}
|
|
284
|
+
const schema = record.schema;
|
|
285
|
+
if (schema === APPLIED_REGIONS_SCHEMA) {
|
|
286
|
+
const part = typeof record.part === 'string' && record.part.trim() ? record.part.trim() : null;
|
|
287
|
+
if (!part) return refuseDropStatement(`${APPLIED_REGIONS_SCHEMA} is missing part`);
|
|
288
|
+
if (isObject(record.bust)) {
|
|
289
|
+
return { panel: 'chest', part, summary: `Chest landmarks on ${part}` };
|
|
290
|
+
}
|
|
291
|
+
const regions = Array.isArray(record.regions) ? record.regions : null;
|
|
292
|
+
if (!regions || !regions.length) {
|
|
293
|
+
return refuseDropStatement(`${APPLIED_REGIONS_SCHEMA} has neither bust landmarks nor regions`);
|
|
294
|
+
}
|
|
295
|
+
const names = regions
|
|
296
|
+
.map(r => (isObject(r) && typeof r.name === 'string' && r.name.trim() ? r.name.trim() : null))
|
|
297
|
+
.filter((n): n is string => n !== null);
|
|
298
|
+
if (!names.length) return refuseDropStatement(`${APPLIED_REGIONS_SCHEMA} regions have no names`);
|
|
299
|
+
return { panel: 'chest', part, summary: `Chest regions on ${part} (${summarizeList(names, 3)})` };
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (schema === APPLIED_PATCH_SCHEMA) {
|
|
303
|
+
const patch = isObject(record.patch) ? record.patch : null;
|
|
304
|
+
const ops = patch && Array.isArray(patch.ops) ? (patch.ops as PatchOp[]) : null;
|
|
305
|
+
if (!ops || !ops.length) return refuseDropStatement(`${APPLIED_PATCH_SCHEMA} has no patch ops`);
|
|
306
|
+
const panels = new Set<AppliedPatchPanel | 'mesh'>();
|
|
307
|
+
for (const op of ops) {
|
|
308
|
+
const p = patchOpPanel(record.op, op);
|
|
309
|
+
if (!p) return refuseDropStatement(`${APPLIED_PATCH_SCHEMA} op ${JSON.stringify(op?.path)} has no panel owner`);
|
|
310
|
+
panels.add(p);
|
|
311
|
+
}
|
|
312
|
+
if (panels.size !== 1) {
|
|
313
|
+
return refuseDropStatement(`${APPLIED_PATCH_SCHEMA} mixes multiple panels (${[...panels].join(', ')})`);
|
|
314
|
+
}
|
|
315
|
+
const panel = [...panels][0]!;
|
|
316
|
+
if (panel === 'mesh') {
|
|
317
|
+
const firstTokens = parsePointer(ops[0]!.path);
|
|
318
|
+
const part = firstTokens[1];
|
|
319
|
+
if (!part) return refuseDropStatement(`${APPLIED_PATCH_SCHEMA} remesh op is missing part`);
|
|
320
|
+
const items = ops.map(op => {
|
|
321
|
+
const tokens = parsePointer(op.path);
|
|
322
|
+
const field = tokens.slice(2).join('/') || part;
|
|
323
|
+
return formatTransition(field, op, lookupHandoffValue(handoff, tokens));
|
|
324
|
+
});
|
|
325
|
+
return { panel: 'mesh', part, summary: `Mesh ${part} ${summarizeList(items)}` };
|
|
326
|
+
}
|
|
327
|
+
if (panel === 'physics') {
|
|
328
|
+
const items = ops.map(op => {
|
|
329
|
+
const tokens = parsePointer(op.path);
|
|
330
|
+
const field = tokens.slice(2).join('/') || op.path;
|
|
331
|
+
return formatTransition(field, op, lookupHandoffValue(handoff, tokens));
|
|
332
|
+
});
|
|
333
|
+
return { panel: 'physics', summary: `Physics ${summarizeList(items)}` };
|
|
334
|
+
}
|
|
335
|
+
if (panel === 'bones') {
|
|
336
|
+
const items = ops.map(op => {
|
|
337
|
+
const tokens = parsePointer(op.path);
|
|
338
|
+
const field = tokens.slice(2).join('/');
|
|
339
|
+
const label = [op.name, field].filter(Boolean).join(' ') || op.path;
|
|
340
|
+
return formatTransition(label, op, lookupHandoffValue(handoff, tokens));
|
|
341
|
+
});
|
|
342
|
+
return { panel: 'bones', summary: `Bones ${summarizeList(items)}` };
|
|
343
|
+
}
|
|
344
|
+
if (panel === 'idle') {
|
|
345
|
+
const items = ops.map(op => {
|
|
346
|
+
const tokens = parsePointer(op.path);
|
|
347
|
+
const tail = tokens[1] === 'tracks' ? tokens.slice(3).join('/') || 'track' : tokens.slice(1).join('/');
|
|
348
|
+
const label = op.name ? `${op.name} ${tail}` : tail || op.path;
|
|
349
|
+
return formatTransition(label, op, lookupHandoffValue(handoff, tokens));
|
|
350
|
+
});
|
|
351
|
+
return { panel: 'idle', summary: `Idle ${summarizeList(items)}` };
|
|
352
|
+
}
|
|
353
|
+
if (panel === 'rig-fields') {
|
|
354
|
+
const items = ops.map(op => {
|
|
355
|
+
const tokens = parsePointer(op.path);
|
|
356
|
+
const label = op.name ? `${op.name} ${tokens.slice(2).join('/') || tokens.at(-1)}` : tokens.join('/');
|
|
357
|
+
return formatTransition(label, op, lookupHandoffValue(handoff, tokens));
|
|
358
|
+
});
|
|
359
|
+
return { panel: 'rig-fields', summary: `Rig fields ${summarizeList(items)}` };
|
|
360
|
+
}
|
|
361
|
+
if (panel === 'cuts') {
|
|
362
|
+
const items = ops.map(op => {
|
|
363
|
+
const tokens = parsePointer(op.path);
|
|
364
|
+
const tail = tokens.slice(3).join('/') || tokens.slice(1).join('/');
|
|
365
|
+
const label = op.name ? `${op.name} ${tail}` : tail || op.path;
|
|
366
|
+
return formatTransition(label, op, lookupHandoffValue(handoff, tokens));
|
|
367
|
+
});
|
|
368
|
+
return { panel: 'cuts', summary: `Cuts ${summarizeList(items)}` };
|
|
369
|
+
}
|
|
370
|
+
const items = ops.map(op => {
|
|
371
|
+
const tokens = parsePointer(op.path);
|
|
372
|
+
const label = tokens.slice(1).join(' ') || op.path;
|
|
373
|
+
return formatTransition(label, op, lookupHandoffValue(handoff, tokens));
|
|
374
|
+
});
|
|
375
|
+
return { panel: 'cloth', summary: `Cloth ${summarizeList(items)}` };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (schema === APPLIED_DELTA_SCHEMA) {
|
|
379
|
+
const part = typeof record.part === 'string' && record.part.trim() ? record.part.trim() : null;
|
|
380
|
+
const delta = isObject(record.delta) ? record.delta : null;
|
|
381
|
+
const ops = delta && Array.isArray(delta.ops) ? delta.ops : null;
|
|
382
|
+
if (!part || !ops || !ops.length) {
|
|
383
|
+
return refuseDropStatement(`${APPLIED_DELTA_SCHEMA} is missing part or delta ops`);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
panel: 'mesh-edit',
|
|
387
|
+
part,
|
|
388
|
+
summary: `Edit mesh on ${part} (${ops.length} ${ops.length === 1 ? 'op' : 'ops'})`,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (schema === APPLIED_RETARGET_SCHEMA) {
|
|
393
|
+
const motion = isObject(record.motion) ? record.motion : null;
|
|
394
|
+
const retarget = isObject(record.retarget) ? record.retarget : null;
|
|
395
|
+
const flags = retarget && isObject(retarget.flags) ? retarget.flags : null;
|
|
396
|
+
const seq = retarget && isObject(retarget.sequence) ? retarget.sequence : null;
|
|
397
|
+
const animation =
|
|
398
|
+
(typeof motion?.animation === 'string' && motion.animation.trim()) ||
|
|
399
|
+
(typeof flags?.animation === 'string' && flags.animation.trim()) ||
|
|
400
|
+
null;
|
|
401
|
+
const reference = typeof seq?.reference === 'string' && seq.reference.trim() ? seq.reference.trim() : null;
|
|
402
|
+
if (!animation || !reference) {
|
|
403
|
+
return refuseDropStatement(`${APPLIED_RETARGET_SCHEMA} is missing animation or sequence reference`);
|
|
404
|
+
}
|
|
405
|
+
return { panel: 'retarget', summary: `Retarget ${animation} from ${reference}` };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (schema === APPLIED_ANIMATION_SCHEMA) {
|
|
409
|
+
const ops = Array.isArray(record.ops) ? record.ops : null;
|
|
410
|
+
if (!ops || !ops.length) return refuseDropStatement(`${APPLIED_ANIMATION_SCHEMA} has no ops`);
|
|
411
|
+
let parsedMotion: Record<string, unknown> | null = null;
|
|
412
|
+
if (typeof handoff?.animations?.text === 'string' && handoff.animations.text.trim()) {
|
|
413
|
+
try {
|
|
414
|
+
const doc = JSON.parse(handoff.animations.text);
|
|
415
|
+
if (isObject(doc) && isObject(doc.animations)) parsedMotion = doc.animations;
|
|
416
|
+
} catch {
|
|
417
|
+
parsedMotion = null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const items = ops.map((raw, i) => {
|
|
421
|
+
if (!isObject(raw) || typeof raw.op !== 'string' || typeof raw.animation !== 'string' || !raw.animation.trim()) {
|
|
422
|
+
return refuseDropStatement(`${APPLIED_ANIMATION_SCHEMA} ops[${i}] is missing op or animation`);
|
|
423
|
+
}
|
|
424
|
+
const animName = raw.animation.trim();
|
|
425
|
+
let bone = typeof raw.bone === 'string' && raw.bone.trim() ? raw.bone.trim() : '';
|
|
426
|
+
if (!bone && typeof raw.track === 'number' && parsedMotion) {
|
|
427
|
+
const animObj = parsedMotion[animName];
|
|
428
|
+
const tracks = isObject(animObj) && Array.isArray(animObj.tracks) ? animObj.tracks : null;
|
|
429
|
+
const tr = tracks?.[raw.track];
|
|
430
|
+
if (isObject(tr) && typeof tr.bone === 'string' && tr.bone.trim()) bone = tr.bone.trim();
|
|
431
|
+
}
|
|
432
|
+
return `${raw.op} ${animName}${bone ? ` ${bone}` : ''}`;
|
|
433
|
+
});
|
|
434
|
+
return { panel: 'animation', summary: `Animation ${summarizeList(items)}` };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return refuseDropStatement(`unknown stage record schema ${JSON.stringify(schema)}`);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* #250: plain-words statement shown beside `panel`'s Apply button before the click when the stage carries an applied
|
|
442
|
+
* edit from another panel (or another part on a per-part panel). Empty string when nothing will be dropped (including
|
|
443
|
+
* `panel`'s own second Apply). Refuses by name (`APPLIED_DROP_STATEMENT_UNAVAILABLE`) when the stage record cannot
|
|
444
|
+
* derive a statement.
|
|
445
|
+
*/
|
|
446
|
+
export function dropNoticeForPanel(
|
|
447
|
+
record: unknown,
|
|
448
|
+
panel: RebuildPanelKind,
|
|
449
|
+
options?: { part?: string | null; handoff?: RebuildHandoffContext | null },
|
|
450
|
+
): string {
|
|
451
|
+
if (!REBUILD_PANEL_KINDS.includes(panel)) {
|
|
452
|
+
return refuseDropStatement(`unknown panel kind ${JSON.stringify(panel)}`);
|
|
453
|
+
}
|
|
454
|
+
const owner = describeAppliedRecord(record, options?.handoff);
|
|
455
|
+
if (!owner) return '';
|
|
456
|
+
if (owner.panel === panel) {
|
|
457
|
+
const targetPart = typeof options?.part === 'string' && options.part.trim() ? options.part.trim() : null;
|
|
458
|
+
if (!targetPart || !owner.part || targetPart === owner.part) return '';
|
|
459
|
+
}
|
|
460
|
+
return `This rebuild starts from the handoff and drops: ${owner.summary}`;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export interface PanelStatusSnapshot {
|
|
464
|
+
text: string;
|
|
465
|
+
part?: string | null;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export interface RestoredPanelOutcome {
|
|
469
|
+
panel: RebuildPanelKind;
|
|
470
|
+
part?: string;
|
|
471
|
+
text: string;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* #250: whether `text` on `panel`'s status line claims an applied scratch build as the current stage state.
|
|
476
|
+
* In-panel preview lines (such as Animation's `Applied <op> on <anim> track <i > (<n> pending op(s), preview active).`)
|
|
477
|
+
* are not applied-build outcome lines and return false.
|
|
478
|
+
*/
|
|
479
|
+
export function isAppliedOutcomeStatus(panel: RebuildPanelKind, text: string): boolean {
|
|
480
|
+
const trimmed = text.trim();
|
|
481
|
+
if (!trimmed) return false;
|
|
482
|
+
switch (panel) {
|
|
483
|
+
case 'chest':
|
|
484
|
+
return (
|
|
485
|
+
(trimmed.startsWith('Applied ') &&
|
|
486
|
+
trimmed.includes(' with ') &&
|
|
487
|
+
trimmed.includes('Reset returns to the inspected build')) ||
|
|
488
|
+
trimmed.startsWith('Applied patch ')
|
|
489
|
+
);
|
|
490
|
+
case 'mesh-edit':
|
|
491
|
+
return trimmed.startsWith('Applied mesh edit ');
|
|
492
|
+
case 'mesh':
|
|
493
|
+
return trimmed.startsWith('Remeshed ') || trimmed.startsWith('Applied patch ');
|
|
494
|
+
case 'bones':
|
|
495
|
+
case 'rig-fields':
|
|
496
|
+
case 'cuts':
|
|
497
|
+
case 'cloth':
|
|
498
|
+
case 'physics':
|
|
499
|
+
case 'idle':
|
|
500
|
+
return trimmed.startsWith('Applied patch ');
|
|
501
|
+
case 'retarget':
|
|
502
|
+
return trimmed.startsWith('Retargeted ');
|
|
503
|
+
case 'animation':
|
|
504
|
+
return (
|
|
505
|
+
/^Applied [0-9a-f]{6,}…/.test(trimmed) ||
|
|
506
|
+
(trimmed.startsWith('Applied ') &&
|
|
507
|
+
trimmed.includes(' with ') &&
|
|
508
|
+
trimmed.includes('Reset returns to the inspected build'))
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* #250: return `{ panel, part? }` for the stage's applied record, or `null` when no known applied record is on the stage.
|
|
515
|
+
*/
|
|
516
|
+
export function appliedBuildOwner(record: unknown): { panel: RebuildPanelKind; part?: string } | null {
|
|
517
|
+
try {
|
|
518
|
+
const d = describeAppliedRecord(record);
|
|
519
|
+
return d ? { panel: d.panel, ...(d.part ? { part: d.part } : {}) } : null;
|
|
520
|
+
} catch {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* #250: reconcile every panel's status line against the record currently on the stage (`record`) and an optional
|
|
527
|
+
* restored build outcome (`restored`, supplied when Undo returns to an earlier applied build). Any non-owning panel
|
|
528
|
+
* whose status line still claims an applied build is cleared (`''`); non-applied status text (pre-checks, preview notes,
|
|
529
|
+
* errors) stays untouched; when Undo restores `panel`'s build, `restored.text` is restored onto `panel`.
|
|
530
|
+
*/
|
|
531
|
+
export function reconcilePanelStatuses(
|
|
532
|
+
current: Partial<Record<RebuildPanelKind, string | PanelStatusSnapshot>>,
|
|
533
|
+
record: unknown,
|
|
534
|
+
restored?: RestoredPanelOutcome | null,
|
|
535
|
+
): Record<RebuildPanelKind, string> {
|
|
536
|
+
const owner = appliedBuildOwner(record);
|
|
537
|
+
const out = {} as Record<RebuildPanelKind, string>;
|
|
538
|
+
for (const panel of REBUILD_PANEL_KINDS) {
|
|
539
|
+
const entry = current[panel];
|
|
540
|
+
const text = typeof entry === 'string' ? entry : (entry?.text ?? '');
|
|
541
|
+
const currentPart =
|
|
542
|
+
typeof entry === 'object' && entry !== null && typeof entry.part === 'string' && entry.part.trim()
|
|
543
|
+
? entry.part.trim()
|
|
544
|
+
: undefined;
|
|
545
|
+
const ownsStage =
|
|
546
|
+
owner !== null &&
|
|
547
|
+
owner.panel === panel &&
|
|
548
|
+
(restored?.panel === panel || owner.part === undefined || currentPart === undefined || owner.part === currentPart);
|
|
549
|
+
if (ownsStage) {
|
|
550
|
+
if (
|
|
551
|
+
restored &&
|
|
552
|
+
restored.panel === panel &&
|
|
553
|
+
(restored.part === undefined || currentPart === undefined || restored.part === currentPart)
|
|
554
|
+
) {
|
|
555
|
+
out[panel] = restored.text;
|
|
556
|
+
} else {
|
|
557
|
+
out[panel] = text;
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
out[panel] = isAppliedOutcomeStatus(panel, text) ? '' : text;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
@@ -234,6 +234,7 @@ export class AnimationInspectionPanel {
|
|
|
234
234
|
</div>
|
|
235
235
|
<div class="animation-dock-status">
|
|
236
236
|
<div class="animation-gate-banner hint" data-animation-gate></div>
|
|
237
|
+
<p class="hint rebuild-drop-notice" data-rebuild-drop="animation" hidden></p>
|
|
237
238
|
<p class="hint" data-animation-editor-status role="status"></p>
|
|
238
239
|
<p class="hint" data-animation-apply-note></p>
|
|
239
240
|
<p data-inspection-status class="hint"></p>
|
|
@@ -870,14 +871,23 @@ export class AnimationInspectionPanel {
|
|
|
870
871
|
* When another kind of Apply (Bones, Mesh, Idle, Retarget, Chest, etc.) replaces the stage build, `applied` is `null`
|
|
871
872
|
* and `this.appliedOps` clears to `[]` while `this.builder.ops` stays intact as pending unapplied edits.
|
|
872
873
|
*/
|
|
873
|
-
reconcileStageApplied(applied:AppliedAnimation|null){
|
|
874
|
+
reconcileStageApplied(applied:AppliedAnimation|null,restoredOutcome?:{text:string;error:boolean}|null){
|
|
874
875
|
const nextApplied=applied?applied.ops.map(o=>structuredClone(o)):[];
|
|
875
|
-
if(JSON.stringify(this.appliedOps)
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
876
|
+
if(JSON.stringify(this.appliedOps)!==JSON.stringify(nextApplied)){
|
|
877
|
+
this.appliedOps=nextApplied;
|
|
878
|
+
this.syncEffectiveInspection(true);
|
|
879
|
+
this.renderEditorBar();
|
|
880
|
+
this.renderTimeline();
|
|
881
|
+
this.renderChannels();
|
|
882
|
+
}
|
|
883
|
+
const curStatus=(this.editorStatus.textContent??'').trim();
|
|
884
|
+
if(applied){
|
|
885
|
+
if(restoredOutcome){
|
|
886
|
+
this.setEditorStatus(restoredOutcome.text,restoredOutcome.error);
|
|
887
|
+
}
|
|
888
|
+
}else if(/^Applied [0-9a-f]{6,}…/.test(curStatus)||(curStatus.startsWith('Applied ')&&curStatus.includes(' with ')&&curStatus.includes('Reset returns to the inspected build'))){
|
|
889
|
+
this.setEditorStatus('',false);
|
|
890
|
+
}
|
|
881
891
|
}
|
|
882
892
|
|
|
883
893
|
syncApplied(applied:AppliedAnimation|null){
|
package/web/chest-editor.ts
CHANGED
|
@@ -164,6 +164,8 @@ export interface ChestEditor {active:()=>boolean;flashing:(side:BustSide)=>boole
|
|
|
164
164
|
armed:()=>LandmarkKey|null;
|
|
165
165
|
/** Hold a status line (null clears it); `log` is the producer's latest lines. */
|
|
166
166
|
notify:(text:string|null,error?:boolean,log?:readonly string[])=>void;
|
|
167
|
+
/** The current notice text (empty string when none). */
|
|
168
|
+
noticeText:()=>string;
|
|
167
169
|
/** Apply is disabled while a rebuild runs; Reset is enabled while a rebuilt build is on the stage. */
|
|
168
170
|
rebuildState:(state:{busy:boolean;applied:boolean})=>void}
|
|
169
171
|
|
|
@@ -288,6 +290,7 @@ export function bindChestEditor(host:ChestEditorHost):ChestEditor {
|
|
|
288
290
|
return {
|
|
289
291
|
active:()=>active,flashing:side=>flash.has(side),sync,mode,landmarks:()=>readLandmarks(read),armed:()=>{const l=readLandmarks(read);return nextLandmark(armed,'missing' in l?l.missing:[]);},
|
|
290
292
|
notify:(text,error=false,lines)=>{notice=text===null?null:{text,error};if(lines){log.textContent=lines.join('\n');log.hidden=!lines.length;log.scrollTop=log.scrollHeight;}sync();},
|
|
293
|
+
noticeText:()=>notice?.text??'',
|
|
291
294
|
rebuildState:({busy,applied})=>{apply.disabled=busy;apply.setAttribute('aria-busy',String(busy));reset.disabled=busy||!applied;},
|
|
292
295
|
dispose:()=>{observer.disconnect();if(flashTimer)clearTimeout(flashTimer);host.pane.removeEventListener('pointerdown',down,true);host.pane.removeEventListener('pointermove',move,true);for(const type of ['pointerup','pointercancel','lostpointercapture'] as const)host.pane.removeEventListener(type,end,true);document.removeEventListener('keydown',keyDown,true);window.removeEventListener('keyup',keyUp,true);window.removeEventListener('blur',blur);},
|
|
293
296
|
};
|