// Use this for initialization void Start() { //Random.InitState(123); float[,] heightmap = new float[1024, 1024]; for (int x = 0; x < 1024; x++) { for (int y = 0; y < 1024; y++) { heightmap[x, y] = getHeight(x, y); } } RoadNetworkGenerator rng = GetComponent <RoadNetworkGenerator>(); Graph <Vector2, Segment> roadGraph = rng.generateNetwork(heightmap); roadGraph.addNode(new Vector2(511, 511)); Dictionary <Vector2, Vector3> pos = new Dictionary <Vector2, Vector3>(); foreach (Vector2 v in roadGraph.edges.Keys) { pos.Add(v, new Vector3(v.x, heightmap[(int)v.x + 512, (int)v.y + 512], v.y)); } transform.GetChild(0).GetComponent <RoadPGraph>().heightmap = heightmap; transform.GetChild(0).GetComponent <RoadPGraph>().drawGraph(roadGraph, pos); TestRenderer renderer = new TestRenderer(heightmap, 1024, 1024); transform.GetChild(1).GetComponent <PhysicalMap>().init(1024, 1024); transform.GetChild(1).GetComponent <PhysicalMap>().draw(renderer); }
void Start() { context = RoadNetworkGenerator.BeginInteractiveGeneration(); visited = new HashSet <Segment>(); mask = ((displayHighways) ? RoadNetworkTraversal.HIGHWAYS_MASK : 0) | ((displayStreets) ? RoadNetworkTraversal.STREETS_MASK : 0); segmentsGOs = new List <GameObject>(); iconGOs = new List <GameObject>(); action = 1; }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { roadNetworkGenerator = new RoadNetworkGenerator(dstManager); using (BlobAssetStore blobAssetStore = new BlobAssetStore()) { this.carEntityBase = GameObjectConversionUtility.ConvertGameObjectHierarchy(CarPrefab, GameObjectConversionSettings.FromWorld(dstManager.World, blobAssetStore)); roadNetworkGenerator.GenerateNetwork(RoadPieces, out var roadNodes, out var roadSegments); this.roadSegments = roadSegments; this.dstManager = dstManager; SpawnCars(dstManager, carEntityBase, roadSegments); } }
void Start() { SetupConfig(); // --- RoadNetworkGenerator.DebugData debugData; RoadNetworkGenerator.Generate(out segments, out quadtree, out debugData); Debug.Log(segments.Count + " segments"); // --- mask = ((generateHighways) ? RoadNetworkTraversal.HIGHWAYS_MASK : 0) | ((generateStreets) ? RoadNetworkTraversal.STREETS_MASK : 0); float minX = float.MaxValue, maxX = -float.MaxValue, minY = float.MaxValue, maxY = -float.MaxValue; HashSet <Segment> visited = new HashSet <Segment>(); foreach (var segment in segments) { RoadNetworkTraversal.PreOrder(segment, (a) => { minX = Mathf.Min(Mathf.Min(a.Start.x, a.End.x), minX); minY = Mathf.Min(Mathf.Min(a.Start.y, a.End.y), minY); maxX = Mathf.Max(Mathf.Max(a.Start.x, a.End.x), maxX); maxY = Mathf.Max(Mathf.Max(a.Start.y, a.End.y), maxY); return(true); }, mask, ref visited); } Vector2 size = new Vector2(maxX - minX, maxY - minY); Vector2 center = new Vector2(minX, minY); boundingBox = new Rect(center, size); finished = true; }
void Update() { if (action == 0) { return; } if (action == 1) { if (!end) { end = Input.GetKeyDown(KeyCode.F5); } if (!step) { step = Input.GetKeyDown(KeyCode.F10); } if (!step && !end) { return; } if (end) { RoadNetworkGenerator.EndInteractiveGeneration(ref context); action = 0; } else { if (!RoadNetworkGenerator.InteractiveGenerationStep(speed, ref context)) { action = 0; } } foreach (Segment segment in context.segments) { RoadNetworkTraversal.PreOrder(segment, Visitor, mask, ref visited); } RemoveIcons(); if (context.debugData.intersections.Count > 0 || context.debugData.snaps.Count > 0 || context.debugData.intersectionsRadius.Count > 0) { foreach (Vector2 intersection in context.debugData.intersections) { iconGOs.Add(CreateIcon(intersection, iconSize, downscaleFactor, z, intersectionIcon)); } foreach (Vector2 snap in context.debugData.snaps) { iconGOs.Add(CreateIcon(snap, iconSize, downscaleFactor, z, snapIcon)); } foreach (Vector2 intersectionRadius in context.debugData.intersectionsRadius) { iconGOs.Add(CreateIcon(intersectionRadius, iconSize, downscaleFactor, z, intersectionRadiusIcon)); } context.debugData.intersections.Clear(); context.debugData.snaps.Clear(); context.debugData.intersectionsRadius.Clear(); } step = false; } }
void Update() { if (action == 0) { return; } if (action == 1) { if (!end) { end = Input.GetKeyDown(KeyCode.F5); } if (!step) { step = Input.GetKeyDown(KeyCode.F10); } if (!step && !end) { return; } if (end) { RoadNetworkGenerator.EndInteractiveGeneration(ref context); action = 0; } else { if (!RoadNetworkGenerator.InteractiveGenerationStep(speed, ref context)) { action = 0; } } // --- var roadGeometry = RoadNetworkGeometryBuilder.Build( scale, Config.highwaySegmentWidth * scale, Config.streetSegmentWidth * scale, lengthStep, context.segments, ((displayHighways) ? RoadNetworkTraversal.HIGHWAYS_MASK : 0) | ((displayStreets) ? RoadNetworkTraversal.STREETS_MASK : 0) ); CreateRoadMesh(roadGeometry); // --- RemoveIcons(); if (context.debugData.intersections.Count > 0 || context.debugData.snaps.Count > 0 || context.debugData.intersectionsRadius.Count > 0) { foreach (Vector2 intersection in context.debugData.intersections) { iconGOs.Add(CreateIcon(intersection, iconSize, scale, z, intersectionIcon)); } foreach (Vector2 snap in context.debugData.snaps) { iconGOs.Add(CreateIcon(snap, iconSize, scale, z, snapIcon)); } foreach (Vector2 intersectionRadius in context.debugData.intersectionsRadius) { iconGOs.Add(CreateIcon(intersectionRadius, iconSize, scale, z, intersectionRadiusIcon)); } context.debugData.intersections.Clear(); context.debugData.snaps.Clear(); context.debugData.intersectionsRadius.Clear(); } step = false; } }
void Start() { context = RoadNetworkGenerator.BeginInteractiveGeneration(); iconGOs = new List <GameObject>(); action = 1; }