Commit
·
27ba54c
1
Parent(s):
c9731fb
added touch orbit
Browse files
viewer/src/routes/viewer/[slug]/SplatViewer.ts
CHANGED
@@ -759,6 +759,9 @@ export class SplatViewer implements IViewer {
|
|
759 |
document.addEventListener("dragleave", preventDefault);
|
760 |
document.addEventListener("contextmenu", preventDefault);
|
761 |
|
|
|
|
|
|
|
762 |
this.handleMouseDown = this.handleMouseDown.bind(this);
|
763 |
this.handleMouseUp = this.handleMouseUp.bind(this);
|
764 |
this.handleMouseMove = this.handleMouseMove.bind(this);
|
@@ -766,6 +769,9 @@ export class SplatViewer implements IViewer {
|
|
766 |
this.handleDrop = this.handleDrop.bind(this);
|
767 |
this.handleResize = this.handleResize.bind(this);
|
768 |
|
|
|
|
|
|
|
769 |
this.canvas.addEventListener("mousedown", this.handleMouseDown);
|
770 |
this.canvas.addEventListener("mouseup", this.handleMouseUp);
|
771 |
this.canvas.addEventListener("mousemove", this.handleMouseMove);
|
@@ -830,6 +836,39 @@ export class SplatViewer implements IViewer {
|
|
830 |
}
|
831 |
}
|
832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
handleMouseDown(e: MouseEvent) {
|
834 |
this.dragging = true;
|
835 |
this.panning = e.button === 2;
|
@@ -946,6 +985,9 @@ export class SplatViewer implements IViewer {
|
|
946 |
document.removeEventListener("dragleave", preventDefault);
|
947 |
document.removeEventListener("contextmenu", preventDefault);
|
948 |
|
|
|
|
|
|
|
949 |
this.canvas.removeEventListener("mousedown", this.handleMouseDown);
|
950 |
this.canvas.removeEventListener("mouseup", this.handleMouseUp);
|
951 |
this.canvas.removeEventListener("mousemove", this.handleMouseMove);
|
|
|
759 |
document.addEventListener("dragleave", preventDefault);
|
760 |
document.addEventListener("contextmenu", preventDefault);
|
761 |
|
762 |
+
this.handleTouchStart = this.handleTouchStart.bind(this);
|
763 |
+
this.handleTouchEnd = this.handleTouchEnd.bind(this);
|
764 |
+
this.handleTouchMove = this.handleTouchMove.bind(this);
|
765 |
this.handleMouseDown = this.handleMouseDown.bind(this);
|
766 |
this.handleMouseUp = this.handleMouseUp.bind(this);
|
767 |
this.handleMouseMove = this.handleMouseMove.bind(this);
|
|
|
769 |
this.handleDrop = this.handleDrop.bind(this);
|
770 |
this.handleResize = this.handleResize.bind(this);
|
771 |
|
772 |
+
this.canvas.addEventListener("touchstart", this.handleTouchStart);
|
773 |
+
this.canvas.addEventListener("touchend", this.handleTouchEnd);
|
774 |
+
this.canvas.addEventListener("touchmove", this.handleTouchMove);
|
775 |
this.canvas.addEventListener("mousedown", this.handleMouseDown);
|
776 |
this.canvas.addEventListener("mouseup", this.handleMouseUp);
|
777 |
this.canvas.addEventListener("mousemove", this.handleMouseMove);
|
|
|
836 |
}
|
837 |
}
|
838 |
|
839 |
+
handleTouchStart(e: TouchEvent) {
|
840 |
+
e.preventDefault();
|
841 |
+
this.dragging = true;
|
842 |
+
this.panning = e.touches.length === 2;
|
843 |
+
this.lastX = e.touches[0].clientX;
|
844 |
+
this.lastY = e.touches[0].clientY;
|
845 |
+
}
|
846 |
+
|
847 |
+
handleTouchEnd(e: TouchEvent) {
|
848 |
+
e.preventDefault();
|
849 |
+
this.dragging = false;
|
850 |
+
this.panning = false;
|
851 |
+
}
|
852 |
+
|
853 |
+
handleTouchMove(e: TouchEvent) {
|
854 |
+
e.preventDefault();
|
855 |
+
if (!this.dragging) return;
|
856 |
+
const dx = e.touches[0].clientX - this.lastX;
|
857 |
+
const dy = e.touches[0].clientY - this.lastY;
|
858 |
+
const zoomNorm = this.camera.getZoomNorm();
|
859 |
+
|
860 |
+
if (this.panning) {
|
861 |
+
this.camera.pan(-dx * this.camera.panSpeed * zoomNorm, -dy * this.camera.panSpeed * zoomNorm);
|
862 |
+
} else {
|
863 |
+
this.camera.desiredAlpha -= dx * this.camera.orbitSpeed;
|
864 |
+
this.camera.desiredBeta += dy * this.camera.orbitSpeed;
|
865 |
+
this.camera.desiredBeta = Math.min(Math.max(this.camera.desiredBeta, this.camera.minBeta), this.camera.maxBeta);
|
866 |
+
}
|
867 |
+
|
868 |
+
this.lastX = e.touches[0].clientX;
|
869 |
+
this.lastY = e.touches[0].clientY;
|
870 |
+
}
|
871 |
+
|
872 |
handleMouseDown(e: MouseEvent) {
|
873 |
this.dragging = true;
|
874 |
this.panning = e.button === 2;
|
|
|
985 |
document.removeEventListener("dragleave", preventDefault);
|
986 |
document.removeEventListener("contextmenu", preventDefault);
|
987 |
|
988 |
+
this.canvas.removeEventListener("touchstart", this.handleTouchStart);
|
989 |
+
this.canvas.removeEventListener("touchend", this.handleTouchEnd);
|
990 |
+
this.canvas.removeEventListener("touchmove", this.handleTouchMove);
|
991 |
this.canvas.removeEventListener("mousedown", this.handleMouseDown);
|
992 |
this.canvas.removeEventListener("mouseup", this.handleMouseUp);
|
993 |
this.canvas.removeEventListener("mousemove", this.handleMouseMove);
|