@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/module.js CHANGED
@@ -2566,6 +2566,60 @@ class Pressability {
2566
2566
  }
2567
2567
  }
2568
2568
 
2569
+ const PIXEL_STEP = 10;
2570
+ const LINE_HEIGHT = 40;
2571
+ const PAGE_HEIGHT = 800;
2572
+ function normalizeWheel(/*object*/ event) /*object*/ {
2573
+ let sX = 0, sY = 0, pX = 0, pY = 0; // pixelX, pixelY
2574
+ // Legacy
2575
+ if ('detail' in event) {
2576
+ sY = event.detail;
2577
+ }
2578
+ if ('wheelDelta' in event) {
2579
+ sY = -event.wheelDelta / 120;
2580
+ }
2581
+ if ('wheelDeltaY' in event) {
2582
+ sY = -event.wheelDeltaY / 120;
2583
+ }
2584
+ if ('wheelDeltaX' in event) {
2585
+ sX = -event.wheelDeltaX / 120;
2586
+ }
2587
+ // side scrolling on FF with DOMMouseScroll
2588
+ if ('axis' in event && event.axis === event.HORIZONTAL_AXIS) {
2589
+ sX = sY;
2590
+ sY = 0;
2591
+ }
2592
+ pX = sX * PIXEL_STEP;
2593
+ pY = sY * PIXEL_STEP;
2594
+ if ('deltaY' in event) {
2595
+ pY = event.deltaY;
2596
+ }
2597
+ if ('deltaX' in event) {
2598
+ pX = event.deltaX;
2599
+ }
2600
+ if ((pX || pY) && event.deltaMode) {
2601
+ if (event.deltaMode == 1) {
2602
+ pX *= LINE_HEIGHT;
2603
+ pY *= LINE_HEIGHT;
2604
+ } else {
2605
+ pX *= PAGE_HEIGHT;
2606
+ pY *= PAGE_HEIGHT;
2607
+ }
2608
+ }
2609
+ // Fall-back if spin cannot be determined
2610
+ if (pX && !sX) {
2611
+ sX = pX < 1 ? -1 : 1;
2612
+ }
2613
+ if (pY && !sY) {
2614
+ sY = pY < 1 ? -1 : 1;
2615
+ }
2616
+ return {
2617
+ spinX: sX,
2618
+ spinY: sY,
2619
+ pixelX: pX,
2620
+ pixelY: pY
2621
+ };
2622
+ }
2569
2623
  class DeviceInput extends Component {
2570
2624
  get pointer() {
2571
2625
  return this._pointer;
@@ -2582,9 +2636,18 @@ class DeviceInput extends Component {
2582
2636
  get prePointerPixel() {
2583
2637
  return this._prePointerPixel;
2584
2638
  }
2639
+ get preTouches() {
2640
+ return this._preTouches;
2641
+ }
2585
2642
  get mouseWheel() {
2586
2643
  return this._mouseWheel;
2587
2644
  }
2645
+ get touchStart() {
2646
+ return this._touchStart;
2647
+ }
2648
+ get touchMoving() {
2649
+ return this._touchMoving;
2650
+ }
2588
2651
  get touchCount() {
2589
2652
  return this._touchCount;
2590
2653
  }
@@ -2648,7 +2711,12 @@ class DeviceInput extends Component {
2648
2711
  lastUpdate(dt) {
2649
2712
  this._prePointer.copy(this._pointer);
2650
2713
  this._prePointerPixel.copy(this._pointerPixel);
2714
+ for(let i = this._touchCount; i--;){
2715
+ this._preTouches[i].id = this._touches[i].id;
2716
+ this._preTouches[i].position.copy(this._touches[i].position);
2717
+ }
2651
2718
  this._mouseWheel = 0;
2719
+ this._touchStart = false;
2652
2720
  }
2653
2721
  connect(target, event) {
2654
2722
  switch(event){
@@ -2744,33 +2812,53 @@ class DeviceInput extends Component {
2744
2812
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2745
2813
  }
2746
2814
  _onMouseWheel(e) {
2747
- this._mouseWheel = e.deltaY || e.wheelDelta;
2815
+ this._mouseWheel = this._normalizeWheel(e).pixelY;
2748
2816
  this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
2749
2817
  }
2750
2818
  _onTouchStart(e) {
2819
+ this._touchStart = true;
2751
2820
  e = this._remapTouch(e);
2821
+ const curr = e.touches;
2822
+ const touches = this._touches;
2823
+ const preTouches = this._preTouches;
2824
+ for(let i = curr.length; i--;){
2825
+ if (touches[i] === undefined) {
2826
+ touches[i] = {
2827
+ id: -1,
2828
+ position: new Vector2()
2829
+ };
2830
+ }
2831
+ const touch = curr[i];
2832
+ touches[i].id = touch.identifier;
2833
+ touches[i].position.set(touch.pageX, touch.pageY);
2834
+ if (preTouches[i] === undefined) {
2835
+ preTouches[i] = {
2836
+ id: touches[i].id,
2837
+ position: touches[i].position.clone()
2838
+ };
2839
+ } else {
2840
+ preTouches[i].id = touches[i].id;
2841
+ preTouches[i].position.copy(touches[i].position);
2842
+ }
2843
+ }
2752
2844
  this.viewer.emit(DeviceInput.TOUCH_START, e);
2753
2845
  }
2754
2846
  _onTouchEnd(e) {
2847
+ this._touchMoving = false;
2755
2848
  e = this._remapTouch(e);
2756
2849
  this.viewer.emit(DeviceInput.TOUCH_END, e);
2757
2850
  }
2758
2851
  _onTouchMove(e) {
2852
+ this._touchMoving = true;
2759
2853
  e = this._remapTouch(e);
2760
- const touches = e.touches;
2761
- const touchesTo = this._touches;
2762
- for(let i = touches.length; i--;){
2763
- if (touchesTo[i] == undefined) {
2764
- touchesTo[i] = {
2765
- id: -1,
2766
- position: new Vector2()
2767
- };
2768
- }
2769
- const touch = touches[i];
2770
- touchesTo[i].id = touch.identifier;
2771
- touchesTo[i].position.set(touch.pageX, touch.pageY);
2772
- }
2773
- this._touchCount = touches.length;
2854
+ const curr = e.touches;
2855
+ const touches = this._touches;
2856
+ for(let i = curr.length; i--;){
2857
+ const touch = curr[i];
2858
+ touches[i].id = touch.identifier;
2859
+ touches[i].position.set(touch.pageX, touch.pageY);
2860
+ }
2861
+ this._touchCount = curr.length;
2774
2862
  this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
2775
2863
  }
2776
2864
  _onKeyDown(e) {
@@ -2785,9 +2873,10 @@ class DeviceInput extends Component {
2785
2873
  this._keys[e.key] = false;
2786
2874
  this.viewer.emit(DeviceInput.KEYUP, e);
2787
2875
  }
2788
- constructor(target){
2789
- super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._pointer = new Vector2(), this._pointerPixel = new Vector2(), this._pointerButton = -1, this._prePointer = new Vector2(), this._prePointerPixel = new Vector2(), this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2790
- this._target = target;
2876
+ constructor(option){
2877
+ super(), this._listeners = [], this._touches = [], this._touchCount = 0, this._touchStart = false, this._touchMoving = false, this._pointer = new Vector2(), this._pointerPixel = new Vector2(), this._pointerButton = -1, this._prePointer = new Vector2(), this._prePointerPixel = new Vector2(), this._preTouches = [], this._mouseWheel = 0, this._keys = {}, this._pressability = new Pressability();
2878
+ this._target = option.source;
2879
+ this._normalizeWheel = option.normalizeWheel || normalizeWheel;
2791
2880
  }
2792
2881
  }
2793
2882
  DeviceInput.CLICK = "click";
@@ -5039,7 +5128,9 @@ class Viewer extends EventEmitter {
5039
5128
  this._mount = applyProps(new Object3D(), {
5040
5129
  name: "Mount"
5041
5130
  });
5042
- this._input = this.add(new DeviceInput(input || this._canvas));
5131
+ this._input = this.add(new DeviceInput(input || {
5132
+ source: this._canvas
5133
+ }));
5043
5134
  this.add(Renderer);
5044
5135
  this.addLoader(GLTFLoader);
5045
5136
  this.addLoader(HDRLoader);