private static Vector3 StopSign_GetRot_LR(GSDRoadIntersection GSDRI, GSDSplineC tSpline)
        {
            float tDist = ((Vector3.Distance(GSDRI.CornerRR, GSDRI.CornerLR) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerRL))) / tSpline.distance;;
            float p     = -1f;

            if (GSDRI.bFlipped)
            {
                p = Mathf.Clamp(GSDRI.Node2.tTime + tDist, 0f, 1f);
            }
            else
            {
                p = Mathf.Clamp(GSDRI.Node2.tTime - tDist, 0f, 1f);
            }
            Vector3 POS = tSpline.GetSplineValue(p, true);

            //POS = Vector3.Cross(POS,Vector3.up);
            if (GSDRI.bFlipped)
            {
                return(POS);
            }
            else
            {
                return(POS * -1);
            }
        }
Пример #2
0
        /// <summary>
        /// This will create an intersection if two nodes overlap on the road. Only good if the roads only overlap once.
        /// </summary>
        /// <param name="bRoad"></param>
        /// <param name="tRoad"></param>
        private static void UnitTest_IntersectionHelper(GSDRoad bRoad, GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType, GSDRoadIntersection.RoadTypeEnum rType)
        {
            GSDSplineN tInter1 = null;
            GSDSplineN tInter2 = null;

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

            if (tInter1 != null && tInter2 != null)
            {
                GameObject          tInter = GSD.Roads.GSDIntersections.CreateIntersection(tInter1, tInter2);
                GSDRoadIntersection GSDRI  = tInter.GetComponent <GSDRoadIntersection>();
                GSDRI.iStopType = iStopType;
                GSDRI.rType     = rType;
            }
        }
        private static Vector3 StopSign_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC tSpline)
        {
            float   tDist = ((Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerLL) / 2f) + (0.025f * Vector3.Distance(GSDRI.CornerLL, GSDRI.CornerRR))) / tSpline.distance;;
            float   p     = Mathf.Clamp(GSDRI.Node1.tTime + tDist, 0f, 1f);
            Vector3 POS   = tSpline.GetSplineValue(p, true);

            return(POS);
        }
Пример #4
0
        private static Vector3 TrafficLightBase_GetRot_LR(GSDRoadIntersection GSDRI, GSDSplineC tSpline, float DistFromCorner, bool bOverrideRegular = false)
        {
            Vector3 POS = default;

            if (!GSDRI.bRegularPoleAlignment && !bOverrideRegular)
            {
                //				float tDist = ((Vector3.Distance(GSDRI.CornerLR,GSDRI.CornerLL) / 2f) + DistFromCorner) / tSpline.distance;;
                float p = Mathf.Clamp(GSDRI.Node1.tTime, 0f, 1f);
                POS = tSpline.GetSplineValue(p, true);
                POS = Vector3.Cross(POS, Vector3.up);
                return(POS * -1);
            }
            else
            {
                POS = GSDRI.CornerRR - GSDRI.CornerLR;
                return(POS);
            }
        }
Пример #5
0
        /// <summary>
        /// Creates intersections where this road intersects with other roads.
        /// </summary>
        /// <param name="tRoad">The primary road to create intersections for.</param>
        /// <param name="iStopType">Stop signs, traffic lights #1 (US) or traffic lights #2 (Euro). Defaults to none.</param>
        /// <param name="rType">Intersection type: No turn lane, left turn lane or both turn lanes. Defaults to no turn lane.</param>
        public static void CreateIntersections_ProgrammaticallyForRoad(GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType = GSDRoadIntersection.iStopTypeEnum.None, GSDRoadIntersection.RoadTypeEnum rType = GSDRoadIntersection.RoadTypeEnum.NoTurnLane)
        {
            /*
             * General logic:
             * 20m increments to gather collection of which roads intersect
             *  2m increments to find actual intersection point
             *  each 2m, primary road checks all intersecting array for an intersection.
             * find intersection point
             *  if any intersections already within 75m or 100m, dont create intersection here
             *  check if nodes within 50m, if more than one just grab closest, and move  it to intersecting point
             *  if no node within 50m, add
             * create intersection with above two nodes
             */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

NoIntersectionCreation:
                            //Gibberish to get rid of warnings:
                            int xxx = 1;
                            if (xxx == 1)
                            {
                                xxx = 2;
                            }
                        }
                        if (EarlyDistanceFound)
                        {
                            break;
                        }
                    }
                }
            }
        }
Пример #6
0
	public float IntersectionStrength(ref Vector3 tPos, ref float nResult, ref GSDRoadIntersection tInter, ref bool bIsPast, ref float p, ref GSDSplineN fNode){
		int mCount = GetNodeCount();
		float tDist;
		GSDSplineN tNode;

        float MetersToCheck = 75f * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f));
		
		for(int i=0;i<mCount;i++){
			tNode = mNodes[i];
			if(tNode.bIsIntersection){
				tNode.GSDRI.Height = tNode.pos.y;
				GSDSplineN xNode;
				if(bUseSQ){
					tDist = Vector3.SqrMagnitude(tPos-tNode.pos);
				}
//				else{
//					tDist = Vector3.Distance(tPos,tNode.pos);
//				}
				
				if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
					if(bUseSQ){
                        MetersToCheck = MetersToCheck_NoTurnLaneSQ * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); ;
					}
//					else{
//						MetersToCheck = MetersToCheck_NoTurnLane;
//					}
				}else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
					if(bUseSQ){
                        MetersToCheck = MetersToCheck_TurnLaneSQ * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); ;
					}
//					else{
//						MetersToCheck = MetersToCheck_TurnLane;
//					}
				}else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
					if(bUseSQ){
                        MetersToCheck = MetersToCheck_BothTurnLaneSQ * ((tRoad.opt_LaneWidth / 5f) * (tRoad.opt_LaneWidth / 5f)); ;
					}
//					else{
//						MetersToCheck = MetersToCheck_BothTurnLane;
//					}
				}
				if(tRoad.opt_Lanes == 4){
					MetersToCheck *= 1.25f;
				}else if(tRoad.opt_Lanes == 6){
					MetersToCheck *= 1.35f;
				}
				
				if(tDist <= MetersToCheck){
					if(tNode.GSDRI.bSameSpline){
						if(tNode.GSDRI.Node1.UID != tNode.UID){
							xNode = tNode.GSDRI.Node1;
						}else{
							xNode = tNode.GSDRI.Node2;
						}
						
						float P1 = tNode.tTime - p; if(P1 < 0f){ P1 *= -1f; }
						float P2 = xNode.tTime - p; if(P2 < 0f){ P2 *= -1f; }
						
						if(P1 > P2){
							if(p > xNode.tTime){
								bIsPast = true;	
							}else{
								bIsPast = false;	
							}
							fNode = xNode;
						}else{
							if(p > tNode.tTime){
								bIsPast = true;	
							}else{
								bIsPast = false;	
							}
							fNode = tNode;
						}
					}else{
						if(p > tNode.tTime){
							bIsPast = true;	
						}else{
							bIsPast = false;	
						}
						fNode = tNode;
					}
					
					
					if(bUseSQ){
						tDist = Mathf.Sqrt(tDist);
						MetersToCheck = Mathf.Sqrt(MetersToCheck);
					}
					
					tInter = tNode.GSDRI;
					nResult = tNode.pos.y + 0.1f;
					tDist = 1f-(tDist / MetersToCheck);
					tDist = Mathf.Pow(tDist,3f) * 5f;
					if(tDist > 1f) tDist = 1f;
					if(tDist < 0f) tDist = 0f;
					return tDist;	
				}
			}
		}
		nResult = tPos.y;
		return 0f;
	}
        private static void InterFinalizeiBLane0(ref GSDSplineN xNode, ref GSDRoadIntersection GSDRI, ref float tIntHeight, bool bLRtoRR, bool bLLtoLR, bool bFirstInterNode)
        {
            if(xNode.iConstruction.bBLane0Done_Final){ return; }

            xNode.iConstruction.bBLane0Done = true;
            if(GSDRI.bFlipped && !bFirstInterNode){
                if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                    xNode.iConstruction.iBLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[4],tIntHeight));
                    xNode.iConstruction.iBLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[3],tIntHeight));
                }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                    xNode.iConstruction.iBLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[3],tIntHeight));
                    xNode.iConstruction.iBLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                }else{
                    xNode.iConstruction.iBLane0L.Add(GVC(GSDRI.fCornerRL_CornerRR[2],tIntHeight));
                    xNode.iConstruction.iBLane0R.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                }
            }else{
                if(bLRtoRR){
                    xNode.iConstruction.iBLane0L.Add(GVC(GSDRI.fCornerLR_CornerRR[0],tIntHeight));
                    xNode.iConstruction.iBLane0R.Add(GVC(GSDRI.fCornerLR_CornerRR[1],tIntHeight));
                }else if(bLLtoLR){
                    xNode.iConstruction.iBLane0L.Add(GVC(GSDRI.fCornerLL_CornerLR[0],tIntHeight));
                    xNode.iConstruction.iBLane0R.Add(GVC(GSDRI.fCornerLL_CornerLR[1],tIntHeight));
                }
            }
            xNode.iConstruction.bBLane0Done_Final = true;
            xNode.iConstruction.bBLane0Done_Final_ThisRound = true;
        }
