public static void UpdateAllRoads()
    {
        GSDRoad[] allRoadObjects = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));

        int roadCount = allRoadObjects.Length;

        GSDRoad singleRoad = null;

        GSDSplineC[] tPiggys = null;
        if (roadCount > 1)
        {
            tPiggys = new GSDSplineC[roadCount - 1];
        }

        for (int count = 0; count < roadCount; count++)
        {
            singleRoad = allRoadObjects[count];
            if (count > 0)
            {
                tPiggys[count - 1] = singleRoad.GSDSpline;
            }
        }

        singleRoad = allRoadObjects[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            singleRoad.PiggyBacks = tPiggys;
        }
        singleRoad.UpdateRoad();
    }
Пример #2
0
        /// <summary>
        /// This will create an intersection if two nodes overlap on the road. Only good if the roads only overlap once.
        /// </summary>
        /// <param name="bRoad"></param>
        /// <param name="tRoad"></param>
        private static void UnitTest_IntersectionHelper(GSDRoad bRoad, GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType, GSDRoadIntersection.RoadTypeEnum rType)
        {
            GSDSplineN tInter1 = null;
            GSDSplineN tInter2 = null;

            foreach (GSDSplineN tNode in bRoad.GSDSpline.mNodes)
            {
                foreach (GSDSplineN xNode in tRoad.GSDSpline.mNodes)
                {
                    if (GSDRootUtil.IsApproximately(Vector3.Distance(tNode.transform.position, xNode.transform.position), 0f, 0.05f))
                    {
                        tInter1 = tNode;
                        tInter2 = xNode;
                        break;
                    }
                }
            }

            if (tInter1 != null && tInter2 != null)
            {
                GameObject          tInter = GSD.Roads.GSDIntersections.CreateIntersection(tInter1, tInter2);
                GSDRoadIntersection GSDRI  = tInter.GetComponent <GSDRoadIntersection>();
                GSDRI.iStopType = iStopType;
                GSDRI.rType     = rType;
            }
        }
    public static void UpdateAllRoads()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));

        int RoadCount = tRoadObjs.Length;

        GSDRoad tRoad = null;

        GSDSplineC[] tPiggys = null;
        if (RoadCount > 1)
        {
            tPiggys = new GSDSplineC[RoadCount - 1];
        }

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (h > 0)
            {
                tPiggys[h - 1] = tRoad.GSDSpline;
            }
        }

        tRoad = tRoadObjs[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            tRoad.PiggyBacks = tPiggys;
        }
        tRoad.UpdateRoad();
    }
Пример #4
0
        /// <summary>
        /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to create nodes on.</param>
        /// <param name="NodeLocation">The location of the newly created node.</param>
        /// <returns></returns>
        public static GSDSplineN CreateNode_Programmatically(GSDRoad tRoad, Vector3 NodeLocation)
        {
            int        SplineChildCount = tRoad.GSDSpline.transform.childCount;
            GameObject tNodeObj         = new GameObject("Node" + (SplineChildCount + 1).ToString());
            GSDSplineN tNode            = tNodeObj.AddComponent <GSDSplineN>(); //Add the node component.

            //Set node location:
            if (NodeLocation.y < 0.03f)
            {
                NodeLocation.y = 0.03f;
            }                                                           //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = tRoad.GSDSplineObj.transform;

            //Set the idOnSpline:
            tNode.idOnSpline = (SplineChildCount + 1);
            tNode.GSDSpline  = tRoad.GSDSpline;

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            tRoad.UpdateRoad();

            return(tNode);
        }
Пример #5
0
 public static void EndProfiling(GSDRoad _road)
 {
     if (_road.bProfiling)
     {
         UnityEngine.Profiling.Profiler.EndSample();
     }
 }
Пример #6
0
 public static void StartProfiling(GSDRoad _road, string _profileName)
 {
     if (_road.bProfiling)
     {
         UnityEngine.Profiling.Profiler.BeginSample(_profileName);
     }
 }
Пример #7
0
    public GameObject AddRoad(bool bForceSelect = false)
    {
        GSDRoad[] tObj          = GetComponentsInChildren <GSDRoad>();
        int       NewRoadNumber = (tObj.Length + 1);

        //Road:
        GameObject tRoadObj = new GameObject("Road" + NewRoadNumber.ToString());

        UnityEditor.Undo.RegisterCreatedObjectUndo(tRoadObj, "Created road");
        tRoadObj.transform.parent = transform;
        GSDRoad tRoad = tRoadObj.AddComponent <GSDRoad>();

        //Spline:
        GameObject tSplineObj = new GameObject("Spline");

        tSplineObj.transform.parent = tRoad.transform;
        tRoad.GSDSpline             = tSplineObj.AddComponent <GSDSplineC>();
        tRoad.GSDSpline.mSplineRoot = tSplineObj;
        tRoad.GSDSpline.tRoad       = tRoad;
        tRoad.GSDSplineObj          = tSplineObj;
        tRoad.GSDRS = this;
        tRoad.SetupUniqueIdentifier();

        tRoad.ConstructRoad_ResetTerrainHistory();

        if (bForceSelect)
        {
            UnityEditor.Selection.activeGameObject = tRoadObj;
        }

        return(tRoadObj);
    }
Пример #8
0
    public void UpdateAllRoads()
    {
        GSDRoad[] tRoadObjs = GetComponentsInChildren <GSDRoad>();
        //		int i=0;

        int RoadCount = tRoadObjs.Length;

        GSDRoad tRoad = null;

        GSDSplineC[] tPiggys = null;
        if (RoadCount > 1)
        {
            tPiggys = new GSDSplineC[RoadCount];
            for (int h = 0; h < RoadCount; h++)
            {
                tRoad      = tRoadObjs[h];
                tPiggys[h] = tRoad.GSDSpline;
            }
        }

        tRoad = tRoadObjs[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            tRoad.PiggyBacks = tPiggys;
        }
        tRoad.UpdateRoad();
    }
Пример #9
0
        /// <summary>
        /// Use this to insert nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to insert nodes in.</param>
        /// <param name="NodeLocation">The location of the newly inserted node.</param>
        /// <returns></returns>
		public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLocation){
			GameObject tNodeObj;
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
            tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			
            //Set node location:
            if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; }     //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = RS.GSDSplineObj.transform;    
			
			int cCount = RS.GSDSpline.mNodes.Count;

            //Get the closet param on spline:
			float tParam = RS.GSDSpline.GetClosestParam(NodeLocation, false, true);
			
			bool bEndInsert = false;
			bool bZeroInsert = false;
			int iStart = 0;
			if(GSDRootUtil.IsApproximately(tParam,0f,0.0001f)){
				bZeroInsert = true;
				iStart = 0;
            } else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f)) {
                //Inserted at end, switch to create node instead:
                Object.DestroyImmediate(tNodeObj);
                return CreateNode_Programmatically(RS, NodeLocation);
			}
			
            //Figure out where to insert the node:
			for(int i=0;i<cCount;i++){
				GSDSplineN xNode = RS.GSDSpline.mNodes[i];
				if(!bZeroInsert && !bEndInsert){
					if(tParam > xNode.tTime){
						iStart = xNode.idOnSpline+1;
					}
				}
			}
			for(int i=iStart;i<cCount;i++){
				RS.GSDSpline.mNodes[i].idOnSpline+=1;
			}
			
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();
			tNode.GSDSpline = RS.GSDSpline;
			tNode.idOnSpline = iStart;
            tNode.pos = NodeLocation;
			RS.GSDSpline.mNodes.Insert(iStart,tNode);

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            RS.UpdateRoad();
			
			return tNode;
		}
Пример #10
0
	public void Setup_Trigger(){
		#if UNITY_EDITOR
		if(!tRoad){ 
			if(mSplineRoot != null){
				tRoad = mSplineRoot.transform.parent.transform.gameObject.GetComponent<GSDRoad>(); 
			}
		}
		if(tRoad){ 
			tRoad.UpdateRoad(); 
		}	
		#endif
	}
Пример #11
0
        private static void RoadArchitectUnitTest1()
        {
            //Create node locations:
            List <Vector3> nodeLocations = new List <Vector3>();
            int            MaxCount      = 18;
            float          tMod          = 100f;
            Vector3        xVect         = new Vector3(50f, 40f, 50f);

            for (int i = 0; i < MaxCount; i++)
            {
                //tLocs.Add(xVect + new Vector3(tMod * Mathf.Pow((float)i / ((float)MaxCount * 0.15f), 2f), 1f*((float)i*1.25f), tMod * i));
                nodeLocations.Add(xVect + new Vector3(tMod * Mathf.Pow((float)i / ((float)25 * 0.15f), 2f), 0f, tMod * i));
            }

            //Get road system create road:
            GSDRoadSystem GSDRS = (GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>();
            GSDRoad       tRoad = GSDRoadAutomation.CreateRoad_Programmatically(GSDRS, ref nodeLocations);

            //Bridge0: (Arch)
            tRoad.GSDSpline.mNodes[4].bIsBridgeStart        = true;
            tRoad.GSDSpline.mNodes[4].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[7].bIsBridgeEnd          = true;
            tRoad.GSDSpline.mNodes[7].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[4].BridgeCounterpartNode = tRoad.GSDSpline.mNodes[7];
            tRoad.GSDSpline.mNodes[4].LoadWizardObjectsFromLibrary("Arch12m-2L", true, true);

            //Bridge1: (Federal causeway)
            tRoad.GSDSpline.mNodes[8].bIsBridgeStart        = true;
            tRoad.GSDSpline.mNodes[8].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[8].BridgeCounterpartNode = tRoad.GSDSpline.mNodes[10];
            tRoad.GSDSpline.mNodes[8].LoadWizardObjectsFromLibrary("Causeway1-2L", true, true);
            tRoad.GSDSpline.mNodes[10].bIsBridgeEnd     = true;
            tRoad.GSDSpline.mNodes[10].bIsBridgeMatched = true;

            //Bridge2: (Steel)
            tRoad.GSDSpline.mNodes[11].bIsBridgeStart        = true;
            tRoad.GSDSpline.mNodes[11].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[11].BridgeCounterpartNode = tRoad.GSDSpline.mNodes[13];
            tRoad.GSDSpline.mNodes[11].LoadWizardObjectsFromLibrary("Steel-2L", true, true);
            tRoad.GSDSpline.mNodes[13].bIsBridgeEnd     = true;
            tRoad.GSDSpline.mNodes[13].bIsBridgeMatched = true;

            //Bridge3: (Causeway)
            tRoad.GSDSpline.mNodes[14].bIsBridgeStart        = true;
            tRoad.GSDSpline.mNodes[14].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[16].bIsBridgeEnd          = true;
            tRoad.GSDSpline.mNodes[16].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[14].BridgeCounterpartNode = tRoad.GSDSpline.mNodes[16];
            tRoad.GSDSpline.mNodes[14].LoadWizardObjectsFromLibrary("Causeway4-2L", true, true);
        }
Пример #12
0
        /// <summary>
        /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to create nodes on.</param>
        /// <param name="NodeLocation">The location of the newly created node.</param>
        /// <returns></returns>
        public static GSDRoad CreateRoad_Programmatically(GSDRoadSystem GSDRS, ref List <Vector3> tLocs)
        {
            GameObject tRoadObj = GSDRS.AddRoad(false);
            GSDRoad    tRoad    = tRoadObj.GetComponent <GSDRoad>();

            int hCount = tLocs.Count;

            for (int i = 0; i < hCount; i++)
            {
                CreateNode_Programmatically(tRoad, tLocs[i]);
            }

            return(tRoad);
        }
    //Workaround for submission rules:
    public void UpdateAllRoads_SaveMeshesAsAssetsOptions()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));
        int       RoadCount = tRoadObjs.Length;
        GSDRoad   tRoad     = null;

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (tRoad != null)
            {
                tRoad.opt_bSaveMeshes = opt_bSaveMeshes;
            }
        }
    }
    //Workaround for submission rules:
    public void UpdateAllRoads_MultiThreadOptions()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));
        int       RoadCount = tRoadObjs.Length;
        GSDRoad   tRoad     = null;

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (tRoad != null)
            {
                tRoad.opt_bMultithreading = opt_bMultithreading;
            }
        }
    }
Пример #15
0
    //Workaround for submission rules:
    public void UpdateAllRoads_SaveMeshesAsAssetsOptions()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GetComponentsInChildren <GSDRoad>();
        int       RoadCount = tRoadObjs.Length;
        GSDRoad   tRoad     = null;

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (tRoad != null)
            {
                tRoad.opt_bSaveMeshes = opt_bSaveMeshes;
            }
        }
    }
Пример #16
0
    //Workaround for submission rules:
    public void UpdateAllRoads_MultiThreadOptions()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GetComponentsInChildren <GSDRoad>();
        int       RoadCount = tRoadObjs.Length;
        GSDRoad   tRoad     = null;

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (tRoad != null)
            {
                tRoad.opt_bMultithreading = opt_bMultithreading;
            }
        }
    }
Пример #17
0
        //Large suspension bridge:
        private static void RoadArchitectUnitTest4()
        {
            //Create base road:
            List <Vector3> nodeLocations = new List <Vector3>();

            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(3500f, 90f, 200f + (800f * i)));
            }
            GSDRoad tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);

            //Suspension bridge:
            tRoad.GSDSpline.mNodes[1].bIsBridgeStart        = true;
            tRoad.GSDSpline.mNodes[1].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[3].bIsBridgeEnd          = true;
            tRoad.GSDSpline.mNodes[3].bIsBridgeMatched      = true;
            tRoad.GSDSpline.mNodes[1].BridgeCounterpartNode = tRoad.GSDSpline.mNodes[3];
            tRoad.GSDSpline.mNodes[1].LoadWizardObjectsFromLibrary("SuspL-2L", true, true);
        }
Пример #18
0
		public static GSDSplineN CreateNode(GSDRoad RS, bool bSpecialEndNode = false, Vector3 vSpecialLoc = default(Vector3), bool bInterNode = false){
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
			GameObject tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());
			if(!bInterNode){
				UnityEditor.Undo.RegisterCreatedObjectUndo(tNodeObj, "Created node");
			}
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();

			if(bSpecialEndNode){
				tNode.bSpecialEndNode = true;
				tNodeObj.transform.position = vSpecialLoc;
			}else{
				tNodeObj.transform.position = RS.Editor_MousePos;
				//This helps prevent double clicks:
				int mCount = RS.GSDSpline.GetNodeCount();
				for(int i=0;i<mCount;i++){
					if(Vector3.Distance(RS.Editor_MousePos,RS.GSDSpline.mNodes[i].pos) < 5f){
						Object.DestroyImmediate(tNodeObj);
						return null;
					}
				}
				//End double click prevention
			}
			Vector3 xVect = tNodeObj.transform.position;
			if(xVect.y < 0.03f){ xVect.y = 0.03f; }
			tNodeObj.transform.position = xVect;

			tNodeObj.transform.parent = RS.GSDSplineObj.transform;
			tNode.idOnSpline = RS.GSDSpline.GetNodeCount()+1;
			tNode.GSDSpline = RS.GSDSpline;
			
			//Enforce max road grade:
			if(RS.opt_bMaxGradeEnabled && !bSpecialEndNode){
				tNode.EnsureGradeValidity(-1,true);
			}
			
			if(!bInterNode && !bSpecialEndNode){
				RS.UpdateRoad();
			}
			return tNode;
		}
Пример #19
0
        //public void Tester() {

        //    Vector3 checkPosition = new Vector3(20,20,20);


        //}

        //Long road
        private static void RoadArchitectUnitTest5()
        {
            //Create node locations:
            List <Vector3> tLocs = new List <Vector3>();

            //Create base road:
            tLocs.Clear();
            for (int i = 0; i < 48; i++)
            {
                tLocs.Add(new Vector3(3000f, 40f, 10f + (79f * i)));
            }
            for (int i = 0; i < 35; i++)
            {
                tLocs.Add(new Vector3(2900f - (79f * i), 30f, 3960f));
            }
            for (int i = 0; i < 40; i++)
            {
                tLocs.Add(new Vector3(30, 30f, 3960f - (79f * i)));
            }
            GSDRoad tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref tLocs);
        }
Пример #20
0
        /// <summary>
        /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to create nodes on.</param>
        /// <param name="NodeLocation">The location of the newly created node.</param>
        /// <returns></returns>
        public static GSDSplineN CreateNode_Programmatically(GSDRoad tRoad, Vector3 NodeLocation) {
            int SplineChildCount = tRoad.GSDSpline.transform.childCount;
			GameObject tNodeObj = new GameObject("Node" + (SplineChildCount+1).ToString());
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>(); //Add the node component.

            //Set node location:
            if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; }     //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = tRoad.GSDSplineObj.transform;     

            //Set the idOnSpline:
            tNode.idOnSpline = (SplineChildCount + 1);
            tNode.GSDSpline = tRoad.GSDSpline;

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            tRoad.UpdateRoad();

            return tNode;
		}
Пример #21
0
    private GSDRoad CreateNewRoad(List <Vector3> nodeList, int numLanes)
    {
        GSDRoad road = GSDRoadAutomation.CreateRoad_Programmatically(roadSystem, ref nodeList);

        //Debug.Log("CreateNewRoad: " + nodeList[0].y);

        /*for (int i = 0; i < road.GSDSpline.mNodes.Count - 1; i++)
         * {
         *  //road.GSDSpline.mNodes[i].LoadWizardObjectsFromLibrary("GSDGroup-KRailLights-6L", true, false);
         *  //road.GSDSpline.mNodes[i].LoadWizardObjectsFromLibrary("GSDGroup-Fancy1-6L", true, false);
         * }*/

        //road.opt_bIsLightmapped = true; // These are just a quick way to edit the road
        //road.opt_bIsStatic = true;
        road.opt_Lanes = numLanes;
        //road.opt_ClearDetailsDistance = 36;

        roadSystem.opt_bAllowRoadUpdates = false;
        //roadSystem.UpdateAllRoads();

        return(road);
    }
Пример #22
0
        /// <summary>
        /// Create 2L intersections:
        /// </summary>
        private static void RoadArchitectUnitTest2()
        {
            //Create node locations:
            float   StartLocX    = 800f;
            float   StartLocY    = 200f;
            float   StartLocYSep = 200f;
            float   tHeight      = 20f;
            GSDRoad bRoad        = null; if (bRoad == null)
            {
            }                                           //Buffer
            GSDRoad tRoad = null; if (tRoad == null)
            {
            }                                           //Buffer

            //Create base road:
            List <Vector3> nodeLocations = new List <Vector3>();

            for (int i = 0; i < 9; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX + (i * 200f), tHeight, 600f));
            }
            bRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);

            //Get road system, create road #1:
            nodeLocations.Clear();
            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX, tHeight, StartLocY + (i * StartLocYSep)));
            }
            tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);
            //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane);

            //Get road system, create road #2:
            nodeLocations.Clear();
            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 2f), tHeight, StartLocY + (i * StartLocYSep)));
            }
            tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);
            //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane);

            //Get road system, create road #3:
            nodeLocations.Clear();
            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 4f), tHeight, StartLocY + (i * StartLocYSep)));
            }
            tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);
            //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.BothTurnLanes);

            //Get road system, create road #4:
            nodeLocations.Clear();
            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 6f), tHeight, StartLocY + (i * StartLocYSep)));
            }
            tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);
            //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane);

            //Get road system, create road #4:
            nodeLocations.Clear();
            for (int i = 0; i < 5; i++)
            {
                nodeLocations.Add(new Vector3(StartLocX + (StartLocYSep * 8f), tHeight, StartLocY + (i * StartLocYSep)));
            }
            tRoad = GSDRoadAutomation.CreateRoad_Programmatically((GSDRoadSystem)GameObject.Find("RoadArchitectSystem1").GetComponent <GSDRoadSystem>(), ref nodeLocations);
            //UnitTest_IntersectionHelper(bRoad, tRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.TurnLane);

            GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(bRoad, GSDRoadIntersection.iStopTypeEnum.None, GSDRoadIntersection.RoadTypeEnum.NoTurnLane);

            //Now count road intersections, if not 5 throw error
            int iCount = 0;

            foreach (GSDSplineN tNode in bRoad.GSDSpline.mNodes)
            {
                if (tNode.bIsIntersection)
                {
                    iCount += 1;
                }
            }
            if (iCount != 5)
            {
                Debug.LogError("Unit Test #2 failed: " + iCount.ToString() + " intersections instead of 5.");
            }
        }
