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);
        }
Пример #2
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);
        }