Removed some unused code. Optimized export bundle.
This commit is contained in:
parent
a2fc7ec460
commit
237b127686
16
src/app.ts
16
src/app.ts
@ -7,17 +7,11 @@ 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 {Controllers} from "./controllers/controllers";
|
import {Controllers} from "./controllers/controllers";
|
||||||
// @ts-ignore
|
|
||||||
import workerUrl from "./worker?worker&url";
|
|
||||||
|
|
||||||
import {PeerjsNetworkConnection} from "./integration/peerjsNetworkConnection";
|
|
||||||
import {DiagramExporter} from "./util/diagramExporter";
|
|
||||||
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";
|
||||||
import {groundMeshObserver} from "./util/functions/groundMeshObserver";
|
import {groundMeshObserver} from "./util/functions/groundMeshObserver";
|
||||||
|
|
||||||
|
|
||||||
export class App {
|
export class App {
|
||||||
//preTasks = [havokModule];
|
//preTasks = [havokModule];
|
||||||
private logger: Logger = log.getLogger('App');
|
private logger: Logger = log.getLogger('App');
|
||||||
@ -28,7 +22,6 @@ export class App {
|
|||||||
|
|
||||||
log.getLogger('App').setLevel('debug');
|
log.getLogger('App').setLevel('debug');
|
||||||
log.getLogger('DiagramManager').setLevel('debug');
|
log.getLogger('DiagramManager').setLevel('debug');
|
||||||
log.getLogger('PeerjsNetworkConnection').setLevel('debug');
|
|
||||||
|
|
||||||
const canvas = document.querySelector('#gameCanvas');
|
const canvas = document.querySelector('#gameCanvas');
|
||||||
|
|
||||||
@ -108,15 +101,6 @@ export class App {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
addSceneInspector(scene);
|
addSceneInspector(scene);
|
||||||
const exportLink = document.querySelector('#downloadLink');
|
|
||||||
if (exportLink) {
|
|
||||||
exportLink.addEventListener('click', (ev) => {
|
|
||||||
ev.preventDefault();
|
|
||||||
const exporter = new DiagramExporter(scene);
|
|
||||||
exporter.exportgltf();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.logger.info('keydown event listener added, use Ctrl+Shift+Alt+I to toggle debug layer');
|
this.logger.info('keydown event listener added, use Ctrl+Shift+Alt+I to toggle debug layer');
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import {
|
|||||||
WebXRInputSource
|
WebXRInputSource
|
||||||
} from "@babylonjs/core";
|
} from "@babylonjs/core";
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
import {DiagramManager} from "../diagram/diagramManager";
|
||||||
import {DiagramEvent, DiagramEventType} from "../diagram/diagramEntity";
|
import {DiagramEvent, DiagramEventType} from "../diagram/types/diagramEntity";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {ControllerEventType, Controllers} from "./controllers";
|
import {ControllerEventType, Controllers} from "./controllers";
|
||||||
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
import {ActionManager, ExecuteCodeAction, PlaySoundAction, Scene} from "@babylonjs/core";
|
|
||||||
import {DiaSounds} from "../util/diaSounds";
|
|
||||||
import {ControllerEventType, Controllers} from "../controllers/controllers";
|
|
||||||
import log from "loglevel";
|
|
||||||
|
|
||||||
export class DiagramEntityActionManager {
|
|
||||||
_actionManager: ActionManager;
|
|
||||||
private readonly logger = log.getLogger('DiagramEntityActionManager');
|
|
||||||
|
|
||||||
constructor(scene: Scene, sounds: DiaSounds, controllers: Controllers) {
|
|
||||||
this._actionManager = new ActionManager(scene);
|
|
||||||
this._actionManager.registerAction(
|
|
||||||
new PlaySoundAction(ActionManager.OnPointerOverTrigger, sounds.tick));
|
|
||||||
this._actionManager.registerAction(
|
|
||||||
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (evt) => {
|
|
||||||
controllers.controllerObserver.notifyObservers({
|
|
||||||
type: ControllerEventType.PULSE,
|
|
||||||
gripId: evt?.additionalData?.pickResult?.gripTransform?.id
|
|
||||||
})
|
|
||||||
this.logger.debug(evt);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get manager() {
|
|
||||||
return this._actionManager;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,18 +1,18 @@
|
|||||||
import {AbstractMesh, Color3, InstancedMesh, Mesh, Observable, Scene} from "@babylonjs/core";
|
import {AbstractMesh, ActionManager, Color3, InstancedMesh, Mesh, Observable, Scene} from "@babylonjs/core";
|
||||||
import {DiagramEvent, DiagramEventType} from "./diagramEntity";
|
import {DiagramEvent, DiagramEventType} from "./types/diagramEntity";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {Controllers} from "../controllers/controllers";
|
import {Controllers} from "../controllers/controllers";
|
||||||
import {DiaSounds} from "../util/diaSounds";
|
import {DiaSounds} from "../util/diaSounds";
|
||||||
import {AppConfig} from "../util/appConfig";
|
import {AppConfig} from "../util/appConfig";
|
||||||
import {Toolbox} from "../toolbox/toolbox";
|
import {Toolbox} from "../toolbox/toolbox";
|
||||||
import {PresentationManager} from "./presentationManager";
|
import {PresentationManager} from "./presentationManager";
|
||||||
import {DiagramEntityActionManager} from "./diagramEntityActionManager";
|
import {diagramEventHandler} from "./functions/diagramEventHandler";
|
||||||
import {diagramEventHandler} from "./diagramEventHandler";
|
|
||||||
import {deepCopy} from "../util/functions/deepCopy";
|
import {deepCopy} from "../util/functions/deepCopy";
|
||||||
import {applyPhysics} from "./functions/diagramShapePhysics";
|
import {applyPhysics} from "./functions/diagramShapePhysics";
|
||||||
import {applyScaling} from "./functions/applyScaling";
|
import {applyScaling} from "./functions/applyScaling";
|
||||||
import {toDiagramEntity} from "./functions/toDiagramEntity";
|
import {toDiagramEntity} from "./functions/toDiagramEntity";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
import {buildEntityActionManager} from "./functions/buildEntityActionManager";
|
||||||
|
|
||||||
|
|
||||||
export class DiagramManager {
|
export class DiagramManager {
|
||||||
@ -22,7 +22,7 @@ export class DiagramManager {
|
|||||||
private readonly scene: Scene;
|
private readonly scene: Scene;
|
||||||
private readonly sounds: DiaSounds;
|
private readonly sounds: DiaSounds;
|
||||||
private readonly controllers: Controllers;
|
private readonly controllers: Controllers;
|
||||||
private readonly diagramEntityActionManager: DiagramEntityActionManager
|
private readonly diagramEntityActionManager: ActionManager;
|
||||||
private presentationManager: PresentationManager;
|
private presentationManager: PresentationManager;
|
||||||
public readonly config: AppConfig;
|
public readonly config: AppConfig;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ export class DiagramManager {
|
|||||||
this.toolbox = toolbox;
|
this.toolbox = toolbox;
|
||||||
this.controllers = controllers;
|
this.controllers = controllers;
|
||||||
this.presentationManager = new PresentationManager(this.scene);
|
this.presentationManager = new PresentationManager(this.scene);
|
||||||
this.diagramEntityActionManager = new DiagramEntityActionManager(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");
|
||||||
@ -80,7 +80,7 @@ export class DiagramManager {
|
|||||||
}
|
}
|
||||||
newMesh.id = 'id' + uuidv4();
|
newMesh.id = 'id' + uuidv4();
|
||||||
|
|
||||||
newMesh.actionManager = this.diagramEntityActionManager.manager;
|
newMesh.actionManager = this.diagramEntityActionManager;
|
||||||
newMesh.position = mesh.absolutePosition.clone();
|
newMesh.position = mesh.absolutePosition.clone();
|
||||||
|
|
||||||
if (mesh.absoluteRotationQuaternion) {
|
if (mesh.absoluteRotationQuaternion) {
|
||||||
@ -107,6 +107,6 @@ 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.manager, this.sounds);
|
this.diagramEntityActionManager, this.sounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
19
src/diagram/functions/buildEntityActionManager.ts
Normal file
19
src/diagram/functions/buildEntityActionManager.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import {ActionManager, ExecuteCodeAction, PlaySoundAction, Scene} from "@babylonjs/core";
|
||||||
|
import {ControllerEventType, Controllers} from "../../controllers/controllers";
|
||||||
|
import {DiaSounds} from "../../util/diaSounds";
|
||||||
|
|
||||||
|
export function buildEntityActionManager(scene: Scene, sounds: DiaSounds, controllers: Controllers) {
|
||||||
|
const actionManager = new ActionManager(scene);
|
||||||
|
actionManager.registerAction(
|
||||||
|
new PlaySoundAction(ActionManager.OnPointerOverTrigger, sounds.tick));
|
||||||
|
actionManager.registerAction(
|
||||||
|
new ExecuteCodeAction(ActionManager.OnPointerOverTrigger, (evt) => {
|
||||||
|
controllers.controllerObserver.notifyObservers({
|
||||||
|
type: ControllerEventType.PULSE,
|
||||||
|
gripId: evt?.additionalData?.pickResult?.gripTransform?.id
|
||||||
|
})
|
||||||
|
this.logger.debug(evt);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return actionManager;
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
import {DiagramEvent, DiagramEventType} from "./diagramEntity";
|
import {DiagramEvent, DiagramEventType} from "../types/diagramEntity";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {applyPhysics} from "./functions/diagramShapePhysics";
|
import {applyPhysics} from "./diagramShapePhysics";
|
||||||
import {ActionManager, PhysicsMotionType, Scene} from "@babylonjs/core";
|
import {ActionManager, PhysicsMotionType, Scene} from "@babylonjs/core";
|
||||||
import {TextLabel} from "./textLabel";
|
import {TextLabel} from "../../objects/textLabel";
|
||||||
import {Toolbox} from "../toolbox/toolbox";
|
import {Toolbox} from "../../toolbox/toolbox";
|
||||||
import {DiaSounds} from "../util/diaSounds";
|
import {DiaSounds} from "../../util/diaSounds";
|
||||||
|
|
||||||
import {fromDiagramEntity} from "./functions/fromDiagramEntity";
|
import {fromDiagramEntity} from "./fromDiagramEntity";
|
||||||
|
|
||||||
|
|
||||||
export function diagramEventHandler(event: DiagramEvent,
|
export function diagramEventHandler(event: DiagramEvent,
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import {DiagramEntity} from "../diagramEntity";
|
import {DiagramEntity} from "../types/diagramEntity";
|
||||||
import {AbstractMesh, Color3, InstancedMesh, Mesh, Quaternion, Scene, StandardMaterial, Vector3} from "@babylonjs/core";
|
import {AbstractMesh, Color3, InstancedMesh, Mesh, Quaternion, Scene, StandardMaterial, Vector3} from "@babylonjs/core";
|
||||||
import {DiagramConnection} from "../diagramConnection";
|
import {DiagramConnection} from "../diagramConnection";
|
||||||
import {TextLabel} from "../textLabel";
|
import {TextLabel} from "../../objects/textLabel";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {AbstractMesh, Vector3} from "@babylonjs/core";
|
import {AbstractMesh, Vector3} from "@babylonjs/core";
|
||||||
import {DiagramEntity} from "../diagramEntity";
|
import {DiagramEntity} from "../types/diagramEntity";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {Color3} from "@babylonjs/core";
|
import {Color3} from "@babylonjs/core";
|
||||||
import {EditMenuState} from "../menus/editMenuState";
|
import {EditMenuState} from "../../menus/editMenuState";
|
||||||
|
|
||||||
export enum DiagramEventType {
|
export enum DiagramEventType {
|
||||||
ADD,
|
ADD,
|
||||||
18
src/diagram/types/diagramListing.ts
Normal file
18
src/diagram/types/diagramListing.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
export enum DiagramListingEventType {
|
||||||
|
GET,
|
||||||
|
ADD,
|
||||||
|
REMOVE,
|
||||||
|
MODIFY
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DiagramListingEvent = {
|
||||||
|
type: DiagramListingEventType;
|
||||||
|
listing: DiagramListing;
|
||||||
|
}
|
||||||
|
export type DiagramListing = {
|
||||||
|
type: DiagramListingEvent;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
sharekey?: string;
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {Color3, Scene, Vector3} from "@babylonjs/core";
|
import {Color3, Scene, Vector3} from "@babylonjs/core";
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
import {DiagramManager} from "../diagram/diagramManager";
|
||||||
import {DiagramEventType} from "../diagram/diagramEntity";
|
import {DiagramEventType} from "../diagram/types/diagramEntity";
|
||||||
|
|
||||||
type DrawIOEntity = {
|
type DrawIOEntity = {
|
||||||
text?: string,
|
text?: string,
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
import {Observable} from "@babylonjs/core";
|
|
||||||
|
|
||||||
export enum NetworkMessageType {
|
|
||||||
DIAGRAM_EVENT = 'diagramEvent',
|
|
||||||
CONNECTION_EVENT = 'connectionEvent',
|
|
||||||
}
|
|
||||||
|
|
||||||
class NetworkMessage {
|
|
||||||
type: NetworkMessageType;
|
|
||||||
data: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface INetworkConnection {
|
|
||||||
onMessageObservable: Observable<NetworkMessage>;
|
|
||||||
|
|
||||||
connect(name: string, room: string);
|
|
||||||
|
|
||||||
disconnect();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
import {Color3, Observable} from "@babylonjs/core";
|
|
||||||
import {DiagramEntity} from "../diagram/diagramEntity";
|
|
||||||
import {AppConfigType} from "../util/appConfigType";
|
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
|
||||||
|
|
||||||
export enum DiagramListingEventType {
|
|
||||||
GET,
|
|
||||||
ADD,
|
|
||||||
REMOVE,
|
|
||||||
MODIFY
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DiagramListingEvent = {
|
|
||||||
type: DiagramListingEventType;
|
|
||||||
listing: DiagramListing;
|
|
||||||
}
|
|
||||||
export type DiagramListing = {
|
|
||||||
type: DiagramListingEvent;
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
description?: string;
|
|
||||||
sharekey?: string;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IPersistenceManager {
|
|
||||||
diagramListingObserver: Observable<DiagramListingEvent>;
|
|
||||||
|
|
||||||
sync();
|
|
||||||
|
|
||||||
addDiagram(diagram: DiagramListing);
|
|
||||||
|
|
||||||
getNewRelicData(): Promise<any[]>;
|
|
||||||
|
|
||||||
setNewRelicData(data: any): Promise<any>;
|
|
||||||
|
|
||||||
removeDiagram(diagram: DiagramListing);
|
|
||||||
|
|
||||||
add(mesh: DiagramEntity);
|
|
||||||
|
|
||||||
remove(id: string);
|
|
||||||
|
|
||||||
modify(mesh: DiagramEntity);
|
|
||||||
|
|
||||||
initialize();
|
|
||||||
|
|
||||||
setConfig(config: AppConfigType);
|
|
||||||
|
|
||||||
getConfig(): Promise<AppConfigType>;
|
|
||||||
|
|
||||||
modifyDiagram(diagram: DiagramListing);
|
|
||||||
|
|
||||||
updateObserver: Observable<DiagramEntity>;
|
|
||||||
configObserver: Observable<AppConfigType>;
|
|
||||||
|
|
||||||
changeColor(oldColor: Color3, newColor: Color3);
|
|
||||||
|
|
||||||
setCurrentDiagram(diagram: DiagramListing);
|
|
||||||
|
|
||||||
setDiagramManager(diagramManager: DiagramManager);
|
|
||||||
}
|
|
||||||
@ -1,201 +0,0 @@
|
|||||||
import {DiagramListing, DiagramListingEvent, DiagramListingEventType, IPersistenceManager} from "./iPersistenceManager";
|
|
||||||
import {Observable} from "@babylonjs/core";
|
|
||||||
import {DiagramEntity} from "../diagram/diagramEntity";
|
|
||||||
import Dexie from "dexie";
|
|
||||||
import log from "loglevel";
|
|
||||||
import {AppConfigType} from "../util/appConfigType";
|
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
|
||||||
|
|
||||||
|
|
||||||
export class IndexdbPersistenceManager implements IPersistenceManager {
|
|
||||||
private readonly logger = log.getLogger('IndexdbPersistenceManager');
|
|
||||||
public readonly diagramListingObserver: Observable<DiagramListingEvent> = new Observable<DiagramListingEvent>();
|
|
||||||
public readonly updateObserver: Observable<DiagramEntity> = new Observable<DiagramEntity>();
|
|
||||||
public readonly configObserver: Observable<AppConfigType> = new Observable<AppConfigType>();
|
|
||||||
private db: Dexie;
|
|
||||||
|
|
||||||
private currentDiagramId: string;
|
|
||||||
|
|
||||||
constructor(name: string) {
|
|
||||||
this.db = new Dexie(name);
|
|
||||||
const version = 7;
|
|
||||||
|
|
||||||
|
|
||||||
this.db.version(version).stores({config: "id,gridSnap,rotateSnap,createSnap"});
|
|
||||||
this.db.version(version).stores({entities: "id,diagramlistingid,position,rotation,last_seen,template,text,scale,color"});
|
|
||||||
this.db.version(version).stores({diagramlisting: "id,name,description,sharekey"});
|
|
||||||
this.db.version(version).stores({newRelicData: "id,priority, incidentId"});
|
|
||||||
this.logger.debug("IndexdbPersistenceManager constructed");
|
|
||||||
}
|
|
||||||
|
|
||||||
public setDiagramManager(diagramManager: DiagramManager) {
|
|
||||||
console.log(diagramManager.config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public setCurrentDiagram(diagram: DiagramListing) {
|
|
||||||
this.currentDiagramId = diagram.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public add(entity: DiagramEntity) {
|
|
||||||
if (!entity) {
|
|
||||||
this.logger.error("Adding null mesh, early return");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
entity.diagramlistingid = this.currentDiagramId;
|
|
||||||
this.db["entities"].add(entity);
|
|
||||||
this.logger.debug('add', entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public addDiagram(diagram: DiagramListing) {
|
|
||||||
this.db["diagramlisting"].add(diagram);
|
|
||||||
const event = {
|
|
||||||
type: DiagramListingEventType.ADD,
|
|
||||||
listing: diagram
|
|
||||||
}
|
|
||||||
this.diagramListingObserver.notifyObservers(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public remove(id: string) {
|
|
||||||
if (!id) {
|
|
||||||
this.logger.error("Removing null mesh, early return");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.db["entities"].delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public setConfig(config: AppConfigType) {
|
|
||||||
config.id = 1;
|
|
||||||
this.db["config"].put(config);
|
|
||||||
this.logger.debug('setConfig', config);
|
|
||||||
this.configObserver.notifyObservers(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeDiagram(diagram: DiagramListing) {
|
|
||||||
this.db["diagramlisting"].delete(diagram.id);
|
|
||||||
const event = {
|
|
||||||
type: DiagramListingEventType.REMOVE,
|
|
||||||
listing: diagram
|
|
||||||
}
|
|
||||||
this.diagramListingObserver.notifyObservers(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
modifyDiagram(diagram: DiagramListing) {
|
|
||||||
this.db["diagramlisting"].update(diagram.id, diagram);
|
|
||||||
const event = {
|
|
||||||
type: DiagramListingEventType.MODIFY,
|
|
||||||
listing: diagram
|
|
||||||
}
|
|
||||||
this.diagramListingObserver.notifyObservers(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async setNewRelicData(data: any[]) {
|
|
||||||
this.db["newRelicData"].clear();
|
|
||||||
data.forEach((d) => {
|
|
||||||
this.db["newRelicData"].add(d);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getNewRelicData(): Promise<any[]> {
|
|
||||||
return this.db["newRelicData"].toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getConfig(): Promise<AppConfigType> {
|
|
||||||
const configs = await this.db['config'].toArray();
|
|
||||||
return configs[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public async initialize() {
|
|
||||||
this.logger.info('initialize', this.db['entities'].length);
|
|
||||||
const configs = await this.db['config'].toArray();
|
|
||||||
const config = configs[0];
|
|
||||||
if (config) {
|
|
||||||
this.logger.debug('initialize config', config);
|
|
||||||
this.configObserver.notifyObservers(config);
|
|
||||||
|
|
||||||
if (config.currentDiagramId) {
|
|
||||||
this.logger.debug('initialize currentDiagramId', config.currentDiagramId);
|
|
||||||
const currentDiagram = await this.db['diagramlisting'].get(config.currentDiagramId);
|
|
||||||
if (currentDiagram) {
|
|
||||||
this.logger.debug('found currentDiagram', currentDiagram);
|
|
||||||
this.currentDiagramId = currentDiagram.id;
|
|
||||||
} else {
|
|
||||||
this.logger.error('could not find currentDiagram', config.currentDiagramId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.logger.warn('no currentDiagramId, using default');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
this.configObserver.notifyObservers(
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
demoCompleted: false,
|
|
||||||
gridSnap: 1,
|
|
||||||
rotateSnap: 0,
|
|
||||||
createSnap: 0,
|
|
||||||
turnSnap: 0,
|
|
||||||
currentDiagramId: null
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.getFilteredEntities().each((e) => {
|
|
||||||
this.logger.debug('adding', e);
|
|
||||||
this.updateObserver.notifyObservers(e);
|
|
||||||
});
|
|
||||||
this.listDiagrams();
|
|
||||||
this.logger.info("initialize finished");
|
|
||||||
}
|
|
||||||
|
|
||||||
public sync() {
|
|
||||||
this.getFilteredEntities().each((e) => {
|
|
||||||
this.logger.debug('adding', e);
|
|
||||||
this.updateObserver.notifyObservers(e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public modify(entity: DiagramEntity) {
|
|
||||||
if (!entity) {
|
|
||||||
this.logger.error("Modifying null mesh, early return");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.db["entities"].update(entity.id, entity);
|
|
||||||
this.logger.debug('modify', entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public changeColor(oldColor, newColor) {
|
|
||||||
if (!oldColor) {
|
|
||||||
if (!newColor) {
|
|
||||||
this.logger.error("changeColor called with no new color, early return");
|
|
||||||
} else {
|
|
||||||
this.logger.info("changeColor called with no old Color, new color added to diagram, early return");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.logger.debug(`changeColor ${oldColor.toHexString()} to ${newColor.toHexString()}`);
|
|
||||||
this.getFilteredEntities().filter((e) => e.color == oldColor.toHexString()).modify({color: newColor.toHexString()});
|
|
||||||
}
|
|
||||||
|
|
||||||
private listDiagrams() {
|
|
||||||
return this.db["diagramlisting"].toArray((diagrams) => {
|
|
||||||
this.logger.debug('listDiagrams', diagrams);
|
|
||||||
for (const diagram of diagrams) {
|
|
||||||
const event = {
|
|
||||||
type: DiagramListingEventType.GET,
|
|
||||||
listing: diagram
|
|
||||||
}
|
|
||||||
this.diagramListingObserver.notifyObservers(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFilteredEntities() {
|
|
||||||
return this.db['entities'].filter((e) => {
|
|
||||||
if (!this.currentDiagramId && !e.diagramlistingid) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return e.diagramlistingid == this.currentDiagramId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
import P2PDataChannel from 'p2p-data-channel';
|
|
||||||
import log from "loglevel";
|
|
||||||
import {Observable} from "@babylonjs/core";
|
|
||||||
import {DiagramEvent} from "../diagram/diagramEntity";
|
|
||||||
|
|
||||||
|
|
||||||
export class PeerjsNetworkConnection {
|
|
||||||
private logger: log.Logger = log.getLogger('PeerjsNetworkConnection');
|
|
||||||
private dataChannel: P2PDataChannel<any>;
|
|
||||||
public readonly connectionObservable: Observable<any> = new Observable<any>;
|
|
||||||
public readonly dataReplicationObservable: Observable<any> = new Observable<any>;
|
|
||||||
public readonly diagramEventObservable: Observable<DiagramEvent> = new Observable<DiagramEvent>;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
const config = {
|
|
||||||
debug: false,
|
|
||||||
dataChannel: 'deepSharedDiagram',
|
|
||||||
connectionTimeout: 5000,
|
|
||||||
pingInterval: 4000,
|
|
||||||
pingTimeout: 8000,
|
|
||||||
logLevel: 'debug',
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const passphrase = window.niceware.generatePassphrase(6).join('-');
|
|
||||||
this.logger.debug('Local Passphrase: ', passphrase);
|
|
||||||
this.dataChannel = new P2PDataChannel(passphrase, config);
|
|
||||||
this.dataChannel.onConnected((peerId) => {
|
|
||||||
this.logger.debug('Connected to ', peerId);
|
|
||||||
this.connectionObservable.notifyObservers(peerId);
|
|
||||||
});
|
|
||||||
this.dataChannel.onMessage((message) => {
|
|
||||||
this.logger.debug(message);
|
|
||||||
if (message.sender !== this.dataChannel.localPeerId) {
|
|
||||||
this.logger.debug(message.payload, ' received from ', message.sender);
|
|
||||||
if (message.payload.request == 'join') {
|
|
||||||
this.dataChannel.send(message.sender, {type: 'join-ack'});
|
|
||||||
this.logger.debug('Join ack sent to ', message.sender);
|
|
||||||
}
|
|
||||||
if (message.payload.diagramEvent) {
|
|
||||||
this.logger.debug('Received diagram event from ', message.sender, message.payload.diagramEvent);
|
|
||||||
this.diagramEventObservable.notifyObservers(message.payload.diagramEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const remote = window.location.pathname.replace('/', '');
|
|
||||||
if (remote && remote.length > 0) {
|
|
||||||
this.connectToRemote(remote);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
const link = 'https://www.oculus.com/open_url/?url=https://cameras.immersiveidea.com/';
|
|
||||||
const linkEl = document.querySelector('#questLaunch a');
|
|
||||||
linkEl.setAttribute('href', link + passphrase);
|
|
||||||
}
|
|
||||||
this.dataReplicationObservable.add((evt) => {
|
|
||||||
this.logger.debug(evt);
|
|
||||||
this.dataChannel.broadcast({diagramEvent: evt});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public connectToRemote(host: string) {
|
|
||||||
this.dataChannel.connect(host).then((peerId) => {
|
|
||||||
this.logger.debug('Broadcasting Join', peerId);
|
|
||||||
this.dataChannel.broadcast({request: 'join'});
|
|
||||||
|
|
||||||
}).catch((err) => {
|
|
||||||
this.logger.error(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,14 +1,14 @@
|
|||||||
import {DiagramListing, DiagramListingEvent, IPersistenceManager} from "./iPersistenceManager";
|
|
||||||
import PouchDB from 'pouchdb';
|
import PouchDB from 'pouchdb';
|
||||||
import {DiagramEntity, DiagramEventType} from "../diagram/diagramEntity";
|
import {DiagramEntity, DiagramEventType} from "../diagram/types/diagramEntity";
|
||||||
import {Color3, Observable} from "@babylonjs/core";
|
import {Color3, Observable} from "@babylonjs/core";
|
||||||
import {AppConfigType} from "../util/appConfigType";
|
import {AppConfigType} from "../util/appConfigType";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
import {DiagramManager} from "../diagram/diagramManager";
|
||||||
import log, {Logger} from "loglevel";
|
import log, {Logger} from "loglevel";
|
||||||
|
import {DiagramListing, DiagramListingEvent} from "../diagram/types/diagramListing";
|
||||||
|
|
||||||
export class PouchdbPersistenceManager implements IPersistenceManager {
|
export class PouchdbPersistenceManager {
|
||||||
configObserver: Observable<AppConfigType> = new Observable<AppConfigType>();
|
configObserver: Observable<AppConfigType> = new Observable<AppConfigType>();
|
||||||
diagramListingObserver: Observable<DiagramListingEvent> = new Observable<DiagramListingEvent>();
|
diagramListingObserver: Observable<DiagramListingEvent> = new Observable<DiagramListingEvent>();
|
||||||
updateObserver: Observable<DiagramEntity> = new Observable<DiagramEntity>();
|
updateObserver: Observable<DiagramEntity> = new Observable<DiagramEntity>();
|
||||||
|
|||||||
@ -14,20 +14,20 @@ import {
|
|||||||
import {GUI3DManager, PlanePanel} from "@babylonjs/gui";
|
import {GUI3DManager, PlanePanel} from "@babylonjs/gui";
|
||||||
import {DiagramManager} from "../diagram/diagramManager";
|
import {DiagramManager} from "../diagram/diagramManager";
|
||||||
import {EditMenuState} from "./editMenuState";
|
import {EditMenuState} from "./editMenuState";
|
||||||
import {DiagramEvent, DiagramEventType} from "../diagram/diagramEntity";
|
import {DiagramEvent, DiagramEventType} from "../diagram/types/diagramEntity";
|
||||||
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 {TextLabel} from "../diagram/textLabel";
|
import {TextLabel} from "../objects/textLabel";
|
||||||
import {DiagramConnection} from "../diagram/diagramConnection";
|
import {DiagramConnection} from "../diagram/diagramConnection";
|
||||||
|
|
||||||
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
||||||
import {AbstractMenu} from "./abstractMenu";
|
import {AbstractMenu} from "./abstractMenu";
|
||||||
import {Controllers} from "../controllers/controllers";
|
import {Controllers} from "../controllers/controllers";
|
||||||
import {setMenuPosition} from "../util/functions/setMenuPosition";
|
import {setMenuPosition} from "../util/functions/setMenuPosition";
|
||||||
import {DiagramExporter} from "../util/diagramExporter";
|
|
||||||
import {SoccerMenu} from "../soccer/soccerMenu";
|
import {SoccerMenu} from "../soccer/soccerMenu";
|
||||||
import {CameraMenu} from "./cameraMenu";
|
import {CameraMenu} from "./cameraMenu";
|
||||||
|
import {exportGltf} from "../util/functions/exportGltf";
|
||||||
|
|
||||||
export class EditMenu extends AbstractMenu {
|
export class EditMenu extends AbstractMenu {
|
||||||
private state: EditMenuState = EditMenuState.NONE;
|
private state: EditMenuState = EditMenuState.NONE;
|
||||||
@ -332,7 +332,6 @@ export class EditMenu extends AbstractMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private downloadgltf() {
|
private downloadgltf() {
|
||||||
const exporter = new DiagramExporter(this.scene);
|
exportGltf(this.scene);
|
||||||
exporter.exportgltf();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
import {IPersistenceManager} from "../integration/iPersistenceManager";
|
|
||||||
import {
|
import {
|
||||||
AbstractMesh,
|
AbstractMesh,
|
||||||
Color3,
|
Color3,
|
||||||
@ -9,16 +8,17 @@ import {
|
|||||||
StandardMaterial,
|
StandardMaterial,
|
||||||
Vector3
|
Vector3
|
||||||
} from "@babylonjs/core";
|
} from "@babylonjs/core";
|
||||||
|
import {PouchdbPersistenceManager} from "../integration/pouchdbPersistenceManager";
|
||||||
|
|
||||||
export class NewRelicData {
|
export class NewRelicData {
|
||||||
private key: string;
|
private key: string;
|
||||||
private account: string;
|
private account: string;
|
||||||
private data: any[];
|
private data: any[];
|
||||||
private readonly scene: Scene;
|
private readonly scene: Scene;
|
||||||
private persistenceManager: IPersistenceManager;
|
private persistenceManager: PouchdbPersistenceManager;
|
||||||
private policyLabels: AbstractMesh[] = [];
|
private policyLabels: AbstractMesh[] = [];
|
||||||
|
|
||||||
constructor(persistenceManager: IPersistenceManager, scene: Scene) {
|
constructor(persistenceManager: PouchdbPersistenceManager, scene: Scene) {
|
||||||
this.persistenceManager = persistenceManager;
|
this.persistenceManager = persistenceManager;
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.persistenceManager.getNewRelicData()
|
this.persistenceManager.getNewRelicData()
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
import {RingApi} from "ring-client-api";
|
|
||||||
|
|
||||||
export class RingCamera {
|
|
||||||
private ringApi: RingApi;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.ringApi = new RingApi({
|
|
||||||
refreshToken: process.env.RING_TOKEN,
|
|
||||||
cameraStatusPollingSeconds: 30,
|
|
||||||
debug: true
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async getCameras() {
|
|
||||||
const cams = await this.ringApi.getCameras();
|
|
||||||
const camid = cams.map((value) => value.id);
|
|
||||||
return cams;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
13
src/util/functions/exportGltf.ts
Normal file
13
src/util/functions/exportGltf.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import {Scene} from "@babylonjs/core";
|
||||||
|
|
||||||
|
export function exportGltf(scene: Scene) {
|
||||||
|
import("@babylonjs/serializers").then((serializers) => {
|
||||||
|
serializers.GLTF2Export.GLBAsync(scene, 'diagram.glb', {
|
||||||
|
shouldExportNode: function (node) {
|
||||||
|
return (node?.metadata?.exportable as boolean);
|
||||||
|
}
|
||||||
|
}).then((gltf) => {
|
||||||
|
gltf.downloadFiles();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -1,51 +0,0 @@
|
|||||||
import {IndexdbPersistenceManager} from "./integration/indexdbPersistenceManager";
|
|
||||||
import {DiagramEvent, DiagramEventType} from "./diagram/diagramEntity";
|
|
||||||
|
|
||||||
const persistenceManager = new IndexdbPersistenceManager("diagram");
|
|
||||||
|
|
||||||
const ctx: Worker = self as any;
|
|
||||||
|
|
||||||
|
|
||||||
ctx.onmessage = (event) => {
|
|
||||||
console.log(event);
|
|
||||||
if (event.data.type == 'sync') {
|
|
||||||
persistenceManager.sync();
|
|
||||||
}
|
|
||||||
if (event.data.type == 'init') {
|
|
||||||
persistenceManager.updateObserver.add((event) => {
|
|
||||||
console.log(event);
|
|
||||||
ctx.postMessage({entity: event});
|
|
||||||
});
|
|
||||||
persistenceManager.configObserver.add((event) => {
|
|
||||||
console.log(event);
|
|
||||||
ctx.postMessage({config: event});
|
|
||||||
});
|
|
||||||
persistenceManager.initialize().then(() => {
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (event.data.entity) {
|
|
||||||
console.log(event.data);
|
|
||||||
const data = (event.data.entity as DiagramEvent);
|
|
||||||
switch (data.type) {
|
|
||||||
case DiagramEventType.ADD:
|
|
||||||
persistenceManager.add(data.entity);
|
|
||||||
break;
|
|
||||||
case DiagramEventType.DROP:
|
|
||||||
case DiagramEventType.MODIFY:
|
|
||||||
persistenceManager.modify(data.entity);
|
|
||||||
break;
|
|
||||||
case DiagramEventType.REMOVE:
|
|
||||||
persistenceManager.remove(data.entity.id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event.data.config) {
|
|
||||||
|
|
||||||
persistenceManager.setConfig(event.data.config);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue
Block a user