@umicat/three-sdk 1.9.0 → 1.10.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.
@@ -265,6 +265,19 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
265
265
  selectionBox.visible = false;
266
266
  selectionBox.renderOrder = 998;
267
267
  selectionBox.material.depthTest = false;
268
+ // ADR-046 — multi-select (box-select + ⌘/Ctrl-click). `multiSelected` is
269
+ // now the ONE authoritative source of truth for "what's selected" — the
270
+ // single-select visuals above (`gizmo.attached`/`selectionBox`) are kept
271
+ // IN SYNC with it whenever it holds exactly one entity (every selection
272
+ // change routes through `applySelection` below, which is the only place
273
+ // that writes to any of these), rather than being a second independent
274
+ // notion of selection the way "gizmo attachment IS the selection state"
275
+ // used to read before this existed. `multiBoxes` is an EXTRA per-entity
276
+ // highlight box, used ONLY for the 2+ case — the existing singular
277
+ // `selectionBox` above still owns the 1-entity case unchanged, so a
278
+ // single click never grows a second, redundant box.
279
+ let multiSelected = new Set();
280
+ const multiBoxes = new Map();
268
281
  // The Move/Rotate/Scale transform gizmo — shows (and is only hit-testable)
269
282
  // on the current mode's handles once something is selected. `gizmo.root`
270
283
  // is added to the scene once, at scene-load time, right alongside the
@@ -485,6 +498,23 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
485
498
  let rightDownX = 0;
486
499
  let rightDownY = 0;
487
500
  let rightMoved = false;
501
+ // ADR-046 — multi-select gesture state. A left-pointerdown becomes a
502
+ // MARQUEE CANDIDATE whenever (a) ⌘/Ctrl is held — ALWAYS, regardless of
503
+ // what's under the cursor, including the ground/baseplate (see
504
+ // onPointerDown's own comment on why that case specifically matters),
505
+ // or (b) no modifier AND the down point hit nothing at all. Committed
506
+ // to an actual marquee only once the pointer moves past the drag
507
+ // threshold (see `onPointerMove`) — released without moving, it's
508
+ // either a ⌘-click TOGGLE (if it hit something) or a plain miss-click
509
+ // deselect (if not), decided in `onPointerUp`. `pendingClickHit`
510
+ // remembers what the down point hit (if anything) for that decision.
511
+ let marqueeCandidate = false;
512
+ let marqueeActive = false;
513
+ let marqueeAdditive = false; // ⌘/Ctrl held during a marquee → ADD to the existing selection instead of replacing it
514
+ let marqueeStartX = 0;
515
+ let marqueeStartY = 0;
516
+ let modifierHeldAtDown = false;
517
+ let pendingClickHit = null;
488
518
  // Entity drag — Phase 1 of real editing (translate only, ground-plane
489
519
  // constrained). Grabbing on an entity moves it; grabbing empty space/sky
490
520
  // still orbits, same convention as Unity/Blender. Whether THIS gesture is
@@ -503,20 +533,163 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
503
533
  let dragPlane = null;
504
534
  let dragGrabOffset = null; // world-space, plane-point minus object position at grab time
