David Catuhe 8 年之前
父节点
当前提交
8145284e7b

文件差异内容过多而无法显示
+ 11 - 10
dist/preview release/babylon.core.js


文件差异内容过多而无法显示
+ 1557 - 1544
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 21 - 20
dist/preview release/babylon.js


+ 123 - 53
dist/preview release/babylon.max.js

@@ -29950,40 +29950,66 @@ var BABYLON;
             this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
             this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
             return true;
             return true;
         };
         };
-        Bone.prototype.translate = function (vec) {
+        Bone.prototype.translate = function (vec, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var lm = this.getLocalMatrix();
             var lm = this.getLocalMatrix();
-            lm.m[12] += vec.x;
-            lm.m[13] += vec.y;
-            lm.m[14] += vec.z;
+            if (space == BABYLON.Space.LOCAL) {
+                lm.m[12] += vec.x;
+                lm.m[13] += vec.y;
+                lm.m[14] += vec.z;
+            }
+            else {
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                var tvec = BABYLON.Tmp.Vector3[0];
+                if (mesh) {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                }
+                tmat.m[12] = 0;
+                tmat.m[13] = 0;
+                tmat.m[14] = 0;
+                tmat.invert();
+                BABYLON.Vector3.TransformCoordinatesToRef(vec, tmat, tvec);
+                lm.m[12] += tvec.x;
+                lm.m[13] += tvec.y;
+                lm.m[14] += tvec.z;
+            }
             this.markAsDirty();
             this.markAsDirty();
         };
         };
-        Bone.prototype.setPosition = function (position) {
+        Bone.prototype.setPosition = function (position, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var lm = this.getLocalMatrix();
             var lm = this.getLocalMatrix();
-            lm.m[12] = position.x;
-            lm.m[13] = position.y;
-            lm.m[14] = position.z;
-            this.markAsDirty();
-        };
-        Bone.prototype.setAbsolutePosition = function (position, mesh) {
-            if (mesh === void 0) { mesh = null; }
-            this._skeleton.computeAbsoluteTransforms();
-            var tmat = BABYLON.Tmp.Matrix[0];
-            var vec = BABYLON.Tmp.Vector3[0];
-            if (mesh) {
-                tmat.copyFrom(this._parent.getAbsoluteTransform());
-                tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+            if (space == BABYLON.Space.LOCAL) {
+                lm.m[12] = position.x;
+                lm.m[13] = position.y;
+                lm.m[14] = position.z;
             }
             }
             else {
             else {
-                tmat.copyFrom(this._parent.getAbsoluteTransform());
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                var vec = BABYLON.Tmp.Vector3[0];
+                if (mesh) {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                }
+                tmat.invert();
+                BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, vec);
+                lm.m[12] = vec.x;
+                lm.m[13] = vec.y;
+                lm.m[14] = vec.z;
             }
             }
-            tmat.invert();
-            BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, vec);
-            var lm = this.getLocalMatrix();
-            lm.m[12] = vec.x;
-            lm.m[13] = vec.y;
-            lm.m[14] = vec.z;
             this.markAsDirty();
             this.markAsDirty();
         };
         };