Пример #8
0
        /// <summary>
        /// Creates intersections where this road intersects with other roads.
        /// </summary>
        /// <param name="tRoad">The primary road to create intersections for.</param>
        /// <param name="iStopType">Stop signs, traffic lights #1 (US) or traffic lights #2 (Euro). Defaults to none.</param>
        /// <param name="rType">Intersection type: No turn lane, left turn lane or both turn lanes. Defaults to no turn lane.</param>
        public static void CreateIntersections_ProgrammaticallyForRoad(GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType = GSDRoadIntersection.iStopTypeEnum.None, GSDRoadIntersection.RoadTypeEnum rType = GSDRoadIntersection.RoadTypeEnum.NoTurnLane) {
            /*
            General logic:
             20m increments to gather collection of which roads intersect
                2m increments to find actual intersection point
                each 2m, primary road checks all intersecting array for an intersection.
             find intersection point
                if any intersections already within 75m or 100m, dont create intersection here
                check if nodes within 50m, if more than one just grab closest, and move  it to intersecting point
                if no node within 50m, add
             create intersection with above two nodes
            */

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

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

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

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

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

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

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

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

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

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

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

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

                        NoIntersectionCreation:
                            //Gibberish to get rid of warnings:
                            int xxx = 1;
                            if (xxx == 1) { xxx = 2; }
                        }
                        if (EarlyDistanceFound) { break; }
                    }
                }
            }
        }
Пример #9
0
		private static void InitializeIntersectionObjects_Internal(GSDRoadIntersection GSDRI){			
			//1. Determine 3-way or 4-way. # of corners for 3-way: 2. 4-way = 4.
			if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){
				GSDRI.CornerPoints = new GSDRoadIntersection.CornerPositionMaker[2];
			}else{
				GSDRI.CornerPoints = new GSDRoadIntersection.CornerPositionMaker[4];
			}
			
			//Contains int IDs of connected nodes:			
			List<GSDSplineN> tList = new List<GSDSplineN>();
			//Get all connected nodes on intersection node1:
			int cCount = GSDRI.Node1.id_connected.Count;
			GSDSplineN tNode;
			for(int i=0;i<cCount;i++){
				//tNode = GetNodeByID(GSDRI.Node1.id_connected[i]);
				tNode = GSDRI.Node1.node_connected[i];
				if(!tList.Contains(tNode)){
					tList.Add(tNode);
				}
			}
			//Get all connected nodes on intersection node2:
			cCount = GSDRI.Node2.id_connected.Count;
			for(int i=0;i<cCount;i++){
				//tNode = GetNodeByID(GSDRI.Node2.id_connected[i]);
				tNode = GSDRI.Node2.node_connected[i];
				if(!tList.Contains(tNode)){
					tList.Add(tNode);
				}
			}
			//Declare connected nodes:
			GSDSplineN n1,n2,n3,n4;
			n1 = tList[0];
			n2 = tList[1];
			n3 = tList[2];
			n4 = null;
			if(tList.Count > 3){ n4 = tList[3]; }
			
			//Determine most relevant spline:
			GSDSplineC n1Spline = n1.GSDSpline;
			GSDSplineC n2Spline = n2.GSDSpline;
			GSDSplineC n3Spline = n3.GSDSpline;
			GSDSplineC n4Spline = null;
			if(n4 != null){ n4Spline = n4.GSDSpline; }
			
			//Get the point:
			Vector3 n1Point = GetFourCornerPoint(ref n1Spline,ref n1,GSDRI);
			Vector3 n2Point = GetFourCornerPoint(ref n2Spline,ref n2,GSDRI);
			Vector3 n3Point = GetFourCornerPoint(ref n3Spline,ref n3,GSDRI);
			Vector3 n4Point = new Vector3(0f,0f,0f);
			if(n4Spline != null){ n4Point = GetFourCornerPoint(ref n4Spline,ref n4,GSDRI); }
			
			//2. If 3 way, we know that 2 of the nodes have the same spline.
			if(1==1 && GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){
				//Should be size 3:
				if(tList.Count != 3){
					Debug.LogError("InitializeIntersections hashset != 3 connected on three way intersection, real size: " + tList.Count + " on intersection: " + GSDRI.transform.name);
					return;
				}
				
				ProcessFourCorners(ref n1Point,ref n2Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n1Spline,n2Spline));
				ProcessFourCorners(ref n1Point,ref n3Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n1Spline,n3Spline));
				ProcessFourCorners(ref n2Point,ref n3Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n2Spline,n3Spline));

			}else if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.FourWay){
				//Should be size 3:
				if(tList.Count != 4){
					Debug.LogError("InitializeIntersections hashset != 4 connected on four way intersection, real size: " + tList.Count + " on intersection: " + GSDRI.transform.name);
					return;
				}
				
				ProcessFourCorners(ref n1Point,ref n2Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n1Spline,n2Spline));
				ProcessFourCorners(ref n1Point,ref n3Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n1Spline,n3Spline));
				ProcessFourCorners(ref n1Point,ref n4Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n1Spline,n4Spline));
				ProcessFourCorners(ref n2Point,ref n3Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n2Spline,n3Spline));
				ProcessFourCorners(ref n2Point,ref n4Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n2Spline,n4Spline));
				ProcessFourCorners(ref n3Point,ref n4Point,GSDRI.transform.gameObject, GetLongestSplineDistance(n3Spline,n4Spline));
			}
		}
Пример #10
0
		private static void CreateIntersectionMesh_Outer(GSDRoadIntersection GSDRI,Vector3[] tVects, ref string tName){
			Vector3[] bVects1 = GetExtendedVectors(GSDRI);
			Vector3[] bVects2 = GetExtendedVectors(GSDRI,false);
			Vector3[] eVects = new Vector3[16];
			eVects[0] = tVects[1];
			eVects[1] = tVects[0];
			eVects[2] = bVects2[3];
			eVects[3] = bVects2[2];
			//
			eVects[4] = tVects[3];
			eVects[5] = tVects[1];
			eVects[6] = bVects1[3];
			eVects[7] = bVects1[2];
			//
			eVects[8] = tVects[2];
			eVects[9] = tVects[3];
			eVects[10] = bVects2[0];
			eVects[11] = bVects2[1];
			//
			eVects[12] = tVects[0];
			eVects[13] = tVects[2];
			eVects[14] = bVects1[0];
			eVects[15] = bVects1[1];

			int cCount = GSDRI.transform.childCount;
//			bool bOuter = false;
			GameObject tOuter = null;
			for(int i=0;i<cCount;i++){
				if(GSDRI.transform.GetChild(i).transform.name == "outer"){
					tOuter = GSDRI.transform.GetChild(i).transform.gameObject;
				}
			}
			if(!tOuter){
				tOuter = new GameObject("outer");
				tOuter.transform.parent = GSDRI.transform;
			}
			tOuter.transform.position = GSDRI.transform.position;

//			GameObject tObj;
//			tObj = GameObject.Find("tInter1"); tObj.transform.position = bVects2[0];
//			tObj = GameObject.Find("tInter2"); tObj.transform.position = bVects2[1];
//			tObj = GameObject.Find("tInter3"); tObj.transform.position = bVects2[2];
//			tObj = GameObject.Find("tInter4"); tObj.transform.position = bVects2[3];
			
			CreateIntersectionMesh_OuterInternal(eVects,tOuter,GSDRI.transform.position, ref tName);	
		}
Пример #11
0
		private static Vector3[] GetExtendedVectors(GSDRoadIntersection GSDRI, bool bPrimary = true){
			Vector3[] tVects = new Vector3[4];
			GSDSplineN tNode;
			if(bPrimary){
				tNode = GSDRI.Node1;
			}else{
				tNode = GSDRI.Node2;
			}
			GSDSplineC tSpline = tNode.GSDSpline;
			Vector3 NodePos = tNode.transform.position;
			
			float tOffset = tNode.GSDSpline.tRoad.RoadWidth(); 
			float tOffset2 = tOffset*0.5f;
			float tPos1 = tNode.tTime - (tOffset/tSpline.distance);
			float tPos2 = tNode.tTime + (tOffset/tSpline.distance);
			Vector3 tVect1 = tSpline.GetSplineValue(tPos1);	
			Vector3 tVect2 = tSpline.GetSplineValue(tPos2);	
			
			//Enforce distance:
			int SpamGuard = 0;
			int SGMax = 50;
			while(Vector3.Distance(tVect1,NodePos) < tOffset && SpamGuard < SGMax){ SpamGuard+=1;
				tPos1-=(1f/tSpline.distance);
				tVect1 = tSpline.GetSplineValue(tPos1);	
			} SpamGuard = 0;
			while(Vector3.Distance(tVect1,NodePos) > (tOffset*1.2f) && SpamGuard < SGMax){ SpamGuard+=1;
				tPos1+=(0.25f/tSpline.distance);
				tVect1 = tSpline.GetSplineValue(tPos1);	
			} SpamGuard = 0;
			while(Vector3.Distance(tVect2,NodePos) < tOffset && SpamGuard < SGMax){ SpamGuard+=1;
				tPos2+=(1f/tSpline.distance);
				tVect2 = tSpline.GetSplineValue(tPos2);	
			} SpamGuard = 0;
			while(Vector3.Distance(tVect1,NodePos) > (tOffset*1.2f) && SpamGuard < SGMax){ SpamGuard+=1;
				tPos2-=(0.25f/tSpline.distance);
				tVect2 = tSpline.GetSplineValue(tPos2);	
			}
			
			Vector3 POS1 = tSpline.GetSplineValue(tPos1,true);
			Vector3 POS2 = tSpline.GetSplineValue(tPos2,true);
			
			tVects[0] = (tVect1 + new Vector3(tOffset2*POS1.normalized.z,0,tOffset2*-POS1.normalized.x));
			tVects[1] = (tVect1 + new Vector3(tOffset2*-POS1.normalized.z,0,tOffset2*POS1.normalized.x));
			tVects[2] = (tVect2 + new Vector3(tOffset2*POS2.normalized.z,0,tOffset2*-POS2.normalized.x));
			tVects[3] = (tVect2 + new Vector3(tOffset2*-POS2.normalized.z,0,tOffset2*POS2.normalized.x));
			
			return tVects;
		}
