Refactored things to be closer together in domain.
This commit is contained in:
parent
d8d91dd688
commit
06333e9123
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 = {
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 };
|
||||
}
|
||||
@ -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();
|
||||
|
||||
@ -106,7 +106,6 @@ export class Toolbox {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private assignHandleParentAndStore(mesh: TransformNode) {
|
||||
|
||||
@ -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:
|
||||
`<div style="width: 100%; height: 100%; font-size: 16px; border-radius: 8px; background-color: #111122; color: #eeeeee"><center>${text.join('<br/>')}</center></div>
|
||||
`, width: .3, height: .05 * text.length, image: {width: 256, height: 32 * text.length}
|
||||
}, transform.getScene());
|
||||
plane.parent = transform;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user