+        Bone.prototype.setAbsolutePosition = function (position, mesh) {
+            this.setPosition(position, BABYLON.Space.WORLD, mesh);
+        };
         Bone.prototype.setScale = function (x, y, z, scaleChildren) {
         Bone.prototype.setScale = function (x, y, z, scaleChildren) {
             if (scaleChildren === void 0) { scaleChildren = false; }
             if (scaleChildren === void 0) { scaleChildren = false; }
             if (this.animations[0] && !this.animations[0].isStopped()) {
             if (this.animations[0] && !this.animations[0].isStopped()) {
@@ -30041,7 +30067,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setYawPitchRoll = function (yaw, pitch, roll, space, mesh) {
         Bone.prototype.setYawPitchRoll = function (yaw, pitch, roll, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMat = BABYLON.Tmp.Matrix[0];
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
             BABYLON.Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -30051,7 +30076,6 @@ var BABYLON;
         };
         };
         Bone.prototype.rotate = function (axis, amount, space, mesh) {
         Bone.prototype.rotate = function (axis, amount, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rmat = BABYLON.Tmp.Matrix[0];
             var rmat = BABYLON.Tmp.Matrix[0];
             rmat.m[12] = 0;
             rmat.m[12] = 0;
             rmat.m[13] = 0;
             rmat.m[13] = 0;
@@ -30061,7 +30085,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
         Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMat = BABYLON.Tmp.Matrix[0];
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -30071,7 +30094,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
         Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMatInv = BABYLON.Tmp.Matrix[0];
             var rotMatInv = BABYLON.Tmp.Matrix[0];
             this._getNegativeRotationToRef(rotMatInv, space, mesh);
             this._getNegativeRotationToRef(rotMatInv, space, mesh);
             var rotMat2 = BABYLON.Tmp.Matrix[1];
             var rotMat2 = BABYLON.Tmp.Matrix[1];
@@ -30081,7 +30103,6 @@ var BABYLON;
         };
         };
         Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
         Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var lmat = this.getLocalMatrix();
             var lmat = this.getLocalMatrix();
             var lx = lmat.m[12];
             var lx = lmat.m[12];
             var ly = lmat.m[13];
             var ly = lmat.m[13];
@@ -30129,7 +30150,6 @@ var BABYLON;
         };
         };
         Bone.prototype._getNegativeRotationToRef = function (rotMatInv, space, mesh) {
         Bone.prototype._getNegativeRotationToRef = function (rotMatInv, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             if (space == BABYLON.Space.WORLD) {
             if (space == BABYLON.Space.WORLD) {
                 var scaleMatrix = BABYLON.Tmp.Matrix[2];
                 var scaleMatrix = BABYLON.Tmp.Matrix[2];
                 scaleMatrix.copyFrom(this._scaleMatrix);
                 scaleMatrix.copyFrom(this._scaleMatrix);
@@ -30167,26 +30187,42 @@ var BABYLON;
         Bone.prototype.getScaleToRef = function (result) {
         Bone.prototype.getScaleToRef = function (result) {
             result.copyFrom(this._scaleVector);
             result.copyFrom(this._scaleVector);
         };
         };
-        Bone.prototype.getAbsolutePosition = function (mesh) {
-            if (mesh === void 0) { mesh = null; }
+        Bone.prototype.getPosition = function (space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var pos = BABYLON.Vector3.Zero();
             var pos = BABYLON.Vector3.Zero();
-            this.getAbsolutePositionToRef(mesh, pos);
+            this.getPositionToRef(space, mesh, pos);
             return pos;
             return pos;
         };
         };
-        Bone.prototype.getAbsolutePositionToRef = function (mesh, result) {
-            if (mesh === void 0) { mesh = null; }
-            this._skeleton.computeAbsoluteTransforms();
-            var tmat = BABYLON.Tmp.Matrix[0];
-            if (mesh) {
-                tmat.copyFrom(this.getAbsoluteTransform());
-                tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+        Bone.prototype.getPositionToRef = function (space, mesh, result) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (space == BABYLON.Space.LOCAL) {
+                var lm = this.getLocalMatrix();
+                result.x = lm.m[12];
+                result.y = lm.m[13];
+                result.z = lm.m[14];
             }
             }
             else {
             else {
-                tmat = this.getAbsoluteTransform();
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                if (mesh) {
+                    tmat.copyFrom(this.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat = this.getAbsoluteTransform();
+                }
+                result.x = tmat.m[12];
+                result.y = tmat.m[13];
+                result.z = tmat.m[14];
             }
             }
-            result.x = tmat.m[12];
-            result.y = tmat.m[13];
-            result.z = tmat.m[14];
+        };
+        Bone.prototype.getAbsolutePosition = function (mesh) {
+            var pos = BABYLON.Vector3.Zero();
+            this.getPositionToRef(BABYLON.Space.WORLD, mesh, pos);
+            return pos;
+        };
+        Bone.prototype.getAbsolutePositionToRef = function (mesh, result) {
+            this.getPositionToRef(BABYLON.Space.WORLD, mesh, result);
         };
         };
         Bone.prototype.computeAbsoluteTransforms = function () {
         Bone.prototype.computeAbsoluteTransforms = function () {
             if (this._parent) {
             if (this._parent) {
@@ -30220,17 +30256,29 @@ var BABYLON;
             BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
             BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
             result.normalize();
             result.normalize();
         };
         };
-        Bone.prototype.getRotation = function (mesh) {
+        Bone.prototype.getRotation = function (space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var result = BABYLON.Quaternion.Identity();
             var result = BABYLON.Quaternion.Identity();
-            this.getRotationToRef(mesh, result);
+            this.getRotationToRef(space, mesh, result);
             return result;
             return result;
         };
         };
-        Bone.prototype.getRotationToRef = function (mesh, result) {
-            var mat = BABYLON.Tmp.Matrix[0];
-            var amat = this.getAbsoluteTransform();
-            var wmat = mesh.getWorldMatrix();
-            amat.multiplyToRef(wmat, mat);
-            mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+        Bone.prototype.getRotationToRef = function (space, mesh, result) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (space == BABYLON.Space.LOCAL) {
+                this.getLocalMatrix().decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+            }
+            else {
+                var mat = BABYLON.Tmp.Matrix[0];
+                var amat = this.getAbsoluteTransform();
+                if (mesh) {
+                    var wmat = mesh.getWorldMatrix();
+                    amat.multiplyToRef(wmat, mat);
+                    mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                }
+                else {
+                    amat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                }
+            }
         };
         };
         return Bone;
         return Bone;
     }(BABYLON.Node));
     }(BABYLON.Node));
@@ -44294,6 +44342,8 @@ var BABYLON;
             this._cacheState = null;
             this._cacheState = null;
             this._vrEnabled = false;
             this._vrEnabled = false;
             this._attached = false;
             this._attached = false;
+            //using the position provided as the current position offset
+            this._positionOffset = position;
             //enable VR
             //enable VR
             this.getEngine().initWebVR();
             this.getEngine().initWebVR();
             if (!this.getEngine().vrDisplaysPromise) {
             if (!this.getEngine().vrDisplaysPromise) {
@@ -44348,7 +44398,10 @@ var BABYLON;
                     this.rotationQuaternion.copyFromFloats(this._cacheState.orientation[0], this._cacheState.orientation[1], -this._cacheState.orientation[2], -this._cacheState.orientation[3]);
                     this.rotationQuaternion.copyFromFloats(this._cacheState.orientation[0], this._cacheState.orientation[1], -this._cacheState.orientation[2], -this._cacheState.orientation[3]);
                     if (this.webVROptions.trackPosition && this._cacheState.position) {
                     if (this.webVROptions.trackPosition && this._cacheState.position) {
                         this.position.copyFromFloats(this._cacheState.position[0], this._cacheState.position[1], -this._cacheState.position[2]);
                         this.position.copyFromFloats(this._cacheState.position[0], this._cacheState.position[1], -this._cacheState.position[2]);
+                        //scale the position accordingly
                         this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale);
                         this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale);
+                        //add the position offset
+                        this.position.addInPlace(this._positionOffset);
                     }
                     }
                 }
                 }
             }
             }
