import * as THREE from 'three'; /** * 双击快速测量:从落点沿所在平面的法线发一条射线,取第一个打到的模型表面作为终点。 * 典型场景是双击墙面直接得到墙到对面墙的垂直距离。 */ /** 射线起点离开表面的距离(米),避免射线一出发就打中落点所在的面 */ export declare const NORMAL_RAY_START_OFFSET = 0.01; /** 终点离起点太近(米)视为无效,例如打中了落点旁边的小凸起 */ export declare const NORMAL_RAY_MIN_DISTANCE = 0.02; /** 射线最远距离(米),超过视为没打到 */ export declare const NORMAL_RAY_MAX_DISTANCE = 100; /** 双击判定:两次抬起的最大间隔(毫秒) */ export declare const DOUBLE_CLICK_INTERVAL = 350; /** 双击判定:两次抬起的最大屏幕距离(像素) */ export declare const DOUBLE_CLICK_MAX_MOVE = 6; export interface RaycastHit { point: THREE.Vector3; distance: number; /** 命中面;THREE.Intersection 的 face.normal 已经是世界坐标系法线 */ face?: { normal?: THREE.Vector3 | null; } | null; } /** 法线快速测量的命中结果 */ export interface NormalMeasureHit { /** 终点 */ point: THREE.Vector3; /** 终点所在表面的世界坐标系法线;拿不到时为 null */ normal: THREE.Vector3 | null; } /** 对模型做射线检测,返回按距离排序的命中结果 */ export type ModelRaycast = (raycaster: THREE.Raycaster) => RaycastHit[]; /** * 沿法线求快速测量的命中点。 * @param point - 起点(双击的落点) * @param normal - 起点所在平面的法线(世界坐标,朝向表面外侧,即朝向相机这一侧) * @returns 命中点及其表面法线;法线无效或没打到模型时返回 null */ export declare function findNormalMeasureHit(point: THREE.Vector3, normal: THREE.Vector3, raycast: ModelRaycast): NormalMeasureHit | null; /** 只要终点时用这个 */ export declare function findNormalMeasureEnd(point: THREE.Vector3, normal: THREE.Vector3, raycast: ModelRaycast): THREE.Vector3 | null; /** * 识别「第二下点在刚打下的点上」的双击。 * 只记录上一次抬起的时间和屏幕位置;时间和位置都足够近才算双击,命中后清空,三连击不会触发两次。 */ export declare class DoubleClickDetector { private readonly interval; private readonly maxMove; private last; constructor(interval?: number, maxMove?: number); /** 每次单击抬起时调用;返回 true 表示与上一次构成双击 */ hit(x: number, y: number, time: number): boolean; reset(): void; } /** 双击时第二下离起点的最大屏幕距离(像素)。起点可能被吸附偏离光标几像素,所以比双击判定宽一些 */ export declare const START_POINT_HIT_RADIUS = 16; interface QuickMeasureCamera { position: THREE.Vector3; } export interface QuickNormalMeasureOptions { /** 当前相机;朝向判断和屏幕投影都用它 */ getCamera: () => THREE.Camera & QuickMeasureCamera; /** five 画布,用来把世界坐标换算成屏幕坐标 */ getElement: () => HTMLElement | null | undefined; /** 对模型做射线检测 */ raycast: ModelRaycast; /** 正在测量的点;不在测量中返回 null */ getMeasuringPoints: () => THREE.Vector3[] | null; /** * 打到对面:用起点和终点生成测量。 * 返回 true 表示测量会话继续(控制器以终点作为下一段的起点),此时命中面的法线会留作下一段的起始法线。 */ finish: (start: THREE.Vector3, end: THREE.Vector3) => boolean | void; /** 没打到:撤掉起点,回到未打点状态 */ cancelStart: () => void; } /** 由 PointSelector 的 wantsSelect 事件驱动,返回 false 表示取消这次选点 */ type WantsSelectHandler = (intersection?: { point?: THREE.Vector3; face?: { normal?: THREE.Vector3 | null; } | null; } | null) => boolean | void; /** * 双击快速测量(只处理鼠标,触屏不触发)。 * * 规则与 MP 一致: * - 第一下单击照常打下起点 A,不延迟;第二下在双击时间内又点在 A 上,就从 A 沿法线测到对面,直接完成这条测量; * - A 已经打下一段时间后,再双击 A 也会快速测量:落在 A 上的单击不会再打一个重合的点; * - 已经开始连线(两个点及以上)时双击按普通单击处理;法线没打到模型时撤掉 A,不生成测量; * - 快速测量完成后不退出选点:控制器以命中点为新一段的起点(finish 返回 true),继续选择下一个点位。 */ export declare class QuickNormalMeasure { private readonly options; private readonly detector; private lastMouseUp; /** 起点 A 所在平面的法线,在打下 A 的那次选点里记下 */ private startNormal; private attached; constructor(options: QuickNormalMeasureOptions); attach(pointSelector: { on: (name: 'wantsSelect', callback: WantsSelectHandler) => unknown; }): void; detach(pointSelector: { off: (name: 'wantsSelect', callback: WantsSelectHandler) => unknown; }): void; reset(): void; private onMouseUp; private onWantsSelect; /** 只认刚刚发生的鼠标抬起,用完即清,避免触屏选点误用上一次鼠标的位置 */ private consumeMouseUp; private isOnStartPoint; /** 面法线可能朝向表面内侧;射线要往相机这一侧(空的一侧)发 */ private orientTowardCamera; } export {};