three-stdlib 2.25.1 → 2.26.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.
@@ -22,6 +22,7 @@ declare class OrbitControls extends EventDispatcher {
22
22
  panSpeed: number;
23
23
  screenSpacePanning: boolean;
24
24
  keyPanSpeed: number;
25
+ zoomToCursor: boolean;
25
26
  autoRotate: boolean;
26
27
  autoRotateSpeed: number;
27
28
  reverseOrbit: boolean;
package/index.cjs CHANGED
@@ -890,7 +890,7 @@ const Visible = 0;
890
890
  const Deleted = 1;
891
891
  const _v1$5 = /* @__PURE__ */ new THREE.Vector3();
892
892
  const _line3 = /* @__PURE__ */ new THREE.Line3();
893
- const _plane$1 = /* @__PURE__ */ new THREE.Plane();
893
+ const _plane$2 = /* @__PURE__ */ new THREE.Plane();
894
894
  const _closestPoint$1 = /* @__PURE__ */ new THREE.Vector3();
895
895
  const _triangle = /* @__PURE__ */ new THREE.Triangle();
896
896
  class ConvexHull {
@@ -1127,11 +1127,11 @@ class ConvexHull {
1127
1127
  }
1128
1128
  }
1129
1129
  maxDistance = -1;
1130
- _plane$1.setFromCoplanarPoints(v0.point, v12.point, v2.point);
1130
+ _plane$2.setFromCoplanarPoints(v0.point, v12.point, v2.point);
1131
1131
  for (let i2 = 0, l = this.vertices.length; i2 < l; i2++) {
1132
1132
  const vertex = vertices[i2];
1133
1133
  if (vertex !== v0 && vertex !== v12 && vertex !== v2) {
1134
- const distance = Math.abs(_plane$1.distanceToPoint(vertex.point));
1134
+ const distance = Math.abs(_plane$2.distanceToPoint(vertex.point));
1135
1135
  if (distance > maxDistance) {
1136
1136
  maxDistance = distance;
1137
1137
  v3 = vertex;
@@ -1139,7 +1139,7 @@ class ConvexHull {
1139
1139
  }
1140
1140
  }
1141
1141
  const faces = [];
1142
- if (_plane$1.distanceToPoint(v3.point) < 0) {
1142
+ if (_plane$2.distanceToPoint(v3.point) < 0) {
1143
1143
  faces.push(Face$1.create(v0, v12, v2), Face$1.create(v3, v12, v0), Face$1.create(v3, v2, v12), Face$1.create(v3, v0, v2));
1144
1144
  for (let i2 = 0; i2 < 3; i2++) {
1145
1145
  const j = (i2 + 1) % 3;
@@ -21468,7 +21468,7 @@ class ImprovedNoise {
21468
21468
  }
21469
21469
  const _v1$2 = /* @__PURE__ */ new THREE.Vector3();
21470
21470
  const _v2$2 = /* @__PURE__ */ new THREE.Vector3();
21471
- const _plane = /* @__PURE__ */ new THREE.Plane();
21471
+ const _plane$1 = /* @__PURE__ */ new THREE.Plane();
21472
21472
  const _line1 = /* @__PURE__ */ new THREE.Line3();
21473
21473
  const _line2 = /* @__PURE__ */ new THREE.Line3();
21474
21474
  const _sphere$1 = /* @__PURE__ */ new THREE.Sphere();
@@ -21555,16 +21555,16 @@ class Octree {
21555
21555
  return triangles;
21556
21556
  }
21557
21557
  triangleCapsuleIntersect(capsule, triangle) {
21558
- triangle.getPlane(_plane);
21559
- const d1 = _plane.distanceToPoint(capsule.start) - capsule.radius;
21560
- const d2 = _plane.distanceToPoint(capsule.end) - capsule.radius;
21558
+ triangle.getPlane(_plane$1);
21559
+ const d1 = _plane$1.distanceToPoint(capsule.start) - capsule.radius;
21560
+ const d2 = _plane$1.distanceToPoint(capsule.end) - capsule.radius;
21561
21561
  if (d1 > 0 && d2 > 0 || d1 < -capsule.radius && d2 < -capsule.radius) {
21562
21562
  return false;
21563
21563
  }
21564
21564
  const delta = Math.abs(d1 / (Math.abs(d1) + Math.abs(d2)));
21565
21565
  const intersectPoint = _v1$2.copy(capsule.start).lerp(capsule.end, delta);
21566
21566
  if (triangle.containsPoint(intersectPoint)) {
21567
- return { normal: _plane.normal.clone(), point: intersectPoint.clone(), depth: Math.abs(Math.min(d1, d2)) };
21567
+ return { normal: _plane$1.normal.clone(), point: intersectPoint.clone(), depth: Math.abs(Math.min(d1, d2)) };
21568
21568
  }
21569
21569
  const r2 = capsule.radius * capsule.radius;
21570
21570
  const line1 = _line1.set(capsule.start, capsule.end);
@@ -21587,17 +21587,17 @@ class Octree {
21587
21587
  return false;
21588
21588
  }
21589
21589
  triangleSphereIntersect(sphere, triangle) {
21590
- triangle.getPlane(_plane);
21591
- if (!sphere.intersectsPlane(_plane))
21590
+ triangle.getPlane(_plane$1);
21591
+ if (!sphere.intersectsPlane(_plane$1))
21592
21592
  return false;
21593
- const depth = Math.abs(_plane.distanceToSphere(sphere));
21593
+ const depth = Math.abs(_plane$1.distanceToSphere(sphere));
21594
21594
  const r2 = sphere.radius * sphere.radius - depth * depth;
21595
- const plainPoint = _plane.projectPoint(sphere.center, _v1$2);
21595
+ const plainPoint = _plane$1.projectPoint(sphere.center, _v1$2);
21596
21596
  if (triangle.containsPoint(sphere.center)) {
21597
21597
  return {
21598
- normal: _plane.normal.clone(),
21598
+ normal: _plane$1.normal.clone(),
21599
21599
  point: plainPoint.clone(),
21600
- depth: Math.abs(_plane.distanceToSphere(sphere))
21600
+ depth: Math.abs(_plane$1.distanceToSphere(sphere))
21601
21601
  };
21602
21602
  }
21603
21603
  const lines = [
@@ -24716,6 +24716,9 @@ class TrackballControls extends THREE.EventDispatcher {
24716
24716
  this.update();
24717
24717
  }
24718
24718
  }
24719
+ const _ray$2 = /* @__PURE__ */ new THREE.Ray();
24720
+ const _plane = /* @__PURE__ */ new THREE.Plane();
24721
+ const TILT_LIMIT = Math.cos(70 * THREE.MathUtils.DEG2RAD);
24719
24722
  const moduloWrapAround = (offset, capacity) => (offset % capacity + capacity) % capacity;
24720
24723
  class OrbitControls extends THREE.EventDispatcher {
24721
24724
  constructor(object, domElement) {
@@ -24762,6 +24765,7 @@ class OrbitControls extends THREE.EventDispatcher {
24762
24765
  // if false, pan orthogonal to world-space direction camera.up
24763
24766
  __publicField(this, "keyPanSpeed", 7);
24764
24767
  // pixels moved per arrow key push
24768
+ __publicField(this, "zoomToCursor", false);
24765
24769
  // Set to true to automatically rotate around the target
24766
24770
  // If auto-rotate is enabled, you must call controls.update() in your animation loop
24767
24771
  __publicField(this, "autoRotate", false);
@@ -24910,13 +24914,16 @@ class OrbitControls extends THREE.EventDispatcher {
24910
24914
  }
24911
24915
  spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
24912
24916
  spherical.makeSafe();
24913
- spherical.radius *= scale;
24914
- spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
24915
24917
  if (scope.enableDamping === true) {
24916
24918
  scope.target.addScaledVector(panOffset, scope.dampingFactor);
24917
24919
  } else {
24918
24920
  scope.target.add(panOffset);
24919
24921
  }
24922
+ if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) {
24923
+ spherical.radius = clampDistance(spherical.radius);
24924
+ } else {
24925
+ spherical.radius = clampDistance(spherical.radius * scale);
24926
+ }
24920
24927
  offset.setFromSpherical(spherical);
24921
24928
  offset.applyQuaternion(quatInverse);
24922
24929
  position.copy(scope.target).add(offset);
@@ -24929,7 +24936,51 @@ class OrbitControls extends THREE.EventDispatcher {
24929
24936
  sphericalDelta.set(0, 0, 0);
24930
24937
  panOffset.set(0, 0, 0);
24931
24938
  }
24939
+ let zoomChanged = false;
24940
+ if (scope.zoomToCursor && performCursorZoom) {
24941
+ let newRadius = null;
24942
+ if (scope.object instanceof THREE.PerspectiveCamera && scope.object.isPerspectiveCamera) {
24943
+ const prevRadius = offset.length();
24944
+ newRadius = clampDistance(prevRadius * scale);
24945
+ const radiusDelta = prevRadius - newRadius;
24946
+ scope.object.position.addScaledVector(dollyDirection, radiusDelta);
24947
+ scope.object.updateMatrixWorld();
24948
+ } else if (scope.object.isOrthographicCamera) {
24949
+ const mouseBefore = new THREE.Vector3(mouse.x, mouse.y, 0);
24950
+ mouseBefore.unproject(scope.object);
24951
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
24952
+ scope.object.updateProjectionMatrix();
24953
+ zoomChanged = true;
24954
+ const mouseAfter = new THREE.Vector3(mouse.x, mouse.y, 0);
24955
+ mouseAfter.unproject(scope.object);
24956
+ scope.object.position.sub(mouseAfter).add(mouseBefore);
24957
+ scope.object.updateMatrixWorld();
24958
+ newRadius = offset.length();
24959
+ } else {
24960
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
24961
+ scope.zoomToCursor = false;
24962
+ }
24963
+ if (newRadius !== null) {
24964
+ if (scope.screenSpacePanning) {
24965
+ scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position);
24966
+ } else {
24967
+ _ray$2.origin.copy(scope.object.position);
24968
+ _ray$2.direction.set(0, 0, -1).transformDirection(scope.object.matrix);
24969
+ if (Math.abs(scope.object.up.dot(_ray$2.direction)) < TILT_LIMIT) {
24970
+ object.lookAt(scope.target);
24971
+ } else {
24972
+ _plane.setFromNormalAndCoplanarPoint(scope.object.up, scope.target);
24973
+ _ray$2.intersectPlane(_plane, scope.target);
24974
+ }
24975
+ }
24976
+ }
24977
+ } else if (scope.object instanceof THREE.OrthographicCamera && scope.object.isOrthographicCamera) {
24978
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
24979
+ scope.object.updateProjectionMatrix();
24980
+ zoomChanged = true;
24981
+ }
24932
24982
  scale = 1;
24983
+ performCursorZoom = false;
24933
24984
  if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS2 || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS2) {
24934
24985
  scope.dispatchEvent(changeEvent);
24935
24986
  lastPosition.copy(scope.object.position);
@@ -24985,7 +25036,6 @@ class OrbitControls extends THREE.EventDispatcher {
24985
25036
  const sphericalDelta = new THREE.Spherical();
24986
25037
  let scale = 1;
24987
25038
  const panOffset = new THREE.Vector3();
24988
- let zoomChanged = false;
24989
25039
  const rotateStart = new THREE.Vector2();
24990
25040
  const rotateEnd = new THREE.Vector2();
24991
25041
  const rotateDelta = new THREE.Vector2();
@@ -24995,6 +25045,9 @@ class OrbitControls extends THREE.EventDispatcher {
24995
25045
  const dollyStart = new THREE.Vector2();
24996
25046
  const dollyEnd = new THREE.Vector2();
24997
25047
  const dollyDelta = new THREE.Vector2();
25048
+ const dollyDirection = new THREE.Vector3();
25049
+ const mouse = new THREE.Vector2();
25050
+ let performCursorZoom = false;
24998
25051
  const pointers = [];
24999
25052
  const pointerPositions = {};
25000
25053
  function getAutoRotationAngle() {
@@ -25065,33 +25118,43 @@ class OrbitControls extends THREE.EventDispatcher {
25065
25118
  };
25066
25119
  })();
25067
25120
  function dollyOut(dollyScale) {
25068
- if (scope.object instanceof THREE.PerspectiveCamera && scope.object.isPerspectiveCamera) {
25121
+ if (scope.object instanceof THREE.PerspectiveCamera && scope.object.isPerspectiveCamera || scope.object instanceof THREE.OrthographicCamera && scope.object.isOrthographicCamera) {
25069
25122
  scale /= dollyScale;
25070
- } else if (scope.object instanceof THREE.OrthographicCamera && scope.object.isOrthographicCamera) {
25071
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
25072
- scope.object.updateProjectionMatrix();
25073
- zoomChanged = true;
25074
25123
  } else {
25075
25124
  console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
25076
25125
  scope.enableZoom = false;
25077
25126
  }
25078
25127
  }
25079
25128
  function dollyIn(dollyScale) {
25080
- if (scope.object instanceof THREE.PerspectiveCamera && scope.object.isPerspectiveCamera) {
25129
+ if (scope.object instanceof THREE.PerspectiveCamera && scope.object.isPerspectiveCamera || scope.object instanceof THREE.OrthographicCamera && scope.object.isOrthographicCamera) {
25081
25130
  scale *= dollyScale;
25082
- } else if (scope.object instanceof THREE.OrthographicCamera && scope.object.isOrthographicCamera) {
25083
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
25084
- scope.object.updateProjectionMatrix();
25085
- zoomChanged = true;
25086
25131
  } else {
25087
25132
  console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
25088
25133
  scope.enableZoom = false;
25089
25134
  }
25090
25135
  }
25136
+ function updateMouseParameters(event) {
25137
+ if (!scope.zoomToCursor || !scope.domElement) {
25138
+ return;
25139
+ }
25140
+ performCursorZoom = true;
25141
+ const rect = scope.domElement.getBoundingClientRect();
25142
+ const x = event.clientX - rect.left;
25143
+ const y = event.clientY - rect.top;
25144
+ const w = rect.width;
25145
+ const h = rect.height;
25146
+ mouse.x = x / w * 2 - 1;
25147
+ mouse.y = -(y / h) * 2 + 1;
25148
+ dollyDirection.set(mouse.x, mouse.y, 1).unproject(scope.object).sub(scope.object.position).normalize();
25149
+ }
25150
+ function clampDistance(dist) {
25151
+ return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist));
25152
+ }
25091
25153
  function handleMouseDownRotate(event) {
25092
25154
  rotateStart.set(event.clientX, event.clientY);
25093
25155
  }
25094
25156
  function handleMouseDownDolly(event) {
25157
+ updateMouseParameters(event);
25095
25158
  dollyStart.set(event.clientX, event.clientY);
25096
25159
  }
25097
25160
  function handleMouseDownPan(event) {
@@ -25127,6 +25190,7 @@ class OrbitControls extends THREE.EventDispatcher {
25127
25190
  scope.update();
25128
25191
  }
25129
25192
  function handleMouseWheel(event) {
25193
+ updateMouseParameters(event);
25130
25194
  if (event.deltaY < 0) {
25131
25195
  dollyIn(getZoomScale());
25132
25196
  } else if (event.deltaY > 0) {
package/index.js CHANGED
@@ -872,7 +872,7 @@ const Visible = 0;
872
872
  const Deleted = 1;
873
873
  const _v1$5 = /* @__PURE__ */ new Vector3();
874
874
  const _line3 = /* @__PURE__ */ new Line3();
875
- const _plane$1 = /* @__PURE__ */ new Plane();
875
+ const _plane$2 = /* @__PURE__ */ new Plane();
876
876
  const _closestPoint$1 = /* @__PURE__ */ new Vector3();
877
877
  const _triangle = /* @__PURE__ */ new Triangle$1();
878
878
  class ConvexHull {
@@ -1109,11 +1109,11 @@ class ConvexHull {
1109
1109
  }
1110
1110
  }
1111
1111
  maxDistance = -1;
1112
- _plane$1.setFromCoplanarPoints(v0.point, v12.point, v2.point);
1112
+ _plane$2.setFromCoplanarPoints(v0.point, v12.point, v2.point);
1113
1113
  for (let i2 = 0, l = this.vertices.length; i2 < l; i2++) {
1114
1114
  const vertex = vertices[i2];
1115
1115
  if (vertex !== v0 && vertex !== v12 && vertex !== v2) {
1116
- const distance = Math.abs(_plane$1.distanceToPoint(vertex.point));
1116
+ const distance = Math.abs(_plane$2.distanceToPoint(vertex.point));
1117
1117
  if (distance > maxDistance) {
1118
1118
  maxDistance = distance;
1119
1119
  v3 = vertex;
@@ -1121,7 +1121,7 @@ class ConvexHull {
1121
1121
  }
1122
1122
  }
1123
1123
  const faces = [];
1124
- if (_plane$1.distanceToPoint(v3.point) < 0) {
1124
+ if (_plane$2.distanceToPoint(v3.point) < 0) {
1125
1125
  faces.push(Face$1.create(v0, v12, v2), Face$1.create(v3, v12, v0), Face$1.create(v3, v2, v12), Face$1.create(v3, v0, v2));
1126
1126
  for (let i2 = 0; i2 < 3; i2++) {
1127
1127
  const j = (i2 + 1) % 3;
@@ -21450,7 +21450,7 @@ class ImprovedNoise {
21450
21450
  }
21451
21451
  const _v1$2 = /* @__PURE__ */ new Vector3();
21452
21452
  const _v2$2 = /* @__PURE__ */ new Vector3();
21453
- const _plane = /* @__PURE__ */ new Plane();
21453
+ const _plane$1 = /* @__PURE__ */ new Plane();
21454
21454
  const _line1 = /* @__PURE__ */ new Line3();
21455
21455
  const _line2 = /* @__PURE__ */ new Line3();
21456
21456
  const _sphere$1 = /* @__PURE__ */ new Sphere();
@@ -21537,16 +21537,16 @@ class Octree {
21537
21537
  return triangles;
21538
21538
  }
21539
21539
  triangleCapsuleIntersect(capsule, triangle) {
21540
- triangle.getPlane(_plane);
21541
- const d1 = _plane.distanceToPoint(capsule.start) - capsule.radius;
21542
- const d2 = _plane.distanceToPoint(capsule.end) - capsule.radius;
21540
+ triangle.getPlane(_plane$1);
21541
+ const d1 = _plane$1.distanceToPoint(capsule.start) - capsule.radius;
21542
+ const d2 = _plane$1.distanceToPoint(capsule.end) - capsule.radius;
21543
21543
  if (d1 > 0 && d2 > 0 || d1 < -capsule.radius && d2 < -capsule.radius) {
21544
21544
  return false;
21545
21545
  }
21546
21546
  const delta = Math.abs(d1 / (Math.abs(d1) + Math.abs(d2)));
21547
21547
  const intersectPoint = _v1$2.copy(capsule.start).lerp(capsule.end, delta);
21548
21548
  if (triangle.containsPoint(intersectPoint)) {
21549
- return { normal: _plane.normal.clone(), point: intersectPoint.clone(), depth: Math.abs(Math.min(d1, d2)) };
21549
+ return { normal: _plane$1.normal.clone(), point: intersectPoint.clone(), depth: Math.abs(Math.min(d1, d2)) };
21550
21550
  }
21551
21551
  const r2 = capsule.radius * capsule.radius;
21552
21552
  const line1 = _line1.set(capsule.start, capsule.end);
@@ -21569,17 +21569,17 @@ class Octree {
21569
21569
  return false;
21570
21570
  }
21571
21571
  triangleSphereIntersect(sphere, triangle) {
21572
- triangle.getPlane(_plane);
21573
- if (!sphere.intersectsPlane(_plane))
21572
+ triangle.getPlane(_plane$1);
21573
+ if (!sphere.intersectsPlane(_plane$1))
21574
21574
  return false;
21575
- const depth = Math.abs(_plane.distanceToSphere(sphere));
21575
+ const depth = Math.abs(_plane$1.distanceToSphere(sphere));
21576
21576
  const r2 = sphere.radius * sphere.radius - depth * depth;
21577
- const plainPoint = _plane.projectPoint(sphere.center, _v1$2);
21577
+ const plainPoint = _plane$1.projectPoint(sphere.center, _v1$2);
21578
21578
  if (triangle.containsPoint(sphere.center)) {
21579
21579
  return {
21580
- normal: _plane.normal.clone(),
21580
+ normal: _plane$1.normal.clone(),
21581
21581
  point: plainPoint.clone(),
21582
- depth: Math.abs(_plane.distanceToSphere(sphere))
21582
+ depth: Math.abs(_plane$1.distanceToSphere(sphere))
21583
21583
  };
21584
21584
  }
21585
21585
  const lines = [
@@ -24698,6 +24698,9 @@ class TrackballControls extends EventDispatcher {
24698
24698
  this.update();
24699
24699
  }
24700
24700
  }
24701
+ const _ray$2 = /* @__PURE__ */ new Ray();
24702
+ const _plane = /* @__PURE__ */ new Plane();
24703
+ const TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD);
24701
24704
  const moduloWrapAround = (offset, capacity) => (offset % capacity + capacity) % capacity;
24702
24705
  class OrbitControls extends EventDispatcher {
24703
24706
  constructor(object, domElement) {
@@ -24744,6 +24747,7 @@ class OrbitControls extends EventDispatcher {
24744
24747
  // if false, pan orthogonal to world-space direction camera.up
24745
24748
  __publicField(this, "keyPanSpeed", 7);
24746
24749
  // pixels moved per arrow key push
24750
+ __publicField(this, "zoomToCursor", false);
24747
24751
  // Set to true to automatically rotate around the target
24748
24752
  // If auto-rotate is enabled, you must call controls.update() in your animation loop
24749
24753
  __publicField(this, "autoRotate", false);
@@ -24892,13 +24896,16 @@ class OrbitControls extends EventDispatcher {
24892
24896
  }
24893
24897
  spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
24894
24898
  spherical.makeSafe();
24895
- spherical.radius *= scale;
24896
- spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
24897
24899
  if (scope.enableDamping === true) {
24898
24900
  scope.target.addScaledVector(panOffset, scope.dampingFactor);
24899
24901
  } else {
24900
24902
  scope.target.add(panOffset);
24901
24903
  }
24904
+ if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) {
24905
+ spherical.radius = clampDistance(spherical.radius);
24906
+ } else {
24907
+ spherical.radius = clampDistance(spherical.radius * scale);
24908
+ }
24902
24909
  offset.setFromSpherical(spherical);
24903
24910
  offset.applyQuaternion(quatInverse);
24904
24911
  position.copy(scope.target).add(offset);
@@ -24911,7 +24918,51 @@ class OrbitControls extends EventDispatcher {
24911
24918
  sphericalDelta.set(0, 0, 0);
24912
24919
  panOffset.set(0, 0, 0);
24913
24920
  }
24921
+ let zoomChanged = false;
24922
+ if (scope.zoomToCursor && performCursorZoom) {
24923
+ let newRadius = null;
24924
+ if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera) {
24925
+ const prevRadius = offset.length();
24926
+ newRadius = clampDistance(prevRadius * scale);
24927
+ const radiusDelta = prevRadius - newRadius;
24928
+ scope.object.position.addScaledVector(dollyDirection, radiusDelta);
24929
+ scope.object.updateMatrixWorld();
24930
+ } else if (scope.object.isOrthographicCamera) {
24931
+ const mouseBefore = new Vector3(mouse.x, mouse.y, 0);
24932
+ mouseBefore.unproject(scope.object);
24933
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
24934
+ scope.object.updateProjectionMatrix();
24935
+ zoomChanged = true;
24936
+ const mouseAfter = new Vector3(mouse.x, mouse.y, 0);
24937
+ mouseAfter.unproject(scope.object);
24938
+ scope.object.position.sub(mouseAfter).add(mouseBefore);
24939
+ scope.object.updateMatrixWorld();
24940
+ newRadius = offset.length();
24941
+ } else {
24942
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.");
24943
+ scope.zoomToCursor = false;
24944
+ }
24945
+ if (newRadius !== null) {
24946
+ if (scope.screenSpacePanning) {
24947
+ scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position);
24948
+ } else {
24949
+ _ray$2.origin.copy(scope.object.position);
24950
+ _ray$2.direction.set(0, 0, -1).transformDirection(scope.object.matrix);
24951
+ if (Math.abs(scope.object.up.dot(_ray$2.direction)) < TILT_LIMIT) {
24952
+ object.lookAt(scope.target);
24953
+ } else {
24954
+ _plane.setFromNormalAndCoplanarPoint(scope.object.up, scope.target);
24955
+ _ray$2.intersectPlane(_plane, scope.target);
24956
+ }
24957
+ }
24958
+ }
24959
+ } else if (scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
24960
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale));
24961
+ scope.object.updateProjectionMatrix();
24962
+ zoomChanged = true;
24963
+ }
24914
24964
  scale = 1;
24965
+ performCursorZoom = false;
24915
24966
  if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS2 || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS2) {
24916
24967
  scope.dispatchEvent(changeEvent);
24917
24968
  lastPosition.copy(scope.object.position);
@@ -24967,7 +25018,6 @@ class OrbitControls extends EventDispatcher {
24967
25018
  const sphericalDelta = new Spherical();
24968
25019
  let scale = 1;
24969
25020
  const panOffset = new Vector3();
24970
- let zoomChanged = false;
24971
25021
  const rotateStart = new Vector2();
24972
25022
  const rotateEnd = new Vector2();
24973
25023
  const rotateDelta = new Vector2();
@@ -24977,6 +25027,9 @@ class OrbitControls extends EventDispatcher {
24977
25027
  const dollyStart = new Vector2();
24978
25028
  const dollyEnd = new Vector2();
24979
25029
  const dollyDelta = new Vector2();
25030
+ const dollyDirection = new Vector3();
25031
+ const mouse = new Vector2();
25032
+ let performCursorZoom = false;
24980
25033
  const pointers = [];
24981
25034
  const pointerPositions = {};
24982
25035
  function getAutoRotationAngle() {
@@ -25047,33 +25100,43 @@ class OrbitControls extends EventDispatcher {
25047
25100
  };
25048
25101
  })();
25049
25102
  function dollyOut(dollyScale) {
25050
- if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera) {
25103
+ if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera || scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
25051
25104
  scale /= dollyScale;
25052
- } else if (scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
25053
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
25054
- scope.object.updateProjectionMatrix();
25055
- zoomChanged = true;
25056
25105
  } else {
25057
25106
  console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
25058
25107
  scope.enableZoom = false;
25059
25108
  }
25060
25109
  }
25061
25110
  function dollyIn(dollyScale) {
25062
- if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera) {
25111
+ if (scope.object instanceof PerspectiveCamera && scope.object.isPerspectiveCamera || scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
25063
25112
  scale *= dollyScale;
25064
- } else if (scope.object instanceof OrthographicCamera && scope.object.isOrthographicCamera) {
25065
- scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
25066
- scope.object.updateProjectionMatrix();
25067
- zoomChanged = true;
25068
25113
  } else {
25069
25114
  console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
25070
25115
  scope.enableZoom = false;
25071
25116
  }
25072
25117
  }
25118
+ function updateMouseParameters(event) {
25119
+ if (!scope.zoomToCursor || !scope.domElement) {
25120
+ return;
25121
+ }
25122
+ performCursorZoom = true;
25123
+ const rect = scope.domElement.getBoundingClientRect();
25124
+ const x = event.clientX - rect.left;
25125
+ const y = event.clientY - rect.top;
25126
+ const w = rect.width;
25127
+ const h = rect.height;
25128
+ mouse.x = x / w * 2 - 1;
25129
+ mouse.y = -(y / h) * 2 + 1;
25130
+ dollyDirection.set(mouse.x, mouse.y, 1).unproject(scope.object).sub(scope.object.position).normalize();
25131
+ }
25132
+ function clampDistance(dist) {
25133
+ return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist));
25134
+ }
25073
25135
  function handleMouseDownRotate(event) {
25074
25136
  rotateStart.set(event.clientX, event.clientY);
25075
25137
  }
25076
25138
  function handleMouseDownDolly(event) {
25139
+ updateMouseParameters(event);
25077
25140
  dollyStart.set(event.clientX, event.clientY);
25078
25141
  }
25079
25142
  function handleMouseDownPan(event) {
@@ -25109,6 +25172,7 @@ class OrbitControls extends EventDispatcher {
25109
25172
  scope.update();
25110
25173
  }
25111
25174
  function handleMouseWheel(event) {
25175
+ updateMouseParameters(event);
25112
25176
  if (event.deltaY < 0) {
25113
25177
  dollyIn(getZoomScale());
25114
25178
  } else if (event.deltaY > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.25.1",
3
+ "version": "2.26.0",
4
4
  "description": "stand-alone library of threejs examples",
5
5
  "keywords": [
6
6
  "three",