diff --git a/src/app/babylon/controller/data-manager.ts b/src/app/babylon/controller/data-manager.ts index 7870503..431e216 100644 --- a/src/app/babylon/controller/data-manager.ts +++ b/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 { //本地捏造测试数据 diff --git a/src/app/babylon/controller/status/building-status.ts b/src/app/babylon/controller/status/building-status.ts index a087bdd..65b6a24 100644 --- a/src/app/babylon/controller/status/building-status.ts +++ b/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); @@ -76,19 +77,19 @@ export class BuildingStatus extends StatusBase { else { //从室内返回 UIManager.show(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 { } } } + } \ No newline at end of file diff --git a/src/app/babylon/controller/status/login-status.ts b/src/app/babylon/controller/status/login-status.ts index 839ebb6..f0c4381 100644 --- a/src/app/babylon/controller/status/login-status.ts +++ b/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); if (status.institutionSelectWindow != null) { UIManager.close(status.institutionSelectWindow); diff --git a/src/app/babylon/game.ts b/src/app/babylon/game.ts index 7b04f45..b45ad39 100644 --- a/src/app/babylon/game.ts +++ b/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,35 +20,63 @@ 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 }); + Database.IDBStorageEnabled = true;//开启本地缓存 + this.scene = new Scene(this.engine); + this.scene.useRightHandedSystem = true;//使用右手坐标系 + RenderingManager.MIN_RENDERINGGROUPS = -1;//最小渲染序列 + this.createScene(); + UIManager.Instance.init(); + 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 && Game.instance.isRender) { + Game.instance.engine.resize(); + UIManager.Instance.uiRoot.renderScale = 0.99; + setTimeout(() => { + UIManager.Instance.uiRoot.renderScale = 1; + }, 10); + } + }); + } + + StatusManager.enterStatus(LoginSatus); - Game.instance = this; - this.canvas = canvas; - this.engine = new Engine(canvas, null, { stencil: true }); - Database.IDBStorageEnabled = true;//开启本地缓存 - 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); - //最后,将场景渲染出来 (重要,不可缺少) - this.engine.runRenderLoop(function () { - scene.render(); - }) - // 监听浏览器改变大小的事件,通过调用engine.resize()来自适应窗口大小 - window.addEventListener("resize", function () { - if (Game.instance != null) { - Game.instance.engine.resize(); - } - }); + } @@ -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; + } + + } // /** diff --git a/src/app/babylon/tool/load-tool.ts b/src/app/babylon/tool/load-tool.ts index 12f267b..222b740 100644 --- a/src/app/babylon/tool/load-tool.ts +++ b/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); } diff --git a/src/app/babylon/view/building-window/building-window.ts b/src/app/babylon/view/building-window/building-window.ts index 2957973..6471318 100644 --- a/src/app/babylon/view/building-window/building-window.ts +++ b/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); } diff --git a/src/app/babylon/view/facility-window/facility-window.ts b/src/app/babylon/view/facility-window/facility-window.ts index c928549..60c597a 100644 --- a/src/app/babylon/view/facility-window/facility-window.ts +++ b/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,26 +167,40 @@ export class FacilityWindow extends UIBase { let instance = this; //为了避免多个模型同时加载、导致indexDB创建冲突,所以先加载一个,保证indexDB创建完成 - BabylonTool.importMeshSync(null, "mesh/indexdb/gd/", "GD.gltf", undefined, "GD_indexDB", (meshes) => { - meshes[0].dispose(); - for (let i = 0; i < facilities.length; i++) { - - let facilityUIItem: FacilityUIItem = new FacilityUIItem( - facilities[i], - null, - null - ); - - instance.allFacilityUIItemes.push(facilityUIItem); - } - // console.log("所有可用的设备", instance.allFacilityUIItemes); - PlanComponent.instance.getAllIcons(instance) + 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( + facilities[i], + null, + null + ); + + FacilityWindow.instance.allFacilityUIItemes.push(facilityUIItem); + } + // console.log("所有可用的设备", instance.allFacilityUIItemes); + PlanComponent.instance.getAllIcons(FacilityWindow.instance) + } + //清空可用设施列表 clearAllFacilityUIItemes() { for (let i = 0; i < this.allFacilityUIItemes.length; i++) { diff --git a/src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts b/src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts index 1dfa899..8b496d9 100644 --- a/src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts +++ b/src/app/babylon/view/facilityinfoinscene-window/facilityinfoinscene-window.ts @@ -164,9 +164,9 @@ export class FacilityInfoInSceneWindow extends UIBase { } } else { // 单选 if (isChecked) { //选中 - this.three.selectProperty(facilityInfoUIItem[0]) + this.three.selectProperty(facilityInfoUIItem[0]) } else { //取消选中 - this.three.isShowNature = false + this.three.isShowNature = false } } @@ -586,7 +586,7 @@ export class FacilityInfoInSceneWindow extends UIBase { } } - + this.three = PlanComponent.instance; //通知ui更新 //this.three.getAllCensusList(this.facilityInfoUIItemes || []); diff --git a/src/app/pages/left-domain/left-domain.component.ts b/src/app/pages/left-domain/left-domain.component.ts index 7c15bc1..8777b8a 100644 --- a/src/app/pages/left-domain/left-domain.component.ts +++ b/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) => { //上传 diff --git a/src/app/pages/plan/plan.component.ts b/src/app/pages/plan/plan.component.ts index 69c01ec..cbcef73 100644 --- a/src/app/pages/plan/plan.component.ts +++ b/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 }