Ejemplo n.º 1
0
        public glTFBufferView Extend(IntPtr p, int bytesLength, int stride, glBufferTarget 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);
        }
Ejemplo n.º 2
0
        public int AddBufferView(glTFBufferView view)
        {
            var index = bufferViews.Count;

            bufferViews.Add(view);
            return(index);
        }
Ejemplo n.º 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.MarshalCopyTo(attrib);
            return(attrib);
        }
Ejemplo n.º 4
0
        IEnumerable <int> _GetIndices(glTFBufferView view, int count, int byteOffset, glComponentType componentType)
        {
            switch (componentType)
            {
            case glComponentType.UNSIGNED_BYTE:
            {
                return(GetAttrib <Byte>(count, byteOffset, view).Select(x => (int)(x)));
            }

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

            case glComponentType.UNSIGNED_INT:
            {
                return(GetAttrib <UInt32>(count, byteOffset, view).Select(x => (int)(x)));
            }
            }
            throw new NotImplementedException("GetIndices: unknown componenttype: " + componentType);
        }
Ejemplo n.º 5
0
 T[] GetAttrib <T>(glTFAccessor accessor, glTFBufferView view) where T : struct
 {
     return(GetAttrib <T>(accessor.count, accessor.byteOffset, view));
 }