Пример #12
0
		private static void FlattenIntersectionArea(ref List<GSDRoad> tRoads, GSDRoadIntersection GSDRI, float iWidth, out float tHeight){
			//Cycle through each road and get all mesh vertices that are within range:
			Vector3 tInterPos = GSDRI.transform.position;
			float tInterPosY = tInterPos.y;
			foreach(GSDRoad tRoad in tRoads){
				MeshFilter MF_Road = tRoad.MeshRoad.GetComponent<MeshFilter>();
				MeshFilter MF_Road_SR = tRoad.MeshShoR.GetComponent<MeshFilter>();
				MeshFilter MF_Road_SL = tRoad.MeshShoL.GetComponent<MeshFilter>();
				
				Mesh Road = MF_Road.sharedMesh;
				Mesh Road_SR = MF_Road_SR.sharedMesh;
				Mesh Road_SL = MF_Road_SL.sharedMesh;
				
				Vector3[] tVects = Road.vertices;
				Vector3[] tVects_SR = Road_SR.vertices;
				Vector3[] tVects_SL = Road_SL.vertices;
				int VertCount = Road.vertices.Length;
				bool bLeftToggle = true;
				for(int i=0;i<VertCount;i+=2){
					if(Vector3.Distance(tVects[i],tInterPos) < iWidth){
						tVects[i].y = tInterPosY;
						tVects[i+1].y = tInterPosY;
						if(bLeftToggle){
							//Left:
							tVects_SL[i+2].y = tInterPosY;
							tVects_SL[i+3].y = tInterPosY;
						}else{
							//Right:
							tVects_SR[i-2].y = tInterPosY;
							tVects_SR[i-1].y = tInterPosY;
						}
					}
					bLeftToggle = !bLeftToggle;
				}
				//Main road:
				Road.vertices = tVects;
				Road.RecalculateNormals();
				MF_Road.sharedMesh = Road;
				//Right shoulder:
				Road_SR.vertices = tVects_SR;
				Road_SR.RecalculateNormals();
				MF_Road_SR.sharedMesh = Road_SR;
				//Left shoulder:
				Road_SL.vertices = tVects_SL;
				Road_SL.RecalculateNormals();
				MF_Road_SL.sharedMesh = Road_SL;
			}
			tHeight = tInterPosY;
		}
Пример #13
0
		public static Vector3[] GetCornerVectors_Test(GSDRoadIntersection GSDRI){
			Vector3[] tVects = new Vector3[4];
			GSDSplineN tNode;
			tNode = GSDRI.Node1;
			GSDSplineC tSpline = tNode.GSDSpline;
			
			//RR = Node1 - 5, Node2 + 5
			//RL = Node1 + 5, Node2 + 5
			//LL = Node1 + 5, Node2 - 5
			//LR = Node1 - 5, Node2 - 5

			float tOffset = 5f;
			float tPos1 = tNode.tTime - (tOffset/tSpline.distance);
			float tPos2 = tNode.tTime + (tOffset/tSpline.distance);
			Vector3 tVect1 = tSpline.GetSplineValue(tPos1);	
			Vector3 POS1 = tSpline.GetSplineValue(tPos1,true);
			Vector3 tVect2 = tSpline.GetSplineValue(tPos2);	
			Vector3 POS2 = tSpline.GetSplineValue(tPos2,true);
	
			tVects[0] = (tVect1 + new Vector3(5f*POS1.normalized.z,0,5f*-POS1.normalized.x));
			tVects[1] = (tVect1 + new Vector3(5f*-POS1.normalized.z,0,5f*POS1.normalized.x));
			tVects[2] = (tVect2 + new Vector3(5f*POS2.normalized.z,0,5f*-POS2.normalized.x));
			tVects[3] = (tVect2 + new Vector3(5f*-POS2.normalized.z,0,5f*POS2.normalized.x));
			
			return tVects;
		}
Пример #14
0
        private static void ProcessPole(GameObject MasterGameObj, GameObject tObj, Vector3 tan, int tCorner, float InterDist)
        {
            GSDRoadIntersection GSDRI   = MasterGameObj.GetComponent <GSDRoadIntersection>();
            GSDSplineC          tSpline = GSDRI.Node1.GSDSpline;
            //			bool bIsRB = true;

            //			float RoadWidth = tSpline.tRoad.RoadWidth();
            float LaneWidth     = tSpline.tRoad.opt_LaneWidth;
            float ShoulderWidth = tSpline.tRoad.opt_ShoulderWidth;

            int   Lanes         = tSpline.tRoad.opt_Lanes;
            int   LanesHalf     = Lanes / 2;
            float LanesForInter = -1;

            if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes)
            {
                LanesForInter = LanesHalf + 1f;
            }
            else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane)
            {
                LanesForInter = LanesHalf + 1f;
            }
            else
            {
                LanesForInter = LanesHalf;
            }
            float DistFromCorner = (ShoulderWidth * 0.35f);
            float TLDistance     = (LanesForInter * LaneWidth) + DistFromCorner;

            MeshFilter MF    = tObj.GetComponent <MeshFilter>();
            Mesh       tMesh = MF.sharedMesh;

            Vector3[] tVerts   = tMesh.vertices;
            Vector3   StartVec = tVerts[520];
            Vector3   EndVec   = tVerts[521];

            StartVec = (((EndVec - StartVec) * (DistFromCorner / TLDistance)) + StartVec);
            Vector3 tempR_Start = tVerts[399];
            Vector3 tempR_End   = tVerts[396];
            Vector3 tLanePosR   = ((tempR_End - tempR_Start) * 0.95f) + tempR_Start;

            tLanePosR.z -= 1f;

            float SmallerDist = Vector3.Distance(StartVec, EndVec);

            //StartVec = Corner
            //2.5m = lane
            //7.5m = lane
            //12.5m = lane
            Vector3[] tLanePos = new Vector3[LanesHalf];
            for (int i = 0; i < LanesHalf; i++)
            {
                tLanePos[i] = (((EndVec - StartVec) * (((LaneWidth * 0.5f) + (i * LaneWidth)) / SmallerDist)) + StartVec);
            }
            Vector3 tLanePosL      = default;
            Vector3 tLanePosL_Sign = default;

            if (GSDRI.bLeftTurnYieldOnGreen)
            {
                tLanePosL      = ((EndVec - StartVec) * ((SmallerDist - 1.8f) / SmallerDist)) + StartVec;
                tLanePosL_Sign = ((EndVec - StartVec) * ((SmallerDist - 3.2f) / SmallerDist)) + StartVec;
            }
            else
            {
                tLanePosL = ((EndVec - StartVec) * ((SmallerDist - 2.5f) / SmallerDist)) + StartVec;
            }

            Vector3 tPos1 = default;

            if (tCorner == 0)
            { //RR
                tPos1 = GSDRI.CornerLR;
            }
            else if (tCorner == 1)
            { //RL
                tPos1 = GSDRI.CornerRR;
            }
            else if (tCorner == 2)
            { //LL
                tPos1 = GSDRI.CornerRL;
            }
            else if (tCorner == 3)
            { //LR
                tPos1 = GSDRI.CornerLL;
            }

            int   mCount    = tLanePos.Length;
            float mDistance = -50000f;
            float tDistance = 0f;

            for (int i = 0; i < mCount; i++)
            {
                tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePos[i]), tPos1);
                if (tDistance > mDistance)
                {
                    mDistance = tDistance;
                }
            }
            tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePosL), tPos1);
            if (tDistance > mDistance)
            {
                mDistance = tDistance;
            }
            tDistance = Vector3.Distance(tObj.transform.TransformPoint(tLanePosR), tPos1);
            if (tDistance > mDistance)
            {
                mDistance = tDistance;
            }

            float tScaleSense = ((200f - GSDRI.ScalingSense) / 200f) * 200f;

            tScaleSense = Mathf.Clamp(tScaleSense * 0.1f, 0f, 20f);
            float ScaleMod = ((mDistance / 17f) + tScaleSense) * (1f / (tScaleSense + 1f));

            if (IsApproximately(tScaleSense, 20f, 0.05f))
            {
                ScaleMod = 1f;
            }
            ScaleMod = Mathf.Clamp(ScaleMod, 1f, 1.5f);
            Vector3 tScale = new Vector3(ScaleMod, ScaleMod, ScaleMod);
            bool    bScale = true; if (IsApproximately(ScaleMod, 1f, 0.001f))
            {
                bScale = false;
            }

            //Debug.Log (mDistance + " " + ScaleMod + " " + tScaleSense);

            GameObject tRight     = null;
            GameObject tLeft      = null;
            GameObject tLeft_Sign = null;
            Object     prefab     = null;

            MeshRenderer MR_Left  = null;
            MeshRenderer MR_Right = null;

            MeshRenderer[] MR_Mains = new MeshRenderer[LanesHalf];
            int            cCount   = -1;

            if (GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane)
            {
                if (GSDRI.bLeftTurnYieldOnGreen)
                {
                    prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDTrafficLightLeftYield.prefab", typeof(GameObject));
                }
                else
                {
                    prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDTrafficLightLeft.prefab", typeof(GameObject));
                }
                tLeft = (GameObject)GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
                tLeft.transform.position = tObj.transform.TransformPoint(tLanePosL);
                tLeft.transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(0f, 90f, 0f);
                tLeft.transform.parent   = tObj.transform;
                tLeft.transform.name     = "LightLeft";

                cCount = tLeft.transform.childCount;
                for (int i = 0; i < cCount; i++)
                {
                    if (tLeft.transform.GetChild(i).name.ToLower() == "lights")
                    {
                        MR_Left = tLeft.transform.GetChild(i).GetComponent <MeshRenderer>();
                    }
                }

                if (bScale)
                {
                    tLeft.transform.localScale = tScale;
                }

                if (GSDRI.bLeftTurnYieldOnGreen)
                {
                    prefab     = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDSignYieldOnGreen.prefab", typeof(GameObject));
                    tLeft_Sign = (GameObject)GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
                    tLeft_Sign.transform.position = tObj.transform.TransformPoint(tLanePosL_Sign);
                    tLeft_Sign.transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(-90f, 90f, 0f);
                    tLeft_Sign.transform.parent   = tObj.transform;
                    tLeft_Sign.transform.name     = "SignYieldOnGreen";
                    if (bScale)
                    {
                        tLeft_Sign.transform.localScale = tScale;
                    }
                }
            }
            if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes)
            {
                prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDTrafficLightRight.prefab", typeof(GameObject));
                tRight = (GameObject)GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
                tRight.transform.position = tObj.transform.TransformPoint(tLanePosR);
                tRight.transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(0f, 90f, 0f);
                tRight.transform.parent   = tObj.transform;
                tRight.transform.name     = "LightRight";
                if (bScale)
                {
                    tRight.transform.localScale = tScale;
                }

                cCount = tRight.transform.childCount;
                for (int i = 0; i < cCount; i++)
                {
                    if (tRight.transform.GetChild(i).name.ToLower() == "lights")
                    {
                        MR_Right = tRight.transform.GetChild(i).GetComponent <MeshRenderer>();
                    }
                }
            }
            GameObject[] tLanes = new GameObject[LanesHalf];
            for (int i = 0; i < LanesHalf; i++)
            {
                prefab    = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDTrafficLightMain.prefab", typeof(GameObject));
                tLanes[i] = (GameObject)GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity);
                tLanes[i].transform.position = tObj.transform.TransformPoint(tLanePos[i]);
                tLanes[i].transform.rotation = Quaternion.LookRotation(tan) * Quaternion.Euler(0f, 90f, 0f);
                tLanes[i].transform.parent   = tObj.transform;
                tLanes[i].transform.name     = "Light" + i.ToString();
                if (bScale)
                {
                    tLanes[i].transform.localScale = tScale;
                }

                cCount = tLanes[i].transform.childCount;
                for (int j = 0; j < cCount; j++)
                {
                    if (tLanes[i].transform.GetChild(j).name.ToLower() == "lights")
                    {
                        MR_Mains[i] = tLanes[i].transform.GetChild(j).GetComponent <MeshRenderer>();
                    }
                }
            }

            GSDTrafficLightController LM = new GSDTrafficLightController(ref tLeft, ref tRight, ref tLanes, ref MR_Left, ref MR_Right, ref MR_Mains);

            if (tCorner == 0)
            {
                GSDRI.LightsRR = null;
                GSDRI.LightsRR = LM;
            }
            else if (tCorner == 1)
            {
                GSDRI.LightsRL = null;
                GSDRI.LightsRL = LM;
            }
            else if (tCorner == 2)
            {
                GSDRI.LightsLL = null;
                GSDRI.LightsLL = LM;
            }
            else if (tCorner == 3)
            {
                GSDRI.LightsLR = null;
                GSDRI.LightsLR = LM;
            }
        }
