@rig-c/review 0.21.0 → 0.22.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.
@@ -11,7 +11,8 @@
11
11
  import type { BoneAdjust, ModelAssets, RigPlayer } from '@rig-c/play';
12
12
  import type { CompareResponse } from '../src/compare.ts';
13
13
  import type { CommentMode } from '../src/stage-comment.ts';
14
- import { AnimationInspectionPanel } from './animation-inspection.ts';
14
+ import { AnimationInspectionPanel, type AnimationSideState } from './animation-inspection.ts';
15
+ import type { AnimationSourceOp } from '../src/animation-ops.ts';
15
16
  import { partBounds, type PartExplorer } from './part-selection.ts';
16
17
  import { bindInspectorBlocks, activeBlocksUI, restoreActiveBlocksUI, type InspectorBlocks } from './inspector-blocks.ts';
17
18
  import { bindChestEditor, canvasToCrop, bustLabel, bustSides, LANDMARKS, landmarkInputId, rowCircle, type ChestEditor, type LandmarkKey } from './chest-editor.ts';
@@ -41,10 +42,10 @@ import { bindRetargetPanel, type PoseMap, type RetargetPanel } from './retarget-
41
42
  import type { RetargetFlags } from '../src/retarget.ts';
42
43
  import {
43
44
  historyRow, isPatchJob, recordFor, refusedText, retargetStage, undoControl,
44
- appliedRecord, deltaAppliedRecord, deltaOutcomeLine, designatedRegions, handoffText,
45
+ animationAppliedRecord, animationOutcomeLine, appliedRecord, deltaAppliedRecord, deltaOutcomeLine, designatedRegions, handoffText,
45
46
  landmarksRequest, seedLandmarks, makePatch, outcomeLine, patchAppliedRecord, patchOutcomeLine,
46
47
  pickPart, runRebuild, seedFields, stageModel, retargetAppliedRecord, retargetOutcomeLine, stripPendingAfter,
47
- type AppliedHistoryView, type UndoView, type AnyJobView, type AppliedAnimation, type AppliedDelta, type AppliedPatch,
48
+ type AnimationJobView, type AnimationRequestBody, type AppliedHistoryView, type UndoView, type AnyJobView, type AppliedAnimation, type AppliedDelta, type AppliedPatch,
48
49
  type AppliedRecord, type AppliedRetarget, type DeltaJobView, type DeltaRequestBody, type ConfigPatch,
49
50
  type PatchJobView, type RebuildJobView, type RebuildRefusal, type RebuildRequestBody, type RebuildStatusView,
50
51
  type RetargetJobView, type RetargetRequestBody, type StageChange,
@@ -101,6 +102,8 @@ interface SideBuildState {
101
102
  readingsJob: ReadingsJobView | null;
102
103
  requirementsCatalog: RequirementsCatalogView | null;
103
104
  lastOverlay: OverlaySnapshot | null;
105
+ animationState: AnimationSideState | null;
106
+ animAdjust: BoneAdjust | null;
104
107
  }
105
108
 
106
109
  function emptySideState(): SideBuildState {
@@ -123,6 +126,8 @@ function emptySideState(): SideBuildState {
123
126
  readingsJob: null,
124
127
  requirementsCatalog: null,
125
128
  lastOverlay: null,
129
+ animationState: null,
130
+ animAdjust: null,
126
131
  };
127
132
  }
128
133
 
@@ -406,11 +411,15 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
406
411
  const player = host.players[side];
407
412
  if (!player) return;
408
413
  const baseTurn = host.turnAdjustFor(side);
409
- player.adjust = side === pickedSide ? composeAdjust(baseTurn, composeAdjust(idleAdjust, dialAdjust)) : baseTurn;
414
+ const activeTools = side === pickedSide ? composeAdjust(idleAdjust, dialAdjust) : null;
415
+ player.adjust = composeAdjust(composeAdjust(baseTurn, activeTools), sides[side].animAdjust);
410
416
  if (player.current && !host.playing()) {
411
- player.repose();
417
+ player.seek(host.time());
412
418
  player.draw();
413
419
  host.parts()?.present(side);
420
+ if (side === pickedSide && sides[side].partModel) {
421
+ animationPanel?.capture(player, host.parts()?.frame(side));
422
+ }
414
423
  host.redrawOverlays(true);
415
424
  }
416
425
  }
@@ -467,6 +476,9 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
467
476
  if (sides[prevSide].chestInputs !== null) {
468
477
  sides[prevSide].chestInputs = snapshotChestInputs();
469
478
  }
479
+ if (animationPanel) {
480
+ sides[prevSide].animationState = animationPanel.exportSideState();
481
+ }
470
482
  physicsPanel?.clearPreview();
471
483
  idleAdjust = null;
472
484
  dialAdjust = null;
@@ -484,12 +496,6 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
484
496
  steppedLive = false;
485
497
  if (workspaceMode !== 'compare') host.syncFeedbackSide(pickedSide);
486
498
  applyEnvironment();
487
- const nextPlayer = currentPlayer();
488
- if (nextPlayer?.current && !host.playing()) {
489
- nextPlayer.repose();
490
- nextPlayer.draw();
491
- host.parts()?.present(pickedSide);
492
- }
493
499
  syncPickedBanner();
494
500
  moveStageHandlesToPickedSide();
495
501
  const currentPart = host.parts()?.value();
@@ -508,13 +514,23 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
508
514
  }
509
515
  switchingSide = true;
510
516
  try {
517
+ const nextAnimState = sides[nextSide].animationState;
518
+ if (nextAnimState && sides[nextSide].partModel && nextAnimState.document !== sides[nextSide].partModel) {
519
+ nextAnimState.document = null;
520
+ nextAnimState.baseInspection = null;
521
+ }
522
+ animationPanel?.importSideState(nextAnimState);
511
523
  clearChestInputs();
512
524
  populateChestBones();
513
525
  applySideStateToPanels();
514
526
  updateChestMapping();
527
+ if (animationPanel) {
528
+ sides[nextSide].animationState = animationPanel.exportSideState();
529
+ }
515
530
  } finally {
516
531
  switchingSide = false;
517
532
  }
533
+ setAdjust(nextSide);
518
534
  host.redrawOverlays(true);
519
535
  host.saveDraft();
520
536
  }
@@ -1110,7 +1126,11 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1110
1126
 
1111
1127
  async function swapPickedSide(side: Side, modelUrl: string, prefix: string, sha256: string, clipName?: string): Promise<void> {
1112
1128
  await host.swapSideRig(side, modelUrl, prefix, sha256, clipName);
1129
+ setAdjust(side);
1113
1130
  applyEnvironment();
1131
+ if (side === pickedSide) {
1132
+ refreshAnimationInspection();
1133
+ }
1114
1134
  }
1115
1135
 
1116
1136
  async function applyRebuild(): Promise<void> {
@@ -1121,60 +1141,72 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1121
1141
  const status = state.rebuildStatus ?? await loadRebuildStatus(side);
1122
1142
  if (!status || !status.available || !status.inputs) {
1123
1143
  const reason = status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE';
1124
- chestEditor?.notify(reason, true, [reason]); host.message(reason, true); return;
1144
+ if (pickedSide === side) chestEditor?.notify(reason, true, [reason]);
1145
+ host.message(reason, true);
1146
+ return;
1125
1147
  }
1126
1148
  let part: string, body: RebuildRequestBody;
1127
1149
  const lines: string[] = [];
1128
1150
  if (chestEditor?.mode() === 'landmarks') {
1129
1151
  const request = landmarksRequest(status, chestEditor.landmarks());
1130
- if ('error' in request) { chestEditor.notify(request.error, true, [request.error]); host.message(request.error, true); return; }
1152
+ if ('error' in request) {
1153
+ if (pickedSide === side) chestEditor.notify(request.error, true, [request.error]);
1154
+ host.message(request.error, true);
1155
+ return;
1156
+ }
1131
1157
  ({ part, body } = request);
1132
1158
  } else {
1133
1159
  const designated = designatedRegions(chestField);
1134
- if ('error' in designated) { chestEditor?.notify(designated.error, true); return; }
1160
+ if ('error' in designated) { if (pickedSide === side) chestEditor?.notify(designated.error, true); return; }
1135
1161
  const picked = pickPart(status, designated.regions);
1136
- if (!picked) { chestEditor?.notify(`REBUILD_PART_AMBIGUOUS: the config states ${status.parts.length} contour meshes and the designated bones name none of them alone`, true); return; }
1162
+ if (!picked) { if (pickedSide === side) chestEditor?.notify(`REBUILD_PART_AMBIGUOUS: the config states ${status.parts.length} contour meshes and the designated bones name none of them alone`, true); return; }
1137
1163
  part = picked; body = { part, regions: designated.regions, configHash: status.inputs.configHash };
1138
1164
  }
1139
1165
  rebuildBusy = true; rebuildState();
1140
- chestEditor?.notify(`Rebuilding ${part} on Build ${side.toUpperCase()} with ${status.producer?.package} ${status.producer?.version}…`, false, []);
1166
+ if (pickedSide === side) chestEditor?.notify(`Rebuilding ${part} on Build ${side.toUpperCase()} with ${status.producer?.package} ${status.producer?.version}…`, false, []);
1141
1167
  try {
1142
1168
  const result = await runRebuild(body, {
1143
1169
  post: value => host.api<RebuildJobView | RebuildRefusal>(`${sideApiPrefix(side)}/rebuild`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }),
1144
1170
  get: id => host.api<RebuildJobView>(`${sideApiPrefix(side)}/rebuild/${id}`),
1145
1171
  sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
1146
- onLine: line => { lines.push(line); chestEditor?.notify(line.trim() || '…', false, lines.slice(-6)); },
1172
+ onLine: line => { lines.push(line); if (pickedSide === side) chestEditor?.notify(line.trim() || '…', false, lines.slice(-6)); },
1147
1173
  });
1148
1174
  const outcome = outcomeLine(result);
1149
1175
  if (!('id' in result) || result.status !== 'built' || !result.build) {
1150
- chestEditor?.notify(outcome.text, true, [...lines.slice(-5), outcome.text]);
1176
+ if (pickedSide === side) chestEditor?.notify(outcome.text, true, [...lines.slice(-5), outcome.text]);
1151
1177
  host.message(outcome.text, true);
1152
1178
  return;
1153
1179
  }
1154
1180
  await swapPickedSide(side, new URL(host.route(result.build.modelUrl), location.href).href, host.route(`/compare-rebuild/${side}/${result.id}/`), result.build.modelHash);
1155
1181
  state.appliedOnStage = appliedRecord(result); state.stageCheck = null; stageChanged(side, { kind: 'apply', via: 'regions' });
1156
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1157
- chestEditor?.notify(outcome.text, false, []); host.message(outcome.text);
1182
+ if (pickedSide === side) {
1183
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1184
+ chestEditor?.notify(outcome.text, false, []);
1185
+ } else if (state.animationState) {
1186
+ state.animationState.appliedOps = [];
1187
+ }
1188
+ host.message(outcome.text);
1158
1189
  } catch (error) {
1159
- chestEditor?.notify(`REBUILD_FAILED: ${errorText(error)}`, true);
1190
+ if (pickedSide === side) chestEditor?.notify(`REBUILD_FAILED: ${errorText(error)}`, true);
1160
1191
  host.message(`REBUILD_FAILED: ${errorText(error)}`, true);
1161
1192
  } finally {
1162
1193
  rebuildBusy = false; rebuildState();
1163
1194
  }
