public void ConnectToNode(GSDSplineN node) { Debug.Log("Would connect to " + node); connectedNode = node; connectedNode.transform.position = transform.position; connectedNode.GSDSpline.tRoad.UpdateRoad(); }
/// <summary> /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates. /// </summary> /// <param name="RS">The road system to create nodes on.</param> /// <param name="NodeLocation">The location of the newly created node.</param> /// <returns></returns> public static GSDSplineN CreateNode_Programmatically(GSDRoad tRoad, Vector3 NodeLocation) { int SplineChildCount = tRoad.GSDSpline.transform.childCount; GameObject tNodeObj = new GameObject("Node" + (SplineChildCount + 1).ToString()); GSDSplineN tNode = tNodeObj.AddComponent <GSDSplineN>(); //Add the node component. //Set node location: if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; } //Make sure it doesn't try to create a node below 0 height. tNodeObj.transform.position = NodeLocation; //Set the node's parent: tNodeObj.transform.parent = tRoad.GSDSplineObj.transform; //Set the idOnSpline: tNode.idOnSpline = (SplineChildCount + 1); tNode.GSDSpline = tRoad.GSDSpline; //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates tRoad.UpdateRoad(); return(tNode); }
/// <summary> /// This will create an intersection if two nodes overlap on the road. Only good if the roads only overlap once. /// </summary> /// <param name="bRoad"></param> /// <param name="tRoad"></param> private static void UnitTest_IntersectionHelper(GSDRoad bRoad, GSDRoad tRoad, GSDRoadIntersection.iStopTypeEnum iStopType, GSDRoadIntersection.RoadTypeEnum rType) { GSDSplineN tInter1 = null; GSDSplineN tInter2 = null; foreach (GSDSplineN tNode in bRoad.GSDSpline.mNodes) { foreach (GSDSplineN xNode in tRoad.GSDSpline.mNodes) { if (GSDRootUtil.IsApproximately(Vector3.Distance(tNode.transform.position, xNode.transform.position), 0f, 0.05f)) { tInter1 = tNode; tInter2 = xNode; break; } } } if (tInter1 != null && tInter2 != null) { GameObject tInter = GSD.Roads.GSDIntersections.CreateIntersection(tInter1, tInter2); GSDRoadIntersection GSDRI = tInter.GetComponent <GSDRoadIntersection>(); GSDRI.iStopType = iStopType; GSDRI.rType = rType; } }
public void TunnelToggleEnd() { //If switching to end, find associated Tunnel if (bIsTunnelEnd) { int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode = null; for (int i = 1; i < (mCount - 1); i++) { tNode = GSDSpline.mNodes[i]; if (tNode.bIsTunnelStart && !tNode.bIsTunnelMatched) { tNode.TunnelToggleStart(); if (tNode.bIsTunnelMatched && tNode.TunnelCounterpartNode == this) { return; } } } } else { TunnelDestroy(); } }
public void BridgeToggleEnd() { //If switching to end, find associated bridge if (bIsBridgeEnd) { int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode = null; for (int i = 1; i < (mCount - 1); i++) { tNode = GSDSpline.mNodes[i]; if (tNode.bIsBridgeStart && !tNode.bIsBridgeMatched) { tNode.BridgeToggleStart(); if (tNode.bIsBridgeMatched && tNode.BridgeCounterpartNode == this) { return; } } } } else { BridgeDestroy(); } }
public void BridgeResetValues() { bIsBridge = false; bIsBridgeStart = false; bIsBridgeEnd = false; bIsBridgeMatched = false; BridgeCounterpartNode = null; }
public void TunnelResetValues() { bIsTunnel = false; bIsTunnelStart = false; bIsTunnelEnd = false; bIsTunnelMatched = false; TunnelCounterpartNode = null; }
private void TunnelStart() { //Cycle through nodes until you find another end or another start (in this case, no creation, encountered another Tunnel): int EndID = idOnSpline + 1; int mCount = GSDSpline.GetNodeCount(); if (bIsEndPoint) { //Attempted to make end point node a Tunnel node: bIsTunnelStart = false; return; } if (EndID >= mCount) { //Attempted to make last node a Tunnel node: bIsTunnelStart = false; return; } else if (idOnSpline == 0) { //Attempted to make first node a Tunnel node: bIsTunnelStart = false; return; } bIsTunnelMatched = false; TunnelCounterpartNode = null; int StartI = idOnSpline + 1; GSDSplineN tNode = null; for (int i = StartI; i < mCount; i++) { tNode = GSDSpline.mNodes[i]; if (tNode.bIsIntersection) { //Encountered intersection. End search. return; } if (tNode.bIsTunnelStart) { //Encountered another Tunnel. Return: return; } if (tNode.bIgnore) { continue; } if (tNode.bIsTunnelEnd) { bIsTunnelMatched = true; tNode.bIsTunnelMatched = true; TunnelCounterpartNode = tNode; tNode.TunnelCounterpartNode = this; GSDSpline.Setup_Trigger(); return; } } }
public void Initialize(WindowTypeEnum _tWindowType, GSDSplineN _tNode) { if (xRect.width < 1f && xRect.height < 1f) { xRect.x = 275f; xRect.y = 200f; xRect.width = 860f; xRect.height = 500f; } position = xRect; tWindowType = _tWindowType; tNode = _tNode; InitWindow(); Show(); }
public void BreakConnection() { GSDSplineN tNode2 = SpecialNodeCounterpart; if (bSpecialEndNode_IsStart) { GSDSpline.bSpecialStartControlNode = false; GSDSpline.bSpecialEndNode_IsStart_Delay = false; } else if (bSpecialEndNode_IsEnd) { GSDSpline.bSpecialEndControlNode = false; GSDSpline.bSpecialEndNode_IsEnd_Delay = false; } if (tNode2.bSpecialEndNode_IsStart) { tNode2.GSDSpline.bSpecialStartControlNode = false; tNode2.GSDSpline.bSpecialEndNode_IsStart_Delay = false; } else if (tNode2.bSpecialEndNode_IsEnd) { tNode2.GSDSpline.bSpecialEndControlNode = false; tNode2.GSDSpline.bSpecialEndNode_IsEnd_Delay = false; } SpecialNodeCounterpart = null; bSpecialEndNode = false; bSpecialEndNode_IsEnd = false; bSpecialEndNode_IsStart = false; bSpecialRoadConnPrimary = false; tNode2.SpecialNodeCounterpart = null; tNode2.bSpecialEndNode = false; tNode2.bSpecialEndNode_IsEnd = false; tNode2.bSpecialEndNode_IsStart = false; tNode2.bSpecialRoadConnPrimary = false; tNode2.SpecialNodeCounterpart_Master.bSpecialRoadConnPrimary = false; SpecialNodeCounterpart_Master.bSpecialRoadConnPrimary = false; try { Object.DestroyImmediate(tNode2.transform.gameObject); Object.DestroyImmediate(transform.gameObject); } catch (MissingReferenceException) { } }
public void SetupSplinationLimits() { //Disallowed nodes: if (!CanSplinate()) { MinSplination = tTime; MaxSplination = tTime; return; } //Figure out min splination: GSDSplineN tNode = null; MinSplination = tTime; for (int i = idOnSpline; i >= 0; i--) { tNode = GSDSpline.mNodes[i]; if (tNode.CanSplinate()) { MinSplination = tNode.tTime; } else { break; } } //Figure out max splination: MaxSplination = tTime; int mCount = GSDSpline.GetNodeCount(); for (int i = idOnSpline; i < mCount; i++) { tNode = GSDSpline.mNodes[i]; if (tNode.CanSplinate()) { MaxSplination = tNode.tTime; } else { break; } } }
public void DeleteRelevantChildren(GSDSplineN tNode, string tString) { int cCount = transform.childCount; for (int i = cCount - 1; i >= 0; i--) { if (transform.GetChild(i).name.ToLower().Contains(tString.ToLower())) { Object.DestroyImmediate(transform.GetChild(i).gameObject); } else if (tNode == Node1) { if (transform.GetChild(i).name.ToLower().Contains("centermarkers")) { Object.DestroyImmediate(transform.GetChild(i).gameObject); } } } }
public void Setup(GSDSplineN tNode, GSDSplineN xNode) { if (tNode.GSDSpline == xNode.GSDSpline) { bSameSpline = true; } if (bSameSpline) { if (tNode.idOnSpline < xNode.idOnSpline) { Node1 = tNode; Node2 = xNode; } else { Node1 = xNode; Node2 = tNode; } } else { Node1 = tNode; Node2 = xNode; } Node1.Intersection_OtherNode = Node2; Node2.Intersection_OtherNode = Node1; Node1.ToggleHideFlags(true); Node2.ToggleHideFlags(true); Node1UID = Node1.UID; Node2UID = Node2.UID; Node1.bIsIntersection = true; Node2.bIsIntersection = true; Node1.GSDRI = this; Node2.GSDRI = this; }
public void BreakConnection(){ GSDSplineN tNode2 = SpecialNodeCounterpart; if(bSpecialEndNode_IsStart){ GSDSpline.bSpecialStartControlNode = false; GSDSpline.bSpecialEndNode_IsStart_Delay = false; }else if(bSpecialEndNode_IsEnd){ GSDSpline.bSpecialEndControlNode = false; GSDSpline.bSpecialEndNode_IsEnd_Delay = false; } if(tNode2.bSpecialEndNode_IsStart){ tNode2.GSDSpline.bSpecialStartControlNode = false; tNode2.GSDSpline.bSpecialEndNode_IsStart_Delay = false; }else if(tNode2.bSpecialEndNode_IsEnd){ tNode2.GSDSpline.bSpecialEndControlNode = false; tNode2.GSDSpline.bSpecialEndNode_IsEnd_Delay = false; } SpecialNodeCounterpart = null; bSpecialEndNode = false; bSpecialEndNode_IsEnd = false; bSpecialEndNode_IsStart = false; bSpecialRoadConnPrimary = false; tNode2.SpecialNodeCounterpart = null; tNode2.bSpecialEndNode = false; tNode2.bSpecialEndNode_IsEnd = false; tNode2.bSpecialEndNode_IsStart = false; tNode2.bSpecialRoadConnPrimary = false; tNode2.SpecialNodeCounterpart_Master.bSpecialRoadConnPrimary = false; SpecialNodeCounterpart_Master.bSpecialRoadConnPrimary = false; Object.DestroyImmediate(tNode2.transform.gameObject); Object.DestroyImmediate(transform.gameObject); }
public void BridgeResetValues(){ bIsBridge = false; bIsBridgeStart = false; bIsBridgeEnd = false; bIsBridgeMatched = false; BridgeCounterpartNode = null; }
public void Initialize(ref Rect tRect, WindowTypeEnum _tWindowType, GSDSplineN tNode, GSD.Roads.Splination.SplinatedMeshMaker SMM = null, GSD.Roads.EdgeObjects.EdgeObjectMaker EOM = null) { int Rheight = 300; int Rwidth = 360; float Rx = ((float)tRect.width/2f) - ((float)Rwidth/2f) + tRect.x; float Ry = ((float)tRect.height/2f) - ((float)Rheight/2f) + tRect.y; if(Rx < 0){ Rx = tRect.x; } if(Ry < 0){ Ry = tRect.y; } if(Rx > (tRect.width + tRect.x)){ Rx = tRect.x; } if(Ry > (tRect.height + tRect.y)){ Ry = tRect.y; } Rect fRect = new Rect(Rx,Ry,Rwidth,Rheight); if(fRect.width < 300){ fRect.width = 300; fRect.x = tRect.x; } if(fRect.height < 300){ fRect.height = 300; fRect.y = tRect.y; } position = fRect; tWindowType = _tWindowType; Show(); title = "Save"; if(tWindowType == WindowTypeEnum.Extrusion){ TitleText = "Save extrusion"; tSMMs = new GSD.Roads.Splination.SplinatedMeshMaker[1]; tSMMs[0] = SMM; if(SMM != null){ tFilename = SMM.tName; tDisplayName = tFilename; } }else if(tWindowType == WindowTypeEnum.Edge){ TitleText = "Save edge object"; tEOMs = new GSD.Roads.EdgeObjects.EdgeObjectMaker[1]; tEOMs[0] = EOM; if(EOM != null){ tFilename = EOM.tName; tDisplayName = tFilename; } }else if(tWindowType == WindowTypeEnum.BridgeWizard){ bIsBridge = true; tSMMs = tNode.SplinatedObjects.ToArray(); tEOMs = tNode.EdgeObjects.ToArray(); TitleText = "Save group"; tFilename = "Group" + Random.Range(0,10000).ToString(); tDisplayName = tFilename; } if(xPath.Length < 5){ xPath = GSDRootUtil.Dir_GetLibrary(); } if(tWindowType == WindowTypeEnum.Edge){ if(System.IO.File.Exists(xPath + "EOM"+tFilename+".gsd")){ bFileExists = true; }else{ bFileExists = false; } }else if(tWindowType == WindowTypeEnum.Extrusion){ if(System.IO.File.Exists(xPath + "ESO"+tFilename+".gsd")){ bFileExists = true; }else{ bFileExists = false; } }else{ if(System.IO.File.Exists(xPath + "B/"+tFilename+".gsd")){ bFileExists = true; }else{ bFileExists = false; } } }
private int CompareListByName(GSDSplineN i1, GSDSplineN i2){ return i1.idOnSpline.CompareTo(i2.idOnSpline); }
public void ActivateEndNodeConnection(GSDSplineN tNode1, GSDSplineN tNode2){ ActivateEndNodeConnection_Do(tNode1,tNode2); }
public bool IntersectionIsPast(ref float p, ref GSDSplineN oNode){ // int mCount = GetNodeCount(); // bool bIsPast; // GSDSplineN tNode = null; // for(int i=0;i<mCount;i++){ // tNode = mNodes[i]; // if(tNode.bIsIntersection){ // float P1 = tNode.GSDRI.Node1.tTime - p; if(P1 < 0f){ P1 *= -1f; } // float P2 = tNode.GSDRI.Node2.tTime - p; if(P2 < 0f){ P2 *= -1f; } // // if(P1 > P2){ // if(p > tNode.GSDRI.Node2.tTime){ // bIsPast = true; // }else{ // bIsPast = false; // } // }else{ // if(p > tNode.GSDRI.Node1.tTime){ // bIsPast = true; // }else{ // bIsPast = false; // } // } // return bIsPast; // } // } // return false; if(p < oNode.tTime){ return false; }else{ return true; } }
private static void Inter_OrganizeVertices(ref GSDSplineN tNode, ref GSDRoad tRoad) { GSD.Roads.GSDIntersections.iConstructionMaker iCon = tNode.iConstruction; GSDRoadIntersection GSDRI = tNode.GSDRI; //Skipping (3 ways): bool bSkipF = false; if(iCon.iFLane0L.Count == 0){ bSkipF = true; } bool bSkipB = false; if(iCon.iBLane0L.Count == 0){ bSkipB = true; } //Is primary node and is first node on a spline, meaning t junction: It does not have a B: if(tNode.idOnSpline == 0 && string.CompareOrdinal(GSDRI.Node1UID,tNode.UID) == 0){ bSkipB = true; } //Is primary node and is last node on a spline, meaning t junction: It does not have a F: if(tNode.idOnSpline == (tNode.GSDSpline.GetNodeCount()-1) && string.CompareOrdinal(GSDRI.Node1UID,tNode.UID) == 0){ bSkipF = true; } //Other node is t junction end node, meaning now we figure out which side we're on if(tNode.Intersection_OtherNode.idOnSpline == 0 || tNode.idOnSpline == (tNode.GSDSpline.GetNodeCount()-1)){ } //Reverse all fronts: if(!bSkipF){ iCon.iFLane0L.Reverse(); iCon.iFLane0R.Reverse(); iCon.iFLane1L.Reverse(); iCon.iFLane2L.Reverse(); iCon.iFLane3L.Reverse(); iCon.iFLane1R.Reverse(); iCon.iFLane2R.Reverse(); iCon.iFLane3R.Reverse(); if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iCon.ShoulderFR_Start = iCon.iFLane0L[0]; iCon.ShoulderFL_Start = iCon.iFLane3R[0]; }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ iCon.ShoulderFR_Start = iCon.iFLane0L[0]; iCon.ShoulderFL_Start = iCon.iFLane2R[0]; }else{ iCon.ShoulderFR_Start = iCon.iFLane0L[0]; iCon.ShoulderFL_Start = iCon.iFLane1R[0]; } } if(!bSkipB){ if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1]; iCon.ShoulderBR_End = iCon.iBLane3R[iCon.iBLane3R.Count-1]; }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1]; iCon.ShoulderBR_End = iCon.iBLane2R[iCon.iBLane2R.Count-1]; }else{ iCon.ShoulderBL_End = iCon.iBLane0L[iCon.iBLane0L.Count-1]; iCon.ShoulderBR_End = iCon.iBLane1R[iCon.iBLane1R.Count-1]; } } if(!bSkipB){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iBLane0L,iCon.ShoulderBL_StartIndex,ref iCon.ShoulderBL_Start, ref iCon.ShoulderBL_End, GSDRI.Height); if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane3R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height); }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane2R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height); }else{ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iBLane1R,iCon.ShoulderBR_StartIndex,ref iCon.ShoulderBR_Start, ref iCon.ShoulderBR_End, GSDRI.Height); } } if(!bSkipF){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderR_Vectors,ref iCon.iFLane0L,iCon.ShoulderFR_StartIndex,ref iCon.ShoulderFR_Start, ref iCon.ShoulderFR_End, GSDRI.Height,true); if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane3R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true); }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane2R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true); }else{ Inter_OrganizeVerticesMatchShoulder(ref tRoad.RCS.ShoulderL_Vectors,ref iCon.iFLane1R,iCon.ShoulderFL_StartIndex,ref iCon.ShoulderFL_Start, ref iCon.ShoulderFL_End, GSDRI.Height,true); } } bool bError = false; string tWarning = "Intersection " + GSDRI.tName + " in road " + tRoad.tName + " at too extreme angle to process this intersection type. Reduce angle or reduce lane count."; if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } } if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } } }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } } if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } } if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane1R, ref iCon.iBLane2L); if(bError){ Debug.Log(tWarning); } } if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane1R, ref iCon.iFLane2L); if(bError){ Debug.Log(tWarning); } } }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane0R, ref iCon.iBLane1L); if(bError){ Debug.Log(tWarning); } } if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane0R, ref iCon.iFLane1L); if(bError){ Debug.Log(tWarning); } } if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane1R, ref iCon.iBLane2L,true,true); if(bError){ Debug.Log(tWarning); } } if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane1R, ref iCon.iFLane2L,true,true); if(bError){ Debug.Log(tWarning); } } // if(!bSkipB){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iBLane2R, ref iCon.iBLane3L,true,false); if(bError){ Debug.Log(tWarning); } } // if(!bSkipF){ bError = Inter_OrganizeVerticesMatchEdges(ref iCon.iFLane2R, ref iCon.iFLane3L,true,false); if(bError){ Debug.Log(tWarning); } } } //Back main plate left: int mCount = -1; if(!bSkipB){ mCount = iCon.iBLane0L.Count; for(int m=0;m<mCount;m++){ iCon.iBMainPlateL.Add(iCon.iBLane0L[m]); } } //Front main plate left: if(!bSkipF){ mCount = iCon.iFLane0L.Count; for(int m=0;m<mCount;m++){ iCon.iFMainPlateL.Add(iCon.iFLane0L[m]); } } //Back main plate right: if(!bSkipB){ if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ mCount = iCon.iBLane1R.Count; for(int m=0;m<mCount;m++){ iCon.iBMainPlateR.Add(iCon.iBLane1R[m]); } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ mCount = iCon.iBLane2R.Count; for(int m=0;m<mCount;m++){ iCon.iBMainPlateR.Add(iCon.iBLane2R[m]); } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ mCount = iCon.iBLane3R.Count; for(int m=0;m<mCount;m++){ iCon.iBMainPlateR.Add(iCon.iBLane3R[m]); } } } //Front main plate right: if(!bSkipF){ if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ mCount = iCon.iFLane1R.Count; for(int m=0;m<mCount;m++){ iCon.iFMainPlateR.Add(iCon.iFLane1R[m]); } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ mCount = iCon.iFLane2R.Count; for(int m=0;m<mCount;m++){ iCon.iFMainPlateR.Add(iCon.iFLane2R[m]); } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ mCount = iCon.iFLane3R.Count; for(int m=0;m<mCount;m++){ iCon.iFMainPlateR.Add(iCon.iFLane3R[m]); } } } mCount = tRoad.RCS.RoadVectors.Count; // float mDistance = 0.05f; Vector3 tVect = default(Vector3); bool biBLane0L = (iCon.iBLane0L.Count > 0); if(biBLane0L == false){ } bool biBLane0R = (iCon.iBLane0R.Count > 0); if(biBLane0R == false){ } bool biBMainPlateL = (iCon.iBMainPlateL.Count > 0); if(biBMainPlateL == false){ } bool biBMainPlateR = (iCon.iBMainPlateR.Count > 0); if(biBMainPlateR == false){ } bool biFLane0L = (iCon.iFLane0L.Count > 0); if(biFLane0L == false){ } bool biFLane0R = (iCon.iFLane0R.Count > 0); if(biFLane0R == false){ } bool biFMainPlateL = (iCon.iFMainPlateL.Count > 0); if(biFMainPlateL == false){ } bool biFMainPlateR = (iCon.iFMainPlateR.Count > 0); if(biFMainPlateR == false){ } bool biBLane2L = (iCon.iBLane2L.Count > 0); if(biBLane2L == false){ } bool biBLane2R = (iCon.iBLane2R.Count > 0); if(biBLane2R == false){ } bool biFLane2L = (iCon.iFLane2L.Count > 0); if(biFLane2L == false){ } bool biFLane2R = (iCon.iFLane2R.Count > 0); if(biFLane2R == false){ } bool biBLane3L = (iCon.iBLane3L.Count > 0); if(biBLane3L == false){ } bool biBLane3R = (iCon.iBLane3R.Count > 0); if(biBLane3R == false){ } bool biFLane3L = (iCon.iFLane3L.Count > 0); if(biFLane3L == false){ } bool biFLane3R = (iCon.iFLane3R.Count > 0); if(biFLane3R == false){ } mCount = tRoad.RCS.RoadVectors.Count; int cCount = tRoad.GSDSpline.GetNodeCount(); int tStartI = 0; int tEndI = mCount; //Start and end the next loop after this one later for opt: if(cCount > 2){ if(!tRoad.GSDSpline.mNodes[0].bIsIntersection && !tRoad.GSDSpline.mNodes[1].bIsIntersection){ for(int i=2;i<cCount;i++){ if(tRoad.GSDSpline.mNodes[i].bIsIntersection){ if(i-2 >= 1){ tStartI = (int)(tRoad.GSDSpline.mNodes[i-2].tTime * mCount); } break; } } } } if(cCount > 3){ if(!tRoad.GSDSpline.mNodes[cCount-1].bIsIntersection && !tRoad.GSDSpline.mNodes[cCount-2].bIsIntersection){ for(int i=(cCount-3);i>=0;i--){ if(tRoad.GSDSpline.mNodes[i].bIsIntersection){ if(i+2 < cCount){ tEndI = (int)(tRoad.GSDSpline.mNodes[i+2].tTime * mCount); } break; } } } } if(tStartI > 0){ if(tStartI % 2 != 0){ tStartI += 1; } } if(tStartI > mCount){ tStartI=mCount-4; } if(tStartI < 0){ tStartI = 0; } if(tEndI < mCount){ if(tEndI % 2 != 0){ tEndI += 1; } } if(tEndI > mCount){ tEndI=mCount-4; } if(tEndI < 0){ tEndI = 0; } for(int i=tStartI;i<tEndI;i+=2){ tVect = tRoad.RCS.RoadVectors[i]; for(int j=0;j<1;j++){ if(biBLane0L && Vector3.SqrMagnitude(tVect-iCon.iBLane0L[j]) < 0.01f && !bSkipB){ iCon.iBLane0L[j] = tVect; } if(biBMainPlateL && Vector3.SqrMagnitude(tVect-iCon.iBMainPlateL[j]) < 0.01f && !bSkipB){ iCon.iBMainPlateL[j] = tVect; } if(biBMainPlateR && Vector3.SqrMagnitude(tVect-iCon.iBMainPlateR[j]) < 0.01f && !bSkipB){ iCon.iBMainPlateR[j] = tVect; } if(biFLane0L && Vector3.SqrMagnitude(tVect-iCon.iFLane0L[j]) < 0.01f && !bSkipF){ iCon.iFLane0L[j] = tVect; } if(biFMainPlateL && Vector3.SqrMagnitude(tVect-iCon.iFMainPlateL[j]) < 0.01f && !bSkipF){ iCon.iFMainPlateL[j] = tVect; } if(biFMainPlateR && Vector3.SqrMagnitude(tVect-iCon.iFMainPlateR[j]) < 0.01f && !bSkipF){ iCon.iFMainPlateR[j] = tVect; } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ if(biBLane3L && Vector3.SqrMagnitude(tVect-iCon.iBLane3L[j]) < 0.01f && !bSkipB){ iCon.iBLane3L[j] = tVect; } if(biBLane3R && Vector3.SqrMagnitude(tVect-iCon.iBLane3R[j]) < 0.01f && !bSkipB){ iCon.iBLane3R[j] = tVect; } if(biFLane3L && Vector3.SqrMagnitude(tVect-iCon.iFLane3L[j]) < 0.01f && !bSkipF){ iCon.iFLane3L[j] = tVect; } if(biFLane3R && Vector3.SqrMagnitude(tVect-iCon.iFLane3R[j]) < 0.01f && !bSkipF){ iCon.iFLane3R[j] = tVect; } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ if(biBLane2L && Vector3.SqrMagnitude(tVect-iCon.iBLane2L[j]) < 0.01f && !bSkipB){ iCon.iBLane2L[j] = tVect; } if(biBLane2R && Vector3.SqrMagnitude(tVect-iCon.iBLane2R[j]) < 0.01f && !bSkipB){ iCon.iBLane2R[j] = tVect; } if(biFLane2L && Vector3.SqrMagnitude(tVect-iCon.iFLane2L[j]) < 0.01f && !bSkipF){ iCon.iFLane2L[j] = tVect; } if(biFLane2R && Vector3.SqrMagnitude(tVect-iCon.iFLane2R[j]) < 0.01f && !bSkipF){ iCon.iFLane2R[j] = tVect; } } } } // float b0 = -1f; // float f0 = -1f; // // if(!bSkipB){ b0 = iCon.iBMainPlateL[0].y; } // if(!bSkipF){ f0 = iCon.iFMainPlateL[0].y; } // // if(iCon.iBLane0R == null || iCon.iBLane0R.Count == 0){ // bSkipB = true; // } if(iCon.iBMainPlateR == null || iCon.iBMainPlateR.Count == 0){ bSkipB = true; } if(iCon.iBMainPlateL == null || iCon.iBMainPlateL.Count == 0){ bSkipB = true; } if(!bSkipB){ iCon.iBLane0R[0] = ((iCon.iBMainPlateR[0]-iCon.iBMainPlateL[0])*0.5f+iCon.iBMainPlateL[0]); } if(!bSkipF){ iCon.iFLane0R[0] = ((iCon.iFMainPlateR[0]-iCon.iFMainPlateL[0])*0.5f+iCon.iFMainPlateL[0]); } // if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ if(!bSkipB){ iCon.iBLane1L[0] = iCon.iBLane0R[0]; iCon.iBLane1R[0] = new Vector3(iCon.iBLane1R[0].x,iCon.iBLane1L[0].y,iCon.iBLane1R[0].z); } if(!bSkipF){ iCon.iFLane1L[0] = iCon.iFLane0R[0]; iCon.iFLane1R[0] = new Vector3(iCon.iFLane1R[0].x,iCon.iFLane1L[0].y,iCon.iFLane1R[0].z); } // } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ if(!bSkipB){ iCon.iBLane3L[0] = new Vector3(iCon.iBLane3L[0].x,iCon.iBLane3R[0].y,iCon.iBLane3L[0].z); } if(!bSkipF){ iCon.iFLane3L[0] = new Vector3(iCon.iFLane3L[0].x,iCon.iFLane3R[0].y,iCon.iFLane3L[0].z); } }else if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){ if(!bSkipB){ iCon.iBLane2L[0] = new Vector3(iCon.iBLane2L[0].x,iCon.iBLane2R[0].y,iCon.iBLane2L[0].z); } if(!bSkipF){ iCon.iFLane2L[0] = new Vector3(iCon.iFLane2L[0].x,iCon.iFLane2R[0].y,iCon.iFLane2L[0].z); } } List<Vector3> iBLane0 = null; List<Vector3> iBLane1 = null; List<Vector3> iBLane2 = null; List<Vector3> iBLane3 = null; if(!bSkipB){ iBLane0 = InterVertices(iCon.iBLane0L,iCon.iBLane0R, tNode.GSDRI.Height); iBLane1 = InterVertices(iCon.iBLane1L,iCon.iBLane1R, tNode.GSDRI.Height); if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ iBLane2 = InterVertices(iCon.iBLane2L,iCon.iBLane2R, tNode.GSDRI.Height); } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iBLane3 = InterVertices(iCon.iBLane3L,iCon.iBLane3R, tNode.GSDRI.Height); } } //Front lanes: List<Vector3> iFLane0 = null; List<Vector3> iFLane1 = null; List<Vector3> iFLane2 = null; List<Vector3> iFLane3 = null; if(!bSkipF){ iFLane0 = InterVertices(iCon.iFLane0L,iCon.iFLane0R, tNode.GSDRI.Height); iFLane1 = InterVertices(iCon.iFLane1L,iCon.iFLane1R, tNode.GSDRI.Height); if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ iFLane2 = InterVertices(iCon.iFLane2L,iCon.iFLane2R, tNode.GSDRI.Height); } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ iFLane3 = InterVertices(iCon.iFLane3L,iCon.iFLane3R, tNode.GSDRI.Height); } } //Main plates: List<Vector3> iBMainPlate = null; List<Vector3> iFMainPlate = null; if(!bSkipB){ iBMainPlate = InterVertices(iCon.iBMainPlateL,iCon.iBMainPlateR, tNode.GSDRI.Height); } if(!bSkipF){ iFMainPlate = InterVertices(iCon.iFMainPlateL,iCon.iFMainPlateR, tNode.GSDRI.Height); } // //Marker plates: // List<Vector3> iBMarkerPlate = InterVertices(iCon.iBMarkerPlateL,iCon.iBMarkerPlateR, tNode.GSDRI.Height); // List<Vector3> iFMarkerPlate = InterVertices(iCon.iFMarkerPlateL,iCon.iFMarkerPlateR, tNode.GSDRI.Height); // //Now add these to RCS: if(!bSkipB){ tRoad.RCS.iBLane0s.Add(iBLane0.ToArray()); tRoad.RCS.iBLane0s_tID.Add(GSDRI); tRoad.RCS.iBLane0s_nID.Add(tNode); tRoad.RCS.iBLane1s.Add(iBLane1.ToArray()); tRoad.RCS.iBLane1s_tID.Add(GSDRI); tRoad.RCS.iBLane1s_nID.Add(tNode); if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ if (iBLane2 != null) { tRoad.RCS.iBLane2s.Add(iBLane2.ToArray()); tRoad.RCS.iBLane2s_tID.Add(GSDRI); tRoad.RCS.iBLane2s_nID.Add(tNode); } } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ tRoad.RCS.iBLane3s.Add(iBLane3.ToArray()); tRoad.RCS.iBLane3s_tID.Add(GSDRI); tRoad.RCS.iBLane3s_nID.Add(tNode); } } //Front lanes: if(!bSkipF){ tRoad.RCS.iFLane0s.Add(iFLane0.ToArray()); tRoad.RCS.iFLane0s_tID.Add(GSDRI); tRoad.RCS.iFLane0s_nID.Add(tNode); tRoad.RCS.iFLane1s.Add(iFLane1.ToArray()); tRoad.RCS.iFLane1s_tID.Add(GSDRI); tRoad.RCS.iFLane1s_nID.Add(tNode); if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ tRoad.RCS.iFLane2s.Add(iFLane2.ToArray()); tRoad.RCS.iFLane2s_tID.Add(GSDRI); tRoad.RCS.iFLane2s_nID.Add(tNode); } if(tNode.GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){ tRoad.RCS.iFLane3s.Add(iFLane3.ToArray()); tRoad.RCS.iFLane3s_tID.Add(GSDRI); tRoad.RCS.iFLane3s_nID.Add(tNode); } } //Main plates: if(iBMainPlate != null && !bSkipB){ tRoad.RCS.iBMainPlates.Add(iBMainPlate.ToArray()); tRoad.RCS.iBMainPlates_tID.Add(GSDRI); tRoad.RCS.iBMainPlates_nID.Add(tNode); } if(iFMainPlate != null && !bSkipF){ tRoad.RCS.iFMainPlates.Add(iFMainPlate.ToArray()); tRoad.RCS.iFMainPlates_tID.Add(GSDRI); tRoad.RCS.iFMainPlates_nID.Add(tNode); } // //Marker plates: // tRoad.RCS.iBMarkerPlates.Add(iBMarkerPlate.ToArray()); // tRoad.RCS.iFMarkerPlates.Add(iFMarkerPlate.ToArray()); // tRoad.RCS.IntersectionTypes.Add((int)tNode.GSDRI.rType); if(tNode.GSDRI.rType != GSDRoadIntersection.RoadTypeEnum.NoTurnLane){ if(!bSkipB){ tRoad.RCS.iBLane1s_IsMiddleLane.Add(true); } if(!bSkipF){ tRoad.RCS.iFLane1s_IsMiddleLane.Add(true); } }else{ if(!bSkipB){ tRoad.RCS.iBLane1s_IsMiddleLane.Add(false); } if(!bSkipF){ tRoad.RCS.iFLane1s_IsMiddleLane.Add(false); } } }
public void Setup(GSDSplineN tNode, GSDSplineN xNode){ if(tNode.GSDSpline == xNode.GSDSpline){ bSameSpline = true; } if(bSameSpline){ if(tNode.idOnSpline < xNode.idOnSpline){ Node1 = tNode; Node2 = xNode; }else{ Node1 = xNode; Node2 = tNode; } }else{ Node1 = tNode; Node2 = xNode; } Node1.Intersection_OtherNode = Node2; Node2.Intersection_OtherNode = Node1; Node1.ToggleHideFlags(true); Node2.ToggleHideFlags(true); Node1UID = Node1.UID; Node2UID = Node2.UID; Node1.bIsIntersection = true; Node2.bIsIntersection = true; Node1.GSDRI = this; Node2.GSDRI = this; }
public void EnsureGradeValidity(int iStart = -1, bool bIsAddToEnd = false) { if (GSDSpline == null) { return; } GSDSplineN PrevNode = null; GSDSplineN NextNode = null; if (bIsAddToEnd && GSDSpline.GetNodeCount() > 0) { PrevNode = GSDSpline.mNodes[GSDSpline.GetNodeCount() - 1]; } else { if (iStart == -1) { PrevNode = GSDSpline.GetPrevLegitimateNode(idOnSpline); } else { PrevNode = GSDSpline.GetPrevLegitimateNode(iStart); } } if (PrevNode == null) { return; } Vector3 tVect = transform.position; float tMinY1 = 0f; float tMinY2 = 0f; float tMaxY1 = 0f; float tMaxY2 = 0f; if (PrevNode != null) { PrevNode.FilterMaxGradeHeight(tVect, out tMinY1, out tMaxY1); } if (NextNode != null) { NextNode.FilterMaxGradeHeight(tVect, out tMinY2, out tMaxY2); } bool bPrevNodeGood = false; bool bNextNodeGood = false; if (tVect.y > tMinY1 && tVect.y < tMaxY1) { bPrevNodeGood = true; } if (tVect.y > tMinY2 && tVect.y < tMaxY2) { bNextNodeGood = true; } if (!bPrevNodeGood && !bNextNodeGood && PrevNode != null && NextNode != null) { float tMaxY3 = Mathf.Min(tMaxY1, tMaxY2); float tMinY3 = Mathf.Max(tMinY1, tMinY2); if (tVect.y < tMinY3) { tVect.y = tMinY3; } else if (tVect.y > tMaxY3) { tVect.y = tMaxY3; } } else { if (!bPrevNodeGood && PrevNode != null) { if (tVect.y < tMinY1) { tVect.y = tMinY1; } else if (tVect.y > tMaxY1) { tVect.y = tMaxY1; } } else if (!bNextNodeGood && NextNode != null) { if (tVect.y < tMinY2) { tVect.y = tMinY2; } else if (tVect.y > tMaxY2) { tVect.y = tMaxY2; } } } transform.position = tVect; }
private void TriggerRoadConnection(GSDSplineN tNode1, GSDSplineN tNode2){ tNode.GSDSpline.ActivateEndNodeConnection(tNode1,tNode2); }
private void TriggerIntersection(GSDSplineN tNode1, GSDSplineN tNode2){ bCreateIntersection = true; iNode1 = tNode1; iNode2 = tNode2; // Selection.activeGameObject = GSD.Roads.GSDIntersections.CreateIntersection(tNode1,tNode2); }
/// <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; } } } } }
public void DeleteRelevantChildren(GSDSplineN tNode, string tString){ int cCount = transform.childCount; for(int i=cCount-1;i>=0;i--){ if(transform.GetChild(i).name.ToLower().Contains(tString.ToLower())){ Object.DestroyImmediate(transform.GetChild(i).gameObject); }else if(tNode == Node1){ if(transform.GetChild(i).name.ToLower().Contains("centermarkers")){ Object.DestroyImmediate(transform.GetChild(i).gameObject); } } } }
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; } }
public void Initialize(WindowTypeEnum _tWindowType, GSDSplineN _tNode) { if(xRect.width < 1f && xRect.height < 1f){ xRect.x = 275f; xRect.y = 200f; xRect.width = 860f; xRect.height = 500f; } position = xRect; tWindowType = _tWindowType; tNode = _tNode; InitWindow(); Show(); }
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; }
public void Init(GSDSplineC _tSpline, GSDSplineN _tNode, Transform tTrans){ tSpline = _tSpline; tNode = _tNode; MasterObjTrans = tTrans; SetupUniqueIdentifier(); }
void DestroyIntersection(GSDSplineN tNode){ if(tNode != null){ if(tNode.bIsEndPoint){ if(tNode.idOnSpline == 1 && tNode.GSDSpline.mNodes[0].bSpecialEndNode_IsStart){ Object.DestroyImmediate(tNode.GSDSpline.mNodes[0].transform.gameObject); tNode.GSDSpline.bSpecialStartControlNode = false; }else if(tNode.idOnSpline == tNode.GSDSpline.GetNodeCount()-2 && tNode.GSDSpline.mNodes[tNode.GSDSpline.GetNodeCount()-1].bSpecialEndNode_IsEnd){ Object.DestroyImmediate(tNode.GSDSpline.mNodes[tNode.GSDSpline.GetNodeCount()-1].transform.gameObject); tNode.GSDSpline.bSpecialEndControlNode = false; } } tNode.bIsIntersection = false; tNode.bSpecialIntersection = false; } if(tNode.Intersection_OtherNode != null){ if(tNode.Intersection_OtherNode.bIsEndPoint){ if(tNode.Intersection_OtherNode.idOnSpline == 1 && tNode.Intersection_OtherNode.GSDSpline.mNodes[0].bSpecialEndNode_IsStart){ Object.DestroyImmediate(tNode.Intersection_OtherNode.GSDSpline.mNodes[0].transform.gameObject); tNode.Intersection_OtherNode.GSDSpline.bSpecialStartControlNode = false; }else if(tNode.Intersection_OtherNode.idOnSpline == tNode.Intersection_OtherNode.GSDSpline.GetNodeCount()-2 && tNode.Intersection_OtherNode.GSDSpline.mNodes[tNode.Intersection_OtherNode.GSDSpline.GetNodeCount()-1].bSpecialEndNode_IsEnd){ Object.DestroyImmediate(tNode.Intersection_OtherNode.GSDSpline.mNodes[tNode.Intersection_OtherNode.GSDSpline.GetNodeCount()-1].transform.gameObject); tNode.Intersection_OtherNode.GSDSpline.bSpecialEndControlNode = false; } } tNode.Intersection_OtherNode.bIsIntersection = false; tNode.Intersection_OtherNode.bSpecialIntersection = false; } if(tNode != null && tNode.Intersection_OtherNode != null){ if(tNode.GSDSpline != tNode.Intersection_OtherNode.GSDSpline){ if(tNode != null){ tNode.GSDSpline.tRoad.bUpdateSpline = true; } if(tNode.Intersection_OtherNode != null){ tNode.Intersection_OtherNode.GSDSpline.tRoad.bUpdateSpline = true; } }else{ tNode.GSDSpline.tRoad.bUpdateSpline = true; } }else if(tNode != null){ tNode.GSDSpline.tRoad.bUpdateSpline = true; } }
public static void LoadNodeObjects(string tFileName, GSDSplineN tNode, bool bIsDefault = false, bool bIsBridge = false){ #if UNITY_WEBPLAYER return; #else string tPath = ""; GSDRootUtil.Dir_GetLibrary_CheckSpecialDirs(); string xPath = GSDRootUtil.Dir_GetLibrary(); if(bIsDefault){ tPath = xPath + "B/W/" + tFileName + ".gsd"; }else{ tPath = xPath + "B/" + tFileName + ".gsd"; } string tData = System.IO.File.ReadAllText(tPath); string[] tSep = new string[1]; tSep[0] = FileSepString; string[] tSplit = tData.Split(tSep,System.StringSplitOptions.RemoveEmptyEntries); Splination.SplinatedMeshMaker SMM = null; Splination.SplinatedMeshMaker.SplinatedMeshLibraryMaker SLM = null; EdgeObjects.EdgeObjectMaker EOM = null; EdgeObjects.EdgeObjectMaker.EdgeObjectLibraryMaker ELM = null; int tSplitCount = tSplit.Length; for(int i=0;i<tSplitCount;i++){ SLM = null; SLM = Splination.SplinatedMeshMaker.SLMFromData(tSplit[i]); if(SLM != null){ SMM = tNode.AddSplinatedObject(); SMM.LoadFromLibraryBulk(ref SLM); SMM.bToggle = false; if(bIsBridge && tNode.bIsBridgeStart && tNode.bIsBridgeMatched && tNode.BridgeCounterpartNode != null){ SMM.StartTime = tNode.tTime; SMM.EndTime = tNode.BridgeCounterpartNode.tTime; SMM.StartPos = tNode.GSDSpline.GetSplineValue(SMM.StartTime); SMM.EndPos = tNode.GSDSpline.GetSplineValue(SMM.EndTime); } continue; } ELM = null; ELM = EdgeObjects.EdgeObjectMaker.ELMFromData(tSplit[i]); if(ELM != null){ EOM = tNode.AddEdgeObject(); EOM.LoadFromLibraryBulk(ref ELM); EOM.bToggle = false; if(!EOM.bSingle && bIsBridge && tNode.bIsBridgeStart && tNode.bIsBridgeMatched && tNode.BridgeCounterpartNode != null){ EOM.StartTime = tNode.tTime; EOM.EndTime = tNode.BridgeCounterpartNode.tTime; EOM.StartPos = tNode.GSDSpline.GetSplineValue(EOM.StartTime); EOM.EndPos = tNode.GSDSpline.GetSplineValue(EOM.EndTime); }else if(EOM.bSingle && bIsBridge && tNode.BridgeCounterpartNode != null && tNode.bIsBridgeStart){ float tDist = (EOM.SingleOnlyBridgePercent * (tNode.BridgeCounterpartNode.tDist - tNode.tDist) + tNode.tDist); EOM.SinglePosition = tNode.GSDSpline.TranslateDistBasedToParam(tDist); EOM.StartPos = tNode.GSDSpline.GetSplineValue(EOM.SinglePosition); EOM.EndPos = tNode.GSDSpline.GetSplineValue(EOM.SinglePosition); } continue; } } tNode.SetupSplinatedMeshes(); tNode.SetupEdgeObjects(); #endif }
private void ActivateEndNodeConnection_Do(GSDSplineN tNode1, GSDSplineN tNode2){ GSDSplineC xSpline = tNode2.GSDSpline; int xCount = xSpline.GetNodeCount(); int mCount = GetNodeCount(); //Don't allow connection with less than 3 nodes: if(mCount < 3 || xCount < 3){ return; } Vector3 tNode1_ExtraPos = default(Vector3); Vector3 tNode2_ExtraPos = default(Vector3); bool bFirstNode_Start = false; // bool bFirstNode_End = false; if(tNode1.idOnSpline == 0){ bFirstNode_Start = true; tNode2_ExtraPos = mNodes[1].transform.position; }else{ // bFirstNode_End = true; tNode2_ExtraPos = mNodes[mCount-2].transform.position; } bool bSecondNode_Start = false; // bool bSecondNode_End = false; if(tNode2.idOnSpline == 0){ bSecondNode_Start = true; tNode1_ExtraPos = xSpline.mNodes[1].transform.position; }else{ // bSecondNode_End = true; tNode1_ExtraPos = xSpline.mNodes[xCount-2].transform.position; } GSDSplineN NodeCreated1 = null; GSDSplineN NodeCreated2 = null; if(bFirstNode_Start){ bSpecialStartControlNode = true; if(mNodes[0].bSpecialEndNode){ mNodes[0].transform.position = tNode1_ExtraPos; mNodes[0].pos = tNode1_ExtraPos; }else{ GSD.Roads.GSDConstruction.InsertNode(tRoad,true,tNode1_ExtraPos,false,0,true); } NodeCreated1 = mNodes[0]; }else{ bSpecialEndControlNode = true; GSDSplineN zNode1 = xSpline.GetLastNode_All(); if (zNode1 != null && zNode1.bSpecialEndNode) { zNode1.transform.position = tNode1_ExtraPos; zNode1.pos = tNode1_ExtraPos; }else{ GSD.Roads.GSDConstruction.CreateNode(tRoad,true,tNode1_ExtraPos); } NodeCreated1 = GetLastNode_All(); } if(bSecondNode_Start){ xSpline.bSpecialStartControlNode = true; if(xSpline.mNodes[0].bSpecialEndNode){ xSpline.mNodes[0].transform.position = tNode2_ExtraPos; xSpline.mNodes[0].pos = tNode2_ExtraPos; }else{ GSD.Roads.GSDConstruction.InsertNode(xSpline.tRoad,true,tNode2_ExtraPos,false,0,true); } NodeCreated2 = xSpline.mNodes[0]; }else{ xSpline.bSpecialEndControlNode = true; GSDSplineN zNode2 = xSpline.GetLastNode_All(); if (zNode2 != null && zNode2.bSpecialEndNode) { zNode2.transform.position = tNode2_ExtraPos; zNode2.pos = tNode2_ExtraPos; }else{ GSD.Roads.GSDConstruction.CreateNode(xSpline.tRoad,true,tNode2_ExtraPos); } NodeCreated2 = xSpline.GetLastNode_All(); } NodeCreated1.bSpecialEndNode_IsStart = bFirstNode_Start; NodeCreated2.bSpecialEndNode_IsStart = bSecondNode_Start; NodeCreated1.bSpecialEndNode_IsEnd = !bFirstNode_Start; NodeCreated2.bSpecialEndNode_IsEnd = !bSecondNode_Start; NodeCreated1.SpecialNodeCounterpart = NodeCreated2; NodeCreated2.SpecialNodeCounterpart = NodeCreated1; float lWidth1 = tNode1.GSDSpline.tRoad.opt_LaneWidth; float lWidth2 = tNode2.GSDSpline.tRoad.opt_LaneWidth; float xWidth = Mathf.Max(lWidth1,lWidth2); float tDelay = 0f; if(tNode1.GSDSpline.tRoad.opt_Lanes > tNode2.GSDSpline.tRoad.opt_Lanes){ tNode2.bSpecialRoadConnPrimary = true; NodeCreated2.bSpecialRoadConnPrimary = true; if(tNode2.GSDSpline.tRoad.opt_Lanes == 4){ xWidth *= 2f; } tDelay = (tNode1.GSDSpline.tRoad.opt_Lanes - tNode2.GSDSpline.tRoad.opt_Lanes) * xWidth; if(tDelay < 10f){ tDelay = 10f; } if(bSecondNode_Start){ tNode2.GSDSpline.bSpecialEndNode_IsStart_Delay = true; tNode2.GSDSpline.SpecialEndNodeDelay_Start = tDelay; tNode2.GSDSpline.SpecialEndNodeDelay_Start_Result = tNode1.GSDSpline.tRoad.RoadWidth(); tNode2.GSDSpline.SpecialEndNode_Start_OtherSpline = tNode1.GSDSpline; }else{ tNode2.GSDSpline.bSpecialEndNode_IsEnd_Delay = true; tNode2.GSDSpline.SpecialEndNodeDelay_End = tDelay; tNode2.GSDSpline.SpecialEndNodeDelay_End_Result = tNode1.GSDSpline.tRoad.RoadWidth(); tNode2.GSDSpline.SpecialEndNode_End_OtherSpline = tNode1.GSDSpline; } }else if(tNode2.GSDSpline.tRoad.opt_Lanes > tNode1.GSDSpline.tRoad.opt_Lanes){ tNode1.bSpecialRoadConnPrimary = true; NodeCreated1.bSpecialRoadConnPrimary = true; if(tNode1.GSDSpline.tRoad.opt_Lanes == 4){ xWidth *= 2f; } tDelay = (tNode2.GSDSpline.tRoad.opt_Lanes - tNode1.GSDSpline.tRoad.opt_Lanes) * xWidth; if(tDelay < 10f){ tDelay = 10f; } if(bFirstNode_Start){ tNode1.GSDSpline.bSpecialEndNode_IsStart_Delay = true; tNode1.GSDSpline.SpecialEndNodeDelay_Start = tDelay; tNode1.GSDSpline.SpecialEndNodeDelay_Start_Result = tNode2.GSDSpline.tRoad.RoadWidth(); tNode1.GSDSpline.SpecialEndNode_Start_OtherSpline = tNode2.GSDSpline; }else{ tNode1.GSDSpline.bSpecialEndNode_IsEnd_Delay = true; tNode1.GSDSpline.SpecialEndNodeDelay_End = tDelay; tNode1.GSDSpline.SpecialEndNodeDelay_End_Result = tNode2.GSDSpline.tRoad.RoadWidth(); tNode1.GSDSpline.SpecialEndNode_End_OtherSpline = tNode2.GSDSpline; } }else{ tNode1.bSpecialRoadConnPrimary = true; NodeCreated1.bSpecialRoadConnPrimary = true; tDelay = 0f; tNode1.GSDSpline.bSpecialEndNode_IsEnd_Delay = false; tNode1.GSDSpline.bSpecialEndNode_IsStart_Delay = false; tNode1.GSDSpline.SpecialEndNodeDelay_End = tDelay; tNode1.GSDSpline.SpecialEndNodeDelay_End_Result = tNode2.GSDSpline.tRoad.RoadWidth(); tNode1.GSDSpline.SpecialEndNode_End_OtherSpline = tNode2.GSDSpline; tNode2.GSDSpline.bSpecialEndNode_IsEnd_Delay = false; tNode2.GSDSpline.bSpecialEndNode_IsStart_Delay = false; tNode2.GSDSpline.SpecialEndNodeDelay_End = tDelay; tNode2.GSDSpline.SpecialEndNodeDelay_End_Result = tNode1.GSDSpline.tRoad.RoadWidth(); tNode2.GSDSpline.SpecialEndNode_End_OtherSpline = tNode1.GSDSpline; } tNode1.SpecialNodeCounterpart = NodeCreated1; tNode2.SpecialNodeCounterpart = NodeCreated2; NodeCreated1.SpecialNodeCounterpart_Master = tNode1; NodeCreated2.SpecialNodeCounterpart_Master = tNode2; NodeCreated1.ToggleHideFlags(true); NodeCreated2.ToggleHideFlags(true); // tNode1.GSDSpline.Setup_Trigger(); // if(tNode1.GSDSpline != tNode2.GSDSpline){ // tNode2.GSDSpline.Setup_Trigger(); // } if(tNode1 != null && tNode2 != null){ if(tNode1.GSDSpline != tNode2.GSDSpline){ tNode1.GSDSpline.tRoad.PiggyBacks = new GSDSplineC[1]; tNode1.GSDSpline.tRoad.PiggyBacks[0] = tNode2.GSDSpline; } tNode1.GSDSpline.tRoad.EditorUpdateMe = true; } }
public static GameObject CreateIntersection(GSDSplineN tNode,GSDSplineN xNode){ return CreateIntersection_Do(tNode,xNode); }
private void Setup_Nodes(ref GSDSplineN[] tNodesRaw){ //Process nodes: int i=0; List<GSDSplineN> tNodes = new List<GSDSplineN>(); int tNodesRawLength = tNodesRaw.Length; for(i=0;i<tNodesRawLength;i++){ if(!tNodesRaw[i].bDestroyed){ tNodes.Add(tNodesRaw[i]); } } mNodes.Clear(); mNodes = new List<GSDSplineN>(); GSDSplineN tNode; float step; Quaternion rot; bool bClosed = false; step = (bClosed) ? 1f / ((float)tNodes.Count) : 1f / ((float)(tNodes.Count - 1)); int tNodesCount = tNodes.Count; for(i=0;i<tNodesCount;i++){ tNode = tNodes[i]; rot = Quaternion.identity; if(i != tNodes.Count - 1){ if((tNodes[i+1].transform.position - tNode.transform.position) == Vector3.zero){ rot = Quaternion.identity; }else{ rot = Quaternion.LookRotation(tNodes[i+1].transform.position - tNode.transform.position, transform.up); } }else if (bClosed){ rot = Quaternion.LookRotation(tNodes[0].transform.position - tNode.transform.position, transform.up); }else{ rot = Quaternion.identity; } tNode.Setup(tNode.transform.position,rot,new Vector2 (0f, 1f),step*((float)i),tNode.transform.gameObject.name); tNode.SetupUniqueIdentifier(); mNodes.Add(tNode); } tNodes = null; tNodesRaw = null; }
private static GameObject CreateIntersection_Do(GSDSplineN tNode,GSDSplineN xNode){ float RoadMod = 10f; GameObject SystemObj = tNode.transform.parent.parent.parent.gameObject; if(!SystemObj){ Debug.LogWarning("Could not find GSD road system master object."); return null; } GameObject InterMaster = null; int cCount = SystemObj.transform.childCount; for(int i=0;i<cCount;i++){ if(SystemObj.transform.GetChild(i).transform.name.ToLower() == "intersections"){ InterMaster=SystemObj.transform.GetChild(i).gameObject; } } if(!InterMaster){ InterMaster = new GameObject("Intersections"); InterMaster.transform.parent = SystemObj.transform; } if(!InterMaster){ Debug.LogWarning("Could not find intersections master object for this road system."); return null; } cCount = InterMaster.transform.childCount; GameObject tObj = new GameObject("Inter" + (cCount+1).ToString()); tObj.transform.parent = InterMaster.transform; GSDRoadIntersection GSDRI = tObj.AddComponent<GSDRoadIntersection>(); GSDRI.IgnoreSide = -1; GSDRI.bFirstSpecial_First = false; GSDRI.bFirstSpecial_Last = false; GSDRI.bSecondSpecial_First = false; GSDRI.bSecondSpecial_Last = false; GSDSplineN tNode1 = null; GSDSplineN tNode2 = null; if(tNode.GSDSpline == xNode.GSDSpline){ if(tNode.idOnSpline < xNode.idOnSpline){ tNode1 = tNode; tNode2 = xNode; }else{ tNode1 = xNode; tNode2 = tNode; } }else{ tNode1 = tNode; tNode2 = xNode; } //If 3way, always add the single node as primary: if(tNode.bIsEndPoint){ tNode1 = tNode; tNode2 = xNode; }else if(xNode.bIsEndPoint){ tNode1 = xNode; tNode2 = tNode; } tNode1.Intersection_OtherNode = tNode2; tNode2.Intersection_OtherNode = tNode1; if(tNode1.bIsEndPoint || tNode2.bIsEndPoint){ GSDRI.iType = GSDRoadIntersection.IntersectionTypeEnum.ThreeWay; } GSDSplineN zNode = null; if(tNode1.bIsEndPoint){ bool bFirstNode = false; bool bAlreadyNode = false; if(tNode1.idOnSpline == 1 || tNode1.idOnSpline == 0){ bFirstNode = true; } if(bFirstNode && tNode1.idOnSpline == 1 && tNode1.GSDSpline.mNodes[0].bSpecialEndNode_IsStart){ bAlreadyNode = true; }else if(!bFirstNode && tNode1.idOnSpline == tNode1.GSDSpline.GetNodeCount()-2 && tNode1.GSDSpline.mNodes[tNode1.GSDSpline.GetNodeCount()-1].bSpecialEndNode_IsEnd){ bAlreadyNode = true; } Vector3 tPos = default(Vector3); if(bFirstNode){ tPos = ((tNode1.tangent * -1f).normalized * (tNode1.GSDSpline.tRoad.RoadWidth()*RoadMod)) + tNode1.pos; }else{ tPos = (tNode1.GSDSpline.GetSplineValue(0.999f,true).normalized * (tNode1.GSDSpline.tRoad.RoadWidth()*RoadMod)) + tNode1.pos; } if(!bAlreadyNode){ if(bFirstNode){ zNode = GSD.Roads.GSDConstruction.InsertNode(tNode1.GSDSpline.tRoad,true,tPos,false,0,true,true); zNode.bSpecialEndNode_IsStart = true; zNode.bSpecialIntersection = true; zNode.tangent = tNode1.tangent; }else{ zNode = GSD.Roads.GSDConstruction.CreateNode(tNode1.GSDSpline.tRoad,true,tPos,true); zNode.bSpecialEndNode_IsEnd = true; zNode.bSpecialIntersection = true; zNode.tangent = tNode1.tangent; } }else{ if(bFirstNode){ tNode1.GSDSpline.mNodes[0].transform.position = tPos; }else{ tNode1.GSDSpline.mNodes[tNode1.GSDSpline.GetNodeCount()-1].transform.position = tPos; } } if(bFirstNode){ tNode1.GSDSpline.bSpecialStartControlNode = true; GSDRI.bFirstSpecial_First = true; }else{ tNode1.GSDSpline.bSpecialEndControlNode = true; GSDRI.bFirstSpecial_Last = true; } }else if(tNode2.bIsEndPoint){ bool bFirstNode = false; bool bAlreadyNode = false; if(tNode2.idOnSpline == 1 || tNode2.idOnSpline == 0){ bFirstNode = true; } if(bFirstNode && tNode2.idOnSpline == 1 && tNode2.GSDSpline.mNodes[0].bSpecialEndNode_IsStart){ bAlreadyNode = true; }else if(!bFirstNode && tNode2.idOnSpline == tNode2.GSDSpline.GetNodeCount()-2 && tNode2.GSDSpline.mNodes[tNode2.GSDSpline.GetNodeCount()-1].bSpecialEndNode_IsEnd){ bAlreadyNode = true; } Vector3 tPos = default(Vector3); if(bFirstNode){ tPos = ((tNode2.tangent * -1f).normalized * (tNode2.GSDSpline.tRoad.RoadWidth()*RoadMod)) + tNode2.pos; }else{ tPos = (tNode2.GSDSpline.GetSplineValue(0.999f,true).normalized * (tNode2.GSDSpline.tRoad.RoadWidth()*RoadMod)) + tNode2.pos; } if(!bAlreadyNode){ if(bFirstNode){ zNode = GSD.Roads.GSDConstruction.InsertNode(tNode2.GSDSpline.tRoad,true,tPos,false,0,true,true); zNode.bSpecialEndNode_IsStart = true; zNode.bSpecialIntersection = true; zNode.tangent = tNode2.tangent; }else{ zNode = GSD.Roads.GSDConstruction.CreateNode(tNode2.GSDSpline.tRoad,true,tPos,true); zNode.bSpecialEndNode_IsEnd = true; zNode.bSpecialIntersection = true; zNode.tangent = tNode2.tangent; } }else{ if(bFirstNode){ tNode2.GSDSpline.mNodes[0].transform.position = tPos; }else{ tNode2.GSDSpline.mNodes[tNode2.GSDSpline.GetNodeCount()-1].transform.position = tPos; } } if(bFirstNode){ tNode2.GSDSpline.bSpecialStartControlNode = true; GSDRI.bSecondSpecial_First = true; }else{ tNode2.GSDSpline.bSpecialEndControlNode = true; GSDRI.bSecondSpecial_Last = true; } } //Undo crap: UnityEditor.Undo.RegisterCreatedObjectUndo(tObj, "Created intersection"); GSDRI.Setup(tNode1,tNode2); tObj.transform.position = tNode.transform.position; GSDRI.ResetMaterials_All(); // if(GSDRI.bSameSpline){ // GSDRI.Node1.GSDSpline.tRoad.UpdateRoad(); // }else{ // GSDRI.Node1.GSDSpline.tRoad.UpdateRoad(); // GSDRI.Node2.GSDSpline.tRoad.UpdateRoad(); // } tNode1.ToggleHideFlags(true); tNode2.ToggleHideFlags(true); if(GSDRI != null && GSDRI.Node1 != null && GSDRI.Node2 != null){ if(!GSDRI.bSameSpline){ GSDRI.Node1.GSDSpline.tRoad.PiggyBacks = new GSDSplineC[4]; GSDRI.Node1.GSDSpline.tRoad.PiggyBacks[0] = GSDRI.Node2.GSDSpline; GSDRI.Node1.GSDSpline.tRoad.PiggyBacks[1] = GSDRI.Node1.GSDSpline; GSDRI.Node1.GSDSpline.tRoad.PiggyBacks[2] = GSDRI.Node2.GSDSpline; GSDRI.Node1.GSDSpline.tRoad.PiggyBacks[3] = GSDRI.Node1.GSDSpline; // GSDRI.Node1.GSDSpline.tRoad.PiggyBacks[4] = GSDRI.Node2.GSDSpline; } GSDRI.Node1.GSDSpline.tRoad.EditorUpdateMe = true; } return tObj; }
public void Initialize(ref Rect _rect, WindowTypeEnum _windowType, GSDSplineN _node, GSD.Roads.Splination.SplinatedMeshMaker _SMM = null, GSD.Roads.EdgeObjects.EdgeObjectMaker _EOM = null) { int Rheight = 300; int Rwidth = 360; float Rx = ((float)_rect.width / 2f) - ((float)Rwidth / 2f) + _rect.x; float Ry = ((float)_rect.height / 2f) - ((float)Rheight / 2f) + _rect.y; if (Rx < 0) { Rx = _rect.x; } if (Ry < 0) { Ry = _rect.y; } if (Rx > (_rect.width + _rect.x)) { Rx = _rect.x; } if (Ry > (_rect.height + _rect.y)) { Ry = _rect.y; } Rect fRect = new Rect(Rx, Ry, Rwidth, Rheight); if (fRect.width < 300) { fRect.width = 300; fRect.x = _rect.x; } if (fRect.height < 300) { fRect.height = 300; fRect.y = _rect.y; } position = fRect; tWindowType = _windowType; Show(); titleContent.text = "Save"; if (tWindowType == WindowTypeEnum.Extrusion) { titleText = "Save extrusion"; tSMMs = new GSD.Roads.Splination.SplinatedMeshMaker[1]; tSMMs[0] = _SMM; if (_SMM != null) { fileName = _SMM.tName; displayName = fileName; } } else if (tWindowType == WindowTypeEnum.Edge) { titleText = "Save edge object"; tEOMs = new GSD.Roads.EdgeObjects.EdgeObjectMaker[1]; tEOMs[0] = _EOM; if (_EOM != null) { fileName = _EOM.tName; displayName = fileName; } } else if (tWindowType == WindowTypeEnum.BridgeWizard) { isBridge = true; tSMMs = _node.SplinatedObjects.ToArray(); tEOMs = _node.EdgeObjects.ToArray(); titleText = "Save group"; fileName = "Group" + Random.Range(0, 10000).ToString(); displayName = fileName; } if (xPath.Length < 5) { xPath = GSDRootUtil.Dir_GetLibrary(); } if (tWindowType == WindowTypeEnum.Edge) { if (System.IO.File.Exists(xPath + "EOM" + fileName + ".gsd")) { fileExists = true; } else { fileExists = false; } } else if (tWindowType == WindowTypeEnum.Extrusion) { if (System.IO.File.Exists(xPath + "ESO" + fileName + ".gsd")) { fileExists = true; } else { fileExists = false; } } else { if (System.IO.File.Exists(xPath + "B/" + fileName + ".gsd")) { fileExists = true; } else { fileExists = false; } } }
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; }
public void TunnelResetValues(){ bIsTunnel = false; bIsTunnelStart = false; bIsTunnelEnd = false; bIsTunnelMatched = false; TunnelCounterpartNode = null; }
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; }
private void BridgeStart(){ //Cycle through nodes until you find another end or another start (in this case, no creation, encountered another bridge): int EndID = idOnSpline + 1; int mCount = GSDSpline.GetNodeCount(); if(bIsEndPoint){ //Attempted to make end point node a bridge node: bIsBridgeStart = false; return; } if(EndID >= mCount){ //Attempted to make last node a bridge node: bIsBridgeStart = false; return; }else if(idOnSpline == 0){ //Attempted to make first node a bridge node: bIsBridgeStart = false; return; } bIsBridgeMatched = false; BridgeCounterpartNode = null; int StartI = idOnSpline+1; GSDSplineN tNode = null; for(int i=StartI;i<mCount;i++){ tNode = GSDSpline.mNodes[i]; if(tNode.bIsIntersection){ //Encountered intersection. End search. return; } if(tNode.bIsBridgeStart){ //Encountered another bridge. Return: return; } if(tNode.bIgnore){ continue; } if(tNode.bIsBridgeEnd){ bIsBridgeMatched = true; tNode.bIsBridgeMatched = true; BridgeCounterpartNode = tNode; tNode.BridgeCounterpartNode = this; GSDSpline.Setup_Trigger(); return; } } }
/// <summary> /// Use this to insert nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates. /// </summary> /// <param name="RS">The road system to insert nodes in.</param> /// <param name="NodeLocation">The location of the newly inserted node.</param> /// <returns></returns> public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLocation) { GameObject tNodeObj; Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN)); tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString()); //Set node location: if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; } //Make sure it doesn't try to create a node below 0 height. tNodeObj.transform.position = NodeLocation; //Set the node's parent: tNodeObj.transform.parent = RS.GSDSplineObj.transform; int cCount = RS.GSDSpline.mNodes.Count; //Get the closet param on spline: float tParam = RS.GSDSpline.GetClosestParam(NodeLocation, false, true); bool bEndInsert = false; bool bZeroInsert = false; int iStart = 0; if (GSDRootUtil.IsApproximately(tParam, 0f, 0.0001f)) { bZeroInsert = true; iStart = 0; } else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f)) { //Inserted at end, switch to create node instead: Object.DestroyImmediate(tNodeObj); return(CreateNode_Programmatically(RS, NodeLocation)); } //Figure out where to insert the node: for (int i = 0; i < cCount; i++) { GSDSplineN xNode = RS.GSDSpline.mNodes[i]; if (!bZeroInsert && !bEndInsert) { if (tParam > xNode.tTime) { iStart = xNode.idOnSpline + 1; } } } for (int i = iStart; i < cCount; i++) { RS.GSDSpline.mNodes[i].idOnSpline += 1; } GSDSplineN tNode = tNodeObj.AddComponent <GSDSplineN>(); tNode.GSDSpline = RS.GSDSpline; tNode.idOnSpline = iStart; tNode.pos = NodeLocation; RS.GSDSpline.mNodes.Insert(iStart, tNode); //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates RS.UpdateRoad(); return(tNode); }