コード例 #1
0
        public static int ExtendSparseBufferAndGetAccessorIndex <T>(this GLTFRoot gltf, int bufferIndex,
                                                                    int accessorCount,
                                                                    ArraySegment <T> sparseValues, int[] sparseIndices, int sparseIndicesViewIndex,
                                                                    GLTFBufferTarget target = GLTFBufferTarget.NONE) where T : struct
        {
            if (sparseValues.Count == 0)
            {
                return(-1);
            }
            var sparseValuesViewIndex = ExtendBufferAndGetViewIndex(gltf, bufferIndex, sparseValues, target);
            var accessorIndex         = gltf.accessors.Count;

            gltf.accessors.Add(new GLTFAccessor
            {
                byteOffset    = 0,
                componentType = GetComponentType <T>(),
                type          = GetAccessorType <T>(),
                count         = accessorCount,

                sparse = new GLTFSparse
                {
                    count   = sparseIndices.Length,
                    indices = new GLTFSparseIndices
                    {
                        bufferView    = sparseIndicesViewIndex,
                        componentType = GLTFComponentType.UNSIGNED_INT
                    },
                    values = new GLTFSparseValues
                    {
                        bufferView = sparseValuesViewIndex,
                    }
                }
            });
            return(accessorIndex);
        }
コード例 #2
0
        public GLTFBufferView Extend(IntPtr p, int bytesLength, int stride, GLTFBufferTarget target)
        {
            var tmp = m_bytes;
            // alignment
            var padding = m_used % stride == 0 ? 0 : stride - m_used % stride;

            if (m_bytes == null || m_used + padding + bytesLength > m_bytes.Length)
            {
                // recreate buffer
                m_bytes = new Byte[m_used + padding + bytesLength];
                if (m_used > 0)
                {
                    Buffer.BlockCopy(tmp, 0, m_bytes, 0, m_used);
                }
            }
            if (m_used + padding + bytesLength > m_bytes.Length)
            {
                throw new ArgumentOutOfRangeException();
            }

            Marshal.Copy(p, m_bytes, m_used + padding, bytesLength);
            var result = new GLTFBufferView
            {
                buffer     = 0,
                byteLength = bytesLength,
                byteOffset = m_used + padding,
                byteStride = stride,
                target     = target,
            };

            m_used = m_used + padding + bytesLength;
            return(result);
        }
コード例 #3
0
ファイル: GLTFBuffer.cs プロジェクト: JiphuTzu/GLTFuma
        public GLTFBufferView Append <T>(ArraySegment <T> segment, GLTFBufferTarget target) where T : struct
        {
            var view = _storage.Extend(segment, target);

            byteLength = _storage.GetBytes().Count;
            return(view);
        }
コード例 #4
0
        public static int ExtendBufferAndGetAccessorIndex <T>(this GLTFRoot gltf, int bufferIndex,
                                                              ArraySegment <T> array,
                                                              GLTFBufferTarget target = GLTFBufferTarget.NONE) where T : struct
        {
            if (array.Count == 0)
            {
                return(-1);
            }
            var viewIndex = ExtendBufferAndGetViewIndex(gltf, bufferIndex, array, target);

            // index buffer's byteStride is unnecessary
            gltf.bufferViews[viewIndex].byteStride = 0;

            var accessorIndex = gltf.accessors.Count;

            gltf.accessors.Add(new GLTFAccessor
            {
                bufferView    = viewIndex,
                byteOffset    = 0,
                componentType = GetComponentType <T>(),
                type          = GetAccessorType <T>(),
                count         = array.Count,
            });
            return(accessorIndex);
        }
コード例 #5
0
 public GLTFBufferView Extend <T>(ArraySegment <T> array, GLTFBufferTarget target) where T : struct
 {
     using (var pin = array.ToPin())
     {
         var elementSize = Marshal.SizeOf(typeof(T));
         var view        = Extend(pin.Ptr, array.Count * elementSize, elementSize, target);
         return(view);
     }
 }
コード例 #6
0
 public static int ExtendSparseBufferAndGetAccessorIndex <T>(this GLTFRoot gltf, int bufferIndex,
                                                             int accessorCount,
                                                             T[] sparseValues, int[] sparseIndices, int sparseViewIndex,
                                                             GLTFBufferTarget target = GLTFBufferTarget.NONE) where T : struct
 {
     return(ExtendSparseBufferAndGetAccessorIndex(gltf, bufferIndex,
                                                  accessorCount,
                                                  new ArraySegment <T>(sparseValues), sparseIndices, sparseViewIndex,
                                                  target));
 }
コード例 #7
0
        public static int ExtendBufferAndGetViewIndex <T>(this GLTFRoot gltf, int bufferIndex,
                                                          ArraySegment <T> array,
                                                          GLTFBufferTarget target = GLTFBufferTarget.NONE) where T : struct
        {
            if (array.Count == 0)
            {
                return(-1);
            }
            var view      = gltf.buffers[bufferIndex].Append(array, target);
            var viewIndex = gltf.bufferViews.Count;

            gltf.bufferViews.Add(view);
            return(viewIndex);
        }
コード例 #8
0
 public GLTFBufferView Extend <T>(ArraySegment <T> array, GLTFBufferTarget target) where T : struct
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public static GLTFBufferView Extend <T>(this IBytesBuffer buffer, T[] array, GLTFBufferTarget target) where T : struct
 {
     return(buffer.Extend(new ArraySegment <T>(array), target));
 }
コード例 #10
0
ファイル: GLTFBuffer.cs プロジェクト: JiphuTzu/GLTFuma
 public GLTFBufferView Append <T>(T[] array, GLTFBufferTarget target) where T : struct
 {
     return(Append(new ArraySegment <T>(array), target));
 }
コード例 #11
0
 public static int ExtendBufferAndGetViewIndex <T>(this GLTFRoot gltf, int bufferIndex,
                                                   T[] array,
                                                   GLTFBufferTarget target = GLTFBufferTarget.NONE) where T : struct
 {
     return(ExtendBufferAndGetViewIndex(gltf, bufferIndex, new ArraySegment <T>(array), target));
 }