Browse Source

优化重复进入同一场景, 不再需要重新加载

dev
刘向辉 3 years ago
parent
commit
5ff6fc6c22
  1. 26
      src/app/babylon/controller/data-manager.ts
  2. 28
      src/app/babylon/controller/status/building-status.ts
  3. 11
      src/app/babylon/controller/status/login-status.ts
  4. 65
      src/app/babylon/game.ts
  5. 2
      src/app/babylon/tool/load-tool.ts
  6. 19
      src/app/babylon/view/building-window/building-window.ts
  7. 27
      src/app/babylon/view/facility-window/facility-window.ts
  8. 2
      src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts
  9. 2
      src/app/pages/left-domain/left-domain.component.ts
  10. 12
      src/app/pages/plan/plan.component.ts

26
src/app/babylon/controller/data-manager.ts

@ -34,7 +34,6 @@ import {
} from '../model/data/model-data/model-data'; } from '../model/data/model-data/model-data';
import { ModelData_building } from '../model/data/model-data/model-data-building'; import { ModelData_building } from '../model/data/model-data/model-data-building';
import { import {
FacilityPosType,
FacilityType FacilityType
} from '../model/data/model-data/model-data-facility'; } from '../model/data/model-data/model-data-facility';
import { ModelEditData } from '../model/data/model-data/model-edit-data'; import { ModelEditData } from '../model/data/model-data/model-edit-data';
@ -75,10 +74,27 @@ export class DataManager {
if (dataFromServe) { if (dataFromServe) {
if (DataManager.institutionData != null) {
//同一单位
console.log("=======", DataManager.institutionData.normalData.key, institutionID.toString());
if (DataManager.institutionData.normalData.key == institutionID.toString()) {
console.log("同一单位");
if (onSuccess) {
onSuccess(institutionID.toString());
}
return;
}
else //不同单位,释放原有单位
{
}
}
ServeManager.instance.getInstitutionData(institutionID, (key, result) => { ServeManager.instance.getInstitutionData(institutionID, (key, result) => {
if (onSuccess) { if (onSuccess) {
DataManager.institutionData = plainToClass(InstitutionData, result); DataManager.institutionData = plainToClass(InstitutionData, result);
DataManager.institutionData.normalData.name = DataManager.institutionData_simple.name; DataManager.institutionData.normalData.name = DataManager.institutionData_simple.name;
DataManager.institutionData.normalData.key = DataManager.institutionData_simple.key;
// console.log(DataManager.institutionData); // console.log(DataManager.institutionData);
onSuccess(key); onSuccess(key);
} }
@ -91,11 +107,11 @@ export class DataManager {
console.error("获取单位信息失败,本地捏造数据"); console.error("获取单位信息失败,本地捏造数据");
PlanComponent.instance.openSnackBar("获取单位失败,请刷新重试"); PlanComponent.instance.openSnackBar("获取单位失败,请刷新重试");
// DataManager.initDebugData_institution();
// if (onSuccess) {
// onSuccess(key);
// }
}); });
} }
else { else {
//本地捏造测试数据 //本地捏造测试数据

28
src/app/babylon/controller/status/building-status.ts

@ -1,5 +1,6 @@
import { Observable, Observer } from "@babylonjs/core"; import { Observable, Observer } from "@babylonjs/core";
import { PlanComponent } from "src/app/pages/plan/plan.component";
import { Game } from "../../game"; import { Game } from "../../game";
import { BuildingType, BuildingData } from "../../model/data/institution/building/building-data"; import { BuildingType, BuildingData } from "../../model/data/institution/building/building-data";
import { FacilityPosType, ModelData_facility } from "../../model/data/model-data/model-data-facility"; import { FacilityPosType, ModelData_facility } from "../../model/data/model-data/model-data-facility";
@ -59,7 +60,7 @@ export class BuildingStatus extends StatusBase {
onEnter() { onEnter() {
super.onEnter(); super.onEnter();
Game.instance.engine.resize(); Game.instance.engine.resize();
this.buildingWindow = BuildingWindow.instance;
//首次进入 //首次进入
if (this.buildingWindow == null) { if (this.buildingWindow == null) {
SceneManager.s_facilityWindow = UIManager.open<FacilityWindow>(FacilityWindow); SceneManager.s_facilityWindow = UIManager.open<FacilityWindow>(FacilityWindow);
@ -76,19 +77,19 @@ export class BuildingStatus extends StatusBase {
else { //从室内返回 else { //从室内返回
UIManager.show<BuildingWindow>(this.buildingWindow); UIManager.show<BuildingWindow>(this.buildingWindow);
if (this.buildingWindow.currentBuidngItem != null) { if (this.buildingWindow.currentBuidngItem != null) {
this.buildingWindow.currentBuidngItem.select(); PlanComponent.instance.selectLeftBuilding(this.buildingWindow.currentBuidngItem);
BuildingStatus.startEnterObservable.notifyObservers(this.buildingWindow.currentBuidngItem); BuildingStatus.startEnterObservable.notifyObservers(this.buildingWindow.currentBuidngItem);
BuildingStatus.enterSuccessObservable.notifyObservers(this.buildingWindow.currentBuidngItem) BuildingStatus.enterSuccessObservable.notifyObservers(this.buildingWindow.currentBuidngItem)
if (MarkWindow.s_cameraData == null) { // if (MarkWindow.s_cameraData == null) {
this.buildingWindow.currentBuidngItem.lookAt(); // this.buildingWindow.currentBuidngItem.lookAt();
} // }
else { // else {
MarkWindow.s_cameraData.setDataToCamera(SceneManager.Instance.defaultCamera); // MarkWindow.s_cameraData.setDataToCamera(SceneManager.Instance.defaultCamera);
MarkWindow.s_cameraData = null; // MarkWindow.s_cameraData = null;
} // }
FacilityInfoInSceneWindow.instance.createAllFacilities(this.buildingWindow.currentBuidngItem.buildingInfo.ModelInfo.facilityInfos); //FacilityInfoInSceneWindow.instance.createAllFacilities(this.buildingWindow.currentBuidngItem.buildingInfo.ModelInfo.facilityInfos);
if (ModeManager.currentMode == ModeType.Look) { if (ModeManager.currentMode == ModeType.Look) {
FacilityInfoInSceneWindow.instance.showFacilityByType(null, false); FacilityInfoInSceneWindow.instance.showFacilityByType(null, false);
} }
@ -117,9 +118,9 @@ export class BuildingStatus extends StatusBase {
//改变当前选中的建筑 //改变当前选中的建筑
changeCurrentBuilding(buildingInfo: BuildingInfo) { changeCurrentBuilding(buildingInfo: BuildingInfo) {
if (buildingInfo == this.currentBuildingInfo) { // if (buildingInfo == this.currentBuildingInfo) {
return; // return;
} // }
// console.log("改变当前建筑" + buildingInfo.buildingData.normalData.key); // console.log("改变当前建筑" + buildingInfo.buildingData.normalData.key);
//FacilityInfoInSceneWindow.instance.clearFacilityInfoUIItemes(); //FacilityInfoInSceneWindow.instance.clearFacilityInfoUIItemes();
@ -165,4 +166,5 @@ export class BuildingStatus extends StatusBase {
} }
} }
} }
} }

11
src/app/babylon/controller/status/login-status.ts

@ -6,6 +6,7 @@ import { plainToClass } from "class-transformer";
import { InstitutionData, NormalData } from "../../model/data/institution/institution-data"; import { InstitutionData, NormalData } from "../../model/data/institution/institution-data";
import { InsitutionDataSimple } from "../../model/data/institution/institution-data-simple"; import { InsitutionDataSimple } from "../../model/data/institution/institution-data-simple";
import { BabylonTool } from "../../tool/babylon-tool"; import { BabylonTool } from "../../tool/babylon-tool";
import { BuildingWindow } from "../../view/building-window/building-window";
import { InstitutionCreateWindow } from "../../view/institution/institution-create-window"; import { InstitutionCreateWindow } from "../../view/institution/institution-create-window";
import { InstitutionSelectWindow } from "../../view/institution/institution-select-window"; import { InstitutionSelectWindow } from "../../view/institution/institution-select-window";
import { TopbarWindow } from "../../view/topbar-window/topbar-window"; import { TopbarWindow } from "../../view/topbar-window/topbar-window";
@ -99,6 +100,16 @@ export class LoginSatus extends StatusBase {
* @param simpleData * @param simpleData
*/ */
onSelectInsSuccess(simpleData: InsitutionDataSimple) { onSelectInsSuccess(simpleData: InsitutionDataSimple) {
if (DataManager.institutionData != null) {
//不同单位,释放建筑
console.log("=======", DataManager.institutionData.normalData.key, simpleData.key.toString());
if (DataManager.institutionData.normalData.key != simpleData.key) {
BuildingWindow.instance.dispose();
}
}
let status: LoginSatus = StatusManager.getStatus<LoginSatus>(LoginSatus); let status: LoginSatus = StatusManager.getStatus<LoginSatus>(LoginSatus);
if (status.institutionSelectWindow != null) { if (status.institutionSelectWindow != null) {
UIManager.close(status.institutionSelectWindow); UIManager.close(status.institutionSelectWindow);

65
src/app/babylon/game.ts

@ -11,6 +11,8 @@ export class Game {
public engine: Engine; public engine: Engine;
public scene: Scene; public scene: Scene;
private isRender: boolean = true;//是否更新渲染
static instance: Game; static instance: Game;
//初始化引擎和画布 //初始化引擎和画布
@ -18,7 +20,24 @@ export class Game {
// FileTools.DefaultRetryStrategy = MyRetryStrategy.ExponentialBackoff(2, 1000); // FileTools.DefaultRetryStrategy = MyRetryStrategy.ExponentialBackoff(2, 1000);
// FileTools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff(2, 1000); // FileTools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff(2, 1000);
if (Game.instance != null) {
// canvas.setAttribute("touch-action", "none");
// canvas.style.touchAction = "none";
// canvas.tabIndex = 1;
this.startRender();
this.scene.detachControl();
let view = this.engine.registerView(canvas, SceneManager.Instance.defaultCamera);
this.canvas = canvas;
this.engine.inputElement = canvas;
this.scene.attachControl();
this.canvas.addEventListener('contextmenu', function (e) {
e.preventDefault();
})
SceneManager.Instance.defaultCamera.attachControl(canvas, true);
}
else {
this.startRender();
Game.instance = this; Game.instance = this;
this.canvas = canvas; this.canvas = canvas;
this.engine = new Engine(canvas, null, { stencil: true }); this.engine = new Engine(canvas, null, { stencil: true });
@ -26,27 +45,38 @@ export class Game {
this.scene = new Scene(this.engine); this.scene = new Scene(this.engine);
this.scene.useRightHandedSystem = true;//使用右手坐标系 this.scene.useRightHandedSystem = true;//使用右手坐标系
RenderingManager.MIN_RENDERINGGROUPS = -1;//最小渲染序列 RenderingManager.MIN_RENDERINGGROUPS = -1;//最小渲染序列
// Engine.DefaultLoadingScreenFactory() //尝试更改canvas
this.createScene(); this.createScene();
let scene = this.scene;
// canvas.translate = true; //用于设置背景透明
// scene.autoClear = true;
UIManager.Instance.init(); UIManager.Instance.init();
let scene = this.scene;
StatusManager.enterStatus<LoginSatus>(LoginSatus);
//最后,将场景渲染出来 (重要,不可缺少) //最后,将场景渲染出来 (重要,不可缺少)
this.engine.runRenderLoop(function () { this.engine.runRenderLoop(function () {
if (Game.instance != null && Game.instance.isRender) {
scene.render(); scene.render();
}
}) })
// 监听浏览器改变大小的事件,通过调用engine.resize()来自适应窗口大小 // 监听浏览器改变大小的事件,通过调用engine.resize()来自适应窗口大小
window.addEventListener("resize", function () { window.addEventListener("resize", function () {
if (Game.instance != null) { if (Game.instance != null && Game.instance.isRender) {
Game.instance.engine.resize(); Game.instance.engine.resize();
UIManager.Instance.uiRoot.renderScale = 0.99;
setTimeout(() => {
UIManager.Instance.uiRoot.renderScale = 1;
}, 10);
} }
}); });
}
StatusManager.enterStatus<LoginSatus>(LoginSatus);
// canvas.translate = true; //用于设置背景透明
// scene.autoClear = true;
} }
@ -66,8 +96,25 @@ export class Game {
this.scene = null; this.scene = null;
this.engine.dispose(); this.engine.dispose();
this.engine = null; this.engine = null;
}
/**
*
*/
pauseRender() {
this.engine.unRegisterView(this.canvas);
this.isRender = false;
}
/**
*
*/
startRender() {
this.isRender = true;
} }
} }
// /** // /**

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

@ -51,7 +51,6 @@ export class LoadTool {
* *
*/ */
static onStart() { static onStart() {
// console.log("开始加载");
PlanComponent.instance.showLoading(true); PlanComponent.instance.showLoading(true);
Event_LoadingChange.dispatch(true); Event_LoadingChange.dispatch(true);
} }
@ -60,7 +59,6 @@ export class LoadTool {
* *
*/ */
static onEnd() { static onEnd() {
// console.log("结束加载");
PlanComponent.instance.showLoading(false); PlanComponent.instance.showLoading(false);
Event_LoadingChange.dispatch(false); Event_LoadingChange.dispatch(false);
} }

19
src/app/babylon/view/building-window/building-window.ts

@ -1,5 +1,5 @@
import { AbstractMesh, Material, Mesh, PBRMaterial, Texture, Animatable } from "@babylonjs/core"; import { AbstractMesh, Material, PBRMaterial, Texture, Animatable } from "@babylonjs/core";
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 } from "../../controller/data-manager"; import { DataManager } from "../../controller/data-manager";
@ -25,7 +25,6 @@ import { ModelInfo_building } from "../../model/info/model/model-info-building";
import { FacilityInfoByType, ModelInfo_facility } from "../../model/info/model/model-info-facility"; import { FacilityInfoByType, ModelInfo_facility } from "../../model/info/model/model-info-facility";
import { BabylonTool } from "../../tool/babylon-tool"; import { BabylonTool } from "../../tool/babylon-tool";
import { GizmoTool } from "../../tool/gizmo-tool"; import { GizmoTool } from "../../tool/gizmo-tool";
import { LoadTool } from "../../tool/load-tool";
import { TsTool } from "../../tool/ts-tool"; import { TsTool } from "../../tool/ts-tool";
import { FacilityInfoInSceneWindow } from "../facilityinfoinscene-window/facilityinfoinscene-window"; import { FacilityInfoInSceneWindow } from "../facilityinfoinscene-window/facilityinfoinscene-window";
import { MarkWindow } from "../mark-window/mark-window"; import { MarkWindow } from "../mark-window/mark-window";
@ -329,6 +328,8 @@ export class BuildingWindow extends UIBase {
} }
onShow() { onShow() {
this.three = PlanComponent.instance;
this.three.buildingUIItems = this.buildingUIItems
this.showModel(true); this.showModel(true);
super.onShow(); super.onShow();
@ -343,6 +344,7 @@ export class BuildingWindow extends UIBase {
} }
/** /**
* loading状态改变时 * loading状态改变时
* @param eventInfo * @param eventInfo
@ -362,11 +364,24 @@ export class BuildingWindow extends UIBase {
} }
} }
/**
*
*/
dispose() {
for (let i = 0; i < this.buildingUIItems.length; i++) {
this.buildingUIItems[i].dispose();
}
BuildingWindow.instance = null;
}
//#endregion //#endregion
//#region 外部公有 //#region 外部公有
/** /**
* *
* @param buildingInfo * @param buildingInfo

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

@ -61,6 +61,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的初始化
onInit() { onInit() {
FacilityWindow.instance = this; FacilityWindow.instance = this;
@ -166,8 +167,26 @@ export class FacilityWindow extends UIBase {
let instance = this; let instance = this;
//为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成 //为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成
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.updateFacilitieUIItems(facilities);
})
}
else {
instance.updateFacilitieUIItems(facilities);
}
instance.three = PlanComponent.instance
}
/**
* Item
* @param facilities
*/
updateFacilitieUIItems(facilities: ModelData_facility[]) {
for (let i = 0; i < facilities.length; i++) { for (let i = 0; i < facilities.length; i++) {
let facilityUIItem: FacilityUIItem = new FacilityUIItem( let facilityUIItem: FacilityUIItem = new FacilityUIItem(
@ -176,14 +195,10 @@ export class FacilityWindow extends UIBase {
null null
); );
instance.allFacilityUIItemes.push(facilityUIItem); FacilityWindow.instance.allFacilityUIItemes.push(facilityUIItem);
} }
// console.log("所有可用的设备", instance.allFacilityUIItemes); // console.log("所有可用的设备", instance.allFacilityUIItemes);
PlanComponent.instance.getAllIcons(instance) PlanComponent.instance.getAllIcons(FacilityWindow.instance)
})
instance.three = PlanComponent.instance
} }
//清空可用设施列表 //清空可用设施列表

2
src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts

@ -586,7 +586,7 @@ export class FacilityInfoInSceneWindow extends UIBase {
} }
} }
this.three = PlanComponent.instance;
//通知ui更新 //通知ui更新
//this.three.getAllCensusList(this.facilityInfoUIItemes || []); //this.three.getAllCensusList(this.facilityInfoUIItemes || []);

2
src/app/pages/left-domain/left-domain.component.ts

@ -83,6 +83,7 @@ export class LeftDomainComponent implements OnInit {
item.getType() === "JY_YQHSGX" ? list.push(item) : null item.getType() === "JY_YQHSGX" ? list.push(item) : null
} }
}) })
console.log("所有设备", list);
this.FacilityList = list this.FacilityList = list
this.selectFacilityId = null this.selectFacilityId = null
if (this.beforeFence === 3) { //消防设施 if (this.beforeFence === 3) { //消防设施
@ -127,6 +128,7 @@ export class LeftDomainComponent implements OnInit {
} }
PlanComponent.instance.isShowLoading = true //打开遮罩 PlanComponent.instance.isShowLoading = true //打开遮罩
let institutionKey = `${PlanComponent.instance.companyData.id}` || "ceshi"; //单位id let institutionKey = `${PlanComponent.instance.companyData.id}` || "ceshi"; //单位id
console.log(PlanComponent.instance.buildingUIItems, PlanComponent.instance.beforeOneBuildingID);
let buildingKey = PlanComponent.instance.buildingUIItems.find(item => { return item.getBuildingID() == PlanComponent.instance.beforeOneBuildingID }) let buildingKey = PlanComponent.instance.buildingUIItems.find(item => { return item.getBuildingID() == PlanComponent.instance.beforeOneBuildingID })
let url = DataManager.getResPath_facilityProperty(institutionKey, buildingKey.getBuildingID(), item.getType(), item.getID(), null) let url = DataManager.getResPath_facilityProperty(institutionKey, buildingKey.getBuildingID(), item.getType(), item.getID(), null)
ServeManager.instance.openFileSelect(file, url, (name: string, path: string) => { //上传 ServeManager.instance.openFileSelect(file, url, (name: string, path: string) => { //上传

12
src/app/pages/plan/plan.component.ts

@ -47,13 +47,13 @@ export class PlanComponent implements OnInit {
static instance: PlanComponent; static instance: PlanComponent;
public game: Game = new Game(); public game: Game;
public beforeOneSatus; //当前 satus public beforeOneSatus; //当前 satus
public canvas: HTMLCanvasElement; //canvas 实例 public canvas: HTMLCanvasElement; //canvas 实例
public editMode: boolean = true; //编辑/查看 模式 public editMode: boolean = true; //编辑/查看 模式
public userMode: boolean = ModeManager.s_isMakeMode; //是否为 内部权限 public userMode: boolean = ModeManager.s_isMakeMode; //是否为 内部权限
public bucketName: string = ObjectsService.getFullPath("文件路径"); //当前桶名 public bucketName: string = ObjectsService.getFullPath("文件路径"); //当前桶名
public isShowLoading: boolean = true; //显隐 loading加载条 public isShowLoading: boolean = false; //显隐 loading加载条
public companyData: any; //当前加油站所属组织机构 data public companyData: any; //当前加油站所属组织机构 data
private readonly c_frameSpace = 16;//更新的帧间隔, 16大概是60帧每秒 private readonly c_frameSpace = 16;//更新的帧间隔, 16大概是60帧每秒
@ -63,6 +63,12 @@ export class PlanComponent implements OnInit {
PlanComponent.instance = this; PlanComponent.instance = this;
ServeManager.Init(this.buildingBISrv, this.objectsSrv); ServeManager.Init(this.buildingBISrv, this.objectsSrv);
this.canvas = this.element.nativeElement.querySelector('#center') as HTMLCanvasElement; this.canvas = this.element.nativeElement.querySelector('#center') as HTMLCanvasElement;
if (Game.instance == null) {
this.game = new Game();
}
else {
this.game = Game.instance;
}
this.game.init(this.canvas); this.game.init(this.canvas);
this.companyData = (JSON.parse(sessionStorage.getItem('userdataOfgasstation'))).organization || {} this.companyData = (JSON.parse(sessionStorage.getItem('userdataOfgasstation'))).organization || {}
let editMode = sessionStorage.getItem('isGasStation') let editMode = sessionStorage.getItem('isGasStation')
@ -148,7 +154,7 @@ export class PlanComponent implements OnInit {
} }
ngOnDestroy(): void { //组件销毁前 销毁canvas ngOnDestroy(): void { //组件销毁前 销毁canvas
this.game.dispose(); this.game.pauseRender();
this.game = null; this.game = null;
} }

Loading…
Cancel
Save