David Catuhe 7 年之前
父节点
当前提交
2eac5e7a48

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


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


+ 58 - 32
dist/preview release/babylon.max.js

@@ -50845,9 +50845,8 @@ var BABYLON;
             if (!this._isStarted) {
                 return this;
             }
-            for (var index = 0; index < this._animatables.length; index++) {
-                var animatable = this._animatables[index];
-                animatable.stop();
+            while (this._animatables.length > 0) {
+                this._animatables[0].stop();
             }
             this._isStarted = false;
             return this;
@@ -88183,9 +88182,13 @@ var BABYLON;
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
+            /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
             // Debug mode will display drag planes to help visualize behavior
             this._debugMode = false;
-            this._maxDragAngle = Math.PI / 5;
+            this._moving = false;
             /**
              *  Fires each time the attached mesh is dragged with the pointer
              *  * delta between last drag position and current drag position in world space
@@ -88207,10 +88210,6 @@ var BABYLON;
              */
             this.moveAttached = true;
             /**
-             *  Mesh with the position where the drag plane should be placed
-             */
-            this._dragPlaneParent = null;
-            /**
              *  If the drag behavior will react to drag events (Default: true)
              */
             this.enabled = true;
@@ -88279,6 +88278,7 @@ var BABYLON;
             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) {
                 return _this._attachedNode == m || m.isDescendantOf(_this._attachedNode);
             };
@@ -88287,14 +88287,15 @@ var BABYLON;
                     return;
                 }
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
-                    if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
-                        _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
+                    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);
                         }
                     }
                 }
@@ -88305,13 +88306,10 @@ var BABYLON;
                 }
                 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);
-                        // 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));
-                        if (angle < _this._maxDragAngle) {
-                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
-                        }
                         if (pickedPoint) {
+                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray, pickedPoint);
                             // depending on the drag mode option drag accordingly
                             if (_this.options.dragAxis) {
                                 // Convert local drag axis to world
@@ -88325,21 +88323,28 @@ var BABYLON;
                                 dragLength = delta.length();
                                 pickedPoint.subtractToRef(_this.lastDragPosition, delta);
                             }
-                            if (_this.moveAttached) {
-                                _this._attachedNode.absolutePosition.addToRef(delta, _this._tmpVector);
-                                _this._attachedNode.setAbsolutePosition(_this._tmpVector);
-                            }
+                            targetPosition.addInPlace(delta);
                             _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward, pointerId: _this.currentDraggingPointerID });
                             _this.lastDragPosition.copyFrom(pickedPoint);
                         }
                     }
                 }
             });
+            this._scene.onBeforeRenderObservable.add(function () {
+                if (_this._moving && _this.moveAttached) {
+                    // Slowly move mesh to avoid jitter
+                    targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._tmpVector.scaleInPlace(0.2);
+                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                }
+            });
         };
         PointerDragBehavior.prototype.releaseDrag = function () {
             this.dragging = false;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
+            this._moving = false;
         };
         PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
             var _this = this;
@@ -88355,8 +88360,8 @@ 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) {
-            this._pointA.copyFrom(this._dragPlaneParent ? this._dragPlaneParent.absolutePosition : this._attachedNode.absolutePosition);
+        PointerDragBehavior.prototype._updateDragPlanePosition = function (ray, dragPlanePosition) {
+            this._pointA.copyFrom(dragPlanePosition);
             if (this.options.dragAxis) {
                 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
@@ -88513,13 +88518,19 @@ var BABYLON;
         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;
+            /**
+             * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 5)
+             */
+            this.zDragFactor = 5;
             /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
             /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
+            /**
              * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
              */
             this.currentDraggingPointerID = -1;
@@ -88598,7 +88609,7 @@ var BABYLON;
                         _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;
+                        _this._virtualDragMesh.position.z -= _this._virtualDragMesh.position.z < 1 ? zDragDistance * _this.zDragFactor : zDragDistance * _this.zDragFactor * _this._virtualDragMesh.position.z;
                         if (_this._virtualDragMesh.position.z < 0) {
                             _this._virtualDragMesh.position.z = 0;
                         }
@@ -88618,7 +88629,7 @@ var BABYLON;
             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));
+                    pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                 }
             });
         };
