Jelajahi Sumber

Merge branch 'master' into ninepatch

David Catuhe 6 tahun lalu
induk
melakukan
8007bc93a1

File diff ditekan karena terlalu besar
+ 565 - 556
Playground/babylon.d.txt


File diff ditekan karena terlalu besar
+ 935 - 928
dist/preview release/babylon.d.ts


File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/babylon.js


+ 36 - 0
dist/preview release/babylon.max.js

@@ -105304,6 +105304,9 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
+            // Dragging
+            _this._dragMesh = null;
+            _this.pointerDragBehavior = new BABYLON.PointerDragBehavior();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -105394,6 +105397,7 @@ var BABYLON;
                         _this.updateBoundingBox();
                         BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
+                    _this._updateDummy();
                 });
                 // Selection/deselection
                 _dragBehavior.onDragStartObservable.add(function () {
@@ -105403,6 +105407,7 @@ var BABYLON;
                 _dragBehavior.onDragEndObservable.add(function () {
                     _this.onRotationSphereDragEndObservable.notifyObservers({});
                     _this._selectNode(null);
+                    _this._updateDummy();
                 });
                 this_1._rotateSpheresParent.addChild(sphere);
             };
@@ -105455,6 +105460,7 @@ var BABYLON;
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
                                 BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
+                            _this._updateDummy();
                         });
                         // Selection/deselection
                         _dragBehavior.onDragStartObservable.add(function () {
@@ -105464,6 +105470,7 @@ var BABYLON;
                         _dragBehavior.onDragEndObservable.add(function () {
                             _this.onScaleBoxDragEndObservable.notifyObservers({});
                             _this._selectNode(null);
+                            _this._updateDummy();
                         });
                         this_2._scaleBoxesParent.addChild(box);
                     };
@@ -105502,6 +105509,11 @@ var BABYLON;
                     _this._updateRotationSpheres();
                     _this._updateScaleBoxes();
                 }
+                // If dragg mesh is enabled and dragging, update the attached mesh pose to match the drag mesh
+                if (_this._dragMesh && _this.attachedMesh && _this.pointerDragBehavior.dragging) {
+                    _this._lineBoundingBox.position.rotateByQuaternionToRef(_this._rootMesh.rotationQuaternion, _this._tmpVector);
+                    _this.attachedMesh.setAbsolutePosition(_this._dragMesh.position.add(_this._tmpVector.scale(-1)));
+                }
             });
             _this.updateBoundingBox();
             return _this;
@@ -105534,6 +105546,7 @@ var BABYLON;
             this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
+            var _this = this;
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
@@ -105542,6 +105555,9 @@ var BABYLON;
                 this._anchorMesh.removeChild(value);
                 BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
+                this.gizmoLayer.utilityLayerScene.onAfterRenderObservable.addOnce(function () {
+                    _this._updateDummy();
+                });
             }
         };
         BoundingBoxGizmo.prototype._selectNode = function (selectedMesh) {
@@ -105663,6 +105679,23 @@ var BABYLON;
                 }
             });
         };
+        BoundingBoxGizmo.prototype._updateDummy = function () {
+            if (this._dragMesh) {
+                this._dragMesh.position.copyFrom(this._lineBoundingBox.getAbsolutePosition());
+                this._dragMesh.scaling.copyFrom(this._lineBoundingBox.scaling);
+                this._dragMesh.rotationQuaternion.copyFrom(this._rootMesh.rotationQuaternion);
+            }
+        };
+        /**
+         * Enables a pointer drag behavior on the bounding box of the gizmo
+         */
+        BoundingBoxGizmo.prototype.enableDragBehavior = function () {
+            this._dragMesh = BABYLON.Mesh.CreateBox("dummy", 1, this.gizmoLayer.utilityLayerScene);
+            this._dragMesh.visibility = 0;
+            this._dragMesh.rotationQuaternion = new BABYLON.Quaternion();
+            this.pointerDragBehavior.useObjectOrienationForDragging = false;
+            this._dragMesh.addBehavior(this.pointerDragBehavior);
+        };
         /**
          * Disposes of the gizmo
          */
