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

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,39 @@ 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 = this._targetLookAt = v;
2630
+ }
2631
+ get springLength() {
2632
+ return this._spherical.radius;
2633
+ }
2634
+ set springLength(v) {
2635
+ this._spherical.radius = this._targetSpringLength = v;
2636
+ }
2637
+ get theta() {
2638
+ return this._spherical.theta;
2639
+ }
2640
+ set theta(v) {
2641
+ this._spherical.theta = this._targetTheta = v;
2642
+ }
2643
+ get phi() {
2644
+ return this._spherical.phi;
2645
+ }
2646
+ set phi(v) {
2647
+ this._spherical.phi = this._targetPhi = v;
2648
+ }
2649
+ get fov() {
2650
+ return this.lens.fov;
2651
+ }
2652
+ set fov(v) {
2653
+ this.lens.fov = this._targetFov = v;
2624
2654
  }
2625
2655
  onEnable() {
2626
2656
  this.viewer.on(DeviceInput.POINTER_DOWN, this._onPointerDown, this);
@@ -2642,10 +2672,7 @@ class FreelookVirtualCamera extends VirtualCamera {
2642
2672
  reset() {
2643
2673
  this._button = -1;
2644
2674
  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);
2675
+ this._setSpherical(this.node.position, this.lookAt);
2649
2676
  }
2650
2677
  _setSpherical(position, lookAt) {
2651
2678
  const { __posDelta } = FreelookVirtualCamera;
@@ -2669,12 +2696,12 @@ 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);
@@ -2682,46 +2709,44 @@ class FreelookVirtualCamera extends VirtualCamera {
2682
2709
  _onMouseWheel(e) {
2683
2710
  if (this.lookAt) {
2684
2711
  if (e.deltaY > 0) {
2685
- this._targetSpherical.radius *= this._calculateDistanceScale(1 / 0.85);
2712
+ this._targetSpringLength *= this._calculateDistanceScale(1 / 0.85);
2686
2713
  } else if (e.deltaY < 0) {
2687
- this._targetSpherical.radius *= this._calculateDistanceScale(0.85);
2714
+ this._targetSpringLength *= this._calculateDistanceScale(0.85);
2688
2715
  }
2689
2716
  }
2690
2717
  }
2691
2718
  _onTouchStart(e) {
2692
2719
  if (!SystemInfo.isMobile) return;
2693
2720
  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);
2721
+ if (touches.length > 1) {
2722
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
2723
+ this._preLoc1.set(touches[1].pageX, touches[1].pageY);
2724
+ } else if (touches.length > 0) {
2725
+ this._touchID = touches[0].identifier;
2726
+ this._preLoc0.set(touches[0].pageX, touches[0].pageY);
2701
2727
  }
2702
2728
  }
2703
2729
  _onTouchMove(e) {
2704
2730
  if (!SystemInfo.isMobile) return;
2705
2731
  const { __loc0, __loc1, __panDelta, __rotateDelta, __preCenter, __center } = FreelookVirtualCamera;
2706
2732
  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);
2733
+ if (touches.length > 1) {
2734
+ __loc0.set(touches[0].pageX, touches[0].pageY);
2735
+ __loc1.set(touches[1].pageX, touches[1].pageY);
2711
2736
  if (this.lookAt) {
2712
- this._targetSpherical.radius *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2737
+ this._targetSpringLength *= this._calculateDistanceScale(this._preLoc0.distanceTo(this._preLoc1) / __loc0.distanceTo(__loc1));
2713
2738
  }
2714
2739
  __preCenter.copy(this._preLoc0).add(this._preLoc1).multiplyScalar(0.5);
2715
2740
  __center.copy(__loc0).add(__loc1).multiplyScalar(0.5);
2716
2741
  this._calculatePanDelta(__panDelta, __preCenter, __center);
2717
- this._calculateLookAtOffset(__panDelta);
2742
+ this._calculateTargetLookAt(__panDelta);
2718
2743
  this._preLoc0.copy(__loc0);
2719
2744
  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);
2745
+ } else if (touches.length > 0) {
2746
+ if (this._touchID === touches[0].identifier) {
2747
+ __loc0.set(touches[0].pageX, touches[0].pageY);
2723
2748
  this._calculateRotatelDelta(__rotateDelta, this._preLoc0, __loc0);
2724
- this._calculateSpherical(__rotateDelta);
2749
+ this._calculateTargetSpringArm(__rotateDelta);
2725
2750
  this._preLoc0.copy(__loc0);
2726
2751
  }
2727
2752
  }
