Changed Connector Width.

This commit is contained in:
Michael Mainguy 2023-08-05 15:04:17 -05:00
parent 781e6fbd3e
commit 5a26f7bca1
2 changed files with 42 additions and 8 deletions

View File

@ -1,5 +1,6 @@
import { import {
AbstractMesh, AbstractMesh,
Color3,
CreateGreasedLine, CreateGreasedLine,
GreasedLineMesh, GreasedLineMesh,
GreasedLineTools, GreasedLineTools,
@ -39,7 +40,7 @@ export class DiagramConnection {
this.buildConnection(); this.buildConnection();
} }
private readonly scene: Scene; private scene: Scene;
private toAnchor: TransformNode; private toAnchor: TransformNode;
private fromAnchor: TransformNode; private fromAnchor: TransformNode;
private points: Vector3[] = []; private points: Vector3[] = [];
@ -101,23 +102,55 @@ export class DiagramConnection {
this.recalculate(); this.recalculate();
this._mesh = CreateGreasedLine(this.id, 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; this._mesh.id = this.id;
if (!this._mesh.metadata) { if (!this._mesh.metadata) {
this._mesh.metadata = {template: "#connection-template", from: this._from}; 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) { if (this._to) {
this.mesh.metadata.to = this.to; this.mesh.metadata.to = this.to;
} }
this.setPoints(); this.setPoints();
this.scene.onBeforeRenderObservable.add(() => { this.scene.onBeforeRenderObservable.add(this.beforeRender, -1, true, this);
this.recalculate();
this.setPoints();
});
this.scene.onNewMeshAddedObservable.add(this.onMeshAdded, -1, true, this); this.scene.onNewMeshAddedObservable.add(this.onMeshAdded, -1, true, this);
this.mesh.onDisposeObservable.add(this.removeConnection, -1, true, this);
return; 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) => { private onMeshAdded = (mesh: AbstractMesh) => {
if (mesh && mesh.id) { if (mesh && mesh.id) {
if (!this.toAnchor || !this.fromAnchor) { if (!this.toAnchor || !this.fromAnchor) {

View File

@ -67,7 +67,6 @@ export class DiagramManager {
this.onDiagramEventObservable.add(this.onDiagramEvent, -1, true, this); this.onDiagramEventObservable.add(this.onDiagramEvent, -1, true, this);
this.logger.debug("DiagramManager constructed"); this.logger.debug("DiagramManager constructed");
} }
public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh { public createCopy(mesh: AbstractMesh, copy: boolean = false): AbstractMesh {
let newMesh; let newMesh;
if (!mesh.isAnInstance) { if (!mesh.isAnInstance) {
@ -147,9 +146,11 @@ export class DiagramManager {
break; break;
case DiagramEventType.ADD: case DiagramEventType.ADD:
this.getPersistenceManager()?.add(mesh); this.getPersistenceManager()?.add(mesh);
if (!mesh.actionManager) {
mesh.actionManager = this.actionManager;
}
DiagramShapePhysics DiagramShapePhysics
.applyPhysics(mesh, this.scene); .applyPhysics(mesh, this.scene);
break; break;
case DiagramEventType.MODIFY: case DiagramEventType.MODIFY:
this.getPersistenceManager()?.modify(mesh); this.getPersistenceManager()?.modify(mesh);