@@ -105672,6 +105705,9 @@ var BABYLON;
             this._lineBoundingBox.dispose();
             this._rotateSpheresParent.dispose();
             this._scaleBoxesParent.dispose();
+            if (this._dragMesh) {
+                this._dragMesh.dispose();
+            }
             _super.prototype.dispose.call(this);
         };
         /**

+ 36 - 0
dist/preview release/babylon.no-module.max.js

@@ -105271,6 +105271,9 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
+            // Dragging
+            _this._dragMesh = null;
+            _this.pointerDragBehavior = new BABYLON.PointerDragBehavior();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -105361,6 +105364,7 @@ var BABYLON;
                         _this.updateBoundingBox();
                         BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
+                    _this._updateDummy();
                 });
                 // Selection/deselection
                 _dragBehavior.onDragStartObservable.add(function () {
@@ -105370,6 +105374,7 @@ var BABYLON;
                 _dragBehavior.onDragEndObservable.add(function () {
                     _this.onRotationSphereDragEndObservable.notifyObservers({});
                     _this._selectNode(null);
+                    _this._updateDummy();
                 });
                 this_1._rotateSpheresParent.addChild(sphere);
             };
@@ -105422,6 +105427,7 @@ var BABYLON;
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
                                 BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
+                            _this._updateDummy();
                         });
                         // Selection/deselection
                         _dragBehavior.onDragStartObservable.add(function () {
@@ -105431,6 +105437,7 @@ var BABYLON;
                         _dragBehavior.onDragEndObservable.add(function () {
                             _this.onScaleBoxDragEndObservable.notifyObservers({});
                             _this._selectNode(null);
+                            _this._updateDummy();
                         });
                         this_2._scaleBoxesParent.addChild(box);
                     };
@@ -105469,6 +105476,11 @@ var BABYLON;
                     _this._updateRotationSpheres();
                     _this._updateScaleBoxes();
                 }
+                // If dragg mesh is enabled and dragging, update the attached mesh pose to match the drag mesh
+                if (_this._dragMesh && _this.attachedMesh && _this.pointerDragBehavior.dragging) {
+                    _this._lineBoundingBox.position.rotateByQuaternionToRef(_this._rootMesh.rotationQuaternion, _this._tmpVector);
+                    _this.attachedMesh.setAbsolutePosition(_this._dragMesh.position.add(_this._tmpVector.scale(-1)));
+                }
             });
             _this.updateBoundingBox();
             return _this;
@@ -105501,6 +105513,7 @@ var BABYLON;
             this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
+            var _this = this;
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
@@ -105509,6 +105522,9 @@ var BABYLON;
                 this._anchorMesh.removeChild(value);
                 BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
+                this.gizmoLayer.utilityLayerScene.onAfterRenderObservable.addOnce(function () {
+                    _this._updateDummy();
+                });
             }
         };
         BoundingBoxGizmo.prototype._selectNode = function (selectedMesh) {
@@ -105630,6 +105646,23 @@ var BABYLON;
                 }
             });
         };
+        BoundingBoxGizmo.prototype._updateDummy = function () {
+            if (this._dragMesh) {
+                this._dragMesh.position.copyFrom(this._lineBoundingBox.getAbsolutePosition());
+                this._dragMesh.scaling.copyFrom(this._lineBoundingBox.scaling);
+                this._dragMesh.rotationQuaternion.copyFrom(this._rootMesh.rotationQuaternion);
+            }
+        };
+        /**
+         * Enables a pointer drag behavior on the bounding box of the gizmo
+         */
+        BoundingBoxGizmo.prototype.enableDragBehavior = function () {
+            this._dragMesh = BABYLON.Mesh.CreateBox("dummy", 1, this.gizmoLayer.utilityLayerScene);
+            this._dragMesh.visibility = 0;
+            this._dragMesh.rotationQuaternion = new BABYLON.Quaternion();
+            this.pointerDragBehavior.useObjectOrienationForDragging = false;
+            this._dragMesh.addBehavior(this.pointerDragBehavior);
+        };
         /**
          * Disposes of the gizmo
          */
