import * as THREE from "three"; import type { Vector3Tuple } from "three"; import { ObjectGroup } from "./nestedgroup.js"; import type { Theme, ClipIndex } from "../core/types"; /** * A THREE.Plane that maintains a constant relative to a center point. */ declare class CenteredPlane extends THREE.Plane { center: number[]; centeredConstant: number; /** * Create a CenteredPlane. * @param normal - The plane normal vector. * @param constant - The centered constant value. * @param center - The center point [x, y, z]. */ constructor(normal: THREE.Vector3, constant: number, center: number[]); /** * Set the constant relative to the center point. * @param value - The centered constant value. */ setConstant(value: number): void; /** * Clone this CenteredPlane. * Overrides THREE.Plane.clone() which calls `new this.constructor()` without * arguments, causing `center` to be undefined during shadow map generation. */ clone(): CenteredPlane; } /** * A THREE.Group that only contains PlaneMesh children. */ declare class PlaneMeshGroup extends THREE.Group { children: PlaneMesh[]; } /** * A mesh that visually represents a clipping plane. */ declare class PlaneMesh extends THREE.Mesh { type: string; material: THREE.MeshBasicMaterial | THREE.MeshStandardMaterial; /** Shared matrix for lookAt calculations */ static matrix: THREE.Matrix4; index: number; plane: CenteredPlane; size: number; center: number[]; /** * Create a PlaneMesh. * @param index - The plane index (0, 1, or 2). * @param plane - The clipping plane. * @param center - The center point [x, y, z]. * @param size - The size of the plane mesh. * @param material - The material for the mesh. * @param color - The color as hex value. * @param type - The mesh type identifier. */ constructor(index: number, plane: CenteredPlane, center: number[], size: number, material: THREE.MeshBasicMaterial | THREE.MeshStandardMaterial, color: number, type: string); /** * Clear stencil buffer after rendering stencil planes. * @param renderer - The renderer. */ onAfterRender: (renderer: THREE.WebGLRenderer) => void; /** * Update the mesh's world matrix to align with the clipping plane. * @param force - Force update even if not needed. */ updateMatrixWorld(force?: boolean): void; } interface NestedGroupLike { groups: Record; rootGroup: THREE.Group | null; } interface ClippingOptions { onNormalChange?: (index: ClipIndex, normalArray: Vector3Tuple) => void; } /** * Saved clipping state for mode transitions (e.g., entering/leaving Studio mode). * Captures only Clipping-internal state; renderer flags and ViewerState keys * are managed by the caller. */ interface ClippingState { /** Centered constant (position) for each of the 3 clip planes */ planeConstants: [number, number, number]; /** Whether the plane helper meshes (translucent colored rectangles) are visible */ helperVisible: boolean; /** Whether the stencil plane meshes (solid colored caps) are visible */ planesVisible: boolean; } /** * Manages clipping planes, stencil rendering, and plane visualization. */ declare class Clipping extends THREE.Group { center: number[] | null; distance: number; onNormalChange: ((index: ClipIndex, normalArray: Vector3Tuple) => void) | null; theme: Theme; nestedGroup: NestedGroupLike; size: number; clipPlanes: CenteredPlane[]; reverseClipPlanes: CenteredPlane[]; objectColors: number[]; objectColorCaps: boolean; planeHelpers: PlaneMeshGroup | null; private _planeMeshGroup; /** * Create a Clipping instance. * @param center - The center point [x, y, z]. * @param size - The size of the clipping region. * @param nestedGroup - The nested group containing objects to clip. * @param options - Configuration options. * @param theme - The UI theme ('light' or 'dark'). */ constructor(center: number[], size: number, nestedGroup: NestedGroupLike, options: ClippingOptions, theme: Theme); /** * Create the three clipping planes and their reverse counterparts. * @param center - The center point. */ private _createClipPlanes; /** * Create the visual plane helpers. * @param center - The center point. * @param size - The size of the plane helpers. * @param theme - The UI theme. */ private _createPlaneHelpers; /** * Create stencil meshes for solid objects. * @param center - The center point. * @param size - The size of the stencil planes. * @param theme - The UI theme. */ private _createStencils; /** * Rebuild stencil meshes after scene changes (part add/remove). * Clears existing stencils from all ObjectGroups and rebuilds from scratch. * Also updates clipping region size if center/size changed. * @param center - The new center point [x, y, z]. * @param size - The new size of the clipping region. */ rebuildStencils(center: number[], size: number): void; /** * Set the constant (distance from center) for a clipping plane. * @param index - The plane index (0, 1, or 2). * @param value - The constant value relative to center. */ setConstant(index: ClipIndex, value: number): void; /** * Set the normal vector for a clipping plane. * @param index - The plane index (0, 1, or 2). * @param normal - The new normal vector. */ setNormal: (index: ClipIndex, normal: THREE.Vector3) => void; /** * Get whether object color caps mode is enabled. * @returns True if object color caps mode is enabled. */ getObjectColorCaps: () => boolean; /** * Toggle object color caps mode. * When enabled, stencil planes use the original object colors. * When disabled, stencil planes use theme-based plane colors. * @param flag - True to enable object color caps. */ setObjectColorCaps: (flag: boolean) => void; /** * Set visibility of stencil plane meshes. * @param flag - True to show, false to hide. */ setVisible: (flag: boolean) => void; /** * Save the current clipping state for later restoration. * Captures plane positions, helper visibility, and stencil plane visibility. * Used by Studio mode to snapshot clipping state before disabling clipping. * * Note: `renderer.localClippingEnabled` and `clipPlaneHelpers` ViewerState * are managed by the caller (Display/Viewer layer), not captured here. */ saveState(): ClippingState; /** * Restore a previously saved clipping state. * Re-applies plane positions, helper visibility, and stencil plane visibility. * Used by Studio mode when leaving to restore the clipping configuration. * * @param state - The state previously captured by `saveState()`. */ restoreState(state: ClippingState): void; /** * Clean up resources. * Note: We don't null out arrays/references as GC handles cleanup when the Clipping object is collected. */ dispose(): void; } export { Clipping }; export type { ClippingState };