@umicat/three-sdk 1.11.0 → 1.12.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.
@@ -726,32 +726,48 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
726
726
  const obj = gizmo.attached;
727
727
  if (!obj)
728
728
  return false;
729
- // ADR-046 Phase 3b — per-axis scale is REFUSED on the shared pivot.
730
- // Scaling a rotated object along a single WORLD axis doesn't commute
731
- // with its own (possibly different) rotation the way UNIFORM scaling
732
- // does — the uniform "xyz" center handle stays exact regardless of
733
- // each member's orientation, a per-axis handle would silently be
734
- // wrong for anything not world-axis-aligned. Only the uniform handle
735
- // is reachable for a 2+ selection; the per-axis ring/arrow handles
736
- // simply don't begin a drag at all.
737
- if (obj === groupPivot && hit.mode === 'scale' && hit.axis !== 'xyz')
738
- return false;
739
729
  const worldPos = obj.getWorldPosition(new THREE.Vector3());
740
730
  // Snapshots every selected real entity's WORLD-space starting
741
731
  // transform, for `updateGizmoDrag` to re-derive each one's CURRENT
742
732
  // transform from (its own start + this frame's pivot delta) rather
743
- // than compounding frame-over-frame.
744
- const beginGroupSnapshot = () => {
733
+ // than compounding frame-over-frame. `worldAxisDir`, when given (a
734
+ // per-axis scale drag only — move/rotate pass nothing), is what each
735
+ // member's `nearestLocalAxisIndex` is computed against.
736
+ const AXIS_UNIT_VECTORS = [new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 1, 0), new THREE.Vector3(0, 0, 1)];
737
+ const beginGroupSnapshot = (worldAxisDir) => {
745
738
  if (obj !== groupPivot)
746
739
  return;
747
740
  const members = [];
748
741
  for (const m of multiSelected) {
742
+ const worldQuat = m.getWorldQuaternion(new THREE.Quaternion());
743
+ let nearestLocalAxisIndex = 0;
744
+ if (worldAxisDir) {
745
+ // ADR-046 Phase 3b.1 — "scale this member along whichever of
746
+ // ITS OWN local axes best matches the dragged world axis," the
747
+ // same nearest-matching-axis approximation real DCCs use for a
748
+ // multi-object per-axis scale when members aren't all
749
+ // world-axis-aligned: a literal world-space stretch of an
750
+ // arbitrarily rotated rigid box would require shear, which a
751
+ // Part-style position+scale (no shear component) can't store,
752
+ // so SOME approximation is unavoidable — this is the simplest
753
+ // one (snap to the best-aligned axis), not a continuous
754
+ // decomposition that would blend as rotation increases.
755
+ let best = -Infinity;
756
+ for (let i = 0; i < 3; i++) {
757
+ const score = Math.abs(AXIS_UNIT_VECTORS[i].clone().applyQuaternion(worldQuat).dot(worldAxisDir));
758
+ if (score > best) {
759
+ best = score;
760
+ nearestLocalAxisIndex = i;
761
+ }
762
+ }
763
+ }
749
764
  members.push({
750
765
  obj: m,
751
766
  startWorldPos: m.getWorldPosition(new THREE.Vector3()),
752
- startWorldQuat: m.getWorldQuaternion(new THREE.Quaternion()),
767
+ startWorldQuat: worldQuat,
753
768
  startLocalScale: m.scale.clone(),
754
769
  parentWorldQuatInverse: m.parent ? m.parent.getWorldQuaternion(new THREE.Quaternion()).invert() : new THREE.Quaternion(),
770
+ nearestLocalAxisIndex,
755
771
  });
756
772
  }
757
773
  groupDrag = {
@@ -779,7 +795,7 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
779
795
  if (Math.abs(startSignedDistance) < 1e-4)
780
796
  return false; // grabbed essentially at the origin — no stable ratio
781
797
  gizmoDrag = { mode: 'scale', axis: hit.axis, lineOrigin: worldPos.clone(), lineDir, startSignedDistance, startScale: obj.scale.clone() };
782
- beginGroupSnapshot();
798
+ beginGroupSnapshot(lineDir);
783
799
  return true;
784
800
  }
785
801
  if (hit.mode === 'scale' && hit.axis === 'xyz') {
@@ -839,14 +855,35 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
839
855
  const signedDistance = grab.clone().sub(gizmoDrag.lineOrigin).dot(gizmoDrag.lineDir);
840
856
  const ratio = THREE.MathUtils.clamp(signedDistance / gizmoDrag.startSignedDistance, 0.02, 50);
841
857
  const { axis, startScale } = gizmoDrag;
842
- // Per-axis scale never reaches a group drag — `beginGizmoDrag`
843
- // refuses it on the pivot — so no member-propagation needed here.
844
858
  if (axis === 'x')
845
859
  obj.scale.x = startScale.x * ratio;
846
860
  else if (axis === 'y')
847
861
  obj.scale.y = startScale.y * ratio;
848
862
  else
849
863
  obj.scale.z = startScale.z * ratio;
864
+ // ADR-046 Phase 3b.1 — group members: scale each member's own
865
+ // NEAREST local axis (picked once at drag-begin, per
866
+ // `nearestLocalAxisIndex`) by the ratio, and scale only the
867
+ // component of its pivot-offset PARALLEL to the dragged world
868
+ // axis (the position math is unambiguous regardless of rotation —
869
+ // only "which of the member's own scale components" needed the
870
+ // nearest-axis approximation).
871
+ if (groupDrag) {
872
+ const worldAxisDir = gizmoDrag.lineDir;
873
+ for (const member of groupDrag.members) {
874
+ const offset = member.startWorldPos.clone().sub(groupDrag.pivotStartPos);
875
+ const along = offset.dot(worldAxisDir);
876
+ const parallel = worldAxisDir.clone().multiplyScalar(along);
877
+ const perp = offset.clone().sub(parallel);
878
+ const memberWorldPos = groupDrag.pivotStartPos.clone().add(perp).add(parallel.multiplyScalar(ratio));
879
+ if (member.obj.parent)
880
+ member.obj.parent.worldToLocal(memberWorldPos);
881
+ member.obj.position.copy(memberWorldPos);
882
+ const i = member.nearestLocalAxisIndex;
883
+ member.obj.scale.setComponent(i, member.startLocalScale.getComponent(i) * ratio);
884
+ multiBoxes.get(member.obj)?.setFromObject(member.obj);
885
+ }
886
+ }
850
887
  }
851
888
  else if (gizmoDrag.mode === 'scale' && gizmoDrag.axis === 'xyz') {
852
889
  const currentScreenDistance = Math.hypot(e.clientX - gizmoDrag.originScreen.x, e.clientY - gizmoDrag.originScreen.y);
@@ -1149,6 +1186,25 @@ export async function runEditorDesignPlayer3D(renderer, opts = {}) {
1149
1186
  }
1150
1187
  }
1151
1188
  }
