Browse Source

Code cleanup

vpenades 2 years ago
parent
commit
6654a4811a

+ 7 - 2
src/SharpGLTF.Runtime/Runtime/MeshDecoder.Schema2.cs

@@ -61,7 +61,9 @@ namespace SharpGLTF.Runtime
         {
             if (_Primitives.Length == 0) return;
 
-            var geometries = _Primitives.Select(item => item._Geometry);
+            var geometries = _Primitives
+                .Select(item => item._Geometry)
+                .ToList();
 
             // we can only skip normals and tangents calculation if all the
             // primitives have them. If we get a case in wich some primitives
@@ -77,9 +79,12 @@ namespace SharpGLTF.Runtime
 
             var morphTargetsCount = _Primitives.Min(item => item.MorphTargetsCount);
 
+            var targets = new List<_MorphTargetDecoder>();
+
             for (int i = 0; i < morphTargetsCount; ++i)
             {
-                var targets = _Primitives.Select(item => item._MorphTargets[i]);
+                targets.Clear();
+                targets.AddRange(_Primitives.Select(item => item._MorphTargets[i]));
 
                 hasNormals = targets.All(item => item.HasNormals);
                 hasTangents = targets.All(item => item.HasTangents);

+ 2 - 0
src/SharpGLTF.Runtime/Runtime/VertexNormalsFactory.cs

@@ -50,6 +50,8 @@ namespace SharpGLTF.Runtime
         {
             Guard.NotNull(primitives, nameof(primitives));
 
+            primitives = primitives.EnsureList();
+
             var normalMap = new Dictionary<Vector3, Vector3>();
 
             // calculate

+ 2 - 0
src/SharpGLTF.Runtime/Runtime/VertexTangentsFactory.cs

@@ -70,6 +70,8 @@ namespace SharpGLTF.Runtime
         {
             Guard.NotNull(primitives, nameof(primitives));
 
+            primitives = primitives.EnsureList();
+
             var tangentsMap = new Dictionary<VERTEXKEY, (Vector3 u, Vector3 v)>();
 
             // calculate