Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 144 additions & 1 deletion src/civil/RoadNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export abstract class RoadNavigator extends Component<any> {
}
const { alignments } = model.civilData;
const allAlignments = filter || alignments.values();

const scene = this.scene.get();

const totalBBox: THREE.Box3 = new THREE.Box3();
Expand All @@ -77,6 +76,22 @@ export abstract class RoadNavigator extends Component<any> {
if (!alignment) {
throw new Error("Alignment not found!");
}
if (this.view !== "vertical") {
// TODO: Generate All The KPs and Stations
// TODO: Look if
this.markerManager.addCivilMarker(
`0+${alignment.initialKP.toFixed(2)}`,
alignment[this.view][0].mesh,
"InitialKP"
);


this.markerManager.addCivilMarker(
"end",
alignment[this.view][alignment[this.view].length - 1].mesh,
"FinalKP"
);
}

for (const curve of alignment[this.view]) {
scene.add(curve.mesh);
Expand Down Expand Up @@ -149,6 +164,134 @@ export abstract class RoadNavigator extends Component<any> {
const result = intersects;
const mesh = result.object as FRAGS.CurveMesh;
this.highlighter.select(mesh);

// TODO: Example and Test, should be replaced with the actual implementation
// this.markerManager.addCivilMarker("Curve", mesh, "Length");
await this.onHighlight.trigger({ mesh, point });

if (this.view === "vertical") {
// Add markers elevation

// Create defSegments desde array mesh.geometry.attributes.position.array
const setDefSegments = (segmentsArray: any) => {
let defSegments: any = [];
let slope: any = [];

// Calcular pendiente desde cada PK
const calculateSlopeSegment = (
point1: number[],
point2: number[]
) => {
const deltaY = point2[1] - point1[1];
const deltaX = point2[0] - point1[0];
return deltaY / deltaX;
};

// Itera sobre cada segmento y calcula la pendiente
for (let i = 0; i < segmentsArray.length; i++) {
const segment = segmentsArray[i];
let startX: number, startY: number, endX: number, endY: number;

// Encuentra el primer punto en el segmento
for (let j = 0; j < Object.keys(segment).length / 3; j++) {
if (
segment[j * 3] !== undefined &&
segment[j * 3 + 1] !== undefined
) {
startX = segment[j * 3];
startY = segment[j * 3 + 1];
break;
}
}

// Encuentra el último punto en el segmento
for (let j = Object.keys(segment).length / 3 - 1; j >= 0; j--) {
if (
segment[j * 3] !== undefined &&
segment[j * 3 + 1] !== undefined
) {
endX = segment[j * 3];
endY = segment[j * 3 + 1];
break;
}
}

const defSlope = calculateSlopeSegment(
// @ts-ignore
[startX, startY],
// @ts-ignore
[endX, endY]
);
const slopeSegment = (defSlope * 100).toFixed(2);
slope.push({ slope: slopeSegment });
}
segmentsArray.forEach((segment: any) => {
for (let i = 0; i < segment.length - 3; i += 3) {
let startX = segment[i];
let startY = segment[i + 1];
let startZ = segment[i + 2];

let endX = segment[i + 3];
let endY = segment[i + 4];
let endZ = segment[i + 5];

// Calcular la longitud del segmento
let segmentLength = Math.sqrt(
Math.pow(endX - startX, 2) +
Math.pow(endY - startY, 2) +
Math.pow(endZ - startZ, 2)
);

defSegments.push({
distance: segmentLength,
start: new THREE.Vector3(startX, startY, startZ),
end: new THREE.Vector3(endX, endY, endZ),
});
}
});

return { defSegments, slope };
};

const { alignment } = mesh.curve;
let positionsVertical = [];

// Crear lista de alignments verticales
for (const align of alignment.vertical) {
const pos = align.mesh.geometry.attributes.position.array;

positionsVertical.push(pos);
}

const { defSegments, slope } = setDefSegments(positionsVertical);

alignment.vertical.forEach((align, index: number) => {
this.markerManager.addCivilMarker(
`S: ${slope[index].slope}%`,
align.mesh,
"Slope"
);

this.markerManager.addCivilMarker(
`H: ${defSegments[index].end.y.toFixed(2)}`,
align.mesh,
"Coordinate"
);
});

this.markerManager.addCivilMarker(
"KP: 0",
alignment.vertical[0].mesh,
"InitialKPV"
);

this.markerManager.addCivilMarker(
`KP: ${alignment.vertical.length}`,
alignment.vertical[alignment.vertical.length - 1].mesh,
"FinalKPV"
);
}

await this.updateMarker(result, "select");

await this.onHighlight.trigger({ mesh, point: result.point });
Expand Down
55 changes: 54 additions & 1 deletion src/core/Simple2DMarker/src/marker-manager.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import * as FRAGS from "bim-fragment";
import * as THREE from "three";
import { Components, Simple2DScene, Simple2DMarker } from "../..";
import { FragmentBoundingBox } from "../../../fragments";
import CameraControls from "camera-controls";
import { Components, Simple2DMarker, SimpleRenderer } from "../..";
import { PostproductionRenderer } from "../../../navigation/PostproductionRenderer";


type CivilLabels =
| "Station"
| "Radius"
| "Length"
| "InitialKP"
| "FinalKP"
| "Coordinate"
| "InitialKPV"
| "FinalKPV"
| "Slope";
| "KP";


interface IMarker {
key: string;
label: Simple2DMarker;
Expand Down Expand Up @@ -370,8 +378,53 @@ export class MarkerManager {
marker
.get()
.position.copy(pointEnd.clone().add(pointStart).divideScalar(2));
}
} else if (type === "Coordinate") {
const span = document.createElement("span");
span.innerHTML = text;
span.style.color = this._color;

const marker = new Simple2DMarker(this.components, span, this.scene);

const { position } = mesh.geometry.attributes;
const setArray = position.array.length / 3;

const firstIndex = (setArray - 1) * 3;
const lastIndex = position.array.slice(firstIndex, firstIndex + 3);

marker.get().position.set(lastIndex[0], lastIndex[1] + 10, lastIndex[2]);
} else if (type === "InitialKPV") {
const { position } = mesh.geometry.attributes;
const pX = position.getX(0);
const pY = position.getY(0);
const pZ = position.getZ(0);
marker.get().position.set(pX - 20, pY, pZ);
} else if (type === "FinalKPV") {
const { position } = mesh.geometry.attributes;

const pX = position.getX(mesh.geometry.attributes.position.count - 1);
const pY = position.getY(mesh.geometry.attributes.position.count - 1);
const pZ = position.getZ(mesh.geometry.attributes.position.count - 1);
marker.get().position.set(pX + 20, pY, pZ);
} else if (type === "Slope") {
span.style.color = "grey";

const { position } = mesh.geometry.attributes;

const pointStart = new THREE.Vector3();
pointStart.x = position.getX(0);
pointStart.y = position.getY(0);
pointStart.z = position.getZ(0);

const pointEnd = new THREE.Vector3();
pointEnd.x = position.getX(position.count - 1);
pointEnd.y = position.getY(position.count - 1);
pointEnd.z = position.getZ(position.count - 1);

const midPoint = new THREE.Vector3();
midPoint.addVectors(pointStart, pointEnd).multiplyScalar(0.5);

marker.get().position.set(midPoint.x, midPoint.y - 10, midPoint.z);
}
this.markers.add({
label: marker,
mesh,
Expand Down