工具
关于 @realsee/Dnalogel 中的工具函数/类 的文档
导入
import { import UtilUtil } from '@realsee/dnalogel'Util.blink
闪烁一个 dom / THREE.Object3D
const const target: HTMLElementtarget = var document: Documentwindow.document returns a reference to the document contained in the window.
document.Document.getElementById(elementId: string): HTMLElement | nullThe getElementById() method of the Document interface returns an Element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.
getElementById('my-dom-element')!
import UtilUtil.function blink(objects: Util.Target | Util.Target[], animeOptions?: Util.BlinkAnimeOptions): Util.AnimeInstance
export blink
闪烁一个物体或DOM元素
blink(const target: HTMLElementtarget)
import UtilUtil.function reblink(objects: Util.Target | Util.Target[], animeOptions?: Util.ReBlinkAnimeOptions): Util.AnimeInstance
export reblink
闪烁一个不可见的物体或DOM元素
reblink(const target: HTMLElementtarget) // 反向闪烁Util.FiveDomEvents
five空间中的物体的交互系统
const const domEvents: Util.FiveDomEventsdomEvents = new import UtilUtil.constructor FiveDomEvents(five: Five, config?: Util.EventHandlerConfig): Util.FiveDomEventsFiveDomEvents(const five: Fivefive)
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"click">(object: Object3DWithEvent, event: "click", callback: (event: Util.FiveDomEvent) => boolean | void, config?: Omit<Util.EventHandlerConfig, "fiveModels">): voidaddEventListener(const object: THREE.Object3Dobject, 'click', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('Clicked!')
})
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"hover">(object: Object3DWithEvent, event: "hover", callback: (event: Util.FiveDomEvent) => void, config?: Omit<Util.EventHandlerConfig, "fiveModels">): voidaddEventListener(const object: THREE.Object3Dobject, 'hover', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('Hovered!')
})
const domEvents: Util.FiveDomEventsdomEvents.FiveDomEvents.addEventListener<"unHover">(object: Object3DWithEvent, event: "unHover", callback: (event: Util.FiveDomEvent) => void, config?: Omit<Util.EventHandlerConfig, "fiveModels">): voidaddEventListener(const object: THREE.Object3Dobject, 'unHover', () => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('Unhovered!')
})Util.FivePuppet
使用独立 canvas 绘制物体,摄像机位置及视角与 five 保持一致
const const fivePuppet: Util.FivePuppetfivePuppet = new import UtilUtil.constructor FivePuppet(five: Five, params?: {
zIndex: number;
}): Util.FivePuppet
FivePuppet(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;
minDistance?: number;
minLatitude?: number;
}): Promise<void>
lookObject(const five: Fivefive, const object: THREE.Object3Dobject)Util.lookPoint
以最佳视角看向一个坐标点
import UtilUtil.function lookPoint(five: Five, point: THREE.Vector3, config?: {
distance?: number;
}): 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?: Util.PointSelectorConfig): Util.PointSelectorPointSelector(const five: Fivefive)
// 连续选点
const selector: Util.PointSelectorselector.Subscribe<EventMap>.on<"select">(name: "select", callback: (intersection?: Util.PointIntersection | null | undefined) => void, once?: boolean): () => void注册事件
on('select', (intersection: Util.PointIntersection | null | undefinedintersection) => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('Selected point:', intersection: Util.PointIntersection | null | undefinedintersection?.Intersection.point: THREE.Vector3 | undefined焦点坐标
point)
})
// 选点后自动结束
const selector: Util.PointSelectorselector.Subscribe<EventMap>.on<"select">(name: "select", callback: (intersection?: Util.PointIntersection | null | undefined) => void, once?: boolean): () => void注册事件
on('select', (intersection: Util.PointIntersection | null | undefinedintersection) => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('Selected point:', intersection: Util.PointIntersection | null | undefinedintersection?.Intersection.point: THREE.Vector3 | undefined焦点坐标
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<PointStyle & PointData>) => 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<LineMeshStyle & LineData>) => 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<PolygonStyle & PolygonData>) => 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>) => 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<CircleWithEdgeMeshStyle & CircleData>) => 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>) => 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 & PrismStyle & {
five?: Five;
}>) => Util.sculpt.BoxMesh
BoxMesh({
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 & PrismStyle & {
five?: Five;
}>) => Util.sculpt.PrismMesh
PrismMesh({
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?: BoxCreateConfig) => Promise<void>createBox } = import UtilUtil.import sculptsculpt
// 创建 boxMesh
const const boxMesh: Util.sculpt.BoxMeshboxMesh = new const BoxMesh: new (params?: Partial<PrismData & PrismStyle & {
five?: Five;
}>) => Util.sculpt.BoxMesh
BoxMesh({ 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?: Util.PointSelectorConfig) => Util.PointSelectorPointSelector(const five: Fivefive)
const createBox: (boxMesh: Util.sculpt.BoxMesh, pointSelector: Util.PointSelector, config?: BoxCreateConfig) => Promise<void>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<void>Attaches callbacks for the resolution and/or rejection of the Promise.
then(() => {
var console: Consoleconsole.Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log('绘制完成')
// 按需启用编辑功能
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;
positionsForRotate?: AnyPosition[];
namespace?: string;
disableOpacityTransition?: boolean;
} | undefined): Util.LightTag
tag(const five: Fivefive, [0, 1, 2])
const tag1: Util.LightTagtag1.LightTag.container: HTMLDivElementcontainer.Element.innerHTML: stringThe innerHTML property of the Element interface gets or sets the HTML or XML markup contained within the element, omitting any shadow roots in both cases.
innerHTML = '<div>tag1</div>'
const const tag2: Util.LightTagtag2 = import UtilUtil.function tag(five: Five, position?: AnyPosition | undefined, config?: {
wrapper?: HTMLElement;
positionsForRotate?: AnyPosition[];
namespace?: string;
disableOpacityTransition?: boolean;
} | undefined): Util.LightTag
tag(const five: Fivefive, [0, 1, 2])
const tag2: Util.LightTagtag2.LightTag.container: HTMLDivElementcontainer.Element.innerHTML: stringThe innerHTML property of the Element interface gets or sets the HTML or XML markup contained within the element, omitting any shadow roots in both cases.
innerHTML = '<div>tag2</div>'或:先初始化,后设置位置
const const tag: Util.LightTagtag = import UtilUtil.function tag(five: Five, position?: AnyPosition | undefined, config?: {
wrapper?: HTMLElement;
positionsForRotate?: AnyPosition[];
namespace?: string;
disableOpacityTransition?: boolean;
} | undefined): Util.LightTag
tag(const five: Fivefive)
const tag: Util.LightTagtag.LightTag.container: HTMLDivElementcontainer.Element.innerHTML: stringThe innerHTML property of the Element interface gets or sets the HTML or XML markup contained within the element, omitting any shadow roots in both cases.
innerHTML = '<div>tag</div>'
const tag: Util.LightTagtag.LightTag.setPosition(position: AnyPosition, positionsForRotate?: AnyPosition[]): voidsetPosition(new import THREETHREE.constructor Vector3(x?: number, y?: number, z?: number): THREE.Vector33D vector.
Vector3(0, 1, 2))