示例#1
0
        private static uint DetermineByteSize(Accessor.ComponentTypeEnum componentType)
        {
            switch (componentType)
            {
            case Accessor.ComponentTypeEnum.BYTE:
                return(1U);

            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(1U);

            case Accessor.ComponentTypeEnum.SHORT:
                return(2U);

            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(2U);

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(4U);

            case Accessor.ComponentTypeEnum.FLOAT:
                return(4U);

            default:
                throw new NotSupportedException();
            }
        }
示例#2
0
        private int GetComponentSize(Accessor.ComponentTypeEnum componentType)
        {
            switch (componentType)
            {
            case Accessor.ComponentTypeEnum.BYTE:
                return(1);

            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(1);

            case Accessor.ComponentTypeEnum.SHORT:
                return(2);

            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(2);

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(4);

            case Accessor.ComponentTypeEnum.FLOAT:
                return(4);
            }

            throw new InvalidEnumArgumentException("Unknown Component type!");
        }
示例#3
0
        private static MgtfElementType DetermineElementType(Accessor.ComponentTypeEnum componentType)
        {
            switch (componentType)
            {
            case Accessor.ComponentTypeEnum.BYTE:
                return(MgtfElementType.SByte);

            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(MgtfElementType.Byte);

            case Accessor.ComponentTypeEnum.SHORT:
                return(MgtfElementType.Short);

            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(MgtfElementType.Ushort);

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(MgtfElementType.Uint);

            case Accessor.ComponentTypeEnum.FLOAT:
                return(MgtfElementType.Float);

            default:
                throw new NotSupportedException();
            }
        }
示例#4
0
文件: Accessor.cs 项目: Hengle/VGltf
        public static Type TypeOf(this Accessor.ComponentTypeEnum e)
        {
            switch (e)
            {
            case Accessor.ComponentTypeEnum.BYTE:
                return(typeof(sbyte));

            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(typeof(byte));

            case Accessor.ComponentTypeEnum.SHORT:
                return(typeof(short));

            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(typeof(ushort));

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(typeof(uint));

            case Accessor.ComponentTypeEnum.FLOAT:
                return(typeof(float));

            default:
                throw new NotImplementedException();
            }
        }
示例#5
0
文件: Accessor.cs 项目: Hengle/VGltf
        public static int SizeInBytes(this Accessor.ComponentTypeEnum e)
        {
            switch (e)
            {
            case Accessor.ComponentTypeEnum.BYTE:
                return(1);

            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(1);

            case Accessor.ComponentTypeEnum.SHORT:
                return(2);

            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(2);

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(4);

            case Accessor.ComponentTypeEnum.FLOAT:
                return(4);

            default:
                throw new NotImplementedException();
            }
        }
示例#6
0
            private int PaddingBytes(Accessor.ComponentTypeEnum componentType)
            {
                switch (componentType)
                {
                case Accessor.ComponentTypeEnum.BYTE:
                case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                    return(1);

                case Accessor.ComponentTypeEnum.SHORT:
                case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                    return(2);

                case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                case Accessor.ComponentTypeEnum.FLOAT:
                default:
                    return(4);
                }
            }
示例#7
0
        public static int GetComponentByteLength(this Accessor.ComponentTypeEnum componentType)
        {
            switch (componentType)
            {
            case Accessor.ComponentTypeEnum.BYTE:
            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                return(1);

            case Accessor.ComponentTypeEnum.SHORT:
            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                return(2);

            case Accessor.ComponentTypeEnum.FLOAT:
            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                return(4);
            }

            return(0);
        }
示例#8
0
        public static int GetComponentTypeMultiplier(Accessor.ComponentTypeEnum componentType)
        {
            var mult = 0;

            switch (componentType)
            {
            case Accessor.ComponentTypeEnum.BYTE:
            case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                mult = 1;
                break;

            case Accessor.ComponentTypeEnum.SHORT:
            case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                mult = 2;
                break;

            case Accessor.ComponentTypeEnum.UNSIGNED_INT:
            case Accessor.ComponentTypeEnum.FLOAT:
                mult = 4;
                break;
            }

            return(mult);
        }
示例#9
0
        private static int AddAccessor(this Gltf gltf, int bufferView, int byteOffset, Accessor.ComponentTypeEnum componentType, int count, float[] min, float[] max, Accessor.TypeEnum accessorType)
        {
            var a = new Accessor();

            a.BufferView    = bufferView;
            a.ByteOffset    = byteOffset;
            a.ComponentType = componentType;
            a.Min           = min;
            a.Max           = max;
            a.Type          = accessorType;
            a.Count         = count;

            if (gltf.Accessors != null)
            {
                var accessors = gltf.Accessors.ToList();
                accessors.Add(a);
                gltf.Accessors = accessors.ToArray();
            }
            else
            {
                gltf.Accessors = new [] { a };
            }

            return(gltf.Accessors.Length - 1);
        }
示例#10
0
        private static int AddAccessor(List <Accessor> accessors, int bufferView, int byteOffset, Accessor.ComponentTypeEnum componentType, int count, float[] min, float[] max, Accessor.TypeEnum accessorType)
        {
            var a = new Accessor();

            a.BufferView    = bufferView;
            a.ByteOffset    = byteOffset;
            a.ComponentType = componentType;
            a.Min           = min;
            a.Max           = max;
            a.Type          = accessorType;
            a.Count         = count;

            accessors.Add(a);

            return(accessors.Count - 1);
        }
