From fd9440985fbece6adfe1ef687f11a226d2a084ce Mon Sep 17 00:00:00 2001 From: liuxianghui <519646741@qq.com> Date: Fri, 7 Jan 2022 14:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E6=9F=A5=E4=BC=98=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=8A=A0=E8=BD=BD=E4=B8=AD=E6=96=AD=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=80=80=E7=96=91=E8=BF=98=E6=98=AFindexDB?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=86=8D=E6=AC=A1=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../babylon/controller/status/main-status.ts | 27 +++++++++++++++++-- src/app/babylon/tool/babylon-tool.ts | 2 +- .../view/facility-window/facility-window.ts | 26 +++++++++--------- 3 files changed, 40 insertions(+), 15 deletions(-) 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 }