@xviewer.js/core 1.0.0-alpha.34 → 1.0.0-alpha.36

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/main.js CHANGED
@@ -706,7 +706,6 @@ class Tween {
706
706
  union(headTween, tailTween) {
707
707
  this._headTween = headTween;
708
708
  this._tailTween = tailTween.chain(this);
709
- this._headStart = true;
710
709
  return this;
711
710
  }
712
711
  repeat(times = 0) {
@@ -803,11 +802,13 @@ class Tween {
803
802
  if (this._onFinishCallback) {
804
803
  this._onFinishCallback(this._object);
805
804
  }
806
- if (this._headTween && this._headStart) {
807
- this._headTween.start(this._startTime + this._duration);
808
- this._headStart = false;
809
- this._isPlaying = false;
810
- return false;
805
+ if (this._headTween) {
806
+ if (this._headTweenStartFired === false) {
807
+ this._headTweenStartFired = true;
808
+ this._headTween.start(this._startTime + this._duration);
809
+ this._isPlaying = false;
810
+ return false;
811
+ }
811
812
  }
812
813
  }
813
814
  const status = this._calculateCompletionStatus(elapsedTime, durationAndDelay);
@@ -830,7 +831,7 @@ class Tween {
830
831
  this._onRepeatCallback(this._object);
831
832
  }
832
833
  if (this._headTween) {
833
- this._headStart = true;
834
+ this._headTweenStartFired = false;
834
835
  this._initialRepeat = this._repeat;
835
836
  }
836
837
  this._onEveryStartCallbackFired = false;
@@ -973,7 +974,7 @@ class Tween {
973
974
  this._propertiesAreSetUp = false;
974
975
  this._headTween = null;
975
976
  this._tailTween = null;
976
- this._headStart = false;
977
+ this._headTweenStartFired = false;
977
978
  this._goToEnd = false;
978
979
  }
979
980
  }
@@ -1442,13 +1443,13 @@ class CinestationBrain extends Component {
1442
1443
  }
1443
1444
  _lerpToMainCamera(vcam, t) {
1444
1445
  const from = this.node, to = vcam;
1445
- const { fov, near, far, finalPosition, finalRotation } = to;
1446
- const isLensChanged = from.fov != fov || from.near != near || from.far != far;
1446
+ const { lens, finalPosition, finalRotation } = to;
1447
+ const isLensChanged = from.fov != lens.fov || from.near != lens.near || from.far != lens.far;
1447
1448
  from.position.lerp(finalPosition, t);
1448
1449
  from.quaternion.slerp(finalRotation, t);
1449
- from.fov = lerp$1(from.fov, fov, t);
1450
- from.near = near;
1451
- from.far = far;
1450
+ from.fov = lerp$1(from.fov, lens.fov, t);
1451
+ from.near = lens.near;
1452
+ from.far = lens.far;
1452
1453
  if (isLensChanged) {
1453
1454
  from.updateProjectionMatrix();
1454
1455
  }
@@ -1466,6 +1467,28 @@ __decorate([
1466
1467
  property
1467
1468
  ], CinestationBrain.prototype, "brainBlend", void 0);
1468
1469
 
1470
+ class Lens {
1471
+ constructor(){
1472
+ this.fov = 45;
1473
+ this.near = 0.1;
1474
+ this.far = 1000;
1475
+ }
1476
+ }
1477
+ __decorate([
1478
+ property({
1479
+ dir: "lens"
1480
+ })
1481
+ ], Lens.prototype, "fov", void 0);
1482
+ __decorate([
1483
+ property({
1484
+ dir: "lens"
1485
+ })
1486
+ ], Lens.prototype, "near", void 0);
1487
+ __decorate([
1488
+ property({
1489
+ dir: "lens"
1490
+ })
1491
+ ], Lens.prototype, "far", void 0);
1469
1492
  class VirtualCamera extends Component {
1470
1493
  get finalPosition() {
1471
1494
  return this._finalPosition.copy(this.node.position).add(this.correctPosition);
@@ -1476,9 +1499,9 @@ class VirtualCamera extends Component {
1476
1499
  onLoad() {
1477
1500
  this.node.isCamera = true;
1478
1501
  const camera = this.viewer.camera;
1479
- this.fov = camera.fov;
1480
- this.near = camera.near;
1481
- this.far = camera.far;
1502
+ this.lens.fov = camera.fov;
1503
+ this.lens.near = camera.near;
1504
+ this.lens.far = camera.far;
1482
1505
  this.node.position.set(0, 0, 4);
1483
1506
  this.brain = this.viewer.getComponent(camera, CinestationBrain, true);
1484
1507
  this.brain.addCamera(this);
@@ -1491,30 +1514,14 @@ class VirtualCamera extends Component {
1491
1514
  this._finalPosition = new three.Vector3();
1492
1515
  this._finalRotation = new three.Quaternion();
1493
1516
  this.priority = 10;
1494
- this.lookAt = null;
1495
- this.follow = null;
1496
- this.fov = 45;
1497
- this.near = 0.1;
1498
- this.far = 1000;
1517
+ this.lens = new Lens();
1499
1518
  this.correctPosition = new three.Vector3();
1500
1519
  this.correctRotation = new three.Quaternion();
1501
1520
  }
1502
1521
  }
1503
1522
  __decorate([
1504
- property({
1505
- dir: "lens"
1506
- })
1507
- ], VirtualCamera.prototype, "fov", void 0);
1508
- __decorate([
1509
- property({
1510
- dir: "lens"
1511
- })
1512
- ], VirtualCamera.prototype, "near", void 0);
1513
- __decorate([
1514
- property({
1515
- dir: "lens"
1516
- })
1517
- ], VirtualCamera.prototype, "far", void 0);
1523
+ property
1524
+ ], VirtualCamera.prototype, "lens", void 0);
1518
1525
 
1519
1526
  const PressState = {
1520
1527
  NONE: 1 << 0,
@@ -2611,16 +2618,40 @@ Perlin._Permutation = [
2611
2618
  ];
2612
2619
 
2613
2620
  const { clamp, degToRad } = three.MathUtils;
2614
- const { abs, tan } = Math;
2621
+ const { abs, tan, PI } = Math;
2622
+ const PI2 = PI * 2;
2623
+ const ESP = 0.001;
2615
2624
  class FreelookVirtualCamera extends VirtualCamera {
2616
- printInfo() {
2617
- const spherical = this._spherical;
2618
- const lookAt = new three.Vector3().copy(this.lookAt.position).add(this._lookAtOffset);
2619
- console.log([
2620
- `springLength: ${spherical.radius.toFixed(2)}`,
2621
- `rotation: ${spherical.theta.toFixed(2)}, ${spherical.phi.toFixed(2)}`,
2622
- `lookAt: ${lookAt.x.toFixed(2)},${lookAt.y.toFixed(2)},${lookAt.z.toFixed(2)}`
2623
- ].join("\n"));
2625
+ get lookAt() {
2626
+ return this._lookAt;
2627
+ }
2628
+ set lookAt(v) {
2629
+ this._lookAt.copy(v);
2630
+ this._targetLookAt.copy(v);
2631
+ }
2632
+ get springLength() {
2633
+ return this._spherical.radius;
2634
+ }
2635
+ set springLength(v) {
2636
+ this._spherical.radius = this._targetSpringLength = v;
2637
+ }
2638
+ get theta() {
2639
+ return this._spherical.theta;
2640
+ }
2641
+ set theta(v) {
2642
+ this._spherical.theta = this._targetTheta = v;
2643
+ }
2644
+ get phi() {
2645
+ return this._spherical.phi;
2646
+ }
2647
+ set phi(v) {
2648
+ this._spherical.phi = this._targetPhi = v;
2649
+ }
2650
+ get fov() {
2651
+ return this.lens.fov;
2652
+ }
2653
+ set fov(v) {
2654
+ this.lens.fov = this._targetFov = v;
2624
2655
  }
2625
2656
  onEnable() {
2626
2657
  this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
@@ -2642,16 +2673,12 @@ class FreelookVirtualCamera extends VirtualCamera {
2642
2673
  reset() {
2643
2674
  this._button = -1;
2644
2675
  this._touchID = -1;
2645
- this._setSpherical(this.node.position, this.lookAtPosition);
2646
- }
2647
- get lookAtPosition() {
2648
- return this._lookAtPosition.copy(this.lookAt.position).add(this._lookAtOffset);
2676
+ this._setSpherical(this.node.position, this._lookAt);
2649
2677
  }
2650
2678
  _setSpherical(position, lookAt) {
2651
2679
  const { __posDelta } = FreelookVirtualCamera;
2652
2680
  __posDelta.copy(position).sub(lookAt);
2653
2681
  this._spherical.setFromVector3(__posDelta);
2654
- this._targetSpherical.copy(this._spherical);
2655
2682
  }
2656
2683
  _onPointerDown(e) {
2657
2684
  if (SystemInfo.isMobile) return;
@@ -2669,59 +2696,55 @@ class FreelookVirtualCamera extends VirtualCamera {
2669
2696
  switch(this._button){
2670
2697
  case 0:
2671
2698
  this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
2672
- this._calculateSpherical(__rotateDelta);
2699
+ this._calculateTargetSpringArm(__rotateDelta);
2673
2700
  break;
2674
2701
  case 1:
2675
2702
  case 2:
2676
2703
  this._calculatePanDelta(__panDelta, this._preLoc0, __loc0);
2677
- this._calculateLookAtOffset(__panDelta);
2704
+ this._calculateTargetLookAt(__panDelta);
2678
2705
  break;
2679
2706
  }
2680
2707
  this._preLoc0.copy(__loc0);
2681
2708
  }
2682
2709
  _onMouseWheel(e) {
2683
- if (this.lookAt) {
2684
- if (e.deltaY > 0) {
2685
- this._targetSpherical.radius *= this._calculateDistanceScale(1 / 0.85);
2686
- } else if (e.deltaY < 0) {
2687
- this._targetSpherical.radius *= this._calculateDistanceScale(0.85);
2688
- }
2710
+ if (e.deltaY > 0) {
2711
+ this._targetSpringLength *= this._calculateDistanceScale(1 / 0.85);
2712
+ } else if (e.deltaY < 0) {
2713
+ this._targetSpringLength *= this._calculateDistanceScale(0.85);
2689
2714
  }
2690
2715
  }
2691
2716
  _onTouchStart(e) {
2692
2717
  if (!SystemInfo.isMobile) return;
2693
2718
  let touches = e.touches;
2694
- let rotateTouchID = this.rotateTouchID;
2695
- if (touches.length > rotateTouchID + 1) {
2696
- this._preLoc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2697
- this._preLoc1.set(touches[rotateTouchID + 1].pageX, touches[rotateTouchID + 1].pageY);
2698
- } else if (touches.length > rotateTouchID) {
2699
- this._touchID = touches[rotateTouchID].identifier;
2700
- this._preLoc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2719
+ if (touches.length > 1) {
2720
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
2721
+ this._preLoc1.set(touches[1].pageX, touches[1].pageY);
2722
+ } else if (touches.length > 0) {
2723
+ this._touchID = touches[0].identifier;
2724
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
2701
2725
  }
2702
2726
  }
2703
2727
  _onTouchMove(e) {
2704
2728
  if (!SystemInfo.isMobile) return;
2705
2729
  const { __loc0, __loc1, __panDelta, __rotateDelta, __preCenter, __center } = FreelookVirtualCamera;
2706
2730
  let touches = e.touches;
2707
- let rotateTouchID = this.rotateTouchID;
2708
- if (touches.length > rotateTouchID + 1) {
2709
- __loc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2710
- __loc1.set(touches[rotateTouchID + 1].pageX, touches[rotateTouchID + 1].pageY);
2731
+ if (touches.length > 1) {
2732
+ __loc0.set(touches[0].pageX, touches[0].pageY);
2733
+ __loc1.set(touches[1].pageX, touches[1].pageY);
2711
2734
  if (this.lookAt) {
2712
- this._targetSpherical.radius *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2735
+ this._targetSpringLength *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2713
2736
  }
2714
2737
  __preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5);
2715
2738
  __center.copy(__loc0).add(__loc1).multiplyScalar(0.5);
2716
2739
  this._calculatePanDelta(__panDelta, __preCenter, __center);
2717
- this._calculateLookAtOffset(__panDelta);
2740
+ this._calculateTargetLookAt(__panDelta);
2718
2741
  this._preLoc0.copy(__loc0);
2719
2742
  this._preLoc1.copy(__loc1);
2720
- } else if (touches.length > rotateTouchID) {
2721
- if (this._touchID === touches[rotateTouchID].identifier) {
2722
- __loc0.set(touches[rotateTouchID].pageX, touches[rotateTouchID].pageY);
2743
+ } else if (touches.length > 0) {
2744
+ if (this._touchID === touches[0].identifier) {
2745
+ __loc0.set(touches[0].pageX, touches[0].pageY);
2723
2746
  this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
2724
- this._calculateSpherical(__rotateDelta);
2747
+ this._calculateTargetSpringArm(__rotateDelta);
2725
2748
  this._preLoc0.copy(__loc0);
2726
2749
  }
2727
2750
  }
@@ -2758,7 +2781,7 @@ class FreelookVirtualCamera extends VirtualCamera {
2758
2781
  }
2759
2782
  return out;
2760
2783
  }
2761
- _calculateLookAtOffset(panDelta) {
2784
+ _calculateTargetLookAt(panDelta) {
2762
2785
  const { __xAxis, __yAxis, __posDelta } = FreelookVirtualCamera;
2763
2786
  __xAxis.setFromMatrixColumn(this.node.matrix, 0);
2764
2787
  __yAxis.setFromMatrixColumn(this.node.matrix, 1);
@@ -2766,46 +2789,43 @@ class FreelookVirtualCamera extends VirtualCamera {
2766
2789
  __yAxis.y = 0;
2767
2790
  __yAxis.normalize();
2768
2791
  }
2769
- __posDelta.copy(this.node.position).sub(this.lookAtPosition);
2792
+ __posDelta.copy(this.node.position).sub(this.lookAt);
2770
2793
  const length = __posDelta.length() * 2 * tan(degToRad(this.fov * 0.5));
2771
- return this._targetLookAtOffset.sub(__xAxis.multiplyScalar(panDelta.x * length)).add(__yAxis.multiplyScalar(panDelta.y * length));
2794
+ this._targetLookAt.sub(__xAxis.multiplyScalar(panDelta.x * length)).add(__yAxis.multiplyScalar(panDelta.y * length));
2772
2795
  }
2773
- _calculateSpherical(rotateDelta, radius) {
2774
- const spherical = this._targetSpherical;
2796
+ _calculateTargetSpringArm(rotateDelta, radius) {
2775
2797
  if (rotateDelta) {
2776
- spherical.theta -= rotateDelta.x;
2777
- spherical.phi += rotateDelta.y;
2798
+ this._targetTheta -= rotateDelta.x;
2799
+ this._targetPhi += rotateDelta.y;
2778
2800
  }
2779
2801
  if (radius) {
2780
- spherical.radius = radius;
2802
+ this._targetSpringLength = radius;
2781
2803
  }
2782
- spherical.theta = clamp(spherical.theta, this.thetaMin, this.thetaMax);
2783
- spherical.phi = clamp(spherical.phi, this.phiMin, this.phiMax);
2784
- spherical.radius = clamp(spherical.radius, this.distanceMin, this.distanceMax);
2785
- return spherical;
2804
+ this._targetTheta = clamp(this._targetTheta, this.thetaMin, this.thetaMax);
2805
+ this._targetPhi = clamp(this._targetPhi, this.phiMin, this.phiMax);
2806
+ this._targetSpringLength = clamp(this._targetSpringLength, this.distanceMin, this.distanceMax);
2786
2807
  }
2787
- gotoPOI(springLength, rotation, lookAt, fov = this.fov, smoothing = this.smoothing) {
2808
+ gotoPOI({ springLength = this._targetSpringLength, theta = this._targetTheta, phi = this._targetPhi, lookAt = this._lookAt, fov = this.lens.fov, smoothing = this.smoothing }) {
2788
2809
  this._targetFov = fov;
2789
2810
  this._tempSmoothing = smoothing;
2790
- this._targetSpherical.radius = springLength;
2791
- if (rotation) {
2792
- this._targetSpherical.theta = rotation.x;
2793
- this._targetSpherical.phi = rotation.y;
2794
- }
2795
- this._calculateSpherical();
2796
- if (lookAt) {
2797
- this._targetLookAtOffset.copy(lookAt).sub(this.lookAt.position);
2798
- }
2811
+ this._targetSpringLength = springLength;
2812
+ this._targetPhi = phi;
2813
+ this._targetTheta = theta;
2814
+ this._calculateTargetSpringArm();
2815
+ const theta0 = three.MathUtils.euclideanModulo(this._spherical.theta, PI2);
2816
+ const theta1 = theta0 - PI2;
2817
+ this._spherical.theta = abs(theta0 - this._targetTheta) < abs(theta1 - this._targetTheta) ? theta0 : theta1;
2818
+ this._targetLookAt.copy(lookAt);
2799
2819
  }
2800
2820
  update(dt) {
2801
2821
  const smoothing = this._tempSmoothing;
2802
- this._spherical.theta = FInterpTo(this._spherical.theta, this._targetSpherical.theta, dt, smoothing);
2803
- this._spherical.phi = FInterpTo(this._spherical.phi, this._targetSpherical.phi, dt, smoothing);
2804
- this._spherical.radius = FInterpTo(this._spherical.radius, this._targetSpherical.radius, dt, smoothing);
2805
- this.node.position.setFromSpherical(this._spherical).add(this.lookAtPosition);
2806
- this.fov = FInterpTo(this.fov, this._targetFov, dt, smoothing);
2807
- VInterpTo(this._lookAtOffset, this._targetLookAtOffset, dt, smoothing);
2808
- this.node.lookAt(this.lookAtPosition);
2822
+ this._spherical.theta = FInterpTo(this._spherical.theta, this._targetTheta, dt, smoothing);
2823
+ this._spherical.phi = FInterpTo(this._spherical.phi, this._targetPhi, dt, smoothing);
2824
+ this._spherical.radius = FInterpTo(this._spherical.radius, this._targetSpringLength, dt, smoothing);
2825
+ this.lens.fov = FInterpTo(this.lens.fov, this._targetFov, dt, smoothing);
2826
+ VInterpTo(this._lookAt, this._targetLookAt, dt, smoothing);
2827
+ this.node.position.setFromSpherical(this._spherical).add(this._lookAt);
2828
+ this.node.lookAt(this._lookAt);
2809
2829
  }
2810
2830
  constructor(...args){
2811
2831
  super(...args);
@@ -2814,30 +2834,28 @@ class FreelookVirtualCamera extends VirtualCamera {
2814
2834
  this._preLoc0 = new three.Vector2();
2815
2835
  this._preLoc1 = new three.Vector2();
2816
2836
  this._spherical = new three.Spherical();
2817
- this._lookAtPosition = new three.Vector3();
2818
- this._lookAtOffset = new three.Vector3();
2837
+ this._lookAt = new three.Vector3();
2819
2838
  this._tempSmoothing = 0;
2839
+ this._targetTheta = 0;
2840
+ this._targetPhi = 0;
2841
+ this._targetSpringLength = 1;
2820
2842
  this._targetFov = this.fov;
2821
- this._targetLookAtOffset = new three.Vector3();
2822
- this._targetSpherical = new three.Spherical();
2843
+ this._targetLookAt = new three.Vector3();
2823
2844
  this.forbidX = false;
2824
2845
  this.forbidY = false;
2825
2846
  this.forbidZ = false;
2826
2847
  this.forbidPanX = false;
2827
2848
  this.forbidPanY = false;
2828
2849
  this.forbitPanOffsetY = false;
2850
+ this.panSpeed = 1;
2851
+ this.rotateSpeed = 1;
2829
2852
  this.smoothing = 5;
2830
- this.rotateSpeed = 2;
2831
- this.panSpeed = 2;
2832
- this.panScale = new three.Vector3(1, 1, 1);
2833
- this.phiMin = 0.001;
2834
- this.phiMax = Math.PI - 0.001;
2853
+ this.phiMin = ESP;
2854
+ this.phiMax = Math.PI - ESP;
2835
2855
  this.thetaMin = -Infinity;
2836
2856
  this.thetaMax = Infinity;
2837
- this.distanceMin = 0.001;
2857
+ this.distanceMin = ESP;
2838
2858
  this.distanceMax = Infinity;
2839
- this.rotateTouchID = 0;
2840
- this.lookAt = new three.Object3D();
2841
2859
  }
2842
2860
  }
2843
2861
  FreelookVirtualCamera.__loc0 = new three.Vector2();
@@ -2881,9 +2899,83 @@ __decorate([
2881
2899
  dir: "set"
2882
2900
  })
2883
2901
  ], FreelookVirtualCamera.prototype, "forbitPanOffsetY", void 0);
2902
+ __decorate([
2903
+ property({
2904
+ dir: "set",
2905
+ step: 0.01
2906
+ })
2907
+ ], FreelookVirtualCamera.prototype, "panSpeed", void 0);
2908
+ __decorate([
2909
+ property({
2910
+ dir: "set",
2911
+ step: 0.01
2912
+ })
2913
+ ], FreelookVirtualCamera.prototype, "rotateSpeed", void 0);
2914
+ __decorate([
2915
+ property({
2916
+ dir: "set",
2917
+ step: 0.01
2918
+ })
2919
+ ], FreelookVirtualCamera.prototype, "smoothing", void 0);
2920
+ __decorate([
2921
+ property({
2922
+ dir: "set",
2923
+ step: 0.01
2924
+ })
2925
+ ], FreelookVirtualCamera.prototype, "phiMin", void 0);
2926
+ __decorate([
2927
+ property({
2928
+ dir: "set",
2929
+ step: 0.01
2930
+ })
2931
+ ], FreelookVirtualCamera.prototype, "phiMax", void 0);
2932
+ __decorate([
2933
+ property({
2934
+ dir: "set",
2935
+ step: 0.01
2936
+ })
2937
+ ], FreelookVirtualCamera.prototype, "thetaMin", void 0);
2938
+ __decorate([
2939
+ property({
2940
+ dir: "set",
2941
+ step: 0.01
2942
+ })
2943
+ ], FreelookVirtualCamera.prototype, "thetaMax", void 0);
2944
+ __decorate([
2945
+ property({
2946
+ dir: "set",
2947
+ step: 0.01
2948
+ })
2949
+ ], FreelookVirtualCamera.prototype, "distanceMin", void 0);
2950
+ __decorate([
2951
+ property({
2952
+ dir: "set",
2953
+ step: 0.01
2954
+ })
2955
+ ], FreelookVirtualCamera.prototype, "distanceMax", void 0);
2956
+ __decorate([
2957
+ property({
2958
+ step: 0.01
2959
+ })
2960
+ ], FreelookVirtualCamera.prototype, "lookAt", null);
2961
+ __decorate([
2962
+ property({
2963
+ step: 0.01
2964
+ })
2965
+ ], FreelookVirtualCamera.prototype, "springLength", null);
2966
+ __decorate([
2967
+ property({
2968
+ step: 0.01
2969
+ })
2970
+ ], FreelookVirtualCamera.prototype, "theta", null);
2971
+ __decorate([
2972
+ property({
2973
+ step: 0.01
2974
+ })
2975
+ ], FreelookVirtualCamera.prototype, "phi", null);
2884
2976
  __decorate([
2885
2977
  property
2886
- ], FreelookVirtualCamera.prototype, "printInfo", null);
2978
+ ], FreelookVirtualCamera.prototype, "fov", null);
2887
2979
 
2888
2980
  class Box extends three.Mesh {
2889
2981
  constructor(...args){