/// <summary> /// WARNING: Only call this on an empty scene that has some terrains on it. MicroGSD LLC is not responsbile for data loss if this function is called by user. /// </summary> public static void RoadArchitectUnitTests() { CleanupTests(); //Create new road system and turn off updates: GameObject tRoadSystemObj = new GameObject("RoadArchitectSystem1"); RoadSystem = tRoadSystemObj.AddComponent <GSDRoadSystem>(); //Add road system component. RoadSystem.opt_bAllowRoadUpdates = false; int numTests = 5; double totalTestTime = 0f; for (int i = 1; i <= numTests; i++) { UnityEngine.Debug.Log("Running test " + i); double testTime = RunTest(i); totalTestTime += testTime; UnityEngine.Debug.Log("Test " + i + " complete. Test time: " + testTime + "ms"); } UnityEngine.Debug.Log("All tests completed. Total test time: " + totalTestTime + "ms"); //Turn updates back on and update road: RoadSystem.opt_bAllowRoadUpdates = true; RoadSystem.UpdateAllRoads(); }
/// <summary> /// WARNING: Only call this on an empty scene that has some terrains on it. MicroGSD LLC is not responsbile for data loss if this function is called by user. /// </summary> public static void RoadArchitectUnitTests() { //Get the existing road system, if it exists: GameObject GSDRS = (GameObject)GameObject.Find("RoadArchitectSystem1"); //Destroy the terrain histories: if (GSDRS != null) { Object[] tRoads = GSDRS.GetComponents <GSDRoad>(); foreach (GSDRoad xRoad in tRoads) { GSD.Roads.GSDTerraforming.TerrainsReset(xRoad); } Object.DestroyImmediate(GSDRS); } //Reset all terrains to 0,0 Object[] zTerrains = Object.FindObjectsOfType <Terrain>(); foreach (Terrain xTerrain in zTerrains) { xTerrain.terrainData.SetHeights(0, 0, new float[513, 513]); } //Create new road system and turn off updates: GameObject tRoadSystemObj = new GameObject("RoadArchitectSystem1"); GSDRoadSystem roadSystem = tRoadSystemObj.AddComponent <GSDRoadSystem>(); //Add road system component. roadSystem.opt_bAllowRoadUpdates = false; //Perform unit tests: RoadArchitectUnitTest1(); //Bridges RoadArchitectUnitTest2(); //2L intersections RoadArchitectUnitTest3(); //4L intersections RoadArchitectUnitTest4(); //Large suspension bridge RoadArchitectUnitTest5(); //Long road: //Turn updates back on and update road: roadSystem.opt_bAllowRoadUpdates = true; roadSystem.UpdateAllRoads(); }
static void Create() { //**************************************************************** // variables string netPath = "C:/DeepDrive/data/road_networks/halfCircle/"; int roadNum = 1; bool createNetworkFlag = true; //int roadNum = Directory.GetFiles(netPath).Length - 1; //**************************************************************** // Create a terrain that is big enough to hold the road network // (requires "RoadBounds" in the above folder) StreamReader reader = new StreamReader(netPath + "RoadBounds"); string line = reader.ReadLine(); string[] words = line.Split(','); Debug.Log("Terrain bounds: minx=" + words[0] + ", maxx=" + words[1] + ", minz=" + words[2] + ", maxz=" + words[3]); float minx = float.Parse(words[0]); float maxx = float.Parse(words[1]); float minz = float.Parse(words[2]); float maxz = float.Parse(words[3]); double transx = minx * 1.5; double transz = minz * 1.5; float ctrz = (minz + maxz) / 2; double twidth = (maxx - minx) * 1.5; // make the terrain 1.5x bigger double tlength = (maxz - minz) * 1.5; int twidthInt = (int)twidth; int tlengthInt = (int)tlength; CreateTerrain(twidthInt, tlengthInt, transx, transz); reader.Close(); // Create a road network if (createNetworkFlag) { string roadSysStr = "RoadArchitectSystem1"; // Get the existing road system (if it exists) and destory its consisting roads GameObject exRoadSystemObj = (GameObject)GameObject.Find(roadSysStr); if (exRoadSystemObj != null) { Object[] tRoads = exRoadSystemObj.GetComponents <GSDRoad>(); foreach (GSDRoad xRoad in tRoads) { GSD.Roads.GSDTerraforming.TerrainsReset(xRoad); } Object.DestroyImmediate(exRoadSystemObj); } // Create a new road system and turn off its updates (only generating the nodes but not the mesh) GameObject roadSystemObj = new GameObject(roadSysStr); GSDRoadSystem roadSystem = roadSystemObj.AddComponent <GSDRoadSystem>(); //Add road system component. roadSystem.opt_bAllowRoadUpdates = false; // this has to be set to false in order for following functions to operate // Create a road network CreateRoadNetwork(roadSystem, netPath, roadNum); // Turn updates back on and update the roads (create meshes for connecting the road nodes) roadSystem.opt_bAllowRoadUpdates = true; roadSystem.UpdateAllRoads(); } }
public void InsertRoads() { Debug.Log("InsertRoads"); foreach (MapRoad road in Map.Instance.mapRoads.GetMapRoads()) { /* * service: driveway * service: alley * service: parking_aisle * highway: service * service: siding * railway: rail */ if (ProcessRoad(road) == false) { continue; } List <List <Vector3> > positions = road.GetPositions(); //List<List<Vector3>> laneWaypoints = road.GetLanes(); List <Vector3> roadPoints = new List <Vector3>(); // positions for each road. path.Length >= 2 foreach (List <Vector3> path in positions) { int count = path.Count; // Can't create an intersection with a road that only has 2 points. There has to be at least 3. So we'll add a third point midway between the two points provided. if (count == 2) { Vector3 pos1 = path[0]; Vector3 pos2 = path[1]; // path[0].y is ignored, so we don't bother to get the average. Vector3 posMid = new Vector3(((path[0].x + path[1].x) / 2), path[0].y, ((path[0].z + path[1].z) / 2)); float terrainHeight1 = Terrain.activeTerrain.SampleHeight(pos1); float terrainHeight2 = Terrain.activeTerrain.SampleHeight(pos2); float terrainHeightMid = Terrain.activeTerrain.SampleHeight(posMid); roadPoints.Add(new Vector3(pos1.x, terrainHeight1, pos1.z)); roadPoints.Add(new Vector3(pos2.x, terrainHeight2, pos2.z)); roadPoints.Add(new Vector3(posMid.x, terrainHeightMid, posMid.z)); } for (int i = 0; i < count; i++) { Vector3 pos = path[i]; float terrainHeight = Terrain.activeTerrain.SampleHeight(pos); roadPoints.Add(new Vector3(pos.x, terrainHeight, pos.z)); //Debug.Log(pos); } } Debug.Log("Create Road"); GSDRoad _gsdRoad = CreateNewRoad(roadPoints, road.lanes); createdRoads.Add(_gsdRoad); } Debug.Log(createdRoads.Count + " roads created."); //GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(createdRoads[0], GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane); roadSystem.opt_bAllowRoadUpdates = true; roadSystem.UpdateAllRoads(); /*for (int i = 0; i < 10; i++) * { * GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(createdRoads[i], GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane); * }*/ /*foreach (GSDRoad _road in createdRoads) * { * * GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(_road, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane); * * }*/ //roadSystem.UpdateAllRoads(); }