|
@@ -18,6 +18,7 @@ import { StandardMaterial } from "../Materials/standardMaterial";
|
|
|
import { PivotTools } from "../Misc/pivotTools";
|
|
|
|
|
|
import "../Meshes/Builders/boxBuilder";
|
|
|
+import { LinesMesh } from '../Meshes/linesMesh';
|
|
|
|
|
|
/**
|
|
|
* Bounding box gizmo
|
|
@@ -91,6 +92,22 @@ export class BoundingBoxGizmo extends Gizmo {
|
|
|
private _dragMesh: Nullable<Mesh> = null;
|
|
|
private pointerDragBehavior = new PointerDragBehavior();
|
|
|
|
|
|
+ private coloredMaterial: StandardMaterial;
|
|
|
+ private hoverColoredMaterial: StandardMaterial;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Sets the color of the bounding box gizmo
|
|
|
+ * @param color the color to set
|
|
|
+ */
|
|
|
+ public setColor(color: Color3) {
|
|
|
+ this.coloredMaterial.emissiveColor = color;
|
|
|
+ this.hoverColoredMaterial.emissiveColor = color.clone().add(new Color3(0.3, 0.3, 0.3));
|
|
|
+ this._lineBoundingBox.getChildren().forEach((l) => {
|
|
|
+ if ((l as LinesMesh).color) {
|
|
|
+ (l as LinesMesh).color = color;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
/**
|
|
|
* Creates an BoundingBoxGizmo
|
|
|
* @param gizmoLayer The utility layer the gizmo will be added to
|
|
@@ -104,12 +121,10 @@ export class BoundingBoxGizmo extends Gizmo {
|
|
|
|
|
|
this._anchorMesh = new AbstractMesh("anchor", gizmoLayer.utilityLayerScene);
|
|
|
// Create Materials
|
|
|
- var coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
|
- coloredMaterial.disableLighting = true;
|
|
|
- coloredMaterial.emissiveColor = color;
|
|
|
- var hoverColoredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
|
- hoverColoredMaterial.disableLighting = true;
|
|
|
- hoverColoredMaterial.emissiveColor = color.clone().add(new Color3(0.3, 0.3, 0.3));
|
|
|
+ this.coloredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
|
+ this.coloredMaterial.disableLighting = true;
|
|
|
+ this.hoverColoredMaterial = new StandardMaterial("", gizmoLayer.utilityLayerScene);
|
|
|
+ this.hoverColoredMaterial.disableLighting = true;
|
|
|
|
|
|
// Build bounding box out of lines
|
|
|
this._lineBoundingBox = new AbstractMesh("", gizmoLayer.utilityLayerScene);
|
|
@@ -135,13 +150,15 @@ export class BoundingBoxGizmo extends Gizmo {
|
|
|
});
|
|
|
this._rootMesh.addChild(this._lineBoundingBox);
|
|
|
|
|
|
+ this.setColor(color);
|
|
|
+
|
|
|
// Create rotation spheres
|
|
|
this._rotateSpheresParent = new AbstractMesh("", gizmoLayer.utilityLayerScene);
|
|
|
this._rotateSpheresParent.rotationQuaternion = new Quaternion();
|
|
|
for (let i = 0; i < 12; i++) {
|
|
|
let sphere = SphereBuilder.CreateSphere("", { diameter: 1 }, gizmoLayer.utilityLayerScene);
|
|
|
sphere.rotationQuaternion = new Quaternion();
|
|
|
- sphere.material = coloredMaterial;
|
|
|
+ sphere.material = this.coloredMaterial;
|
|
|
|
|
|
// Drag behavior
|
|
|
var _dragBehavior = new PointerDragBehavior({});
|
|
@@ -230,7 +247,7 @@ export class BoundingBoxGizmo extends Gizmo {
|
|
|
for (var j = 0; j < 2; j++) {
|
|
|
for (var k = 0; k < 2; k++) {
|
|
|
let box = BoxBuilder.CreateBox("", { size: 1 }, gizmoLayer.utilityLayerScene);
|
|
|
- box.material = coloredMaterial;
|
|
|
+ box.material = this.coloredMaterial;
|
|
|
|
|
|
// Dragging logic
|
|
|
let dragAxis = new Vector3(i == 0 ? -1 : 1, j == 0 ? -1 : 1, k == 0 ? -1 : 1);
|
|
@@ -301,12 +318,12 @@ export class BoundingBoxGizmo extends Gizmo {
|
|
|
this._rotateSpheresParent.getChildMeshes().concat(this._scaleBoxesParent.getChildMeshes()).forEach((mesh) => {
|
|
|
if (pointerInfo.pickInfo && pointerInfo.pickInfo.pickedMesh == mesh) {
|
|
|
pointerIds[(<PointerEvent>pointerInfo.event).pointerId] = mesh;
|
|
|
- mesh.material = hoverColoredMaterial;
|
|
|
+ mesh.material = this.hoverColoredMaterial;
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
if (pointerInfo.pickInfo && pointerInfo.pickInfo.pickedMesh != pointerIds[(<PointerEvent>pointerInfo.event).pointerId]) {
|
|
|
- pointerIds[(<PointerEvent>pointerInfo.event).pointerId].material = coloredMaterial;
|
|
|
+ pointerIds[(<PointerEvent>pointerInfo.event).pointerId].material = this.coloredMaterial;
|
|
|
delete pointerIds[(<PointerEvent>pointerInfo.event).pointerId];
|
|
|
}
|
|
|
}
|