Pārlūkot izejas kodu

Nightly + unlit LAVA

sebastien 7 gadi atpakaļ
vecāks
revīzija
ae0fce51f5

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 21674 - 21660
Playground/babylon.d.txt


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 21638 - 21624
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/babylon.js


+ 96 - 51
dist/preview release/babylon.max.js

@@ -91626,6 +91626,11 @@ var BABYLON;
             this._tmpVector = new BABYLON.Vector3(0, 0, 0);
             this._alternatePickedPoint = 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
             this._pointA = 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);
             // State of the drag
             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);
             };
-            var attachedElement = null;
             this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
                 if (!_this.enabled) {
                     return;
                 }
                 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)) {
-                        _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) {
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
                         _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) {
-                    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 () {
                 if (_this._moving && _this.moveAttached) {
                     // 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._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
                     _this._attachedNode.setAbsolutePosition(_this._tmpVector);
@@ -91772,6 +91738,85 @@ var BABYLON;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
             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) {
             var _this = this;

+ 96 - 51
dist/preview release/babylon.no-module.max.js

@@ -91593,6 +91593,11 @@ var BABYLON;
             this._tmpVector = new BABYLON.Vector3(0, 0, 0);
             this._alternatePickedPoint = 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
             this._pointA = new BABYLON.Vector3(0, 0, 0);
             this._pointB = new BABYLON.Vector3(0, 0, 0);
@@ -91653,73 +91658,34 @@ var BABYLON;
             this._dragPlane = BABYLON.Mesh.CreatePlane("pointerDragPlane", this._debugMode ? 1 : 10000, PointerDragBehavior._planeScene, false, BABYLON.Mesh.DOUBLESIDE);
             // State of the drag
             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);
             };
-            var attachedElement = null;
             this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
                 if (!_this.enabled) {
                     return;
                 }
                 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)) {
-                        _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) {
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
                         _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) {
-                    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);
                         }
                     }
                 }
@@ -91727,7 +91693,7 @@ var BABYLON;
             this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
                 if (_this._moving && _this.moveAttached) {
                     // 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._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
                     _this._attachedNode.setAbsolutePosition(_this._tmpVector);
@@ -91739,6 +91705,85 @@ var BABYLON;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
             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) {
             var _this = this;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/babylon.worker.js


+ 96 - 51
dist/preview release/es6.js

@@ -91593,6 +91593,11 @@ var BABYLON;
             this._tmpVector = new BABYLON.Vector3(0, 0, 0);
             this._alternatePickedPoint = 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
             this._pointA = new BABYLON.Vector3(0, 0, 0);
             this._pointB = new BABYLON.Vector3(0, 0, 0);
@@ -91653,73 +91658,34 @@ var BABYLON;
             this._dragPlane = BABYLON.Mesh.CreatePlane("pointerDragPlane", this._debugMode ? 1 : 10000, PointerDragBehavior._planeScene, false, BABYLON.Mesh.DOUBLESIDE);
             // State of the drag
             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);
             };
-            var attachedElement = null;
             this._pointerObserver = this._scene.onPointerObservable.add(function (pointerInfo, eventState) {
                 if (!_this.enabled) {
                     return;
                 }
                 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)) {
-                        _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) {
                     if (_this.currentDraggingPointerID == pointerInfo.event.pointerId) {
                         _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) {
-                    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);
                         }
                     }
                 }
