Browse Source

added new observables on gamepads

David Catuhe 8 years ago
parent
commit
7bc86ab0b5

File diff suppressed because it is too large
+ 689 - 683
dist/preview release/babylon.d.ts


File diff suppressed because it is too large
+ 13 - 13
dist/preview release/babylon.js


+ 36 - 12
dist/preview release/babylon.max.js

@@ -51933,6 +51933,8 @@ var BABYLON;
         __extends(GenericPad, _super);
         function GenericPad(id, index, browserGamepad) {
             var _this = _super.call(this, id, index, browserGamepad) || this;
+            _this.onButtonDownObservable = new BABYLON.Observable();
+            _this.onButtonUpObservable = new BABYLON.Observable();
             _this.type = Gamepad.GENERIC;
             _this._buttons = new Array(browserGamepad.buttons.length);
             return _this;
@@ -51945,11 +51947,17 @@ var BABYLON;
         };
         GenericPad.prototype._setButtonValue = function (newValue, currentValue, buttonIndex) {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonIndex);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonIndex);
+                    }
+                    this.onButtonDownObservable.notifyObservers(buttonIndex);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonIndex);
+                if (newValue === 0) {
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonIndex);
+                    }
+                    this.onButtonUpObservable.notifyObservers(buttonIndex);
                 }
             }
             return newValue;
@@ -51997,6 +52005,10 @@ var BABYLON;
             var _this = _super.call(this, id, index, gamepad, 0, 1, (xboxOne ? 3 : 2), (xboxOne ? 4 : 3)) || this;
             _this._leftTrigger = 0;
             _this._rightTrigger = 0;
+            _this.onButtonDownObservable = new BABYLON.Observable();
+            _this.onButtonUpObservable = new BABYLON.Observable();
+            _this.onPadDownObservable = new BABYLON.Observable();
+            _this.onPadUpObservable = new BABYLON.Observable();
             _this._buttonA = 0;
             _this._buttonB = 0;
             _this._buttonX = 0;
@@ -52062,22 +52074,34 @@ var BABYLON;
         };
         Xbox360Pad.prototype._setButtonValue = function (newValue, currentValue, buttonType) {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonType);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonType);
+                    }
+                    this.onButtonDownObservable.notifyObservers(buttonType);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonType);
+                if (newValue === 0) {
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonType);
+                    }
+                    this.onButtonUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;
         };
         Xbox360Pad.prototype._setDPadValue = function (newValue, currentValue, buttonType) {
             if (newValue !== currentValue) {
-                if (this._ondpaddown && newValue === 1) {
-                    this._ondpaddown(buttonType);
+                if (newValue === 1) {
+                    if (this._ondpaddown) {
+                        this._ondpaddown(buttonType);
+                    }
+                    this.onPadDownObservable.notifyObservers(buttonType);
                 }
-                if (this._ondpadup && newValue === 0) {
-                    this._ondpadup(buttonType);
+                if (newValue === 0) {
+                    if (this._ondpadup) {
+                        this._ondpadup(buttonType);
+                    }
+                    this.onPadUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;

File diff suppressed because it is too large
+ 689 - 683
dist/preview release/babylon.module.d.ts


File diff suppressed because it is too large
+ 13 - 13
dist/preview release/babylon.worker.js


File diff suppressed because it is too large
+ 3806 - 3800
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


File diff suppressed because it is too large
+ 13 - 13
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 36 - 12
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -51933,6 +51933,8 @@ var BABYLON;
         __extends(GenericPad, _super);
         function GenericPad(id, index, browserGamepad) {
             var _this = _super.call(this, id, index, browserGamepad) || this;
+            _this.onButtonDownObservable = new BABYLON.Observable();
+            _this.onButtonUpObservable = new BABYLON.Observable();
             _this.type = Gamepad.GENERIC;
             _this._buttons = new Array(browserGamepad.buttons.length);
             return _this;
@@ -51945,11 +51947,17 @@ var BABYLON;
         };
         GenericPad.prototype._setButtonValue = function (newValue, currentValue, buttonIndex) {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonIndex);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonIndex);
+                    }
+                    this.onButtonDownObservable.notifyObservers(buttonIndex);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonIndex);
+                if (newValue === 0) {
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonIndex);
+                    }
+                    this.onButtonUpObservable.notifyObservers(buttonIndex);
                 }
             }
             return newValue;
@@ -51997,6 +52005,10 @@ var BABYLON;
             var _this = _super.call(this, id, index, gamepad, 0, 1, (xboxOne ? 3 : 2), (xboxOne ? 4 : 3)) || this;
             _this._leftTrigger = 0;
             _this._rightTrigger = 0;
+            _this.onButtonDownObservable = new BABYLON.Observable();
+            _this.onButtonUpObservable = new BABYLON.Observable();
+            _this.onPadDownObservable = new BABYLON.Observable();
+            _this.onPadUpObservable = new BABYLON.Observable();
             _this._buttonA = 0;
             _this._buttonB = 0;
             _this._buttonX = 0;
@@ -52062,22 +52074,34 @@ var BABYLON;
         };
         Xbox360Pad.prototype._setButtonValue = function (newValue, currentValue, buttonType) {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonType);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonType);
