Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var inputFilename = args[0];
            var outputFilename = args.Length < 2 ? "output.mesh" : args[1];

            PlyFile ply;
            using(var inputFile = File.OpenText(inputFilename)) {
                ply = new PlyParser().Parse(inputFile);
            }

            var vertex = GetRequiredElementType(ply, "vertex");
            var face = GetRequiredElementType(ply, "face");

            VerifySimplePropertiesExist(vertex, "x", "y", "z");
            VerifyListPropertiesExist(face, "vertex_indices");

            var vertices =
                ply.Elements[vertex]
                    .Select(el => new Point(
                        (float)el.GetValue("x"),
                        (float)el.GetValue("y"),
                        (float)el.GetValue("z")));

            var triangles = from el in ply.Elements[face]
                            let indices = (object[]) el.GetValue("vertex_indices")
                            select new MeshTriangle((int) indices[0], (int) indices[1], (int) indices[2], null); // HACK

            var mesh = new Mesh(vertices, triangles);

            using(var outputFile = File.Create(outputFilename)) {
                new MeshSerializer().Serialize(outputFile, mesh);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var inputFilename  = args[0];
            var outputFilename = args.Length < 2 ? "output.mesh" : args[1];

            PlyFile ply;

            using (var inputFile = File.OpenText(inputFilename)) {
                ply = new PlyParser().Parse(inputFile);
            }

            var vertex = GetRequiredElementType(ply, "vertex");
            var face   = GetRequiredElementType(ply, "face");

            VerifySimplePropertiesExist(vertex, "x", "y", "z");
            VerifyListPropertiesExist(face, "vertex_indices");

            var vertices =
                ply.Elements[vertex]
                .Select(el => new Point(
                            (float)el.GetValue("x"),
                            (float)el.GetValue("y"),
                            (float)el.GetValue("z")));

            var triangles = from el in ply.Elements[face]
                            let indices = (object[])el.GetValue("vertex_indices")
                                          select new MeshTriangle((int)indices[0], (int)indices[1], (int)indices[2], null);  // HACK

            var mesh = new Mesh(vertices, triangles);

            using (var outputFile = File.Create(outputFilename)) {
                new MeshSerializer().Serialize(outputFile, mesh);
            }
        }