diff --git a/src/controllers/base.ts b/src/controllers/base.ts index 6fbc589..71142c4 100644 --- a/src/controllers/base.ts +++ b/src/controllers/base.ts @@ -30,7 +30,7 @@ import {pointable} from "./functions/pointable"; import {DefaultScene} from "../defaultScene"; const CLICK_TIME = 300; -const logger = log.getLogger('Base'); + export class Base { static stickVector = Vector3.Zero(); @@ -50,10 +50,11 @@ export class Base { protected controllers: Controllers; private clickMenu: ClickMenu; private pickPoint: Vector3 = new Vector3(); - + private logger = log.getLogger('Base'); constructor(controller: WebXRInputSource, xr: WebXRDefaultExperience, diagramManager: DiagramManager) { + this.logger.debug('Base Controller Constructor called'); this.xrInputSource = controller; this.controllers = diagramManager.controllers; this.scene = DefaultScene.Scene; @@ -61,7 +62,7 @@ export class Base { this.scene.onPointerObservable.add((pointerInfo) => { if (pointerInfo.pickInfo.pickedMesh?.metadata?.template) { const mesh = pointerInfo.pickInfo.pickedMesh; - const pos = mesh.absolutePosition; + //const pos = mesh.absolutePosition; this.pickPoint.copyFrom(pointerInfo.pickInfo.pickedPoint); } @@ -72,13 +73,13 @@ export class Base { //@TODO THis works, but it uses initGrip, not sure if this is the best idea this.xrInputSource.onMotionControllerInitObservable.add(motionControllerObserver, -1, false, this); this.controllers.controllerObservable.add((event) => { - logger.debug(event); + this.logger.debug(event); switch (event.type) { case ControllerEventType.PULSE: if (event.gripId == this?.xrInputSource?.grip?.id) { this.xrInputSource?.motionController?.pulse(.25, 30) .then(() => { - logger.debug("pulse done"); + this.logger.debug("pulse done"); }); } break; @@ -105,7 +106,7 @@ export class Base { } protected initClicker(trigger: WebXRControllerComponent) { - logger.debug("initTrigger"); + this.logger.debug("initTrigger"); trigger.onButtonStateChangedObservable.add(() => { if (trigger.changes.pressed) { if (trigger.pressed) { @@ -113,7 +114,7 @@ export class Base { this.clickStart = Date.now(); window.setTimeout(() => { if (this.clickStart > 0) { - logger.debug("grabbing and cloning"); + this.logger.debug("grabbing and cloning"); this.grab(true); } }, 300, this); @@ -160,7 +161,7 @@ export class Base { } this.previousParentId = mesh?.parent?.id; - logger.warn("grabbed " + mesh?.id + " parent " + this.previousParentId); + this.logger.warn("grabbed " + mesh?.id + " parent " + this.previousParentId); this.previousRotation = mesh?.rotation.clone(); this.previousScaling = mesh?.scaling.clone(); this.previousPosition = mesh?.position.clone(); @@ -175,7 +176,7 @@ export class Base { } this.grabbedMesh = mesh; } else { - logger.debug("cloning " + mesh?.id); + this.logger.debug("cloning " + mesh?.id); const clone = grabAndClone(this.diagramManager, mesh, this.xrInputSource.motionController.rootMesh); clone.newMesh.metadata.grabClone = false; clone.newMesh.metadata.tool = false; @@ -233,12 +234,12 @@ export class Base { const body = mesh?.physicsBody; if (body) { body.setMotionType(PhysicsMotionType.DYNAMIC); - logger.debug(body.transformNode.absolutePosition); - logger.debug(this.lastPosition); + this.logger.debug(body.transformNode.absolutePosition); + this.logger.debug(this.lastPosition); if (this.lastPosition) { body.setLinearVelocity(body.transformNode.absolutePosition.subtract(this.lastPosition).scale(20)); //body.setLinearVelocity(this.lastPosition.subtract(body.transformNode.absolutePosition).scale(20)); - logger.debug(this.lastPosition.subtract(body.transformNode.absolutePosition).scale(20)); + this.logger.debug(this.lastPosition.subtract(body.transformNode.absolutePosition).scale(20)); } } this.diagramManager.onDiagramEventObservable.notifyObservers(event, DiagramEventObserverMask.ALL); @@ -247,7 +248,7 @@ export class Base { private click() { let mesh = this.xr.pointerSelection.getMeshUnderPointer(this.xrInputSource.uniqueId); if (pointable(mesh)) { - logger.debug("click on " + mesh.id); + this.logger.debug("click on " + mesh.id); if (this.clickMenu && !this.clickMenu.isDisposed) { if (this.clickMenu.isConnecting) { this.clickMenu.connect(mesh); @@ -258,7 +259,7 @@ export class Base { } } else { - logger.debug("click on nothing"); + this.logger.debug("click on nothing"); } diff --git a/src/controllers/functions/beforeRenderObserver.ts b/src/controllers/functions/beforeRenderObserver.ts index 03b79f0..4895520 100644 --- a/src/controllers/functions/beforeRenderObserver.ts +++ b/src/controllers/functions/beforeRenderObserver.ts @@ -1,7 +1,10 @@ import {HavokPlugin} from "@babylonjs/core"; import {DefaultScene} from "../../defaultScene"; +import log from "loglevel"; + export function beforeRenderObserver() { + const logger = log.getLogger('beforeRenderObserver'); if (this?.grabbedMesh?.physicsBody) { const scene = DefaultScene.Scene; const hk = (scene.getPhysicsEngine().getPhysicsPlugin() as HavokPlugin); @@ -12,11 +15,11 @@ export function beforeRenderObserver() { hk.setPhysicsBodyTransformation(this.grabbedMesh.physicsBody, parent); hk.sync(this.grabbedMesh.physicsBody); } else { - this.logger.error("parent not found for " + this.grabbedMeshParentId); + logger.error("parent not found for " + this.grabbedMeshParentId); } } else { - this.logger.warn("no parent id"); + logger.warn("no parent id"); } } diff --git a/src/controllers/functions/handleWasGrabbed.ts b/src/controllers/functions/handleWasGrabbed.ts index 67330e5..7b2fca3 100644 --- a/src/controllers/functions/handleWasGrabbed.ts +++ b/src/controllers/functions/handleWasGrabbed.ts @@ -1,10 +1,16 @@ import {AbstractMesh} from "@babylonjs/core"; import {isDiagramEntity} from "../../diagram/functions/isDiagramEntity"; +import log from "loglevel"; export function handleWasGrabbed(mesh: AbstractMesh): boolean { + const logger = log.getLogger("handleWasGrabbed"); if (isDiagramEntity(mesh)) { + logger.debug("handleWasGrabbed: mesh is a diagram entity"); return false; } else { - return (mesh?.metadata?.handle == true); + + const result = (mesh?.metadata?.handle == true); + logger.debug("handleWasGrabbed: mesh ", result); + return result; } } \ No newline at end of file diff --git a/src/controllers/functions/motionControllerObserver.ts b/src/controllers/functions/motionControllerObserver.ts index 2115f63..4a31324 100644 --- a/src/controllers/functions/motionControllerObserver.ts +++ b/src/controllers/functions/motionControllerObserver.ts @@ -1,7 +1,8 @@ import log from "loglevel"; -const logger = log.getLogger('motionControllerObserver'); + export function motionControllerObserver(init) { + const logger = log.getLogger('motionControllerObserver'); logger.debug(init.components); if (init.components['xr-standard-squeeze']) { this.initGrip(init.components['xr-standard-squeeze']) diff --git a/src/controllers/functions/reparent.ts b/src/controllers/functions/reparent.ts index f18c3c5..aea21fb 100644 --- a/src/controllers/functions/reparent.ts +++ b/src/controllers/functions/reparent.ts @@ -1,9 +1,9 @@ import {AbstractMesh} from "@babylonjs/core"; import log from "loglevel"; -const logger = log.getLogger('reparent'); export function reparent(mesh: AbstractMesh, previousParentId: string, grabbedMeshParentId: string) { + const logger = log.getLogger('reparent'); if (previousParentId) { const parent = mesh.getScene().getMeshById(previousParentId); if (parent) { diff --git a/src/controllers/left.ts b/src/controllers/left.ts index 4b2d2d8..0cf4240 100644 --- a/src/controllers/left.ts +++ b/src/controllers/left.ts @@ -5,8 +5,9 @@ import log from "loglevel"; import {DiagramManager} from "../diagram/diagramManager"; import {DefaultScene} from "../defaultScene"; -const logger = log.getLogger('Left'); + export class Left extends Base { + private leftLogger = log.getLogger('Left'); constructor(controller: WebXRInputSource, xr: WebXRDefaultExperience, diagramManager: DiagramManager) { super(controller, xr, diagramManager); @@ -15,7 +16,7 @@ export class Left extends Base { if (init.components['xr-standard-thumbstick']) { init.components['xr-standard-thumbstick'] .onAxisValueChangedObservable.add((value) => { - logger.trace(`thumbstick moved ${value.x}, ${value.y}`); + this.leftLogger.trace(`thumbstick moved ${value.x}, ${value.y}`); if (!this.controllers.movable) { this.moveRig(value); } else { @@ -27,7 +28,7 @@ export class Left extends Base { this.initTrigger(init.components['xr-standard-trigger']); init.components['xr-standard-thumbstick'].onButtonStateChangedObservable.add((value) => { if (value.pressed) { - logger.trace('Left', 'thumbstick changed'); + this.leftLogger.trace('Left', 'thumbstick changed'); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.DECREASE_VELOCITY, value: value.value @@ -44,7 +45,7 @@ export class Left extends Base { trigger .onButtonStateChangedObservable .add((button) => { - logger.trace('trigger pressed'); + this.leftLogger.trace('trigger pressed'); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.TRIGGER, value: button.value, @@ -58,7 +59,7 @@ export class Left extends Base { if (xbutton) { xbutton.onButtonStateChangedObservable.add((button) => { if (button.pressed) { - logger.trace('X button pressed'); + this.leftLogger.trace('X button pressed'); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.X_BUTTON, value: button.value @@ -72,7 +73,7 @@ export class Left extends Base { if (ybutton) { ybutton.onButtonStateChangedObservable.add((button) => { if (button.pressed) { - logger.trace('Y button pressed'); + this.leftLogger.trace('Y button pressed'); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.Y_BUTTON, value: button.value diff --git a/src/controllers/right.ts b/src/controllers/right.ts index b11e531..174660b 100644 --- a/src/controllers/right.ts +++ b/src/controllers/right.ts @@ -6,16 +6,16 @@ import {DiagramManager} from "../diagram/diagramManager"; import log from "loglevel"; import {DefaultScene} from "../defaultScene"; -const logger = log.getLogger("Right"); + export class Right extends Base { private startPosition: Vector3 = null; - + private rightLogger = log.getLogger("Right"); private initBButton(bbutton: WebXRControllerComponent) { if (bbutton) { bbutton.onButtonStateChangedObservable.add((button) => { if (button.pressed) { - logger.debug('B Button Pressed'); + this.rightLogger.debug('B Button Pressed'); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.B_BUTTON, value: button.value @@ -49,7 +49,7 @@ export class Right extends Base { trigger .onButtonStateChangedObservable .add((button) => { - logger.debug("right trigger pressed"); + this.rightLogger.debug("right trigger pressed"); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.TRIGGER, value: button.value, @@ -63,7 +63,7 @@ export class Right extends Base { if (abutton) { abutton.onButtonStateChangedObservable.add((value) => { if (value.pressed) { - logger.debug('A button pressed'); + this.rightLogger.debug('A button pressed'); this.controllers.controllerObservable.notifyObservers({type: ControllerEventType.MENU}); } }); @@ -73,12 +73,12 @@ export class Right extends Base { private initThumbstick(thumbstick: WebXRControllerComponent) { if (thumbstick) { thumbstick.onAxisValueChangedObservable.add((value) => { - logger.trace(`thumbstick moved ${value.x}, ${value.y}`); + this.rightLogger.trace(`thumbstick moved ${value.x}, ${value.y}`); this.moveRig(value); }); thumbstick.onButtonStateChangedObservable.add((value) => { if (value.pressed) { - logger.trace('Right', `thumbstick changed ${value.value}`); + this.rightLogger.trace('Right', `thumbstick changed ${value.value}`); this.controllers.controllerObservable.notifyObservers({ type: ControllerEventType.INCREASE_VELOCITY, value: value.value diff --git a/src/controllers/rigplatform.ts b/src/controllers/rigplatform.ts index 73f6597..d11d716 100644 --- a/src/controllers/rigplatform.ts +++ b/src/controllers/rigplatform.ts @@ -10,9 +10,10 @@ import {DefaultScene} from "../defaultScene"; const RIGHT = "right"; const LEFT = "left"; -const logger = log.getLogger('Rigplatform'); + export class Rigplatform { + private logger = log.getLogger('Rigplatform'); private readonly controllers: Controllers; private readonly diagramManager: DiagramManager; private readonly scene: Scene; @@ -55,10 +56,10 @@ export class Rigplatform { this._flyMode = value; if (this._flyMode) { this.rigMesh.physicsBody.setGravityFactor(.01); - logger.debug('flymode'); + this.logger.debug('flymode'); } else { this.rigMesh.physicsBody.setGravityFactor(1); - logger.debug('walkmode'); + this.logger.debug('walkmode'); } } @@ -104,7 +105,7 @@ export class Rigplatform { vel.y = 0; } if (vel.length() > 0) { - logger.debug('Velocity', this.velocity, vel, this.scene.activeCamera.absoluteRotation); + this.logger.debug('Velocity', this.velocity, vel, this.scene.activeCamera.absoluteRotation); } this.rigMesh.physicsBody.setLinearVelocity(vel); }); @@ -114,7 +115,7 @@ export class Rigplatform { if (!this.registered) { this.registered = true; this.controllers.controllerObservable.add((event: ControllerEvent) => { - logger.debug(event); + this.logger.debug(event); switch (event.type) { case ControllerEventType.INCREASE_VELOCITY: if (this.velocityIndex < this.velocityArray.length - 1) { @@ -145,7 +146,7 @@ export class Rigplatform { } break; case ControllerEventType.MOTION: - logger.debug(JSON.stringify(event)); + this.logger.debug(JSON.stringify(event)); break; } }); diff --git a/src/defaultScene.ts b/src/defaultScene.ts index 056d61a..2e53d07 100644 --- a/src/defaultScene.ts +++ b/src/defaultScene.ts @@ -1,12 +1,13 @@ import {Engine, Scene} from "@babylonjs/core"; import log from "loglevel"; -const logger = log.getLogger('DefaultScene'); + export class DefaultScene { private static _Scene: Scene; public static get Scene(): Scene { if (!DefaultScene._Scene) { + const logger = log.getLogger('DefaultScene'); logger.error('default scene not yet created'); if (Engine.LastCreatedScene) { logger.warn('using last created scene, this may not be what you want, proceed with caution'); @@ -21,6 +22,7 @@ export class DefaultScene { } public static set Scene(scene: Scene) { + const logger = log.getLogger('DefaultScene'); if (DefaultScene._Scene) { logger.error('default scene already created, disposing and recreating'); if (DefaultScene._Scene.isDisposed) { diff --git a/src/diagram/diagramConnection.ts b/src/diagram/diagramConnection.ts index bdf0d74..200f540 100644 --- a/src/diagram/diagramConnection.ts +++ b/src/diagram/diagramConnection.ts @@ -3,14 +3,13 @@ import {v4 as uuidv4} from 'uuid'; import log, {Logger} from "loglevel"; import {buildStandardMaterial} from "../materials/functions/buildStandardMaterial"; -const logger: Logger = log.getLogger('DiagramConnection'); export class DiagramConnection { private readonly id: string; - + private logger: Logger = log.getLogger('DiagramConnection'); constructor(from: string, to: string, id: string, scene?: Scene, gripTransform?: TransformNode, clickPoint?: Vector3) { - logger.debug('buildConnection constructor'); + this.logger.debug('buildConnection constructor'); if (id) { this.id = id; } else { @@ -46,7 +45,7 @@ export class DiagramConnection { this.toAnchor = to; } else { - logger.info("no fromMesh yet, will build when toMesh is available"); + this.logger.info("no fromMesh yet, will build when toMesh is available"); } } this.buildConnection(); @@ -127,7 +126,7 @@ export class DiagramConnection { } private buildConnection() { - logger.debug(`buildConnection from ${this._from} to ${this._to}`); + this.logger.debug(`buildConnection from ${this._from} to ${this._to}`); this._mesh = MeshBuilder.CreateCylinder(this.id + "_connection", {diameter: .025, height: 1}, this.scene); this.transformNode = new TransformNode(this.id + "_transform", this.scene); this.transformNode.metadata = {exportable: true}; @@ -159,7 +158,7 @@ export class DiagramConnection { } } private removeConnection = () => { - logger.debug("removeConnection"); + this.logger.debug("removeConnection"); this.scene.onBeforeRenderObservable.removeCallback(this.beforeRender); this._mesh.onDisposeObservable.removeCallback(this.removeConnection); this.removeObserver(); @@ -181,17 +180,17 @@ export class DiagramConnection { if (mesh && mesh.id) { if (!this.toAnchor || !this.fromAnchor) { if (mesh?.id == this?._to) { - logger.debug("Found to anchor"); + this.logger.debug("Found to anchor"); this.toAnchor = mesh; this._mesh.metadata.to = this.to; } if (mesh?.id == this?._from) { - logger.debug("Found from anchor"); + this.logger.debug("Found from anchor"); this.fromAnchor = mesh; this._mesh.metadata.from = this.from; } if (this.toAnchor && this.fromAnchor) { - logger.debug(`connection built from ${this._from} to ${this._to}`); + this.logger.debug(`connection built from ${this._from} to ${this._to}`); this.removeObserver(); } } @@ -199,7 +198,7 @@ export class DiagramConnection { } private removeObserver() { - logger.debug("removing observer"); + this.logger.debug("removing observer"); this.scene.onNewMeshAddedObservable.removeCallback(this.onMeshAdded); } } diff --git a/src/diagram/diagramManager.ts b/src/diagram/diagramManager.ts index b9ac895..943a006 100644 --- a/src/diagram/diagramManager.ts +++ b/src/diagram/diagramManager.ts @@ -15,13 +15,14 @@ import {DefaultScene} from "../defaultScene"; import {DiagramMenuManager} from "./diagramMenuManager"; import {ClickMenu} from "../menus/clickMenu"; -const logger = log.getLogger('DiagramManager'); + export enum DiagramEventObserverMask { ALL = -1, FROM_DB = 1, TO_DB = 2, } export class DiagramManager { + private logger = log.getLogger('DiagramManager'); public readonly _config: AppConfig; private readonly _controllers: Controllers; private readonly _diagramEntityActionManager: ActionManager; @@ -36,7 +37,7 @@ export class DiagramManager { this._diagramMenuManager = new DiagramMenuManager(this.onDiagramEventObservable, this._controllers, this._config); this._diagramEntityActionManager = buildEntityActionManager(this._controllers); this.onDiagramEventObservable.add(this.onDiagramEvent, DiagramEventObserverMask.FROM_DB, true, this); - logger.debug("DiagramManager constructed"); + this.logger.debug("DiagramManager constructed"); this._scene.onMeshRemovedObservable.add((mesh) => { if (isDiagramEntity(mesh)) { this.cleanupOrphanConnections(mesh) @@ -74,7 +75,7 @@ export class DiagramManager { if (mesh.absoluteRotationQuaternion) { newMesh.rotation = mesh.absoluteRotationQuaternion.toEulerAngles().clone(); } else { - logger.error("no rotation quaternion"); + this.logger.error("no rotation quaternion"); } applyScaling(mesh, newMesh, copy, this._config.current?.createSnap); newMesh.material = mesh.material; @@ -92,7 +93,7 @@ export class DiagramManager { if (mesh.metadata.template != '#connection-template') { this._scene.meshes.forEach((m) => { if (m?.metadata?.to == mesh.id || m?.metadata?.from == mesh.id) { - logger.debug("removing connection", m.id); + this.logger.debug("removing connection", m.id); this.notifyAll({type: DiagramEventType.REMOVE, entity: toDiagramEntity(m)}); } }); diff --git a/src/diagram/diagramMenuManager.ts b/src/diagram/diagramMenuManager.ts index 1e2c98f..80cb22f 100644 --- a/src/diagram/diagramMenuManager.ts +++ b/src/diagram/diagramMenuManager.ts @@ -12,7 +12,6 @@ import {ClickMenu} from "../menus/clickMenu"; import {ConfigMenu} from "../menus/configMenu"; import {AppConfig} from "../util/appConfig"; -const logger = log.getLogger('DiagramMenuManager'); export class DiagramMenuManager { public readonly toolbox: Toolbox; @@ -21,7 +20,7 @@ export class DiagramMenuManager { private readonly _notifier: Observable; private readonly _inputTextView: InputTextView; private readonly _scene: Scene; - + private logger = log.getLogger('DiagramMenuManager'); constructor(notifier: Observable, controllers: Controllers, config: AppConfig) { this._scene = DefaultScene.Scene; @@ -36,7 +35,7 @@ export class DiagramMenuManager { entity.text = evt.text; this.notifyAll({type: DiagramEventType.MODIFY, entity: entity}); } else { - logger.error("mesh not found", evt.id); + this.logger.error("mesh not found", evt.id); } }); this.toolbox = new Toolbox(); diff --git a/src/diagram/functions/buildMeshFromDiagramEntity.ts b/src/diagram/functions/buildMeshFromDiagramEntity.ts index 3c8d3f5..8958835 100644 --- a/src/diagram/functions/buildMeshFromDiagramEntity.ts +++ b/src/diagram/functions/buildMeshFromDiagramEntity.ts @@ -6,9 +6,9 @@ import log from "loglevel"; import {v4 as uuidv4} from 'uuid'; import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial"; -const logger = log.getLogger('buildMeshFromDiagramEntity'); export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh { + const logger = log.getLogger('buildMeshFromDiagramEntity'); if (!entity) { logger.error("buildMeshFromDiagramEntity: entity is null"); return null; @@ -26,6 +26,7 @@ export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): } function createNewInstanceIfNecessary(entity: DiagramEntity, scene: Scene): AbstractMesh { + const logger = log.getLogger('createNewInstanceIfNecessary'); const oldMesh: AbstractMesh = scene.getMeshById(entity.id); let newMesh: AbstractMesh; if (oldMesh) { @@ -58,6 +59,7 @@ function generateId(entity: DiagramEntity) { } function mapMetadata(entity: DiagramEntity, newMesh: AbstractMesh, scene: Scene): AbstractMesh { + const logger = log.getLogger('mapMetaqdata'); if (newMesh) { if (!newMesh.metadata) { newMesh.metadata = {}; diff --git a/src/diagram/functions/diagramShapePhysics.ts b/src/diagram/functions/diagramShapePhysics.ts index 6739a0b..19d05a1 100644 --- a/src/diagram/functions/diagramShapePhysics.ts +++ b/src/diagram/functions/diagramShapePhysics.ts @@ -2,13 +2,14 @@ import {AbstractMesh, PhysicsAggregate, PhysicsBody, PhysicsMotionType, PhysicsS import log from "loglevel"; import {isDiagramEntity} from "./isDiagramEntity"; -const logger = log.getLogger('DiagramShapePhysics'); + const MASS_FACTOR = 10; export function applyPhysics( mesh: AbstractMesh, scene: Scene, motionType?: PhysicsMotionType) { + const logger = log.getLogger('DiagramShapePhysics'); if (!isDiagramEntity(mesh)) { logger.error("applyPhysics: mesh.metadata.template is null", mesh); return; diff --git a/src/diagram/functions/toDiagramEntity.ts b/src/diagram/functions/toDiagramEntity.ts index 591f02c..35d78cf 100644 --- a/src/diagram/functions/toDiagramEntity.ts +++ b/src/diagram/functions/toDiagramEntity.ts @@ -3,10 +3,9 @@ import {DiagramEntity} from "../types/diagramEntity"; import log from "loglevel"; import {v4 as uuidv4} from 'uuid'; -const logger = log.getLogger('toDiagramEntity'); export function toDiagramEntity(mesh: AbstractMesh): DiagramEntity { - + const logger = log.getLogger('toDiagramEntity'); if (!mesh) { logger.error("toDiagramEntity: mesh is null"); return null; diff --git a/src/information/inputTextView.ts b/src/information/inputTextView.ts index 2c8b8ed..8473a84 100644 --- a/src/information/inputTextView.ts +++ b/src/information/inputTextView.ts @@ -9,8 +9,9 @@ export type TextEvent = { id: string; text: string; } -const logger: Logger = log.getLogger('InputTextView'); + export class InputTextView { + private logger: Logger = log.getLogger('InputTextView'); public readonly onTextObservable: Observable = new Observable(); private readonly scene: Scene; private readonly inputMesh: AbstractMesh; @@ -42,7 +43,7 @@ export class InputTextView { this.diagramMesh = mesh; this.keyboard.isVisible = true; this.inputText.focus(); - logger.debug(mesh.metadata); + this.logger.debug(mesh.metadata); } public get handleMesh(): AbstractMesh { @@ -68,7 +69,7 @@ export class InputTextView { if (!platform) { this.scene.onNewMeshAddedObservable.add((mesh) => { if (mesh.id == 'platform') { - logger.debug("platform added"); + this.logger.debug("platform added"); handle.mesh.parent = mesh; if (!handle.idStored) { handle.mesh.position = position; @@ -114,7 +115,7 @@ export class InputTextView { keyboard.isEnabled = true; keyboard.children.forEach((key) => { key.onPointerEnterObservable.add((eventData, eventState) => { - logger.debug(eventData); + this.logger.debug(eventData); const gripId = eventState?.userInfo?.pickInfo?.gripTransform?.id; if (gripId) { this.controllers.controllerObservable.notifyObservers({ @@ -132,7 +133,7 @@ export class InputTextView { keyboard.onKeyPressObservable.add((key) => { if (key === '↵') { if (this.inputText.text && this.inputText.text.length > 0) { - logger.error(this.inputText.text); + this.logger.error(this.inputText.text); this.onTextObservable.notifyObservers({id: this.diagramMesh.id, text: this.inputText.text}); } else { this.onTextObservable.notifyObservers({id: this.diagramMesh.id, text: null}); diff --git a/src/integration/pouchdbPersistenceManager.ts b/src/integration/pouchdbPersistenceManager.ts index 200040e..9cee575 100644 --- a/src/integration/pouchdbPersistenceManager.ts +++ b/src/integration/pouchdbPersistenceManager.ts @@ -7,8 +7,9 @@ import log, {Logger} from "loglevel"; import {ascii_to_hex} from "./functions/hexFunctions"; import {getPath} from "../util/functions/getPath"; -const logger: Logger = log.getLogger('PouchdbPersistenceManager'); + export class PouchdbPersistenceManager { + private logger: Logger = log.getLogger('PouchdbPersistenceManager'); onDBUpdateObservable: Observable = new Observable(); onDBRemoveObservable: Observable = new Observable(); @@ -21,7 +22,7 @@ export class PouchdbPersistenceManager { } public setDiagramManager(diagramManager: DiagramManager) { diagramManager.onDiagramEventObservable.add((evt) => { - logger.debug(evt); + this.logger.debug(evt); switch (evt.type) { case DiagramEventType.REMOVE: this.remove(evt.entity.id); @@ -32,12 +33,12 @@ export class PouchdbPersistenceManager { this.upsert(evt.entity); break; default: - logger.warn('unknown diagram event type', evt); + this.logger.warn('unknown diagram event type', evt); } }, DiagramEventObserverMask.TO_DB); this.onDBUpdateObservable.add((evt) => { - logger.debug(evt); + this.logger.debug(evt); diagramManager.onDiagramEventObservable.notifyObservers({ type: DiagramEventType.ADD, entity: evt @@ -45,7 +46,7 @@ export class PouchdbPersistenceManager { }); this.onDBRemoveObservable.add((entity) => { - logger.debug(entity); + this.logger.debug(entity); diagramManager.onDiagramEventObservable.notifyObservers( {type: DiagramEventType.REMOVE, entity: entity}, DiagramEventObserverMask.FROM_DB); }); @@ -59,7 +60,7 @@ export class PouchdbPersistenceManager { const doc = await this.db.get(id); this.db.remove(doc); } catch (err) { - logger.error(err); + this.logger.error(err); } } @@ -79,10 +80,10 @@ export class PouchdbPersistenceManager { const newEntity = {...entity, _id: entity.id}; this.db.put(newEntity); } catch (err2) { - logger.error(err2); + this.logger.error(err2); } } else { - logger.error(err); + this.logger.error(err); } } } @@ -131,8 +132,8 @@ export class PouchdbPersistenceManager { } return true; } catch (err) { - logger.error(err); - logger.error('cannot initialize pouchdb for sync'); + this.logger.error(err); + this.logger.error('cannot initialize pouchdb for sync'); return false; } } @@ -141,11 +142,11 @@ export class PouchdbPersistenceManager { try { const all = await this.db.allDocs({include_docs: true}); for (const entity of all.rows) { - logger.debug(entity.doc); + this.logger.debug(entity.doc); this.onDBUpdateObservable.notifyObservers(entity.doc, 1); } } catch (err) { - logger.error(err); + this.logger.error(err); } } @@ -155,13 +156,13 @@ export class PouchdbPersistenceManager { } private syncDoc(info) { - logger.debug(info); + this.logger.debug(info); if (info.direction == 'pull') { const docs = info.change.docs; for (const doc of docs) { - logger.debug(doc); + this.logger.debug(doc); if (doc._deleted) { - logger.debug('Delete', doc); + this.logger.debug('Delete', doc); this.onDBRemoveObservable.notifyObservers({id: doc._id, template: doc.template}, 1); } else { this.onDBUpdateObservable.notifyObservers(doc, 1); @@ -178,9 +179,9 @@ export class PouchdbPersistenceManager { const remoteUserName = localName; const password = localName; const dbs = await axios.get(import.meta.env.VITE_SYNCDB_ENDPOINT + 'list'); - logger.debug(dbs.data); + this.logger.debug(dbs.data); if (dbs.data.indexOf(remoteDbName) == -1) { - logger.warn('sync target missing attempting to create'); + this.logger.warn('sync target missing attempting to create'); const newdb = await axios.post(import.meta.env.VITE_CREATE_ENDPOINT, { "_id": "org.couchdb.user:" + localName, @@ -191,17 +192,18 @@ export class PouchdbPersistenceManager { } ); if (newdb.status == 201) { - logger.info('sync target created'); + this.logger.info('sync target created'); } else { + this.logger.warn('sync target not created', newdb); return; } } const userEndpoint: string = import.meta.env.VITE_USER_ENDPOINT - logger.debug(userEndpoint); - logger.debug(remoteDbName); + this.logger.debug(userEndpoint); + this.logger.debug(remoteDbName); const target = await axios.get(userEndpoint); if (target.status != 200) { - logger.info(target.statusText); + this.logger.warn(target.statusText); return; } if (target.data && target.data.userCtx) { @@ -209,37 +211,36 @@ export class PouchdbPersistenceManager { const buildTarget = await axios.post(userEndpoint, {username: remoteUserName, password: password}); if (buildTarget.status != 200) { - logger.info(buildTarget.statusText); + this.logger.info(buildTarget.statusText); return; } else { this.user = buildTarget.data.userCtx; - logger.debug(this.user); + this.logger.debug(this.user); } } } - const remoteEndpoint: string = import.meta.env.VITE_SYNCDB_ENDPOINT; - logger.debug(remoteEndpoint + remoteDbName); + this.logger.debug(remoteEndpoint + remoteDbName); this.remote = new PouchDB(remoteEndpoint + remoteDbName, {auth: {username: remoteUserName, password: password}, skip_setup: true}); const dbInfo = await this.remote.info(); - logger.debug(dbInfo); + this.logger.debug(dbInfo); this.db.sync(this.remote, {live: true, retry: true}) .on('change', (info) => { this.syncDoc(info) }) - .on('active', function (info) { - logger.debug('sync active', info) + .on('active', (info) => { + this.logger.debug('sync active', info) }) - .on('paused', function (info) { - logger.debug('sync paused', info) + .on('paused', (info) => { + this.logger.debug('sync paused', info) }) - .on('error', function (err) { - logger.error('sync error', err) + .on('error', (err) => { + this.logger.error('sync error', err) }); } catch (err) { - logger.error(err); + this.logger.error(err); } } } diff --git a/src/menus/configMenu.ts b/src/menus/configMenu.ts index 65180fb..947136e 100644 --- a/src/menus/configMenu.ts +++ b/src/menus/configMenu.ts @@ -5,9 +5,9 @@ import log from "loglevel"; import {DefaultScene} from "../defaultScene"; import {Handle} from "../objects/handle"; -const logger = log.getLogger('ConfigMenu'); export class ConfigMenu { + private logger = log.getLogger('ConfigMenu'); private config: AppConfig; private readonly baseTransform: TransformNode; private gridSnaps: Array<{ label: string, value: number }> = [ @@ -61,7 +61,7 @@ export class ConfigMenu { selectionPanel.addGroup(radio); for (const [index, snap] of this.gridSnaps.entries()) { const selected = (this.config.current.createSnap == snap.value); - logger.debug(selected); + this.logger.debug(selected); radio.addRadio(snap.label, this.createVal.bind(this), selected); } this.adjustRadio(radio); diff --git a/src/tutorial/introduction.ts b/src/tutorial/introduction.ts index 2a01b12..8dca068 100644 --- a/src/tutorial/introduction.ts +++ b/src/tutorial/introduction.ts @@ -49,13 +49,14 @@ const steps: Array = [ {'name': 'Done', 'video': null} ] -const logger = log.getLogger('Introduction'); + export class Introduction { + private logger = log.getLogger('Introduction'); private readonly _scene: Scene; private videoElement: HTMLVideoElement; constructor() { - logger.info('Introduction constructor'); + this.logger.debug('Introduction constructor'); this._scene = DefaultScene.Scene; this.initialize(); } @@ -82,7 +83,7 @@ export class Introduction { hls.on(Hls.Events.MANIFEST_PARSED, function () { vid.loop = false; vid.play().then(() => { - logger.debug("Video Playing"); + this.logger.debug("Video Playing"); }); }); } else if (vid.canPlayType('application/vnd.apple.mpegurl')) { diff --git a/src/util/appConfig.ts b/src/util/appConfig.ts index e8267bd..7b76141 100644 --- a/src/util/appConfig.ts +++ b/src/util/appConfig.ts @@ -24,6 +24,7 @@ export class AppConfig { if (config) { this._currentConfig = config; } else { + localStorage.setItem('appConfig', JSON.stringify(this._currentConfig)); } } catch (err) { diff --git a/src/util/functions/groundMeshObserver.ts b/src/util/functions/groundMeshObserver.ts index a299de6..54328f5 100644 --- a/src/util/functions/groundMeshObserver.ts +++ b/src/util/functions/groundMeshObserver.ts @@ -5,11 +5,11 @@ import {Rigplatform} from "../../controllers/rigplatform"; import {DiagramManager} from "../../diagram/diagramManager"; import {Spinner} from "../../objects/spinner"; -const logger = log.getLogger('groungMeshObserver'); export async function groundMeshObserver(ground: AbstractMesh, diagramManager: DiagramManager, spinner: Spinner) { + const logger = log.getLogger('groungMeshObserver'); WebXRMotionControllerManager.PrioritizeOnlineRepository = false; WebXRMotionControllerManager.UseOnlineRepository = true; const xr = await WebXRDefaultExperience.CreateAsync(ground.getScene(), { @@ -55,6 +55,7 @@ export async function groundMeshObserver(ground: AbstractMesh, }); xr.baseExperience.onStateChangedObservable.add((state) => { + logger.debug(WebXRState[state]); switch (state) { case WebXRState.IN_XR: ground.getScene().audioEnabled = true; diff --git a/src/util/functions/snapRotateVal.ts b/src/util/functions/snapRotateVal.ts index e13feee..c369e3b 100644 --- a/src/util/functions/snapRotateVal.ts +++ b/src/util/functions/snapRotateVal.ts @@ -2,7 +2,6 @@ import {Angle, Vector3} from "@babylonjs/core"; import round from "round"; import log from "loglevel"; -const logger = log.getLogger('snapRotateVal'); export function snapRotateVal(value: Vector3, snap: number): Vector3 { if (!snap) { @@ -15,6 +14,7 @@ export function snapRotateVal(value: Vector3, snap: number): Vector3 { } function snapAngle(val: number, snap: number): number { + const logger = log.getLogger('snapRotateVal'); const angle = snap; const deg = Angle.FromRadians(val).degrees(); const snappedDegrees = round(deg, angle); diff --git a/src/vrApp.ts b/src/vrApp.ts index 49ac796..8c6cf78 100644 --- a/src/vrApp.ts +++ b/src/vrApp.ts @@ -14,6 +14,8 @@ import {DefaultScene} from "./defaultScene"; import {Introduction} from "./tutorial/introduction"; const webGpu = false; + +//log.setLevel('debug', false); export class VrApp { private engine: WebGPUEngine | Engine; @@ -21,6 +23,7 @@ export class VrApp { private logger: Logger = log.getLogger('App'); constructor() { + this.initializeEngine().then(() => { this.logger.info('Engine initialized'); }); @@ -88,8 +91,8 @@ export class VrApp { scene.ambientColor = new Color3(.1, .1, .1); DefaultScene.Scene = scene; - log.resetLevel(); - log.setDefaultLevel('error'); + //log.resetLevel(); + //log.setDefaultLevel('error'); this.logger.debug('App', 'gameCanvas created'); await this.initialize(); }