Browse Source

Better handling of generic VR controller

David Rousset 8 năm trước cách đây
mục cha
commit
6724a46f52
21 tập tin đã thay đổi với 5189 bổ sung5021 xóa
  1. 1264 1255
      dist/preview release/babylon.d.ts
  2. 36 36
      dist/preview release/babylon.js
  3. 66 3
      dist/preview release/babylon.max.js
  4. 1264 1255
      dist/preview release/babylon.module.d.ts
  5. 37 37
      dist/preview release/babylon.worker.js
  6. 1071 1062
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts
  7. 32 32
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js
  8. 30 0
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js
  9. 1071 1062
      dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts
  10. 1 1
      dist/preview release/gui/babylon.gui.min.js
  11. 263 263
      dist/preview release/inspector/babylon.inspector.bundle.js
  12. 3 3
      dist/preview release/inspector/babylon.inspector.min.js
  13. 2 2
      dist/preview release/loaders/babylon.glTF1FileLoader.min.js
  14. 1 1
      dist/preview release/loaders/babylon.glTF2FileLoader.min.js
  15. 2 2
      dist/preview release/loaders/babylon.glTFFileLoader.min.js
  16. 1 1
      dist/preview release/loaders/babylon.objFileLoader.min.js
  17. 1 1
      dist/preview release/materialsLibrary/babylon.customMaterial.min.js
  18. 1 1
      dist/preview release/materialsLibrary/babylon.waterMaterial.min.js
  19. 1 1
      dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js
  20. 1 1
      dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js
  21. 41 2
      src/Tools/babylon.extendedGamepad.ts

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1264 - 1255
dist/preview release/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 36 - 36
dist/preview release/babylon.js


+ 66 - 3
dist/preview release/babylon.max.js

@@ -41677,6 +41677,7 @@ var BABYLON;
             _this._floats = {};
             _this._floatsArrays = {};
             _this._colors3 = {};
+            _this._colors3Arrays = {};
             _this._colors4 = {};
             _this._vectors2 = {};
             _this._vectors3 = {};
@@ -41741,6 +41742,14 @@ var BABYLON;
             this._colors3[name] = value;
             return this;
         };
