Browse Source

Merge pull request #4433 from TrevorDev/onTrackpadChangedObservableFix

update trackpad field before button events are fired
David Catuhe 7 năm trước cách đây
mục cha
commit
c24250094d

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

@@ -54,6 +54,7 @@
 - VR experience helper will now fire pointer events even when no mesh is currently hit ([TrevorDev](https://github.com/TrevorDev))
 - RawTexture.CreateAlphaTexture no longer fails to create a usable texture ([TrevorDev](https://github.com/TrevorDev))
 - SceneSerializer.SerializeMesh now serializes all materials kinds (not only StandardMaterial) ([julien-moreau](https://github.com/julien-moreau))
+- WindowsMotionController's trackpad field will be updated prior to it's onTrackpadChangedObservable event ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 12 - 5
src/Gamepad/Controllers/babylon.windowsMotionController.ts

@@ -189,17 +189,21 @@ module BABYLON {
             return this.onTrackpadValuesChangedObservable;
         }
 
+        private _updateTrackpad(){
+            if (this.browserGamepad.axes && (this.browserGamepad.axes[2] != this.trackpad.x || this.browserGamepad.axes[3] != this.trackpad.y)) {
+                this.trackpad.x = this.browserGamepad["axes"][2];
+                this.trackpad.y = this.browserGamepad["axes"][3];
+                this.onTrackpadValuesChangedObservable.notifyObservers(this.trackpad);
+            }
+        }
+
         /**
          * Called once per frame by the engine.
          */
         public update() {
             super.update();
             if (this.browserGamepad.axes) {
-                if (this.browserGamepad.axes[2] != this.trackpad.x || this.browserGamepad.axes[3] != this.trackpad.y) {
-                    this.trackpad.x = this.browserGamepad["axes"][2];
-                    this.trackpad.y = this.browserGamepad["axes"][3];
-                    this.onTrackpadValuesChangedObservable.notifyObservers(this.trackpad);
-                }
+                this._updateTrackpad();
                 // Only need to animate axes if there is a loaded mesh
                 if (this._loadedMeshInfo) {
                     for (let axis = 0; axis < this._mapping.axisMeshNames.length; axis++) {
@@ -221,6 +225,9 @@ module BABYLON {
                 return;
             }
 
+            // Update the trackpad to ensure trackpad.x/y are accurate during button events between frames
+            this._updateTrackpad();
+
             // Only emit events for buttons that we know how to map from index to name
             let observable = (<any>this)[(<any>(this._mapping.buttonObservableNames))[buttonName]];
             if (observable) {