工具
关于 @realsee/Dnalogel 中的工具函数/类 的文档
导入
import { import UtilUtil } from '@realsee/dnalogel'Util.blink
闪烁一个 dom / THREE.Object3D
const const target: HTMLElementtarget = var document: Documentdocument.Document.getElementById(elementId: string): HTMLElement | nullReturns a reference to the first object with the specified value of the ID attribute.
getElementById('my-dom-element')!
import UtilUtil.function blink(objects: Target | Target[], animeOptions?: Util.BlinkAnimeOptions | undefined): Util.AnimeInstance
export blinkblink(const target: HTMLElementtarget)
import UtilUtil.function reblink(objects: Target | Target[], animeOptions?: Util.BlinkAnimeOptions | undefined): Util.AnimeInstance
export reblinkreblink(const target: HTMLElementtarget) // 反向闪烁Util.FiveDomEvents
five空间中的物体的交互系统
const const domEvents: Util.FiveDomEventsdomEvents = new import UtilUtil.constructor FiveDomEvents(five: Five, config?: Util.EventHandlerConfig | undefined): Util.FiveDomEventsFiveDomEvents(const five: Fivefive)
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"click">(object: Object3DWithEvent, event: "click", callback: (event: Util.FiveDomEvent) => boolean | void, config?: Util.EventHandlerConfig | undefined): voidaddEventListener(const object: THREE.Object3Dobject, 'click', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('Clicked!')
})
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"hover">(object: Object3DWithEvent, event: "hover", callback: (event: Util.FiveDomEvent) => void, config?: Util.EventHandlerConfig | undefined): voidaddEventListener(const object: THREE.Object3Dobject, 'hover', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('Hovered!')
})
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"unHover">(object: Object3DWithEvent, event: "unHover", callback: (event: Util.FiveDomEvent) => void, config?: Util.EventHandlerConfig | undefined): voidaddEventListener(const object: THREE.Object3Dobject, 'unHover', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('Unhovered!')
})Util.FivePuppet
使用独立 canvas 绘制物体,摄像机位置及视角与 five 保持一致
const const fivePuppet: Util.FivePuppetfivePuppet = new import UtilUtil.constructor FivePuppet(five: Five, params?: {
zIndex: number;
} | undefined): Util.FivePuppetFivePuppet(const five: Fivefive)
const fivePuppet: Util.FivePuppetfivePuppet.FivePuppet.scene: THREE.Scenescene.Object3D.add(...object: THREE.Object3D[]): THREE.SceneAdds object as child of this object.
add(const object: THREE.Object3Dobject)Util.lookObject
以最佳视角观察一个物体
import UtilUtil.function lookObject(five: Five, object: THREE.Object3D, config?: {
scale?: number | undefined;
} | undefined): Promise<void>lookObject(const five: Fivefive, const object: THREE.Object3Dobject)Util.lookPoint
以最佳视角看向一个坐标点
import UtilUtil.function lookPoint(five: Five, point: THREE.Vector3, config?: {
distance?: number | undefined;
} | undefined): Promise<void>lookPoint(const five: Fivefive, const vector3: THREE.Vector3vector3)Util.PointSelector
选点器,支持触摸屏长按选点
const const selector: Util.PointSelectorselector = new import UtilUtil.constructor PointSelector(five: Five, config?: Partial<Config> | undefined): Util.PointSelectorPointSelector(const five: Fivefive)
// 连续选点
const selector: Util.PointSelectorselector.Subscribe<EventMap>.on<"select">(name: "select", callback: (intersection: Util.PointIntersection) => void, once?: boolean | undefined): () => void注册事件
on('select', ({ point: THREE.Vector3焦点坐标
point }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('Selected point:', point: THREE.Vector3焦点坐标
point)
})
// 选点后自动结束
const selector: Util.PointSelectorselector.Subscribe<EventMap>.on<"select">(name: "select", callback: (intersection: Util.PointIntersection) => void, once?: boolean | undefined): () => void注册事件
on('select', ({ point: THREE.Vector3焦点坐标
point }) => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('Selected point:', point: THREE.Vector3焦点坐标
point)
const selector: Util.PointSelectorselector.PointSelector.disable(): voiddisable()
})
const selector: Util.PointSelectorselector.PointSelector.enable(): voidenable()Util.sculpt
封装了一些常用的 mesh。完整数据结构:data
const {
const LineMesh: typeof Util.sculpt.LineMeshLineMesh,
const BoxMesh: typeof Util.sculpt.BoxMeshBoxMesh,
const CircleMesh: typeof Util.sculpt.CircleMeshCircleMesh,
const CircleWithEdgeMesh: typeof Util.sculpt.CircleWithEdgeMeshCircleWithEdgeMesh,
const CylinderMesh: typeof Util.sculpt.CylinderMeshCylinderMesh,
const PointMesh: typeof Util.sculpt.PointMeshPointMesh,
const PolygonMesh: typeof Util.sculpt.PolygonMeshPolygonMesh,
const PrismMesh: typeof Util.sculpt.PrismMeshPrismMesh
} = import UtilUtil.import sculptsculpt
// 在空间中添加 (0,1,2) 点
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const PointMesh: new (params?: Partial<ColorStyle & {
size: number;
} & OcclusionStyle & Partial<DisplayInfoConfig> & PointData> | undefined) => Util.sculpt.PointMeshPointMesh({ point?: AnyPosition | undefinedpoint: [0, 1, 2] }))
// 添加线
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const LineMesh: new (params?: Partial<LineColorStyle & LineOpacityStyle & LineWidthStyle & {
dashed?: boolean | undefined;
} & OcclusionStyle & Partial<...> & Partial<...> & PointsData> | undefined) => Util.sculpt.LineMeshLineMesh({ points?: AnyPosition[] | undefinedpoints: [[0, 1, 2], [3, 4, 5]] }))
// 添加多边形
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const PolygonMesh: new (params?: Partial<OpacityStyle & ColorStyle & OcclusionStyle & {
lengthEnable: boolean;
} & PointsData> | undefined) => Util.sculpt.PolygonMeshPolygonMesh({ points?: AnyPosition[] | undefinedpoints: [[0, 1, 2], [3, 4, 5], [6, 7, 8]] }))
// 添加半径为3的圆,圆心为 (0,1,2) 点
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const CircleMesh: new (params?: Partial<OpacityStyle & ColorStyle & OcclusionStyle & CircleData> | undefined) => Util.sculpt.CircleMeshCircleMesh({ center?: AnyPosition | undefinedcenter: [0, 1, 2], radius?: number | undefinedradius: 3 }))
// 添加带边的圆
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const CircleWithEdgeMesh: new (params?: Partial<OpacityStyle & ColorStyle & OcclusionStyle & LineColorStyle & LineOpacityStyle & LineWidthStyle & CircleData> | undefined) => Util.sculpt.CircleWithEdgeMeshCircleWithEdgeMesh({ center?: AnyPosition | undefinedcenter: [0, 1, 2], radius?: number | undefinedradius: 3 }))
// 添加柱体
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const CylinderMesh: new (params?: Partial<OpacityStyle & ColorStyle & OcclusionStyle & LineColorStyle & LineOpacityStyle & LineWidthStyle & CylinderData> | undefined) => Util.sculpt.CylinderMeshCylinderMesh({ bottomCenter?: AnyPosition | undefinedbottomCenter: [0, 1, 0], topCenter?: AnyPosition | undefinedtopCenter: [0, 2, 0], radius?: number | undefinedradius: 3 }))
// 添加 box,底面矩形为 [[0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1]],高点为 [0, 2, 0]
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const BoxMesh: new (params?: Partial<PrismData & OpacityStyle & ColorStyle & OcclusionStyle & LineColorStyle & LineOpacityStyle & LineWidthStyle> | undefined) => Util.sculpt.BoxMeshBoxMesh({
points?: AnyPosition[] | undefinedpoints: [
[0, 0, 0],
[1, 0, 0],
[1, 0, 1],
[0, 0, 1]
],
heightPoint?: AnyPosition | undefinedheightPoint: [0, 2, 0],
}))
// 添加棱柱
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(new const PrismMesh: new (params?: Partial<PrismData & OpacityStyle & ColorStyle & OcclusionStyle & LineColorStyle & LineOpacityStyle & LineWidthStyle> | undefined) => Util.sculpt.PrismMeshPrismMesh({
points?: AnyPosition[] | undefinedpoints: [
[0, 0, 0],
[1, 0, 0],
[1, 0, 2],
[1, 0, 1],
[0, 0, 1]
],
heightPoint?: AnyPosition | undefinedheightPoint: [0, 2, 0],
}))其他的一些用法:Sculpt (e.g.: 绘制一个 boxMesh 并启用 box 编辑功能)
const { const PointSelector: typeof Util.PointSelectorPointSelector } = import UtilUtil
const { const BoxMesh: typeof Util.sculpt.BoxMeshBoxMesh, const BoxMeshEditor: typeof Util.sculpt.BoxMeshEditorBoxMeshEditor, const createBox: (boxMesh: Util.sculpt.BoxMesh, pointSelector: Util.PointSelector, config?: Partial<CreateLimitConfig & DrawMethodConfig> | undefined) => Promise<void>createBox } = import UtilUtil.import sculptsculpt
// 创建 boxMesh
const const boxMesh: Util.sculpt.BoxMeshboxMesh = new const BoxMesh: new (params?: Partial<PrismData & OpacityStyle & ColorStyle & OcclusionStyle & LineColorStyle & LineOpacityStyle & LineWidthStyle> | undefined) => Util.sculpt.BoxMeshBoxMesh({ lineColor?: Color | undefinedlineColor: 0xff0000 })
const five: Fivefive.Five.scene: Scene内部使用的 THREE.Scene
scene.Scene.add(...objects: AddableObject[]): SceneAdds object as child of this object.
add(const boxMesh: Util.sculpt.BoxMeshboxMesh)
// 按需初始化编辑器
const const editor: Util.sculpt.BoxMeshEditoreditor = new const BoxMeshEditor: new (boxMesh: Util.sculpt.BoxMesh) => Util.sculpt.BoxMeshEditorBoxMeshEditor(const boxMesh: Util.sculpt.BoxMeshboxMesh)
// 创建选择器
const const pointSelector: Util.PointSelectorpointSelector = new const PointSelector: new (five: Five, config?: Partial<Config> | undefined) => Util.PointSelectorPointSelector(const five: Fivefive)
const createBox: (boxMesh: Util.sculpt.BoxMesh, pointSelector: Util.PointSelector, config?: Partial<CreateLimitConfig & DrawMethodConfig> | undefined) => Promise<...>createBox(const boxMesh: Util.sculpt.BoxMeshboxMesh, const pointSelector: Util.PointSelectorpointSelector).Promise<void>.then<void, never>(onfulfilled?: ((value: void) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>Attaches callbacks for the resolution and/or rejection of the Promise.
then(() => {
var console: Consoleconsole.Console.log(...data: any[]): voidlog('绘制完成')
// 按需启用编辑功能
const editor: Util.sculpt.BoxMeshEditoreditor.BaseEditorWithObjectHelper<BoxMesh>.enable(): voidenable()
})Util.tag
轻量化的标签
const const tag1: Util.LightTagtag1 = import UtilUtil.function tag(five: Five, position?: AnyPosition | undefined, config?: {
wrapper?: HTMLElement | undefined;
positionsForRotate?: AnyPosition[] | undefined;
namespace?: string | undefined;
} | undefined): Util.LightTagtag(const five: Fivefive, [0, 1, 2])
const tag1: Util.LightTagtag1.LightTag.container: HTMLDivElementcontainer.InnerHTML.innerHTML: stringinnerHTML = '<div>tag1</div>'
const const tag2: Util.LightTagtag2 = import UtilUtil.function tag(five: Five, position?: AnyPosition | undefined, config?: {
wrapper?: HTMLElement | undefined;
positionsForRotate?: AnyPosition[] | undefined;
namespace?: string | undefined;
} | undefined): Util.LightTagtag(const five: Fivefive, [0, 1, 2])
const tag2: Util.LightTagtag2.LightTag.container: HTMLDivElementcontainer.InnerHTML.innerHTML: stringinnerHTML = '<div>tag2</div>'或:先初始化,后设置位置
const const tag: Util.LightTagtag = import UtilUtil.function tag(five: Five, position?: AnyPosition | undefined, config?: {
wrapper?: HTMLElement | undefined;
positionsForRotate?: AnyPosition[] | undefined;
namespace?: string | undefined;
} | undefined): Util.LightTagtag(const five: Fivefive)
const tag: Util.LightTagtag.LightTag.container: HTMLDivElementcontainer.InnerHTML.innerHTML: stringinnerHTML = '<div>tag</div>'
const tag: Util.LightTagtag.LightTag.setPosition(position: AnyPosition, positionsForRotate?: AnyPosition[] | undefined): voidsetPosition(new import THREETHREE.constructor Vector3(x?: number | undefined, y?: number | undefined, z?: number | undefined): THREE.Vector33D vector.
Vector3(0, 1, 2))