refactored logging.

This commit is contained in:
Michael Mainguy 2024-04-03 09:59:16 -05:00
parent 2c03ad1123
commit c87472b722
5 changed files with 49 additions and 29 deletions

View File

@ -1,7 +1,6 @@
import {Angle, Mesh, Quaternion, Scene, Vector3, WebXRDefaultExperience} from "@babylonjs/core";
import {Right} from "./right";
import {Left} from "./left";
import {EditMenu} from "../menus/editMenu";
import {ControllerEvent, ControllerEventType, Controllers} from "./controllers";
import log from "loglevel";
import {DiagramManager} from "../diagram/diagramManager";
@ -10,16 +9,29 @@ import {buildRig} from "./functions/buildRig";
const RIGHT = "right";
const LEFT = "left";
const logger = log.getLogger('Rigplatform');
export class Rigplatform {
private velocityIndex = 2;
private readonly velocityArray = [0.01, 0.1, 1, 2, 5];
public bMenu: EditMenu;
private readonly controllers: Controllers;
private readonly diagramManager: DiagramManager;
private readonly scene: Scene;
public static instance: Rigplatform;
private readonly velocityArray = [0.01, 0.1, 1, 2, 5];
private readonly xr: WebXRDefaultExperience;
private rightController: Right;
private leftController: Left;
private readonly xr: WebXRDefaultExperience;
private turning: boolean = false;
private velocity: Vector3 = Vector3.Zero();
private velocityIndex: number = 2;
private turnVelocity: number = 0;
private registered = false;
private yRotation: number = 0;
private _flyMode: boolean = true;
public static instance: Rigplatform;
public turnSnap: number = 0;
public rigMesh: Mesh;
@ -38,34 +50,28 @@ export class Rigplatform {
this.registerVelocityObserver();
}
private turning: boolean = false;
private velocity: Vector3 = Vector3.Zero();
private turnVelocity: number = 0;
private logger = log.getLogger('Rigplatform');
private readonly diagramManager: DiagramManager;
private readonly controllers: Controllers;
private registered = false;
private _flyMode: boolean = true;
public set flyMode(value: boolean) {
this._flyMode = value;
if (this._flyMode) {
this.rigMesh.physicsBody.setGravityFactor(.01);
console.log('flymode');
logger.debug('flymode');
} else {
this.rigMesh.physicsBody.setGravityFactor(1);
console.log('walkmode');
logger.debug('walkmode');
}
}
public forwardback(val: number) {
this.velocity.z = (val * this.velocityArray[this.velocityIndex])*-1;
this.velocity.z = (val * this.velocityArray[this.velocityIndex]) * -1;
}
public leftright(val: number) {
this.velocity.x = (val * this.velocityArray[this.velocityIndex]);
}
public updown(val: number) {
this.velocity.y = (val * this.velocityArray[this.velocityIndex])*-1;
this.velocity.y = (val * this.velocityArray[this.velocityIndex]) * -1;
}
public turn(val: number) {
@ -98,7 +104,7 @@ export class Rigplatform {
vel.y = 0;
}
if (vel.length() > 0) {
this.logger.debug('Velocity', this.velocity, vel, this.scene.activeCamera.absoluteRotation);
logger.debug('Velocity', this.velocity, vel, this.scene.activeCamera.absoluteRotation);
}
this.rigMesh.physicsBody.setLinearVelocity(vel);
});
@ -108,6 +114,7 @@ export class Rigplatform {
if (!this.registered) {
this.registered = true;
this.controllers.controllerObserver.add((event: ControllerEvent) => {
logger.debug(event);
switch (event.type) {
case ControllerEventType.INCREASE_VELOCITY:
if (this.velocityIndex < this.velocityArray.length - 1) {
@ -138,8 +145,7 @@ export class Rigplatform {
}
break;
case ControllerEventType.MOTION:
this.logger.debug(JSON.stringify(event));
logger.debug(JSON.stringify(event));
break;
}
});
@ -169,6 +175,7 @@ export class Rigplatform {
}
});
}
private fixRotation() {
this.scene.onAfterPhysicsObservable.add(() => {
const turnSnap = this.turnSnap;

View File

@ -1,11 +1,14 @@
import log from "loglevel";
const logger = log.getLogger('syncDoc');
export function syncDoc(info) {
console.log(info);
console.log(this);
logger.debug(info);
if (info.direction == 'pull') {
const docs = info.change.docs;
for (const doc of docs) {
logger.debug(doc);
if (doc._deleted) {
console.log(doc);
logger.debug('Delete', doc);
this.removeObserver.notifyObservers({id: doc._id, template: doc.template}, 1);
} else {
this.updateObserver.notifyObservers(doc, 1);

View File

@ -137,7 +137,7 @@ export class SoccerMenu extends AbstractMenu {
if (mesh) {
const meta = mesh?.parent?.parent?.parent
if (meta) {
console.log(meta.id);
this.logger.debug(meta.id);
}
}
break;

View File

@ -7,12 +7,19 @@ export function addSceneInspector(scene) {
//voiceManager.stopRecording();
}
if (ev.shiftKey && ev.ctrlKey && ev.altKey && ev.keyCode === 73) {
import("@babylonjs/core/Debug/debugLayer").then(() => {
import("@babylonjs/core/Debug").then(() => {
import("@babylonjs/inspector").then(() => {
const web = document.querySelector('#webApp');
if (scene.debugLayer.isVisible()) {
if (web) {
(web as HTMLDivElement).style.display = 'block';
}
scene.debugLayer.hide();
} else {
scene.debugLayer.show();
if (web) {
(web as HTMLDivElement).style.display = 'none';
}
}
});
});

View File

@ -1,5 +1,8 @@
import {Scene, TransformNode, Vector3} from "@babylonjs/core";
import {getFrontPosition} from "./getFrontPosition";
import log from "loglevel";
const logger = log.getLogger('setMenuPosition');
export function setMenuPosition(node: TransformNode, scene: Scene, offset: Vector3 = Vector3.Zero()) {
/*
@ -42,7 +45,7 @@ export function setMenuPosition(node: TransformNode, scene: Scene, offset: Vecto
scene.onActiveCameraChanged.add((scene: Scene) => {
setPosition(node, scene, offset);
});
console.error("No active camera");
logger.error("No active camera");
}
}
@ -77,6 +80,6 @@ function setPosition(node: TransformNode, scene: Scene, offset: Vector3 = Vector
node.position.x = offset.x;
break;
}
console.log('menu position set');
logger.debug('menu position set');
}