@@ -2758,7 +2783,7 @@ class FreelookVirtualCamera extends VirtualCamera {
2758
2783
  }
2759
2784
  return out;
2760
2785
  }
2761
- _calculateLookAtOffset(panDelta) {
2786
+ _calculateTargetLookAt(panDelta) {
2762
2787
  const { __xAxis, __yAxis, __posDelta } = FreelookVirtualCamera;
2763
2788
  __xAxis.setFromMatrixColumn(this.node.matrix, 0);
2764
2789
  __yAxis.setFromMatrixColumn(this.node.matrix, 1);
@@ -2766,46 +2791,43 @@ class FreelookVirtualCamera extends VirtualCamera {
2766
2791
  __yAxis.y = 0;
2767
2792
  __yAxis.normalize();
2768
2793
  }
2769
- __posDelta.copy(this.node.position).sub(this.lookAtPosition);
2794
+ __posDelta.copy(this.node.position).sub(this.lookAt);
2770
2795
  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));
2796
+ this._targetLookAt.sub(__xAxis.multiplyScalar(panDelta.x * length)).add(__yAxis.multiplyScalar(panDelta.y * length));
2772
2797
  }
2773
- _calculateSpherical(rotateDelta, radius) {
2774
- const spherical = this._targetSpherical;
2798
+ _calculateTargetSpringArm(rotateDelta, radius) {
2775
2799
  if (rotateDelta) {
2776
- spherical.theta -= rotateDelta.x;
2777
- spherical.phi += rotateDelta.y;
2800
+ this._targetTheta -= rotateDelta.x;
2801
+ this._targetPhi += rotateDelta.y;
2778
2802
  }
2779
2803
  if (radius) {
2780
- spherical.radius = radius;
2804
+ this._targetSpringLength = radius;
2781
2805
  }
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;
2806
+ this._targetTheta = clamp(this._targetTheta, this.thetaMin, this.thetaMax);
2807
+ this._targetPhi = clamp(this._targetPhi, this.phiMin, this.phiMax);
2808
+ this._targetSpringLength = clamp(this._targetSpringLength, this.distanceMin, this.distanceMax);
2786
2809
  }
2787
- gotoPOI(springLength, rotation, lookAt, fov = this.fov, smoothing = this.smoothing) {
2810
+ gotoPOI({ springLength = this._targetSpringLength, theta = this._targetTheta, phi = this._targetPhi, lookAt = this.lookAt, fov = this.lens.fov, smoothing = this.smoothing }) {
2788
2811
  this._targetFov = fov;
2789
2812
  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
- }
2813
+ this._targetSpringLength = springLength;
2814
+ this._targetPhi = phi;
2815
+ this._targetTheta = theta;
2816
+ this._calculateTargetSpringArm();
2817
+ const theta0 = three.MathUtils.euclideanModulo(this._spherical.theta, PI2);
2818
+ const theta1 = theta0 - PI2;
2819
+ this._spherical.theta = abs(theta0 - this._targetTheta) < abs(theta1 - this._targetTheta) ? theta0 : theta1;
2820
+ this._targetLookAt.copy(lookAt);
2799
2821
  }
2800
2822
  update(dt) {
2801
2823
  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);
2824
+ this._spherical.theta = FInterpTo(this._spherical.theta, this._targetTheta, dt, smoothing);
2825
+ this._spherical.phi = FInterpTo(this._spherical.phi, this._targetPhi, dt, smoothing);
2826
+ this._spherical.radius = FInterpTo(this._spherical.radius, this._targetSpringLength, dt, smoothing);
2827
+ this.lens.fov = FInterpTo(this.lens.fov, this._targetFov, dt, smoothing);
2828
+ VInterpTo(this._lookAt, this._targetLookAt, dt, smoothing);
2829
+ this.node.position.setFromSpherical(this._spherical).add(this.lookAt);
2830
+ this.node.lookAt(this._lookAt);
2809
2831
  }
