示例#1
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);
        }
示例#2
0
        public int AddBufferView(GLTFBufferView view)
        {
            var index = bufferViews.Count;

            bufferViews.Add(view);
            return(index);
        }
示例#3
0
        T[] GetAttrib <T>(int count, int byteOffset, GLTFBufferView view) where T : struct
        {
            var attrib = new T[count];
            //
            var segment = buffers[view.buffer].GetBytes();
            var bytes   = new ArraySegment <Byte>(segment.Array, segment.Offset + view.byteOffset + byteOffset, count * view.byteStride);

            bytes.MarshalCoyTo(attrib);
            return(attrib);
        }
示例#4
0
        IEnumerable <int> GetIndices(GLTFBufferView view, int count, int byteOffset, GLTFComponentType componentType)
        {
            switch (componentType)
            {
            case GLTFComponentType.UNSIGNED_BYTE:
            {
                return(GetAttrib <Byte>(count, byteOffset, view).Select(x => (int)(x)));
            }

            case GLTFComponentType.UNSIGNED_SHORT:
            {
                return(GetAttrib <UInt16>(count, byteOffset, view).Select(x => (int)(x)));
            }

            case GLTFComponentType.UNSIGNED_INT:
            {
                return(GetAttrib <UInt32>(count, byteOffset, view).Select(x => (int)(x)));
            }
            }
            throw new NotImplementedException("GetIndices: unknown componenttype: " + componentType);
        }
示例#5
0
 T[] GetAttrib <T>(GLTFAccessor accessor, GLTFBufferView view) where T : struct
 {
     return(GetAttrib <T>(accessor.count, accessor.byteOffset, view));
 }