David Catuhe 7 anni fa
parent
commit
b9ea8cd8cf

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


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


+ 64 - 44
dist/preview release/babylon.max.js

@@ -92194,11 +92194,13 @@ var BABYLON;
             });
             this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
                 if (_this._moving && _this.moveAttached) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(_this._attachedNode);
                     // Slowly move mesh to avoid jitter
-                    _this._targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._targetPosition.subtractToRef((_this._attachedNode).absolutePosition, _this._tmpVector);
                     _this._tmpVector.scaleInPlace(_this.dragDeltaRatio);
-                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
-                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                    (_this._attachedNode).getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    (_this._attachedNode).setAbsolutePosition(_this._tmpVector);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(_this._attachedNode);
                 }
             });
         };
@@ -92231,6 +92233,7 @@ var BABYLON;
             if (!this._scene.activeCamera || this.dragging || !this._attachedNode) {
                 return;
             }
+            BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(this._attachedNode);
             // Create start ray from the camera to the object
             if (fromRay) {
                 this._startDragRay.direction.copyFrom(fromRay.direction);
@@ -92248,7 +92251,7 @@ var BABYLON;
                 this.currentDraggingPointerID = 1;
                 this.lastDragPosition.copyFrom(pickedPoint);
                 this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID });
-                this._targetPosition.copyFrom(this._attachedNode.absolutePosition);
+                this._targetPosition.copyFrom((this._attachedNode).absolutePosition);
                 // Detatch camera controls
                 if (this.detachCameraControls && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
                     if (this._scene.activeCamera.inputs.attachedElement) {
@@ -92260,6 +92263,7 @@ var BABYLON;
                     }
                 }
             }
+            BABYLON.BoundingBoxGizmo._RestorePivotPoint(this._attachedNode);
         };
         PointerDragBehavior.prototype._moveDrag = function (ray) {
             this._moving = true;
@@ -92303,7 +92307,7 @@ var BABYLON;
                 if (this._useAlternatePickedPointAboveMaxDragAngle) {
                     // Invert ray direction along the towards object axis
                     this._tmpVector.copyFrom(ray.direction);
-                    this._attachedNode.absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
+                    (this._attachedNode).absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
                     this._alternatePickedPoint.normalize();
                     this._alternatePickedPoint.scaleInPlace(-2 * BABYLON.Vector3.Dot(this._alternatePickedPoint, this._tmpVector));
                     this._tmpVector.addInPlace(this._alternatePickedPoint);
@@ -92311,7 +92315,7 @@ var BABYLON;
                     var dot = BABYLON.Vector3.Dot(this._dragPlane.forward, this._tmpVector);
                     this._dragPlane.forward.scaleToRef(-dot, this._alternatePickedPoint);
                     this._alternatePickedPoint.addInPlace(this._tmpVector);
-                    this._alternatePickedPoint.addInPlace(this._attachedNode.absolutePosition);
+                    this._alternatePickedPoint.addInPlace((this._attachedNode).absolutePosition);
                     return this._alternatePickedPoint;
                 }
                 else {
@@ -92555,6 +92559,7 @@ var BABYLON;
                             pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
                         }
                         pickedMesh = _this._ownerNode;
+                        BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                         lastSixDofOriginPosition.copyFrom(pointerInfo.pickInfo.ray.origin);
                         // Set position and orientation of the controller
                         _this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
@@ -92584,6 +92589,7 @@ var BABYLON;
                                 attachedElement = null;
                             }
                         }
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                     }
                 }
                 else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
@@ -92636,6 +92642,7 @@ var BABYLON;
             // On every frame move towards target scaling to avoid jitter caused by vr controllers
             this._sceneRenderObserver = ownerNode.getScene().onBeforeRenderObservable.add(function () {
                 if (_this.dragging && _this._moving && pickedMesh) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                     // Get change in rotation
@@ -92652,6 +92659,7 @@ var BABYLON;
                     pickedMesh.setParent(null);
                     BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
                     pickedMesh.setParent(oldParent);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                 }
             });
         };
@@ -93925,11 +93933,6 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
-            // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
-            // store/remove pivot point should only be applied during their outermost calls
-            _this._pivotCached = 0;
-            _this._oldPivotPoint = new BABYLON.Vector3();
-            _this._pivotTranslation = new BABYLON.Vector3();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -93984,7 +93987,7 @@ var BABYLON;
                 _dragBehavior.onDragObservable.add(function (event) {
                     _this.onRotationSphereDragObservable.notifyObservers({});
                     if (_this.attachedMesh) {
-                        _this._removeAndStorePivotPoint();
+                        BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                         var worldDragDirection = startingTurnDirection;
                         // Project the world right on to the drag plane
                         var toSub = event.dragPlaneNormal.scale(BABYLON.Vector3.Dot(event.dragPlaneNormal, worldDragDirection));
@@ -94018,7 +94021,7 @@ var BABYLON;
                             _this._anchorMesh.removeChild(_this.attachedMesh);
                         }
                         _this.updateBoundingBox();
-                        _this._restorePivotPoint();
+                        BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
                 });
                 // Selection/deselection
@@ -94053,7 +94056,7 @@ var BABYLON;
                         _dragBehavior.onDragObservable.add(function (event) {
                             _this.onScaleBoxDragObservable.notifyObservers({});
                             if (_this.attachedMesh) {
-                                _this._removeAndStorePivotPoint();
+                                BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                                 var relativeDragDistance = (event.dragDistance / _this._boundingDimensions.length()) * _this._anchorMesh.scaling.length();
                                 var deltaScale = new BABYLON.Vector3(relativeDragDistance, relativeDragDistance, relativeDragDistance);
                                 deltaScale.scaleInPlace(_this._scaleDragSpeed);
@@ -94079,7 +94082,7 @@ var BABYLON;
                                     _this._anchorMesh.scaling.subtractInPlace(deltaScale);
                                 }
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
-                                _this._restorePivotPoint();
+                                BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
                         });
                         // Selection/deselection
@@ -94128,40 +94131,41 @@ var BABYLON;
             _this.updateBoundingBox();
             return _this;
         }
