模型标注插件
ModelMakerPlugin
功能说明
模型标注插件提供了以下功能:
- 提供三维空间中的标注模型,包括区域标注(prism)模型、盒(box)模型和多边形(triangles)模型
效果展示
安装引用
请按需选择 yarn
或 npm
安装方式:
- npm
- Yarn
- pnpm
npm install @realsee/dnalogel
yarn add @realsee/dnalogel
pnpm add @realsee/dnalogel
插件方法
初始化
import { class Five
如视 VR Web展示器
Five } from '@realsee/five'
import { const ModelMakerPlugin: (five: import("@realsee/five").Five, config?: {
tagContainerZIndex?: number;
occlusionVisibility?: boolean | import("@realsee/five").Mode[];
occlusionMode?: "translucence" | "depthTest";
}) => ModelMakerPluginType.ModelMakerController
ModelMakerPlugin } from "@realsee/dnalogel";
const const five: Five
five = new new Five(initArgs?: FiveInitArgs | undefined): Five
如视 VR Web展示器
Five({
FiveInitArgs.plugins?: (((five: Five) => void) | [Plugin: ((five: Five) => any) | ((five: Five, parameters: any) => any), instanceName: string | null] | [Plugin: ((five: Five) => any) | ((five: Five, parameters: any) => any), instanceName: string | null, parameters: any] | [Plugin: (five: Five) => any, instanceName: string | null])[] | undefined
插件定义
plugins: [
[
const ModelMakerPlugin: (five: import("@realsee/five").Five, config?: {
tagContainerZIndex?: number;
occlusionVisibility?: boolean | import("@realsee/five").Mode[];
occlusionMode?: "translucence" | "depthTest";
}) => ModelMakerPluginType.ModelMakerController
ModelMakerPlugin,
'modelMakerPlugin', // 自定义插件名称
]
]
})
const const plugin: any
plugin = const five: Five
five.Five.plugins: {
[key: string]: any;
}
插件暴露的方法
plugins.__type[string]: any
modelMakerPlugin
加载数据
const plugin: Controller
plugin.Controller.load(serverData: ServerData): Promise<void>
加载插件依赖数据
load(const data: ServerData
data)
启用/禁用/显示/隐藏插件
const plugin: Controller
plugin.Controller.enable(): void
启用插件,让插件能够响应交互
enable()
const plugin: Controller
plugin.Controller.disable(): void
禁用插件,让插件停止响应交互
disable()
const plugin: Controller
plugin.Controller.show(): void
展示UI
show()
const plugin: Controller
plugin.Controller.hide(): void
隐藏UI
hide()
销毁插件
const plugin: Controller
plugin.Controller.dispose(): void
插件进行销毁
dispose()
事件监听
const plugin: Controller
plugin.Controller<State, EventMap>.hooks: Subscribe<EventMap>
hooks.Subscribe<EventMap>.on<"show">(name: "show", callback: (event: {
userAction: boolean;
}) => void, once?: boolean | undefined): () => void
注册事件
on('show', () => {
var console: Console
console.Console.log(...data: any[]): void
log('插件展示')
})
const plugin: Controller
plugin.Controller<State, EventMap>.hooks: Subscribe<EventMap>
hooks.Subscribe<EventMap>.on<keyof EventMap>(name: keyof EventMap, callback: (...args: [event: {
userAction: boolean;
}] | [event: {
userAction: boolean;
}] | [event: {
userAction: boolean;
}] | [event: {
userAction: boolean;
}] | [data: ServerData, prevData?: ServerData | undefined] | [data: ...] | [] | [params: ...]) => void, once?: boolean | undefined): () => void
注册事件
on('- show
- hide
- enable
- disable
- dataChange
- dataLoaded
- dispose
- stateChange
')
标注方法
插件中加载的每个标注都是一个item。
获取 item
方式1
const const item: ModelMakerBaseItem
item = const plugin: Controller
plugin.Controller.getItemById(id: string | number): ModelMakerBaseItem
getItemById(1)
方式2
const const item: ModelMakerBaseItem
item = const plugin: Controller
plugin.Controller.items: ModelMakerBaseItem[]
items[0]
启用/禁用/显示/隐藏item
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.enable(): void
enable()
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.disable(): void
disable()
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.show(): void
show()
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.hide(): void
hide()
显示/隐藏 item 模型
// 显示
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.model: Object3D
model.Object3D.visible: boolean
Object gets rendered if true.
visible = true
// 隐藏
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.model: Object3D
model.Object3D.visible: boolean
Object gets rendered if true.
visible = false
显示/隐藏 item 标签
// 显示
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.tag: LightTag
tag?.LightTag.show(params?: {
force?: boolean | undefined;
} | undefined): void
show()
// 隐藏
const item: ModelMakerBaseItem
item.ModelMakerBaseItem.tag: LightTag
tag?.LightTag.hide(): void
hide()
自定义 item 标签样式
// 自定义 box 标签渲染
const plugin: Controller
plugin.Controller.registerTagRenderer(map: Partial<Record<"box" | "triangles" | "prism", ElementRenderer>>): void
registerTagRenderer({ 'box': (container: HTMLElement
container: HTMLElement, item: ModelMakerBaseItem
item: class ModelMakerBaseItem
ModelMakerBaseItem) => {
// 示例
container: HTMLElement
container.InnerHTML.innerHTML: string
innerHTML = item: ModelMakerBaseItem
item.ModelMakerBaseItem.rawData: any
rawData.name
// 支持 React
// ReactDOM.render(<div>{item.rawData.name}</div>, container)
// 返回一个销毁函数
return () => {
container: HTMLElement
container.InnerHTML.innerHTML: string
innerHTML = ''
}
}})
item 事件监听
const item: ModelMakerBaseItem
item.Subscribe<Event>.on<"show">(name: "show", callback: () => void, once?: boolean | undefined): () => void
注册事件
on('show', () => {
var console: Console
console.Console.log(...data: any[]): void
log('item展示')
})
const item: ModelMakerBaseItem
item.Subscribe<Event>.on<keyof Event>(name: keyof Event, callback: (...args: [] | [item: ModelMakerBaseItem]) => boolean | void, once?: boolean | undefined): () => void
注册事件
on('- show
- enable
- disable
- hide
- click
')
数据结构
插件事件类型
export interface EventMap {
/** 插件展示 */
show: () => void
/** 插件隐藏 */
hide: () => void
/** 插件启用 */
enable: () => void
/** 插件禁用 */
disable: () => void
/** 数据加载完成 */
dataLoaded: () => void
/** 插件被销毁 */
dispose: () => void
}
item 事件类型
export interface EventMap {
/** item展示 */
show: () => void
/** item隐藏 */
hide: () => void
/** item启用 */
enable: () => void
/** item禁用 */
disable: () => void
/** item被点击 */
click: () => void
}
load数据
/** load 的数据 */
export interface ServerData {
list: (ServerBoxItem | ServerTrianglesItem | ServerPrismItem)[]
}
export interface ServerBaseItem {
/** 唯一标识 */
id?: number
/** 标签名 */
name?: string
}
export interface ServerBoxItem extends ServerBaseItem {
type: 'box'
object_data: {
/** box 的其中一个顶点坐标 */
start: number[]
/** start 对角位置的顶点坐标 */
end: number[]
/** box 的欧拉角旋转,旋转顺序是 [XYZ] */
rotation?: number[]
/** 标注颜色 */
color?: string
/** 透明度 */
opacity?: number
}
}
export interface ServerTrianglesItem extends ServerBaseItem {
type: 'triangles'
object_data: {
/** 多边形的顶点坐标数组 */
points: number[][]
/** 标注颜色 */
color?: string
/** 透明度 */
opacity?: number
}
}
export interface ServerPrismItem extends ServerBaseItem {
type: 'prism'
object_data: {
/** 绘制平面的三维世界坐标点数组 */
points: number[][]
/** 楼层高度 */
height: number
/** 所在楼层 */
floorIndex?: number
/** 人工设置的y坐标方向偏移 */
fixedY?: number
/** 人工设置的高度修正 */
fixedHeight?: number
/** 标注颜色 */
color?: string
/** 透明度 */
opacity?: number
}
}