@@ -105639,6 +105672,9 @@ var BABYLON;
             this._lineBoundingBox.dispose();
             this._rotateSpheresParent.dispose();
             this._scaleBoxesParent.dispose();
+            if (this._dragMesh) {
+                this._dragMesh.dispose();
+            }
             _super.prototype.dispose.call(this);
         };
         /**

File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/babylon.worker.js


+ 36 - 0
dist/preview release/es6.js

@@ -105271,6 +105271,9 @@ var BABYLON;
              */
             _this.scalePivot = null;
             _this._existingMeshScale = new BABYLON.Vector3();
+            // Dragging
+            _this._dragMesh = null;
+            _this.pointerDragBehavior = new BABYLON.PointerDragBehavior();
             // Do not update the gizmo's scale so it has a fixed size to the object its attached to
             _this._updateScale = false;
             _this._anchorMesh = new BABYLON.AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
@@ -105361,6 +105364,7 @@ var BABYLON;
                         _this.updateBoundingBox();
                         BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                     }
+                    _this._updateDummy();
                 });
                 // Selection/deselection
                 _dragBehavior.onDragStartObservable.add(function () {
@@ -105370,6 +105374,7 @@ var BABYLON;
                 _dragBehavior.onDragEndObservable.add(function () {
                     _this.onRotationSphereDragEndObservable.notifyObservers({});
                     _this._selectNode(null);
+                    _this._updateDummy();
                 });
                 this_1._rotateSpheresParent.addChild(sphere);
             };
@@ -105422,6 +105427,7 @@ var BABYLON;
                                 _this._anchorMesh.removeChild(_this.attachedMesh);
                                 BoundingBoxGizmo._RestorePivotPoint(_this.attachedMesh);
                             }
+                            _this._updateDummy();
                         });
                         // Selection/deselection
                         _dragBehavior.onDragStartObservable.add(function () {
@@ -105431,6 +105437,7 @@ var BABYLON;
                         _dragBehavior.onDragEndObservable.add(function () {
                             _this.onScaleBoxDragEndObservable.notifyObservers({});
                             _this._selectNode(null);
+                            _this._updateDummy();
                         });
                         this_2._scaleBoxesParent.addChild(box);
                     };
@@ -105469,6 +105476,11 @@ var BABYLON;
                     _this._updateRotationSpheres();
                     _this._updateScaleBoxes();
                 }
+                // If dragg mesh is enabled and dragging, update the attached mesh pose to match the drag mesh
+                if (_this._dragMesh && _this.attachedMesh && _this.pointerDragBehavior.dragging) {
+                    _this._lineBoundingBox.position.rotateByQuaternionToRef(_this._rootMesh.rotationQuaternion, _this._tmpVector);
+                    _this.attachedMesh.setAbsolutePosition(_this._dragMesh.position.add(_this._tmpVector.scale(-1)));
+                }
             });
             _this.updateBoundingBox();
             return _this;
@@ -105501,6 +105513,7 @@ var BABYLON;
             this._PivotCached--;
         };
         BoundingBoxGizmo.prototype._attachedMeshChanged = function (value) {
+            var _this = this;
             if (value) {
                 // Reset anchor mesh to match attached mesh's scale
                 // This is needed to avoid invalid box/sphere position on first drag
@@ -105509,6 +105522,9 @@ var BABYLON;
                 this._anchorMesh.removeChild(value);
                 BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
+                this.gizmoLayer.utilityLayerScene.onAfterRenderObservable.addOnce(function () {
+                    _this._updateDummy();
+                });
             }
         };
         BoundingBoxGizmo.prototype._selectNode = function (selectedMesh) {
@@ -105630,6 +105646,23 @@ var BABYLON;
                 }
             });
         };