@@ -91727,7 +91693,7 @@ var BABYLON;
             this._beforeRenderObserver = this._scene.onBeforeRenderObservable.add(function () {
                 if (_this._moving && _this.moveAttached) {
                     // 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._attachedNode.getAbsolutePosition().addToRef(_this._tmpVector, _this._tmpVector);
                     _this._attachedNode.setAbsolutePosition(_this._tmpVector);
@@ -91739,6 +91705,85 @@ var BABYLON;
             this.onDragEndObservable.notifyObservers({ dragPlanePoint: this.lastDragPosition, pointerId: this.currentDraggingPointerID });
             this.currentDraggingPointerID = -1;
             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) {
             var _this = this;

+ 2 - 0
dist/preview release/materialsLibrary/babylon.lavaMaterial.d.ts

@@ -13,6 +13,8 @@ declare module BABYLON {
         diffuseColor: Color3;
         private _disableLighting;
         disableLighting: boolean;
+        private _unlit;
+        unlit: boolean;
         private _maxSimultaneousLights;
         maxSimultaneousLights: number;
         private _scaledDiffuse;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 12 - 2
dist/preview release/materialsLibrary/babylon.lavaMaterial.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/materialsLibrary/babylon.lavaMaterial.min.js


+ 2 - 0
dist/preview release/materialsLibrary/babylonjs.materials.d.ts

@@ -91,6 +91,8 @@ declare module BABYLON {
         diffuseColor: Color3;
         private _disableLighting;
         disableLighting: boolean;
+        private _unlit;
+        unlit: boolean;
         private _maxSimultaneousLights;
         maxSimultaneousLights: number;
         private _scaledDiffuse;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 12 - 2
dist/preview release/materialsLibrary/babylonjs.materials.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/materialsLibrary/babylonjs.materials.min.js


+ 2 - 0
dist/preview release/materialsLibrary/babylonjs.materials.module.d.ts

@@ -96,6 +96,8 @@ declare module BABYLON {
         diffuseColor: Color3;
         private _disableLighting;
         disableLighting: boolean;
+        private _unlit;
+        unlit: boolean;
         private _maxSimultaneousLights;
         maxSimultaneousLights: number;
         private _scaledDiffuse;

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 4 - 0
dist/preview release/what's new.md

@@ -135,6 +135,10 @@
 - Viewer supports 3D printing on windows 10 ([RaananW](https://github.com/RaananW))
 - The viewer's environment map is using the new .env feature ([RaananW](https://github.com/RaananW))
 
+### Materials Library
+
+- Added ```unlit``` mode to lava material ([sebavan](http://www.github.com/sebavan))
+
 ### Documentation
 
 - Added all code comments for GUI

+ 11 - 1
materialsLibrary/src/lava/babylon.lavaMaterial.ts

@@ -60,6 +60,7 @@ module BABYLON {
         public NUM_BONE_INFLUENCERS = 0;
         public BonesPerMesh = 0;
         public INSTANCES = false;
+        public UNLIT = false;
 
         constructor() {
             super();
@@ -101,6 +102,11 @@ module BABYLON {
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
         public disableLighting: boolean;
 
+        @serialize("unlit")
+        private _unlit = false;
+        @expandToProperty("_markAllSubMeshesAsLightsDirty")
+        public unlit: boolean;
+
         @serialize("maxSimultaneousLights")
         private _maxSimultaneousLights = 4;
         @expandToProperty("_markAllSubMeshesAsLightsDirty")
@@ -167,7 +173,9 @@ module BABYLON {
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
 
             // Lights
-            defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
+            defines._needNormals = true;
+            
+            MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
 
             // Values that need to be evaluated on every frame
             MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
@@ -278,6 +286,8 @@ module BABYLON {
             }
             this._activeEffect = effect;
 
+            defines.UNLIT = this._unlit;
+
             // Matrices        
             this.bindOnlyWorldMatrix(world);
             this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());

+ 5 - 0
materialsLibrary/src/lava/lava.fragment.fx

@@ -124,6 +124,10 @@ void main(void) {
 	vec3 normalW = vec3(1.0, 1.0, 1.0);
 #endif
 
+#ifdef UNLIT
+	vec3 diffuseBase = vec3(1., 1., 1.);
+#else
+
 	// Lighting
 	vec3 diffuseBase = vec3(0., 0., 0.);
     lightingInfo info;
@@ -135,6 +139,7 @@ void main(void) {
 #include<lightFragment>[2]
 #include<lightFragment>[3]
 
+#endif
 
 #ifdef VERTEXALPHA
 	alpha *= vColor.a;