1164
1195
  }
1165
1196
 
1166
- async function applyPatch(patch: ConfigPatch, _world: StageWorld | null = null): Promise<PatchJobView | RebuildRefusal> {
1197
+ async function applyPatch(patch: ConfigPatch, _world: StageWorld | null = null, side: Side = pickedSide): Promise<PatchJobView | RebuildRefusal> {
1167
1198
  if (rebuildBusy) return { status: 'refused', error: 'REBUILD_BUSY: an Apply is still running', producerLine: null };
1168
1199
  const ro = host.readOnly();
1169
- if (ro) { chestEditor?.notify(ro, true); return { status: 'refused', error: ro, producerLine: null }; }
1170
- const side = pickedSide, state = sides[side];
1200
+ if (ro) { if (pickedSide === side) chestEditor?.notify(ro, true); return { status: 'refused', error: ro, producerLine: null }; }
1201
+ const state = sides[side];
1171
1202
  const lines: string[] = [];
1172
1203
  rebuildBusy = true; rebuildState();
1173
- chestEditor?.notify(`Applying patch on Build ${side.toUpperCase()} (${patch.op.cmd}, ${patch.ops.length} op(s))…`, false, []);
1204
+ if (pickedSide === side) chestEditor?.notify(`Applying patch on Build ${side.toUpperCase()} (${patch.op.cmd}, ${patch.ops.length} op(s))…`, false, []);
1174
1205
  try {
1175
1206
  const scheduled = useWorld() ? worldFor(checkAnimation(side), side) : null;
1176
1207
  if (scheduled && 'error' in scheduled) {
1177
- chestEditor?.notify(scheduled.error, true); host.message(scheduled.error, true);
1208
+ if (pickedSide === side) chestEditor?.notify(scheduled.error, true);
1209
+ host.message(scheduled.error, true);
1178
1210
  return { status: 'refused', error: scheduled.error, producerLine: scheduled.error };
1179
1211
  }
1180
1212
  const result = await runRebuild<{ patch: ConfigPatch; environment?: WorldExport['schedule'] }, PatchJobView>(
@@ -1183,12 +1215,12 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1183
1215
  post: value => host.api<PatchJobView | RebuildRefusal>(`${sideApiPrefix(side)}/rebuild`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }),
1184
1216
  get: id => host.api<PatchJobView>(`${sideApiPrefix(side)}/rebuild/${id}`),
1185
1217
  sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
1186
- onLine: line => { lines.push(line); chestEditor?.notify(line.trim() || '…', false, lines.slice(-6)); },
1218
+ onLine: line => { lines.push(line); if (pickedSide === side) chestEditor?.notify(line.trim() || '…', false, lines.slice(-6)); },
1187
1219
  },
1188
1220
  );
1189
1221
  const outcome = patchOutcomeLine(result), next = stageModel(result, { url: '', hash: state.stageModelHash ?? '' });
1190
1222
  if (next.id === null || !('id' in result)) {
1191
- chestEditor?.notify(outcome.text, true, [...lines.slice(-5), outcome.text]);
1223
+ if (pickedSide === side) chestEditor?.notify(outcome.text, true, [...lines.slice(-5), outcome.text]);
1192
1224
  host.message(outcome.text, true);
1193
1225
  return result;
1194
1226
  }
@@ -1196,12 +1228,18 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1196
1228
  state.appliedOnStage = patchAppliedRecord(result);
1197
1229
  state.stageCheck = { lines: [...result.lines], check: result.check };
1198
1230
  stageChanged(side, { kind: 'apply', via: 'patch' });
1199
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1200
- chestEditor?.notify(outcome.text, outcome.error, []); host.message(outcome.text, outcome.error);
1231
+ if (pickedSide === side) {
1232
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1233
+ chestEditor?.notify(outcome.text, outcome.error, []);
1234
+ } else if (state.animationState) {
1235
+ state.animationState.appliedOps = [];
1236
+ }
1237
+ host.message(outcome.text, outcome.error);
1201
1238
  return result;
1202
1239
  } catch (error) {
1203
1240
  const textMsg = `REBUILD_FAILED: ${errorText(error)}`;
1204
- chestEditor?.notify(textMsg, true); host.message(textMsg, true);
1241
+ if (pickedSide === side) chestEditor?.notify(textMsg, true);
1242
+ host.message(textMsg, true);
1205
1243
  return { status: 'refused', error: textMsg, producerLine: null };
1206
1244
  } finally {
1207
1245
  rebuildBusy = false; rebuildState();
@@ -1222,13 +1260,17 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1222
1260
  post: value => host.api<DeltaJobView | RebuildRefusal>(`${sideApiPrefix(side)}/rebuild`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }),
1223
1261
  get: id => host.api<DeltaJobView>(`${sideApiPrefix(side)}/rebuild/${id}`),
1224
1262
  sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
1225
- onLine: textLine => line(textLine),
1263
+ onLine: textLine => { if (pickedSide === side) line(textLine); },
1226
1264
  });
1227
1265
  const outcome = deltaOutcomeLine(result), next = stageModel(result, { url: '', hash: state.stageModelHash ?? '' });
1228
1266
  if (next.id === null || !('id' in result)) { host.message(outcome.text, true); return { built: false, text: outcome.text, error: true }; }
1229
1267
  await swapPickedSide(side, new URL(host.route(next.url), location.href).href, host.route(`/compare-rebuild/${side}/${next.id}/`), next.hash);
1230
1268
  state.appliedOnStage = deltaAppliedRecord(result); state.stageCheck = null; stageChanged(side, { kind: 'apply', via: 'delta' });
1231
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1269
+ if (pickedSide === side) {
1270
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1271
+ } else if (state.animationState) {
1272
+ state.animationState.appliedOps = [];
1273
+ }
1232
1274
  host.message(outcome.text);
1233
1275
  return { built: true, text: outcome.text, error: false };
