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 {ControllerEventType, Controllers} from "./controllers";
|
||||||
import {grabAndClone} from "./functions/grabAndClone";
|
import {grabAndClone} from "./functions/grabAndClone";
|
||||||
import {ClickMenu} from "../menus/clickMenu";
|
import {ClickMenu} from "../menus/clickMenu";
|
||||||
import {displayDebug} from "../util/displayDebug";
|
|
||||||
import {motionControllerObserver} from "./functions/motionControllerObserver";
|
import {motionControllerObserver} from "./functions/motionControllerObserver";
|
||||||
import {DefaultScene} from "../defaultScene";
|
import {DefaultScene} from "../defaultScene";
|
||||||
import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask";
|
import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask";
|
||||||
import {DiagramObject} from "../objects/diagramObject";
|
import {DiagramObject} from "../diagram/diagramObject";
|
||||||
import {snapAll} from "./functions/snapAll";
|
import {snapAll} from "./functions/snapAll";
|
||||||
import {MeshTypeEnum} from "../diagram/types/meshTypeEnum";
|
import {MeshTypeEnum} from "../diagram/types/meshTypeEnum";
|
||||||
import {getMeshType} from "./functions/getMeshType";
|
import {getMeshType} from "./functions/getMeshType";
|
||||||
@ -143,7 +142,8 @@ export class Base {
|
|||||||
this.grabbedMesh = mesh;
|
this.grabbedMesh = mesh;
|
||||||
this.grabbedMeshType = getMeshType(mesh, this.diagramManager);
|
this.grabbedMeshType = getMeshType(mesh, this.diagramManager);
|
||||||
|
|
||||||
displayDebug(mesh);
|
//displayDebug(mesh);
|
||||||
|
this._logger.debug("grabbing " + mesh.id + " type " + this.grabbedMeshType);
|
||||||
switch (this.grabbedMeshType) {
|
switch (this.grabbedMeshType) {
|
||||||
case MeshTypeEnum.ENTITY:
|
case MeshTypeEnum.ENTITY:
|
||||||
const diagramObject = this.diagramManager.getDiagramObject(mesh.id);
|
const diagramObject = this.diagramManager.getDiagramObject(mesh.id);
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import {
|
|||||||
WebXRDefaultExperience
|
WebXRDefaultExperience
|
||||||
} from "@babylonjs/core";
|
} from "@babylonjs/core";
|
||||||
|
|
||||||
import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial";
|
|
||||||
import {DefaultScene} from "../../defaultScene";
|
import {DefaultScene} from "../../defaultScene";
|
||||||
|
|
||||||
export function buildRig(xr: WebXRDefaultExperience): Mesh {
|
export function buildRig(xr: WebXRDefaultExperience): Mesh {
|
||||||
@ -31,7 +30,7 @@ export function buildRig(xr: WebXRDefaultExperience): Mesh {
|
|||||||
}
|
}
|
||||||
cameratransform.rotation.set(0, Math.PI, 0);
|
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.setAbsolutePosition(new Vector3(0, .01, 4));
|
||||||
rigMesh.isPickable = false;
|
rigMesh.isPickable = false;
|
||||||
const axis = new AxesViewer(scene, .25);
|
const axis = new AxesViewer(scene, .25);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import {AbstractMesh, Vector3} from "@babylonjs/core";
|
import {AbstractMesh, Vector3} from "@babylonjs/core";
|
||||||
import {DiagramManager} from "../../diagram/diagramManager";
|
import {DiagramManager} from "../../diagram/diagramManager";
|
||||||
import {DiagramObject} from "../../objects/diagramObject";
|
import {DiagramObject} from "../../diagram/diagramObject";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
|
||||||
export function grabAndClone(diagramManager: DiagramManager, mesh: AbstractMesh, parent: AbstractMesh):
|
export function grabAndClone(diagramManager: DiagramManager, mesh: AbstractMesh, parent: AbstractMesh):
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {buildEntityActionManager} from "./functions/buildEntityActionManager";
|
|||||||
import {DefaultScene} from "../defaultScene";
|
import {DefaultScene} from "../defaultScene";
|
||||||
import {DiagramMenuManager} from "./diagramMenuManager";
|
import {DiagramMenuManager} from "./diagramMenuManager";
|
||||||
import {DiagramEventObserverMask} from "./types/diagramEventObserverMask";
|
import {DiagramEventObserverMask} from "./types/diagramEventObserverMask";
|
||||||
import {DiagramObject} from "../objects/diagramObject";
|
import {DiagramObject} from "./diagramObject";
|
||||||
|
|
||||||
|
|
||||||
export class DiagramManager {
|
export class DiagramManager {
|
||||||
|
|||||||
@ -8,12 +8,12 @@ import {
|
|||||||
TransformNode,
|
TransformNode,
|
||||||
Vector3
|
Vector3
|
||||||
} from "@babylonjs/core";
|
} from "@babylonjs/core";
|
||||||
import {DiagramEntity, DiagramEvent, DiagramEventType} from "../diagram/types/diagramEntity";
|
import {DiagramEntity, DiagramEvent, DiagramEventType} from "./types/diagramEntity";
|
||||||
import {buildMeshFromDiagramEntity} from "../diagram/functions/buildMeshFromDiagramEntity";
|
import {buildMeshFromDiagramEntity} from "./functions/buildMeshFromDiagramEntity";
|
||||||
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
import {toDiagramEntity} from "./functions/toDiagramEntity";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import {createLabel} from "../diagram/functions/createLabel";
|
import {createLabel} from "./functions/createLabel";
|
||||||
import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask";
|
import {DiagramEventObserverMask} from "./types/diagramEventObserverMask";
|
||||||
import log, {Logger} from "loglevel";
|
import log, {Logger} from "loglevel";
|
||||||
|
|
||||||
type DiagramObjectOptionsType = {
|
type DiagramObjectOptionsType = {
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import {DiagramEntity, DiagramEntityType, DiagramTemplates} from "../types/diagramEntity";
|
import {DiagramEntity, DiagramEntityType, DiagramTemplates} from "../types/diagramEntity";
|
||||||
import {
|
import {
|
||||||
AbstractMesh,
|
AbstractMesh,
|
||||||
|
Color3,
|
||||||
InstancedMesh,
|
InstancedMesh,
|
||||||
Mesh,
|
Mesh,
|
||||||
MeshBuilder,
|
MeshBuilder,
|
||||||
@ -11,7 +12,6 @@ import {
|
|||||||
} from "@babylonjs/core";
|
} from "@babylonjs/core";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial";
|
|
||||||
|
|
||||||
export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh {
|
export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh {
|
||||||
const logger = log.getLogger('buildMeshFromDiagramEntity');
|
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") {
|
if (!newMesh.material && newMesh?.metadata?.template != "#object-template") {
|
||||||
logger.warn("new material created, this shouldn't happen");
|
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) {
|
if (entity.text) {
|
||||||
newMesh.metadata.text = entity.text;
|
newMesh.metadata.text = entity.text;
|
||||||
@ -161,3 +161,15 @@ function xyztovec(xyz: { x, y, z }): Vector3 {
|
|||||||
function vectoxys(v: Vector3): { x, y, z } {
|
function vectoxys(v: Vector3): { x, y, z } {
|
||||||
return {x: v.x, y: v.y, z: v.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;
|
return this._isStored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public staort() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private buildHandle() {
|
private buildHandle() {
|
||||||
const scene: Scene = this._menuItem.getScene();
|
const scene: Scene = this._menuItem.getScene();
|
||||||
const handle = HtmlMeshBuilder.CreatePlaneSync('handle-' + this._menuItem.id, {
|
const handle = HtmlMeshBuilder.CreatePlaneSync('handle-' + this._menuItem.id, {
|
||||||
@ -41,14 +45,16 @@ export class Handle {
|
|||||||
try {
|
try {
|
||||||
const locationdata = JSON.parse(stored);
|
const locationdata = JSON.parse(stored);
|
||||||
this._logger.debug('Stored location data found ', locationdata);
|
this._logger.debug('Stored location data found ', locationdata);
|
||||||
|
|
||||||
handle.position = new Vector3(locationdata.position.x, locationdata.position.y, locationdata.position.z);
|
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;
|
this._isStored = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._logger.error(e);
|
this._logger.error(e);
|
||||||
handle.position = Vector3.Zero();
|
handle.position = Vector3.Zero();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this._logger.debug('No stored location found for ' + handle.id + ', using defaults');
|
||||||
handle.position = this._offset;
|
handle.position = this._offset;
|
||||||
handle.rotation = this._rotation;
|
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));
|
//start.applyRotationQuaternionInPlace(Quaternion.FromEulerAngles(0, e.y, 0));
|
||||||
this.startPosition = start;
|
this.startPosition = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.startTime) {
|
if (this.startTime) {
|
||||||
const end = event.controller.grip.absolutePosition.clone();
|
const end = event.controller.grip.absolutePosition.clone();
|
||||||
|
|||||||
@ -106,7 +106,6 @@ export class Toolbox {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private assignHandleParentAndStore(mesh: TransformNode) {
|
private assignHandleParentAndStore(mesh: TransformNode) {
|
||||||
|
|||||||
@ -1,77 +1,28 @@
|
|||||||
import {
|
import {TransformNode} from "@babylonjs/core";
|
||||||
AbstractMesh,
|
import {HtmlMeshBuilder} from "babylon-html";
|
||||||
DynamicTexture,
|
|
||||||
Material,
|
|
||||||
MeshBuilder,
|
|
||||||
StandardMaterial,
|
|
||||||
TransformNode,
|
|
||||||
Vector3
|
|
||||||
} from "@babylonjs/core";
|
|
||||||
|
|
||||||
const debug = false;
|
const debug = true;
|
||||||
|
|
||||||
export function displayDebug(transform: TransformNode) {
|
export function displayDebug(text: string[]) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
const position = `position: (${transform.position.x.toFixed(2)}, ${transform.position.y.toFixed(2)}, ${transform.position.z.toFixed(2)})`;
|
drawDebugText(text);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function drawDebugText(text: string[]) {
|
||||||
|
const transform = new TransformNode("debugTransform");
|
||||||
|
transform.parent = transform.getScene().activeCamera;
|
||||||
|
transform.getScene().onActiveCameraChanged.add(() => {
|
||||||
|
transform.parent = transform.getScene().activeCamera;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
transform.position.z = 1;
|
||||||
|
transform.position.y = .2;
|
||||||
function buildText(text: string, transform: TransformNode, position) {
|
|
||||||
const height = 0.05;
|
const plane = HtmlMeshBuilder.CreatePlaneSync('debugMesh', {
|
||||||
const font_size = 24;
|
html:
|
||||||
const font = "bold " + font_size + "px Arial";
|
`<div style="width: 100%; height: 100%; font-size: 16px; border-radius: 8px; background-color: #111122; color: #eeeeee"><center>${text.join('<br/>')}</center></div>
|
||||||
//Set height for dynamic texture
|
`, width: .3, height: .05 * text.length, image: {width: 256, height: 32 * text.length}
|
||||||
const DTHeight = 1.5 * font_size; //or set as wished
|
}, transform.getScene());
|
||||||
//Calc Ratio
|
plane.parent = transform;
|
||||||
const ratio = height / DTHeight;
|
|
||||||
|
|
||||||
//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;
|
|
||||||
|
|
||||||
//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;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user