505
535
  /**
506
- * Deselect whatever's selected in WORLD — marker/box hidden, gizmo
507
- * detached, and (new, 2026-10-07) the host told, since a miss-click used
508
- * to deselect visually but post nothing: the host's own `lastPick` kept
509
- * the stale prior selection forever, harmless only while the Inspector's
510
- * visibility was gated on a now-removed "world mode" flag rather than on
511
- * `lastPick` itself. Also called from the HUD click listener below (cross-
512
- * layer deselect — see this file's header comment on why only one of
513
- * World/HUD should ever look selected at once).
536
+ * ADR-046 — the ONE place that changes the world selection. Takes the
537
+ * COMPLETE new selection (not a delta) and does three things: (1) syncs
538
+ * every visual (gizmo/selectionBox for the 1-entity case, `multiBoxes`
539
+ * for 2+, all hidden for 0), (2) tells the host via the new
540
+ * `selectionChanged3d` message (every count, including 0 and 1 — the
541
+ * authoritative "what's selected" signal multi-select-aware features
542
+ * read), and (3) ALSO fires the EXISTING `pickPoint3d` message every
543
+ * time, with `entityId` set only for the exactly-one case and `null`
544
+ * otherwise (0 OR 2+) — "not a single clean pick." This is what keeps
545
+ * the single-entity Scene3DInspector correctly hidden for a 2+
546
+ * selection with ZERO new host-side logic: without firing `null` for
547
+ * the 2+ case too, the host's `lastPick` would stay stale at whatever
548
+ * WAS the lone selection right before a marquee/⌘-click grew it past
549
+ * one, and the Inspector would keep showing that old entity.
550
+ */
551
+ function applySelection(objs, clickPoint) {
552
+ const next = new Set(objs);
553
+ const uniqueObjs = [...next];
554
+ // Drop any extra box no longer in the selection, OR every extra box at
555
+ // all once the count drops to ≤1 (the singular `selectionBox` owns
556
+ // that case; a leftover `multiBoxes` entry would double-highlight).
557
+ for (const [obj, box] of Array.from(multiBoxes)) {
558
+ if (!next.has(obj) || next.size < 2) {
559
+ scene?.remove(box);
560
+ box.geometry.dispose();
561
+ box.material.dispose();
562
+ multiBoxes.delete(obj);
563
+ }
564
+ }
565
+ multiSelected = next;
566
+ if (next.size === 0) {
567
+ marker.visible = false;
568
+ selectionBox.visible = false;
569
+ gizmo.detach();
570
+ }
571
+ else if (next.size === 1) {
572
+ const obj = uniqueObjs[0];
573
+ gizmo.attach(obj, camera);
574
+ selectionBox.setFromObject(obj);
575
+ selectionBox.visible = true;
576
+ // A click carries a real surface point; a programmatic 1-entity
577
+ // selection (⌘-click toggling down to one, a marquee netting
578
+ // exactly one) doesn't — the marker just hides rather than showing
579
+ // a stale or fabricated point.
580
+ if (clickPoint) {
581
+ marker.position.copy(clickPoint);
582
+ marker.visible = true;
583
+ }
584
+ else
585
+ marker.visible = false;
586
+ }
587
+ else {
588
+ gizmo.detach();
589
+ selectionBox.visible = false;
590
+ marker.visible = false;
591
+ for (const obj of uniqueObjs) {
592
+ let box = multiBoxes.get(obj);
593
+ if (!box) {
594
+ box = new THREE.BoxHelper(obj, 0xffd23f);
595
+ box.renderOrder = 998;
596
+ box.material.depthTest = false;
597
+ scene?.add(box);
598
+ multiBoxes.set(obj, box);
599
+ }
600
+ box.setFromObject(obj);
601
+ }
602
+ }
603
+ const entityIds = uniqueObjs.map((o) => entityByObject.get(o)).filter((id) => !!id);
604
+ window.parent.postMessage({ type: 'umicat:editor:selectionChanged3d', entityIds }, '*');
605
+ // ALWAYS fires, not just for 0/1 — a 2+ selection has to post
606
+ // `entityId: null` too, or the host's single-entity `lastPick` would
607
+ // stay stale at whatever WAS the lone selection right before a
608
+ // marquee/⌘-click grew it past one (the Inspector would keep showing
609
+ // the old single entity instead of correctly hiding for a
610
+ // multi-selection).
611
+ {
612
+ const id = next.size === 1 ? (entityByObject.get(uniqueObjs[0]) ?? null) : null;
613
+ let p = clickPoint;
614
+ if (!p && next.size === 1)
615
+ p = uniqueObjs[0].getWorldPosition(new THREE.Vector3());
616
+ window.parent.postMessage({ type: 'umicat:editor:pickPoint3d', x: p?.x ?? 0, y: p?.y ?? 0, z: p?.z ?? 0, entityId: id }, '*');
617
+ }
618
+ }
619
+ /**
620
+ * Deselect whatever's selected in WORLD. Also called from the HUD click
621
+ * listener below (cross-layer deselect — see this file's header comment
622
+ * on why only one of World/HUD should ever look selected at once).
514
623
  */
