Added glb object type loader, cleaned up loggers and change web controller.

This commit is contained in:
Michael Mainguy 2023-12-12 14:00:39 -06:00
parent 4c45ac5ef0
commit dcd5a8835c
11 changed files with 100 additions and 694 deletions

Binary file not shown.

View File

@ -0,0 +1,10 @@
{
"objects": [
{
"name": "Server",
"id": "server",
"type": "glb",
"path": "models/server_racking_system.glb"
}
]
}

View File

@ -1,668 +0,0 @@
[
{
"series": [
{
"name": "Total Numeric(price)",
"series": [
{
"id": "04c9457963f067213705689ff95a1aa1f01822239",
"name": "CTR",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
4676808.549999999,
1700750433000
],
[
1700750433000,
7723020.09,
1700836833000
],
[
1700836833000,
6262204.39,
1700923233000
],
[
1700923233000,
3772184.58,
1701009633000
],
[
1701009633000,
4903447.579999999,
1701096033000
],
[
1701096033000,
8205618.880000001,
1701182433000
],
[
1701182433000,
3702760.1500000004,
1701268833000
],
[
1701268833000,
4117192.0100000002,
1701355233000
],
[
1701355233000,
4081216.350000001,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#00b9d9",
"x_axis": "begin_time",
"display": "line",
"name": "CTR",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'CTR'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "06c651696bed66d97625f2673be90695d04328b8d",
"name": "SC",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
2588610.670000001,
1700750433000
],
[
1700750433000,
3864433.64,
1700836833000
],
[
1700836833000,
4958889.069999999,
1700923233000
],
[
1700923233000,
3083910.9099999997,
1701009633000
],
[
1701009633000,
3698118.42,
1701096033000
],
[
1701096033000,
4800171.459999998,
1701182433000
],
[
1701182433000,
2453778.76,
1701268833000
],
[
1701268833000,
2477775.4499999993,
1701355233000
],
[
1701355233000,
998172.8500000003,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#f0ca4d",
"x_axis": "begin_time",
"display": "line",
"name": "SC",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'SC'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "0043f2ddf69955ec2012fb9964380b4fb3696eaed",
"name": "MKS",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
1387502.0800000005,
1700750433000
],
[
1700750433000,
2033349.0000000005,
1700836833000
],
[
1700836833000,
2316991.13,
1700923233000
],
[
1700923233000,
1670253.9000000001,
1701009633000
],
[
1701009633000,
1811092.6699999997,
1701096033000
],
[
1701096033000,
2308590.9699999997,
1701182433000
],
[
1701182433000,
1335727.1400000006,
1701268833000
],
[
1701268833000,
1454412.4800000004,
1701355233000
],
[
1701355233000,
489153.62000000005,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#f06c53",
"x_axis": "begin_time",
"display": "line",
"name": "MKS",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'MKS'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "0e55cb43fdad3bb592f03a06239b286b27f631e20",
"name": "LEQ",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
119854.05999999994,
1700750433000
],
[
1700750433000,
150485.83,
1700836833000
],
[
1700836833000,
167186.66999999998,
1700923233000
],
[
1700923233000,
132224.41999999998,
1701009633000
],
[
1701009633000,
163320.71,
1701096033000
],
[
1701096033000,
181005.11000000004,
1701182433000
],
[
1701182433000,
109123.26999999996,
1701268833000
],
[
1701268833000,
128689.60000000003,
1701355233000
],
[
1701355233000,
39533.739999999976,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#98cb65",
"x_axis": "begin_time",
"display": "line",
"name": "LEQ",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'LEQ'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "07f9d06664925804a7c184e6c036e1e52315e8091",
"name": "ATM",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
64957.82999999999,
1700750433000
],
[
1700750433000,
99035.64999999998,
1700836833000
],
[
1700836833000,
123557.49999999996,
1700923233000
],
[
1700923233000,
90598.46999999996,
1701009633000
],
[
1701009633000,
106364.25999999998,
1701096033000
],
[
1701096033000,
141777.25999999995,
1701182433000
],
[
1701182433000,
74628.67999999998,
1701268833000
],
[
1701268833000,
71244.18,
1701355233000
],
[
1701355233000,
15901.249999999996,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#9b61a7",
"x_axis": "begin_time",
"display": "line",
"name": "ATM",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'ATM'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "0d86544f75148d36eb06a18f69e878a2870ac0087",
"name": "PTY",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
14202.94,
1700750433000
],
[
1700750433000,
16589.829999999998,
1700836833000
],
[
1700836833000,
14595.310000000001,
1700923233000
],
[
1700923233000,
8760.19,
1701009633000
],
[
1701009633000,
9123.740000000002,
1701096033000
],
[
1701096033000,
14973.260000000002,
1701182433000
],
[
1701182433000,
14041.58,
1701268833000
],
[
1701268833000,
16656.37,
1701355233000
],
[
1701355233000,
16985.59,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#1e51ad",
"x_axis": "begin_time",
"display": "line",
"name": "PTY",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'PTY'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
},
{
"id": "0728ad08286766d72dcedbdd0ceedbcc450ff1d12",
"name": "TRIANGLE",
"columns": [
"begin_time",
"Total numeric(price)",
"end_time"
],
"units": [
"timestamp",
"count",
"timestamp"
],
"data": [
[
1700664033000,
16020.0,
1700750433000
],
[
1700750433000,
18512.0,
1700836833000
],
[
1700836833000,
12816.0,
1700923233000
],
[
1700923233000,
8099.0,
1701009633000
],
[
1701009633000,
7921.0,
1701096033000
],
[
1701096033000,
7921.0,
1701182433000
],
[
1701182433000,
4895.0,
1701268833000
],
[
1701268833000,
7476.0,
1701355233000
],
[
1701355233000,
7387.0,
1701441633000
]
],
"presentation": {
"y_axis": "Total numeric(price)",
"color": "#562d1e",
"x_axis": "begin_time",
"display": "line",
"name": "TRIANGLE",
"tooltip_template": "{{Total numeric(price)}} from {{begin_time}} to {{end_time}}",
"x_display_order": [
"begin_time"
],
"y_display_order": [
"Total numeric(price)"
]
},
"metadata": {
"unknown_group": false,
"total_result": false,
"function": "sum",
"alias": "",
"attribute": "numeric(price)",
"type": "Log_CCV2",
"facet": {
"label": "'TRIANGLE'",
"expression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')"
}
}
}
]
}
],
"events": [],
"metadata": {
"version": 3,
"since": "Since 9 days ago",
"sinceTime": 1700664033333,
"beginTime": 1700664033333,
"endTime": 1701441633333,
"facets": [
"banner"
],
"performanceStats": {
"inspectedCount": 2172129338,
"responseTime": 22604,
"exceedsRetentionWindow": false
},
"nrqlQuery": "SELECT sum(numeric(capture(message, r'.*TotalPriceExcludingTax:(?P<price>\\S+).*'))) FROM Log_CCV2 WHERE message like '%CTFS Payment Response%' Since 9 days ago timeseries 1 day facet capture(message, r'.*BannerId:(?P<banner>\\S+).*')",
"refresh_interval": 86400000,
"time_zone_offsets": [
{
"begin_time": 1700642433333,
"zone_id": "America/Chicago",
"offset": -21600000
}
],
"account_name": "",
"rawUntil": "NOW",
"rawSince": "9 DAYS AGO",
"offset": 0,
"rawBeginTime": "2023-11-22T14:40:33Z",
"openEnded": true,
"facetExpression": "`regexcapture`(`message`, r'.*BannerId:(?P<banner>\\S+).*')",
"eventType": "Log_CCV2",
"eventTypes": [
"Log_CCV2"
],
"routerGuid": "378e5d27-d02a-e980-a421-838bf14786aa",
"bucketSizeMillis": 86400000,
"rawCompareWith": "",
"limit": 10,
"guid": "378e5d27-d02a-e980-a421-838bf14786aa",
"rawEndTime": "2023-12-01T14:40:33Z",
"accounts": [
1679802
]
},
"account_ids": [
1679802
]
}
]