1234
1276
  } catch (error) {
@@ -1245,44 +1287,62 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1245
1287
  if (ro) { retargetPanel?.status(ro, true); return null; }
1246
1288
  const side = pickedSide, state = sides[side];
1247
1289
  const status = state.rebuildStatus ?? await loadRebuildStatus(side);
1248
- if (!status?.inputs) { retargetPanel?.status(status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE', true); return null; }
1290
+ if (!status?.inputs) { if (pickedSide === side) retargetPanel?.status(status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE', true); return null; }
1249
1291
  const request: RetargetRequestBody = { retarget: { ...body, configHash: status.inputs.configHash } };
1250
- rebuildBusy = true; rebuildState(); retargetPanel?.busy(true); retargetPanel?.result(null);
1251
- retargetPanel?.status(`Retargeting ${body.sequence} as "${body.flags.animation}" on Build ${side.toUpperCase()}…`, false);
1292
+ rebuildBusy = true; rebuildState();
1293
+ if (pickedSide === side) {
1294
+ retargetPanel?.busy(true); retargetPanel?.result(null);
1295
+ retargetPanel?.status(`Retargeting ${body.sequence} as "${body.flags.animation}" on Build ${side.toUpperCase()}…`, false);
1296
+ }
1252
1297
  try {
1253
1298
  const result = await runRebuild<RetargetRequestBody, RetargetJobView>(request, {
1254
1299
  post: value => host.api<RetargetJobView | RebuildRefusal>(`${sideApiPrefix(side)}/rebuild`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }),
1255
1300
  get: id => host.api<RetargetJobView>(`${sideApiPrefix(side)}/rebuild/${id}`),
1256
1301
  sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
1257
- onLine: textLine => retargetPanel?.line(textLine),
1302
+ onLine: textLine => { if (pickedSide === side) retargetPanel?.line(textLine); },
1258
1303
  });
1259
1304
  const outcome = retargetOutcomeLine(result), next = stageModel(result, { url: '', hash: state.stageModelHash ?? '' });
1260
- retargetPanel?.result(result); retargetPanel?.status(outcome.text, outcome.error);
1305
+ if (pickedSide === side) {
1306
+ retargetPanel?.result(result); retargetPanel?.status(outcome.text, outcome.error);
1307
+ }
1261
1308
  if (next.id === null || !('id' in result)) { host.message(outcome.text, true); return result; }
1262
1309
  await swapPickedSide(side, new URL(host.route(next.url), location.href).href, host.route(`/compare-rebuild/${side}/${next.id}/`), next.hash, result.request.record.flags.animation);
1263
1310
  state.appliedOnStage = retargetAppliedRecord(result); state.stageCheck = null; stageChanged(side, { kind: 'apply', via: 'retarget' });
1264
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1311
+ if (pickedSide === side) {
1312
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = JSON.stringify(state.appliedOnStage); draft.dispatchEvent(new Event('input', { bubbles: true }));
1313
+ } else if (state.animationState) {
1314
+ state.animationState.appliedOps = [];
1315
+ }
1265
1316
  host.message(outcome.text, outcome.error);
1266
1317
  return result;
1267
1318
  } catch (error) {
1268
- const textMsg = `REBUILD_FAILED: ${errorText(error)}`; retargetPanel?.status(textMsg, true); host.message(textMsg, true);
1319
+ const textMsg = `REBUILD_FAILED: ${errorText(error)}`;
1320
+ if (pickedSide === side) retargetPanel?.status(textMsg, true);
1321
+ host.message(textMsg, true);
1269
1322
  return { status: 'refused', error: textMsg, producerLine: null };
1270
1323
  } finally {
1271
1324
  rebuildBusy = false; rebuildState(); retargetPanel?.busy(false);
1272
1325
  }
1273
1326
  }
1274
1327
 
1275
- async function resetRebuild(_world: StageWorld | null = null): Promise<void> {
1276
- const side = pickedSide, state = sides[side];
1328
+ async function resetRebuild(_world: StageWorld | null = null, side: Side = pickedSide): Promise<void> {
1329
+ const state = sides[side];
1277
1330
  if (rebuildBusy || (!state.appliedOnStage && !state.stripPending) || !state.inspectedModel) return;
1278
1331
  rebuildBusy = true; rebuildState();
1279
1332
  try {
1280
1333
  await swapPickedSide(side, state.inspectedModel.url, state.inspectedModel.prefix, state.inspectedModel.sha256);
1281
1334
  state.appliedOnStage = null; state.stageCheck = null; stageChanged(side, { kind: 'reset' });
1282
- chestEditor?.notify(`Reset: Build ${side.toUpperCase()} is back on its inspected build.`, false);
1335
+ if (pickedSide === side) {
1336
+ animationPanel?.reconcileStageApplied(null);
1337
+ if (animationPanel) state.animationState = animationPanel.exportSideState();
1338
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1339
+ chestEditor?.notify(`Reset: Build ${side.toUpperCase()} is back on its inspected build.`, false);
1340
+ } else if (state.animationState) {
1341
+ state.animationState.appliedOps = [];
1342
+ }
1283
1343
  host.message(`Reset Build ${side.toUpperCase()} to its inspected build.`);
1284
1344
  } catch (error) {
1285
- chestEditor?.notify(`REBUILD_RESET_FAILED: ${errorText(error)}`, true);
1345
+ if (pickedSide === side) chestEditor?.notify(`REBUILD_RESET_FAILED: ${errorText(error)}`, true);
1286
1346
  } finally {
1287
1347
  rebuildBusy = false; rebuildState();
1288
1348
  }
@@ -1304,15 +1364,23 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1304
1364
  while (job.status === 'running') {
1305
1365
  await new Promise(resolve => setTimeout(resolve, 700));
1306
1366
  job = await host.api<AnyJobView>(`${sideApiPrefix(side)}/rebuild/${job.id}`);
1307
- for (; seen < job.lines.length; seen++) appliedStatus(job.lines[seen]!.trim() || '…');
1367
+ if (pickedSide === side) {
1368
+ for (; seen < job.lines.length; seen++) appliedStatus(job.lines[seen]!.trim() || '…');
1369
+ }
1308
1370
  }
1309
1371
  if (job.status !== 'built') {
1310
- const textMsg = refusedText(job); appliedStatus(textMsg, true); host.message(textMsg, true);
1372
+ const textMsg = refusedText(job);
1373
+ if (pickedSide === side) appliedStatus(textMsg, true);
1374
+ host.message(textMsg, true);
1311
1375
  return { status: 'refused', error: textMsg, producerLine: job.producerLine };
1312
1376
  }
1313
1377
  result = { status: 'built', undone, job, history: await host.api<AppliedHistoryView>(`${sideApiPrefix(side)}/rebuild/history`) };
1314
1378
  }
1315
- if (result.status === 'refused') { appliedStatus(result.error, true); host.message(result.error, true); return result; }
1379
+ if (result.status === 'refused') {
1380
+ if (pickedSide === side) appliedStatus(result.error, true);
1381
+ host.message(result.error, true);
1382
+ return result;
1383
+ }
1316
1384
  let ops: PatchOp[] | null = null;
1317
1385
  if (result.status === 'inspected') {
1318
1386
  await swapPickedSide(side, state.inspectedModel.url, state.inspectedModel.prefix, state.inspectedModel.sha256);
@@ -1325,16 +1393,27 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1325
1393
  if ((job as PatchJobView).kind === 'patch') ops = (job as PatchJobView).request.patch.ops;
1326
1394
  }
1327
1395
  stageChanged(side, { kind: 'undo' });
1328
- physicsPanel?.applied(ops); idlePanel?.applied(ops); rigFieldsPanel?.applied(ops); bonesPanel?.applied(ops);
1329
- const restored = result.status === 'built' && isPatchJob(result.job) ? result.job : null, block = recordBlock(state.appliedOnStage);
1330
- cutsPanel?.shown(block === 'cuts' ? restored : null); clothPanel?.shown(block === 'cloth' ? restored : null);
1331
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = state.appliedOnStage ? JSON.stringify(state.appliedOnStage) : ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1332
1396
  state.appliedHistory = result.history;
1333
1397
  const textMsg = `Undid ${result.undone.slice(0, 12)}… on Build ${side.toUpperCase()} · ${result.history.depth} applied record(s) left`;
1334
- appliedStatus(textMsg); host.message(textMsg); host.redrawOverlays(true);
1398
+ if (pickedSide === side) {
1399
+ physicsPanel?.applied(ops); idlePanel?.applied(ops); rigFieldsPanel?.applied(ops); bonesPanel?.applied(ops);
1400
+ animationPanel?.reconcileStageApplied(state.appliedOnStage?.schema === 'rig-review-applied/5' ? state.appliedOnStage : null);
1401
+ if (animationPanel) state.animationState = animationPanel.exportSideState();
1402
+ const restored = result.status === 'built' && isPatchJob(result.job) ? result.job : null, block = recordBlock(state.appliedOnStage);
1403
+ cutsPanel?.shown(block === 'cuts' ? restored : null); clothPanel?.shown(block === 'cloth' ? restored : null);
1404
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = state.appliedOnStage ? JSON.stringify(state.appliedOnStage) : ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1405
+ appliedStatus(textMsg);
1406
+ } else if (state.animationState) {
1407
+ state.animationState.appliedOps = state.appliedOnStage?.schema === 'rig-review-applied/5'
1408
+ ? state.appliedOnStage.ops.map(o => structuredClone(o))
1409
+ : [];
1410
+ }
1411
+ host.message(textMsg); host.redrawOverlays(true);
1335
1412
  return result;
1336
1413
  } catch (error) {
1337
- const textMsg = `UNDO_FAILED: ${errorText(error)}`; appliedStatus(textMsg, true); host.message(textMsg, true);
1414
+ const textMsg = `UNDO_FAILED: ${errorText(error)}`;
1415
+ if (pickedSide === side) appliedStatus(textMsg, true);
1416
+ host.message(textMsg, true);
1338
1417
  return { status: 'refused', error: textMsg, producerLine: null };
1339
1418
  } finally {
1340
1419
  rebuildBusy = false; rebuildState();
@@ -1359,17 +1438,18 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1359
1438
  const side = pickedSide, state = sides[side];
1360
1439
  const status = state.rebuildStatus ?? await loadRebuildStatus(side);
1361
1440
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig' }) : null;
1362
- if (!patch) { const reason = !ops.length ? 'PHYSICS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; physicsPanel?.status(reason, true); return null; }
1363
- physicsPanel?.clearPreview();
1441
+ if (!patch) { const reason = !ops.length ? 'PHYSICS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) physicsPanel?.status(reason, true); return null; }
1442
+ if (pickedSide === side) physicsPanel?.clearPreview();
1364
1443
  const world = stageWorld(), before = state.stageCheck;
1365
- physicsPanel?.busy(true); physicsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1444
+ if (pickedSide === side) { physicsPanel?.busy(true); physicsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1366
1445
  try {
1367
- const result = await applyPatch(patch, world);
1368
- const outcome = patchOutcomeLine(result); physicsPanel?.status(outcome.text, outcome.error);
1446
+ const result = await applyPatch(patch, world, side);
1447
+ const outcome = patchOutcomeLine(result);
1448
+ if (pickedSide === side) physicsPanel?.status(outcome.text, outcome.error);
1369
1449
  if ('id' in result && result.status === 'built') {
1370
- physicsPanel?.applied(result.request.patch.ops);
1450
+ if (pickedSide === side) physicsPanel?.applied(result.request.patch.ops);
1371
1451
  const after = { lines: [...result.lines], check: result.check };
1372
- const show = () => physicsPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after));
1452
+ const show = () => { if (pickedSide === side) physicsPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after)); };
1373
1453
  show(); if (!before) void followInspectedCheck(show, side);
1374
1454
  }
1375
1455
  return result;
@@ -1377,25 +1457,27 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1377
1457
  }
1378
1458
 
1379
1459
  async function resetPhysicsBuild(): Promise<void> {
1460
+ const side = pickedSide, state = sides[side];
1380
1461
  physicsPanel?.clear(); physicsPanel?.applied(null); physicsPanel?.readout([]);
1381
- if (currentState().appliedOnStage) { physicsPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { physicsPanel?.busy(false); } }
1382
- physicsPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1462
+ if (state.appliedOnStage) { physicsPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { physicsPanel?.busy(false); } }
1463
+ if (pickedSide === side) physicsPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1383
1464
  }
1384
1465
 
1385
1466
  async function applyIdle(ops: PatchOp[], keys: 'ctl' | 'direct' | null): Promise<PatchJobView | RebuildRefusal | null> {
1386
1467
  const side = pickedSide, state = sides[side];
1387
1468
  const status = state.rebuildStatus ?? await loadRebuildStatus(side);
1388
1469
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig', args: keys ? ['--idle-keys', keys] : [] }) : null;
1389
- if (!patch) { const reason = !ops.length ? 'IDLE_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; idlePanel?.status(reason, true); return null; }
1470
+ if (!patch) { const reason = !ops.length ? 'IDLE_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) idlePanel?.status(reason, true); return null; }
1390
1471
  const world = stageWorld(), before = state.stageCheck;
1391
- idlePanel?.busy(true); idlePanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1472
+ if (pickedSide === side) { idlePanel?.busy(true); idlePanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1392
1473
  try {
1393
- const result = await applyPatch(patch, world);
1394
- const outcome = patchOutcomeLine(result); idlePanel?.status(outcome.text, outcome.error);
1474
+ const result = await applyPatch(patch, world, side);
1475
+ const outcome = patchOutcomeLine(result);
1476
+ if (pickedSide === side) idlePanel?.status(outcome.text, outcome.error);
1395
1477
  if ('id' in result && result.status === 'built') {
1396
- idlePanel?.applied(result.request.patch.ops);
1478
+ if (pickedSide === side) idlePanel?.applied(result.request.patch.ops);
1397
1479
  const after = { lines: [...result.lines], check: result.check };
1398
- const show = () => idlePanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, IDLE_READOUT_BARS));
1480
+ const show = () => { if (pickedSide === side) idlePanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, IDLE_READOUT_BARS)); };
1399
1481
  show(); if (!before) void followInspectedCheck(show, side);
1400
1482
  }
1401
1483
  return result;
@@ -1403,9 +1485,122 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1403
1485
  }
1404
1486
 
1405
1487
  async function resetIdleBuild(): Promise<void> {
1488
+ const side = pickedSide, state = sides[side];
1406
1489
  idlePanel?.clear(); idlePanel?.applied(null); idlePanel?.readout([]);
1407
- if (currentState().appliedOnStage) { idlePanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { idlePanel?.busy(false); } }
1408
- idlePanel?.status('Reset: the inspected build is on the stage; no pending ops; the preview is cleared.', false);
1490
+ if (state.appliedOnStage) { idlePanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { idlePanel?.busy(false); } }
1491
+ if (pickedSide === side) idlePanel?.status('Reset: the inspected build is on the stage; no pending ops; the preview is cleared.', false);
1492
+ }
1493
+
1494
+ async function applyAnimation(ops: readonly AnimationSourceOp[]): Promise<AnimationJobView | RebuildRefusal | null> {
1495
+ if (rebuildBusy) { animationPanel?.setEditorStatus('REBUILD_BUSY: an Apply is still running', true); return null; }
1496
+ const ro = host.readOnly();
1497
+ if (ro) { animationPanel?.setEditorStatus(ro, true); return null; }
1498
+ if (!ops.length) { animationPanel?.setEditorStatus('ANIMATION_OPS_EMPTY: no pending animation ops to apply', true); return null; }
1499
+ const side = pickedSide, state = sides[side];
1500
+ const status = state.rebuildStatus ?? await loadRebuildStatus(side);
1501
+ if (!status?.inputs) {
1502
+ const r = status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE';
1503
+ if (pickedSide === side) animationPanel?.setEditorStatus(r, true);
1504
+ return null;
1505
+ }
1506
+ const animSource = status.animations;
1507
+ if (!animSource?.available || !animSource.sha256) {
1508
+ const r = animSource?.reason ?? 'ANIMATION_SOURCE_MISSING: config.json does not declare an "animations_from" motion spec file.';
1509
+ if (pickedSide === side) animationPanel?.setEditorStatus(r, true);
1510
+ return null;
1511
+ }
1512
+ const scheduled = useWorld() ? worldFor(checkAnimation(side), side) : null;
1513
+ if (scheduled && 'error' in scheduled) {
1514
+ if (pickedSide === side) animationPanel?.setEditorStatus(scheduled.error, true);
1515
+ host.message(scheduled.error, true);
1516
+ return { status: 'refused', error: scheduled.error, producerLine: scheduled.error };
1517
+ }
1518
+ const keying = status.idle?.keying, keys = keying && 'keys' in keying ? keying.keys : null;
1519
+ const request: AnimationRequestBody = {
1520
+ animation: {
1521
+ configHash: status.inputs.configHash,
1522
+ animationsFromHash: animSource.sha256,
1523
+ ops: [...ops],
1524
+ ...(keys ? { args: ['--idle-keys', keys] } : {}),
1525
+ },
1526
+ ...(scheduled ? { environment: scheduled.schedule } : {}),
1527
+ };
1528
+ rebuildBusy = true; rebuildState();
1529
+ if (pickedSide === side) {
1530
+ animationPanel?.busy(true);
1531
+ animationPanel?.setEditorStatus(`Applying ${ops.length} animation op(s) on Build ${side.toUpperCase()} (${animSource.path ?? 'animations_from'}: rig-parts rig → rigc build → rig-parts check)…`, false);
1532
+ }
1533
+ try {
1534
+ const result = await runRebuild<AnimationRequestBody, AnimationJobView>(request, {
1535
+ post: value => host.api<AnimationJobView | RebuildRefusal>(`${sideApiPrefix(side)}/rebuild`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(value) }),
1536
+ get: id => host.api<AnimationJobView>(`${sideApiPrefix(side)}/rebuild/${id}`),
1537
+ sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
1538
+ onLine: line => { if (pickedSide === side) animationPanel?.setEditorStatus(line.trim() || '…', false); },
1539
+ });
1540
+ const outcome = animationOutcomeLine(result), next = stageModel(result, { url: '', hash: state.stageModelHash ?? '' });
1541
+ if (next.id === null || !('id' in result)) {
1542
+ if (pickedSide === side) animationPanel?.setEditorStatus(outcome.text, true);
1543
+ host.message(outcome.text, true);
1544
+ return result;
1545
+ }
1546
+ if (pickedSide === side) {
1547
+ animationPanel?.markApplied(ops, outcome.text, outcome.error);
1548
+ }
1549
+ await swapPickedSide(side, new URL(host.route(next.url), location.href).href, host.route(`/compare-rebuild/${side}/${next.id}/`), next.hash);
1550
+ state.appliedOnStage = animationAppliedRecord(result);
1551
+ state.stageCheck = { lines: [...result.lines], check: result.check };
1552
+ stageChanged(side, { kind: 'apply', via: 'animation' });
1553
+ if (pickedSide === side) {
1554
+ const draft = el<HTMLTextAreaElement>('rebuild-applied');
1555
+ draft.value = JSON.stringify(state.appliedOnStage);
1556
+ draft.dispatchEvent(new Event('input', { bubbles: true }));
1557
+ animationPanel?.setEditorStatus(outcome.text, outcome.error);
1558
+ state.animationState = animationPanel?.exportSideState() ?? state.animationState;
1559
+ } else if (state.animationState) {
1560
+ state.animationState.appliedOps = ops.map(o => structuredClone(o));
1561
+ state.animationState.editorStatus = { text: outcome.text, error: outcome.error };
1562
+ }
1563
+ host.message(outcome.text, outcome.error);
1564
+ return result;
1565
+ } catch (error) {
1566
+ const textMsg = `REBUILD_FAILED: ${errorText(error)}`;
1567
+ if (pickedSide === side) animationPanel?.setEditorStatus(textMsg, true);
1568
+ host.message(textMsg, true);
1569
+ return { status: 'refused', error: textMsg, producerLine: null };
1570
+ } finally {
1571
+ rebuildBusy = false; rebuildState(); animationPanel?.busy(false);
1572
+ }
1573
+ }
1574
+
1575
+ async function resetAnimationBuild(): Promise<void> {
1576
+ const side = pickedSide, state = sides[side];
1577
+ const resetMsg = `Reset: Build ${side.toUpperCase()} is back on its inspected build; no pending animation ops.`;
1578
+ animationPanel?.resetEdits();
1579
+ animationPanel?.setEditorStatus(resetMsg, false);
1580
+ if (animationPanel) state.animationState = animationPanel.exportSideState();
1581
+ state.animAdjust = null;
1582
+ setAdjust(side);
1583
+ if (state.appliedOnStage) {
1584
+ animationPanel?.busy(true);
1585
+ try {
1586
+ await resetRebuild(stageWorld(), side);
1587
+ } finally {
1588
+ animationPanel?.busy(false);
1589
+ if (pickedSide === side) {
1590
+ animationPanel?.resetEdits();
1591
+ } else if (state.animationState) {
1592
+ state.animationState.appliedOps = [];
1593
+ state.animationState.selectedKey = null;
1594
+ state.animationState.selectedKeys = [];
1595
+ }
1596
+ }
1597
+ }
1598
+ if (pickedSide === side) {
1599
+ animationPanel?.setEditorStatus(resetMsg, false);
1600
+ if (animationPanel) state.animationState = animationPanel.exportSideState();
1601
+ } else if (state.animationState) {
1602
+ state.animationState.editorStatus = { text: resetMsg, error: false };
1603
+ }
1409
1604
  }
1410
1605
 
1411
1606
  async function checkBones(ops: PatchOp[]): Promise<BonesCheckView> {
@@ -1418,74 +1613,84 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1418
1613
  async function applyBones(ops: PatchOp[]): Promise<PatchJobView | RebuildRefusal | null> {
1419
1614
  const side = pickedSide, status = sides[side].rebuildStatus ?? await loadRebuildStatus(side);
1420
1615
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig' }) : null;
1421
- if (!patch) { const reason = !ops.length ? 'BONES_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; bonesPanel?.status(reason, true); return null; }
1422
- bonesPanel?.busy(true); bonesPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1616
+ if (!patch) { const reason = !ops.length ? 'BONES_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) bonesPanel?.status(reason, true); return null; }
1617
+ if (pickedSide === side) { bonesPanel?.busy(true); bonesPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1423
1618
  try {
1424
- const result = await applyPatch(patch, stageWorld());
1425
- const outcome = patchOutcomeLine(result); bonesPanel?.status(outcome.text, outcome.error);
1426
- if ('id' in result && result.status === 'built') { bonesPanel?.applied(result.request.patch.ops); host.redrawOverlays(true); }
1619
+ const result = await applyPatch(patch, stageWorld(), side);
1620
+ const outcome = patchOutcomeLine(result);
1621
+ if (pickedSide === side) bonesPanel?.status(outcome.text, outcome.error);
1622
+ if ('id' in result && result.status === 'built') {
1623
+ if (pickedSide === side) bonesPanel?.applied(result.request.patch.ops);
1624
+ host.redrawOverlays(true);
1625
+ }
1427
1626
  return result;
1428
1627
  } finally { bonesPanel?.busy(false); }
1429
1628
  }
1430
1629
 
1431
1630
  async function resetBonesBuild(): Promise<void> {
1631
+ const side = pickedSide, state = sides[side];
1432
1632
  bonesPanel?.clear(); bonesPanel?.applied(null);
1433
- if (currentState().appliedOnStage) { bonesPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { bonesPanel?.busy(false); } }
1434
- bonesPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1633
+ if (state.appliedOnStage) { bonesPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { bonesPanel?.busy(false); } }
1634
+ if (pickedSide === side) bonesPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1435
1635
  }
1436
1636
 
1437
1637
  async function applyCuts(ops: PatchOp[]): Promise<PatchJobView | RebuildRefusal | null> {
1438
1638
  const side = pickedSide, status = sides[side].rebuildStatus ?? await loadRebuildStatus(side);
1439
1639
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig' }) : null;
1440
- if (!patch) { const reason = !ops.length ? 'CUTS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; cutsPanel?.status(reason, true); return null; }
1441
- cutsPanel?.busy(true); cutsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1640
+ if (!patch) { const reason = !ops.length ? 'CUTS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) cutsPanel?.status(reason, true); return null; }
1641
+ if (pickedSide === side) { cutsPanel?.busy(true); cutsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1442
1642
  try {
1443
- const result = await applyPatch(patch, stageWorld());
1444
- const outcome = patchOutcomeLine(result); cutsPanel?.status(outcome.text, outcome.error);
1643
+ const result = await applyPatch(patch, stageWorld(), side);
1644
+ const outcome = patchOutcomeLine(result);
1645
+ if (pickedSide === side) cutsPanel?.status(outcome.text, outcome.error);
1445
1646
  if ('id' in result && result.status === 'built') host.redrawOverlays(true);
1446
1647
  return result;
1447
1648
  } finally { cutsPanel?.busy(false); }
1448
1649
  }
1449
1650
 
1450
1651
  async function resetCutsBuild(): Promise<void> {
1652
+ const side = pickedSide, state = sides[side];
1451
1653
  cutsPanel?.clear(); cutsPanel?.shown(null);
1452
- if (currentState().appliedOnStage) { cutsPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { cutsPanel?.busy(false); } }
1453
- cutsPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1654
+ if (state.appliedOnStage) { cutsPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { cutsPanel?.busy(false); } }
1655
+ if (pickedSide === side) cutsPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1454
1656
  }
1455
1657
 
1456
1658
  async function applyCloth(ops: PatchOp[]): Promise<PatchJobView | RebuildRefusal | null> {
1457
1659
  const side = pickedSide, status = sides[side].rebuildStatus ?? await loadRebuildStatus(side);
1458
1660
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig' }) : null;
1459
- if (!patch) { const reason = !ops.length ? 'CLOTH_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; clothPanel?.status(reason, true); return null; }
1460
- clothPanel?.busy(true); clothPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1661
+ if (!patch) { const reason = !ops.length ? 'CLOTH_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) clothPanel?.status(reason, true); return null; }
1662
+ if (pickedSide === side) { clothPanel?.busy(true); clothPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1461
1663
  try {
1462
- const result = await applyPatch(patch, stageWorld());
1463
- const outcome = patchOutcomeLine(result); clothPanel?.status(outcome.text, outcome.error);
1664
+ const result = await applyPatch(patch, stageWorld(), side);
1665
+ const outcome = patchOutcomeLine(result);
1666
+ if (pickedSide === side) clothPanel?.status(outcome.text, outcome.error);
1464
1667
  if ('id' in result && result.status === 'built') host.redrawOverlays(true);
1465
1668
  return result;
1466
1669
  } finally { clothPanel?.busy(false); }
1467
1670
  }
1468
1671
 
1469
1672
  async function resetClothBuild(): Promise<void> {
1673
+ const side = pickedSide, state = sides[side];
1470
1674
  clothPanel?.clear(); clothPanel?.shown(null);
1471
- if (currentState().appliedOnStage) { clothPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { clothPanel?.busy(false); } }
1472
- clothPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1675
+ if (state.appliedOnStage) { clothPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { clothPanel?.busy(false); } }
1676
+ if (pickedSide === side) clothPanel?.status('Reset: the inspected build is on the stage; no pending ops.', false);
1473
1677
  }
1474
1678
 
1475
1679
  async function applyRigFields(ops: PatchOp[]): Promise<PatchJobView | RebuildRefusal | null> {
1476
1680
  const side = pickedSide, state = sides[side], status = state.rebuildStatus ?? await loadRebuildStatus(side);
1477
- try { assertRigFieldOps(ops); } catch (error) { rigFieldsPanel?.status(errorText(error), true); return null; }
1681
+ try { assertRigFieldOps(ops); } catch (error) { if (pickedSide === side) rigFieldsPanel?.status(errorText(error), true); return null; }
1478
1682
  const patch = status && ops.length ? makePatch(status, ops, { cmd: 'rig' }) : null;
1479
- if (!patch) { const reason = !ops.length ? 'RIG_FIELDS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; rigFieldsPanel?.status(reason, true); return null; }
1683
+ if (!patch) { const reason = !ops.length ? 'RIG_FIELDS_NOTHING_PENDING: no pending ops' : status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE'; if (pickedSide === side) rigFieldsPanel?.status(reason, true); return null; }
1480
1684
  const world = stageWorld(), before = state.stageCheck;
1481
- rigFieldsPanel?.busy(true); rigFieldsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false);
1685
+ if (pickedSide === side) { rigFieldsPanel?.busy(true); rigFieldsPanel?.status(`Applying ${ops.length} op(s) on Build ${side.toUpperCase()}…`, false); }
1482
1686
  try {
1483
- const result = await applyPatch(patch, world);
1484
- const outcome = patchOutcomeLine(result); rigFieldsPanel?.status(outcome.text, outcome.error);
1687
+ const result = await applyPatch(patch, world, side);
1688
+ const outcome = patchOutcomeLine(result);
1689
+ if (pickedSide === side) rigFieldsPanel?.status(outcome.text, outcome.error);
1485
1690
  if ('id' in result && result.status === 'built') {
1486
- rigFieldsPanel?.applied(result.request.patch.ops);
1691
+ if (pickedSide === side) rigFieldsPanel?.applied(result.request.patch.ops);
1487
1692
  const after = { lines: [...result.lines], check: result.check };
1488
- const show = () => rigFieldsPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, RIG_FIELDS_READOUT_BARS));
1693
+ const show = () => { if (pickedSide === side) rigFieldsPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, RIG_FIELDS_READOUT_BARS)); };
1489
1694
  show(); if (!before) void followInspectedCheck(show, side);
1490
1695
  }
1491
1696
  return result;
@@ -1493,25 +1698,26 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1493
1698
  }
1494
1699
 
1495
1700
  async function resetRigFieldsBuild(): Promise<void> {
1701
+ const side = pickedSide, state = sides[side];
1496
1702
  rigFieldsPanel?.setDial(0); rigFieldsPanel?.clear(); rigFieldsPanel?.applied(null); rigFieldsPanel?.readout([]);
1497
- if (currentState().appliedOnStage) { rigFieldsPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { rigFieldsPanel?.busy(false); } }
1498
- rigFieldsPanel?.status('Reset: the inspected build is on the stage; no pending ops; the dial is at 0.', false);
1703
+ if (state.appliedOnStage) { rigFieldsPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { rigFieldsPanel?.busy(false); } }
1704
+ if (pickedSide === side) rigFieldsPanel?.status('Reset: the inspected build is on the stage; no pending ops; the dial is at 0.', false);
1499
1705
  }
1500
1706
 
1501
1707
  async function applyMesh(part: string, entry: MeshEntry): Promise<PatchJobView | RebuildRefusal | null> {
1502
1708
  const side = pickedSide, state = sides[side], status = state.rebuildStatus ?? await loadRebuildStatus(side);
1503
1709
  const problems = meshPanel?.precheck() ?? [];
1504
- if (problems.length) { meshPanel?.status(`${problems[0]} (review pre-check; nothing sent)`, true); return null; }
1710
+ if (problems.length) { if (pickedSide === side) meshPanel?.status(`${problems[0]} (review pre-check; nothing sent)`, true); return null; }
1505
1711
  const patch = status ? makePatch(status, meshPatchOps(part, entry), { cmd: 'remesh', args: ['--part', part] }) : null;
1506
- if (!patch) { meshPanel?.status(status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE', true); return null; }
1507
- try { assertMeshPatch(patch, part); } catch (error) { meshPanel?.status(errorText(error), true); return null; }
1712
+ if (!patch) { if (pickedSide === side) meshPanel?.status(status?.reason ?? 'REBUILD_STATUS_UNAVAILABLE', true); return null; }
1713
+ try { assertMeshPatch(patch, part); } catch (error) { if (pickedSide === side) meshPanel?.status(errorText(error), true); return null; }
1508
1714
  lastMeshPatch = patch;
1509
1715
  const world = stageWorld(), before = state.stageCheck;
1510
- meshPanel?.busy(true); meshPanel?.status(`Applying meshes.${part} on Build ${side.toUpperCase()} with ${patch.producer.name} ${patch.producer.version}: remesh --mesh, compile, check…`, false);
1716
+ if (pickedSide === side) { meshPanel?.busy(true); meshPanel?.status(`Applying meshes.${part} on Build ${side.toUpperCase()} with ${patch.producer.name} ${patch.producer.version}: remesh --mesh, compile, check…`, false); }
1511
1717
  try {
1512
- const result = await applyPatch(patch, world);
1718
+ const result = await applyPatch(patch, world, side);
1513
1719
  const outcome = meshApplyOutcome(result as Parameters<typeof meshApplyOutcome>[0]);
1514
- meshPanel?.status(outcome.text, outcome.error);
1720
+ if (pickedSide === side) meshPanel?.status(outcome.text, outcome.error);
1515
1721
  if ('id' in result && result.status === 'built') {
1516
1722
  if (!host.layers.mesh) { host.layers.mesh = true; input('layer-mesh').checked = true; }
1517
1723
  const player = host.players[side];
@@ -1519,12 +1725,14 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1519
1725
  host.redrawOverlays(true);
1520
1726
  const counts = result.remesh ?? null, overlay = state.lastOverlay?.meshTriangles[part] ?? null;
1521
1727
  const agree = triangleAgreement(counts, counts?.modelTriangles ?? null, overlay);
1522
- meshPanel?.counts([
1523
- ...(counts ? [{ label: 'BEFORE', text: `${counts.part} ${countsText(counts.before)} (remesh.json)` }, { label: 'AFTER', text: `${counts.part} ${countsText(counts.after)} (remesh.json)` }] : []),
1524
- { label: agree.ok ? 'AGREE' : 'DIFFER', text: agree.line, error: !agree.ok },
1525
- ]);
1728
+ if (pickedSide === side) {
1729
+ meshPanel?.counts([
1730
+ ...(counts ? [{ label: 'BEFORE', text: `${counts.part} ${countsText(counts.before)} (remesh.json)` }, { label: 'AFTER', text: `${counts.part} ${countsText(counts.after)} (remesh.json)` }] : []),
1731
+ { label: agree.ok ? 'AGREE' : 'DIFFER', text: agree.line, error: !agree.ok },
1732
+ ]);
1733
+ }
1526
1734
  const after = { lines: [...result.lines], check: result.check };
1527
- const show = () => meshPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, ['TEXTURE_STRETCH']));
1735
+ const show = () => { if (pickedSide === side) meshPanel?.readout(readoutRows(before, before ? null : inspectedCheckView(side), after, ['TEXTURE_STRETCH'])); };
1528
1736
  show(); if (!before) void followInspectedCheck(show, side);
1529
1737
  }
1530
1738
  return result;
@@ -1532,14 +1740,18 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1532
1740
  }
1533
1741
 
1534
1742
  async function resetMeshBuild(): Promise<void> {
1743
+ const side = pickedSide, state = sides[side];
1535
1744
  meshPanel?.counts([]); meshPanel?.readout([]);
1536
- if (currentState().appliedOnStage || currentState().stripPending) {
1537
- meshPanel?.busy(true); try { await resetRebuild(stageWorld()); } finally { meshPanel?.busy(false); }
1745
+ if (state.appliedOnStage || state.stripPending) {
1746
+ meshPanel?.busy(true); try { await resetRebuild(stageWorld(), side); } finally { meshPanel?.busy(false); }
1538
1747
  }
1539
- meshPanel?.status('Reset: the inspected build is on the stage; the pending entry is the config\'s.', false);
1748
+ if (pickedSide === side) meshPanel?.status('Reset: the inspected build is on the stage; the pending entry is the config\'s.', false);
1540
1749
  }
1541
1750
 
1542
- const densityLine = (msg: string, error = false) => { densityStrip?.status(msg, error); if (error) host.message(msg, true); };
1751
+ const densityLine = (msg: string, error = false, side: Side = pickedSide) => {
1752
+ if (pickedSide === side) densityStrip?.status(msg, error);
1753
+ if (error) host.message(msg, true);
1754
+ };
1543
1755
  const renderStrip = () => {
1544
1756
  const state = currentState();
1545
1757
  densityStrip?.show(state.stripView, state.stripPending && state.stripView?.id === state.stripPending.id ? state.stripPending.index : null, densityBusy || rebuildBusy || !!host.readOnly());
@@ -1556,9 +1768,9 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1556
1768
  if (ro) { densityLine(ro, true); return { error: ro }; }
1557
1769
  const side = pickedSide, state = sides[side];
1558
1770
  const status = state.rebuildStatus ?? await loadRebuildStatus(side), part = meshPanel?.part() ?? null, entry = meshPanel?.entry() ?? null;
1559
- if (!status || !part || !entry) { const t = status?.reason ?? 'MESH_PANEL_NO_PART: select a mesh part'; densityLine(t, true); return { error: t }; }
1771
+ if (!status || !part || !entry) { const t = status?.reason ?? 'MESH_PANEL_NO_PART: select a mesh part'; densityLine(t, true, side); return { error: t }; }
1560
1772
  const problems = meshPanel?.precheck() ?? [];
1561
- if (problems.length) { const t = `${problems[0]} (review pre-check; nothing sent)`; densityLine(t, true); return { error: t }; }
1773
+ if (problems.length) { const t = `${problems[0]} (review pre-check; nothing sent)`; densityLine(t, true, side); return { error: t }; }
1562
1774
  let patches: ConfigPatch[];
1563
1775
  try {
1564
1776
  const field = densityField(entry, part);
@@ -1568,26 +1780,26 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1568
1780
  assertMeshPatch(patch, part);
1569
1781
  return patch;
1570
1782
  });
1571
- } catch (error) { const t = errorText(error); densityLine(t, true); return { error: t }; }
1572
- if (state.stripPending) await stripBack();
1573
- densityBusy = true; renderStrip();
1574
- densityLine(`Building a strip of ${values.length} on ${part} (Build ${side.toUpperCase()}): ${values.join(', ')}…`);
1783
+ } catch (error) { const t = errorText(error); densityLine(t, true, side); return { error: t }; }
1784
+ if (state.stripPending) await stripBack(side);
1785
+ densityBusy = true; if (pickedSide === side) renderStrip();
1786
+ densityLine(`Building a strip of ${values.length} on ${part} (Build ${side.toUpperCase()}): ${values.join(', ')}…`, false, side);
1575
1787
  const t0 = performance.now();
1576
1788
  try {
1577
1789
  let view: DensityStripViewLike | { status: string; error: string };
1578
1790
  try { view = await host.api<DensityStripViewLike | { status: string; error: string }>(`${sideApiPrefix(side)}/density-strip`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ patches }) }); }
1579
- catch (error) { const t = errorText(error); densityLine(t, true); return { error: t }; }
1580
- if ('error' in view) { densityLine(view.error, true); return { error: view.error }; }
1581
- state.stripView = view; renderStrip();
1791
+ catch (error) { const t = errorText(error); densityLine(t, true, side); return { error: t }; }
1792
+ if ('error' in view) { densityLine(view.error, true, side); return { error: view.error }; }
1793
+ state.stripView = view; if (pickedSide === side) renderStrip();
1582
1794
  while (state.stripView.status === 'running') {
1583
1795
  await new Promise(resolve => setTimeout(resolve, 1500));
1584
1796
  state.stripView = await host.api<DensityStripViewLike>(`${sideApiPrefix(side)}/density-strip/${state.stripView.id}`);
1585
- renderStrip();
1797
+ if (pickedSide === side) renderStrip();
1586
1798
  const settled = state.stripView.rows.filter(r => r.status !== 'running').length;
1587
- densityLine(`Strip ${state.stripView.id.slice(0, 12)}…: ${settled} of ${state.stripView.rows.length} settled · ${((performance.now() - t0) / 1000).toFixed(0)} s`);
1799
+ densityLine(`Strip ${state.stripView.id.slice(0, 12)}…: ${settled} of ${state.stripView.rows.length} settled · ${((performance.now() - t0) / 1000).toFixed(0)} s`, false, side);
1588
1800
  }
1589
1801
  const passing = state.stripView.rows.filter(r => r.verdict === 'PASS').length;
1590
- densityLine(`Strip of ${state.stripView.rows.length} on ${state.stripView.part} settled: ${passing} passing.`);
1802
+ densityLine(`Strip of ${state.stripView.rows.length} on ${state.stripView.part} settled: ${passing} passing.`, false, side);
1591
1803
  return state.stripView;
1592
1804
  } finally { densityBusy = false; renderStrip(); }
1593
1805
  }
@@ -1596,7 +1808,7 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1596
1808
  const side = pickedSide, state = sides[side];
1597
1809
  const view = state.stripView, row = view?.rows[index];
1598
1810
  if (!view || !row) return { error: 'DENSITY_STRIP_NOT_FOUND' };
1599
- if (!row.modelUrl || !row.modelHash) { const t = `DENSITY_STRIP_ROW_NOT_LOADABLE: ${row.value} — ${row.applied ? 'applied already' : row.verdict}`; densityLine(t, true); return { error: t }; }
1811
+ if (!row.modelUrl || !row.modelHash) { const t = `DENSITY_STRIP_ROW_NOT_LOADABLE: ${row.value} — ${row.applied ? 'applied already' : row.verdict}`; densityLine(t, true, side); return { error: t }; }
1600
1812
  if (rebuildBusy || densityBusy) return { error: 'REBUILD_BUSY' };
1601
1813
  const back = state.stripPending?.back ?? {
1602
1814
  url: state.stageSource?.url ?? state.inspectedModel!.url,
@@ -1610,42 +1822,51 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1610
1822
  await swapPickedSide(side, new URL(host.route(row.modelUrl), location.href).href, host.route(`/compare-density-strip/${side}/${view.id}/${row.id}/`), row.modelHash);
1611
1823
  state.stripPending = { index, id: view.id, candidate: row.id, back };
1612
1824
  state.appliedOnStage = null; state.stageCheck = null;
1613
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1614
- meshPanel?.setEntry(row.entry as MeshEntry);
1825
+ if (pickedSide === side) {
1826
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1827
+ meshPanel?.setEntry(row.entry as MeshEntry);
1828
+ } else if (state.animationState) {
1829
+ state.animationState.appliedOps = [];
1830
+ }
1615
1831
  if (!host.layers.mesh) { host.layers.mesh = true; input('layer-mesh').checked = true; }
1616
1832
  host.redrawOverlays(true);
1617
1833
  const c = row.counts ? { vertices: row.counts.vertices, triangles: row.counts.triangles, hull: 0 } : null;
1618
1834
  const agree = triangleAgreement(c ? { part: view.part, before: c, after: c } : null, row.modelTriangles, state.lastOverlay?.meshTriangles[view.part] ?? null);
1619
- meshPanel?.counts([{ label: 'PENDING', text: `${view.field} ${row.value} — not applied` }, { label: agree.ok ? 'AGREE' : 'DIFFER', text: agree.line, error: !agree.ok }]);
1620
- densityLine(`Pending on Build ${side.toUpperCase()}: ${view.part} ${view.field} ${row.value} (strip row ${index + 1}) — not applied.`, !agree.ok);
1835
+ if (pickedSide === side) {
1836
+ meshPanel?.counts([{ label: 'PENDING', text: `${view.field} ${row.value} — not applied` }, { label: agree.ok ? 'AGREE' : 'DIFFER', text: agree.line, error: !agree.ok }]);
1837
+ }
1838
+ densityLine(`Pending on Build ${side.toUpperCase()}: ${view.part} ${view.field} ${row.value} (strip row ${index + 1}) — not applied.`, !agree.ok, side);
1621
1839
  return { line: agree.line, ok: agree.ok };
1622
- } catch (error) { const t = `DENSITY_STRIP_LOAD_FAILED: ${errorText(error)}`; densityLine(t, true); return { error: t }; }
1840
+ } catch (error) { const t = `DENSITY_STRIP_LOAD_FAILED: ${errorText(error)}`; densityLine(t, true, side); return { error: t }; }
1623
1841
  finally { rebuildBusy = false; rebuildState(); renderStrip(); }
1624
1842
  }
1625
1843
 
1626
- async function stripBack(): Promise<void> {
1627
- const side = pickedSide, state = sides[side], pending = state.stripPending;
1844
+ async function stripBack(side: Side = pickedSide): Promise<void> {
1845
+ const state = sides[side], pending = state.stripPending;
1628
1846
  if (!pending || rebuildBusy) return;
1629
1847
  rebuildBusy = true; rebuildState();
1630
1848
  try {
1631
1849
  await swapPickedSide(side, pending.back.url, pending.back.prefix, pending.back.hash);
1632
1850
  state.appliedOnStage = pending.back.applied; state.stageCheck = pending.back.check; state.stripPending = null;
1633
- const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = state.appliedOnStage ? JSON.stringify(state.appliedOnStage) : ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1634
- meshPanel?.counts([]); host.redrawOverlays(true);
1635
- densityLine(`Back: Build ${side.toUpperCase()} shows ${state.appliedOnStage ? 'the last applied record' : 'the inspected build'}.`);
1636
- } catch (error) { densityLine(`DENSITY_STRIP_BACK_FAILED: ${errorText(error)}`, true); }
1851
+ if (pickedSide === side) {
1852
+ const draft = el<HTMLTextAreaElement>('rebuild-applied'); draft.value = state.appliedOnStage ? JSON.stringify(state.appliedOnStage) : ''; draft.dispatchEvent(new Event('input', { bubbles: true }));
1853
+ meshPanel?.counts([]);
1854
+ }
1855
+ host.redrawOverlays(true);
1856
+ densityLine(`Back: Build ${side.toUpperCase()} shows ${state.appliedOnStage ? 'the last applied record' : 'the inspected build'}.`, false, side);
1857
+ } catch (error) { densityLine(`DENSITY_STRIP_BACK_FAILED: ${errorText(error)}`, true, side); }
1637
1858
  finally { rebuildBusy = false; rebuildState(); renderStrip(); }
1638
1859
  }
1639
1860
 
1640
1861
  async function closeDensityStrip(): Promise<{ status: string; error?: string }> {
1641
1862
  const side = pickedSide, state = sides[side], view = state.stripView;
1642
1863
  if (!view) return { status: 'closed' };
1643
- if (state.stripPending && state.stripPending.id === view.id) await stripBack();
1864
+ if (state.stripPending && state.stripPending.id === view.id) await stripBack(side);
1644
1865
  try {
1645
1866
  const r = await host.api<{ status: string; error?: string }>(`${sideApiPrefix(side)}/density-strip/close`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: view.id }) });
1646
- if (r.status !== 'closed') { densityLine(r.error ?? 'DENSITY_STRIP_CLOSE_REFUSED', true); return r; }
1647
- state.stripView = null; renderStrip(); densityLine('Strip closed; its scratch is removed.'); return r;
1648
- } catch (error) { const t = errorText(error); densityLine(t, true); return { status: 'refused', error: t }; }
1867
+ if (r.status !== 'closed') { densityLine(r.error ?? 'DENSITY_STRIP_CLOSE_REFUSED', true, side); return r; }
1868
+ state.stripView = null; if (pickedSide === side) renderStrip(); densityLine('Strip closed; its scratch is removed.', false, side); return r;
1869
+ } catch (error) { const t = errorText(error); densityLine(t, true, side); return { status: 'refused', error: t }; }
1649
1870
  }
