Explorar o código

Merge pull request #3783 from brianzinn/master

add basic Daydream controller support
David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
4c092aa399

+ 2 - 1
Tools/Gulp/config.json

@@ -660,7 +660,8 @@
                 "../../src/Gamepad/Controllers/babylon.viveController.js",
                 "../../src/Gamepad/Controllers/babylon.genericController.js",
                 "../../src/Gamepad/Controllers/babylon.windowsMotionController.js",
-                "../../src/Gamepad/Controllers/babylon.gearVRController.js"
+                "../../src/Gamepad/Controllers/babylon.gearVRController.js",
+                "../../src/Gamepad/Controllers/babylon.daydreamController.js"
             ],
             "dependUpon": [
                 "core"

+ 1 - 1
dist/preview release/what's new.md

@@ -6,7 +6,7 @@
 - Improved building process: We now run a full visual validation test for each pull request. Furthermore, code comments and what's new updates are now mandatory ([sebavan](https://github.com/sebavan))
 - Introduced texture binding atlas. This optimization allows the engine to reuse texture bindings instead of rebinding textures when they are not on constant sampler indexes ([deltakosh](https://github.com/deltakosh))
 - New [AnimationGroup class](http://doc.babylonjs.com/how_to/group) to control simultaneously multiple animations with different targets ([deltakosh](https://github.com/deltakosh))
-- `WebVRCamera` now supports GearVR ([brianzinn](https://github.com/brianzinn))
+- `WebVRCamera` add basic support for Daydream and Gear VR ([brianzinn](https://github.com/brianzinn))
 - New glTF [serializer](https://github.com/BabylonJS/Babylon.js/tree/master/serializers/src/glTF/2.0). You can now export glTF or glb files directly from a Babylon scene ([kcoley](https://github.com/kcoley))
 - Babylon.js now uses Promises in addition to callbacks. We created several `xxxAsync` functions all over the framework (`SceneLoader.AppendAsync` for instance, which returns a Promise). A polyfill is also integrated to support older browsers ([deltakosh](https://github.com/deltakosh))
 - Introduced [Projection Texture on SpotLight](http://doc.babylonjs.com/babylon101/lights#projection-texture) ([lostink](https://github.com/lostink))

+ 50 - 0
src/Gamepad/Controllers/babylon.daydreamController.ts

@@ -0,0 +1,50 @@
+module BABYLON {
+    /**
+     * Google Daydream controller
+     */
+    export class DaydreamController extends WebVRController {
+        /**
+         * Base Url for the controller model.
+         */
+        public static MODEL_BASE_URL: string = 'https://controllers.babylonjs.com/generic/';
+
+        /**
+         * File name for the controller model.
+         */
+        public static MODEL_FILENAME: string = 'generic.babylon';
+
+        /**
+         * Gamepad Id prefix used to identify Daydream Controller.
+         */
+        public static readonly GAMEPAD_ID_PREFIX: string = 'Daydream'; // id is 'Daydream Controller'
+
+        constructor(vrGamepad: any) {
+            super(vrGamepad);
+            this.controllerType = PoseEnabledControllerType.DAYDREAM;
+        }
+
+        public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
+            SceneLoader.ImportMesh("", DaydreamController.MODEL_BASE_URL, DaydreamController.MODEL_FILENAME, scene, (newMeshes) => {
+                this._defaultModel = newMeshes[1];
+                this.attachToMesh(this._defaultModel);
+
+                if (meshLoaded) {
+                    meshLoaded(this._defaultModel);
+                }
+            });
+        }
+
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+            // Daydream controller only has 1 GamepadButton (on the trackpad).
+            if (buttonIdx === 0) {
+                let observable = this.onTriggerStateChangedObservable;
+                if (observable) {
+                    observable.notifyObservers(state);
+                }
+            } else {
+                // If the app or home buttons are ever made available
+                Tools.Warn(`Unrecognized Daydream button index: ${buttonIdx}`)
+            }
+        }
+    }
+}

+ 1 - 1
src/Gamepad/Controllers/babylon.gearVRController.ts

@@ -26,7 +26,7 @@ module BABYLON {
             });
         }
 
-        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
             if (buttonIdx < this._buttonIndexToObservableNameMap.length) {
                 const observableName : string = this._buttonIndexToObservableNameMap[buttonIdx];
                 

+ 1 - 1
src/Gamepad/Controllers/babylon.genericController.ts

@@ -18,7 +18,7 @@ module BABYLON {
             });
         }
 
-        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
             console.log("Button id: " + buttonIdx + "state: ");
             console.dir(state);
         }

+ 1 - 1
src/Gamepad/Controllers/babylon.oculusTouchController.ts

@@ -87,7 +87,7 @@ module BABYLON {
          4) B / Y 
          5) thumb rest
         */
-        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
             let notifyObject = state; //{ state: state, changes: changes };
             let triggerDirection = this.hand === 'right' ? -1 : 1;
             switch (buttonIdx) {

+ 8 - 1
src/Gamepad/Controllers/babylon.poseEnabledController.ts

@@ -5,6 +5,10 @@ module BABYLON {
         OCULUS,
         WINDOWS,
         GEAR_VR,
+        /**
+         * Google Daydream
+         */
+        DAYDREAM,
         GENERIC
     }
 
@@ -38,6 +42,10 @@ module BABYLON {
             else if (vrGamepad.id.indexOf(GearVRController.GAMEPAD_ID_PREFIX) === 0) {
                 return new GearVRController(vrGamepad);
             }
+            // Google Daydream
+            else if (vrGamepad.id.indexOf(DaydreamController.GAMEPAD_ID_PREFIX) === 0) {
+                return new DaydreamController(vrGamepad);
+            }
             // Generic 
             else {
                 return new GenericController(vrGamepad);
@@ -115,7 +123,6 @@ module BABYLON {
 
                     this._deviceRoomPosition.scaleToRef(this.deviceScaleFactor, this._calculatedPosition);
                     this._calculatedPosition.addInPlace(this.position);
-
                 }
                 let pose = this.rawPose;
                 if (poseData.orientation && pose.orientation) {

+ 1 - 1
src/Gamepad/Controllers/babylon.viveController.ts

@@ -50,7 +50,7 @@ module BABYLON {
          * 2: left AND right buttons
          * 3: menu button
          */
-        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
             let notifyObject = state; //{ state: state, changes: changes };
             switch (buttonIdx) {
                 case 0:

+ 2 - 2
src/Gamepad/Controllers/babylon.webVRController.ts

@@ -45,7 +45,7 @@ module BABYLON {
             }
         }
 
-        protected abstract handleButtonChange(buttonIdx: number, value: ExtendedGamepadButton, changes: GamepadButtonChanges): void;
+        protected abstract _handleButtonChange(buttonIdx: number, value: ExtendedGamepadButton, changes: GamepadButtonChanges): void;
 
         public abstract initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void): void;
 
@@ -69,7 +69,7 @@ module BABYLON {
             if (this._changes.changed) {
                 this._onButtonStateChange && this._onButtonStateChange(this.index, buttonIndex, newState);
 
-                this.handleButtonChange(buttonIndex, newState, this._changes);
+                this._handleButtonChange(buttonIndex, newState, this._changes);
             }
             this._buttons[buttonIndex].pressed = newState.pressed;
             this._buttons[buttonIndex].touched = newState.touched;

+ 1 - 1
src/Gamepad/Controllers/babylon.windowsMotionController.ts

@@ -126,7 +126,7 @@ module BABYLON {
          * @param state New state of the button
          * @param changes Which properties on the state changed since last frame
          */
-        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+        protected _handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
             let buttonName = this._mapping.buttons[buttonIdx];
             if (!buttonName) {
                 return;