@@ -44381,6 +44434,23 @@ var BABYLON;
             //pitch and roll won't be affected.
             //pitch and roll won't be affected.
             this._vrDevice.resetPose();
             this._vrDevice.resetPose();
         };
         };
+        /**
+         *
+         * Set the position offset of the VR camera
+         * The offset will be added to the WebVR pose, after scaling it (if set).
+         *
+         * @param {Vector3} [newPosition] an optional new position. if not provided, the current camera position will be used.
+         *
+         * @memberOf WebVRFreeCamera
+         */
+        WebVRFreeCamera.prototype.setPositionOffset = function (newPosition) {
+            if (newPosition) {
+                this._positionOffset = newPosition;
+            }
+            else {
+                this._positionOffset.copyFrom(this.position);
+            }
+        };
         return WebVRFreeCamera;
         return WebVRFreeCamera;
     }(BABYLON.FreeCamera));
     }(BABYLON.FreeCamera));
     BABYLON.WebVRFreeCamera = WebVRFreeCamera;
     BABYLON.WebVRFreeCamera = WebVRFreeCamera;

文件差异内容过多而无法显示
+ 21 - 20
dist/preview release/babylon.noworker.js


+ 101 - 53
src/Bones/babylon.bone.js

@@ -163,40 +163,66 @@ var BABYLON;
             this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
             this.animations[0].createRange(rangeName, from + frameOffset, to + frameOffset);
             return true;
             return true;
         };
         };