View File

@ -1,4 +1,5 @@
import { import {
AxesViewer,
Mesh, Mesh,
MeshBuilder, MeshBuilder,
PhysicsAggregate, PhysicsAggregate,
@ -29,6 +30,7 @@ export function buildRig(scene: Scene, appConfig: AppConfig): Mesh {
}); });
rigMesh.material = buildStandardMaterial("rigMaterial", scene, "#2222ff"); rigMesh.material = buildStandardMaterial("rigMaterial", scene, "#2222ff");
rigMesh.setAbsolutePosition(new Vector3(0, .01, 3)); rigMesh.setAbsolutePosition(new Vector3(0, .01, 3));
const home = new AxesViewer(scene, .5);
rigMesh.lookAt(new Vector3(0, 0.01, 0)); rigMesh.lookAt(new Vector3(0, 0.01, 0));
rigMesh.visibility = 0; rigMesh.visibility = 0;
const rigAggregate = const rigAggregate =

View File

@ -1,12 +1,13 @@
import {AbstractMesh, MeshBuilder, Scene, Vector3} from "@babylonjs/core"; import {AbstractMesh, MeshBuilder, Scene} from "@babylonjs/core";
import {Rigplatform} from "./rigplatform"; import {Rigplatform} from "./rigplatform";
import {ControllerEventType, Controllers} from "./controllers"; import {ControllerEventType, Controllers} from "./controllers";
import {DiagramManager} from "../diagram/diagramManager"; import {DiagramManager} from "../diagram/diagramManager";
import {GridMaterial} from "@babylonjs/materials"; import {GridMaterial} from "@babylonjs/materials";
import {setMenuPosition} from "../util/functions/setMenuPosition";
import {wheelHandler} from "./functions/wheelHandler"; import {wheelHandler} from "./functions/wheelHandler";
import log, {Logger} from "loglevel"; import log, {Logger} from "loglevel";
import {isDiagramEntity} from "../diagram/functions/isDiagramEntity"; import {isDiagramEntity} from "../diagram/functions/isDiagramEntity";
import {DiagramEventType} from "../diagram/types/diagramEntity";
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
export class WebController { export class WebController {
private readonly scene: Scene; private readonly scene: Scene;
@ -80,6 +81,7 @@ export class WebController {
if (kbInfo.type == 1) { if (kbInfo.type == 1) {
//this.referencePlane.setEnabled(true); //this.referencePlane.setEnabled(true);
} else { } else {
this.referencePlane.setEnabled(false); this.referencePlane.setEnabled(false);
if (this.pickedMesh) { if (this.pickedMesh) {
this.pickedMesh.showBoundingBox = false; this.pickedMesh.showBoundingBox = false;
@ -126,9 +128,13 @@ export class WebController {
this.scene.onPointerDown = (evt, state) => { this.scene.onPointerDown = (evt, state) => {
if (evt.pointerType == "mouse") { if (evt.pointerType == "mouse") {
if (evt.shiftKey) { if (evt.shiftKey) {
setMenuPosition(this.referencePlane, this.scene, new Vector3(0, 0, 5)); //setMenuPosition(this.referencePlane, this.scene, new Vector3(0, 0, 5));
//this.referencePlane.rotation = scene.activeCamera.absoluteRotation.toEulerAngles(); //this.referencePlane.rotation = scene.activeCamera.absoluteRotation.toEulerAngles();
this.pickedMesh = state.pickedMesh.clone('pickedMesh', null, true); this.pickedMesh = state.pickedMesh;
if (this.pickedMesh) {
this.referencePlane.position = this.pickedMesh.position;
this.referencePlane.rotation = scene.activeCamera.absoluteRotation.toEulerAngles();
}
this.pickedMesh.rotation = scene.activeCamera.absoluteRotation.toEulerAngles(); this.pickedMesh.rotation = scene.activeCamera.absoluteRotation.toEulerAngles();
this.referencePlane.setEnabled(true); this.referencePlane.setEnabled(true);
} else { } else {
@ -137,6 +143,9 @@ export class WebController {
} }
}; };
this.scene.onPointerMove = (evt) => { this.scene.onPointerMove = (evt) => {
if (evt.pointerType != "mouse") {
return;
}
if (this.mouseDown) { if (this.mouseDown) {
this.rig.turn(evt.movementX); this.rig.turn(evt.movementX);
} }
@ -156,6 +165,12 @@ export class WebController {
} }
} }
} else { } else {
if (this.mesh) {
this.diagramManager.onDiagramEventObservable.notifyObservers({
type: DiagramEventType.MODIFY,
entity: toDiagramEntity(this.mesh)
}, -1);
}
this.mesh = null; this.mesh = null;
} }
if (this.pickedMesh && planePickInfo.hit) { if (this.pickedMesh && planePickInfo.hit) {

View File

@ -6,11 +6,11 @@ import log from "loglevel";
import {v4 as uuidv4} from 'uuid'; import {v4 as uuidv4} from 'uuid';
import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial"; import {buildStandardMaterial} from "../../materials/functions/buildStandardMaterial";
const logger = log.getLogger('fromDiagramEntity'); const logger = log.getLogger('buildMeshFromDiagramEntity');
export function fromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh { export function buildMeshFromDiagramEntity(entity: DiagramEntity, scene: Scene): AbstractMesh {
if (!entity) { if (!entity) {
logger.error("fromDiagramEntity: entity is null"); logger.error("buildMeshFromDiagramEntity: entity is null");
return null; return null;
} }
if (!entity.id) { if (!entity.id) {
@ -30,7 +30,7 @@ export function fromDiagramEntity(entity: DiagramEntity, scene: Scene): Abstract
const toolMesh = scene.getMeshById("tool-" + entity.template + "-" + entity.color); const toolMesh = scene.getMeshById("tool-" + entity.template + "-" + entity.color);
if (toolMesh && !oldMesh) { if (toolMesh && !oldMesh) {
newMesh = new InstancedMesh(entity.id, (toolMesh as Mesh)); newMesh = new InstancedMesh(entity.id, (toolMesh as Mesh));
newMesh.metadata = {template: entity.template, exportable: true}; newMesh.metadata = {template: entity.template, exportable: true, tool: false};
} else { } else {
logger.warn('no tool mesh found for ' + entity.template + "-" + entity.color); logger.warn('no tool mesh found for ' + entity.template + "-" + entity.color);
} }
@ -54,8 +54,8 @@ export function fromDiagramEntity(entity: DiagramEntity, scene: Scene): Abstract
if (entity.scale) { if (entity.scale) {
newMesh.scaling = xyztovec(entity.scale); newMesh.scaling = xyztovec(entity.scale);
} }
if (!newMesh.material) { if (!newMesh.material && newMesh?.metadata?.template != "#object-template") {
this.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 = buildStandardMaterial("material-" + entity.id, scene, entity.color);
} }
if (entity.text) { if (entity.text) {
@ -69,7 +69,7 @@ export function fromDiagramEntity(entity: DiagramEntity, scene: Scene): Abstract
newMesh.metadata.to = entity.to; newMesh.metadata.to = entity.to;
} }
} else { } else {
logger.error("fromDiagramEntity: mesh is null after it should have been created"); logger.error("buildMeshFromDiagramEntity: mesh is null after it should have been created");
} }
return newMesh; return newMesh;
} }

View File

@ -6,7 +6,7 @@ import {TextLabel} from "../../objects/textLabel";
import {Toolbox} from "../../toolbox/toolbox"; import {Toolbox} from "../../toolbox/toolbox";
import {DiaSounds} from "../../util/diaSounds"; import {DiaSounds} from "../../util/diaSounds";
import {fromDiagramEntity} from "./fromDiagramEntity"; import {buildMeshFromDiagramEntity} from "./buildMeshFromDiagramEntity";
import {isDiagramEntity} from "./isDiagramEntity"; import {isDiagramEntity} from "./isDiagramEntity";
@ -27,7 +27,7 @@ export function diagramEventHandler(event: DiagramEvent,
log.debug('no mesh found for ' + event.entity.template + "-" + event.entity.color, 'adding it'); log.debug('no mesh found for ' + event.entity.template + "-" + event.entity.color, 'adding it');
toolbox.updateToolbox(event.entity.color); toolbox.updateToolbox(event.entity.color);
} }
mesh = fromDiagramEntity(event.entity, scene); mesh = buildMeshFromDiagramEntity(event.entity, scene);
if (mesh) { if (mesh) {
mesh.actionManager = actionManager; mesh.actionManager = actionManager;
if (physicsEnabled) { if (physicsEnabled) {

View File

@ -27,7 +27,10 @@ export function toDiagramEntity(mesh: AbstractMesh): DiagramEntity {
if (mesh.material) { if (mesh.material) {
entity.color = (mesh.material as any).diffuseColor.toHexString(); entity.color = (mesh.material as any).diffuseColor.toHexString();
} else { } else {
logger.error("toDiagramEntity: mesh.material is null"); if (entity.template != "#object-template") {
logger.error("toDiagramEntity: mesh.material is null");
}
} }
return entity; return entity;
} }

View File

@ -0,0 +1,9 @@
import {Scene} from "@babylonjs/core";
export class DiagramObject {
private scene: Scene;
constructor(scene: Scene) {
this.scene = scene;
}
}

View File

@ -49,16 +49,11 @@ export class TextLabel {
mat.diffuseTexture = dynamicTexture; mat.diffuseTexture = dynamicTexture;
//mat.emissiveColor = Color3.White(); //mat.emissiveColor = Color3.White();
dynamicTexture.drawText(text, null, null, font, "#000000", "#ffffff", true); dynamicTexture.drawText(text, null, null, font, "#000000", "#ffffff", true);
//Create plane and set dynamic texture as material //Create plane and set dynamic texture as material
//const plane = MeshBuilder.CreatePlane("text" + text, {width: planeWidth, height: height}, mesh.getScene()); //const plane = MeshBuilder.CreatePlane("text" + text, {width: planeWidth, height: height}, mesh.getScene());
const plane1 = this.createPlane(mat, mesh, text, planeWidth, height); const plane1 = this.createPlane(mat, mesh, text, planeWidth, height);
const plane2 = this.createPlane(mat, mesh, text, planeWidth, height); const plane2 = this.createPlane(mat, mesh, text, planeWidth, height);
plane2.rotation.y = Math.PI; plane2.rotation.y = Math.PI;
} }
private static createPlane(mat: Material, mesh: AbstractMesh, text: string, planeWidth: number, height: number): AbstractMesh { private static createPlane(mat: Material, mesh: AbstractMesh, text: string, planeWidth: number, height: number): AbstractMesh {
@ -68,12 +63,12 @@ export class TextLabel {
//plane.billboardMode = Mesh.BILLBOARDMODE_ALL; //plane.billboardMode = Mesh.BILLBOARDMODE_ALL;
plane.metadata = {exportable: true, label: true}; plane.metadata = {exportable: true, label: true};
const yOffset = mesh.getBoundingInfo().boundingSphere.radius; const yOffset = mesh.getBoundingInfo().boundingSphere.maximum.y;
plane.parent = mesh; plane.parent = mesh;
plane.position.y = yOffset + height / 2; plane.position.y = yOffset + height;
plane.scaling.y = 1 / mesh.scaling.y; //plane.scaling.y = mesh.scaling.y;
plane.scaling.x = 1 / mesh.scaling.x; //plane.scaling.x = mesh.scaling.x;
plane.scaling.z = 1 / mesh.scaling.z; //plane.scaling.z = mesh.scaling.z;
return plane; return plane;
} }
} }

View File

@ -1,4 +1,14 @@
import {Color3, Mesh, Observable, Scene, TransformNode, Vector3} from "@babylonjs/core"; import {
AssetContainer,
Color3,
Mesh,
MeshBuilder,
Observable,
Scene,
SceneLoader,
TransformNode,
Vector3
} from "@babylonjs/core";
import {Button3D, GUI3DManager, StackPanel3D, TextBlock} from "@babylonjs/gui"; import {Button3D, GUI3DManager, StackPanel3D, TextBlock} from "@babylonjs/gui";
import {ControllerEventType, Controllers} from "../controllers/controllers"; import {ControllerEventType, Controllers} from "../controllers/controllers";
@ -59,6 +69,7 @@ export class Toolbox {
} }
private readonly objectObservable: Observable<AssetContainer> = new Observable();
private buildToolbox() { private buildToolbox() {
const color = "#7777FF"; const color = "#7777FF";
@ -69,7 +80,26 @@ export class Toolbox {
this.addPanel.addControl(addButton); this.addPanel.addControl(addButton);
this.addPanel.node.scaling = new Vector3(.1, .1, .1); this.addPanel.node.scaling = new Vector3(.1, .1, .1);
this.addPanel.position = new Vector3(-.25, 0, 0); this.addPanel.position = new Vector3(-.25, 0, 0);
//@TODO: move this somewhere else, just to prototype loading objects.
//loadObject(this.scene, this.objectObservable);
this.objectObservable.add((container) => {
this.logger.debug("loaded object");
const data = container.instantiateModelsToScene(undefined, false, {doNotInstantiate: true});
const mesh = (data.rootNodes[0] as Mesh);
const bounds = data.rootNodes[0].getHierarchyBoundingVectors(true);
console.log(bounds);
const size = bounds.max.subtract(bounds.min);
const top = MeshBuilder.CreateBox("container", {width: size.x, height: size.y, depth: size.z}, this.scene);
top.position.y = 1.5;
top.metadata = {template: "#object-template", grabbable: true, tool: true};
mesh.parent = top;
mesh.position.y = -size.y / 2;
top.position = new Vector3(-.6, .2, 0);
//top.scaling = new Vector3(.1, .1, .1);
top.visibility = 0;
console.log(data.rootNodes.length);
});
addButton.onPointerClickObservable.add(() => { addButton.onPointerClickObservable.add(() => {
buildColor(Color3.Random(), this.scene, this.node, this.index++, this.colorChangeObservable); buildColor(Color3.Random(), this.scene, this.node, this.index++, this.colorChangeObservable);
}); });
@ -77,10 +107,20 @@ export class Toolbox {
this.node.parent.setEnabled(false); this.node.parent.setEnabled(false);
setMenuPosition(this.node.parent as Mesh, this.scene, setMenuPosition(this.node.parent as Mesh, this.scene,
Vector3.Zero()); Vector3.Zero());
//
} }
} }
function loadObject(scene: Scene, observable: Observable<AssetContainer>) {
SceneLoader.LoadAssetContainer("/assets/models/",
"server_racking_system.glb",
scene,
(container: AssetContainer) => {
observable.notifyObservers(container);
});
}
function createButton(): Button3D { function createButton(): Button3D {
const addButton = new Button3D("add-button"); const addButton = new Button3D("add-button");
const text = new TextBlock("add-button-text", "Add Color"); const text = new TextBlock("add-button-text", "Add Color");