Ejemplo n.º 1
0
        public float GetCustomVertexData(VertexDataType vertexDataType, VertAttribute attr)
        {
            switch (vertexDataType)
            {
            case VertexDataType.VertexColorR:
                return(GetData(VertexColorR.OutDataType, attr));

            case VertexDataType.VertexColorG:
                return(GetData(VertexColorG.OutDataType, attr));

            case VertexDataType.VertexColorB:
                return(GetData(VertexColorB.OutDataType, attr));

            case VertexDataType.VertexColorA:
                return(GetData(VertexColorA.OutDataType, attr));

            case VertexDataType.UV1Z:
                return(GetData(UV1Z.OutDataType, attr));

            case VertexDataType.UV1W:
                return(GetData(UV1W.OutDataType, attr));

            default:
                throw new ArgumentOutOfRangeException(nameof(vertexDataType), vertexDataType, null);
            }
        }
Ejemplo n.º 2
0
 public static bool TryConvertToType(System.Type type, out VertexDataType dataType)
 {
     if (type == typeof(byte))
     {
         dataType = VertexDataType.UNORM8;
         return(true);
     }
     if (type == typeof(short))
     {
         dataType = VertexDataType.UNORM16;
         return(true);
     }
     if (type == typeof(Half))
     {
         dataType = VertexDataType.UNORM16;
         return(true);
     }
     if (type == typeof(float))
     {
         dataType = VertexDataType.FLOAT;
         return(true);
     }
     dataType = VertexDataType.UNORM8;
     return(false);
 }
Ejemplo n.º 3
0
 static object ReadData(byte[] buffer, VertexDataType type, int offset)
 {
     switch (type) {
         case VertexDataType.Half2:
             return new Vector2 {
                 X = HalfHelper.Unpack(buffer, offset + 0x00),
                 Y = HalfHelper.Unpack(buffer, offset + 0x02)
             };
         case VertexDataType.Half4:
             return new Vector4 {
                 X = HalfHelper.Unpack(buffer, offset + 0x00),
                 Y = HalfHelper.Unpack(buffer, offset + 0x02),
                 Z = HalfHelper.Unpack(buffer, offset + 0x04),
                 W = HalfHelper.Unpack(buffer, offset + 0x06)
             };
         case VertexDataType.UInt:
             return BitConverter.ToUInt32(buffer, offset);
         case VertexDataType.ByteFloat4:
             return new Vector4 {
                 X = buffer[offset + 0] / 255f,
                 Y = buffer[offset + 1] / 255f,
                 Z = buffer[offset + 2] / 255f,
                 W = buffer[offset + 3] / 255f
             };
         case VertexDataType.Single3:
             return buffer.ToStructure<Vector3>(offset);
         case VertexDataType.Single4:
             return buffer.ToStructure<Vector4>(offset);
         default:
             throw new NotSupportedException();
     }
 }
Ejemplo n.º 4
0
        public Mesh(VertexDataType type, bool isStatic, int maxVertices, int maxIndices, VertexAttributes attributes)
        {
            // todo: handle other type

            vertices      = new VertexBufferObjectWithVAO(isStatic, maxVertices, attributes);
            indices       = new IndexBufferObject(isStatic, maxIndices);
            isVertexArray = false;
        }
Ejemplo n.º 5
0
            public MyMeshAttribFormat(string name, VertexDataType type, int componentCount)
            {
                if (!(0 <= componentCount && componentCount <= 4))
                {
                    throw new ArgumentOutOfRangeException("componentCount should <= 4");
                }

                this.name           = name;
                this.type           = type;
                this.componentCount = componentCount;
            }
 public float GetCustomVertexData(VertexDataType vertexDataType, float density, float rand)
 {
     foreach (var v in VertexDataDefinitions)
     {
         if (vertexDataType == v.VertexDataType)
         {
             return(GetData(v.OutDataType, density, rand));
         }
     }
     return(0f);
 }
Ejemplo n.º 7
0
 public static int VertexDataTypeToByteCount(VertexDataType type)
 {
     if (type == VertexDataType.UNORM8)
     {
         return(1);
     }
     if (type == VertexDataType.UNORM16)
     {
         return(2);
     }
     if (type == VertexDataType.FLOAT)
     {
         return(4);
     }
     return(0);
 }
        public void SetVertexData(VertexType[] vertexData, VertexDataType dataType, Boolean bNeedCPUAccess = false)
        {
            UInt32 numVertexData = Convert.ToUInt32(vertexData.Count());

            if (dataType != VertexDataType.Texcoord)
            {
                m_NumVertices = numVertexData;
            }
            else
            {
                m_NumTexcoords = numVertexData;
            }

            m_bNeedCPUAccess = bNeedCPUAccess;
            m_VertexDataType = dataType;

            // copy the vertex data
            m_VertexData = new VertexType[vertexData.Count()];
            vertexData.CopyTo(m_VertexData, 0);
        }
Ejemplo n.º 9
0
        static object ReadData(byte[] buffer, VertexDataType type, int offset)
        {
            switch (type)
            {
            case VertexDataType.Half2:
                return(new Vector2 {
                    X = HalfHelper.Unpack(buffer, offset + 0x00),
                    Y = HalfHelper.Unpack(buffer, offset + 0x02)
                });

            case VertexDataType.Half4:
                return(new Vector4 {
                    X = HalfHelper.Unpack(buffer, offset + 0x00),
                    Y = HalfHelper.Unpack(buffer, offset + 0x02),
                    Z = HalfHelper.Unpack(buffer, offset + 0x04),
                    W = HalfHelper.Unpack(buffer, offset + 0x06)
                });

            case VertexDataType.UInt:
                return(BitConverter.ToUInt32(buffer, offset));

            case VertexDataType.ByteFloat4:
                return(new Vector4 {
                    X = buffer[offset + 0] / 255f,
                    Y = buffer[offset + 1] / 255f,
                    Z = buffer[offset + 2] / 255f,
                    W = buffer[offset + 3] / 255f
                });

            case VertexDataType.Single3:
                return(buffer.ToStructure <Vector3>(offset));

            case VertexDataType.Single4:
                return(buffer.ToStructure <Vector4>(offset));

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 10
0
 public ShapeVertexAttribute(VertexArrayType arrayType, VertexDataType dataType)
 {
     ArrayType = arrayType;
     DataType  = dataType;
 }
Ejemplo n.º 11
0
 public GLMesh(VertexDataType type, bool isStatic, int maxVertices,
               int maxIndices, params Loon.Core.Graphics.Opengl.GLAttributes.VertexAttribute[] attributes)
 {
     isVertexArray = true;
 }
Ejemplo n.º 12
0
 public GLMesh(VertexDataType type, bool isStatic, int maxVertices,
         int maxIndices, params Loon.Core.Graphics.Opengl.GLAttributes.VertexAttribute[] attributes)
 {
     isVertexArray = true;
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public Mesh(VertexDataType type, bool isStatic, int maxVertices, int maxIndices, params VertexAttribute[] attributes)
     : this(type, isStatic, maxVertices, maxIndices, new VertexAttributes(attributes))
 {
 }