Пример #15
0
        private static void CreateTrafficLightMains(GameObject MasterGameObj, GameObject tRR, GameObject tRL, GameObject tLL, GameObject tLR)
        {
            GSDRoadIntersection GSDRI   = MasterGameObj.GetComponent <GSDRoadIntersection>();
            GSDSplineC          tSpline = GSDRI.Node1.GSDSpline;

            float   tDist = (Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerRR) / 2f) / tSpline.distance;
            Vector3 tan   = tSpline.GetSplineValue(GSDRI.Node1.tTime + tDist, true);

            ProcessPole(MasterGameObj, tRL, tan * -1, 1, Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerRR));
            tDist = (Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerLL) / 2f) / tSpline.distance;
            tan   = tSpline.GetSplineValue(GSDRI.Node1.tTime - tDist, true);
            ProcessPole(MasterGameObj, tLR, tan, 3, Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerLL));


            float InterDist = Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerLL);

            tDist = (InterDist / 2f) / tSpline.distance;
            tan   = tSpline.GetSplineValue(GSDRI.Node1.tTime + tDist, true);

            float fTime1    = GSDRI.Node2.tTime + tDist;
            float fTime2neg = GSDRI.Node2.tTime - tDist;

            tSpline = GSDRI.Node2.GSDSpline;
            if (GSDRI.bFlipped)
            {
                tan = tSpline.GetSplineValue(fTime1, true);
                ProcessPole(MasterGameObj, tRR, tan, 0, InterDist);
                tan = tSpline.GetSplineValue(fTime2neg, true);
                ProcessPole(MasterGameObj, tLL, tan * -1, 2, InterDist);
            }
            else
            {
                tan = tSpline.GetSplineValue(fTime2neg, true);
                ProcessPole(MasterGameObj, tRR, tan * -1, 0, InterDist);
                tan = tSpline.GetSplineValue(fTime1, true);
                ProcessPole(MasterGameObj, tLL, tan, 2, InterDist);
            }

            if (GSDRI.IgnoreCorner == 0)
            {
                if (tRR != null)
                {
                    Object.DestroyImmediate(tRR);
                }
            }
            else if (GSDRI.IgnoreCorner == 1)
            {
                if (tRL != null)
                {
                    Object.DestroyImmediate(tRL);
                }
            }
            else if (GSDRI.IgnoreCorner == 2)
            {
                if (tLL != null)
                {
                    Object.DestroyImmediate(tLL);
                }
            }
            else if (GSDRI.IgnoreCorner == 3)
            {
                if (tLR != null)
                {
                    Object.DestroyImmediate(tLR);
                }
            }
        }
Пример #16
0
 private static bool CreateTrafficLightBase_IsInIntersection(GSDRoadIntersection GSDRI, ref Vector3 StartVec, ref Vector3 EndVec)
 {
     return(GSDRI.ContainsLine(StartVec, EndVec));
 }
