UNPKG

@turbox3d/design-engine

Version:

Large-scale design application engine library

285 lines (284 loc) 8.91 kB
import { Domain } from '@turbox3d/reactivity'; import { Box2, Box3, Matrix3, Matrix4, Vector2, Vector3 } from '@turbox3d/math'; /** 视角类型 */ export declare enum EPerspectiveType { /** 正视 */ FRONT = "front", /** 顶视 */ TOP = "top", /** 左视 */ LEFT = "left" } export interface MeshModel { vertices: ArrayBuffer; indices: ArrayBuffer; uvs: ArrayBuffer; normals: ArrayBuffer; tiledImgUrl: string; material?: string; } /** * | y * | * | * | x * /— — — — — — * / * / * /z * 右手坐标系 */ export default class EntityObject extends Domain { static EPerspectiveType: typeof EPerspectiveType; private static entityMap; static getEntityById(id: string): EntityObject | undefined; id: string; /** 模型名称 */ name: string; /** 模型位置 */ position: Vector3; /** 模型旋转角度(注意不是弧度) */ rotation: Vector3; /** 模型缩放 */ scale: Vector3; /** 模型尺寸 */ size: Vector3; /** 模型父节点 */ parent?: EntityObject; /** 模型子节点 */ children: Set<EntityObject>; /** 是否隐藏 */ hidden: boolean; /** 是否锁定 */ locked: boolean; /** 是否可被点击 */ isClickable: boolean; /** 是否可被 hover */ isHoverable: boolean; /** 是否可被拖拽 */ isDraggable: boolean; /** 是否可被捏合(移动端) */ isPinchable: boolean; /** 是否可被旋转(移动端) */ isRotatable: boolean; /** 是否可被按压(移动端) */ isPressable: boolean; /** 渲染顺序 */ renderOrder: number; /** 对应的模型网格 */ meshes: MeshModel[]; /** 响应式的任务管线 */ protected reactivePipeLine: Array<{ func: Function; options?: { name?: string; deps?: Function[]; immediately?: boolean; }; }>; private reactions; constructor(id?: string); initDomainContext(): { isNeedRecord: boolean; }; /** 启动响应式任务管线 */ runReactivePipeLine(): void; /** 销毁所有响应式任务管线 */ disposeReactivePipeLine(): void; /** back * 0---------3 * | | * |left |right * | | * 1---------2 * front * 顶视的紧贴包围盒点集合,忽略 x、z 轴旋转 */ get box2Top(): Vector2[]; /** 基于世界坐标系的顶视的紧贴包围盒点集合,忽略 x、z 轴旋转 */ get box2TopWCS(): Vector2[]; /** * 基于世界坐标系的顶视的 AABB 包围盒点集合,忽略 x、z 轴旋转 */ get box2TopAABBWCS(): Vector2[]; /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 正视/立面的紧贴包围盒点集合,忽略 x、y 轴旋转 */ get box2Front(): Vector2[]; /** 基于世界坐标系的正视/立面的紧贴包围盒点集合,忽略 x、y 轴旋转 */ get box2FrontWCS(): Vector2[]; /** * 基于世界坐标系的正视/立面的 AABB 包围盒点集合,忽略 x、y 轴旋转 */ get box2FrontAABBWCS(): Vector2[]; /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 左视的紧贴包围盒点集合,忽略 y、z 轴旋转 */ get box2Left(): Vector2[]; /** 基于世界坐标系的左视的紧贴包围盒点集合,忽略 y、z 轴旋转 */ get box2LeftWCS(): Vector2[]; /** * 基于世界坐标系的左视的 AABB 包围盒点集合,忽略 y、z 轴旋转 */ get box2LeftAABBWCS(): Vector2[]; /** * 7-----------6 * / . / | * / . / | * 4-----------5 | * | . | | * | . | | * | 0.......|...3 * | . | / * | . | / * 1-----------2 * 三维的紧贴包围盒点集合 */ get box3(): Vector3[]; /** 基于世界坐标系的三维的紧贴包围盒点集合 */ get box3WCS(): Vector3[]; /** * 三维的 AABB 包围盒点集合 */ get box3AABB(): Vector3[]; /** * 基于世界坐标系的三维的 AABB 包围盒点集合 */ get box3AABBWCS(): Vector3[]; /** 缩放过的尺寸 */ get scaledSize(): Vector3; /** 3x3 entity 顶视矩阵 */ get matrix3Top(): Matrix3; /** 3x3 entity 正视/立面矩阵 */ get matrix3Front(): Matrix3; /** 3x3 entity 左视矩阵 */ get matrix3Left(): Matrix3; /** 4x4 entity 矩阵 */ get matrix4(): Matrix4; setClickable(clickable: boolean): this; setHoverable(hoverable: boolean): this; setDraggable(draggable: boolean): this; setPinchable(pinchable: boolean): this; setRotatable(rotatable: boolean): this; setPressable(pressable: boolean): this; /** 设置是否可交互 */ setInteractive(interactive: boolean): this; setRenderOrder(renderOrder: number): this; /** 锁定 */ lock(): this; /** 解锁 */ unlock(): this; /** 隐藏模型 */ hide(): this; /** 显示模型 */ show(): this; /** 设置名称 */ setName(name: string): this; /** 设置一个 4x4 矩阵 */ setMatrix4(value: Matrix4): this; /** 相对于世界坐标系的矩阵 */ get concatenatedMatrix(): Matrix4; /** 是否是顶层模型 */ isRoot(): boolean; /** * 获取该模型的顶层模型 * @param stopCondition 停止查找的条件函数,返回 true 就停下查找 */ getRoot(stopCondition?: (currentNode: EntityObject) => boolean): EntityObject; /** * 遍历 * @param callback 遍历的处理逻辑函数,返回值是布尔值,如果是 true,则会停止当前遍历到的节点继续往下遍历 */ traverse(callback: (current: EntityObject) => boolean | void): this; /** 添加子模型 */ addChild(child: EntityObject): this; /** 批量添加子模型 */ addChildren(children: EntityObject[]): this; /** 删除子模型 */ removeChild(child: EntityObject): this; /** 批量移除指定的子模型,不传参则移除所有子模型 */ removeChildren(children?: EntityObject[]): this; /** 获取该模型与其祖先节点的路径链(从祖先节点到当前模型的顺序) */ getParentPathChain(): EntityObject[]; /** 获取模型节点深度 */ getDepth(): number; getScaledSize(): Vector3; setPosition(position: { x?: number; y?: number; z?: number; }): this; setRotation(rotation: { x?: number; y?: number; z?: number; }): this; setScale(scale: { x?: number; y?: number; z?: number; }): this; setSize(size: { x?: number; y?: number; z?: number; }): this; setMeshes(value: MeshModel[]): this; getMatrix4(order?: string): Matrix4; getMatrix3From3d(type?: EPerspectiveType): Matrix3; getConcatenatedMatrix(): Matrix4; /** * 初始建模包围盒,默认建模原点为几何中心,如需修改请重写该方法 * @BreakingChange 之前建模原点默认为左后下,现在默认为几何中心(更便于做计算) */ getRawBox3(): Box3; getRawBox3Points(): Vector3[]; /** 获取 AABB 包围盒 */ getBox3AABB(matrix4?: Matrix4, useWCS?: boolean): Vector3[]; /** 获取紧贴包围盒 */ getBox3(matrix4?: Matrix4, useWCS?: boolean): Vector3[]; getRawBox2PointsFrom3d(type?: EPerspectiveType): Vector2[]; /** 从 3d 下不同视角获取 2d AABB 包围盒 */ getBox2AABBFrom3d(type?: EPerspectiveType, useWCS?: boolean): Vector2[]; /** 从 3d 下不同视角获取 2d 紧贴包围盒 */ getBox2From3d(type?: EPerspectiveType, useWCS?: boolean): Vector2[]; /** * ------------------------------------------------ 以下是纯 2d 坐标系下的方法 ------------------------------------------------ * x * |— — — — — — * | * | * | * y | * 2d 坐标系 */ getRawBox2(): Box2; /** top * 3---------2 * | | * |left |right * | | * 0---------1 * bottom * 获取原始包围盒的 4 个点 */ getRawBox2Points(): Vector2[]; getMatrix3(): Matrix3; getConcatenatedMatrix3(): Matrix3; /** 获取 AABB 包围盒 */ getBox2AABB(matrix3?: Matrix3, useWCS?: boolean): Vector2[]; /** 获取紧贴包围盒 */ getBox2(matrix3?: Matrix3, useWCS?: boolean): Vector2[]; }