@three3d/tools
Version:
@three3d/tools 提供了 ThreeJS 常用的工具库
1,725 lines (1,570 loc) • 47.2 kB
TypeScript
/**
* ThreeJS的工具库
*
* @remarks
* ThreeJS 常用工具、类型等
*
* @packageDocumentation
*/
import type { AnyPixelFormat } from 'three';
import type { ArrayItemType } from 'type-tls';
import { Axis } from 'type-tls';
import { Axis4 } from 'type-tls';
import { Axis4Name } from 'type-tls';
import { AxisName } from 'type-tls';
import { BufferAttribute } from 'three';
import { BufferGeometry } from 'three';
import { ColorGradient } from 'image-tls';
import type { ColorRepresentation } from 'three';
import type { Curve } from 'three';
import { CurvePath } from 'three';
import type { Data3DTexture } from 'three';
import type { DataArrayTexture } from 'three';
import type { EulerOrder } from 'three';
import { IData2D } from 'image-tls';
import type { InterleavedBufferAttribute } from 'three';
import { IVector } from 'type-tls';
import { IVector2 } from 'type-tls';
import { IVector3 } from 'type-tls';
import { IVector4 } from 'type-tls';
import { Line } from 'three';
import { Line3 } from 'three';
import { LineCurve } from 'three';
import { LineCurve3 } from 'three';
import type { Material } from 'three';
import { Matrix3 } from 'three';
import { NormalBufferAttributes } from 'three';
import { Quaternion } from 'three';
import { Texture } from 'three';
import type { Vector } from 'three';
import { Vector2 } from 'three';
import { Vector3 } from 'three';
import { Vector4 } from 'three';
import { Wrapping } from 'three';
/**
* 调整由 tangent 和 normal 决定的 Frenet 坐标系,以使其互相垂直
* @remarks
* 为了节约性能,该方法会改变 tangent 和 normal;
* 遵守右手坐标系;
* tangent:会作为 z 轴的方向;
* normal:会作为 x 轴的方向
* binormal:会作为 y 轴的方向
*
*
* @param tangent - 已归一化的切线方向;会作为 z 轴的方向;
* @param normal - 已归一化的法线方向;会作为 x 轴的方向
* @param fixNormal - 是否固定法线
* @param binormalResult - 存储副法线的向量;会作为 y 轴的方向
* @returns
*/
export declare function adjustFrenetFrame(tangent: Vector3, normal: Vector3, fixNormal?: boolean | null, binormalResult?: Vector3): FrenetFrame;
/**
* 调整由 front 和 up 决定的坐标系,以使其互相垂直
* @remarks
* 为了节约性能,该方法会改变 front 和 up ;
* 遵守右手坐标系;
* front:会作为 z 轴的方向;
* up:会作为 y 轴的方向
* binormal:会作为 x 轴的方向
*
*
* @param front - 已归一化的向前的方向;会作为 z 轴的方向;
* @param up - 已归一化的向上的方向;会作为 y 轴的方向
* @param fixUp - 是否固定up方向
* @param binormalResult - 存储副法线的向量;会作为 x 轴的方向
* @returns
*/
export declare function adjustFrontUpFrame(front: Vector3, up: Vector3, fixUp?: boolean | null, binormalResult?: Vector3): FrontUpFrame;
/**
* 生成一个用于调整方向的矩阵
* @param front - 表示前方的矩阵;会将 front 作为 z 轴
* @param up - 表示上方的矩阵,会将 up 作为 y轴
* @param fixUp - 是否固定 up;保证up不变
* @param result - 保存结果的变量
* @returns
*/
export declare function adjustOrientation(front: Vector3, up: Vector3, fixUp?: boolean | null, result?: Matrix3 | null): Matrix3;
/**
* 角度范围
* @remarks
* - 可以是 [start,end] 也可以是 [end,start],即:可以第一个值 可以在于 第二个值
* - 范围始终包含 第一个值,不包含第二个值
*/
export declare type AngleRange = [number, number];
export { Axis }
export { Axis4 }
export { Axis4Name }
export { AxisName }
/**
* 计算方位的类
*/
export declare class Azimuth {
constructor(options?: AzimuthOptions);
static get options(): AzimuthOptions;
static set options(value: AzimuthOptions);
protected static _options?: AzimuthOptions | null;
/**
* 默认选项
*/
protected get defaultOptions(): AzimuthOptions;
get options(): AzimuthOptions;
set options(value: AzimuthOptions);
protected _options?: AzimuthOptions | null;
/**
* 是否使用角度,而非弧度
*/
get degrees(): boolean;
set degrees(value: boolean);
get map(): CourseAzimuthMap<AzimuthDefine> | null | undefined;
set map(value: CourseAzimuthMap<AzimuthDefine> | null | undefined);
protected get listMap(): CourseAzimuthMap<AzimuthList>;
protected _listMap?: CourseAzimuthMap<AzimuthList> | null;
get front(): IVector3;
set front(value: IVector3);
protected _front?: Vector3 | null;
get up(): IVector3;
set up(value: IVector3);
protected _up?: Vector3 | null;
/**
* 计算方位
* @param target
* @param front
* @param up
*/
computeAzimuth(target: IVector3, front?: IVector3 | null, up?: IVector3 | null): CourseInfo;
/**
* 查找匹配的方位名字
* @param type - 类型
* @param angle - 角度
* @returns 匹配的名字列表
*/
findAzimuthNames(type: keyof CourseAzimuthMap, angle: number): string[];
}
/**
* 计算方位对象
*/
export declare const azimuth: Azimuth;
/**
* 方位定义
*/
export declare type AzimuthDefine = AzimuthList | AzimuthMap;
export declare interface AzimuthInfo {
/**
* 角度
*/
angle: number;
/**
* 所有匹配的名字
*/
name: string[];
}
/**
* 方位范围列表
*/
export declare type AzimuthList = AzimuthRange[];
/**
* 方位映射
*/
export declare type AzimuthMap = Record<string, [number, number]>;
/**
* Azimuth 的选项
*/
export declare interface AzimuthOptions {
/**
* 是否使用角度,而非弧度
* @defaultValue true
*/
degrees?: boolean | null;
/**
* 方位映射定义
*/
map?: CourseAzimuthMap | null;
/**
* 前方向量
* @defaultValue {x:0,y:0,z:1}
*/
front?: IVector3;
/**
* 前方向量
* @defaultValue {x:0,y:1,z:0}
*/
up?: IVector3;
}
/**
* 方位范围,用来描述方位对应的角度范围
*/
export declare interface AzimuthRange {
name: string;
range: [number, number];
}
/**
* 闭合曲线路径
* @remarks
* 在 three@0.156.1 中 `CurvePath.prototype.closePath()` 方法有bug,执行方法后,无论 CurvePath 是3维曲线还是2维曲线,都只会以起终两点添加一段2维直线 `LineCurve`
* @param curvePath
*/
export declare function closeCurvePath(curvePath: CurvePath<Vector>): CurvePath<Vector>;
/**
* 点与一组线之间的最近信息
*/
export declare interface ClosestDistanceInfoOfPointToLines {
/**
* 最近的线
*/
line: Line3;
/**
* 最近线的索引
*/
index: number;
/**
* 最近的线段距离
*/
clampDist: number;
/**
* 距离最近的线段上的点
*/
clampPoint: Vector3;
/**
* 最近的点在其所在线上的 t 值
*/
t: number;
/**
* 线段上最近的点在其所在线段上的 t 的值
*/
clampT: number;
}
/**计算曲线的 FrenetFrames
* @param curve
* @param division
* @param up
* @param options
* @returns
*/
export declare function computeCurveFrenetFrames(curve: Curve<Vector3>, division: number, up: Vector3, options?: ComputeCurveFrenetFramesOptions): UT_Point_FrenetFrames;
/**
* 通过固定up方向的方式计算曲线的 FrenetFrames
* @param curve
* @param division
* @param up
* @param useU - 是否使用分分u的方式;
* @returns
*/
export declare function computeCurveFrenetFramesByFixUp(curve: Curve<Vector3>, division: number, up: Vector3, useU?: boolean): UT_Point_FrenetFrames;
/**
* 通过等分t的方式计算曲线的 FrenetFrames
* @param curve
* @param division
* @param up
* @returns
*/
export declare function computeCurveFrenetFramesByT(curve: Curve<Vector3>, division: number, up: Vector3): UT_Point_FrenetFrames;
/**
* 通过等分u的方式计算曲线的 FrenetFrames
* @param curve
* @param division
* @param up
* @returns
*/
export declare function computeCurveFrenetFramesByU(curve: Curve<Vector3>, division: number, up: Vector3, closed?: Boolean): UT_Point_FrenetFrames;
export declare interface ComputeCurveFrenetFramesOptions {
/**
* 是否使用等分u的方式
*/
useU?: boolean;
/**
* 是否固定 up;保证up不变
*/
fixUp?: boolean;
/**
* 是否墨盒曲线
* @remarks
* 只有在 useU 为 true 且 fixUp 为 false 的情况下才有效
* @defaultValue 曲线的 autoClose 属性值
*/
closed?: Boolean;
}
/**
* 计算FrenetFrame各轴的平行和垂直关系
* @param frontFrame
* @param backFrame
* @param zeroThreshold
* @returns
*/
export declare function computeFrenetFrameRelation(frontFrame: FrenetFrame, backFrame: FrenetFrame, zeroThreshold?: number): FrenetFrameRelation;
/**
* 计算线和圆的交点比例
* @remarks
* 比例指定的是:
* - 线的开始点为 0,结束点为 1;
* @param line
* @param circle
* @returns
*/
export declare function computeIntersectionFactorOfLine_Circle<Vec extends VectorInstance>(line: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): number[];
/**
* 计算两个带的交线
* @remarks
* 假设带的功宽度为1
* @param frontFrame
* @param backFrame
* @param zeroThreshold
* @returns
*/
export declare function computeIntersectionLineOfBands(frontFrame: FrenetFrame, backFrame: FrenetFrame, zeroThreshold?: number): IntersectionLineInfo;
/**
* 计算线和圆的交点
* @param line
* @param circle
* @returns
*/
export declare function computeIntersectionOfLine_Circle<Vec extends VectorInstance>(line: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): (Vector3 | Vector2 | Vector4)[];
/**
* 计算线和线的交点
* @param line1
* @param line2
* @returns
*/
export declare function computeIntersectionOfLine_Line<Vec extends VectorInstance>(line1: [Vec, Vec], line2: [Vec, Vec]): Vector3 | Vector2 | Vector4 | null;
/**
* 计算线段和圆的交点
* @param line
* @param circle
* @returns
*/
export declare function computeIntersectionOfLineSegment_Circle<Vec extends VectorInstance>(line: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): Vec[];
/**
* 计算线段和线段的交点
* @param lineSegment1
* @param lineSegment2
* @returns
*/
export declare function computeIntersectionOfLineSegment_LineSegment<Vec extends VectorInstance>(lineSegment1: [Vec, Vec], lineSegment2: [Vec, Vec]): Vector3 | Vector2 | Vector4 | null;
/**
* 计算多边形和圆的交点
* @param polygon - 多边形
* @param circle
* @returns
*/
export declare function computeIntersectionOfPolygon_Circle(polygon: Vector2[], circle: {
center: Vector2;
radius: number;
}): Vector2[];
/**
* 计算射线和圆的交点
* @param ray - 射线,第一个点射线的起点,第二个点为射线所经过的任意一点(注意,不是射线的方向)
* @param circle
* @returns
*/
export declare function computeIntersectionOfRay_Circle<Vec extends VectorInstance>(ray: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): Vec[];
/**
* 计算射线和线段的交点
* @param ray - 射线,第一个点射线的起点,第二个点为射线所经过的任意一点(注意,不是射线的方向)
* @param line2
* @returns
*/
export declare function computeIntersectionOfRay_LineSegment<Vec extends VectorInstance>(ray: [Vec, Vec], lineSegment: [Vec, Vec]): Vector3 | Vector2 | Vector4 | null;
/**
* 计算相交球
* @param points
* @returns 所有球的相交索引映射
*/
export declare function computeIntersectSpheres<IVec extends IVector>(points: (IVec & {
radius: number;
})[]): number[][];
/**
* 计算折线的的 FrenetFrames
* @remarks
* 最后一个顶点的 tangent,normal,binormal 与前一个顶点的相同
* @param points
* @param up
* @returns
*/
export declare function computePolylineFrenetFrames(points: Vector3[], up: Vector3): {
tangents: Vector3[];
normals: Vector3[];
binormals: Vector3[];
lengths: number[];
length: number;
};
/**
* 通过固定up方向的方式计算折线的的 FrenetFrames
* @remarks
* 最后一个顶点的 tangent,normal,binormal 与前一个顶点的相同
* @param points
* @param up
* @returns
*/
export declare function computePolylineFrenetFramesByFixUp(points: Vector3[], up: Vector3): {
tangents: Vector3[];
normals: Vector3[];
binormals: Vector3[];
lengths: number[];
length: number;
lines: Line3[];
};
/**
* 计算从向量 from 到 向量 to 的 等比例缩放;
* @remarks
* 假设 from 和 to 共线
* @param from
* @param to
* @returns
*/
export declare function computeVectorScalar<Vec extends VectorInstance>(from: Vec, to: Vec): number;
/**
* 使用纹理选项来设置uv
* @param uv
* @param options
* @returns
*/
export declare function configUV(uv: IVector2, options: ConfigUVOptions): IVector2;
/**
* 使用纹理选项批量设置uv
* @param uv
* @param options
* @returns
*/
export declare function configUVBufferAttribute(uvs: BufferAttribute, options: ConfigUVOptions): BufferAttribute;
/**
* 配置uv的选项
*/
export declare interface ConfigUVOptions {
/**
* 定义了纹理贴图在水平方向上将如何包裹,在UV映射中对应于U。
*/
wrapS?: Wrapping;
/**
* 定义了纹理贴图在垂直方向上将如何包裹,在UV映射中对应于V。
*/
wrapT?: Wrapping;
/**
* 是否横向的翻转
*/
flipX?: boolean;
/**
* 是否纵向的翻转
*/
flipY?: boolean;
}
/**
* 使用纹理选项批量设置uv
* @param uv
* @param options
* @returns
*/
export declare function configUVs(uvs: ArrayLike<number>, options: ConfigUVOptions): ArrayLike<number>;
/**
* 航向方位映射
*/
export declare interface CourseAzimuthMap<Define extends AzimuthDefine = AzimuthDefine> {
/**
* 偏航角
* @remarks
* - 旋转轴 上方向量
* - 起始向量:前方向量
*/
yaw?: Define | null;
/**
* 俯仰角
* @remarks
* - 旋转轴 右方向量
* - 起始向量:前方向量
*/
pitch?: Define | null;
/**
* 横滚角
* @remarks
* - 旋转轴 后方向量
* - 起始向量:上方向量
*/
roll?: Define | null;
}
/**
* 航向信息
*/
export declare interface CourseInfo {
/**
* 偏航角
* @remarks
* - 旋转轴 上方向量
* - 起始向量:前方向量
*/
yaw: AzimuthInfo;
/**
* 俯仰角
* @remarks
* - 旋转轴 右方向量
* - 起始向量:前方向量
*/
pitch: AzimuthInfo;
/**
* 横滚角
* @remarks
* - 旋转轴 后方向量
* - 起始向量:上方向量
*/
roll: AzimuthInfo;
}
/**
* 创建斜角的线连接数据
* @param cornerPointInfo
* @param frontFrame
* @param backFrame
* @param chamfer - 是否斜切
* @param zeroThreshold - 零的阀值;绝对值小于该值的都认为是零
* @returns
*/
export declare function createBevelLineConnection(cornerPointInfo: VertexInfo, frontFrame: FrenetFrame, backFrame: FrenetFrame, chamfer?: boolean, zeroThreshold?: number): {
points: Vector3[];
normals: Vector3[];
lengths: number[];
};
/**
* 创建曲线几何体
* @param options - 选项
* @returns
*/
export declare function createCurveBufferGeometry<T extends Vector2 | Vector3>(curve: Curve<T>, options?: CreateCurveBufferGeometryOptions | null): BufferGeometry<NormalBufferAttributes>;
/**
* 创建曲线几何体的选项
*/
export declare type CreateCurveBufferGeometryOptions = CreatePolylineBufferGeometryOptions & SampleOptions;
/**
* 创建颜色梯度材质
* @param gradient
*/
export declare function createLinearGradientTexture(gradient: GradientTextureOptions): Texture;
/**
* 创建圆角的线连接数据
* @param cornerPointInfo
* @param frontFrame
* @param backFrame
* @param options - 选项
* @returns
*/
export declare function createLineConnection(cornerPointInfo: VertexInfo, frontFrame: Omit<FrenetFrame, "">, backFrame: FrenetFrame, options?: CreateLineConnectionOptions): {
points: Vector3[];
normals: Vector3[];
lengths: number[];
};
export declare interface CreateLineConnectionOptions extends CreateRoundLineConnectionOptions {
/**
* 线的连接类型
*/
connectionType: LineConnectionType;
}
/**
* 创建 LineCurve
* @remarks
* 会根据入参自动判断是二维曲线,还是三维曲线
* @param start
* @param end
* @returns
*/
export declare function createLineCurve<Vec extends Vector3 | Vector2>(start: Vec, end: Vec): LineCurveInstance<Vec>;
/**
* 通过顶点列表创建其所围成的折线的线段列表
* @param points
* @returns
*/
export declare function createLineCurves<Vec extends Vector3 | Vector2>(points: Vec[]): LineCurveInstance<Vec>[];
/**
* 通过顶点列表创建其所围成的折线的线段列表
* @param points
* @returns
*/
export declare function createLines(points: Vector3[]): Line3[];
/**
* 创建线段连接器
* @remarks
* 只是简单地将两个线段连接起来
* @param cornerPointInfo
* @param frontFrame
* @param backFrame
* @param chamfer
* @returns
*/
export declare function createLineSegmentConnection(cornerPointInfo: VertexInfo, frontFrame: Omit<FrenetFrame, "tangent">, backFrame: Omit<FrenetFrame, "tangent">): {
points: Vector3[];
normals: Vector3[];
lengths: number[];
};
export declare function createLineSegmentsByCurve<T extends Vector2 | Vector3>(curve: Vector3[] | Curve<T>, options?: CurveHelperOptions | null): Line<BufferGeometry<NormalBufferAttributes>, Material>;
/**
* 创建曲线几何体
* @param options - 选项
* @returns
*/
export declare function createPolylineBufferGeometry(points: Vector3[], options?: CreatePolylineBufferGeometryOptions | null): BufferGeometry<NormalBufferAttributes>;
/**
* 创建折线线几何体的选项
*/
export declare interface CreatePolylineBufferGeometryOptions {
/**
* 每个顶点的曲线长度列表
* @remarks
* 用于节约计算资源,如果没有提供,将会自动计算
*/
lengths?: number[];
/**
* 线的颜色
* @remarks
* 顶点颜色
*/
color?: ColorRepresentation | null;
/**
* 开始处的颜色
*/
startColor?: ColorRepresentation | null;
/**
* 终点处的颜色
*/
endColor?: ColorRepresentation | null;
}
/**
* 创建折线曲线
* @param points - 折线的顶点列表
* @returns
*/
export declare function createPolylineCurve<V extends Vector>(points: V[]): CurvePath<V>;
/**
* 创建圆角的线连接数据
* @param cornerPointInfo
* @param frontFrame
* @param backFrame
* @param options - 圆角选项
* @param zeroThreshold - 零的阀值;绝对值小于该值的都认为是零
* @returns
*/
export declare function createRoundLineConnection(cornerPointInfo: VertexInfo, frontFrame: FrenetFrame, backFrame: FrenetFrame, options?: CreateRoundLineConnectionOptions, zeroThreshold?: number): {
points: Vector3[];
normals: Vector3[];
lengths: number[];
};
export declare interface CreateRoundLineConnectionOptions {
/**
* 圆形衔接角的步长角
* @remarks
* 与 smoothStepLength 作用相同
* smoothStepAngle 的优先级高于 smoothStepLength
*/
smoothStepAngle?: number;
/**
* 圆形衔接角的长度步长
* @remarks
* 与 smoothStepAngle 作用相同
* smoothStepAngle 的优先级高于 smoothStepLength
*/
smoothStepLength?: number;
}
/**
* 创建对称分段的三角面索引
* @remarks
* 当几何体两侧总有对称的顶点时,可用此方法来为其构建三角面索引
* @param vertexCount - 顶点个数
* @param startIndex - 开始索引
* @param connectPre - 是否和之前的面进行拼接
*/
export declare function createSymmetricSegmentedTrigonometricIndexs(vertexCount: number, startIndex?: number, connectPre?: boolean | null): number[];
/**
* 创建对称分段的三角面索引
* @remarks
* 当几何体两侧总有对称的顶点时,可用此方法来为其构建三角面索引
* 本方法会根据转角方向来设置三角面,以使其看起来更合理
* @param vertexCount - 顶点个数
* @param startIndex - 开始索引
* @param connectPre - 是否和之前的面进行拼接
*/
export declare function createSymmetricSegmentedTrigonometricIndexsByVertexs(vertexs: ArrayLike<number>, startIndex?: number, connectPre?: boolean | null): number[];
/**
* 创建uv的变换矩阵
* @param transfrom
* @param target
* @returns
*/
export declare function createUVTransformMatrix(transfrom: UVTransformOptions, target?: Matrix3): Matrix3;
export declare interface CurveHelperOptions extends CreateCurveBufferGeometryOptions {
/**
* 线的材质
*/
material: Material;
/**
* 线宽
*/
linewidth?: number;
}
/**
* 默认选项
*/
export declare const defaultAzimuthOptions: Required<AzimuthOptions>;
/**
* 默认的方位映射
* @remarks
* 将每个旋转面都成了4份:
* - [-15,15]
* - [15,165]
* - [-165,-15]
* - [165,-165]
*/
export declare const defaultCourseAzimuthMap: CourseAzimuthMap;
export declare enum DirectionSide {
/**
* 前面
*/
back = "back",
/**
* 后面
*/
front = "front"
}
/**
* 判别线和圆的位置关系
* @remarks
* 有以下几种情况:
* - Tangency:相切;
* - Dissociation:相离:
* - Intersect;相交;
* @param line
* @param circle
* @returns
*/
export declare function discriminateRelationshipOfLine_Circle<Vec extends VectorInstance>(line: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): GeometricRelationship.Dissociation | GeometricRelationship.Intersect | GeometricRelationship.Tangency;
/**
* 判别线和线的位置关系
* @remarks
* 有以下几种情况:
* - Tangency:相切;两线重合;
* - Dissociation:相离;
* - Intersect;相交
* @param line1
* @param line2
* @returns
*/
export declare function discriminateRelationshipOfLine_Line<Vec extends VectorInstance>(line1: [Vec, Vec], line2: [Vec, Vec]): InfinityGeometricRelationship;
/**
* 判别线段和圆的位置关系
* 有以下几种情况:
* - Contain:包含;线段包含在圆里;包括线段的两个端点在圆上的情况;
* - Tangency:相切;线段与圆相切,且切点在经线段内;
* - Dissociation:相离;
* - Intersect;相交;射线和线段相交;
* @param ray - 射线,第一个点射线的起点,第二个点为射线所经过的任意一点(注意,不是射线的方向)
* @param line
* @param circle
* @returns
*/
export declare function discriminateRelationshipOfLineSegment_Circle<Vec extends VectorInstance>(line: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): GeometricRelationship;
/**
* 判别线段和线段的位置关系
* 有以下几种情况:
* - Contain:包含;其中一个包含在另一个中;
* - Tangency:相切;两线段共线 且 有部分重合;
* - Dissociation:相离:没有重合的部分;
* - Intersect;相交;
* @param lineSegment1
* @param lineSegment2 - 线段
* @returns
*/
export declare function discriminateRelationshipOfLineSegment_LineSegment<Vec extends VectorInstance>(lineSegment1: [Vec, Vec], lineSegment2: [Vec, Vec]): GeometricRelationship;
/**
* 判别点和线段的位置关系
* @remarks
* 有以下几种情况:
* - Contain:包含;线段包含点
* - Tangency:相切;点与线段共线,但不在线段上;
* - Dissociation:相离:不共线;
* @param point
* @param lineSegment
* @returns
*/
export declare function discriminateRelationshipOfLineSegment_Point<Vec extends VectorInstance>(lineSegment: [Vec, Vec], point: Vec): GeometricRelationship.Dissociation | GeometricRelationship.Tangency | GeometricRelationship.Contain;
/**
* 判别点和凸多边形的位置关系
* @remarks
* 叉乘法
* @param point
* @param polygon - 凸多边形
* @returns
*/
export declare function discriminateRelationshipOfPoint_ConvexPolygon(point: Vector2, polygon: Vector2[]): GeometricRelationship.Tangency | GeometricRelationship.Contain;
/**
* 判别点和多边形的位置关系
* @remarks
* 射线法;可以是任意多边形
*
* 有以下几种情况:
* - Contain:包含;点在多边形内部
* - Tangency:相切;点在多边形的边上;
* - Dissociation:相离:点在多边形外部;
* @param point
* @param polygon
* @returns
*/
export declare function discriminateRelationshipOfPoint_Polygon(point: Vector2, polygon: Vector2[]): GeometricRelationship.Dissociation | GeometricRelationship.Tangency | GeometricRelationship.Contain;
/**
* 判别多边形和圆的位置关系
* @remarks
* 可以是任意多边形
* 有以下几种情况:
* - Contain:包含;其中一个在另一个的内部
* - Tangency:相切;
* - Dissociation:相离:点在多边形外部;
* - Intersect:相交;
* @param polygon - 多边形
* @param circle
* @returns
*/
export declare function discriminateRelationshipOfPolygon_Circle(polygon: Vector2[], circle: {
center: Vector2;
radius: number;
}): GeometricRelationship;
/**
* 判别射线和圆的位置关系
* @remarks
* 有以下几种情况:
* - Tangency:相切;
* - Dissociation:相离:
* - Intersect;相交;
* @param ray - 射线,第一个点射线的起点,第二个点为射线所经过的任意一点(注意,不是射线的方向)
* @param circle
* @returns
*/
export declare function discriminateRelationshipOfRay_Circle<Vec extends VectorInstance>(ray: [Vec, Vec], circle: {
center: Vec;
radius: number;
}): InfinityGeometricRelationship;
/**
* 判别射线和线段的位置关系
* @remarks
* 有以下几种情况:
* - Contain:包含;线段包含在射线里;
* - Tangency:相切;射线与线段共线,但射线并不完全包含线段;
* - Dissociation:相离:线段与射线没有重合的部分;
* - Intersect;相交;射线和线段相交;
* @param ray - 射线,第一个点射线的起点,第二个点为射线所经过的任意一点(注意,不是射线的方向)
* @param lineSegment - 线段
* @returns
*/
export declare function discriminateRelationshipOfRay_LineSegment<Vec extends VectorInstance>(ray: [Vec, Vec], lineSegment: [Vec, Vec]): GeometricRelationship;
export declare interface DistanceInfoOfPointToLines {
/**
* 根据点与线的距离进行排序后的索引
*/
distSortIndexs: number[];
/**
* 点到各个线段的距离
*/
clampDists: number[];
/**
* 点到各个线段上最近的点
*/
clampPoints: Vector3[];
/**
* 点到各个线上最近的点的 t 的值
*/
ts: number[];
/**
* 点到各个线段上最近的点的 t 的值
*/
clampTs: number[];
}
/**
* 格式化方位定义映射对象
* @param map
* @returns
*/
export declare function formatAzimuthDefineMap(map: CourseAzimuthMap): CourseAzimuthMap<AzimuthList>;
/**
* 如果 V 是 IVector 类型,则转为对应的 Vector 类型,否则,保持不变
*/
export declare type FormatIVectorMemberToVector<V> = V extends IVector4 ? Vector4 : (V extends IVector3 ? Vector3 : (V extends IVector2 ? Vector2 : V));
/**
* 如果 V 是 Vector 类型,则转为对应的 IVector 类型,否则,保持不变
*/
declare type FormatVectorMemberToIVector<V> = V extends Vector4 ? IVector4 : (V extends Vector3 ? IVector3 : (V extends Vector2 ? IVector2 : V));
export declare interface FrenetFrame {
/**
* 切线;为z轴
*/
tangent: Vector3;
/**
* 法线;作为x轴
*/
normal: Vector3;
/**
* 副法线;作为y轴
*/
binormal: Vector3;
}
export declare type FrenetFrameInfo = FrenetFrame & FrenetFrameLocation;
export declare interface FrenetFrameLocation {
/**
* u或t的列表
*/
ut: number;
/**
* 点列表
*/
point: Vector3;
/**
* 长度信息
*/
length: number;
}
export declare interface FrenetFrameLocations {
/**
* u或t的列表
*/
uts: number[];
/**
* 点列表
*/
points: Vector3[];
/**
* 长度信息
*/
lengths: number[];
}
/**
* 表示两个 FrenetFrame 的关系
*/
export declare enum FrenetFrameRelation {
/**
* 所有的轴都是斜着的
* @remarks
* 即:所有的轴都不平行也不垂直
*/
AllOblique = 0,
/**
* 切线同向
*/
TangentSame = 1,
/**
* 切线反向
*/
TangentReverse = 2,
/**
* 切线垂直
*/
TangentVertical = 4,
/**
* 法线同向
*/
NormalSame = 8,
/**
* 法线反向
*/
NormalReverse = 16,
/**
* 法线垂直
*/
NormalVertical = 32,
/**
* 副法线同向
*/
BinormalSame = 64,
/**
* 副法线反向
*/
BinormalReverse = 128,
/**
* 副法线垂直
*/
BinormalVertical = 256
}
/**
* FrenetFrame列表
* @remarks
* 各个列表的长度相等
*/
export declare interface FrenetFrames {
/**
* 切线列表;为z轴
*/
tangents: Vector3[];
/**
* 法线列表;作为x轴
*/
normals: Vector3[];
/**
* 副法线列表;作为y轴
*/
binormals: Vector3[];
}
export declare type FrenetFramesInfo = FrenetFrames & FrenetFrameLocations;
/**
* FrenetFrame 转为 FrontUpFrame
* @param frame
* @returns
*/
export declare function frenetFrameToFrontUpFrame(frame: FrenetFrame): FrontUpFrame;
export declare interface FrontUpFrame {
/**
* 向前的方向;为z轴
*/
front: Vector3;
/**
* 向上的方向;作为y轴
*/
up: Vector3;
/**
* 副法线;作为x轴
*/
binormal: Vector3;
}
/**
* FrontUpFrame 转为 FrenetFrame
* @param frame
* @returns
*/
export declare function frontUpFrameToFrenetFrame(frame: FrontUpFrame): FrenetFrame;
/**
* 几何位置关系
*/
export declare enum GeometricRelationship {
Dissociation = "\u76F8\u79BB",
Intersect = "\u76F8\u4EA4",
Tangency = "\u76F8\u5207",
Contain = "\u5305\u542B"
}
/**
* 获取3D纹理中指定坐标处的数据项目
* @param texture
* @param coord
* @returns
*/
export declare function get3DTextureItem(texture: Texture3D, coord: IVector3): {
index: number;
value: number[];
};
/**
* 获取3D纹理的切片
* @remarks
* 切片就是指定轴的指定位置的垂直截面
* @param texture - 3D的纹理
* @param axis - 轴
* @param depth - 在轴上的坐标值
* @returns
*/
export declare function get3DTextureSlice(texture: Texture3D, axis: Axis, depth: number): IData2D<number>;
/**
* 以轴 axis 为旋转轴,获取从向量 from 到 向量 to 的旋转角度
* @remarks
* 与 {@link getRotationAngle} 区别是:
* - getRotationAngle 计算的是 从向量 from 到向量 to 旋转角度
* - getAxisRotationAngle 计算的是 向量 from 和 向量 to 在垂直于旋转轴 axis 平面上的投影的旋转角度;即:以 axis 为旋转轴的旋转角度
*
* 以逆时钟方向为旋转正方向
* @param from - 起始向量
* @param to - 结束向量
* @param axis - 旋转轴;
* @returns
*/
export declare function getAxisRotationAngle(from: Vector3, to: Vector3, axis: Vector3): number;
/**
* 获取方位角:即:偏航角、俯仰角、横滚角
* @remarks
* 以 front 为前方,以 up 为上方,计算 target 的 偏航角、俯仰角、横滚角
*
* 这些角度都是在各个轴上的投影旋转,各个轴相互独立,互不影响
*
*
* @param target - 目标向量
* @param front - 表示前方的向量
* @param up - 表示上方的向量
* @returns 返回 {@link YawPitchRoll}
*/
export declare function getAzimuthAngle(target: Vector3, front: Vector3, up: Vector3): YawPitchRoll;
/**
* 获取最近的点相关的信息
* @param point
* @param lines
* @returns
*/
export declare function getClosestDistanceInfoOfPointToLines(point: Vector3, lines: Line3[]): ClosestDistanceInfoOfPointToLines;
/**
* 获取曲线的分段和长度
* @param options
* @returns
*/
export declare function getCurveDivisionLength(options: SampleOptions & {
curve: Curve<Vector3>;
}): {
length: number;
division: number;
};
/**
* 获取曲线上与指定位置(fromU)相距一定距离的点
* @param options - 选项
* @returns
*/
export declare function getCurvePointAwayFrom<T extends Vector>(options: GetCurvePointAwayFromOptions<T>): GetCurvePointAwayFrom_Result<T>;
declare interface GetCurvePointAwayFrom_Result<T extends Vector> {
/**
* 是否成功找到符合条件的点
*/
succeed: boolean;
/**
* 最后查找到的点的u
*/
u: number;
/**
* 最后查找到的点
*/
point: T;
/**
* 最后查找到的点的距离
*/
distance: number;
}
/**
* getCurvePointAwayFrom 的选项
*/
export declare interface GetCurvePointAwayFromOptions<T extends Vector> {
/**
* 曲线
*/
curve: Curve<T>;
/**
* 距离
* @remarks
* 与 fromU 相隔的距离
*/
distance: number;
/**
* 起点
*
* @defaultValue 0
*/
fromU?: number;
/**
* 曲线的长度
* @remarks
* 用于节约计算,不传时,会自动从 curve 上获取
*/
length?: number;
/**
* 查找的方向
*/
side?: DirectionSide;
/**
* 距离容差
* @remarks
* 在容差范围呢视为等距
*/
tolerance?: number;
}
export declare function getCurvePointAwayFromOrigin<T extends Vector>(options: GetCurvePointAwayFromOriginOptions<T>): {
u: number;
point: T;
} | null;
/**
* getCurvePointAwayFromOrigin 的选项
*/
export declare interface GetCurvePointAwayFromOriginOptions<T extends Vector> extends Omit<GetCurvePointAwayFromOptions<T>, "side"> {
origin: T;
}
/**
* 获取曲线的累积段长度的列表。
* @param curve - 曲线
* @param divisions - 要将曲线划分为的分段数;默认是 `curve.arcLengthDivisions`
* @returns
*/
export declare function getCurveULengths<T extends Vector>(curve: Curve<T>, divisions?: number): {
lengths: number[];
length: number;
};
/**
* 获取点到所有线的距离信息
* @param point
* @param lines
* @returns
*/
export declare function getDistanceInfoOfPointToLines(point: Vector3, lines: Line3[]): DistanceInfoOfPointToLines;
/**
* 计算两个向量的夹角
* @remarks
* 与 `Vector3.angleTo(v)` 不同的是:当 from 或 to 为零时,会返回 0
* @param from - 起始向量
* @param to - 目标向量
* @returns 返回一个 0 到 pi(弧度)的数值
*/
export declare function getIncludedAngle(from: Vector3, to: Vector3): number;
/**
* 获取每个点对应的长度
* @param points
* @returns
*/
export declare function getLengthsOfPoints(points: Vector3[]): {
lengths: number[];
length: number;
};
/**
* 获取每个点对应的长度
* @param positionAttribute
* @returns
*/
export declare function getLengthsOfPositionAttribute(positionAttribute: BufferAttribute | InterleavedBufferAttribute): {
lengths: number[];
length: number;
};
/**
* 获取u列表对应的曲线累积长度列表。
* @param curve - 曲线
* @param ts - t 列表
* @param isU - 是否将 ts 列表中的 t 作为 u 来使用
* @returns
*/
export declare function getLengthsOfTs<T extends Vector>(curve: Curve<T>, ts: number[], isU?: boolean): {
lengths: number[];
length: number;
};
/**
* 获取折线的信息
* @param points
* @returns
*/
export declare function getLinesInfo(points: Vector3[]): {
lines: Line3[];
lengths: number[];
length: number;
};
/**
* 获取点的投影线
* @remarks
* 投影线是点在线段上的垂足落在线段内的线
*
* @param point
* @param lines
* @returns
*/
export declare function getProjectionLines(point: Vector3, lines: Line3[]): {
lines: Line3[];
indexs: number[];
};
/**
* 获取两个向量之间的绕轴旋转
* @param from - 旋转的起始向量
* @param to - 旋转的终点向量
* @param axis - 轴
* @param result
* @returns
*/
export declare function getQuaternionBetweenVectorsAroundAxis(from: Vector3, to: Vector3, axis: Vector3, result?: Quaternion | null): Quaternion;
/**
* 以轴 refAxis 为参考轴,获取从向量 from 到 向量 to 的旋转角度
* @remarks
* 参考轴只提供大致的方向;最终计算的旋转角度不是以参考轴为旋转轴的,而是以垂直于 from 和 to 的轴为旋转轴的;
*
* 以逆时钟方向为旋转正方向
* @param from - 起始向量
* @param to - 结束向量
* @param refAxis - 参考轴;
* @returns
*/
export declare function getRotationAngle(from: Vector3, to: Vector3, refAxis: Vector3): number;
/**
* 获取采样数(整数)
* @remarks
* 优先使用 `sampleLength` 选项;
* @param options - 采样选项
* @param length - 曲线总长度
* @returns
*/
export declare function getSampleNum(options: SampleOptions, length: number): number;
/**
* 获取 Texture 的 format 对应的 item 尺寸(长度)
* @param format
* @returns
*/
export declare function getTextureFormatSize(format: AnyPixelFormat): number;
/**
* 获取 IVector 对应的 Vector 类
* @param vec
* @returns
*/
export declare function getVectorClass<IVec extends IVector>(vec: IVec): [IVectorToVectorClass<IVec>, number];
export declare type GradientTextureOptions = Texture | TexImageSource | string | ColorGradient;
export declare interface IColor {
r: number;
g: number;
b: number;
}
export declare type IColorRepresentation = IColor | number | string;
export declare interface IEuler extends IVector3 {
order?: EulerOrder;
}
/**
* 无限大的几何图形之间的关系
* @remarks
* 有以下几种情况:
* - Tangency:相切;
* - Dissociation:相离:
* - Intersect;相交;
*/
export declare type InfinityGeometricRelationship = GeometricRelationship.Dissociation | GeometricRelationship.Tangency | GeometricRelationship.Intersect;
/**
* 交线的关系
*/
export declare interface IntersectionLineInfo {
/**
* 两个带的相交关系
*/
relation: FrenetFrameRelation;
line?: {
/**
* 交线的切线方向
*/
tangent: Vector3;
/**
* 交线的切线方向
*/
normal: Vector3;
/**
* 交结的长度
*/
length: number;
};
}
/**
* 判断两个向量是否共线
*/
export declare function isCollinear<Vec extends VectorInstance>(vec1: Vec, vec2: Vec): boolean;
export { IVector }
export { IVector2 }
export { IVector3 }
export { IVector4 }
/**
* 将对象所有属性为 IVector 类型的值转为 Vector 类型的值
* 将对象所有属性为 IVector[] 类型的值转为 Vector[] 类型的值
*/
export declare type IVectorMembersToVectors<T> = {
[P in keyof T]: ArrayItemType<T[P]> extends never ? FormatIVectorMemberToVector<T[P]> : FormatIVectorMemberToVector<ArrayItemType<T[P]>>[];
};
/**
* 深度拷贝并转换所有的 IVector 成员及其子成员为 Vector
* @remarks
* 本函数返回的类型没做递归处理,其实函数会对所有成员及子孙成员进行处理
*
* @param target
* @param recursive 是否对对象成员的成员进行递归转换
* @param level 递归的层级,从0开始;这个是程序递归时自己传的,用户不需要传递
* @returns
*/
export declare function ivectorMemberToVector<T>(target: T, recursive?: boolean, level?: number): IVectorMembersToVectors<T>;
/**
* 向量接口类型转向量类型
*/
export declare type IVectorToVector<V extends IVector> = V extends IVector4 ? Vector4 : (V extends IVector3 ? Vector3 : Vector2);
/**
* IVector 类型转为 Vector 类型
* @param ivector
* @returns
*/
export declare function ivectorToVector<V extends IVector>(ivector: V): IVectorToVector<V>;
/**
* 向量接口类型转向量类类型
*/
export declare type IVectorToVectorClass<V extends IVector> = V extends IVector4 ? typeof Vector4 : (V extends IVector3 ? typeof Vector3 : typeof Vector2);
/**
* 线的衔接类型
*/
export declare enum LineConnectionType {
/**
* 斜角
*/
bevel = "bevel",
/**
* 斜切
*/
chamfer = "chamfer",
/**
* 圆
*/
round = "round",
/**
* 线段
*/
lineSegment = "lineSegment"
}
/**
* 2维和3维的LineCurve类的类型
*/
export declare type LineCurveClass<Vec extends Vector3 | Vector2> = Vec extends Vector3 ? typeof LineCurve3 : typeof LineCurve;
/**
* 2维和3维的LineCurve实例的类型
*/
export declare type LineCurveInstance<Vec extends Vector3 | Vector2> = Vec extends Vector3 ? LineCurve3 : LineCurve;
export declare type Point_Length_FrenetFrames = FrenetFrames & Pick<FrenetFrameLocations, "points" | "lengths">;
/**
* 采样选项
*/
export declare interface SampleOptions {
/**
* 采样长度
* @remarks
* 多长的弧长长度会生成一个采样点
*
* `sampleNum` 和 `sampleLength` 只需要其一;优先使用 `sampleLength`
*
* @defaultValue 1
*/
sampleLength?: number;
/**
* 采样个数
* @remarks
* 生成多少个采样点;
*
* `sampleNum` 和 `sampleLength` 只需要其一;优先使用 `sampleLength`
*/
sampleNum?: number;
}
/**
* 3D的纹理
* @remarks
* 包含三维数据的纹理
*/
export declare type Texture3D = Data3DTexture | DataArrayTexture;
/**
* 修复 three中发现的bug
*/
export declare function threeBugPatch(): void;
/**
* 变换单个uv
* @param uv
* @param transfrom
* @returns
*/
export declare function transformUV(uv: Vector2, transfrom: UVTransformOptions, options?: ConfigUVOptions | null): Vector2;
/**
* 对 uv BufferAttribute 进行变换
* @param uvs
* @param transfrom
* @param options
* @returns
*/
export declare function transformUVBufferAttribute(uvs: BufferAttribute, transfrom: UVTransformOptions, options?: ConfigUVOptions | null): BufferAttribute;
/**
* 对 uv 数组进行变换
* @param uvs
* @param transfrom
* @param options
* @returns
*/
export declare function transformUVs(uvs: ArrayLike<number>, transfrom: UVTransformOptions, options?: ConfigUVOptions | null): ArrayLike<number>;
export declare type UT_FrenetFrames = FrenetFrames & Pick<FrenetFrameLocations, "uts">;
export declare type UT_Point_FrenetFrames = FrenetFrames & Pick<FrenetFrameLocations, "uts" | "points">;
/**
* uv 变换选项
*/
export declare interface UVTransformOptions {
/**
* 偏移
*
* @defaultValue {x:0,y:0}
*/
offset?: IVector2;
/**
* 重复
* @defaultValue {x:1,y:1}
*/
repeat?: IVector2;
/**
* 旋转角度
* @remarks
* 弧度
*
* @defaultValue 0
*/
rotation?: number;
/**
* 旋转中心
* @defaultValue {x:0,y:0}
*/
center?: IVector2;
}
/**
* 向量的类类型
*/
export declare type VectorClass = typeof Vector4 | typeof Vector3 | typeof Vector2;
/**
* 将 VectorClass 类型 转为 Vector 类型
*/
export declare type VectorClassToInstance<VC extends VectorClass> = VC extends typeof Vector4 ? Vector4 : (VC extends typeof Vector3 ? Vector3 : Vector2);
/**
* 向量
* @remarks
* 与 Vector 的区别是:
* - Vector 只描述的基本的方法,不够全面
*/
export declare type VectorInstance = Vector4 | Vector3 | Vector2;
/**
* 将对象所有属性为 Vector 类型的值转为 IVector 类型的值
* 将对象所有属性为 Vector[] 类型的值转为 IVector[] 类型的值
*/
export declare type VectorMembersToIVectors<T> = {
[P in keyof T]: ArrayItemType<T[P]> extends never ? FormatVectorMemberToIVector<T[P]> : FormatVectorMemberToIVector<ArrayItemType<T[P]>>[];
};
/**
* 向量类型转向量接口类型
*/
export declare type VectorToIVector<V extends VectorInstance> = V extends Vector4 ? IVector4 : (V extends Vector3 ? IVector3 : IVector2);
export declare interface VertexInfo {
point: Vector3;
length: number;
width: number;
}
/**
* 航向角
*
* @remarks
* 所有角度都是以逆时针方向为正方向
*/
export declare interface YawPitchRoll {
/**
* 偏航角
* @remarks
* - 旋转轴 上方向量
* - 起始向量:前方向量
*/
yaw: number;
/**
* 俯仰角
* @remarks
* - 旋转轴 右方向量
* - 起始向量:前方向量
*/
pitch: number;
/**
* 横滚角
* @remarks
* - 旋转轴 后方向量
* - 起始向量:上方向量
*/
roll: number;
}
/**
* 零的阀值
* @remarks
* 绝对值小于该值的都认为是零
*/
export declare const zeroThreshold_Default = 0.1;
export { }