Esempio n. 1
0
        public float[] SerializeData(VertexAttribute attributes)
        {
            if (attributes == VertexAttribute.NONE)
            {
                throw new ArgumentException("Cannot serialize shape data with no selected attributes.");
            }

            var vertexsize = vertex.SizeOf(attributes);
            var data       = new float[Vertices.Length * vertexsize];

            for (int i = 0; i < Vertices.Length; ++i)
            {
                var vertex = Vertices[i];
                var c      = 0;

                if (attributes.HasFlag(VertexAttribute.POSITION))
                {
                    data[i * vertexsize + c++] = vertex.position.x;
                    data[i * vertexsize + c++] = vertex.position.y;
                    data[i * vertexsize + c++] = vertex.position.z;
                }

                if (attributes.HasFlag(VertexAttribute.COLOR))
                {
                    data[i * vertexsize + c++] = vertex.color.x;
                    data[i * vertexsize + c++] = vertex.color.y;
                    data[i * vertexsize + c++] = vertex.color.z;
                }

                if (attributes.HasFlag(VertexAttribute.NORMAL))
                {
                    data[i * vertexsize + c++] = vertex.normal.x;
                    data[i * vertexsize + c++] = vertex.normal.y;
                    data[i * vertexsize + c++] = vertex.normal.z;
                }

                if (attributes.HasFlag(VertexAttribute.UV))
                {
                    data[i * vertexsize + c++] = vertex.uv.x;
                    data[i * vertexsize + c++] = vertex.uv.y;
                }
            }

            return(data);
        }
Esempio n. 2
0
        public static int SizeOf(VertexAttribute attributes)
        {
            var size = 0;

            for (var i = 0u; i < AttribCount; ++i)
            {
                var e = (VertexAttribute)(1 << (int)i);
                if (attributes.HasFlag(e))
                {
                    size += AttribSize(e);
                }
            }

            return(size);
        }