@@ -88652,6 +88663,14 @@ var BABYLON;
             var _this = this;
             this.gizmoLayer = gizmoLayer;
             /**
+             * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoRotationToMatchAttachedMesh = true;
+            /**
+             * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoPositionToMatchAttachedMesh = true;
+            /**
              * When set, the gizmo will always appear the same size no matter where the camera is (default: false)
              */
             this._updateScale = true;
@@ -88663,7 +88682,15 @@ var BABYLON;
                     _this._rootMesh.scaling.set(dist, dist, dist);
                 }
                 if (_this.attachedMesh) {
-                    _this._rootMesh.position.copyFrom(_this.attachedMesh.position);
+                    if (_this.updateGizmoRotationToMatchAttachedMesh) {
+                        if (!_this._rootMesh.rotationQuaternion) {
+                            _this._rootMesh.rotationQuaternion = new BABYLON.Quaternion();
+                        }
+                        BABYLON.Quaternion.FromRotationMatrixToRef(_this.attachedMesh.getWorldMatrix().getRotationMatrix(), _this._rootMesh.rotationQuaternion);
+                    }
+                    if (_this.updateGizmoPositionToMatchAttachedMesh) {
+                        _this._rootMesh.position.copyFrom(_this.attachedMesh.absolutePosition);
+                    }
                 }
             });
         }
@@ -88715,6 +88742,7 @@ var BABYLON;
          */
         function AxisDragGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88780,6 +88808,7 @@ var BABYLON;
          */
         function AxisScaleGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88845,6 +88874,7 @@ var BABYLON;
          */
         function PlaneRotationGizmo(gizmoLayer, planeNormal, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -89082,6 +89112,7 @@ var BABYLON;
             _this._boundingDimensions = new BABYLON.Vector3(1, 1, 1);
             _this._renderObserver = null;
             _this._pointerObserver = null;
+            _this._scaleDragSpeed = 0.2;
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             // Create Materials
@@ -89179,6 +89210,7 @@ var BABYLON;
                                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(_this.attachedMesh.scaling);
                                 // Get the change in bounding box size/2 and add this to the mesh's position to offset from scaling with center pivot point
                                 var deltaScale = new BABYLON.Vector3(event.dragDistance, event.dragDistance, event.dragDistance);
+                                deltaScale.scaleInPlace(_this._scaleDragSpeed);
                                 var scaleRatio = deltaScale.divide(_this.attachedMesh.scaling).scaleInPlace(0.5);
                                 var moveDirection = boundBoxDimensions.multiply(scaleRatio).multiplyInPlace(dragAxis);
                                 var worldMoveDirection = BABYLON.Vector3.TransformCoordinates(moveDirection, _this.attachedMesh.getWorldMatrix().getRotationMatrix());
@@ -89241,12 +89273,6 @@ var BABYLON;
                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(this.attachedMesh.scaling);
                 this._boundingDimensions.copyFrom(boundBoxDimensions);
                 this._lineBoundingBox.scaling.copyFrom(this._boundingDimensions);
-                if (!this.attachedMesh.rotationQuaternion) {
-                    this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
-                }
-                this._lineBoundingBox.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._rotateSpheresParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._scaleBoxesParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
             }
             // Update rotation sphere locations
             var rotateSpheres = this._rotateSpheresParent.getChildMeshes();

+ 58 - 32
dist/preview release/babylon.no-module.max.js

@@ -50812,9 +50812,8 @@ var BABYLON;
             if (!this._isStarted) {
                 return this;
             }
-            for (var index = 0; index < this._animatables.length; index++) {
-                var animatable = this._animatables[index];
-                animatable.stop();
+            while (this._animatables.length > 0) {
+                this._animatables[0].stop();
             }
             this._isStarted = false;
             return this;
@@ -88150,9 +88149,13 @@ var BABYLON;
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
+            /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
             // Debug mode will display drag planes to help visualize behavior
             this._debugMode = false;
-            this._maxDragAngle = Math.PI / 5;
+            this._moving = false;
             /**
              *  Fires each time the attached mesh is dragged with the pointer
              *  * delta between last drag position and current drag position in world space
@@ -88174,10 +88177,6 @@ var BABYLON;
              */
             this.moveAttached = true;
             /**
-             *  Mesh with the position where the drag plane should be placed
-             */
-            this._dragPlaneParent = null;
-            /**
              *  If the drag behavior will react to drag events (Default: true)
              */
             this.enabled = true;
@@ -88246,6 +88245,7 @@ var BABYLON;
             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) {
                 return _this._attachedNode == m || m.isDescendantOf(_this._attachedNode);
             };
