Skip to content

Commit

Permalink
chore: refactor as to hide internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite committed Jul 17, 2024
1 parent d43a5d2 commit 4f9a853
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions viewer/packages/camera-manager/src/CameraManagerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,46 @@ export class CameraManagerHelper {
* @param boundingBox Bounding box of all objects on the scene.
* @param nearAndFarPlaneBuffers to read from
* @param cameraFarBuffers
* @deprecated should use instance method instead
* @deprecated use instance method instead
*/
static updateCameraNearAndFar(
static updateCameraNearAndFar(camera: PerspectiveCamera, boundingBox: Box3): void {
CameraManagerHelper.updateCameraNearAndFarInternal(
camera,
boundingBox,
CameraManagerHelper._updateNearAndFarPlaneBuffers,
CameraManagerHelper._calculateCameraFarBuffers
);
}

public updateCameraNearAndFar(camera: PerspectiveCamera, boundingBox: Box3): void {
CameraManagerHelper.updateCameraNearAndFarInternal(
camera,
boundingBox,
this._instanceUpdateNearAndFarPlaneBuffers,
this._instanceCalculateCameraFarBuffers
);
}

/**
* Calculates camera position and target that allows to see the content of provided bounding box.
* @param camera Used camera instance.
* @param boundingBox Bounding box to be fitted.
* @param radiusFactor The ratio of the distance from camera to center of box and radius of the box.
* @returns
*/
static calculateCameraStateToFitBoundingBox(
camera: PerspectiveCamera,
boundingBox: Box3,
radiusFactor: number = 2
): { position: Vector3; target: Vector3 } {
return fitCameraToBoundingBox(camera, boundingBox, radiusFactor);
}

private static updateCameraNearAndFarInternal(
camera: PerspectiveCamera,
boundingBox: Box3,
nearAndFarPlaneBuffers: NearAndFarPlaneBuffers = CameraManagerHelper._updateNearAndFarPlaneBuffers,
cameraFarBuffers: CameraFarBuffers = CameraManagerHelper._calculateCameraFarBuffers
nearAndFarPlaneBuffers: NearAndFarPlaneBuffers,
cameraFarBuffers: CameraFarBuffers
): void {
const { cameraPosition, cameraDirection, corners } = nearAndFarPlaneBuffers;
this.getBoundingBoxCorners(boundingBox, corners);
Expand All @@ -146,30 +179,6 @@ export class CameraManagerHelper {
camera.updateProjectionMatrix();
}

public updateCameraNearAndFar(camera: PerspectiveCamera, boundingBox: Box3): void {
CameraManagerHelper.updateCameraNearAndFar(
camera,
boundingBox,
this._instanceUpdateNearAndFarPlaneBuffers,
this._instanceCalculateCameraFarBuffers
);
}

/**
* Calculates camera position and target that allows to see the content of provided bounding box.
* @param camera Used camera instance.
* @param boundingBox Bounding box to be fitted.
* @param radiusFactor The ratio of the distance from camera to center of box and radius of the box.
* @returns
*/
static calculateCameraStateToFitBoundingBox(
camera: PerspectiveCamera,
boundingBox: Box3,
radiusFactor: number = 2
): { position: Vector3; target: Vector3 } {
return fitCameraToBoundingBox(camera, boundingBox, radiusFactor);
}

private static calculateCameraFar(
near: number,
cameraPosition: Vector3,
Expand Down

0 comments on commit 4f9a853

Please sign in to comment.