From d641ab01d30e2e9457e8ea9c0dd2a598a884cf1b Mon Sep 17 00:00:00 2001 From: liuxianghui <519646741@qq.com> Date: Mon, 24 Jan 2022 13:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E5=85=89=E3=80=81?= =?UTF-8?q?=E6=97=A0=E9=98=B4=E5=BD=B1=E6=97=B6=EF=BC=8C=E4=B8=8EInstanceM?= =?UTF-8?q?esh=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/babylon/controller/scene-manager.ts | 7 ++++--- src/app/babylon/tool/babylon-tool.ts | 10 +++++++--- src/app/babylon/tool/mesh-pool.ts | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/babylon/controller/scene-manager.ts b/src/app/babylon/controller/scene-manager.ts index 648567e..4f1d9fc 100644 --- a/src/app/babylon/controller/scene-manager.ts +++ b/src/app/babylon/controller/scene-manager.ts @@ -58,6 +58,7 @@ import { ModelInfo_mark_multiArrow } from '../model/info/mark/other/mark-plan-mu import { ModelInfo_mark_particle } from '../model/info/mark/other/mark-plan-particle-info'; import { FacilityPosType, ModelData_facility } from '../model/data/model-data/model-data-facility'; import { LoadTool } from '../tool/load-tool'; +import { flatten } from 'earcut'; //场景管理器 @@ -78,7 +79,7 @@ export class SceneManager { static s_openLight: boolean = true;//开启光照效果(关闭是要同时关闭阴影) - static s_openShadow: boolean = true;//开启阴影(必须开启阴影) + static s_openShadow: boolean = true;//开启阴影(必须开启光照) static s_openSkyBox: boolean = true;//使用天空盒 static s_environmentCubeTexture: CubeTexture;//环境所用的cubeTexture static s_openEnvironmentReflection: boolean = true;//使用环境反射 @@ -232,7 +233,7 @@ export class SceneManager { } else { - if (this.sunLight == null) { + if (this.sunLight != null) { this.sunLight.setEnabled(false); } @@ -244,7 +245,7 @@ export class SceneManager { * 初始化阴影 */ public updateShadow() { - if (SceneManager.s_openShadow) { + if (SceneManager.s_openLight && SceneManager.s_openShadow) { if (this.shadowGenerator == null) { this.shadowGenerator = new ShadowGenerator(2048, this.sunLight); } diff --git a/src/app/babylon/tool/babylon-tool.ts b/src/app/babylon/tool/babylon-tool.ts index 9fd3dac..4209798 100644 --- a/src/app/babylon/tool/babylon-tool.ts +++ b/src/app/babylon/tool/babylon-tool.ts @@ -147,10 +147,14 @@ export class BabylonTool { ).then(function (result) { LoadTool.remove(modelPath); isSuccess = true; - onSuccess(result.meshes, result.particleSystems, result.skeletons, result.animationGroups); - }).catch(function (result) { - onError(scene, "load error", result); + if (onSuccess) { + onSuccess(result.meshes, result.particleSystems, result.skeletons, result.animationGroups); + } + }).catch(function (result) { + if (onError) { + onError(scene, "load error", result); + } }); // setTimeout(() => { diff --git a/src/app/babylon/tool/mesh-pool.ts b/src/app/babylon/tool/mesh-pool.ts index 101ff0d..3a927e7 100644 --- a/src/app/babylon/tool/mesh-pool.ts +++ b/src/app/babylon/tool/mesh-pool.ts @@ -307,7 +307,7 @@ export class MeshPoolInfo { // let box = MeshBuilder.CreateBox("box", { size: 1 }); //用于测试阴影 // box.setParent(modelInfo.modelBox); // box.position = new Vector3(0, 2, 0); - if (SceneManager.s_openShadow) { + if (SceneManager.s_openLight && SceneManager.s_openShadow) { SceneManager.Instance.shadowGenerator.addShadowCaster(modelInfo.modelBox, true); // console.log("添加到阴影", modelInfo.modelBox.name); }