@@ -88254,14 +88254,15 @@ var BABYLON;
                     return;
                 }
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
-                    if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
-                        _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
+                    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);
                         }
                     }
                 }
@@ -88272,13 +88273,10 @@ var BABYLON;
                 }
                 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);
-                        // 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));
-                        if (angle < _this._maxDragAngle) {
-                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
-                        }
                         if (pickedPoint) {
+                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray, pickedPoint);
                             // depending on the drag mode option drag accordingly
                             if (_this.options.dragAxis) {
                                 // Convert local drag axis to world
@@ -88292,21 +88290,28 @@ var BABYLON;
                                 dragLength = delta.length();
                                 pickedPoint.subtractToRef(_this.lastDragPosition, delta);
                             }
-                            if (_this.moveAttached) {
-                                _this._attachedNode.absolutePosition.addToRef(delta, _this._tmpVector);
-                                _this._attachedNode.setAbsolutePosition(_this._tmpVector);
-                            }
+                            targetPosition.addInPlace(delta);
                             _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward, pointerId: _this.currentDraggingPointerID });
                             _this.lastDragPosition.copyFrom(pickedPoint);
                         }
                     }
                 }
             });
+            this._scene.onBeforeRenderObservable.add(function () {
+                if (_this._moving && _this.moveAttached) {
+                    // Slowly move mesh to avoid jitter
+                    targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._tmpVector.scaleInPlace(0.2);
+                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                }
+            });
         };
         PointerDragBehavior.prototype.releaseDrag = function () {
             this.dragging = false;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
+            this._moving = false;
         };
         PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
             var _this = this;
@@ -88322,8 +88327,8 @@ 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) {
-            this._pointA.copyFrom(this._dragPlaneParent ? this._dragPlaneParent.absolutePosition : this._attachedNode.absolutePosition);
+        PointerDragBehavior.prototype._updateDragPlanePosition = function (ray, dragPlanePosition) {
+            this._pointA.copyFrom(dragPlanePosition);
             if (this.options.dragAxis) {
                 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
@@ -88480,13 +88485,19 @@ var BABYLON;
         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;
+            /**
+             * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 5)
+             */
+            this.zDragFactor = 5;
             /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
             /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
+            /**
              * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
              */
             this.currentDraggingPointerID = -1;
@@ -88565,7 +88576,7 @@ var BABYLON;
                         _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;
+                        _this._virtualDragMesh.position.z -= _this._virtualDragMesh.position.z < 1 ? zDragDistance * _this.zDragFactor : zDragDistance * _this.zDragFactor * _this._virtualDragMesh.position.z;
                         if (_this._virtualDragMesh.position.z < 0) {
                             _this._virtualDragMesh.position.z = 0;
                         }
@@ -88585,7 +88596,7 @@ var BABYLON;
             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));
+                    pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                 }
             });
         };
@@ -88619,6 +88630,14 @@ var BABYLON;
             var _this = this;
             this.gizmoLayer = gizmoLayer;
             /**
+             * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoRotationToMatchAttachedMesh = true;
+            /**
+             * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoPositionToMatchAttachedMesh = true;
+            /**
              * When set, the gizmo will always appear the same size no matter where the camera is (default: false)
              */
             this._updateScale = true;
@@ -88630,7 +88649,15 @@ var BABYLON;
                     _this._rootMesh.scaling.set(dist, dist, dist);
                 }
                 if (_this.attachedMesh) {
-                    _this._rootMesh.position.copyFrom(_this.attachedMesh.position);
+                    if (_this.updateGizmoRotationToMatchAttachedMesh) {
+                        if (!_this._rootMesh.rotationQuaternion) {
+                            _this._rootMesh.rotationQuaternion = new BABYLON.Quaternion();
+                        }
+                        BABYLON.Quaternion.FromRotationMatrixToRef(_this.attachedMesh.getWorldMatrix().getRotationMatrix(), _this._rootMesh.rotationQuaternion);
+                    }
+                    if (_this.updateGizmoPositionToMatchAttachedMesh) {
+                        _this._rootMesh.position.copyFrom(_this.attachedMesh.absolutePosition);
+                    }
                 }
             });
         }
