Example #1
0
        public TypedArrayStorageFromBufferView(ResourcesStore store,
                                               int bufferViewIndex,
                                               int byteOffset,
                                               int componentSize, // Size of primitives (e.g. int = 4)
                                               int componentNum,  // Number of primitives in compound values (e.g. VEC3 = 3)
                                               int count)         // Number of compound values (e.g. Number of VEC3)
        {
            var bufferView = store.Gltf.BufferViews[bufferViewIndex];
            var r          = store.GetOrLoadBufferViewResourceAt(bufferViewIndex);

            var compoundSize = componentSize * componentNum; // Size in bytes sizeof(int * VEC3) = 4 * 3
            var stride       = bufferView.ByteStride != null ? bufferView.ByteStride.Value : compoundSize;

            var buffer = new ArraySegment <byte>(r.Data.Array, r.Data.Offset + byteOffset, count * stride);

            Storage = new TypedArrayStorage <T>(buffer, byteOffset, stride, count);
        }
Example #2
0
 public TypedBuffer(ResourcesStore store, Types.Accessor accessor)
 {
     Store    = store;
     Accessor = accessor;
 }
Example #3
0
        public TypedArrayEntity(ResourcesStore store, Accessor accessor)
        {
            Length = accessor.Count;

            if (accessor.BufferView != null)
            {
                DenseView = new TypedArrayStorageFromBufferView <T>(
                    store, accessor.BufferView.Value,
                    accessor.ByteOffset,
                    accessor.ComponentType.SizeInBytes(),
                    accessor.Type.NumOfComponents(),
                    accessor.Count);
            }

            if (accessor.Sparse != null)
            {
                var sparse = accessor.Sparse;

                var indices = sparse.Indices;
                switch (indices.ComponentType)
                {
                case Types.Accessor.SparseType.IndicesType.ComponentTypeEnum.UNSIGNED_BYTE:
                    SparseIndices = new TypedArrayStorageFromBufferView <byte>(
                        store, indices.BufferView,
                        indices.ByteOffset,
                        indices.ComponentType.SizeInBytes(),
                        1,     // must be scalar
                        sparse.Count
                        ).CastTo <uint>();
                    break;

                case Types.Accessor.SparseType.IndicesType.ComponentTypeEnum.UNSIGNED_SHORT:
                    SparseIndices = new TypedArrayStorageFromBufferView <ushort>(
                        store, indices.BufferView,
                        indices.ByteOffset,
                        indices.ComponentType.SizeInBytes(),
                        1,     // must be scalar
                        sparse.Count
                        ).CastTo <uint>();
                    break;

                case Types.Accessor.SparseType.IndicesType.ComponentTypeEnum.UNSIGNED_INT:
                    SparseIndices = new TypedArrayStorageFromBufferView <uint>(
                        store, indices.BufferView,
                        indices.ByteOffset,
                        indices.ComponentType.SizeInBytes(),
                        1,     // must be scalar
                        sparse.Count
                        );
                    break;
                }

                var values = sparse.Values;
                SparseValues = new TypedArrayStorageFromBufferView <T>(
                    store, values.BufferView,
                    values.ByteOffset,
                    accessor.ComponentType.SizeInBytes(),
                    accessor.Type.NumOfComponents(),
                    sparse.Count);
            }
        }