Skip to content

Commit 62f736c

Browse files
committed
fix: allow to use measurement tools with clipping planes
1 parent c42958d commit 62f736c

File tree

7 files changed

+89
-5
lines changed

7 files changed

+89
-5
lines changed

packages/front/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thatopen/components-front",
33
"description": "Collection of frontend tools to author BIM apps.",
4-
"version": "3.2.4",
4+
"version": "3.2.5",
55
"author": "That Open Company",
66
"contributors": [
77
"Antonio Gonzalez Viegas (https://github.com/agviegas)",

packages/front/src/core/Marker/src/mark.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ export class Mark implements OBC.Hideable, OBC.Disposable {
1616
*/
1717
world: OBC.World;
1818

19+
/**
20+
* The visibility state of the marker, used for culling (e.g. clipping planes).
21+
*/
22+
wasVisible = true;
23+
1924
/** {@link OBC.Disposable.onDisposed} */
2025
readonly onDisposed = new OBC.Event();
2126

2227
/** {@link OBC.Hideable.visible} */
2328
set visible(value: boolean) {
2429
this.three.visible = value;
30+
this.wasVisible = value;
2531
}
2632

2733
/** {@link OBC.Hideable.visible} */

packages/front/src/measurement/Measurement/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ export abstract class Measurement<
7575

7676
private pointerStopTimeout: number | null = null;
7777

78+
applyPlanesVisibility(planes: THREE.Plane[]) {
79+
for (const line of this.lines) {
80+
line.applyPlanesVisibility(planes);
81+
}
82+
for (const fill of this.fills) {
83+
fill.applyPlanesVisibility(planes);
84+
}
85+
for (const volume of this.volumes) {
86+
volume.applyPlanesVisibility(planes);
87+
}
88+
}
89+
7890
private onMove = () => {
7991
if (!this.enabled) return;
8092

packages/front/src/utils/area.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class Area {
9595
const points = this.points2D;
9696
if (!points) return 0;
9797
const area = Math.abs(THREE.ShapeUtils.area(points));
98-
return area
98+
return area;
9999
}
100100

101101
get boundingBox() {
@@ -184,9 +184,9 @@ export class Area {
184184
// Create an exact copy of this area
185185
clone() {
186186
const area = new Area([...this.points]);
187-
area.units = this.units
188-
area.rounding = this.rounding
189-
area.tolerance = this.tolerance
187+
area.units = this.units;
188+
area.rounding = this.rounding;
189+
area.tolerance = this.tolerance;
190190
return area;
191191
}
192192

packages/front/src/utils/dimension-line.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,36 @@ export class DimensionLine {
253253
(this._components as any) = null;
254254
}
255255

256+
applyPlanesVisibility(planes: THREE.Plane[]) {
257+
// Using wasVisible prevents showing labels that were hidden before
258+
259+
for (const endpoint of this._endpoints) {
260+
if (!endpoint.wasVisible) continue;
261+
let isBehind = false;
262+
for (const plane of planes) {
263+
if (plane.distanceToPoint(endpoint.three.position) < 0) {
264+
isBehind = true;
265+
break;
266+
}
267+
}
268+
endpoint.three.visible = !isBehind;
269+
}
270+
271+
// Check if label (measurement mark) is behind any plane
272+
273+
if (this.label.wasVisible) {
274+
let labelIsBehind = false;
275+
const labelPos = this.label.three.position;
276+
for (const plane of planes) {
277+
if (plane.distanceToPoint(labelPos) < 0) {
278+
labelIsBehind = true;
279+
break;
280+
}
281+
}
282+
this.label.three.visible = !labelIsBehind;
283+
}
284+
}
285+
256286
/**
257287
* Creates a bounding box for the dimension line.
258288
* The bounding box is a 3D box that encloses the dimension line.

packages/front/src/utils/measure-fill.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ export class MeasureFill {
9393
area.points.onCleared.add(this._triggerUpdate);
9494
}
9595

96+
applyPlanesVisibility(planes: THREE.Plane[]) {
97+
// Using wasVisible prevents showing labels that were hidden before
98+
if (!this.label.wasVisible) {
99+
return;
100+
}
101+
let isHidden = false;
102+
const center = this.area.center;
103+
if (center) {
104+
for (const plane of planes) {
105+
if (plane.distanceToPoint(center) < 0) {
106+
isHidden = true;
107+
break;
108+
}
109+
}
110+
}
111+
this.label.three.visible = !isHidden;
112+
}
113+
96114
private _triggerUpdate = () => this.update();
97115

98116
private updateMesh() {

packages/front/src/utils/measure-volume.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ export class MeasureVolume {
9494
this.volume.onItemsChanged.add(() => this.update());
9595
}
9696

97+
applyPlanesVisibility(planes: THREE.Plane[]) {
98+
// Using wasVisible prevents showing labels that were hidden before
99+
if (!this.label.wasVisible) {
100+
return;
101+
}
102+
let isBehind = false;
103+
for (const mesh of this.meshes) {
104+
for (const plane of planes) {
105+
if (plane.distanceToPoint(mesh.position) < 0) {
106+
isBehind = true;
107+
break;
108+
}
109+
}
110+
111+
this.label.three.visible = !isBehind;
112+
}
113+
}
114+
97115
private async updateMesh() {
98116
this.cleanMeshes();
99117
const mesher = this._components.get(Mesher);

0 commit comments

Comments
 (0)