# sbm 模型
# loadSbm
加载 .sbm
文件格式模型。
# 用法:
const baseUrl = './model/edifice'
const sbmsInfo = [
{
id: 'edifice_1F',
name: '1F',
url: `${baseUrl}/edifice_1F.sbm` ,
level: {
max: 1000,
min: null
},
position: { x: 1000, y: 0, z: 1000 },
rotation: { x: 0, y: Math.PI / 2, z: 0 },
scale: { x: 2, y: 2, z: 2 },
onClick(e) {
/**
* 对象的独立事件触发后,默认不传播(类似 DOM 的事件冒泡)到全局事件,
* 调用 eventPropagation 方法通知事件继续传播到全局。
*
* warn:
* 在 **非箭头函数** 中参数 e 与 this 的指向都是当前模型对象,
* 在 *箭头函数** 参数 e 依然是模型对象,但 this 指向会发生改变。
*
* 熟悉 es6 语法的朋友应该很容易理解。
*/
this.eventPropagation()
console.log('model self clickEvent', this)
},
onDblClick: e => {
/**
* 这里模拟在 **箭头函数** 中的场景
*/
e.eventPropagation()
console.log('model self dblClickEvent', e)
}
},
{
id: 'edifice_1F',
id: '2F',
url: `${baseUrl}/edifice_2F.sbm`
},
]
ssp.loadSbm(sbmInfo)
.then(modelList => console.log(modelList))
.catch(err => console.error(err))
# 参数:
# sbmInfo
- 类型: array[object]|object
- 描述: object 包含以下字段
- id string | number
- url string 模型(.sbm)文件 路径
- name string 默认值:null
- level object 显示层级 默认值:{ max: null, min: null }
- max number | null 最大值 默认值:null
- min number | null 最小值 默认值:null
- position object 模型位置坐标 默认值:{ x: 0, y: 0, z: 0 }
- rotation object 模型旋转角度 默认值:{ x: 0, y: 0, z: 0 }
- scale object 模型缩放比例 默认值:{ x: 1, y: 1, z: 1 }
- userData object 用户数据 默认值:{}
- onHover function 鼠标悬浮事件 默认值:null
- onUnHover function 鼠标悬浮后离开事件 默认值:null
- onClick function 左键单击事件 默认值:null
- onDblClick function 左键双击事件 默认值:null
- onRightClick function 右键单击事件 默认值:null
- onLoad function 加载完成事件 默认值:null
# onProgress
- 类型: function
- 描述: 模型加载进度回调函数 - 函数返回一个回调参数显示实时数据
- current object 当前加载中的模型进度相关
- loaded number 已加载的子集数量
- total number 需要加载的子集总数
- timeStamp number 本次加载所用时间(单位ms)
- modelTotal number 本次加载模型总数
- loadingModelIndex number 当前加载中的模型索引
# 返回值:
返回一个 Promise (opens new window) 对象
# getSbmById
通过 id
查找。
# 用法:
ssp.getSbmById('1F')
# 参数:
# id
- 类型: string | number
- 描述: 创建时的 id
# 返回值:
返回一个 sbm 对象。
# getSbmByName
通过 name
查找
# 参数:
# name
- 类型: string
- 描述: 创建时的 name
# 返回值:
返回 sbm 对象集合。
# getSbmByUserDataProperty
通过 userData
属性查找
# 用法:
ssp.getSbmByUserDataProperty('propKey', 'propVal')
// or
ssp.getSbmByUserDataProperty(item => item['itemPropKey'] === 'itemPropVal')
# 参数:
# propKey
- 类型: string | function
- 描述:
userData
内属性名 或find
函数
# propVal
- 类型: any
- 描述:
userData
内属性值。
find 函数使用场景
sbm.userData = {
people: {
name: 'xiaoming',
age: 18
}
}
ssp.getSbmByUserDataProperty(userData => userData?.people?.name === 'xiaoming')
# 返回值:
返回 sbm 对象集合
# removeSbmById
通过 id
移除
# 参数:
# id
- 类型: string | number
- 描述: 创建时的 id
# 返回值:
返回一个 boolean
,表示操作是否成功。
# loadSbmToGroup
加载 sbm
到一个组内。
# 用法:
ssp.loadSbmToGroup(
// groupParam
{
id: 'firstSbmGroup',
name: 'name_firstSbmGroup',
level: {
max: 50000,
min: 20000
}
},
// sbmInfo
sbmsInfo
)
.then(group => console.log(group))
# 参数
# groupParam
- 类型: object
- 描述: groupParam 包含以下字段
- id string | number
- name string | number 默认值:null
- level object 显示层级 默认值:{ max: null, min: null }
- max number | null 最大值 默认值:null
- min number | null 最小值 默认值:null
- userData object 用户数据 默认值:{}
# sbmInfo
- 类型: array[object] | object
- 描述: 同 loadSbm 参数
sbmInfo
# 返回值:
返回一个 Promise (opens new window) 对象
# addSbmForGroup
向一个已经存在的组内添加 sbm
对象。
# 用法:
ssp.addSbmForGroup(
// groupId
'firstSbmGroup',
// sbmInfo
{
id: '8F',
name: '8F',
url: `./yingtaidasha_22F_22.sbm`
}
// or
// [
// {
// id: '8F',
// name: '8F',
// url: `./yingtaidasha_22F_22.sbm`,
// }
// ]
)
.then(group => console.log(group))
# 参数
# groupId
- 类型: string | number
- 描述: 已存在的组 ID
# sbmInfo
- 类型: array[object] | object
- 描述: 同 loadSbm 参数
sbmInfo
# 返回值:
返回一个 Promise (opens new window) 对象
# getSbmGroupById
通过 id
查找组
# 用法:
ssp.getSbmGroupById('firstSbmGroup')
# 参数:
# id
- 类型: string | number
- 描述: 创建时的 id
# 返回值:
返回一个 group 对象
# getSbmGroupByName
通过 name
查找组
# 参数:
# name
- 类型: string
- 描述: 创建时的 name
# 返回值:
返回 group 对象集合
# removeSbmGroupById
通过 id
移除组
# 参数:
# id
- 类型: string | number
- 描述: 创建时的 id
# 返回值:
返回一个 boolean
,表示操作是否成功。
# loadXml
加载一个包含 .sbm
模型集合信息的 .xml
文件,加载后的模型被收集到一个组内管理。
# 用法:
ssp.loadXml(
// groupParam
{
id: 'firstSbmGroup',
name: 'name_firstSbmGroup',
level: {
max: 70000,
min: 30000
}
},
// xmlUrl
xmlUrl
)
.then(modelList => console.log(modelList))
.catch(err => console.error(err))
# 参数:
# groupParam
- 类型: object
- 描述: 同 loadSbmToGroup 的
groupParam
# xmlUrl
- 类型: string
- 描述: xml 文件路径
# 返回值:
返回一个 Promise (opens new window) 对象
# clearSbm
清除当前场景内所有 sbm
对象。
# 用法:
ssp.clearSbm()
没有参数和返回值。
# showAllSbm
显示当前场景内所有 sbm
对象。
# 用法:
ssp.showAllSbm()
没有参数和返回值。
# hideAllSbm
隐藏当前场景内所有 sbm
对象。
# 用法:
ssp.hideAllSbm()
没有参数和返回值。
其他模型 →