Skip to content

Commit

Permalink
feat: KP Manager + Supporting Plan-Navigator + Cleanup (#355)
Browse files Browse the repository at this point in the history
* KP Manager + Supporting Plan-Navigator + Cleanup

* fix: remove forEach loops
  • Loading branch information
aka-blackboots authored Apr 9, 2024
1 parent 62257c0 commit 46d8a94
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 139 deletions.
118 changes: 75 additions & 43 deletions resources/openbim-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -25019,7 +25019,7 @@ class Alignment {
let accumulatedLength = 0;
for (const curve of alignment) {
const curveLength = curve.getLength();
if (accumulatedLength + curveLength >= targetLength) {
if (accumulatedLength + curveLength > targetLength) {
const targetCurveLength = targetLength - accumulatedLength;
const percentage = targetCurveLength / curveLength;
return { curve, percentage };
Expand Down Expand Up @@ -25075,7 +25075,7 @@ class CivilCurve {
for (let index = 0; index < this._index.array.length - 1; index += 2) {
const { startPoint, endPoint } = this.getSegment(index);
const segmentLength = startPoint.distanceTo(endPoint);
if (accumulatedLength + segmentLength >= targetLength) {
if (accumulatedLength + segmentLength > targetLength) {
// Position is the distance from the startPoint to the target point
const distanceToStart = targetLength - accumulatedLength;
return { distanceToStart, index, startPoint, endPoint };
Expand Down Expand Up @@ -120982,6 +120982,9 @@ class RoadNavigator extends Component {
this.setupEvents();
this.adjustRaycasterOnZoom();
}
initialize() {
console.log("View for RoadNavigator: ", this.view);
}
get() {
return null;
}
Expand Down Expand Up @@ -121052,8 +121055,10 @@ class RoadNavigator extends Component {
await this.updateMarker(result, "select");
await this.onHighlight.trigger({ mesh, point: result.point });
if (this._previousAlignment !== mesh.curve.alignment) {
this.clearKPStations();
this.showKPStations(mesh);
this.kpManager.clearKPStations();
// this.showKPStations(mesh);
this.kpManager.showKPStations(mesh);
// this.kpManager.createKP();
this._previousAlignment = mesh.curve.alignment;
}
}
Expand Down Expand Up @@ -121276,8 +121281,9 @@ CurveHighlighter.settings = {
};

class PlanHighlighter extends CurveHighlighter {
constructor(scene) {
constructor(scene, kpManager) {
super(scene, "horizontal");
this.kpManager = kpManager;
this.offset = 10;
this.markupLines = [];
this.markupMaterial = new THREE$1.LineBasicMaterial({
Expand Down Expand Up @@ -121387,6 +121393,7 @@ class PlanHighlighter extends CurveHighlighter {
return newPoints;
}
showLineInfo(curveMesh, offset) {
this.kpManager.clearMarkersByType("Length");
const positions = curveMesh.geometry.attributes.position.array;
const parallelCurvePoints = this.calculateParallelCurve(positions, positions.length / 3, offset);
const lengthGeometry = new THREE$1.BufferGeometry().setFromPoints(parallelCurvePoints);
Expand All @@ -121404,6 +121411,8 @@ class PlanHighlighter extends CurveHighlighter {
const lineEndDimensionlLine = new THREE$1.Line(endDimensionGeometry, this.markupMaterial);
this.scene.add(lineEndDimensionlLine);
this.markupLines.push(lineEndDimensionlLine);
// TODO: Felipe, replace with your implementation
this.kpManager.showCurveLength(lineParallelLine, curveMesh.curve.getLength());
}
showClothoidInfo(curveMesh, offset) {
const positions = curveMesh.geometry.attributes.position.array;
Expand Down Expand Up @@ -121541,9 +121550,9 @@ class MarkerManager {
}
set color(value) {
this._color = value;
this.markers.forEach((marker) => {
for (const marker of this.markers) {
marker.label.get().element.style.color = value;
});
}
}
set clusterThreeshold(value) {
this._clusterThreeshold = value;
Expand All @@ -121565,25 +121574,25 @@ class MarkerManager {
}
}
resetMarkers() {
this.markers.forEach((marker) => {
for (const marker of this.markers) {
marker.merged = false;
});
this.clusterLabels.forEach((cluster) => {
}
for (const cluster of this.clusterLabels) {
this.scene.remove(cluster.label.get());
});
}
this.clusterLabels.clear();
this._clusterKey = 0;
}
removeMergeMarkers() {
this.markers.forEach((marker) => {
for (const marker of this.markers) {
if (marker.merged) {
this.scene.remove(marker.label.get());
}
else {
this.scene.add(marker.label.get());
}
});
this.clusterLabels.forEach((cluster) => {
}
for (const cluster of this.clusterLabels) {
if (cluster.markerKeys.length === 1) {
const marker = Array.from(this.markers).find((marker) => marker.key === cluster.markerKeys[0]);
if (marker) {
Expand All @@ -121593,22 +121602,22 @@ class MarkerManager {
this.scene.remove(cluster.label.get());
this.clusterLabels.delete(cluster);
}
});
}
}
manageCluster() {
this.resetMarkers();
this.markers.forEach((marker) => {
for (const marker of this.markers) {
if (!marker.merged) {
this.currentKeys.clear();
this.markers.forEach((marker2) => {
for (const marker2 of this.markers) {
if (marker.key !== marker2.key && !marker2.merged) {
const distance = this.distance(marker.label, marker2.label);
if (distance < this._clusterThreeshold) {
this.currentKeys.add(marker2.key);
marker2.merged = true;
}
}
});
}
if (this.currentKeys.size > 0) {
if (!this.scene) {
return;
Expand All @@ -121629,7 +121638,7 @@ class MarkerManager {
this._clusterKey++;
}
}
});
}
this.removeMergeMarkers();
}
getAveragePositionFromLabels(clusterGroup) {
Expand Down Expand Up @@ -121695,6 +121704,7 @@ class MarkerManager {
mesh: new THREE$1.Mesh(),
key: this._markerKey.toString(),
merged: false,
type,
});
this._markerKey++;
}
Expand Down Expand Up @@ -121831,12 +121841,12 @@ class MarkerManager {
const boundingRegion = [];
const cluster = Array.from(this.clusterLabels).find((cluster) => cluster.key === key);
if (cluster) {
cluster.markerKeys.forEach((markerKey) => {
for (const markerKey of cluster.markerKeys) {
const marker = Array.from(this.markers).find((marker) => marker.key === markerKey);
if (marker) {
boundingRegion.push(marker.label.get().position);
}
});
}
this.scene.remove(cluster?.label.get());
this.clusterLabels.delete(cluster);
}
Expand All @@ -121862,18 +121872,26 @@ class MarkerManager {
}
createBox3FromPoints(points) {
const bbox = new THREE$1.Box3();
points.forEach((point) => {
for (const point of points) {
bbox.expandByPoint(point);
});
}
return bbox;
}
clearMarkers() {
this.markers.forEach((marker) => {
for (const marker of this.markers) {
this.scene.remove(marker.label.get());
});
}
this.markers.clear();
this._markerKey = 0;
}
clearMarkersByType(type) {
for (const marker of this.markers) {
if (marker.type === type) {
this.scene.remove(marker.label.get());
this.markers.delete(marker);
}
}
}
dispose() {
this.markers.forEach((marker) => {
marker.label.dispose();
Expand All @@ -121889,25 +121907,38 @@ class MarkerManager {
}
}

class KPStation {
class KPManager extends MarkerManager {
constructor(components, renderer, scene, controls, type) {
super(components, renderer, scene, controls);
this.divisionLength = 100;
// this.scene = scene;
this.type = type;
this.markerManager = new MarkerManager(components, renderer, scene, controls);
this.view = type;
}
showKPStations(mesh) {
if (this.type === "horizontal") {
if (this.view === "horizontal") {
const endKPStations = this.generateStartAndEndKP(mesh);
for (const [, data] of endKPStations) {
this.markerManager.addKPStation(data.value, data.normal);
this.addKPStation(data.value, data.normal);
}
const constantKPStations = this.generateConstantKP(mesh);
for (const [, data] of constantKPStations) {
this.markerManager.addKPStation(data.value, data.normal);
this.addKPStation(data.value, data.normal);
}
}
}
showCurveLength(line, length) {
const startPoint = new THREE$1.Vector3();
startPoint.x = line.geometry.getAttribute("position").getX(0);
startPoint.y = line.geometry.getAttribute("position").getY(0);
startPoint.z = line.geometry.getAttribute("position").getZ(0);
const endPoint = new THREE$1.Vector3();
endPoint.x = line.geometry.getAttribute("position").getX(1);
endPoint.y = line.geometry.getAttribute("position").getY(1);
endPoint.z = line.geometry.getAttribute("position").getZ(1);
const formattedLength = length.toFixed(2);
const middlePoint = new THREE$1.Vector3();
middlePoint.addVectors(startPoint, endPoint).multiplyScalar(0.5);
this.addMarkerAtPoint(formattedLength, middlePoint, "Length");
}
generateStartAndEndKP(mesh) {
const { alignment } = mesh.curve;
const data = new Map();
Expand Down Expand Up @@ -122054,10 +122085,10 @@ class KPStation {
return `0+${integerPart.padStart(3, "0")}.${formattedFractionalPart}`;
}
clearKPStations() {
this.markerManager.clearMarkers();
this.clearMarkers();
}
dispose() {
this.markerManager.dispose();
this.dispose();
}
}

Expand All @@ -122067,8 +122098,8 @@ class RoadPlanNavigator extends RoadNavigator {
this.view = "horizontal";
this.uiElement = new UIElement();
const scene = this.scene.get();
this.highlighter = new PlanHighlighter(scene);
this.kpStation = new KPStation(components, this.scene.renderer, this.scene.get(), this.scene.controls, this.view);
this.kpManager = new KPManager(components, this.scene.renderer, this.scene.get(), this.scene.controls, this.view);
this.highlighter = new PlanHighlighter(scene, this.kpManager);
this.setUI();
this.components.tools.add(RoadPlanNavigator.uuid, this);
this.onHighlight.add(({ mesh }) => {
Expand All @@ -122092,17 +122123,17 @@ class RoadPlanNavigator extends RoadNavigator {
bbox.reset();
await this.scene.controls.fitToBox(box, true);
}
showKPStations(curveMesh) {
this.kpStation.showKPStations(curveMesh);
}
clearKPStations() {
this.kpStation.clearKPStations();
}
// showKPStations(curveMesh: FRAGS.CurveMesh): void {
// this.kpStation.showKPStations(curveMesh);
// }
// clearKPStations(): void {
// this.kpStation.clearKPStations();
// }
setUI() {
const name = "Horizontal alignment";
const floatingWindow = CivilFloatingWindow.get(this.components, this.scene, name);
this.uiElement.set({ floatingWindow });
this.scene.controls.addEventListener("update", () => {
this.scene.controls.addEventListener("sleep", () => {
const screenSize = floatingWindow.containerSize;
const { zoom } = this.scene.camera;
this.highlighter.updateOffset(screenSize, zoom, true);
Expand All @@ -122125,6 +122156,7 @@ class RoadElevationNavigator extends RoadNavigator {
this.setUI();
const scene = this.scene.get();
this.highlighter = new CurveHighlighter(scene, "vertical");
this.kpManager = new KPManager(components, this.scene.renderer, this.scene.get(), this.scene.controls, this.view);
}
get() {
return null;
Expand Down
10 changes: 10 additions & 0 deletions src/civil/RoadElevationNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Drawer } from "../../ui";
import { Components } from "../../core";
import { RoadNavigator } from "../RoadNavigator";
import { CurveHighlighter } from "../RoadNavigator/src/curve-highlighter";
import { KPManager } from "../RoadNavigator/src/kp-manager";

export class RoadElevationNavigator extends RoadNavigator implements UI {
static readonly uuid = "097eea29-2d5a-431a-a247-204d44670621" as const;
Expand All @@ -16,11 +17,20 @@ export class RoadElevationNavigator extends RoadNavigator implements UI {

highlighter: CurveHighlighter;

kpManager: KPManager;

constructor(components: Components) {
super(components);
this.setUI();
const scene = this.scene.get();
this.highlighter = new CurveHighlighter(scene, "vertical");
this.kpManager = new KPManager(
components,
this.scene.renderer,
this.scene.get(),
this.scene.controls,
this.view
);
}

get() {
Expand Down
20 changes: 16 additions & 4 deletions src/civil/RoadNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Alignment, FragmentsGroup } from "bim-fragment";
import { Component, Event } from "../../base-types";
import { Components, Simple2DMarker, Simple2DScene } from "../../core";
import { CurveHighlighter } from "./src/curve-highlighter";
import { KPManager } from "./src/kp-manager";

export type CivilMarkerType = "hover" | "select";

Expand All @@ -16,8 +17,11 @@ export abstract class RoadNavigator extends Component<any> {

abstract highlighter: CurveHighlighter;

abstract showKPStations(curveMesh: FRAGS.CurveMesh): void;
abstract clearKPStations(): void;
// abstract showKPStations(curveMesh: FRAGS.CurveMesh): void;
// abstract clearKPStations(): void;

// abstract kpManager: KPManager;
abstract kpManager: KPManager;

readonly onHighlight = new Event<{
point: THREE.Vector3;
Expand Down Expand Up @@ -57,6 +61,10 @@ export abstract class RoadNavigator extends Component<any> {
this.adjustRaycasterOnZoom();
}

initialize() {
console.log("View for RoadNavigator: ", this.view);
}

get() {
return null as any;
}
Expand Down Expand Up @@ -154,8 +162,12 @@ export abstract class RoadNavigator extends Component<any> {
await this.onHighlight.trigger({ mesh, point: result.point });

if (this._previousAlignment !== mesh.curve.alignment) {
this.clearKPStations();
this.showKPStations(mesh);
this.kpManager.clearKPStations();
// this.showKPStations(mesh);
this.kpManager.showKPStations(mesh);

// this.kpManager.createKP();

this._previousAlignment = mesh.curve.alignment;
}
}
Expand Down
Loading

2 comments on commit 46d8a94

@ervinalla99
Copy link

@ervinalla99 ervinalla99 commented on 46d8a94 Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aka-blackboots . Do you have any idea how to set the marker at a specific KP along the Alignment in a parametric way? Let's say I want to place the market at KP 2 or 2.5 along the Alignment length?

@aka-blackboots
Copy link
Contributor Author

@aka-blackboots aka-blackboots commented on 46d8a94 Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ervinalla99 as far as I remember the divisions are set at 100.
@agviegas if we introduce civilMarker.setDivisions(n) this should be possible I guess 🤔

Please sign in to comment.