@xviewer.js/core 1.0.4-alpha.5 → 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
@@ -2252,22 +2252,11 @@ class ComponentScheduler {
2252
2252
  }
2253
2253
  }
2254
2254
  constructor(){
2255
- this.startInvoker = new InvokerOneCall((comp)=>{
2256
- comp.start();
2257
- comp.start = undefined;
2258
- });
2259
- this.updateInvoker = new Invoker((comp, dt)=>{
2260
- !comp.start && comp.update(dt);
2261
- });
2262
- this.lastUpdateInvoker = new Invoker((comp, dt)=>{
2263
- !comp.start && comp.lastUpdate(dt);
2264
- });
2265
- this.renderInvoker = new Invoker((comp, dt)=>{
2266
- !comp.start && comp.render(dt);
2267
- });
2268
- this.resizeInvoker = new Invoker((comp, width, height)=>{
2269
- !comp.start && comp.resize(width, height);
2270
- });
2255
+ this.startInvoker = new InvokerOneCall((comp)=>comp.start());
2256
+ this.updateInvoker = new Invoker((comp, dt)=>comp.update(dt));
2257
+ this.lastUpdateInvoker = new Invoker((comp, dt)=>comp.lastUpdate(dt));
2258
+ this.renderInvoker = new Invoker((comp, dt)=>comp.render(dt));
2259
+ this.resizeInvoker = new Invoker((comp, width, height)=>comp.resize(width, height));
2271
2260
  }
2272
2261
  }
2273
2262
 
@@ -2577,6 +2566,60 @@ class Pressability {
2577
2566
  }
2578
2567
  }
2579
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
+ }
2580
2623
  class DeviceInput extends Component {
2581
2624
  get pointer() {
2582
2625
  return this._pointer;
@@ -2593,9 +2636,18 @@ class DeviceInput extends Component {
2593
2636
  get prePointerPixel() {
2594
2637
  return this._prePointerPixel;
2595
2638
  }
2639
+ get preTouches() {
2640
+ return this._preTouches;
2641
+ }
2596
2642
  get mouseWheel() {
2597
2643
  return this._mouseWheel;
2598
2644
  }
2645
+ get touchStart() {
2646
+ return this._touchStart;
2647
+ }
2648
+ get touchMoving() {
2649
+ return this._touchMoving;
2650
+ }
2599
2651
  get touchCount() {
2600
2652
  return this._touchCount;
2601
2653
  }
@@ -2659,7 +2711,12 @@ class DeviceInput extends Component {
2659
2711
  lastUpdate(dt) {
2660
2712
  this._prePointer.copy(this._pointer);
2661
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
+ }
2662
2718
  this._mouseWheel = 0;
2719
+ this._touchStart = false;
2663
2720
  }
2664
2721
  connect(target, event) {
2665
2722
  switch(event){
@@ -2755,33 +2812,53 @@ class DeviceInput extends Component {
2755
2812
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2756
2813
  }
2757
2814
  _onMouseWheel(e) {
2758
- this._mouseWheel = e.deltaY || e.wheelDelta;
2815
+ this._mouseWheel = this._normalizeWheel(e).pixelY;
2759
2816
  this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
2760
2817
  }
2761
2818
  _onTouchStart(e) {
2819
+ this._touchStart = true;
2762
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
+ }
2763
2844
  this.viewer.emit(DeviceInput.TOUCH_START, e);
2764
2845
  }
2765
2846
  _onTouchEnd(e) {
2847
+ this._touchMoving = false;
2766
2848
  e = this._remapTouch(e);
2767
2849
  this.viewer.emit(DeviceInput.TOUCH_END, e);
2768
2850
  }
2769
2851
  _onTouchMove(e) {
2852
+ this._touchMoving = true;
2770
2853
  e = this._remapTouch(e);
2771
- const touches = e.touches;
2772
- const touchesTo = this._touches;
2773
- for(let i = touches.length; i--;){
2774
- if (touchesTo[i] == undefined) {
2775
- touchesTo[i] = {
2776
- id: -1,
2777
- position: new Vector2()
2778
- };
2779
- }
2780
- const touch = touches[i];
2781
- touchesTo[i].id = touch.identifier;
2782
- touchesTo[i].position.set(touch.pageX, touch.pageY);
2783
- }
2784
- 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;
2785
2862
  this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
2786
2863
  }
2787
2864
  _onKeyDown(e) {
@@ -2796,9 +2873,10 @@ class DeviceInput extends Component {
2796
2873
  this._keys[e.key] = false;
2797
2874
  this.viewer.emit(DeviceInput.KEYUP, e);
2798
2875
  }
2799
- constructor(target){
2800
- 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();
2801
- 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;
2802
2880
  }
2803
2881
  }
2804
2882
  DeviceInput.CLICK = "click";
@@ -5050,7 +5128,9 @@ class Viewer extends EventEmitter {
5050
5128
  this._mount = applyProps(new Object3D(), {
5051
5129
  name: "Mount"
5052
5130
  });
5053
- this._input = this.add(new DeviceInput(input || this._canvas));
5131
+ this._input = this.add(new DeviceInput(input || {
5132
+ source: this._canvas
5133
+ }));
5054
5134
  this.add(Renderer);
5055
5135
  this.addLoader(GLTFLoader);
5056
5136
  this.addLoader(HDRLoader);