-        Bone.prototype.translate = function (vec) {
+        Bone.prototype.translate = function (vec, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var lm = this.getLocalMatrix();
             var lm = this.getLocalMatrix();
-            lm.m[12] += vec.x;
-            lm.m[13] += vec.y;
-            lm.m[14] += vec.z;
+            if (space == BABYLON.Space.LOCAL) {
+                lm.m[12] += vec.x;
+                lm.m[13] += vec.y;
+                lm.m[14] += vec.z;
+            }
+            else {
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                var tvec = BABYLON.Tmp.Vector3[0];
+                if (mesh) {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                }
+                tmat.m[12] = 0;
+                tmat.m[13] = 0;
+                tmat.m[14] = 0;
+                tmat.invert();
+                BABYLON.Vector3.TransformCoordinatesToRef(vec, tmat, tvec);
+                lm.m[12] += tvec.x;
+                lm.m[13] += tvec.y;
+                lm.m[14] += tvec.z;
+            }
             this.markAsDirty();
             this.markAsDirty();
         };
         };
-        Bone.prototype.setPosition = function (position) {
+        Bone.prototype.setPosition = function (position, space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var lm = this.getLocalMatrix();
             var lm = this.getLocalMatrix();
-            lm.m[12] = position.x;
-            lm.m[13] = position.y;
-            lm.m[14] = position.z;
-            this.markAsDirty();
-        };
-        Bone.prototype.setAbsolutePosition = function (position, mesh) {
-            if (mesh === void 0) { mesh = null; }
-            this._skeleton.computeAbsoluteTransforms();
-            var tmat = BABYLON.Tmp.Matrix[0];
-            var vec = BABYLON.Tmp.Vector3[0];
-            if (mesh) {
-                tmat.copyFrom(this._parent.getAbsoluteTransform());
-                tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+            if (space == BABYLON.Space.LOCAL) {
+                lm.m[12] = position.x;
+                lm.m[13] = position.y;
+                lm.m[14] = position.z;
             }
             }
             else {
             else {
-                tmat.copyFrom(this._parent.getAbsoluteTransform());
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                var vec = BABYLON.Tmp.Vector3[0];
+                if (mesh) {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat.copyFrom(this._parent.getAbsoluteTransform());
+                }
+                tmat.invert();
+                BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, vec);
+                lm.m[12] = vec.x;
+                lm.m[13] = vec.y;
+                lm.m[14] = vec.z;
             }
             }
-            tmat.invert();
-            BABYLON.Vector3.TransformCoordinatesToRef(position, tmat, vec);
-            var lm = this.getLocalMatrix();
-            lm.m[12] = vec.x;
-            lm.m[13] = vec.y;
-            lm.m[14] = vec.z;
             this.markAsDirty();
             this.markAsDirty();
         };
         };
