Exemplo n.º 1
0
    public void BuildPath()
    {
        List <Vector3> path = city.metricConstraint.ProcessPathNoEndpoints(startPosition, endPosition);

        Intersection start = exposedHead;
        Intersection end   = exposedChild;

        if (exposedHead == null) //initialized with Init(Intersection, Intersection);
        {
            start = CigenFactory.CreateOrMergeIntersection(startPosition, city);
        }
        if (exposedChild == null)
        {
            end = CigenFactory.CreateOrMergeIntersection(endPosition, city);
        }

        Intersection curr = start;

        foreach (Vector3 v in path)
        {
            Intersection newIntersection = CigenFactory.CreateOrMergeIntersection(v, city);
            CigenFactory.CreateRoad(curr, newIntersection);
            curr = newIntersection;
        }
        CigenFactory.CreateRoad(curr, end);
    }
Exemplo n.º 2
0
 public void Init(Vector3 position, CitySettings settings)
 {
     transform.position = position;
     this.settings      = settings;
     metricConstraint   = MetricFactory.Process(this.settings.metric, settings);
     origin             = CigenFactory.CreateOrMergeIntersection(RandomLocalPosition(), this);
 }
Exemplo n.º 3
0
    public Intersection CreateIntersectionAtPositionOnRoad(Vector3 position, Road road)
    {
        Intersection newIntersection = CigenFactory.CreateOrMergeIntersection(position, this);
        Intersection parent          = road.parentNode;
        Intersection child           = road.childNode;

        road.Remove();
        CigenFactory.CreateRoad(parent, newIntersection);
        CigenFactory.CreateRoad(newIntersection, child);
        return(newIntersection);
    }
Exemplo n.º 4
0
        public IEnumerator BuildCity(Vector3 initState)
        {
            if (waitUntilBuilt != null)
            {
                yield return(new WaitUntil(() => waitUntilBuilt.isBuilt));
            }

            if (settings == null)
            {
                Debug.LogError("No CigenSettings detected, drag and drop one into the inspector.");
                yield break;
            }

            //print("building city");
            int it = 0;

            city = CigenFactory.CreateCity(initState, settings);
            while (true)
            {
                it++;
                if (city.roads.Count >= settings.maxNumberOfRoads)
                {
                    break;
                }

                //print("Starting next iteration...");
                city.AddRandomIntersectionToRoadNetwork();
                yield return(new WaitForEndOfFrame());
            }

            //Because new roads can make an intersection need rebuilding, lets
            //wait until we finish generating every road before we generate intersection meshes.
            foreach (Intersection i in city.intersections)
            {
                yield return(StartCoroutine(i.BuildMesh()));
            }

            foreach (Road r in city.roads)
            {
                r.ZonePlots();
                yield return(new WaitForEndOfFrame());
            }

            print("Intersections: " + city.intersections.Count);
            print("Roads: " + city.roads.Count);
            print("Plots: " + city.plots.Count);
            print("Iterations: " + it);
            this.isBuilt = true;
            yield break;
        }
Exemplo n.º 5
0
Arquivo: Road.cs Projeto: yazici/Cigen
    public void ZonePlots()
    {
        if (length < city.settings.minimumRoadLength)
        {
            return;
        }

        if (this.leftPlot != null)
        {
            Destroy(this.leftPlot.gameObject);
        }
        if (this.rightPlot != null)
        {
            Destroy(this.rightPlot.gameObject);
        }

        Plot[] plots = CigenFactory.CreatePlots(this);
        this.leftPlot  = plots[0];
        this.rightPlot = plots[1];
    }
Exemplo n.º 6
0
    public void AddRandomIntersectionToRoadNetwork()
    {
        Vector3 p1 = RandomLocalPosition();

        Vector3      bestPositionForIntersection = Vector3.one * float.MaxValue;
        Road         roadToConnectTo             = null;
        Intersection intersectionToConnectTo     = null;
        object       cmpr = null;

        {
            object[] data = ClosestPointOnRoadNetwork(p1);
            bestPositionForIntersection = (Vector3)data[0];
            cmpr = data[1];
        }
        if (bestPositionForIntersection != Vector3.one * float.MaxValue)
        {
            if (IsValidRoad(bestPositionForIntersection, p1))
            {
                Intersection q1 = CigenFactory.CreateOrMergeIntersection(p1, this);

                if (cmpr is Intersection)
                {
                    intersectionToConnectTo = (Intersection)cmpr;
                }

                if (cmpr is Road)
                {
                    roadToConnectTo         = (Road)cmpr;
                    intersectionToConnectTo = CreateIntersectionAtPositionOnRoad(bestPositionForIntersection, roadToConnectTo);
                }

                if (intersectionToConnectTo != null)
                {
                    CigenFactory.CreatePath(q1, intersectionToConnectTo);
                }
            }
        }
    }
Exemplo n.º 7
0
 private void ConnectNodes(Intersection parent, Intersection child)
 {
     CigenFactory.CreateRoad(parent, child);
     //DrawLineBetweenPoints(parent.Position, child.Position);
 }