import * as THREE from "three"; import type { Vector3Tuple, QuaternionTuple } from "three"; import type { UpDirection } from "../core/types"; type CameraDirection = "iso" | "front" | "rear" | "left" | "right" | "top" | "bottom"; type UpMode = "y_up" | "z_up" | "legacy"; /** * Manages orthographic and perspective cameras for the viewer. * * Camera wraps both camera types and provides: * - Seamless switching between orthographic and perspective * - Preset positions (iso, front, top, etc.) * - Support for Y-up and Z-up coordinate systems * - Synchronized position/zoom across camera types * * ## Coordinate Systems * Supports three modes via `up` parameter: * - `"Y"`: Y-up (Fusion 360 compatible) * - `"Z"`: Z-up (FreeCAD, OnShape compatible) * - Legacy Z-up mode * * @internal - This is an internal class used by Viewer */ declare class Camera { private static readonly DISTANCE_FACTOR; /** * Near plane factor: near = max(0.1, NEAR_FACTOR * distance). * With far = 100 * distance, this gives a far/near ratio of 10,000:1, * which is comfortable for 24-bit depth buffers and avoids z-fighting * on large models (e.g. toycar at ~1100 unit bounding radius). */ private static readonly NEAR_FACTOR; target: THREE.Vector3; ortho: boolean; up: UpMode; yaxis: THREE.Vector3; zaxis: THREE.Vector3; camera_distance: number; pCamera: THREE.PerspectiveCamera; oCamera: THREE.OrthographicCamera; camera: THREE.PerspectiveCamera | THREE.OrthographicCamera; /** * Compute the near clipping plane from the bounding radius. * Keeps the far/near ratio bounded for depth buffer precision. */ private static _computeNear; /** * Create a combined camera (orthographic and perspective). * @param width - canvas width. * @param height - canvas height. * @param distance - distance from the lookAt point. * @param target - target (Vector3) to look at. * @param ortho - flag whether the initial camera should be orthographic. * @param up - Z or Y to define whether Z or Y direction is camera up. */ constructor(width: number, height: number, distance: number, target: Vector3Tuple, ortho: boolean, up: UpDirection); /** * Update the near/far clipping planes for both cameras. * @param distance - The new bounding radius to base the clipping planes on. */ updateFarPlane(distance: number): void; /** * Recalculate camera_distance from a new bounding radius. * Uses the same factor as the constructor so that zoom 1.0 frames the scene. * @param distance - The new bounding radius (bb_radius). */ updateCameraDistance(distance: number): void; /** * Remove assets. */ dispose(): void; /** * Get the current camera. * @returns Camera object. */ getCamera(): THREE.PerspectiveCamera | THREE.OrthographicCamera; /** * Set the lookAt point for the camera to the provided target. */ lookAtTarget(): void; /** * Update current camera's projection matrix. */ updateProjectionMatrix(): void; /** * Switch between orthographic and perspective camera. * @param ortho_flag - true for orthographic camera, else perspective camera. */ switchCamera(ortho_flag: boolean): void; /** * Calculate projected size for orthographic camera. * @param frustum - View frustum size. * @param aspect - Viewer aspect ratio (width / height). * @returns Width and height [w, h] for the orthographic camera. */ projectSize(frustum: number, aspect: number): [number, number]; /** * Setup the current camera. * @param relative - flag whether the position is a relative (e.g. [1,1,1] for iso) or absolute point. * @param position - the camera position (relative or absolute). * @param quaternion - the camera rotation expressed by a quaternion. * @param zoom - zoom value. */ setupCamera(relative: boolean, position?: THREE.Vector3 | null, quaternion?: THREE.Quaternion | null, zoom?: number | null): void; /** * Move the camera to a given preset. * @param dir - can be "iso", "top", "bottom", "front", "rear", "left", "right" */ presetCamera(dir: CameraDirection, zoom?: number | null): void; /** * Return current zoom value. * @returns zoom value. */ getZoom(): number; /** * Set zoom value. * @param val - float zoom value. */ setZoom(val: number): void; /** * Get the current camera position. * @returns camera position. */ getPosition(): THREE.Vector3; /** * Set camera position. * @param position - position as 3 dim Array [x,y,z] or as Vector3. * @param relative - flag whether the position is a relative (e.g. [1,1,1] for iso) or absolute point. */ setPosition(position: Vector3Tuple | THREE.Vector3, relative: boolean): void; /** * Get the current camera quaternion. * @returns camera quaternion. */ getQuaternion(): THREE.Quaternion; /** * Set camera quaternion. * @param quaternion - quaternion as 4 dim Array or as Quaternion. */ setQuaternion(quaternion: QuaternionTuple | THREE.Quaternion): void; /** * Get the current camera rotation. * @returns camera rotation. */ getRotation(): THREE.Euler; /** * Get the visible area dimensions at the target plane. * @returns The visible width and height. */ getVisibleArea(): { width: number; height: number; }; /** * Update camera dimensions when viewport size changes. * @param distance - Distance used for orthographic frustum calculation. * @param width - New viewport width in pixels. * @param height - New viewport height in pixels. */ changeDimensions(distance: number, width: number, height: number): void; } export { Camera }; export type { CameraDirection, UpMode };