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