515
624
  function clearWorldSelection() {
516
- marker.visible = false;
517
- selectionBox.visible = false;
518
- gizmo.detach();
519
- window.parent.postMessage({ type: 'umicat:editor:pickPoint3d', x: 0, y: 0, z: 0, entityId: null }, '*');
625
+ applySelection([]);
626
+ }
627
+ // ADR-046 — box-select. A plain `<div>` overlay (NOT a 3D object — this
628
+ // is pure screen-space UI, same reasoning a 2D editor's marquee would
629
+ // use), created lazily on first use and reused for the life of this
630
+ // player. `position: fixed` in viewport pixels matches `e.clientX/Y`
631
+ // directly — no coordinate conversion needed, since this editor's canvas
632
+ // already fills the viewport.
633
+ let marqueeEl = null;
634
+ function ensureMarqueeEl() {
635
+ if (marqueeEl)
636
+ return marqueeEl;
637
+ const el = document.createElement('div');
638
+ el.style.position = 'fixed';
639
+ el.style.border = '1px solid #4da3ff';
640
+ el.style.background = 'rgba(77,163,255,0.15)';
641
+ el.style.pointerEvents = 'none';
642
+ el.style.zIndex = '9999';
643
+ el.style.display = 'none';
644
+ document.body.appendChild(el);
645
+ marqueeEl = el;
646
+ return el;
647
+ }
648
+ function updateMarqueeRect(x1, y1, x2, y2) {
649
+ const el = ensureMarqueeEl();
650
+ el.style.display = 'block';
651
+ el.style.left = `${Math.min(x1, x2)}px`;
652
+ el.style.top = `${Math.min(y1, y2)}px`;
653
+ el.style.width = `${Math.abs(x2 - x1)}px`;
654
+ el.style.height = `${Math.abs(y2 - y1)}px`;
655
+ }
656
+ function hideMarqueeRect() {
657
+ if (marqueeEl)
658
+ marqueeEl.style.display = 'none';
659
+ }
660
+ /**
661
+ * ADR-046 — which entities a marquee rect nets. Tests each entity's
662
+ * WORLD-POSITION (its origin/pivot), projected to screen, for plain
663
+ * CONTAINMENT in the rect — not a full bounding-box/overlap test. This
664
+ * is a deliberate v1 simplification: a Part's pivot sitting inside the
665
+ * dragged rectangle is an unambiguous, easy-to-predict rule ("drag
666
+ * around the things you want"), whereas a full AABB-overlap test would
667
+ * also select anything merely GRAZED by the rect's edge — arguably more
668
+ * "correct" for a large or partially-covered mesh, but a materially
669
+ * bigger and more failure-prone computation (8-corner projection,
670
+ * near-plane clipping per corner) for a benefit that doesn't matter for
671
+ * the small, discrete Parts this feature is built around. Worth
672
+ * revisiting if real use shows pivot-containment missing things people
673
+ * expected to net.
674
+ */
675
+ function selectEntitiesInScreenRect(x1, y1, x2, y2) {
676
+ const left = Math.min(x1, x2);
677
+ const right = Math.max(x1, x2);
678
+ const top = Math.min(y1, y2);
679
+ const bottom = Math.max(y1, y2);
680
+ const worldPos = new THREE.Vector3();
681
+ const camSpace = new THREE.Vector3();
682
+ const hits = [];
683
+ for (const obj of objectByEntity.values()) {
684
+ obj.getWorldPosition(worldPos);
685
+ camSpace.copy(worldPos).applyMatrix4(camera.matrixWorldInverse);
686
+ if (camSpace.z > -camera.near)
687
+ continue; // behind the camera (or inside the near clip) — not actually visible, don't net it
688
+ const screen = worldToClientXY(worldPos);
689
+ if (screen.x >= left && screen.x <= right && screen.y >= top && screen.y <= bottom)
690
+ hits.push(obj);
691
+ }
692
+ return hits;
520
693
  }
521
694
  let gizmoDrag = null;