Пример #23
0
        /// <summary>
        /// Creates intersections where this road intersects with other roads.
        /// </summary>
        /// <param name="tRoad">The primary road to create intersections for.</param>
        /// <param name="iStopType">Stop signs, traffic lights #1 (US) or traffic lights #2 (Euro). Defaults to none.</param>
        /// <param name="rType">Intersection type: No turn lane, left turn lane or both turn lanes. Defaults to no turn lane.</param>
        public static void CreateIntersections_ProgrammaticallyForRoad(GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType = GSDRoadIntersection.iStopTypeEnum.None, GSDRoadIntersection.RoadTypeEnum rType = GSDRoadIntersection.RoadTypeEnum.NoTurnLane)
        {
            /*
             * General logic:
             * 20m increments to gather collection of which roads intersect
             *  2m increments to find actual intersection point
             *  each 2m, primary road checks all intersecting array for an intersection.
             * find intersection point
             *  if any intersections already within 75m or 100m, dont create intersection here
             *  check if nodes within 50m, if more than one just grab closest, and move  it to intersecting point
             *  if no node within 50m, add
             * create intersection with above two nodes
             */

            Object[] GSDRoadObjs = Object.FindObjectsOfType <GSDRoad>();

            //20m increments to gather collection of which roads intersect
            List <GSDRoad> xRoads = new List <GSDRoad>();

            foreach (GSDRoad xRoad in GSDRoadObjs)
            {
                if (tRoad != xRoad)
                {
                    float   EarlyDistanceCheckMeters    = 10f;
                    float   EarlyDistanceCheckThreshold = 50f;
                    bool    EarlyDistanceFound          = false;
                    float   tRoadMod = EarlyDistanceCheckMeters / tRoad.GSDSpline.distance;
                    float   xRoadMod = EarlyDistanceCheckMeters / xRoad.GSDSpline.distance;
                    Vector3 tVect1   = default(Vector3);
                    Vector3 tVect2   = default(Vector3);
                    for (float i = 0f; i < 1.0000001f; i += tRoadMod)
                    {
                        tVect1 = tRoad.GSDSpline.GetSplineValue(i);
                        for (float x = 0f; x < 1.000001f; x += xRoadMod)
                        {
                            tVect2 = xRoad.GSDSpline.GetSplineValue(x);
                            if (Vector3.Distance(tVect1, tVect2) < EarlyDistanceCheckThreshold)
                            {
                                if (!xRoads.Contains(xRoad))
                                {
                                    xRoads.Add(xRoad);
                                }
                                EarlyDistanceFound = true;
                                break;
                            }
                        }
                        if (EarlyDistanceFound)
                        {
                            break;
                        }
                    }
                }
            }

            //See if any end point nodes are on top of each other already since T might not intersect all the time.:
            List <KeyValuePair <GSDSplineN, GSDSplineN> > tKVP = new List <KeyValuePair <GSDSplineN, GSDSplineN> >();

            foreach (GSDRoad xRoad in xRoads)
            {
                foreach (GSDSplineN IntersectionNode1 in tRoad.GSDSpline.mNodes)
                {
                    if (IntersectionNode1.bIsIntersection || !IntersectionNode1.IsLegitimate())
                    {
                        continue;
                    }
                    foreach (GSDSplineN IntersectionNode2 in xRoad.GSDSpline.mNodes)
                    {
                        if (IntersectionNode2.bIsIntersection || !IntersectionNode2.IsLegitimate())
                        {
                            continue;
                        }
                        if (IntersectionNode1.transform.position == IntersectionNode2.transform.position)
                        {
                            //Only do T intersections and let the next algorithm handle the +, since T might not intersect all the time.
                            if (IntersectionNode1.bIsEndPoint || IntersectionNode2.bIsEndPoint)
                            {
                                tKVP.Add(new KeyValuePair <GSDSplineN, GSDSplineN>(IntersectionNode1, IntersectionNode2));
                            }
                        }
                    }
                }
            }
            foreach (KeyValuePair <GSDSplineN, GSDSplineN> KVP in tKVP)
            {
                //Now create the f*****g intersection:
                GameObject          tInter            = GSD.Roads.GSDIntersections.CreateIntersection(KVP.Key, KVP.Value);
                GSDRoadIntersection GSDRI_JustCreated = tInter.GetComponent <GSDRoadIntersection>();
                GSDRI_JustCreated.iStopType = iStopType;
                GSDRI_JustCreated.rType     = rType;
            }

            //Main algorithm: 2m increments to find actual intersection point:
            foreach (GSDRoad xRoad in xRoads)
            {
                if (tRoad != xRoad)
                {
                    //Debug.Log("Checking road: " + xRoad.transform.name);
                    float   DistanceCheckMeters = 2f;
                    bool    EarlyDistanceFound  = false;
                    float   tRoadMod            = DistanceCheckMeters / tRoad.GSDSpline.distance;
                    float   xRoadMod            = DistanceCheckMeters / xRoad.GSDSpline.distance;
                    Vector3 tVect            = default(Vector3);
                    Vector2 iVect1           = default(Vector2);
                    Vector2 iVect2           = default(Vector2);
                    Vector2 xVect1           = default(Vector2);
                    Vector2 xVect2           = default(Vector2);
                    Vector2 IntersectPoint2D = default(Vector2);
                    float   i2 = 0f;
                    for (float i = 0f; i < 1.0000001f; i += tRoadMod)
                    {
                        i2 = (i + tRoadMod);
                        if (i2 > 1f)
                        {
                            i2 = 1f;
                        }
                        tVect  = tRoad.GSDSpline.GetSplineValue(i);
                        iVect1 = new Vector2(tVect.x, tVect.z);
                        tVect  = tRoad.GSDSpline.GetSplineValue(i2);
                        iVect2 = new Vector2(tVect.x, tVect.z);

                        float x2 = 0f;
                        for (float x = 0f; x < 1.000001f; x += xRoadMod)
                        {
                            x2 = (x + xRoadMod);
                            if (x2 > 1f)
                            {
                                x2 = 1f;
                            }
                            tVect  = xRoad.GSDSpline.GetSplineValue(x);
                            xVect1 = new Vector2(tVect.x, tVect.z);
                            tVect  = xRoad.GSDSpline.GetSplineValue(x2);
                            xVect2 = new Vector2(tVect.x, tVect.z);

                            //Now see if these two lines intersect:
                            if (GSD.GSDRootUtil.Intersects2D(ref iVect1, ref iVect2, ref xVect1, ref xVect2, out IntersectPoint2D))
                            {
                                //Get height of intersection on primary road:
                                float   tHeight = 0f;
                                float   hParam  = tRoad.GSDSpline.GetClosestParam(new Vector3(IntersectPoint2D.x, 0f, IntersectPoint2D.y));
                                Vector3 hVect   = tRoad.GSDSpline.GetSplineValue(hParam);
                                tHeight = hVect.y;

                                //if any intersections already within 75m or 100m, dont create intersection here
                                Object[] AllInterectionObjects = Object.FindObjectsOfType <GSDRoadIntersection>();
                                foreach (GSDRoadIntersection GSDRI in AllInterectionObjects)
                                {
                                    if (Vector2.Distance(new Vector2(GSDRI.transform.position.x, GSDRI.transform.position.z), IntersectPoint2D) < 100f)
                                    {
                                        goto NoIntersectionCreation;
                                    }
                                }

                                GSDSplineN IntersectionNode1   = null;
                                GSDSplineN IntersectionNode2   = null;
                                Vector3    IntersectionPoint3D = new Vector3(IntersectPoint2D.x, tHeight, IntersectPoint2D.y);
                                //Debug.Log("Instersect found road: " + xRoad.transform.name + " at point: " + IntersectionPoint3D.ToString());

                                //Check primary road if any nodes are nearby and usable for intersection
                                foreach (GSDSplineN tNode in tRoad.GSDSpline.mNodes)
                                {
                                    if (tNode.IsLegitimate())
                                    {
                                        if (Vector2.Distance(new Vector2(tNode.transform.position.x, tNode.transform.position.z), IntersectPoint2D) < 30f)
                                        {
                                            IntersectionNode1 = tNode;
                                            IntersectionNode1.transform.position = IntersectionPoint3D;
                                            IntersectionNode1.pos = IntersectionPoint3D;
                                            break;
                                        }
                                    }
                                }

                                //Check secondary road if any nodes are nearby and usable for intersection
                                foreach (GSDSplineN tNode in xRoad.GSDSpline.mNodes)
                                {
                                    if (tNode.IsLegitimate())
                                    {
                                        if (Vector2.Distance(new Vector2(tNode.transform.position.x, tNode.transform.position.z), IntersectPoint2D) < 30f)
                                        {
                                            IntersectionNode2 = tNode;
                                            IntersectionNode2.transform.position = IntersectionPoint3D;
                                            IntersectionNode2.pos = IntersectionPoint3D;
                                            break;
                                        }
                                    }
                                }

                                //Check if any of the nodes are null. If so, need to insert node. And maybe update it.
                                if (IntersectionNode1 == null)
                                {
                                    IntersectionNode1 = InsertNode_Programmatically(tRoad, IntersectionPoint3D);
                                }
                                if (IntersectionNode2 == null)
                                {
                                    IntersectionNode2 = InsertNode_Programmatically(xRoad, IntersectionPoint3D);
                                }

                                //Now create the f*****g intersection:
                                GameObject          tInter            = GSD.Roads.GSDIntersections.CreateIntersection(IntersectionNode1, IntersectionNode2);
                                GSDRoadIntersection GSDRI_JustCreated = tInter.GetComponent <GSDRoadIntersection>();
                                GSDRI_JustCreated.iStopType = iStopType;
                                GSDRI_JustCreated.rType     = rType;
                            }

NoIntersectionCreation:
                            //Gibberish to get rid of warnings:
                            int xxx = 1;
                            if (xxx == 1)
                            {
                                xxx = 2;
                            }
                        }
                        if (EarlyDistanceFound)
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #24
0
		public RoadConstructorBufferMaker(GSDRoad _tRoad, RoadUpdateTypeEnum _tUpdateType){
			tUpdateType = _tUpdateType;
			bRoadOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection || tUpdateType == RoadUpdateTypeEnum.Bridges);
			bTerrainOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection || tUpdateType == RoadUpdateTypeEnum.Bridges);
			bBridgesOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Bridges);
			bInterseOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection);
			
			tRoad = _tRoad;
			Nullify();
			RoadVectors = new List<Vector3>();
			ShoulderR_Vectors = new List<Vector3>();
			ShoulderL_Vectors = new List<Vector3>();
			normals_ShoulderR_averageStartIndexes = new List<int>();
			normals_ShoulderL_averageStartIndexes = new List<int>();
			
			cut_RoadVectors = new List<List<Vector3>>();
			cut_RoadVectorsHome = new List<Vector3>();
			cut_ShoulderR_Vectors = new List<List<Vector3>>();
			cut_ShoulderL_Vectors = new List<List<Vector3>>();
			cut_ShoulderR_VectorsHome = new List<Vector3>();
			cut_ShoulderL_VectorsHome = new List<Vector3>();
			cut_tris = new List<int[]>();
			cut_tris_ShoulderR = new List<int[]>();
			cut_tris_ShoulderL = new List<int[]>();
			cut_normals = new List<Vector3[]>();
			cut_normals_ShoulderR = new List<Vector3[]>();
			cut_normals_ShoulderL = new List<Vector3[]>();
			cut_uv = new List<Vector2[]>();
			cut_uv_SR = new List<Vector2[]>();
			cut_uv_SL = new List<Vector2[]>();
			cut_tangents = new List<Vector4[]>();
			cut_tangents_SR = new List<Vector4[]>();
			cut_tangents_SL = new List<Vector4[]>();
			
			cut_uv_world = new List<Vector2[]>();
			cut_uv_SR_world = new List<Vector2[]>();
			cut_uv_SL_world = new List<Vector2[]>();
			cut_tangents_world = new List<Vector4[]>();
			cut_tangents_SR_world = new List<Vector4[]>();
			cut_tangents_SL_world = new List<Vector4[]>();
			
			RoadCutNodes = new List<GSDSplineN>();
			ShoulderCutsRNodes = new List<GSDSplineN>();
			ShoulderCutsLNodes = new List<GSDSplineN>();
			
			RoadConnections_verts = new List<Vector3[]>();
		 	RoadConnections_tris = new List<int[]>();
		 	RoadConnections_normals = new List<Vector3[]>();
		 	RoadConnections_uv = new List<Vector2[]>();
		 	RoadConnections_tangents = new List<Vector4[]>();
			
			RoadCuts = new List<int>();
			ShoulderCutsR = new List<int>();
			ShoulderCutsL = new List<int>();
			
			//if(bInterseOn){
				//Back lanes:
				iBLane0s = new List<Vector3[]>();
				iBLane1s = new List<Vector3[]>();
				iBLane2s = new List<Vector3[]>();
				iBLane3s = new List<Vector3[]>();
				//Front lanes:
				iFLane0s = new List<Vector3[]>();
				iFLane1s = new List<Vector3[]>();
				iFLane2s = new List<Vector3[]>();
				iFLane3s = new List<Vector3[]>();
				//Main plates:
				iBMainPlates = new List<Vector3[]>();
				iFMainPlates = new List<Vector3[]>();
				//Marker plates:
				iBMarkerPlates = new List<Vector3[]>();
				iFMarkerPlates = new List<Vector3[]>();
				
				//Back lanes:
				iBLane0s_tris = new List<int[]>();
				iBLane1s_tris = new List<int[]>();
				iBLane2s_tris = new List<int[]>();
				iBLane3s_tris = new List<int[]>();
				//Front lanes:
				iFLane0s_tris = new List<int[]>();
				iFLane1s_tris = new List<int[]>();
				iFLane2s_tris = new List<int[]>();
				iFLane3s_tris = new List<int[]>();
				//Main plates:
				iBMainPlates_tris = new List<int[]>();
				iFMainPlates_tris = new List<int[]>();
				//Marker plates:
				iBMarkerPlates_tris = new List<int[]>();
				iFMarkerPlates_tris = new List<int[]>();
				
				//Back lanes:
				iBLane0s_normals = new List<Vector3[]>();
				iBLane1s_normals = new List<Vector3[]>();
				iBLane2s_normals = new List<Vector3[]>();
				iBLane3s_normals = new List<Vector3[]>();
				//Front lanes:
				iFLane0s_normals = new List<Vector3[]>();
				iFLane1s_normals = new List<Vector3[]>();
				iFLane2s_normals = new List<Vector3[]>();
				iFLane3s_normals = new List<Vector3[]>();
				//Main plates:
				iBMainPlates_normals = new List<Vector3[]>();
				iFMainPlates_normals = new List<Vector3[]>();
				//Marker plates:
				iBMarkerPlates_normals = new List<Vector3[]>();
				iFMarkerPlates_normals = new List<Vector3[]>();
				
				//Back lanes:
				iBLane0s_uv = new List<Vector2[]>();
				iBLane1s_uv = new List<Vector2[]>();
				iBLane2s_uv = new List<Vector2[]>();
				iBLane3s_uv = new List<Vector2[]>();
				//Front lanes:
				iFLane0s_uv = new List<Vector2[]>();
				iFLane1s_uv = new List<Vector2[]>();
				iFLane2s_uv = new List<Vector2[]>();
				iFLane3s_uv = new List<Vector2[]>();
				//Main plates:
				iBMainPlates_uv = new List<Vector2[]>();
				iFMainPlates_uv = new List<Vector2[]>();
				iBMainPlates_uv2 = new List<Vector2[]>();
				iFMainPlates_uv2 = new List<Vector2[]>();
				//Marker plates:
				iBMarkerPlates_uv = new List<Vector2[]>();
				iFMarkerPlates_uv = new List<Vector2[]>();
				
				//Back lanes:
				iBLane0s_tangents = new List<Vector4[]>();
				iBLane1s_tangents = new List<Vector4[]>();
				iBLane2s_tangents = new List<Vector4[]>();
				iBLane3s_tangents = new List<Vector4[]>();
				//Front lanes:
				iFLane0s_tangents = new List<Vector4[]>();
				iFLane1s_tangents = new List<Vector4[]>();
				iFLane2s_tangents = new List<Vector4[]>();
				iFLane3s_tangents = new List<Vector4[]>();
				//Main plates:
				iBMainPlates_tangents = new List<Vector4[]>();
				iFMainPlates_tangents = new List<Vector4[]>();
				iBMainPlates_tangents2 = new List<Vector4[]>();
				iFMainPlates_tangents2 = new List<Vector4[]>();
				//Marker plates:
				iBMarkerPlates_tangents = new List<Vector4[]>();
				iFMarkerPlates_tangents = new List<Vector4[]>();
				
				iFLane1s_IsMiddleLane = new List<bool>();
				iBLane1s_IsMiddleLane = new List<bool>();
		
				//Back lanes:
				iBLane0s_tID = new List<GSDRoadIntersection>();
				iBLane1s_tID = new List<GSDRoadIntersection>();
				iBLane2s_tID = new List<GSDRoadIntersection>();
				iBLane3s_tID = new List<GSDRoadIntersection>();
				//Front lanes:
				iFLane0s_tID = new List<GSDRoadIntersection>();
				iFLane1s_tID = new List<GSDRoadIntersection>();
				iFLane2s_tID = new List<GSDRoadIntersection>();
				iFLane3s_tID = new List<GSDRoadIntersection>();
				//Main plates:
				iBMainPlates_tID = new List<GSDRoadIntersection>();
				iFMainPlates_tID = new List<GSDRoadIntersection>();
				//Marker plates:
				iBMarkerPlates_tID = new List<GSDRoadIntersection>();
				iFMarkerPlates_tID = new List<GSDRoadIntersection>();
			
				iBLane0s_nID = new List<GSDSplineN>();
				iBLane1s_nID = new List<GSDSplineN>();
				iBLane2s_nID = new List<GSDSplineN>();
				iBLane3s_nID = new List<GSDSplineN>();
				//Front lanes:
				iFLane0s_nID = new List<GSDSplineN>();
				iFLane1s_nID = new List<GSDSplineN>();
				iFLane2s_nID = new List<GSDSplineN>();
				iFLane3s_nID = new List<GSDSplineN>();
				//Main plates:
				iBMainPlates_nID = new List<GSDSplineN>();
				iFMainPlates_nID = new List<GSDSplineN>();
				//Marker plates:
				iBMarkerPlates_nID = new List<GSDSplineN>();
				iFMarkerPlates_nID = new List<GSDSplineN>();
			//}
			
			tTerrain = null;
			
			tMesh = new Mesh();
			tMesh_SR = new Mesh();
			tMesh_SL = new Mesh();
			tMesh_RoadCuts = new List<Mesh>();
			tMesh_SRCuts = new List<Mesh>();
			tMesh_SLCuts = new List<Mesh>();
			tMesh_RoadCuts_world = new List<Mesh>();
			tMesh_SRCuts_world = new List<Mesh>();
			tMesh_SLCuts_world = new List<Mesh>();
			
			tMesh_RoadConnections = new List<Mesh>();
			
			//if(bInterseOn){
				tMesh_iBLanes0 = new List<Mesh>();
				tMesh_iBLanes1 = new List<Mesh>();
				tMesh_iBLanes2 = new List<Mesh>();
				tMesh_iBLanes3 = new List<Mesh>();
				tMesh_iFLanes0 = new List<Mesh>();
				tMesh_iFLanes1 = new List<Mesh>();
				tMesh_iFLanes2 = new List<Mesh>();
				tMesh_iFLanes3 = new List<Mesh>();
				tMesh_iBMainPlates = new List<Mesh>();
				tMesh_iFMainPlates = new List<Mesh>();
				tMesh_iBMarkerPlates = new List<Mesh>();
				tMesh_iFMarkerPlates = new List<Mesh>();
				tIntersectionBounds = new List<GSD.Roads.GSDRoadUtil.Construction2DRect>();
				ImmuneVects = new HashSet<Vector3>();
			//}

			InitGameObjects();
		}
        public static void RunMe(ref List<GSD.Roads.GSDTerraforming.TempTerrainData> TTDList, GSDSplineC tSpline, GSDRoad tRoad)
        {
            float Step = (tRoad.opt_RoadDefinition*0.4f) / tSpline.distance;
            if(Step > 2f){ Step = 2f; }
            if(Step < 1f){ Step = 1f; }
            //			float tDistance = tRoad.RoadWidth()*2f;

            //			Vector3 tVect,POS;

            foreach(GSD.Roads.GSDTerraforming.TempTerrainData TTD in TTDList){
            //				float PrevHeight = 0f;
            //				float FinalMax = 1f;
            //				float StartMin = 0f;
            //				if(tSpline.bSpecialEndControlNode){
            //					FinalMax = tSpline.mNodes[tSpline.GetNodeCount()-2].tTime;
            //				}
            //				if(tSpline.bSpecialStartControlNode){
            //					StartMin = tSpline.mNodes[1].tTime;
            //				}

            //				if(tRoad.opt_MatchTerrain){
                if(tRoad.bProfiling){
                    Profiler.BeginSample("DoRects");
                }
                    GSDTerraformingT.DoRects(tSpline,TTD);

                if(tRoad.bProfiling){
                    Profiler.EndSample();
                }
            //				}else{
            //					for(float i=StartMin;i<=FinalMax;i+=Step){
            //						if(tSpline.IsInBridgeTerrain(i)){
            //							float tFloat = tSpline.GetBridgeEnd(i);
            //							if(IsApproximately(tFloat,1f,0.00001f) || tFloat > 1f){ continue; }
            //							if(tFloat < 0f){ continue; }
            //							i = tFloat;
            //						}
            //						tSpline.GetSplineValue_Both(i,out tVect,out POS);
            //						PrevHeight = GSDTerraformingT.ProcessLineHeights(tSpline,ref tVect,ref POS,tDistance,TTD,PrevHeight);
            //						tSpline.HeightHistory.Add(new KeyValuePair<float,float>(i,PrevHeight*TTD.TerrainSize.y));
            //					}
            //
            //					for(int i=0;i<TTD.cI;i++){
            //						TTD.heights[TTD.cX[i],TTD.cY[i]] = TTD.cH[i];
            //					}
            //				}
            }
            tSpline.HeightHistory.Sort(Compare1);
        }
 public void Setup(ref GSD.Roads.RoadConstructorBufferMaker _RCS, ref GSDRoad _tRoad)
 {
     RCS = _RCS;
     tRoad = _tRoad;
 }
 private static void RoadJob_Prelim_FinalizeInter(ref GSDRoad tRoad)
 {
     int mCount = tRoad.GSDSpline.GetNodeCount();
     GSDSplineN tNode;
     for(int i=0;i<mCount;i++){
         tNode = tRoad.GSDSpline.mNodes[i];
         if(tNode.bIsIntersection){
             Inter_OrganizeVertices(ref tNode,ref tRoad);
             tNode.iConstruction.Nullify();
             tNode.iConstruction = null;
         }
     }
 }
        private static void AddIntersectionBounds(ref GSDRoad tRoad, ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            bool bIsBridge = false;
            bool bBridgeInitial = false; if(bBridgeInitial == false){ }
            bool bTempbridge = false;
            bool bBridgeLast = false; if(bBridgeLast == false){ }

            bool bIsTunnel = false;
            bool bTunnelInitial = false; if(bTunnelInitial == false){ }
            bool bTempTunnel = false;
            bool bTunnelLast = false; if(bTunnelLast == false){ }

            GSDRoadIntersection GSDRI = null;
            bool bIsPastInter = false;
            bool bMaxIntersection = false;
            bool bWasPrevMaxInter = false;
            Vector3 tVect = default(Vector3);
            Vector3 POS = default(Vector3);
            float tIntHeight = 0f;
            float tIntStrength = 0f;
            float tIntStrength_temp = 0f;
            //			float tIntDistCheck = 75f;
            bool bFirstInterNode = false;
            Vector3 tVect_Prev = default(Vector3); 		if(tVect_Prev == default(Vector3)){ }
            Vector3 rVect_Prev = default(Vector3); 		if(rVect_Prev == default(Vector3)){ }
            Vector3 lVect_Prev = default(Vector3); 		if(lVect_Prev == default(Vector3)){ }
            Vector3 rVect = default(Vector3);			if(rVect == default(Vector3)){ }
            Vector3 lVect = default(Vector3);			if(lVect == default(Vector3)){ }
            Vector3 ShoulderR_rVect = default(Vector3);	if(ShoulderR_rVect == default(Vector3)){ }
            Vector3 ShoulderR_lVect = default(Vector3);	if(ShoulderR_lVect == default(Vector3)){ }
            Vector3 ShoulderL_rVect = default(Vector3);	if(ShoulderL_rVect == default(Vector3)){ }
            Vector3 ShoulderL_lVect = default(Vector3);	if(ShoulderL_lVect == default(Vector3)){ }

            Vector3 RampR_R = default(Vector3);
            Vector3 RampR_L = default(Vector3);
            Vector3 RampL_R = default(Vector3);
            Vector3 RampL_L = default(Vector3);
            float ShoulderR_OuterAngle = 0f;	if(ShoulderR_OuterAngle < 0f){ }
            float ShoulderL_OuterAngle = 0f;	if(ShoulderL_OuterAngle < 0f){ }
            Vector3 ShoulderR_PrevLVect = default(Vector3); if(ShoulderR_PrevLVect == default(Vector3)){ }
            Vector3 ShoulderL_PrevRVect = default(Vector3); if(ShoulderL_PrevRVect == default(Vector3)){ }
            Vector3 ShoulderR_PrevRVect = default(Vector3); if(ShoulderR_PrevRVect == default(Vector3)){ }
            Vector3 ShoulderL_PrevLVect = default(Vector3); if(ShoulderL_PrevLVect == default(Vector3)){ }
            //			Vector3 ShoulderR_PrevRVect2 = default(Vector3);
            //			Vector3 ShoulderL_PrevLVect2 = default(Vector3);
            //			Vector3 ShoulderR_PrevRVect3 = default(Vector3);
            //			Vector3 ShoulderL_PrevLVect3 = default(Vector3);
            Vector3 RampR_PrevR = default(Vector3); if(RampR_PrevR == default(Vector3)){ }
            Vector3 RampR_PrevL = default(Vector3); if(RampR_PrevL == default(Vector3)){ }
            Vector3 RampL_PrevR = default(Vector3); if(RampL_PrevR == default(Vector3)){ }
            Vector3 RampL_PrevL = default(Vector3); if(RampL_PrevL == default(Vector3)){ }
            GSDSplineC tSpline = tRoad.GSDSpline;
            //Road width:
            float RoadWidth = tRoad.RoadWidth();
            float ShoulderWidth = tRoad.opt_ShoulderWidth;
            float RoadSeperation = RoadWidth / 2f;
            float RoadSeperation_NoTurn = RoadWidth / 2f;
            float ShoulderSeperation = RoadSeperation + ShoulderWidth;
            float LaneWidth = tRoad.opt_LaneWidth;
            float RoadSep1Lane = (RoadSeperation + (LaneWidth*0.5f));
            float RoadSep2Lane = (RoadSeperation + (LaneWidth*1.5f));
            float ShoulderSep1Lane = (ShoulderSeperation + (LaneWidth*0.5f));		if(ShoulderSep1Lane < 0f){ }
            float ShoulderSep2Lane = (ShoulderSeperation + (LaneWidth*1.5f));		if(ShoulderSep2Lane < 0f){ }

            //			float tAngle = 0f;
            //			float OrigStep = 0.06f;
            float Step = tRoad.opt_RoadDefinition / tSpline.distance;

            GSDSplineN xNode = null;
            float tInterSubtract = 4f;
            float tLastInterHeight = -4f;

            //			GameObject xObj = null;
            //			xObj = GameObject.Find("temp22");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22");
            //			}
            //			xObj = GameObject.Find("temp23");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp23");
            //			}
            //			xObj = GameObject.Find("temp22_RR");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_RR");
            //			}
            //			xObj = GameObject.Find("temp22_RL");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_RL");
            //			}
            //			xObj = GameObject.Find("temp22_LR");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_LR");
            //			}
            //			xObj = GameObject.Find("temp22_LL");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_LL");
            //			}

            bool bFinalEnd = false;
            float i = 0f;

            float FinalMax = 1f;
            float StartMin = 0f;
            if(tSpline.bSpecialEndControlNode){
                FinalMax = tSpline.mNodes[tSpline.GetNodeCount()-2].tTime;
            }
            if(tSpline.bSpecialStartControlNode){
                StartMin = tSpline.mNodes[1].tTime;
            }

            //			int StartIndex = tSpline.GetClosestRoadDefIndex(StartMin,true,false);
            //			int EndIndex = tSpline.GetClosestRoadDefIndex(FinalMax,false,true);
            //			float cDist = 0f;
            bool kSkip = true;
            bool kSkipFinal = false;
            int kCount = 0;
            int kFinalCount = tSpline.RoadDefKeysArray.Length;
            int spamcheckmax1 = 18000;
            int spamcheck1 = 0;

            if(IsApproximately(StartMin,0f,0.0001f)){
                kSkip = false;
            }
            if(IsApproximately(FinalMax,1f,0.0001f)){
                kSkipFinal = true;
            }

            while(!bFinalEnd && spamcheck1 < spamcheckmax1){
                spamcheck1++;

                if(kSkip){
                    i = StartMin;
                    kSkip = false;
                }else{
                    if(kCount >= kFinalCount){
                        i = FinalMax;
                        if(kSkipFinal){ break; }
                    }else{
                        i = tSpline.TranslateInverseParamToFloat(tSpline.RoadDefKeysArray[kCount]);
                        kCount+=1;
                    }
                }

                if(i > 1f){ break; }
                if(i < 0f){ i = 0f; }

                if(IsApproximately(i,FinalMax,0.00001f)){
                    bFinalEnd = true;
                }else if(i > FinalMax){
                    if(tSpline.bSpecialEndControlNode){
                        i = FinalMax;
                        bFinalEnd = true;
                    }else{
                        bFinalEnd = true;
                        break;
                    }
                }

                tSpline.GetSplineValue_Both(i,out tVect,out POS);
                bIsPastInter = false;
                tIntStrength = tSpline.IntersectionStrength(ref tVect,ref tIntHeight, ref GSDRI, ref bIsPastInter, ref i, ref xNode);
                if(IsApproximately(tIntStrength,1f,0.001f) || tIntStrength > 1f){
                    bMaxIntersection = true;
                }else{
                    bMaxIntersection = false;
                }

                if(bMaxIntersection){
                    if(string.Compare(xNode.UID,GSDRI.Node1.UID) == 0){
                        bFirstInterNode = true;
                    }else{
                        bFirstInterNode = false;
                    }

                    //Convoluted for initial trigger:
                    bBridgeInitial = false;
                    bBridgeLast = false;
                    bTempbridge = tSpline.IsInBridge(i);
                    if(!bIsBridge && bTempbridge){
                        bIsBridge = true;
                        bBridgeInitial = true;
                    }else if(bIsBridge && !bTempbridge){
                        bIsBridge = false;
                    }
                    //Check if this is the last bridge run for this bridge:
                    if(bIsBridge){
                        bTempbridge = tSpline.IsInBridge(i+Step);
                        if(!bTempbridge){
                            bBridgeLast = true;
                        }
                    }

                    //Convoluted for initial trigger:
                    bTunnelInitial = false;
                    bTunnelLast = false;
                    bTempTunnel = tSpline.IsInTunnel(i);
                    if(!bIsTunnel && bTempTunnel){
                        bIsTunnel = true;
                        bTunnelInitial = true;
                    }else if(bIsTunnel && !bTempTunnel){
                        bIsTunnel = false;
                    }
                    //Check if this is the last Tunnel run for this Tunnel:
                    if(bIsTunnel){
                        bTempTunnel = tSpline.IsInTunnel(i+Step);
                        if(!bTempTunnel){
                            bTunnelLast = true;
                        }
                    }

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        rVect = (tVect + new Vector3(RoadSeperation_NoTurn*POS.normalized.z,0,RoadSeperation_NoTurn*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation_NoTurn*-POS.normalized.z,0,RoadSeperation_NoTurn*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        if(bIsPastInter){
                            rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));;
                        }else{
                            rVect = (tVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                        }
                    }else{
                        rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                    }

                    if(tIntStrength >= 1f){
                        tVect.y -= tInterSubtract;
                        tLastInterHeight = tVect.y;
                        rVect.y -= tInterSubtract;
                        lVect.y -= tInterSubtract;
                    }else{
                        if(!IsApproximately(tIntStrength,0f,0.001f)){ tVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect.y); }
                        tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
                        if(!IsApproximately(tIntStrength_temp,0f,0.001f)){ rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*rVect.y); ShoulderR_lVect = rVect; }
                    }

                    //Add bounds for later removal:
                    GSD.Roads.GSDRoadUtil.Construction2DRect vRect = null;
                    if(!bIsBridge && !bIsTunnel && bMaxIntersection && bWasPrevMaxInter){
                        bool bGoAhead = true;
                        if(xNode.bIsEndPoint){
                            if(xNode.idOnSpline == 1){
                                if(i < xNode.tTime){
                                    bGoAhead = false;
                                }
                            }else{
                                if(i > xNode.tTime){
                                    bGoAhead = false;
                                }
                            }
                        }
                        //Get this and prev lvect rvect rects:
                        if(Vector3.Distance(xNode.pos,tVect) < (3f * RoadWidth) && bGoAhead){
                            if(GSDRI.bFlipped && !bFirstInterNode){
                                vRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(
                                    new Vector2(rVect.x,rVect.z),
                                    new Vector2(lVect.x,lVect.z),
                                    new Vector2(rVect_Prev.x,rVect_Prev.z),
                                    new Vector2(lVect_Prev.x,lVect_Prev.z),
                                    tLastInterHeight
                                    );
                            }else{
                                 vRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(
                                    new Vector2(lVect.x,lVect.z),
                                    new Vector2(rVect.x,rVect.z),
                                    new Vector2(lVect_Prev.x,lVect_Prev.z),
                                    new Vector2(rVect_Prev.x,rVect_Prev.z),
                                    tLastInterHeight
                                    );
                            }
            //							GameObject tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //							tObj.transform.position = lVect;
            //							tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //							tObj.transform.name = "temp22";
            //
            //							tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //							tObj.transform.position = rVect;
            //							tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //							tObj.transform.name = "temp22";

                            RCS.tIntersectionBounds.Add(vRect);
                        }
                    }
                }

                bWasPrevMaxInter = bMaxIntersection;
                tVect_Prev = tVect;
                rVect_Prev = rVect;
                lVect_Prev = lVect;
                ShoulderR_PrevLVect = ShoulderR_lVect;
                ShoulderL_PrevRVect = ShoulderL_rVect;
            //				ShoulderR_PrevRVect3 = ShoulderR_PrevRVect2;
            //				ShoulderL_PrevLVect3 = ShoulderL_PrevLVect2;
            //				ShoulderR_PrevRVect2 = ShoulderR_PrevRVect;
            //				ShoulderL_PrevLVect2 = ShoulderL_PrevLVect;
                ShoulderR_PrevRVect = ShoulderR_rVect;
                ShoulderL_PrevLVect = ShoulderL_lVect;
                RampR_PrevR = RampR_R;
                RampR_PrevL = RampR_L;
                RampL_PrevR = RampL_R;
                RampL_PrevL = RampL_L;
            //				i+=Step;
            }
        }
Пример #29
0
        /// <summary>
        /// This will create an intersection if two nodes overlap on the road. Only good if the roads only overlap once.
        /// </summary>
        /// <param name="bRoad"></param>
        /// <param name="tRoad"></param>
        private static void UnitTest_IntersectionHelper(GSDRoad bRoad, GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType, GSDRoadIntersection.RoadTypeEnum rType) {
            GSDSplineN tInter1 = null;
            GSDSplineN tInter2 = null;
            foreach (GSDSplineN tNode in bRoad.GSDSpline.mNodes) {
                foreach (GSDSplineN xNode in tRoad.GSDSpline.mNodes) {
                    if (GSDRootUtil.IsApproximately(Vector3.Distance(tNode.transform.position, xNode.transform.position), 0f, 0.05f)) {
                        tInter1 = tNode;
                        tInter2 = xNode;
                        break;
                    }
                }
            }

            if (tInter1 != null && tInter2 != null) {
                GameObject tInter = GSD.Roads.GSDIntersections.CreateIntersection(tInter1, tInter2);
                GSDRoadIntersection GSDRI = tInter.GetComponent<GSDRoadIntersection>();
                GSDRI.iStopType = iStopType;
                GSDRI.rType = rType;
            }
        }
Пример #30
0
 public static void ConstructRoad_StoreTerrainHistory(ref GSDRoad tRoad){
     ConstructRoad_DoStoreTerrainHistory(ref tRoad);
 }
Пример #31
0
		private static string GetRoadTHFilename(ref GSDRoad tRoad){
			string tSceneName = System.IO.Path.GetFileName(UnityEditor.EditorApplication.currentScene).ToLower().Replace(".unity","");
			tSceneName = tSceneName.Replace("/","");
			tSceneName = tSceneName.Replace(".","");
			string tRoadName = tRoad.GSDRS.transform.name.Replace("RoadArchitectSystem","RAS") + "-" + tRoad.transform.name;
			return tSceneName + "-" + tRoadName + "-TH.gsd";
		}
