@xviewer.js/core 1.0.4-alpha.6 → 1.0.4-alpha.7

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.cjs CHANGED
@@ -2586,6 +2586,60 @@ class Pressability {
2586
2586
  }
2587
2587
  }
2588
2588
 
2589
+ const PIXEL_STEP = 10;
2590
+ const LINE_HEIGHT = 40;
2591
+ const PAGE_HEIGHT = 800;
2592
+ function normalizeWheel(/*object*/ event) /*object*/ {
2593
+ let sX = 0, sY = 0, pX = 0, pY = 0; // pixelX, pixelY
2594
+ // Legacy
2595
+ if ('detail' in event) {
2596
+ sY = event.detail;
2597
+ }
2598
+ if ('wheelDelta' in event) {
2599
+ sY = -event.wheelDelta / 120;
2600
+ }
2601
+ if ('wheelDeltaY' in event) {
2602
+ sY = -event.wheelDeltaY / 120;
2603
+ }
2604
+ if ('wheelDeltaX' in event) {
2605
+ sX = -event.wheelDeltaX / 120;
2606
+ }
2607
+ // side scrolling on FF with DOMMouseScroll
2608
+ if ('axis' in event && event.axis === event.HORIZONTAL_AXIS) {
2609
+ sX = sY;
2610
+ sY = 0;
2611
+ }
2612
+ pX = sX * PIXEL_STEP;
2613
+ pY = sY * PIXEL_STEP;
2614
+ if ('deltaY' in event) {
2615
+ pY = event.deltaY;
2616
+ }
2617
+ if ('deltaX' in event) {
2618
+ pX = event.deltaX;
2619
+ }
2620
+ if ((pX || pY) && event.deltaMode) {
2621
+ if (event.deltaMode == 1) {
2622
+ pX *= LINE_HEIGHT;
2623
+ pY *= LINE_HEIGHT;
2624
+ } else {
2625
+ pX *= PAGE_HEIGHT;
2626
+ pY *= PAGE_HEIGHT;
2627
+ }
2628
+ }
2629
+ // Fall-back if spin cannot be determined
2630
+ if (pX && !sX) {
2631
+ sX = pX < 1 ? -1 : 1;
2632
+ }
2633
+ if (pY && !sY) {
2634
+ sY = pY < 1 ? -1 : 1;
2635
+ }
2636
+ return {
2637
+ spinX: sX,
2638
+ spinY: sY,
2639
+ pixelX: pX,
2640
+ pixelY: pY
2641
+ };
2642
+ }
2589
2643
  class DeviceInput extends Component {
2590
2644
  get pointer() {
2591
2645
  return this._pointer;
@@ -2602,9 +2656,18 @@ class DeviceInput extends Component {
2602
2656
  get prePointerPixel() {
2603
2657
  return this._prePointerPixel;
2604
2658
  }
2659
+ get preTouches() {
2660
+ return this._preTouches;
2661
+ }
2605
2662
  get mouseWheel() {
2606
2663
  return this._mouseWheel;
2607
2664
  }
2665
+ get touchStart() {
2666
+ return this._touchStart;
2667
+ }
2668
+ get touchMoving() {
2669
+ return this._touchMoving;
2670
+ }
2608
2671
  get touchCount() {
2609
2672
  return this._touchCount;
2610
2673
  }
@@ -2668,7 +2731,12 @@ class DeviceInput extends Component {
2668
2731
  lastUpdate(dt) {
2669
2732
  this._prePointer.copy(this._pointer);
2670
2733
  this._prePointerPixel.copy(this._pointerPixel);
2734
+ for(let i = this._touchCount; i--;){
2735
+ this._preTouches[i].id = this._touches[i].id;
2736
+ this._preTouches[i].position.copy(this._touches[i].position);
2737
+ }
2671
2738
  this._mouseWheel = 0;
2739
+ this._touchStart = false;
2672
2740
  }
2673
2741
  connect(target, event) {
2674
2742
  switch(event){
@@ -2764,33 +2832,53 @@ class DeviceInput extends Component {
2764
2832
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2765
2833
  }
2766
2834
  _onMouseWheel(e) {
2767
- this._mouseWheel = e.deltaY || e.wheelDelta;
2835
+ this._mouseWheel = this._normalizeWheel(e).pixelY;
2768
2836
  this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
2769
2837
  }
2770
2838
  _onTouchStart(e) {
2839
+ this._touchStart = true;
2771
2840
  e = this._remapTouch(e);
2841
+ const curr = e.touches;
2842
+ const touches = this._touches;
2843
+ const preTouches = this._preTouches;
2844
+ for(let i = curr.length; i--;){
2845
+ if (touches[i] === undefined) {
2846
+ touches[i] = {
2847
+ id: -1,
2848
+ position: new THREE.Vector2()
2849
+ };
2850
+ }
2851
+ const touch = curr[i];
2852
+ touches[i].id = touch.identifier;
2853
+ touches[i].position.set(touch.pageX, touch.pageY);
2854
+ if (preTouches[i] === undefined) {
2855
+ preTouches[i] = {
2856
+ id: touches[i].id,
2857
+ position: touches[i].position.clone()
2858
+ };
2859
+ } else {
2860
+ preTouches[i].id = touches[i].id;
2861
+ preTouches[i].position.copy(touches[i].position);
2862
+ }
2863
+ }
2772
2864
  this.viewer.emit(DeviceInput.TOUCH_START, e);
2773
2865
  }
2774
2866
  _onTouchEnd(e) {
2867
+ this._touchMoving = false;
2775
2868
  e = this._remapTouch(e);
2776
2869
  this.viewer.emit(DeviceInput.TOUCH_END, e);
2777
2870
  }
2778
2871
  _onTouchMove(e) {
2872
+ this._touchMoving = true;
2779
2873
  e = this._remapTouch(e);
2780
- const touches = e.touches;
2781
- const touchesTo = this._touches;
2782
- for(let i = touches.length; i--;){
2783
- if (touchesTo[i] == undefined) {
2784
- touchesTo[i] = {
2785
- id: -1,
2786
- position: new THREE.Vector2()
2787
- };
2788
- }
2789
- const touch = touches[i];
2790
- touchesTo[i].id = touch.identifier;
2791
- touchesTo[i].position.set(touch.pageX, touch.pageY);
2792
- }
2793
- this._touchCount = touches.length;
2874
+ const curr = e.touches;
2875
+ const touches = this._touches;
2876
+ for(let i = curr.length; i--;){
2877
+ const touch = curr[i];
2878
+ touches[i].id = touch.identifier;
2879
+ touches[i].position.set(touch.pageX, touch.pageY);
2880
+ }
2881
+ this._touchCount = curr.length;
2794
2882
  this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
2795
2883
  }
2796
2884
  _onKeyDown(e) {
@@ -2805,9 +2893,10 @@ class DeviceInput extends Component {
2805
2893
  this._keys[e.key] = false;
2806
2894
  this.viewer.emit(DeviceInput.KEYUP, e);
2807
2895
  }
2808
- constructor(target){
2809
- super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._pointer = new THREE.Vector2(), this._pointerPixel = new THREE.Vector2(), this._pointerButton = -1, this._prePointer = new THREE.Vector2(), this._prePointerPixel = new THREE.Vector2(), this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2810
- this._target = target;
2896
+ constructor(option){
2897
+ super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new THREE.Vector2(), this._pointerPixel = new THREE.Vector2(), this._pointerButton = -1, this._prePointer = new THREE.Vector2(), this._prePointerPixel = new THREE.Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2898
+ this._target = option.source;
2899
+ this._normalizeWheel = option.normalizeWheel || normalizeWheel;
2811
2900
  }
2812
2901
  }
2813
2902
  DeviceInput.CLICK = "click";
@@ -5059,7 +5148,9 @@ class Viewer extends EventEmitter {
5059
5148
  this._mount = applyProps(new THREE.Object3D(), {
5060
5149
  name: "Mount"
5061
5150
  });
5062
- this._input = this.add(new DeviceInput(input || this._canvas));
5151
+ this._input = this.add(new DeviceInput(input || {
5152
+ source: this._canvas
5153
+ }));
5063
5154
  this.add(Renderer);
5064
5155
  this.addLoader(GLTFLoader);
5065
5156
  this.addLoader(HDRLoader);