522
695
  const beginGizmoDrag = (hit, e) => {
@@ -643,7 +816,13 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
643
816
  moved = false;
644
817
  if (!scene)
645
818
  return;
646
- if (gizmo.attached) {
819
+ // ADR-046 — ⌘/Ctrl held: never starts ANY drag (gizmo, single-entity,
820
+ // OR gizmo-hit-test) — the modifier means "I'm multi-selecting," and
821
+ // deciding what that click actually DOES (toggle one entity, or start
822
+ // a marquee-ADD) has to wait for release, so a ⌘-drag that moved the
823
+ // pointer doesn't get misread as a toggle (see onPointerUp).
824
+ modifierHeldAtDown = e.metaKey || e.ctrlKey;
825
+ if (!modifierHeldAtDown && gizmo.attached) {
647
826
  raycaster.setFromCamera(ndcFromEvent(e), camera);
648
827
  const gizmoHit = gizmo.hitTest(raycaster);
649
828
  if (gizmoHit && beginGizmoDrag(gizmoHit, e)) {
@@ -667,12 +846,46 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
667
846
  }
668
847
  }
669
848
  const hit = pickEntityAt(e);
670
- // Empty space: a left-drag here is a no-op now (Roblox scheme — rotate
671
- // lives on the right button; OrbitControls' LEFT binding is null, so
672
- // there's nothing left to fall through to). Reserved for a future
673
- // marquee-select, not built yet.
674
- if (!hit)
849
+ if (modifierHeldAtDown) {
850
+ // ⌘/Ctrl held — ALWAYS a selection gesture: toggle-on-click (decided
851
+ // on release, below, if the pointer never moved) or marquee-ADD on
852
+ // drag, regardless of what's under the cursor. Deliberately NOT
853
+ // gated on `!hit` the way the non-modifier marquee below is — a
854
+ // baseplate-style scene's ground is itself a real, registered
855
+ // `Entity3D` (see `template-3d-baseplate` — the SAME plane primitive
856
+ // this fixture's own "ground" entity uses) that can cover the ENTIRE
857
+ // viewport, leaving no truly empty pixel to start a plain marquee
858
+ // from. The modifier is what makes box-select reachable on such a
859
+ // scene at all — the alternative (treating it as a no-op) would
860
+ // make Phase 3a's whole feature unreachable there.
861
+ pendingClickHit = hit;
862
+ marqueeCandidate = true;
863
+ marqueeAdditive = true;
864
+ marqueeStartX = e.clientX;
865
+ marqueeStartY = e.clientY;
866
+ try {
867
+ renderer.domElement.setPointerCapture(e.pointerId);
868
+ }
869
+ catch { /* enhancement only */ }
870
+ return;
871
+ }
872
+ if (!hit) {
873
+ // Empty space, no modifier — might become a marquee that REPLACES
874
+ // the selection; committed only once the pointer actually moves
875
+ // (see onPointerMove). A plain miss-click (no movement) still just
876
+ // deselects, same as before marquee-select existed.
877
+ marqueeCandidate = true;
878
+ marqueeAdditive = false;
879
+ marqueeStartX = e.clientX;
880
+ marqueeStartY = e.clientY;
881
+ try {
882
+ renderer.domElement.setPointerCapture(e.pointerId);
883
+ }
884
+ catch { /* enhancement only */ }
675
885
  return;
886
+ }
887
+ marqueeCandidate = false;
888
+ pendingClickHit = null;
676
889
  const objectPos = hit.entityRoot.getWorldPosition(new THREE.Vector3());
677
890
  const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -objectPos.y);
678
891
  const planePoint = new THREE.Vector3();
@@ -716,6 +929,16 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
716
929
  return;
717
930
  if (Math.abs(e.clientX - downX) > 4 || Math.abs(e.clientY - downY) > 4)
718
931
  moved = true;
932
+ if (marqueeCandidate) {
933
+ // Not yet committed to a marquee until the pointer actually moves —
934
+ // a plain miss-click (released with `moved` still false) stays a
935
+ // deselect, decided in onPointerUp.
936
+ if (!moved)
937
+ return;
938
+ marqueeActive = true;
939
+ updateMarqueeRect(marqueeStartX, marqueeStartY, e.clientX, e.clientY);
940
+ return;
941
+ }
719
942
  if (gizmoDrag) {
720
943
  raycaster.setFromCamera(ndcFromEvent(e), camera);
721
944
  updateGizmoDrag(e);
@@ -762,12 +985,15 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
762
985
  }
763
986
  if (hudSelectedId)
764
987
  selectHudEntity(null);
765
- marker.position.copy(hit.point);
766
- marker.visible = true;
767
- selectionBox.setFromObject(hit.entityRoot);
768
- selectionBox.visible = true;
769
- gizmo.attach(hit.entityRoot, camera);
770
- window.parent.postMessage({ type: 'umicat:editor:pickPoint3d', x: hit.point.x, y: hit.point.y, z: hit.point.z, entityId: hit.entityId }, '*');
988
+ // ADR-046 — right-clicking an entity that's ALREADY part of a
989
+ // multi-selection keeps the WHOLE selection, so the menu acts on all
990
+ // of them (explorer-style: right-clicking one of several selected
991
+ // items doesn't collapse the selection to one). Right-clicking
992
+ // anything else collapses to just that one, same as a plain
993
+ // left-click already does.
994
+ if (!(multiSelected.size >= 2 && multiSelected.has(hit.entityRoot))) {
995
+ applySelection([hit.entityRoot], hit.point);
996
+ }
771
997
  window.parent.postMessage({ type: 'umicat:editor:contextMenu3d', entityId: hit.entityId, clientX: e.clientX, clientY: e.clientY }, '*');
772
998
  return;
773
999
  }
