diff --git a/src/app/babylon/controller/status/main-status.ts b/src/app/babylon/controller/status/main-status.ts index 29d68d8..657d76a 100644 --- a/src/app/babylon/controller/status/main-status.ts +++ b/src/app/babylon/controller/status/main-status.ts @@ -1,10 +1,12 @@ +import { BabylonTool } from "../../tool/babylon-tool"; import { DataManager } from "../data-manager"; import { BuildingStatus } from "./building-status"; import { StatusBase, StatusManager } from "./status-manager"; //主状态 export class MainStatus extends StatusBase { + indexDBInit: boolean;//是否初始化完成IndexDB //初始化 onCreate() { super.onCreate(); @@ -17,12 +19,33 @@ export class MainStatus extends StatusBase { if (DataManager.institutionData == null) { //新建单位信息、开启上传建筑模型的界面 } else { - //已有信息,进入建筑物模式 - StatusManager.enterStatus(BuildingStatus); + let instance = this; + + if (!instance.indexDBInit) { + BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => { + meshes[0].dispose(); + instance.indexDBInit = true; + console.log("IndexDB init success"); + instance.onIndexDBInit(); + }) + } + else { + instance.onIndexDBInit(); + } } } //退出状态 onExit() { super.onExit(); } + + + /** + * 为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成 + * 通过加载一个模型,初始化完成了indexDB数据库 + */ + onIndexDBInit() { + //已有信息,进入建筑物模式 + StatusManager.enterStatus(BuildingStatus); + } } diff --git a/src/app/babylon/tool/babylon-tool.ts b/src/app/babylon/tool/babylon-tool.ts index 406ad6d..1f8aabb 100644 --- a/src/app/babylon/tool/babylon-tool.ts +++ b/src/app/babylon/tool/babylon-tool.ts @@ -130,7 +130,7 @@ export class BabylonTool { path = ObjectsService.getFullPath(path); //根据环境,动态改变桶名 } - // console.log("异步加载模型" + path + sceneFilename); + console.log("异步加载模型" + path + sceneFilename); let modelPath = path + sceneFilename; LoadTool.add(modelPath, tag); diff --git a/src/app/babylon/view/facility-window/facility-window.ts b/src/app/babylon/view/facility-window/facility-window.ts index c19f362..a79732d 100644 --- a/src/app/babylon/view/facility-window/facility-window.ts +++ b/src/app/babylon/view/facility-window/facility-window.ts @@ -14,6 +14,7 @@ import { Image, Rectangle, } from '@babylonjs/gui'; +import { config } from 'rxjs'; import { PlanComponent } from 'src/app/pages/plan/plan.component'; import { ConfigManager } from '../../controller/config-manager'; import { DataManager, ModelChangeType } from '../../controller/data-manager'; @@ -61,7 +62,7 @@ export class FacilityWindow extends UIBase { static readonly c_createIcon_width = 40; createIndex = 0; //临时的创建序号 - indexDBInit: boolean = false; //是否完成了indexDB的初始化 + // indexDBInit: boolean = false; //是否完成了indexDB的初始化 onInit() { FacilityWindow.instance = this; @@ -167,17 +168,18 @@ export class FacilityWindow extends UIBase { let instance = this; //为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成 - if (!instance.indexDBInit) { - BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => { - meshes[0].dispose(); - instance.indexDBInit = true; - instance.updateFacilitieUIItems(facilities); - }) - } - else { - instance.updateFacilitieUIItems(facilities); - } - + // if (!instance.indexDBInit) { + // BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => { + // meshes[0].dispose(); + // instance.indexDBInit = true; + // instance.updateFacilitieUIItems(facilities); + // console.log("加载完IndexDB"); + // }) + // } + // else { + // instance.updateFacilitieUIItems(facilities); + // } + instance.updateFacilitieUIItems(facilities); instance.three = PlanComponent.instance }