示例#11
0
        private static MgFormat DetermineFormat(Accessor.TypeEnum type, Accessor.ComponentTypeEnum componentType)
        {
            if (type == Accessor.TypeEnum.SCALAR)
            {
                switch (componentType)
                {
                case Accessor.ComponentTypeEnum.BYTE:
                    return(MgFormat.R8_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                    return(MgFormat.R8_UINT);

                case Accessor.ComponentTypeEnum.FLOAT:
                    return(MgFormat.R32_SFLOAT);

                case Accessor.ComponentTypeEnum.SHORT:
                    return(MgFormat.R16_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                    return(MgFormat.R16_UINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                    return(MgFormat.R32_UINT);

                default:
                    throw new NotSupportedException();
                }
            }
            else if (type == Accessor.TypeEnum.VEC2)
            {
                switch (componentType)
                {
                case Accessor.ComponentTypeEnum.BYTE:
                    return(MgFormat.R8G8_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                    return(MgFormat.R8G8_UINT);

                case Accessor.ComponentTypeEnum.FLOAT:
                    return(MgFormat.R32G32_SFLOAT);

                case Accessor.ComponentTypeEnum.SHORT:
                    return(MgFormat.R16G16_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                    return(MgFormat.R16G16_UINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                    return(MgFormat.R32G32_UINT);

                default:
                    throw new NotSupportedException();
                }
            }
            else if (type == Accessor.TypeEnum.VEC3)
            {
                switch (componentType)
                {
                case Accessor.ComponentTypeEnum.BYTE:
                    return(MgFormat.R8G8B8_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                    return(MgFormat.R8G8B8_UINT);

                case Accessor.ComponentTypeEnum.FLOAT:
                    return(MgFormat.R32G32B32_SFLOAT);

                case Accessor.ComponentTypeEnum.SHORT:
                    return(MgFormat.R16G16B16_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                    return(MgFormat.R16G16B16_UINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                    return(MgFormat.R32G32B32_UINT);

                default:
                    throw new NotSupportedException();
                }
            }
            else if (type == Accessor.TypeEnum.VEC4)
            {
                switch (componentType)
                {
                case Accessor.ComponentTypeEnum.BYTE:
                    return(MgFormat.R8G8B8A8_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_BYTE:
                    return(MgFormat.R8G8B8A8_UINT);

                case Accessor.ComponentTypeEnum.FLOAT:
                    return(MgFormat.R32G32B32A32_SFLOAT);

                case Accessor.ComponentTypeEnum.SHORT:
                    return(MgFormat.R16G16B16A16_SINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_SHORT:
                    return(MgFormat.R16G16B16A16_UINT);

                case Accessor.ComponentTypeEnum.UNSIGNED_INT:
                    return(MgFormat.R32G32B32A32_UINT);

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                throw new NotSupportedException();
            }
        }
示例#12
0
        public static dynamic AccessBuffer(Accessor.TypeEnum accessorType, int count, Accessor.ComponentTypeEnum componentType, int stride, byte[] arr)
        {
            dynamic result = null;

            var elementCount   = count;                                     //how many times do we need to do this?
            var componentCount = GetTypeMultiplier(accessorType);;          //each time we do this, how many times do I need to read the buffer?
            var byteCount      = GetComponentTypeMultiplier(componentType); //how many bytes is each component from ComponentTypeEnum
            var elementBytes   = componentCount * byteCount;

            var strideDiff = stride > 0 ? stride - elementBytes : 0;

            using (var memoryStream = new MemoryStream(arr))
                using (var reader = new BinaryReader(memoryStream))
                {
                    // TODO: clean this up
                    switch (componentType)
                    {
                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.BYTE:

                        var listSByte = new List <sbyte>();

                        //loop through element count

                        //loop through component count
                        //if stride, position the reader appropriately
                        // element bytes should be byteCount * componentCount
                        // stride diff should be stride - elementbytes

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listSByte.Add(reader.ReadSByte());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listSByte;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.FLOAT:

                        var listSingle = new List <Single>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listSingle.Add(reader.ReadSingle());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listSingle;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.SHORT:

                        var listShort = new List <Int16>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listShort.Add(reader.ReadInt16());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listShort;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_BYTE:

                        var listByte = new List <byte>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listByte.Add(reader.ReadByte());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listByte;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_INT:

                        var listUInt = new List <uint>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listUInt.Add(reader.ReadUInt32());
                            }
                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listUInt;

                        break;

                    case glTFLoader.Schema.Accessor.ComponentTypeEnum.UNSIGNED_SHORT:

                        var listUInt16 = new List <UInt16>();

                        for (int i = 0; i < elementCount; i++)
                        {
                            for (int j = 0; j < componentCount; j++)
                            {
                                listUInt16.Add(reader.ReadUInt16());
                            }

                            reader.BaseStream.Position += strideDiff;
                        }

                        result = listUInt16;

                        break;
                    }
                }

            return(result);
        }
示例#13
0
        /// <summary>
        /// Computes how much to advance a byte-offset to store components of the given type.
        /// </summary>
        public static int GetComponentPadding(this Accessor.ComponentTypeEnum componentType, int byteOffset)
        {
            var componentByteLength = GetComponentByteLength(componentType);

            return(GetComponentPadding(componentByteLength, byteOffset));
        }