public VertexProcessor(SoftwareVertex vertex, Vector4[] colors, Vector3[] normals, Vector2[] uvs, HardwareMeshProcessor mesh)
        {
            Positions = new Vector3[mesh.positions.Count];
            for (int i = 0; i != Positions.Length; ++i)
            {
                Positions[i] = mesh.positions[i][vertex.Index];
            }

            Colors = colors;
            Normals = normals;
            UVs = uvs;

            mesh.Verticies.AddLast(this);
        }
        public TriangleProcessor(SoftwareTriangle triangle, HardwareMeshProcessor mesh, bool loadColors, bool loadUVs, bool loadNormals)
        {
            // get color components
            var colors = new Vector4[3][];
            if (loadColors)
            {
                int componentCount = mesh.colorComponents.Count;
                for (int i = 0; i != colors.Length; ++i)
                {
                    colors[i] = new Vector4[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var colorComponent = mesh.colorComponents[i][triangle.Index].Colors;
                    colors[0][i] = colorComponent[0];
                    colors[1][i] = colorComponent[1];
                    colors[2][i] = colorComponent[2];
                }
            }

            // get normal components
            var normals = new Vector3[3][];
            if (loadNormals)
            {
                int componentCount = mesh.normalComponents.Count;
                for (int i = 0; i != normals.Length; ++i)
                {
                    normals[i] = new Vector3[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.normalComponents[i][triangle.Index].Normals;
                    normals[0][i] = normalComponent[0];
                    normals[1][i] = normalComponent[1];
                    normals[2][i] = normalComponent[2];
                }
            }

            // get uv components
            var uvs = new Vector2[3][];
            if (loadUVs)
            {
                int componentCount = mesh.uvComponents.Count;
                for (int i = 0; i != uvs.Length; ++i)
                {
                    uvs[i] = new Vector2[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.uvComponents[i][triangle.Index].UVs;
                    uvs[0][i] = normalComponent[0];
                    uvs[1][i] = normalComponent[1];
                    uvs[2][i] = normalComponent[2];
                }
            }

            // add verticies
            var vertex1 = new VertexProcessor(triangle.Verticies[0], colors[0], normals[0], uvs[0], mesh);
            var vertex2 = new VertexProcessor(triangle.Verticies[1], colors[1], normals[1], uvs[1], mesh);
            var vertex3 = new VertexProcessor(triangle.Verticies[2], colors[2], normals[2], uvs[2], mesh);
            Verticies = new VertexProcessor[3] {vertex1, vertex2, vertex3};

            mesh.Triangles.Add(this);
        }
Example #3
0
        private static void initData(SoftwareMesh softwareMesh, bool loadColors, bool loadUVs, bool loadNormals, out List<BufferLayoutElement> elements, out float[] vertices, out int[] indices)
        {
            // get position float size
            int posFloatCount = 0;
            var posElementType = BufferLayoutElementTypes.Vector3;
            switch (softwareMesh.Dimensions)
            {
                case 2:
                    posElementType = BufferLayoutElementTypes.Vector2;
                    posFloatCount = 2;
                    break;

                case 3:
                    posElementType = BufferLayoutElementTypes.Vector3;
                    posFloatCount = 3;
                    break;
            }

            // get vertex float size and create layout
            elements = new List<BufferLayoutElement>();
            int vertFloatCount = 0, posCount = 0, colorCount = 0, normalCount = 0, uvCount = 0;
            foreach (var key in softwareMesh.VertexComponentKeys)
            {
                switch (key.Key)
                {
                    case VertexComponentKeyTypes.Positions:
                        elements.Add(new BufferLayoutElement(posElementType, BufferLayoutElementUsages.Position, 0, posCount, vertFloatCount));
                        vertFloatCount += posFloatCount;
                        ++posCount;
                        break;
                }
            }

            foreach (var key in softwareMesh.TriangleComponentKeys)
            {
                switch (key.Key)
                {
                    case TriangleComponentKeyTypes.ColorComponents:
                        if (loadColors)
                        {
                            elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector4, BufferLayoutElementUsages.Color, 0, colorCount, vertFloatCount));
                            vertFloatCount += 4;
                            ++colorCount;
                        }
                        break;

                    case TriangleComponentKeyTypes.NormalComponents:
                        if (loadNormals)
                        {
                            elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector3, BufferLayoutElementUsages.Normal, 0, normalCount, vertFloatCount));
                            vertFloatCount += 3;
                            ++normalCount;
                        }
                        break;

                    case TriangleComponentKeyTypes.UVComponents:
                        if (loadUVs)
                        {
                            elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.UV, 0, uvCount, vertFloatCount));
                            vertFloatCount += 2;
                            ++uvCount;
                        }
                        break;
                }
            }

            // create vertex buffer
            var meshProcessor = new HardwareMeshProcessor(softwareMesh, loadColors, loadUVs, loadNormals);
            vertices = new float[meshProcessor.Verticies.Count * vertFloatCount];
            int vi = 0;
            foreach (var vertex in meshProcessor.Verticies)
            {
                int posIndex = 0, colorIndex = 0, normIndex = 0, uvIndex = 0;
                foreach (var element in elements)
                {
                    switch (element.Usage)
                    {
                        case BufferLayoutElementUsages.Position:
                            vertices[vi] = vertex.Positions[posIndex].X;
                            vertices[vi+1] = vertex.Positions[posIndex].Y;
                            if (posFloatCount == 3) vertices[vi+2] = vertex.Positions[posIndex].Z;
                            vi += posFloatCount;
                            ++posIndex;
                            break;

                        case BufferLayoutElementUsages.Color:
                            if (loadColors)
                            {
                                vertices[vi] = vertex.Colors[uvIndex].X;
                                vertices[vi+1] = vertex.Colors[uvIndex].Y;
                                vi += 4;
                                ++colorIndex;
                            }
                            break;

                        case BufferLayoutElementUsages.Normal:
                            if (loadNormals)
                            {
                                vertices[vi] = vertex.Normals[normIndex].X;
                                vertices[vi+1] = vertex.Normals[normIndex].Y;
                                vertices[vi+2] = vertex.Normals[normIndex].Z;
                                vi += 3;
                                ++normIndex;
                            }
                            break;

                        case BufferLayoutElementUsages.UV:
                            if (loadUVs)
                            {
                                vertices[vi] = vertex.UVs[uvIndex].X;
                                vertices[vi+1] = vertex.UVs[uvIndex].Y;
                                vi += 2;
                                ++uvIndex;
                            }
                            break;
                    }
                }
            }

            // create index buffer
            indices = new int[meshProcessor.Triangles.Count * 3];
            int ti = 0;
            foreach (var triangle in meshProcessor.Triangles)
            {
                indices[ti] = triangle.Verticies[0].Index;
                indices[ti+1] = triangle.Verticies[1].Index;
                indices[ti+2] = triangle.Verticies[2].Index;
                ti += 3;
            }
        }
