import * as THREE from "three"; import { CADOrbitControls } from "./controls/CADOrbitControls.js"; import { CADTrackballControls } from "./controls/CADTrackballControls.js"; import type { ControlType } from "../core/types"; type ControlsInstance = CADOrbitControls | CADTrackballControls; /** * Unified camera controls supporting both orbit and trackball modes. * * Controls wraps CADOrbitControls and CADTrackballControls, providing: * - Consistent API regardless of control type * - Normalized speed settings (1.0 = default experience) * - State saving/restoring for reset functionality * - Camera switching support * * ## Control Types * - `"orbit"`: OrbitControls - familiar Google Maps style rotation * - `"trackball"`: TrackballControls - unrestricted rotation with optional Holroyd mode * * ## Holroyd Mode * When enabled for trackball controls, prevents tumbling by keeping * the up vector stable. This provides a more intuitive CAD experience. * * @internal - This is an internal class used by Viewer */ declare class Controls { type: ControlType; camera: THREE.Camera; target: THREE.Vector3; target0: THREE.Vector3; domElement: HTMLElement; rotateSpeed: number; zoomSpeed: number; panSpeed: number; holroyd: boolean; controls: ControlsInstance; currentUpdateCallback: (() => void) | null; /** * Create Camera Controls. * @param type - Type of controls: "orbit", "trackball". * @param camera - The camera object. * @param target - The lookAt target for the camera. * @param domElement - The dom element of the rendering canvas. * @param rotateSpeed - Speed for rotating. * @param zoomSpeed - Speed for zooming. * @param panSpeed - Speed for panning. * @param holroyd - Enable holroyd (non-tumbling) mode for trackball. */ constructor(type: ControlType, camera: THREE.Camera, target: THREE.Vector3, domElement: HTMLElement, rotateSpeed?: number, zoomSpeed?: number, panSpeed?: number, holroyd?: boolean); /** * Get the speed factors for the current control type. */ private _getSpeedFactors; /** * Apply speed factors to controls. */ private _applySpeedFactors; /** * Remove assets and event handlers. */ dispose(): void; /** * Save state for reset. */ saveState(): void; /** * Initialize Trackball Controls. * @param holroyd - enable holroyd (non tumbling) mode. */ initTrackballControls(holroyd?: boolean): void; /** * Initialize Orbit Controls. */ initOrbitControls(): void; /** * Add an event listener callback for the "change" event. * @param callback - the callback function. */ addChangeListener(callback: () => void): void; /** * Remove the event listener callback for the "change" event. */ removeChangeListener(): void; /** * Update controls after camera position, zoom or quaternion changes. */ update(): void; /** * Update screen dimensions after canvas resize. * Only applies to TrackballControls which caches screen dimensions. */ handleResize(): void; /** * Reset camera to initial (automatically saved) state of position, up, quaternion and zoom. */ reset(): void; /** * Set the camera to be controlled. * @param camera - a threejs Camera object. */ setCamera(camera: THREE.Camera): void; /** * Change the trackball holroyd (non tumbling) flag. * @param flag - holroyd mode enabled. */ setHolroydTrackball(flag: boolean): void; /** * Get the lookAt target of the camera. * @returns The lookAt target */ getTarget(): THREE.Vector3; /** * Check if the user is currently interacting with the controls (rotating, panning, zooming). * @returns true if user is dragging/interacting, false otherwise. */ isInteracting(): boolean; /** * Get the initial zoom value of the camera. */ getZoom0(): number; /** * Set the lookAt target of the camera. * @param target - camera target as THREE.Vector3. */ setTarget(target: THREE.Vector3): void; /** * Set the zoom speed. * @param val - the speed value (1.0 = default). */ setZoomSpeed(val: number): void; /** * Set the pan speed. * @param val - the speed value (1.0 = default). */ setPanSpeed(val: number): void; /** * Set the rotate speed. * @param val - the speed value (1.0 = default). */ setRotateSpeed(val: number): void; /** * Get reset location value. * @returns target, position, quaternion, zoom as object. */ getResetLocation: () => { target0: THREE.Vector3; position0: THREE.Vector3; quaternion0: THREE.Quaternion; zoom0: number; }; /** * Set reset location value. * @param target - camera target as THREE.Vector3. * @param position - camera position as THREE.Vector3. * @param quaternion - camera rotation as THREE.Quaternion. * @param zoom - camera zoom value. */ setResetLocation: (target: THREE.Vector3, position: THREE.Vector3, quaternion: THREE.Quaternion, zoom: number) => void; private getOrbitControls; private getTrackballControls; /** * Rotate camera up (OrbitControls only) * @param angle - the angle to rotate. */ rotateUp(angle: number): void; /** * Rotate camera left (OrbitControls only) * @param angle - the angle to rotate. */ rotateLeft(angle: number): void; /** * Rotate camera around x-axis (TrackballControls only) * @param angle - the angle to rotate. */ rotateX(angle: number): void; /** * Rotate camera around y-axis (TrackballControls only) * @param angle - the angle to rotate. */ rotateY(angle: number): void; /** * Rotate camera around z-axis (TrackballControls only) * @param angle - the angle to rotate. */ rotateZ(angle: number): void; } export { Controls };