@@ -88682,6 +88709,7 @@ var BABYLON;
          */
         function AxisDragGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88747,6 +88775,7 @@ var BABYLON;
          */
         function AxisScaleGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88812,6 +88841,7 @@ var BABYLON;
          */
         function PlaneRotationGizmo(gizmoLayer, planeNormal, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -89049,6 +89079,7 @@ var BABYLON;
             _this._boundingDimensions = new BABYLON.Vector3(1, 1, 1);
             _this._renderObserver = null;
             _this._pointerObserver = null;
+            _this._scaleDragSpeed = 0.2;
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             // Create Materials
@@ -89146,6 +89177,7 @@ var BABYLON;
                                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(_this.attachedMesh.scaling);
                                 // Get the change in bounding box size/2 and add this to the mesh's position to offset from scaling with center pivot point
                                 var deltaScale = new BABYLON.Vector3(event.dragDistance, event.dragDistance, event.dragDistance);
+                                deltaScale.scaleInPlace(_this._scaleDragSpeed);
                                 var scaleRatio = deltaScale.divide(_this.attachedMesh.scaling).scaleInPlace(0.5);
                                 var moveDirection = boundBoxDimensions.multiply(scaleRatio).multiplyInPlace(dragAxis);
                                 var worldMoveDirection = BABYLON.Vector3.TransformCoordinates(moveDirection, _this.attachedMesh.getWorldMatrix().getRotationMatrix());
@@ -89208,12 +89240,6 @@ var BABYLON;
                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(this.attachedMesh.scaling);
                 this._boundingDimensions.copyFrom(boundBoxDimensions);
                 this._lineBoundingBox.scaling.copyFrom(this._boundingDimensions);
-                if (!this.attachedMesh.rotationQuaternion) {
-                    this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
-                }
-                this._lineBoundingBox.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._rotateSpheresParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._scaleBoxesParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
             }
             // Update rotation sphere locations
             var rotateSpheres = this._rotateSpheresParent.getChildMeshes();

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


+ 58 - 32
dist/preview release/es6.js

@@ -50812,9 +50812,8 @@ var BABYLON;
             if (!this._isStarted) {
                 return this;
             }
-            for (var index = 0; index < this._animatables.length; index++) {
-                var animatable = this._animatables[index];
-                animatable.stop();
+            while (this._animatables.length > 0) {
+                this._animatables[0].stop();
             }
             this._isStarted = false;
             return this;
@@ -88150,9 +88149,13 @@ var BABYLON;
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
+            /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
             // Debug mode will display drag planes to help visualize behavior
             this._debugMode = false;
-            this._maxDragAngle = Math.PI / 5;
+            this._moving = false;
             /**
              *  Fires each time the attached mesh is dragged with the pointer
              *  * delta between last drag position and current drag position in world space
@@ -88174,10 +88177,6 @@ var BABYLON;
              */
             this.moveAttached = true;
             /**
-             *  Mesh with the position where the drag plane should be placed
-             */
-            this._dragPlaneParent = null;
-            /**
              *  If the drag behavior will react to drag events (Default: true)
              */
             this.enabled = true;
@@ -88246,6 +88245,7 @@ var BABYLON;
             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) {
                 return _this._attachedNode == m || m.isDescendantOf(_this._attachedNode);
             };
@@ -88254,14 +88254,15 @@ var BABYLON;
                     return;
                 }
                 if (pointerInfo.type == BABYLON.PointerEventTypes.POINTERDOWN) {
-                    if (!_this.dragging && pointerInfo.pickInfo && pointerInfo.pickInfo.hit && pointerInfo.pickInfo.pickedMesh && pointerInfo.pickInfo.ray && pickPredicate(pointerInfo.pickInfo.pickedMesh)) {
-                        _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
+                    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);
                         }
                     }
                 }
@@ -88272,13 +88273,10 @@ var BABYLON;
                 }
                 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);
-                        // 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));
-                        if (angle < _this._maxDragAngle) {
-                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray);
-                        }
                         if (pickedPoint) {
+                            _this._updateDragPlanePosition(pointerInfo.pickInfo.ray, pickedPoint);
                             // depending on the drag mode option drag accordingly
                             if (_this.options.dragAxis) {
                                 // Convert local drag axis to world
@@ -88292,21 +88290,28 @@ var BABYLON;
                                 dragLength = delta.length();
                                 pickedPoint.subtractToRef(_this.lastDragPosition, delta);
                             }
-                            if (_this.moveAttached) {
-                                _this._attachedNode.absolutePosition.addToRef(delta, _this._tmpVector);
-                                _this._attachedNode.setAbsolutePosition(_this._tmpVector);
-                            }
+                            targetPosition.addInPlace(delta);
                             _this.onDragObservable.notifyObservers({ dragDistance: dragLength, delta: delta, dragPlanePoint: pickedPoint, dragPlaneNormal: _this._dragPlane.forward, pointerId: _this.currentDraggingPointerID });
                             _this.lastDragPosition.copyFrom(pickedPoint);
                         }
                     }
                 }
             });
