Просмотр исходного кода

refactored memory accessors as arrays to distinguish from schema2.accessors

Vicente Penades 6 лет назад
Родитель
Сommit
d6c553ce01

+ 3 - 0
README.md

@@ -47,3 +47,6 @@ The current status of the library is preview alpha, but, for some cases it is pr
 - [ ] [EXT_texture_webp](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp)
 - [ ] [ADOBE_materials_thin_transparency](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/ADOBE_materials_thin_transparency)
 
+#### Alternative glTF2 c# libraries
+- [Khronos Group glTF-CSharp-Loader](https://github.com/KhronosGroup/glTF-CSharp-Loader)
+- [Khronos Group UnityGLTF](https://github.com/KhronosGroup/UnityGLTF)

+ 21 - 21
src/glTF2Sharp.DOM/Memory/Accessors.cs → src/glTF2Sharp.DOM/Memory/Arrays.cs

@@ -6,7 +6,7 @@ using System.Text;
 
 namespace glTF2Sharp.Memory
 {    
-    public interface IAccessor<T> : IReadOnlyCollection<T>
+    public interface IEncodedArray<T> : IReadOnlyCollection<T>
         where T : unmanaged
     {        
         T this[int index] { get; set; }
@@ -21,7 +21,7 @@ namespace glTF2Sharp.Memory
     {
         #region lifecycle        
 
-        public AccessorEnumerator(IAccessor<T> accessor)
+        public AccessorEnumerator(IEncodedArray<T> accessor)
         {
             this._Accessor = accessor;
             this._Count = accessor.Count;
@@ -37,7 +37,7 @@ namespace glTF2Sharp.Memory
 
         #region data
 
-        private readonly IAccessor<T> _Accessor;
+        private readonly IEncodedArray<T> _Accessor;
         private readonly int _Count;
         private int _Index;
 
@@ -65,18 +65,18 @@ namespace glTF2Sharp.Memory
 
     public static class AccessorsUtils
     {
-        public static void Copy<T>(IAccessor<T> src, T[] dst) where T : unmanaged
+        public static void Copy<T>(IEncodedArray<T> src, T[] dst) where T : unmanaged
         {
             Copy<T>(src, new ArraySegment<T>(dst));
         }
 
-        public static void Copy<T>(IAccessor<T> src, ArraySegment<T> dst) where T : unmanaged
+        public static void Copy<T>(IEncodedArray<T> src, ArraySegment<T> dst) where T : unmanaged
         {
             var c = src.Count;
             for (int i = 0; i < c; ++i) dst.Array[dst.Offset + i] = src[i];
         }                
 
-        public static (Single, Single) GetBounds(ScalarAccessor accesor)
+        public static (Single, Single) GetBounds(ScalarArray accesor)
         {
             var min = Single.MaxValue;
             var max = Single.MinValue;
@@ -92,7 +92,7 @@ namespace glTF2Sharp.Memory
             return (min, max);
         }
 
-        public static (Vector2, Vector2) GetBounds(Vector2Accessor accesor)
+        public static (Vector2, Vector2) GetBounds(Vector2Array accesor)
         {
             var min = new Vector2(Single.MaxValue);
             var max = new Vector2(Single.MinValue);
@@ -108,7 +108,7 @@ namespace glTF2Sharp.Memory
             return (min, max);
         }
 
-        public static (Vector3, Vector3) GetBounds(Vector3Accessor accesor)
+        public static (Vector3, Vector3) GetBounds(Vector3Array accesor)
         {
             var min = new Vector3(Single.MaxValue);
             var max = new Vector3(Single.MinValue);
@@ -124,7 +124,7 @@ namespace glTF2Sharp.Memory
             return (min, max);
         }
 
-        public static (Vector4, Vector4) GetBounds(IAccessor<Vector4> accesor)
+        public static (Vector4, Vector4) GetBounds(IEncodedArray<Vector4> accesor)
         {
             var min = new Vector4(Single.MaxValue);
             var max = new Vector4(Single.MinValue);
@@ -145,14 +145,14 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps a collection of Scalar values and exposes it as a collection of Vector4 values
     /// </summary>
-    struct _MapScalarToVector4 : IAccessor<Vector4>
+    struct _MapScalarToVector4 : IEncodedArray<Vector4>
     {
-        public _MapScalarToVector4(ScalarAccessor source)
+        public _MapScalarToVector4(ScalarArray source)
         {
             _Accessor = source;
         }
 
-        private ScalarAccessor _Accessor;
+        private ScalarArray _Accessor;
 
         public int Count => _Accessor.Count;
 
@@ -174,14 +174,14 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps a collection of Vector2 values and exposes it as a collection of Vector4 values
     /// </summary>
-    struct _MapVector2ToVector4 : IAccessor<Vector4>
+    struct _MapVector2ToVector4 : IEncodedArray<Vector4>
     {
-        public _MapVector2ToVector4(Vector2Accessor source)
+        public _MapVector2ToVector4(Vector2Array source)
         {
             _Accessor = source;
         }
 
-        private Vector2Accessor _Accessor;
+        private Vector2Array _Accessor;
 
         public int Count => _Accessor.Count;
 
@@ -203,14 +203,14 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps a collection of Vector3 values and exposes it as a collection of Vector4 values
     /// </summary>
-    struct _MapVector3ToVector4 : IAccessor<Vector4>
+    struct _MapVector3ToVector4 : IEncodedArray<Vector4>
     {
-        public _MapVector3ToVector4(Vector3Accessor source)
+        public _MapVector3ToVector4(Vector3Array source)
         {
             _Accessor = source;
         }
 
-        private Vector3Accessor _Accessor;
+        private Vector3Array _Accessor;
 
         public int Count => _Accessor.Count;
 
@@ -232,14 +232,14 @@ namespace glTF2Sharp.Memory
     /// <summary>
     /// Wraps a collection of Quaternion values and exposes it as a collection of Vector4 values
     /// </summary>
-    struct _MapQuaternionToVector4 : IAccessor<Vector4>
+    struct _MapQuaternionToVector4 : IEncodedArray<Vector4>
     {
-        public _MapQuaternionToVector4(QuaternionAccessor source)
+        public _MapQuaternionToVector4(QuaternionArray source)
         {
             _Accessor = source;
         }
 
-        private QuaternionAccessor _Accessor;
+        private QuaternionArray _Accessor;
 
         public int Count => _Accessor.Count;
 

+ 23 - 23
src/glTF2Sharp.DOM/Memory/FloatingAccessors.cs → src/glTF2Sharp.DOM/Memory/FloatingArrays.cs

@@ -190,14 +190,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Single Scalar values
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Scalar Accessor {Count}")]
-    public struct ScalarAccessor : IAccessor<Single>
+    public struct ScalarArray : IEncodedArray<Single>
     {
         #region constructors
 
-        public ScalarAccessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public ScalarArray(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data), byteStride, encoding, normalized) { }
 
-        public ScalarAccessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public ScalarArray(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 1, byteStride);
@@ -237,7 +237,7 @@ namespace glTF2Sharp.Memory
 
         public (Single, Single) GetBounds() { return AccessorsUtils.GetBounds(this); }
 
-        public IAccessor<Vector4> AsVector4() { return new _MapScalarToVector4(this); }        
+        public IEncodedArray<Vector4> AsVector4() { return new _MapScalarToVector4(this); }        
 
         #endregion
     }
@@ -246,14 +246,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Vector2 values
     /// </summary>    
     [System.Diagnostics.DebuggerDisplay("Vector2 Accessor {Count}")]
-    public struct Vector2Accessor : IAccessor<Vector2>
+    public struct Vector2Array : IEncodedArray<Vector2>
     {
         #region constructors
 
-        public Vector2Accessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector2Array(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data),byteStride,encoding,normalized) { }
         
-        public Vector2Accessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector2Array(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 2, byteStride);
@@ -302,7 +302,7 @@ namespace glTF2Sharp.Memory
 
         public (Vector2, Vector2) GetBounds() { return AccessorsUtils.GetBounds(this); }
 
-        public IAccessor<Vector4> AsVector4() { return new _MapVector2ToVector4(this); }        
+        public IEncodedArray<Vector4> AsVector4() { return new _MapVector2ToVector4(this); }        
 
         #endregion
     }
@@ -311,14 +311,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Vector3 values
     /// </summary>    
     [System.Diagnostics.DebuggerDisplay("Vector3 Accessor {Count}")]
-    public struct Vector3Accessor: IAccessor<Vector3>
+    public struct Vector3Array: IEncodedArray<Vector3>
     {
         #region constructors
 
-        public Vector3Accessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector3Array(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data), byteStride, encoding, normalized) { }
 
-        public Vector3Accessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector3Array(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 3, byteStride);
@@ -369,7 +369,7 @@ namespace glTF2Sharp.Memory
 
         public (Vector3, Vector3) GetBounds() { return AccessorsUtils.GetBounds(this); }
 
-        public IAccessor<Vector4> AsVector4() { return new _MapVector3ToVector4(this); }
+        public IEncodedArray<Vector4> AsVector4() { return new _MapVector3ToVector4(this); }
 
         #endregion
     }
@@ -378,14 +378,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Vector4 values
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Vector4 Accessor {Count}")]
-    public struct Vector4Accessor: IAccessor<Vector4>
+    public struct Vector4Array: IEncodedArray<Vector4>
     {
         #region constructors
 
-        public Vector4Accessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector4Array(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data), byteStride, encoding, normalized) { }
 
-        public Vector4Accessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Vector4Array(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 4, byteStride);
@@ -437,7 +437,7 @@ namespace glTF2Sharp.Memory
 
         public (Vector4, Vector4) GetBounds() { return AccessorsUtils.GetBounds(this); }
 
-        public IAccessor<Vector4> AsVector4() { return this; }
+        public IEncodedArray<Vector4> AsVector4() { return this; }
 
         #endregion
     }
@@ -446,14 +446,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Quaternion values
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("Quaternion Accessor {Count}")]
-    public struct QuaternionAccessor : IAccessor<Quaternion>
+    public struct QuaternionArray : IEncodedArray<Quaternion>
     {
         #region constructors
 
-        public QuaternionAccessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public QuaternionArray(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data), byteStride, encoding, normalized) { }
 
-        public QuaternionAccessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public QuaternionArray(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 4, byteStride);
@@ -505,7 +505,7 @@ namespace glTF2Sharp.Memory
 
         public (Quaternion, Quaternion) GetBounds() { throw new NotImplementedException(); }
 
-        public IAccessor<Vector4> AsVector4() { return new _MapQuaternionToVector4(this); }
+        public IEncodedArray<Vector4> AsVector4() { return new _MapQuaternionToVector4(this); }
 
         #endregion
     }
@@ -514,14 +514,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of Matrix4x4 values
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("MAtrix4x4 Accessor {Count}")]
-    public struct Matrix4x4Accessor : IAccessor<Matrix4x4>
+    public struct Matrix4x4Array : IEncodedArray<Matrix4x4>
     {
         #region constructors
 
-        public Matrix4x4Accessor(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Matrix4x4Array(Byte[] data, int byteStride, ENCODING encoding, Boolean normalized)
             : this(new BYTES(data), byteStride, encoding, normalized) { }
 
-        public Matrix4x4Accessor(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
+        public Matrix4x4Array(BYTES data, int byteStride, ENCODING encoding, Boolean normalized)
         {
             _Accesor = new FloatingAccessor(data, encoding, normalized);
             _ByteStride = Math.Max(encoding.ByteLength() * 16, byteStride);

+ 3 - 3
src/glTF2Sharp.DOM/Memory/IntegerAccessor.cs → src/glTF2Sharp.DOM/Memory/IntegerArrays.cs

@@ -14,14 +14,14 @@ namespace glTF2Sharp.Memory
     /// Wraps an encoded byte array and exposes it as a collection of UInt32 indices
     /// </summary
     [System.Diagnostics.DebuggerDisplay("Integer Accessor {Count}")]
-    public struct IntegerAccessor : IAccessor<UInt32>
+    public struct IntegerArray : IEncodedArray<UInt32>
     {
         #region constructors
 
-        public IntegerAccessor(Byte[] data, ENCODING encoding)
+        public IntegerArray(Byte[] data, ENCODING encoding)
             : this(new BYTES(data), encoding) { }
 
-        public IntegerAccessor(BYTES data, ENCODING encoding)
+        public IntegerArray(BYTES data, ENCODING encoding)
         {
             _Data = data;
             _ByteStride = encoding.ByteLength();

+ 4 - 4
src/glTF2Sharp.DOM/Memory/SparseAccesor.cs → src/glTF2Sharp.DOM/Memory/SparseArrays.cs

@@ -11,12 +11,12 @@ namespace glTF2Sharp.Memory
     /// </summary>
     /// <typeparam name="T"></typeparam>
     [System.Diagnostics.DebuggerDisplay("Sparse {typeof(T).Name} Accessor {Count}")]
-    public struct SparseAccessor<T> : IAccessor<T>
+    public struct SparseArray<T> : IEncodedArray<T>
         where T : unmanaged
     {
         #region lifecycle
 
-        public SparseAccessor(IAccessor<T> bottom, IAccessor<T> top, IntegerAccessor topMapping)
+        public SparseArray(IEncodedArray<T> bottom, IEncodedArray<T> top, IntegerArray topMapping)
         {
             _BottomItems = bottom;
             _TopItems = top;
@@ -34,10 +34,10 @@ namespace glTF2Sharp.Memory
         #region data
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private readonly IAccessor<T> _BottomItems;
+        private readonly IEncodedArray<T> _BottomItems;
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private readonly IAccessor<T> _TopItems;
+        private readonly IEncodedArray<T> _TopItems;
 
         [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
         private readonly Dictionary<int, int> _Mapping;

+ 6 - 15
src/glTF2Sharp.DOM/README.md

@@ -1,8 +1,5 @@
 # glTF2 Sharp
 
-This is my personal attempt to create a c# library to parse and also build
-Khronos glTF2 files.
-
 #### Development
 
 The bulk of the code is generated from the schema using the glTF2Sharp.CodeGen tools.
@@ -16,14 +13,6 @@ and cross referencing is done by integer indices. The public API implentation tr
 to simplify model access by resolving the references and offering a more C# friendly
 API.
 
-#### Extensions
-
-Extensions support is experimental, and at best it will be implemented on extensions that
-can be included seamlessly.
-
-Then, there's extensions like Draco, which relies on [Google's DRACO](https://github.com/google/draco)
-library which is a highly optimized C++ Library.
-
 #### Examples
 
 Many examples can be found in the Tests project, but in essence, loading a model
@@ -33,7 +22,9 @@ is as easy as this:
 var model = Schema2.ModelRoot.Load("model.gltf");
 ```
 
-#### Alternative glTF2 c# libraries
-- [Khronos Group glTF-CSharp-Loader](https://github.com/KhronosGroup/glTF-CSharp-Loader)
-- [Khronos Group UnityGLTF](https://github.com/KhronosGroup/UnityGLTF)
-- [glTF viewer using SharpDX](https://github.com/ousttrue/DXGLTF)
+Loading a gltf and saving it as glb:
+```c#
+var model = Schema2.ModelRoot.Load("model.gltf");
+model.MergeBuffers(); // this is required since glb only supports a single binary buffer.
+model.SaveGLB("model.glb");
+```

+ 30 - 30
src/glTF2Sharp.DOM/Schema2/gltf.AccessorSparse.cs

@@ -36,40 +36,40 @@ namespace glTF2Sharp.Schema2
 
         public int Count => _count; // what is this!?? TODO: check with specs        
 
-        public Memory.SparseAccessor<Single> GetScalarAccesor(Accessor baseAccessor)
+        public Memory.SparseArray<Single> GetScalarArray(Accessor baseAccessor)
         {
-            var bot = baseAccessor.CastToScalarAccessor(false);
-            var top = this._values.CastToScalarAccessor(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
-            var idx = this._indices.CastToIndicesAccessor(baseAccessor.LogicalParent);
+            var bot = baseAccessor.AsScalarArray(false);
+            var top = this._values.GetScalarArray(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
+            var idx = this._indices.GetIndicesArray(baseAccessor.LogicalParent);
 
-            return new Memory.SparseAccessor<Single>(bot, top, idx);
+            return new Memory.SparseArray<Single>(bot, top, idx);
         }
 
-        public Memory.SparseAccessor<Vector2> GetVector2Accesor(Accessor baseAccessor)
+        public Memory.SparseArray<Vector2> GetVector2Array(Accessor baseAccessor)
         {
-            var bot = baseAccessor.CastToVector2Accessor(false);
-            var top = this._values.CastToVector2Accessor(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
-            var idx = this._indices.CastToIndicesAccessor(baseAccessor.LogicalParent);
+            var bot = baseAccessor.AsVector2Array(false);
+            var top = this._values.GetVector2Array(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
+            var idx = this._indices.GetIndicesArray(baseAccessor.LogicalParent);
 
-            return new Memory.SparseAccessor<Vector2>(bot, top, idx);
+            return new Memory.SparseArray<Vector2>(bot, top, idx);
         }
 
-        public Memory.SparseAccessor<Vector3> GetVector3Accesor(Accessor baseAccessor)
+        public Memory.SparseArray<Vector3> GetVector3Array(Accessor baseAccessor)
         {
-            var bot = baseAccessor.CastToVector3Accessor(false);
-            var top = this._values.CastToVector3Accessor(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
-            var idx = this._indices.CastToIndicesAccessor(baseAccessor.LogicalParent);
+            var bot = baseAccessor.AsVector3Array(false);
+            var top = this._values.GetVector3Array(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
+            var idx = this._indices.GetIndicesArray(baseAccessor.LogicalParent);
 
-            return new Memory.SparseAccessor<Vector3>(bot, top, idx);
+            return new Memory.SparseArray<Vector3>(bot, top, idx);
         }
 
-        public Memory.SparseAccessor<Vector4> GetVector4Accesor(Accessor baseAccessor)
+        public Memory.SparseArray<Vector4> GetVector4Array(Accessor baseAccessor)
         {
-            var bot = baseAccessor.CastToVector4Accessor(false);
-            var top = this._values.CastToVector4Accessor(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
-            var idx = this._indices.CastToIndicesAccessor(baseAccessor.LogicalParent);
+            var bot = baseAccessor.AsVector4Array(false);
+            var top = this._values.GetVector4Array(baseAccessor.LogicalParent, baseAccessor.Encoding, baseAccessor.Normalized);
+            var idx = this._indices.GetIndicesArray(baseAccessor.LogicalParent);
 
-            return new Memory.SparseAccessor<Vector4>(bot, top, idx);
+            return new Memory.SparseArray<Vector4>(bot, top, idx);
         }
     }
 
@@ -87,10 +87,10 @@ namespace glTF2Sharp.Schema2
             this._componentType = encoding;
         }
 
-        public Memory.IntegerAccessor CastToIndicesAccessor(ROOT root)
+        public Memory.IntegerArray GetIndicesArray(ROOT root)
         {
             var srcBuffer = root.LogicalBufferViews[this._bufferView];
-            return srcBuffer.CreateIndicesAccessor(this._byteOffset ?? 0, this._componentType);
+            return srcBuffer.CreateIndicesArray(this._byteOffset ?? 0, this._componentType);
         }        
     }
 
@@ -107,28 +107,28 @@ namespace glTF2Sharp.Schema2
             this._byteOffset = byteOffset.AsNullable(_byteOffsetDefault);            
         }
 
-        public Memory.ScalarAccessor CastToScalarAccessor(ROOT root, ComponentType encoding, Boolean normalized)
+        public Memory.ScalarArray GetScalarArray(ROOT root, ComponentType encoding, Boolean normalized)
         {
             var srcBuffer = root.LogicalBufferViews[this._bufferView];
-            return srcBuffer.CreateScalarAccessor(this._byteOffset ?? 0, encoding, normalized);
+            return srcBuffer.CreateScalarArray(this._byteOffset ?? 0, encoding, normalized);
         }
 
-        public Memory.Vector2Accessor CastToVector2Accessor(ROOT root, ComponentType encoding, Boolean normalized)
+        public Memory.Vector2Array GetVector2Array(ROOT root, ComponentType encoding, Boolean normalized)
         {
             var srcBuffer = root.LogicalBufferViews[this._bufferView];
-            return srcBuffer.CreateVector2Accessor(this._byteOffset ?? 0, encoding, normalized);
+            return srcBuffer.CreateVector2Array(this._byteOffset ?? 0, encoding, normalized);
         }
 
-        public Memory.Vector3Accessor CastToVector3Accessor(ROOT root, ComponentType encoding, Boolean normalized)
+        public Memory.Vector3Array GetVector3Array(ROOT root, ComponentType encoding, Boolean normalized)
         {
             var srcBuffer = root.LogicalBufferViews[this._bufferView];
-            return srcBuffer.CreateVector3Accessor(this._byteOffset ?? 0, encoding, normalized);
+            return srcBuffer.CreateVector3Array(this._byteOffset ?? 0, encoding, normalized);
         }
 
-        public Memory.Vector4Accessor CastToVector4Accessor(ROOT root, ComponentType encoding, Boolean normalized)
+        public Memory.Vector4Array GetVector4Array(ROOT root, ComponentType encoding, Boolean normalized)
         {
             var srcBuffer = root.LogicalBufferViews[this._bufferView];
-            return srcBuffer.CreateVector4Accessor(this._byteOffset ?? 0, encoding, normalized);
+            return srcBuffer.CreateVector4Array(this._byteOffset ?? 0, encoding, normalized);
         }
     }
 }

+ 20 - 20
src/glTF2Sharp.DOM/Schema2/gltf.Accessors.cs

@@ -88,12 +88,12 @@ namespace glTF2Sharp.Schema2
             _UpdateBounds();
         }
 
-        public Memory.Matrix4x4Accessor CastToMatrix4x4Accessor()
+        public Memory.Matrix4x4Array CastToMatrix4x4Accessor()
         {
             Guard.IsFalse(this.IsSparse, nameof(IsSparse));
             Guard.IsTrue(this.Dimensions == ElementType.MAT4, nameof(Dimensions));
 
-            return SourceBufferView.CreateMatrix4x4Accessor(this.ByteOffset, this.Encoding, this.Normalized);
+            return SourceBufferView.CreateMatrix4x4Array(this.ByteOffset, this.Encoding, this.Normalized);
         }
 
         #endregion
@@ -120,11 +120,11 @@ namespace glTF2Sharp.Schema2
             _UpdateBounds();
         }
 
-        public Memory.IntegerAccessor CastToIndicesAccessor()
+        public Memory.IntegerArray CastToIndicesAccessor()
         {
             Guard.IsFalse(this.IsSparse, nameof(IsSparse));
             Guard.IsTrue(this.Dimensions == ElementType.SCALAR, nameof(Dimensions));
-            return SourceBufferView.CreateIndicesAccessor(this.ByteOffset, this.Encoding.ToIndex());
+            return SourceBufferView.CreateIndicesArray(this.ByteOffset, this.Encoding.ToIndex());
         }
         
         #endregion
@@ -151,40 +151,40 @@ namespace glTF2Sharp.Schema2
             _UpdateBounds();
         }
 
-        public Memory.IAccessor<Single> CastToScalarAccessor(bool useSparse=true)
+        public Memory.IEncodedArray<Single> AsScalarArray(bool useSparse=true)
         {
             Guard.IsTrue(this.Dimensions == ElementType.SCALAR, nameof(Dimensions));
 
-            if (this._sparse != null && useSparse) return this._sparse.GetScalarAccesor(this);
+            if (this._sparse != null && useSparse) return this._sparse.GetScalarArray(this);
 
-            return SourceBufferView.CreateScalarAccessor(this.ByteOffset, this.Encoding, this.Normalized);            
+            return SourceBufferView.CreateScalarArray(this.ByteOffset, this.Encoding, this.Normalized);            
         }
 
-        public Memory.IAccessor<Vector2> CastToVector2Accessor(bool useSparse = true)
+        public Memory.IEncodedArray<Vector2> AsVector2Array(bool useSparse = true)
         {
             Guard.IsTrue(this.Dimensions == ElementType.VEC2, nameof(Dimensions));
 
-            if (this._sparse != null && useSparse) return this._sparse.GetVector2Accesor(this);
+            if (this._sparse != null && useSparse) return this._sparse.GetVector2Array(this);
 
-            return SourceBufferView.CreateVector2Accessor(this.ByteOffset, this.Encoding, this.Normalized);
+            return SourceBufferView.CreateVector2Array(this.ByteOffset, this.Encoding, this.Normalized);
         }
 
-        public Memory.IAccessor<Vector3> CastToVector3Accessor(bool useSparse = true)
+        public Memory.IEncodedArray<Vector3> AsVector3Array(bool useSparse = true)
         {
             Guard.IsTrue(this.Dimensions == ElementType.VEC3, nameof(Dimensions));
 
-            if (this._sparse != null && useSparse) return this._sparse.GetVector3Accesor(this);
+            if (this._sparse != null && useSparse) return this._sparse.GetVector3Array(this);
 
-            return SourceBufferView.CreateVector3Accessor(this.ByteOffset, this.Encoding, this.Normalized);
+            return SourceBufferView.CreateVector3Array(this.ByteOffset, this.Encoding, this.Normalized);
         }
 
-        public Memory.IAccessor<Vector4> CastToVector4Accessor(bool useSparse = true)
+        public Memory.IEncodedArray<Vector4> AsVector4Array(bool useSparse = true)
         {
             Guard.IsTrue(this.Dimensions == ElementType.VEC4, nameof(Dimensions));
 
-            if (this._sparse != null && useSparse) return this._sparse.GetVector4Accesor(this);
+            if (this._sparse != null && useSparse) return this._sparse.GetVector4Array(this);
 
-            return SourceBufferView.CreateVector4Accessor(this.ByteOffset, this.Encoding, this.Normalized);
+            return SourceBufferView.CreateVector4Array(this.ByteOffset, this.Encoding, this.Normalized);
         }
 
         public ArraySegment<Byte> TryGetVertexBytes(int vertexIdx)
@@ -213,7 +213,7 @@ namespace glTF2Sharp.Schema2
 
             if (count == 1)
             {
-                var minmax = this.CastToScalarAccessor().GetBounds();
+                var minmax = this.AsScalarArray().GetBounds();
 
                 this._min[0] = minmax.Item1;
                 this._max[0] = minmax.Item2;
@@ -221,7 +221,7 @@ namespace glTF2Sharp.Schema2
 
             if (count == 2)
             {
-                var minmax = this.CastToVector2Accessor().GetBounds();
+                var minmax = this.AsVector2Array().GetBounds();
 
                 this._min[0] = minmax.Item1.X;
                 this._max[0] = minmax.Item2.X;
@@ -232,7 +232,7 @@ namespace glTF2Sharp.Schema2
 
             if (count == 3)
             {
-                var minmax = this.CastToVector3Accessor().GetBounds();
+                var minmax = this.AsVector3Array().GetBounds();
 
                 this._min[0] = minmax.Item1.X;
                 this._max[0] = minmax.Item2.X;
@@ -246,7 +246,7 @@ namespace glTF2Sharp.Schema2
 
             if (count == 4)
             {
-                var minmax = this.CastToVector4Accessor().GetBounds();
+                var minmax = this.AsVector4Array().GetBounds();
 
                 this._min[0] = minmax.Item1.X;
                 this._max[0] = minmax.Item2.X;

+ 2 - 2
src/glTF2Sharp.DOM/Schema2/gltf.Buffer.cs

@@ -122,7 +122,7 @@ namespace glTF2Sharp.Schema2
         {
             var buffer = CreateBuffer(indices.Length * 4);
 
-            var accessor = new Memory.IntegerAccessor(buffer._Data, IndexType.UNSIGNED_INT);
+            var accessor = new Memory.IntegerArray(buffer._Data, IndexType.UNSIGNED_INT);
 
             for (int i = 0; i < indices.Length; ++i)
             {
@@ -136,7 +136,7 @@ namespace glTF2Sharp.Schema2
         {
             var buffer = CreateBuffer(vectors.Length * 12);
 
-            var accessor = new Memory.Vector3Accessor(new ArraySegment<byte>(buffer._Data), 0, ComponentType.FLOAT, false);
+            var accessor = new Memory.Vector3Array(new ArraySegment<byte>(buffer._Data), 0, ComponentType.FLOAT, false);
 
             for (int i = 0; i < vectors.Length; ++i)
             {

+ 15 - 29
src/glTF2Sharp.DOM/Schema2/gltf.BufferView.cs

@@ -102,55 +102,41 @@ namespace glTF2Sharp.Schema2
             return String.Join(" ", accessors.Select(item => item._DebuggerDisplay_TryIdentifyContent()));
         }
 
-        public Memory.IntegerAccessor CreateIndicesAccessor(int byteOffset, IndexType encoding)
+        public Memory.IntegerArray CreateIndicesArray(int byteOffset, IndexType encoding)
         {
             Guard.IsTrue(this.ByteStride == 0,null, "bytestride must be zero");
 
-            return new Memory.IntegerAccessor(this.Data.Slice(byteOffset), encoding);
-        }
-
-        public Memory.IAccessor<Vector4> CreateVertexAccessor(int byteOffset, ElementType dimensions, ENCODING encoding, Boolean normalized)
-        {
-            var srcData = this.Data.Slice(byteOffset);
-
-            switch (dimensions)
-            {
-                case ElementType.SCALAR: return new Memory.ScalarAccessor(srcData, this.ByteStride, encoding, normalized).AsVector4();
-                case ElementType.VEC2: return new Memory.Vector2Accessor(srcData, this.ByteStride, encoding, normalized).AsVector4();
-                case ElementType.VEC3: return new Memory.Vector3Accessor(srcData, this.ByteStride, encoding, normalized).AsVector4();
-                case ElementType.VEC4: return new Memory.Vector4Accessor(srcData, this.ByteStride, encoding, normalized);
-                default: throw new NotImplementedException();
-            }            
-        }
+            return new Memory.IntegerArray(this.Data.Slice(byteOffset), encoding);
+        }        
 
-        public Memory.ScalarAccessor CreateScalarAccessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.ScalarArray CreateScalarArray(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.ScalarAccessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);            
+            return new Memory.ScalarArray(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);            
         }
 
-        public Memory.Vector2Accessor CreateVector2Accessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.Vector2Array CreateVector2Array(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.Vector2Accessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
+            return new Memory.Vector2Array(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
         }
 
-        public Memory.Vector3Accessor CreateVector3Accessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.Vector3Array CreateVector3Array(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.Vector3Accessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
+            return new Memory.Vector3Array(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
         }
 
-        public Memory.Vector4Accessor CreateVector4Accessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.Vector4Array CreateVector4Array(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.Vector4Accessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
+            return new Memory.Vector4Array(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
         }
 
-        public Memory.QuaternionAccessor CreateQuaternionAccessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.QuaternionArray CreateQuaternionArray(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.QuaternionAccessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
+            return new Memory.QuaternionArray(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
         }
 
-        public Memory.Matrix4x4Accessor CreateMatrix4x4Accessor(int byteOffset, ENCODING encoding, Boolean normalized)
+        public Memory.Matrix4x4Array CreateMatrix4x4Array(int byteOffset, ENCODING encoding, Boolean normalized)
         {
-            return new Memory.Matrix4x4Accessor(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
+            return new Memory.Matrix4x4Array(this.Data.Slice(byteOffset), this.ByteStride, encoding, normalized);
         }
 
         /// <summary>

+ 57 - 46
src/glTF2Sharp.DOM/Schema2/gltf.MeshPrimitive.cs

@@ -13,6 +13,15 @@ namespace glTF2Sharp.Schema2
     [System.Diagnostics.DebuggerDisplay("MeshPrimitive[{LogicalIndex}] {_mode} {_DebuggerDisplay_TryIdentifyContent()}")]
     public partial class MeshPrimitive : IChildOf<Mesh>
     {
+        #region debug
+
+        private String _DebuggerDisplay_TryIdentifyContent()
+        {
+            return String.Join(" ", VertexAccessors.Keys);
+        }
+
+        #endregion
+
         #region lifecycle
 
         internal MeshPrimitive()
@@ -78,6 +87,42 @@ namespace glTF2Sharp.Schema2
 
         #region API
 
+        public IEnumerable<BufferView> GetBufferViews(bool includeIndices, bool includeVertices, bool includeMorphs)
+        {
+            var accessors = new List<Accessor>();
+
+            var attributes = this._attributes.Keys.ToArray();
+
+            if (includeIndices)
+            {
+                if (IndexAccessor != null) accessors.Add(IndexAccessor);
+            }
+
+            if (includeVertices)
+            {
+                accessors.AddRange(attributes.Select(k => VertexAccessors[k]));
+            }
+
+            if (includeMorphs)
+            {
+                for (int i = 0; i < MorpthTargets; ++i)
+                {
+                    foreach (var key in attributes)
+                    {
+                        var morpthAccessors = GetMorphTargetAccessors(i);
+                        if (morpthAccessors.TryGetValue(key, out Accessor accessor)) accessors.Add(accessor);
+                    }
+                }
+            }
+
+            var indices = accessors
+                .Select(item => item._LogicalBufferViewIndex)
+                .Where(item => item >= 0)
+                .Distinct();
+
+            return indices.Select(idx => this.LogicalParent.LogicalParent.LogicalBufferViews[idx]);
+        }
+
         public Accessor GetVertexAccessor(string attributeKey)
         {
             Guard.NotNullOrEmpty(attributeKey, nameof(attributeKey));
@@ -125,43 +170,7 @@ namespace glTF2Sharp.Schema2
             {
                 target[kvp.Key] = kvp.Value.LogicalIndex;
             }
-        }
-
-        public IEnumerable<BufferView> GetBufferViews(bool includeIndices, bool includeVertices, bool includeMorphs)
-        {            
-            var accessors = new List<Accessor>();
-
-            var attributes = this._attributes.Keys.ToArray();
-
-            if (includeIndices)
-            {                
-                if (IndexAccessor != null) accessors.Add(IndexAccessor);
-            }
-
-            if (includeVertices)
-            {
-                accessors.AddRange(attributes.Select(k => VertexAccessors[k]));
-            }
-
-            if (includeMorphs)
-            {
-                for (int i = 0; i < MorpthTargets; ++i)
-                {
-                    foreach (var key in attributes)
-                    {
-                        var morpthAccessors = GetMorphTargetAccessors(i);
-                        if (morpthAccessors.TryGetValue(key, out Accessor accessor)) accessors.Add(accessor);
-                    }
-                }
-            }
-
-            var indices = accessors
-                .Select(item => item._LogicalBufferViewIndex)
-                .Where(item => item >= 0)
-                .Distinct();
-
-            return indices.Select(idx => this.LogicalParent.LogicalParent.LogicalBufferViews[idx]);            
-        }
+        }        
 
         public IReadOnlyList<KeyValuePair<String, Accessor>> GetVertexAccessorsByBuffer(BufferView vb)
         {
@@ -174,17 +183,19 @@ namespace glTF2Sharp.Schema2
                 .ToArray();
         }
 
-        private Accessor _GetAccessor(IReadOnlyDictionary<string, int> attributes, string attribute)
-        {
-            if (!attributes.TryGetValue(attribute, out int idx)) return null;
+        public Memory.IEncodedArray<UInt32> GetIndices() => IndexAccessor.CastToIndicesAccessor();
 
-            return this.LogicalParent.LogicalParent.LogicalAccessors[idx];
-        }
+        public Memory.IEncodedArray<Single> GetScalarArray(string attributeKey) => GetVertexAccessor(attributeKey).AsScalarArray();
 
-        private String _DebuggerDisplay_TryIdentifyContent()
-        {
-            return String.Join(" ", VertexAccessors.Keys);
-        }
+        public Memory.IEncodedArray<Vector2> GetVector2Array(string attributeKey) => GetVertexAccessor(attributeKey).AsVector2Array();
+
+        public Memory.IEncodedArray<Vector3> GetVector3Array(string attributeKey) => GetVertexAccessor(attributeKey).AsVector3Array();
+
+        public Memory.IEncodedArray<Vector4> GetVector4Array(string attributeKey) => GetVertexAccessor(attributeKey).AsVector4Array();
+
+        public Memory.IEncodedArray<Vector3> GetVertexPositions() => GetVector3Array("POSITION");
+
+        public Memory.IEncodedArray<Vector3> GetVertexNormals() => GetVector3Array("NORMAL");
 
         #endregion
 

+ 3 - 3
src/glTF2Sharp.Tests/Memory/MemoryAccessorTests.cs → src/glTF2Sharp.Tests/Memory/MemoryArrayTests.cs

@@ -8,10 +8,10 @@ using NUnit.Framework;
 namespace glTF2Sharp.Memory
 {
     [TestFixture]
-    public class MemoryAccessorTests
+    public class MemoryArrayTests
     {
         [Test]
-        public void TestFloatingAccesor()
+        public void TestFloatingArray()
         {
             Assert.AreEqual(17, new FloatingAccessor(new Byte[] { 17 }, Schema2.ComponentType.UNSIGNED_BYTE, false)[0]);
             Assert.AreEqual(17, new FloatingAccessor(new Byte[] { 17, 0 }, Schema2.ComponentType.UNSIGNED_SHORT, false)[0]);            
@@ -36,7 +36,7 @@ namespace glTF2Sharp.Memory
         {
             var buffer = new Byte[] { 1, 52, 43, 6, 23, 234 };
 
-            var accessor = new Vector2Accessor(buffer, 0, Schema2.ComponentType.BYTE, true);
+            var accessor = new Vector2Array(buffer, 0, Schema2.ComponentType.BYTE, true);
 
             var result = accessor.ToArray();
 

+ 2 - 2
src/glTF2Sharp.Tests/Schema2/AccessorSparseTests.cs

@@ -22,8 +22,8 @@ namespace glTF2Sharp.Schema2
 
             var accessor = primitive.GetVertexAccessor("POSITION");
 
-            var basePositions = accessor.CastToVector3Accessor(false);
-            var goodPositions = accessor.CastToVector3Accessor(true);
+            var basePositions = accessor.AsVector3Array(false);
+            var goodPositions = accessor.AsVector3Array(true);
         }
     }
 }

+ 3 - 3
src/glTF2Sharp.Tests/Schema2/LoadModelTests.cs

@@ -108,9 +108,9 @@ namespace glTF2Sharp.Schema2
 
             var pollyPrimitive = pollyNode.Mesh.Primitives[0];
 
-            var pollyIndices = pollyPrimitive.IndexAccessor.CastToIndicesAccessor();
-            var pollyPositions = pollyPrimitive.VertexAccessors["POSITION"].CastToVector3Accessor();
-            var pollyNormals = pollyPrimitive.VertexAccessors["NORMAL"].CastToVector3Accessor();
+            var pollyIndices = pollyPrimitive.GetIndices();
+            var pollyPositions = pollyPrimitive.GetVertexPositions();
+            var pollyNormals = pollyPrimitive.GetVertexNormals();
 
             for (int i=0; i < pollyIndices.Count; i+=3)
             {