refactored controllers and diagram manager.
This commit is contained in:
parent
9a9b865843
commit
2d3855621e
@ -192,8 +192,8 @@ export class Base {
|
|||||||
this.grabbedMeshParentId = null;
|
this.grabbedMeshParentId = null;
|
||||||
|
|
||||||
if (!mesh.physicsBody) {
|
if (!mesh.physicsBody) {
|
||||||
mesh.position = snapGridVal(mesh.position, this.diagramManager.config.current.gridSnap);
|
mesh.position = snapGridVal(mesh.position, this.diagramManager._config.current.gridSnap);
|
||||||
mesh.rotation = snapRotateVal(mesh.rotation, this.diagramManager.config.current.rotateSnap);
|
mesh.rotation = snapRotateVal(mesh.rotation, this.diagramManager._config.current.rotateSnap);
|
||||||
}
|
}
|
||||||
this.previousParentId = null;
|
this.previousParentId = null;
|
||||||
this.previousScaling = null;
|
this.previousScaling = null;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export enum ControllerEventType {
|
|||||||
SHOW = 'show',
|
SHOW = 'show',
|
||||||
PULSE = 'pulse',
|
PULSE = 'pulse',
|
||||||
SQUEEZE = 'squeeze',
|
SQUEEZE = 'squeeze',
|
||||||
|
CLICK = 'click',
|
||||||
Y_BUTTON = 'y-button',
|
Y_BUTTON = 'y-button',
|
||||||
X_BUTTON = 'x-button',
|
X_BUTTON = 'x-button',
|
||||||
A_BUTTON = 'a-button',
|
A_BUTTON = 'a-button',
|
||||||
|
|||||||
@ -17,25 +17,25 @@ import {isDiagramEntity} from "./functions/isDiagramEntity";
|
|||||||
|
|
||||||
|
|
||||||
export class DiagramManager {
|
export class DiagramManager {
|
||||||
public readonly onDiagramEventObservable: Observable<DiagramEvent> = new Observable();
|
public readonly _config: AppConfig;
|
||||||
|
private readonly _controllers: Controllers;
|
||||||
|
private readonly diagramEntityActionManager: ActionManager;
|
||||||
|
private presentationManager: PresentationManager;
|
||||||
|
|
||||||
|
public readonly onDiagramEventObservable: Observable<DiagramEvent> = new Observable();
|
||||||
private readonly logger = log.getLogger('DiagramManager');
|
private readonly logger = log.getLogger('DiagramManager');
|
||||||
private readonly toolbox: Toolbox;
|
private readonly toolbox: Toolbox;
|
||||||
private readonly scene: Scene;
|
private readonly scene: Scene;
|
||||||
private readonly sounds: DiaSounds;
|
private readonly sounds: DiaSounds;
|
||||||
private readonly controllers: Controllers;
|
|
||||||
private readonly diagramEntityActionManager: ActionManager;
|
|
||||||
private presentationManager: PresentationManager;
|
|
||||||
public readonly config: AppConfig;
|
|
||||||
|
|
||||||
constructor(scene: Scene, controllers: Controllers, toolbox: Toolbox, config: AppConfig) {
|
constructor(scene: Scene) {
|
||||||
|
this._config = new AppConfig();
|
||||||
|
this._controllers = new Controllers();
|
||||||
this.sounds = new DiaSounds(scene);
|
this.sounds = new DiaSounds(scene);
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.config = config;
|
this.toolbox = new Toolbox(scene);
|
||||||
this.toolbox = toolbox;
|
|
||||||
this.controllers = controllers;
|
|
||||||
this.presentationManager = new PresentationManager(this.scene);
|
this.presentationManager = new PresentationManager(this.scene);
|
||||||
this.diagramEntityActionManager = buildEntityActionManager(this.scene, this.sounds, this.controllers);
|
this.diagramEntityActionManager = buildEntityActionManager(this.scene, this.sounds, this._controllers);
|
||||||
|
|
||||||
if (this.onDiagramEventObservable.hasObservers()) {
|
if (this.onDiagramEventObservable.hasObservers()) {
|
||||||
this.logger.warn("onDiagramEventObservable already has Observers, you should be careful");
|
this.logger.warn("onDiagramEventObservable already has Observers, you should be careful");
|
||||||
@ -67,6 +67,13 @@ export class DiagramManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get controllers(): Controllers {
|
||||||
|
return this._controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get config(): AppConfig {
|
||||||
|
return this._config;
|
||||||
|
}
|
||||||
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
|
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
|
||||||
let newMesh;
|
let newMesh;
|
||||||
if (!mesh.isAnInstance) {
|
if (!mesh.isAnInstance) {
|
||||||
@ -84,10 +91,10 @@ export class DiagramManager {
|
|||||||
} else {
|
} else {
|
||||||
this.logger.error("no rotation quaternion");
|
this.logger.error("no rotation quaternion");
|
||||||
}
|
}
|
||||||
applyScaling(mesh, newMesh, copy, this.config.current?.createSnap);
|
applyScaling(mesh, newMesh, copy, this._config.current?.createSnap);
|
||||||
newMesh.material = mesh.material;
|
newMesh.material = mesh.material;
|
||||||
newMesh.metadata = deepCopy(mesh.metadata);
|
newMesh.metadata = deepCopy(mesh.metadata);
|
||||||
if (this.config.current?.physicsEnabled) {
|
if (this._config.current?.physicsEnabled) {
|
||||||
applyPhysics(this.sounds, newMesh, this.scene);
|
applyPhysics(this.sounds, newMesh, this.scene);
|
||||||
}
|
}
|
||||||
return newMesh;
|
return newMesh;
|
||||||
@ -95,7 +102,7 @@ export class DiagramManager {
|
|||||||
|
|
||||||
private onDiagramEvent(event: DiagramEvent) {
|
private onDiagramEvent(event: DiagramEvent) {
|
||||||
diagramEventHandler(
|
diagramEventHandler(
|
||||||
event, this.scene, this.toolbox, this.config.current.physicsEnabled,
|
event, this.scene, this.toolbox, this._config.current.physicsEnabled,
|
||||||
this.diagramEntityActionManager, this.sounds);
|
this.diagramEntityActionManager, this.sounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,14 +254,14 @@ export class EditMenu extends AbstractMenu {
|
|||||||
const inputTextView = new InputTextView('test', this.xr, this.scene, this.controllers);
|
const inputTextView = new InputTextView('test', this.xr, this.scene, this.controllers);
|
||||||
inputTextView.show();
|
inputTextView.show();
|
||||||
inputTextView.onTextObservable.addOnce((value) => {
|
inputTextView.onTextObservable.addOnce((value) => {
|
||||||
const config = this.diagramManager.config.current;
|
const config = this.diagramManager._config.current;
|
||||||
config.newRelicKey = value.text;
|
config.newRelicKey = value.text;
|
||||||
this.diagramManager.config.current = config;
|
this.diagramManager._config.current = config;
|
||||||
inputTextView.show();
|
inputTextView.show();
|
||||||
inputTextView.onTextObservable.addOnce((value) => {
|
inputTextView.onTextObservable.addOnce((value) => {
|
||||||
const config = this.diagramManager.config.current;
|
const config = this.diagramManager._config.current;
|
||||||
config.newRelicAccount = value.text;
|
config.newRelicAccount = value.text;
|
||||||
this.diagramManager.config.current = config;
|
this.diagramManager._config.current = config;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,6 @@ export class Toolbox {
|
|||||||
private readonly addPanel: StackPanel3D;
|
private readonly addPanel: StackPanel3D;
|
||||||
public readonly colorChangeObservable: Observable<{ oldColor: string, newColor: string }> =
|
public readonly colorChangeObservable: Observable<{ oldColor: string, newColor: string }> =
|
||||||
new Observable<{ oldColor: string; newColor: string }>()
|
new Observable<{ oldColor: string; newColor: string }>()
|
||||||
private handle: Handle;
|
|
||||||
private axes: AxesViewer;
|
private axes: AxesViewer;
|
||||||
|
|
||||||
constructor(scene: Scene) {
|
constructor(scene: Scene) {
|
||||||
@ -32,7 +31,7 @@ export class Toolbox {
|
|||||||
this.manager = new GUI3DManager(scene);
|
this.manager = new GUI3DManager(scene);
|
||||||
this.manager.addControl(this.addPanel);
|
this.manager.addControl(this.addPanel);
|
||||||
this.toolboxBaseNode = new TransformNode("toolbox", this.scene);
|
this.toolboxBaseNode = new TransformNode("toolbox", this.scene);
|
||||||
this.handle = new Handle(this.toolboxBaseNode);
|
new Handle(this.toolboxBaseNode);
|
||||||
this.toolboxBaseNode.position.y = .2;
|
this.toolboxBaseNode.position.y = .2;
|
||||||
//this.toolboxBaseNode.position.z = .05;
|
//this.toolboxBaseNode.position.z = .05;
|
||||||
/**this.axes = new AxesViewer(this.scene);
|
/**this.axes = new AxesViewer(this.scene);
|
||||||
@ -71,7 +70,6 @@ export class Toolbox {
|
|||||||
this.scene.onPointerObservable.add((pointerInfo) => {
|
this.scene.onPointerObservable.add((pointerInfo) => {
|
||||||
if (pointerInfo.type == 1 && pointerInfo.pickInfo.pickedMesh?.metadata?.tool == 'color') {
|
if (pointerInfo.type == 1 && pointerInfo.pickInfo.pickedMesh?.metadata?.tool == 'color') {
|
||||||
if (this.changing) {
|
if (this.changing) {
|
||||||
|
|
||||||
this.colorPicker.setEnabled(true);
|
this.colorPicker.setEnabled(true);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -86,9 +84,7 @@ export class Toolbox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
let initial = true;
|
let initial = true;
|
||||||
for (const c of colors) {
|
for (const c of colors) {
|
||||||
@ -101,9 +97,10 @@ export class Toolbox {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.toolboxBaseNode.parent.setEnabled(false);
|
//this.toolboxBaseNode.parent.setEnabled(false);
|
||||||
setMenuPosition(this.toolboxBaseNode.parent as Mesh, this.scene,
|
setMenuPosition(this.toolboxBaseNode.parent as Mesh, this.scene,
|
||||||
Vector3.Zero());
|
Vector3.Zero());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
26
src/vrApp.ts
26
src/vrApp.ts
@ -1,12 +1,9 @@
|
|||||||
import {Color3, Engine, FreeCamera, Scene, Vector3} from "@babylonjs/core";
|
import {Color3, Engine, FreeCamera, Scene, Vector3} from "@babylonjs/core";
|
||||||
import '@babylonjs/loaders';
|
import '@babylonjs/loaders';
|
||||||
import {DiagramManager} from "./diagram/diagramManager";
|
import {DiagramManager} from "./diagram/diagramManager";
|
||||||
import {Toolbox} from "./toolbox/toolbox";
|
|
||||||
import log, {Logger} from "loglevel";
|
import log, {Logger} from "loglevel";
|
||||||
import {AppConfig} from "./util/appConfig";
|
|
||||||
import {GamepadManager} from "./controllers/gamepadManager";
|
import {GamepadManager} from "./controllers/gamepadManager";
|
||||||
import {CustomEnvironment} from "./util/customEnvironment";
|
import {CustomEnvironment} from "./util/customEnvironment";
|
||||||
import {ControllerEventType, Controllers} from "./controllers/controllers";
|
|
||||||
import {Spinner} from "./util/spinner";
|
import {Spinner} from "./util/spinner";
|
||||||
import {PouchdbPersistenceManager} from "./integration/pouchdbPersistenceManager";
|
import {PouchdbPersistenceManager} from "./integration/pouchdbPersistenceManager";
|
||||||
import {addSceneInspector} from "./util/functions/sceneInspctor";
|
import {addSceneInspector} from "./util/functions/sceneInspctor";
|
||||||
@ -42,17 +39,9 @@ export class VrApp {
|
|||||||
|
|
||||||
const spinner = new Spinner(scene);
|
const spinner = new Spinner(scene);
|
||||||
spinner.show();
|
spinner.show();
|
||||||
const config = new AppConfig();
|
//const config = new AppConfig();
|
||||||
const controllers = new Controllers();
|
|
||||||
const toolbox = new Toolbox(scene);
|
const diagramManager = new DiagramManager(scene);
|
||||||
controllers.controllerObserver.add((evt) => {
|
|
||||||
if (evt.type == ControllerEventType.X_BUTTON) {
|
|
||||||
if (evt.value == 1) {
|
|
||||||
toolbox.toggle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const diagramManager = new DiagramManager(scene, controllers, toolbox, config);
|
|
||||||
const db = new PouchdbPersistenceManager();
|
const db = new PouchdbPersistenceManager();
|
||||||
db.setDiagramManager(diagramManager);
|
db.setDiagramManager(diagramManager);
|
||||||
db.configObserver.add((newConfig) => {
|
db.configObserver.add((newConfig) => {
|
||||||
@ -61,9 +50,9 @@ export class VrApp {
|
|||||||
} else {
|
} else {
|
||||||
const create = document.querySelector('#create');
|
const create = document.querySelector('#create');
|
||||||
}
|
}
|
||||||
config.onConfigChangedObservable.notifyObservers(newConfig, 1);
|
diagramManager.config.onConfigChangedObservable.notifyObservers(newConfig, 1);
|
||||||
});
|
});
|
||||||
config.onConfigChangedObservable.add((newConfig) => {
|
diagramManager.config.onConfigChangedObservable.add((newConfig) => {
|
||||||
db.setConfig(newConfig);
|
db.setConfig(newConfig);
|
||||||
}, 2, false, this);
|
}, 2, false, this);
|
||||||
await db.initialize();
|
await db.initialize();
|
||||||
@ -72,9 +61,9 @@ export class VrApp {
|
|||||||
new Vector3(0, 1.6, 0), scene);
|
new Vector3(0, 1.6, 0), scene);
|
||||||
//camera.setTarget(new Vector3(0, 1.6, -3));
|
//camera.setTarget(new Vector3(0, 1.6, -3));
|
||||||
scene.setActiveCameraByName("Main Camera");
|
scene.setActiveCameraByName("Main Camera");
|
||||||
const environment = new CustomEnvironment(scene, "default", config);
|
const environment = new CustomEnvironment(scene, "default", diagramManager.config);
|
||||||
environment.groundMeshObservable.add((ground) => {
|
environment.groundMeshObservable.add((ground) => {
|
||||||
groundMeshObserver(ground, scene, diagramManager, controllers, spinner);
|
groundMeshObserver(ground, scene, diagramManager, diagramManager.controllers, spinner);
|
||||||
}, -1, false, this);
|
}, -1, false, this);
|
||||||
|
|
||||||
const gamepadManager = new GamepadManager(scene);
|
const gamepadManager = new GamepadManager(scene);
|
||||||
@ -97,7 +86,6 @@ export class VrApp {
|
|||||||
if (i++ % 60 == 0) {
|
if (i++ % 60 == 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
this.logger.info('Render loop started');
|
this.logger.info('Render loop started');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user