1189
+ // ADR-046 Phase 3b.1 — the pivot's rotation/scale are reset back
1190
+ // to identity/1 the instant the drag ends, not just when the
1191
+ // SELECTION changes. A rotate drag necessarily leaves the pivot
1192
+ // itself rotated (that's how its delta is computed), and a scale
1193
+ // drag leaves it scaled — if either stuck around into the NEXT
1194
+ // gesture, `axisDirectionWorld('x')` (used both for rendering the
1195
+ // handles AND for Phase 3b.1's own nearest-matching-axis per-axis
1196
+ // scale math) would resolve against the PIVOT's stale leftover
1197
+ // rotation instead of true world space, corrupting an
1198
+ // immediately-following per-axis scale with no visible symptom
1199
+ // beyond "the wrong member axis changed" — exactly the bug this
1200
+ // reset fixes. The pivot's POSITION is never reset here — move/
1201
+ // rotate/scale all keep it exactly at the true centroid
1202
+ // throughout (rotating and uniform-scaling around the centroid
1203
+ // can't move it; a translate moves it by the same amount the
1204
+ // members moved, which IS the new centroid).
1205
+ groupPivot.quaternion.identity();
1206
+ groupPivot.scale.set(1, 1, 1);
1207
+ gizmo.update(camera);
1152
1208
  groupDrag = null;
1153
1209
  gizmoDrag = null;
1154
1210
  controls.enabled = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umicat/three-sdk",
3
- "version": "1.11.0",
3
+ "version": "1.12.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",