+            this._scene.onBeforeRenderObservable.add(function () {
+                if (_this._moving && _this.moveAttached) {
+                    // Slowly move mesh to avoid jitter
+                    targetPosition.subtractToRef(_this._attachedNode.absolutePosition, _this._tmpVector);
+                    _this._tmpVector.scaleInPlace(0.2);
+                    _this._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
+                    _this._attachedNode.setAbsolutePosition(_this._tmpVector);
+                }
+            });
         };
         PointerDragBehavior.prototype.releaseDrag = function () {
             this.dragging = false;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
+            this._moving = false;
         };
         PointerDragBehavior.prototype._pickWithRayOnDragPlane = function (ray) {
             var _this = this;
@@ -88322,8 +88327,8 @@ 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) {
-            this._pointA.copyFrom(this._dragPlaneParent ? this._dragPlaneParent.absolutePosition : this._attachedNode.absolutePosition);
+        PointerDragBehavior.prototype._updateDragPlanePosition = function (ray, dragPlanePosition) {
+            this._pointA.copyFrom(dragPlanePosition);
             if (this.options.dragAxis) {
                 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
@@ -88480,13 +88485,19 @@ var BABYLON;
         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;
+            /**
+             * How much faster the object should move when the controller is moving towards it. This is useful to bring objects that are far away from the user to them faster. Set this to 0 to avoid any speed increase. (Default: 5)
+             */
+            this.zDragFactor = 5;
             /**
              * If the behavior is currently in a dragging state
              */
             this.dragging = false;
             /**
+             * The distance towards the target drag position to move each frame. This can be useful to avoid jitter. Set this to 1 for no delay. (Default: 0.2)
+             */
+            this.dragDeltaRatio = 0.2;
+            /**
              * The id of the pointer that is currently interacting with the behavior (-1 when no pointer is active)
              */
             this.currentDraggingPointerID = -1;
@@ -88565,7 +88576,7 @@ var BABYLON;
                         _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;
+                        _this._virtualDragMesh.position.z -= _this._virtualDragMesh.position.z < 1 ? zDragDistance * _this.zDragFactor : zDragDistance * _this.zDragFactor * _this._virtualDragMesh.position.z;
                         if (_this._virtualDragMesh.position.z < 0) {
                             _this._virtualDragMesh.position.z = 0;
                         }
@@ -88585,7 +88596,7 @@ var BABYLON;
             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));
+                    pickedMesh.position.addInPlace(_this._targetPosition.subtract(pickedMesh.position).scale(_this.dragDeltaRatio));
                 }
             });
         };
@@ -88619,6 +88630,14 @@ var BABYLON;
             var _this = this;
             this.gizmoLayer = gizmoLayer;
             /**
+             * If set the gizmo's rotation will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoRotationToMatchAttachedMesh = true;
+            /**
+             * If set the gizmo's position will be updated to match the attached mesh each frame (Default: true)
+             */
+            this.updateGizmoPositionToMatchAttachedMesh = true;
+            /**
              * When set, the gizmo will always appear the same size no matter where the camera is (default: false)
              */
             this._updateScale = true;
@@ -88630,7 +88649,15 @@ var BABYLON;
                     _this._rootMesh.scaling.set(dist, dist, dist);
                 }
                 if (_this.attachedMesh) {
-                    _this._rootMesh.position.copyFrom(_this.attachedMesh.position);
+                    if (_this.updateGizmoRotationToMatchAttachedMesh) {
+                        if (!_this._rootMesh.rotationQuaternion) {
+                            _this._rootMesh.rotationQuaternion = new BABYLON.Quaternion();
+                        }
+                        BABYLON.Quaternion.FromRotationMatrixToRef(_this.attachedMesh.getWorldMatrix().getRotationMatrix(), _this._rootMesh.rotationQuaternion);
+                    }
+                    if (_this.updateGizmoPositionToMatchAttachedMesh) {
+                        _this._rootMesh.position.copyFrom(_this.attachedMesh.absolutePosition);
+                    }
                 }
             });
         }
