|
@@ -12092,7 +12092,7 @@ var BABYLON;
|
|
|
* Returns the current version of the framework
|
|
|
*/
|
|
|
get: function () {
|
|
|
- return "3.3.0-alpha.6";
|
|
|
+ return "3.3.0-alpha.7";
|
|
|
},
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
@@ -39230,7 +39230,7 @@ var BABYLON;
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
- * Affects all gemetry data in one call
|
|
|
+ * Affects all geometry data in one call
|
|
|
* @param vertexData defines the geometry data
|
|
|
* @param updatable defines if the geometry must be flagged as updatable (false as default)
|
|
|
*/
|
|
@@ -71113,6 +71113,17 @@ var BABYLON;
|
|
|
if (!this._mesh.rotationQuaternion) {
|
|
|
this._mesh.rotationQuaternion = new BABYLON.Quaternion();
|
|
|
}
|
|
|
+ // Sync controller mesh and pointing pose node's state with controller
|
|
|
+ this.update();
|
|
|
+ if (this._pointingPoseNode) {
|
|
|
+ var parents = [];
|
|
|
+ var obj = this._pointingPoseNode;
|
|
|
+ while (obj.parent) {
|
|
|
+ parents.push(obj.parent);
|
|
|
+ obj = obj.parent;
|
|
|
+ }
|
|
|
+ parents.reverse().forEach(function (p) { p.computeWorldMatrix(true); });
|
|
|
+ }
|
|
|
this._meshAttachedObservable.notifyObservers(mesh);
|
|
|
};
|
|
|
/**
|
|
@@ -72062,6 +72073,9 @@ var BABYLON;
|
|
|
if (!loadedMeshInfo.pointingPoseNode) {
|
|
|
BABYLON.Tools.Warn('Missing pointing pose mesh with name: ' + this._mapping.pointingPoseMeshName);
|
|
|
}
|
|
|
+ else {
|
|
|
+ this._pointingPoseNode = loadedMeshInfo.pointingPoseNode;
|
|
|
+ }
|
|
|
return loadedMeshInfo;
|
|
|
// Look through all children recursively. This will return null if no mesh exists with the given name.
|
|
|
function getChildByName(node, name) {
|
|
@@ -87951,7 +87965,14 @@ var BABYLON;
|
|
|
*/
|
|
|
function PointerDragBehavior(options) {
|
|
|
this.options = options;
|
|
|
- this._draggingID = -1;
|
|
|
+ /**
|
|
|
+ * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
|
|
|
+ */
|
|
|
+ this.currentDraggingPointerID = -1;
|
|
|
+ /**
|
|
|
+ * If the behavior is currently in a dragging state
|
|
|
+ */
|
|
|
+ this.dragging = false;
|
|
|
// Debug mode will display drag planes to help visualize behavior
|
|
|
this._debugMode = false;
|
|
|
this._maxDragAngle = Math.PI / 5;
|
|
@@ -87980,9 +88001,23 @@ var BABYLON;
|
|
|
*/
|
|
|
this._dragPlaneParent = null;
|
|
|
/**
|
|
|
- * If the drag behavior will react to drag events
|
|
|
+ * If the drag behavior will react to drag events (Default: true)
|
|
|
*/
|
|
|
this.enabled = true;
|
|
|
+ /**
|
|
|
+ * If set, the drag plane/axis will be rotated based on the attached mesh's world rotation (Default: true)
|
|
|
+ */
|
|
|
+ this.useObjectOrienationForDragging = true;
|
|
|
+ this._tmpVector = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._worldDragAxis = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ // Variables to avoid instantiation in the below method
|
|
|
+ this._pointA = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._pointB = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._pointC = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._lineA = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._lineB = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._localAxis = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._lookAt = new BABYLON.Vector3(0, 0, 0);
|
|
|
var optionCount = 0;
|
|
|
if (options === undefined) {
|
|
|
options = {};
|
|
@@ -88031,8 +88066,7 @@ var BABYLON;
|
|
|
}
|
|
|
this._dragPlane = BABYLON.Mesh.CreatePlane("pointerDragPlane", this._debugMode ? 1 : 10000, PointerDragBehavior._planeScene, false, BABYLON.Mesh.DOUBLESIDE);
|
|
|
// State of the drag
|
|
|
- var dragging = false;
|
|
|
- var lastPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this.lastDragPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
var delta = new BABYLON.Vector3(0, 0, 0);
|
|
|
var dragLength = 0;
|
|
|
var pickPredicate = function (m) {
|
|
@@ -88043,26 +88077,24 @@ var BABYLON;
|
|
|
return;
|
|
|
}
|
|
|
if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
|
- if (!dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
|
|
|
+ if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
|
|
|
_this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
|
|
|
var pickedPoint = _this._pickWithRayOnDragPlane(pointerInfo.pickInfo.ray);
|
|
|
if (pickedPoint) {
|
|
|
- dragging = true;
|
|
|
- _this._draggingID = pointerInfo.event.pointerId;
|
|
|
- lastPosition.copyFrom(pickedPoint);
|
|
|
- _this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint });
|
|
|
+ _this.dragging = true;
|
|
|
+ _this.currentDraggingPointerID = pointerInfo.event.pointerId;
|
|
|
+ _this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
+ _this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: _this.currentDraggingPointerID });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
|
|
|
- if (_this._draggingID == pointerInfo.event.pointerId) {
|
|
|
- dragging = false;
|
|
|
- _this._draggingID = -1;
|
|
|
- _this.onDragEndObservable.notifyObservers({ dragPlanePoint: lastPosition });
|
|
|
+ if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
|
|
|
+ _this.releaseDrag();
|
|
|
}
|
|
|
}
|
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
|
- if (_this._draggingID == pointerInfo.event.pointerId && dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {
|
|
|
+ if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {
|
|
|
var pickedPoint = _this._pickWithRayOnDragPlane(pointerInfo.pickInfo.ray);
|
|
|
// Get angle between drag plane and ray. Only update the drag plane at non steep angles to avoid jumps in delta position
|
|
|
var angle = Math.acos(BABYLON.Vector3.Dot(_this._dragPlane.forward, pointerInfo.pickInfo.ray.direction));
|
|
@@ -88073,25 +88105,32 @@ var BABYLON;
|
|
|
// depending on the drag mode option drag accordingly
|
|
|
if (_this.options.dragAxis) {
|
|
|
// Convert local drag axis to world
|
|
|
- var worldDragAxis = BABYLON.Vector3.TransformCoordinates(_this.options.dragAxis, _this._attachedNode.getWorldMatrix().getRotationMatrix());
|
|
|
+ BABYLON.Vector3.TransformCoordinatesToRef(_this.options.dragAxis, _this._attachedNode.getWorldMatrix().getRotationMatrix(), _this._worldDragAxis);
|
|
|
// Project delta drag from the drag plane onto the drag axis
|
|
|
- dragLength = BABYLON.Vector3.Dot(pickedPoint.subtract(lastPosition), worldDragAxis);
|
|
|
- worldDragAxis.scaleToRef(dragLength, delta);
|
|
|
+ pickedPoint.subtractToRef(_this.lastDragPosition, _this._tmpVector);
|
|
|
+ dragLength = BABYLON.Vector3.Dot(_this._tmpVector, _this._worldDragAxis);
|
|
|
+ _this._worldDragAxis.scaleToRef(dragLength, delta);
|
|
|
}
|
|
|
else {
|
|
|
dragLength = delta.length();
|
|
|
- pickedPoint.subtractToRef(lastPosition, delta);
|
|
|
+ pickedPoint.subtractToRef(_this.lastDragPosition, delta);
|
|
|
}
|
|
|
if (_this.moveAttached) {
|
|
|
- _this._attachedNode.position.addInPlace(delta);
|
|
|
+ _this._attachedNode.absolutePosition.addToRef(delta, _this._tmpVector);
|
|
|
+ _this._attachedNode.setAbsolutePosition(_this._tmpVector);
|
|
|
}
|
|
|
- _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward });
|
|
|
- lastPosition.copyFrom(pickedPoint);
|
|
|
+ _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward, pointerId: _this.currentDraggingPointerID });
|
|
|
+ _this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
+ PointerDragBehavior.prototype.releaseDrag = function () {
|
|
|
+ this.dragging = false;
|
|
|
+ this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
|
|
|
+ this.currentDraggingPointerID = -1;
|
|
|
+ };
|
|
|
PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
|
|
|
var _this = this;
|
|
|
if (!ray) {
|
|
@@ -88107,27 +88146,32 @@ var BABYLON;
|
|
|
};
|
|
|
// Position the drag plane based on the attached mesh position, for single axis rotate the plane along the axis to face the camera
|
|
|
PointerDragBehavior.prototype._updateDragPlanePosition = function (ray) {
|
|
|
- var pointA = this._dragPlaneParent ? this._dragPlaneParent.absolutePosition : this._attachedNode.absolutePosition;
|
|
|
+ this._pointA.copyFrom(this._dragPlaneParent ? this._dragPlaneParent.absolutePosition : this._attachedNode.absolutePosition);
|
|
|
if (this.options.dragAxis) {
|
|
|
- var localAxis = BABYLON.Vector3.TransformCoordinates(this.options.dragAxis, this._attachedNode.getWorldMatrix().getRotationMatrix());
|
|
|
+ this.useObjectOrienationForDragging ? BABYLON.Vector3.TransformCoordinatesToRef(this.options.dragAxis, this._attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis) : this._localAxis.copyFrom(this.options.dragAxis);
|
|
|
// Calculate plane normal in direction of camera but perpendicular to drag axis
|
|
|
- var pointB = pointA.add(localAxis); // towards drag axis
|
|
|
- var pointC = pointA.add(ray.origin.subtract(pointA).normalize()); // towards camera
|
|
|
+ this._pointA.addToRef(this._localAxis, this._pointB); // towards drag axis
|
|
|
+ ray.origin.subtractToRef(this._pointA, this._pointC);
|
|
|
+ this._pointA.addToRef(this._pointC.normalize(), this._pointC); // towards camera
|
|
|
// Get perpendicular line from direction to camera and drag axis
|
|
|
- var lineA = pointB.subtract(pointA);
|
|
|
- var lineB = pointC.subtract(pointA);
|
|
|
- var perpLine = BABYLON.Vector3.Cross(lineA, lineB);
|
|
|
+ this._pointB.subtractToRef(this._pointA, this._lineA);
|
|
|
+ this._pointC.subtractToRef(this._pointA, this._lineB);
|
|
|
+ BABYLON.Vector3.CrossToRef(this._lineA, this._lineB, this._lookAt);
|
|
|
// Get perpendicular line from previous result and drag axis to adjust lineB to be perpendiculat to camera
|
|
|
- var norm = BABYLON.Vector3.Cross(lineA, perpLine).normalize();
|
|
|
- this._dragPlane.position.copyFrom(pointA);
|
|
|
- this._dragPlane.lookAt(pointA.subtract(norm));
|
|
|
+ BABYLON.Vector3.CrossToRef(this._lineA, this._lookAt, this._lookAt);
|
|
|
+ this._lookAt.normalize();
|
|
|
+ this._dragPlane.position.copyFrom(this._pointA);
|
|
|
+ this._pointA.subtractToRef(this._lookAt, this._lookAt);
|
|
|
+ this._dragPlane.lookAt(this._lookAt);
|
|
|
}
|
|
|
else if (this.options.dragPlaneNormal) {
|
|
|
- this._dragPlane.position.copyFrom(pointA);
|
|
|
- this._dragPlane.lookAt(pointA.subtract(this.options.dragPlaneNormal));
|
|
|
+ this.useObjectOrienationForDragging ? BABYLON.Vector3.TransformCoordinatesToRef(this.options.dragPlaneNormal, this._attachedNode.getWorldMatrix().getRotationMatrix(), this._localAxis) : this._localAxis.copyFrom(this.options.dragPlaneNormal);
|
|
|
+ this._dragPlane.position.copyFrom(this._pointA);
|
|
|
+ this._pointA.subtractToRef(this._localAxis, this._lookAt);
|
|
|
+ this._dragPlane.lookAt(this._lookAt);
|
|
|
}
|
|
|
else {
|
|
|
- this._dragPlane.position.copyFrom(pointA);
|
|
|
+ this._dragPlane.position.copyFrom(this._pointA);
|
|
|
this._dragPlane.lookAt(ray.origin);
|
|
|
}
|
|
|
this._dragPlane.computeWorldMatrix(true);
|
|
@@ -88150,6 +88194,243 @@ var BABYLON;
|
|
|
var BABYLON;
|
|
|
(function (BABYLON) {
|
|
|
/**
|
|
|
+ * A behavior that when attached to a mesh will allow the mesh to be scaled
|
|
|
+ */
|
|
|
+ var MultiPointerScaleBehavior = /** @class */ (function () {
|
|
|
+ function MultiPointerScaleBehavior() {
|
|
|
+ this._startDistance = 0;
|
|
|
+ this._initialScale = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._targetScale = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ this._sceneRenderObserver = null;
|
|
|
+ this._dragBehaviorA = new BABYLON.PointerDragBehavior({});
|
|
|
+ this._dragBehaviorA.moveAttached = false;
|
|
|
+ this._dragBehaviorB = new BABYLON.PointerDragBehavior({});
|
|
|
+ this._dragBehaviorB.moveAttached = false;
|
|
|
+ }
|
|
|
+ Object.defineProperty(MultiPointerScaleBehavior.prototype, "name", {
|
|
|
+ /**
|
|
|
+ * The name of the behavior
|
|
|
+ */
|
|
|
+ get: function () {
|
|
|
+ return "MultiPointerScale";
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ /**
|
|
|
+ * Initializes the behavior
|
|
|
+ */
|
|
|
+ MultiPointerScaleBehavior.prototype.init = function () { };
|
|
|
+ MultiPointerScaleBehavior.prototype._getCurrentDistance = function () {
|
|
|
+ return this._dragBehaviorA.lastDragPosition.subtract(this._dragBehaviorB.lastDragPosition).length();
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * Attaches the scale behavior the passed in mesh
|
|
|
+ * @param ownerNode The mesh that will be scaled around once attached
|
|
|
+ */
|
|
|
+ MultiPointerScaleBehavior.prototype.attach = function (ownerNode) {
|
|
|
+ var _this = this;
|
|
|
+ this._ownerNode = ownerNode;
|
|
|
+ // Create 2 drag behaviors such that each will only be triggered by a separate pointer
|
|
|
+ this._dragBehaviorA.onDragStartObservable.add(function (e) {
|
|
|
+ if (_this._dragBehaviorA.dragging && _this._dragBehaviorB.dragging) {
|
|
|
+ if (_this._dragBehaviorA.currentDraggingPointerID == _this._dragBehaviorB.currentDraggingPointerID) {
|
|
|
+ _this._dragBehaviorA.releaseDrag();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this._initialScale.copyFrom(ownerNode.scaling);
|
|
|
+ _this._startDistance = _this._getCurrentDistance();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this._dragBehaviorB.onDragStartObservable.add(function (e) {
|
|
|
+ if (_this._dragBehaviorA.dragging && _this._dragBehaviorB.dragging) {
|
|
|
+ if (_this._dragBehaviorA.currentDraggingPointerID == _this._dragBehaviorB.currentDraggingPointerID) {
|
|
|
+ _this._dragBehaviorB.releaseDrag();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this._initialScale.copyFrom(ownerNode.scaling);
|
|
|
+ _this._startDistance = _this._getCurrentDistance();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // Once both drag behaviors are active scale based on the distance between the two pointers
|
|
|
+ [this._dragBehaviorA, this._dragBehaviorB].forEach(function (behavior) {
|
|
|
+ behavior.onDragObservable.add(function () {
|
|
|
+ if (_this._dragBehaviorA.dragging && _this._dragBehaviorB.dragging) {
|
|
|
+ var ratio = _this._getCurrentDistance() / _this._startDistance;
|
|
|
+ _this._initialScale.scaleToRef(ratio, _this._targetScale);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ ownerNode.addBehavior(this._dragBehaviorA);
|
|
|
+ ownerNode.addBehavior(this._dragBehaviorB);
|
|
|
+ // On every frame move towards target scaling to avoid jitter caused by vr controllers
|
|
|
+ this._sceneRenderObserver = ownerNode.getScene().onBeforeRenderObservable.add(function () {
|
|
|
+ if (_this._dragBehaviorA.dragging && _this._dragBehaviorB.dragging) {
|
|
|
+ var change = _this._targetScale.subtract(ownerNode.scaling).scaleInPlace(0.1);
|
|
|
+ if (change.length() > 0.01) {
|
|
|
+ ownerNode.scaling.addInPlace(change);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * Detaches the behavior from the mesh
|
|
|
+ */
|
|
|
+ MultiPointerScaleBehavior.prototype.detach = function () {
|
|
|
+ var _this = this;
|
|
|
+ this._ownerNode.getScene().onBeforeRenderObservable.remove(this._sceneRenderObserver);
|
|
|
+ [this._dragBehaviorA, this._dragBehaviorB].forEach(function (behavior) {
|
|
|
+ behavior.onDragStartObservable.clear();
|
|
|
+ behavior.onDragObservable.clear();
|
|
|
+ _this._ownerNode.removeBehavior(behavior);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ return MultiPointerScaleBehavior;
|
|
|
+ }());
|
|
|
+ BABYLON.MultiPointerScaleBehavior = MultiPointerScaleBehavior;
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+//# sourceMappingURL=babylon.multiPointerScaleBehavior.js.map
|
|
|
+
|
|
|
+var BABYLON;
|
|
|
+(function (BABYLON) {
|
|
|
+ /**
|
|
|
+ * A behavior that when attached to a mesh will allow the mesh to be dragged around based on directions and origin of the pointer's ray
|
|
|
+ */
|
|
|
+ var SixDofDragBehavior = /** @class */ (function () {
|
|
|
+ function SixDofDragBehavior() {
|
|
|
+ this._sceneRenderObserver = null;
|
|
|
+ this._targetPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ // How much faster the object should move when its further away
|
|
|
+ this._sixDofZDragFactor = 5;
|
|
|
+ /**
|
|
|
+ * If the behavior is currently in a dragging state
|
|
|
+ */
|
|
|
+ this.dragging = false;
|
|
|
+ /**
|
|
|
+ * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
|
|
|
+ */
|
|
|
+ this.currentDraggingPointerID = -1;
|
|
|
+ }
|
|
|
+ Object.defineProperty(SixDofDragBehavior.prototype, "name", {
|
|
|
+ /**
|
|
|
+ * The name of the behavior
|
|
|
+ */
|
|
|
+ get: function () {
|
|
|
+ return "SixDofDrag";
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+ /**
|
|
|
+ * Initializes the behavior
|
|
|
+ */
|
|
|
+ SixDofDragBehavior.prototype.init = function () { };
|
|
|
+ /**
|
|
|
+ * Attaches the scale behavior the passed in mesh
|
|
|
+ * @param ownerNode The mesh that will be scaled around once attached
|
|
|
+ */
|
|
|
+ SixDofDragBehavior.prototype.attach = function (ownerNode) {
|
|
|
+ var _this = this;
|
|
|
+ this._ownerNode = ownerNode;
|
|
|
+ this._scene = this._ownerNode.getScene();
|
|
|
+ if (!SixDofDragBehavior._virtualScene) {
|
|
|
+ SixDofDragBehavior._virtualScene = new BABYLON.Scene(this._scene.getEngine());
|
|
|
+ this._scene.getEngine().scenes.pop();
|
|
|
+ }
|
|
|
+ var pickedMesh = null;
|
|
|
+ var lastSixDofOriginPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
+ // Setup virtual meshes to be used for dragging without dirtying the existing scene
|
|
|
+ this._virtualOriginMesh = new BABYLON.AbstractMesh("", SixDofDragBehavior._virtualScene);
|
|
|
+ this._virtualOriginMesh.rotationQuaternion = new BABYLON.Quaternion();
|
|
|
+ this._virtualDragMesh = new BABYLON.AbstractMesh("", SixDofDragBehavior._virtualScene);
|
|
|
+ this._virtualDragMesh.rotationQuaternion = new BABYLON.Quaternion();
|
|
|
+ var pickPredicate = function (m) {
|
|
|
+ return _this._ownerNode == m || m.isDescendantOf(_this._ownerNode);
|
|
|
+ };
|
|
|
+ this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
|
|
|
+ if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
|
+ if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
|
|
|
+ pickedMesh = pointerInfo.pickInfo.pickedMesh;
|
|
|
+ lastSixDofOriginPosition.copyFrom(pointerInfo.pickInfo.ray.origin);
|
|
|
+ // Set position and orientation of the controller
|
|
|
+ _this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
|
|
|
+ _this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.subtract(pointerInfo.pickInfo.ray.direction));
|
|
|
+ // Attach the virtual drag mesh to the virtual origin mesh so it can be dragged
|
|
|
+ _this._virtualOriginMesh.removeChild(_this._virtualDragMesh);
|
|
|
+ _this._virtualDragMesh.position.copyFrom(pickedMesh.absolutePosition);
|
|
|
+ if (!pickedMesh.rotationQuaternion) {
|
|
|
+ pickedMesh.rotationQuaternion = new BABYLON.Quaternion();
|
|
|
+ }
|
|
|
+ _this._virtualDragMesh.rotationQuaternion.copyFrom(pickedMesh.rotationQuaternion);
|
|
|
+ _this._virtualOriginMesh.addChild(_this._virtualDragMesh);
|
|
|
+ // Update state
|
|
|
+ _this.dragging = true;
|
|
|
+ _this.currentDraggingPointerID = pointerInfo.event.pointerId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
|
|
|
+ if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
|
|
|
+ _this.dragging = false;
|
|
|
+ _this.currentDraggingPointerID = -1;
|
|
|
+ pickedMesh = null;
|
|
|
+ _this._virtualOriginMesh.removeChild(_this._virtualDragMesh);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
|
+ if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray && pickedMesh) {
|
|
|
+ // Calculate controller drag distance in controller space
|
|
|
+ var originDragDifference = pointerInfo.pickInfo.ray.origin.subtract(lastSixDofOriginPosition);
|
|
|
+ lastSixDofOriginPosition.copyFrom(pointerInfo.pickInfo.ray.origin);
|
|
|
+ var localOriginDragDifference = BABYLON.Vector3.TransformCoordinates(originDragDifference, BABYLON.Matrix.Invert(_this._virtualOriginMesh.getWorldMatrix().getRotationMatrix()));
|
|
|
+ _this._virtualOriginMesh.addChild(_this._virtualDragMesh);
|
|
|
+ // Determine how much the controller moved to/away towards the dragged object and use this to move the object further when its further away
|
|
|
+ var zDragDistance = BABYLON.Vector3.Dot(localOriginDragDifference, _this._virtualOriginMesh.position.normalizeToNew());
|
|
|
+ _this._virtualDragMesh.position.z -= _this._virtualDragMesh.position.z < 1 ? zDragDistance * _this._sixDofZDragFactor : zDragDistance * _this._sixDofZDragFactor * _this._virtualDragMesh.position.z;
|
|
|
+ if (_this._virtualDragMesh.position.z < 0) {
|
|
|
+ _this._virtualDragMesh.position.z = 0;
|
|
|
+ }
|
|
|
+ // Update the controller position
|
|
|
+ _this._virtualOriginMesh.position.copyFrom(pointerInfo.pickInfo.ray.origin);
|
|
|
+ _this._virtualOriginMesh.lookAt(pointerInfo.pickInfo.ray.origin.subtract(pointerInfo.pickInfo.ray.direction));
|
|
|
+ _this._virtualOriginMesh.removeChild(_this._virtualDragMesh);
|
|
|
+ // Move the virtualObjectsPosition into the picked mesh's space if needed
|
|
|
+ _this._targetPosition.copyFrom(_this._virtualDragMesh.absolutePosition);
|
|
|
+ if (pickedMesh.parent) {
|
|
|
+ BABYLON.Vector3.TransformCoordinatesToRef(_this._targetPosition, BABYLON.Matrix.Invert(pickedMesh.parent.getWorldMatrix()), _this._targetPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // On every frame move towards target scaling to avoid jitter caused by vr controllers
|
|
|
+ this._sceneRenderObserver = ownerNode.getScene().onBeforeRenderObservable.add(function () {
|
|
|
+ if (_this.dragging && pickedMesh) {
|
|
|
+ // Slowly move mesh to avoid jitter
|
|
|
+ pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(0.2));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * Detaches the behavior from the mesh
|
|
|
+ */
|
|
|
+ SixDofDragBehavior.prototype.detach = function () {
|
|
|
+ this._scene.onPointerObservable.remove(this._pointerObserver);
|
|
|
+ this._ownerNode.getScene().onBeforeRenderObservable.remove(this._sceneRenderObserver);
|
|
|
+ this._virtualOriginMesh.dispose();
|
|
|
+ this._virtualDragMesh.dispose();
|
|
|
+ };
|
|
|
+ return SixDofDragBehavior;
|
|
|
+ }());
|
|
|
+ BABYLON.SixDofDragBehavior = SixDofDragBehavior;
|
|
|
+})(BABYLON || (BABYLON = {}));
|
|
|
+
|
|
|
+//# sourceMappingURL=babylon.sixDofDragBehavior.js.map
|
|
|
+
|
|
|
+var BABYLON;
|
|
|
+(function (BABYLON) {
|
|
|
+ /**
|
|
|
* Renders gizmos on top of an existing scene which provide controls for position, rotation, etc.
|
|
|
*/
|
|
|
var Gizmo = /** @class */ (function () {
|
|
@@ -88367,7 +88648,7 @@ var BABYLON;
|
|
|
rotationMesh.rotation.x = Math.PI / 2;
|
|
|
_this._rootMesh.lookAt(_this._rootMesh.position.subtract(planeNormal));
|
|
|
// Add drag behavior to handle events when the gizmo is dragged
|
|
|
- _this._dragBehavior = new BABYLON.PointerDragBehavior({ dragPlaneNormal: planeNormal });
|
|
|
+ _this._dragBehavior = new BABYLON.PointerDragBehavior({ dragPlaneNormal: new BABYLON.Vector3(0, 0, 1) });
|
|
|
_this._dragBehavior.moveAttached = false;
|
|
|
_this._rootMesh.addBehavior(_this._dragBehavior);
|
|
|
var lastDragPosition = null;
|
|
@@ -91028,7 +91309,7 @@ var BABYLON;
|
|
|
if (_this.rightController && _this.rightController._activePointer) {
|
|
|
_this._castRayAndSelectObject(_this.rightController);
|
|
|
}
|
|
|
- if (!(_this.leftController && _this.leftController._activePointer) && !(_this.rightController && _this.rightController._activePointer)) {
|
|
|
+ if (_this._noControllerIsActive) {
|
|
|
_this._castRayAndSelectObject(_this._cameraGazer);
|
|
|
}
|
|
|
else {
|
|
@@ -91665,6 +91946,13 @@ var BABYLON;
|
|
|
this._interactionsEnabled = true;
|
|
|
}
|
|
|
};
|
|
|
+ Object.defineProperty(VRExperienceHelper.prototype, "_noControllerIsActive", {
|
|
|
+ get: function () {
|
|
|
+ return !(this.leftController && this.leftController._activePointer) && !(this.rightController && this.rightController._activePointer);
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
VRExperienceHelper.prototype._isTeleportationFloor = function (mesh) {
|
|
|
for (var i = 0; i < this._floorMeshesCollection.length; i++) {
|
|
|
if (this._floorMeshesCollection[i].id === mesh.id) {
|
|
@@ -91761,13 +92049,17 @@ var BABYLON;
|
|
|
});
|
|
|
}
|
|
|
controller.webVRController.onTriggerStateChangedObservable.add(function (stateObject) {
|
|
|
- if (!controller._pointerDownOnMeshAsked) {
|
|
|
+ var gazer = controller;
|
|
|
+ if (_this._noControllerIsActive) {
|
|
|
+ gazer = _this._cameraGazer;
|
|
|
+ }
|
|
|
+ if (!gazer._pointerDownOnMeshAsked) {
|
|
|
if (stateObject.value > _this._padSensibilityUp) {
|
|
|
- controller._selectionPointerDown();
|
|
|
+ gazer._selectionPointerDown();
|
|
|
}
|
|
|
}
|
|
|
else if (stateObject.value < _this._padSensibilityDown) {
|
|
|
- controller._selectionPointerUp();
|
|
|
+ gazer._selectionPointerUp();
|
|
|
}
|
|
|
});
|
|
|
}
|