-        BoundingBoxGizmo.prototype._removeAndStorePivotPoint = function () {
-            if (this.attachedMesh && this._pivotCached === 0) {
+        /** @hidden */
+        BoundingBoxGizmo._RemoveAndStorePivotPoint = function (mesh) {
+            if (mesh && BoundingBoxGizmo._PivotCached === 0) {
                 // Save old pivot and set pivot to 0,0,0
-                this.attachedMesh.getPivotPointToRef(this._oldPivotPoint);
-                if (this._oldPivotPoint.equalsToFloats(0, 0, 0)) {
-                    return;
+                mesh.getPivotPointToRef(BoundingBoxGizmo._OldPivotPoint);
+                if (!BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0)) {
+                    mesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
+                    BoundingBoxGizmo._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), BoundingBoxGizmo._PivotTranslation);
+                    BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                    BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                    BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                    mesh.position.addInPlace(BoundingBoxGizmo._PivotTmpVector);
                 }
-                this.attachedMesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
-                this._oldPivotPoint.subtractToRef(this.attachedMesh.getPivotPoint(), this._pivotTranslation);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.addInPlace(this._tmpVector);
             }
-            this._pivotCached++;
+            BoundingBoxGizmo._PivotCached++;
         };
-        BoundingBoxGizmo.prototype._restorePivotPoint = function () {
-            if (this.attachedMesh && !this._oldPivotPoint.equalsToFloats(0, 0, 0) && this._pivotCached === 1) {
-                this.attachedMesh.setPivotPoint(this._oldPivotPoint);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.subtractInPlace(this._tmpVector);
+        /** @hidden */
+        BoundingBoxGizmo._RestorePivotPoint = function (mesh) {
+            if (mesh && !BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0) && BoundingBoxGizmo._PivotCached === 1) {
+                mesh.setPivotPoint(BoundingBoxGizmo._OldPivotPoint);
+                BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                mesh.position.subtractInPlace(BoundingBoxGizmo._PivotTmpVector);
             }
-            this._pivotCached--;
+            this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(value);
                 this._anchorMesh.addChild(value);
                 this._anchorMesh.removeChild(value);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
             }
         };
