@xviewer.js/core 1.0.0-alpha.31 → 1.0.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1467,7 +1467,7 @@ class VirtualCamera extends Component {
1467
1467
  this.correctPosition = new Vector3();
1468
1468
  this.correctRotation = new Quaternion();
1469
1469
  this.lookaheadPosition = new Vector3();
1470
- this.trackedObjectOffset = new Vector3();
1470
+ this.lookAtOffset = new Vector3();
1471
1471
  }
1472
1472
  }
1473
1473
  __decorate([
@@ -2582,11 +2582,10 @@ Perlin._Permutation = [
2582
2582
 
2583
2583
  const { clamp, degToRad } = MathUtils;
2584
2584
  const { abs, tan } = Math;
2585
- const VCamFreeLookMode = {
2586
- FREE: 0,
2587
- TRANSLATE: 1
2588
- };
2589
2585
  class FreelookVirtualCamera extends VirtualCamera {
2586
+ printInfo() {
2587
+ console.log(this.node.position, this.lookAt.position);
2588
+ }
2590
2589
  onEnable() {
2591
2590
  this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
2592
2591
  this.viewer.on(DeviceInput.POINTER_UP, this._onPointerUp, this);
@@ -2611,14 +2610,6 @@ class FreelookVirtualCamera extends VirtualCamera {
2611
2610
  this._panDelta.set(0, 0);
2612
2611
  this._distanceDelta = 0;
2613
2612
  }
2614
- gotoPOI(position, lookAt, duration = 1, easing = Easing.Quadratic.InOut) {
2615
- this.viewer.killTweensOf(this._tweenPOI);
2616
- this.viewer.tween(this._tweenPOI).to({
2617
- position,
2618
- lookAt,
2619
- trackedObjectOffset: Vector3_ZERO
2620
- }, duration).easing(easing).start();
2621
- }
2622
2613
  _onPointerDown(e) {
2623
2614
  if (SystemInfo.isMobile) return;
2624
2615
  this._button = e.button;
@@ -2630,21 +2621,23 @@ class FreelookVirtualCamera extends VirtualCamera {
2630
2621
  }
2631
2622
  _onPointerMove(e) {
2632
2623
  if (SystemInfo.isMobile) return;
2633
- FreelookVirtualCamera.__loc0.set(e.pageX, e.pageY);
2624
+ const { __loc0, __moveDelta } = FreelookVirtualCamera;
2625
+ __loc0.set(e.pageX, e.pageY);
2634
2626
  switch(this._button){
2635
2627
  case 0:
2636
- this._rotateDelta.add(this._calculateRotateDelta(FreelookVirtualCamera.__moveDelta, this._preLoc0, FreelookVirtualCamera.__loc0));
2628
+ this._rotateDelta.add(this._calculateRotateDelta(__moveDelta, this._preLoc0, __loc0));
2637
2629
  break;
2638
2630
  case 1:
2639
2631
  case 2:
2640
- this._panDelta.add(this._calculatePanDelta(FreelookVirtualCamera.__moveDelta, this._preLoc0, FreelookVirtualCamera.__loc0));
2632
+ this._panDelta.add(this._calculatePanDelta(__moveDelta, this._preLoc0, __loc0));
2641
2633
  break;
2642
2634
  }
2643
- this._preLoc0.copy(FreelookVirtualCamera.__loc0);
2635
+ this._preLoc0.copy(__loc0);
2644
2636
  }
2645
2637
  _onMouseWheel(e) {
2638
+ const { __worldPos } = FreelookVirtualCamera;
2646
2639
  if (this.lookAt) {
2647
- let dist = FreelookVirtualCamera.__worldPos.copy(this.lookAt.position).add(this.trackedObjectOffset).distanceTo(this.node.position);
2640
+ let dist = __worldPos.copy(this.lookAt.position).add(this.lookAtOffset).distanceTo(this.node.position);
2648
2641
  let distNew = dist + this._distanceDelta;
2649
2642
  if (e.deltaY > 0) {
2650
2643
  distNew *= this._calculateDistanceScale(1 / 0.85);
@@ -2675,11 +2668,13 @@ class FreelookVirtualCamera extends VirtualCamera {
2675
2668
  __loc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2676
2669
  __loc1.set(touches[rotateTouchID + 1].pageX, touches[rotateTouchID + 1].pageY);
2677
2670
  if (this.lookAt) {
2678
- let dist = __worldPos.copy(this.lookAt.position).add(this.trackedObjectOffset).distanceTo(this.node.position);
2671
+ let dist = __worldPos.copy(this.lookAt.position).add(this.lookAtOffset).distanceTo(this.node.position);
2679
2672
  let distNew = (dist + this._distanceDelta) * this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2680
2673
  this._distanceDelta = distNew - dist;
2681
2674
  }
2682
- this._panDelta.add(this._calculatePanDelta(__moveDelta, __preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5), __center.copy(__loc0).add(__loc1).multiplyScalar(0.5)));
2675
+ __preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5);
2676
+ __center.copy(__loc0).add(__loc1).multiplyScalar(0.5);
2677
+ this._panDelta.add(this._calculatePanDelta(__moveDelta, __preCenter, __center));
2683
2678
  this._preLoc0.copy(__loc0);
2684
2679
  this._preLoc1.copy(__loc1);
2685
2680
  } else if (touches.length > rotateTouchID) {
@@ -2706,6 +2701,7 @@ class FreelookVirtualCamera extends VirtualCamera {
2706
2701
  if (this.forbidY) {
2707
2702
  out.y = 0;
2708
2703
  }
2704
+ this._tempSmoothing = this.smoothing;
2709
2705
  return out;
2710
2706
  }
2711
2707
  _calculatePanDelta(out, loc0, loc1) {
@@ -2717,51 +2713,52 @@ class FreelookVirtualCamera extends VirtualCamera {
2717
2713
  if (this.forbidPanY) {
2718
2714
  out.y = 0;
2719
2715
  }
2716
+ this._tempSmoothing = this.smoothing;
2720
2717
  return out;
2721
2718
  }
2719
+ gotoPOI(position, lookAt, smoothing = 1) {
2720
+ const { __posDelta, __worldPos, __quat, __spherical } = FreelookVirtualCamera;
2721
+ __quat.setFromUnitVectors(this.node.up, Object3D.DEFAULT_UP);
2722
+ __posDelta.copy(position).sub(lookAt);
2723
+ __posDelta.applyQuaternion(__quat);
2724
+ __spherical.setFromVector3(__posDelta);
2725
+ const { theta, phi, radius } = __spherical;
2726
+ __worldPos.copy(this.lookAt.position).add(this.lookAtOffset);
2727
+ __posDelta.copy(this.node.position).sub(__worldPos);
2728
+ __posDelta.applyQuaternion(__quat);
2729
+ __spherical.setFromVector3(__posDelta);
2730
+ const dx = theta - __spherical.theta;
2731
+ const dy = phi - __spherical.phi;
2732
+ const dz = radius - __spherical.radius;
2733
+ this._rotateDelta.x = -dx;
2734
+ this._rotateDelta.y = dy;
2735
+ this._distanceDelta = dz;
2736
+ this._tempSmoothing = smoothing;
2737
+ this._lookAtOffsetDelta.copy(lookAt).sub(this.lookAt.position).sub(this.lookAtOffset);
2738
+ }
2722
2739
  update(dt) {
2723
2740
  if (!this.lookAt) return;
2724
- const { __posDelta, __posOffset, __worldPos, __quat, __spherical, __xAxis, __yAxis } = FreelookVirtualCamera;
2725
- __worldPos.copy(this.lookAt.position).add(this.trackedObjectOffset);
2726
- switch(this.mode){
2727
- case VCamFreeLookMode.FREE:
2728
- if (abs(this._rotateDelta.x) + abs(this._rotateDelta.y) + abs(this._distanceDelta) > 0.001) {
2729
- const { __posDelta, __posOffset, __worldPos } = FreelookVirtualCamera;
2730
- __quat.setFromUnitVectors(this.node.up, Object3D.DEFAULT_UP);
2731
- __posDelta.copy(this.node.position).sub(__worldPos);
2732
- __posDelta.applyQuaternion(__quat);
2733
- __spherical.setFromVector3(__posDelta);
2734
- let dampFactor = quarticDamp(1, 0, this.rotateSmoothing, dt);
2735
- this._rotateDelta.x = __spherical.theta - clamp(__spherical.theta - this._rotateDelta.x, this.thetaMin, this.thetaMax);
2736
- __spherical.theta = __spherical.theta - this._rotateDelta.x * (1 - dampFactor);
2737
- this._rotateDelta.y = clamp(__spherical.phi + this._rotateDelta.y, this.phiMin, this.phiMax) - __spherical.phi;
2738
- __spherical.phi = clamp(__spherical.phi + this._rotateDelta.y * (1 - dampFactor), 0.001, Math.PI - 0.001);
2739
- this._distanceDelta = clamp(__spherical.radius + this._distanceDelta, this.distanceMin, this.distanceMax) - __spherical.radius;
2740
- __spherical.radius = __spherical.radius + this._distanceDelta * (1 - dampFactor);
2741
- this._rotateDelta.multiplyScalar(dampFactor);
2742
- this._distanceDelta *= dampFactor;
2743
- __posDelta.setFromSpherical(__spherical);
2744
- __posDelta.applyQuaternion(__quat.invert());
2745
- this.node.position.copy(__posDelta.add(__worldPos));
2746
- }
2747
- break;
2748
- case VCamFreeLookMode.TRANSLATE:
2749
- if (abs(this._distanceDelta) > 0.001) {
2750
- __posDelta.copy(this.node.position).sub(this.lookAt.position);
2751
- let dampFactor = quarticDamp(1, 0, this.rotateSmoothing, dt);
2752
- let dist0 = __posDelta.length();
2753
- this._distanceDelta = clamp(dist0 + this._distanceDelta, this.distanceMin, this.distanceMax) - dist0;
2754
- let dist = dist0 + this._distanceDelta * (1 - dampFactor);
2755
- this._distanceDelta *= dampFactor;
2756
- let pos = __posDelta.normalize().multiplyScalar(dist).add(this.lookAt.position);
2757
- __posOffset.copy(pos).sub(this.node.position);
2758
- this.trackedObjectOffset.add(__posOffset);
2759
- this.node.position.copy(pos);
2760
- __worldPos.copy(this.lookAt.position).add(this.trackedObjectOffset);
2761
- }
2762
- break;
2741
+ const dampFactor = exponentialDamp(1, 0, this._tempSmoothing, dt);
2742
+ const { __posDelta, __offsetDelta, __worldPos, __quat, __spherical, __xAxis, __yAxis } = FreelookVirtualCamera;
2743
+ __worldPos.copy(this.lookAt.position).add(this.lookAtOffset);
2744
+ if (this._rotateDelta.manhattanLength() + abs(this._distanceDelta) > 0.001) {
2745
+ __quat.setFromUnitVectors(this.node.up, Object3D.DEFAULT_UP);
2746
+ __posDelta.copy(this.node.position).sub(__worldPos);
2747
+ __posDelta.applyQuaternion(__quat);
2748
+ __spherical.setFromVector3(__posDelta);
2749
+ this._rotateDelta.x = __spherical.theta - clamp(__spherical.theta - this._rotateDelta.x, this.thetaMin, this.thetaMax);
2750
+ __spherical.theta = __spherical.theta - this._rotateDelta.x * (1 - dampFactor);
2751
+ this._rotateDelta.y = clamp(__spherical.phi + this._rotateDelta.y, this.phiMin, this.phiMax) - __spherical.phi;
2752
+ __spherical.phi = clamp(__spherical.phi + this._rotateDelta.y * (1 - dampFactor), 0.001, Math.PI - 0.001);
2753
+ this._distanceDelta = clamp(__spherical.radius + this._distanceDelta, this.distanceMin, this.distanceMax) - __spherical.radius;
2754
+ __spherical.radius = __spherical.radius + this._distanceDelta * (1 - dampFactor);
2755
+ this._rotateDelta.multiplyScalar(dampFactor);
2756
+ this._distanceDelta *= dampFactor;
2757
+ __posDelta.setFromSpherical(__spherical);
2758
+ __posDelta.applyQuaternion(__quat.invert());
2759
+ this.node.position.copy(__posDelta.add(__worldPos));
2763
2760
  }
2764
- if (abs(this._panDelta.x) + abs(this._panDelta.y) > 0.001) {
2761
+ if (this._panDelta.manhattanLength() > 0.001) {
2765
2762
  __posDelta.copy(this.node.position).sub(__worldPos);
2766
2763
  __xAxis.setFromMatrixColumn(this.node.matrix, 0);
2767
2764
  __yAxis.setFromMatrixColumn(this.node.matrix, 1);
@@ -2770,14 +2767,17 @@ class FreelookVirtualCamera extends VirtualCamera {
2770
2767
  __yAxis.normalize();
2771
2768
  }
2772
2769
  let length = __posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
2773
- let dampFactor = quarticDamp(1, 0, this.panSmoothing, dt);
2774
- let trackedObjectOffset = this.trackedObjectOffset;
2775
- trackedObjectOffset.sub(__xAxis.multiplyScalar(this._panDelta.x * length * (1 - dampFactor)));
2776
- trackedObjectOffset.add(__yAxis.multiplyScalar(this._panDelta.y * length * (1 - dampFactor)));
2770
+ let lookAtOffset = this.lookAtOffset;
2771
+ lookAtOffset.sub(__xAxis.multiplyScalar(this._panDelta.x * length * (1 - dampFactor)));
2772
+ lookAtOffset.add(__yAxis.multiplyScalar(this._panDelta.y * length * (1 - dampFactor)));
2777
2773
  this._panDelta.multiplyScalar(dampFactor);
2778
- __worldPos.copy(this.lookAt.position).add(trackedObjectOffset);
2774
+ __worldPos.copy(this.lookAt.position).add(lookAtOffset);
2779
2775
  this.node.position.copy(__posDelta.add(__worldPos));
2780
2776
  }
2777
+ if (this._lookAtOffsetDelta.manhattanLength() > 0.001) {
2778
+ this.lookAtOffset.add(__offsetDelta.copy(this._lookAtOffsetDelta).multiplyScalar(1 - dampFactor));
2779
+ this._lookAtOffsetDelta.multiplyScalar(dampFactor);
2780
+ }
2781
2781
  this.node.lookAt(__worldPos);
2782
2782
  }
2783
2783
  constructor(...args){
@@ -2789,17 +2789,17 @@ class FreelookVirtualCamera extends VirtualCamera {
2789
2789
  this._preLoc1 = new Vector2();
2790
2790
  this._rotateDelta = new Vector2();
2791
2791
  this._panDelta = new Vector2();
2792
- this.mode = VCamFreeLookMode.FREE;
2792
+ this._tempSmoothing = 0;
2793
+ this._lookAtOffsetDelta = new Vector3();
2793
2794
  this.forbidX = false;
2794
2795
  this.forbidY = false;
2795
2796
  this.forbidZ = false;
2796
2797
  this.forbidPanX = false;
2797
2798
  this.forbidPanY = false;
2798
2799
  this.forbitPanOffsetY = false;
2800
+ this.smoothing = 0.5;
2799
2801
  this.rotateSpeed = 2;
2800
- this.rotateSmoothing = 0.5;
2801
2802
  this.panSpeed = 2;
2802
- this.panSmoothing = 0.5;
2803
2803
  this.panScale = new Vector3(1, 1, 1);
2804
2804
  this.phiMin = 0.001;
2805
2805
  this.phiMax = Math.PI - 0.001;
@@ -2809,26 +2809,6 @@ class FreelookVirtualCamera extends VirtualCamera {
2809
2809
  this.distanceMax = Infinity;
2810
2810
  this.rotateTouchID = 0;
2811
2811
  this.lookAt = new Object3D();
2812
- this._tweenPOI = {
2813
- get position () {
2814
- return this.node.position;
2815
- },
2816
- set position (v){
2817
- this.node.position.copy(v);
2818
- },
2819
- get lookAt () {
2820
- return this.lookAt.position;
2821
- },
2822
- set lookAt (v){
2823
- this.lookAt.position.copy(v);
2824
- },
2825
- get trackedObjectOffset () {
2826
- return this.trackedObjectOffset;
2827
- },
2828
- set trackedObjectOffset (v){
2829
- this.trackedObjectOffset.copy(v);
2830
- }
2831
- };
2832
2812
  }
2833
2813
  }
2834
2814
  FreelookVirtualCamera.__loc0 = new Vector2();
@@ -2838,16 +2818,11 @@ FreelookVirtualCamera.__preCenter = new Vector2();
2838
2818
  FreelookVirtualCamera.__moveDelta = new Vector2();
2839
2819
  FreelookVirtualCamera.__worldPos = new Vector3();
2840
2820
  FreelookVirtualCamera.__posDelta = new Vector3();
2841
- FreelookVirtualCamera.__posOffset = new Vector3();
2842
2821
  FreelookVirtualCamera.__xAxis = new Vector3();
2843
2822
  FreelookVirtualCamera.__yAxis = new Vector3();
2844
2823
  FreelookVirtualCamera.__quat = new Quaternion();
2845
2824
  FreelookVirtualCamera.__spherical = new Spherical();
2846
- __decorate([
2847
- property({
2848
- value: VCamFreeLookMode
2849
- })
2850
- ], FreelookVirtualCamera.prototype, "mode", void 0);
2825
+ FreelookVirtualCamera.__offsetDelta = new Vector3();
2851
2826
  __decorate([
2852
2827
  property({
2853
2828
  dir: "set"
@@ -2878,6 +2853,9 @@ __decorate([
2878
2853
  dir: "set"
2879
2854
  })
2880
2855
  ], FreelookVirtualCamera.prototype, "forbitPanOffsetY", void 0);
2856
+ __decorate([
2857
+ property
2858
+ ], FreelookVirtualCamera.prototype, "printInfo", null);
2881
2859
 
2882
2860
  class Box extends Mesh {
2883
2861
  constructor(...args){