IEnumerator ProceduralLocal() { msg.Stop(Job.StartProcedural); msg.Start(Job.ProceduralPreparation); SimpleClient.jobStatus[jobNumber] = msg; this.transform.position = TilePosition - new Vector3((float)TileManager.TileWidth * (float)TileManager.Scaling / 2f, 0f, (float)TileManager.TileWidth * (float)TileManager.Scaling / 2f); terrain = this.gameObject.GetOrAddComponent <Terrain>(); tC = this.gameObject.GetOrAddComponent <TerrainCollider>(); Building.Clear(); Intersection.Clear(); Street.Clear(); Water.Clear(); River.Clear(); Bridge.Clear(); unusedWays.Clear(); streets.Clear(); streetPolygons.Clear(); msg.Stop(Job.ProceduralPreparation); #region LOD0 if (lOD == 0) { Console.AddMessage("Procedural lod 0"); Debug.Log("Procedural lod 0"); #region terrain TerrainData terrainData = new TerrainData(); //HeightMap terrainData.heightmapResolution = 257; float[,] heights = new float[257, 257]; for (int x = 0; x < heights.GetLength(0); x++) { for (int y = 0; y < heights.GetLength(1); y++) { heights[x, y] = 1f; } } terrainData.SetHeights(0, 0, heights); terrainData.size = new Vector3((float)TileManager.TileWidth * (float)TileManager.Scaling, 10f, (float)TileManager.TileWidth * (float)TileManager.Scaling); ////SplatPrototypes //SplatPrototype[] splatPrototypes = new SplatPrototype[1]; //splatPrototypes[0] = new SplatPrototype(); ////splatPrototypes[0].texture = (Texture2D)Resources.Load("Textures/White1px"); //splatPrototypes[0].texture = (Texture2D)Resources.Load("Textures/Terrain/Grass (Hill)"); //terrainData.splatPrototypes = splatPrototypes; terrain.terrainData = terrainData; tC.terrainData = terrainData; #endregion terrain #region mesh TileMesh.Clear(); Vertex[] tileQuadVertices = new Vertex[4]; tileQuadVertices[0] = new Vertex(new Vector3((float)(-TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(-TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[1] = new Vertex(new Vector3((float)(-TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[2] = new Vertex(new Vector3((float)(TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[3] = new Vertex(new Vector3((float)(TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(-TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); new Quad(tileQuadVertices, TileMesh, MaterialManager.GetMaterial("diffuseBrown")); TileMesh.FillMeshDivideMaterialsKeepMeshStructure(transform, true); #endregion Debug.Log("Procedural lod 0 - Done"); } #endregion #region LOD5 if (lOD == 5) { msg.Start(Job.CreateTerrain); SimpleClient.jobStatus[jobNumber] = msg; #region terrain if (terrain.terrainData == null) { terrain.terrainData = new TerrainData(); } //HeightMap terrain.terrainData.heightmapResolution = 257; terrain.terrainData.alphamapResolution = 257; float height = 0f; terrain.terrainData.SetHeights(0, 0, SRTMHeightProvider.GetInterpolatedTerrain(this.Query.BoundingBox, out height)); terrain.terrainData.size = new Vector3((float)TileManager.TileWidth * (float)TileManager.Scaling, height, (float)TileManager.TileWidth * (float)TileManager.Scaling); tC.terrainData = terrain.terrainData; msg.Stop(Job.CreateTerrain); #endregion terrain #region mesh msg.Start(Job.MeshPreparation); SimpleClient.jobStatus[jobNumber] = msg; TileMesh.Clear(); if (BackgroundMesh != null) { BackgroundMesh.Clear(); } else { BackgroundMesh = new ModularMesh(TileMesh, "BackgroundMesh"); } if (BuildingMesh != null) { BuildingMesh.Clear(); } else { BuildingMesh = new ModularMesh(TileMesh, "BuildingMesh"); } if (StreetMesh != null) { StreetMesh.Clear(); } else { StreetMesh = new ModularMesh(TileMesh, "StreetMesh"); } if (OtherMesh != null) { OtherMesh.Clear(); } else { OtherMesh = new ModularMesh(TileMesh, "OtherMesh"); } msg.Stop(Job.MeshPreparation); msg.Start(Job.TileQuad); SimpleClient.jobStatus[jobNumber] = msg; Vertex[] tileQuadVertices = new Vertex[4]; tileQuadVertices[0] = new Vertex(new Vector3((float)(-TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(-TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[1] = new Vertex(new Vector3((float)(-TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[2] = new Vertex(new Vector3((float)(TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); tileQuadVertices[3] = new Vertex(new Vector3((float)(TileManager.TileWidth * TileManager.Scaling / 2d), 0f, (float)(-TileManager.TileWidth * TileManager.Scaling / 2d)) + TilePosition); new Quad(tileQuadVertices, BackgroundMesh, MaterialManager.GetMaterial("diffuseBlack")); msg.Stop(Job.TileQuad); yield return(null); msg.Start(Job.River); SimpleClient.jobStatus[jobNumber] = msg; //Create Domain Objects ///Relations foreach (KeyValuePair <long, OSMRelation> kV in Query.OSM.relations) { OSMRelation relation = kV.Value; River.TryCreateFromOSM(relation, this); yield return(null); } msg.Stop(Job.River); msg.Start(Job.Ways); SimpleClient.jobStatus[jobNumber] = msg; ///Ways foreach (KeyValuePair <long, OSMWay> kV in Query.OSM.ways) { OSMWay way = kV.Value; if (!way.FirstInBounds(Query.BoundingBox, Query.OSM)) { continue; } if (!Building.TryCreateFromOSM(way, this)) { if (!Intersection.TryCreateFromOSM(way, this)) { if (!Water.TryCreateFromOSM(way, this)) { } } } yield return(null); } msg.Stop(Job.Ways); //Nodes!? //foreach (KeyValuePair<long, OSMNode> kV in Query.OSM.nodes) //{ // OSMNode node = kV.Value; // TrafficSignal.TryCreateFromOSM(node, this); //} //Debug.Log("CreateStreets"); ////Create Streets (and Bridges) //Street.CreateStreets(this); //CreateTheMeshes //Debug.Log("CreateAllMeshes StreetMesh"); //Street.CreateAllMeshes(StreetMesh); //Debug.Log("CreateAllMeshes StreetMesh Bridge"); //Bridge.CreateAllMeshes(StreetMesh); //Debug.Log("CreateAllMeshes StreetMesh Intersection"); //Intersection.CreateAllMeshes(StreetMesh); //Debug.Log("CreateAllMeshes StreetMesh Street"); //Street.CreateAllMeshes(StreetMesh); // A second time, cause Intersections change streetproperties msg.Start(Job.CreateBuildingMesh); SimpleClient.jobStatus[jobNumber] = msg; Building.CreateAllMeshes(BuildingMesh); msg.Stop(Job.CreateBuildingMesh); //Debug.Log("CreateAllMeshes Water"); //Water.CreateAllMeshes(OtherMesh); //Debug.Log("CreateAllMeshes TrafficSignal"); //TrafficSignal.CreateAllMeshes(OtherMesh); //StreetPolygon currentStreetPolygon; //bool hasLeftPolygon = false; //bool hasRightPolygon = false; //for (int i = 0; i < streets.Count; i++) //{ // for (int j = 0; j < streetPolygons.Count; j++) // { // hasLeftPolygon = streetPolygons[j].IsLefthandPolygonOf(streets[i]); // hasRightPolygon = streetPolygons[j].IsRighthandPolygonOf(streets[i]); // } // if (!hasLeftPolygon) // { // if (StreetPolygon.GetLefthandStreetPolygon(streets[i], out currentStreetPolygon)) // streetPolygons.Add(currentStreetPolygon); // } // if (!hasRightPolygon) // { // if (StreetPolygon.GetRighthandStreetPolygon(streets[i], out currentStreetPolygon)) // streetPolygons.Add(currentStreetPolygon); // } // hasLeftPolygon = false; // hasRightPolygon = false; //} //for (int i = 0; i < streetPolygons.Count; i++) //{ // streetPolygons[i].Triangulate(StreetMesh , MaterialManager.GetMaterial("error")); //} msg.Start(Job.FillMeshDivideMaterials); SimpleClient.jobStatus[jobNumber] = msg; TileMesh.FillMeshDivideMaterialsKeepMeshStructure(transform, true); msg.Stop(Job.FillMeshDivideMaterials); #endregion } #endregion msg.Start(Job.GarbageCollection); SimpleClient.jobStatus[jobNumber] = msg; System.GC.Collect(); msg.Stop(Job.GarbageCollection); yield return(null); msg.Start(Job.ProceduralDone); SimpleClient.jobStatus[jobNumber] = msg; OnProceduralDoneLocal(); msg.Stop(Job.Worker); msg.Stop(); yield return(true); }