+                    }
+                    this.onButtonDownObservable.notifyObservers(buttonType);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonType);
+                if (newValue === 0) {
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonType);
+                    }
+                    this.onButtonUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;
         };
         Xbox360Pad.prototype._setDPadValue = function (newValue, currentValue, buttonType) {
             if (newValue !== currentValue) {
-                if (this._ondpaddown && newValue === 1) {
-                    this._ondpaddown(buttonType);
+                if (newValue === 1) {
+                    if (this._ondpaddown) {
+                        this._ondpaddown(buttonType);
+                    }
+                    this.onPadDownObservable.notifyObservers(buttonType);
                 }
-                if (this._ondpadup && newValue === 0) {
-                    this._ondpadup(buttonType);
+                if (newValue === 0) {
+                    if (this._ondpadup) {
+                        this._ondpadup(buttonType);
+                    }
+                    this.onPadUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;

File diff suppressed because it is too large
+ 3806 - 3800
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


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

@@ -17,6 +17,7 @@
 - Added support for Particle animation in ParticleSystem ([Ibraheem Osama](https://github.com/IbraheemOsama))
 
 ## Updates
+- New observables for gamepads: `onButtonDownObservable`, `onButtonUpObservable`, `onPadDownObservable`, `onPadUpObservable` ([deltakosh](https://github.com/deltakosh))
 - New `camera.storeState()` and `camera.restoreState()` functions to store / restore cameras position / rotation / fov. (Doc here)[http://doc.babylonjs.com/tutorials/cameras#state] ([deltakosh](https://github.com/deltakosh))
 - POW2 textures rescale is now done by shaders (It was previously done using canvas) ([deltakosh](https://github.com/deltakosh))
 - Added `SceneLoader.CleanBoneMatrixWeights` to force the loader to normalize matrix weights when loading bones (off by default) ([deltakosh](https://github.com/deltakosh)) 

+ 16 - 5
src/Gamepad/babylon.gamepad.ts

@@ -94,7 +94,10 @@
     export class GenericPad extends Gamepad {
         private _buttons: Array<number>;
         private _onbuttondown: (buttonPressed: number) => void;
-        private _onbuttonup: (buttonReleased: number) => void;
+        private _onbuttonup: (buttonReleased: number) => void;        
+
+        public onButtonDownObservable = new Observable<number>();
+        public onButtonUpObservable = new Observable<number>();
 
         public onbuttondown(callback: (buttonPressed: number) => void) {
             this._onbuttondown = callback;
@@ -111,11 +114,19 @@
 
         private _setButtonValue(newValue: number, currentValue: number, buttonIndex: number): number {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonIndex);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonIndex);
+                    }
+
+                    this.onButtonDownObservable.notifyObservers(buttonIndex);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonIndex);
+                if (newValue === 0) {
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonIndex);
+                    }
+
+                    this.onButtonUpObservable.notifyObservers(buttonIndex);
                 }
             }
             return newValue;

+ 30 - 8
src/Gamepad/babylon.xboxGamepad.ts

@@ -32,6 +32,11 @@
         private _ondpaddown: (dPadPressed: Xbox360Dpad) => void;
         private _ondpadup: (dPadReleased: Xbox360Dpad) => void;
 
+        public onButtonDownObservable = new Observable<Xbox360Button>();
+        public onButtonUpObservable = new Observable<Xbox360Button>();        
+        public onPadDownObservable = new Observable<Xbox360Dpad>();
+        public onPadUpObservable = new Observable<Xbox360Dpad>();        
+
         private _buttonA: number = 0;
         private _buttonB: number = 0;
         private _buttonX: number = 0;
@@ -99,11 +104,20 @@
 
         private _setButtonValue(newValue: number, currentValue: number, buttonType: Xbox360Button): number {
             if (newValue !== currentValue) {
-                if (this._onbuttondown && newValue === 1) {
-                    this._onbuttondown(buttonType);
+                if (newValue === 1) {
+                    if (this._onbuttondown) {
+                        this._onbuttondown(buttonType);
+                    }
+
+                    this.onButtonDownObservable.notifyObservers(buttonType);
                 }
-                if (this._onbuttonup && newValue === 0) {
-                    this._onbuttonup(buttonType);
+                if (newValue === 0) {
+
+                    if (this._onbuttonup) {
+                        this._onbuttonup(buttonType);
+                    }
+                    
+                    this.onButtonUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;
@@ -111,11 +125,19 @@
 
         private _setDPadValue(newValue: number, currentValue: number, buttonType: Xbox360Dpad): number {
             if (newValue !== currentValue) {
-                if (this._ondpaddown && newValue === 1) {
-                    this._ondpaddown(buttonType);
+                if (newValue === 1) {
+                    if (this._ondpaddown) {
+                        this._ondpaddown(buttonType);
+                    }
+                    
+                    this.onPadDownObservable.notifyObservers(buttonType);
                 }
-                if (this._ondpadup && newValue === 0) {
-                    this._ondpadup(buttonType);
+                if (newValue === 0) {
+                    if (this._ondpadup) {
+                        this._ondpadup(buttonType);
+                    }
+
+                    this.onPadUpObservable.notifyObservers(buttonType);
                 }
             }
             return newValue;