MeshWithRenderer.FromNodes

This commit is contained in:
ousttrue 2021-01-13 16:15:58 +09:00
parent e0784c245f
commit e94276ec65
2 changed files with 21 additions and 17 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace UniGLTF
@ -15,5 +16,24 @@ namespace UniGLTF
Mesh = x.GetSharedMesh();
Renderer = x.GetComponent<Renderer>();
}
public static IEnumerable<MeshWithRenderer> FromNodes(IEnumerable<Transform> nodes)
{
foreach (var node in nodes)
{
var x = new MeshWithRenderer(node);
if (x.Mesh == null)
{
continue; ;
}
if (x.Renderer.sharedMaterials == null
|| x.Renderer.sharedMaterials.Length == 0)
{
continue;
}
yield return x;
}
}
}
}

View File

@ -252,23 +252,7 @@ namespace UniGLTF
#endregion
#region Meshes
var unityMeshes = Nodes
.Select(x => new MeshWithRenderer(x))
.Where(x =>
{
if (x.Mesh == null)
{
return false;
}
if (x.Renderer.sharedMaterials == null
|| x.Renderer.sharedMaterials.Length == 0)
{
return false;
}
return true;
})
.ToList();
var unityMeshes = MeshWithRenderer.FromNodes(Nodes).ToList();
MeshBlendShapeIndexMap = new Dictionary<Mesh, Dictionary<int, int>>();
foreach (var (mesh, gltfMesh, blendShapeIndexMap) in MeshExporter.ExportMeshes(