中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1176 lines
38 KiB

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";
import { EventManager } from "../../controller/event-manager/event-manager";
import { Event_LoadingChange } from "../../controller/event-manager/events/event-loading-change";
import { InfoManager } from "../../controller/info-manager";
import { ModeManager, ModeType } from "../../controller/mode-manager";
import { SceneManager } from "../../controller/scene-manager";
import { ServeManager } from "../../controller/serve-manager";
import { BuildingStatus } from "../../controller/status/building-status";
import { StatusManager } from "../../controller/status/status-manager";
import { ArcRotateCameraData } from "../../model/data/camera-data";
import { BuildingData, BuildingData_ChemicalPlant, BuildingData_Environment, BuildingData_Normal, BuildingType } from "../../model/data/institution/building/building-data";
import { JYZInfoMoudleType, JYZShowData } from "../../model/data/institution/jyz-show-data";
import { ModelType } from "../../model/data/model-data/model-data";
import { FacilityPosType, FacilityType, ModelData_facility } from "../../model/data/model-data/model-data-facility";
import { ModelEditData } from "../../model/data/model-data/model-edit-data";
import { BuildingInfo } from "../../model/info/building/building-info";
import { BuildingInfo_ChemicalPlant } from "../../model/info/building/building-info-chemicalplant";
import { BuildingInfo_Environment } from "../../model/info/building/building-info-environment";
import { BuildingInfo_Normal } from "../../model/info/building/building-info-normal";
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 { TsTool } from "../../tool/ts-tool";
import { FacilityInfoInSceneWindow } from "../facilityinfoinscene-window/facilityinfoinscene-window";
import { MarkWindow } from "../mark-window/mark-window";
import { UIBase } from "../window-base/ui-base";
import { BuildingUIItem } from "./building-ui-item";
//建筑界面
export class BuildingWindow extends UIBase {
/**
* uv动画材质的特殊命名
*/
readonly c_MAT_UV = "MAT_UV";
static instance: BuildingWindow;
buldingStatus: BuildingStatus;
buildingUIItems: BuildingUIItem[] = [];//所有建筑UI
currentBuidngItem: BuildingUIItem; //当前正在操作的建筑
three: PlanComponent;//前端组件
cameraAnim: Animatable;//相机动画
//#region 与前端对接部分
/**
* UI上添加一个建筑item
* @param buildingData 建筑data数据
* @param index 序号
* @param onSuccess 成功的回调
*/
createOneBuildingItem(buildingData: BuildingData_Normal | BuildingData_Environment | BuildingData_ChemicalPlant, index: number, onSuccess?: (buildingUIItem: BuildingUIItem, index: number) => void) {
let buildingInfo: BuildingInfo_Normal | BuildingInfo_Environment | BuildingInfo_ChemicalPlant;
switch (buildingData.buildingType) {
case BuildingType.Normal:
buildingInfo = new BuildingInfo_Normal(buildingData as BuildingData_Normal, null);
break;
case BuildingType.Environment:
buildingInfo = new BuildingInfo_Environment(buildingData, null);
break;
case BuildingType.ChemicalPlant:
buildingInfo = new BuildingInfo_ChemicalPlant(buildingData, null);
break;
}
// console.log("初始化建筑info");
// console.log(buildingInfo.buildingData);
let uiItem = this.addBuildingItem(buildingInfo);
if (buildingData.outdoorData != null && buildingData.outdoorData.modelData != null && buildingData.outdoorData.modelData.resName != null) {
this.updateBuildingModel(buildingInfo, true, () => {
// buildingInfo.initFacility();
BuildingStatus.enterSuccessObservable.notifyObservers(uiItem);
if (onSuccess) {
onSuccess(uiItem, index);
}
})
}
}
//删除建筑
deleteBuilding(buidlingUIItem: BuildingUIItem) {
// console.log("删除建筑" + buidlingUIItem.buildingInfo.buildingData.normalData.key);
DataManager.deleteOneBuildingData(buidlingUIItem.buildingInfo.buildingData.buildingType, buidlingUIItem.buildingInfo.buildingData.normalData.key);
for (let i = 0; i < this.buildingUIItems.length; i++) {
if (this.buildingUIItems[i] == buidlingUIItem) {
buidlingUIItem.dispose();
TsTool.arrayRemove(this.buildingUIItems, buidlingUIItem);
break;
}
}
}
/**
* 改变模型
* @param file
*/
changeModel(file: File[], buildingData: BuildingData) {
if (file == null || file.length == 0) {
return;
}
console.log("修改模型");
buildingData.outdoorData.modelData.key = buildingData.normalData.key;
buildingData.outdoorData.modelData.name = buildingData.normalData.key;
let normalData = buildingData.normalData;
let resPath_out = DataManager.getResPath_building(
DataManager.institutionData.normalData.key.toLowerCase(),
normalData.key.toLocaleLowerCase(),
"outDoor"
);
console.log("新资源路径" + resPath_out);
let buildingWindow = this;
let manifestFile: File = null;
if (buildingData.outdoorData.modelData.resName != null) {
manifestFile = DataManager.createManifestFile(buildingData.outdoorData.modelData);
file.push(manifestFile); //临时关闭缓存文件
}
PlanComponent.instance.showLoading(true);
ServeManager.instance.uploadFile(0, file, resPath_out, (name: string, path: string, currentfile) => {
if (TsTool.stringContain(name, ".gltf")) {
if (TsTool.stringContain(name, ".gltf.manifest")) {
//缓存文件,提取版本号
DataManager.readFile_manifest(currentfile, (version: number) => {
buildingData.outdoorData.modelData.version = version;
// console.log("设置version" + version);
});
}
else {
buildingData.outdoorData.modelData.resName = name;
buildingData.outdoorData.modelData.resPath = path;
if (manifestFile == null) {
manifestFile = DataManager.createManifestFile(buildingData.outdoorData.modelData);
file.push(manifestFile);
}//临时关闭缓存文件
}
}
}
, () => {
PlanComponent.instance.showLoading(false);
let buildingInfo = buildingWindow.getBuildingInfo(buildingData.normalData.key);
buildingWindow.updateBuildingModel(buildingInfo, true);
// buildingWindow.three = ThreeDimensionalHomeComponent.instance;
// buildingWindow.three.maskLayerService.sendMessage(false) //关闭遮罩层
});
}
/**
* 获取目标建筑中,室内的某类设备数目
*/
getNormalBuildingIndoorFacilitys(buildingUIItem: BuildingUIItem, facilityType: FacilityType) {
let result = 0;
if (buildingUIItem.buildingInfo.buildingData.buildingType != BuildingType.Normal) {
//不是普通建筑,没有室内
}
else {
let indoorData: ModelEditData[] = (buildingUIItem.buildingInfo.buildingData as BuildingData_Normal).indoorsData;
if (indoorData != null) {
for (let i = 0; i < indoorData.length; i++) {
let facilitiesByType = indoorData[i].getFacilitiesByType(facilityType);
if (facilitiesByType != null) {
result += facilitiesByType.length;
}
}
}
}
return result;
}
/**
* 进入第一个具有本设备的室内楼层
*/
changeToFirstIndoorByFacility(buildingUIItem: BuildingUIItem, facilityType: FacilityType) {
let result = false;//是否成功找到并进入某室内层
let num = 0;
if (buildingUIItem.buildingInfo.buildingData.buildingType != BuildingType.Normal) {
//不是普通建筑,没有室内
}
else {
let indoorData: ModelEditData[] = (buildingUIItem.buildingInfo.buildingData as BuildingData_Normal).indoorsData;
for (let i = 0; i < indoorData.length; i++) {
let facilitiesByType = indoorData[i].getFacilitiesByType(facilityType);
if (facilitiesByType != null) {
num += facilitiesByType.length;
}
if (num > 0) {
result = true;
buildingUIItem.enterIndoor(indoorData[i].modelData.key, true);
break;
}
}
}
return result;
}
/**
* 加油站信息各个模块的显示、隐藏
* @param type
* @param show true表示显示
*/
changeJYZInfoModel(type: JYZInfoMoudleType, show: boolean) {
if (this.currentJYZInfoMoudleType == type) {
if (show) {
return; //与上次显示的模块相同
}
else {
this.showJYZModules(type, show); //单纯隐藏
}
}
else {
if (this.currentJYZInfoMoudleType != null) {
this.showJYZModules(this.currentJYZInfoMoudleType, false); //先恢复之前隐藏的内容
}
this.showJYZModules(type, show);//展示本次要展示的内容
}
if (show) {
if (type == JYZInfoMoudleType.YJCZ) {
//进入应急处置
}
else {//恢复查看状态
}
this.recoverMoudleShow(type);
}
else {
if (type == JYZInfoMoudleType.YJCZ) {
//退出应急处置
}
this.recoverMoudleShow(null);
}
}
/**
* 恢复展示模块状态(视角、罩棚)
* @param type
*/
recoverMoudleShow(type: JYZInfoMoudleType) {
let showData = DataManager.institutionData.getMoudleShowData(type);
if (showData != null) {
//let camera = SceneManager.Instance.defaultCamera;
//showData.cameraData.setDataToCamera(camera);
let cameraData = showData.cameraData;
// BabylonTool.AnimMoveCameraTargetAB(camera, 60, cameraData.target, cameraData.radius, cameraData.alpha, cameraData.beta);
// this.showZP(showData.showZP);
// PlanComponent.instance.isOpenAwning = showData.showZP;
this.revoverCamera(cameraData, showData.showZP);
}
}
/**
* 动画恢复相机状态
* @param cameraData
* @param showZP
*/
revoverCamera(cameraData: ArcRotateCameraData, showZP: boolean, onAnimationEnd?: () => void) {
this.showZP(showZP);
PlanComponent.instance.isOpenAwning = showZP;
let camera = SceneManager.Instance.defaultCamera;
if (cameraData != null) {
this.cameraAnim = BabylonTool.AnimMoveCameraTargetAB(camera, 60, cameraData.target, cameraData.radius, cameraData.alpha, cameraData.beta, onAnimationEnd);
if (Event_LoadingChange.isLoading) { //加载中,暂停
this.cameraAnim.pause();
}
}
}
//#endregion
//#region 生命周期
onInit() {
super.onInit();
GizmoTool.changeGizmoOpen(ModeManager.s_isMakeMode); //内部模式才默认打开gizmo
this.buldingStatus = StatusManager.getStatus<BuildingStatus>(BuildingStatus);
this.initBuildings();//创建每一个建筑buildingItem
BuildingWindow.instance = this;
this.three = PlanComponent.instance;
this.three.buildingUIItems = this.buildingUIItems
this.buildingUIItems.length ? this.three.beforeOneBuildingID = this.three.buildingUIItems[0].getBuildingID() : null
let instance = this;
SceneManager.Instance.scene.onBeforeRenderObservable.add(() => {
instance.onUpdate();
})
EventManager.addListener<Event_LoadingChange>(Event_LoadingChange, (eventInfo) => {
instance.onChangeLoading(eventInfo);
});
}
onShow() {
this.three = PlanComponent.instance;
this.three.buildingUIItems = this.buildingUIItems
this.showModel(true);
super.onShow();
}
onHide() {
this.showModel(false);
super.onHide();
}
onUpdate() {
this.updateUVAnim();
this.updateLimitCameraY();
}
/**
* loading状态改变时
* @param eventInfo
*/
onChangeLoading(eventInfo: Event_LoadingChange) {
if (eventInfo.showLoading) {
if (this.cameraAnim != null) {
this.cameraAnim.pause();
}
}
else {
if (this.cameraAnim != null) {
this.cameraAnim.restart();
}
}
}
/**
* 释放建筑,回到未创建建筑前
*/
dispose() {
for (let i = 0; i < this.buildingUIItems.length; i++) {
this.buildingUIItems[i].dispose();
}
BuildingWindow.instance = null;
}
//#endregion
//#region 外部公有
/**
* 清空建筑上的设备实例
* @param buildingInfo
*/
clearFacilityInfos(buildingInfo: BuildingInfo) {
if (buildingInfo.ModelInfo != null) {
for (let i = 0; i < buildingInfo.ModelInfo.facilityInfos.length; i++) {
buildingInfo.ModelInfo.facilityInfos[i].dispose();
}
buildingInfo.ModelInfo.facilityInfos = [];
}
}
/**
* 显示或隐藏建筑上的设备icon
* @param buildingInfo
* @param show
*/
showFacilityInfosIcon(buildingInfo: BuildingInfo, show: boolean) {
if (buildingInfo.ModelInfo != null) {
buildingInfo.ModelInfo.showFacilityUI(show);
}
}
/**
* 根据buildingInfo找到item,然后模拟选中
* @param buildingInfo 建筑信息
*/
changeCurrentBuildingInfo(modelInfo: ModelInfo_building) {
let item: BuildingUIItem = null;
for (let i = 0; i < this.buildingUIItems.length; i++) {
if (this.buildingUIItems[i].buildingInfo.ModelInfo == modelInfo) {
item = this.buildingUIItems[i];
break;
}
}
// console.log("选中建筑", modelInfo);
this.showJYZModules(JYZInfoMoudleType.YJCZ, false);
this.showJYZModules(JYZInfoMoudleType.JBXX, false);
this.showJYZModules(JYZInfoMoudleType.AQSS, false);
this.showJYZModules(JYZInfoMoudleType.YQHSGX, false);
this.showJYZModules(JYZInfoMoudleType.SYG, false);
this.recoverMoudleShow(null);
//this.onChangeCurrentBuildingItem(item);
//this.three.selectLeftBuilding(item);
}
/**
* 改变当前操作建筑目标
* @param buidlingUIItem 新选中的目标
*/
onChangeCurrentBuildingItem(buidlingUIItem: BuildingUIItem, animMove = true) {
if (this.currentBuidngItem != null && this.currentBuidngItem != buidlingUIItem) {
this.currentBuidngItem.onSelect(false);
}
this.currentBuidngItem = buidlingUIItem;
this.currentBuidngItem.onSelect(true, animMove);
this.buldingStatus.changeCurrentBuilding(buidlingUIItem.buildingInfo);
}
/**
* 查询buildingKey
* @param key
*/
public getBuildingInfo(key: string): BuildingInfo {
for (let i = 0; i < this.buildingUIItems.length; i++) {
if (this.buildingUIItems[i].buildingInfo.buildingData.normalData.key == key) {
return this.buildingUIItems[i].buildingInfo;
}
}
return null;
}
/**
* 查询UIItem
* @param key
*/
public getBuildingUIItem(key: string) {
for (let i = 0; i < this.buildingUIItems.length; i++) {
if (this.buildingUIItems[i].buildingInfo.buildingData.normalData.key == key) {
return this.buildingUIItems[i];
}
}
return null;
}
/**
* 更新建筑模型
* @param buildingInfo
* @param updateFacility
* @param onSuccess
*/
public updateBuildingModel(buildingInfo: BuildingInfo, updateFacility: boolean, onSuccess?: () => void) {
if (buildingInfo == null) {
return;
}
if (buildingInfo.ModelInfo != null) {
buildingInfo.ModelInfo.dispose();
}
SceneManager.createModel(ModelType.Building, buildingInfo.buildingData.outdoorData.modelData, true, true, "Building", (newMesh, box, modelInfo) => {
buildingInfo.ModelInfo = modelInfo as ModelInfo_building;
buildingInfo.ModelInfo.updateName(buildingInfo.buildingData.normalData.name);
if (updateFacility) {
InfoManager.createFacilityInfos(buildingInfo.buildingData.outdoorData, buildingInfo);
}
if (buildingInfo instanceof BuildingInfo_Environment) {
buildingInfo.updateFuGaiCeng();
}
if (onSuccess) {
onSuccess();
}
});
}
//#endregion
//#region 内部私有
//填充建筑列表
private initBuildings() {
//因为babylon内对indexDB的封装使用有问题,在用户第一次使用时触发了创建数据库操作,导致我们同时调用多个加载方法时报错
//解决策略是:如果发现有多个模型要加载,则先加载第一个模型,保证indexDB数据库正常建立, 第一个加载完成后,在加载剩余模型
BuildingStatus.startEnterObservable.notifyObservers(null);
let instance = this;
let firstItem; //第一个要加载的模型
let firstType: BuildingType;
let allModelNumber = 0;
let buildingDatas_Environment = DataManager.getBuildingDataListByType(BuildingType.Environment);
if (buildingDatas_Environment != null) {
allModelNumber += buildingDatas_Environment.length;
if (buildingDatas_Environment.length > 0) {
firstItem = buildingDatas_Environment[0];
firstType = BuildingType.Environment;
}
}
let buildingDatas_mormal = DataManager.getBuildingDataListByType(BuildingType.Normal);
if (buildingDatas_mormal != null) {
allModelNumber += buildingDatas_mormal.length;
if (buildingDatas_mormal.length > 0) {
firstItem = buildingDatas_mormal[0];
firstType = BuildingType.Normal;
}
}
//暂时关闭 1+ n的加载模式
// if (allModelNumber > 1) {
// if (firstType == BuildingType.Environment) {
// instance.createOneBuildingItem(firstItem, 0, (uiItem, index) => {
// instance.onChangeCurrentBuildingItem(uiItem, false);
// // uiItem.lookAt(false);
// if (buildingDatas_Environment.length > 1) {
// instance.addBuildings(BuildingType.Environment, 1);
// }
// instance.addBuildings(BuildingType.Normal, 0);
// });
// }
// else {
// instance.createOneBuildingItem(firstItem, 0, (uiItem, index) => {
// instance.onChangeCurrentBuildingItem(uiItem, false);
// // uiItem.lookAt(false);
// if (buildingDatas_mormal.length > 1) {
// instance.addBuildings(BuildingType.Normal, 1);
// }
// instance.addBuildings(BuildingType.Environment, 0);
// });
// }
// }
// else {
// instance.addBuildings(BuildingType.Normal, 0, (uiItem, index) => {
// if (index == 0 && uiItem.buildingInfo.isEnable) {
// instance.onChangeCurrentBuildingItem(uiItem, false);
// //uiItem.lookAt(false);
// // console.log("默认选中" + uiItem.buildingInfo.buildingData.normalData.key);
// }
// });
// instance.addBuildings(BuildingType.Environment, 0);
// }
instance.addBuildings(BuildingType.Normal, 0, (uiItem, index) => {
if (index == 0 && uiItem.buildingInfo.isEnable) {
instance.onChangeCurrentBuildingItem(uiItem, false);
//uiItem.lookAt(false);
// console.log("默认选中" + uiItem.buildingInfo.buildingData.normalData.key);
}
});
instance.addBuildings(BuildingType.Environment, 0);
}
//初始化建筑显示(根据类别)
private addBuildings(buildingType: BuildingType, startIndex: number, onSuccess?: (buildingUIItem: BuildingUIItem, index: number) => void) {
let index = startIndex;
let buildingDatas = DataManager.getBuildingDataListByType(buildingType);
// console.log(buildingDatas);
while (buildingDatas != null && index < buildingDatas.length) {
let l_index = index;
let buildingData = buildingDatas[l_index];
this.createOneBuildingItem(buildingData, l_index, onSuccess);
index++;
}
}
//添加一个item到界面中
private addBuildingItem(buildingInfo: BuildingInfo): BuildingUIItem {
let buildingItem = new BuildingUIItem(buildingInfo, this);
this.buildingUIItems.push(buildingItem);
return buildingItem;
}
/**
* 隐藏或展示模型
* @param show true-表示展示
*/
private showModel(show: boolean) {
for (let i = 0; i < this.buildingUIItems.length; i++) {
//周围环境,不隐藏(也就不用再显示)
if (this.buildingUIItems[i].buildingInfo.ModelInfo.buildingType == BuildingType.Environment) {
(this.buildingUIItems[i].buildingInfo as BuildingInfo_Environment).updateFuGaiCeng();
if (show) { //切换到室外时,根据选中状态恢复设备UI
if (this.currentBuidngItem == this.buildingUIItems[i]) {
this.buildingUIItems[i].buildingInfo.ModelInfo.showFacilityUI(show);
}
else {
this.buildingUIItems[i].buildingInfo.ModelInfo.showFacilityUI(false);
}
this.buildingUIItems[i].buildingInfo.ModelInfo.showFollowUI(true);//环境的名称UI 不显示
}
else { //切换到室内时,显示环境的设备UI
this.buildingUIItems[i].buildingInfo.ModelInfo.showFacilityUI(false);//(感觉太乱,暂时取消)
this.buildingUIItems[i].buildingInfo.ModelInfo.showFollowUI(false);//环境的名称UI 不显示
}
}
else { // 建筑,正常显隐
this.buildingUIItems[i].setModelEnable(show);
}
// if (this.buildingUIItems[i].buildingInfo != null) {
// this.buildingUIItems[i].buildingInfo.setEnable(show);
// }
}
}
//#endregion
//#region 寻找建筑内已有设备相关
/**
* 消防相关
*/
readonly c_xiaoFang = "XF_";
/**
* 安全疏散
*/
readonly c_shuSan = "AQSS_";
/**
* 加油站相关
*/
readonly c_jiaYou = "JY_";
/**
* 遮挡
*/
readonly c_zheDang = "ZD";
/**
* 清空找不到具体模型的设备信息
*/
public clearHomeLessFacilityData() {
if (this.currentBuidngItem != null) {
let allFacilities = this.currentBuidngItem.buildingInfo.buildingData.outdoorData.facilities;
let needClear: ModelData_facility[] = [];
for (let i = 0; i < allFacilities.length; i++) {
let facilityByType = allFacilities[i];
for (let j = 0; j < facilityByType.facilities.length; j++) {
let info = FacilityInfoInSceneWindow.instance.getFacilityInfo(facilityByType.facilities[j]);
if (info == null
|| TsTool.stringContain(info._modelBox.id, "(Box)")) {
needClear.push(facilityByType.facilities[j]);
}
}
}
for (let k = 0; k < needClear.length; k++) {
for (let i = 0; i < allFacilities.length; i++) {
let facilityByType = allFacilities[i];
TsTool.arrayRemove(facilityByType.facilities, needClear[k]);
}
}
}
}
/**
* 清空所有来自模型的设备
*/
public clearAllFacilityFromMeshData() {
if (this.currentBuidngItem != null) {
this.currentBuidngItem.clearFacilityFromMesh();
}
}
/**
* 获取并创建建筑上的消防设备数据(内部模式制作时,调用一次)
*/
public getModelAndCreateFacilityData() {
this.clearHomeLessFacilityData();
if (this.currentBuidngItem != null) {
//获取所有transformNodes
let allNode = this.currentBuidngItem.buildingInfo.ModelInfo.modelBox.getChildMeshes(false);
for (let i = 0; i < allNode.length; i++) {
let nodeName = allNode[i].name;
if (TsTool.stringContain(nodeName, "primitive")) {
//复合材质被分解为多个子mesh,不看做特殊意义的对象
}
else if (TsTool.stringContain(nodeName, this.c_zheDang))//遮挡
{
this.currentBuidngItem.createStopByMesh(allNode[i]);
}
else if (TsTool.stringContain(nodeName, this.c_xiaoFang)) //消防
{
this.currentBuidngItem.createFacilityByMesh(allNode[i]);
}
else if (TsTool.stringContain(nodeName, this.c_shuSan)) {
this.currentBuidngItem.createAQSSFromMesh(allNode[i]);//安全疏散
}
else if (TsTool.stringContain(nodeName, this.c_jiaYou))//加油站
{
this.currentBuidngItem.createOilingByMesh(allNode[i]);
}
}
}
}
//#endregion
//#region 加油站基本信息模块的显隐表现
/**
* 箭头UV动画速度
*/
readonly c_uvAnimSpeed = 0.001;
/**
* 当前查看的加油站信息模块类型
*/
currentJYZInfoMoudleType: JYZInfoMoudleType = null;
/**
* 当前模块需要显示的各类设备
*/
facilitysByMoudle: Map<JYZInfoMoudleType, FacilityInfoByType[]> = new Map();
/**
* 当前模块需要隐藏的设备
*/
zdByMoudle: Map<JYZInfoMoudleType, FacilityInfoByType[]> = new Map();
/**
* uv动画所需材质
*/
mat_UV: Map<JYZInfoMoudleType, Material[]> = new Map();
/**
* 当前罩棚是否显示
*/
currentZPShow: boolean = true;
/**
* 展示加油站信息模块
* @param type
* @param show
*/
showJYZModules(type: JYZInfoMoudleType, show: boolean) {
if (this.currentBuidngItem == null) {
return;
}
if (show) {
this.updateGizmoType(type);
}
if (type == JYZInfoMoudleType.YJCZ) {
if (show) {
// console.log("进入应急处置");
MarkWindow.openWindow();
}
else {
// console.log("退出应急处置");
MarkWindow.closeWindow();
}
}
this.initFacilityTypeByMoudleType(type, this.currentBuidngItem.buildingInfo);
FacilityInfoInSceneWindow.instance.selectJYJFrom3D(null);
//设备: 显示UI
let facilityByType: FacilityInfoByType[] = [];
if (this.facilitysByMoudle.has(type)) {
facilityByType = this.facilitysByMoudle.get(type);
}
for (let i = 0; i < facilityByType.length; i++) {
let infos = facilityByType[i].facilityInfo;
if (infos != null) {
for (let j = 0; j < infos.length; j++) {
infos[j].playShowAnim(show);
//安全疏散,特殊,要在不显示时隐藏本体
if (type == JYZInfoMoudleType.AQSS) {
infos[j].setEnable(show);
}
}
}
}
//阻挡类物体
let zdByType: FacilityInfoByType[] = [];
if (this.zdByMoudle.has(type)) {
zdByType = this.zdByMoudle.get(type);
}
else {
}
for (let i = 0; i < zdByType.length; i++) {
let infos = zdByType[i].facilityInfo;
if (infos != null) {
for (let j = 0; j < infos.length; j++) {
infos[j].setEnable(!show);
}
}
}
/**
* 在输油管和油气回收模块, 要展示油罐和加油机的名字UI
*/
let isShowNameUI_JYJ_YG = show && (type == JYZInfoMoudleType.SYG || type == JYZInfoMoudleType.YQHSGX);
let showNameFacilitys: ModelInfo_facility[] = [];
showNameFacilitys = showNameFacilitys.concat(this.currentBuidngItem.buildingInfo.ModelInfo.getFacilityInfoByType(FacilityType.JY_JYJ));
showNameFacilitys = showNameFacilitys.concat(this.currentBuidngItem.buildingInfo.ModelInfo.getFacilityInfoByType(FacilityType.JY_YG));
for (let i = 0; i < showNameFacilitys.length; i++) {
showNameFacilitys[i].showNameUI(isShowNameUI_JYJ_YG);
}
//SceneManager.Instance.openInnerGlow(!isShowNameUI_JYJ_YG); //输油管和油气回收管太细,关闭内发光
if (show) {
this.currentJYZInfoMoudleType = type;
}
else {
this.currentJYZInfoMoudleType = null;
// SceneManager.Instance.highLightLayer.removeAllMeshes();
}
}
/**
* 根据各个模块,更新gizmo状态
* @param type
*/
updateGizmoType(type: JYZInfoMoudleType) {
let open = false;
if (ModeManager.currentMode == ModeType.Edit) {
switch (type) {
case JYZInfoMoudleType.JBXX:
case JYZInfoMoudleType.YJCZ: open = true; break;
}
}
if (ModeManager.s_isMakeMode) {
open = true;
}
GizmoTool.changeGizmoOpen(open);
}
/**
* 根据功能模块,获取所需的设备类型
* @param moudleType 功能模块
*/
initFacilityTypeByMoudleType(moudleType: JYZInfoMoudleType, buildingInfo: BuildingInfo) {
let moudleTypeKey = moudleType; //当前模块物体的特殊字段
let zdKey = "ZD_" + moudleType; //阻挡类物体特殊字段
//编辑模式下,基本信息下的设备会随时变化
if (ModeManager.currentMode == ModeType.Edit) {
let jbxxMoudle = JYZInfoMoudleType.JBXX;
if (this.facilitysByMoudle.has(jbxxMoudle)) {
this.facilitysByMoudle.get(jbxxMoudle).length = 0;
}
else {
this.facilitysByMoudle.set(jbxxMoudle, []);
}
let allFacilityByType = buildingInfo.ModelInfo.facilityInfos;
if (allFacilityByType == null) {
return; //没有设备
}
for (let i = 0; i < allFacilityByType.length; i++) {
let l_facilityByType = allFacilityByType[i];
if (ConfigManager.getPosType(l_facilityByType.type) == FacilityPosType.Out) {
this.facilitysByMoudle.get(jbxxMoudle).push(l_facilityByType);
}
}
}
if (this.facilitysByMoudle.has(moudleType)) {
//已经初始化过了
return;
}
else {
this.facilitysByMoudle.set(moudleType, []);
}
let allFacilityByType = buildingInfo.ModelInfo.facilityInfos;
if (allFacilityByType == null) {
return; //没有设备
}
for (let i = 0; i < allFacilityByType.length; i++) {
let l_facilityByType = allFacilityByType[i];
if (TsTool.stringContain(l_facilityByType.type, zdKey)) { //遮挡物
if (!this.zdByMoudle.has(moudleType)) {
this.zdByMoudle.set(moudleType, []);
}
this.zdByMoudle.get(moudleType).push(l_facilityByType);
}
else if (TsTool.stringContain(l_facilityByType.type, "_" + moudleTypeKey) || TsTool.stringContain(l_facilityByType.type, moudleTypeKey + "_")) {
this.facilitysByMoudle.get(moudleType).push(l_facilityByType);
}
}
}
/**
* 显示罩棚
* @param show false 表示隐藏罩棚
*/
showZP(show: boolean) {
this.initFacilityTypeByMoudleType(JYZInfoMoudleType.ZP, this.currentBuidngItem.buildingInfo);
let zpInfoByTypes = this.zdByMoudle.get(JYZInfoMoudleType.ZP);
if (zpInfoByTypes != null) {
for (let i = 0; i < zpInfoByTypes.length; i++) {
let infos = zpInfoByTypes[i].facilityInfo;
for (let j = 0; j < infos.length; j++) {
infos[j].setEnable(show);
}
}
}
this.currentZPShow = show;
}
/**
* 获取设备所需UV材质(如果有的话)
* @param facilityType
* @param mesh
*/
getUVMat(facilityType: FacilityType, mesh: AbstractMesh) {
let moudleType: JYZInfoMoudleType = null;
switch (facilityType) {
case FacilityType.AQSS_TSLX:
moudleType = JYZInfoMoudleType.AQSS;
break;
case FacilityType.JY_SYGX:
moudleType = JYZInfoMoudleType.SYG;
break;
case FacilityType.JY_YQHSGX:
moudleType = JYZInfoMoudleType.YQHSGX;
break;
}
if (moudleType != null) {
if (!this.mat_UV.has(moudleType)) {
this.mat_UV.set(moudleType, []);
}
let mats = this.findUVMat(mesh); //找到mesh上的uv材质
for (let i = 0; i < mats.length; i++) {
let l_mat = mats[i];
let mat_uvByType = this.mat_UV.get(moudleType);
let isRepeat = false;//是重复的
for (let j = 0; j < mat_uvByType.length; j++) {
if (isRepeat) {
continue;
}
if (l_mat == mat_uvByType[j]) {
isRepeat = true;
}
}
if (!isRepeat)//不重复,就添加进去
{
this.mat_UV.get(moudleType).push(l_mat);
}
}
}
}
/**
* 查找mesh中uv动画所需的材质
* @param mesh
*/
private findUVMat(mesh: AbstractMesh) {
let result = [];
if (mesh == null) {
return result;
}
let childMesh = mesh.getChildMeshes();
childMesh.push(mesh);
for (let i = 0; i < childMesh.length; i++) {
let mat = childMesh[i].material;
if (TsTool.stringContain(mat.name, this.c_MAT_UV)) {
result.push(mat);
}
}
return result;
}
/**
* uv动画 update
*/
updateUVAnim() {
// console.log("uv", this.mat_UV);
if (this.mat_UV == null || this.currentJYZInfoMoudleType == null) {
return;
}
let mats = this.mat_UV.get(this.currentJYZInfoMoudleType);
if (mats == null) {
return;
}
for (let i = 0; i < mats.length; i++) {
let mat = mats[i];
if (mat instanceof PBRMaterial) {
(mat.albedoTexture as Texture).vOffset += SceneManager.Instance.scene.deltaTime * this.c_uvAnimSpeed;
}
}
}
/**
* 保存展示模块当前数据
*/
saveShowMoudleData() {
let moudleType = this.currentJYZInfoMoudleType;
let camera = SceneManager.Instance.defaultCamera;
let showZP = this.currentZPShow;
if (DataManager.institutionData.JYZShowDatas == null) {
DataManager.institutionData.JYZShowDatas = [];
}
let jyzShowData: JYZShowData = null;
for (let i = 0; i < DataManager.institutionData.JYZShowDatas.length; i++) {
if (DataManager.institutionData.JYZShowDatas[i].moudleType == moudleType) {
jyzShowData = DataManager.institutionData.JYZShowDatas[i];
break;
}
}
if (jyzShowData == null) {
jyzShowData = new JYZShowData(moudleType, camera, showZP);
DataManager.institutionData.JYZShowDatas.push(jyzShowData);
}
jyzShowData.moudleType = moudleType;
jyzShowData.cameraData.getDataFromCamera(camera);
jyzShowData.showZP = showZP;
console.log("保存展示数据", DataManager.institutionData.JYZShowDatas);
}
//#endregion
//#region 限制摄像机Y
/**
* 摄像机Y高度的限制
*/
limitCameraY_min: number = null;
/**
* 设置相机target最小Y
* @param value
*/
setLimitCameraY_min(value: number) {
this.limitCameraY_min = value;
}
/**
* 限制摄像机Y
*/
updateLimitCameraY() {
if (SceneManager.Instance.defaultCamera != null) {
if (this.limitCameraY_min != null) {
if (SceneManager.Instance.defaultCamera.target.y < this.limitCameraY_min) {
SceneManager.Instance.defaultCamera.target.y = this.limitCameraY_min;
}
}
}
}
//#endregion
}