|
@@ -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);
|