Skip to content

Commit

Permalink
fixes #133 - make sure the topology are triangles for calculating nor…
Browse files Browse the repository at this point in the history
…mals/tangents
  • Loading branch information
pfcDorn committed Feb 27, 2024
1 parent 899776f commit 5fc3fd5
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions Runtime/Scripts/SceneImporter/ImporterMeshes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,31 @@ private async Task MeshOptDecodeBuffer(GLTFRoot root)

protected void ApplyImportOptionsOnMesh(Mesh mesh)
{
if (_options.ImportNormals == GLTFImporterNormals.None)
mesh.normals = new Vector3[0];
else if (_options.ImportNormals == GLTFImporterNormals.Calculate && mesh.GetTopology(0) == MeshTopology.Triangles)
mesh.RecalculateNormals();
else if (_options.ImportNormals == GLTFImporterNormals.Import && mesh.normals.Length == 0 && mesh.GetTopology(0) == MeshTopology.Triangles)
mesh.RecalculateNormals();
else if (_options.ImportTangents != GLTFImporterNormals.None && mesh.normals.Length == 0)
mesh.RecalculateNormals();
bool isTrinagleTopology = mesh.GetTopology(0) == MeshTopology.Triangles;

if (_options.ImportNormals == GLTFImporterNormals.None)
mesh.normals = Array.Empty<Vector3>();
else
if (isTrinagleTopology)
{
if (_options.ImportNormals == GLTFImporterNormals.Calculate)
mesh.RecalculateNormals();
else if (_options.ImportNormals == GLTFImporterNormals.Import && mesh.normals.Length == 0)
mesh.RecalculateNormals();
else if (_options.ImportTangents != GLTFImporterNormals.None && mesh.normals.Length == 0)
mesh.RecalculateNormals();
}

if (_options.ImportTangents == GLTFImporterNormals.None)
mesh.tangents = new Vector4[0];
else if (_options.ImportTangents == GLTFImporterNormals.Calculate && mesh.GetTopology(0) == MeshTopology.Triangles)
mesh.RecalculateTangents();
else if (_options.ImportTangents == GLTFImporterNormals.Import && mesh.tangents.Length == 0 && mesh.GetTopology(0) == MeshTopology.Triangles)
mesh.RecalculateTangents();
mesh.tangents = Array.Empty<Vector4>();
else
if (isTrinagleTopology)
{
if (_options.ImportTangents == GLTFImporterNormals.Calculate)
mesh.RecalculateTangents();
else if (_options.ImportTangents == GLTFImporterNormals.Import && mesh.tangents.Length == 0)
mesh.RecalculateTangents();
}

if (_options.SwapUVs)
{
Expand Down

0 comments on commit 5fc3fd5

Please sign in to comment.