Browse Source

排查优化模型加载中断的问题,怀疑还是indexDB问题,再次尝试修复

dev
刘向辉 3 years ago
parent
commit
fd9440985f
  1. 27
      src/app/babylon/controller/status/main-status.ts
  2. 2
      src/app/babylon/tool/babylon-tool.ts
  3. 24
      src/app/babylon/view/facility-window/facility-window.ts

27
src/app/babylon/controller/status/main-status.ts

@ -1,10 +1,12 @@
import { BabylonTool } from "../../tool/babylon-tool";
import { DataManager } from "../data-manager"; import { DataManager } from "../data-manager";
import { BuildingStatus } from "./building-status"; import { BuildingStatus } from "./building-status";
import { StatusBase, StatusManager } from "./status-manager"; import { StatusBase, StatusManager } from "./status-manager";
//主状态 //主状态
export class MainStatus extends StatusBase { export class MainStatus extends StatusBase {
indexDBInit: boolean;//是否初始化完成IndexDB
//初始化 //初始化
onCreate() { onCreate() {
super.onCreate(); super.onCreate();
@ -17,12 +19,33 @@ export class MainStatus extends StatusBase {
if (DataManager.institutionData == null) { if (DataManager.institutionData == null) {
//新建单位信息、开启上传建筑模型的界面 //新建单位信息、开启上传建筑模型的界面
} else { } else {
//已有信息,进入建筑物模式 let instance = this;
StatusManager.enterStatus<BuildingStatus>(BuildingStatus);
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() { onExit() {
super.onExit(); super.onExit();
} }
/**
* indexDB创建冲突indexDB创建完成
* indexDB数据库
*/
onIndexDBInit() {
//已有信息,进入建筑物模式
StatusManager.enterStatus<BuildingStatus>(BuildingStatus);
}
} }

2
src/app/babylon/tool/babylon-tool.ts

@ -130,7 +130,7 @@ export class BabylonTool {
path = ObjectsService.getFullPath(path); //根据环境,动态改变桶名 path = ObjectsService.getFullPath(path); //根据环境,动态改变桶名
} }
// console.log("异步加载模型" + path + sceneFilename); console.log("异步加载模型" + path + sceneFilename);
let modelPath = path + sceneFilename; let modelPath = path + sceneFilename;
LoadTool.add(modelPath, tag); LoadTool.add(modelPath, tag);

24
src/app/babylon/view/facility-window/facility-window.ts

@ -14,6 +14,7 @@ import {
Image, Image,
Rectangle, Rectangle,
} from '@babylonjs/gui'; } from '@babylonjs/gui';
import { config } from 'rxjs';
import { PlanComponent } from 'src/app/pages/plan/plan.component'; import { PlanComponent } from 'src/app/pages/plan/plan.component';
import { ConfigManager } from '../../controller/config-manager'; import { ConfigManager } from '../../controller/config-manager';
import { DataManager, ModelChangeType } from '../../controller/data-manager'; import { DataManager, ModelChangeType } from '../../controller/data-manager';
@ -61,7 +62,7 @@ export class FacilityWindow extends UIBase {
static readonly c_createIcon_width = 40; static readonly c_createIcon_width = 40;
createIndex = 0; //临时的创建序号 createIndex = 0; //临时的创建序号
indexDBInit: boolean = false; //是否完成了indexDB的初始化 // indexDBInit: boolean = false; //是否完成了indexDB的初始化
onInit() { onInit() {
FacilityWindow.instance = this; FacilityWindow.instance = this;
@ -167,17 +168,18 @@ export class FacilityWindow extends UIBase {
let instance = this; let instance = this;
//为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成 //为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成
if (!instance.indexDBInit) { // if (!instance.indexDBInit) {
BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => { // BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => {
meshes[0].dispose(); // meshes[0].dispose();
instance.indexDBInit = true; // instance.indexDBInit = true;
instance.updateFacilitieUIItems(facilities); // instance.updateFacilitieUIItems(facilities);
}) // console.log("加载完IndexDB");
} // })
else { // }
// else {
// instance.updateFacilitieUIItems(facilities);
// }
instance.updateFacilitieUIItems(facilities); instance.updateFacilitieUIItems(facilities);
}
instance.three = PlanComponent.instance instance.three = PlanComponent.instance
} }

Loading…
Cancel
Save