Example #4
0
        private static void initData(SoftwareMesh softwareMesh, bool loadColors, bool loadUVs, bool loadNormals, out List <BufferLayoutElement> elements, out float[] vertices, out int[] indices)
        {
            // get position float size
            int posFloatCount  = 0;
            var posElementType = BufferLayoutElementTypes.Vector3;

            switch (softwareMesh.Dimensions)
            {
            case 2:
                posElementType = BufferLayoutElementTypes.Vector2;
                posFloatCount  = 2;
                break;

            case 3:
                posElementType = BufferLayoutElementTypes.Vector3;
                posFloatCount  = 3;
                break;
            }

            // get vertex float size and create layout
            elements = new List <BufferLayoutElement>();
            int vertFloatCount = 0, posCount = 0, colorCount = 0, normalCount = 0, uvCount = 0;

            foreach (var key in softwareMesh.VertexComponentKeys)
            {
                switch (key.Key)
                {
                case VertexComponentKeyTypes.Positions:
                    elements.Add(new BufferLayoutElement(posElementType, BufferLayoutElementUsages.Position, 0, posCount, vertFloatCount));
                    vertFloatCount += posFloatCount;
                    ++posCount;
                    break;
                }
            }

            foreach (var key in softwareMesh.TriangleComponentKeys)
            {
                switch (key.Key)
                {
                case TriangleComponentKeyTypes.ColorComponents:
                    if (loadColors)
                    {
                        elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector4, BufferLayoutElementUsages.Color, 0, colorCount, vertFloatCount));
                        vertFloatCount += 4;
                        ++colorCount;
                    }
                    break;

                case TriangleComponentKeyTypes.NormalComponents:
                    if (loadNormals)
                    {
                        elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector3, BufferLayoutElementUsages.Normal, 0, normalCount, vertFloatCount));
                        vertFloatCount += 3;
                        ++normalCount;
                    }
                    break;

                case TriangleComponentKeyTypes.UVComponents:
                    if (loadUVs)
                    {
                        elements.Add(new BufferLayoutElement(BufferLayoutElementTypes.Vector2, BufferLayoutElementUsages.UV, 0, uvCount, vertFloatCount));
                        vertFloatCount += 2;
                        ++uvCount;
                    }
                    break;
                }
            }

            // create vertex buffer
            var meshProcessor = new HardwareMeshProcessor(softwareMesh, loadColors, loadUVs, loadNormals);

            vertices = new float[meshProcessor.Verticies.Count * vertFloatCount];
            int vi = 0;

            foreach (var vertex in meshProcessor.Verticies)
            {
                int posIndex = 0, colorIndex = 0, normIndex = 0, uvIndex = 0;
                foreach (var element in elements)
                {
                    switch (element.Usage)
                    {
                    case BufferLayoutElementUsages.Position:
                        vertices[vi]     = vertex.Positions[posIndex].X;
                        vertices[vi + 1] = vertex.Positions[posIndex].Y;
                        if (posFloatCount == 3)
                        {
                            vertices[vi + 2] = vertex.Positions[posIndex].Z;
                        }
                        vi += posFloatCount;
                        ++posIndex;
                        break;

                    case BufferLayoutElementUsages.Color:
                        if (loadColors)
                        {
                            vertices[vi]     = vertex.Colors[uvIndex].X;
                            vertices[vi + 1] = vertex.Colors[uvIndex].Y;
                            vi += 4;
                            ++colorIndex;
                        }
                        break;

                    case BufferLayoutElementUsages.Normal:
                        if (loadNormals)
                        {
                            vertices[vi]     = vertex.Normals[normIndex].X;
                            vertices[vi + 1] = vertex.Normals[normIndex].Y;
                            vertices[vi + 2] = vertex.Normals[normIndex].Z;
                            vi += 3;
                            ++normIndex;
                        }
                        break;

                    case BufferLayoutElementUsages.UV:
                        if (loadUVs)
                        {
                            vertices[vi]     = vertex.UVs[uvIndex].X;
                            vertices[vi + 1] = vertex.UVs[uvIndex].Y;
                            vi += 2;
                            ++uvIndex;
                        }
                        break;
                    }
                }
            }

            // create index buffer
            indices = new int[meshProcessor.Triangles.Count * 3];
            int ti = 0;

            foreach (var triangle in meshProcessor.Triangles)
            {
                indices[ti]     = triangle.Verticies[0].Index;
                indices[ti + 1] = triangle.Verticies[1].Index;
                indices[ti + 2] = triangle.Verticies[2].Index;
                ti += 3;
            }
        }
