/// <summary> /// Divides the Current Section in half /// </summary> public void InsertSection() { int CurrIdx = BezCtrlPt.Current.CtrlPtId; int newSectnIdx = CurrIdx + 1; iRoadSectn CurrSectn = Rd.Sectns[CurrIdx]; int CurrSectnSegStartId = BezCtrlPt.Current.SegStartIdx; int CurrSectnSegCount = BezCtrlPt.Current.SegCount; int CurrSectnNewSegCount = CurrSectnSegCount / 2; int NewSectnSegStartId = CurrSectnSegStartId + CurrSectnNewSegCount; int NewSectnSegCount = CurrSectnSegCount - CurrSectnNewSegCount; int NxtSectnStartId = Bez.CtrlPts[newSectnIdx].SegStartIdx; //Insert Bezier Control Point Vector3 NewPos = Bez.Path[NewSectnSegStartId]; BezCtrlPt NewCtrlPt = new BezCtrlPt(Bez, NewPos); NewCtrlPt.BankAngle = BezCtrlPt.Current.BankAngle; Bez.CtrlPts.Insert(newSectnIdx, NewCtrlPt); Bez.SetCtrlPtIds(); //We dont have to move the path points from the old CtrlPt to the new one BezCtrlPt.Current.SegCount = CurrSectnNewSegCount; NewCtrlPt.SegCount = NewSectnSegCount; Bez.SetSegStartIds(); NewCtrlPt.CreateRoadMarker(); Bez.Interp(newSectnIdx - 1); Bez.Interp(newSectnIdx); Bez.Interp(newSectnIdx + 1); Bez.DrawLine(); Bez.AlignAllRoadMarkers(); //Insert Section iRoadSectn NewSectn = new RoadSectn(); NewSectn.Chargeable = false; NewSectn.Idx = newSectnIdx; NewSectn.LFenceType = CurrSectn.LFenceType; NewSectn.RFenceType = CurrSectn.RFenceType; NewSectn.SetMaterial(CurrSectn.Segments[0].roadMaterial); NewSectn.CreateGameObjects(); NewSectn.name = "RoadSection" + (newSectnIdx); NewSectn.goSectn.name = "RoadSection" + (newSectnIdx); Road.Instance.Sectns.Insert(newSectnIdx, NewSectn); // Section1 comes after RoadMarker1 Rd.OrganiseObjectsUsingBezierCtrlPtsAndPath(); /* * XSecCalculator.CalcXSecs(newSectnIdx-1, RoadWidth); * XSecCalculator.CalcXSecs(newSectnIdx, RoadWidth); * XSecCalculator.CalcXSecs(newSectnIdx+1, RoadWidth); * * CurrSectn.CalcFenceVerts(); * NewSectn.CalcFenceVerts(); * BuildQueue.Enqueue(newSectnIdx-1); * BuildQueue.Enqueue(newSectnIdx); */ }