+        BoundingBoxGizmo.prototype._updateDummy = function () {
+            if (this._dragMesh) {
+                this._dragMesh.position.copyFrom(this._lineBoundingBox.getAbsolutePosition());
+                this._dragMesh.scaling.copyFrom(this._lineBoundingBox.scaling);
+                this._dragMesh.rotationQuaternion.copyFrom(this._rootMesh.rotationQuaternion);
+            }
+        };
+        /**
+         * Enables a pointer drag behavior on the bounding box of the gizmo
+         */
+        BoundingBoxGizmo.prototype.enableDragBehavior = function () {
+            this._dragMesh = BABYLON.Mesh.CreateBox("dummy", 1, this.gizmoLayer.utilityLayerScene);
+            this._dragMesh.visibility = 0;
+            this._dragMesh.rotationQuaternion = new BABYLON.Quaternion();
+            this.pointerDragBehavior.useObjectOrienationForDragging = false;
+            this._dragMesh.addBehavior(this.pointerDragBehavior);
+        };
         /**
          * Disposes of the gizmo
          */
@@ -105639,6 +105672,9 @@ var BABYLON;
             this._lineBoundingBox.dispose();
             this._rotateSpheresParent.dispose();
             this._scaleBoxesParent.dispose();
+            if (this._dragMesh) {
+                this._dragMesh.dispose();
+            }
             _super.prototype.dispose.call(this);
         };
         /**

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

@@ -1615,6 +1615,8 @@ declare module BABYLON.GUI {
             thickness: number;
             /** Gets or sets the background color when focused */
             focusedBackground: string;
+            /** Gets or sets the background color when focused */
+            focusedColor: string;
             /** Gets or sets the background color */
             background: string;
             /** Gets or sets the placeholder color */

File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/gui/babylon.gui.js


File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js


File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js.map


+ 4 - 0
dist/preview release/gui/babylon.gui.module.d.ts

