public static VertexArray FromType(VertexArrayType type)
            {
                var array = new VertexArray {
                    Type = type
                };

                switch (type)
                {
                case VertexArrayType.TexCoord:
                    array.Size   = 2;
                    array.Format = VertexArrayFormat.Single;
                    break;

                case VertexArrayType.Position:
                case VertexArrayType.Normal:
                    array.Size   = 3;
                    array.Format = VertexArrayFormat.Single;
                    break;

                case VertexArrayType.Tangent:
                    array.Size   = 4;
                    array.Format = VertexArrayFormat.Single;
                    break;

                case VertexArrayType.Color:
                case VertexArrayType.BlendIndexes:
                case VertexArrayType.BlendWeights:
                    array.Size   = 4;
                    array.Format = VertexArrayFormat.Byte;
                    break;
                }

                return(array);
            }
Exemple #2
0
        private ShaderAttributeIds ArrayTypeToShader(VertexArrayType type)
        {
            switch (type)
            {
            case VertexArrayType.Position:
                return(ShaderAttributeIds.Position);

            case VertexArrayType.Normal:
                return(ShaderAttributeIds.Normal);

            case VertexArrayType.Color0:
                return(ShaderAttributeIds.Color0);

            case VertexArrayType.Color1:
                return(ShaderAttributeIds.Color1);

            case VertexArrayType.Tex0:
                return(ShaderAttributeIds.Tex0);

            case VertexArrayType.Tex1:
                return(ShaderAttributeIds.Tex1);

            case VertexArrayType.Tex2:
                return(ShaderAttributeIds.Tex2);

            case VertexArrayType.Tex3:
                return(ShaderAttributeIds.Tex3);

            case VertexArrayType.Tex4:
                return(ShaderAttributeIds.Tex4);

            case VertexArrayType.Tex5:
                return(ShaderAttributeIds.Tex5);

            case VertexArrayType.Tex6:
                return(ShaderAttributeIds.Tex6);

            case VertexArrayType.Tex7:
                return(ShaderAttributeIds.Tex7);

            default:
                return(ShaderAttributeIds.Position);
            }
        }
Exemple #3
0
 public ShapeVertexAttribute(VertexArrayType arrayType, VertexDataType dataType)
 {
     ArrayType = arrayType;
     DataType  = dataType;
 }
Exemple #4
0
        private static List <T> LoadVertexAttribute <T>(EndianBinaryReader reader, int totalAttributeDataLength, byte decimalPoint, VertexArrayType arrayType, VertexDataType dataType, VertexColorType colorType) where T : new()
        {
            int componentCount = 0;

            switch (arrayType)
            {
            case VertexArrayType.Position:
            case VertexArrayType.Normal:
                componentCount = 3;
                break;

            case VertexArrayType.Color0:
            case VertexArrayType.Color1:
                componentCount = 4;
                break;

            case VertexArrayType.Tex0:
            case VertexArrayType.Tex1:
            case VertexArrayType.Tex2:
            case VertexArrayType.Tex3:
            case VertexArrayType.Tex4:
            case VertexArrayType.Tex5:
            case VertexArrayType.Tex6:
            case VertexArrayType.Tex7:
                componentCount = 2;
                break;

            default:
                WLog.Warning(LogCategory.ModelLoading, null, "Unsupported ArrayType \"{0}\" found while loading VTX1!", arrayType);
                break;
            }


            // We need to know the length of each 'vertex' (which can vary based on how many attributes and what types there are)
            int vertexSize = 0;

            switch (dataType)
            {
            case VertexDataType.Float32:
                vertexSize = componentCount * 4;
                break;

            case VertexDataType.Unsigned16:
            case VertexDataType.Signed16:
                vertexSize = componentCount * 2;
                break;

            case VertexDataType.Signed8:
            case VertexDataType.Unsigned8:
                vertexSize = componentCount * 1;
                break;

            case VertexDataType.None:
                break;

            default:
                WLog.Warning(LogCategory.ModelLoading, null, "Unsupported DataType \"{0}\" found while loading VTX1!", dataType);
                break;
            }

            switch (colorType)
            {
            case VertexColorType.RGB8:
                vertexSize = 3;
                break;

            case VertexColorType.RGBX8:
            case VertexColorType.RGBA8:
                vertexSize = 4;
                break;

            case VertexColorType.None:
                break;

            case VertexColorType.RGB565:
            case VertexColorType.RGBA4:
            case VertexColorType.RGBA6:
            default:
                WLog.Warning(LogCategory.ModelLoading, null, "Unsupported Color Data Type: {0}!", colorType);
                break;
            }


            int      sectionSize = totalAttributeDataLength / vertexSize;
            List <T> values      = new List <T>(sectionSize);
            float    scaleFactor = (float)Math.Pow(0.5, decimalPoint);

            for (int v = 0; v < sectionSize; v++)
            {
                // Create a default version of the object and then fill it up depending on our component count and its data type...
                dynamic value = new T();

                for (int i = 0; i < componentCount; i++)
                {
                    switch (dataType)
                    {
                    case VertexDataType.Float32:
                        value[i] = reader.ReadSingle() * scaleFactor;
                        break;

                    case VertexDataType.Unsigned16:
                        value[i] = (float)reader.ReadUInt16() * scaleFactor;
                        break;

                    case VertexDataType.Signed16:
                        value[i] = (float)reader.ReadInt16() * scaleFactor;
                        break;

                    case VertexDataType.Unsigned8:
                        value[i] = (float)reader.ReadByte() * scaleFactor;
                        break;

                    case VertexDataType.Signed8:
                        value[i] = (float)reader.ReadSByte() * scaleFactor;
                        break;

                    case VertexDataType.None:
                        // Let the next switch statement get it.
                        break;

                    default:
                        WLog.Warning(LogCategory.ModelLoading, null, "Unsupported Data Type: {0}!", dataType);
                        break;
                    }


                    switch (colorType)
                    {
                    case VertexColorType.RGBX8:
                    case VertexColorType.RGB8:
                    case VertexColorType.RGBA8:
                        value[i] = reader.ReadByte() / 255f;
                        break;

                    case VertexColorType.None:
                        break;

                    case VertexColorType.RGB565:
                    case VertexColorType.RGBA4:
                    case VertexColorType.RGBA6:
                    default:
                        WLog.Warning(LogCategory.ModelLoading, null, "Unsupported Color Data Type: {0}!", colorType);
                        break;
                    }
                }
                values.Add(value);
            }

            return(values);
        }
Exemple #5
0
 public VertexArray(VertexArrayType _type)
 {
     this.Type = _type;
 }