1650
1871
 
1651
1872
  async function runReadings(override?: { readings: import('../src/readings.ts').ReadingRequest[] }): Promise<ReadingsJobView | ReadingsRefusal | null> {
@@ -1666,19 +1887,26 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1666
1887
  let job = await host.api<ReadingsJobView | ReadingsRefusal>(`${sideApiPrefix(side)}/readings`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }).catch(error => ({ status: 'refused' as const, error: errorText(error).replace(/^\d+: /, '') }));
1667
1888
  if (!('id' in job)) {
1668
1889
  const textMsg = (() => { try { return (JSON.parse(job.error) as { error?: string }).error ?? job.error; } catch { return job.error; } })();
1669
- readingsPanel.status(textMsg, true); return { status: 'refused', error: textMsg };
1890
+ if (pickedSide === side) readingsPanel.status(textMsg, true);
1891
+ return { status: 'refused', error: textMsg };
1670
1892
  }
1671
1893
  while (job.status === 'running') {
1672
1894
  await new Promise(resolve => setTimeout(resolve, 800));
1673
1895
  job = await host.api<ReadingsJobView>(`${sideApiPrefix(side)}/readings/${job.id}`);
1674
1896
  }
1675
- if (job.status === 'failed') { readingsPanel.status(job.error ?? 'READINGS_FAILED', true); return job; }
1676
- sides[side].readingsJob = job; readingsPanel.lines(job);
1677
- const ticks = job.runs.map(r => `${r.build} ${r.results.reduce((n, x) => n + x.frames.length, 0)} tick(s)`).join(' · ');
1678
- const refused = job.runs.flatMap(r => r.results).find(r => r.status !== 'read');
1679
- readingsPanel.status(`${refused ? `${refused.refusal} · ` : ''}Readings of ${job.request.animation}: ${ticks} · ${((performance.now() - started) / 1000).toFixed(1)} s`, !!refused);
1897
+ if (job.status === 'failed') {
1898
+ if (pickedSide === side) readingsPanel.status(job.error ?? 'READINGS_FAILED', true);
1899
+ return job;
1900
+ }
1901
+ sides[side].readingsJob = job;
1902
+ if (pickedSide === side) {
1903
+ readingsPanel.lines(job);
1904
+ const ticks = job.runs.map(r => `${r.build} ${r.results.reduce((n, x) => n + x.frames.length, 0)} tick(s)`).join(' · ');
1905
+ const refused = job.runs.flatMap(r => r.results).find(r => r.status !== 'read');
1906
+ readingsPanel.status(`${refused ? `${refused.refusal} · ` : ''}Readings of ${job.request.animation}: ${ticks} · ${((performance.now() - started) / 1000).toFixed(1)} s`, !!refused);
1907
+ }
1680
1908
  return job;
