diff --git a/src/controllers/base.ts b/src/controllers/base.ts index 5d2417e..7e979e2 100644 --- a/src/controllers/base.ts +++ b/src/controllers/base.ts @@ -12,11 +12,10 @@ import log from "loglevel"; import {ControllerEventType, Controllers} from "./controllers"; import {grabAndClone} from "./functions/grabAndClone"; import {ClickMenu} from "../menus/clickMenu"; -import {displayDebug} from "../util/displayDebug"; import {motionControllerObserver} from "./functions/motionControllerObserver"; import {DefaultScene} from "../defaultScene"; import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask"; -import {DiagramObject} from "../objects/diagramObject"; +import {DiagramObject} from "../diagram/diagramObject"; import {snapAll} from "./functions/snapAll"; import {MeshTypeEnum} from "../diagram/types/meshTypeEnum"; import {getMeshType} from "./functions/getMeshType"; @@ -143,7 +142,8 @@ export class Base { this.grabbedMesh = mesh; this.grabbedMeshType = getMeshType(mesh, this.diagramManager); - displayDebug(mesh); + //displayDebug(mesh); + this._logger.debug("grabbing " + mesh.id + " type " + this.grabbedMeshType); switch (this.grabbedMeshType) { case MeshTypeEnum.ENTITY: const diagramObject = this.diagramManager.getDiagramObject(mesh.id); diff --git a/src/controllers/functions/buildRig.ts b/src/controllers/functions/buildRig.ts index ca287aa..076688d 100644 --- a/src/controllers/functions/buildRig.ts +++ b/src/controllers/functions/buildRig.ts @@ -10,7 +10,6 @@ import { WebXRDefaultExperience } from "@babylonjs/core"; -import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial"; import {DefaultScene} from "../../defaultScene"; export function buildRig(xr: WebXRDefaultExperience): Mesh { @@ -31,7 +30,7 @@ export function buildRig(xr: WebXRDefaultExperience): Mesh { } cameratransform.rotation.set(0, Math.PI, 0); }); - rigMesh.material = buildStandardMaterial("rigMaterial", scene, "#2222ff"); + //rigMesh.material = buildStandardMaterial("rigMaterial", scene, "#2222ff"); rigMesh.setAbsolutePosition(new Vector3(0, .01, 4)); rigMesh.isPickable = false; const axis = new AxesViewer(scene, .25); diff --git a/src/controllers/functions/grabAndClone.ts b/src/controllers/functions/grabAndClone.ts index b34fb8f..534edb5 100644 --- a/src/controllers/functions/grabAndClone.ts +++ b/src/controllers/functions/grabAndClone.ts @@ -1,6 +1,6 @@ import {AbstractMesh, Vector3} from "@babylonjs/core"; import {DiagramManager} from "../../diagram/diagramManager"; -import {DiagramObject} from "../../objects/diagramObject"; +import {DiagramObject} from "../../diagram/diagramObject"; import log from "loglevel"; export function grabAndClone(diagramManager: DiagramManager, mesh: AbstractMesh, parent: AbstractMesh): diff --git a/src/diagram/diagramManager.ts b/src/diagram/diagramManager.ts index d117171..eec987d 100644 --- a/src/diagram/diagramManager.ts +++ b/src/diagram/diagramManager.ts @@ -7,7 +7,7 @@ import {buildEntityActionManager} from "./functions/buildEntityActionManager"; import {DefaultScene} from "../defaultScene"; import {DiagramMenuManager} from "./diagramMenuManager"; import {DiagramEventObserverMask} from "./types/diagramEventObserverMask"; -import {DiagramObject} from "../objects/diagramObject"; +import {DiagramObject} from "./diagramObject"; export class DiagramManager { diff --git a/src/objects/diagramObject.ts b/src/diagram/diagramObject.ts similarity index 94% rename from src/objects/diagramObject.ts rename to src/diagram/diagramObject.ts index 72927b4..b2363ec 100644 --- a/src/objects/diagramObject.ts +++ b/src/diagram/diagramObject.ts @@ -8,12 +8,12 @@ import { TransformNode, Vector3 } from "@babylonjs/core"; -import {DiagramEntity, DiagramEvent, DiagramEventType} from "../diagram/types/diagramEntity"; -import {buildMeshFromDiagramEntity} from "../diagram/functions/buildMeshFromDiagramEntity"; -import {toDiagramEntity} from "../diagram/functions/toDiagramEntity"; +import {DiagramEntity, DiagramEvent, DiagramEventType} from "./types/diagramEntity"; +import {buildMeshFromDiagramEntity} from "./functions/buildMeshFromDiagramEntity"; +import {toDiagramEntity} from "./functions/toDiagramEntity"; import {v4 as uuidv4} from 'uuid'; -import {createLabel} from "../diagram/functions/createLabel"; -import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask"; +import {createLabel} from "./functions/createLabel"; +import {DiagramEventObserverMask} from "./types/diagramEventObserverMask"; import log, {Logger} from "loglevel"; type DiagramObjectOptionsType = { diff --git a/src/diagram/functions/buildMeshFromDiagramEntity.ts b/src/diagram/functions/buildMeshFromDiagramEntity.ts index bad6e2b..0a71258 100644 --- a/src/diagram/functions/buildMeshFromDiagramEntity.ts +++ b/src/diagram/functions/buildMeshFromDiagramEntity.ts @@ -1,6 +1,7 @@ import {DiagramEntity, DiagramEntityType, DiagramTemplates} from "../types/diagramEntity"; import { AbstractMesh, + Color3, InstancedMesh, Mesh, MeshBuilder, @@ -11,7 +12,6 @@ import { } from "@babylonjs/core"; import log from "loglevel"; import {v4 as uuidv4} from 'uuid'; -import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial"; export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh { const logger = log.getLogger('buildMeshFromDiagramEntity'); @@ -136,7 +136,7 @@ function mapMetadata(entity: DiagramEntity, newMesh: AbstractMesh, scene: Scene) }*/ if (!newMesh.material && newMesh?.metadata?.template != "#object-template") { logger.warn("new material created, this shouldn't happen"); - newMesh.material = buildStandardMaterial("material-" + entity.id, scene, entity.color); + newMesh.material = buildMissingMaterial("material-" + entity.id, scene, entity.color); } if (entity.text) { newMesh.metadata.text = entity.text; @@ -160,4 +160,16 @@ function xyztovec(xyz: { x, y, z }): Vector3 { function vectoxys(v: Vector3): { x, y, z } { return {x: v.x, y: v.y, z: v.z}; +} + +export function buildMissingMaterial(name: string, scene: Scene, color: string): StandardMaterial { + const existingMaterial = scene.getMaterialById(name); + if (existingMaterial) { + return (existingMaterial as StandardMaterial); + } + const newMaterial = new StandardMaterial(name, scene); + newMaterial.id = name; + newMaterial.diffuseColor = Color3.FromHexString(color); + newMaterial.alpha = 1; + return newMaterial; } \ No newline at end of file diff --git a/src/materials/functions/buildStandardMaterial.ts b/src/materials/functions/buildStandardMaterial.ts deleted file mode 100644 index d1fca7f..0000000 --- a/src/materials/functions/buildStandardMaterial.ts +++ /dev/null @@ -1,13 +0,0 @@ -import {Color3, Scene, StandardMaterial} from "@babylonjs/core"; - -export function buildStandardMaterial(name: string, scene: Scene, color: string): StandardMaterial { - const existingMaterial = scene.getMaterialById(name); - if (existingMaterial) { - return (existingMaterial as StandardMaterial); - } - const newMaterial = new StandardMaterial(name, scene); - newMaterial.id = name; - newMaterial.diffuseColor = Color3.FromHexString(color); - newMaterial.alpha = 1; - return newMaterial; -} \ No newline at end of file diff --git a/src/objects/handle.ts b/src/objects/handle.ts index 9ff68a9..1b8c370 100644 --- a/src/objects/handle.ts +++ b/src/objects/handle.ts @@ -24,6 +24,10 @@ export class Handle { return this._isStored; } + public staort() { + + } + private buildHandle() { const scene: Scene = this._menuItem.getScene(); const handle = HtmlMeshBuilder.CreatePlaneSync('handle-' + this._menuItem.id, { @@ -41,14 +45,16 @@ export class Handle { try { const locationdata = JSON.parse(stored); this._logger.debug('Stored location data found ', locationdata); + handle.position = new Vector3(locationdata.position.x, locationdata.position.y, locationdata.position.z); - handle.rotation = new Vector3(locationdata._rotation.x, locationdata._rotation.y, locationdata._rotation.z); + handle.rotation = new Vector3(locationdata.rotation.x, locationdata.rotation.y, locationdata.rotation.z); this._isStored = true; } catch (e) { this._logger.error(e); handle.position = Vector3.Zero(); } } else { + this._logger.debug('No stored location found for ' + handle.id + ', using defaults'); handle.position = this._offset; handle.rotation = this._rotation; } diff --git a/src/objects/objectMetaType.ts b/src/objects/objectMetaType.ts deleted file mode 100644 index ce58e3c..0000000 --- a/src/objects/objectMetaType.ts +++ /dev/null @@ -1,6 +0,0 @@ -export type ObjectMetaType = { - id: string; - parent: string; - position: { x: number, y: number, z: number }; - rotation: { x: number, y: number, z: number }; -} \ No newline at end of file diff --git a/src/soccer/soccerMenu.ts b/src/soccer/soccerMenu.ts index 326a13a..52d8d50 100644 --- a/src/soccer/soccerMenu.ts +++ b/src/soccer/soccerMenu.ts @@ -89,8 +89,6 @@ export class SoccerMenu extends AbstractMenu { //start.applyRotationQuaternionInPlace(Quaternion.FromEulerAngles(0, e.y, 0)); this.startPosition = start; } - - } else { if (this.startTime) { const end = event.controller.grip.absolutePosition.clone(); diff --git a/src/toolbox/toolbox.ts b/src/toolbox/toolbox.ts index a524f77..483d81a 100644 --- a/src/toolbox/toolbox.ts +++ b/src/toolbox/toolbox.ts @@ -106,7 +106,6 @@ export class Toolbox { } } - } private assignHandleParentAndStore(mesh: TransformNode) { diff --git a/src/util/displayDebug.ts b/src/util/displayDebug.ts index 4763e1b..7a70d9c 100644 --- a/src/util/displayDebug.ts +++ b/src/util/displayDebug.ts @@ -1,77 +1,28 @@ -import { - AbstractMesh, - DynamicTexture, - Material, - MeshBuilder, - StandardMaterial, - TransformNode, - Vector3 -} from "@babylonjs/core"; +import {TransformNode} from "@babylonjs/core"; +import {HtmlMeshBuilder} from "babylon-html"; -const debug = false; +const debug = true; -export function displayDebug(transform: TransformNode) { +export function displayDebug(text: string[]) { if (debug) { - const position = `position: (${transform.position.x.toFixed(2)}, ${transform.position.y.toFixed(2)}, ${transform.position.z.toFixed(2)})`; - const rotation = `rotation: (${transform.rotation.x.toFixed(2)}, ${transform.rotation.y.toFixed(2)}, ${transform.rotation.z.toFixed(2)})`; - buildText(position, transform, new Vector3(0, 1.5, 1)); - buildText(rotation, transform, new Vector3(0, 1.4, 1)); + drawDebugText(text); } - - } -function buildText(text: string, transform: TransformNode, position) { - const height = 0.05; - const font_size = 24; - const font = "bold " + font_size + "px Arial"; - //Set height for dynamic texture - const DTHeight = 1.5 * font_size; //or set as wished - //Calc Ratio - const ratio = height / DTHeight; +function drawDebugText(text: string[]) { + const transform = new TransformNode("debugTransform"); + transform.parent = transform.getScene().activeCamera; + transform.getScene().onActiveCameraChanged.add(() => { + transform.parent = transform.getScene().activeCamera; + }); - //Use a temporary dynamic texture to calculate the length of the text on the dynamic texture canvas - const temp = new DynamicTexture("DynamicTexture", 32, transform.getScene()); - const tmpctx = temp.getContext(); - tmpctx.font = font; - const DTWidth = tmpctx.measureText(text).width + 8; + transform.position.z = 1; + transform.position.y = .2; - //Calculate width the plane has to be - const planeWidth = DTWidth * ratio; - - //Create dynamic texture and write the text - const dynamicTexture = new DynamicTexture("DynamicTexture", { - width: DTWidth, - height: DTHeight - }, transform.getScene(), false); - const mat = new StandardMaterial("mat", transform.getScene()); - mat.diffuseTexture = dynamicTexture; - //mat.emissiveColor = Color3.White(); - dynamicTexture.drawText(text, null, null, font, "#000000", "#ffffff", true); - //Create plane and set dynamic texture as material - //const plane = MeshBuilder.CreatePlane("text" + text, {width: planeWidth, height: height}, mesh.getScene()); - const plane1 = createPlane(mat, transform, text, planeWidth, height, position); - const plane2 = createPlane(mat, transform, text, planeWidth, height, position); - plane2.rotation.y = Math.PI; -} - -function createPlane(mat: Material, transform: TransformNode, text: string, planeWidth: number, height: number, position): AbstractMesh { - const plane = MeshBuilder.CreatePlane("text" + text, {width: planeWidth, height: height}, transform.getScene()); - - plane.material = mat; - //plane.billboardMode = Mesh.BILLBOARDMODE_ALL; - plane.metadata = {exportable: false, label: false}; - - //const yOffset = mesh.getBoundingInfo().boundingSphere.maximum.y; - //plane.parent = mesh; - //plane.scaling.y = (1 / mesh.scaling.y); - //plane.scaling.x = (1 / mesh.scaling.x); - //plane.scaling.z = (1 / mesh.scaling.z); - //plane.position = transform.position.y = yOffset + (height * plane.scaling.y); - plane.position = position; - window.setTimeout(() => { - plane.dispose(); - }, 5000); - return plane; - -} + const plane = HtmlMeshBuilder.CreatePlaneSync('debugMesh', { + html: + `