Updated text labels to be two sided and removed emissive.
This commit is contained in:
parent
717a5c6151
commit
7366b7e856
@ -152,6 +152,7 @@ export class Base {
|
||||
transformNode.rotation = newMesh.rotation.clone();
|
||||
}
|
||||
transformNode.setParent(this.controller.motionController.rootMesh);
|
||||
newMesh.setParent(transformNode);
|
||||
this.grabbedMeshParentId = transformNode.id;
|
||||
this.grabbedMesh = newMesh;
|
||||
this.previousParentId = null;
|
||||
|
||||
@ -18,6 +18,7 @@ export function reparent(mesh: AbstractMesh, previousParentId: string, grabbedMe
|
||||
if (parent) {
|
||||
logger.warn('setting parent to null', grabbedMeshParentId, parent)
|
||||
//this.grabbedMeshParentId = null;
|
||||
mesh.setParent(null);
|
||||
parent.dispose();
|
||||
} else {
|
||||
mesh.setParent(null);
|
||||
|
||||
@ -12,6 +12,7 @@ import {deepCopy} from "../util/functions/deepCopy";
|
||||
import {applyPhysics} from "./functions/diagramShapePhysics";
|
||||
import {applyScaling} from "./functions/applyScaling";
|
||||
import {toDiagramEntity} from "./functions/toDiagramEntity";
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
|
||||
|
||||
export class DiagramManager {
|
||||
@ -70,12 +71,15 @@ export class DiagramManager {
|
||||
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
|
||||
let newMesh;
|
||||
if (!mesh.isAnInstance) {
|
||||
newMesh = new InstancedMesh("new", (mesh as Mesh));
|
||||
newMesh = new InstancedMesh('id' + uuidv4(), (mesh as Mesh));
|
||||
} else {
|
||||
newMesh = new InstancedMesh("new", (mesh as InstancedMesh).sourceMesh);
|
||||
newMesh = new InstancedMesh('id' + uuidv4(), (mesh as InstancedMesh).sourceMesh);
|
||||
}
|
||||
newMesh.id = 'id' + uuidv4();
|
||||
|
||||
newMesh.actionManager = this.diagramEntityActionManager.manager;
|
||||
newMesh.position = mesh.absolutePosition.clone();
|
||||
|
||||
if (mesh.absoluteRotationQuaternion) {
|
||||
newMesh.rotation = mesh.absoluteRotationQuaternion.toEulerAngles().clone();
|
||||
} else {
|
||||
@ -88,11 +92,12 @@ export class DiagramManager {
|
||||
applyPhysics(this.sounds, newMesh, this.scene);
|
||||
}
|
||||
//@TODO Refactor
|
||||
this.onDiagramEventObservable.notifyObservers({
|
||||
/*this.onDiagramEventObservable.notifyObservers({
|
||||
type: DiagramEventType.ADD,
|
||||
entity: toDiagramEntity(newMesh)
|
||||
}, 2);
|
||||
}, 2);*/
|
||||
//this.persistenceManager.add(toDiagramEntity(newMesh));
|
||||
|
||||
return newMesh;
|
||||
}
|
||||
|
||||
|
||||
@ -1,20 +1,23 @@
|
||||
import {AbstractMesh, Color3, DynamicTexture, Mesh, MeshBuilder, StandardMaterial} from "@babylonjs/core";
|
||||
import {AbstractMesh, DynamicTexture, Material, MeshBuilder, StandardMaterial} from "@babylonjs/core";
|
||||
import log from "loglevel";
|
||||
|
||||
export class TextLabel {
|
||||
private static logger: log.Logger = log.getLogger('TextLabel');
|
||||
|
||||
public static updateTextNode(mesh: AbstractMesh, text: string): AbstractMesh {
|
||||
public static updateTextNode(mesh: AbstractMesh, text: string) {
|
||||
if (!mesh) {
|
||||
this.logger.error("updateTextNode: mesh is null");
|
||||
return null;
|
||||
}
|
||||
let textNode = (mesh.getChildren((node) => {
|
||||
return node.name == 'text'
|
||||
})[0] as Mesh);
|
||||
if (textNode) {
|
||||
textNode.dispose(false, true);
|
||||
const textNodes = mesh.getChildren((node) => {
|
||||
return node.metadata?.label == true;
|
||||
});
|
||||
if (textNodes && textNodes.length > 0) {
|
||||
textNodes.forEach((node) => {
|
||||
node.dispose(false, true);
|
||||
});
|
||||
}
|
||||
|
||||
if (!text) {
|
||||
return null;
|
||||
}
|
||||
@ -44,18 +47,30 @@ export class TextLabel {
|
||||
}, mesh.getScene(), false);
|
||||
const mat = new StandardMaterial("mat", mesh.getScene());
|
||||
mat.diffuseTexture = dynamicTexture;
|
||||
mat.emissiveColor = Color3.White();
|
||||
//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 = this.createPlane(mat, mesh, text, planeWidth, height);
|
||||
const plane2 = this.createPlane(mat, mesh, text, planeWidth, height);
|
||||
plane2.rotation.y = Math.PI;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static createPlane(mat: Material, mesh: AbstractMesh, text: string, planeWidth: number, height: number): AbstractMesh {
|
||||
const plane = MeshBuilder.CreatePlane("text" + text, {width: planeWidth, height: height}, mesh.getScene());
|
||||
|
||||
plane.material = mat;
|
||||
plane.billboardMode = Mesh.BILLBOARDMODE_ALL;
|
||||
plane.metadata = {exportable: true};
|
||||
//plane.billboardMode = Mesh.BILLBOARDMODE_ALL;
|
||||
plane.metadata = {exportable: true, label: true};
|
||||
|
||||
const yOffset = mesh.getBoundingInfo().boundingSphere.radius;
|
||||
plane.parent = mesh;
|
||||
plane.position.y = yOffset;
|
||||
plane.position.y = yOffset + height / 2;
|
||||
plane.scaling.y = 1 / mesh.scaling.y;
|
||||
plane.scaling.x = 1 / mesh.scaling.x;
|
||||
plane.scaling.z = 1 / mesh.scaling.z;
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import {MeshBuilder, Scene, Vector3, WebXRDefaultExperience} from "@babylonjs/core";
|
||||
import {AbstractMesh, MeshBuilder, Scene, Vector3, WebXRDefaultExperience} from "@babylonjs/core";
|
||||
import {AbstractMenu} from "./abstractMenu";
|
||||
import {ControllerEventType, Controllers} from "../controllers/controllers";
|
||||
import {AdvancedDynamicTexture, Button, Control, ScrollViewer, StackPanel, TextBlock} from "@babylonjs/gui";
|
||||
import {setMenuPosition} from "../util/functions/setMenuPosition";
|
||||
|
||||
export class DiagramListingMenu extends AbstractMenu {
|
||||
private mesh: AbstractMesh;
|
||||
constructor(scene: Scene, xr: WebXRDefaultExperience, controllers: Controllers) {
|
||||
super(scene, xr, controllers);
|
||||
this.buildMenu();
|
||||
@ -17,6 +18,8 @@ export class DiagramListingMenu extends AbstractMenu {
|
||||
|
||||
public toggle() {
|
||||
setMenuPosition(this.handle.mesh, this.scene, new Vector3(0, .4, 0));
|
||||
this.mesh.isVisible = !this.mesh.isVisible;
|
||||
(this.mesh.parent as AbstractMesh).isVisible = this.mesh.isVisible;
|
||||
}
|
||||
|
||||
private buildMenu() {
|
||||
@ -26,6 +29,7 @@ export class DiagramListingMenu extends AbstractMenu {
|
||||
width: 1,
|
||||
height: .5
|
||||
}, this.scene);
|
||||
this.mesh = configPlane;
|
||||
const configTexture = AdvancedDynamicTexture.CreateForMesh(configPlane, 2048, 1024);
|
||||
|
||||
configTexture.background = "white";
|
||||
@ -61,6 +65,7 @@ export class DiagramListingMenu extends AbstractMenu {
|
||||
this.createHandle(configPlane);
|
||||
configPlane.position.y = .5;
|
||||
setMenuPosition(this.handle.mesh, this.scene, new Vector3(0, .4, 0));
|
||||
|
||||
this.mesh.isVisible = false;
|
||||
(this.mesh.parent as AbstractMesh).isVisible = false;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user