Пример #32
0
		public static List<GSDTerrainHistoryMaker> TerrainHistory_Load(GSDRoad tRoad){
			string tPath = CheckNonAssetDirTH() + GetRoadTHFilename(ref tRoad);
			if(string.IsNullOrEmpty(tPath) || tPath.Length < 2){ return null; }
			if(!File.Exists(tPath)){ return null; }
		    List<GSDTerrainHistoryMaker> result;
            Stream stream = File.Open(tPath, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();
            bFormatter.Binder = new VersionDeserializationBinder();
//			try{
            	result = (List<GSDTerrainHistoryMaker>)bFormatter.Deserialize(stream) as List<GSDTerrainHistoryMaker>;
//			}catch{
//				result = null;	
//			}
            stream.Close();
            return result;
		}
Пример #33
0
		public static void TerrainHistory_Delete(GSDRoad tRoad){
			string tPath = CheckNonAssetDirTH() + GetRoadTHFilename(ref tRoad);
			if(System.IO.File.Exists(tPath)){
				System.IO.File.Delete(tPath);	
			}
		}
Пример #34
0
	    public static void TerrainHistory_Save(List<GSDTerrainHistoryMaker> tObj, GSDRoad tRoad){
			string tPath = CheckNonAssetDirTH() + GetRoadTHFilename(ref tRoad);
			if(string.IsNullOrEmpty(tPath) || tPath.Length < 2){ return; }
		    Stream stream = File.Open(tPath, FileMode.Create);
		    BinaryFormatter bformatter = new BinaryFormatter();
		    bformatter.Binder = new VersionDeserializationBinder();
		    bformatter.Serialize(stream, tObj);
			tRoad.TerrainHistoryByteSize = (stream.Length*0.001f).ToString("n0") + " kb";
		    stream.Close();
		}
Пример #35
0
		private static void SaveMesh(SaveMeshTypeEnum SaveType, Mesh tMesh, GSDRoad tRoad, string tName){
			if(!tRoad.GSDRS.opt_bSaveMeshes){ return; }
			
			string tSceneName = System.IO.Path.GetFileName(UnityEditor.EditorApplication.currentScene).ToLower().Replace(".unity","");
			tSceneName = tSceneName.Replace("/","");
			tSceneName = tSceneName.Replace(".","");
			string tFolderName = "";
			if(SaveType == SaveMeshTypeEnum.Road){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Roads/";
			}else if(SaveType == SaveMeshTypeEnum.Shoulder){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Shoulders/";
			}else if(SaveType == SaveMeshTypeEnum.Intersection){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Intersections/";
			}else if(SaveType == SaveMeshTypeEnum.Railing){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Railings/";
			}else if(SaveType == SaveMeshTypeEnum.Center){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/CenterDividers/";
			}else if(SaveType == SaveMeshTypeEnum.RoadCut){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Roads/Cuts/";
			}else if(SaveType == SaveMeshTypeEnum.SCut){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/Shoulders/Cuts/";
			}else if(SaveType == SaveMeshTypeEnum.RoadConn){
				tFolderName = "Assets/RoadArchitect/Mesh/Generated/RoadConn/";
			}
			
			string xPath = Application.dataPath.Replace("/Assets","/" + tFolderName);
			if(!System.IO.Directory.Exists(xPath)){
				System.IO.Directory.CreateDirectory(xPath);
			}
			
			string tRoadName = tRoad.transform.name;
			string FinalName = tFolderName + tSceneName + "-" + tRoadName + "-" + tName + ".asset";
			if(SaveType == SaveMeshTypeEnum.Intersection){
				FinalName = tFolderName + tSceneName + "-" + tName + ".asset";
			}
			
			UnityEditor.AssetDatabase.CreateAsset(tMesh,FinalName);
		}
Пример #36
0
//		static void TerrainHistorySerialize(ref GSDRoad tRoad) {
//			MemoryStream ms = new MemoryStream();
//	        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
//			formatter.Serialize(ms,tRoad.TerrainHistory);
//			ms.Close();
//			tRoad.TerrainHistoryRaw = ms.ToArray();
//	        ms = null;
//	    }
//		
//		static void TerrainHistoryDeserialize(ref GSDRoad tRoad) {
//			MemoryStream ms = new MemoryStream(tRoad.TerrainHistoryRaw);
//	        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
//			tRoad.TerrainHistory = (List<GSDTerrainHistoryMaker>)formatter.Deserialize(ms);
//			ms.Close();
//	        ms = null;
//	    }

        public static void ConstructRoad_ResetTerrainHistory(ref GSDRoad tRoad)
        {
            ConstructRoad_DoResetTerrainHistory(ref tRoad);
        }
        private static void RoadJob_DoPrelim(ref GSDRoad tRoad)
        {
            GSDSplineC tSpline = tRoad.GSDSpline;
            //Road,shoulder,ramp and lane widths:
            float RoadWidth = tRoad.RoadWidth();
            float ShoulderWidth = tRoad.opt_ShoulderWidth;
            float RoadSeperation = RoadWidth / 2f;
            float RoadSeperation_NoTurn = RoadWidth / 2f;
            float ShoulderSeperation = RoadSeperation + ShoulderWidth;
            float LaneWidth = tRoad.opt_LaneWidth;
            float RoadSep1Lane = (RoadSeperation + (LaneWidth*0.5f));
            float RoadSep2Lane = (RoadSeperation + (LaneWidth*1.5f));
            float ShoulderSep1Lane = (ShoulderSeperation + (LaneWidth*0.5f));
            float ShoulderSep2Lane = (ShoulderSeperation + (LaneWidth*1.5f));

            //Vector3 buffers used in construction:
            Vector3 rVect = default(Vector3);
            Vector3 lVect = default(Vector3);
            Vector3 ShoulderR_rVect = default(Vector3);
            Vector3 ShoulderR_lVect = default(Vector3);
            Vector3 ShoulderL_rVect = default(Vector3);
            Vector3 ShoulderL_lVect = default(Vector3);
            Vector3 RampR_R = default(Vector3);
            Vector3 RampR_L = default(Vector3);
            Vector3 RampL_R = default(Vector3);
            Vector3 RampL_L = default(Vector3);
            float ShoulderR_OuterAngle = 0f; if(ShoulderR_OuterAngle < 0f){ }
            float ShoulderL_OuterAngle = 0f; if(ShoulderL_OuterAngle < 0f){ }
            //			Vector3 ShoulderR_OuterDirection = default(Vector3);
            //			Vector3 ShoulderL_OuterDirection = default(Vector3);

            //Previous temp storage values:
            Vector3 tVect_Prev = default(Vector3);				if(tVect_Prev == default(Vector3)){ } //Prev step storage of road variable.
            Vector3 rVect_Prev = default(Vector3);				if(rVect_Prev == default(Vector3)){ }//Prev step storage of road variable.
            Vector3 lVect_Prev = default(Vector3);				if(lVect_Prev == default(Vector3)){ }//Prev step storage of road variable.
            Vector3 ShoulderR_PrevLVect = default(Vector3);		if(ShoulderR_PrevLVect == default(Vector3)){ }//Prev step storage of shoulder variable.
            Vector3 ShoulderL_PrevRVect = default(Vector3);		if(ShoulderL_PrevRVect == default(Vector3)){ }//Prev step storage of shoulder variable.
            Vector3 ShoulderR_PrevRVect = default(Vector3);		if(ShoulderR_PrevRVect == default(Vector3)){ }//Prev step storage of shoulder variable.
            Vector3 ShoulderL_PrevLVect = default(Vector3);		if(ShoulderL_PrevLVect == default(Vector3)){ }//Prev step storage of shoulder variable.
            //			Vector3 ShoulderR_PrevRVect2 = default(Vector3);	//Prev storage of shoulder variable (2 step history).
            //			Vector3 ShoulderL_PrevLVect2 = default(Vector3);	//Prev storage of shoulder variable (2 step history).
            //			Vector3 ShoulderR_PrevRVect3 = default(Vector3);	//Prev storage of shoulder variable (3 step history).
            //			Vector3 ShoulderL_PrevLVect3 = default(Vector3);	//Prev storage of shoulder variable (3 step history).
            Vector3 RampR_PrevR = default(Vector3);				if(RampR_PrevR == default(Vector3)){ }//Prev storage of ramp variables (outer shoulder).
            Vector3 RampR_PrevL = default(Vector3);				if(RampR_PrevL == default(Vector3)){ }//Prev storage of ramp variables (outer shoulder).
            Vector3 RampL_PrevR = default(Vector3);				if(RampL_PrevR == default(Vector3)){ }//Prev storage of ramp variables (outer shoulder).
            Vector3 RampL_PrevL = default(Vector3);				if(RampL_PrevL == default(Vector3)){ }//Prev storage of ramp variables (outer shoulder).
            //			Vector3 ShoulderR_OuterDirectionPrev = default(Vector3);	//Prev storage of outer shoulder direction (euler).
            //			Vector3 ShoulderL_OuterDirectionPrev = default(Vector3);	//Prev storage of outer shoulder direction (euler).

            //Height and angle variables, used to change certain parameters of road depending on past & future angle and height changes.
            //			float tAngle = 0f;
            //			float OrigStep = 0.06f;
            float Step = tRoad.opt_RoadDefinition / tSpline.distance;
            //			float AngleStep = 5f;
            Vector3 tHeight0 = new Vector3(0f,0.1f,0f);
            //			Vector3 tHeight2 = new Vector3(0f,0.15f,0f);
            //			Vector3 tHeight1 = new Vector3(0f,0.2f,0f);
            float OuterShoulderWidthR = 0f;
            float OuterShoulderWidthL = 0f;
            float RampOuterWidthR = (OuterShoulderWidthR / 6f) + OuterShoulderWidthR;
            float RampOuterWidthL = (OuterShoulderWidthL / 6f) + OuterShoulderWidthL;
            Vector3 tVect = default(Vector3);
            Vector3 POS = default(Vector3);
            float TempY = 0f;
            //			bool bTempYWasNegative = false;
            //			Vector3 tY = new Vector3(0f,0f,0f);
            float tHeightAdded = 0f;		if(tHeightAdded < 0f){ }
            //			float[] HeightChecks = new float[5];
            Vector3 gHeight = default(Vector3);

            //Bridge variables:
            bool bIsBridge = false;			if(bIsBridge == false){ }
            bool bTempbridge = false;		if(bTempbridge == false){ }
            bool bBridgeInitial = false;	if(bBridgeInitial == false){ }
            bool bBridgeLast = false;		if(bBridgeLast == false){ }
            float BridgeUpComing;
            //			int BridgeLIndex;
            //			int BridgeRIndex;

            //Tunnel variables:
            bool bIsTunnel = false;			if(bIsTunnel == false){ }
            bool bTempTunnel = false;		if(bTempTunnel == false){ }
            bool bTunnelInitial = false; 	if(bTunnelInitial == false){ }
            bool bTunnelLast = false; 		if(bTunnelLast == false){ }
            float TunnelUpComing = 0f;		if(TunnelUpComing < 0f){ }
            //			int TunnelLIndex;
            //			int TunnelRIndex;

            //Intersection variables and buffers:
            float tIntHeight = 0f;			if(tIntHeight < 0f){ }
            float tIntStrength = 0f;		if(tIntStrength < 0f){ }
            float tIntStrength_temp = 0f; 	if(tIntStrength_temp < 0f){ }
            //			float tIntDistCheck = 75f;
            GSDRoadIntersection GSDRI = null;
            bool bIsPastInter = false;
            bool bMaxIntersection = false;
            bool bWasPrevMaxInter = false;
            GSDSplineN xNode = null;
            float tInterSubtract = 4f;
            float tLastInterHeight = -4f;
            bool bOverrideRampR = false;
            bool bOverrideRampL = false;
            Vector3 RampR_Override = default(Vector3);
            Vector3 RampL_Override = default(Vector3);
            bool bFirstInterNode = false;
            bool bInter_PrevWasCorner = false; if(bInter_PrevWasCorner == false){ }
            bool bInter_CurreIsCorner = false;
            bool bInter_CurreIsCornerRR = false;
            bool bInter_CurreIsCornerRL = false;
            bool bInter_CurreIsCornerLL = false;
            bool bInter_CurreIsCornerLR = false;
            bool bInter_PrevWasCornerRR = false;
            bool bInter_PrevWasCornerRL = false;
            bool bInter_PrevWasCornerLL = false;
            bool bInter_PrevWasCornerLR = false;
            Vector3 iTemp_HeightVect = default(Vector3);
            Vector3 rVect_iTemp = default(Vector3);
            Vector3 lVect_iTemp = default(Vector3);
            Vector3 ShoulderR_R_iTemp = default(Vector3);
            Vector3 ShoulderL_L_iTemp = default(Vector3);
            Vector3 RampR_R_iTemp = default(Vector3);
            Vector3 RampR_L_iTemp = default(Vector3);
            Vector3 RampL_R_iTemp = default(Vector3);
            Vector3 RampL_L_iTemp = default(Vector3);
            Vector3 tempIVect_Prev = default(Vector3);
            Vector3 tempIVect = tVect;
            bool b0LAdded = false; if(b0LAdded == false){ }
            bool b1LAdded = false; if(b1LAdded == false){ }
            bool b2LAdded = false; if(b2LAdded == false){ }
            bool b3LAdded = false; if(b3LAdded == false){ }
            bool f0LAdded = false; if(f0LAdded == false){ }
            bool f1LAdded = false; if(f1LAdded == false){ }
            bool f2LAdded = false; if(f2LAdded == false){ }
            bool f3LAdded = false; if(f3LAdded == false){ }
            bool b0RAdded = false; if(b0RAdded == false){ }
            bool b1RAdded = false; if(b1RAdded == false){ }
            bool b2RAdded = false; if(b2RAdded == false){ }
            bool b3RAdded = false; if(b3RAdded == false){ }
            bool f0RAdded = false; if(f0RAdded == false){ }
            bool f1RAdded = false; if(f1RAdded == false){ }
            bool f2RAdded = false; if(f2RAdded == false){ }
            bool f3RAdded = false; if(f3RAdded == false){ }
            bool bInterTestAddAfterR = false; if(bInterTestAddAfterR == false){ }
            bool bInterTestAddAfterL = false; if(bInterTestAddAfterL == false){ }
            //			Vector3 InterTestVect1 = default(Vector3);
            //			Vector3 InterTestVect2 = default(Vector3);
            //			Vector3 InterTestVect3 = default(Vector3);
            //			Vector3 InterTestVect4 = default(Vector3);
            bool bShoulderSkipR = false;
            bool bShoulderSkipL = false;
            bool bShrinkRoadB = false;
            bool bShrinkRoadFNext = false;
            bool bShrinkRoadF = false;
            bool bIsNextInter = false;
            GSDSplineN cNode = null;
            int NodeID = -1;
            int NodeIDPrev = -1;
            int NodeCount = tSpline.GetNodeCount();
            bool bDynamicCut = false;
            float CullDistanceSQ = (3f * RoadWidth) * (3f * RoadWidth);
            float mCornerDist = 0f;
            Vector2 CornerRR = default(Vector2);		if(CornerRR == default(Vector2)){ }
            Vector2 CornerRL = default(Vector2);		if(CornerRL == default(Vector2)){ }
            Vector2 CornerLR = default(Vector2);		if(CornerLR == default(Vector2)){ }
            Vector2 CornerLL = default(Vector2);		if(CornerLL == default(Vector2)){ }
            Vector2 rVect2D = default(Vector2);			if(rVect2D == default(Vector2)){ }
            Vector2 lVect2D = default(Vector2);			if(lVect2D == default(Vector2)){ }
            Vector3 tempIVect_prev = default(Vector3);	if(tempIVect_prev == default(Vector3)){ }
            Vector3 POS_Next = default(Vector3);		if(POS_Next == default(Vector3)){ }
            Vector3 tVect_Next = default(Vector3);		if(tVect_Next == default(Vector3)){ }
            Vector3 rVect_Next = default(Vector3);		if(rVect_Next == default(Vector3)){ }
            Vector3 lVect_Next = default(Vector3);		if(lVect_Next == default(Vector3)){ }
            Vector3 xHeight = default(Vector3); 		if(xHeight == default(Vector3)){ }
            bool bLRtoRR = false;
            bool bLLtoLR = false;
            bool bLine = false;
            bool bImmuneR = false;
            bool bImmuneL = false;
            bool bSpecAddedL = false; if(bSpecAddedL == false){ }
            bool bSpecAddedR = false; if(bSpecAddedR == false){ }
            bool bTriggerInterAddition = false;
            bool bSpecialThreeWayIgnoreR = false;
            bool bSpecialThreeWayIgnoreL = false;
            //			int eCount = -1;
            //			int eIndex = -1;
            //			int uCount = -1;
            //			int uIndex = -1;
            float bMod1 = 1.75f;
            float bMod2 = 1.25f;
            float t2DDist = -1f;
            List<Vector3> vList = null;
            List<int> eList = null;
            float tParam2 = 0f;
            float tParam1 = 0f;
            bool bRecordShoulderForNormals = false;
            bool bRecordShoulderLForNormals = false;

            //Unused for now, for later partial construction methods:
            bool bInterseOn = tRoad.RCS.bInterseOn;
            //			bool bBridgesOn = tRoad.RCS.bBridgesOn;
            //			if(tRoad.RCS.bRoadOn){
                bInterseOn = true;
            //			}

            //Prelim intersection construction and profiling:
            if(tRoad.bProfiling){ Profiler.BeginSample("RoadJob_Prelim_Inter"); }
            if(bInterseOn){
                RoadJob_Prelim_Inter(ref tRoad);
            }

            if(tRoad.bProfiling){ Profiler.EndSample(); }

            if(tRoad.bProfiling){ Profiler.BeginSample("RoadPrelimForLoop"); }

            //Road/shoulder cuts: Init necessary since a road cut is added for the last segment after this function:
            if(tRoad.opt_bRoadCuts || tRoad.opt_bDynamicCuts){
                tRoad.RCS.RoadCutNodes.Add(tSpline.mNodes[0]);
            }
            if(tRoad.opt_bShoulderCuts || tRoad.opt_bDynamicCuts){
                tRoad.RCS.ShoulderCutsLNodes.Add(tSpline.mNodes[0]);
                tRoad.RCS.ShoulderCutsRNodes.Add(tSpline.mNodes[0]);
            }

            //Start initializing the loop. Convuluted to handle special control nodes, so roads don't get rendered where they aren't supposed to, while still preserving the proper curvature.
            float FinalMax = 1f;
            float StartMin = 0f;
            if(tSpline.bSpecialEndControlNode){	//If control node, start after the control node:
                FinalMax = tSpline.mNodes[tSpline.GetNodeCount()-2].tTime;
            }
            if(tSpline.bSpecialStartControlNode){	//If ends in control node, end construction before the control node:
                StartMin = tSpline.mNodes[1].tTime;
            }
            bool bFinalEnd = false;
            float RoadConnection_StartMin1 = StartMin;	//Storage of incremental start values for the road connection mesh construction at the end of this function.
            float RoadConnection_FinalMax1 = FinalMax; 	//Storage of incremental end values for the road connection mesh construction at the end of this function.
            if(tSpline.bSpecialEndNode_IsStart_Delay){
                StartMin += (tSpline.SpecialEndNodeDelay_Start / tSpline.distance);	//If there's a start delay (in meters), delay the start of road construction: Due to special control nodes for road connections or 3 way intersections.
            }else if(tSpline.bSpecialEndNode_IsEnd_Delay){
                FinalMax -= (tSpline.SpecialEndNodeDelay_End / tSpline.distance);	//If there's a end delay (in meters), cut early the end of road construction: Due to special control nodes for road connections or 3 way intersections.
            }
            //			float RoadConnection_StartMin2 = StartMin;	//Storage of incremental start values for the road connection mesh construction at the end of this function.
            //			float RoadConnection_FinalMax2 = FinalMax; 	//Storage of incremental end values for the road connection mesh construction at the end of this function.
            float i=StartMin;

            //			int StartIndex = tSpline.GetClosestRoadDefIndex(StartMin,true,false);
            //			int EndIndex = tSpline.GetClosestRoadDefIndex(FinalMax,false,true);
            //			float cDist = 0f;
            bool kSkip = true;
            bool kSkipFinal = false;
            int kCount = 0;
            int vCount = kCount;
            int kFinalCount = tSpline.RoadDefKeysArray.Length;
            int spamcheckmax1 = 18000;
            int spamcheck1 = 0;

            if(IsApproximately(StartMin,0f,0.0001f)){
                kSkip = false;
            }
            if(IsApproximately(FinalMax,1f,0.0001f)){
                kSkipFinal = true;
            }

            //If startmin > 0 then kcount needs to start at proper road def
            //			bool bStartMinEnabled = false;
            int StartMinIndex1 = 0;

            if(StartMin > 0f){
                kCount = tSpline.GetClosestRoadDefIndex(StartMin,true,false);
            //				bStartMinEnabled = true;
                StartMinIndex1 = 1;
            }

            while(!bFinalEnd && spamcheck1 < spamcheckmax1){
                spamcheck1++;

                if(kSkip){
                    i = StartMin;
                    kSkip = false;
                }else{
                    if(kCount >= kFinalCount){
                        i = FinalMax;
                        if(kSkipFinal){ break; }
                    }else{
                        i = tSpline.TranslateInverseParamToFloat(tSpline.RoadDefKeysArray[kCount]);
                        kCount+=1;
                    }
                }

                if(i > 1f){
                    break;
                }
                if(i < 0f){
                    i = 0f;
                }

                if(IsApproximately(i,FinalMax,0.00001f)){
                    bFinalEnd = true;
                }else if(i > FinalMax){
                    if(tSpline.bSpecialEndControlNode){
                        i = FinalMax;
                        bFinalEnd = true;
                    }else{
                        bFinalEnd = true;
                        break;
                    }
                }
                cNode = tSpline.GetCurrentNode(i);	//Set the current node.
                NodeID = cNode.idOnSpline;			//Set the current node ID.
                if(NodeID != NodeIDPrev && (tRoad.opt_bRoadCuts || tRoad.opt_bDynamicCuts)){	//If different than the previous node id, time to make a cut, if necessary:
                    //Don't ever cut the first node, last node, intersection node, special control nodes, bridge nodes or bridge control nodes:
                    if(NodeID > StartMinIndex1 && NodeID < (NodeCount-1) && !cNode.bIsIntersection && !cNode.bSpecialEndNode){ // && !cNode.bIsBridge_PreNode && !cNode.bIsBridge_PostNode){
                        if(tRoad.opt_bDynamicCuts){
                            bDynamicCut = cNode.bRoadCut;
                        }else{
                            bDynamicCut = true;
                        }

                        if(bDynamicCut){
                            tRoad.RCS.RoadCuts.Add(tRoad.RCS.RoadVectors.Count);			//Add the vector index to cut later.
                            tRoad.RCS.RoadCutNodes.Add(cNode);								//Store the node which was at the beginning of this cut.
                        }
                        if(tRoad.opt_bShoulderCuts && bDynamicCut){	//If option shoulder cuts is on.
                            tRoad.RCS.ShoulderCutsL.Add(tRoad.RCS.ShoulderL_Vectors.Count);	//Add the vector index to cut later.
                            tRoad.RCS.ShoulderCutsLNodes.Add(cNode);						//Store the node which was at the beginning of this cut.
                            tRoad.RCS.ShoulderCutsR.Add(tRoad.RCS.ShoulderR_Vectors.Count);	//Add the vector index to cut later.
                            tRoad.RCS.ShoulderCutsRNodes.Add(cNode);						//Store the node which was at the beginning of this cut.
                        }
                    }
                }
                if(NodeID != NodeIDPrev){
                    if(tRoad.RCS.RoadVectors.Count > 0){
                        cNode.bInitialRoadHeight = tRoad.RCS.RoadVectors[tRoad.RCS.RoadVectors.Count-1].y;
                    }
                }
                NodeIDPrev = NodeID;				//Store the previous node ID for the next round. Done now with road cuts as far as this function is concerned.

                //Set all necessary intersection triggers to false:
                bInter_CurreIsCorner = false;
                bInter_CurreIsCornerRR = false;
                bInter_CurreIsCornerRL = false;
                bInter_CurreIsCornerLL = false;
                bInter_CurreIsCornerLR = false;
                b0LAdded = false;
                b1LAdded = false;
                b2LAdded = false;
                b3LAdded = false;
                f0LAdded = false;
                f1LAdded = false;
                f2LAdded = false;
                f3LAdded = false;
                b0RAdded = false;
                b1RAdded = false;
                b2RAdded = false;
                b3RAdded = false;
                f0RAdded = false;
                f1RAdded = false;
                f2RAdded = false;
                f3RAdded = false;
                bInterTestAddAfterR=false;
                bInterTestAddAfterL=false;
                bShoulderSkipR = false;
                bShoulderSkipL = false;
                bShrinkRoadB = false;
                bShrinkRoadF = false;
                bIsNextInter = false;
                if(bShrinkRoadFNext){
                    bShrinkRoadFNext = false;
                    bShrinkRoadF = true;
                }
                bRecordShoulderForNormals = false;
                bRecordShoulderLForNormals = false;

                //Bridges: Note: This is convoluted due to need for triggers:
                bBridgeInitial = false;
                bBridgeLast = false;
                bTempbridge = tSpline.IsInBridge(i);
                if(!bIsBridge && bTempbridge){
                    bIsBridge = true;
                    bBridgeInitial = true;
                }else if(bIsBridge && !bTempbridge){
                    bIsBridge = false;
                }
                //Check if this is the last bridge run for this bridge:
                if(bIsBridge){
                    bTempbridge = tSpline.IsInBridge(i+Step);
                    if(!bTempbridge){
                        bBridgeLast = true;
                    }
                }

                //Tunnels: Note: This is convoluted due to need for triggers:
                bTunnelInitial = false;
                bTunnelLast = false;
                bTempTunnel = tSpline.IsInTunnel(i);
                if(!bIsTunnel && bTempTunnel){
                    bIsTunnel = true;
                    bTunnelInitial = true;
                }else if(bIsTunnel && !bTempTunnel){
                    bIsTunnel = false;
                }
                //Check if this is the last Tunnel run for this Tunnel:
                if(bIsTunnel){
                    bTempTunnel = tSpline.IsInTunnel(i+Step);
                    if(!bTempTunnel){
                        bTunnelLast = true;
                    }
                }

                //Master Vector3 for the current road construction location:
                tSpline.GetSplineValue_Both(i,out tVect,out POS);

            //				Profiler.EndSample();
            //				Profiler.BeginSample("Test2");

                //Detect downward or upward slope:
                TempY = POS.y;
            //				bTempYWasNegative = false;
                if(TempY < 0f){
            //					bTempYWasNegative = true;
                    TempY *= -1f;
                }
                if(tVect.y < 0f){
                    tVect.y = 0f;
                }

                //Determine if intersection:
                if(bInterseOn){
                    bIsPastInter = false;	//If past intersection
                    tIntStrength = tRoad.GSDSpline.IntersectionStrength(ref tVect,ref tIntHeight, ref GSDRI, ref bIsPastInter, ref i, ref xNode);
                    bMaxIntersection = (tIntStrength >= 1f);	//1f strength = max intersection
                    bFirstInterNode = false;
                }

                //Outer widths:
                if(bMaxIntersection && bInterseOn){
                    GSDRI.SignHeight = tIntHeight;
                    xNode.iConstruction.bBLane0Done_Final_ThisRound = false;
                    xNode.iConstruction.bBLane1Done_Final_ThisRound = false;
                    xNode.iConstruction.bBLane2Done_Final_ThisRound = false;
                    xNode.iConstruction.bBLane3Done_Final_ThisRound = false;
                    xNode.iConstruction.bFLane0Done_Final_ThisRound = false;
                    xNode.iConstruction.bFLane1Done_Final_ThisRound = false;
                    xNode.iConstruction.bFLane2Done_Final_ThisRound = false;
                    xNode.iConstruction.bFLane3Done_Final_ThisRound = false;
                    xNode.iConstruction.bIsFrontFirstRound = false;

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        OuterShoulderWidthR = ShoulderSeperation;
                        OuterShoulderWidthL = ShoulderSeperation;
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        OuterShoulderWidthR = ShoulderSep1Lane;
                        OuterShoulderWidthL = ShoulderSep1Lane;
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        if(bIsPastInter){
                            OuterShoulderWidthR = ShoulderSep1Lane;
                            OuterShoulderWidthL = ShoulderSep2Lane;
                        }else{
                            OuterShoulderWidthR = ShoulderSep2Lane;
                            OuterShoulderWidthL = ShoulderSep1Lane;
                        }
                    }
                }else{
                    if(TempY < 0.5f || bIsBridge || bIsTunnel){
                        OuterShoulderWidthR = ShoulderSeperation;
                        OuterShoulderWidthL = ShoulderSeperation;
                    }else{
                        OuterShoulderWidthR = ShoulderSeperation + (TempY*0.05f);
                        OuterShoulderWidthL = ShoulderSeperation + (TempY*0.05f);
                    }
                }

                if(bIsBridge){ //No ramps for bridges:
                    RampOuterWidthR = OuterShoulderWidthR;
                    RampOuterWidthL = OuterShoulderWidthL;
                }else{
                    RampOuterWidthR = (OuterShoulderWidthR / 4f) + OuterShoulderWidthR;
                    RampOuterWidthL = (OuterShoulderWidthL / 4f) + OuterShoulderWidthL;
                }

                //The master outer road edges vector locations:
                if(bMaxIntersection && bInterseOn){	//If in maximum intersection, adjust road edge (also the shoulder inner edges):
                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        rVect = (tVect + new Vector3(RoadSeperation_NoTurn*POS.normalized.z,0,RoadSeperation_NoTurn*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation_NoTurn*-POS.normalized.z,0,RoadSeperation_NoTurn*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        if(bIsPastInter){
                            rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));;
                        }else{
                            rVect = (tVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                        }
                    }else{
                        rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                    }
                }else{
                    //Typical road/shoulder inner edge location:
                    rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                    lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                }

                //Shoulder right vectors:
                ShoulderR_rVect = (tVect + new Vector3(OuterShoulderWidthR*POS.normalized.z,0,OuterShoulderWidthR*-POS.normalized.x));
                ShoulderR_lVect = rVect;	//Note that the shoulder inner edge is the same as the road edge vector.
                //Shoulder left vectors:
                ShoulderL_rVect = lVect;	//Note that the shoulder inner edge is the same as the road edge vector.
                ShoulderL_lVect = (tVect + new Vector3(OuterShoulderWidthL*-POS.normalized.z,0,OuterShoulderWidthL*POS.normalized.x));

            //				Profiler.EndSample();
            //				Profiler.BeginSample("Test3");

                //Now to start the main lane construction for the intersection:
                if(bMaxIntersection && bInterseOn){
            //					if(kCount >= tSpline.RoadDefKeysArray.Length){
            //						vCount = tSpline.RoadDefKeysArray.Length-1;
            //					}else{
            //						vCount = kCount-1;
            //					}
                    vCount = kCount;

                    tParam2 = tSpline.TranslateInverseParamToFloat(tSpline.RoadDefKeysArray[vCount]);
                    float tInterStrNext = tRoad.GSDSpline.IntersectionStrength_Next(tSpline.GetSplineValue(tParam2,false));
                    if(IsApproximately(tInterStrNext,1f,0.001f) || tInterStrNext > 1f){
                        bIsNextInter = true;
                    }else{
                        bIsNextInter = false;
                    }

                    if(string.Compare(xNode.UID,GSDRI.Node1.UID) == 0){
                        bFirstInterNode = true;
                    }else{
                        bFirstInterNode = false;
                    }

                    tempIVect = tVect;
                    if(bIsPastInter){
                        bool bLLtoRL = bFirstInterNode;
                        bool bRLtoRR = !bFirstInterNode;
                        if(xNode.iConstruction.iFLane0L.Count == 0){
                            xNode.iConstruction.bIsFrontFirstRound = true;
                            xNode.iConstruction.bIsFrontFirstRoundTriggered = true;
                            xNode.iConstruction.bFLane0Done_Final_ThisRound = true;
                            xNode.iConstruction.bFLane1Done_Final_ThisRound = true;
                            xNode.iConstruction.bFLane2Done_Final_ThisRound = true;
                            xNode.iConstruction.bFLane3Done_Final_ThisRound = true;

                            if(GSDRI.bFlipped && !bFirstInterNode){
                                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                    xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerLR[0],tIntHeight));
                                    xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerLR[2],tIntHeight));
                                    xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerLL_CornerLR[2],tIntHeight));
                                    xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerLL_CornerLR[3],tIntHeight));
                                    xNode.iConstruction.iFLane3L.Add(GVC(GSDRI.fCornerLL_CornerLR[3],tIntHeight));
                                    xNode.iConstruction.iFLane3R.Add(GVC(GSDRI.fCornerLL_CornerLR[4],tIntHeight));
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                    xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerLR[0],tIntHeight));
                                    xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerLR[2],tIntHeight));
                                    xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerLL_CornerLR[2],tIntHeight));
                                    xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerLL_CornerLR[3],tIntHeight));
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                    xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerLR[0],tIntHeight));
                                    xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                                    xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerLR[2],tIntHeight));
                                }
                            }else{
                                if(bLLtoRL){
                                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerRL[4],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerRL[3],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerRL[3],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerRL[2],tIntHeight));
                                        xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerLL_CornerRL[2],tIntHeight));
                                        xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane3L.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane3R.Add(GVC(GSDRI.fCornerLL_CornerRL[0],tIntHeight));
                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerRL[3],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerRL[2],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerRL[2],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerLL_CornerRL[0],tIntHeight));
                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerLL_CornerRL[2],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerLL_CornerRL[1],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerLL_CornerRL[0],tIntHeight));
                                    }
                                }else if(bRLtoRR){
                                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[4],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[3],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerRL_CornerRR[3],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                                        xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                                        xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane3L.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane3R.Add(GVC(GSDRI.fCornerRL_CornerRR[0],tIntHeight));
                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[3],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane2L.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane2R.Add(GVC(GSDRI.fCornerRL_CornerRR[0],tIntHeight));
                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                        xNode.iConstruction.iFLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                                        xNode.iConstruction.iFLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane1L.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                                        xNode.iConstruction.iFLane1R.Add(GVC(GSDRI.fCornerRL_CornerRR[0],tIntHeight));
                                    }
                                }
                            }

                            xNode.iConstruction.ShoulderFR_End = xNode.iConstruction.iFLane0L[0];
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                xNode.iConstruction.ShoulderFL_End = xNode.iConstruction.iFLane3R[0];
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                xNode.iConstruction.ShoulderFL_End = xNode.iConstruction.iFLane2R[0];
                            }else{
                                xNode.iConstruction.ShoulderFL_End = xNode.iConstruction.iFLane1R[0];
                            }
                            xNode.iConstruction.ShoulderFL_StartIndex = tRoad.RCS.ShoulderL_Vectors.Count-2;
                            xNode.iConstruction.ShoulderFR_StartIndex = tRoad.RCS.ShoulderR_Vectors.Count-2;
                        }

                        //Line 0:
                        xNode.iConstruction.f0LAttempt = rVect;
                        if(!xNode.iConstruction.bFLane0Done && !GSDRI.Contains(ref rVect)){
                            xNode.iConstruction.iFLane0L.Add(GVC(rVect,tIntHeight)); f0LAdded = true;
                        }

                        //Line 1:
                    //	if(f0LAdded){
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            tempIVect = tVect;
                            if(!xNode.iConstruction.bFLane1Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect,rVect)){
                                if(f0LAdded){ xNode.iConstruction.iFLane0R.Add(GVC(tempIVect,tIntHeight)); f0RAdded = true; }
                                xNode.iConstruction.iFLane1L.Add(GVC(tempIVect,tIntHeight)); f1LAdded = true;
                            }else{
                                if(f0LAdded){ xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count-1); f0LAdded = false; }
                            }
                        }else{
                            tempIVect = (tVect + new Vector3((LaneWidth*0.5f)*POS.normalized.z,0f,(LaneWidth*0.5f)*-POS.normalized.x));
                            if(!xNode.iConstruction.bFLane1Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect,rVect)){
                                if(f0LAdded){ xNode.iConstruction.iFLane0R.Add(GVC(tempIVect,tIntHeight));f0RAdded = true; }
                                xNode.iConstruction.iFLane1L.Add(GVC(tempIVect,tIntHeight)); f1LAdded = true;
                            }else{
                                if(f0LAdded){ xNode.iConstruction.iFLane0L.RemoveAt(xNode.iConstruction.iFLane0L.Count-1); f0LAdded = false; }
                            }
                        }
                        //}
                        xNode.iConstruction.f0RAttempt = tempIVect;
                        xNode.iConstruction.f1LAttempt = tempIVect;

                        //Line 2:
                        //if(f1LAdded){
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            tempIVect = lVect;
                            if(!xNode.iConstruction.bFLane2Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect,rVect)){
                                if(f1LAdded){ xNode.iConstruction.iFLane1R.Add(GVC(tempIVect,tIntHeight)); f1RAdded = true; }
                            }else{
                                if(f1LAdded && xNode.iConstruction.iFLane1L.Count > 1){ xNode.iConstruction.iFLane1L.RemoveAt(xNode.iConstruction.iFLane1L.Count-1); f1LAdded = false; }
                            }
                        }else{
                            tempIVect = (tVect + new Vector3((LaneWidth*0.5f)*-POS.normalized.z,0f,(LaneWidth*0.5f)*POS.normalized.x));
                            tempIVect_prev = tempIVect;
                            if(!xNode.iConstruction.bFLane2Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(tempIVect,rVect)){
                                if(f1LAdded){ xNode.iConstruction.iFLane1R.Add(GVC(tempIVect,tIntHeight)); f1RAdded = true; }
                                xNode.iConstruction.iFLane2L.Add(GVC(tempIVect,tIntHeight)); f2LAdded = true;
                            }else{
                                if(f1LAdded){ xNode.iConstruction.iFLane1L.RemoveAt(xNode.iConstruction.iFLane1L.Count-1); f1LAdded = false; f1RAdded=false; }
                            }
                        }
                        //}
                        xNode.iConstruction.f1RAttempt = tempIVect;
                        xNode.iConstruction.f2LAttempt = tempIVect;

                        //Line 3 / 4:
                        //if(f2LAdded){

                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            tempIVect = (tVect + new Vector3(((LaneWidth*0.5f)+RoadSeperation)*-POS.normalized.z,0,((LaneWidth*0.5f)+RoadSeperation)*POS.normalized.x));
                            if(!xNode.iConstruction.bFLane3Done && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(lVect,tempIVect)){

                                xNode.iConstruction.iFLane3L.Add(GVC(tempIVect,tIntHeight));  f3LAdded = true;
                                xNode.iConstruction.iFLane3R.Add(GVC(lVect,tIntHeight)); f3RAdded = true;
            //								if(bIsNextInter && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.FourWay){
                                    if(f2LAdded){ xNode.iConstruction.iFLane2R.Add(GVC(tempIVect,tIntHeight)); f2RAdded = true; }
            //								}
                            }else{
                                if(f2LAdded){
                                    xNode.iConstruction.iFLane2L.RemoveAt(xNode.iConstruction.iFLane2L.Count-1); f2LAdded = false;
                                }
                            }

                        }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                            tempIVect = (tVect + new Vector3(((LaneWidth*0.5f)+RoadSeperation)*-POS.normalized.z,0,((LaneWidth*0.5f)+RoadSeperation)*POS.normalized.x));
                            if(f2LAdded && !GSDRI.Contains(ref tempIVect) && !GSDRI.ContainsLine(rVect,tempIVect)){
                                xNode.iConstruction.iFLane2R.Add(GVC(tempIVect,tIntHeight)); f2RAdded = true;
                            }else if(f2LAdded){
                                xNode.iConstruction.iFLane2L.RemoveAt(xNode.iConstruction.iFLane2L.Count-1);  f2LAdded = false;
                            }
                        }

                    //	}
                        xNode.iConstruction.f2RAttempt = tempIVect;
                        xNode.iConstruction.f3LAttempt = tempIVect;
                        xNode.iConstruction.f3RAttempt = lVect;

                        if(!bIsNextInter && !xNode.iConstruction.bFDone){
            //							xNode.iConstruction.bFDone = true;
                            xNode.iConstruction.bFLane0Done = true;
                            xNode.iConstruction.bFLane1Done = true;
                            xNode.iConstruction.bFLane2Done = true;
                            xNode.iConstruction.bFLane3Done = true;

                            POS_Next = default(Vector3);
                            tVect_Next = default(Vector3);

                            tParam1 = tSpline.TranslateInverseParamToFloat(tSpline.RoadDefKeysArray[kCount]);
                            tSpline.GetSplineValue_Both(tParam1,out tVect_Next,out POS_Next);
                            rVect_Next = (tVect_Next + new Vector3(RoadSeperation*POS_Next.normalized.z,0,RoadSeperation*-POS_Next.normalized.x));
                            lVect_Next = (tVect_Next + new Vector3(RoadSeperation*-POS_Next.normalized.z,0,RoadSeperation*POS_Next.normalized.x));

                            xNode.iConstruction.iFLane0L.Add(GVC(rVect_Next,tIntHeight));
                            xNode.iConstruction.iFLane0R.Add(GVC(tVect_Next,tIntHeight));
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                xNode.iConstruction.iFLane1L.Add(GVC(tVect_Next,tIntHeight));
                                if(tRoad.opt_Lanes == 2){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.475f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 4){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.488f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 6){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.492f)+lVect_Next,tIntHeight));
                                }

                                if(tRoad.opt_Lanes == 2){
                                    xNode.iConstruction.iFLane3L.Add(GVC(((rVect_Next-lVect_Next)*0.03f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 4){
                                    xNode.iConstruction.iFLane3L.Add(GVC(((rVect_Next-lVect_Next)*0.015f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 6){
                                    xNode.iConstruction.iFLane3L.Add(GVC(((rVect_Next-lVect_Next)*0.01f)+lVect_Next,tIntHeight));
                                }

                                xNode.iConstruction.iFLane3R.Add(GVC(lVect_Next,tIntHeight));
            //								xNode.iConstruction.iFLane2L.Add(GVC(tVect_Next,tIntHeight));
            //								xNode.iConstruction.iFLane2R.Add(GVC(lVect_Next,tIntHeight));

                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                xNode.iConstruction.iFLane1L.Add(GVC(tVect_Next,tIntHeight));
                                if(tRoad.opt_Lanes == 2){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.475f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 4){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.488f)+lVect_Next,tIntHeight));
                                }else if(tRoad.opt_Lanes == 6){
                                    xNode.iConstruction.iFLane1R.Add(GVC(((rVect_Next-lVect_Next)*0.492f)+lVect_Next,tIntHeight));
                                }
                                xNode.iConstruction.iFLane2L.Add(GVC(tVect_Next,tIntHeight));
                                xNode.iConstruction.iFLane2R.Add(GVC(lVect_Next,tIntHeight));

                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                xNode.iConstruction.iFLane1L.Add(GVC(tVect_Next,tIntHeight));
                                xNode.iConstruction.iFLane1R.Add(GVC(lVect_Next,tIntHeight));
                            }
                            bShrinkRoadFNext = true;
            //							bShrinkRoadF = true;
                        }

                    }else{
                        bLRtoRR = bFirstInterNode;
                        bLLtoLR = !bFirstInterNode;
                        //B:
                        //Line 0:
                        tempIVect = lVect;
                        bool bFirst123 = false;
                        if(xNode.iConstruction.iBLane0R.Count == 0){
                            xNode.iConstruction.iBLane0L.Add(lVect_Prev);
                            xNode.iConstruction.iBLane0R.Add(tVect_Prev);
                            bShrinkRoadB = true;

                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                xNode.iConstruction.iBLane1L.Add(tVect_Prev);
                                xNode.iConstruction.iBLane1R.Add((tVect_Prev + new Vector3((LaneWidth*0.05f)*POS.normalized.z,0,(LaneWidth*0.05f)*-POS.normalized.x)));
                                xNode.iConstruction.iBLane3L.Add(((lVect_Prev-rVect_Prev)*0.03f)+rVect_Prev);
                                xNode.iConstruction.iBLane3R.Add(rVect_Prev);

                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                xNode.iConstruction.iBLane1L.Add(tVect_Prev);
                                xNode.iConstruction.iBLane1R.Add((tVect_Prev + new Vector3((LaneWidth*0.05f)*POS.normalized.z,0,(LaneWidth*0.05f)*-POS.normalized.x)));
                                xNode.iConstruction.iBLane2L.Add(xNode.iConstruction.iBLane1R[0]);
                                xNode.iConstruction.iBLane2R.Add(rVect_Prev);

                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                xNode.iConstruction.iBLane1L.Add(tVect_Prev);
                                xNode.iConstruction.iBLane1R.Add(rVect_Prev);
                            }

                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                xNode.iConstruction.ShoulderBL_Start = xNode.iConstruction.iBLane0L[0];
                                xNode.iConstruction.ShoulderBR_Start = xNode.iConstruction.iBLane3R[0];
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                xNode.iConstruction.ShoulderBL_Start = xNode.iConstruction.iBLane0L[0];
                                xNode.iConstruction.ShoulderBR_Start = xNode.iConstruction.iBLane2R[0];
                            }else{
                                xNode.iConstruction.ShoulderBL_Start = xNode.iConstruction.iBLane0L[0];
                                xNode.iConstruction.ShoulderBR_Start = xNode.iConstruction.iBLane1R[0];
                            }

                            xNode.iConstruction.ShoulderBL_StartIndex = tRoad.RCS.ShoulderL_Vectors.Count-2;
                            xNode.iConstruction.ShoulderBR_StartIndex = tRoad.RCS.ShoulderR_Vectors.Count-2;
            //							bFirst123 = true;
            //							goto InterSkip;
                        }

                        bLine = false;
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            bLine = !GSDRI.ContainsLine(tempIVect,(tVect + new Vector3((LaneWidth*0.5f)*-POS.normalized.z,0,(LaneWidth*0.5f)*POS.normalized.x)));
                        }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                            bLine = !GSDRI.ContainsLine(tempIVect,(tVect + new Vector3((LaneWidth*0.5f)*-POS.normalized.z,0,(LaneWidth*0.5f)*POS.normalized.x)));
                        }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            bLine = !GSDRI.ContainsLine(lVect,tVect);
                        }
                        if(!xNode.iConstruction.bBLane0Done && !GSDRI.Contains(ref tempIVect) && bLine){
                            xNode.iConstruction.iBLane0L.Add(GVC(tempIVect,tIntHeight)); b0LAdded = true;
                        }else if(!xNode.iConstruction.bBLane0Done_Final){
                            //Finalize lane 0:
                            InterFinalizeiBLane0(ref xNode, ref GSDRI, ref tIntHeight, bLRtoRR, bLLtoLR,bFirstInterNode);
                        }

                        //Line 1:
                        if(xNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            if(xNode.iConstruction.iBLane0L.Count == 2){
                                tempIVect = (tVect + new Vector3((LaneWidth*0.5f)*-POS.normalized.z,0,(LaneWidth*0.5f)*POS.normalized.x));
                                xNode.iConstruction.iBLane0R.Add(GVC(tempIVect,tIntHeight));  		b0RAdded = true;
                            }
                        }
                        tempIVect_Prev = tempIVect;
                        tempIVect = (tVect + new Vector3((LaneWidth*0.5f)*-POS.normalized.z,0,(LaneWidth*0.5f)*POS.normalized.x));
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ tempIVect = tVect; }
                        bLine = false;
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            bLine = !GSDRI.ContainsLine(tempIVect,(tVect + new Vector3((LaneWidth*0.5f)*POS.normalized.z,0,(LaneWidth*0.5f)*-POS.normalized.x)));
                        }if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                            bLine = !GSDRI.ContainsLine(tempIVect,rVect);
                        }else{
                            bLine = !GSDRI.ContainsLine(tempIVect,rVect);
                        }
                        tempIVect_Prev = tempIVect;
                        if(b0LAdded && !xNode.iConstruction.bBLane1Done && !GSDRI.Contains(ref tempIVect) && bLine){
                            if(b0LAdded && (xNode.iConstruction.iBLane0L.Count != 2 || GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane)){
                                xNode.iConstruction.iBLane0R.Add(GVC(tempIVect,tIntHeight));   	b0RAdded = true;
                            }
                            xNode.iConstruction.iBLane1L.Add(GVC(tempIVect,tIntHeight));		b1LAdded = true;
                        }else if(!xNode.iConstruction.bBLane1Done_Final){
                            //Finalize lane 1:
                            InterFinalizeiBLane1(ref xNode, ref GSDRI, ref tIntHeight, bLRtoRR, bLLtoLR, bFirstInterNode, ref b0LAdded, ref b1RAdded);
                        }

                        //Line 2:
                        if(xNode.iConstruction.iBLane1R.Count == 0 && xNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            xNode.iConstruction.iBLane1R.Add(GVC(tVect,tIntHeight));		b1RAdded = true;
                            xNode.iConstruction.iBLane2L.Add(GVC(tVect,tIntHeight));		b2LAdded = true;
                            b2LAdded = true;
                        }else{
                            tempIVect = (tVect + new Vector3((LaneWidth*0.5f)*POS.normalized.z,0,(LaneWidth*0.5f)*-POS.normalized.x));
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ tempIVect = rVect; }
                            if(b1LAdded){
                                bLine = !GSDRI.ContainsLine(tempIVect,tempIVect_Prev);
                            }else{
                                bLine = !GSDRI.ContainsLine(tempIVect,rVect);
                            }
                            if(!xNode.iConstruction.bBLane2Done && !GSDRI.Contains(ref tempIVect) && bLine){
                                if(b1LAdded){ xNode.iConstruction.iBLane1R.Add(GVC(tempIVect,tIntHeight)); b1RAdded = true; }
                                xNode.iConstruction.iBLane2L.Add(GVC(tempIVect,tIntHeight)); b2LAdded = true;
                            }else if(!xNode.iConstruction.bBLane2Done_Final){
                                InterFinalizeiBLane2(ref xNode, ref GSDRI, ref tIntHeight, bLRtoRR, bLLtoLR, bFirstInterNode, ref b2LAdded, ref b1LAdded, ref b0LAdded, ref b1RAdded);
                            }
                        }

                        //Line 3 / 4:
                        tempIVect = (tVect + new Vector3(((LaneWidth*0.5f)+RoadSeperation)*POS.normalized.z,0,((LaneWidth*0.5f)+RoadSeperation)*-POS.normalized.x));
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ tempIVect = rVect; }
                        if(!xNode.iConstruction.bBLane3Done && !GSDRI.ContainsLine(rVect,tempIVect) && !GSDRI.ContainsLine(rVect,lVect)){
                            xNode.iConstruction.iBLane3L.Add(GVC(tempIVect,tIntHeight)); b3LAdded = true;
                            xNode.iConstruction.iBLane3R.Add(GVC(rVect,tIntHeight)); b3RAdded = true;
                            if(!bFirst123 && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.FourWay){
                                if(b2LAdded){ xNode.iConstruction.iBLane2R.Add(GVC(tempIVect,tIntHeight));	 b2RAdded = true; }
                            }
                        }else if(!xNode.iConstruction.bBLane3Done_Final){
                            InterFinalizeiBLane3(ref xNode, ref GSDRI, ref tIntHeight, bLRtoRR, bLLtoLR, bFirstInterNode, ref b2LAdded, ref b1LAdded, ref b0LAdded, ref b1RAdded);
                        }

                    }
                }

            //			InterSkip:

                if(!bIsBridge){
                    BridgeUpComing = tRoad.GSDSpline.BridgeUpComing(i);
            //					if(TempY < 0.5f){
            //						gHeight = tHeight0;
            //					}else if(TempY < 2f){
            //						gHeight = tHeight2;
            //					}else{
            //						if(bTempYWasNegative){
            //							tY = new Vector3(0f,(TempY*0.035f),0f);
            //						}
            //						if(tY.y < tHeight1.y){
            //							tY = tHeight1;
            //						}
            //						gHeight = tY;
            //					}
                    if(BridgeUpComing < 0.2f){
                        BridgeUpComing = 0.2f;
                    }
            //					gHeight.y = gHeight.y * BridgeUpComing;

            //					if(tRoad.opt_MatchTerrain){
                        gHeight.y = 0f;
            //					}

                    lVect += gHeight;
                    rVect += gHeight;
                    ShoulderR_lVect += gHeight;
                    ShoulderL_rVect += gHeight;
                    ShoulderL_lVect += gHeight;
                    ShoulderR_rVect += gHeight;
                    tHeightAdded = gHeight.y;
                }

                if(tIntStrength >= 1f){
                    tVect.y -= tInterSubtract;
                    tLastInterHeight = tVect.y;
                    rVect.y -= tInterSubtract;
                    lVect.y -= tInterSubtract;

                    ShoulderL_rVect.y = tIntHeight;
                    ShoulderR_lVect.y = tIntHeight;
                    ShoulderR_rVect.y = tIntHeight;
                    ShoulderL_lVect.y = tIntHeight;

            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderL_rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderL_rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderL_rVect.y); }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderR_lVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderR_lVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderR_lVect.y); }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderR_rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderR_rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderR_rVect.y); }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderL_lVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderL_lVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderL_lVect.y); }
                }else if(tIntStrength > 0f){

                    rVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*rVect.y);
                    ShoulderR_lVect = rVect;
                    lVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*lVect.y);
                    ShoulderL_rVect = lVect;
                    ShoulderR_rVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*ShoulderR_rVect.y);
                    ShoulderL_lVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*ShoulderL_lVect.y);

            //					if(!Mathf.Approximately(tIntStrength,0f)){ tVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect.y); }
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*rVect.y); ShoulderR_lVect = rVect; }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref lVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ lVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*lVect.y); ShoulderL_rVect = lVect; }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderR_rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderR_rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderR_rVect.y); }
            //
            //					tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref ShoulderL_lVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
            //					if(!Mathf.Approximately(tIntStrength_temp,0f)){ ShoulderL_lVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*ShoulderL_lVect.y); }
                }

                //Ramp:
                RampR_L = ShoulderR_rVect;
                RampL_R = ShoulderL_lVect;
                if(bIsBridge){
                    RampR_R = RampR_L;
                    RampL_L = RampL_R;
                }else{
                    RampR_R = (tVect + new Vector3(RampOuterWidthR*POS.normalized.z,0,RampOuterWidthR*-POS.normalized.x)) + gHeight;
                    SetVectorHeight2(ref RampR_R,ref i, ref tSpline.HeightHistory, ref tSpline);
                    RampR_R.y -= 0.35f;

                    RampL_L = (tVect + new Vector3(RampOuterWidthL*-POS.normalized.z,0,RampOuterWidthL*POS.normalized.x)) + gHeight;
                    SetVectorHeight2(ref RampL_L,ref i, ref tSpline.HeightHistory, ref tSpline);
                    RampL_L.y -= 0.35f;
                }

                //Merge points to intersection corners if necessary:
                if(bMaxIntersection && !bIsBridge && !bIsTunnel && bInterseOn){
                    mCornerDist = tRoad.opt_RoadDefinition* 1.35f;
                    mCornerDist *= mCornerDist;

                    CornerRR = new Vector2(GSDRI.CornerRR.x, GSDRI.CornerRR.z);
                    CornerRL = new Vector2(GSDRI.CornerRL.x, GSDRI.CornerRL.z);
                    CornerLR = new Vector2(GSDRI.CornerLR.x, GSDRI.CornerLR.z);
                    CornerLL = new Vector2(GSDRI.CornerLL.x, GSDRI.CornerLL.z);
                    rVect2D = new Vector2(rVect.x,rVect.z);
                    lVect2D = new Vector2(lVect.x,lVect.z);
                    bOverrideRampR = false;
                    bOverrideRampL = false;
                    bImmuneR = false;
                    bImmuneL = false;
                    bMod1 = 1.75f;
                    bMod2 = 1.25f;
                    t2DDist = -1f;

                    //Find equatable lane vect and move it too
            //					eCount = -1;
            //					eIndex = -1;
            //					uCount = -1;
            //					uIndex = -1;

                    xHeight = new Vector3(0f,-0.1f,0f);
                    bSpecAddedL = false;
                    bSpecAddedR = false;

                    if(bFirstInterNode){
                        bSpecAddedL = (b0LAdded || f0LAdded);
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                            bSpecAddedR = (b1RAdded || f1LAdded);
                        }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                            bSpecAddedR = (b2RAdded || f2LAdded);
                        }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            bSpecAddedR = (b3RAdded || f3LAdded);
                        }
                    }

                    float tempRoadDef = Mathf.Clamp(tRoad.opt_LaneWidth, 3f, 5f);

                    if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane) {

                    } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane) {

                    } else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes) {

                    }

                    //RR:
                    if(GSDRI.EvenAngle > 90f){ mCornerDist = tempRoadDef*bMod1; } else { mCornerDist = tempRoadDef*bMod2; }
                    mCornerDist *= mCornerDist;
                    t2DDist = Vector2.SqrMagnitude(CornerRR-rVect2D);
                    if(t2DDist < mCornerDist){
                        bImmuneR = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerRR = true;

                        if(bFirstInterNode){
                            vList = null;
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                vList = xNode.iConstruction.iBLane1R;
                                if(xNode.iConstruction.bBLane1Done_Final_ThisRound){ vList = null; }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                vList = xNode.iConstruction.iBLane2R;
                                if(xNode.iConstruction.bBLane2Done_Final_ThisRound){ vList = null; }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                vList = xNode.iConstruction.iBLane3R;
                                if(xNode.iConstruction.bBLane3Done_Final_ThisRound){ vList = null; }
                            }

                            eList = new List<int>();
                            if(vList != null){
                                for(int m=0;m<vList.Count;m++){
                                    if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                        if(!(IsApproximately(vList[m].x,GSDRI.CornerRR.x,0.01f) && IsApproximately(vList[m].z,GSDRI.CornerRR.z,0.01f))){
                                            eList.Add(m);
                                        }
                                    }
                                }
                                for(int m=(eList.Count-1);m>=0;m--){
                                    vList.RemoveAt(eList[m]);
                                }
                            }
                            eList = null;
                        }else{
                            //2nd node can only come through RR as front with R
                            vList = null;
                            vList = xNode.iConstruction.iFLane0L;
                            eList = new List<int>();
                            if(vList != null){
                                for(int m=1;m<vList.Count;m++){
                                    if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                        if(!(IsApproximately(vList[m].x,GSDRI.CornerRR.x,0.01f) && IsApproximately(vList[m].z,GSDRI.CornerRR.z,0.01f))){
                                            eList.Add(m);
                                        }
                                    }
                                }
                                for(int m=(eList.Count-1);m>=0;m--){
                                    vList.RemoveAt(eList[m]);
                                }
                            }
                            eList = null;
                        }

                        ShoulderR_lVect = new Vector3(CornerRR.x,tIntHeight,CornerRR.y);
                        ShoulderR_rVect = new Vector3(GSDRI.CornerRR_Outer.x,tIntHeight,GSDRI.CornerRR_Outer.z);
                        RampR_Override = new Vector3(GSDRI.CornerRR_RampOuter.x,tIntHeight,GSDRI.CornerRR_RampOuter.z);
                        bRecordShoulderForNormals = true;
                    }else{
                        t2DDist = Vector2.SqrMagnitude(CornerRR-lVect2D);
                        if(t2DDist < mCornerDist){
                            bImmuneL = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerRR = true;

                            //2nd node can come in via left
                            if(!bFirstInterNode){
                                vList = null;
                                vList = xNode.iConstruction.iBLane0L;
                                if(xNode.iConstruction.bBLane0Done_Final_ThisRound){ vList = null; }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=0;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerRR.x) && IsApproximately(vList[m].z,GSDRI.CornerRR.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }

                            ShoulderL_rVect = new Vector3(CornerRR.x,tIntHeight,CornerRR.y);
                            ShoulderL_lVect = new Vector3(GSDRI.CornerRR_Outer.x,tIntHeight,GSDRI.CornerRR_Outer.z);
                            RampL_Override = new Vector3(GSDRI.CornerRR_RampOuter.x,tIntHeight,GSDRI.CornerRR_RampOuter.z);
                            bRecordShoulderLForNormals = true;
                        }
                    }
                    //RL:
                    if(GSDRI.OddAngle > 90f){ mCornerDist = tempRoadDef*bMod1; } else { mCornerDist = tempRoadDef*bMod2; }
                    mCornerDist *= mCornerDist;
                    t2DDist = Vector2.SqrMagnitude(CornerRL-rVect2D);
                    if(t2DDist < mCornerDist){
                        bImmuneR = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerRL = true;

                        if(bFirstInterNode){
                            vList = null;
                            vList = xNode.iConstruction.iFLane0L;
                            eList = new List<int>();
                            if(vList != null){
                                for(int m=1;m<vList.Count;m++){
                                    if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                        if(!(IsApproximately(vList[m].x,GSDRI.CornerRL.x) && IsApproximately(vList[m].z,GSDRI.CornerRL.z))){
                                            eList.Add(m);
                                        }
                                    }
                                }
                                for(int m=(eList.Count-1);m>=0;m--){
                                    vList.RemoveAt(eList[m]);
                                }
                            }
                            eList = null;
                        }else{
                            vList = null;
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                vList = xNode.iConstruction.iBLane1R;
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                vList = xNode.iConstruction.iBLane2R;
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                vList = xNode.iConstruction.iBLane3R;
                            }

                            //Hitting RL from backside with second node:
                            if(!bFirstInterNode){
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=0;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerRL.x) && IsApproximately(vList[m].z,GSDRI.CornerRL.z))){
                                                eList.Add(m);
                                                if(m == vList.Count-1){
                                                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                                        b1RAdded = false;
                                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                                        b2RAdded = false;
                                                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                                        b3RAdded = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                            }
                            eList = null;
                        }

                        ShoulderR_lVect = new Vector3(CornerRL.x,tIntHeight,CornerRL.y);
                        ShoulderR_rVect = new Vector3(GSDRI.CornerRL_Outer.x,tIntHeight,GSDRI.CornerRL_Outer.z);
                        RampR_Override = new Vector3(GSDRI.CornerRL_RampOuter.x,tIntHeight,GSDRI.CornerRL_RampOuter.z);
                        bRecordShoulderForNormals = true;
                    }else{
                        t2DDist = Vector2.SqrMagnitude(CornerRL-lVect2D);
                        if(t2DDist < mCornerDist){
                            bImmuneL = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerRL = true;

                            if(!bFirstInterNode){
                                vList = null;
                                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                    vList = xNode.iConstruction.iFLane1R;
                                    if(xNode.iConstruction.bFLane1Done_Final_ThisRound){ vList = null; }
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                    vList = xNode.iConstruction.iFLane2R;
                                    if(xNode.iConstruction.bFLane2Done_Final_ThisRound){ vList = null; }
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                    vList = xNode.iConstruction.iFLane3R;
                                    if(xNode.iConstruction.bFLane3Done_Final_ThisRound){ vList = null; }
                                }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=1;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerRL.x) && IsApproximately(vList[m].z,GSDRI.CornerRL.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }

                            ShoulderL_rVect = new Vector3(CornerRL.x,tIntHeight,CornerRL.y);
                            ShoulderL_lVect = new Vector3(GSDRI.CornerRL_Outer.x,tIntHeight,GSDRI.CornerRL_Outer.z);
                            RampL_Override = new Vector3(GSDRI.CornerRL_RampOuter.x,tIntHeight,GSDRI.CornerRL_RampOuter.z);
                            bRecordShoulderLForNormals = true;
                        }
                    }
                    //LR:
                    if(GSDRI.OddAngle > 90f){ mCornerDist = tempRoadDef*bMod1; } else { mCornerDist = tempRoadDef*bMod2; }
                    mCornerDist *= mCornerDist;
                    t2DDist = Vector2.SqrMagnitude(CornerLR-rVect2D);
                    if(t2DDist < mCornerDist){
                        bImmuneR = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerLR = true;

                        if(!bFirstInterNode){
                            vList = null;
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                vList = xNode.iConstruction.iBLane1R;
                                if(xNode.iConstruction.bBLane1Done_Final_ThisRound){ vList = null; }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                vList = xNode.iConstruction.iBLane2R;
                                if(xNode.iConstruction.bBLane2Done_Final_ThisRound){ vList = null; }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                vList = xNode.iConstruction.iBLane3R;
                                if(xNode.iConstruction.bBLane3Done_Final_ThisRound){ vList = null; }
                            }

                            eList = new List<int>();
                            if(vList != null){
                                for(int m=0;m<vList.Count;m++){
                                    if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                        if(!(IsApproximately(vList[m].x,GSDRI.CornerLR.x) && IsApproximately(vList[m].z,GSDRI.CornerLR.z))){
                                            eList.Add(m);
                                        }
                                    }
                                }
                                for(int m=(eList.Count-1);m>=0;m--){
                                    vList.RemoveAt(eList[m]);
                                }
                            }
                            eList = null;
                        }

                        ShoulderR_lVect = new Vector3(CornerLR.x,tIntHeight,CornerLR.y);
                        ShoulderR_rVect = new Vector3(GSDRI.CornerLR_Outer.x,tIntHeight,GSDRI.CornerLR_Outer.z);
                        RampR_Override = new Vector3(GSDRI.CornerLR_RampOuter.x,tIntHeight,GSDRI.CornerLR_RampOuter.z);
                        bRecordShoulderForNormals = true;
                    }else{
                        t2DDist = Vector2.SqrMagnitude(CornerLR-lVect2D);
                        if(t2DDist < mCornerDist){
                            bImmuneL = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerLR = true;

                            if(bFirstInterNode){
                                vList = null;
                                vList = xNode.iConstruction.iBLane0L;
                                if(xNode.iConstruction.bBLane0Done_Final_ThisRound){ vList = null; }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=0;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerLR.x) && IsApproximately(vList[m].z,GSDRI.CornerLR.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }else{
                                //2nd node can only come through LR as front with L
                                vList = null;
                                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                    vList = xNode.iConstruction.iFLane1R;
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                    vList = xNode.iConstruction.iFLane2R;
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                    vList = xNode.iConstruction.iFLane3R;
                                }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=1;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerLR.x) && IsApproximately(vList[m].z,GSDRI.CornerLR.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }

                            ShoulderL_rVect = new Vector3(CornerLR.x,tIntHeight,CornerLR.y);
                            ShoulderL_lVect = new Vector3(GSDRI.CornerLR_Outer.x,tIntHeight,GSDRI.CornerLR_Outer.z);
                            RampL_Override = new Vector3(GSDRI.CornerLR_RampOuter.x,tIntHeight,GSDRI.CornerLR_RampOuter.z);
                            bRecordShoulderLForNormals = true;
                        }
                    }
                    //LL:
                    if(GSDRI.EvenAngle > 90f){ mCornerDist = tempRoadDef*bMod1; } else { mCornerDist = tempRoadDef*bMod2; }
                    mCornerDist *= mCornerDist;
                    t2DDist = Vector2.SqrMagnitude(CornerLL-rVect2D);
                    if(t2DDist < mCornerDist){
                        bImmuneR = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerLL = true;

                        if(!bFirstInterNode){
                            vList = null;
                            vList = xNode.iConstruction.iFLane0L;
                            eList = new List<int>();
                            if(vList != null){
                                for(int m=1;m<vList.Count;m++){
                                    if(Vector3.SqrMagnitude(vList[m]-ShoulderR_lVect) < 0.01f){
                                        if(!(IsApproximately(vList[m].x,GSDRI.CornerLL.x) && IsApproximately(vList[m].z,GSDRI.CornerLL.z))){
                                            eList.Add(m);
                                        }
                                    }
                                }
                                for(int m=(eList.Count-1);m>=0;m--){
                                    vList.RemoveAt(eList[m]);
                                }
                            }
                            eList = null;
                        }

                        ShoulderR_lVect = new Vector3(CornerLL.x,tIntHeight,CornerLL.y);
                        ShoulderR_rVect = new Vector3(GSDRI.CornerLL_Outer.x,tIntHeight,GSDRI.CornerLL_Outer.z);
                        RampR_Override = new Vector3(GSDRI.CornerLL_RampOuter.x,tIntHeight,GSDRI.CornerLL_RampOuter.z);
                        bRecordShoulderForNormals = true;
                    }else{
                        t2DDist = Vector2.SqrMagnitude(CornerLL-lVect2D);
                        if(t2DDist < mCornerDist){
                            bImmuneL = true; bInter_CurreIsCorner = true; bInter_CurreIsCornerLL = true;

                            if(bFirstInterNode){
                                vList = null;
                                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                                    vList = xNode.iConstruction.iFLane1R;
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                    vList = xNode.iConstruction.iFLane2R;
                                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                    vList = xNode.iConstruction.iFLane3R;
                                }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=1;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerLL.x) && IsApproximately(vList[m].z,GSDRI.CornerLL.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }else{
                                vList = null;
                                vList = xNode.iConstruction.iBLane0L;
                                if(xNode.iConstruction.bBLane0Done_Final_ThisRound){ vList = null; }
                                eList = new List<int>();
                                if(vList != null){
                                    for(int m=0;m<vList.Count;m++){
                                        if(Vector3.SqrMagnitude(vList[m]-ShoulderL_rVect) < 0.01f){
                                            if(!(IsApproximately(vList[m].x,GSDRI.CornerLL.x) && IsApproximately(vList[m].z,GSDRI.CornerLL.z))){
                                                eList.Add(m);
                                            }
                                        }
                                    }
                                    for(int m=(eList.Count-1);m>=0;m--){
                                        vList.RemoveAt(eList[m]);
                                    }
                                }
                                eList = null;
                            }

                            ShoulderL_rVect = new Vector3(CornerLL.x,tIntHeight,CornerLL.y);
                            ShoulderL_lVect = new Vector3(GSDRI.CornerLL_Outer.x,tIntHeight,GSDRI.CornerLL_Outer.z);
                            RampL_Override = new Vector3(GSDRI.CornerLL_RampOuter.x,tIntHeight,GSDRI.CornerLL_RampOuter.z);
                            bRecordShoulderLForNormals = true;
                        }
                    }

                    if(bImmuneR){
                        bOverrideRampR = true;
                        if(!tRoad.RCS.ImmuneVects.Contains(ShoulderR_lVect)){ tRoad.RCS.ImmuneVects.Add(ShoulderR_lVect); }
                        if(!tRoad.RCS.ImmuneVects.Contains(ShoulderR_rVect)){ tRoad.RCS.ImmuneVects.Add(ShoulderR_rVect); }
                    }
                    if(bImmuneL){
                        bOverrideRampL = true;
                        if(!tRoad.RCS.ImmuneVects.Contains(ShoulderL_rVect)){ tRoad.RCS.ImmuneVects.Add(ShoulderL_rVect); }
                        if(!tRoad.RCS.ImmuneVects.Contains(ShoulderL_lVect)){ tRoad.RCS.ImmuneVects.Add(ShoulderL_lVect); }
                    }
                }

                if(bShrinkRoadB){

                    if (lVect_Prev != new Vector3(0f, 0f, 0f)) {
                        tRoad.RCS.RoadVectors.Add(lVect_Prev);
                        tRoad.RCS.RoadVectors.Add(lVect_Prev);
                        tRoad.RCS.RoadVectors.Add(lVect_Prev);
                        tRoad.RCS.RoadVectors.Add(lVect_Prev);
                    }
                }
                if(bShrinkRoadF){
                    if (lVect != new Vector3(0f, 0f, 0f)) {
                        tRoad.RCS.RoadVectors.Add(lVect);
                        tRoad.RCS.RoadVectors.Add(lVect);
                        tRoad.RCS.RoadVectors.Add(lVect);
                        tRoad.RCS.RoadVectors.Add(lVect);
                    }
                }

                tRoad.RCS.RoadVectors.Add(lVect);
                tRoad.RCS.RoadVectors.Add(lVect);
                tRoad.RCS.RoadVectors.Add(rVect);
                tRoad.RCS.RoadVectors.Add(rVect);

                //Add bounds for later removal:
                if(!bIsBridge && !bIsTunnel && bMaxIntersection && bWasPrevMaxInter && bInterseOn){
                    bool bGoAhead = true;
                    if(xNode.bIsEndPoint){
                        if(xNode.idOnSpline == 1){
                            if(i < xNode.tTime){
                                bGoAhead = false;
                            }
                        }else{
                            if(i > xNode.tTime){
                                bGoAhead = false;
                            }
                        }
                    }

                    //Get this and prev lvect rvect rects:
                    if((Vector3.SqrMagnitude(xNode.pos-tVect) < CullDistanceSQ) && bGoAhead){
                            GSD.Roads.GSDRoadUtil.Construction2DRect vRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(
                                new Vector2(lVect.x,lVect.z),
                                new Vector2(rVect.x,rVect.z),
                                new Vector2(lVect_Prev.x,lVect_Prev.z),
                                new Vector2(rVect_Prev.x,rVect_Prev.z),
                                tLastInterHeight
                                );

                        tRoad.RCS.tIntersectionBounds.Add(vRect);
            //						GameObject tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //						tObj.transform.position = lVect;
            //						tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //						tObj.transform.name = "temp22";
            //
            //						tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //						tObj.transform.position = rVect;
            //						tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //						tObj.transform.name = "temp22";
                    }
                }

                //Ramp construction:
                RampR_L = ShoulderR_rVect;
                RampL_R = ShoulderL_lVect;
                if(bIsBridge){
                    RampR_R = RampR_L;
                    RampL_L = RampL_R;
                }else{
                    RampR_R = (tVect + new Vector3(RampOuterWidthR*POS.normalized.z,0,RampOuterWidthR*-POS.normalized.x)) + gHeight;;
                    if(bOverrideRampR){ RampR_R = RampR_Override; }	//Overrides will come from intersection.
                    SetVectorHeight2(ref RampR_R,ref i, ref tSpline.HeightHistory, ref tSpline);
                    RampR_R.y -= 0.35f;

                    RampL_L = (tVect + new Vector3(RampOuterWidthL*-POS.normalized.z,0,RampOuterWidthL*POS.normalized.x)) + gHeight;;
                    if(bOverrideRampL){ RampL_L = RampL_Override; }	//Overrides will come from intersection.
                    SetVectorHeight2(ref RampL_L,ref i, ref tSpline.HeightHistory, ref tSpline);
                    RampL_L.y -= 0.35f;
                    bOverrideRampR = false;
                    bOverrideRampL = false;
                }

                //If necessary during intersection construction, sometimes an addition will be created inbetween intersection corner points.
                //This addition will create a dip between corner points to 100% ensure there is no shoulder visible on the roads between corner points.
                bTriggerInterAddition = false;
                if(bMaxIntersection && bInterseOn){
                    if(bFirstInterNode){
                        if((bInter_PrevWasCornerLR && bInter_CurreIsCornerLL) || (bInter_PrevWasCornerRR && bInter_CurreIsCornerRL)){
                            bTriggerInterAddition = true;
                        }
                    }else{
                        if(!GSDRI.bFlipped){
                            if((bInter_PrevWasCornerLL && bInter_CurreIsCornerRL) || (bInter_PrevWasCornerLR && bInter_CurreIsCornerRR) || (bInter_PrevWasCornerRR && bInter_CurreIsCornerLR)){
                                bTriggerInterAddition = true;
                            }
                        }else{
                            if((bInter_PrevWasCornerRR && bInter_CurreIsCornerLR) || (bInter_PrevWasCornerLR && bInter_CurreIsCornerRR) || (bInter_PrevWasCornerRL && bInter_CurreIsCornerLL)){
                                bTriggerInterAddition = true;
                            }
                        }
                    }

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        bTriggerInterAddition = false;
                    }

                    //For 3-way intersections:
                    bSpecialThreeWayIgnoreR = false;
                    bSpecialThreeWayIgnoreL = false;
                    if(GSDRI.IgnoreSide > -1){
                        if(GSDRI.IgnoreSide == 0){
                            //RR to RL:
                            if(bFirstInterNode && (bInter_PrevWasCornerRR && bInter_CurreIsCornerRL)){
                                bTriggerInterAddition = false;
                            }
                        }else if(GSDRI.IgnoreSide == 1){
                            //RL to LL:
                            if(!bFirstInterNode && ((bInter_PrevWasCornerRL && bInter_CurreIsCornerLL) || (bInter_PrevWasCornerLL && bInter_CurreIsCornerRL))){
                                //bTriggerInterAddition = false;
                                if(GSDRI.bFlipped){
                                    bSpecialThreeWayIgnoreR = true;
                                }else{
                                    bSpecialThreeWayIgnoreL = true;
                                }
                            }
                        }else if(GSDRI.IgnoreSide == 2){
                            //LL to LR:
                            if(bFirstInterNode && (bInter_PrevWasCornerLR && bInter_CurreIsCornerLL)){
                                bTriggerInterAddition = false;
                            }
                        }else if(GSDRI.IgnoreSide == 3){
                            //LR to RR:
                            if(!bFirstInterNode && ((bInter_PrevWasCornerRR && bInter_CurreIsCornerLR) || (bInter_PrevWasCornerLR && bInter_CurreIsCornerRR))){
                                //bTriggerInterAddition = false;
                                if(GSDRI.bFlipped){
                                    bSpecialThreeWayIgnoreL = true;
                                }else{
                                    bSpecialThreeWayIgnoreR = true;
                                }
                            }
                        }
                    }

                    if(bTriggerInterAddition){
                        iTemp_HeightVect = new Vector3(0f,0f,0f);
                        rVect_iTemp = (((rVect_Prev-rVect)*0.5f)+rVect) + iTemp_HeightVect;
                        lVect_iTemp = (((lVect_Prev-lVect)*0.5f)+lVect) + iTemp_HeightVect;
                        ShoulderR_R_iTemp = (((ShoulderR_PrevRVect-ShoulderR_rVect)*0.5f)+ShoulderR_rVect) + iTemp_HeightVect;
                        ShoulderL_L_iTemp = (((ShoulderL_PrevLVect-ShoulderL_lVect)*0.5f)+ShoulderL_lVect) + iTemp_HeightVect;
                        RampR_R_iTemp = (((RampR_PrevR-RampR_R)*0.5f)+RampR_R) + iTemp_HeightVect;
                        RampR_L_iTemp = (((RampR_PrevL-RampR_L)*0.5f)+RampR_L) + iTemp_HeightVect;
                        RampL_R_iTemp = (((RampL_PrevR-RampL_R)*0.5f)+RampL_R) + iTemp_HeightVect;
                        RampL_L_iTemp = (((RampL_PrevL-RampL_L)*0.5f)+RampL_L) + iTemp_HeightVect;

            //						ShoulderL_L_iTemp = lVect_iTemp;
            //						RampL_R_iTemp = lVect_iTemp;
            //						RampL_L_iTemp = lVect_iTemp;
            //
            //						ShoulderR_R_iTemp = rVect_iTemp;
            //						RampR_R_iTemp = rVect_iTemp;
            //						RampR_L_iTemp = rVect_iTemp;
                    }

                    if(bTriggerInterAddition && !(GSDRI.bFlipped && !bFirstInterNode)){
                        if(bFirstInterNode){
                            if((bInter_PrevWasCornerRR && bInter_CurreIsCornerRL && !bSpecialThreeWayIgnoreR)){
                                //Right shoulder:
                                tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                                //Ramps:
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                            }
                            if((bInter_PrevWasCornerLR && bInter_CurreIsCornerLL && !bSpecialThreeWayIgnoreL)){
                                //Left shoulder:
                                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                                //Ramp:
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                            }
                        }else{
                            if((bInter_PrevWasCornerLR && bInter_CurreIsCornerRR && !bSpecialThreeWayIgnoreR)){
                                //Right shoulder:
                                tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                                //Ramps:
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                            }
                            if((bInter_PrevWasCornerLL && bInter_CurreIsCornerRL && !bSpecialThreeWayIgnoreL)){
                                //Left shoulder:
                                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                                //Ramp:
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                                tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                            }
                        }
                    }else if(bTriggerInterAddition && (GSDRI.bFlipped && !bFirstInterNode)){
                        if((bInter_PrevWasCornerRR && bInter_CurreIsCornerLR && !bSpecialThreeWayIgnoreL)){
                            //Left shoulder:
                            tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_L_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(lVect_iTemp);
                            //Ramp:
                            tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(RampL_L_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                            tRoad.RCS.ShoulderL_Vectors.Add(RampL_R_iTemp);
                        }
                        if((bInter_PrevWasCornerRL && bInter_CurreIsCornerLL && !bSpecialThreeWayIgnoreR)){
                            //Right shoulder:
                            tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(rVect_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_R_iTemp);
                            //Ramps:
                            tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(RampR_L_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                            tRoad.RCS.ShoulderR_Vectors.Add(RampR_R_iTemp);
                        }
                    }
                }

                //Right shoulder:
                if(!bShoulderSkipR){
                    if(bRecordShoulderForNormals){
                        tRoad.RCS.normals_ShoulderR_averageStartIndexes.Add(tRoad.RCS.ShoulderR_Vectors.Count);
                    }

                    tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_lVect);
                    tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_lVect);
                    tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                    tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                    tRoad.RCS.ShoulderR_Vectors.Add(RampR_L);
                    tRoad.RCS.ShoulderR_Vectors.Add(RampR_L);
                    tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);
                    tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);

                    //Double up to prevent normal errors from intersection subtraction:
                    if(bImmuneR && bRecordShoulderForNormals){
                        tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_lVect);
                        tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_lVect);
                        tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                        tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                        tRoad.RCS.ShoulderR_Vectors.Add(RampR_L);
                        tRoad.RCS.ShoulderR_Vectors.Add(RampR_L);
                        tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);
                        tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);
                    }
                }

                //Left shoulder:
                if(!bShoulderSkipL){
                    if(bRecordShoulderLForNormals){
                        tRoad.RCS.normals_ShoulderL_averageStartIndexes.Add(tRoad.RCS.ShoulderL_Vectors.Count);
                    }
                    tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                    tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                    tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_rVect);
                    tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_rVect);
                    tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                    tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                    tRoad.RCS.ShoulderL_Vectors.Add(RampL_R);
                    tRoad.RCS.ShoulderL_Vectors.Add(RampL_R);

                    //Double up to prevent normal errors from intersection subtraction:
                    if(bImmuneL && bRecordShoulderForNormals){
                        tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                        tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                        tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_rVect);
                        tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_rVect);
                        tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                        tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                        tRoad.RCS.ShoulderL_Vectors.Add(RampL_R);
                        tRoad.RCS.ShoulderL_Vectors.Add(RampL_R);
                    }
                }

                //Previous storage:
                tVect_Prev = tVect;
                rVect_Prev = rVect;
                lVect_Prev = lVect;
                ShoulderR_PrevLVect = ShoulderR_lVect;
                ShoulderL_PrevRVect = ShoulderL_rVect;
            //				ShoulderR_PrevRVect3 = ShoulderR_PrevRVect2;
            //				ShoulderL_PrevLVect3 = ShoulderL_PrevLVect2;
            //				ShoulderR_PrevRVect2 = ShoulderR_PrevRVect;
            //				ShoulderL_PrevLVect2 = ShoulderL_PrevLVect;
                ShoulderR_PrevRVect = ShoulderR_rVect;
                ShoulderL_PrevLVect = ShoulderL_lVect;
                RampR_PrevR = RampR_R;
                RampR_PrevL = RampR_L;
                RampL_PrevR = RampL_R;
                RampL_PrevL = RampL_L;

                //Store more prev variables:
                bWasPrevMaxInter = bMaxIntersection;
                bInter_PrevWasCorner = bInter_CurreIsCorner;
                bInter_PrevWasCornerRR = bInter_CurreIsCornerRR;
                bInter_PrevWasCornerRL = bInter_CurreIsCornerRL;
                bInter_PrevWasCornerLL = bInter_CurreIsCornerLL;
                bInter_PrevWasCornerLR = bInter_CurreIsCornerLR;

            //				i+=Step;//Master step incrementer.
            }
            if(tRoad.bProfiling){ Profiler.EndSample(); }

            if(tRoad.bProfiling){ Profiler.BeginSample("RoadJob_Prelim_FinalizeInter"); }
            //Finalize intersection vectors:
            if(bInterseOn){
                RoadJob_Prelim_FinalizeInter(ref tRoad);
            }
            if(tRoad.bProfiling){ Profiler.EndSample(); }

            if(tRoad.bProfiling){ Profiler.BeginSample("RoadJob_Prelim_RoadConnections"); }
            //Creates road connections if necessary:
            //			float ExtraHeight = 0f;
            //			float RampPercent = 0.2f;
            if(tSpline.bSpecialEndNode_IsStart_Delay){
                Vector3[] RoadConn_verts = new Vector3[4];

                RampR_R = tRoad.RCS.ShoulderR_Vectors[7];
                ShoulderR_rVect = tRoad.RCS.ShoulderR_Vectors[3];
                rVect = tRoad.RCS.ShoulderR_Vectors[0];

                tRoad.RCS.ShoulderR_Vectors.Insert(0,RampR_R);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,RampR_R);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,rVect);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,rVect);

                RampL_L = tRoad.RCS.ShoulderL_Vectors[4];
                ShoulderL_lVect = tRoad.RCS.ShoulderL_Vectors[0];
                lVect = tRoad.RCS.ShoulderL_Vectors[3];

                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,lVect);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,lVect);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect);

                RoadConn_verts[0] = lVect;
                RoadConn_verts[1] = rVect;
                tSpline.GetSplineValue_Both(RoadConnection_StartMin1,out tVect,out POS);
                RoadSeperation = tSpline.SpecialEndNodeDelay_Start_Result / 2f;
                rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                ShoulderSeperation = RoadSeperation + ShoulderWidth;
                OuterShoulderWidthR = ShoulderSeperation;
                OuterShoulderWidthL = ShoulderSeperation;
                RampOuterWidthR = (OuterShoulderWidthR / 4f) + OuterShoulderWidthR;
                RampOuterWidthL = (OuterShoulderWidthL / 4f) + OuterShoulderWidthL;
                ShoulderR_rVect = (tVect + new Vector3(ShoulderSeperation*POS.normalized.z,0,ShoulderSeperation*-POS.normalized.x));
                ShoulderL_lVect = (tVect + new Vector3(ShoulderSeperation*-POS.normalized.z,0,ShoulderSeperation*POS.normalized.x));
                RampR_R = (tVect + new Vector3(RampOuterWidthR*POS.normalized.z,0,RampOuterWidthR*-POS.normalized.x));
                SetVectorHeight2(ref RampR_R,ref i, ref tSpline.HeightHistory, ref tSpline);
                RampR_R.y -= 0.45f;
                RampL_L = (tVect + new Vector3(RampOuterWidthL*-POS.normalized.z,0,RampOuterWidthL*POS.normalized.x));
                SetVectorHeight2(ref RampL_L,ref i, ref tSpline.HeightHistory, ref tSpline);
                RampL_L.y -= 0.45f;

                tRoad.RCS.ShoulderR_Vectors.Insert(0,RampR_R + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,RampR_R + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,ShoulderR_rVect + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,rVect + tHeight0);
                tRoad.RCS.ShoulderR_Vectors.Insert(0,rVect + tHeight0);

                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,RampL_L + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,RampL_L + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,lVect + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,lVect + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect + tHeight0);
                tRoad.RCS.ShoulderL_Vectors.Insert(0,ShoulderL_lVect + tHeight0);

                RoadConn_verts[2] = lVect + tHeight0;
                RoadConn_verts[3] = rVect + tHeight0;
                //Tris:
                int[] RoadConn_tris = new int[6];
                RoadConn_tris[0] = 2;
                RoadConn_tris[1] = 0;
                RoadConn_tris[2] = 3;
                RoadConn_tris[3] = 0;
                RoadConn_tris[4] = 1;
                RoadConn_tris[5] = 3;

                Vector3[] RoadConn_normals = new Vector3[4];
                RoadConn_normals[0] = -Vector3.forward;
                RoadConn_normals[1] = -Vector3.forward;
                RoadConn_normals[2] = -Vector3.forward;
                RoadConn_normals[3] = -Vector3.forward;
                Vector2[] RoadConn_uv = new Vector2[4];
                float tMod1 = -1;
                float tMod2 = -1;

                if(tRoad.opt_Lanes == 2){
                    tMod1 = 0.5f - (LaneWidth / tSpline.SpecialEndNodeDelay_Start_Result);
                    tMod2 = 0.5f + (LaneWidth / tSpline.SpecialEndNodeDelay_Start_Result);
                }else if(tRoad.opt_Lanes == 4){
                    tMod1 = 0.5f - ((LaneWidth*2f) / tSpline.SpecialEndNodeDelay_Start_Result);
                    tMod2 = 0.5f + ((LaneWidth*2f) / tSpline.SpecialEndNodeDelay_Start_Result);
                }
                RoadConn_uv[0] = new Vector2(tMod1,0f);
                RoadConn_uv[1] = new Vector2(tMod2,0f);
                RoadConn_uv[2] = new Vector2(0f,1f);
                RoadConn_uv[3] = new Vector2(1f,1f);

                tRoad.RCS.RoadConnections_verts.Add(RoadConn_verts);
                tRoad.RCS.RoadConnections_tris.Add(RoadConn_tris);
                tRoad.RCS.RoadConnections_normals.Add(RoadConn_normals);
                tRoad.RCS.RoadConnections_uv.Add(RoadConn_uv);
            }else if(tSpline.bSpecialEndNode_IsEnd_Delay){
                Vector3[] RoadConn_verts = new Vector3[4];
                int rrCount = tRoad.RCS.ShoulderR_Vectors.Count;
                RampR_R = tRoad.RCS.ShoulderR_Vectors[rrCount-1];
                ShoulderR_rVect = tRoad.RCS.ShoulderR_Vectors[rrCount-3];
                rVect = tRoad.RCS.ShoulderR_Vectors[rrCount-7];

                //Right shoulder:
                tRoad.RCS.ShoulderR_Vectors.Add(rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);
                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);

                rrCount = tRoad.RCS.ShoulderL_Vectors.Count;
                RampL_L = tRoad.RCS.ShoulderL_Vectors[rrCount-3];
                ShoulderL_lVect = tRoad.RCS.ShoulderL_Vectors[rrCount-1];
                lVect = tRoad.RCS.ShoulderL_Vectors[rrCount-5];

                //Left shoulder:
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);

                RoadConn_verts[0] = lVect;
                RoadConn_verts[1] = rVect;
                tSpline.GetSplineValue_Both(RoadConnection_FinalMax1,out tVect,out POS);
                RoadSeperation = tSpline.SpecialEndNodeDelay_End_Result / 2f;
                rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                ShoulderSeperation = RoadSeperation + ShoulderWidth;
                OuterShoulderWidthR = ShoulderSeperation;
                OuterShoulderWidthL = ShoulderSeperation;
                RampOuterWidthR = (OuterShoulderWidthR / 4f) + OuterShoulderWidthR;
                RampOuterWidthL = (OuterShoulderWidthL / 4f) + OuterShoulderWidthL;
                ShoulderR_rVect = (tVect + new Vector3(ShoulderSeperation*POS.normalized.z,0,ShoulderSeperation*-POS.normalized.x));
                ShoulderL_lVect = (tVect + new Vector3(ShoulderSeperation*-POS.normalized.z,0,ShoulderSeperation*POS.normalized.x));
                RampR_R = (tVect + new Vector3(RampOuterWidthR*POS.normalized.z,0,RampOuterWidthR*-POS.normalized.x));
                SetVectorHeight2(ref RampR_R,ref i, ref tSpline.HeightHistory, ref tSpline);
                RampR_R.y -= 0.35f;
                RampL_L = (tVect + new Vector3(RampOuterWidthL*-POS.normalized.z,0,RampOuterWidthL*POS.normalized.x));
                SetVectorHeight2(ref RampL_L,ref i, ref tSpline.HeightHistory, ref tSpline);
                RampL_L.y -= 0.35f;

                //Right shoulder:
                tRoad.RCS.ShoulderR_Vectors.Add(rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(ShoulderR_rVect);
                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);
                tRoad.RCS.ShoulderR_Vectors.Add(RampR_R);

                //Left shoulder:
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Add(RampL_L);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);
                tRoad.RCS.ShoulderL_Vectors.Add(ShoulderL_lVect);

                RoadConn_verts[2] = lVect;
                RoadConn_verts[3] = rVect;
                //Tris:
                int[] RoadConn_tris = new int[6];
                RoadConn_tris[0] = 0;
                RoadConn_tris[1] = 2;
                RoadConn_tris[2] = 1;
                RoadConn_tris[3] = 2;
                RoadConn_tris[4] = 3;
                RoadConn_tris[5] = 1;

                Vector3[] RoadConn_normals = new Vector3[4];
                RoadConn_normals[0] = -Vector3.forward;
                RoadConn_normals[1] = -Vector3.forward;
                RoadConn_normals[2] = -Vector3.forward;
                RoadConn_normals[3] = -Vector3.forward;
                Vector2[] RoadConn_uv = new Vector2[4];
                float tMod = (RoadWidth / tSpline.SpecialEndNodeDelay_End_Result)/2f;
                RoadConn_uv[0] = new Vector2(tMod,0f);
                RoadConn_uv[1] = new Vector2(tMod*3f,0f);
                RoadConn_uv[2] = new Vector2(0f,1f);
                RoadConn_uv[3] = new Vector2(1f,1f);
                tRoad.RCS.RoadConnections_verts.Add(RoadConn_verts);
                tRoad.RCS.RoadConnections_tris.Add(RoadConn_tris);
                tRoad.RCS.RoadConnections_normals.Add(RoadConn_normals);
                tRoad.RCS.RoadConnections_uv.Add(RoadConn_uv);
            }
            if(tRoad.bProfiling){ Profiler.EndSample(); }
        }
