Пример #1
0
        static string DoExport(string path, IEnumerable <ProBuilderMesh> models, PlyOptions options)
        {
            string name      = Path.GetFileNameWithoutExtension(path);
            string directory = Path.GetDirectoryName(path);

            string ply;

            if (PlyExporter.Export(models, out ply, options))
            {
                try
                {
                    FileUtility.WriteAllText(string.Format("{0}/{1}.ply", directory, name), ply);
                }
                catch (System.Exception e)
                {
                    Debug.LogWarning(string.Format("Failed writing PLY to path: {0}\n{1}", string.Format("{0}/{1}.ply", path, name), e.ToString()));
                    return(null);
                }
            }
            else
            {
                Debug.LogWarning("No meshes selected.");
                return(null);
            }

            return(path);
        }
        /// <summary>
        /// Exports the currently shown mesh to a location chosen by the user.
        /// </summary>
        /// <remarks>
        /// The method supports .obj and .ply file formats.
        /// </remarks>
        public void Export()
        {
            var path = PathChooser.FindSaveLocation();

            if (path == null)
            {
                return;
            }

            var vert = _mainMesh.Positions.Select(p => new Vec3((float)p.X, (float)p.Y, (float)p.Z)).ToArray();
            var tris = new List <int>();

            for (int i = 0; i < _stepcount; i++)
            {
                var step = _steps[i];
                foreach (int[] tri in step.triangles)
                {
                    foreach (int ii in tri)
                    {
                        tris.Add(ii);
                    }
                }
            }

            var polygon = new ExportPolygon(vert, tris.ToArray());

            if (path.EndsWith(".obj"))
            {
                IOhandler.ObjExporter.Export(path, polygon);
            }
            else
            {
                PlyExporter.Export(path, polygon);
            }
        }
Пример #3
0
    public static void NumbersAreCultureInvariant()
    {
        var cube    = ShapeGenerator.CreateShape(ShapeType.Cube);
        var current = Thread.CurrentThread.CurrentCulture;

        try
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

            string ply;

            if (PlyExporter.Export(new ProBuilderMesh[] { cube }, out ply))
            {
                Assert.IsFalse(ply.Any(x => x.Equals(',')));
            }
        }
        finally
        {
            Thread.CurrentThread.CurrentCulture = current;
            UnityEngine.Object.DestroyImmediate(cube);
        }
    }
        /// <summary>
        /// Exports the mesh to a location chosen by the user.
        /// </summary>
        /// <remarks>
        /// The method supports .obj and .ply file formats.
        /// </remarks>
        public void Export()
        {
            var path = PathChooser.FindSaveLocation();

            if (path == null)
            {
                return;
            }

            var vert = _mainMesh.Positions.Select(p => new Vec3((float)p.X, (float)p.Y, (float)p.Z)).ToArray();
            var tris = _mainMesh.TriangleIndices.ToArray();

            var polygon = new ExportPolygon(vert, tris);

            if (path.EndsWith(".obj"))
            {
                IOhandler.ObjExporter.Export(path, polygon);
            }
            else
            {
                PlyExporter.Export(path, polygon);
            }
        }
Пример #5
0
        /// <summary>
        /// Exports all given meshes.
        /// </summary>
        /// <param name="mesh">Meshes to export.</param>
        /// <param name="elapsedTime">Elapsed creation time for each mesh, expected to match mesh in length.</param>
        public static void Export(IPolygon[] mesh, long[] elapsedTime)
        {
            int n             = mesh.Count();
            var paths         = new string[n];
            var exportSuccess = new bool[n];

            PrintTitle("EXPORTING");
            Console.WriteLine();
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine($"Choose location for export {i + 1} of {n}\n");
                paths[i] = PathChooser.FindSaveLocation();
            }

            Parallel.For(0, n, i => {
                if (paths[i] != null)
                {
                    exportSuccess[i] = paths[i].EndsWith("obj") ? ObjExporter.Export(paths[i], mesh[i], elapsedTime[i]) : PlyExporter.Export(paths[i], mesh[i], elapsedTime[i]);
                }
            });

            for (int i = 0; i < n; i++)
            {
                if (paths[i] == null)
                {
                    Console.WriteLine($"\nExporting of file {i + 1} of {n} failed!");
                    continue;
                }

                var s = paths[i].Split('\\');
                Console.WriteLine($"\nOpen generated '{s[s.Length - 1]}' file? Y/N");
                Console.Write("> ");
                if (Console.ReadLine().ToLower().Contains("y"))
                {
                    Process.Start(paths[i]);
                }
            }
        }