Example #5
0
        public TriangleProcessor(SoftwareTriangle triangle, HardwareMeshProcessor mesh, bool loadColors, bool loadUVs, bool loadNormals)
        {
            // get color components
            var colors = new Vector4[3][];

            if (loadColors)
            {
                int componentCount = mesh.colorComponents.Count;
                for (int i = 0; i != colors.Length; ++i)
                {
                    colors[i] = new Vector4[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var colorComponent = mesh.colorComponents[i][triangle.Index].Colors;
                    colors[0][i] = colorComponent[0];
                    colors[1][i] = colorComponent[1];
                    colors[2][i] = colorComponent[2];
                }
            }

            // get normal components
            var normals = new Vector3[3][];

            if (loadNormals)
            {
                int componentCount = mesh.normalComponents.Count;
                for (int i = 0; i != normals.Length; ++i)
                {
                    normals[i] = new Vector3[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.normalComponents[i][triangle.Index].Normals;
                    normals[0][i] = normalComponent[0];
                    normals[1][i] = normalComponent[1];
                    normals[2][i] = normalComponent[2];
                }
            }

            // get uv components
            var uvs = new Vector2[3][];

            if (loadUVs)
            {
                int componentCount = mesh.uvComponents.Count;
                for (int i = 0; i != uvs.Length; ++i)
                {
                    uvs[i] = new Vector2[componentCount];
                }

                for (int i = 0; i != componentCount; ++i)
                {
                    var normalComponent = mesh.uvComponents[i][triangle.Index].UVs;
                    uvs[0][i] = normalComponent[0];
                    uvs[1][i] = normalComponent[1];
                    uvs[2][i] = normalComponent[2];
                }
            }

            // add verticies
            var vertex1 = new VertexProcessor(triangle.Verticies[0], colors[0], normals[0], uvs[0], mesh);
            var vertex2 = new VertexProcessor(triangle.Verticies[1], colors[1], normals[1], uvs[1], mesh);
            var vertex3 = new VertexProcessor(triangle.Verticies[2], colors[2], normals[2], uvs[2], mesh);

            Verticies = new VertexProcessor[3] {
                vertex1, vertex2, vertex3
            };

            mesh.Triangles.Add(this);
        }
Example #6
0
        public VertexProcessor(SoftwareVertex vertex, Vector4[] colors, Vector3[] normals, Vector2[] uvs, HardwareMeshProcessor mesh)
        {
            Positions = new Vector3[mesh.positions.Count];
            for (int i = 0; i != Positions.Length; ++i)
            {
                Positions[i] = mesh.positions[i][vertex.Index];
            }

            Colors  = colors;
            Normals = normals;
            UVs     = uvs;

            mesh.Verticies.AddLast(this);
        }