|
@@ -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();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|