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