Пример #38
0
 private static void ConstructRoad_DoResetTerrainHistory(ref GSDRoad tRoad)
 {
     if (tRoad.TerrainHistory != null)
     {
         tRoad.TerrainHistory.Clear();
         tRoad.TerrainHistory = null;
     }
 }
        private static void RoadJob_Prelim_Inter(ref GSDRoad tRoad)
        {
            GSDSplineC tSpline = tRoad.GSDSpline;
            float RoadWidth = tRoad.RoadWidth();
            float ShoulderWidth = tRoad.opt_ShoulderWidth;
            float RoadSeperation = RoadWidth / 2f;
            float RoadSeperation_NoTurn = RoadWidth / 2f;
            float ShoulderSeperation = RoadSeperation + ShoulderWidth;	if(ShoulderSeperation < 0f){ }
            float LaneWidth = tRoad.opt_LaneWidth;
            float RoadSep1Lane = (RoadSeperation + (LaneWidth*0.5f));
            float RoadSep2Lane = (RoadSeperation + (LaneWidth*1.5f));
            Vector3 POS = default(Vector3);
            bool bIsPastInter = false;
            bool bOldMethod = false;
            //bool bCancel = false; if (bTempCancel) { }
            bool bTempCancel = false; if (bTempCancel) { }

            //If left collides with left, etc

            //This will speed up later calculations for intersection 4 corner construction:
            int mCount = tSpline.GetNodeCount();
            float PreInter_RoadWidthMod = 4.5f;
            if(!bOldMethod){
                PreInter_RoadWidthMod = 5.5f;
            }
            float preInterDistance = (tSpline.RoadWidth*PreInter_RoadWidthMod) / tSpline.distance;
            GSDSplineN iNode = null;
            for(int j=0;j<mCount;j++){
                bTempCancel = false;
                if(tSpline.mNodes[j].bIsIntersection){
                    iNode = tSpline.mNodes[j];
                    //First node set min / max float:
                    if(iNode.iConstruction == null){ iNode.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); }
                    if(!iNode.iConstruction.tempconstruction_HasProcessed_Inter1){
                        preInterDistance = (iNode.GSDSpline.RoadWidth*PreInter_RoadWidthMod) / iNode.GSDSpline.distance;
                        iNode.iConstruction.tempconstruction_InterStart = iNode.tTime - preInterDistance;
                     	iNode.iConstruction.tempconstruction_InterEnd = iNode.tTime + preInterDistance;
                        if(iNode.iConstruction.tempconstruction_InterStart > 1f){ iNode.iConstruction.tempconstruction_InterStart = 1f; }
                        if(iNode.iConstruction.tempconstruction_InterStart < 0f){ iNode.iConstruction.tempconstruction_InterStart = 0f; }
                        if(iNode.iConstruction.tempconstruction_InterEnd > 1f){ iNode.iConstruction.tempconstruction_InterEnd = 1f; }
                        if(iNode.iConstruction.tempconstruction_InterEnd < 0f){ iNode.iConstruction.tempconstruction_InterEnd = 0f; }
                        iNode.iConstruction.tempconstruction_HasProcessed_Inter1 = true;
                    }

                    if(string.Compare(iNode.UID,iNode.GSDRI.Node1.UID) == 0){
                        iNode = iNode.GSDRI.Node2;
                    }else{
                        iNode = iNode.GSDRI.Node1;
                    }

                    //Grab other intersection node and set min / max float
                    try{
                        if(!iNode.iConstruction.tempconstruction_HasProcessed_Inter1){
                            preInterDistance = (iNode.GSDSpline.RoadWidth*PreInter_RoadWidthMod) / iNode.GSDSpline.distance;
                            iNode.iConstruction.tempconstruction_InterStart = iNode.tTime - preInterDistance;
                         	iNode.iConstruction.tempconstruction_InterEnd = iNode.tTime + preInterDistance;
                            if(iNode.iConstruction.tempconstruction_InterStart > 1f){ iNode.iConstruction.tempconstruction_InterStart = 1f; }
                            if(iNode.iConstruction.tempconstruction_InterStart < 0f){ iNode.iConstruction.tempconstruction_InterStart = 0f; }
                            if(iNode.iConstruction.tempconstruction_InterEnd > 1f){ iNode.iConstruction.tempconstruction_InterEnd = 1f; }
                            if(iNode.iConstruction.tempconstruction_InterEnd < 0f){ iNode.iConstruction.tempconstruction_InterEnd = 0f; }
                            iNode.iConstruction.tempconstruction_HasProcessed_Inter1 = true;
                        }
                    }catch{
                        //Do nothing
                    }
                }
            }

            //Now get the four points per intersection:
            GSDSplineN oNode1 = null;
            GSDSplineN oNode2 = null;
            float PreInterPrecision1 = -1f;
            float PreInterPrecision2 = -1f;
            Vector3 PreInterVect = default(Vector3);
            Vector3 PreInterVectR = default(Vector3);
            Vector3 PreInterVectR_RightTurn = default(Vector3);
            Vector3 PreInterVectL = default(Vector3);
            Vector3 PreInterVectL_RightTurn = default(Vector3);
            GSDRoadIntersection GSDRI = null;

            for(int j=0;j<mCount;j++){
                oNode1 = tSpline.mNodes[j];
                if(oNode1.bIsIntersection){
                    oNode1 = oNode1.GSDRI.Node1;
                    oNode2 = oNode1.GSDRI.Node2;
                    if(bOldMethod){
                        PreInterPrecision1 = 0.1f / oNode1.GSDSpline.distance;
                        PreInterPrecision2 = 0.1f / oNode2.GSDSpline.distance;
                    }else{
                        PreInterPrecision1 = 4f / oNode1.GSDSpline.distance;
                        PreInterPrecision2 = 4f / oNode2.GSDSpline.distance;
                    }
                    GSDRI = oNode1.GSDRI;
                    try{
                        if(oNode1.iConstruction.tempconstruction_HasProcessed_Inter2 && oNode2.iConstruction.tempconstruction_HasProcessed_Inter2){
                            continue;
                        }
                    }catch{
                        continue;
                    }
                    GSDRI = oNode1.GSDRI;
                    GSDRI.CornerRR1 = false;
                    GSDRI.CornerRR2 = false;
                    GSDRI.CornerRL1 = false;
                    GSDRI.CornerRL2 = false;
                    GSDRI.CornerLR1 = false;
                    GSDRI.CornerLR2 = false;
                    GSDRI.CornerLL1 = false;
                    GSDRI.CornerLL2 = false;

                    if(!oNode1.iConstruction.tempconstruction_HasProcessed_Inter2){
                        oNode1.iConstruction.tempconstruction_R = new List<Vector2>();
                        oNode1.iConstruction.tempconstruction_L = new List<Vector2>();
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            oNode1.iConstruction.tempconstruction_R_RightTurn = new List<Vector2>();
                            oNode1.iConstruction.tempconstruction_L_RightTurn = new List<Vector2>();
                        }

                        for(float i=oNode1.iConstruction.tempconstruction_InterStart;i<oNode1.iConstruction.tempconstruction_InterEnd;i+=PreInterPrecision1){
                            oNode1.GSDSpline.GetSplineValue_Both(i,out PreInterVect,out POS);

                            bIsPastInter = oNode1.GSDSpline.IntersectionIsPast(ref i,ref oNode1);
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                if(bIsPastInter){
                                    PreInterVectR = (PreInterVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                                    PreInterVectL = (PreInterVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));
                                }else{
                                    PreInterVectR = (PreInterVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                                    PreInterVectL = (PreInterVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                                }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                PreInterVectR = (PreInterVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                                PreInterVectL = (PreInterVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                            }else{
                                PreInterVectR = (PreInterVect + new Vector3(RoadSeperation_NoTurn*POS.normalized.z,0,RoadSeperation_NoTurn*-POS.normalized.x));
                                PreInterVectL = (PreInterVect + new Vector3(RoadSeperation_NoTurn*-POS.normalized.z,0,RoadSeperation_NoTurn*POS.normalized.x));
                            }

                            oNode1.iConstruction.tempconstruction_R.Add(new Vector2(PreInterVectR.x,PreInterVectR.z));
                            oNode1.iConstruction.tempconstruction_L.Add(new Vector2(PreInterVectL.x,PreInterVectL.z));

                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                PreInterVectR_RightTurn = (PreInterVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                                oNode1.iConstruction.tempconstruction_R_RightTurn.Add(ConvertVect3_To_Vect2(PreInterVectR_RightTurn));

                                PreInterVectL_RightTurn = (PreInterVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));
                                oNode1.iConstruction.tempconstruction_L_RightTurn.Add(ConvertVect3_To_Vect2(PreInterVectL_RightTurn));
                            }
                        }
                    }

                    //Process second node:
                    if(oNode2.iConstruction == null){ oNode2.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); }
                    if(!oNode2.iConstruction.tempconstruction_HasProcessed_Inter2){
                        oNode2.iConstruction.tempconstruction_R = new List<Vector2>();
                        oNode2.iConstruction.tempconstruction_L = new List<Vector2>();
                        if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                            oNode2.iConstruction.tempconstruction_R_RightTurn = new List<Vector2>();
                            oNode2.iConstruction.tempconstruction_L_RightTurn = new List<Vector2>();
                        }

                        for(float i=oNode2.iConstruction.tempconstruction_InterStart;i<oNode2.iConstruction.tempconstruction_InterEnd;i+=PreInterPrecision2){
                            oNode2.GSDSpline.GetSplineValue_Both(i,out PreInterVect,out POS);

                            bIsPastInter = oNode2.GSDSpline.IntersectionIsPast(ref i,ref oNode2);
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                if(bIsPastInter){
                                    PreInterVectR = (PreInterVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                                    PreInterVectL = (PreInterVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));
                                }else{
                                    PreInterVectR = (PreInterVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                                    PreInterVectL = (PreInterVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                                }
                            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                                PreInterVectR = (PreInterVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                                PreInterVectL = (PreInterVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                            }else{
                                PreInterVectR = (PreInterVect + new Vector3(RoadSeperation_NoTurn*POS.normalized.z,0,RoadSeperation_NoTurn*-POS.normalized.x));
                                PreInterVectL = (PreInterVect + new Vector3(RoadSeperation_NoTurn*-POS.normalized.z,0,RoadSeperation_NoTurn*POS.normalized.x));
                            }

                            oNode2.iConstruction.tempconstruction_R.Add(new Vector2(PreInterVectR.x,PreInterVectR.z));
                            oNode2.iConstruction.tempconstruction_L.Add(new Vector2(PreInterVectL.x,PreInterVectL.z));
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                PreInterVectR_RightTurn = (PreInterVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                                oNode2.iConstruction.tempconstruction_R_RightTurn.Add(ConvertVect3_To_Vect2(PreInterVectR_RightTurn));

                                PreInterVectL_RightTurn = (PreInterVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));
                                oNode2.iConstruction.tempconstruction_L_RightTurn.Add(ConvertVect3_To_Vect2(PreInterVectL_RightTurn));
                            }
                        }
                    }

                    bool bFlipped = false;
                    bool bFlippedSet = false;
                    int hCount1 = oNode1.iConstruction.tempconstruction_R.Count;
                    int hCount2 = oNode2.iConstruction.tempconstruction_R.Count;
                    int N1RCount = oNode1.iConstruction.tempconstruction_R.Count;
                    int N1LCount = oNode1.iConstruction.tempconstruction_L.Count;
                    int N2RCount = oNode2.iConstruction.tempconstruction_R.Count;
                    int N2LCount = oNode2.iConstruction.tempconstruction_L.Count;

                    int[] tCounts = new int[4];
                    tCounts[0] = N1RCount;
                    tCounts[1] = N1LCount;
                    tCounts[2] = N2RCount;
                    tCounts[3] = N2LCount;

                    //RR:
                    int MaxCount = -1;
                    MaxCount = Mathf.Max(N2RCount,N2LCount);
                    for(int h=0;h<hCount1;h++){
                        for(int k=0;k<MaxCount;k++){
                            if(k < N2RCount){
                                if(Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_R[k]) < tRoad.opt_RoadDefinition){
                                    bFlipped = false;
                                    bFlippedSet = true;
                                    break;
                                }
                            }
                            if(k < N2LCount){
                                if(Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_L[k]) < tRoad.opt_RoadDefinition){
                                    bFlipped = true;
                                    bFlippedSet = true;
                                    break;
                                }
                            }
                        }
                        if(bFlippedSet){ break; }
                    }
                    oNode1.GSDRI.bFlipped = bFlipped;

                    //Three-way intersections lane specifics:
                    GSDRI.bNode2B_LeftTurnLane = true;
                    GSDRI.bNode2B_RightTurnLane = true;
                    GSDRI.bNode2F_LeftTurnLane = true;
                    GSDRI.bNode2F_RightTurnLane = true;

                    //Three-way intersections:
                    GSDRI.IgnoreSide = -1;
                    GSDRI.IgnoreCorner = -1;
                    GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.FourWay;
                    if(GSDRI.bFirstSpecial_First){
                        GSDRI.IgnoreSide = 3;
                        GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                        if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                            GSDRI.IgnoreCorner = 0;
                        }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                            GSDRI.IgnoreCorner = 1;
                        }

                        if(!oNode1.GSDRI.bFlipped){
                            GSDRI.bNode2F_LeftTurnLane = false;
                            GSDRI.bNode2B_RightTurnLane = false;
                        }else{
                            GSDRI.bNode2B_LeftTurnLane = false;
                            GSDRI.bNode2F_RightTurnLane = false;
                        }

                    }else if(GSDRI.bFirstSpecial_Last){
                        GSDRI.IgnoreSide = 1;
                        GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                        if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                            GSDRI.IgnoreCorner = 2;
                        }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                            GSDRI.IgnoreCorner = 3;
                        }

                        if(!oNode1.GSDRI.bFlipped){
                            GSDRI.bNode2B_LeftTurnLane = false;
                            GSDRI.bNode2F_RightTurnLane = false;
                        }else{
                            GSDRI.bNode2F_LeftTurnLane = false;
                            GSDRI.bNode2B_RightTurnLane = false;
                        }

                    }
                    if(!bFlipped){
                        if(GSDRI.bSecondSpecial_First){
                            GSDRI.IgnoreSide = 2;
                            GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                            if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                                GSDRI.IgnoreCorner = 3;
                            }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                                GSDRI.IgnoreCorner = 0;
                            }

                            if(!oNode1.GSDRI.bFlipped){
                                GSDRI.bNode2B_LeftTurnLane = false;
                                GSDRI.bNode2F_RightTurnLane = false;
                            }else{
                                GSDRI.bNode2F_LeftTurnLane = false;
                                GSDRI.bNode2B_RightTurnLane = false;
                            }

                        }else if(GSDRI.bSecondSpecial_Last){
                            GSDRI.IgnoreSide = 0;
                            GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                            if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                                GSDRI.IgnoreCorner = 1;
                            }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                                GSDRI.IgnoreCorner = 2;
                            }

                            if(!oNode1.GSDRI.bFlipped){
                                GSDRI.bNode2B_LeftTurnLane = false;
                                GSDRI.bNode2F_RightTurnLane = false;
                            }else{
                                GSDRI.bNode2F_LeftTurnLane = false;
                                GSDRI.bNode2B_RightTurnLane = false;
                            }

                        }
                    }else{
                        if(GSDRI.bSecondSpecial_First){
                            GSDRI.IgnoreSide = 0;
                            GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                            if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                                GSDRI.IgnoreCorner = 1;
                            }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                                GSDRI.IgnoreCorner = 2;
                            }

                            if(!oNode1.GSDRI.bFlipped){
                                GSDRI.bNode2B_LeftTurnLane = false;
                                GSDRI.bNode2F_RightTurnLane = false;
                            }else{
                                GSDRI.bNode2F_LeftTurnLane = false;
                                GSDRI.bNode2B_RightTurnLane = false;
                            }

                        }else if(GSDRI.bSecondSpecial_Last){
                            GSDRI.IgnoreSide = 2;
                            GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay;
                            if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.StopSign_AllWay){
                                GSDRI.IgnoreCorner = 3;
                            }else if(GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight1 || GSDRI.iStopType == GSDRoadIntersection.iStopTypeEnum.TrafficLight2){
                                GSDRI.IgnoreCorner = 0;
                            }

                            if(!oNode1.GSDRI.bFlipped){
                                GSDRI.bNode2B_LeftTurnLane = false;
                                GSDRI.bNode2F_RightTurnLane = false;
                            }else{
                                GSDRI.bNode2F_LeftTurnLane = false;
                                GSDRI.bNode2B_RightTurnLane = false;
                            }
                        }
                    }

                    //Find corners:
                    Vector2 tFoundVectRR = default(Vector2);
                    Vector2 tFoundVectRL = default(Vector2);
                    Vector2 tFoundVectLR = default(Vector2);
                    Vector2 tFoundVectLL = default(Vector2);
                    if(!bOldMethod){
                        //RR:
                        if(!bFlipped){
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectRR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R_RightTurn, ref oNode2.iConstruction.tempconstruction_R);
                            }else{
                                tFoundVectRR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_R);
                            }
                        }else{
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectRR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R_RightTurn, ref oNode2.iConstruction.tempconstruction_L);
                            }else{
                                tFoundVectRR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_L);
                            }
                        }

                        //RL:
                        if(!bFlipped){
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectRL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_L_RightTurn);
                            }else{
                                tFoundVectRL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_L);
                            }
                        }else{
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectRL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_R_RightTurn);
                            }else{
                                tFoundVectRL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_R, ref oNode2.iConstruction.tempconstruction_R);
                            }
                        }

                        //LL:
                        if(!bFlipped){
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectLL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L_RightTurn, ref oNode2.iConstruction.tempconstruction_L);
                            }else{
                                tFoundVectLL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_L);
                            }
                        }else{
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectLL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L_RightTurn, ref oNode2.iConstruction.tempconstruction_R);
                            }else{
                                tFoundVectLL = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_R);
                            }
                        }

                        //LR:
                        if(!bFlipped){
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectLR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_R_RightTurn);
                            }else{
                                tFoundVectLR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_R);
                            }
                        }else{
                            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                                tFoundVectLR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_L_RightTurn);
                            }else{
                                tFoundVectLR = IntersectionCornerCalc(ref oNode1.iConstruction.tempconstruction_L, ref oNode2.iConstruction.tempconstruction_L);
                            }
                        }
                    }else{
                        //Now two lists of R and L on each intersection node, now match:
                        float eDistanceRR = 5000f;
                        float oDistanceRR = 0f;
                        float eDistanceRL = 5000f;
                        float oDistanceRL = 0f;
                        float eDistanceLR = 5000f;
                        float oDistanceLR = 0f;
                        float eDistanceLL = 5000f;
                        float oDistanceLL = 0f;
                        bool bHasBeen1mRR = false;
                        bool bHasBeen1mRL = false;
                        bool bHasBeen1mLR = false;
                        bool bHasBeen1mLL = false;
                        bool bHasBeen1mRR_ignore = false;
                        bool bHasBeen1mRL_ignore = false;
                        bool bHasBeen1mLR_ignore = false;
                        bool bHasBeen1mLL_ignore = false;
                        bool bHasBeen1mRR_ignore_Max = false;
                        bool bHasBeen1mRL_ignore_Max = false;
                        bool bHasBeen1mLR_ignore_Max = false;
                        bool bHasBeen1mLL_ignore_Max = false;
                        float mMin = 0.2f;
                        float mMax = 0.5f;

                        MaxCount = Mathf.Max(tCounts);
                        int MaxHCount = Mathf.Max(hCount1,hCount2);
                        for(int h=0;h<MaxHCount;h++){
                            bHasBeen1mRR = false;
                            bHasBeen1mRL = false;
                            bHasBeen1mLR = false;
                            bHasBeen1mLL = false;
                            bHasBeen1mRR_ignore = false;
                            bHasBeen1mRL_ignore = false;
                            bHasBeen1mLR_ignore = false;
                            bHasBeen1mLL_ignore = false;
                            for(int k=0;k<MaxCount;k++){
                                if(!bFlipped){
                                    //RR:
                                    if(!bHasBeen1mRR_ignore_Max && !bHasBeen1mRR_ignore && (h < N1RCount && k < N2RCount)){
                                        oDistanceRR = Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_R[k]);
                                        if(oDistanceRR < eDistanceRR){
                                            eDistanceRR = oDistanceRR;
                                            tFoundVectRR = oNode1.iConstruction.tempconstruction_R[h]; //RR
                                            if(eDistanceRR < 0.07f){ bHasBeen1mRR_ignore_Max = true; }
                                        }
                                        if(oDistanceRR > mMax && bHasBeen1mRR){ bHasBeen1mRR_ignore = true; }
                                        if(oDistanceRR < mMin){ bHasBeen1mRR = true; }
                                    }
                                    //RL:
                                    if(!bHasBeen1mRL_ignore_Max && !bHasBeen1mRL_ignore && (h < N1RCount && k < N2LCount)){
                                        oDistanceRL = Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_L[k]);
                                        if(oDistanceRL < eDistanceRL){
                                            eDistanceRL = oDistanceRL;
                                            tFoundVectRL = oNode1.iConstruction.tempconstruction_R[h]; //RL
                                            if(eDistanceRL < 0.07f){ bHasBeen1mRL_ignore_Max = true; }
                                        }
                                        if(oDistanceRL > mMax && bHasBeen1mRL){ bHasBeen1mRL_ignore = true; }
                                        if(oDistanceRL < mMin){ bHasBeen1mRL = true; }
                                    }
                                    //LR:
                                    if(!bHasBeen1mLR_ignore_Max && !bHasBeen1mLR_ignore && (h < N1LCount && k < N2RCount)){
                                        oDistanceLR = Vector2.Distance(oNode1.iConstruction.tempconstruction_L[h],oNode2.iConstruction.tempconstruction_R[k]);
                                        if(oDistanceLR < eDistanceLR){
                                            eDistanceLR = oDistanceLR;
                                            tFoundVectLR = oNode1.iConstruction.tempconstruction_L[h]; //LR
                                            if(eDistanceLR < 0.07f){ bHasBeen1mLR_ignore_Max = true; }
                                        }
                                        if(oDistanceLR > mMax && bHasBeen1mLR){ bHasBeen1mLR_ignore = true; }
                                        if(oDistanceLR < mMin){ bHasBeen1mLR = true; }
                                    }
                                    //LL:
                                    if(!bHasBeen1mLL_ignore_Max && !bHasBeen1mLL_ignore && (h < N1LCount && k < N2LCount)){
                                        oDistanceLL = Vector2.Distance(oNode1.iConstruction.tempconstruction_L[h],oNode2.iConstruction.tempconstruction_L[k]);
                                        if(oDistanceLL < eDistanceLL){
                                            eDistanceLL = oDistanceLL;
                                            tFoundVectLL = oNode1.iConstruction.tempconstruction_L[h]; //LL
                                            if(eDistanceLL < 0.07f){ bHasBeen1mLL_ignore_Max = true; }
                                        }
                                        if(oDistanceLL > mMax && bHasBeen1mLL){ bHasBeen1mLL_ignore = true; }
                                        if(oDistanceLL < mMin){ bHasBeen1mLL = true; }
                                    }
                                }else{
                                    //RR:
                                    if(!bHasBeen1mRR_ignore_Max && !bHasBeen1mRR_ignore && (h < N1RCount && k < N2LCount)){
                                        oDistanceRR = Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_L[k]);
                                        if(oDistanceRR < eDistanceRR){
                                            eDistanceRR = oDistanceRR;
                                            tFoundVectRR = oNode1.iConstruction.tempconstruction_R[h]; //RR
                                            if(eDistanceRR < 0.07f){ bHasBeen1mRR_ignore_Max = true; }
                                        }
                                        if(oDistanceRR > mMax && bHasBeen1mRR){ bHasBeen1mRR_ignore = true; }
                                        if(oDistanceRR < mMin){ bHasBeen1mRR = true; }
                                    }
                                    //RL:
                                    if(!bHasBeen1mRL_ignore_Max && !bHasBeen1mRL_ignore && (h < N1RCount && k < N2RCount)){
                                        oDistanceRL = Vector2.Distance(oNode1.iConstruction.tempconstruction_R[h],oNode2.iConstruction.tempconstruction_R[k]);
                                        if(oDistanceRL < eDistanceRL){
                                            eDistanceRL = oDistanceRL;
                                            tFoundVectRL = oNode1.iConstruction.tempconstruction_R[h]; //RL
                                            if(eDistanceRL < 0.07f){ bHasBeen1mRL_ignore_Max = true; }
                                        }
                                        if(oDistanceRL > mMax && bHasBeen1mRL){ bHasBeen1mRL_ignore = true; }
                                        if(oDistanceRL < mMin){ bHasBeen1mRL = true; }
                                    }
                                    //LR:
                                    if(!bHasBeen1mLR_ignore_Max && !bHasBeen1mLR_ignore && (h < N1LCount && k < N2LCount)){
                                        oDistanceLR = Vector2.Distance(oNode1.iConstruction.tempconstruction_L[h],oNode2.iConstruction.tempconstruction_L[k]);
                                        if(oDistanceLR < eDistanceLR){
                                            eDistanceLR = oDistanceLR;
                                            tFoundVectLR = oNode1.iConstruction.tempconstruction_L[h]; //LR
                                            if(eDistanceLR < 0.07f){ bHasBeen1mLR_ignore_Max = true; }
                                        }
                                        if(oDistanceLR > mMax && bHasBeen1mLR){ bHasBeen1mLR_ignore = true; }
                                        if(oDistanceLR < mMin){ bHasBeen1mLR = true; }
                                    }
                                    //LL:
                                    if(!bHasBeen1mLL_ignore_Max && !bHasBeen1mLL_ignore && (h < N1LCount && k < N2RCount)){
                                        oDistanceLL = Vector2.Distance(oNode1.iConstruction.tempconstruction_L[h],oNode2.iConstruction.tempconstruction_R[k]);
                                        if(oDistanceLL < eDistanceLL){
                                            eDistanceLL = oDistanceLL;
                                            tFoundVectLL = oNode1.iConstruction.tempconstruction_L[h]; //LL
                                            if(eDistanceLL < 0.07f){ bHasBeen1mLL_ignore_Max = true; }
                                        }
                                        if(oDistanceLL > mMax && bHasBeen1mLL){ bHasBeen1mLL_ignore = true; }
                                        if(oDistanceLL < mMin){ bHasBeen1mLL = true; }
                                    }
                                }
                            }
                        }
                    }

                    oNode1.iConstruction.tempconstruction_HasProcessed_Inter2 = true;
                    oNode2.iConstruction.tempconstruction_HasProcessed_Inter2 = true;

                    Vector3 tVectRR = new Vector3(tFoundVectRR.x,0f,tFoundVectRR.y);
                    Vector3 tVectRL = new Vector3(tFoundVectRL.x,0f,tFoundVectRL.y);
                    Vector3 tVectLR = new Vector3(tFoundVectLR.x,0f,tFoundVectLR.y);
                    Vector3 tVectLL = new Vector3(tFoundVectLL.x,0f,tFoundVectLL.y);

                    oNode1.GSDRI.CornerRR = tVectRR;
                    oNode1.GSDRI.CornerRL = tVectRL;
                    oNode1.GSDRI.CornerLR = tVectLR;
                    oNode1.GSDRI.CornerLL = tVectLL;

                    float[] tMaxFloats = new float[4];
                    tMaxFloats[0] = Vector3.Distance(((tVectRR-tVectRL)*0.5f)+tVectRL,oNode1.pos) * 1.25f;
                    tMaxFloats[1] = Vector3.Distance(((tVectRR-tVectLR)*0.5f)+tVectLR,oNode1.pos) * 1.25f;
                    tMaxFloats[2] = Vector3.Distance(((tVectRL-tVectLL)*0.5f)+tVectLL,oNode1.pos) * 1.25f;
                    tMaxFloats[3] = Vector3.Distance(((tVectLR-tVectLL)*0.5f)+tVectLL,oNode1.pos) * 1.25f;
                    GSDRI.MaxInterDistance = Mathf.Max(tMaxFloats);

                    float[] tMaxFloatsSQ = new float[4];
                    tMaxFloatsSQ[0] = Vector3.SqrMagnitude((((tVectRR-tVectRL)*0.5f)+tVectRL)-oNode1.pos) * 1.25f;
                    tMaxFloatsSQ[1] = Vector3.SqrMagnitude((((tVectRR-tVectLR)*0.5f)+tVectLR)-oNode1.pos) * 1.25f;
                    tMaxFloatsSQ[2] = Vector3.SqrMagnitude((((tVectRL-tVectLL)*0.5f)+tVectLL)-oNode1.pos) * 1.25f;
                    tMaxFloatsSQ[3] = Vector3.SqrMagnitude((((tVectLR-tVectLL)*0.5f)+tVectLL)-oNode1.pos) * 1.25f;
                    GSDRI.MaxInterDistanceSQ = Mathf.Max(tMaxFloatsSQ);

                    float TotalLanes = (int)(RoadWidth/LaneWidth);
                    float TotalLanesI = TotalLanes;
                    float LanesPerSide = TotalLanes/2f;

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        TotalLanesI = TotalLanes + 2f;
                        //Lower left to lower right:
                        GSDRI.fCornerLR_CornerRR = new Vector3[5];
                        GSDRI.fCornerLR_CornerRR[0] = tVectLR;
                        GSDRI.fCornerLR_CornerRR[1] = ((tVectRR - tVectLR)*(LanesPerSide/TotalLanesI))+tVectLR;
                        GSDRI.fCornerLR_CornerRR[2] = ((tVectRR - tVectLR)*((LanesPerSide+1)/TotalLanesI))+tVectLR;
                        GSDRI.fCornerLR_CornerRR[3] = ((tVectRR - tVectLR)*((LanesPerSide+1+LanesPerSide)/TotalLanesI))+tVectLR;
                        GSDRI.fCornerLR_CornerRR[4] = tVectRR;
                        //Upper right to lower right:
                        GSDRI.fCornerRL_CornerRR = new Vector3[5];
                        GSDRI.fCornerRL_CornerRR[0] = tVectRL;
                        GSDRI.fCornerRL_CornerRR[1] = ((tVectRR - tVectRL)*(1/TotalLanesI))+tVectRL;
                        GSDRI.fCornerRL_CornerRR[2] = ((tVectRR - tVectRL)*((LanesPerSide+1)/TotalLanesI))+tVectRL;
                        GSDRI.fCornerRL_CornerRR[3] = ((tVectRR - tVectRL)*((LanesPerSide+2)/TotalLanesI))+tVectRL;
                        GSDRI.fCornerRL_CornerRR[4] = tVectRR;
                        //Upper left to upper right:
                        GSDRI.fCornerLL_CornerRL = new Vector3[5];
                        GSDRI.fCornerLL_CornerRL[0] = tVectLL;
                        GSDRI.fCornerLL_CornerRL[1] = ((tVectRL - tVectLL)*(1/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerRL[2] = ((tVectRL - tVectLL)*((LanesPerSide+1)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerRL[3] = ((tVectRL - tVectLL)*((LanesPerSide+2)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerRL[4] = tVectRL;
                        //Upper left to lower left:
                        GSDRI.fCornerLL_CornerLR = new Vector3[5];
                        GSDRI.fCornerLL_CornerLR[0] = tVectLL;
                        GSDRI.fCornerLL_CornerLR[1] = ((tVectLR - tVectLL)*(LanesPerSide/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerLR[2] = ((tVectLR - tVectLL)*((LanesPerSide+1)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerLR[3] = ((tVectLR - tVectLL)*((LanesPerSide+1+LanesPerSide)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerLR[4] = tVectLR;
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        TotalLanesI = TotalLanes + 1;
                        //Lower left to lower right:
                        GSDRI.fCornerLR_CornerRR = new Vector3[4];
                        GSDRI.fCornerLR_CornerRR[0] = tVectLR;
                        GSDRI.fCornerLR_CornerRR[1] = ((tVectRR - tVectLR)*(LanesPerSide/TotalLanesI))+tVectLR;
                        GSDRI.fCornerLR_CornerRR[2] = ((tVectRR - tVectLR)*((LanesPerSide+1)/TotalLanesI))+tVectLR;
                        GSDRI.fCornerLR_CornerRR[3] = tVectRR;
                        //Upper right to lower right:
                        GSDRI.fCornerRL_CornerRR = new Vector3[4];
                        GSDRI.fCornerRL_CornerRR[0] = tVectRL;
                        GSDRI.fCornerRL_CornerRR[1] = ((tVectRR - tVectRL)*(LanesPerSide/TotalLanesI))+tVectRL;
                        GSDRI.fCornerRL_CornerRR[2] = ((tVectRR - tVectRL)*((LanesPerSide+1)/TotalLanesI))+tVectRL;
                        GSDRI.fCornerRL_CornerRR[3] = tVectRR;
                        //Upper left to upper right:
                        GSDRI.fCornerLL_CornerRL = new Vector3[4];
                        GSDRI.fCornerLL_CornerRL[0] = tVectLL;
                        GSDRI.fCornerLL_CornerRL[1] = ((tVectRL - tVectLL)*(LanesPerSide/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerRL[2] = ((tVectRL - tVectLL)*((LanesPerSide+1)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerRL[3] = tVectRL;
                        //Upper left to lower left:
                        GSDRI.fCornerLL_CornerLR = new Vector3[4];
                        GSDRI.fCornerLL_CornerLR[0] = tVectLL;
                        GSDRI.fCornerLL_CornerLR[1] = ((tVectLR - tVectLL)*(LanesPerSide/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerLR[2] = ((tVectLR - tVectLL)*((LanesPerSide+1)/TotalLanesI))+tVectLL;
                        GSDRI.fCornerLL_CornerLR[3] = tVectLR;
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        TotalLanesI = TotalLanes + 0;
                        //Lower left to lower right:
                        GSDRI.fCornerLR_CornerRR = new Vector3[3];
                        GSDRI.fCornerLR_CornerRR[0] = tVectLR;
                        GSDRI.fCornerLR_CornerRR[1] = ((tVectRR - tVectLR)*0.5f)+tVectLR;
                        GSDRI.fCornerLR_CornerRR[2] = tVectRR;
                        //Upper right to lower right:
                        GSDRI.fCornerRL_CornerRR = new Vector3[3];
                        GSDRI.fCornerRL_CornerRR[0] = tVectRL;
                        GSDRI.fCornerRL_CornerRR[1] = ((tVectRR - tVectRL)*0.5f)+tVectRL;
                        GSDRI.fCornerRL_CornerRR[2] = tVectRR;
                        //Upper left to upper right:
                        GSDRI.fCornerLL_CornerRL = new Vector3[3];
                        GSDRI.fCornerLL_CornerRL[0] = tVectLL;
                        GSDRI.fCornerLL_CornerRL[1] = ((tVectRL - tVectLL)*0.5f)+tVectLL;
                        GSDRI.fCornerLL_CornerRL[2] = tVectRL;
                        //Upper left to lower left:
                        GSDRI.fCornerLL_CornerLR = new Vector3[3];
                        GSDRI.fCornerLL_CornerLR[0] = tVectLL;
                        GSDRI.fCornerLL_CornerLR[1] = ((tVectLR - tVectLL)*0.5f)+tVectLL;
                        GSDRI.fCornerLL_CornerLR[2] = tVectLR;
                    }

                    //Use node1/node2 for angles instead
                    float tShoulderWidth = ShoulderWidth * 1.75f;
                    float tRampWidth = ShoulderWidth * 2f;

                    oNode1.GSDRI.OddAngle = Vector3.Angle(GSDRI.Node2.tangent,GSDRI.Node1.tangent);
                    oNode1.GSDRI.EvenAngle = 180f - Vector3.Angle(GSDRI.Node2.tangent,GSDRI.Node1.tangent);

                 	GSD.Roads.GSDIntersectionObjects.GetFourPoints(GSDRI,out GSDRI.CornerRR_Outer, out GSDRI.CornerRL_Outer, out GSDRI.CornerLL_Outer, out GSDRI.CornerLR_Outer, tShoulderWidth);
                    GSD.Roads.GSDIntersectionObjects.GetFourPoints(GSDRI,out GSDRI.CornerRR_RampOuter, out GSDRI.CornerRL_RampOuter, out GSDRI.CornerLL_RampOuter, out GSDRI.CornerLR_RampOuter, tRampWidth);

                    GSDRI.ConstructBoundsRect();
                    GSDRI.CornerRR_2D = new Vector2(tVectRR.x,tVectRR.z);
                    GSDRI.CornerRL_2D = new Vector2(tVectRL.x,tVectRL.z);
                    GSDRI.CornerLL_2D = new Vector2(tVectLL.x,tVectLL.z);
                    GSDRI.CornerLR_2D = new Vector2(tVectLR.x,tVectLR.z);

                    if(!oNode1.GSDRI.bSameSpline){
                        if(string.Compare(tRoad.GSDSpline.UID,oNode1.GSDSpline.tRoad.GSDSpline.UID) != 0){
                            AddIntersectionBounds(ref oNode1.GSDSpline.tRoad, ref tRoad.RCS);
                        }else if(string.Compare(tRoad.GSDSpline.UID,oNode2.GSDSpline.tRoad.GSDSpline.UID) != 0){
                            AddIntersectionBounds(ref oNode2.GSDSpline.tRoad, ref tRoad.RCS);
                        }
                    }
                }
            }
        }
Пример #40
0
		public static void TerrainsReset(GSDRoad tRoad){
			TerrainsReset_Do(ref tRoad);
		}
 public void Setup(ref List<GSD.Roads.GSDTerraforming.TempTerrainData> _TTDList, GSDSplineC _tSpline, GSDRoad _tRoad)
 {
     TTDList = _TTDList;
     tSpline = _tSpline;
     tRoad = _tRoad;
 }
Пример #42
0
		private static void TerrainsReset_Do(ref GSDRoad tRoad){
			if(tRoad.TerrainHistory == null){ return; }
			if(tRoad.TerrainHistory.Count < 1){ return; }
		
			Object[] TIDs = GameObject.FindObjectsOfType(typeof(GSDTerrain));
			float[,] heights;
			int[,] tDetails;
			int ArrayCount;
			foreach(GSDTerrainHistoryMaker TH in tRoad.TerrainHistory){
				Terrain tTerrain = null;
				foreach(GSDTerrain TID in TIDs){
					if(TID.GSDID == TH.TID){
						tTerrain = TID.tTerrain;
					}
				}
				if(!tTerrain){
					continue;		
				}
					
				//Heights:
				if(TH.x1 != null){
					heights = tTerrain.terrainData.GetHeights(0,0,tTerrain.terrainData.heightmapWidth,tTerrain.terrainData.heightmapHeight);
					ArrayCount = TH.cI;
					for(int i=0;i<ArrayCount;i++){
						heights[TH.x1[i],TH.y1[i]] = TH.h[i];
					}
					tTerrain.terrainData.SetHeights(0,0,heights);
				}
				//Details:
				if(TH.DetailsI != null && TH.DetailsX != null && TH.DetailsY != null && TH.DetailsOldValue != null){
					int RealLayerCount = tTerrain.terrainData.detailPrototypes.Length;
					int StartIndex = 0;
					int EndIndex = 0;
					for(int i=0;i<TH.DetailLayersCount;i++){
						if(i >= RealLayerCount){ break; }
						if(TH.DetailsX.Length <= i){ break; }
						if(TH.DetailsY.Length <= i){ break; }
						if(TH.DetailsX == null || TH.DetailsY == null || TH.DetailsI == null || TH.DetailsX.Length < 1){
							continue;
						}

						tDetails = tTerrain.terrainData.GetDetailLayer(0,0,tTerrain.terrainData.detailWidth,tTerrain.terrainData.detailHeight,i);
						ArrayCount = TH.DetailsI[i];
						if(ArrayCount == 0){ continue; }
						EndIndex += ArrayCount;
						for(int j=StartIndex;j<EndIndex;j++){
							tDetails[TH.DetailsX[j],TH.DetailsY[j]] = TH.DetailsOldValue[j];
						}
						StartIndex = EndIndex;
						tTerrain.terrainData.SetDetailLayer(0,0,i,tDetails);
						tDetails = null;
					}
				}
				//Trees:
				TreeInstance[] xTress = TH.MakeTrees();
				if(xTress != null){
					ArrayCount = xTress.Length;
					if(ArrayCount > 0 && TH.TreesOld != null){
						int TerrainTreeCount = tTerrain.terrainData.treeInstances.Length;;
						TreeInstance[] tTrees = new TreeInstance[ArrayCount+TerrainTreeCount];
						System.Array.Copy(tTerrain.terrainData.treeInstances,0,tTrees,0,TerrainTreeCount);
						System.Array.Copy(xTress,0,tTrees,TerrainTreeCount,ArrayCount);
						tTerrain.terrainData.treeInstances = tTrees;
					}
					xTress = null;
				}
			}
			System.GC.Collect();
		}	
        private static void Inter_OrganizeVertices(ref GSDSplineN tNode, ref GSDRoad tRoad)
        {
            GSD.Roads.GSDIntersections.iConstructionMaker iCon = tNode.iConstruction;
            GSDRoadIntersection GSDRI = tNode.GSDRI;

            //Skipping (3 ways):
            bool bSkipF = false;
            if(iCon.iFLane0L.Count == 0){
                bSkipF = true;
            }
            bool bSkipB = false;
            if(iCon.iBLane0L.Count == 0){
                bSkipB = true;
            }

            //Is primary node and is first node on a spline, meaning t junction: It does not have a B:
            if(tNode.idOnSpline == 0 && string.CompareOrdinal(GSDRI.Node1UID,tNode.UID) == 0){
                bSkipB = true;
            }
            //Is primary node and is last node on a spline, meaning t junction: It does not have a F:
            if(tNode.idOnSpline == (tNode.GSDSpline.GetNodeCount()-1) && string.CompareOrdinal(GSDRI.Node1UID,tNode.UID) == 0){
                bSkipF = true;
            }

            //Other node is t junction end node, meaning now we figure out which side we're on
            if(tNode.Intersection_OtherNode.idOnSpline == 0 || tNode.idOnSpline == (tNode.GSDSpline.GetNodeCount()-1)){

            }

            //Reverse all fronts:
            if(!bSkipF){
                iCon.iFLane0L.Reverse();
                iCon.iFLane0R.Reverse();

                iCon.iFLane1L.Reverse();
                iCon.iFLane2L.Reverse();
                iCon.iFLane3L.Reverse();
                iCon.iFLane1R.Reverse();
                iCon.iFLane2R.Reverse();
                iCon.iFLane3R.Reverse();

                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    iCon.ShoulderFR_Start = iCon.iFLane0L[0];
                    iCon.ShoulderFL_Start = iCon.iFLane3R[0];
                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    iCon.ShoulderFR_Start = iCon.iFLane0L[0];
                    iCon.ShoulderFL_Start = iCon.iFLane2R[0];
                }else{
                    iCon.ShoulderFR_Start = iCon.iFLane0L[0];
                    iCon.ShoulderFL_Start = iCon.iFLane1R[0];
                }
            }

            if(!bSkipB){
                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1];
                    iCon.ShoulderBR_End = iCon.iBLane3R[iCon.iBLane3R.Count-1];
                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1];
                    iCon.ShoulderBR_End = iCon.iBLane2R[iCon.iBLane2R.Count-1];
                }else{
                    iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1];
                    iCon.ShoulderBR_End = iCon.iBLane1R[iCon.iBLane1R.Count-1];
                }
            }

            if(!bSkipB){
                Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iBLane0L,iCon.ShoulderBL_StartIndex,ref iCon.ShoulderBL_Start, ref iCon.ShoulderBL_End, GSDRI.Height);
                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane3R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height);
                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane2R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height);
                }else{
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane1R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height);
                }
            }

            if(!bSkipF){
                Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iFLane0L,iCon.ShoulderFR_StartIndex,ref iCon.ShoulderFR_Start, ref iCon.ShoulderFR_End, GSDRI.Height,true);
                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane3R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true);
                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane2R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true);
                }else{
                    Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane1R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true);
                }
            }

            bool bError = false;
            string tWarning = "Intersection " + GSDRI.tName + " in road " + tRoad.tName + " at too extreme angle to process this intersection type. Reduce angle or reduce lane count.";

            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } }
                if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } }
            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } }
                if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } }

                if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane1R, ref iCon.iBLane2L); if(bError){ Debug.Log(tWarning); } }
                if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane1R, ref iCon.iFLane2L); if(bError){ Debug.Log(tWarning); } }
            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } }
                if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } }

                if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane1R, ref iCon.iBLane2L,true,true); if(bError){ Debug.Log(tWarning); } }
                if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane1R, ref iCon.iFLane2L,true,true); if(bError){ Debug.Log(tWarning); } }

            //				if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane2R, ref iCon.iBLane3L,true,false); if(bError){ Debug.Log(tWarning); } }
            //				if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane2R, ref iCon.iFLane3L,true,false); if(bError){ Debug.Log(tWarning); } }
            }

            //Back main plate left:
            int mCount = -1;
            if(!bSkipB){
                mCount = iCon.iBLane0L.Count;
                for(int m=0;m<mCount;m++){
                    iCon.iBMainPlateL.Add(iCon.iBLane0L[m]);
                }
            }
            //Front main plate left:
            if(!bSkipF){
                mCount = iCon.iFLane0L.Count;
                for(int m=0;m<mCount;m++){
                    iCon.iFMainPlateL.Add(iCon.iFLane0L[m]);
                }
            }

            //Back main plate right:
            if(!bSkipB){
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                    mCount = iCon.iBLane1R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iBMainPlateR.Add(iCon.iBLane1R[m]);
                    }
                }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    mCount = iCon.iBLane2R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iBMainPlateR.Add(iCon.iBLane2R[m]);
                    }
                }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    mCount = iCon.iBLane3R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iBMainPlateR.Add(iCon.iBLane3R[m]);
                    }
                }
            }

            //Front main plate right:
            if(!bSkipF){
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                    mCount = iCon.iFLane1R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iFMainPlateR.Add(iCon.iFLane1R[m]);
                    }
                }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    mCount = iCon.iFLane2R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iFMainPlateR.Add(iCon.iFLane2R[m]);
                    }
                }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    mCount = iCon.iFLane3R.Count;
                    for(int m=0;m<mCount;m++){
                        iCon.iFMainPlateR.Add(iCon.iFLane3R[m]);
                    }
                }
            }

            mCount = tRoad.RCS.RoadVectors.Count;
            //			float mDistance = 0.05f;
            Vector3 tVect = default(Vector3);

            bool biBLane0L = (iCon.iBLane0L.Count > 0);				if(biBLane0L == false){ }
            bool biBLane0R = (iCon.iBLane0R.Count > 0);				if(biBLane0R == false){ }
            bool biBMainPlateL = (iCon.iBMainPlateL.Count > 0);		if(biBMainPlateL == false){ }
            bool biBMainPlateR = (iCon.iBMainPlateR.Count > 0);		if(biBMainPlateR == false){ }
            bool biFLane0L = (iCon.iFLane0L.Count > 0);				if(biFLane0L == false){ }
            bool biFLane0R = (iCon.iFLane0R.Count > 0);				if(biFLane0R == false){ }
            bool biFMainPlateL = (iCon.iFMainPlateL.Count > 0);		if(biFMainPlateL == false){ }
            bool biFMainPlateR = (iCon.iFMainPlateR.Count > 0);		if(biFMainPlateR == false){ }
            bool biBLane2L = (iCon.iBLane2L.Count > 0);				if(biBLane2L == false){ }
            bool biBLane2R = (iCon.iBLane2R.Count > 0);				if(biBLane2R == false){ }
            bool biFLane2L = (iCon.iFLane2L.Count > 0);				if(biFLane2L == false){ }
            bool biFLane2R = (iCon.iFLane2R.Count > 0);				if(biFLane2R == false){ }
            bool biBLane3L = (iCon.iBLane3L.Count > 0);				if(biBLane3L == false){ }
            bool biBLane3R = (iCon.iBLane3R.Count > 0);				if(biBLane3R == false){ }
            bool biFLane3L = (iCon.iFLane3L.Count > 0);				if(biFLane3L == false){ }
            bool biFLane3R = (iCon.iFLane3R.Count > 0);				if(biFLane3R == false){ }

            mCount = tRoad.RCS.RoadVectors.Count;
            int cCount = tRoad.GSDSpline.GetNodeCount();
            int tStartI = 0;
            int tEndI = mCount;
            //Start and end the next loop after this one later for opt:
            if(cCount > 2){
                if(!tRoad.GSDSpline.mNodes[0].bIsIntersection && !tRoad.GSDSpline.mNodes[1].bIsIntersection){
                    for(int i=2;i<cCount;i++){
                        if(tRoad.GSDSpline.mNodes[i].bIsIntersection){
                            if(i-2 >= 1){
                                tStartI = (int)(tRoad.GSDSpline.mNodes[i-2].tTime * mCount);
                            }
                            break;
                        }
                    }
                }
            }
            if(cCount > 3){
                if(!tRoad.GSDSpline.mNodes[cCount-1].bIsIntersection && !tRoad.GSDSpline.mNodes[cCount-2].bIsIntersection){
                    for(int i=(cCount-3);i>=0;i--){
                        if(tRoad.GSDSpline.mNodes[i].bIsIntersection){
                            if(i+2 < cCount){
                                tEndI = (int)(tRoad.GSDSpline.mNodes[i+2].tTime * mCount);
                            }
                            break;
                        }
                    }
                }
            }

            if(tStartI > 0){
                if(tStartI % 2 != 0){
                    tStartI += 1;
                }
            }
            if(tStartI > mCount){ tStartI=mCount-4; }
            if(tStartI < 0){ tStartI = 0; }
            if(tEndI < mCount){
                if(tEndI % 2 != 0){
                    tEndI += 1;
                }
            }
            if(tEndI > mCount){ tEndI=mCount-4; }
            if(tEndI < 0){ tEndI = 0; }

            for(int i=tStartI;i<tEndI;i+=2){
                tVect = tRoad.RCS.RoadVectors[i];
                for(int j=0;j<1;j++){
                    if(biBLane0L && Vector3.SqrMagnitude(tVect-iCon.iBLane0L[j]) < 0.01f && !bSkipB){
                        iCon.iBLane0L[j] = tVect;
                    }
                    if(biBMainPlateL && Vector3.SqrMagnitude(tVect-iCon.iBMainPlateL[j]) < 0.01f && !bSkipB){
                        iCon.iBMainPlateL[j] = tVect;
                    }
                    if(biBMainPlateR && Vector3.SqrMagnitude(tVect-iCon.iBMainPlateR[j]) < 0.01f && !bSkipB){
                        iCon.iBMainPlateR[j] = tVect;
                    }
                    if(biFLane0L && Vector3.SqrMagnitude(tVect-iCon.iFLane0L[j]) < 0.01f && !bSkipF){
                        iCon.iFLane0L[j] = tVect;
                    }
                    if(biFMainPlateL && Vector3.SqrMagnitude(tVect-iCon.iFMainPlateL[j]) < 0.01f && !bSkipF){
                        iCon.iFMainPlateL[j] = tVect;
                    }
                    if(biFMainPlateR && Vector3.SqrMagnitude(tVect-iCon.iFMainPlateR[j]) < 0.01f && !bSkipF){
                        iCon.iFMainPlateR[j] = tVect;
                    }
                    if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        if(biBLane3L && Vector3.SqrMagnitude(tVect-iCon.iBLane3L[j]) < 0.01f && !bSkipB){
                            iCon.iBLane3L[j] = tVect;
                        }
                        if(biBLane3R && Vector3.SqrMagnitude(tVect-iCon.iBLane3R[j]) < 0.01f && !bSkipB){
                            iCon.iBLane3R[j] = tVect;
                        }
                        if(biFLane3L && Vector3.SqrMagnitude(tVect-iCon.iFLane3L[j]) < 0.01f && !bSkipF){
                            iCon.iFLane3L[j] = tVect;
                        }
                        if(biFLane3R && Vector3.SqrMagnitude(tVect-iCon.iFLane3R[j]) < 0.01f && !bSkipF){
                            iCon.iFLane3R[j] = tVect;
                        }
                    }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        if(biBLane2L && Vector3.SqrMagnitude(tVect-iCon.iBLane2L[j]) < 0.01f && !bSkipB){
                            iCon.iBLane2L[j] = tVect;
                        }
                        if(biBLane2R && Vector3.SqrMagnitude(tVect-iCon.iBLane2R[j]) < 0.01f && !bSkipB){
                            iCon.iBLane2R[j] = tVect;
                        }
                        if(biFLane2L && Vector3.SqrMagnitude(tVect-iCon.iFLane2L[j]) < 0.01f && !bSkipF){
                            iCon.iFLane2L[j] = tVect;
                        }
                        if(biFLane2R && Vector3.SqrMagnitude(tVect-iCon.iFLane2R[j]) < 0.01f && !bSkipF){
                            iCon.iFLane2R[j] = tVect;
                        }
                    }
                }
            }

            //			float b0 = -1f;
            //			float f0 = -1f;
            //
            //			if(!bSkipB){ b0 = iCon.iBMainPlateL[0].y; }
            //			if(!bSkipF){ f0 = iCon.iFMainPlateL[0].y; }
            //
            //			if(iCon.iBLane0R == null || iCon.iBLane0R.Count == 0){
            //				bSkipB = true;
            //			}
            if(iCon.iBMainPlateR == null || iCon.iBMainPlateR.Count == 0){
                bSkipB = true;
            }
            if(iCon.iBMainPlateL == null || iCon.iBMainPlateL.Count == 0){
                bSkipB = true;
            }

            if(!bSkipB){ iCon.iBLane0R[0] = ((iCon.iBMainPlateR[0]-iCon.iBMainPlateL[0])*0.5f+iCon.iBMainPlateL[0]); }
            if(!bSkipF){ iCon.iFLane0R[0] = ((iCon.iFMainPlateR[0]-iCon.iFMainPlateL[0])*0.5f+iCon.iFMainPlateL[0]); }

            //			if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                if(!bSkipB){
                    iCon.iBLane1L[0] = iCon.iBLane0R[0];
                    iCon.iBLane1R[0] = new Vector3(iCon.iBLane1R[0].x,iCon.iBLane1L[0].y,iCon.iBLane1R[0].z);
                }

                if(!bSkipF){
                    iCon.iFLane1L[0] = iCon.iFLane0R[0];
                    iCon.iFLane1R[0] = new Vector3(iCon.iFLane1R[0].x,iCon.iFLane1L[0].y,iCon.iFLane1R[0].z);
                }
            //			}

            if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                if(!bSkipB){ iCon.iBLane3L[0] = new Vector3(iCon.iBLane3L[0].x,iCon.iBLane3R[0].y,iCon.iBLane3L[0].z); }
                if(!bSkipF){ iCon.iFLane3L[0] = new Vector3(iCon.iFLane3L[0].x,iCon.iFLane3R[0].y,iCon.iFLane3L[0].z); }
            }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                if(!bSkipB){ iCon.iBLane2L[0] = new Vector3(iCon.iBLane2L[0].x,iCon.iBLane2R[0].y,iCon.iBLane2L[0].z); }
                if(!bSkipF){ iCon.iFLane2L[0] = new Vector3(iCon.iFLane2L[0].x,iCon.iFLane2R[0].y,iCon.iFLane2L[0].z); }
            }

            List<Vector3> iBLane0 = null;
            List<Vector3> iBLane1 = null;
            List<Vector3> iBLane2 = null;
            List<Vector3> iBLane3 = null;
            if(!bSkipB){
                iBLane0 = InterVertices(iCon.iBLane0L,iCon.iBLane0R, tNode.GSDRI.Height);
                iBLane1 = InterVertices(iCon.iBLane1L,iCon.iBLane1R, tNode.GSDRI.Height);
                if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ iBLane2 = InterVertices(iCon.iBLane2L,iCon.iBLane2R, tNode.GSDRI.Height); }
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iBLane3 = InterVertices(iCon.iBLane3L,iCon.iBLane3R, tNode.GSDRI.Height); }
            }

            //Front lanes:
            List<Vector3> iFLane0 = null;
            List<Vector3> iFLane1 = null;
            List<Vector3> iFLane2 = null;
            List<Vector3> iFLane3 = null;
            if(!bSkipF){
                iFLane0 = InterVertices(iCon.iFLane0L,iCon.iFLane0R, tNode.GSDRI.Height);
                iFLane1 = InterVertices(iCon.iFLane1L,iCon.iFLane1R, tNode.GSDRI.Height);
                if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ iFLane2 = InterVertices(iCon.iFLane2L,iCon.iFLane2R, tNode.GSDRI.Height); }
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iFLane3 = InterVertices(iCon.iFLane3L,iCon.iFLane3R, tNode.GSDRI.Height); }
            }

            //Main plates:
            List<Vector3> iBMainPlate = null;
            List<Vector3> iFMainPlate = null;
            if(!bSkipB){
                iBMainPlate = InterVertices(iCon.iBMainPlateL,iCon.iBMainPlateR, tNode.GSDRI.Height);
            }
            if(!bSkipF){
                iFMainPlate = InterVertices(iCon.iFMainPlateL,iCon.iFMainPlateR, tNode.GSDRI.Height);
            }
            //			//Marker plates:
            //			List<Vector3> iBMarkerPlate = InterVertices(iCon.iBMarkerPlateL,iCon.iBMarkerPlateR, tNode.GSDRI.Height);
            //			List<Vector3> iFMarkerPlate = InterVertices(iCon.iFMarkerPlateL,iCon.iFMarkerPlateR, tNode.GSDRI.Height);
            //
            //Now add these to RCS:
            if(!bSkipB){
                tRoad.RCS.iBLane0s.Add(iBLane0.ToArray());
                tRoad.RCS.iBLane0s_tID.Add(GSDRI);
                tRoad.RCS.iBLane0s_nID.Add(tNode);
                tRoad.RCS.iBLane1s.Add(iBLane1.ToArray());
                tRoad.RCS.iBLane1s_tID.Add(GSDRI);
                tRoad.RCS.iBLane1s_nID.Add(tNode);
                if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                    if (iBLane2 != null) {
                        tRoad.RCS.iBLane2s.Add(iBLane2.ToArray());
                        tRoad.RCS.iBLane2s_tID.Add(GSDRI);
                        tRoad.RCS.iBLane2s_nID.Add(tNode);
                    }
                }
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    tRoad.RCS.iBLane3s.Add(iBLane3.ToArray());
                    tRoad.RCS.iBLane3s_tID.Add(GSDRI);
                    tRoad.RCS.iBLane3s_nID.Add(tNode);
                }
            }
            //Front lanes:
            if(!bSkipF){
                tRoad.RCS.iFLane0s.Add(iFLane0.ToArray());
                tRoad.RCS.iFLane0s_tID.Add(GSDRI);
                tRoad.RCS.iFLane0s_nID.Add(tNode);
                tRoad.RCS.iFLane1s.Add(iFLane1.ToArray());
                tRoad.RCS.iFLane1s_tID.Add(GSDRI);
                tRoad.RCS.iFLane1s_nID.Add(tNode);
                if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                    tRoad.RCS.iFLane2s.Add(iFLane2.ToArray());
                    tRoad.RCS.iFLane2s_tID.Add(GSDRI);
                    tRoad.RCS.iFLane2s_nID.Add(tNode);
                }
                if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    tRoad.RCS.iFLane3s.Add(iFLane3.ToArray());
                    tRoad.RCS.iFLane3s_tID.Add(GSDRI);
                    tRoad.RCS.iFLane3s_nID.Add(tNode);
                }
            }
            //Main plates:
            if(iBMainPlate != null && !bSkipB){
                tRoad.RCS.iBMainPlates.Add(iBMainPlate.ToArray());
                tRoad.RCS.iBMainPlates_tID.Add(GSDRI);
                tRoad.RCS.iBMainPlates_nID.Add(tNode);
            }
            if(iFMainPlate != null && !bSkipF){
                tRoad.RCS.iFMainPlates.Add(iFMainPlate.ToArray());
                tRoad.RCS.iFMainPlates_tID.Add(GSDRI);
                tRoad.RCS.iFMainPlates_nID.Add(tNode);
            }
            //			//Marker plates:
            //			tRoad.RCS.iBMarkerPlates.Add(iBMarkerPlate.ToArray());
            //			tRoad.RCS.iFMarkerPlates.Add(iFMarkerPlate.ToArray());
            //			tRoad.RCS.IntersectionTypes.Add((int)tNode.GSDRI.rType);

            if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                if(!bSkipB){ tRoad.RCS.iBLane1s_IsMiddleLane.Add(true);	}
                if(!bSkipF){ tRoad.RCS.iFLane1s_IsMiddleLane.Add(true);	}
            }else{
                if(!bSkipB){ tRoad.RCS.iBLane1s_IsMiddleLane.Add(false); }
                if(!bSkipF){ tRoad.RCS.iFLane1s_IsMiddleLane.Add(false); }
            }
        }
