Browse Source

Merge pull request #2786 from BabylonJS/master

Nightly
David Catuhe 8 years ago
parent
commit
20ea431fca

BIN
assets/meshes/controllers/microsoft/045E-065B/left.glb


BIN
assets/meshes/controllers/microsoft/045E-065B/right.glb


BIN
assets/meshes/controllers/microsoft/default/left.glb


BIN
assets/meshes/controllers/microsoft/default/right.glb


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


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


+ 40 - 8
dist/preview release/babylon.max.js

@@ -13262,6 +13262,25 @@ var BABYLON;
             this._isDirty = true;
             return this;
         };
+        AbstractMesh.prototype.getHierarchyBoundingVectors = function () {
+            this.computeWorldMatrix();
+            var min = this.getBoundingInfo().boundingBox.minimumWorld;
+            var max = this.getBoundingInfo().boundingBox.maximumWorld;
+            var descendants = this.getDescendants(false, function (node) { return node.subMeshes; });
+            for (var _i = 0, descendants_1 = descendants; _i < descendants_1.length; _i++) {
+                var descendant = descendants_1[_i];
+                var childMesh = descendant;
+                childMesh.computeWorldMatrix();
+                var minBox = childMesh.getBoundingInfo().boundingBox.minimumWorld;
+                var maxBox = childMesh.getBoundingInfo().boundingBox.maximumWorld;
+                BABYLON.Tools.CheckExtends(minBox, min, max);
+                BABYLON.Tools.CheckExtends(maxBox, min, max);
+            }
+            return {
+                min: min,
+                max: max
+            };
+        };
         /**
          * Updates the mesh BoundingInfo object and all its children BoundingInfo objects also.
          * Returns the AbstractMesh.
@@ -52538,7 +52557,8 @@ var BABYLON;
                     'THUMBSTICK_Y',
                     'TOUCHPAD_TOUCH_X',
                     'TOUCHPAD_TOUCH_Y'
-                ]
+                ],
+                pointingPoseMeshName: 'POINTING_POSE'
             };
             _this.onTrackpadChangedObservable = new BABYLON.Observable();
             _this.controllerType = BABYLON.PoseEnabledControllerType.WINDOWS;
@@ -52698,13 +52718,10 @@ var BABYLON;
             var childMesh = null;
             for (var i = 0; i < meshes.length; i++) {
                 var mesh = meshes[i];
-                if (mesh.id === WindowsMotionController.MODEL_ROOT_NODE_NAME) {
-                    // There may be a parent mesh to perform the RH to LH matrix transform.
+                if (!mesh.parent) {
                     // Exclude controller meshes from picking results
                     mesh.isPickable = false;
                     // Handle root node, attach to the new parentMesh
-                    if (mesh.parent && mesh.parent.name === WindowsMotionController.GLTF_ROOT_TRANSFORM_NAME)
-                        mesh = mesh.parent;
                     childMesh = mesh;
                     break;
                 }
@@ -52715,7 +52732,7 @@ var BABYLON;
                 loadedMeshInfo = this.createMeshInfo(parentMesh);
             }
             else {
-                BABYLON.Tools.Warn('No node with name ' + WindowsMotionController.MODEL_ROOT_NODE_NAME + ' in model file.');
+                BABYLON.Tools.Warn('Could not find root node in model file.');
             }
             return loadedMeshInfo;
         };
@@ -52786,6 +52803,11 @@ var BABYLON;
                         ')');
                 }
             }
+            // Pointing Ray
+            loadedMeshInfo.pointingPoseNode = getChildByName(rootNode, this._mapping.pointingPoseMeshName);
+            if (!loadedMeshInfo.pointingPoseNode) {
+                BABYLON.Tools.Warn('Missing pointing pose mesh with name: ' + this._mapping.pointingPoseMeshName);
+            }
             return loadedMeshInfo;
             // Look through all children recursively. This will return null if no mesh exists with the given name.
             function getChildByName(node, name) {
@@ -52796,6 +52818,18 @@ var BABYLON;
                 return node.getChildMeshes(true, function (n) { return n.name == name; })[0];
             }
         };
+        WindowsMotionController.prototype.getForwardRay = function (length) {
+            if (length === void 0) { length = 100; }
+            if (!(this._loadedMeshInfo && this._loadedMeshInfo.pointingPoseNode)) {
+                return _super.prototype.getForwardRay.call(this, length);
+            }
+            var m = this._loadedMeshInfo.pointingPoseNode.getWorldMatrix();
+            var origin = m.getTranslation();
+            var forward = new BABYLON.Vector3(0, 0, -1);
+            var forwardWorld = BABYLON.Vector3.TransformNormal(forward, m);
+            var direction = BABYLON.Vector3.Normalize(forwardWorld);
+            return new BABYLON.Ray(origin, direction, length);
+        };
         WindowsMotionController.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
             this.onTrackpadChangedObservable.clear();
@@ -52803,8 +52837,6 @@ var BABYLON;
         WindowsMotionController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/microsoft/';
         WindowsMotionController.MODEL_LEFT_FILENAME = 'left.glb';
         WindowsMotionController.MODEL_RIGHT_FILENAME = 'right.glb';
-        WindowsMotionController.MODEL_ROOT_NODE_NAME = 'RootNode';
-        WindowsMotionController.GLTF_ROOT_TRANSFORM_NAME = 'root';
         WindowsMotionController.GAMEPAD_ID_PREFIX = 'Spatial Controller (Spatial Interaction Source) ';
         WindowsMotionController.GAMEPAD_ID_PATTERN = /([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/;
         return WindowsMotionController;

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


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


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


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


+ 40 - 8
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -13262,6 +13262,25 @@ var BABYLON;
             this._isDirty = true;
             return this;
         };
+        AbstractMesh.prototype.getHierarchyBoundingVectors = function () {
+            this.computeWorldMatrix();
+            var min = this.getBoundingInfo().boundingBox.minimumWorld;
+            var max = this.getBoundingInfo().boundingBox.maximumWorld;
+            var descendants = this.getDescendants(false, function (node) { return node.subMeshes; });
+            for (var _i = 0, descendants_1 = descendants; _i < descendants_1.length; _i++) {
+                var descendant = descendants_1[_i];
+                var childMesh = descendant;
+                childMesh.computeWorldMatrix();
+                var minBox = childMesh.getBoundingInfo().boundingBox.minimumWorld;
+                var maxBox = childMesh.getBoundingInfo().boundingBox.maximumWorld;
+                BABYLON.Tools.CheckExtends(minBox, min, max);
+                BABYLON.Tools.CheckExtends(maxBox, min, max);
+            }
+            return {
+                min: min,
+                max: max
+            };
+        };
         /**
          * Updates the mesh BoundingInfo object and all its children BoundingInfo objects also.
          * Returns the AbstractMesh.
@@ -52538,7 +52557,8 @@ var BABYLON;
                     'THUMBSTICK_Y',
                     'TOUCHPAD_TOUCH_X',
                     'TOUCHPAD_TOUCH_Y'
-                ]
+                ],
+                pointingPoseMeshName: 'POINTING_POSE'
             };
             _this.onTrackpadChangedObservable = new BABYLON.Observable();
             _this.controllerType = BABYLON.PoseEnabledControllerType.WINDOWS;
@@ -52698,13 +52718,10 @@ var BABYLON;
             var childMesh = null;
             for (var i = 0; i < meshes.length; i++) {
                 var mesh = meshes[i];
-                if (mesh.id === WindowsMotionController.MODEL_ROOT_NODE_NAME) {
-                    // There may be a parent mesh to perform the RH to LH matrix transform.
+                if (!mesh.parent) {
                     // Exclude controller meshes from picking results
                     mesh.isPickable = false;
                     // Handle root node, attach to the new parentMesh
-                    if (mesh.parent && mesh.parent.name === WindowsMotionController.GLTF_ROOT_TRANSFORM_NAME)
-                        mesh = mesh.parent;
                     childMesh = mesh;
                     break;
                 }
@@ -52715,7 +52732,7 @@ var BABYLON;
                 loadedMeshInfo = this.createMeshInfo(parentMesh);
             }
             else {
-                BABYLON.Tools.Warn('No node with name ' + WindowsMotionController.MODEL_ROOT_NODE_NAME + ' in model file.');
+                BABYLON.Tools.Warn('Could not find root node in model file.');
             }
             return loadedMeshInfo;
         };
@@ -52786,6 +52803,11 @@ var BABYLON;
                         ')');
                 }
             }
+            // Pointing Ray
+            loadedMeshInfo.pointingPoseNode = getChildByName(rootNode, this._mapping.pointingPoseMeshName);
+            if (!loadedMeshInfo.pointingPoseNode) {
+                BABYLON.Tools.Warn('Missing pointing pose mesh with name: ' + this._mapping.pointingPoseMeshName);
+            }
             return loadedMeshInfo;
             // Look through all children recursively. This will return null if no mesh exists with the given name.
             function getChildByName(node, name) {
@@ -52796,6 +52818,18 @@ var BABYLON;
                 return node.getChildMeshes(true, function (n) { return n.name == name; })[0];
             }
         };
+        WindowsMotionController.prototype.getForwardRay = function (length) {
+            if (length === void 0) { length = 100; }
+            if (!(this._loadedMeshInfo && this._loadedMeshInfo.pointingPoseNode)) {
+                return _super.prototype.getForwardRay.call(this, length);
+            }
+            var m = this._loadedMeshInfo.pointingPoseNode.getWorldMatrix();
+            var origin = m.getTranslation();
+            var forward = new BABYLON.Vector3(0, 0, -1);
+            var forwardWorld = BABYLON.Vector3.TransformNormal(forward, m);
+            var direction = BABYLON.Vector3.Normalize(forwardWorld);
+            return new BABYLON.Ray(origin, direction, length);
+        };
         WindowsMotionController.prototype.dispose = function () {
             _super.prototype.dispose.call(this);
             this.onTrackpadChangedObservable.clear();
@@ -52803,8 +52837,6 @@ var BABYLON;
         WindowsMotionController.MODEL_BASE_URL = 'https://controllers.babylonjs.com/microsoft/';
         WindowsMotionController.MODEL_LEFT_FILENAME = 'left.glb';
         WindowsMotionController.MODEL_RIGHT_FILENAME = 'right.glb';
-        WindowsMotionController.MODEL_ROOT_NODE_NAME = 'RootNode';
-        WindowsMotionController.GLTF_ROOT_TRANSFORM_NAME = 'root';
         WindowsMotionController.GAMEPAD_ID_PREFIX = 'Spatial Controller (Spatial Interaction Source) ';
         WindowsMotionController.GAMEPAD_ID_PATTERN = /([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/;
         return WindowsMotionController;

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


+ 28 - 11
src/Gamepad/Controllers/babylon.windowsMotionController.ts

@@ -3,7 +3,6 @@ module BABYLON {
     class LoadedMeshInfo {
         public rootNode: AbstractMesh;
         public pointingPoseNode: AbstractMesh;
-        public holdingPoseNode: AbstractMesh;
         public buttonMeshes: { [id: string] : IButtonMeshInfo; } = {};
         public axisMeshes: { [id: number] : IAxisMeshInfo; } = {};
     }
@@ -27,8 +26,6 @@ module BABYLON {
         private static readonly MODEL_BASE_URL:string = 'https://controllers.babylonjs.com/microsoft/';
         private static readonly MODEL_LEFT_FILENAME:string = 'left.glb';
         private static readonly MODEL_RIGHT_FILENAME:string = 'right.glb';
-        private static readonly MODEL_ROOT_NODE_NAME:string = 'RootNode';
-        private static readonly GLTF_ROOT_TRANSFORM_NAME:string = 'root';
 
         public static readonly GAMEPAD_ID_PREFIX:string = 'Spatial Controller (Spatial Interaction Source) ';
         private static readonly GAMEPAD_ID_PATTERN = /([0-9a-zA-Z]+-[0-9a-zA-Z]+)$/;
@@ -64,7 +61,8 @@ module BABYLON {
                 'THUMBSTICK_Y',
                 'TOUCHPAD_TOUCH_X',
                 'TOUCHPAD_TOUCH_Y'
-            ]
+            ],
+            pointingPoseMeshName: 'POINTING_POSE'
         };
 
         public onTrackpadChangedObservable = new Observable<ExtendedGamepadButton>();
@@ -247,15 +245,12 @@ module BABYLON {
             let childMesh : AbstractMesh = null;
             for (let i = 0; i < meshes.length; i++) {
                 let mesh = meshes[i];
-                if (mesh.id === WindowsMotionController.MODEL_ROOT_NODE_NAME) {
-                    // There may be a parent mesh to perform the RH to LH matrix transform.
+
+                if (!mesh.parent) {
                     // Exclude controller meshes from picking results
                     mesh.isPickable = false;
-
-                    // Handle root node, attach to the new parentMesh
-                    if (mesh.parent && mesh.parent.name === WindowsMotionController.GLTF_ROOT_TRANSFORM_NAME)
-                        mesh = <AbstractMesh>mesh.parent;
                     
+                    // Handle root node, attach to the new parentMesh
                     childMesh = mesh;
                     break;
                 }
@@ -267,7 +262,7 @@ module BABYLON {
                 // Create our mesh info. Note that this method will always return non-null.
                 loadedMeshInfo = this.createMeshInfo(parentMesh);
             } else {
-                Tools.Warn('No node with name ' + WindowsMotionController.MODEL_ROOT_NODE_NAME +' in model file.');
+                Tools.Warn('Could not find root node in model file.');
             }
 
             return loadedMeshInfo;
@@ -346,6 +341,12 @@ module BABYLON {
                 }
             }
 
+            // Pointing Ray
+            loadedMeshInfo.pointingPoseNode = getChildByName(rootNode, this._mapping.pointingPoseMeshName);
+            if (!loadedMeshInfo.pointingPoseNode) {                
+                Tools.Warn('Missing pointing pose mesh with name: ' + this._mapping.pointingPoseMeshName);
+            }
+
             return loadedMeshInfo;
             
             // Look through all children recursively. This will return null if no mesh exists with the given name.
@@ -358,6 +359,22 @@ module BABYLON {
             }
         }
 
+        public getForwardRay(length = 100): Ray {
+            if (!(this._loadedMeshInfo && this._loadedMeshInfo.pointingPoseNode)) {
+                return super.getForwardRay(length);
+            }
+
+            var m = this._loadedMeshInfo.pointingPoseNode.getWorldMatrix();
+            var origin = m.getTranslation();
+
+            var forward = new BABYLON.Vector3(0, 0, -1);
+            var forwardWorld = BABYLON.Vector3.TransformNormal(forward, m);
+
+            var direction = BABYLON.Vector3.Normalize(forwardWorld);            
+
+            return new Ray(origin, direction, length);
+        }
+
         public dispose(): void {
             super.dispose();
 

+ 24 - 0
src/Mesh/babylon.abstractMesh.ts

@@ -1155,6 +1155,30 @@
             return this;
         }
 
+        public getHierarchyBoundingVectors(): { min: Vector3, max: Vector3 }{
+            this.computeWorldMatrix();
+            let min = this.getBoundingInfo().boundingBox.minimumWorld;
+            let max = this.getBoundingInfo().boundingBox.maximumWorld;
+
+            let descendants = this.getDescendants(false, (node) => (<any>node).subMeshes);
+
+            for (var descendant of descendants) {
+                let childMesh = <AbstractMesh>descendant;
+
+                childMesh.computeWorldMatrix();
+                var minBox = childMesh.getBoundingInfo().boundingBox.minimumWorld;
+                var maxBox = childMesh.getBoundingInfo().boundingBox.maximumWorld;
+
+                Tools.CheckExtends(minBox, min, max);
+                Tools.CheckExtends(maxBox, min, max);
+            }
+
+            return {
+                min: min,
+                max: max
+            }
+        }
+
         /**
          * Updates the mesh BoundingInfo object and all its children BoundingInfo objects also.  
          * Returns the AbstractMesh.