refactored menu manager positioning.
This commit is contained in:
parent
8412b6f378
commit
f1d974dd1d
@ -15,7 +15,7 @@ import {MeshConverter} from "../diagram/meshConverter";
|
|||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {InputTextView} from "../information/inputTextView";
|
import {InputTextView} from "../information/inputTextView";
|
||||||
import {DiaSounds} from "../util/diaSounds";
|
import {DiaSounds} from "../util/diaSounds";
|
||||||
import {Cameras} from "../integration/ring/cameras";
|
import {CameraHelper} from "../util/cameraHelper";
|
||||||
|
|
||||||
export class EditMenu {
|
export class EditMenu {
|
||||||
private state: BmenuState = BmenuState.NONE;
|
private state: BmenuState = BmenuState.NONE;
|
||||||
@ -60,7 +60,6 @@ export class EditMenu {
|
|||||||
DiaSounds.instance.exit.play();
|
DiaSounds.instance.exit.play();
|
||||||
this.manager.dispose();
|
this.manager.dispose();
|
||||||
this.manager = null;
|
this.manager = null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DiaSounds.instance.enter.play();
|
DiaSounds.instance.enter.play();
|
||||||
this.manager = new GUI3DManager(this.scene);
|
this.manager = new GUI3DManager(this.scene);
|
||||||
@ -69,15 +68,9 @@ export class EditMenu {
|
|||||||
panel.addControl(this.makeButton("Modify", "modify"));
|
panel.addControl(this.makeButton("Modify", "modify"));
|
||||||
panel.addControl(this.makeButton("Remove", "remove"));
|
panel.addControl(this.makeButton("Remove", "remove"));
|
||||||
panel.addControl(this.makeButton("Add Label", "label"));
|
panel.addControl(this.makeButton("Add Label", "label"));
|
||||||
panel.addControl(this.makeButton("Add Ring Cameras", "addRingCameras"));
|
//panel.addControl(this.makeButton("Add Ring Cameras", "addRingCameras"));
|
||||||
this.manager.controlScaling = .5;
|
this.manager.controlScaling = .5;
|
||||||
const offset = new Vector3(0, -.2, 3);
|
CameraHelper.setMenuPosition(panel.node, this.scene);
|
||||||
offset.applyRotationQuaternionInPlace(this.scene.activeCamera.absoluteRotation);
|
|
||||||
panel.node.position =
|
|
||||||
this.scene.activeCamera.globalPosition.add(offset);
|
|
||||||
panel.node.lookAt(this.scene.activeCamera.globalPosition);
|
|
||||||
panel.node.rotation.y = panel.node.rotation.y + Math.PI;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,49 +106,61 @@ export class EditMenu {
|
|||||||
}
|
}
|
||||||
switch (this.state) {
|
switch (this.state) {
|
||||||
case BmenuState.REMOVING:
|
case BmenuState.REMOVING:
|
||||||
log.debug("removing " + mesh?.id);
|
this.remove(mesh);
|
||||||
const event: DiagramEvent = {
|
|
||||||
type: DiagramEventType.REMOVE,
|
|
||||||
entity:
|
|
||||||
MeshConverter.toDiagramEntity(pointerInfo.pickInfo.pickedMesh)
|
|
||||||
}
|
|
||||||
this.diagramManager.onDiagramEventObservable.notifyObservers(event);
|
|
||||||
break;
|
break;
|
||||||
case BmenuState.MODIFYING:
|
case BmenuState.MODIFYING:
|
||||||
if (mesh.metadata?.template &&
|
this.setModify(mesh);
|
||||||
mesh.parent?.parent?.id != "toolbox") {
|
|
||||||
if (this.gizmoManager.gizmos.boundingBoxGizmo.attachedMesh?.id == mesh.id) {
|
|
||||||
this.gizmoManager.gizmos.boundingBoxGizmo.attachedMesh = null;
|
|
||||||
} else {
|
|
||||||
this.gizmoManager.attachToMesh(mesh);
|
|
||||||
this.gizmoManager.gizmos.boundingBoxGizmo.onScaleBoxDragObservable.add(() => {
|
|
||||||
this.diagramManager.onDiagramEventObservable.notifyObservers({
|
|
||||||
type: DiagramEventType.MODIFY,
|
|
||||||
entity: MeshConverter.toDiagramEntity(mesh),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
log.debug(mesh.scaling);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case BmenuState.LABELING:
|
case BmenuState.LABELING:
|
||||||
log.debug("labeling " + mesh.id);
|
this.setLabeling(mesh);
|
||||||
let text = "";
|
|
||||||
if (mesh?.metadata?.text) {
|
|
||||||
text = mesh.metadata.text;
|
|
||||||
}
|
|
||||||
const textInput = new InputTextView(this.xr.sessionManager, text);
|
|
||||||
textInput.show();
|
|
||||||
textInput.onTextObservable.addOnce((value) => {
|
|
||||||
this.persist(mesh, value.text);
|
|
||||||
MeshConverter.updateTextNode(mesh, value.text);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private remove(mesh: AbstractMesh) {
|
||||||
|
log.debug("removing " + mesh?.id);
|
||||||
|
const event: DiagramEvent = {
|
||||||
|
type: DiagramEventType.REMOVE,
|
||||||
|
entity:
|
||||||
|
MeshConverter.toDiagramEntity(mesh)
|
||||||
|
}
|
||||||
|
this.diagramManager.onDiagramEventObservable.notifyObservers(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setModify(mesh: AbstractMesh) {
|
||||||
|
if (mesh.metadata?.template &&
|
||||||
|
mesh.parent?.parent?.id != "toolbox") {
|
||||||
|
if (this.gizmoManager.gizmos.boundingBoxGizmo.attachedMesh?.id == mesh.id) {
|
||||||
|
this.gizmoManager.gizmos.boundingBoxGizmo.attachedMesh = null;
|
||||||
|
} else {
|
||||||
|
this.gizmoManager.attachToMesh(mesh);
|
||||||
|
this.gizmoManager.gizmos.boundingBoxGizmo.onScaleBoxDragObservable.add(() => {
|
||||||
|
this.diagramManager.onDiagramEventObservable.notifyObservers({
|
||||||
|
type: DiagramEventType.MODIFY,
|
||||||
|
entity: MeshConverter.toDiagramEntity(mesh),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
log.debug(mesh.scaling);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private setLabeling(mesh: AbstractMesh) {
|
||||||
|
log.debug("labeling " + mesh.id);
|
||||||
|
let text = "";
|
||||||
|
if (mesh?.metadata?.text) {
|
||||||
|
text = mesh.metadata.text;
|
||||||
|
}
|
||||||
|
const textInput = new InputTextView(this.xr.sessionManager, text);
|
||||||
|
textInput.show();
|
||||||
|
textInput.onTextObservable.addOnce((value) => {
|
||||||
|
this.persist(mesh, value.text);
|
||||||
|
MeshConverter.updateTextNode(mesh, value.text);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private handleClick(_info, state) {
|
private handleClick(_info, state) {
|
||||||
switch (state.currentTarget.name) {
|
switch (state.currentTarget.name) {
|
||||||
case "modify":
|
case "modify":
|
||||||
@ -167,9 +172,6 @@ export class EditMenu {
|
|||||||
case "label":
|
case "label":
|
||||||
this.state = BmenuState.LABELING;
|
this.state = BmenuState.LABELING;
|
||||||
break;
|
break;
|
||||||
case "addRingCameras":
|
|
||||||
const cameras = new Cameras(this.scene, this.xr.sessionManager);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
log.error("Unknown button");
|
log.error("Unknown button");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import {Scene, Vector3} from "@babylonjs/core";
|
import {Scene, TransformNode, Vector3} from "@babylonjs/core";
|
||||||
|
|
||||||
export class CameraHelper {
|
export class CameraHelper {
|
||||||
public static getFrontPosition(distance: number, scene: Scene): Vector3 {
|
public static getFrontPosition(distance: number, scene: Scene): Vector3 {
|
||||||
@ -6,4 +6,13 @@ export class CameraHelper {
|
|||||||
offset.applyRotationQuaternionInPlace(scene.activeCamera.absoluteRotation);
|
offset.applyRotationQuaternionInPlace(scene.activeCamera.absoluteRotation);
|
||||||
return scene.activeCamera.globalPosition.add(offset);
|
return scene.activeCamera.globalPosition.add(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static setMenuPosition(node: TransformNode, scene: Scene) {
|
||||||
|
node.position =
|
||||||
|
CameraHelper.getFrontPosition(2, scene);
|
||||||
|
node.lookAt(scene.activeCamera.globalPosition);
|
||||||
|
node.rotation.y = node.rotation.y + Math.PI;
|
||||||
|
node.position.y += .2;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user