Пример #17
0
        private static void CreateTrafficLightBases_Do(ref GameObject MasterGameObj, bool bIsTrafficLight1)
        {
            GSDRoadIntersection GSDRI   = MasterGameObj.GetComponent <GSDRoadIntersection>();
            GSDSplineC          tSpline = GSDRI.Node1.GSDSpline;
            bool bIsRB = true;

            //			float RoadWidth = tSpline.tRoad.RoadWidth();
            float LaneWidth     = tSpline.tRoad.opt_LaneWidth;
            float ShoulderWidth = tSpline.tRoad.opt_ShoulderWidth;

            int   Lanes         = tSpline.tRoad.opt_Lanes;
            int   LanesHalf     = Lanes / 2;
            float LanesForInter = -1;

            if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes)
            {
                LanesForInter = LanesHalf + 1f;
            }
            else if (GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane)
            {
                LanesForInter = LanesHalf + 1f;
            }
            else
            {
                LanesForInter = LanesHalf - 1 + 1f;
            }
            float DistFromCorner = (ShoulderWidth * 0.45f);
            float TLDistance     = (LanesForInter * LaneWidth) + DistFromCorner;

            GameObject tObjRR = null;
            GameObject tObjRL = null;
            GameObject tObjLL = null;
            GameObject tObjLR = null;
            //			Vector3 xDir = default();
            Vector3 tDir     = default;
            float   Mass     = 12500f;
            Vector3 COM      = new Vector3(0f, 0f, 4f);
            Vector3 zeroVect = new Vector3(0f, 0f, 0f);
            Vector3 StartVec = default;
            Vector3 EndVec   = default;
            //			bool bContains = false;
            //			MeshFilter MF = null;
            //			Vector3[] tVerts = null;
            Rigidbody RB = null;

            //Get four points:
            Vector3 tPosRR = default;
            Vector3 tPosRL = default;
            Vector3 tPosLR = default;
            Vector3 tPosLL = default;

            GetFourPoints(GSDRI, out tPosRR, out tPosRL, out tPosLL, out tPosLR, DistFromCorner);

            //Cleanup:
            CleanupIntersections(MasterGameObj);

            float[] tempDistances = new float[4];
            tempDistances[0] = Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerLL);
            tempDistances[1] = Vector3.Distance(GSDRI.CornerRL, GSDRI.CornerRR);
            tempDistances[2] = Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerLL);
            tempDistances[3] = Vector3.Distance(GSDRI.CornerLR, GSDRI.CornerRR);
            float MaxDistanceStart  = Mathf.Max(tempDistances);
            bool  OrigPoleAlignment = GSDRI.bRegularPoleAlignment;

            //Node1:
            //RL:
            tObjRL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
            //			xDir = (GSDRI.CornerRL - GSDRI.transform.position).normalized;
            tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner);
            if (tDir == zeroVect)
            {
                tDir = new Vector3(0f, 0.0001f, 0f);
            }
            tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
            tObjRL.transform.parent   = MasterGameObj.transform;
            StartVec = tPosRL;
            EndVec   = (tDir.normalized * TLDistance) + StartVec;
            if (!GSDRI.bRegularPoleAlignment && GSDRI.ContainsLine(StartVec, EndVec))
            { //Convert to regular alignment if necessary
                tObjRL.transform.parent = null;
                tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner, true);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjRL.transform.parent   = MasterGameObj.transform;
            }
            else
            {
                GSDRI.bRegularPoleAlignment = true;
                if (tObjRL != null)
                {
                    Object.DestroyImmediate(tObjRL);
                }
                tObjRL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
                //				xDir = (GSDRI.CornerRL - GSDRI.transform.position).normalized;
                tDir = TrafficLightBase_GetRot_RL(GSDRI, tSpline, DistFromCorner);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjRL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjRL.transform.parent   = MasterGameObj.transform;
                StartVec = tPosRL;
                EndVec   = (tDir.normalized * TLDistance) + StartVec;
                GSDRI.bRegularPoleAlignment = OrigPoleAlignment;
            }
            if (bIsRB)
            {
                RB              = tObjRL.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = COM;
                tObjRL.AddComponent <GSDRigidBody>();
            }
            tObjRL.transform.position = tPosRL;
            tObjRL.transform.name     = "TrafficLightRL";
            //LR:
            tObjLR = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
            //			xDir = (GSDRI.CornerLR - GSDRI.transform.position).normalized;
            tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner);
            if (tDir == zeroVect)
            {
                tDir = new Vector3(0f, 0.0001f, 0f);
            }
            tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
            tObjLR.transform.parent   = MasterGameObj.transform;
            StartVec = tPosLR;
            EndVec   = (tDir.normalized * TLDistance) + StartVec;
            if (!GSDRI.bRegularPoleAlignment && GSDRI.ContainsLine(StartVec, EndVec))
            { //Convert to regular alignment if necessary
                tObjLR.transform.parent = null;
                tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner, true);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjLR.transform.parent   = MasterGameObj.transform;
            }
            else
            {
                GSDRI.bRegularPoleAlignment = true;
                if (tObjLR != null)
                {
                    Object.DestroyImmediate(tObjLR);
                }
                tObjLR = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
                //				xDir = (GSDRI.CornerLR - GSDRI.transform.position).normalized;
                tDir = TrafficLightBase_GetRot_LR(GSDRI, tSpline, DistFromCorner);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjLR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjLR.transform.parent   = MasterGameObj.transform;
                StartVec = tPosLR;
                EndVec   = (tDir.normalized * TLDistance) + StartVec;
                GSDRI.bRegularPoleAlignment = OrigPoleAlignment;
            }
            if (bIsRB)
            {
                RB              = tObjLR.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = COM;
                tObjLR.AddComponent <GSDRigidBody>();
            }
            tObjLR.transform.position = tPosLR;
            tObjLR.transform.name     = "TrafficLightLR";
            //Node2:
            //RR:
            tObjRR = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
            //			xDir = (GSDRI.CornerRR - GSDRI.transform.position).normalized;
            tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner);
            if (tDir == zeroVect)
            {
                tDir = new Vector3(0f, 0.0001f, 0f);
            }
            tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
            tObjRR.transform.parent   = MasterGameObj.transform;
            StartVec = tPosRR;
            EndVec   = (tDir.normalized * TLDistance) + StartVec;
            if (!GSDRI.bRegularPoleAlignment && GSDRI.ContainsLine(StartVec, EndVec))
            { //Convert to regular alignment if necessary
                tObjRR.transform.parent = null;
                tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner, true);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, 0f, 0f);
                tObjRR.transform.parent   = MasterGameObj.transform;
            }
            else
            {
                GSDRI.bRegularPoleAlignment = true;
                if (tObjRR != null)
                {
                    Object.DestroyImmediate(tObjRR);
                }
                tObjRR = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
                //				xDir = (GSDRI.CornerRR - GSDRI.transform.position).normalized;
                tDir = TrafficLightBase_GetRot_RR(GSDRI, tSpline, DistFromCorner);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjRR.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjRR.transform.parent   = MasterGameObj.transform;
                StartVec = tPosRR;
                EndVec   = (tDir.normalized * TLDistance) + StartVec;
                GSDRI.bRegularPoleAlignment = OrigPoleAlignment;
            }
            if (bIsRB)
            {
                RB              = tObjRR.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = COM;
                tObjRR.AddComponent <GSDRigidBody>();
            }
            tObjRR.transform.position = tPosRR;
            tObjRR.transform.name     = "TrafficLightRR";

            //LL:
            tObjLL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
            //			xDir = (GSDRI.CornerLL - GSDRI.transform.position).normalized;
            tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner);
            if (tDir == zeroVect)
            {
                tDir = new Vector3(0f, 0.0001f, 0f);
            }
            tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
            tObjLL.transform.parent   = MasterGameObj.transform;
            StartVec = tPosLL;
            EndVec   = (tDir.normalized * TLDistance) + StartVec;
            if (!GSDRI.bRegularPoleAlignment && GSDRI.ContainsLine(StartVec, EndVec))
            { //Convert to regular alignment if necessary
                tObjLL.transform.parent = null;
                tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner, true);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, 0f, 0f);
                tObjLL.transform.parent   = MasterGameObj.transform;
            }
            else
            {
                GSDRI.bRegularPoleAlignment = true;
                if (tObjLL != null)
                {
                    Object.DestroyImmediate(tObjLL);
                }
                tObjLL = CreateTrafficLight(TLDistance, true, true, MaxDistanceStart, GSDRI.bTrafficPoleStreetLight, tSpline.tRoad.GSDRS.opt_bSaveMeshes);
                //				xDir = (GSDRI.CornerLL - GSDRI.transform.position).normalized;
                tDir = TrafficLightBase_GetRot_LL(GSDRI, tSpline, DistFromCorner);
                if (tDir == zeroVect)
                {
                    tDir = new Vector3(0f, 0.0001f, 0f);
                }
                tObjLL.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(-90f, -180f, 0f);
                tObjLL.transform.parent   = MasterGameObj.transform;
                StartVec = tPosLL;
                EndVec   = (tDir.normalized * TLDistance) + StartVec;
                GSDRI.bRegularPoleAlignment = OrigPoleAlignment;
            }
            if (bIsRB)
            {
                RB              = tObjLL.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = COM;
                tObjLL.AddComponent <GSDRigidBody>();
            }
            tObjLL.transform.position = tPosLL;
            tObjLL.transform.name     = "TrafficLightLL";

            //Create the actual lights:
            CreateTrafficLightMains(MasterGameObj, tObjRR, tObjRL, tObjLL, tObjLR);
        }
        private static void CreateStopSignsAllWay_Do(ref GameObject MasterGameObj, bool bIsRB)
        {
            Object prefab = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/RoadArchitect/Mesh/RoadObj/Signs/GSDSignStopAllway.prefab", typeof(GameObject));

            GSDRoadIntersection GSDRI   = MasterGameObj.GetComponent <GSDRoadIntersection>();
            GSDSplineC          tSpline = GSDRI.Node1.GSDSpline;

            GameObject tObj = null;
            //			Vector3 xDir = default(Vector3);
            Vector3 tDir = default(Vector3);
            //			float RoadWidth = tSpline.tRoad.RoadWidth();
            //			float LaneWidth = tSpline.tRoad.opt_LaneWidth;
            float ShoulderWidth = tSpline.tRoad.opt_ShoulderWidth;

            //Cleanup:
            CleanupIntersections(MasterGameObj);

            float Mass = 100f;

            //Get four points:
            float   DistFromCorner = (ShoulderWidth * 0.45f);
            Vector3 tPosRR         = default(Vector3);
            Vector3 tPosRL         = default(Vector3);
            Vector3 tPosLR         = default(Vector3);
            Vector3 tPosLL         = default(Vector3);

            GetFourPoints(GSDRI, out tPosRR, out tPosRL, out tPosLL, out tPosLR, DistFromCorner);

            //RR:
            tSpline = GSDRI.Node1.GSDSpline;
            tObj    = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
            //			xDir = (GSDRI.CornerRR - GSDRI.transform.position).normalized;
            tDir = StopSign_GetRot_RR(GSDRI, tSpline);
            tObj.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(0f, 180f, 0f);
            if (bIsRB)
            {
                Rigidbody RB = tObj.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = new Vector3(0f, -10f, 0f);
            }
            tObj.transform.parent   = MasterGameObj.transform;
            tObj.transform.position = tPosRR;
            tObj.name = "StopSignRR";
            if (GSDRI.IgnoreCorner == 0)
            {
                Object.DestroyImmediate(tObj);
            }

            //LL:
            tSpline = GSDRI.Node1.GSDSpline;
            tObj    = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
            //			xDir = (GSDRI.CornerLL - GSDRI.transform.position).normalized;
            tDir = StopSign_GetRot_LL(GSDRI, tSpline);
            tObj.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(0f, 180f, 0f);
            if (bIsRB)
            {
                Rigidbody RB = tObj.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = new Vector3(0f, -10f, 0f);
            }
            tObj.transform.parent   = MasterGameObj.transform;
            tObj.transform.position = tPosLL;
            tObj.name = "StopSignLL";
            if (GSDRI.IgnoreCorner == 2)
            {
                Object.DestroyImmediate(tObj);
            }

            //RL:
            tSpline = GSDRI.Node2.GSDSpline;
            tObj    = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
            //			xDir = (GSDRI.CornerRL - GSDRI.transform.position).normalized;
            tDir = StopSign_GetRot_RL(GSDRI, tSpline);
            tObj.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(0f, 180f, 0f);
            if (bIsRB)
            {
                Rigidbody RB = tObj.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = new Vector3(0f, -10f, 0f);
            }
            tObj.transform.parent   = MasterGameObj.transform;
            tObj.transform.position = tPosRL;
            tObj.name = "StopSignRL";
            if (GSDRI.IgnoreCorner == 1)
            {
                Object.DestroyImmediate(tObj);
            }

            //LR:
            tSpline = GSDRI.Node2.GSDSpline;
            tObj    = Object.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
            //			xDir = (GSDRI.CornerLR - GSDRI.transform.position).normalized;
            tDir = StopSign_GetRot_LR(GSDRI, tSpline);
            tObj.transform.rotation = Quaternion.LookRotation(tDir) * Quaternion.Euler(0f, 180f, 0f);
            if (bIsRB)
            {
                Rigidbody RB = tObj.AddComponent <Rigidbody>();
                RB.mass         = Mass;
                RB.centerOfMass = new Vector3(0f, -10f, 0f);
            }
            tObj.transform.parent   = MasterGameObj.transform;
            tObj.transform.position = tPosLR;
            tObj.name = "StopSignLR";
            if (GSDRI.IgnoreCorner == 3)
            {
                Object.DestroyImmediate(tObj);
            }
        }
