From ac9a7471c6d2695e68d779ca87f8e5980546c536 Mon Sep 17 00:00:00 2001 From: liuxianghui <519646741@qq.com> Date: Tue, 9 Nov 2021 17:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=84=E6=A8=A1=E5=9D=97=E9=97=B4=E8=A7=86?= =?UTF-8?q?=E8=A7=92=E4=BF=9D=E5=AD=98=E4=B8=8E=E8=BF=98=E5=8E=9F=EF=BC=8C?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/babylon/controller/scene-manager.ts | 1 + src/app/babylon/model/data/camera-data.ts | 9 +++-- .../model/data/institution/jyz-show-data.ts | 7 ++-- src/app/babylon/tool/babylon-tool.ts | 3 ++ .../view/building-window/building-window.ts | 33 +++++++++++++------ 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/app/babylon/controller/scene-manager.ts b/src/app/babylon/controller/scene-manager.ts index fed7287..c285922 100644 --- a/src/app/babylon/controller/scene-manager.ts +++ b/src/app/babylon/controller/scene-manager.ts @@ -138,6 +138,7 @@ export class SceneManager { // camera.upperBetaLimit = 1.5; //beta方向上的旋转限制(防止看到模型底面) camera.lowerRadiusLimit = 1; //相机距离拍摄目标的最小距离(防止穿插) camera.setTarget(Vector3.Zero()); //设置拍摄目标 + camera.radius = 100; camera.attachControl(this.canvas, true); //把相机连接到画布 this.defaultCamera = camera; diff --git a/src/app/babylon/model/data/camera-data.ts b/src/app/babylon/model/data/camera-data.ts index 8ab6ed5..16c1bf5 100644 --- a/src/app/babylon/model/data/camera-data.ts +++ b/src/app/babylon/model/data/camera-data.ts @@ -12,13 +12,18 @@ export class ArcRotateCameraData { alpha: number; beta: number; + + constructor() { + this.target = new Vector3(); + } + /** * 将数据设置到相机上 * @param camera */ setDataToCamera(camera: ArcRotateCamera) { camera._scene.stopAnimation(camera); - camera.target = this.target; + camera.target = this.target.clone(); camera.radius = this.radius; camera.alpha = this.alpha; camera.beta = this.beta; @@ -29,7 +34,7 @@ export class ArcRotateCameraData { * @param camera */ getDataFromCamera(camera: ArcRotateCamera) { - this.target = camera.target; + this.target = camera.target.clone(); this.radius = camera.radius; this.alpha = camera.alpha; this.beta = camera.beta; diff --git a/src/app/babylon/model/data/institution/jyz-show-data.ts b/src/app/babylon/model/data/institution/jyz-show-data.ts index 68ec178..23e717f 100644 --- a/src/app/babylon/model/data/institution/jyz-show-data.ts +++ b/src/app/babylon/model/data/institution/jyz-show-data.ts @@ -16,7 +16,7 @@ export class JYZShowData { * 摄像机数据 */ @Type(() => ArcRotateCameraData) - cameraData: ArcRotateCameraData; + cameraData: ArcRotateCameraData = new ArcRotateCameraData(); /** * 展示罩棚 @@ -26,7 +26,10 @@ export class JYZShowData { constructor(moudleType: JYZInfoMoudleType, camera: ArcRotateCamera, showZP: boolean) { this.moudleType = moudleType; this.cameraData = new ArcRotateCameraData(); - this.cameraData.getDataFromCamera(camera); + if (camera != null) { + this.cameraData.getDataFromCamera(camera); + } + } } diff --git a/src/app/babylon/tool/babylon-tool.ts b/src/app/babylon/tool/babylon-tool.ts index 8369ff6..9b04c7f 100644 --- a/src/app/babylon/tool/babylon-tool.ts +++ b/src/app/babylon/tool/babylon-tool.ts @@ -288,6 +288,9 @@ export class BabylonTool { } + /** + * 动画移动摄像机target、半径、alpha、beta + */ public static AnimMoveCameraTargetAB( camera: ArcRotateCamera, allFrame: number, diff --git a/src/app/babylon/view/building-window/building-window.ts b/src/app/babylon/view/building-window/building-window.ts index 9478575..a2abb06 100644 --- a/src/app/babylon/view/building-window/building-window.ts +++ b/src/app/babylon/view/building-window/building-window.ts @@ -239,15 +239,7 @@ export class BuildingWindow extends UIBase { //进入应急处置 } else {//恢复查看状态 - 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.recoverMoudleShow(type); } } else { @@ -259,6 +251,24 @@ export class BuildingWindow extends UIBase { } + /** + * 恢复展示模块状态(视角、罩棚) + * @param type + */ + recoverMoudleShow(type: JYZInfoMoudleType) { + let showData = DataManager.institutionData.getMoudleShowData(type); + console.log("恢复模块状态", showData); + 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; + } + + } + //#endregion @@ -345,6 +355,7 @@ export class BuildingWindow extends UIBase { this.showJYZModules(JYZInfoMoudleType.AQSS, false); this.showJYZModules(JYZInfoMoudleType.YQHSGX, false); this.showJYZModules(JYZInfoMoudleType.YQHSGX, false); + this.recoverMoudleShow(null); //this.onChangeCurrentBuildingItem(item); @@ -503,7 +514,7 @@ export class BuildingWindow extends UIBase { instance.addBuildings(BuildingType.Normal, 0, (uiItem, index) => { if (index == 0 && uiItem.buildingInfo.isEnable) { instance.onChangeCurrentBuildingItem(uiItem, false); - uiItem.lookAt(false); + //uiItem.lookAt(false); // console.log("默认选中" + uiItem.buildingInfo.buildingData.normalData.key); } }); @@ -936,10 +947,12 @@ export class BuildingWindow extends UIBase { } 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); }