Procházet zdrojové kódy

Gizmo update for dispose

1. Extended functionality to scaling gizmo
2. updated dispose() for all
3. constructor with parent = null
balupg před 6 roky
rodič
revize
3e22187347

+ 28 - 13
src/Gizmos/axisDragGizmo.ts

@@ -35,7 +35,11 @@ export class AxisDragGizmo extends Gizmo {
     public onSnapObservable = new Observable<{ snapDistance: number }>();
 
     private _isEnabled: boolean = true;
-    private _parent: PositionGizmo ;
+    private _parent: Nullable<PositionGizmo> = null;
+
+    private _arrow: TransformNode;
+    private _coloredMaterial: StandardMaterial;
+    private _hoverMaterial: StandardMaterial;
 
     /** @hidden */
     public static _CreateArrow(scene: Scene, material: StandardMaterial): TransformNode {
@@ -71,23 +75,23 @@ export class AxisDragGizmo extends Gizmo {
      * @param dragAxis The axis which the gizmo will be able to drag on
      * @param color The color of the gizmo
      */
-    constructor(dragAxis: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, parent: PositionGizmo) {
+    constructor(dragAxis: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, parent: Nullable<PositionGizmo> = null) {
         super(gizmoLayer);
         this._parent = parent;
         // Create Material
-        var coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
-        coloredMaterial.diffuseColor = color;
-        coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
+        this._coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
+        this._coloredMaterial.diffuseColor = color;
+        this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
 
-        var hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
-        hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
+        this._hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
+        this._hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
 
         // Build mesh on root node
-        var arrow = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, coloredMaterial);
+        this._arrow = AxisDragGizmo._CreateArrow(gizmoLayer.utilityLayerScene, this._coloredMaterial);
 
-        arrow.lookAt(this._rootMesh.position.add(dragAxis));
-        arrow.scaling.scaleInPlace(1 / 3);
-        arrow.parent = this._rootMesh;
+        this._arrow.lookAt(this._rootMesh.position.add(dragAxis));
+        this._arrow.scaling.scaleInPlace(1 / 3);
+        this._arrow.parent = this._rootMesh;
 
         var currentSnapDragDistance = 0;
         var tmpVector = new Vector3();
@@ -132,7 +136,7 @@ export class AxisDragGizmo extends Gizmo {
                 return;
             }
             var isHovered = pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1);
-            var material = isHovered ? hoverMaterial : coloredMaterial;
+            var material = isHovered ? this._hoverMaterial : this._coloredMaterial;
             this._rootMesh.getChildMeshes().forEach((m) => {
                 m.material = material;
                 if ((<LinesMesh>m).color) {
@@ -159,7 +163,9 @@ export class AxisDragGizmo extends Gizmo {
             this.attachedMesh = null;
         }
         else {
-            this.attachedMesh = this._parent.attachedMesh;
+            if (this._parent) {
+                this.attachedMesh = this._parent.attachedMesh;
+            }
         }
     }
     public get isEnabled(): boolean {
@@ -173,6 +179,15 @@ export class AxisDragGizmo extends Gizmo {
         this.onSnapObservable.clear();
         this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
         this.dragBehavior.detach();
+        if (this._arrow)
+        {
+            this._arrow.dispose();
+        }
+        [this._coloredMaterial, this._hoverMaterial].forEach((matl) => {
+            if (matl) {
+                matl.dispose();
+            }
+        });
         super.dispose();
     }
 }

+ 47 - 12
src/Gizmos/axisScaleGizmo.ts

@@ -13,11 +13,12 @@ import { _TimeToken } from "../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../States/index";
 import { Gizmo } from "./gizmo";
 import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
+import { ScaleGizmo } from "./scaleGizmo";
+
 /**
  * Single axis scale gizmo
  */
 export class AxisScaleGizmo extends Gizmo {
-    private _coloredMaterial: StandardMaterial;
     /**
      * Drag behavior responsible for the gizmos dragging interactions
      */
@@ -36,30 +37,38 @@ export class AxisScaleGizmo extends Gizmo {
      * If the scaling operation should be done on all axis (default: false)
      */
     public uniformScaling = false;
+
+    private _isEnabled: boolean = true;
+    private _parent: Nullable<ScaleGizmo> = null;
+
+    private _arrow: AbstractMesh;
+    private _coloredMaterial: StandardMaterial;
+    private _hoverMaterial: StandardMaterial;
+
     /**
      * Creates an AxisScaleGizmo
      * @param gizmoLayer The utility layer the gizmo will be added to
      * @param dragAxis The axis which the gizmo will be able to scale on
      * @param color The color of the gizmo
      */
-    constructor(dragAxis: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer) {
+    constructor(dragAxis: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, parent: Nullable<ScaleGizmo> = null) {
         super(gizmoLayer);
-
+        this._parent = parent;
         // Create Material
         this._coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
         this._coloredMaterial.diffuseColor = color;
         this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
 
-        var hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
-        hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
+        this._hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
+        this._hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
 
         // Build mesh on root node
-        var arrow = new AbstractMesh("", gizmoLayer.utilityLayerScene);
+        this._arrow = new AbstractMesh("", gizmoLayer.utilityLayerScene);
         var arrowMesh = BoxBuilder.CreateBox("yPosMesh", { size: 0.4 }, gizmoLayer.utilityLayerScene);
         var arrowTail = CylinderBuilder.CreateCylinder("cylinder", { diameterTop: 0.005, height: 0.275, diameterBottom: 0.005, tessellation: 96 }, gizmoLayer.utilityLayerScene);
         arrowTail.material = this._coloredMaterial;
-        arrow.addChild(arrowMesh);
-        arrow.addChild(arrowTail);
+        this._arrow.addChild(arrowMesh);
+        this._arrow.addChild(arrowTail);
 
         // Position arrow pointing in its drag axis
         arrowMesh.scaling.scaleInPlace(0.1);
@@ -68,9 +77,9 @@ export class AxisScaleGizmo extends Gizmo {
         arrowMesh.position.z += 0.3;
         arrowTail.position.z += 0.275 / 2;
         arrowTail.rotation.x = Math.PI / 2;
-        arrow.lookAt(this._rootMesh.position.add(dragAxis));
-        this._rootMesh.addChild(arrow);
-        arrow.scaling.scaleInPlace(1 / 3);
+        this._arrow.lookAt(this._rootMesh.position.add(dragAxis));
+        this._rootMesh.addChild(this._arrow);
+        this._arrow.scaling.scaleInPlace(1 / 3);
 
         // Add drag behavior to handle events when the gizmo is dragged
         this.dragBehavior = new PointerDragBehavior({ dragAxis: dragAxis });
@@ -127,7 +136,7 @@ export class AxisScaleGizmo extends Gizmo {
                 return;
             }
             var isHovered = pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1);
-            var material = isHovered ? hoverMaterial : this._coloredMaterial;
+            var material = isHovered ? this._hoverMaterial : this._coloredMaterial;
             this._rootMesh.getChildMeshes().forEach((m) => {
                 m.material = material;
                 if ((<LinesMesh>m).color) {
@@ -147,12 +156,38 @@ export class AxisScaleGizmo extends Gizmo {
     }
 
     /**
+ * If the gizmo is enabled
+ */
+    public set isEnabled(value: boolean) {
+        this._isEnabled = value;
+        if (!value) {
+            this.attachedMesh = null;
+        }
+        else {
+            if (this._parent) {
+                this.attachedMesh = this._parent.attachedMesh;
+            }
+        }
+    }
+    public get isEnabled(): boolean {
+        return this._isEnabled;
+    }
+
+    /**
      * Disposes of the gizmo
      */
     public dispose() {
         this.onSnapObservable.clear();
         this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
         this.dragBehavior.detach();
+        if (this._arrow) {
+            this._arrow.dispose();
+        }
+        [this._coloredMaterial, this._hoverMaterial].forEach((matl) => {
+            if (matl) {
+                matl.dispose();
+            }
+        });
         super.dispose();
     }
 

+ 27 - 17
src/Gizmos/planeDragGizmo.ts

@@ -5,7 +5,6 @@ import { Vector3, Color3, Matrix } from "../Maths/math";
 import { TransformNode } from "../Meshes/transformNode";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
-import { LinesMesh } from "../Meshes/linesMesh";
 import { PlaneBuilder } from "../Meshes/Builders/planeBuilder";
 import { PointerDragBehavior } from "../Behaviors/Meshes/pointerDragBehavior";
 import { _TimeToken } from "../Instrumentation/timeToken";
@@ -34,8 +33,12 @@ export class PlaneDragGizmo extends Gizmo {
      */
     public onSnapObservable = new Observable<{ snapDistance: number }>();
 
+    private _plane: TransformNode;
+    private _coloredMaterial: StandardMaterial;
+    private _hoverMaterial: StandardMaterial;
+
     private _isEnabled: boolean = false;
-    private _parent: PositionGizmo ;
+    private _parent: Nullable<PositionGizmo> = null;
 
     /** @hidden */
     public static _CreatePlane(scene: Scene, material: StandardMaterial): TransformNode {
@@ -67,23 +70,23 @@ export class PlaneDragGizmo extends Gizmo {
      * @param dragPlaneNormal The axis normal to which the gizmo will be able to drag on
      * @param color The color of the gizmo
      */
-    constructor(dragPlaneNormal: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, parent: PositionGizmo) {
+    constructor(dragPlaneNormal: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, parent: Nullable<PositionGizmo> = null) {
         super(gizmoLayer);
         this._parent = parent;
         // Create Material
-        var coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
-        coloredMaterial.diffuseColor = color;
-        coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
+        this._coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
+        this._coloredMaterial.diffuseColor = color;
+        this._coloredMaterial.specularColor = color.subtract(new Color3(0.1, 0.1, 0.1));
 
-        var hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
-        hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
+        this._hoverMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
+        this._hoverMaterial.diffuseColor = color.add(new Color3(0.3, 0.3, 0.3));
 
         // Build plane mesh on root node
-        var plane = PlaneDragGizmo._CreatePlane(gizmoLayer.utilityLayerScene, coloredMaterial);
+        this._plane = PlaneDragGizmo._CreatePlane(gizmoLayer.utilityLayerScene, this._coloredMaterial);
 
-        plane.lookAt(this._rootMesh.position.add(dragPlaneNormal));
-        plane.scaling.scaleInPlace(1 / 3);
-        plane.parent = this._rootMesh;
+        this._plane.lookAt(this._rootMesh.position.add(dragPlaneNormal));
+        this._plane.scaling.scaleInPlace(1 / 3);
+        this._plane.parent = this._rootMesh;
 
         var currentSnapDragDistance = 0;
         var tmpVector = new Vector3();
@@ -128,12 +131,9 @@ export class PlaneDragGizmo extends Gizmo {
                 return;
             }
             var isHovered = pointerInfo.pickInfo && (this._rootMesh.getChildMeshes().indexOf(<Mesh>pointerInfo.pickInfo.pickedMesh) != -1);
-            var material = isHovered ? hoverMaterial : coloredMaterial;
+            var material = isHovered ? this._hoverMaterial : this._coloredMaterial;
             this._rootMesh.getChildMeshes().forEach((m) => {
                 m.material = material;
-                if ((<LinesMesh>m).color) {
-                    (<LinesMesh>m).color = material.diffuseColor;
-                }
             });
         });
 
@@ -155,7 +155,9 @@ export class PlaneDragGizmo extends Gizmo {
             this.attachedMesh = null;
         }
         else {
-            this.attachedMesh = this._parent.attachedMesh;
+            if (this._parent) {
+                this.attachedMesh = this._parent.attachedMesh;
+            }
         }
     }
     public get isEnabled(): boolean {
@@ -169,5 +171,13 @@ export class PlaneDragGizmo extends Gizmo {
         this.gizmoLayer.utilityLayerScene.onPointerObservable.remove(this._pointerObserver);
         this.dragBehavior.detach();
         super.dispose();
+        if (this._plane) {
+            this._plane.dispose();
+        }
+        [this._coloredMaterial, this._hoverMaterial].forEach((matl) => {
+            if (matl) {
+                matl.dispose();
+            }
+        });
     }
 }

+ 5 - 3
src/Gizmos/planeRotationGizmo.ts

@@ -36,7 +36,7 @@ export class PlaneRotationGizmo extends Gizmo {
     public onSnapObservable = new Observable<{ snapDistance: number }>();
 
     private _isEnabled: boolean = true;
-    private _parent: RotationGizmo ;
+    private _parent: Nullable<RotationGizmo> = null;
 
     /**
      * Creates a PlaneRotationGizmo
@@ -45,7 +45,7 @@ export class PlaneRotationGizmo extends Gizmo {
      * @param color The color of the gizmo
      * @param tessellation Amount of tessellation to be used when creating rotation circles
      */
-    constructor(planeNormal: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, tessellation = 32, parent: RotationGizmo) {
+    constructor(planeNormal: Vector3, color: Color3 = Color3.Gray(), gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer, tessellation = 32, parent: Nullable<RotationGizmo> = null) {
         super(gizmoLayer);
         this._parent = parent;
         // Create Material
@@ -220,7 +220,9 @@ export class PlaneRotationGizmo extends Gizmo {
             this.attachedMesh = null;
         }
         else {
-            this.attachedMesh = this._parent.attachedMesh;
+            if (this._parent) {
+                this.attachedMesh = this._parent.attachedMesh;
+            }
         }
     }
     public get isEnabled(): boolean {

+ 63 - 42
src/Gizmos/scaleGizmo.ts

@@ -7,6 +7,7 @@ import { PolyhedronBuilder } from "../Meshes/Builders/polyhedronBuilder";
 import { Gizmo } from "./gizmo";
 import { AxisScaleGizmo } from "./axisScaleGizmo";
 import { UtilityLayerRenderer } from "../Rendering/utilityLayerRenderer";
+import { Mesh } from 'Meshes';
 /**
  * Gizmo that enables scaling a mesh along 3 axis
  */
@@ -29,21 +30,31 @@ export class ScaleGizmo extends Gizmo {
      */
     public uniformScaleGizmo: AxisScaleGizmo;
 
+    private _meshAttached: Nullable<AbstractMesh> = null;
+    private _updateGizmoRotationToMatchAttachedMesh: boolean;
+    private _snapDistance: number;
+    private _scaleRatio: number;
+    private _uniformScalingMesh: Mesh;
+    private _octahedron: Mesh;
+
     /** Fires an event when any of it's sub gizmos are dragged */
     public onDragStartObservable = new Observable();
     /** Fires an event when any of it's sub gizmos are released from dragging */
     public onDragEndObservable = new Observable();
 
     public get attachedMesh() {
-        return this.xGizmo.attachedMesh;
+        return this._meshAttached;
     }
     public set attachedMesh(mesh: Nullable<AbstractMesh>) {
-        if (this.xGizmo) {
-            this.xGizmo.attachedMesh = mesh;
-            this.yGizmo.attachedMesh = mesh;
-            this.zGizmo.attachedMesh = mesh;
-            this.uniformScaleGizmo.attachedMesh = mesh;
-        }
+        this._meshAttached = mesh;
+        [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+            if (gizmo.isEnabled) {
+                gizmo.attachedMesh = mesh;
+            }
+            else {
+                gizmo.attachedMesh = null;
+            }
+        });
     }
     /**
      * Creates a ScaleGizmo
@@ -51,23 +62,23 @@ export class ScaleGizmo extends Gizmo {
      */
     constructor(gizmoLayer: UtilityLayerRenderer = UtilityLayerRenderer.DefaultUtilityLayer) {
         super(gizmoLayer);
-        this.xGizmo = new AxisScaleGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer);
-        this.yGizmo = new AxisScaleGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer);
-        this.zGizmo = new AxisScaleGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer);
+        this.xGizmo = new AxisScaleGizmo(new Vector3(1, 0, 0), Color3.Red().scale(0.5), gizmoLayer, this);
+        this.yGizmo = new AxisScaleGizmo(new Vector3(0, 1, 0), Color3.Green().scale(0.5), gizmoLayer, this);
+        this.zGizmo = new AxisScaleGizmo(new Vector3(0, 0, 1), Color3.Blue().scale(0.5), gizmoLayer, this);
 
         // Create uniform scale gizmo
-        this.uniformScaleGizmo = new AxisScaleGizmo(new Vector3(0, 1, 0), Color3.Yellow().scale(0.5), gizmoLayer);
+        this.uniformScaleGizmo = new AxisScaleGizmo(new Vector3(0, 1, 0), Color3.Yellow().scale(0.5), gizmoLayer, this);
         this.uniformScaleGizmo.updateGizmoRotationToMatchAttachedMesh = false;
         this.uniformScaleGizmo.uniformScaling = true;
-        var uniformScalingMesh = PolyhedronBuilder.CreatePolyhedron("", { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);
-        uniformScalingMesh.scaling.scaleInPlace(0.02);
-        uniformScalingMesh.visibility = 0;
-        var octahedron = PolyhedronBuilder.CreatePolyhedron("", { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);
-        octahedron.scaling.scaleInPlace(0.007);
-        uniformScalingMesh.addChild(octahedron);
-        this.uniformScaleGizmo.setCustomMesh(uniformScalingMesh, true);
+        this._uniformScalingMesh = PolyhedronBuilder.CreatePolyhedron("", { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);
+        this._uniformScalingMesh.scaling.scaleInPlace(0.02);
+        this._uniformScalingMesh.visibility = 0;
+        this._octahedron = PolyhedronBuilder.CreatePolyhedron("", { type: 1 }, this.uniformScaleGizmo.gizmoLayer.utilityLayerScene);
+        this._octahedron.scaling.scaleInPlace(0.007);
+        this._uniformScalingMesh.addChild(this._octahedron);
+        this.uniformScaleGizmo.setCustomMesh(this._uniformScalingMesh, true);
         var light = gizmoLayer._getSharedGizmoLight();
-        light.includedOnlyMeshes = light.includedOnlyMeshes.concat(octahedron);
+        light.includedOnlyMeshes = light.includedOnlyMeshes.concat(this._octahedron);
 
         // Relay drag events
         [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
@@ -86,55 +97,65 @@ export class ScaleGizmo extends Gizmo {
         if (!value) {
             Logger.Warn("Setting updateGizmoRotationToMatchAttachedMesh = false on scaling gizmo is not supported.");
         }
-        if (this.xGizmo) {
-            this.xGizmo.updateGizmoRotationToMatchAttachedMesh = value;
-            this.yGizmo.updateGizmoRotationToMatchAttachedMesh = value;
-            this.zGizmo.updateGizmoRotationToMatchAttachedMesh = value;
+        else {
+            this._updateGizmoRotationToMatchAttachedMesh = value;
+            [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+                if (gizmo) {
+                    gizmo.updateGizmoRotationToMatchAttachedMesh = value;
+                }
+            });
         }
     }
     public get updateGizmoRotationToMatchAttachedMesh() {
-        return this.xGizmo.updateGizmoRotationToMatchAttachedMesh;
+        return this._updateGizmoRotationToMatchAttachedMesh;
     }
 
     /**
      * Drag distance in babylon units that the gizmo will snap to when dragged (Default: 0)
      */
     public set snapDistance(value: number) {
-        if (this.xGizmo) {
-            this.xGizmo.snapDistance = value;
-            this.yGizmo.snapDistance = value;
-            this.zGizmo.snapDistance = value;
-            this.uniformScaleGizmo.snapDistance = value;
-        }
+        this._snapDistance = value;
+        [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+            if (gizmo) {
+                gizmo.snapDistance = value;
+            }
+        });
     }
     public get snapDistance() {
-        return this.xGizmo.snapDistance;
+        return this._snapDistance;
     }
 
     /**
      * Ratio for the scale of the gizmo (Default: 1)
      */
     public set scaleRatio(value: number) {
-        if (this.xGizmo) {
-            this.xGizmo.scaleRatio = value;
-            this.yGizmo.scaleRatio = value;
-            this.zGizmo.scaleRatio = value;
-            this.uniformScaleGizmo.scaleRatio = value;
-        }
+        this._scaleRatio = value;
+        [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+            if (gizmo) {
+                gizmo.scaleRatio = value;
+            }
+        });
     }
     public get scaleRatio() {
-        return this.xGizmo.scaleRatio;
+        return this._scaleRatio;
     }
 
     /**
      * Disposes of the gizmo
      */
     public dispose() {
-        this.xGizmo.dispose();
-        this.yGizmo.dispose();
-        this.zGizmo.dispose();
-        this.uniformScaleGizmo.dispose();
+        [this.xGizmo, this.yGizmo, this.zGizmo, this.uniformScaleGizmo].forEach((gizmo) => {
+            if (gizmo) {
+                gizmo.dispose();
+            }
+        });
         this.onDragStartObservable.clear();
         this.onDragEndObservable.clear();
+
+        [this._uniformScalingMesh, this._octahedron].forEach((msh) => {
+            if (msh) {
+                msh.dispose();
+            }
+        });
     }
 }