@@ -94185,7 +94189,7 @@ var BABYLON;
          */
         BoundingBoxGizmo.prototype.updateBoundingBox = function () {
             if (this.attachedMesh) {
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
                 this._update();
                 // Rotate based on axis
                 if (!this.attachedMesh.rotationQuaternion) {
@@ -94276,7 +94280,7 @@ var BABYLON;
             }
             if (this.attachedMesh) {
                 this._existingMeshScale.copyFrom(this.attachedMesh.scaling);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
             }
         };
         /**
@@ -94350,6 +94354,12 @@ var BABYLON;
         BoundingBoxGizmo.prototype.setCustomMesh = function (mesh) {
             BABYLON.Tools.Error("Custom meshes are not supported on this gizmo");
         };
+        // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
+        // store/remove pivot point should only be applied during their outermost calls
+        BoundingBoxGizmo._PivotCached = 0;
+        BoundingBoxGizmo._OldPivotPoint = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTranslation = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTmpVector = new BABYLON.Vector3();
         return BoundingBoxGizmo;
     }(BABYLON.Gizmo));
     BABYLON.BoundingBoxGizmo = BoundingBoxGizmo;
@@ -96200,6 +96210,17 @@ var BABYLON;
             camLeft.position.copyFrom(this._deviceRoomPosition);
             camRight.position.copyFrom(this._deviceRoomPosition);
         };
+        // Remove translation from 6dof headset if trackposition is set to false
+        WebVRFreeCamera.prototype._correctPositionIfNotTrackPosition = function (matrix, isViewMatrix) {
+            if (isViewMatrix === void 0) { isViewMatrix = false; }
+            if (this.rawPose && this.rawPose.position && !this.webVROptions.trackPosition) {
+                BABYLON.Matrix.TranslationToRef(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2], this._tmpMatrix);
+                if (!isViewMatrix) {
+                    this._tmpMatrix.invert();
+                }
+                this._tmpMatrix.multiplyToRef(matrix, matrix);
+            }
+        };
         /**
          * @hidden
          * Updates the cached values of the camera
@@ -96230,6 +96251,7 @@ var BABYLON;
                 // Update the gamepad to ensure the mesh is updated on the same frame as camera
                 this.controllers.forEach(function (controller) {
                     controller._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(controller._deviceToWorld);
                     controller.update();
                 });
             }
@@ -96294,12 +96316,9 @@ var BABYLON;
                 }
                 this._webvrViewMatrix.invert();
             }
-            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Remove translation from 6dof headset if trackposition is set to false
-            if (parentCamera.rawPose && parentCamera.rawPose.position && !parentCamera.webVROptions.trackPosition) {
-                BABYLON.Matrix.TranslationToRef(parentCamera.rawPose.position[0], parentCamera.rawPose.position[1], -parentCamera.rawPose.position[2], parentCamera._tmpMatrix);
-                parentCamera._tmpMatrix.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
-            }
+            parentCamera._correctPositionIfNotTrackPosition(this._webvrViewMatrix, true);
+            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Compute global position
             this._workingMatrix = this._workingMatrix || BABYLON.Matrix.Identity();
             this._webvrViewMatrix.invertToRef(this._workingMatrix);
@@ -96353,6 +96372,7 @@ var BABYLON;
                     var webVrController_1 = gamepad;
                     webVrController_1.deviceScaleFactor = _this.deviceScaleFactor;
                     webVrController_1._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(webVrController_1._deviceToWorld);
                     if (_this.webVROptions.controllerMeshes) {
                         if (webVrController_1.defaultModel) {
                             webVrController_1.defaultModel.setEnabled(true);

+ 64 - 44
dist/preview release/babylon.no-module.max.js

@@ -92161,11 +92161,13 @@ var BABYLON;
             });
             this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
                 if (_this._moving && _this.moveAttached) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(_this._attachedNode);
                     // Slowly move mesh to avoid jitter
-                    _this._targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._targetPosition.subtractToRef((_this._attachedNode).absolutePosition, _this._tmpVector);
                     _this._tmpVector.scaleInPlace(_this.dragDeltaRatio);
-                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
-                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                    (_this._attachedNode).getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    (_this._attachedNode).setAbsolutePosition(_this._tmpVector);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(_this._attachedNode);
                 }
             });
         };
@@ -92198,6 +92200,7 @@ var BABYLON;
             if (!this._scene.activeCamera || this.dragging || !this._attachedNode) {
                 return;
             }
+            BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(this._attachedNode);
             // Create start ray from the camera to the object
             if (fromRay) {
                 this._startDragRay.direction.copyFrom(fromRay.direction);
@@ -92215,7 +92218,7 @@ var BABYLON;
                 this.currentDraggingPointerID = 1;
                 this.lastDragPosition.copyFrom(pickedPoint);
                 this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID });
-                this._targetPosition.copyFrom(this._attachedNode.absolutePosition);
+                this._targetPosition.copyFrom((this._attachedNode).absolutePosition);
                 // Detatch camera controls
                 if (this.detachCameraControls && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
                     if (this._scene.activeCamera.inputs.attachedElement) {
@@ -92227,6 +92230,7 @@ var BABYLON;
                     }
                 }
             }
+            BABYLON.BoundingBoxGizmo._RestorePivotPoint(this._attachedNode);
         };
         PointerDragBehavior.prototype._moveDrag = function (ray) {
             this._moving = true;
@@ -92270,7 +92274,7 @@ var BABYLON;
                 if (this._useAlternatePickedPointAboveMaxDragAngle) {
                     // Invert ray direction along the towards object axis
                     this._tmpVector.copyFrom(ray.direction);
-                    this._attachedNode.absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
+                    (this._attachedNode).absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
                     this._alternatePickedPoint.normalize();
                     this._alternatePickedPoint.scaleInPlace(-2 * BABYLON.Vector3.Dot(this._alternatePickedPoint, this._tmpVector));
                     this._tmpVector.addInPlace(this._alternatePickedPoint);
@@ -92278,7 +92282,7 @@ var BABYLON;
                     var dot = BABYLON.Vector3.Dot(this._dragPlane.forward, this._tmpVector);
                     this._dragPlane.forward.scaleToRef(-dot, this._alternatePickedPoint);
                     this._alternatePickedPoint.addInPlace(this._tmpVector);
-                    this._alternatePickedPoint.addInPlace(this._attachedNode.absolutePosition);
+                    this._alternatePickedPoint.addInPlace((this._attachedNode).absolutePosition);
                     return this._alternatePickedPoint;
                 }
                 else {
@@ -92522,6 +92526,7 @@ var BABYLON;
                             pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
                         }
                         pickedMesh = _this._ownerNode;
+                        BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                         lastSixDofOriginPosition.copyFrom(pointerInfo.pickInfo.ray.origin);
                         // Set position and orientation of the controller
                         _this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
@@ -92551,6 +92556,7 @@ var BABYLON;
                                 attachedElement = null;
                             }
                         }
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                     }
                 }
                 else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
@@ -92603,6 +92609,7 @@ var BABYLON;
             // On every frame move towards target scaling to avoid jitter caused by vr controllers
             this._sceneRenderObserver = ownerNode.getScene().onBeforeRenderObservable.add(function () {
                 if (_this.dragging && _this._moving && pickedMesh) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                     // Get change in rotation
@@ -92619,6 +92626,7 @@ var BABYLON;
                     pickedMesh.setParent(null);
                     BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
                     pickedMesh.setParent(oldParent);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                 }
             });
         };
@@ -93892,11 +93900,6 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
-            // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
-            // store/remove pivot point should only be applied during their outermost calls
-            _this._pivotCached = 0;
-            _this._oldPivotPoint = new BABYLON.Vector3();
-            _this._pivotTranslation = new BABYLON.Vector3();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -93951,7 +93954,7 @@ var BABYLON;
                 _dragBehavior.onDragObservable.add(function (event) {
                     _this.onRotationSphereDragObservable.notifyObservers({});
                     if (_this.attachedMesh) {
-                        _this._removeAndStorePivotPoint();
+                        BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                         var worldDragDirection = startingTurnDirection;
                         // Project the world right on to the drag plane
                         var toSub = event.dragPlaneNormal.scale(BABYLON.Vector3.Dot(event.dragPlaneNormal, worldDragDirection));
@@ -93985,7 +93988,7 @@ var BABYLON;
                             _this._anchorMesh.removeChild(_this.attachedMesh);
                         }
                         _this.updateBoundingBox();
-                        _this._restorePivotPoint();
+                        BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
                 });
                 // Selection/deselection
@@ -94020,7 +94023,7 @@ var BABYLON;
                         _dragBehavior.onDragObservable.add(function (event) {
                             _this.onScaleBoxDragObservable.notifyObservers({});
                             if (_this.attachedMesh) {
-                                _this._removeAndStorePivotPoint();
+                                BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                                 var relativeDragDistance = (event.dragDistance / _this._boundingDimensions.length()) * _this._anchorMesh.scaling.length();
                                 var deltaScale = new BABYLON.Vector3(relativeDragDistance, relativeDragDistance, relativeDragDistance);
                                 deltaScale.scaleInPlace(_this._scaleDragSpeed);
@@ -94046,7 +94049,7 @@ var BABYLON;
                                     _this._anchorMesh.scaling.subtractInPlace(deltaScale);
                                 }
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
-                                _this._restorePivotPoint();
+                                BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
                         });
                         // Selection/deselection
@@ -94095,40 +94098,41 @@ var BABYLON;
             _this.updateBoundingBox();
             return _this;
         }
-        BoundingBoxGizmo.prototype._removeAndStorePivotPoint = function () {
-            if (this.attachedMesh && this._pivotCached === 0) {
+        /** @hidden */
+        BoundingBoxGizmo._RemoveAndStorePivotPoint = function (mesh) {
+            if (mesh && BoundingBoxGizmo._PivotCached === 0) {
                 // Save old pivot and set pivot to 0,0,0
-                this.attachedMesh.getPivotPointToRef(this._oldPivotPoint);
-                if (this._oldPivotPoint.equalsToFloats(0, 0, 0)) {
-                    return;
+                mesh.getPivotPointToRef(BoundingBoxGizmo._OldPivotPoint);
+                if (!BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0)) {
+                    mesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
+                    BoundingBoxGizmo._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), BoundingBoxGizmo._PivotTranslation);
+                    BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                    BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                    BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                    mesh.position.addInPlace(BoundingBoxGizmo._PivotTmpVector);
                 }
-                this.attachedMesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
-                this._oldPivotPoint.subtractToRef(this.attachedMesh.getPivotPoint(), this._pivotTranslation);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.addInPlace(this._tmpVector);
             }