Пример #44
0
		//Insert
		//Detect closest node (if end node, auto select other node)
		//Determine which node is closest (up or down) on spline
		//Place node, adjust all id on splines
		//Setup spline
		public static GSDSplineN InsertNode(GSDRoad RS, bool bForcedLoc = false, Vector3 ForcedLoc = default(Vector3), bool bIsPreNode = false, int InsertIndex = -1, bool bSpecialEndNode = false, bool bInterNode = false){
			GameObject tNodeObj;
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
			if(!bForcedLoc){
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			}else if(bForcedLoc && !bSpecialEndNode){
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString() + "Ignore");
			}else{
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			}
			if(!bInterNode){
				UnityEditor.Undo.RegisterCreatedObjectUndo(tNodeObj, "Inserted node");
			}
			
			if(!bForcedLoc){
				tNodeObj.transform.position = RS.Editor_MousePos;
				
				//This helps prevent double clicks:
				int mCount = RS.GSDSpline.GetNodeCount();
				for(int i=0;i<mCount;i++){
					if(Vector3.Distance(RS.Editor_MousePos,RS.GSDSpline.mNodes[i].pos) < 15f){
						Object.DestroyImmediate(tNodeObj);
						return null;
					}
				}
				//End double click prevention
			}else{
				tNodeObj.transform.position = ForcedLoc;
			}
			Vector3 xVect = tNodeObj.transform.position;
			if(xVect.y < 0.03f){ xVect.y = 0.03f; }
			tNodeObj.transform.position = xVect;
			tNodeObj.transform.parent = RS.GSDSplineObj.transform;
			
			int cCount = RS.GSDSpline.mNodes.Count;