Пример #19
0
		public static void CreateIntersection(GSDRoadIntersection GSDRI){
			//1. Overlap sphere to find all road objects within intersection:
			float iWidth = GSDRI.IntersectionWidth*1.25f;
			Collider[] tColliders = Physics.OverlapSphere(GSDRI.transform.position,iWidth);
			if(tColliders == null || tColliders.Length < 1){ return; }
			List<GSDRoad> tRoads = new List<GSDRoad>();
			foreach(Collider tCollider in tColliders){
				if(tCollider.transform.parent){
					GSDRoad tRoad = tCollider.transform.parent.GetComponent<GSDRoad>();
					if(tRoad){
						if(!tRoads.Contains(tRoad)){
							tRoads.Add(tRoad);
						}
					}
				}
			}
			
			//Flatten intersection area:
			float tHeight = -1f;
			FlattenIntersectionArea(ref tRoads,GSDRI,iWidth,out tHeight);
			
			//Create main intersection mesh:
			string tName = GSDRI.transform.name;
			Vector3[] tVects;
			CreateIntersectionMesh_Main(GSDRI,tHeight,out tVects,ref tName);
			
			//Now create the 4 text overlays:
			CreateIntersectionMesh_Outer(GSDRI,tVects,ref tName);
			
			//Update connected nodes:
			GSDNavigation.UpdateConnectedNodes();
			
			//Now initialize intersection objects:
			InitializeIntersectionObjects(GSDRI);
		}
Пример #20
0
 public static void GetFourPoints(GSDRoadIntersection GSDRI, out Vector3 tPosRR, out Vector3 tPosRL, out Vector3 tPosLL, out Vector3 tPosLR, float DistFromCorner)
 {
     GetFourPoints_Do(ref GSDRI, out tPosRR, out tPosRL, out tPosLL, out tPosLR, DistFromCorner);
 }
Пример #21
0
		private static Vector3[] GetCornerVectors(GSDRoadIntersection GSDRI, bool bPrimary = true){
			Vector3[] tVects = new Vector3[4];
			GSDSplineN tNode;
			if(bPrimary){
				tNode = GSDRI.Node1;
			}else{
				tNode = GSDRI.Node2;
			}
			GSDSplineC tSpline = tNode.GSDSpline;
			
			float tOffset = 7f;
			float tPos1 = tNode.tTime - (tOffset/tSpline.distance);
			float tPos2 = tNode.tTime + (tOffset/tSpline.distance);
			Vector3 tVect1 = tSpline.GetSplineValue(tPos1);	
			Vector3 POS1 = tSpline.GetSplineValue(tPos1,true);
			Vector3 tVect2 = tSpline.GetSplineValue(tPos2);	
			Vector3 POS2 = tSpline.GetSplineValue(tPos2,true);
	
			tVects[0] = (tVect1 + new Vector3(5f*POS1.normalized.z,0,5f*-POS1.normalized.x));
			tVects[1] = (tVect1 + new Vector3(5f*-POS1.normalized.z,0,5f*POS1.normalized.x));
			tVects[2] = (tVect2 + new Vector3(5f*POS2.normalized.z,0,5f*-POS2.normalized.x));
			tVects[3] = (tVect2 + new Vector3(5f*-POS2.normalized.z,0,5f*POS2.normalized.x));
			
			return tVects;
		}
Пример #22
0
        static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 tPosRR, out Vector3 tPosRL, out Vector3 tPosLL, out Vector3 tPosLR, float DistFromCorner)
        {
            //Get four points:
            float   tPos1          = 0f;
            float   tPos2          = 0f;
            Vector3 tTan1          = default(Vector3);
            Vector3 tTan2          = default(Vector3);
            float   Node1Width     = -1f;
            float   Node2Width     = -1f;
            Vector3 tVectRR        = GSDRI.CornerRR;
            Vector3 tVectRL        = GSDRI.CornerRL;
            Vector3 tVectLR        = GSDRI.CornerLR;
            Vector3 tVectLL        = GSDRI.CornerLL;
            Vector3 tDir           = default(Vector3);
            float   ShoulderWidth1 = GSDRI.Node1.GSDSpline.tRoad.opt_ShoulderWidth;
            float   ShoulderWidth2 = GSDRI.Node2.GSDSpline.tRoad.opt_ShoulderWidth;

            if (!GSDRI.bFlipped)
            {
                //RR:
                Node1Width = (Vector3.Distance(GSDRI.CornerRR, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerRR, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime - Node1Width;
                tTan1      = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true) * -1f;
                tPos2      = GSDRI.Node2.tTime + Node2Width;
                tTan2      = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true);
                tDir       = (tTan1.normalized + tTan2.normalized).normalized;
                tPosRR     = tVectRR + (tDir * DistFromCorner);
                //RL:
                Node1Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime + Node1Width;
                if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay)
                {
                    tPos1 = GSDRI.Node1.tTime;
                }
                tTan1  = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true);
                tPos2  = GSDRI.Node2.tTime + Node2Width;
                tTan2  = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true);
                tDir   = (tTan1.normalized + tTan2.normalized).normalized;
                tPosRL = tVectRL + (tDir * DistFromCorner);
                //LL:
                Node1Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime + Node1Width;
                if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay)
                {
                    tPos1 = GSDRI.Node1.tTime;
                }
                tTan1  = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true);
                tPos2  = GSDRI.Node2.tTime - Node2Width;
                tTan2  = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f;
                tDir   = (tTan1.normalized + tTan2.normalized).normalized;
                tPosLL = tVectLL + (tDir * DistFromCorner);
                //LR:
                Node1Width = (Vector3.Distance(GSDRI.CornerLR, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerLR, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime - Node1Width;
                tTan1      = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true) * -1f;
                tPos2      = GSDRI.Node2.tTime - Node2Width;
                tTan2      = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f;
                tDir       = (tTan1.normalized + tTan2.normalized).normalized;
                tPosLR     = tVectLR + (tDir * DistFromCorner);
            }
            else
            {
                //RR:
                Node1Width = (Vector3.Distance(GSDRI.CornerRR, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerRR, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime - Node1Width;
                tTan1      = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true) * -1f;
                tPos2      = GSDRI.Node2.tTime - Node2Width;
                tTan2      = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f;
                tDir       = (tTan1.normalized + tTan2.normalized).normalized;
                tPosRR     = tVectRR + (tDir * DistFromCorner);
                //RL:
                Node1Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerRL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime + Node1Width;
                if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay)
                {
                    tPos1 = GSDRI.Node1.tTime;
                }
                tTan1  = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true);
                tPos2  = GSDRI.Node2.tTime - Node2Width;
                tTan2  = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true) * -1f;
                tDir   = (tTan1.normalized + tTan2.normalized).normalized;
                tPosRL = tVectRL + (tDir * DistFromCorner);
                //LL:
                Node1Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerLL, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime + Node1Width;
                if (GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay)
                {
                    tPos1 = GSDRI.Node1.tTime;
                }
                tTan1  = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true);
                tPos2  = GSDRI.Node2.tTime + Node2Width;
                tTan2  = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true);
                tDir   = (tTan1.normalized + tTan2.normalized).normalized;
                tPosLL = tVectLL + (tDir * DistFromCorner);
                //LR:
                Node1Width = (Vector3.Distance(GSDRI.CornerLR, GSDRI.Node1.pos) + ShoulderWidth1) / GSDRI.Node1.GSDSpline.distance;
                Node2Width = (Vector3.Distance(GSDRI.CornerLR, GSDRI.Node2.pos) + ShoulderWidth2) / GSDRI.Node2.GSDSpline.distance;
                tPos1      = GSDRI.Node1.tTime - Node1Width;
                tTan1      = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1, true) * -1f;
                tPos2      = GSDRI.Node2.tTime + Node2Width;
                tTan2      = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2, true);
                tDir       = (tTan1.normalized + tTan2.normalized).normalized;
                tPosLR     = tVectLR + (tDir * DistFromCorner);
            }
            tPosRR.y = GSDRI.SignHeight;
            tPosRL.y = GSDRI.SignHeight;
            tPosLL.y = GSDRI.SignHeight;
            tPosLR.y = GSDRI.SignHeight;

            //			GameObject tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //			tObj.transform.name = "temp22_RR";
            //			tObj.transform.position = tPosRR;
            //			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //			tObj.transform.name = "temp22_RL";
            //			tObj.transform.position = tPosRL;
            //			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //			tObj.transform.name = "temp22_LL";
            //			tObj.transform.position = tPosLL;
            //			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //			tObj.transform.name = "temp22_LR";
            //			tObj.transform.position = tPosLR;
        }
Пример #23
0
		private static void CreateIntersectionMesh_Main(GSDRoadIntersection GSDRI, float tHeight, out Vector3[] tVects,ref string tName){
			//Get four points:
			Vector3[] pVects = GetCornerVectors(GSDRI);
			Vector3[] sVects = GetCornerVectors(GSDRI,false);
			tVects = new Vector3[4];
			Vector3 oIntersection = new Vector3(0f,0f,0f);
			Vector3 oIntersection2 = new Vector3(0f,0f,0f);//Unused
			
//			bool bIntersection;
			ClosestPointsOnTwoLines(out oIntersection,out oIntersection2,pVects[0],(pVects[2]-pVects[0]),sVects[0],(sVects[2]-sVects[0]));
			tVects[0] = oIntersection;
			tVects[0].y = tHeight;
			
			ClosestPointsOnTwoLines(out oIntersection,out oIntersection2,pVects[0],(pVects[2]-pVects[0]),sVects[1],(sVects[3]-sVects[1]));
			tVects[1] = oIntersection;
			tVects[1].y = tHeight;
			
			ClosestPointsOnTwoLines(out oIntersection,out oIntersection2,pVects[1],(pVects[3]-pVects[1]),sVects[0],(sVects[2]-sVects[0]));
			tVects[2] = oIntersection;
			tVects[2].y = tHeight;
			
			ClosestPointsOnTwoLines(out oIntersection,out oIntersection2,pVects[1],(pVects[3]-pVects[1]),sVects[1],(sVects[3]-sVects[1]));
			tVects[3] = oIntersection;
			tVects[3].y = tHeight;
			
			CreateIntersectionMesh_MainInternal(tVects,GSDRI.transform.gameObject, ref tName);	
		}