@@ -1740,6 +1740,8 @@ declare module 'babylonjs-gui/2D/controls/inputText' {
             thickness: number;
             /** Gets or sets the background color when focused */
             focusedBackground: string;
+            /** Gets or sets the background color when focused */
+            focusedColor: string;
             /** Gets or sets the background color */
             background: string;
             /** Gets or sets the placeholder color */
@@ -4791,6 +4793,8 @@ declare module BABYLON.GUI {
             thickness: number;
             /** Gets or sets the background color when focused */
             focusedBackground: string;
+            /** Gets or sets the background color when focused */
+            focusedColor: string;
             /** Gets or sets the background color */
             background: string;
             /** Gets or sets the placeholder color */

File diff ditekan karena terlalu besar
+ 7 - 7
dist/preview release/inspector/babylon.inspector.bundle.js


File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.js.map


+ 31 - 0
dist/preview release/viewer/babylon.viewer.d.ts

@@ -1728,6 +1728,37 @@ declare module BabylonViewer {
     }
 }
 declare module BabylonViewer {
+    export interface ICameraConfiguration {
+        position?: {
+            x: number;
+            y: number;
+            z: number;
+        };
+        rotation?: {
+            x: number;
+            y: number;
+            z: number;
+            w: number;
+        };
+        fov?: number;
+        fovMode?: number;
+        minZ?: number;
+        maxZ?: number;
+        inertia?: number;
+        exposure?: number;
+        pinchPrecision?: number;
+        behaviors?: {
+            [name: string]: boolean | number | ICameraBehaviorConfiguration;
+        };
+        disableCameraControl?: boolean;
+        disableCtrlForPanning?: boolean;
+        disableAutoFocus?: boolean;
+        [propName: string]: any;
+    }
+    export interface ICameraBehaviorConfiguration {
+        type: number;
+        [propName: string]: any;
+    }
 }
 declare module BabylonViewer {
     /**

File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


File diff ditekan karena terlalu besar
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 31 - 1
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -1872,7 +1872,37 @@ declare module 'babylonjs-viewer/loader/plugins/extendedMaterialLoaderPlugin' {
 }
 
 declare module 'babylonjs-viewer/configuration/interfaces/cameraConfiguration' {
-    
+    export interface ICameraConfiguration {
+        position?: {
+            x: number;
+            y: number;
+            z: number;
+        };
+        rotation?: {
+            x: number;
+            y: number;
+            z: number;
+            w: number;
+        };
+        fov?: number;
+        fovMode?: number;
+        minZ?: number;
+        maxZ?: number;
+        inertia?: number;
+        exposure?: number;
+        pinchPrecision?: number;
+        behaviors?: {
+            [name: string]: boolean | number | ICameraBehaviorConfiguration;
+        };
+        disableCameraControl?: boolean;
+        disableCtrlForPanning?: boolean;
+        disableAutoFocus?: boolean;
+        [propName: string]: any;
+    }
+    export interface ICameraBehaviorConfiguration {
+        type: number;
+        [propName: string]: any;
+    }
 }
 
 declare module 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration' {

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

@@ -26,6 +26,7 @@
 
 ### GUI
 
+- Added `inputText.onKeyboardEventProcessedObservable` ([Deltakosh](https://github.com/deltakosh))
 - Added `button.image` and `button.textBlock` to simplify access to button internal parts ([Deltakosh](https://github.com/deltakosh))
 - Added `sldier.displayThumb` to show/hide slider's thumb ([Deltakosh](https://github.com/deltakosh))
 - Added `grid.rowCount`, `grid.columnCount` and `grid.getChildrenAt()` ([Deltakosh](https://github.com/deltakosh))
@@ -80,6 +81,7 @@
 - Factored out `setDirection` function from `lookAt` for transform node ([bghgary](https://github.com/bghgary))
 - Add support for setting renderingGroupId and creating instances to `AxesViewer` ([bghgary](https://github.com/bghgary))
 - Invert vScale of compressed ktx textures as they are inverted in the file and UNPACK_FLIP_Y_WEBGL is not supported by ktx ([TrevorDev](https://github.com/TrevorDev))
+- Enable dragging in boundingBoxGizmo without needing a parent ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 36 - 11
gui/src/2D/controls/inputText.ts

@@ -12,6 +12,7 @@ export class InputText extends Control implements IFocusableControl {
     private _placeholderText = "";
     private _background = "#222222";
     private _focusedBackground = "#000000";
+    private _focusedColor = "white";
     private _placeholderColor = "gray";
     private _thickness = 1;
     private _margin = new ValueAndUnit(10, ValueAndUnit.UNITMODE_PIXEL);
@@ -61,6 +62,8 @@ export class InputText extends Control implements IFocusableControl {
     public onTextCutObservable = new Observable<InputText>();
     /** Observable raised when paste event is triggered */
     public onTextPasteObservable = new Observable<InputText>();
+    /** Observable raised when a key event was processed */
+    public onKeyboardEventProcessedObservable = new Observable<KeyboardEvent>();
 
     /** Gets or sets the maximum width allowed by the control */
     public get maxWidth(): string | number {
@@ -183,6 +186,20 @@ export class InputText extends Control implements IFocusableControl {
         this._markAsDirty();
     }
 
+    /** Gets or sets the background color when focused */
+    public get focusedColor(): string {
+        return this._focusedColor;
+    }
+
+    public set focusedColor(value: string) {
+        if (this._focusedColor === value) {
+            return;
+        }
+
+        this._focusedColor = value;
+        this._markAsDirty();
+    }
+
     /** Gets or sets the background color */
     public get background(): string {
         return this._background;
@@ -727,6 +744,8 @@ export class InputText extends Control implements IFocusableControl {
     public processKeyboard(evt: KeyboardEvent): void {
         // process pressed key
         this.processKey(evt.keyCode, evt.key, evt);
+
+        this.onKeyboardEventProcessedObservable.notifyObservers(evt);
     }
 
     /** @hidden */
@@ -829,9 +848,7 @@ export class InputText extends Control implements IFocusableControl {
         let rootY = this._fontOffset.ascent + (this._currentMeasure.height - this._fontOffset.height) / 2;
         let availableWidth = this._width.getValueInPixel(this._host, this._tempParentMeasure.width) - marginWidth;
 
-        if (this._isFocused) {
-            context.save();
-        }
+        context.save();
         context.beginPath();
         context.rect(clipTextLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, availableWidth + 2, this._currentMeasure.height);
         context.clip();
@@ -923,20 +940,27 @@ export class InputText extends Control implements IFocusableControl {
                 context.fillRect(highlightCursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, width, this._fontOffset.height);
                 context.globalAlpha = 1.0;
             }
+        }
+        context.restore();
 
-            context.restore();
-
-            // Border
-            if (this._thickness) {
+        // Border
+        if (this._thickness) {
+            if (this._isFocused) {
+                if (this.focusedColor) {
+                    context.strokeStyle = this.focusedColor;
+                }
+            } else {
                 if (this.color) {
                     context.strokeStyle = this.color;
                 }
-                context.lineWidth = this._thickness;
-
-                context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2,
-                    this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
             }
+
+            context.lineWidth = this._thickness;
+
+            context.strokeRect(this._currentMeasure.left + this._thickness / 2, this._currentMeasure.top + this._thickness / 2,
+                this._currentMeasure.width - this._thickness, this._currentMeasure.height - this._thickness);
         }
+
         context.restore();
     }
 
@@ -994,5 +1018,6 @@ export class InputText extends Control implements IFocusableControl {
         this.onTextCutObservable.clear();
         this.onTextPasteObservable.clear();
         this.onTextHighlightObservable.clear();
+        this.onKeyboardEventProcessedObservable.clear();
     }
 }

+ 3 - 17
inspector/src/components/sceneExplorer/entities/meshTreeItemComponent.tsx

@@ -1,4 +1,4 @@
-import { AbstractMesh, Mesh, IExplorerExtensibilityGroup } from "babylonjs";
+import { AbstractMesh, IExplorerExtensibilityGroup } from "babylonjs";
 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
 import { faCube } from '@fortawesome/free-solid-svg-icons';
 import { faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons';
@@ -44,36 +44,22 @@ export class MeshTreeItemComponent extends React.Component<IMeshTreeItemComponen
                 mesh.reservedDataStore.previousParent.reservedDataStore.detachedChildren.push(mesh);
             }
 
-            // Connect to gizmo
-            const dummy = BABYLON.BoundingBoxGizmo.MakeNotPickableAndWrapInBoundingBox(mesh as Mesh);
-            dummy.reservedDataStore = { hidden: true };
             const gizmo = new BABYLON.BoundingBoxGizmo(BABYLON.Color3.FromHexString("#0984e3"));
-            gizmo.attachedMesh = dummy;
+            gizmo.attachedMesh = mesh;
+            gizmo.enableDragBehavior();
 
             gizmo.updateBoundingBox();
 
             gizmo.fixedDragMeshScreenSize = true;
             mesh.reservedDataStore.gizmo = gizmo;
-
-            var pointerDragBehavior = new BABYLON.PointerDragBehavior();
-            pointerDragBehavior.useObjectOrienationForDragging = false;
-
-            dummy.addBehavior(pointerDragBehavior);
-
-            mesh.reservedDataStore.pointerDragBehavior = pointerDragBehavior;
-            mesh.reservedDataStore.dummy = dummy;
-
             this.setState({ isGizmoEnabled: true });
             return;
         }
 
         const previousParent = mesh.reservedDataStore.previousParent;
-        mesh.removeBehavior(mesh.reservedDataStore.pointerDragBehavior);
         mesh.reservedDataStore.gizmo.dispose();
         mesh.reservedDataStore.gizmo = null;
         mesh.setParent(previousParent);
-        mesh.reservedDataStore.dummy.dispose();
-        mesh.reservedDataStore.dummy = null;
 
         if (previousParent && previousParent.reservedDataStore) {
             previousParent.reservedDataStore.detachedChildren = null;

+ 40 - 0
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -67,6 +67,10 @@ module BABYLON {
         private _anchorMesh: AbstractMesh;
         private _existingMeshScale = new Vector3();
 
+        // Dragging
+        private _dragMesh: Nullable<Mesh> = null;
+        private pointerDragBehavior = new BABYLON.PointerDragBehavior();
+
         // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
         // store/remove pivot point should only be applied during their outermost calls
         private static _PivotCached = 0;
@@ -209,6 +213,7 @@ module BABYLON {
 
                         BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
                     }
+                    this._updateDummy();
                 });
 
                 // Selection/deselection
@@ -219,6 +224,7 @@ module BABYLON {
                 _dragBehavior.onDragEndObservable.add(() => {
                     this.onRotationSphereDragEndObservable.notifyObservers({});
                     this._selectNode(null);
+                    this._updateDummy();
                 });
 
                 this._rotateSpheresParent.addChild(sphere);
@@ -271,6 +277,7 @@ module BABYLON {
 
                                 BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
                             }
+                            this._updateDummy();
                         });
 
                         // Selection/deselection
@@ -281,6 +288,7 @@ module BABYLON {
                         _dragBehavior.onDragEndObservable.add(() => {
                             this.onScaleBoxDragEndObservable.notifyObservers({});
                             this._selectNode(null);
+                            this._updateDummy();
                         });
 
                         this._scaleBoxesParent.addChild(box);
@@ -316,6 +324,12 @@ module BABYLON {
                     this._updateRotationSpheres();
                     this._updateScaleBoxes();
                 }
+
+                // If dragg mesh is enabled and dragging, update the attached mesh pose to match the drag mesh
+                if (this._dragMesh && this.attachedMesh && this.pointerDragBehavior.dragging) {
+                    this._lineBoundingBox.position.rotateByQuaternionToRef(this._rootMesh.rotationQuaternion!, this._tmpVector);
+                    this.attachedMesh.setAbsolutePosition(this._dragMesh.position.add(this._tmpVector.scale(-1)));
+                }
             });
             this.updateBoundingBox();
         }