@@ -88682,6 +88709,7 @@ var BABYLON;
          */
         function AxisDragGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88747,6 +88775,7 @@ var BABYLON;
          */
         function AxisScaleGizmo(gizmoLayer, dragAxis, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -88812,6 +88841,7 @@ var BABYLON;
          */
         function PlaneRotationGizmo(gizmoLayer, planeNormal, color) {
             var _this = _super.call(this, gizmoLayer) || this;
+            _this.updateGizmoRotationToMatchAttachedMesh = false;
             // Create Material
             var coloredMaterial = new BABYLON.StandardMaterial("", gizmoLayer.utilityLayerScene);
             coloredMaterial.disableLighting = true;
@@ -89049,6 +89079,7 @@ var BABYLON;
             _this._boundingDimensions = new BABYLON.Vector3(1, 1, 1);
             _this._renderObserver = null;
             _this._pointerObserver = null;
+            _this._scaleDragSpeed = 0.2;
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             // Create Materials
@@ -89146,6 +89177,7 @@ var BABYLON;
                                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(_this.attachedMesh.scaling);
                                 // Get the change in bounding box size/2 and add this to the mesh's position to offset from scaling with center pivot point
                                 var deltaScale = new BABYLON.Vector3(event.dragDistance, event.dragDistance, event.dragDistance);
+                                deltaScale.scaleInPlace(_this._scaleDragSpeed);
                                 var scaleRatio = deltaScale.divide(_this.attachedMesh.scaling).scaleInPlace(0.5);
                                 var moveDirection = boundBoxDimensions.multiply(scaleRatio).multiplyInPlace(dragAxis);
                                 var worldMoveDirection = BABYLON.Vector3.TransformCoordinates(moveDirection, _this.attachedMesh.getWorldMatrix().getRotationMatrix());
@@ -89208,12 +89240,6 @@ var BABYLON;
                 var boundBoxDimensions = boundingInfo.maximum.subtract(boundingInfo.minimum).multiplyInPlace(this.attachedMesh.scaling);
                 this._boundingDimensions.copyFrom(boundBoxDimensions);
                 this._lineBoundingBox.scaling.copyFrom(this._boundingDimensions);
-                if (!this.attachedMesh.rotationQuaternion) {
-                    this.attachedMesh.rotationQuaternion = new BABYLON.Quaternion();
-                }
-                this._lineBoundingBox.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._rotateSpheresParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
-                this._scaleBoxesParent.rotationQuaternion.copyFrom(this.attachedMesh.rotationQuaternion);
             }
             // Update rotation sphere locations
             var rotateSpheres = this._rotateSpheresParent.getChildMeshes();

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


文件差异内容过多而无法显示
+ 67 - 42
dist/preview release/viewer/babylon.viewer.max.js


+ 2 - 1
dist/preview release/what's new.md

@@ -14,7 +14,8 @@
   - Added support for `isBillboardBased`. [Doc](http://doc.babylonjs.com/babylon101/particles#alignment)
   - Added support for `minScaleX`, `minScaleY`, `maxScaleX`, `maxScaleY`. [Doc](http://doc.babylonjs.com/babylon101/particles#size)
   - Added support for `radiusRange` for sphere emitter. [Doc](http://doc.babylonjs.com/babylon101/particles#sphere-emitter)
-  - Added support for `ParticleSystem.BLENDMODE_ADD` alpha mode. [Doc](http://doc.babylonjs.com/babylon101/particles#particle-colors)
+  - Added support for `ParticleSystem.BLENDMODE_ADD` alpha mode. [Doc](http://doc.babylonjs.com/babylon101/particles#particle-blending)
+  - Added support for color gradients. [Doc](http://doc.babylonjs.com/babylon101/particles#particle-colors)
 
 ## Updates
 

+ 3 - 2
src/Animations/babylon.animationGroup.ts

@@ -270,8 +270,9 @@ module BABYLON {
                 return this;
             }
 
-            while (this._animatables.length > 0) {
-                this._animatables[0].stop();
+            var list = this._animatables.slice();
+            for (var index = 0; index < list.length; index++) {
+                list[index].stop();
             }
 
             this._isStarted = false;