-            this._pivotCached++;
+            BoundingBoxGizmo._PivotCached++;
         };
-        BoundingBoxGizmo.prototype._restorePivotPoint = function () {
-            if (this.attachedMesh && !this._oldPivotPoint.equalsToFloats(0, 0, 0) && this._pivotCached === 1) {
-                this.attachedMesh.setPivotPoint(this._oldPivotPoint);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.subtractInPlace(this._tmpVector);
+        /** @hidden */
+        BoundingBoxGizmo._RestorePivotPoint = function (mesh) {
+            if (mesh && !BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0) && BoundingBoxGizmo._PivotCached === 1) {
+                mesh.setPivotPoint(BoundingBoxGizmo._OldPivotPoint);
+                BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                mesh.position.subtractInPlace(BoundingBoxGizmo._PivotTmpVector);
             }
-            this._pivotCached--;
+            this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(value);
                 this._anchorMesh.addChild(value);
                 this._anchorMesh.removeChild(value);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
             }
         };
@@ -94152,7 +94156,7 @@ var BABYLON;
          */
         BoundingBoxGizmo.prototype.updateBoundingBox = function () {
             if (this.attachedMesh) {
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
                 this._update();
                 // Rotate based on axis
                 if (!this.attachedMesh.rotationQuaternion) {
@@ -94243,7 +94247,7 @@ var BABYLON;
             }
             if (this.attachedMesh) {
                 this._existingMeshScale.copyFrom(this.attachedMesh.scaling);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
             }
         };
         /**
@@ -94317,6 +94321,12 @@ var BABYLON;
         BoundingBoxGizmo.prototype.setCustomMesh = function (mesh) {
             BABYLON.Tools.Error("Custom meshes are not supported on this gizmo");
         };
+        // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
+        // store/remove pivot point should only be applied during their outermost calls
+        BoundingBoxGizmo._PivotCached = 0;
+        BoundingBoxGizmo._OldPivotPoint = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTranslation = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTmpVector = new BABYLON.Vector3();
         return BoundingBoxGizmo;
     }(BABYLON.Gizmo));
     BABYLON.BoundingBoxGizmo = BoundingBoxGizmo;
@@ -96167,6 +96177,17 @@ var BABYLON;
             camLeft.position.copyFrom(this._deviceRoomPosition);
             camRight.position.copyFrom(this._deviceRoomPosition);
         };
+        // Remove translation from 6dof headset if trackposition is set to false
+        WebVRFreeCamera.prototype._correctPositionIfNotTrackPosition = function (matrix, isViewMatrix) {
+            if (isViewMatrix === void 0) { isViewMatrix = false; }
+            if (this.rawPose && this.rawPose.position && !this.webVROptions.trackPosition) {
+                BABYLON.Matrix.TranslationToRef(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2], this._tmpMatrix);
+                if (!isViewMatrix) {
+                    this._tmpMatrix.invert();
+                }
+                this._tmpMatrix.multiplyToRef(matrix, matrix);
+            }
+        };
         /**
          * @hidden
          * Updates the cached values of the camera
@@ -96197,6 +96218,7 @@ var BABYLON;
                 // Update the gamepad to ensure the mesh is updated on the same frame as camera
                 this.controllers.forEach(function (controller) {
                     controller._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(controller._deviceToWorld);
                     controller.update();
                 });
             }
@@ -96261,12 +96283,9 @@ var BABYLON;
                 }
                 this._webvrViewMatrix.invert();
             }
-            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Remove translation from 6dof headset if trackposition is set to false
-            if (parentCamera.rawPose && parentCamera.rawPose.position && !parentCamera.webVROptions.trackPosition) {
-                BABYLON.Matrix.TranslationToRef(parentCamera.rawPose.position[0], parentCamera.rawPose.position[1], -parentCamera.rawPose.position[2], parentCamera._tmpMatrix);
-                parentCamera._tmpMatrix.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
-            }
+            parentCamera._correctPositionIfNotTrackPosition(this._webvrViewMatrix, true);
+            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Compute global position
             this._workingMatrix = this._workingMatrix || BABYLON.Matrix.Identity();
             this._webvrViewMatrix.invertToRef(this._workingMatrix);
@@ -96320,6 +96339,7 @@ var BABYLON;
                     var webVrController_1 = gamepad;
                     webVrController_1.deviceScaleFactor = _this.deviceScaleFactor;
                     webVrController_1._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(webVrController_1._deviceToWorld);
                     if (_this.webVROptions.controllerMeshes) {
                         if (webVrController_1.defaultModel) {
                             webVrController_1.defaultModel.setEnabled(true);

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


+ 64 - 44
dist/preview release/es6.js

@@ -92161,11 +92161,13 @@ var BABYLON;
             });
             this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
                 if (_this._moving && _this.moveAttached) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(_this._attachedNode);
                     // Slowly move mesh to avoid jitter
-                    _this._targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._targetPosition.subtractToRef((_this._attachedNode).absolutePosition, _this._tmpVector);
                     _this._tmpVector.scaleInPlace(_this.dragDeltaRatio);
-                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
-                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                    (_this._attachedNode).getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    (_this._attachedNode).setAbsolutePosition(_this._tmpVector);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(_this._attachedNode);
                 }
             });
         };
@@ -92198,6 +92200,7 @@ var BABYLON;
             if (!this._scene.activeCamera || this.dragging || !this._attachedNode) {
                 return;
             }
+            BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(this._attachedNode);
             // Create start ray from the camera to the object
             if (fromRay) {
                 this._startDragRay.direction.copyFrom(fromRay.direction);
@@ -92215,7 +92218,7 @@ var BABYLON;
                 this.currentDraggingPointerID = 1;
                 this.lastDragPosition.copyFrom(pickedPoint);
                 this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID });
-                this._targetPosition.copyFrom(this._attachedNode.absolutePosition);
+                this._targetPosition.copyFrom((this._attachedNode).absolutePosition);
                 // Detatch camera controls
                 if (this.detachCameraControls && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
                     if (this._scene.activeCamera.inputs.attachedElement) {
@@ -92227,6 +92230,7 @@ var BABYLON;
                     }
                 }
             }
+            BABYLON.BoundingBoxGizmo._RestorePivotPoint(this._attachedNode);
         };
         PointerDragBehavior.prototype._moveDrag = function (ray) {
             this._moving = true;
@@ -92270,7 +92274,7 @@ var BABYLON;
                 if (this._useAlternatePickedPointAboveMaxDragAngle) {
                     // Invert ray direction along the towards object axis
                     this._tmpVector.copyFrom(ray.direction);
-                    this._attachedNode.absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
+                    (this._attachedNode).absolutePosition.subtractToRef(ray.origin, this._alternatePickedPoint);
                     this._alternatePickedPoint.normalize();
                     this._alternatePickedPoint.scaleInPlace(-2 * BABYLON.Vector3.Dot(this._alternatePickedPoint, this._tmpVector));
                     this._tmpVector.addInPlace(this._alternatePickedPoint);
@@ -92278,7 +92282,7 @@ var BABYLON;
                     var dot = BABYLON.Vector3.Dot(this._dragPlane.forward, this._tmpVector);
                     this._dragPlane.forward.scaleToRef(-dot, this._alternatePickedPoint);
                     this._alternatePickedPoint.addInPlace(this._tmpVector);
-                    this._alternatePickedPoint.addInPlace(this._attachedNode.absolutePosition);
+                    this._alternatePickedPoint.addInPlace((this._attachedNode).absolutePosition);
                     return this._alternatePickedPoint;
                 }
                 else {
@@ -92522,6 +92526,7 @@ var BABYLON;
                             pointerInfo.pickInfo.ray.origin.copyFrom(_this._scene.activeCamera.position);
                         }
                         pickedMesh = _this._ownerNode;
+                        BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                         lastSixDofOriginPosition.copyFrom(pointerInfo.pickInfo.ray.origin);
                         // Set position and orientation of the controller
                         _this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
@@ -92551,6 +92556,7 @@ var BABYLON;
                                 attachedElement = null;
                             }
                         }
+                        BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                     }
                 }
                 else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
@@ -92603,6 +92609,7 @@ var BABYLON;
             // On every frame move towards target scaling to avoid jitter caused by vr controllers
             this._sceneRenderObserver = ownerNode.getScene().onBeforeRenderObservable.add(function () {
                 if (_this.dragging && _this._moving && pickedMesh) {
+                    BABYLON.BoundingBoxGizmo._RemoveAndStorePivotPoint(pickedMesh);
                     // Slowly move mesh to avoid jitter
                     pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                     // Get change in rotation
@@ -92619,6 +92626,7 @@ var BABYLON;
                     pickedMesh.setParent(null);
                     BABYLON.Quaternion.SlerpToRef(pickedMesh.rotationQuaternion, tmpQuaternion, _this.dragDeltaRatio, pickedMesh.rotationQuaternion);
                     pickedMesh.setParent(oldParent);
+                    BABYLON.BoundingBoxGizmo._RestorePivotPoint(pickedMesh);
                 }
             });
         };
@@ -93892,11 +93900,6 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
-            // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
-            // store/remove pivot point should only be applied during their outermost calls
-            _this._pivotCached = 0;
-            _this._oldPivotPoint = new BABYLON.Vector3();
-            _this._pivotTranslation = new BABYLON.Vector3();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -93951,7 +93954,7 @@ var BABYLON;
                 _dragBehavior.onDragObservable.add(function (event) {
                     _this.onRotationSphereDragObservable.notifyObservers({});
                     if (_this.attachedMesh) {
-                        _this._removeAndStorePivotPoint();
+                        BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                         var worldDragDirection = startingTurnDirection;
                         // Project the world right on to the drag plane
                         var toSub = event.dragPlaneNormal.scale(BABYLON.Vector3.Dot(event.dragPlaneNormal, worldDragDirection));
@@ -93985,7 +93988,7 @@ var BABYLON;
                             _this._anchorMesh.removeChild(_this.attachedMesh);
                         }
                         _this.updateBoundingBox();
-                        _this._restorePivotPoint();
+                        BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
                 });
                 // Selection/deselection
@@ -94020,7 +94023,7 @@ var BABYLON;
                         _dragBehavior.onDragObservable.add(function (event) {
                             _this.onScaleBoxDragObservable.notifyObservers({});
                             if (_this.attachedMesh) {
-                                _this._removeAndStorePivotPoint();
+                                BoundingBoxGizmo._RemoveAndStorePivotPoint(_this.attachedMesh);
                                 var relativeDragDistance = (event.dragDistance / _this._boundingDimensions.length()) * _this._anchorMesh.scaling.length();
                                 var deltaScale = new BABYLON.Vector3(relativeDragDistance, relativeDragDistance, relativeDragDistance);
                                 deltaScale.scaleInPlace(_this._scaleDragSpeed);
@@ -94046,7 +94049,7 @@ var BABYLON;
                                     _this._anchorMesh.scaling.subtractInPlace(deltaScale);
                                 }
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
-                                _this._restorePivotPoint();
+                                BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
                         });
                         // Selection/deselection
@@ -94095,40 +94098,41 @@ var BABYLON;
             _this.updateBoundingBox();
             return _this;
         }
-        BoundingBoxGizmo.prototype._removeAndStorePivotPoint = function () {
-            if (this.attachedMesh && this._pivotCached === 0) {
+        /** @hidden */
+        BoundingBoxGizmo._RemoveAndStorePivotPoint = function (mesh) {
+            if (mesh && BoundingBoxGizmo._PivotCached === 0) {
                 // Save old pivot and set pivot to 0,0,0
-                this.attachedMesh.getPivotPointToRef(this._oldPivotPoint);
-                if (this._oldPivotPoint.equalsToFloats(0, 0, 0)) {
-                    return;
+                mesh.getPivotPointToRef(BoundingBoxGizmo._OldPivotPoint);
+                if (!BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0)) {
+                    mesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
+                    BoundingBoxGizmo._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), BoundingBoxGizmo._PivotTranslation);
+                    BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                    BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                    BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                    mesh.position.addInPlace(BoundingBoxGizmo._PivotTmpVector);
                 }
-                this.attachedMesh.setPivotMatrix(BABYLON.Matrix.IdentityReadOnly);
-                this._oldPivotPoint.subtractToRef(this.attachedMesh.getPivotPoint(), this._pivotTranslation);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.addInPlace(this._tmpVector);
             }