//			float mDistance = 50000f;
//			float tDistance = 0f;
			
			float tParam; 
			if(!bForcedLoc){
				tParam = RS.GSDSpline.GetClosestParam(RS.Editor_MousePos,false,true);
			}else{
				tParam = RS.GSDSpline.GetClosestParam(ForcedLoc,false,true);
			}
			bool bEndInsert = false;
			bool bZeroInsert = false;
			int iStart = 0;
            if (GSDRootUtil.IsApproximately(tParam, 0f, 0.0001f)) {
				bZeroInsert = true;
				iStart = 0;
            } else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f)) {
				bEndInsert = true;
			}
			
			if(bForcedLoc){
				iStart = InsertIndex;
			}else{
				for(int i=0;i<cCount;i++){
					GSDSplineN xNode = RS.GSDSpline.mNodes[i];
					if(!bZeroInsert && !bEndInsert){
						if(tParam > xNode.tTime){
							iStart = xNode.idOnSpline+1;
						}
					}
				}
			}
	
			if(bEndInsert){
				iStart = RS.GSDSpline.mNodes.Count;
			}else{
				for(int i=iStart;i<cCount;i++){
					RS.GSDSpline.mNodes[i].idOnSpline+=1;
				}
			}
			
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();
			if(bForcedLoc && !bSpecialEndNode){
				tNode.bIsBridge = true;
				tNode.bIgnore = true;
//				tNode.bIsBridge_PreNode = bIsPreNode;
//				tNode.bIsBridge_PostNode = !bIsPreNode;	
			}
			tNode.GSDSpline = RS.GSDSpline;
			tNode.idOnSpline = iStart;
			tNode.bSpecialEndNode = bSpecialEndNode;
			if(!bForcedLoc){
				tNode.pos = RS.Editor_MousePos;
			}else{
				tNode.pos = ForcedLoc;
			}
			
			RS.GSDSpline.mNodes.Insert(iStart,tNode);
	
			//Enforce maximum road grade:
			if(!bForcedLoc && !bSpecialEndNode && RS.opt_bMaxGradeEnabled){
				tNode.EnsureGradeValidity(iStart);
			}

			if(!bInterNode && !bSpecialEndNode){
				if(!bForcedLoc){
					RS.UpdateRoad();
				}
			}
			
			return tNode;
		}