1681
- } catch (error) { readingsPanel.status(`READINGS_FAILED: ${errorText(error)}`, true); return null; }
1909
+ } catch (error) { if (pickedSide === side) readingsPanel.status(`READINGS_FAILED: ${errorText(error)}`, true); return null; }
1682
1910
  finally { readingsBusy = false; readingsPanel.busy(false); }
1683
1911
  }
1684
1912
 
@@ -1702,16 +1930,17 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1702
1930
  }
1703
1931
 
1704
1932
  async function meshFolds(): Promise<string[]> {
1705
- const animation = host.data().animation;
1933
+ const side = pickedSide, animation = host.data().animation;
1706
1934
  meshPanel?.status(`Running the folds reading of ${animation}…`, false);
1707
1935
  const job = await runReadings({ readings: [{ kind: 'folds' }] });
1708
1936
  if (!job || !('runs' in job)) {
1709
1937
  const textMsg = job && 'error' in job && job.error ? job.error : 'READINGS_UNAVAILABLE: no reading ran';
1710
- meshPanel?.status(textMsg, true); return [textMsg];
1938
+ if (pickedSide === side) meshPanel?.status(textMsg, true);
1939
+ return [textMsg];
1711
1940
  }
1712
1941
  const lines = job.runs.map(run => { const r = run.results[0]; return r ? worstLine(run.build, r) : `${run.build} · folds: not run`; });
1713
1942
  if (job.runs.length < 2) lines.push('scratch · folds: no scratch build yet (Apply builds one)');
1714
- meshPanel?.status(lines.join(' | '), job.runs.some(run => run.results.some(r => r.status !== 'read')));
1943
+ if (pickedSide === side) meshPanel?.status(lines.join(' | '), job.runs.some(run => run.results.some(r => r.status !== 'read')));
1715
1944
  return lines;
1716
1945
  }