Пример #24
0
		private static Vector3 StopSign_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC tSpline){
			float tDist = ((Vector3.Distance(GSDRI.CornerLR,GSDRI.CornerLL) / 2f) + (0.025f*Vector3.Distance(GSDRI.CornerLL,GSDRI.CornerRR))) / tSpline.distance;;
			float p = Mathf.Clamp(GSDRI.Node1.tTime+tDist,0f,1f);
			Vector3 POS = tSpline.GetSplineValue(p,true);
			return POS;
		}
Пример #25
0
		private static void InitializeIntersectionObjects(GSDRoadIntersection tGSDRI){
			if(tGSDRI != null){
				InitializeIntersectionObjects_Internal(tGSDRI);
			}else{
				Object[] iObjects = GameObject.FindObjectsOfType(typeof(GSDRoadIntersection));
				//Add intersection components, if necessary:
				foreach (GSDRoadIntersection GSDRI in iObjects){
					InitializeIntersectionObjects_Internal(GSDRI);
				}
			}
		}
Пример #26
0
		private static Vector3 StopSign_GetRot_LR(GSDRoadIntersection GSDRI, GSDSplineC tSpline){
			float tDist = ((Vector3.Distance(GSDRI.CornerRR,GSDRI.CornerLR) / 2f) + (0.025f*Vector3.Distance(GSDRI.CornerLR,GSDRI.CornerRL))) / tSpline.distance;;
			float p = -1f;
			if(GSDRI.bFlipped){
				p = Mathf.Clamp(GSDRI.Node2.tTime+tDist,0f,1f);
			}else{
				p = Mathf.Clamp(GSDRI.Node2.tTime-tDist,0f,1f);
			}
			Vector3 POS = tSpline.GetSplineValue(p,true);
			//POS = Vector3.Cross(POS,Vector3.up);
			if(GSDRI.bFlipped){
				return POS;
			}else{
				return (POS*-1);
			}
		}
Пример #27
0
		static Vector3 GetFourCornerPoint(ref GSDSplineC tSpline, ref GSDSplineN tNode, GSDRoadIntersection GSDRI){
			GSDSplineN iNode;
			if(tNode.node_connected.Contains(GSDRI.Node1)){
				iNode = GSDRI.Node1;	
			}else{
				iNode = GSDRI.Node2;
			}
			
			float Pos1 = tNode.tTime;
			float iPos = iNode.tTime;
			
			float tFloat = 0;
			float NewSplinePos = 0;
			if(iPos >= Pos1){
				tFloat = iPos - Pos1;
				tFloat = tFloat / 8;
				NewSplinePos = iPos - tFloat;
			}else{
				tFloat = Pos1 - iPos;
				tFloat = tFloat / 8;
				NewSplinePos = iPos + tFloat;
			}
			
			Vector3 tVect = new Vector3(0,0,0); 
			
			bool bDone = false;
			int spamguard = 0;
			float tDist = 0f;
			while(!bDone && spamguard < 20000){
				spamguard+=1;
				tVect = tSpline.GetSplineValue(NewSplinePos);
				tDist = Vector3.Distance(tVect,iNode.transform.position);
	
				if(tDist > 22f){
					//Get closer to intersection:
					if(iPos >= NewSplinePos){
						NewSplinePos += 0.001f;	
					}else{
						NewSplinePos -= 0.001f;
					}
				}else if(tDist < 20f){
					//Move away from intersection:
					if(iPos >= NewSplinePos){
						NewSplinePos -= 0.001f;	
					}else{
						NewSplinePos += 0.001f;
					}
				}else{
					bDone = true;	
				}
			}
			return tVect;
		}
Пример #28
0
		private static bool CreateTrafficLightBase_IsInIntersection(GSDRoadIntersection GSDRI,ref Vector3 StartVec,ref Vector3 EndVec){
			return GSDRI.ContainsLine(StartVec,EndVec);
		}
        private static Vector2[] ProcessRoad_UVs_Intersection_MainPlate2(ref GSD.Roads.RoadConstructorBufferMaker RCS, Vector3[] tVerts, GSDRoadIntersection GSDRI)
        {
            //Finally, adding texture coordinates to the mesh will enable it to display a material correctly.
            //Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture.
            //int MVL = tMesh.vertices.Length;
            int MVL = tVerts.Length;
            Vector2[] uv = new Vector2[MVL];
            int i=0;
            bool bOddToggle = true;
            //			float tDistance= 0f;
            float tDistanceLeft = 0f;
            float tDistanceRight = 0f;
            float tDistanceLeftSum = 0f;
            float tDistanceRightSum = 0f;
            //			float tDistanceSum = 0f;
            //			float DistRepresent = 5f;

            float mDistanceL = Vector3.Distance(tVerts[i+4],tVerts[tVerts.Length-3]);
            float mDistanceR = Vector3.Distance(tVerts[i+6],tVerts[tVerts.Length-1]);
            mDistanceL = mDistanceL * 1.125f;
            mDistanceR = mDistanceR * 1.125f;

            //			int bHitMaxL = 0;
            //			int bHitMaxR = 0;

            float tAdd1;
            float tAdd2;
            float tAdd3;
            float tAdd4;

            float RoadWidth = RCS.tRoad.RoadWidth();
            float LaneWidth = RCS.tRoad.opt_LaneWidth;
            float iWidth = -1;
            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                iWidth = RoadWidth + (LaneWidth*2f);
            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                iWidth = RoadWidth + (LaneWidth*1f);
            }else{
                iWidth = RoadWidth;
            }

            while(i+6 < MVL){
                if(i==0){

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

                        //(Lane width / 2)/roadwidth
                        //1-((lanewidth / 2)/roadwidth)

                        uv[i] = new Vector2((LaneWidth * 0.5f)/iWidth, 0f);
                        uv[i+2] = new Vector2(1f-(((LaneWidth * 0.5f) + LaneWidth)/iWidth), 0f);
                        //Debug.Log (GSDRI.tName + " " + uv[i+2].x);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        uv[i] = new Vector2((LaneWidth * 0.5f)/iWidth, 0f);
                        uv[i+2] = new Vector2(1f-((LaneWidth * 0.5f)/iWidth), 0f);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        uv[i] = new Vector2(0f, 0f);
                        uv[i+2] = new Vector2(1f, 0f);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }
                    tDistanceLeft = 0.125f;
                    tDistanceRight = 0.125f;
                }else{
                    tDistanceLeft = Vector3.Distance(tVerts[i],tVerts[i+4]);
                    tDistanceRight = Vector3.Distance(tVerts[i+2],tVerts[i+6]);
                    tDistanceLeft = tDistanceLeft / mDistanceL;
                    tDistanceRight = tDistanceRight / mDistanceR;

            //					if(bHitMaxL > 0 || (tDistanceLeftSum+tDistanceLeft) > 1f){
            //						tDistanceLeftSum = 0.998f + (0.0001f*bHitMaxL);
            //						tDistanceLeft = 0.001f;
            //						bHitMaxL+=1;
            //					}
            //					if(bHitMaxR > 0 || (tDistanceRightSum+tDistanceRight) > 1f){
            //						tDistanceRightSum = 0.998f + (0.0001f*bHitMaxR);
            //						tDistanceRight = 0.001f;
            //						bHitMaxR+=1;
            //					}

                    tAdd1 = tDistanceLeftSum; 					if(tAdd1 > 1f){ tAdd1 = 1f; }
                    tAdd2 = tDistanceRightSum; 					if(tAdd2 > 1f){ tAdd2 = 1f; }
                    tAdd3 = tDistanceLeft+tDistanceLeftSum; 	if(tAdd3 > 1f){ tAdd3 = 1f; }
                    tAdd4 = tDistanceRight+tDistanceRightSum; 	if(tAdd4 > 1f){ tAdd4 = 1f; }

                    uv[i] = new Vector2(0f, tAdd1);
                    uv[i+2] = new Vector2(1f, tAdd2);
                    uv[i+4] = new Vector2(0f, tAdd3);
                    uv[i+6] = new Vector2(1f, tAdd4);
                    //Debug.Log (tAdd3 + " R:"+ tAdd4 + " RLoc: " + tVerts[i+6]);
                }

                //Debug.Log ("1.0 R:1.0 RLoc: " + tVerts[i+6]);

                //Last segment needs adjusted due to double vertices:
                if((i+7) == MVL){
                    if(bOddToggle){
                        //First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-3] = uv[i+4];
                        uv[MVL-1] = uv[i+6];
                    }else{
                        //Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-4] = uv[i+4];
                        uv[MVL-2] = uv[i+6];
                    }
                }

                if(bOddToggle){
                    i+=5;

                    if(i+6 >= MVL){
                        uv[i+4-5] = new Vector2(0f, 1f);
                        uv[i+6-5] = new Vector2(1f, 1f);
                    }

                }else{
                    i+=3;

                    if(i+6 >= MVL){
                        uv[i+4-3] = new Vector2(0f, 1f);
                        uv[i+6-3] = new Vector2(1f, 1f);
                    }
                }

                tDistanceLeftSum+=tDistanceLeft;
                tDistanceRightSum+=tDistanceRight;
                //tDistanceSum+=tDistance;
                bOddToggle = !bOddToggle;
            }

            //			uv[MVL-1].y = 1f;
            //			uv[MVL-2].y = 1f;
            //			uv[MVL-3].y = 1f;
            //			uv[MVL-4].y = 1f;

            return uv;
        }
