Skip to content

Commit 7f7b773

Browse files
committed
fix(simplifier): options for uv component count
1 parent 6fcb6da commit 7f7b773

2 files changed

Lines changed: 37 additions & 56 deletions

File tree

Runtime/LODGenerator.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -607,22 +607,9 @@ private static void CollectChildRenderersForLOD(Transform transform, List<Render
607607

608608
private static Mesh SimplifyMesh(Mesh mesh, float quality, SimplificationOptions options)
609609
{
610-
int uvComponentCount = -1;
611-
if (options.ManualUVComponentCount)
612-
{
613-
uvComponentCount = options.UVComponentCount;
614-
}
615-
616610
var meshSimplifier = new MeshSimplifier();
617-
meshSimplifier.PreserveBorderEdges = options.PreserveBorderEdges;
618-
meshSimplifier.PreserveUVSeamEdges = options.PreserveUVSeamEdges;
619-
meshSimplifier.PreserveUVFoldoverEdges = options.PreserveUVFoldoverEdges;
620-
meshSimplifier.PreserveSurfaceCurvature = options.PreserveSurfaceCurvature;
621-
meshSimplifier.EnableSmartLink = options.EnableSmartLink;
622-
meshSimplifier.VertexLinkDistance = options.VertexLinkDistance;
623-
meshSimplifier.MaxIterationCount = options.MaxIterationCount;
624-
meshSimplifier.Agressiveness = options.Agressiveness;
625-
meshSimplifier.Initialize(mesh, uvComponentCount);
611+
meshSimplifier.SimplificationOptions = options;
612+
meshSimplifier.Initialize(mesh);
626613
meshSimplifier.SimplifyMesh(quality);
627614

628615
var simplifiedMesh = meshSimplifier.ToMesh();

Runtime/MeshSimplifier.cs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,27 +1992,19 @@ public void AddBlendShapes(BlendShape[] blendShapes)
19921992
#region Initialize
19931993
/// <summary>
19941994
/// Initializes the algorithm with the original mesh.
1995-
/// Will automatically detect the count of UV components used on the mesh.
19961995
/// </summary>
19971996
/// <param name="mesh">The mesh.</param>
19981997
public void Initialize(Mesh mesh)
1999-
{
2000-
Initialize(mesh, -1);
2001-
}
2002-
2003-
/// <summary>
2004-
/// Initializes the algorithm with the original mesh.
2005-
/// </summary>
2006-
/// <param name="mesh">The mesh.</param>
2007-
/// <param name="uvComponentCount">The count of UV components that are used on the mesh.
2008-
/// -1 means that it will be automatically detected.
2009-
/// Note that all UV channels would use the same UV component count.</param>
2010-
public void Initialize(Mesh mesh, int uvComponentCount)
20111998
{
20121999
if (mesh == null)
20132000
throw new ArgumentNullException(nameof(mesh));
2014-
if (uvComponentCount < -1 || uvComponentCount > 4)
2015-
throw new ArgumentOutOfRangeException(nameof(uvComponentCount));
2001+
2002+
int uvComponentCount = simplificationOptions.UVComponentCount;
2003+
if (simplificationOptions.ManualUVComponentCount)
2004+
{
2005+
if (uvComponentCount < 0 || uvComponentCount > 4)
2006+
throw new InvalidOperationException("The UV component count cannot be below 0 or above 4.");
2007+
}
20162008

20172009
this.Vertices = mesh.vertices;
20182010
this.Normals = mesh.normals;
@@ -2024,33 +2016,35 @@ public void Initialize(Mesh mesh, int uvComponentCount)
20242016

20252017
for (int channel = 0; channel < UVChannelCount; channel++)
20262018
{
2027-
switch (uvComponentCount)
2019+
if (simplificationOptions.ManualUVComponentCount)
20282020
{
2029-
case -1:
2030-
{
2031-
var uvs = MeshUtils.GetMeshUVs(mesh, channel);
2032-
SetUVsAuto(channel, uvs);
2033-
break;
2034-
}
2035-
case 1:
2036-
case 2:
2037-
{
2038-
var uvs = MeshUtils.GetMeshUVs2D(mesh, channel);
2039-
SetUVs(channel, uvs);
2040-
break;
2041-
}
2042-
case 3:
2043-
{
2044-
var uvs = MeshUtils.GetMeshUVs3D(mesh, channel);
2045-
SetUVs(channel, uvs);
2046-
break;
2047-
}
2048-
case 4:
2049-
{
2050-
var uvs = MeshUtils.GetMeshUVs(mesh, channel);
2051-
SetUVs(channel, uvs);
2052-
break;
2053-
}
2021+
switch (uvComponentCount)
2022+
{
2023+
case 1:
2024+
case 2:
2025+
{
2026+
var uvs = MeshUtils.GetMeshUVs2D(mesh, channel);
2027+
SetUVs(channel, uvs);
2028+
break;
2029+
}
2030+
case 3:
2031+
{
2032+
var uvs = MeshUtils.GetMeshUVs3D(mesh, channel);
2033+
SetUVs(channel, uvs);
2034+
break;
2035+
}
2036+
case 4:
2037+
{
2038+
var uvs = MeshUtils.GetMeshUVs(mesh, channel);
2039+
SetUVs(channel, uvs);
2040+
break;
2041+
}
2042+
}
2043+
}
2044+
else
2045+
{
2046+
var uvs = MeshUtils.GetMeshUVs(mesh, channel);
2047+
SetUVsAuto(channel, uvs);
20542048
}
20552049
}
20562050

0 commit comments

Comments
 (0)