1717
1946
 
@@ -1734,6 +1963,7 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1734
1963
  const side = pickedSide, state = sides[side];
1735
1964
  const out = el('environment-check-lines');
1736
1965
  const show = (rows: { kind: string; text: string }[]) => {
1966
+ if (pickedSide !== side) return;
1737
1967
  out.replaceChildren(...rows.map(row => { const line = document.createElement('div'); line.className = `env-${row.kind}`; line.textContent = row.text; return line; }));
1738
1968
  };
1739
1969
  const name = checkAnimation(side), world = worldFor(name, side);
@@ -1903,7 +2133,14 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
1903
2133
  stage: viewportProxy,
1904
2134
  project: (x, y) => rigProject()(x, y),
1905
2135
  enabled: () => !!currentState().partModel && currentInspector() === 'playback',
1906
- readOnlyReason: 'keyed animation editing is read-only in comparison sessions until per-side animation rebuild is wired.',
2136
+ readOnlyReason: () => host.readOnly(),
2137
+ pause: () => host.pause(),
2138
+ preview: fn => {
2139
+ sides[pickedSide].animAdjust = fn;
2140
+ setAdjust(pickedSide);
2141
+ },
2142
+ apply: ops => applyAnimation(ops),
2143
+ reset: () => resetAnimationBuild(),
1907
2144
  seek: exact => {
1908
2145
  if (!Number.isFinite(exact) || exact < 0 || exact > host.duration()) {
1909
2146
  host.message('KEY_TIME_OUT_OF_DOMAIN: no substitute time was used.', true);
@@ -2298,6 +2535,46 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
2298
2535
  lines: () => retargetPanel?.shownLines() ?? [],
2299
2536
  refusals: () => [...document.querySelectorAll('#retarget-refusals code')].map(c => c.textContent),
2300
2537
  },
2538
+ animation: {
2539
+ ops: () => animationPanel?.ops() ?? [],
2540
+ unappliedOps: () => animationPanel?.unappliedOps() ?? [],
2541
+ hasPreview: () => animationPanel?.hasUnappliedPreview() ?? false,
2542
+ source: () => animationPanel?.sourceInfo() ?? null,
2543
+ setSourceLoading: () => animationPanel?.setSourceLoading(),
2544
+ setSource: (source: Parameters<AnimationInspectionPanel['loadSource']>[0], fallbackReason?: string | null) => animationPanel?.loadSource(source, fallbackReason),
2545
+ gate: () => animationPanel?.gateInfo() ?? null,
2546
+ tracks: () => animationPanel?.tracksInfo() ?? [],
2547
+ selectedKey: () => animationPanel?.selectedKeyInfo() ?? null,
2548
+ selectedKeys: () => animationPanel?.selectedKeysInfo() ?? [],
2549
+ selectKey: (track: number, key: number) => animationPanel?.selectKey(track, key) ?? false,
2550
+ selectKeys: (selections: ReadonlyArray<{ track: number; key: number }>) => animationPanel?.selectKeys(selections) ?? false,
2551
+ toggleKeySelection: (track: number, key: number) => animationPanel?.toggleKeySelection(track, key) ?? false,
2552
+ deleteSelection: () => animationPanel?.deleteSelection() ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2553
+ stagePoseMode: () => animationPanel?.stagePoseMode() ?? 'rotate',
2554
+ setStagePoseMode: (mode: 'rotate' | 'translate') => animationPanel?.setStagePoseMode(mode),
2555
+ poseBone: (boneName: string, arg2: 'rotate' | 'translate' | number, arg3: number, arg4: number | 'rotate' | 'translate') => {
2556
+ const mode = typeof arg2 === 'string' ? arg2 : (arg4 as 'rotate' | 'translate');
2557
+ const clientX = typeof arg2 === 'number' ? arg2 : arg3;
2558
+ const clientY = typeof arg2 === 'number' ? arg3 : (arg4 as number);
2559
+ return animationPanel?.poseBoneOnStage(boneName, mode, clientX, clientY) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' };
2560
+ },
2561
+ overlaid: () => animationPanel?.overlaidInspection() ?? null,
2562
+ boneWorld: (boneName: string) => animationPanel?.boneWorldMatrix(boneName) ?? null,
2563
+ setKeyTime: (track: number, key: number, t: number) => animationPanel?.setKeyTime(track, key, t) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2564
+ setKeyValue: (track: number, key: number, channel: number | undefined, value: number | readonly number[]) => animationPanel?.setKeyValue(track, key, channel, value) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2565
+ setKeyCurve: (track: number, key: number, curve: readonly number[] | 'stepped' | null) => animationPanel?.setKeyCurve(track, key, curve) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2566
+ setKeyEase: (track: number, key: number, ease: string | null) => animationPanel?.setKeyEase(track, key, ease) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2567
+ insertKey: (track: number, t: number, value?: readonly number[]) => animationPanel?.insertKey(track, t, value) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2568
+ deleteKey: (track: number, key: number) => animationPanel?.deleteKey(track, key) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2569
+ moveSelection: (selections: ReadonlyArray<{ track: number; key: number }>, deltaTime: number) => animationPanel?.moveSelection(selections, deltaTime) ?? { ok: false, error: 'ANIMATION_PANEL_UNAVAILABLE' },
2570
+ undoOp: () => animationPanel?.undoOp() ?? false,
2571
+ clearPending: () => animationPanel?.clearPending(),
2572
+ zoom: () => animationPanel?.zoomLevel() ?? 1,
2573
+ setZoom: (z: number) => animationPanel?.setZoom(z),
2574
+ apply: () => applyAnimation(animationPanel?.ops() ?? []),
2575
+ reset: () => resetAnimationBuild(),
2576
+ status: () => document.querySelector('[data-animation-editor-status]')?.textContent ?? '',
2577
+ },
2301
2578
  stage: (side: Side = pickedSide) => ({
2302
2579
  side,
2303
2580
  modelHash: sides[side].stageModelHash,
@@ -2324,6 +2601,10 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
2324
2601
  st.stageSource = { url: modelUrl, prefix, hash: sha256 };
2325
2602
  st.stageModelHash = sha256;
2326
2603
  st.partModel = partModel;
2604
+ if (side !== pickedSide && st.animationState) {
2605
+ st.animationState.document = null;
2606
+ st.animationState.baseInspection = null;
2607
+ }
2327
2608
  void loadModelDocument(modelUrl, sha256).then(loaded => {
2328
2609
  if (loaded.ok) {
2329
2610
  st.inspectedDocument = loaded.document;
@@ -2391,10 +2672,10 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
2391
2672
  requirementsPanel?.selectionChanged();
2392
2673
  },
2393
2674
  overlayInputFor: side => {
2394
- animationPanel?.redraw(host.layers.bones);
2395
2675
  if (side !== pickedSide) {
2396
2676
  return { regions: [], circles: [], markers: [], meshEdit: null, weights: null, anchors: null };
2397
2677
  }
2678
+ animationPanel?.redraw(host.layers.bones);
2398
2679
  idlePanel?.place(host.duration());
2399
2680
  rigFieldsPanel?.place();
2400
2681
  return {
@@ -2440,7 +2721,7 @@ export function mountComparePickedTools(host: ComparePickedToolsHost): ComparePi
2440
2721
  if (rebuildBusy) {
2441
2722
  return 'COMMENT_SOURCE_BUSY: wait for the rebuild or candidate model replacement before commenting';
2442
2723
  }
2443
- const preview = idleAdjust ? 'Idle tracks' : dialAdjust ? 'Rig fields turn dial' : physicsPreview.read().length ? 'Physics live overrides' :
2724
+ const preview = idleAdjust ? 'Idle tracks' : (sides.a.animAdjust || sides.b.animAdjust) ? 'Keyed animation preview' : dialAdjust ? 'Rig fields turn dial' : physicsPreview.read().length ? 'Physics live overrides' :
2444
2725
  (sides.a.stripPending || sides.b.stripPending) ? 'Density strip candidate' :
2445
2726
  meshEditor?.overlay() ? 'Edit Mesh' : bonesPanel?.overlay() ? 'Bones anchors' :
2446
2727
  cutsPanel && (cutsPanel.overlayRegions().length || cutsPanel.overlayMarkers().length) ? 'Cuts/patches/joints' :