+        ShaderMaterial.prototype.setColor3Array = function (name, value) {
+            this._checkUniform(name);
+            this._colors3Arrays[name] = value.reduce(function (arr, color) {
+                color.toArray(arr, arr.length);
+                return arr;
+            }, []);
+            return this;
+        };
         ShaderMaterial.prototype.setColor4 = function (name, value) {
             this._checkUniform(name);
             this._colors4[name] = value;
@@ -41915,6 +41924,9 @@ var BABYLON;
                 for (name in this._colors3) {
                     this._effect.setColor3(name, this._colors3[name]);
                 }
+                for (name in this._colors3Arrays) {
+                    this._effect.setArray3(name, this._colors3Arrays[name]);
+                }
                 // Color4      
                 for (name in this._colors4) {
                     var color = this._colors4[name];
@@ -42038,6 +42050,11 @@ var BABYLON;
             for (name in this._colors3) {
                 serializationObject.colors3[name] = this._colors3[name].asArray();
             }
+            // Color3 array
+            serializationObject.colors3Arrays = {};
+            for (name in this._colors3Arrays) {
+                serializationObject.colors3Arrays[name] = this._colors3Arrays[name];
+            }
             // Color4  
             serializationObject.colors4 = {};
             for (name in this._colors4) {
@@ -42108,6 +42125,19 @@ var BABYLON;
             for (name in source.colors3) {
                 material.setColor3(name, BABYLON.Color3.FromArray(source.colors3[name]));
             }
+            // Color3 arrays
+            for (name in source.colors3Arrays) {
+                var colors = source.colors3Arrays[name].reduce(function (arr, num, i) {
+                    if (i % 3 === 0) {
+                        arr.push([num]);
+                    }
+                    else {
+                        arr[arr.length - 1].push(num);
+                    }
+                    return arr;
+                }, []).map(function (color) { return BABYLON.Color3.FromArray(color); });
+                material.setColor3Array(name, colors);
+            }
             // Color4      
             for (name in source.colors4) {
                 material.setColor4(name, BABYLON.Color4.FromArray(source.colors4[name]));
@@ -50062,19 +50092,23 @@ var BABYLON;
     (function (PoseEnabledControllerType) {
         PoseEnabledControllerType[PoseEnabledControllerType["VIVE"] = 0] = "VIVE";
         PoseEnabledControllerType[PoseEnabledControllerType["OCULUS"] = 1] = "OCULUS";
-        PoseEnabledControllerType[PoseEnabledControllerType["GENERIC"] = 2] = "GENERIC";
+        PoseEnabledControllerType[PoseEnabledControllerType["WINDOWS"] = 2] = "WINDOWS";
+        PoseEnabledControllerType[PoseEnabledControllerType["GENERIC"] = 3] = "GENERIC";
     })(PoseEnabledControllerType = BABYLON.PoseEnabledControllerType || (BABYLON.PoseEnabledControllerType = {}));
     var PoseEnabledControllerHelper = (function () {
         function PoseEnabledControllerHelper() {
         }
         PoseEnabledControllerHelper.InitiateController = function (vrGamepad) {
-            // for now, only Oculus and Vive are supported
+            // Oculus Touch
             if (vrGamepad.id.indexOf('Oculus Touch') !== -1) {
                 return new OculusTouchController(vrGamepad);
             }
-            else {
+            else if (vrGamepad.id.toLowerCase().indexOf('openvr') !== -1) {
                 return new ViveController(vrGamepad);
             }
+            else {
+                return new GenericController(vrGamepad);
+            }
         };
         return PoseEnabledControllerHelper;
     }());
@@ -50214,6 +50248,13 @@ var BABYLON;
             }
         };
         WebVRController.prototype._setButtonValue = function (newState, currentState, buttonIndex) {
+            if (!newState) {
+                newState = {
+                    pressed: false,
+                    touched: false,
+                    value: 0
+                };
+            }
             if (!currentState) {
                 this._buttons[buttonIndex] = {
                     pressed: newState.pressed,
@@ -50467,6 +50508,28 @@ var BABYLON;
         return ViveController;
     }(WebVRController));
     BABYLON.ViveController = ViveController;
+    var GenericController = (function (_super) {
+        __extends(GenericController, _super);
+        function GenericController(vrGamepad) {
+            return _super.call(this, vrGamepad) || this;
+        }
+        GenericController.prototype.initControllerMesh = function (scene, meshLoaded) {
+            var _this = this;
+            BABYLON.SceneLoader.ImportMesh("", "http://yoda.blob.core.windows.net/models/", "genericvrcontroller.babylon", scene, function (newMeshes) {
+                _this._defaultModel = newMeshes[1];
+                if (meshLoaded) {
+                    meshLoaded(_this._defaultModel);
+                }
+                _this.attachToMesh(_this._defaultModel);
+            });
+        };
+        GenericController.prototype.handleButtonChange = function (buttonIdx, state, changes) {
+            console.log("Button id: " + buttonIdx + "state: ");
+            console.dir(state);
+        };
+        return GenericController;
+    }(WebVRController));
+    BABYLON.GenericController = GenericController;
 })(BABYLON || (BABYLON = {}));
 
 //# sourceMappingURL=babylon.extendedGamepad.js.map

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1264 - 1255
dist/preview release/babylon.module.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 37 - 37
dist/preview release/babylon.worker.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1071 - 1062
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 32 - 32
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 30 - 0
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -38103,6 +38103,7 @@ var BABYLON;
             _this._floats = {};
             _this._floatsArrays = {};
             _this._colors3 = {};
+            _this._colors3Arrays = {};
             _this._colors4 = {};
             _this._vectors2 = {};
             _this._vectors3 = {};
@@ -38167,6 +38168,14 @@ var BABYLON;
             this._colors3[name] = value;
             return this;
         };
+        ShaderMaterial.prototype.setColor3Array = function (name, value) {
+            this._checkUniform(name);
+            this._colors3Arrays[name] = value.reduce(function (arr, color) {
+                color.toArray(arr, arr.length);
+                return arr;
+            }, []);
+            return this;
+        };
         ShaderMaterial.prototype.setColor4 = function (name, value) {
             this._checkUniform(name);
             this._colors4[name] = value;
@@ -38341,6 +38350,9 @@ var BABYLON;
                 for (name in this._colors3) {
                     this._effect.setColor3(name, this._colors3[name]);
                 }
+                for (name in this._colors3Arrays) {
+                    this._effect.setArray3(name, this._colors3Arrays[name]);
+                }
                 // Color4      
                 for (name in this._colors4) {
                     var color = this._colors4[name];
@@ -38464,6 +38476,11 @@ var BABYLON;
             for (name in this._colors3) {
                 serializationObject.colors3[name] = this._colors3[name].asArray();
             }
+            // Color3 array
+            serializationObject.colors3Arrays = {};
+            for (name in this._colors3Arrays) {
+                serializationObject.colors3Arrays[name] = this._colors3Arrays[name];
+            }
             // Color4  
             serializationObject.colors4 = {};
             for (name in this._colors4) {
@@ -38534,6 +38551,19 @@ var BABYLON;
             for (name in source.colors3) {
                 material.setColor3(name, BABYLON.Color3.FromArray(source.colors3[name]));
             }
+            // Color3 arrays
+            for (name in source.colors3Arrays) {
+                var colors = source.colors3Arrays[name].reduce(function (arr, num, i) {
+                    if (i % 3 === 0) {
+                        arr.push([num]);
+                    }
+                    else {
+                        arr[arr.length - 1].push(num);
+                    }
+                    return arr;
+                }, []).map(function (color) { return BABYLON.Color3.FromArray(color); });
+                material.setColor3Array(name, colors);
+            }
             // Color4      
             for (name in source.colors4) {
                 material.setColor4(name, BABYLON.Color4.FromArray(source.colors4[name]));

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1071 - 1062
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.module.d.ts


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 263 - 263
dist/preview release/inspector/babylon.inspector.bundle.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 3 - 3
dist/preview release/inspector/babylon.inspector.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2 - 2
dist/preview release/loaders/babylon.glTF1FileLoader.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/loaders/babylon.glTF2FileLoader.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 2 - 2
dist/preview release/loaders/babylon.glTFFileLoader.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/loaders/babylon.objFileLoader.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/materialsLibrary/babylon.customMaterial.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/materialsLibrary/babylon.waterMaterial.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.asciiArtPostProcess.min.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
dist/preview release/postProcessesLibrary/babylon.digitalRainPostProcess.min.js


+ 41 - 2
src/Tools/babylon.extendedGamepad.ts

@@ -3,6 +3,7 @@ module BABYLON {
     export enum PoseEnabledControllerType {
         VIVE,
         OCULUS,
+        WINDOWS,
         GENERIC
     }
 
@@ -14,12 +15,22 @@ module BABYLON {
 
     export class PoseEnabledControllerHelper {
         public static InitiateController(vrGamepad: any) {
-            // for now, only Oculus and Vive are supported
+            // Oculus Touch
             if (vrGamepad.id.indexOf('Oculus Touch') !== -1) {
                 return new OculusTouchController(vrGamepad);
-            } else {
+            }
+            // Windows Mixed Reality controllers 
+            // else if (vrGamepad.id.indexOf('Spatial Control') === 0) {
+            //     //return new WindowsMixedRealityController(vrGamepad);
+            // }
+            // HTC Vive
+            else if (vrGamepad.id.toLowerCase().indexOf('openvr') !== -1) {
                 return new ViveController(vrGamepad);
             }
+            // Generic 
+            else {
+                return new GenericController(vrGamepad);
+            }
         }
     }
 
@@ -197,6 +208,13 @@ module BABYLON {
         public abstract initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void)
 
         private _setButtonValue(newState: ExtendedGamepadButton, currentState: ExtendedGamepadButton, buttonIndex: number) {
+            if (!newState) {
+                newState = {
+                    pressed: false,
+                    touched: false,
+                    value: 0
+                };
+            }  
             if (!currentState) {
                 this._buttons[buttonIndex] = {
                     pressed: newState.pressed,
@@ -440,7 +458,28 @@ module BABYLON {
         }
     }
 
+    export class GenericController extends WebVRController {
+        private _defaultModel: BABYLON.AbstractMesh;
+
+        constructor(vrGamepad) {
+            super(vrGamepad);
+        }
+
+        public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
+            SceneLoader.ImportMesh("", "http://yoda.blob.core.windows.net/models/", "genericvrcontroller.babylon", scene, (newMeshes) => {
+                this._defaultModel = newMeshes[1];
+                if (meshLoaded) {
+                    meshLoaded(this._defaultModel);
+                }
+                this.attachToMesh(this._defaultModel);
+            });
+        }
 
+        protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
+            console.log("Button id: " + buttonIdx + "state: ");
+            console.dir(state);
+        }
+    }
 }
 
 interface ExtendedGamepadButton extends GamepadButton {