Пример #30
0
		private static Vector3 TrafficLightBase_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC tSpline, float DistFromCorner, bool bOverrideRegular = false){
			Vector3 POS = default(Vector3);
			if(!GSDRI.bRegularPoleAlignment && !bOverrideRegular){
//				float tDist = ((Vector3.Distance(GSDRI.CornerLL,GSDRI.CornerRL) / 2f) + DistFromCorner) / tSpline.distance;;
				float p = Mathf.Clamp(GSDRI.Node2.tTime,0f,1f);
				POS = tSpline.GetSplineValue(p,true);
				POS = Vector3.Cross(POS,Vector3.up); if(GSDRI.bFlipped){ POS = POS*-1; }
			}else{
				POS = GSDRI.CornerRL - GSDRI.CornerRR;
			}
			return POS * -1;
		}
        private static void InterFinalizeiBLane3(ref GSDSplineN xNode, ref GSDRoadIntersection GSDRI, ref float tIntHeight, bool bLRtoRR, bool bLLtoLR, bool bFirstInterNode, ref bool b2LAdded, ref bool b1LAdded, ref bool b0LAdded, ref bool b1RAdded)
        {
            if(b2LAdded && !xNode.iConstruction.bBLane2Done_Final){
                xNode.iConstruction.iBLane2L.RemoveAt(xNode.iConstruction.iBLane2L.Count-1);
                b2LAdded = false;
                InterFinalizeiBLane2(ref xNode, ref GSDRI, ref tIntHeight, bLRtoRR, bLLtoLR, bFirstInterNode, ref b2LAdded, ref b1LAdded, ref b0LAdded, ref b1RAdded);
            }
            xNode.iConstruction.bBLane2Done = true;
            xNode.iConstruction.bBLane3Done = true;
            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                if(GSDRI.bFlipped && !bFirstInterNode){
                    xNode.iConstruction.iBLane3L.Add(GVC(GSDRI.fCornerRL_CornerRR[1],tIntHeight));
                    xNode.iConstruction.iBLane3R.Add(GVC(GSDRI.fCornerRL_CornerRR[0],tIntHeight));
                }else{
                    if(bLRtoRR){
                        xNode.iConstruction.iBLane3L.Add(GVC(GSDRI.fCornerLR_CornerRR[3],tIntHeight));
                        xNode.iConstruction.iBLane3R.Add(GVC(GSDRI.fCornerLR_CornerRR[4],tIntHeight));
                    }else if(bLLtoLR){
                        xNode.iConstruction.iBLane3L.Add(GVC(GSDRI.fCornerLL_CornerLR[3],tIntHeight));
                        xNode.iConstruction.iBLane3R.Add(GVC(GSDRI.fCornerLL_CornerLR[4],tIntHeight));
                    }
                }
            }
            xNode.iConstruction.bBLane3Done_Final = true;
            xNode.iConstruction.bBLane3Done_Final_ThisRound = true;

            if(bFirstInterNode && GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                xNode.iConstruction.bBackRRpassed = true;
            }
        }
Пример #32
0
		public static void GetFourPoints(GSDRoadIntersection GSDRI, out Vector3 tPosRR, out Vector3 tPosRL, out Vector3 tPosLL, out Vector3 tPosLR, float DistFromCorner){
			GetFourPoints_Do(ref GSDRI,out tPosRR,out tPosRL,out tPosLL,out tPosLR,DistFromCorner);
		}
Пример #33
0
		private static void GetFourPoints_Do(ref GSDRoadIntersection GSDRI, out Vector3 tPosRR, out Vector3 tPosRL, out Vector3 tPosLL, out Vector3 tPosLR, float DistFromCorner){
			//Get four points:
			float tPos1 = 0f;
			float tPos2 = 0f;
			Vector3 tTan1 = default(Vector3);
			Vector3 tTan2 = default(Vector3);
			float Node1Width = -1f;
			float Node2Width = -1f;
			Vector3 tVectRR = GSDRI.CornerRR;
			Vector3 tVectRL = GSDRI.CornerRL;
			Vector3 tVectLR = GSDRI.CornerLR;
			Vector3 tVectLL = GSDRI.CornerLL;
			Vector3 tDir = default(Vector3);
			float ShoulderWidth1 = GSDRI.Node1.GSDSpline.tRoad.opt_ShoulderWidth;
			float ShoulderWidth2 = GSDRI.Node2.GSDSpline.tRoad.opt_ShoulderWidth;
			
			if(!GSDRI.bFlipped){
				//RR:
				Node1Width = (Vector3.Distance(GSDRI.CornerRR,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerRR,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime - Node1Width;
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true) * -1f;
				tPos2 = GSDRI.Node2.tTime + Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true);
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosRR = tVectRR + (tDir * DistFromCorner);
				//RL:
				Node1Width = (Vector3.Distance(GSDRI.CornerRL,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerRL,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime + Node1Width;
				if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){ tPos1 = GSDRI.Node1.tTime; }
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true);
				tPos2 = GSDRI.Node2.tTime + Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true);
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosRL = tVectRL + (tDir * DistFromCorner);
				//LL:
				Node1Width = (Vector3.Distance(GSDRI.CornerLL,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerLL,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime + Node1Width;
				if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){ tPos1 = GSDRI.Node1.tTime; }
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true);
				tPos2 = GSDRI.Node2.tTime - Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true) * -1f;
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosLL = tVectLL + (tDir * DistFromCorner);
				//LR:
				Node1Width = (Vector3.Distance(GSDRI.CornerLR,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerLR,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime - Node1Width;
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true) * -1f;
				tPos2 = GSDRI.Node2.tTime - Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true) * -1f;
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosLR = tVectLR + (tDir * DistFromCorner);
			}else{
				//RR:
				Node1Width = (Vector3.Distance(GSDRI.CornerRR,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerRR,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime - Node1Width;
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true) * -1f;
				tPos2 = GSDRI.Node2.tTime - Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true) * -1f;
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosRR = tVectRR + (tDir * DistFromCorner);
				//RL:
				Node1Width = (Vector3.Distance(GSDRI.CornerRL,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerRL,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime + Node1Width;
				if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){ tPos1 = GSDRI.Node1.tTime; }
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true);
				tPos2 = GSDRI.Node2.tTime - Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true) * -1f;
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosRL = tVectRL + (tDir * DistFromCorner);
				//LL:
				Node1Width = (Vector3.Distance(GSDRI.CornerLL,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerLL,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime + Node1Width;
				if(GSDRI.iType == GSDRoadIntersection.IntersectionTypeEnum.ThreeWay){ tPos1 = GSDRI.Node1.tTime; }
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true);
				tPos2 = GSDRI.Node2.tTime + Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true);
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosLL = tVectLL + (tDir * DistFromCorner);
				//LR:
				Node1Width = (Vector3.Distance(GSDRI.CornerLR,GSDRI.Node1.pos) + ShoulderWidth1)/GSDRI.Node1.GSDSpline.distance;
				Node2Width = (Vector3.Distance(GSDRI.CornerLR,GSDRI.Node2.pos) + ShoulderWidth2)/GSDRI.Node2.GSDSpline.distance;
				tPos1 = GSDRI.Node1.tTime - Node1Width;
				tTan1 = GSDRI.Node1.GSDSpline.GetSplineValue(tPos1,true) * -1f;
				tPos2 = GSDRI.Node2.tTime + Node2Width;
				tTan2 = GSDRI.Node2.GSDSpline.GetSplineValue(tPos2,true);
				tDir = (tTan1.normalized + tTan2.normalized).normalized;
				tPosLR = tVectLR + (tDir * DistFromCorner);
			}	
			tPosRR.y = GSDRI.SignHeight;
			tPosRL.y = GSDRI.SignHeight;
			tPosLL.y = GSDRI.SignHeight;
			tPosLR.y = GSDRI.SignHeight;
			
//			GameObject tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
//			tObj.transform.name = "temp22_RR";
//			tObj.transform.position = tPosRR;
//			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
//			tObj.transform.name = "temp22_RL";
//			tObj.transform.position = tPosRL;
//			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
//			tObj.transform.name = "temp22_LL";
//			tObj.transform.position = tPosLL;
//			tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
//			tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
//			tObj.transform.name = "temp22_LR";
//			tObj.transform.position = tPosLR;
		}
Пример #34
0
        /// <summary>
        /// This will create an intersection if two nodes overlap on the road. Only good if the roads only overlap once.
        /// </summary>
        /// <param name="bRoad"></param>
        /// <param name="tRoad"></param>
        private static void UnitTest_IntersectionHelper(GSDRoad bRoad, GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType, GSDRoadIntersection.RoadTypeEnum rType) {
            GSDSplineN tInter1 = null;
            GSDSplineN tInter2 = null;
            foreach (GSDSplineN tNode in bRoad.GSDSpline.mNodes) {
                foreach (GSDSplineN xNode in tRoad.GSDSpline.mNodes) {
                    if (GSDRootUtil.IsApproximately(Vector3.Distance(tNode.transform.position, xNode.transform.position), 0f, 0.05f)) {
                        tInter1 = tNode;
                        tInter2 = xNode;
                        break;
                    }
                }
            }

            if (tInter1 != null && tInter2 != null) {
                GameObject tInter = GSD.Roads.GSDIntersections.CreateIntersection(tInter1, tInter2);
                GSDRoadIntersection GSDRI = tInter.GetComponent<GSDRoadIntersection>();
                GSDRI.iStopType = iStopType;
                GSDRI.rType = rType;
            }
        }