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
23 changes: 9 additions & 14 deletions resources/openbim-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -21634,6 +21634,7 @@ class Simple2DScene extends Component {
this.controls.setTarget(0, 0, 0);
this.controls.addEventListener("update", () => this.grid.regenerate());
this.controls.mouseButtons.left = CameraControls.ACTION.TRUCK;
this.controls.dollyToCursor = true;
}
/**
* {@link Component.get}
Expand Down Expand Up @@ -120496,10 +120497,12 @@ class RoadNavigator extends Component {
this.enabled = true;
this.caster = new THREE$1.Raycaster();
this._curves = new Set();
this.curveMeshes = [];
this.onHighlight = new Event();
this.caster.params.Line = { threshold: 5 };
this.scene = new Simple2DScene(this.components, false);
this.highlighter = new CurveHighlighter(this.scene.get());
this.setupEvents();
}
get() {
return null;
Expand All @@ -120523,6 +120526,7 @@ class RoadNavigator extends Component {
for (const curve of alignment[this.view]) {
this._curves.add(curve);
scene.add(curve.mesh);
this.curveMeshes.push(curve.mesh);
if (!totalBBox.isEmpty()) {
totalBBox.expandByObject(curve.mesh);
}
Expand All @@ -120536,12 +120540,10 @@ class RoadNavigator extends Component {
}
}
await this.scene.controls.fitToBox(totalBBox, false);
const curveMesh = [];
for (const curve of this._curves) {
curveMesh.push(curve.mesh);
}
}
setupEvents() {
const mousePositionSphere = new THREE$1.Mesh(new THREE$1.SphereGeometry(0.5), new THREE$1.MeshBasicMaterial({ color: 0xff0000 }));
scene.add(mousePositionSphere);
this.scene.get().add(mousePositionSphere);
this.scene.uiElement
.get("container")
.domElement.addEventListener("mousemove", (event) => {
Expand All @@ -120552,20 +120554,13 @@ class RoadNavigator extends Component {
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
const raycaster = new THREE$1.Raycaster();
raycaster.setFromCamera(mouse, this.scene.camera);
const intersects = raycaster.intersectObjects(curveMesh);
const intersects = raycaster.intersectObjects(this.curveMeshes);
if (intersects.length > 0) {
const intersect = intersects[0];
const { point } = intersect;
mousePositionSphere.position.copy(point);
}
});
this.setupEvents();
}
setupEvents() {
const curveMesh = [];
for (const curve of this._curves) {
curveMesh.push(curve.mesh);
}
this.scene.uiElement
.get("container")
.domElement.addEventListener("click", (event) => {
Expand All @@ -120576,7 +120571,7 @@ class RoadNavigator extends Component {
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
const raycaster = new THREE$1.Raycaster();
raycaster.setFromCamera(mouse, this.scene.camera);
const intersects = raycaster.intersectObjects(curveMesh);
const intersects = raycaster.intersectObjects(this.curveMeshes);
if (intersects.length > 0) {
const curve = intersects[0].object;
this.onHighlight.trigger(curve);
Expand Down
26 changes: 8 additions & 18 deletions src/civil/RoadNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export abstract class RoadNavigator extends Component<any> {
abstract view: "horizontal" | "vertical";

protected _curves = new Set<FRAGS.CivilCurve>();
private curveMeshes: THREE.Object3D[] = [];

readonly onHighlight = new Event();
highlighter: CurveHighlighter;
Expand All @@ -24,6 +25,7 @@ export abstract class RoadNavigator extends Component<any> {
this.caster.params.Line = { threshold: 5 };
this.scene = new Simple2DScene(this.components, false);
this.highlighter = new CurveHighlighter(this.scene.get());
this.setupEvents();
}

get() {
Expand Down Expand Up @@ -53,6 +55,7 @@ export abstract class RoadNavigator extends Component<any> {
for (const curve of alignment[this.view]) {
this._curves.add(curve);
scene.add(curve.mesh);
this.curveMeshes.push(curve.mesh);

if (!totalBBox.isEmpty()) {
totalBBox.expandByObject(curve.mesh);
Expand All @@ -68,19 +71,15 @@ export abstract class RoadNavigator extends Component<any> {
}

await this.scene.controls.fitToBox(totalBBox, false);
}

const curveMesh: THREE.Object3D[] = [];

for (const curve of this._curves) {
curveMesh.push(curve.mesh);
}

setupEvents() {
const mousePositionSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.5),
new THREE.MeshBasicMaterial({ color: 0xff0000 })
);

scene.add(mousePositionSphere);
this.scene.get().add(mousePositionSphere);

this.scene.uiElement
.get("container")
Expand All @@ -92,23 +91,14 @@ export abstract class RoadNavigator extends Component<any> {
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, this.scene.camera);
const intersects = raycaster.intersectObjects(curveMesh);
const intersects = raycaster.intersectObjects(this.curveMeshes);
if (intersects.length > 0) {
const intersect = intersects[0];
const { point } = intersect;
mousePositionSphere.position.copy(point);
}
});

this.setupEvents();
}

setupEvents() {
const curveMesh: THREE.Object3D[] = [];
for (const curve of this._curves) {
curveMesh.push(curve.mesh);
}

this.scene.uiElement
.get("container")
.domElement.addEventListener("click", (event) => {
Expand All @@ -119,7 +109,7 @@ export abstract class RoadNavigator extends Component<any> {
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, this.scene.camera);
const intersects = raycaster.intersectObjects(curveMesh);
const intersects = raycaster.intersectObjects(this.curveMeshes);
if (intersects.length > 0) {
const curve = intersects[0].object as THREE.LineSegments;
this.onHighlight.trigger(curve);
Expand Down
1 change: 1 addition & 0 deletions src/core/Simple2DScene/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class Simple2DScene
this.controls.setTarget(0, 0, 0);
this.controls.addEventListener("update", () => this.grid.regenerate());
this.controls.mouseButtons.left = CameraControls.ACTION.TRUCK;
this.controls.dollyToCursor = true;
}

/**
Expand Down