+        Bone.prototype.setAbsolutePosition = function (position, mesh) {
+            this.setPosition(position, BABYLON.Space.WORLD, mesh);
+        };
         Bone.prototype.setScale = function (x, y, z, scaleChildren) {
         Bone.prototype.setScale = function (x, y, z, scaleChildren) {
             if (scaleChildren === void 0) { scaleChildren = false; }
             if (scaleChildren === void 0) { scaleChildren = false; }
             if (this.animations[0] && !this.animations[0].isStopped()) {
             if (this.animations[0] && !this.animations[0].isStopped()) {
@@ -254,7 +280,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setYawPitchRoll = function (yaw, pitch, roll, space, mesh) {
         Bone.prototype.setYawPitchRoll = function (yaw, pitch, roll, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMat = BABYLON.Tmp.Matrix[0];
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
             BABYLON.Matrix.RotationYawPitchRollToRef(yaw, pitch, roll, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -264,7 +289,6 @@ var BABYLON;
         };
         };
         Bone.prototype.rotate = function (axis, amount, space, mesh) {
         Bone.prototype.rotate = function (axis, amount, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rmat = BABYLON.Tmp.Matrix[0];
             var rmat = BABYLON.Tmp.Matrix[0];
             rmat.m[12] = 0;
             rmat.m[12] = 0;
             rmat.m[13] = 0;
             rmat.m[13] = 0;
@@ -274,7 +298,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
         Bone.prototype.setAxisAngle = function (axis, angle, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMat = BABYLON.Tmp.Matrix[0];
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -284,7 +307,6 @@ var BABYLON;
         };
         };
         Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
         Bone.prototype.setRotationMatrix = function (rotMat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var rotMatInv = BABYLON.Tmp.Matrix[0];
             var rotMatInv = BABYLON.Tmp.Matrix[0];
             this._getNegativeRotationToRef(rotMatInv, space, mesh);
             this._getNegativeRotationToRef(rotMatInv, space, mesh);
             var rotMat2 = BABYLON.Tmp.Matrix[1];
             var rotMat2 = BABYLON.Tmp.Matrix[1];
@@ -294,7 +316,6 @@ var BABYLON;
         };
         };
         Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
         Bone.prototype._rotateWithMatrix = function (rmat, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             var lmat = this.getLocalMatrix();
             var lmat = this.getLocalMatrix();
             var lx = lmat.m[12];
             var lx = lmat.m[12];
             var ly = lmat.m[13];
             var ly = lmat.m[13];
@@ -342,7 +363,6 @@ var BABYLON;
         };
         };
         Bone.prototype._getNegativeRotationToRef = function (rotMatInv, space, mesh) {
         Bone.prototype._getNegativeRotationToRef = function (rotMatInv, space, mesh) {
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
             if (space === void 0) { space = BABYLON.Space.LOCAL; }
-            if (mesh === void 0) { mesh = null; }
             if (space == BABYLON.Space.WORLD) {
             if (space == BABYLON.Space.WORLD) {
                 var scaleMatrix = BABYLON.Tmp.Matrix[2];
                 var scaleMatrix = BABYLON.Tmp.Matrix[2];
                 scaleMatrix.copyFrom(this._scaleMatrix);
                 scaleMatrix.copyFrom(this._scaleMatrix);
@@ -380,26 +400,42 @@ var BABYLON;
         Bone.prototype.getScaleToRef = function (result) {
         Bone.prototype.getScaleToRef = function (result) {
             result.copyFrom(this._scaleVector);
             result.copyFrom(this._scaleVector);
         };
         };
-        Bone.prototype.getAbsolutePosition = function (mesh) {
-            if (mesh === void 0) { mesh = null; }
+        Bone.prototype.getPosition = function (space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var pos = BABYLON.Vector3.Zero();
             var pos = BABYLON.Vector3.Zero();
-            this.getAbsolutePositionToRef(mesh, pos);
+            this.getPositionToRef(space, mesh, pos);
             return pos;
             return pos;
         };
         };
-        Bone.prototype.getAbsolutePositionToRef = function (mesh, result) {
-            if (mesh === void 0) { mesh = null; }
-            this._skeleton.computeAbsoluteTransforms();
-            var tmat = BABYLON.Tmp.Matrix[0];
-            if (mesh) {
-                tmat.copyFrom(this.getAbsoluteTransform());
-                tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+        Bone.prototype.getPositionToRef = function (space, mesh, result) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (space == BABYLON.Space.LOCAL) {
+                var lm = this.getLocalMatrix();
+                result.x = lm.m[12];
+                result.y = lm.m[13];
+                result.z = lm.m[14];
             }
             }
             else {
             else {
-                tmat = this.getAbsoluteTransform();
+                this._skeleton.computeAbsoluteTransforms();
+                var tmat = BABYLON.Tmp.Matrix[0];
+                if (mesh) {
+                    tmat.copyFrom(this.getAbsoluteTransform());
+                    tmat.multiplyToRef(mesh.getWorldMatrix(), tmat);
+                }
+                else {
+                    tmat = this.getAbsoluteTransform();
+                }
+                result.x = tmat.m[12];
+                result.y = tmat.m[13];
+                result.z = tmat.m[14];
             }
             }
-            result.x = tmat.m[12];
-            result.y = tmat.m[13];
-            result.z = tmat.m[14];
+        };
+        Bone.prototype.getAbsolutePosition = function (mesh) {
+            var pos = BABYLON.Vector3.Zero();
+            this.getPositionToRef(BABYLON.Space.WORLD, mesh, pos);
+            return pos;
+        };
+        Bone.prototype.getAbsolutePositionToRef = function (mesh, result) {
+            this.getPositionToRef(BABYLON.Space.WORLD, mesh, result);
         };
         };
         Bone.prototype.computeAbsoluteTransforms = function () {
         Bone.prototype.computeAbsoluteTransforms = function () {
             if (this._parent) {
             if (this._parent) {
@@ -433,17 +469,29 @@ var BABYLON;
             BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
             BABYLON.Vector3.TransformNormalToRef(localAxis, mat, result);
             result.normalize();
             result.normalize();
         };
         };
-        Bone.prototype.getRotation = function (mesh) {
+        Bone.prototype.getRotation = function (space, mesh) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
             var result = BABYLON.Quaternion.Identity();
             var result = BABYLON.Quaternion.Identity();
-            this.getRotationToRef(mesh, result);
+            this.getRotationToRef(space, mesh, result);
             return result;
             return result;
         };
         };
-        Bone.prototype.getRotationToRef = function (mesh, result) {
-            var mat = BABYLON.Tmp.Matrix[0];
-            var amat = this.getAbsoluteTransform();
-            var wmat = mesh.getWorldMatrix();
-            amat.multiplyToRef(wmat, mat);
-            mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+        Bone.prototype.getRotationToRef = function (space, mesh, result) {
+            if (space === void 0) { space = BABYLON.Space.LOCAL; }
+            if (space == BABYLON.Space.LOCAL) {
+                this.getLocalMatrix().decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+            }
+            else {
+                var mat = BABYLON.Tmp.Matrix[0];
+                var amat = this.getAbsoluteTransform();
+                if (mesh) {
+                    var wmat = mesh.getWorldMatrix();
+                    amat.multiplyToRef(wmat, mat);
+                    mat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                }
+                else {
+                    amat.decompose(BABYLON.Tmp.Vector3[0], result, BABYLON.Tmp.Vector3[1]);
+                }
+            }
         };
         };
         return Bone;
         return Bone;
     }(BABYLON.Node));
     }(BABYLON.Node));

+ 22 - 0
src/Cameras/VR/babylon.webVRCamera.js

@@ -17,6 +17,8 @@ var BABYLON;
             this._cacheState = null;
             this._cacheState = null;
             this._vrEnabled = false;
             this._vrEnabled = false;
             this._attached = false;
             this._attached = false;
+            //using the position provided as the current position offset
+            this._positionOffset = position;
             //enable VR
             //enable VR
             this.getEngine().initWebVR();
             this.getEngine().initWebVR();
             if (!this.getEngine().vrDisplaysPromise) {
             if (!this.getEngine().vrDisplaysPromise) {
@@ -71,7 +73,10 @@ var BABYLON;
                     this.rotationQuaternion.copyFromFloats(this._cacheState.orientation[0], this._cacheState.orientation[1], -this._cacheState.orientation[2], -this._cacheState.orientation[3]);
                     this.rotationQuaternion.copyFromFloats(this._cacheState.orientation[0], this._cacheState.orientation[1], -this._cacheState.orientation[2], -this._cacheState.orientation[3]);
                     if (this.webVROptions.trackPosition && this._cacheState.position) {
                     if (this.webVROptions.trackPosition && this._cacheState.position) {
                         this.position.copyFromFloats(this._cacheState.position[0], this._cacheState.position[1], -this._cacheState.position[2]);
                         this.position.copyFromFloats(this._cacheState.position[0], this._cacheState.position[1], -this._cacheState.position[2]);
+                        //scale the position accordingly
                         this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale);
                         this.webVROptions.positionScale && this.position.scaleInPlace(this.webVROptions.positionScale);
+                        //add the position offset
+                        this.position.addInPlace(this._positionOffset);
                     }
                     }
                 }
                 }
             }
             }
@@ -104,6 +109,23 @@ var BABYLON;
             //pitch and roll won't be affected.
             //pitch and roll won't be affected.
             this._vrDevice.resetPose();
             this._vrDevice.resetPose();
         };
         };
+        /**
+         *
+         * Set the position offset of the VR camera
+         * The offset will be added to the WebVR pose, after scaling it (if set).
+         *
+         * @param {Vector3} [newPosition] an optional new position. if not provided, the current camera position will be used.
+         *
+         * @memberOf WebVRFreeCamera
+         */
+        WebVRFreeCamera.prototype.setPositionOffset = function (newPosition) {
+            if (newPosition) {
+                this._positionOffset = newPosition;
+            }
+            else {
+                this._positionOffset.copyFrom(this.position);
+            }
+        };
         return WebVRFreeCamera;
         return WebVRFreeCamera;
     }(BABYLON.FreeCamera));
     }(BABYLON.FreeCamera));
     BABYLON.WebVRFreeCamera = WebVRFreeCamera;
     BABYLON.WebVRFreeCamera = WebVRFreeCamera;