Пример #45
0
        /// <summary>
        /// Use this to insert nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to insert nodes in.</param>
        /// <param name="NodeLocation">The location of the newly inserted node.</param>
        /// <returns></returns>
        public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLocation)
        {
            GameObject tNodeObj;

            Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
            tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());

            //Set node location:
            if (NodeLocation.y < 0.03f)
            {
                NodeLocation.y = 0.03f;
            }                                                           //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = RS.GSDSplineObj.transform;

            int cCount = RS.GSDSpline.mNodes.Count;

            //Get the closet param on spline:
            float tParam = RS.GSDSpline.GetClosestParam(NodeLocation, false, true);

            bool bEndInsert  = false;
            bool bZeroInsert = false;
            int  iStart      = 0;

            if (GSDRootUtil.IsApproximately(tParam, 0f, 0.0001f))
            {
                bZeroInsert = true;
                iStart      = 0;
            }
            else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f))
            {
                //Inserted at end, switch to create node instead:
                Object.DestroyImmediate(tNodeObj);
                return(CreateNode_Programmatically(RS, NodeLocation));
            }

            //Figure out where to insert the node:
            for (int i = 0; i < cCount; i++)
            {
                GSDSplineN xNode = RS.GSDSpline.mNodes[i];
                if (!bZeroInsert && !bEndInsert)
                {
                    if (tParam > xNode.tTime)
                    {
                        iStart = xNode.idOnSpline + 1;
                    }
                }
            }
            for (int i = iStart; i < cCount; i++)
            {
                RS.GSDSpline.mNodes[i].idOnSpline += 1;
            }

            GSDSplineN tNode = tNodeObj.AddComponent <GSDSplineN>();

            tNode.GSDSpline  = RS.GSDSpline;
            tNode.idOnSpline = iStart;
            tNode.pos        = NodeLocation;
            RS.GSDSpline.mNodes.Insert(iStart, tNode);

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            RS.UpdateRoad();

            return(tNode);
        }