@@ -815,10 +1041,60 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
815
1041
  dragPlane = null;
816
1042
  dragGrabOffset = null;
817
1043
  controls.enabled = true;
1044
+ // ADR-046 — marquee/toggle finalize. Reachable whenever the
1045
+ // pointerdown either hit empty space (no modifier) OR had the
1046
+ // modifier held at all (see onPointerDown — both set
1047
+ // `marqueeCandidate`). Three outcomes, by what actually happened:
1048
+ // (1) it became an active drag → marquee select/add; (2) modifier
1049
+ // held, no drag → toggle whatever was under the cursor at down (can
1050
+ // be nothing, if that was empty space too); (3) no modifier, no drag
1051
+ // → plain miss-click deselect, exactly as before marquee existed.
1052
+ if (marqueeCandidate) {
1053
+ marqueeCandidate = false;
1054
+ if (marqueeActive) {
1055
+ marqueeActive = false;
1056
+ hideMarqueeRect();
1057
+ const hits = selectEntitiesInScreenRect(marqueeStartX, marqueeStartY, e.clientX, e.clientY);
1058
+ if (marqueeAdditive) {
1059
+ const next = new Set(multiSelected);
1060
+ for (const h of hits)
1061
+ next.add(h);
1062
+ applySelection([...next]);
1063
+ }
1064
+ else {
1065
+ applySelection(hits);
1066
+ }
1067
+ if (hudSelectedId)
1068
+ selectHudEntity(null);
1069
+ }
1070
+ else if (modifierHeldAtDown && pendingClickHit) {
1071
+ const obj = pendingClickHit.entityRoot;
1072
+ const next = new Set(multiSelected);
1073
+ if (next.has(obj))
1074
+ next.delete(obj);
1075
+ else
1076
+ next.add(obj);
1077
+ applySelection([...next], pendingClickHit.point);
1078
+ if (hudSelectedId)
1079
+ selectHudEntity(null);
1080
+ }
1081
+ else if (!modifierHeldAtDown && scene) {
1082
+ clearWorldSelection();
1083
+ if (hudSelectedId)
1084
+ selectHudEntity(null);
1085
+ }
1086
+ // The remaining case — modifier held, no drag, no hit (⌘-click on
1087
+ // truly empty space) — is intentionally a no-op: nothing to toggle,
1088
+ // and the modifier means "don't blow away my selection" anyway.
1089
+ modifierHeldAtDown = false;
1090
+ pendingClickHit = null;
1091
+ return;
1092
+ }
818
1093
  if (moved || !scene)
819
1094
  return;
820
- // A plain click (no drag) — the existing read-a-coordinate behavior,
821
- // plus attaching/detaching the transform gizmo to match selection.
1095
+ // A plain click (no drag, no modifier) — collapses the selection to
1096
+ // just the clicked entity (or clears it), same as every pre-multi-
1097
+ // select click already did.
822
1098
  const hit = pickEntityAt(e);
