Exemplo n.º 1
0
        public void TestRoads()
        {
            var path1 = new LinePath(new List <Vector2>
            {
                new Vector2(0, 0),
                new Vector2(40, 0),
                new Vector2(44, 1),
                new Vector2(46, 2),
                new Vector2(46 + 10, 2 + 10)
            });

            var path2 = new LinePath(new List <Vector2>
            {
                new Vector2(20, -30),
                new Vector2(20, 29)
            });

            var geom = new RoadGeometry(new List <LinePath>()
            {
                path1, path2
            }, TS1RoadTemplates.OLD_TOWN_DEFAULT_TEMPLATES);

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

            //write result
            using (var file = File.Open(@"C:\Users\Rhys\Documents\testroad.obj", FileMode.Create))
            {
                SaveRoadResult(geom, file);
            }
        }
Exemplo n.º 2
0
        public void TestRoads2()
        {
            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();

            //write result
            using (var file = File.Open(@"C:\Users\Rhys\Documents\testroad2.obj", FileMode.Create))
            {
                SaveRoadResult(geom, file);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }