Пример #1
0
        private static int GetByteStride(Accessor accessor, BufferView view)
        {
            int len = 0;

            if (view.ByteStride == 0)
            {
                len = GetByteLength((GLenum)accessor.ComponentType);
                String type = accessor.Type;
                if (type == "SCALAR")
                {
                    len *= 1;
                }
                else if (type == "VEC2")
                {
                    len *= 2;
                }
                else if (type == "VEC3")
                {
                    len *= 3;
                }
                else if (type == "VEC4")
                {
                    len *= 4;
                }
                else if (type == "MAT2")
                {
                    len *= 4;
                }
                else if (type == "MAT3")
                {
                    len *= 9;
                }
                else if (type == "MAT4")
                {
                    len *= 16;
                }
                else
                {
                    len = 0;
                }
                return(len);
            }
            else
            {
                /*len = GetByteLength((GLenum)accessor.ComponentType);
                 * if ((view.ByteStride % len) != 0) {
                 *      return 0;
                 * }*/
                return(view.ByteStride);
            }
        }
Пример #2
0
        /// <summary>
        /// バイナリデータをAccessorをもとに切り出す
        /// </summary>
        /// <param name="accessor">VRM Model Accessor</param>
        /// <param name="view">VRM Model Buffer View</param>
        /// <returns></returns>
        public MemoryStream ParseBinary(Accessor accessor, BufferView view)
        {
            // 切り出し
            byte[] buffer = new byte[view.ByteLength];
            byte[] temp   = new byte[view.ByteLength - accessor.ByteOffset];
            Array.Copy(Binary, view.ByteOffset, buffer, 0, view.ByteLength);
            Array.Copy(buffer, accessor.ByteOffset, temp, 0, temp.Length);

            // Byte Stride 算出
            int len = GetByteStride(accessor, view);

            // 展開
            using (var stream = new MemoryStream(len * accessor.Count)) {
                for (int j = 0; j < accessor.Count * len; j++)
                {
                    stream.WriteByte(temp[j]);
                }
                stream.Position = 0;
                return(new MemoryStream(stream.GetBuffer()));
            }
        }