-            this._pivotCached++;
+            BoundingBoxGizmo._PivotCached++;
         };
-        BoundingBoxGizmo.prototype._restorePivotPoint = function () {
-            if (this.attachedMesh && !this._oldPivotPoint.equalsToFloats(0, 0, 0) && this._pivotCached === 1) {
-                this.attachedMesh.setPivotPoint(this._oldPivotPoint);
-                this._tmpVector.copyFromFloats(1, 1, 1);
-                this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
-                this._tmpVector.multiplyInPlace(this._pivotTranslation);
-                this.attachedMesh.position.subtractInPlace(this._tmpVector);
+        /** @hidden */
+        BoundingBoxGizmo._RestorePivotPoint = function (mesh) {
+            if (mesh && !BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0, 0, 0) && BoundingBoxGizmo._PivotCached === 1) {
+                mesh.setPivotPoint(BoundingBoxGizmo._OldPivotPoint);
+                BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1, 1, 1);
+                BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
+                BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
+                mesh.position.subtractInPlace(BoundingBoxGizmo._PivotTmpVector);
             }
-            this._pivotCached--;
+            this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(value);
                 this._anchorMesh.addChild(value);
                 this._anchorMesh.removeChild(value);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
             }
         };
@@ -94152,7 +94156,7 @@ var BABYLON;
          */
         BoundingBoxGizmo.prototype.updateBoundingBox = function () {
             if (this.attachedMesh) {
-                this._removeAndStorePivotPoint();
+                BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
                 this._update();
                 // Rotate based on axis
                 if (!this.attachedMesh.rotationQuaternion) {
@@ -94243,7 +94247,7 @@ var BABYLON;
             }
             if (this.attachedMesh) {
                 this._existingMeshScale.copyFrom(this.attachedMesh.scaling);
-                this._restorePivotPoint();
+                BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
             }
         };
         /**
@@ -94317,6 +94321,12 @@ var BABYLON;
         BoundingBoxGizmo.prototype.setCustomMesh = function (mesh) {
             BABYLON.Tools.Error("Custom meshes are not supported on this gizmo");
         };
+        // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
+        // store/remove pivot point should only be applied during their outermost calls
+        BoundingBoxGizmo._PivotCached = 0;
+        BoundingBoxGizmo._OldPivotPoint = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTranslation = new BABYLON.Vector3();
+        BoundingBoxGizmo._PivotTmpVector = new BABYLON.Vector3();
         return BoundingBoxGizmo;
     }(BABYLON.Gizmo));
     BABYLON.BoundingBoxGizmo = BoundingBoxGizmo;
@@ -96167,6 +96177,17 @@ var BABYLON;
             camLeft.position.copyFrom(this._deviceRoomPosition);
             camRight.position.copyFrom(this._deviceRoomPosition);
         };
+        // Remove translation from 6dof headset if trackposition is set to false
+        WebVRFreeCamera.prototype._correctPositionIfNotTrackPosition = function (matrix, isViewMatrix) {
+            if (isViewMatrix === void 0) { isViewMatrix = false; }
+            if (this.rawPose && this.rawPose.position && !this.webVROptions.trackPosition) {
+                BABYLON.Matrix.TranslationToRef(this.rawPose.position[0], this.rawPose.position[1], -this.rawPose.position[2], this._tmpMatrix);
+                if (!isViewMatrix) {
+                    this._tmpMatrix.invert();
+                }
+                this._tmpMatrix.multiplyToRef(matrix, matrix);
+            }
+        };
         /**
          * @hidden
          * Updates the cached values of the camera
@@ -96197,6 +96218,7 @@ var BABYLON;
                 // Update the gamepad to ensure the mesh is updated on the same frame as camera
                 this.controllers.forEach(function (controller) {
                     controller._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(controller._deviceToWorld);
                     controller.update();
                 });
             }
@@ -96261,12 +96283,9 @@ var BABYLON;
                 }
                 this._webvrViewMatrix.invert();
             }
-            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Remove translation from 6dof headset if trackposition is set to false
-            if (parentCamera.rawPose && parentCamera.rawPose.position && !parentCamera.webVROptions.trackPosition) {
-                BABYLON.Matrix.TranslationToRef(parentCamera.rawPose.position[0], parentCamera.rawPose.position[1], -parentCamera.rawPose.position[2], parentCamera._tmpMatrix);
-                parentCamera._tmpMatrix.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
-            }
+            parentCamera._correctPositionIfNotTrackPosition(this._webvrViewMatrix, true);
+            parentCamera._worldToDevice.multiplyToRef(this._webvrViewMatrix, this._webvrViewMatrix);
             // Compute global position
             this._workingMatrix = this._workingMatrix || BABYLON.Matrix.Identity();
             this._webvrViewMatrix.invertToRef(this._workingMatrix);
@@ -96320,6 +96339,7 @@ var BABYLON;
                     var webVrController_1 = gamepad;
                     webVrController_1.deviceScaleFactor = _this.deviceScaleFactor;
                     webVrController_1._deviceToWorld.copyFrom(_this._deviceToWorld);
+                    _this._correctPositionIfNotTrackPosition(webVrController_1._deviceToWorld);
                     if (_this.webVROptions.controllerMeshes) {
                         if (webVrController_1.defaultModel) {
                             webVrController_1.defaultModel.setEnabled(true);

+ 2 - 159
dist/preview release/viewer/babylon.viewer.d.ts

@@ -515,167 +515,10 @@ declare module BabylonViewer {
     }
 }
 declare module BabylonViewer {
-    /**
-        * The current state of the model
-        */
-    export enum ModelState {
-            INIT = 0,
-            LOADING = 1,
-            LOADED = 2,
-            ENTRY = 3,
-            ENTRYDONE = 4,
-            COMPLETE = 5,
-            CANCELED = 6,
-            ERROR = 7
-    }
-    /**
-        * The viewer model is a container for all assets representing a sngle loaded model.
-        */
-    export class ViewerModel implements BABYLON.IDisposable {
-            /**
-                * The loader used to load this model.
-                */
-            loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync;
-            /**
-                * This model's root mesh (the parent of all other meshes).
-                * This mesh does not(!) exist in the meshes array.
-                */
-            rootMesh: BABYLON.AbstractMesh;
-            /**
-                * ParticleSystems connected to this model
-                */
-            particleSystems: Array<BABYLON.IParticleSystem>;
-            /**
-                * Skeletons defined in this model
-                */
-            skeletons: Array<BABYLON.Skeleton>;
-            /**
-                * The current model animation.
-                * On init, this will be undefined.
-                */
-            currentAnimation: IModelAnimation;
-            /**
-                * Observers registered here will be executed when the model is done loading
-                */
-            onLoadedObservable: BABYLON.Observable<ViewerModel>;
-            /**
-                * Observers registered here will be executed when the loader notified of a progress event
-                */
-            onLoadProgressObservable: BABYLON.Observable<BABYLON.SceneLoaderProgressEvent>;
-            /**
-                * Observers registered here will be executed when the loader notified of an error.
-                */
-            onLoadErrorObservable: BABYLON.Observable<{
-                    message: string;
-                    exception: any;
-            }>;
-            /**
-                * Will be executed after the model finished loading and complete, including entry animation and lod
-                */
-            onCompleteObservable: BABYLON.Observable<ViewerModel>;
-            /**
-                * Observers registered here will be executed every time the model is being configured.
-                * This can be used to extend the model's configuration without extending the class itself
-                */
-            onAfterConfigure: BABYLON.Observable<ViewerModel>;
-            /**
-                * The current model state (loaded, error, etc)
-                */
-            state: ModelState;
-            /**
-                * A loadID provided by the modelLoader, unique to ths (Abstract)Viewer instance.
-                */
-            loadId: number;
-            loadInfo: BABYLON.GLTF2.IAsset;
-            constructor(_observablesManager: ObservablesManager, modelConfiguration: IModelConfiguration, _configurationContainer?: ConfigurationContainer | undefined);
-            shadowsRenderedAfterLoad: boolean;
-            getViewerId(): string | undefined;
-            /**
-             * Set whether this model is enabled or not.
-             */
-            enabled: boolean;
-            loaderDone: boolean;
-            /**
-                * Add a mesh to this model.
-                * Any mesh that has no parent will be provided with the root mesh as its new parent.
-                *
-                * @param mesh the new mesh to add
-                * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
-                */
-            addMesh(mesh: BABYLON.AbstractMesh, triggerLoaded?: boolean): Promise<ViewerModel> | undefined;
-            /**
-                * get the list of meshes (excluding the root mesh)
-                */
-            readonly meshes: BABYLON.AbstractMesh[];
-            /**
-             * (Re-)set the model's entire configuration
-             * @param newConfiguration the new configuration to replace the new one
-             */
-            configuration: IModelConfiguration;
-            /**
-                * Update the current configuration with new values.
-                * Configuration will not be overwritten, but merged with the new configuration.
-                * Priority is to the new configuration
-                * @param newConfiguration the configuration to be merged into the current configuration;
-                */
-            updateConfiguration(newConfiguration: Partial<IModelConfiguration>): void;
-            /**
-                * Add a new animation group to this model.
-                * @param animationGroup the new animation group to be added
-                */
-            addAnimationGroup(animationGroup: BABYLON.AnimationGroup): void;
-            /**
-                * Get the ModelAnimation array
-                */
-            getAnimations(): Array<IModelAnimation>;
-            /**
-                * Get the animations' names. Using the names you can play a specific animation.
-                */
-            getAnimationNames(): Array<string>;
-            /**
-                * Get an animation by the provided name. Used mainly when playing n animation.
-                * @param name the name of the animation to find
-                */
-            protected _getAnimationByName(name: string): BABYLON.Nullable<IModelAnimation>;
-            /**
-                * Choose an initialized animation using its name and start playing it
-                * @param name the name of the animation to play
-                * @returns The model aniamtion to be played.
-                */
-            playAnimation(name: string): IModelAnimation;
-            setCurrentAnimationByName(name: string): IModelAnimation;
-            /**
-                * Apply a material configuration to a material
-                * @param material BABYLON.Material to apply configuration to
-                * @hidden
-                */
-            _applyModelMaterialConfiguration(material: BABYLON.Material): void;
-            /**
-             * Begin @animations with the specified @easingFunction
-             * @param animations The BABYLON Animations to begin
-             * @param duration of transition, in seconds
-             * @param easingFunction An easing function to apply
-             * @param easingMode A easing mode to apply to the easingFunction
-             * @param onAnimationEnd Call back trigger at the end of the animation.
-             */
-            transitionTo(animations: BABYLON.Animation[], duration: number, easingFunction: any, easingMode: number | undefined, onAnimationEnd: () => void): void;
-            /**
-                * Stops and removes all animations that have been applied to the model
-                */
-            stopAllAnimations(): void;
-            /**
-                * Will remove this model from the viewer (but NOT dispose it).
-                */
-            remove(): void;
-            /**
-                * Dispose this model, including all of its associated assets.
-                */
-            dispose(): void;
-    }
 }
 declare module BabylonViewer {
     /**
-        * BABYLON.Animation play mode enum - is the animation looping or playing once
+        * Animation play mode enum - is the animation looping or playing once
         */
     export const enum AnimationPlayMode {
             ONCE = 0,
@@ -757,7 +600,7 @@ declare module BabylonViewer {
                 */
             readonly currentFrame: number;
             /**
-                * BABYLON.Animation's FPS value
+                * Animation's FPS value
                 */
             readonly fps: number;
             /**

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


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


+ 1 - 163
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -566,169 +566,7 @@ declare module 'babylonjs-viewer/loader/modelLoader' {
 }
 
 declare module 'babylonjs-viewer/model/viewerModel' {
-    import { ISceneLoaderPlugin, ISceneLoaderPluginAsync, AnimationGroup, AbstractMesh, Observable, SceneLoaderProgressEvent, IParticleSystem, Skeleton, IDisposable, Nullable, Animation, Material } from "babylonjs";
-    import { GLTF2 } from "babylonjs-loaders";
-    import { IModelConfiguration } from "babylonjs-viewer/configuration/interfaces/modelConfiguration";
-    import { IModelAnimation } from "babylonjs-viewer/model/modelAnimation";
-    import { ObservablesManager } from "babylonjs-viewer/managers/observablesManager";
-    import { ConfigurationContainer } from "babylonjs-viewer/configuration/configurationContainer";
-    /**
-        * The current state of the model
-        */
-    export enum ModelState {
-            INIT = 0,
-            LOADING = 1,
-            LOADED = 2,
-            ENTRY = 3,
-            ENTRYDONE = 4,
-            COMPLETE = 5,
-            CANCELED = 6,
-            ERROR = 7
-    }
-    /**
-        * The viewer model is a container for all assets representing a sngle loaded model.
-        */
-    export class ViewerModel implements IDisposable {
-            /**
-                * The loader used to load this model.
-                */
-            loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
-            /**
-                * This model's root mesh (the parent of all other meshes).
-                * This mesh does not(!) exist in the meshes array.
-                */
-            rootMesh: AbstractMesh;
-            /**
-                * ParticleSystems connected to this model
-                */
-            particleSystems: Array<IParticleSystem>;
-            /**
-                * Skeletons defined in this model
-                */
-            skeletons: Array<Skeleton>;
-            /**
-                * The current model animation.
-                * On init, this will be undefined.
-                */
-            currentAnimation: IModelAnimation;
-            /**
-                * Observers registered here will be executed when the model is done loading
-                */
-            onLoadedObservable: Observable<ViewerModel>;
-            /**
-                * Observers registered here will be executed when the loader notified of a progress event
-                */
-            onLoadProgressObservable: Observable<SceneLoaderProgressEvent>;
-            /**
-                * Observers registered here will be executed when the loader notified of an error.
-                */
-            onLoadErrorObservable: Observable<{
-                    message: string;
-                    exception: any;
-            }>;
-            /**
-                * Will be executed after the model finished loading and complete, including entry animation and lod
-                */
-            onCompleteObservable: Observable<ViewerModel>;
-            /**
-                * Observers registered here will be executed every time the model is being configured.
-                * This can be used to extend the model's configuration without extending the class itself
-                */
-            onAfterConfigure: Observable<ViewerModel>;
-            /**
-                * The current model state (loaded, error, etc)
-                */
-            state: ModelState;
-            /**
-                * A loadID provided by the modelLoader, unique to ths (Abstract)Viewer instance.
-                */
-            loadId: number;
-            loadInfo: GLTF2.IAsset;
-            constructor(_observablesManager: ObservablesManager, modelConfiguration: IModelConfiguration, _configurationContainer?: ConfigurationContainer | undefined);
-            shadowsRenderedAfterLoad: boolean;
-            getViewerId(): string | undefined;
-            /**
-             * Set whether this model is enabled or not.
-             */
-            enabled: boolean;
-            loaderDone: boolean;
-            /**
-                * Add a mesh to this model.
-                * Any mesh that has no parent will be provided with the root mesh as its new parent.
-                *
-                * @param mesh the new mesh to add
-                * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
-                */
-            addMesh(mesh: AbstractMesh, triggerLoaded?: boolean): Promise<ViewerModel> | undefined;
-            /**
-                * get the list of meshes (excluding the root mesh)
-                */
-            readonly meshes: AbstractMesh[];
-            /**
-             * (Re-)set the model's entire configuration
-             * @param newConfiguration the new configuration to replace the new one
-             */
-            configuration: IModelConfiguration;
-            /**
-                * Update the current configuration with new values.
-                * Configuration will not be overwritten, but merged with the new configuration.
-                * Priority is to the new configuration
-                * @param newConfiguration the configuration to be merged into the current configuration;
-                */
-            updateConfiguration(newConfiguration: Partial<IModelConfiguration>): void;
-            /**
-                * Add a new animation group to this model.
-                * @param animationGroup the new animation group to be added
-                */
-            addAnimationGroup(animationGroup: AnimationGroup): void;
-            /**
-                * Get the ModelAnimation array
-                */
-            getAnimations(): Array<IModelAnimation>;
-            /**
-                * Get the animations' names. Using the names you can play a specific animation.
-                */
-            getAnimationNames(): Array<string>;
-            /**
-                * Get an animation by the provided name. Used mainly when playing n animation.
-                * @param name the name of the animation to find
-                */
-            protected _getAnimationByName(name: string): Nullable<IModelAnimation>;
-            /**
-                * Choose an initialized animation using its name and start playing it
-                * @param name the name of the animation to play
-                * @returns The model aniamtion to be played.
-                */
-            playAnimation(name: string): IModelAnimation;
-            setCurrentAnimationByName(name: string): IModelAnimation;
-            /**
-                * Apply a material configuration to a material
-                * @param material Material to apply configuration to
-                * @hidden
-                */
-            _applyModelMaterialConfiguration(material: Material): void;
-            /**
-             * Begin @animations with the specified @easingFunction
-             * @param animations The BABYLON Animations to begin
-             * @param duration of transition, in seconds
-             * @param easingFunction An easing function to apply
-             * @param easingMode A easing mode to apply to the easingFunction
-             * @param onAnimationEnd Call back trigger at the end of the animation.
-             */
-            transitionTo(animations: Animation[], duration: number, easingFunction: any, easingMode: number | undefined, onAnimationEnd: () => void): void;
-            /**
-                * Stops and removes all animations that have been applied to the model
-                */
-            stopAllAnimations(): void;
-            /**
-                * Will remove this model from the viewer (but NOT dispose it).
-                */
-            remove(): void;
-            /**
-                * Dispose this model, including all of its associated assets.
-                */
-            dispose(): void;
-    }
+    
 }
 
 declare module 'babylonjs-viewer/model/modelAnimation' {