Skip to content

Commit

Permalink
fix: allow to delete all clipping planes without destroying floor plans
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Jul 16, 2024
1 parent fe7c112 commit 80c72af
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components",
"description": "Collection of core functionalities to author BIM apps.",
"version": "2.1.2",
"version": "2.1.3",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
29 changes: 21 additions & 8 deletions packages/core/src/core/Clipper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ export class Clipper

const intersects = caster.castRay();
if (intersects) {
this.createPlaneFromIntersection(world, intersects);
return this.createPlaneFromIntersection(world, intersects);
}
return null;
}

/**
Expand Down Expand Up @@ -234,11 +235,21 @@ export class Clipper
this.deletePlane(plane);
}

/** Deletes all the existing clipping planes. */
deleteAll() {
while (this.list.length > 0) {
const plane = this.list[0];
this.delete(plane.world, plane);
/**
* Deletes all the existing clipping planes.
*
* @param types - the types of planes to be deleted. If not provided, all planes will be deleted.
*/
deleteAll(types?: Set<string>) {
const planes = [...this.list];
for (const plane of planes) {
if (!types || types.has(plane.type)) {
this.delete(plane.world, plane);
const index = this.list.indexOf(plane);
if (index !== -1) {
this.list.splice(index, 1);
}
}
}
}

Expand Down Expand Up @@ -285,14 +296,16 @@ export class Clipper
}
const constant = intersect.point.distanceTo(new THREE.Vector3(0, 0, 0));
const normal = intersect.face?.normal;
if (!constant || !normal) return;

if (!constant || !normal) {
return null;
}
const worldNormal = this.getWorldNormal(intersect, normal);
const plane = this.newPlane(world, intersect.point, worldNormal.negate());
plane.visible = this._visible;
plane.size = this._size;
world.renderer.setPlane(true, plane.three);
this.updateMaterialsAndPlanes();
return plane;
}

private getWorldNormal(intersect: THREE.Intersection, normal: THREE.Vector3) {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/core/Clipper/src/simple-plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class SimplePlane implements Disposable, Hideable {
/** The world instance to which this plane belongs. */
world: World;

/** A custom string to identify what this plane is used for. */
type = "default";

protected readonly _helper: THREE.Object3D;

protected _visible = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/front/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thatopen/components-front",
"description": "Collection of frontend tools to author BIM apps.",
"version": "2.1.4",
"version": "2.1.5",
"author": "That Open Company",
"contributors": [
"Antonio Gonzalez Viegas (https://github.com/agviegas)",
Expand Down
5 changes: 5 additions & 0 deletions packages/front/src/fragments/Plans/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export class Plans extends OBC.Component implements OBC.Disposable {
/** {@link OBC.Disposable.onDisposed} */
readonly onDisposed = new OBC.Event();

/** The plane type for the clipping planes created by this component. */
readonly planeType = "floorplan";

/**
* Event triggered when the user navigates to a different floor plan.
* The event provides the id of the floor plan the user navigated to.
Expand Down Expand Up @@ -224,6 +227,8 @@ export class Plans extends OBC.Component implements OBC.Disposable {
clippingPoint,
) as EdgesPlane;

plane.type = this.planeType;

plane.edges.update();

plane.visible = false;
Expand Down

0 comments on commit 80c72af

Please sign in to comment.