public void SaveHMResult(SimplifiedHeightmap hm, Stream stream)
        {
            using (var io = new StreamWriter(stream))
            {
                io.WriteLine("# Experimental mesh projection output.");

                io.WriteLine("s 1");

                io.WriteLine("o projected");
                foreach (var vert in hm.Vertices)
                {
                    io.WriteLine("v " + vert.X.ToString(CultureInfo.InvariantCulture) + " " + vert.Y.ToString(CultureInfo.InvariantCulture) + " " + vert.Z.ToString(CultureInfo.InvariantCulture));
                }

                io.Write("f ");
                var baseInd = 1;
                var ticker  = 0;
                var j       = 0;
                foreach (var ind in hm.Indices)
                {
                    var i = ind + baseInd;
                    io.Write(i + " ");
                    if (++ticker == 3)
                    {
                        io.WriteLine("");
                        if (j < hm.Indices.Count - 1)
                        {
                            io.Write("f ");
                        }
                        ticker = 0;
                    }
                    j++;
                }
            }
        }
        public void TestHeightmapGen()
        {
            var map = BasicMap();

            var timer = new System.Diagnostics.Stopwatch();

            timer.Start();
            var heightmap = new SimplifiedHeightmap(512, map);

            heightmap.BuildSecondDerivative();
            heightmap.GenerateFullTree();
            heightmap.GenerateMesh();
            timer.Stop();

            Console.WriteLine("=== 512x512 heightmap took " + timer.ElapsedMilliseconds);
            //write result
            using (var file = File.Open(@"C:\Users\Rhys\Documents\testhm2.obj", FileMode.Create))
            {
                SaveHMResult(heightmap, file);
            }
        }
        public void TestCombo()
        {
            var map = BasicMap();

            var timer = new System.Diagnostics.Stopwatch();

            timer.Start();

            var heightmap = new SimplifiedHeightmap(512, map);

            heightmap.BuildSecondDerivative();
            heightmap.GenerateFullTree();
            heightmap.GenerateMesh();

            timer.Stop();
            Console.WriteLine("!!! Heightmap took " + timer.ElapsedMilliseconds + "ms.");
            timer.Restart();

            var svg   = new SVGParser(File.ReadAllText(@"C:\Users\Rhys\Documents\roads.svg"));
            var paths = svg.ToLinePaths();

            var geom = new RoadGeometry(paths, TS1RoadTemplates.OLD_TOWN_DEFAULT_TEMPLATES);

            geom.GenerateIntersections();
            geom.GenerateRoadGeometry();

            timer.Stop();
            Console.WriteLine("!!! Road took " + timer.ElapsedMilliseconds + "ms.");
            timer.Restart();

            List <MeshProjector> projectors = new List <MeshProjector>();

            foreach (var pair in geom.Meshes)
            {
                var mesh = pair.Value;

                var baseTris = new List <BaseMeshTriangle>();
                for (int i = 0; i < heightmap.Indices.Count; i += 3)
                {
                    baseTris.Add(new BaseMeshTriangle()
                    {
                        Vertices = new Vector3[] {
                            heightmap.Vertices[heightmap.Indices[i]],
                            heightmap.Vertices[heightmap.Indices[i + 1]],
                            heightmap.Vertices[heightmap.Indices[i + 2]],
                        }
                    });
                }

                var projTris = new List <MeshTriangle>();
                for (int i = 0; i < mesh.Indices.Count; i += 3)
                {
                    projTris.Add(new MeshTriangle()
                    {
                        Vertices = new Vector3[] {
                            mesh.Vertices[mesh.Indices[i]].Position,
                            mesh.Vertices[mesh.Indices[i + 1]].Position,
                            mesh.Vertices[mesh.Indices[i + 2]].Position,
                        },
                        TexCoords = new float[][]
                        {
                            mesh.Vertices[mesh.Indices[i]].TexCoords,
                            mesh.Vertices[mesh.Indices[i + 1]].TexCoords,
                            mesh.Vertices[mesh.Indices[i + 2]].TexCoords,
                        }
                    });
                }

                var proj = new MeshProjector(baseTris, projTris);
                proj.Project();
                projectors.Add(proj);
            }

            timer.Stop();
            Console.WriteLine("!!! Projection took " + timer.ElapsedMilliseconds + "ms.");

            //write result
            using (var file = File.Open(@"C:\Users\Rhys\Documents\combined.obj", FileMode.Create))
            {
                SaveResults(projectors, file);
            }
        }