@xviewer.js/core 1.0.4-alpha.6 → 1.0.4-alpha.8
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 +116 -22
- package/dist/main.cjs.map +1 -1
- package/dist/module.js +116 -22
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/DeviceInput.d.ts +20 -1
- package/types/Viewer.d.ts +2 -2
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){
|
|
@@ -2719,14 +2787,16 @@ class DeviceInput extends Component {
|
|
|
2719
2787
|
const isDocument = target instanceof Document;
|
|
2720
2788
|
const width = isDocument ? window.innerWidth : target.offsetWidth;
|
|
2721
2789
|
const height = isDocument ? window.innerHeight : target.offsetHeight;
|
|
2722
|
-
this._pointer.x = e.
|
|
2723
|
-
this._pointer.y = 1 - e.
|
|
2724
|
-
this._pointerPixel.set(e.
|
|
2790
|
+
this._pointer.x = e.pageX / width * 2 - 1;
|
|
2791
|
+
this._pointer.y = 1 - e.pageY / height * 2;
|
|
2792
|
+
this._pointerPixel.set(e.pageX, e.pageY);
|
|
2725
2793
|
}
|
|
2726
2794
|
_onPointerDown(e) {
|
|
2727
2795
|
e = this._remapPointer(e);
|
|
2728
2796
|
this._pointerButton = e.button;
|
|
2729
2797
|
this._computePointer(e);
|
|
2798
|
+
this._prePointer.copy(this._pointer);
|
|
2799
|
+
this._prePointerPixel.copy(this._pointerPixel);
|
|
2730
2800
|
this._pressability.pointerDown(this._pointer, this.viewer.camera);
|
|
2731
2801
|
this.viewer.emit(DeviceInput.POINTER_DOWN, e);
|
|
2732
2802
|
}
|
|
@@ -2744,33 +2814,54 @@ class DeviceInput extends Component {
|
|
|
2744
2814
|
this.viewer.emit(DeviceInput.POINTER_MOVE, e);
|
|
2745
2815
|
}
|
|
2746
2816
|
_onMouseWheel(e) {
|
|
2747
|
-
this._mouseWheel =
|
|
2817
|
+
this._mouseWheel = this._normalizeWheel(e).pixelY;
|
|
2748
2818
|
this.viewer.emit(DeviceInput.MOUSE_WHEEL, e);
|
|
2749
2819
|
}
|
|
2750
2820
|
_onTouchStart(e) {
|
|
2821
|
+
this._touchStart = true;
|
|
2751
2822
|
e = this._remapTouch(e);
|
|
2823
|
+
const curr = e.touches;
|
|
2824
|
+
const touches = this._touches;
|
|
2825
|
+
const preTouches = this._preTouches;
|
|
2826
|
+
for(let i = curr.length; i--;){
|
|
2827
|
+
if (touches[i] === undefined) {
|
|
2828
|
+
touches[i] = {
|
|
2829
|
+
id: -1,
|
|
2830
|
+
position: new Vector2()
|
|
2831
|
+
};
|
|
2832
|
+
}
|
|
2833
|
+
const touch = curr[i];
|
|
2834
|
+
touches[i].id = touch.identifier;
|
|
2835
|
+
touches[i].position.set(touch.pageX, touch.pageY);
|
|
2836
|
+
if (preTouches[i] === undefined) {
|
|
2837
|
+
preTouches[i] = {
|
|
2838
|
+
id: touches[i].id,
|
|
2839
|
+
position: touches[i].position.clone()
|
|
2840
|
+
};
|
|
2841
|
+
} else {
|
|
2842
|
+
preTouches[i].id = touches[i].id;
|
|
2843
|
+
preTouches[i].position.copy(touches[i].position);
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
this._touchCount = curr.length;
|
|
2752
2847
|
this.viewer.emit(DeviceInput.TOUCH_START, e);
|
|
2753
2848
|
}
|
|
2754
2849
|
_onTouchEnd(e) {
|
|
2850
|
+
this._touchMoving = false;
|
|
2755
2851
|
e = this._remapTouch(e);
|
|
2756
2852
|
this.viewer.emit(DeviceInput.TOUCH_END, e);
|
|
2757
2853
|
}
|
|
2758
2854
|
_onTouchMove(e) {
|
|
2855
|
+
this._touchMoving = true;
|
|
2759
2856
|
e = this._remapTouch(e);
|
|
2760
|
-
const
|
|
2761
|
-
const
|
|
2762
|
-
for(let i =
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
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;
|
|
2857
|
+
const curr = e.touches;
|
|
2858
|
+
const touches = this._touches;
|
|
2859
|
+
for(let i = curr.length; i--;){
|
|
2860
|
+
const touch = curr[i];
|
|
2861
|
+
touches[i].id = touch.identifier;
|
|
2862
|
+
touches[i].position.set(touch.pageX, touch.pageY);
|
|
2863
|
+
}
|
|
2864
|
+
this._touchCount = curr.length;
|
|
2774
2865
|
this.viewer.emit(DeviceInput.TOUCH_MOVE, e);
|
|
2775
2866
|
}
|
|
2776
2867
|
_onKeyDown(e) {
|
|
@@ -2785,9 +2876,10 @@ class DeviceInput extends Component {
|
|
|
2785
2876
|
this._keys[e.key] = false;
|
|
2786
2877
|
this.viewer.emit(DeviceInput.KEYUP, e);
|
|
2787
2878
|
}
|
|
2788
|
-
constructor(
|
|
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 =
|
|
2879
|
+
constructor(option){
|
|
2880
|
+
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();
|
|
2881
|
+
this._target = option.source;
|
|
2882
|
+
this._normalizeWheel = option.normalizeWheel || normalizeWheel;
|
|
2791
2883
|
}
|
|
2792
2884
|
}
|
|
2793
2885
|
DeviceInput.CLICK = "click";
|
|
@@ -5039,7 +5131,9 @@ class Viewer extends EventEmitter {
|
|
|
5039
5131
|
this._mount = applyProps(new Object3D(), {
|
|
5040
5132
|
name: "Mount"
|
|
5041
5133
|
});
|
|
5042
|
-
this._input = this.add(new DeviceInput(input ||
|
|
5134
|
+
this._input = this.add(new DeviceInput(input || {
|
|
5135
|
+
source: this._canvas
|
|
5136
|
+
}));
|
|
5043
5137
|
this.add(Renderer);
|
|
5044
5138
|
this.addLoader(GLTFLoader);
|
|
5045
5139
|
this.addLoader(HDRLoader);
|