From 772bf50d168982bd401c30e58172e0a60fbafe46 Mon Sep 17 00:00:00 2001 From: wmltogether Date: Wed, 24 Jan 2024 14:44:59 +0800 Subject: [PATCH] fix: fix abnormal mesh bounds error close #213 --- Packages/src/Runtime/UIParticleRenderer.cs | 1 + Packages/src/Runtime/Utils.cs | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Packages/src/Runtime/UIParticleRenderer.cs b/Packages/src/Runtime/UIParticleRenderer.cs index 6abfae10..045f997b 100644 --- a/Packages/src/Runtime/UIParticleRenderer.cs +++ b/Packages/src/Runtime/UIParticleRenderer.cs @@ -339,6 +339,7 @@ public void UpdateMesh(Camera bakeCamera) } else if (_renderer.CanBakeMesh()) { + _particleSystem.ValidateShape(); #if PS_BAKE_API_V2 _renderer.BakeMesh(s_CombineInstances[0].mesh, bakeCamera, ParticleSystemBakeMeshOptions.BakeRotationAndScale); diff --git a/Packages/src/Runtime/Utils.cs b/Packages/src/Runtime/Utils.cs index 36c64441..9c3b80aa 100644 --- a/Packages/src/Runtime/Utils.cs +++ b/Packages/src/Runtime/Utils.cs @@ -109,6 +109,29 @@ public static ParticleSystem.Particle[] GetParticleArray(int size) return s_TmpParticles; } + public static void ValidateShape(this ParticleSystem self) + { + var shape = self.shape; + if (shape.enabled && shape.alignToDirection) + { + if (Mathf.Approximately(shape.scale.x * shape.scale.y * shape.scale.z, 0)) + { + if (Mathf.Approximately(shape.scale.x, 0)) + { + shape.scale.Set(0.0001f, shape.scale.y, shape.scale.z); + } + else if (Mathf.Approximately(shape.scale.y, 0)) + { + shape.scale.Set(shape.scale.x, 0.0001f, shape.scale.z); + } + else if (Mathf.Approximately(shape.scale.z, 0)) + { + shape.scale.Set(shape.scale.x, shape.scale.y, 0.0001f); + } + } + } + } + public static bool CanBakeMesh(this ParticleSystemRenderer self) { // #69: Editor crashes when mesh is set to null when `ParticleSystem.RenderMode = Mesh`