2810
2832
  constructor(...args){
2811
2833
  super(...args);
@@ -2814,11 +2836,13 @@ class FreelookVirtualCamera extends VirtualCamera {
2814
2836
  this._preLoc0 = new three.Vector2();
2815
2837
  this._preLoc1 = new three.Vector2();
2816
2838
  this._spherical = new three.Spherical();
2817
- this._lookAtPosition = new three.Vector3();
2818
- this._lookAtOffset = new three.Vector3();
2839
+ this._lookAt = new three.Vector3();
2819
2840
  this._tempSmoothing = 0;
2841
+ this._targetTheta = 0;
2842
+ this._targetPhi = 0;
2843
+ this._targetSpringLength = 1;
2820
2844
  this._targetFov = this.fov;
2821
- this._targetLookAtOffset = new three.Vector3();
2845
+ this._targetLookAt = new three.Vector3();
2822
2846
  this._targetSpherical = new three.Spherical();
2823
2847
  this.forbidX = false;
2824
2848
  this.forbidY = false;
@@ -2826,18 +2850,15 @@ class FreelookVirtualCamera extends VirtualCamera {
2826
2850
  this.forbidPanX = false;
2827
2851
  this.forbidPanY = false;
2828
2852
  this.forbitPanOffsetY = false;
2853
+ this.panSpeed = 1;
2854
+ this.rotateSpeed = 1;
2829
2855
  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;
2856
+ this.phiMin = ESP;
2857
+ this.phiMax = Math.PI - ESP;
2835
2858
  this.thetaMin = -Infinity;
2836
2859
  this.thetaMax = Infinity;
2837
- this.distanceMin = 0.001;
2860
+ this.distanceMin = ESP;
2838
2861
  this.distanceMax = Infinity;
2839
- this.rotateTouchID = 0;
2840
- this.lookAt = new three.Object3D();
2841
2862
  }
2842
2863
  }
2843
2864
  FreelookVirtualCamera.__loc0 = new three.Vector2();
@@ -2881,9 +2902,83 @@ __decorate([
2881
2902
  dir: "set"
2882
2903
  })
2883
2904
  ], FreelookVirtualCamera.prototype, "forbitPanOffsetY", void 0);
2905
+ __decorate([
2906
+ property({
2907
+ dir: "set",
2908
+ step: 0.01
2909
+ })
2910
+ ], FreelookVirtualCamera.prototype, "panSpeed", void 0);
2911
+ __decorate([
2912
+ property({
2913
+ dir: "set",
2914
+ step: 0.01
2915
+ })
2916
+ ], FreelookVirtualCamera.prototype, "rotateSpeed", void 0);
2917
+ __decorate([
2918
+ property({
2919
+ dir: "set",
2920
+ step: 0.01
2921
+ })
2922
+ ], FreelookVirtualCamera.prototype, "smoothing", void 0);
2923
+ __decorate([
2924
+ property({
2925
+ dir: "set",
2926
+ step: 0.01
2927
+ })
2928
+ ], FreelookVirtualCamera.prototype, "phiMin", void 0);
2929
+ __decorate([
2930
+ property({
2931
+ dir: "set",
2932
+ step: 0.01
2933
+ })
2934
+ ], FreelookVirtualCamera.prototype, "phiMax", void 0);
2935
+ __decorate([
2936
+ property({
2937
+ dir: "set",
2938
+ step: 0.01
2939
+ })
2940
+ ], FreelookVirtualCamera.prototype, "thetaMin", void 0);
2941
+ __decorate([
2942
+ property({
2943
+ dir: "set",
2944
+ step: 0.01
2945
+ })
2946
+ ], FreelookVirtualCamera.prototype, "thetaMax", void 0);
2947
+ __decorate([
2948
+ property({
2949
+ dir: "set",
2950
+ step: 0.01
2951
+ })
2952
+ ], FreelookVirtualCamera.prototype, "distanceMin", void 0);
2953
+ __decorate([
2954
+ property({
2955
+ dir: "set",
2956
+ step: 0.01
2957
+ })
2958
+ ], FreelookVirtualCamera.prototype, "distanceMax", void 0);
2959
+ __decorate([
2960
+ property({
2961
+ step: 0.01
2962
+ })
2963
+ ], FreelookVirtualCamera.prototype, "lookAt", null);
2964
+ __decorate([
2965
+ property({
2966
+ step: 0.01
2967
+ })
2968
+ ], FreelookVirtualCamera.prototype, "springLength", null);
2969
+ __decorate([
2970
+ property({
2971
+ step: 0.01
2972
+ })
2973
+ ], FreelookVirtualCamera.prototype, "theta", null);
2974
+ __decorate([
2975
+ property({
2976
+ step: 0.01
2977
+ })
2978
+ ], FreelookVirtualCamera.prototype, "phi", null);
2884
2979
  __decorate([
2885
2980
  property
2886
- ], FreelookVirtualCamera.prototype, "printInfo", null);
2981
+ ], FreelookVirtualCamera.prototype, "fov", null);
2887
2982
 
2888
2983
  class Box extends three.Mesh {
2889
2984
  constructor(...args){