823
1099
  if (!hit) {
824
1100
  // Clicked empty space with nothing grabbed — deselect. Previously a
@@ -831,16 +1107,7 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
831
1107
  }
832
1108
  if (hudSelectedId)
833
1109
  selectHudEntity(null); // cross-layer deselect
834
- marker.position.copy(hit.point);
835
- marker.visible = true;
836
- // Frame the whole entity the click landed on, not just the point on its
837
- // surface — `setFromObject` walks the root's full subtree, so a
838
- // multi-mesh entity (a model with separate parts) gets one box around
839
- // all of it, matching what "entityId" actually refers to.
840
- selectionBox.setFromObject(hit.entityRoot);
841
- selectionBox.visible = true;
842
- gizmo.attach(hit.entityRoot, camera);
843
- window.parent.postMessage({ type: 'umicat:editor:pickPoint3d', x: hit.point.x, y: hit.point.y, z: hit.point.z, entityId: hit.entityId }, '*');
1110
+ applySelection([hit.entityRoot], hit.point);
844
1111
  };
845
1112
  renderer.domElement.addEventListener('pointerdown', onPointerDown);
846
1113
  renderer.domElement.addEventListener('pointermove', onPointerMove);
@@ -1091,14 +1358,26 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
1091
1358
  entityByObject.delete(object);
1092
1359
  entityByObject.set(fresh, m.entityId);
1093
1360
  objectByEntity.set(m.entityId, fresh);
1094
- // Same "gizmo attachment IS the selection state" convention the
1095
- // position/rotation/scale branch above already relies on — there is
1096
- // no separate "currently selected" variable to update.
1361
+ // Same object-instance swap the position/rotation/scale branch
1362
+ // above already handles for the single-select visuals — `object`
1363
+ // itself is being replaced, so anything keyed by the OLD instance
1364
+ // (gizmo attachment, AND now `multiSelected`/`multiBoxes` — ADR-046)
1365
+ // has to move to `fresh` or it silently points at a disposed object.
1097
1366
  if (gizmo.attached === object) {
1098
1367
  gizmo.detach();
1099
1368
  gizmo.attach(fresh, camera);
1100
1369
  selectionBox.setFromObject(fresh);
1101
1370
  }
1371
+ if (multiSelected.has(object)) {
1372
+ multiSelected.delete(object);
1373
+ multiSelected.add(fresh);
1374
+ const box = multiBoxes.get(object);
1375
+ if (box) {
1376
+ multiBoxes.delete(object);
1377
+ multiBoxes.set(fresh, box);
1378
+ box.setFromObject(fresh);
1379
+ }
1380
+ }
1102
1381
  object = fresh;
1103
1382
  }
1104
1383
  done();
@@ -1358,10 +1637,13 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
1358
1637
  }
1359
1638
  if (gizmoDrag && gizmo.attached === object)
1360
1639
  gizmoDrag = null;
1361
- if (gizmo.attached === object) {
1362
- gizmo.detach();
1363
- marker.visible = false;
1364
- selectionBox.visible = false;
1640
+ // ADR-046 — if the deleted entity was selected (single OR part of a
1641
+ // multi-selection), route the shrunk selection back through
1642
+ // `applySelection` rather than hand-rolling the gizmo/box cleanup here
1643
+ // — that's the one place all of it (including re-attaching the gizmo
1644
+ // if this drops a 2-selection down to 1) already lives.
1645
+ if (gizmo.attached === object || multiSelected.has(object)) {
1646
+ applySelection([...multiSelected].filter((o) => o !== object));
1365
1647
  }
1366
1648
  scene?.remove(object);
1367
1649
  disposeObjectTree(object);
@@ -1404,44 +1686,42 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
1404
1686
  const target = e.target;
1405
1687
  if (target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable))
1406
1688
  return;
