import * as THREE from "three"; import { LineSegments2 } from "three/examples/jsm/lines/LineSegments2.js"; import { ZebraTool } from "../tools/cad_tools/zebra.js"; import type { ZebraColorScheme, ZebraMappingMode, ColorValue, ColoredMaterial } from "../core/types"; interface ShapeInfo { topo: string; geomtype: number | string | null; } type FaceMesh = THREE.Mesh; type VertexPoints = THREE.Points; interface EdgeMaterial extends THREE.Material { color: THREE.Color; linewidth: number; } type Edges = LineSegments2 | THREE.LineSegments; /** * Encapsulates material, visibility, and interaction state for a renderable CAD object. * * ObjectGroup is the leaf node in the scene graph, managing a single CAD entity: * - Front mesh (visible face) * - Back mesh (for clipping visualization) * - Edges (wireframe/boundary lines) * - Vertices (point cloud) * * ## Responsibilities * - Material management (color, opacity, metalness, roughness) * - Visibility toggling (shapes, edges independently) * - Selection/hover highlighting * - Zebra stripe tool integration * - Clipping plane caps * * ## Usage * ObjectGroups are created by NestedGroup and accessed via `nestedGroup.groups[path]`. * * @example * ```typescript * const obj = viewer.nestedGroup.groups["/assembly/part"]; * if (isObjectGroup(obj)) { * obj.setShapeVisible(true); * obj.setEdgesVisible(false); * } * ``` * * @internal - This is an internal class used by NestedGroup */ declare class ObjectGroup extends THREE.Group { [key: string]: unknown; /** Type identifier following Three.js convention */ readonly type = "ObjectGroup"; /** Type guard property following Three.js convention */ readonly isObjectGroup = true; opacity: number; alpha: number; transparent: boolean; edge_color: ColorValue; shapeInfo: ShapeInfo | null; subtype: string | null; renderback: boolean; front: FaceMesh | null; back: FaceMesh | null; edges: Edges | null; edgeMaterial: EdgeMaterial | null; vertices: VertexPoints | null; clipping: Map; isSelected: boolean; originalColor: THREE.Color | null; originalBackColor: THREE.Color | null; originalWidth: number | null; vertexFocusSize: number; edgeFocusWidth: number; shapeGeometry?: THREE.BufferGeometry | null; /** Material tag from shapes data, used for Studio mode material lookup */ materialTag: string; minZ?: number; height?: number; private _zebra; private _cadFrontMaterial; private _cadBackMaterial; private _cadOriginalColor; private _cadOriginalBackColor; private _isStudioMode; private _cadEdgesVisible; /** * Create an ObjectGroup for managing a CAD object's visual representation. * @param opacity - Default opacity value (0.0 to 1.0). * @param alpha - Transparency alpha value (0.0 to 1.0). * @param edge_color - Edge color as hex value. * @param shapeInfo - Shape metadata with topo and geomtype fields. * @param subtype - Shape subtype (e.g., "solid", "edges", "vertices"). * @param renderback - Whether back faces should be rendered. */ constructor(opacity: number, alpha: number, edge_color: ColorValue, shapeInfo: ShapeInfo | null, subtype: string | null, renderback?: boolean); /** * Get the zebra tool, creating it on first access. */ get zebra(): ZebraTool; /** * Whether this ObjectGroup is currently in Studio mode. */ get isStudioMode(): boolean; /** * Dispose of all resources and clean up memory. * Releases geometry, materials, children, and zebra tool. */ dispose(): void; /** * Set the front face mesh. */ setFront(mesh: FaceMesh): void; /** * Set the back face mesh. */ setBack(mesh: FaceMesh): void; /** * Set the edges geometry. * Extracts and stores the material separately for type-safe access. */ setEdges(edges: Edges): void; /** * Set the vertices points. */ setVertices(points: VertexPoints): void; /** * Add a clipping group for a plane index. */ addClipping(group: THREE.Group, index: number): void; /** * Widen or restore point/edge size for visual emphasis. * @param flag - Whether to widen (true) or restore original size (false). */ widen(flag: boolean): void; /** * Toggle the selection state of this object. * Updates highlight and resets widening. */ toggleSelection(): void; /** * Remove highlight from this object. * @param keepSelection - If true, preserve selection state. */ unhighlight(keepSelection: boolean): void; /** * Get the highlight color based on selection state. */ private _getHighlightColor; /** * Apply color to a mesh and mark material for update. */ private _applyColorToMaterial; /** * Iterate over all child materials, excluding clipping planes. */ private _forEachMaterial; /** * Iterate over face materials that are MeshStandardMaterial (have PBR properties). * Skips MeshBasicMaterial and other non-PBR materials. */ private _forEachStandardMaterial; /** * Apply or remove highlight color to this object. * @param flag - Whether to apply highlight (true) or restore original color (false). */ highlight(flag: boolean): void; /** * Clear all highlights and selection state. */ clearHighlights(): void; /** * Get metrics about this object's topology type. */ metrics(): { name: string; value: number; } | null; /** * Set metalness value for front face materials. */ setMetalness(value: number): void; /** * Set roughness value for front face materials. */ setRoughness(value: number): void; /** * Enable or disable transparency mode. * Adjusts opacity and depth write settings. */ setTransparent(flag: boolean): void; /** * Set whether edges should be rendered in black or original color. * Skips edges with vertexColors enabled (e.g., trihedron axes). */ setBlackEdges(flag: boolean): void; /** * Set the edge color. * Skips edges with vertexColors enabled (e.g., trihedron axes). */ setEdgeColor(color: number): void; /** * Set the opacity value. Only applied visually when transparent mode is enabled. */ setOpacity(opacity: number): void; /** * Set visibility of the shape (front face and clipping caps). */ setShapeVisible(flag: boolean): void; /** * Set visibility of edges and vertices. */ setEdgesVisible(flag: boolean): void; /** * Set visibility of back faces. */ setBackVisible(flag: boolean): void; /** * Get the current visibility state. */ getVisibility(): boolean; /** * Set clip intersection mode for all materials. */ setClipIntersection(flag: boolean): void; /** * Set clipping planes for all materials. */ setClipPlanes(planes: THREE.Plane[]): void; /** * Set polygon offset for depth sorting of back faces. */ setPolygonOffset(offset: number): void; /** * Set Z-axis scale for GDS extrusion visualization. * Recursively scales all meshes and adjusts positions. */ setZScale(value: number): void; /** * Mark all materials as needing update. */ updateMaterials(flag: boolean): void; /** * Remove and dispose all clipping groups from this object. */ clearClipping(): void; /** * Enable or disable zebra stripe visualization on front faces. */ setZebra(flag: boolean): void; /** * Set the number of zebra stripes. */ setZebraCount(value: number): void; /** * Set the opacity of zebra stripes. */ setZebraOpacity(value: number): void; /** * Set the direction/angle of zebra stripes. */ setZebraDirection(value: number): void; /** * Set the color scheme for zebra stripes. */ setZebraColorScheme(value: ZebraColorScheme): void; /** * Set the mapping mode for zebra stripes. */ setZebraMappingMode(value: ZebraMappingMode): void; /** * Enter Studio mode: swap CAD materials for pre-built Studio materials. * * The caller (NestedGroup) is responsible for resolving material tags and * building MeshPhysicalMaterial instances via MaterialFactory. ObjectGroup * just receives the finished materials and performs the swap. * * On first call, saves the current CAD material references so they can be * restored by `leaveStudioMode()`. Copies the `material.visible` flag from * CAD to Studio material to preserve tree-view hide/show state. Updates * `originalColor` / `originalBackColor` so highlight/unhighlight works * correctly in Studio mode. * * @param studioFront - Studio material for front face, or null if this object has no front mesh * @param studioBack - Studio material for back face, or null if back face should not be swapped */ enterStudioMode(studioFront: THREE.MeshPhysicalMaterial | null, studioBack: THREE.MeshPhysicalMaterial | null): void; /** * Leave Studio mode: restore CAD materials. * * Copies `material.visible` from Studio back to CAD material to preserve * any visibility changes made while in Studio mode (e.g., tree-view toggle). * Restores `originalColor` / `originalBackColor` to CAD material colors. * Restores edge visibility to the state saved when entering Studio mode. */ leaveStudioMode(): void; /** * Toggle edge visibility while in Studio mode. * * Only affects edges (not vertices). Should only be called while in * Studio mode; the saved CAD edge visibility is not affected. * * @param visible - Whether edges should be visible */ setStudioShowEdges(visible: boolean): void; } /** * Type guard to check if an object is an ObjectGroup instance. * Uses the isObjectGroup property following Three.js convention. */ declare function isObjectGroup(obj: THREE.Object3D | null): obj is ObjectGroup; export { ObjectGroup, isObjectGroup }; export type { ShapeInfo, FaceMesh, Edges, EdgeMaterial, VertexPoints };