Skip to content

Commit

Permalink
fix: fix abnormal mesh bounds error
Browse files Browse the repository at this point in the history
close #213
  • Loading branch information
wmltogether authored and mob-sakai committed Jan 24, 2024
1 parent 93d3919 commit 772bf50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions Packages/src/Runtime/UIParticleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions Packages/src/Runtime/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 772bf50

Please sign in to comment.