Skip to content
Open
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
43 changes: 37 additions & 6 deletions viewer/src/components/display/plans/plan-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Mesh, Vector3 } from 'three';
import { Box3, Mesh, Vector3 } from 'three';
import { IFCBUILDINGSTOREY, IFCBUILDING } from 'web-ifc';
import { IfcPlane } from '../clipping-planes/planes';
import { IfcClipper } from '../clipping-planes/clipper';
Expand Down Expand Up @@ -70,12 +70,13 @@ export class PlanManager {

async goTo(modelID: number, name: string, animate = false) {
if (this.currentPlan?.modelID === modelID && this.currentPlan.name === name) return;
const isChangingModel = this.active && this.currentPlan?.modelID !== modelID;
this.storeCameraPosition();
this.hidePreviousClippingPlane();
this.getCurrentPlan(modelID, name);
this.activateCurrentPlan();
if (!this.active) {
await this.moveCameraTo2DPlanPosition(animate);
if (!this.active || isChangingModel) {
await this.moveCameraTo2DPlanPosition(animate, isChangingModel);
this.active = true;
}
}
Expand Down Expand Up @@ -152,6 +153,9 @@ export class PlanManager {
}

private async getTransformHeight(modelID: number) {
const appliedMatrix = this.ifc.loader.ifcManager.state.coordinationMatrix;
if (appliedMatrix) return appliedMatrix.elements[13];

const transformMatrix = await this.ifc.loader.ifcManager.ifcAPI.GetCoordinationMatrix(modelID);
return transformMatrix[13];
}
Expand Down Expand Up @@ -179,9 +183,36 @@ export class PlanManager {
this.context.ifcCamera.cameraControls.saveState();
}

private async moveCameraTo2DPlanPosition(animate: boolean) {
if (this.floorPlanViewCached) await this.context.ifcCamera.cameraControls.reset(animate);
else await this.context.ifcCamera.cameraControls.setLookAt(0, 100, 0, 0, 0, 0, animate);
private async moveCameraTo2DPlanPosition(animate: boolean, ignoreCache = false) {
if (this.floorPlanViewCached && !ignoreCache) {
await this.context.ifcCamera.cameraControls.reset(animate);
return;
}

const center = this.getCurrentPlanCenter();
const targetHeight = this.currentPlan?.plane?.origin.y || 0;
await this.context.ifcCamera.cameraControls.setLookAt(
center.x,
targetHeight + this.defaultCameraOffset,
center.z,
center.x,
targetHeight,
center.z,
animate
);
}

private getCurrentPlanCenter() {
const currentPlan = this.currentPlan;
if (!currentPlan) return new Vector3();
const model = this.context.items.ifcModels.find(
(model) => model.modelID === currentPlan.modelID
);
if (!model) return new Vector3();
const box = new Box3().setFromObject(model);
const center = new Vector3();
box.getCenter(center);
return center;
}

private activateCurrentPlan() {
Expand Down
3 changes: 3 additions & 0 deletions viewer/src/components/display/plans/storey-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export class StoreyManager {
}

private async getTransformHeight(modelID: number) {
const appliedMatrix = this.loader!.ifcManager.state.coordinationMatrix;
if (appliedMatrix) return appliedMatrix.elements[13];

const transformMatrix = await this.loader!.ifcManager.ifcAPI.GetCoordinationMatrix(modelID);
return transformMatrix[13];
}
Expand Down