@@ -329,6 +343,10 @@ module BABYLON {
                 this._anchorMesh.removeChild(value);
                 BoundingBoxGizmo._RestorePivotPoint(value);
                 this.updateBoundingBox();
+
+                this.gizmoLayer.utilityLayerScene.onAfterRenderObservable.addOnce(() => {
+                    this._updateDummy();
+                });
             }
         }
 
@@ -458,6 +476,25 @@ module BABYLON {
             });
         }
 
+        private _updateDummy() {
+            if (this._dragMesh) {
+                this._dragMesh.position.copyFrom(this._lineBoundingBox.getAbsolutePosition());
+                this._dragMesh.scaling.copyFrom(this._lineBoundingBox.scaling);
+                this._dragMesh.rotationQuaternion!.copyFrom(this._rootMesh.rotationQuaternion!);
+            }
+        }
+
+        /**
+         * Enables a pointer drag behavior on the bounding box of the gizmo
+         */
+        public enableDragBehavior() {
+            this._dragMesh = BABYLON.Mesh.CreateBox("dummy", 1, this.gizmoLayer.utilityLayerScene);
+            this._dragMesh.visibility = 0;
+            this._dragMesh.rotationQuaternion = new BABYLON.Quaternion();
+            this.pointerDragBehavior.useObjectOrienationForDragging = false;
+            this._dragMesh.addBehavior(this.pointerDragBehavior);
+        }
+
         /**
          * Disposes of the gizmo
          */
@@ -467,6 +504,9 @@ module BABYLON {
             this._lineBoundingBox.dispose();
             this._rotateSpheresParent.dispose();
             this._scaleBoxesParent.dispose();
+            if (this._dragMesh) {
+                this._dragMesh.dispose();
+            }
             super.dispose();
         }