Connection saving/loading.
This commit is contained in:
parent
4b93e3856e
commit
781e6fbd3e
@ -1,4 +1,5 @@
|
||||
import {
|
||||
AbstractMesh,
|
||||
CreateGreasedLine,
|
||||
GreasedLineMesh,
|
||||
GreasedLineTools,
|
||||
@ -37,6 +38,7 @@ export class DiagramConnection {
|
||||
}
|
||||
this.buildConnection();
|
||||
}
|
||||
|
||||
private readonly scene: Scene;
|
||||
private toAnchor: TransformNode;
|
||||
private fromAnchor: TransformNode;
|
||||
@ -85,7 +87,6 @@ export class DiagramConnection {
|
||||
} else {
|
||||
this.points = [Vector3.Zero(), Vector3.Zero()];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private setPoints() {
|
||||
@ -96,9 +97,7 @@ export class DiagramConnection {
|
||||
}
|
||||
|
||||
private buildConnection() {
|
||||
this.logger.debug('buildConnection');
|
||||
this.logger.debug(this._to);
|
||||
this.logger.debug(this._from);
|
||||
this.logger.debug(`buildConnection from ${this._from} to ${this._to}`);
|
||||
|
||||
this.recalculate();
|
||||
this._mesh = CreateGreasedLine(this.id,
|
||||
@ -115,10 +114,13 @@ export class DiagramConnection {
|
||||
this.recalculate();
|
||||
this.setPoints();
|
||||
});
|
||||
this.scene.onNewMeshAddedObservable.add((mesh) => {
|
||||
this.scene.onNewMeshAddedObservable.add(this.onMeshAdded, -1, true, this);
|
||||
return;
|
||||
}
|
||||
|
||||
private onMeshAdded = (mesh: AbstractMesh) => {
|
||||
if (mesh && mesh.id) {
|
||||
if (!this.toAnchor || !this.fromAnchor) {
|
||||
this.logger.debug('render');
|
||||
if (mesh?.id == this?._to) {
|
||||
this.logger.debug("Found to anchor");
|
||||
this.toAnchor = mesh;
|
||||
@ -129,11 +131,16 @@ export class DiagramConnection {
|
||||
this.fromAnchor = mesh;
|
||||
this._mesh.metadata.from = this.from;
|
||||
}
|
||||
if (this.toAnchor && this.fromAnchor) {
|
||||
this.logger.debug(`connection built from ${this._from} to ${this._to}`);
|
||||
this.removeObserver();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, -1, true, this);
|
||||
return;
|
||||
|
||||
private removeObserver() {
|
||||
this.logger.debug("removing observer");
|
||||
this.scene.onNewMeshAddedObservable.removeCallback(this.onMeshAdded);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,23 +44,26 @@ export class MeshConverter {
|
||||
}
|
||||
let mesh: AbstractMesh = scene.getMeshById(entity.id);
|
||||
if (mesh) {
|
||||
log.debug('mesh already exists');
|
||||
this.logger.debug(`mesh ${mesh.id} already exists`);
|
||||
} else {
|
||||
if (entity.template == "#connection-template") {
|
||||
const connection: DiagramConnection = new DiagramConnection(entity.from, entity.to, scene);
|
||||
|
||||
}
|
||||
this.logger.debug(`connection.mesh = ${connection.mesh.id}`);
|
||||
mesh = connection.mesh;
|
||||
} else {
|
||||
mesh = scene.getMeshById("tool-" + entity.template + "-" + entity.color);
|
||||
if (mesh) {
|
||||
if (mesh.isAnInstance) {
|
||||
log.debug('error: mesh is an instance');
|
||||
this.logger.error(`mesh ${mesh.id} is an instance`);
|
||||
} else {
|
||||
mesh = new InstancedMesh(entity.id, (mesh as Mesh));
|
||||
}
|
||||
} else {
|
||||
log.debug('no mesh found for ' + entity.template + "-" + entity.color);
|
||||
this.logger.warn('no mesh found for ' + entity.template + "-" + entity.color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (mesh) {
|
||||
mesh.metadata = {template: entity.template};
|
||||
if (entity.position) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user