private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float param,ref Vector3 tVect1,ref Vector3 POS1,ref Vector3 tVect2,ref Vector3 POS2, float Sep, float TreeSep, ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, ref GSDSplineC tSpline)
        {
            Vector3 lVect1far = default(Vector3);
            Vector3 rVect1far = default(Vector3);
            Vector3 lVect2far = default(Vector3);
            Vector3 rVect2far = default(Vector3);

            bool bIsInBridge = tSpline.IsInBridgeTerrain(param);
            bool bIsInTunnel = tSpline.IsInTunnelTerrain(param);
            int x2,y2,x3,y3;
            GetTempHeights_Coordinates(ref tVect1,ref TTD,out x2,out y2);
            if(x2 >= TTD.HM){ x2=-1; }
            if(y2 >= TTD.HM){ y2=-1; }
            if(x2 < 0){ x2=-1; }
            if(y2 < 0){ y2=-1; }
            if(x2 == -1){ return null; }
            if(y2 == -1){ return null; }

            float tDiff1 = ((TTD.heights[x2,y2]*(float)TTD.TerrainSize.y) - tVect1.y);
            GetTempHeights_Coordinates(ref tVect2,ref TTD,out x3,out y3);
            if(x3 >= TTD.HM){ x3=-1; }
            if(y3 >= TTD.HM){ y3=-1; }
            if(x3 < 0){ x3=-1; }
            if(y3 < 0){ y3=-1; }
            if(x3 == -1){ return null; }
            if(y3 == -1){ return null; }
            float tDiff2 = ((TTD.heights[x3,y3]*(float)TTD.TerrainSize.y) - tVect2.y);

            GSD.Roads.GSDRoadUtil.Construction2DRect tRect = null;
            if(tSpline.tRoad.opt_TreeModEnabled){
                bool bQuit = false;
                if(x2 == -1){ bQuit = true; }
                if(y2 == -1){ bQuit = true; }

                if(bIsInBridge && !bQuit){
                    if(tDiff1 < 0f){ tDiff1 *= -1f; }
                    if(tDiff2 < 0f){ tDiff2 *= -1f; }
                    if(tDiff1 > tSpline.tRoad.opt_ClearTreesDistanceHeight){
                        bQuit = true;
                    }
                    if(tDiff2 > tSpline.tRoad.opt_ClearTreesDistanceHeight){
                        bQuit = true;
                    }
                }
                if(bIsInTunnel && !bQuit){
                    if(tDiff1 < 0f){
                        if((tDiff1*-1f) > tSpline.tRoad.opt_ClearTreesDistanceHeight){
                            bQuit = true;
                        }
                    }else{
                        if(tDiff1 > (tSpline.tRoad.opt_ClearTreesDistanceHeight*0.1f)){
                            bQuit = true;
                        }
                    }
                    if(tDiff2 < 0f){
                        if((tDiff2*-1f) > tSpline.tRoad.opt_ClearTreesDistanceHeight){
                            bQuit = true;
                        }
                    }else{
                        if(tDiff2 > (tSpline.tRoad.opt_ClearTreesDistanceHeight*0.1f)){
                            bQuit = true;
                        }
                    }
                }

                if(!bQuit){
                    TreeSep = TreeSep * 0.5f;
                    lVect1far = (tVect1 + new Vector3(TreeSep*-POS1.normalized.z,0,TreeSep*POS1.normalized.x));
                    rVect1far = (tVect1 + new Vector3(TreeSep*POS1.normalized.z,0,TreeSep*-POS1.normalized.x));
                    lVect2far = (tVect2 + new Vector3(TreeSep*-POS2.normalized.z,0,TreeSep*POS2.normalized.x));
                    rVect2far = (tVect2 + new Vector3(TreeSep*POS2.normalized.z,0,TreeSep*-POS2.normalized.x));
                    tRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(new Vector2(lVect1far.x,lVect1far.z),new Vector2(rVect1far.x,rVect1far.z),new Vector2(rVect2far.x,rVect2far.z),new Vector2(lVect2far.x,lVect2far.z),0f);
                }
            }

            if(tSpline.tRoad.opt_DetailModEnabled){
                if(bIsInBridge || bIsInTunnel){
                    if(tDiff1 < 0f){ tDiff1 *= -1f; }
                    if(tDiff2 < 0f){ tDiff2 *= -1f; }

                    bool bQuit = false;
                    if(x2 == -1){ bQuit = true; }
                    if(y2 == -1){ bQuit = true; }

                    if(tDiff1 > tSpline.tRoad.opt_ClearDetailsDistanceHeight){
                        bQuit = true;
                    }
                    if(tDiff2 > tSpline.tRoad.opt_ClearDetailsDistanceHeight){
                        bQuit = true;
                    }

                    if(bQuit){
                        return tRect;
                    }
                }

                Sep = Sep * 0.5f;

                lVect1far = (tVect1 + new Vector3(Sep*-POS1.normalized.z,0,Sep*POS1.normalized.x));
                rVect1far = (tVect1 + new Vector3(Sep*POS1.normalized.z,0,Sep*-POS1.normalized.x));
                lVect2far = (tVect2 + new Vector3(Sep*-POS2.normalized.z,0,Sep*POS2.normalized.x));
                rVect2far = (tVect2 + new Vector3(Sep*POS2.normalized.z,0,Sep*-POS2.normalized.x));

                int[] Xs = new int[4];
                int[] Ys = new int[4];

                int x1,y1;
                GetTempDetails_Coordinates(ref lVect1far,ref TTD,out x1, out y1);
                Xs[0] = x1;
                Ys[0] = y1;
                GetTempDetails_Coordinates(ref lVect2far,ref TTD,out x1, out y1);
                Xs[1] = x1;
                Ys[1] = y1;
                GetTempDetails_Coordinates(ref rVect1far,ref TTD,out x1, out y1);
                Xs[2] = x1;
                Ys[2] = y1;
                GetTempDetails_Coordinates(ref rVect2far,ref TTD,out x1, out y1);
                Xs[3] = x1;
                Ys[3] = y1;
            //
            //				if(TTD.DetailLayersCount == 1 && x1 > 0 && y1 > 0){
            //					Debug.Log(Xs[0]+","+Ys[0] + " " + Xs[1]+","+Ys[1]);
            //				}

                int MinX = Mathf.Min(Xs);
                int MinY = Mathf.Min(Ys);
                int MaxX = Mathf.Max(Xs);
                int MaxY = Mathf.Max(Ys);

                if(MinX >= TTD.DetailMaxIndex){ MinX = TTD.DetailMaxIndex-1; }
                if(MinY >= TTD.DetailMaxIndex){ MinY = TTD.DetailMaxIndex-1; }
                if(MaxX >= TTD.DetailMaxIndex){ MaxX = TTD.DetailMaxIndex-1; }
                if(MaxY >= TTD.DetailMaxIndex){ MaxY = TTD.DetailMaxIndex-1; }

                if(MinX < 0){ MinX = 0; }
                if(MinY < 0){ MinY = 0; }
                if(MaxX < 0){ MaxX = 0; }
                if(MaxY < 0){ MaxY = 0; }

            //				int DetailI = 0;
                if(tSpline.tRoad.bProfiling){ Profiler.BeginSample("Dorectsdetails"); }
                int tInt = 0;
                for(int i=MinX;i<=MaxX;i++){
                    for(int k=MinY;k<=MaxY;k++){
                        //Bitfield for identification:
                        tInt = k;
                        tInt = tInt << 16;
               			 		tInt = tInt | (ushort)i;
                        if(!TTD.DetailHasProcessed.Contains(tInt)){
            //							for(int h=0;h<TTD.DetailLayersCount;h++){
            //								if(TTD.DetailLayersSkip.Contains(h)){ continue; }
            //							if(!TTD.DetailHasProcessed[h][i,k]){// && TTD.DetailValues[h][i,k] > 0){

                            TTD.MainDetailsX.Add((ushort)i);
                            TTD.MainDetailsY.Add((ushort)k);

            //								DetailI = TTD.DetailsI[h];

            //								TTD.DetailsX[h].Add((ushort)i);
            //								TTD.DetailsY[h].Add((ushort)k);

            //								TTD.DetailsX[h][DetailI] = (ushort)i;
            //								TTD.DetailsY[h][DetailI] = (ushort)k;
            //								TTD.OldDetailsValue[h][DetailI] = (ushort)TTD.DetailValues[h][i,k];
            //								TTD.DetailValues[h][i,k] = 0;

            //								TTD.DetailsI[h]+=1;

            //							}
                            TTD.DetailHasProcessed.Add(tInt);
                        }
                    }
                }
                if(tSpline.tRoad.bProfiling){ Profiler.EndSample(); }
            }

            return tRect;
        }
        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;
            }
        }
        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(); }
        }
 public void ConstructBoundsRect()
 {
     BoundsRect = null;
     BoundsRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(new Vector2(CornerRR.x, CornerRR.z), new Vector2(CornerRL.x, CornerRL.z), new Vector2(CornerLR.x, CornerLR.z), new Vector2(CornerLL.x, CornerLL.z));
 }