Пример #46
0
        /// <summary>
        /// Creates intersections where this road intersects with other roads.
        /// </summary>
        /// <param name="tRoad">The primary road to create intersections for.</param>
        /// <param name="iStopType">Stop signs, traffic lights #1 (US) or traffic lights #2 (Euro). Defaults to none.</param>
        /// <param name="rType">Intersection type: No turn lane, left turn lane or both turn lanes. Defaults to no turn lane.</param>
        public static void CreateIntersections_ProgrammaticallyForRoad(GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType = GSDRoadIntersection.iStopTypeEnum.None, GSDRoadIntersection.RoadTypeEnum rType = GSDRoadIntersection.RoadTypeEnum.NoTurnLane) {
            /*
            General logic:
             20m increments to gather collection of which roads intersect
                2m increments to find actual intersection point
                each 2m, primary road checks all intersecting array for an intersection.
             find intersection point
                if any intersections already within 75m or 100m, dont create intersection here
                check if nodes within 50m, if more than one just grab closest, and move  it to intersecting point
                if no node within 50m, add
             create intersection with above two nodes
            */

            Object[] GSDRoadObjs = Object.FindObjectsOfType<GSDRoad>();

            //20m increments to gather collection of which roads intersect
            List<GSDRoad> xRoads = new List<GSDRoad>();
            foreach (GSDRoad xRoad in GSDRoadObjs) {
                if (tRoad != xRoad) {
                    float EarlyDistanceCheckMeters = 10f;
                    float EarlyDistanceCheckThreshold = 50f;
                    bool EarlyDistanceFound = false;
                    float tRoadMod = EarlyDistanceCheckMeters / tRoad.GSDSpline.distance;
                    float xRoadMod = EarlyDistanceCheckMeters / xRoad.GSDSpline.distance;
                    Vector3 tVect1 = default(Vector3);
                    Vector3 tVect2 = default(Vector3);
                    for (float i = 0f; i < 1.0000001f; i += tRoadMod) {
                        tVect1 = tRoad.GSDSpline.GetSplineValue(i);
                        for (float x = 0f; x < 1.000001f; x += xRoadMod) {
                            tVect2 = xRoad.GSDSpline.GetSplineValue(x);
                            if (Vector3.Distance(tVect1, tVect2) < EarlyDistanceCheckThreshold) {
                                if (!xRoads.Contains(xRoad)) {
                                    xRoads.Add(xRoad);
                                }
                                EarlyDistanceFound = true;
                                break;
                            }
                        }
                        if (EarlyDistanceFound) { break; }
                    }
                }
            }

            //See if any end point nodes are on top of each other already since T might not intersect all the time.:
            List<KeyValuePair<GSDSplineN, GSDSplineN>> tKVP = new List<KeyValuePair<GSDSplineN, GSDSplineN>>();
            foreach (GSDRoad xRoad in xRoads) {
                foreach (GSDSplineN IntersectionNode1 in tRoad.GSDSpline.mNodes) {
                    if (IntersectionNode1.bIsIntersection || !IntersectionNode1.IsLegitimate()) { continue; }
                    foreach (GSDSplineN IntersectionNode2 in xRoad.GSDSpline.mNodes) {
                        if (IntersectionNode2.bIsIntersection || !IntersectionNode2.IsLegitimate()) { continue; }
                        if (IntersectionNode1.transform.position == IntersectionNode2.transform.position) {
                            //Only do T intersections and let the next algorithm handle the +, since T might not intersect all the time.
                            if (IntersectionNode1.bIsEndPoint || IntersectionNode2.bIsEndPoint) {
                                tKVP.Add(new KeyValuePair<GSDSplineN, GSDSplineN>(IntersectionNode1, IntersectionNode2));
                            }
                        }
                    }
                }
            }
            foreach (KeyValuePair<GSDSplineN, GSDSplineN> KVP in tKVP) {
                //Now create the f*****g intersection:
                GameObject tInter = GSD.Roads.GSDIntersections.CreateIntersection(KVP.Key, KVP.Value);
                GSDRoadIntersection GSDRI_JustCreated = tInter.GetComponent<GSDRoadIntersection>();
                GSDRI_JustCreated.iStopType = iStopType;
                GSDRI_JustCreated.rType = rType;
            }

            //Main algorithm: 2m increments to find actual intersection point:
            foreach (GSDRoad xRoad in xRoads) {
                if (tRoad != xRoad) {
                    //Debug.Log("Checking road: " + xRoad.transform.name);
                    float DistanceCheckMeters = 2f;
                    bool EarlyDistanceFound = false;
                    float tRoadMod = DistanceCheckMeters / tRoad.GSDSpline.distance;
                    float xRoadMod = DistanceCheckMeters / xRoad.GSDSpline.distance;
                    Vector3 tVect = default(Vector3);
                    Vector2 iVect1 = default(Vector2);
                    Vector2 iVect2 = default(Vector2);
                    Vector2 xVect1 = default(Vector2);
                    Vector2 xVect2 = default(Vector2);
                    Vector2 IntersectPoint2D = default(Vector2);
                    float i2 = 0f;
                    for (float i = 0f; i < 1.0000001f; i += tRoadMod) {
                        i2 = (i + tRoadMod);
                        if (i2 > 1f) { i2 = 1f; }
                        tVect = tRoad.GSDSpline.GetSplineValue(i);
                        iVect1 = new Vector2(tVect.x, tVect.z);
                        tVect = tRoad.GSDSpline.GetSplineValue(i2);
                        iVect2 = new Vector2(tVect.x, tVect.z);

                        float x2 = 0f;
                        for (float x = 0f; x < 1.000001f; x += xRoadMod) {
                            x2 = (x + xRoadMod);
                            if (x2 > 1f) { x2 = 1f; }
                            tVect = xRoad.GSDSpline.GetSplineValue(x);
                            xVect1 = new Vector2(tVect.x, tVect.z);
                            tVect = xRoad.GSDSpline.GetSplineValue(x2);
                            xVect2 = new Vector2(tVect.x, tVect.z);

                            //Now see if these two lines intersect:
                            if (GSD.GSDRootUtil.Intersects2D(ref iVect1,ref iVect2,ref xVect1,ref xVect2, out IntersectPoint2D)) {
                                //Get height of intersection on primary road:
                                float tHeight = 0f;
                                float hParam = tRoad.GSDSpline.GetClosestParam(new Vector3(IntersectPoint2D.x, 0f, IntersectPoint2D.y));
                                Vector3 hVect = tRoad.GSDSpline.GetSplineValue(hParam);
                                tHeight = hVect.y;

                                //if any intersections already within 75m or 100m, dont create intersection here
                                Object[] AllInterectionObjects = Object.FindObjectsOfType<GSDRoadIntersection>();
                                foreach (GSDRoadIntersection GSDRI in AllInterectionObjects) {
                                    if (Vector2.Distance(new Vector2(GSDRI.transform.position.x, GSDRI.transform.position.z), IntersectPoint2D) < 100f) {
                                        goto NoIntersectionCreation;
                                    }
                                }

                                GSDSplineN IntersectionNode1 = null;
                                GSDSplineN IntersectionNode2 = null;
                                Vector3 IntersectionPoint3D = new Vector3(IntersectPoint2D.x, tHeight, IntersectPoint2D.y);
                                //Debug.Log("Instersect found road: " + xRoad.transform.name + " at point: " + IntersectionPoint3D.ToString());

                                //Check primary road if any nodes are nearby and usable for intersection
                                foreach(GSDSplineN tNode in tRoad.GSDSpline.mNodes){
                                    if (tNode.IsLegitimate()) {
                                        if (Vector2.Distance(new Vector2(tNode.transform.position.x, tNode.transform.position.z), IntersectPoint2D) < 30f) {
                                            IntersectionNode1 = tNode;
                                            IntersectionNode1.transform.position = IntersectionPoint3D;
                                            IntersectionNode1.pos = IntersectionPoint3D;
                                            break;
                                        }
                                    }
                                }

                                //Check secondary road if any nodes are nearby and usable for intersection
                                foreach (GSDSplineN tNode in xRoad.GSDSpline.mNodes) {
                                    if (tNode.IsLegitimate()) {
                                        if (Vector2.Distance(new Vector2(tNode.transform.position.x, tNode.transform.position.z), IntersectPoint2D) < 30f) {
                                            IntersectionNode2 = tNode;
                                            IntersectionNode2.transform.position = IntersectionPoint3D;
                                            IntersectionNode2.pos = IntersectionPoint3D;
                                            break;
                                        }
                                    }
                                }

                                //Check if any of the nodes are null. If so, need to insert node. And maybe update it.
                                if (IntersectionNode1 == null) {
                                    IntersectionNode1 = InsertNode_Programmatically(tRoad, IntersectionPoint3D);
                                }
                                if (IntersectionNode2 == null) {
                                    IntersectionNode2 = InsertNode_Programmatically(xRoad, IntersectionPoint3D);
                                }

                                //Now create the f*****g intersection:
                                GameObject tInter = GSD.Roads.GSDIntersections.CreateIntersection(IntersectionNode1, IntersectionNode2);
                                GSDRoadIntersection GSDRI_JustCreated = tInter.GetComponent<GSDRoadIntersection>();
                                GSDRI_JustCreated.iStopType = iStopType;
                                GSDRI_JustCreated.rType = rType;
                            }

                        NoIntersectionCreation:
                            //Gibberish to get rid of warnings:
                            int xxx = 1;
                            if (xxx == 1) { xxx = 2; }
                        }
                        if (EarlyDistanceFound) { break; }
                    }
                }
            }
        }
Пример #47
0
    static void CreateRoadNetwork(GSDRoadSystem roadSystem, string netPath, int roadNum)
    {
        for (int i = 1; i <= roadNum; i++)
        {
            string fileName = netPath + "/Road" + i.ToString();

            StreamReader reader = new StreamReader(fileName);
            string       line   = reader.ReadLine();

            List <Vector3> nodePos = new List <Vector3>();
            while (line != null)
            {
                string[] words = line.Split(',');
                nodePos.Add(new Vector3(float.Parse(words[0]), float.Parse(words[1]), float.Parse(words[2])));
                line = reader.ReadLine();
            }
            reader.Close();

            GSDRoad tmpRoad = null;
            tmpRoad = GSDRoadAutomation.CreateRoad_Programmatically(roadSystem, ref nodePos);

            // TODO: the generation of intersection doesn't work very well at this point
            // Weizi: seems like an intersection will only get created when two nodes are within 3.3 distance
            //GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(tmpRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane); // GSDRoadIntersection.iStopTypeEnum.TrafficLight2 doesn't work
        }


        ///////////////////////////
        // Debug file reading
        ///////////////////////////

        /*int hCount = nodePos.Count;
         * Debug.Log(hCount.ToString());
         * for (int i = 0; i < hCount; i++)
         * {
         *  string ot = nodePos[i].x.ToString() + " " + nodePos[i].y.ToString() + " " + nodePos[i].z.ToString() + "\n";
         *  Debug.Log(ot);
         * }*/


        ///////////////////////////
        // Test road and intersection creation by manually specifying some road nodes
        ///////////////////////////

        /*float StartLocX = 800f;
         * float StartLocZ = 200f;
         * float GapZ = 200f;
         * float tHeight = 0.03f;
         * GSDRoad bRoad = null;
         *
         *
         * // Create roads
         * List<Vector3> nodePos = new List<Vector3>();
         * for (int i = 0; i < 5; i++)
         * {
         *  nodePos.Add(new Vector3(StartLocX + (i * 200f), tHeight, 600f));
         * }
         * bRoad = GSDRoadAutomation.CreateRoad_Programmatically(roadSystem, ref nodePos);
         *
         * nodePos.Clear();
         * for (int i = 0; i < 5; i++)
         * {
         *  nodePos.Add(new Vector3(StartLocX, tHeight, StartLocZ + (i * GapZ) + 3.3f));
         * }
         * bRoad = GSDRoadAutomation.CreateRoad_Programmatically(roadSystem, ref nodePos);
         *
         * // Create intersections (TrafficLight2 doesn't work)
         * // Weizi: seems like an intersection will only get created when two nodes are within 3.3 distance
         * GSDRoadAutomation.CreateIntersections_ProgrammaticallyForRoad(bRoad, GSDRoadIntersection.iStopTypeEnum.TrafficLight1, GSDRoadIntersection.RoadTypeEnum.NoTurnLane);*/
    }
Пример #48
0
		public static void ProcessRoad_Terrain_Hook1(GSDSplineC tSpline, GSDRoad tRoad, bool bMultithreaded = true){		
			ProcessRoad_Terrain_Hook1_Do(ref tSpline, ref tRoad, bMultithreaded);
		}
Пример #49
0
    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();
    }
 //Privatized for obfuscate:
 public static void RoadJob_Prelim(ref GSDRoad tRoad)
 {
     RoadJob_DoPrelim(ref tRoad);
 }
Пример #51
0
        private static void ConstructRoad_DoStoreTerrainHistory(ref GSDRoad tRoad){
            Object[] TIDs = GameObject.FindObjectsOfType(typeof(GSDTerrain));
			
			HashSet<int> tTIDS = new HashSet<int>();
			foreach(GSDTerrain TID in TIDs){
				tTIDS.Add (TID.GSDID);
			}
			
			if(tRoad.TerrainHistory != null && tRoad.TerrainHistory.Count > 0){
				//Delete unnecessary terrain histories:
				foreach(GSDTerrainHistoryMaker THf in tRoad.TerrainHistory){
					if(!tTIDS.Contains(THf.TID)){
						THf.Nullify();
						THf.bDestroyMe = true;
					}
				}
				
				int hCount = tRoad.TerrainHistory.Count;
				for(int i=hCount-1;i>=0;i--){
					if(tRoad.TerrainHistory[i].bDestroyMe){
						GSDTerrainHistoryMaker THf = tRoad.TerrainHistory[i];
						tRoad.TerrainHistory.RemoveAt(i);
						if(THf != null){ THf = null; }
					}
				}
			}

            if (tRoad.TerrainHistory == null) { tRoad.TerrainHistory = new List<GSDTerrainHistoryMaker>(); }
            foreach (GSDTerraforming.TempTerrainData TTD in tRoad.EditorTTDList){
                GSDTerrainHistoryMaker TH = null;
                GSDTerrain TID = null;
                //Get TID:
                foreach(GSDTerrain _TID in TIDs){
                    if (_TID.GSDID == TTD.GSDID)
                    {
                        TID = _TID;
                    }
                }

				if(tRoad.TerrainHistory == null) { tRoad.TerrainHistory = new List<GSDTerrainHistoryMaker>(); }
				if(TID == null){ continue; }
				
				int THCount = tRoad.TerrainHistory.Count;
				bool bContainsTID = false;
				for(int i=0;i<THCount;i++){
					if(tRoad.TerrainHistory[i].TID == TID.GSDID){
						bContainsTID = true;
						break;
					}
				}
				
                if(!bContainsTID){
                    GSDTerrainHistoryMaker THx = new GSDTerrainHistoryMaker();
					THx.TID = TID.GSDID;
                    tRoad.TerrainHistory.Add(THx);
                }
				
				TH = null;
				for(int i=0;i<THCount;i++){
					if(tRoad.TerrainHistory[i].TID == TID.GSDID){
						TH = tRoad.TerrainHistory[i];
						break;
					}
				}
				if(TH == null){ continue; }

                //Heights:
                if(tRoad.opt_HeightModEnabled){
                    if(TTD.cX != null && TTD.cY != null){
	                    TH.x1 = new int[TTD.cI];
	                    System.Array.Copy(TTD.cX, 0, TH.x1, 0, TTD.cI);
	                    TH.y1 = new int[TTD.cI];
	                    System.Array.Copy(TTD.cY, 0, TH.y1, 0, TTD.cI);
	                    TH.h = new float[TTD.cI];
	                    System.Array.Copy(TTD.oldH, 0, TH.h, 0, TTD.cI);
	                    TH.cI = TTD.cI;
					}
                }else{
                    TH.x1 = null;
                    TH.y1 = null;
                    TH.h = null;
                    TH.cI = 0;
                }
                //Details:
                if(tRoad.opt_DetailModEnabled){
					int TotalSize = 0;
					for(int i=0;i<TTD.DetailLayersCount;i++){
						TotalSize += TTD.DetailsI[i];
					}
					
//					float tHalf = (float)TotalSize / 2f;
//					int IntHalf = Mathf.CeilToInt(tHalf);
					
					TH.DetailsX = new int[TotalSize];
					TH.DetailsY = new int[TotalSize];
					TH.DetailsOldValue = new int[TotalSize];
	
					int RunningIndex = 0;
					int cLength = 0;
					for(int i=0;i<TTD.DetailLayersCount;i++){
						cLength = TTD.DetailsI[i];
						if(cLength < 1){ continue; }
						System.Array.Copy(TTD.DetailsX[i].ToArray(),0,TH.DetailsX,RunningIndex,cLength);
						System.Array.Copy(TTD.DetailsY[i].ToArray(),0,TH.DetailsY,RunningIndex,cLength);
						System.Array.Copy(TTD.OldDetailsValue[i].ToArray(),0,TH.DetailsOldValue,RunningIndex,cLength);
						RunningIndex += TTD.DetailsI[i];
					}
					
//                    TH.DetailsX = TTD.DetailsX;
//                    TH.DetailsY = TTD.DetailsY;
//                    TH.DetailsOldValue = TTD.OldDetailsValue;
                    TH.DetailsI = TTD.DetailsI;
                    TH.DetailLayersCount = TTD.DetailLayersCount;
                }else{
                    TH.DetailsX = null;
                    TH.DetailsY = null;
                    TH.DetailsOldValue = null;
                    TH.DetailsI = null;
                    TH.DetailLayersCount = 0;
                }
                //Trees:
                if(tRoad.opt_TreeModEnabled){
					if(TTD.TreesOld != null){
	                    TH.MakeGSDTrees(ref TTD.TreesOld);
						TTD.TreesOld.Clear();
						TTD.TreesOld = null;
	                    TH.TreesI = TTD.TreesI;
					}
                }else{
                    TH.TreesOld = null;
                    TH.TreesI = 0;
                }
            }
			
//			//TerrainHistoryRaw
//			if(tRoad.bProfiling){ Profiler.BeginSample("TerrainHistorySerialize"); }
//			TerrainHistorySerialize(ref tRoad);
//			if(tRoad.bProfiling){ Profiler.EndSample(); }
        }
Пример #52
0
		private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline,ref GSDRoad tRoad, bool bMultithreaded){			
			if(tRoad.bProfiling){ Profiler.BeginSample("ProcessRoad_Terrain_Hook1_Do"); }
			//First lets make sure all terrains have GSD shit on them:
			CheckAllTerrains();
			
			//Reset the terrain:
			if(tRoad.bProfiling){ Profiler.BeginSample("TerrainsReset"); }
			GSDTerraforming.TerrainsReset(tRoad);
			if(tRoad.bProfiling){ Profiler.EndSample(); }

			float heightDistance = tRoad.opt_MatchHeightsDistance;
//			float treeDistance = tRoad.opt_ClearTreesDistance;
			float detailDistance = tRoad.opt_ClearDetailsDistance;
				
			Dictionary<Terrain,TempTerrainData> TempTerrainDict = new Dictionary<Terrain, TempTerrainData>();
			//Populate dictionary:
			Object[] tTerrains = GameObject.FindObjectsOfType(typeof(Terrain));
			GSDTerrain TID;
			int aSize = 0;
			int dSize = 0;
			TempTerrainData TTD;
			bool bContains = false;
			GSDRoadUtil.Construction2DRect tRect = null;
//			GSDRoadUtil.Construction2DRect rRect = null;
			foreach(Terrain tTerrain in tTerrains){
				tRect = GetTerrainBounds(tTerrain);
				bContains = false;
                //Debug.Log(tTerrain.transform.name + " bounds: " + tRect.ToStringGSD());
                //Debug.Log("  Road bounds: " + tSpline.RoadV0 + "," + tSpline.RoadV1 + "," + tSpline.RoadV2 + "," + tSpline.RoadV3);

                if (bContains != true && tRect.Contains(ref tSpline.RoadV0)) {
                    bContains = true;
                } else if (bContains != true && tRect.Contains(ref tSpline.RoadV1)) {
                    bContains = true;
                } else if (bContains != true && tRect.Contains(ref tSpline.RoadV2)) {
                    bContains = true;
                } else if (bContains != true && tRect.Contains(ref tSpline.RoadV3)) {
                    bContains = true;
                } else {
                    int mCount3 = tRoad.GSDSpline.GetNodeCount();
                    Vector2 tVect2D_321 = default(Vector2);
                    for (int i = 0; i < mCount3; i++) {
                        tVect2D_321 = new Vector2(tRoad.GSDSpline.mNodes[i].pos.x, tRoad.GSDSpline.mNodes[i].pos.z);
                        if (tRect.Contains(ref tVect2D_321)) {
                            bContains = true;
                            break;
                        }
                    }

                    if (!bContains) {
                        float tDef = 5f / tSpline.distance;
                        Vector2 x2D = default(Vector2);
                        Vector3 x3D = default(Vector3);
                        for (float i = 0f; i <= 1f; i += tDef) {
                            x3D = tSpline.GetSplineValue(i);
                            x2D = new Vector2(x3D.x, x3D.z);
                            if (tRect.Contains(ref x2D)) {
                                bContains = true;
                                break;
                            }
                        }
                    }
                }
				
//				rRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(tSpline.RoadV0,tSpline.RoadV1,tSpline.RoadV2,tSpline.RoadV3);
				
				
				if(bContains && !TempTerrainDict.ContainsKey(tTerrain)){
					TTD = new TempTerrainData();
					TTD.HM = tTerrain.terrainData.heightmapResolution;			
					TTD.HMHeight = tTerrain.terrainData.heightmapHeight;
					TTD.heights = tTerrain.terrainData.GetHeights(0,0,tTerrain.terrainData.heightmapWidth,tTerrain.terrainData.heightmapHeight);
					TTD.HMRatio = TTD.HM / tTerrain.terrainData.size.x;
					TTD.MetersPerHM = tTerrain.terrainData.size.x / tTerrain.terrainData.heightmapResolution;
					float DetailRatio = tTerrain.terrainData.detailResolution / tTerrain.terrainData.size.x;
					
					//Heights:
					if(tRoad.bProfiling){ Profiler.BeginSample("Heights"); }
					if(tRoad.opt_HeightModEnabled){
						aSize = (int)tSpline.distance * ((int)(heightDistance*1.65f*TTD.HMRatio)+2);
						if(aSize > (tTerrain.terrainData.heightmapResolution * tTerrain.terrainData.heightmapResolution)){
							aSize = tTerrain.terrainData.heightmapResolution * tTerrain.terrainData.heightmapResolution;	
						}
						TTD.cX = new ushort[aSize];
						TTD.cY = new ushort[aSize];
						TTD.oldH = new float[aSize];
						TTD.cH = new float[aSize];		
						TTD.cI = 0;
						TTD.TerrainMaxIndex = tTerrain.terrainData.heightmapResolution;
						TTD.TerrainSize = tTerrain.terrainData.size;
						TTD.TerrainPos = tTerrain.transform.position;
						TTD.tHeights = new bool[tTerrain.terrainData.heightmapWidth,tTerrain.terrainData.heightmapHeight];
						TID = tTerrain.transform.gameObject.GetComponent<GSDTerrain>();
						if(TID != null){
							TTD.GSDID = TID.GSDID;
							TempTerrainDict.Add(tTerrain,TTD);	
						}
					}
					if(tRoad.bProfiling){ Profiler.EndSample(); }
			
					//Details:
					if(tRoad.bProfiling){ Profiler.BeginSample("Details"); }
					if(tRoad.opt_DetailModEnabled){
//						TTD.DetailValues = new Dictionary<int, int[,]>();
						TTD.DetailLayersCount = tTerrain.terrainData.detailPrototypes.Length;	
//						TTD.DetailHasProcessed = new Dictionary<int, bool[,]>();
						TTD.DetailHasProcessed = new HashSet<int>();
						TTD.MainDetailsX = new List<ushort>();
						TTD.MainDetailsY = new List<ushort>();
						TTD.DetailsI = new int[TTD.DetailLayersCount];
						TTD.DetailToHeightRatio = (float)((float)tTerrain.terrainData.detailResolution) / ((float)tTerrain.terrainData.heightmapResolution);
						TTD.DetailMaxIndex = tTerrain.terrainData.detailResolution;
						TTD.DetailLayersSkip = new HashSet<int>();
						
						// Get all of layer zero.
//						int[] mMinMaxDetailEntryCount = new int[TTD.DetailLayersCount];
//						if(tRoad.bProfiling){ Profiler.BeginSample("DetailValues"); }
//						Vector3 bVect = default(Vector3);
//						Vector2 bVect2D = default(Vector2);
//						int DetailRes = tTerrain.terrainData.detailResolution;
//						for(int i=0;i<TTD.DetailLayersCount;i++){
//							int[,] tInts = tTerrain.terrainData.GetDetailLayer(0,0,tTerrain.terrainData.detailWidth,tTerrain.terrainData.detailHeight,i);
//							int Length1 = tInts.GetLength(0);
//							int Length2 = tInts.GetLength(1);
//							for (int y=0;y < Length1;y++){
//								for (int x=0;x < Length2;x++){
//									if(tInts[x,y] > 0){
//										bVect = new Vector3(((float)y/(float)DetailRes) * TTD.TerrainSize.x,0f,((float)x/(float)DetailRes) * TTD.TerrainSize.z);
//										bVect = tTerrain.transform.TransformPoint(bVect);
//										bVect2D = new Vector2(bVect.z,bVect.x);
//										if(rRect.Contains(ref bVect2D)){
//											mMinMaxDetailEntryCount[i] += 1;
//										}
//									}
//								}
//							}
							
//							if(mMinMaxDetailEntryCount[i] < 1){
//								TTD.DetailLayersSkip.Add(i);
//								tInts = null;
//							}else{
//								TTD.DetailValues.Add(i,tInts);
//								TTD.DetailHasProcessed.Add(i,new bool[tTerrain.terrainData.detailWidth,tTerrain.terrainData.detailHeight]);
//							}
//						}
//						if(tRoad.bProfiling){ Profiler.EndSample(); }
						

						dSize = (int)tSpline.distance * ((int)(detailDistance*3f*DetailRatio)+2);
						if(dSize > (tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution)){
							dSize = tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution;	
						}
						
//						TTD.DetailsX = new List<ushort[]>();
//						TTD.DetailsY = new List<ushort[]>();
//						TTD.OldDetailsValue = new List<ushort[]>();
						TTD.DetailsX = new List<List<ushort>>();
						TTD.DetailsY = new List<List<ushort>>();
						TTD.OldDetailsValue = new List<List<ushort>>();
//						TTD.DetailHasProcessed = new List<List<bool>>();
						
						for(int i=0;i<TTD.DetailLayersCount;i++){
//							if(TTD.DetailLayersSkip.Contains(i)){ 
//								TTD.DetailsX.Add(new ushort[0]);
//								TTD.DetailsY.Add(new ushort[0]);
//								TTD.OldDetailsValue.Add(new ushort[0]);
//								continue; 
//							}
//							int detailentrycount = (int)((float)mMinMaxDetailEntryCount[i] * 1.5f);
//							int d_temp_Size = dSize;
//							if(d_temp_Size > detailentrycount){ d_temp_Size = detailentrycount; }
//							if(d_temp_Size < 1){ d_temp_Size = 1; }
//							if(d_temp_Size > (tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution)){
//								d_temp_Size = tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution;	
//							}
//
//							TTD.DetailsX.Add(new ushort[d_temp_Size]);
//							TTD.DetailsY.Add(new ushort[d_temp_Size]);
//							TTD.OldDetailsValue.Add(new ushort[d_temp_Size]);
							
							TTD.DetailsX.Add(new List<ushort>());
							TTD.DetailsY.Add(new List<ushort>());
							TTD.OldDetailsValue.Add(new List<ushort>());
						}
						
						
//						TTD.DetailsX = new ushort[TTD.DetailLayersCount,dSize];
//						TTD.DetailsY = new ushort[TTD.DetailLayersCount,dSize];
//						TTD.OldDetailsValue = new ushort[TTD.DetailLayersCount,dSize];
				

					}
					if(tRoad.bProfiling){ Profiler.EndSample(); }
					
					//Trees:
					if(tRoad.bProfiling){ Profiler.BeginSample("Trees"); }
					if(tRoad.opt_TreeModEnabled){
//						TTD.TreesCurrent = tTerrain.terrainData.treeInstances;
						TTD.TreesCurrent = new List<TreeInstance>(tTerrain.terrainData.treeInstances);
						TTD.TreeSize = TTD.TreesCurrent.Count;
						TTD.TreesI = 0;
						TTD.TreesOld = new List<TreeInstance>();
					}
					if(tRoad.bProfiling){ Profiler.EndSample(); }
				}
			}
				
			//Figure out relevant TTD to spline:
			List<TempTerrainData> EditorTTDList = new List<TempTerrainData>();
			if(TempTerrainDict != null){
				foreach(Terrain tTerrain in tTerrains){
					if(TempTerrainDict.ContainsKey(tTerrain)){
						EditorTTDList.Add(TempTerrainDict[tTerrain]);
					}
				}
			}
			
			if(tRoad.bProfiling){ Profiler.EndSample(); }
				
			//Start job now, for each relevant TTD:
			tRoad.EditorTerrainCalcs(ref EditorTTDList);
			if(bMultithreaded){
				GSD.Threaded.TerrainCalcs tJob = new GSD.Threaded.TerrainCalcs();
				tJob.Setup(ref EditorTTDList,tSpline,tRoad);
				tRoad.TerrainCalcsJob = tJob;
				tJob.Start();
			}else{
				GSD.Threaded.TerrainCalcs_Static.RunMe(ref EditorTTDList,tSpline,tRoad);
			}
		}