@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/main.cjs CHANGED
@@ -2272,22 +2272,11 @@ class ComponentScheduler {
2272
2272
  }
2273
2273
  }
2274
2274
  constructor(){
2275
- this.startInvoker = new InvokerOneCall((comp)=>{
2276
- comp.start();
2277
- comp.start = undefined;
2278
- });
2279
- this.updateInvoker = new Invoker((comp, dt)=>{
2280
- !comp.start && comp.update(dt);
2281
- });
2282
- this.lastUpdateInvoker = new Invoker((comp, dt)=>{
2283
- !comp.start && comp.lastUpdate(dt);
2284
- });
2285
- this.renderInvoker = new Invoker((comp, dt)=>{
2286
- !comp.start && comp.render(dt);
2287
- });
2288
- this.resizeInvoker = new Invoker((comp, width, height)=>{
2289
- !comp.start && comp.resize(width, height);
2290
- });
2275
+ this.startInvoker = new InvokerOneCall((comp)=>comp.start());
2276
+ this.updateInvoker = new Invoker((comp, dt)=>comp.update(dt));
2277
+ this.lastUpdateInvoker = new Invoker((comp, dt)=>comp.lastUpdate(dt));
2278
+ this.renderInvoker = new Invoker((comp, dt)=>comp.render(dt));
2279
+ this.resizeInvoker = new Invoker((comp, width, height)=>comp.resize(width, height));
2291
2280
  }
2292
2281
  }
2293
2282
 
@@ -2597,6 +2586,60 @@ class Pressability {
2597
2586
  }
2598
2587
  }
2599
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
+ }
2600
2643
  class DeviceInput extends Component {
2601
2644
  get pointer() {
2602
2645
  return this._pointer;
@@ -2613,9 +2656,18 @@ class DeviceInput extends Component {
2613
2656
  get prePointerPixel() {
2614
2657
  return this._prePointerPixel;
2615
2658
  }
2659
+ get preTouches() {
2660
+ return this._preTouches;
2661
+ }
2616
2662
  get mouseWheel() {
2617
2663
  return this._mouseWheel;
2618
2664
  }
2665
+ get touchStart() {
2666
+ return this._touchStart;
2667
+ }
2668
+ get touchMoving() {
2669
+ return this._touchMoving;
2670
+ }
2619
2671
  get touchCount() {
2620
2672
  return this._touchCount;
2621
2673
  }
@@ -2679,7 +2731,12 @@ class DeviceInput extends Component {
2679
2731
  lastUpdate(dt) {
2680
2732
  this._prePointer.copy(this._pointer);
2681
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
+ }
2682
2738
  this._mouseWheel = 0;
2739
+ this._touchStart = false;
2683
2740
  }
2684
2741
  connect(target, event) {
2685
2742
  switch(event){
@@ -2775,33 +2832,53 @@ class DeviceInput extends Component {
2775
2832
  this.viewer.emit(DeviceInput.POINTER_MOVE, e);
2776
2833
  }
2777
2834
  _onMouseWheel(e) {
2778
- this._mouseWheel = e.deltaY || e.wheelDelta;
2835
+ this._mouseWheel = this._normalizeWheel(e).pixelY;
2779
2836
  this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
2780
2837
  }
2781
2838
  _onTouchStart(e) {
2839
+ this._touchStart = true;
2782
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
+ }
2783
2864
  this.viewer.emit(DeviceInput.TOUCH_START, e);
2784
2865
  }
2785
2866
  _onTouchEnd(e) {
2867
+ this._touchMoving = false;
2786
2868
  e = this._remapTouch(e);
2787
2869
  this.viewer.emit(DeviceInput.TOUCH_END, e);
2788
2870
  }
2789
2871
  _onTouchMove(e) {
2872
+ this._touchMoving = true;
2790
2873
  e = this._remapTouch(e);
2791
- const touches = e.touches;
2792
- const touchesTo = this._touches;
2793
- for(let i = touches.length; i--;){
2794
- if (touchesTo[i] == undefined) {
2795
- touchesTo[i] = {
2796
- id: -1,
2797
- position: new THREE.Vector2()
2798
- };
2799
- }
2800
- const touch = touches[i];
2801
- touchesTo[i].id = touch.identifier;
2802
- touchesTo[i].position.set(touch.pageX, touch.pageY);
2803
- }
2804
- 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;
2805
2882
  this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
2806
2883
  }
2807
2884
  _onKeyDown(e) {
@@ -2816,9 +2893,10 @@ class DeviceInput extends Component {
2816
2893
  this._keys[e.key] = false;
2817
2894
  this.viewer.emit(DeviceInput.KEYUP, e);
2818
2895
  }
2819
- constructor(target){
2820
- 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();
2821
- 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;
2822
2900
  }
2823
2901
  }
2824
2902
  DeviceInput.CLICK = "click";
@@ -5070,7 +5148,9 @@ class Viewer extends EventEmitter {
5070
5148
  this._mount = applyProps(new THREE.Object3D(), {
5071
5149
  name: "Mount"
5072
5150
  });
5073
- this._input = this.add(new DeviceInput(input || this._canvas));
5151
+ this._input = this.add(new DeviceInput(input || {
5152
+ source: this._canvas
5153
+ }));
5074
5154
  this.add(Renderer);
5075
5155
  this.addLoader(GLTFLoader);
5076
5156
  this.addLoader(HDRLoader);