From 5a26f7bca17c5d4ece055353431fcfbde7d585f0 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Sat, 5 Aug 2023 15:04:17 -0500 Subject: [PATCH] Changed Connector Width. --- src/diagram/diagramConnection.ts | 45 +++++++++++++++++++++++++++----- src/diagram/diagramManager.ts | 5 ++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/diagram/diagramConnection.ts b/src/diagram/diagramConnection.ts index 263dacf..8475eeb 100644 --- a/src/diagram/diagramConnection.ts +++ b/src/diagram/diagramConnection.ts @@ -1,5 +1,6 @@ import { AbstractMesh, + Color3, CreateGreasedLine, GreasedLineMesh, GreasedLineTools, @@ -39,7 +40,7 @@ export class DiagramConnection { this.buildConnection(); } - private readonly scene: Scene; + private scene: Scene; private toAnchor: TransformNode; private fromAnchor: TransformNode; private points: Vector3[] = []; @@ -101,23 +102,55 @@ export class DiagramConnection { this.recalculate(); this._mesh = CreateGreasedLine(this.id, - {points: (GreasedLineTools.ToNumberArray(this.points) as number[]), updatable: true}, null, this.scene); + { + points: (GreasedLineTools.ToNumberArray(this.points) as number[]), + updatable: true + }, {color: Color3.Black()}, this.scene); + this._mesh.intersectionThreshold = 10; + this.logger.debug(this._mesh.widths); + this._mesh.widths = [0.1, 0.1, .1, .1]; + this._mesh.id = this.id; if (!this._mesh.metadata) { this._mesh.metadata = {template: "#connection-template", from: this._from}; + } else { + this._mesh.metadata.template = "#connection-template"; + this._mesh.metadata.from = this._from; } if (this._to) { this.mesh.metadata.to = this.to; } this.setPoints(); - this.scene.onBeforeRenderObservable.add(() => { - this.recalculate(); - this.setPoints(); - }); + this.scene.onBeforeRenderObservable.add(this.beforeRender, -1, true, this); this.scene.onNewMeshAddedObservable.add(this.onMeshAdded, -1, true, this); + this.mesh.onDisposeObservable.add(this.removeConnection, -1, true, this); return; } + private beforeRender = () => { + this.recalculate(); + this.setPoints(); + } + private removeConnection = () => { + this.logger.debug("removeConnection"); + this.scene.onBeforeRenderObservable.removeCallback(this.beforeRender); + this.removeObserver(); + if (this.toAnchor) { + this.toAnchor = null; + } + if (this.fromAnchor) { + this.fromAnchor = null; + } + if (this._mesh) { + this._mesh = null; + } + if (this.scene) { + this.scene = null; + } + if (this.logger) { + this.logger = null; + } + } private onMeshAdded = (mesh: AbstractMesh) => { if (mesh && mesh.id) { if (!this.toAnchor || !this.fromAnchor) { diff --git a/src/diagram/diagramManager.ts b/src/diagram/diagramManager.ts index 79f20bc..a7c60c9 100644 --- a/src/diagram/diagramManager.ts +++ b/src/diagram/diagramManager.ts @@ -67,7 +67,6 @@ export class DiagramManager { this.onDiagramEventObservable.add(this.onDiagramEvent, -1, true, this); this.logger.debug("DiagramManager constructed"); } - public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh { let newMesh; if (!mesh.isAnInstance) { @@ -147,9 +146,11 @@ export class DiagramManager { break; case DiagramEventType.ADD: this.getPersistenceManager()?.add(mesh); + if (!mesh.actionManager) { + mesh.actionManager = this.actionManager; + } DiagramShapePhysics .applyPhysics(mesh, this.scene); - break; case DiagramEventType.MODIFY: this.getPersistenceManager()?.modify(mesh);