1407
- if (e.key === 'Delete' && gizmo.attached) {
1408
- const entityId = entityByObject.get(gizmo.attached);
1409
- if (entityId) {
1410
- e.preventDefault();
1689
+ // ADR-046 — these all now read `multiSelected` (the authoritative
1690
+ // selection set), not `gizmo.attached` — the gizmo is DETACHED
1691
+ // whenever 2+ entities are selected (no shared-pivot gizmo yet, Phase
1692
+ // 3b), so reading `gizmo.attached` alone would silently do nothing
1693
+ // for a multi-selection. `gizmo.attached` is always a MEMBER of
1694
+ // `multiSelected` when exactly one entity is selected (the invariant
1695
+ // `applySelection` maintains), so this is a pure generalization, not a
1696
+ // behavior change for the single-select case.
1697
+ const selectedIds = () => [...multiSelected].map((o) => entityByObject.get(o)).filter((id) => !!id);
1698
+ if (e.key === 'Delete' && multiSelected.size > 0) {
1699
+ e.preventDefault();
1700
+ for (const entityId of selectedIds())
1411
1701
  void onDeleteEntity3d({ entityId });
1412
- }
1413
1702
  }
1414
1703
  else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'z') {
1415
1704
  e.preventDefault();
1416
1705
  window.parent.postMessage({ type: 'umicat:editor:requestUndo3d' }, '*');
1417
1706
  }
1418
- else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'c' && gizmo.attached) {
1707
+ else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'c' && multiSelected.size > 0) {
1419
1708
  // ADR-045 — same "ask, don't act" shape as Undo above: the CLIPBOARD
1420
1709
  // lives on the host (Copy is a pure read of the host's own scene
1421
1710
  // copy), so this player can't act on it locally the way Delete does.
1422
- const entityId = entityByObject.get(gizmo.attached);
1423
- if (entityId) {
1424
- e.preventDefault();
1425
- window.parent.postMessage({ type: 'umicat:editor:requestCopy3d', entityId }, '*');
1426
- }
1711
+ e.preventDefault();
1712
+ window.parent.postMessage({ type: 'umicat:editor:requestCopy3d', entityIds: selectedIds() }, '*');
1427
1713
  }
1428
- else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'x' && gizmo.attached) {
1429
- const entityId = entityByObject.get(gizmo.attached);
1430
- if (entityId) {
1431
- e.preventDefault();
1432
- window.parent.postMessage({ type: 'umicat:editor:requestCut3d', entityId }, '*');
1433
- }
1714
+ else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'x' && multiSelected.size > 0) {
1715
+ e.preventDefault();
1716
+ window.parent.postMessage({ type: 'umicat:editor:requestCut3d', entityIds: selectedIds() }, '*');
1434
1717
  }
1435
1718
  else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'v') {
1436
1719
  e.preventDefault();
1437
1720
  window.parent.postMessage({ type: 'umicat:editor:requestPaste3d' }, '*');
1438
1721
  }
1439
- else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'd' && gizmo.attached) {
1440
- const entityId = entityByObject.get(gizmo.attached);
1441
- if (entityId) {
1442
- e.preventDefault();
1443
- window.parent.postMessage({ type: 'umicat:editor:requestDuplicate3d', entityId }, '*');
1444
- }
1722
+ else if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'd' && multiSelected.size > 0) {
1723
+ e.preventDefault();
1724
+ window.parent.postMessage({ type: 'umicat:editor:requestDuplicate3d', entityIds: selectedIds() }, '*');
1445
1725
  }
1446
1726
  });
1447
1727
  // WASD/QE fly-camera + Shift speed boost — held-STATE, not a discrete
@@ -1575,6 +1855,13 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
1575
1855
  selectionBox.visible = false;
1576
1856
  scene.add(selectionBox);
1577
1857
  scene.add(gizmo.root);
1858
+ // ADR-046 — a (re)load tears down the whole scene graph; any
1859
+ // multi-select boxes from a PRIOR scene were added to that scene, not
1860
+ // this one, and the objects they tracked are gone. No disposal loop
1861
+ // needed here (nothing in the new scene references them) — just drop
1862
+ // the stale bookkeeping.
1863
+ multiSelected = new Set();
1864
+ multiBoxes.clear();
1578
1865
  // Frame the whole scene — auto-fit, since a small template scene and a
1579
1866
  // real level's dozens of entities need wildly different orbit distances.
1580
1867
  const box = new THREE.Box3().setFromObject(scene);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/three-sdk",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Three.js runtime for Umicat games: the scene3d design format, its loader with physics, a kinematic character controller, and the Umicat platform via @umicat/platform-sdk.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",