| 
 
| 本帖最后由 tangan 于 2023-8-18 18:30 编辑 
 // 查看浏览器内核和版本号
 navigator.userAgent.includes('Windows')?navigator.userAgent.includes("Win64")?console.warn(`浏览器是64位版本,Chrome内核版本号是:${/Chrome\/(\d+)/g.exec(navigator.appVersion)[1]}`):console.warn(`浏览器是32位版本,Chrome内核版本号是:${/Chrome\/(\d+)/g.exec(navigator.appVersion)[1]}`):console.warn(`运行在${navigator.userAgentData.platform},Chrome内核版本是:${/Chrome\/(\d+)/g.exec(navigator.appVersion)[1]}`)
 
 // 在某些情况下,可能需要检测 localStorage 是否可用
 if (typeof localStorage !== 'undefined') {
 // 在这里可以安全地使用 localStorage
 // 例如:localStorage.setItem('key', 'value');
 console.warn('localStorage 可用')
 } else {
 // 提供备用方案,因为 localStorage 不可用
 console.warn('localStorage 不可用')
 }
 
 下面是ThingJS-X4常用的检查API:
 THINGX.System.Version.version            ThingJS-X版本
 THINGX.System.Version.geo                  地图uearth版本
 THINGX.System.Version.thingjs             thingjs版本
 THING.THEMEVERSION                         效果插件版本
 THINGX.System.Version.marker             标记库版本
 THING.WASM.VERSION                         加密解密模块版本信息
 VideoSurveillanceManager.Version       视频模块版本信息
 THING.INSTANCETOOL_VERSION         批量渲染instance模块版本信息
 THING.Utils.isSupportWebGL()             是否支持WebGL
 
 const app = THING.App.current                        app 是 ThinigJS 的主程序
 const map = CMAP.getCurrentMap()                地图类对象 map => 图层管理器
 
 uinv.disableMods = [];   模块屏蔽
 X4:"业务&图层","操作集","标记","物体面板","场景控制","扩展","皮肤","业务","系统"
 X3:"业务&图层","操作集","标记","物体面板","场景控制","扩展","皮肤","核心"
 
 在线模型预览工具(链接上换模型ID即可预览):查看模型信息
 https://thingdepot.uino.cn/view/ ... 9f0ad9613011886137b
 
 const map = CMAP.getCurrentMap()                获取地球map对象
 map.mapConfig                                                                获取地球配置
 const app = Thing.App.current                        获取场景对象
 const curLevel = app.level.current                获取当前层级
 curLevel.query('xx')                                                从当前层级往下查询
 const o = app.selection.objects[0]                获取选中孪生体
 app.renderState.fps                                                当前层级渲染帧率
 app.renderStates.calls                                        当前层级渲染次数 drawcall数量
 app.lighting.mainLight.shadow                        当前层级光源设置是否开启阴影
 app.renderStates.textures                                当前层级纹理贴图数量,单位:个 (使用ThingJS Debugger可看其消耗内存)
 
 cp = app.root.defaultCampus                                获取场景默认园区
 cp.builder.indexJson                                                模型信息
 cp.builder.sceneJson                                                场景信息:可根据场景信息查看到场景内渲染的孪生体等内容
 cp.node.getMeshes()                                                获取该对象节点下网格对象集合
 
 // 所有节点mesh的效果标签,可根据打的标签查看其使用的效果
 meshArr = cp.node.getMeshes()
 meshArr.map(m=>m._sfStyle)                                获取mesh效果标签
 mats=meshArr[0].getMaterials()                        获取某个mesh的所有材质
 
 const ground = app.query('.Ground')[0]
 ground.node.getFacesNumber()                        获取地面的面数
 
 // 降序排列输出当前层级下所有节点mesh的面数; 比如:1棵树叶用了1万面等
 var table = []
 var curLevel = app.level.current
 curLevel.node.getMeshes().forEach(mesh => {
 var name = mesh.name;
 var facesNum = mesh.getFacesNumber();
 table.push({name,facesNum});
 })
 table = _.orderBy(table,'facesNum','desc') // 降序排列
 console.table(table)
 
 instance
 批处理镜像的样式分类属于Thing(也只能是Thing)
 // 查看模型是否批量渲染
 t = app.query('#temp')[0]   (这里注意,存下来之后就不要选中了,因为选中沟边会影响__batchState)
 t.__batchState                 // running表示正在生效 pause表示暂停了(未生效) ""表示 压根不支持
 t._batchTarget._batchObject    // 获取批量渲染mesh对象
 t._batchTarget._batchObject.name
 
 选择集
 app.selection.objects[0]                                                                        获取当前选中的孪生体集合取第一个
 app.selection.objects                                                                        获取当前选中的孪生体集合
 app.selection.select(digitalTwin,[ digitalTwin])                选中指定的孪生体
 app.selection.deselect(digitalTwin)                                        取消选中孪生体
 app.selection.clear()                                                                        清空选择集
 
 uinv.themeManager.changeEarthEffect('default')                移除地球效果模板
 uinv.themeManager.changeEarthEffect('安德地图')                地球应用'安德地图'效果模板
 uinv.themeManager.changeCampusTheme(null)                                移除园区效果模板
 uinv.themeManager.changeCampusTheme('川陀_默认')                园区应用'川陀_默认'效果模板
 obj._themeKey_                                                                                        获取孪生体对象当前应用的效果模版生效情景
 obj.applyTheme('default')                                                                移除孪生体的效果模板
 obj.applyTheme('川陀_默认')                                                                设置孪生体应用'川陀_默认'效果模板
 app.skyBox                                                                                                        场景天空盒
 app.background                                                                                        背景
 app.lighting                                                                                                灯光
 app.lighting.mainLight.shadow                                                        主光源的阴影设置是否开启
 app.postEffect                                                                                        后期
 环境反射贴图(以建筑外立面为例,假设下面代码中的 obj 为建筑外立面)
 mesh = obj.node.getMeshes();
 envMap = mesh[0].material.envMap.name;
 
 特殊的对象
 地面类型: 获取园区地面
 app.query('.Ground')[0]
 ground = app.query('.Campus')[0].ground
 杂物类型(Misc):提供楼层中杂物的管理能力。杂物指没有设置用户属性的对象
 const misc = floor.misc
 console.log(misc)
 合并物体(CombinedObject)
 模型合并
 场景常用方法
 app.pixelRatio                                                                // 像素比(0~1数值越大,渲染效果越清晰(帧率降低))
 app.captureScreenshot('myScreenshot.jpg')        // 将3D渲染的画面保存成 myScreenshot.jpg图片并 下载至浏览器默认文件下载目录
 app.saveFile('xx.json','text')                                // 第一个参数是文件名称,第二个参数 是文件内容,必须是字符串
 
 包围盒
 o.getOrientedBox()
 o.style.orientedBoundingBox = true
 
 // 输出当前园区地面下的所有mesh包围盒信息
 cp = app.root.defaultCampus
 // cp = app.query('.Campus')[0]
 ground = cp.ground
 meshes = ground.node.getMeshes()
 // meshes.forEach(mesh=>{console.info(mesh.id,mesh.getSelfWorldAABB(),mesh,'全量2')})
 meshes.forEach(mesh=>{
 console.warn(mesh.id,mesh.name,mesh)
 if(mesh.geometry.boundingSphere){
 console.warn(mesh.id,mesh.name,mesh.geometry.boundingSphere.radius,mesh.geometry.boundingSphere.center,mesh,'全量1')
 }else{
 // 有些地面有空mesh对象,需要单独处理排除,不然可能会有异常日志
 console.warn(mesh.id,mesh.name,mesh,'部分')
 }
 })
 
 // 如果发现某个对象的包围不对了,可以尝试遍历孩子,看看是不是孩子里有位置不对的对象或包围盒过大的对象
 obj.children.forEach((child) => {
 const obb = child.orientedBoundingBox
 console.info(child.id, child.name, child.position, obb.size)
 })
 
 // 接口请求
 fetch('http://ip:port/xxx', {
 method: "POST",
 headers: {
 "content-type": "application/json"
 },
 body: JSON.stringify({
 name: 'bocaige',
 age: 18
 })
 }).then(rsp=>rsp.json()).then(res=>{
 console.trace(res,'bocaige')
 })
 
 // 插件开发相关(常用)
 uinv.utils.createCss('.bocaige{ font-size: 24px!important;}','设置指定的类字体大小')    用于设置全局样式
 
 | 
 | 
|  | 
|
|  | 
|  |  |