Example #1
0
 public BufferAccessor(ArraySegment <byte> bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count)
 {
     Bytes         = bytes;
     ComponentType = componentType;
     AccessorType  = accessorType;
     Count         = count;
 }
Example #2
0
 public BufferAccessor(INativeArrayManager arrayManager, NativeArray <byte> bytes, AccessorValueType componentType, AccessorVectorType accessorType, int count)
 {
     ArrayManager  = arrayManager;
     Bytes         = bytes;
     ComponentType = componentType;
     AccessorType  = accessorType;
     Count         = count;
 }
Example #3
0
        public static BufferAccessor Create <T>(T[] list) where T : struct
        {
            var t     = typeof(T);
            var bytes = new byte[list.Length * Marshal.SizeOf(t)];
            var span  = SpanLike.Wrap <T>(new ArraySegment <byte>(bytes));

            for (int i = 0; i < list.Length; ++i)
            {
                span[i] = list[i];
            }
            AccessorValueType  componentType = default(AccessorValueType);
            AccessorVectorType accessorType  = default(AccessorVectorType);

            if (t == typeof(Vector2))
            {
                componentType = AccessorValueType.FLOAT;
                accessorType  = AccessorVectorType.VEC2;
            }
            else if (t == typeof(Vector3))
            {
                componentType = AccessorValueType.FLOAT;
                accessorType  = AccessorVectorType.VEC3;
            }
            else if (t == typeof(Vector4))
            {
                componentType = AccessorValueType.FLOAT;
                accessorType  = AccessorVectorType.VEC4;
            }
            else if (t == typeof(Quaternion))
            {
                componentType = AccessorValueType.FLOAT;
                accessorType  = AccessorVectorType.VEC4;
            }
            else if (t == typeof(SkinJoints))
            {
                componentType = AccessorValueType.UNSIGNED_SHORT;
                accessorType  = AccessorVectorType.VEC4;
            }
            else if (t == typeof(int))
            {
                componentType = AccessorValueType.UNSIGNED_INT;
                accessorType  = AccessorVectorType.SCALAR;
            }
            else
            {
                throw new NotImplementedException();
            }
            return(new BufferAccessor(
                       new ArraySegment <byte>(bytes), componentType, accessorType, list.Length));
        }
Example #4
0
        // for index buffer
        public void AssignAsShort(SpanLike <int> values)
        {
            if (AccessorType != AccessorVectorType.SCALAR)
            {
                throw new NotImplementedException();
            }
            ComponentType = AccessorValueType.UNSIGNED_SHORT;

            Bytes = new ArraySegment <byte>(new byte[Stride * values.Length]);
            var span = GetSpan <ushort>();

            Count = values.Length;
            for (int i = 0; i < values.Length; ++i)
            {
                span[i] = (ushort)values[i];
            }
        }
Example #5
0
        public static int ByteSize(this AccessorValueType t)
        {
            switch (t)
            {
            case AccessorValueType.BYTE: return(1);

            case AccessorValueType.UNSIGNED_BYTE: return(4);

            case AccessorValueType.SHORT: return(2);

            case AccessorValueType.UNSIGNED_SHORT: return(2);

            case AccessorValueType.UNSIGNED_INT: return(4);

            case AccessorValueType.FLOAT: return(4);

            default: throw new ArgumentException();
            }
        }
Example #6
0
 private static BufferAccessor ToBufferAccessor <T>(INativeArrayManager arrayManager, T[] value, AccessorValueType valueType, AccessorVectorType vectorType) where T : struct
 {
     return(new BufferAccessor(arrayManager,
                               arrayManager.CreateNativeArray(value).Reinterpret <byte>(Marshal.SizeOf <T>()),
                               valueType,
                               vectorType,
                               value.Length
                               ));
 }