瀏覽代碼

Fix touch inputs

David `Deltakosh` Catuhe 5 年之前
父節點
當前提交
b4c0a357e4
共有 3 個文件被更改,包括 19 次插入3 次删除
  1. 2 1
      src/Cameras/Inputs/freeCameraMouseInput.ts
  2. 13 1
      src/Cameras/Inputs/freeCameraTouchInput.ts
  3. 4 1
      src/Cameras/touchCamera.ts

+ 2 - 1
src/Cameras/Inputs/freeCameraMouseInput.ts

@@ -68,7 +68,8 @@ export class FreeCameraMouseInput implements ICameraInput<FreeCamera> {
                     return;
                 }
 
-                if (!this.touchEnabled && evt.pointerType === "touch") {
+                let isMouseEvent = evt instanceof MouseEvent;
+                if (!this.touchEnabled && evt.pointerType === "touch" && !isMouseEvent) {
                     return;
                 }
 

+ 13 - 1
src/Cameras/Inputs/freeCameraTouchInput.ts

@@ -38,6 +38,18 @@ export class FreeCameraTouchInput implements ICameraInput<FreeCamera> {
     private _onLostFocus: Nullable<(e: FocusEvent) => any>;
 
     /**
+     * Manage the touch inputs to control the movement of a free camera.
+     * @see https://doc.babylonjs.com/how_to/customizing_camera_inputs
+     * @param allowMouse Defines if mouse events can be treated as touch events
+     */
+    constructor(
+        /**
+         * Define if mouse events can be treated as touch events
+         */
+        public allowMouse = false) {
+    }    
+
+    /**
      * Attach the input controls to a specific dom element to get the input from.
      * @param element Defines the element the controls should be listened from
      * @param noPreventDefault Defines whether event caught by the controls should call preventdefault() (https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault)
@@ -55,7 +67,7 @@ export class FreeCameraTouchInput implements ICameraInput<FreeCamera> {
                 var evt = <PointerEvent>p.event;
 
                 let isMouseEvent = evt instanceof MouseEvent;
-                if (evt.pointerType === "mouse" || isMouseEvent) {
+                if (!this.allowMouse && (evt.pointerType === "mouse" || isMouseEvent)) {
                     return;
                 }
 

+ 4 - 1
src/Cameras/touchCamera.ts

@@ -81,9 +81,12 @@ export class TouchCamera extends FreeCamera {
 
     /** @hidden */
     public _setupInputs() {
+        var touch = <FreeCameraTouchInput>this.inputs.attached["touch"];
         var mouse = <FreeCameraMouseInput>this.inputs.attached["mouse"];
         if (mouse) {
-            mouse.touchEnabled = false;
+            mouse.touchEnabled = false;            
+        } else {
+            touch.allowMouse = true;
         }
     }
 }