فهرست منبع

+progress in sparse accessor handling

Vicente Penades 7 سال پیش
والد
کامیت
ff38fce0aa

+ 2 - 13
src/glTF2Sharp.DOM/Debug/DebugViews.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Numerics;
 using System.Text;
 
 namespace glTF2Sharp.Debug
@@ -48,17 +49,5 @@ namespace glTF2Sharp.Debug
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
         public Schema2.Accessor[] Accessors => _Value.Accessors.ToArray();
-    }
-
-    [System.Diagnostics.DebuggerDisplay("{_Value.Count}")]
-    internal sealed class _MemoryAccessorDebugView<T>
-        where T:unmanaged
-    {
-        public _MemoryAccessorDebugView(Memory.IAccessor<T> value) { _Value = value; }        
-
-        private readonly Memory.IAccessor<T> _Value;
-
-        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
-        public T[] Accessors => _Value.ToArray();
-    }
+    }    
 }

+ 1 - 1
src/glTF2Sharp.DOM/Memory/Accessors.cs

@@ -5,7 +5,7 @@ using System.Numerics;
 using System.Text;
 
 namespace glTF2Sharp.Memory
-{
+{    
     public interface IAccessor<T> : IReadOnlyCollection<T>
         where T : unmanaged
     {        

+ 53 - 11
src/glTF2Sharp.DOM/Memory/FloatingAccessors.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Text;
 using System.Numerics;
 using System.Collections;
+using System.Linq;
 
 namespace glTF2Sharp.Memory
 {    
@@ -188,7 +189,7 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Single Scalar values
     /// </summary>
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Single>))]
+    [System.Diagnostics.DebuggerDisplay("Scalar Accessor {Count}")]
     public struct ScalarAccessor : IAccessor<Single>
     {
         #region constructors
@@ -206,13 +207,20 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Single[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Accesor.ByteLength / _ByteStride;
         
         public Single this[int index]
@@ -236,8 +244,8 @@ namespace glTF2Sharp.Memory
 
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Vector2 values
-    /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Vector2>))]
+    /// </summary>    
+    [System.Diagnostics.DebuggerDisplay("Vector2 Accessor {Count}")]
     public struct Vector2Accessor : IAccessor<Vector2>
     {
         #region constructors
@@ -255,9 +263,15 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Vector2[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
@@ -295,8 +309,8 @@ namespace glTF2Sharp.Memory
 
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Vector3 values
-    /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Vector3>))]
+    /// </summary>    
+    [System.Diagnostics.DebuggerDisplay("Vector3 Accessor {Count}")]
     public struct Vector3Accessor: IAccessor<Vector3>
     {
         #region constructors
@@ -314,13 +328,20 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Vector3[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Accesor.ByteLength / _ByteStride;
 
         public Vector3 this[int index]
@@ -355,8 +376,8 @@ namespace glTF2Sharp.Memory
 
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Vector4 values
-    /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Vector4>))]
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("Vector4 Accessor {Count}")]
     public struct Vector4Accessor: IAccessor<Vector4>
     {
         #region constructors
@@ -374,13 +395,20 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Vector4[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Accesor.ByteLength / _ByteStride;
 
         public Vector4 this[int index]
@@ -416,8 +444,8 @@ namespace glTF2Sharp.Memory
 
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Quaternion values
-    /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Quaternion>))]
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("Quaternion Accessor {Count}")]
     public struct QuaternionAccessor : IAccessor<Quaternion>
     {
         #region constructors
@@ -435,13 +463,20 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Quaternion[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Accesor.ByteLength / _ByteStride;
 
         public Quaternion this[int index]
@@ -477,8 +512,8 @@ namespace glTF2Sharp.Memory
 
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of Matrix4x4 values
-    /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<Matrix4x4>))]
+    /// </summary>
+    [System.Diagnostics.DebuggerDisplay("MAtrix4x4 Accessor {Count}")]
     public struct Matrix4x4Accessor : IAccessor<Matrix4x4>
     {
         #region constructors
@@ -496,13 +531,20 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private FloatingAccessor _Accesor;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private Matrix4x4[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Accesor.ByteLength / _ByteStride;
 
         public Matrix4x4 this[int index]

+ 13 - 1
src/glTF2Sharp.DOM/Memory/IntegerAccessor.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Text;
 using System.Collections;
+using System.Linq;
 
 namespace glTF2Sharp.Memory
 {    
@@ -12,7 +13,7 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps an encoded byte array and exposes it as a collection of UInt32 indices
     /// </summary
-    [System.Diagnostics.DebuggerTypeProxy(typeof(Debug._MemoryAccessorDebugView<UInt32>))]
+    [System.Diagnostics.DebuggerDisplay("Integer Accessor {Count}")]
     public struct IntegerAccessor : IAccessor<UInt32>
     {
         #region constructors
@@ -77,15 +78,26 @@ namespace glTF2Sharp.Memory
 
         delegate void _SetterCallback(int index, UInt32 value);
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly BYTES _Data;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly int _ByteStride;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly _GetterCallback _Getter;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly _SetterCallback _Setter;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private UInt32[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         public int Count => _Data.Count / _ByteStride;
 
         public UInt32 this[int index]

+ 14 - 3
src/glTF2Sharp.DOM/Memory/SparseAccesor.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
 
 namespace glTF2Sharp.Memory
@@ -9,6 +10,7 @@ namespace glTF2Sharp.Memory
     /// Special accessor to wrap over a base accessor and a sparse accessor
     /// </summary>
     /// <typeparam name="T"></typeparam>
+    [System.Diagnostics.DebuggerDisplay("Sparse {typeof(T).Name} Accessor {Count}")]
     public struct SparseAccessor<T> : IAccessor<T>
         where T : unmanaged
     {
@@ -31,14 +33,25 @@ namespace glTF2Sharp.Memory
 
         #region data
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly IAccessor<T> _BottomItems;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly IAccessor<T> _TopItems;
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly Dictionary<int, int> _Mapping;
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.RootHidden)]
+        private T[] _DebugItems => this.ToArray();
+
         #endregion
 
         #region API
 
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        public int Count => _BottomItems.Count;
+
         public T this[int index]
         {
             get => _Mapping.TryGetValue(index, out int topIndex) ? _TopItems[topIndex] : _BottomItems[index];
@@ -46,9 +59,7 @@ namespace glTF2Sharp.Memory
             {
                 if (_Mapping.TryGetValue(index, out int topIndex)) _TopItems[topIndex] = value;
             }
-        }
-
-        public int Count => _BottomItems.Count;
+        }        
 
         public void CopyTo(ArraySegment<T> dst) { AccessorsUtils.Copy(this, dst); }
 

+ 9 - 29
src/glTF2Sharp.Tests/Schema2/AccessorSparseTests.cs

@@ -11,39 +11,19 @@ namespace glTF2Sharp.Schema2
     public class AccessorSparseTests
     {
         [Test]
-        public void LoadMorphCubeModel()
+        public void LoadSparseModels()
         {
-            foreach (var path in TestFiles.GetGeneratedFilePaths())
-            {
-                var model = ModelRoot.Load(path);
-                Assert.NotNull(model);
-
-                var primitives = model.LogicalMeshes
-                    .SelectMany(item => item.Primitives)
-                    .Where(item => item.MorpthTargets > 0);
-                
-                foreach (var primitive in primitives)
-                {
-                    var basePositions = primitive.GetVertexAccessor("POSITION").CastToVector3Accessor();
-
-                    for (int i = 0; i < primitive.MorpthTargets; ++i)
-                    {
-                        var morphs = primitive.GetMorphTargetAccessors(i);
-                        Assert.NotNull(morphs);
-
-                        var morphPositions = morphs["POSITION"].CastToVector3Accessor();
+            var path = TestFiles.GetSampleFilePaths().FirstOrDefault(item => item.Contains("SimpleSparseAccessor.gltf"));
+            
+            var model = ModelRoot.Load(path);
+            Assert.NotNull(model);
 
-                        // Assert.AreEqual(basePositions.Count, morphPositions.Count);
+            var primitive = model.LogicalMeshes[0].Primitives[0];
 
-                        if (morphs["POSITION"].IsSparse)
-                        {
-                            TestContext.WriteLine($"{path}");
-                        }
-                    }
-                }                
-            }
+            var accessor = primitive.GetVertexAccessor("POSITION");
 
-            
+            var basePositions = accessor.CastToVector3Accessor(false);
+            var goodPositions = accessor.CastToVector3Accessor(true);
         }
     }
 }