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. 21
      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. 22
      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';
import { ModelData_building } from '../model/data/model-data/model-data-building';
import {
FacilityPosType,
FacilityType
} from '../model/data/model-data/model-data-facility';
import { ModelEditData } from '../model/data/model-data/model-edit-data';
@ -75,10 +74,27 @@ export class DataManager {
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) => {
if (onSuccess) {
DataManager.institutionData = plainToClass(InstitutionData, result);
DataManager.institutionData.normalData.name = DataManager.institutionData_simple.name;
DataManager.institutionData.normalData.key = DataManager.institutionData_simple.key;
// console.log(DataManager.institutionData);
onSuccess(key);
}
@ -91,11 +107,11 @@ export class DataManager {
console.error("获取单位信息失败,本地捏造数据");
PlanComponent.instance.openSnackBar("获取单位失败,请刷新重试");
// DataManager.initDebugData_institution();
// if (onSuccess) {
// onSuccess(key);
// }
});
}
else {
//本地捏造测试数据

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

@ -1,5 +1,6 @@
import { Observable, Observer } from "@babylonjs/core";
import { PlanComponent } from "src/app/pages/plan/plan.component";
import { Game } from "../../game";
import { BuildingType, BuildingData } from "../../model/data/institution/building/building-data";
import { FacilityPosType, ModelData_facility } from "../../model/data/model-data/model-data-facility";
@ -59,7 +60,7 @@ export class BuildingStatus extends StatusBase {
onEnter() {
super.onEnter();
Game.instance.engine.resize();
this.buildingWindow = BuildingWindow.instance;
//首次进入
if (this.buildingWindow == null) {
SceneManager.s_facilityWindow = UIManager.open<FacilityWindow>(FacilityWindow);
@ -76,19 +77,19 @@ export class BuildingStatus extends StatusBase {
else { //从室内返回
UIManager.show<BuildingWindow>(this.buildingWindow);
if (this.buildingWindow.currentBuidngItem != null) {
this.buildingWindow.currentBuidngItem.select();
PlanComponent.instance.selectLeftBuilding(this.buildingWindow.currentBuidngItem);
BuildingStatus.startEnterObservable.notifyObservers(this.buildingWindow.currentBuidngItem);
BuildingStatus.enterSuccessObservable.notifyObservers(this.buildingWindow.currentBuidngItem)
if (MarkWindow.s_cameraData == null) {
this.buildingWindow.currentBuidngItem.lookAt();
}
else {
// if (MarkWindow.s_cameraData == null) {
// this.buildingWindow.currentBuidngItem.lookAt();
// }
// else {
MarkWindow.s_cameraData.setDataToCamera(SceneManager.Instance.defaultCamera);
MarkWindow.s_cameraData = null;
}
// MarkWindow.s_cameraData.setDataToCamera(SceneManager.Instance.defaultCamera);
// 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) {
FacilityInfoInSceneWindow.instance.showFacilityByType(null, false);
}
@ -117,9 +118,9 @@ export class BuildingStatus extends StatusBase {
//改变当前选中的建筑
changeCurrentBuilding(buildingInfo: BuildingInfo) {
if (buildingInfo == this.currentBuildingInfo) {
return;
}
// if (buildingInfo == this.currentBuildingInfo) {
// return;
// }
// console.log("改变当前建筑" + buildingInfo.buildingData.normalData.key);
//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 { InsitutionDataSimple } from "../../model/data/institution/institution-data-simple";
import { BabylonTool } from "../../tool/babylon-tool";
import { BuildingWindow } from "../../view/building-window/building-window";
import { InstitutionCreateWindow } from "../../view/institution/institution-create-window";
import { InstitutionSelectWindow } from "../../view/institution/institution-select-window";
import { TopbarWindow } from "../../view/topbar-window/topbar-window";
@ -99,6 +100,16 @@ export class LoginSatus extends StatusBase {
* @param simpleData
*/
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);
if (status.institutionSelectWindow != null) {
UIManager.close(status.institutionSelectWindow);

65
src/app/babylon/game.ts

@ -11,6 +11,8 @@ export class Game {
public engine: Engine;
public scene: Scene;
private isRender: boolean = true;//是否更新渲染
static instance: Game;
//初始化引擎和画布
@ -18,7 +20,24 @@ export class Game {
// FileTools.DefaultRetryStrategy = MyRetryStrategy.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;
this.canvas = canvas;
this.engine = new Engine(canvas, null, { stencil: true });
@ -26,27 +45,38 @@ export class Game {
this.scene = new Scene(this.engine);
this.scene.useRightHandedSystem = true;//使用右手坐标系
RenderingManager.MIN_RENDERINGGROUPS = -1;//最小渲染序列
// Engine.DefaultLoadingScreenFactory() //尝试更改canvas
this.createScene();
let scene = this.scene;
// canvas.translate = true; //用于设置背景透明
// scene.autoClear = true;
UIManager.Instance.init();
StatusManager.enterStatus<LoginSatus>(LoginSatus);
let scene = this.scene;
//最后,将场景渲染出来 (重要,不可缺少)
this.engine.runRenderLoop(function () {
if (Game.instance != null && Game.instance.isRender) {
scene.render();
}
})
// 监听浏览器改变大小的事件,通过调用engine.resize()来自适应窗口大小
window.addEventListener("resize", function () {
if (Game.instance != null) {
if (Game.instance != null && Game.instance.isRender) {
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.engine.dispose();
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() {
// console.log("开始加载");
PlanComponent.instance.showLoading(true);
Event_LoadingChange.dispatch(true);
}
@ -60,7 +59,6 @@ export class LoadTool {
*
*/
static onEnd() {
// console.log("结束加载");
PlanComponent.instance.showLoading(false);
Event_LoadingChange.dispatch(false);
}

21
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 { ConfigManager } from "../../controller/config-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 { BabylonTool } from "../../tool/babylon-tool";
import { GizmoTool } from "../../tool/gizmo-tool";
import { LoadTool } from "../../tool/load-tool";
import { TsTool } from "../../tool/ts-tool";
import { FacilityInfoInSceneWindow } from "../facilityinfoinscene-window/facilityinfoinscene-window";
import { MarkWindow } from "../mark-window/mark-window";
@ -329,6 +328,8 @@ export class BuildingWindow extends UIBase {
}
onShow() {
this.three = PlanComponent.instance;
this.three.buildingUIItems = this.buildingUIItems
this.showModel(true);
super.onShow();
@ -343,6 +344,7 @@ export class BuildingWindow extends UIBase {
}
/**
* loading状态改变时
* @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
//#region 外部公有
/**
*
* @param buildingInfo
@ -415,7 +430,7 @@ export class BuildingWindow extends UIBase {
//this.onChangeCurrentBuildingItem(item);
// this.three.selectLeftBuilding(item);
//this.three.selectLeftBuilding(item);
}

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;
createIndex = 0; //临时的创建序号
indexDBInit: boolean = false; //是否完成了indexDB的初始化
onInit() {
FacilityWindow.instance = this;
@ -166,8 +167,26 @@ 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);
}
instance.three = PlanComponent.instance
}
/**
* Item
* @param facilities
*/
updateFacilitieUIItems(facilities: ModelData_facility[]) {
for (let i = 0; i < facilities.length; i++) {
let facilityUIItem: FacilityUIItem = new FacilityUIItem(
@ -176,14 +195,10 @@ export class FacilityWindow extends UIBase {
null
);
instance.allFacilityUIItemes.push(facilityUIItem);
FacilityWindow.instance.allFacilityUIItemes.push(facilityUIItem);
}
// console.log("所有可用的设备", instance.allFacilityUIItemes);
PlanComponent.instance.getAllIcons(instance)
})
instance.three = PlanComponent.instance
PlanComponent.instance.getAllIcons(FacilityWindow.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更新
//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
}
})
console.log("所有设备", list);
this.FacilityList = list
this.selectFacilityId = null
if (this.beforeFence === 3) { //消防设施
@ -127,6 +128,7 @@ export class LeftDomainComponent implements OnInit {
}
PlanComponent.instance.isShowLoading = true //打开遮罩
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 url = DataManager.getResPath_facilityProperty(institutionKey, buildingKey.getBuildingID(), item.getType(), item.getID(), null)
ServeManager.instance.openFileSelect(file, url, (name: string, path: string) => { //上传

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

@ -47,13 +47,13 @@ export class PlanComponent implements OnInit {
static instance: PlanComponent;
public game: Game = new Game();
public game: Game;
public beforeOneSatus; //当前 satus
public canvas: HTMLCanvasElement; //canvas 实例
public editMode: boolean = true; //编辑/查看 模式
public userMode: boolean = ModeManager.s_isMakeMode; //是否为 内部权限
public bucketName: string = ObjectsService.getFullPath("文件路径"); //当前桶名
public isShowLoading: boolean = true; //显隐 loading加载条
public isShowLoading: boolean = false; //显隐 loading加载条
public companyData: any; //当前加油站所属组织机构 data
private readonly c_frameSpace = 16;//更新的帧间隔, 16大概是60帧每秒
@ -63,6 +63,12 @@ export class PlanComponent implements OnInit {
PlanComponent.instance = this;
ServeManager.Init(this.buildingBISrv, this.objectsSrv);
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.companyData = (JSON.parse(sessionStorage.getItem('userdataOfgasstation'))).organization || {}
let editMode = sessionStorage.getItem('isGasStation')
@ -148,7 +154,7 @@ export class PlanComponent implements OnInit {
}
ngOnDestroy(): void { //组件销毁前 销毁canvas
this.game.dispose();
this.game.pauseRender();
this.game = null;
}
@ -403,7 +409,7 @@ export class PlanComponent implements OnInit {
//选中 设备
selectProperty(e: FacilityInfoUIItem) {
this.propertyImg? this.propertyImg.destroy() : null
this.propertyImg ? this.propertyImg.destroy() : null
this.isShowNature = true
this.beforeOnePropertyData = e
if (this.selectFence === 1 || this.selectFence === 2) { //刷新弹窗 位置
@ -433,7 +439,7 @@ export class PlanComponent implements OnInit {
return
}
if (this.beforeOnePropertyData.getPropertyData().is360) { //全景模式 销毁 Viewer
this.propertyImg? this.propertyImg.destroy() : null
this.propertyImg ? this.propertyImg.destroy() : null
} else { //非全景模式 初始化 Viewer
window.setTimeout(() => {
this.propertyImg = new Viewer(this.element.nativeElement.querySelector('#propertyImg'), { url: 'data-original', navbar: false });
@ -446,15 +452,15 @@ export class PlanComponent implements OnInit {
if (this.beforeOnePropertyData.getPropertyData().img && this.beforeOnePropertyData.getPropertyData().is360) { //全景模式 打开canvas弹窗
this.videoDialogType.isVideo = false
this.videoDialogType.url = this.beforeOnePropertyData.getPropertyData().img
window.setTimeout(()=>{
window.setTimeout(() => {
Photo360Tool.open(document.getElementById('panorama') as HTMLCanvasElement, this.videoDialogType.url)
},0)
}, 0)
}
}
//销毁全景图片 canvas/ 关闭弹窗
closePanorama() {
!this.videoDialogType.isVideo? Photo360Tool.close() : null
!this.videoDialogType.isVideo ? Photo360Tool.close() : null
this.videoDialogType.url = null
}

Loading…
Cancel
Save