|
@@ -91626,6 +91626,11 @@ var BABYLON;
|
|
this._tmpVector = new BABYLON.Vector3(0, 0, 0);
|
|
this._tmpVector = new BABYLON.Vector3(0, 0, 0);
|
|
this._alternatePickedPoint = new BABYLON.Vector3(0, 0, 0);
|
|
this._alternatePickedPoint = new BABYLON.Vector3(0, 0, 0);
|
|
this._worldDragAxis = new BABYLON.Vector3(0, 0, 0);
|
|
this._worldDragAxis = new BABYLON.Vector3(0, 0, 0);
|
|
|
|
+ this._targetPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
|
+ this._attachedElement = null;
|
|
|
|
+ this._startDragRay = new BABYLON.Ray(new BABYLON.Vector3(), new BABYLON.Vector3());
|
|
|
|
+ this._lastPointerRay = {};
|
|
|
|
+ this._dragDelta = new BABYLON.Vector3();
|
|
// Variables to avoid instantiation in the below method
|
|
// Variables to avoid instantiation in the below method
|
|
this._pointA = new BABYLON.Vector3(0, 0, 0);
|
|
this._pointA = new BABYLON.Vector3(0, 0, 0);
|
|
this._pointB = new BABYLON.Vector3(0, 0, 0);
|
|
this._pointB = new BABYLON.Vector3(0, 0, 0);
|
|
@@ -91686,73 +91691,34 @@ var BABYLON;
|
|
this._dragPlane = BABYLON.Mesh.CreatePlane("pointerDragPlane", this._debugMode ? 1 : 10000, PointerDragBehavior._planeScene, false, BABYLON.Mesh.DOUBLESIDE);
|
|
this._dragPlane = BABYLON.Mesh.CreatePlane("pointerDragPlane", this._debugMode ? 1 : 10000, PointerDragBehavior._planeScene, false, BABYLON.Mesh.DOUBLESIDE);
|
|
// State of the drag
|
|
// State of the drag
|
|
this.lastDragPosition = 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 targetPosition = new BABYLON.Vector3(0, 0, 0);
|
|
|
|
var pickPredicate = function (m) {
|
|
var pickPredicate = function (m) {
|
|
return _this._attachedNode == m || m.isDescendantOf(_this._attachedNode);
|
|
return _this._attachedNode == m || m.isDescendantOf(_this._attachedNode);
|
|
};
|
|
};
|
|
- var attachedElement = null;
|
|
|
|
this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
|
|
this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
|
|
if (!_this.enabled) {
|
|
if (!_this.enabled) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
|
|
if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.pickedPoint && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
|
|
if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.pickedPoint && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
|
|
- _this._updateDragPlanePosition(pointerInfo.pickInfo.ray, pointerInfo.pickInfo.pickedPoint);
|
|
|
|
- var pickedPoint = _this._pickWithRayOnDragPlane(pointerInfo.pickInfo.ray);
|
|
|
|
- if (pickedPoint) {
|
|
|
|
- _this.dragging = true;
|
|
|
|
- _this.currentDraggingPointerID = pointerInfo.event.pointerId;
|
|
|
|
- _this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
|
- _this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: _this.currentDraggingPointerID });
|
|
|
|
- targetPosition.copyFrom(_this._attachedNode.absolutePosition);
|
|
|
|
- // Detatch camera controls
|
|
|
|
- if (_this.detachCameraControls && _this._scene.activeCamera && !_this._scene.activeCamera.leftCamera) {
|
|
|
|
- if (_this._scene.activeCamera.inputs.attachedElement) {
|
|
|
|
- attachedElement = _this._scene.activeCamera.inputs.attachedElement;
|
|
|
|
- _this._scene.activeCamera.detachControl(_this._scene.activeCamera.inputs.attachedElement);
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- attachedElement = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ _this._startDrag(pointerInfo.event.pointerId, pointerInfo.pickInfo.ray, pointerInfo.pickInfo.pickedPoint);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERUP) {
|
|
if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
|
|
if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
|
|
_this.releaseDrag();
|
|
_this.releaseDrag();
|
|
- // Reattach camera controls
|
|
|
|
- if (_this.detachCameraControls && attachedElement && _this._scene.activeCamera && !_this._scene.activeCamera.leftCamera) {
|
|
|
|
- _this._scene.activeCamera.attachControl(attachedElement, true);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
else if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERMOVE) {
|
|
- if (_this.currentDraggingPointerID == pointerInfo.event.pointerId && _this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {
|
|
|
|
- _this._moving = true;
|
|
|
|
- var pickedPoint = _this._pickWithRayOnDragPlane(pointerInfo.pickInfo.ray);
|
|
|
|
- if (pickedPoint) {
|
|
|
|
- if (_this.updateDragPlane) {
|
|
|
|
- _this._updateDragPlanePosition(pointerInfo.pickInfo.ray, pickedPoint);
|
|
|
|
- }
|
|
|
|
- // depending on the drag mode option drag accordingly
|
|
|
|
- if (_this._options.dragAxis) {
|
|
|
|
- // Convert local drag axis to world
|
|
|
|
- BABYLON.Vector3.TransformCoordinatesToRef(_this._options.dragAxis, _this._attachedNode.getWorldMatrix().getRotationMatrix(), _this._worldDragAxis);
|
|
|
|
- // Project delta drag from the drag plane onto the drag axis
|
|
|
|
- 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(_this.lastDragPosition, delta);
|
|
|
|
- }
|
|
|
|
- targetPosition.addInPlace(delta);
|
|
|
|
- _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward, pointerId: _this.currentDraggingPointerID });
|
|
|
|
- _this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
|
|
|
+ var pointerId = pointerInfo.event.pointerId;
|
|
|
|
+ // Keep track of last pointer ray, this is used simulating the start of a drag in startDrag()
|
|
|
|
+ if (!_this._lastPointerRay[pointerId]) {
|
|
|
|
+ _this._lastPointerRay[pointerId] = new BABYLON.Ray(new BABYLON.Vector3(), new BABYLON.Vector3());
|
|
|
|
+ }
|
|
|
|
+ if (pointerInfo.pickInfo && pointerInfo.pickInfo.ray) {
|
|
|
|
+ _this._lastPointerRay[pointerId].origin.copyFrom(pointerInfo.pickInfo.ray.origin);
|
|
|
|
+ _this._lastPointerRay[pointerId].direction.copyFrom(pointerInfo.pickInfo.ray.direction);
|
|
|
|
+ if (_this.currentDraggingPointerID == pointerId && _this.dragging) {
|
|
|
|
+ _this._moveDrag(pointerInfo.pickInfo.ray);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -91760,7 +91726,7 @@ var BABYLON;
|
|
this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
|
|
this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
|
|
if (_this._moving && _this.moveAttached) {
|
|
if (_this._moving && _this.moveAttached) {
|
|
// Slowly move mesh to avoid jitter
|
|
// Slowly move mesh to avoid jitter
|
|
- targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
|
|
|
|
|
|
+ _this._targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
|
|
_this._tmpVector.scaleInPlace(_this.dragDeltaRatio);
|
|
_this._tmpVector.scaleInPlace(_this.dragDeltaRatio);
|
|
_this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
|
|
_this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
|
|
_this._attachedNode.setAbsolutePosition(_this._tmpVector);
|
|
_this._attachedNode.setAbsolutePosition(_this._tmpVector);
|
|
@@ -91772,6 +91738,85 @@ var BABYLON;
|
|
this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
|
|
this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
|
|
this.currentDraggingPointerID = -1;
|
|
this.currentDraggingPointerID = -1;
|
|
this._moving = false;
|
|
this._moving = false;
|
|
|
|
+ // Reattach camera controls
|
|
|
|
+ if (this.detachCameraControls && this._attachedElement && this._scene.activeCamera && !this._scene.activeCamera.leftCamera) {
|
|
|
|
+ this._scene.activeCamera.attachControl(this._attachedElement, true);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ /**
|
|
|
|
+ * Simulates the start of a pointer drag event on the behavior
|
|
|
|
+ * @param pointerId pointerID of the pointer that should be simulated (Default: 1 for mouse pointer)
|
|
|
|
+ * @param fromRay initial ray of the pointer to be simulated (Default: Ray from camera to attached mesh)
|
|
|
|
+ * @param startPickedPoint picked point of the pointer to be simulated (Default: attached mesh position)
|
|
|
|
+ */
|
|
|
|
+ PointerDragBehavior.prototype.startDrag = function (pointerId, fromRay, startPickedPoint) {
|
|
|
|
+ if (pointerId === void 0) { pointerId = 1; }
|
|
|
|
+ this._startDrag(pointerId, fromRay, startPickedPoint);
|
|
|
|
+ if (this._lastPointerRay[pointerId]) {
|
|
|
|
+ // if there was a last pointer ray drag the object there
|
|
|
|
+ this._moveDrag(this._lastPointerRay[pointerId]);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ PointerDragBehavior.prototype._startDrag = function (pointerId, fromRay, startPickedPoint) {
|
|
|
|
+ if (pointerId === void 0) { pointerId = 1; }
|
|
|
|
+ if (!this._scene.activeCamera || this.dragging || !this._attachedNode) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Create start ray from the camera to the object
|
|
|
|
+ if (fromRay) {
|
|
|
|
+ this._startDragRay.direction.copyFrom(fromRay.direction);
|
|
|
|
+ this._startDragRay.origin.copyFrom(fromRay.origin);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._startDragRay.origin.copyFrom(this._scene.activeCamera.position);
|
|
|
|
+ this._attachedNode.getWorldMatrix().getTranslationToRef(this._tmpVector);
|
|
|
|
+ this._tmpVector.subtractToRef(this._scene.activeCamera.position, this._startDragRay.direction);
|
|
|
|
+ }
|
|
|
|
+ this._updateDragPlanePosition(this._startDragRay, startPickedPoint ? startPickedPoint : this._tmpVector);
|
|
|
|
+ var pickedPoint = this._pickWithRayOnDragPlane(this._startDragRay);
|
|
|
|
+ if (pickedPoint) {
|
|
|
|
+ this.dragging = true;
|
|
|
|
+ this.currentDraggingPointerID = 1;
|
|
|
|
+ this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
|
+ this.onDragStartObservable.notifyObservers({ dragPlanePoint: pickedPoint, pointerId: this.currentDraggingPointerID });
|
|
|
|
+ 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) {
|
|
|
|
+ this._attachedElement = this._scene.activeCamera.inputs.attachedElement;
|
|
|
|
+ this._scene.activeCamera.detachControl(this._scene.activeCamera.inputs.attachedElement);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this._attachedElement = null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ PointerDragBehavior.prototype._moveDrag = function (ray) {
|
|
|
|
+ this._moving = true;
|
|
|
|
+ var pickedPoint = this._pickWithRayOnDragPlane(ray);
|
|
|
|
+ if (pickedPoint) {
|
|
|
|
+ if (this.updateDragPlane) {
|
|
|
|
+ this._updateDragPlanePosition(ray, pickedPoint);
|
|
|
|
+ }
|
|
|
|
+ var dragLength = 0;
|
|
|
|
+ // depending on the drag mode option drag accordingly
|
|
|
|
+ if (this._options.dragAxis) {
|
|
|
|
+ // Convert local drag axis to world
|
|
|
|
+ BABYLON.Vector3.TransformCoordinatesToRef(this._options.dragAxis, this._attachedNode.getWorldMatrix().getRotationMatrix(), this._worldDragAxis);
|
|
|
|
+ // Project delta drag from the drag plane onto the drag axis
|
|
|
|
+ pickedPoint.subtractToRef(this.lastDragPosition, this._tmpVector);
|
|
|
|
+ dragLength = BABYLON.Vector3.Dot(this._tmpVector, this._worldDragAxis);
|
|
|
|
+ this._worldDragAxis.scaleToRef(dragLength, this._dragDelta);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ dragLength = this._dragDelta.length();
|
|
|
|
+ pickedPoint.subtractToRef(this.lastDragPosition, this._dragDelta);
|
|
|
|
+ }
|
|
|
|
+ this._targetPosition.addInPlace(this._dragDelta);
|
|
|
|
+ this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: this._dragDelta, dragPlanePoint: pickedPoint, dragPlaneNormal: this._dragPlane.forward, pointerId: this.currentDraggingPointerID });
|
|
|
|
+ this.lastDragPosition.copyFrom(pickedPoint);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
|
|
PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
|
|
var _this = this;
|
|
var _this = this;
|