Skip to content

Commit

Permalink
feat: make cross section work with marker
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Apr 8, 2024
1 parent e793f4e commit 8ce261d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 78 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/three": "0.160.0",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"bim-fragment": "1.5.0-alpha.5",
"bim-fragment": "1.5.0-alpha.6",
"cpy-cli": "^3.1.1",
"eslint": "^7.28.0",
"eslint-config-airbnb-base": "^14.2.1",
Expand Down Expand Up @@ -57,7 +57,7 @@
"unzipit": "^1.4.3"
},
"peerDependencies": {
"bim-fragment": "1.5.0-alpha.5",
"bim-fragment": "1.5.0-alpha.6",
"three": "^0.160.1",
"web-ifc": "0.0.51"
}
Expand Down
38 changes: 16 additions & 22 deletions resources/openbim-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -121434,12 +121434,13 @@ class RoadNavigator extends Component {
async updateMarker(intersects, type) {
const { point, index, object } = intersects;
const mesh = object;
const curve = mesh.curve;
const alignment = mesh.curve.alignment;
const percentage = alignment.getPercentageAt(point, this.view);
const markerPoint = point.clone();
this.setMouseMarker(markerPoint, mesh, index, type);
if (percentage !== null) {
await this.onMarkerChange.trigger({ alignment, percentage, type });
await this.onMarkerChange.trigger({ alignment, percentage, type, curve });
}
}
}
Expand Down Expand Up @@ -121949,41 +121950,34 @@ class RoadCrossSectionNavigator extends Component {
get() {
return null;
}
updateStyles() {
const scene = this.scene.get();
const edges = this.plane.edges.get();
for (const styleName in edges) {
const { mesh } = edges[styleName];
scene.add(mesh);
}
}
async set(curve, point, curveIndex) {
if (curve.geometry.index === null) {
async set(curveMesh, point) {
this.plane.enabled = true;
const percentage = curveMesh.curve.getPercentageAt(point);
if (percentage === null)
return;
const { startPoint, endPoint } = curveMesh.curve.getSegmentAt(percentage);
if (curveMesh.geometry.index === null) {
throw new Error("Geometry must be indexed!");
}
const pos = curve.geometry.attributes.position.array;
const index = curve.geometry.index.array;
const start = index[curveIndex] * 3;
const end = index[curveIndex + 1] * 3;
const startX = pos[start];
const startY = pos[start + 1];
const startZ = pos[start + 2];
const endX = pos[end];
const endY = pos[end + 1];
const endZ = pos[end + 2];
const direction = new THREE$1.Vector3(endX - startX, endY - startY, endZ - startZ);
const direction = new THREE$1.Vector3();
direction.subVectors(endPoint, startPoint);
direction.normalize();
await this.plane.setFromNormalAndCoplanarPoint(direction, point);
const transform = this.plane.helper.matrix.clone();
transform.invert();
const scene = this.scene.get();
const edges = this.plane.edges.get();
for (const styleName in edges) {
const { mesh } = edges[styleName];
mesh.position.set(0, 0, 0);
mesh.rotation.set(0, 0, 0);
mesh.updateMatrix();
mesh.applyMatrix4(transform);
if (mesh.parent !== scene) {
scene.add(mesh);
}
}
this.plane.enabled = false;
}
setUI() {
const name = "Cross section";
Expand Down
60 changes: 42 additions & 18 deletions src/civil/RoadCrossSectionNavigator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,55 @@

// Set up road navigator

const navigator = new OBC.Road3DNavigator(components);

const navigator = new OBC.RoadPlanNavigator(components);
const horizontalWindow = navigator.uiElement.get("floatingWindow");
horizontalWindow.visible = true;
navigator.draw(model);
navigator.setup();

navigator.highlighter.hoverCurve.material.color.set(1, 1, 1);
navigator.highlighter.hoverPoints.material.color.set(1, 1, 1);
const elevationNavigator = new OBC.RoadElevationNavigator(components);
const drawer = elevationNavigator.uiElement.get("drawer");
drawer.visible = true;

const sphere = new THREE.Sphere(undefined, 20);
const navigator3D = new OBC.Road3DNavigator(components);
navigator3D.draw(model);
navigator3D.setup();

navigator.onHighlight.add(({ point }) => {
// sphere.center.copy(point);
// components.camera.controls.fitToSphere(sphere, true);
});
navigator3D.highlighter.hoverCurve.material.color.set(1, 1, 1);
navigator3D.highlighter.hoverPoints.material.color.set(1, 1, 1);

const crossNavigator = new OBC.RoadCrossSectionNavigator(components);
navigator.onHighlight.add(({ mesh, point }) => {
elevationNavigator.clear();
elevationNavigator.draw(model, [mesh.curve.alignment]);
elevationNavigator.highlighter.select(mesh);
navigator3D.highlighter.select(mesh);

const horizontalWindow = crossNavigator.uiElement.get("floatingWindow");
horizontalWindow.visible = true;
const index = mesh.curve.index;
const curve3d = mesh.curve.alignment.absolute[index];
curve3d.mesh.geometry.computeBoundingSphere();
components.camera.controls.fitToSphere(curve3d.mesh.geometry.boundingSphere, true);
})

navigator.onMarkerChange.add(({ alignment, percentage, type, curve }) => {
elevationNavigator.setMarker(alignment, percentage, type);

// navigator.highlighter.highlightColor = 0xff0000;
navigator.onHighlight.add(({ curve, point, index }) => {
console.log(crossNavigator.plane);
crossNavigator.set(curve, point, index);
crossNavigator.updateStyles();
});
if(type === "select") {
const mesh = curve.alignment.absolute[curve.index].mesh;
const point = alignment.getPointAt(percentage, "absolute");
crossNavigator.set(mesh, point);
}
})

// const navigator = new OBC.Road3DNavigator(components);
// navigator.draw(model);
// navigator.setup();
//
// navigator.highlighter.hoverCurve.material.color.set(1, 1, 1);
// navigator.highlighter.hoverPoints.material.color.set(1, 1, 1);

const crossNavigator = new OBC.RoadCrossSectionNavigator(components);
const crossWindow = crossNavigator.uiElement.get("floatingWindow");
crossWindow.visible = true;

crossNavigator.plane.visible = false;

Expand Down
45 changes: 16 additions & 29 deletions src/civil/RoadCrossSectionNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,54 +38,41 @@ export class RoadCrossSectionNavigator extends Component<any> implements UI {
return null as any;
}

updateStyles() {
const scene = this.scene.get();
const edges = this.plane.edges.get();
for (const styleName in edges) {
const { mesh } = edges[styleName];
scene.add(mesh);
}
}
async set(curveMesh: FRAGS.CurveMesh, point: THREE.Vector3) {
this.plane.enabled = true;

async set(curve: FRAGS.CurveMesh, point: THREE.Vector3, curveIndex: number) {
if (curve.geometry.index === null) {
const percentage = curveMesh.curve.getPercentageAt(point);
if (percentage === null) return;
const { startPoint, endPoint } = curveMesh.curve.getSegmentAt(percentage);

if (curveMesh.geometry.index === null) {
throw new Error("Geometry must be indexed!");
}

const pos = curve.geometry.attributes.position.array;
const index = curve.geometry.index.array;

const start = index[curveIndex] * 3;
const end = index[curveIndex + 1] * 3;

const startX = pos[start];
const startY = pos[start + 1];
const startZ = pos[start + 2];

const endX = pos[end];
const endY = pos[end + 1];
const endZ = pos[end + 2];

const direction = new THREE.Vector3(
endX - startX,
endY - startY,
endZ - startZ
);
const direction = new THREE.Vector3();
direction.subVectors(endPoint, startPoint);
direction.normalize();

await this.plane.setFromNormalAndCoplanarPoint(direction, point);

const transform = this.plane.helper.matrix.clone();
transform.invert();

const scene = this.scene.get();

const edges = this.plane.edges.get();
for (const styleName in edges) {
const { mesh } = edges[styleName];
mesh.position.set(0, 0, 0);
mesh.rotation.set(0, 0, 0);
mesh.updateMatrix();
mesh.applyMatrix4(transform);
if (mesh.parent !== scene) {
scene.add(mesh);
}
}

this.plane.enabled = false;
}

private setUI() {
Expand Down
4 changes: 3 additions & 1 deletion src/civil/RoadNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export abstract class RoadNavigator extends Component<any> {
alignment: FRAGS.Alignment;
percentage: number;
type: CivilMarkerType;
curve: FRAGS.CivilCurve;
}>();

private _curveMeshes: FRAGS.CurveMesh[] = [];
Expand Down Expand Up @@ -248,12 +249,13 @@ export abstract class RoadNavigator extends Component<any> {
) {
const { point, index, object } = intersects;
const mesh = object as FRAGS.CurveMesh;
const curve = mesh.curve;
const alignment = mesh.curve.alignment;
const percentage = alignment.getPercentageAt(point, this.view);
const markerPoint = point.clone();
this.setMouseMarker(markerPoint, mesh, index, type);
if (percentage !== null) {
await this.onMarkerChange.trigger({ alignment, percentage, type });
await this.onMarkerChange.trigger({ alignment, percentage, type, curve });
}
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1799,16 +1799,16 @@ __metadata:
languageName: node
linkType: hard

"bim-fragment@npm:1.5.0-alpha.5":
version: 1.5.0-alpha.5
resolution: "bim-fragment@npm:1.5.0-alpha.5"
"bim-fragment@npm:1.5.0-alpha.6":
version: 1.5.0-alpha.6
resolution: "bim-fragment@npm:1.5.0-alpha.6"
dependencies:
flatbuffers: ^23.3.3
three-mesh-bvh: 0.7.0
unzipit: 1.4.3
peerDependencies:
three: ^0.160.1
checksum: acdf2537081b412486ed24aa5e87de974ad8ea64f7f76f25ff8e428953d512dd134f0fb7925fd55f6187fb652a7b733577a2651895902076cb9615298cac37c6
checksum: 4141a022d880743f28d68b38aeb2545886b001857a4076ce3aa2602b91eb471c870cf665f3b7c0f2811d6cba7659e0aae2538a96c7eddf24e5caa045dc6af9b0
languageName: node
linkType: hard

Expand Down Expand Up @@ -5876,7 +5876,7 @@ __metadata:
"@types/three": 0.160.0
"@typescript-eslint/eslint-plugin": ^4.27.0
"@typescript-eslint/parser": ^4.27.0
bim-fragment: 1.5.0-alpha.5
bim-fragment: 1.5.0-alpha.6
camera-controls: 2.7.3
cpy-cli: ^3.1.1
dexie: ^3.2.3
Expand Down Expand Up @@ -5905,7 +5905,7 @@ __metadata:
unzipit: ^1.4.3
web-ifc: 0.0.51
peerDependencies:
bim-fragment: 1.5.0-alpha.5
bim-fragment: 1.5.0-alpha.6
three: ^0.160.1
web-ifc: 0.0.51
languageName: unknown
Expand Down

0 comments on commit 8ce261d

Please sign in to comment.