public void RemoveLastNode() { GSDSplineC spline = GetComponent <GSDSplineC>(); spline.mNodes.RemoveAt(spline.mNodes.Count - 1); spline.tRoad.UpdateRoad(); }
public static void UpdateAllRoads() { GSDRoad[] allRoadObjects = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad)); int roadCount = allRoadObjects.Length; GSDRoad singleRoad = null; GSDSplineC[] tPiggys = null; if (roadCount > 1) { tPiggys = new GSDSplineC[roadCount - 1]; } for (int count = 0; count < roadCount; count++) { singleRoad = allRoadObjects[count]; if (count > 0) { tPiggys[count - 1] = singleRoad.GSDSpline; } } singleRoad = allRoadObjects[0]; if (tPiggys != null && tPiggys.Length > 0) { singleRoad.PiggyBacks = tPiggys; } singleRoad.UpdateRoad(); }
public static void UpdateAllRoads() { GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad)); int RoadCount = tRoadObjs.Length; GSDRoad tRoad = null; GSDSplineC[] tPiggys = null; if(RoadCount > 1){ tPiggys = new GSDSplineC[RoadCount-1]; } for(int h=0;h<RoadCount;h++){ tRoad=tRoadObjs[h]; if(h > 0){ tPiggys[h-1] = tRoad.GSDSpline; } } tRoad=tRoadObjs[0]; if(tPiggys != null && tPiggys.Length > 0){ tRoad.PiggyBacks = tPiggys; } tRoad.UpdateRoad(); }
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); } }
public void UpdateAllRoads() { GSDRoad[] tRoadObjs = GetComponentsInChildren <GSDRoad>(); // int i=0; int RoadCount = tRoadObjs.Length; GSDRoad tRoad = null; GSDSplineC[] tPiggys = null; if (RoadCount > 1) { tPiggys = new GSDSplineC[RoadCount]; for (int h = 0; h < RoadCount; h++) { tRoad = tRoadObjs[h]; tPiggys[h] = tRoad.GSDSpline; } } tRoad = tRoadObjs[0]; if (tPiggys != null && tPiggys.Length > 0) { tRoad.PiggyBacks = tPiggys; } tRoad.UpdateRoad(); }
public static void UpdateAllRoads() { GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad)); int RoadCount = tRoadObjs.Length; GSDRoad tRoad = null; GSDSplineC[] tPiggys = null; if (RoadCount > 1) { tPiggys = new GSDSplineC[RoadCount - 1]; } for (int h = 0; h < RoadCount; h++) { tRoad = tRoadObjs[h]; if (h > 0) { tPiggys[h - 1] = tRoad.GSDSpline; } } tRoad = tRoadObjs[0]; if (tPiggys != null && tPiggys.Length > 0) { tRoad.PiggyBacks = tPiggys; } tRoad.UpdateRoad(); }
void Start() { spline = road.GSDSpline; foreach (var node in spline.mNodes) { Debug.Log(node.tName + " time: " + node.tTime); } }
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); }
public void UpdateRoads() { #if UNITY_EDITOR if (!bSameSpline) { GSDSplineC[] tPiggys = new GSDSplineC[1]; tPiggys[0] = Node2.GSDSpline; Node1.GSDSpline.tRoad.PiggyBacks = tPiggys; Node1.GSDSpline.Setup_Trigger(); } else { Node1.GSDSpline.Setup_Trigger(); } #endif }
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); } }
private static float GetLongestSplineDistance(GSDSplineC s1, GSDSplineC s2){ if(s1.distance > s2.distance){ return s1.distance; }else{ return s2.distance; } }
private static void ProcessRoad_Terrain_Hook2_Do(ref GSDSplineC tSpline,ref List<TempTerrainData> TTDList){ if(!tSpline.tRoad.opt_TreeModEnabled && !tSpline.tRoad.opt_HeightModEnabled && !tSpline.tRoad.opt_DetailModEnabled){ //Exit if no mod taking place. return; } Object[] TIDs = GameObject.FindObjectsOfType(typeof(GSDTerrain)); Terrain tTerrain; int[,] tDetails = null; int IntBufferX = 0; int IntBufferY = 0; int tVal = 0; // ushort Invalid = 16384; foreach(TempTerrainData TTD in TTDList){ foreach(GSDTerrain TID in TIDs){ if(TID.GSDID == TTD.GSDID){ tTerrain = TID.transform.gameObject.GetComponent<Terrain>(); if(tTerrain != null){ //Details: if(tSpline.tRoad.opt_DetailModEnabled){ for(int i=0;i<TTD.DetailLayersCount;i++){ // if(TTD.DetailLayersSkip.Contains(i) || TTD.DetailValues[i] == null){ continue; } // if(TTD.DetailsI[i] > 0){ // tTerrain.terrainData.SetDetailLayer(0,0,i,TTD.DetailValues[i]); // } if(TTD.DetailLayersSkip.Contains(i) || TTD.MainDetailsX == null || TTD.MainDetailsX.Count < 1){ continue; } tDetails = tTerrain.terrainData.GetDetailLayer(0,0,TTD.DetailMaxIndex,TTD.DetailMaxIndex,i); int MaxCount = TTD.MainDetailsX.Count; for(int j=0;j<MaxCount;j++){ IntBufferX = TTD.MainDetailsX[j]; IntBufferY = TTD.MainDetailsY[j]; tVal = tDetails[IntBufferX,IntBufferY]; if(tVal > 0){ TTD.DetailsX[i].Add((ushort)IntBufferX); TTD.DetailsY[i].Add((ushort)IntBufferY); TTD.OldDetailsValue[i].Add((ushort)tVal); tDetails[IntBufferX,IntBufferY] = 0; } } TTD.DetailsI[i] = TTD.DetailsX[i].Count; tTerrain.terrainData.SetDetailLayer(0,0,i,tDetails); tDetails = null; TTD.DetailHasProcessed = null; } TTD.MainDetailsX = null; TTD.MainDetailsY = null; System.GC.Collect(); } //Trees: if(tSpline.tRoad.opt_TreeModEnabled && TTD.TreesCurrent != null && TTD.TreesI > 0){ tTerrain.terrainData.treeInstances = TTD.TreesCurrent.ToArray(); } //Heights: if(tSpline.tRoad.opt_HeightModEnabled && TTD.heights != null && TTD.cI > 0){ //Do heights last to trigger collisions and stuff properly: tTerrain.terrainData.SetHeights(0,0,TTD.heights); } } } } } }
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; } }
public void Init(GSDSplineC _tSpline, GSDSplineN _tNode, Transform tTrans){ tSpline = _tSpline; tNode = _tNode; MasterObjTrans = tTrans; SetupUniqueIdentifier(); }
public void Setup(ref List<GSD.Roads.GSDTerraforming.TempTerrainData> _TTDList, GSDSplineC _tSpline, GSDRoad _tRoad) { TTDList = _TTDList; tSpline = _tSpline; tRoad = _tRoad; }
private static float ProcessCoordinateGrabber(ref float param, ref GSDSplineC tSpline, ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, ref List<TerrainBoundsMaker> tList,ref int[] tXY, bool bIsBridge, bool bIsTunnel) { int MinX = tXY[0]; int MinY = tXY[1]; int MaxX = tXY[2]; int MaxY = tXY[3]; if(MinX >= TTD.TerrainMaxIndex){ MinX = TTD.TerrainMaxIndex-1; } if(MinY >= TTD.TerrainMaxIndex){ MinY = TTD.TerrainMaxIndex-1; } if(MaxX >= TTD.TerrainMaxIndex){ MaxX = TTD.TerrainMaxIndex-1; } if(MaxY >= TTD.TerrainMaxIndex){ MaxY = TTD.TerrainMaxIndex-1; } if(MinX < 0){ MinX = 0; } if(MinY < 0){ MinY = 0; } if(MaxX < 0){ MaxX = 0; } if(MaxY < 0){ MaxY = 0; } Vector3 xVect = default(Vector3); bool bAdjusted = false; float tHeight = -1f; float tReturnFloat = 0f; // int dX = 0; // int dY = 0; // int tdX = 0; // int tdY = 0; // bool bOneHit = false; for(int i=MinX;i<=MaxX;i++){ for(int k=MinY;k<=MaxY;k++){ if(TTD.tHeights[i,k] != true){ if(TTD.cX.Length <= TTD.cI){ break; } xVect = ConvertTerrainCoordToWorldVect(i,k,TTD.heights[i,k],ref TTD); AdjustedTerrainVect_Tri(ref param, out bAdjusted,out tHeight,ref xVect,ref tList, bIsBridge, bIsTunnel); if(bAdjusted){ tHeight-= tSpline.tRoad.opt_TerrainSubtract_Match; if(tHeight < 0f){ tHeight = 0f; } xVect.y = tHeight; tHeight = ((tHeight) / TTD.TerrainSize.y); //Set height values: TTD.tHeights[i,k] = true; TTD.cX[TTD.cI] = (ushort)i; TTD.cY[TTD.cI] = (ushort)k; TTD.oldH[TTD.cI] = TTD.heights[i,k]; TTD.heights[i,k] = tHeight; TTD.cI+=1; tReturnFloat = xVect.y; // bOneHit = true; } }else{ xVect = ConvertTerrainCoordToWorldVect(i,k,TTD.heights[i,k],ref TTD); AdjustedTerrainVect_Tri(ref param, out bAdjusted,out tHeight,ref xVect,ref tList, bIsBridge, bIsTunnel); if(bAdjusted){ tHeight-= tSpline.tRoad.opt_TerrainSubtract_Match; if(tHeight < 0f){ tHeight = 0f; } tReturnFloat = tHeight; // bOneHit = true; } } } } if(bIsBridge && IsApproximately(tReturnFloat,0f,0.0001f)){ tReturnFloat = tSpline.GetSplineValue(param,false).y; } return tReturnFloat; }
//Privatized for obfuscate: public static void DoRects(GSDSplineC tSpline, GSD.Roads.GSDTerraforming.TempTerrainData TTD) { DoRectsDo(ref tSpline, ref TTD); }
public static void ProcessRoad_Terrain_Hook1(GSDSplineC tSpline, GSDRoad tRoad, bool bMultithreaded = true){ ProcessRoad_Terrain_Hook1_Do(ref tSpline, ref tRoad, bMultithreaded); }
public void UpdateRoads(){ #if UNITY_EDITOR if(!bSameSpline){ GSDSplineC[] tPiggys = new GSDSplineC[1]; tPiggys[0] = Node2.GSDSpline; Node1.GSDSpline.tRoad.PiggyBacks = tPiggys; Node1.GSDSpline.Setup_Trigger(); }else{ Node1.GSDSpline.Setup_Trigger(); } #endif }
private void Construction_Cleanup(){ FixZ(); if(TerrainCalcsJob != null){ TerrainCalcsJob.Abort(); TerrainCalcsJob = null; } if(RoadCalcsJob1 != null){ RoadCalcsJob1.Abort(); RoadCalcsJob1 = null; } if(RoadCalcsJob2 != null){ RoadCalcsJob2.Abort(); RoadCalcsJob2 = null; } Editor_bIsConstructing = false; int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode; for(int i=0;i<mCount;i++){ tNode = GSDSpline.mNodes[i]; if(tNode.bIsIntersection){ if(tNode.iConstruction != null){ tNode.iConstruction.Nullify(); tNode.iConstruction = null; } } tNode.SetupSplinationLimits(); tNode.SetupEdgeObjects(false); tNode.SetupSplinatedMeshes(false); } if(GSDSpline.HeightHistory != null){ GSDSpline.HeightHistory.Clear(); GSDSpline.HeightHistory = null; } if(RCS != null){ RCS.Nullify(); RCS = null; } if(GSDRS.opt_bSaveMeshes){ UnityEditor.AssetDatabase.SaveAssets(); } bEditorProgressBar = false; EditorUtility.ClearProgressBar(); //Make sure terrain history out of memory if necessary (redudant but keep): if(opt_SaveTerrainHistoryOnDisk && TerrainHistory != null){ TerrainHistory.Clear(); TerrainHistory = null; } //Collect: bTriggerGC = true; if (tRoadMaterialDropdownOLD != opt_tRoadMaterialDropdown) { tRoadMaterialDropdownOLD = opt_tRoadMaterialDropdown; SetAllCutsToCurrentMaterials(); } if(PiggyBacks != null && PiggyBacks.Length > 0){ for(int i=0;i<PiggyBacks.Length;i++){ if(PiggyBacks[i] == null){ PiggyBacks = null; break; } } if(PiggyBacks != null){ GSDSplineC tPiggy = PiggyBacks[0]; GSDSplineC[] NewPiggys = null; PiggyBacks[0] = null; if(PiggyBacks.Length > 1){ NewPiggys = new GSDSplineC[PiggyBacks.Length-1]; for(int i=1;i<PiggyBacks.Length;i++){ NewPiggys[i-1] = PiggyBacks[i]; } } if(NewPiggys != null){ tPiggy.tRoad.PiggyBacks = NewPiggys; } NewPiggys = null; tPiggy.Setup_Trigger(); } } }
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); }
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; }
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); } }
private static void SetVectorHeight2(ref Vector3 tWorldVect, ref float p, ref List<KeyValuePair<float,float>> tList, ref GSDSplineC tSpline) { int mCount = tList.Count; int i=0; if(mCount < 1){ tWorldVect.y = 0f; return; } float cValue = 0f; for(i=0;i<(mCount-1);i++){ if(p >= tList[i].Key && p < tList[i+1].Key){ cValue = tList[i].Value; if(i > 3){ if(tList[i-1].Value < cValue){ cValue = tList[i-1].Value; } if(tList[i-2].Value < cValue){ cValue = tList[i-2].Value; } if(tList[i-3].Value < cValue){ cValue = tList[i-3].Value; } } if(i < (mCount-3)){ if(tList[i+1].Value < cValue){ cValue = tList[i+1].Value; } if(tList[i+2].Value < cValue){ cValue = tList[i+2].Value; } if(tList[i+3].Value < cValue){ cValue = tList[i+3].Value; } } break; } } //if(p > 0.95f && GSDRootUtil.IsApproximately(cValue,0f,0.001f)){ // float DeadValue = 0f; // Vector3 tPos = tSpline.GetSplineValue(p,false); // if(!tSpline.IsNearIntersection(ref tPos,ref DeadValue)){ // cValue = tList[tList.Count-1].Value; // } //} //Zero protection: if (GSDRootUtil.IsApproximately(cValue, 0f, 0.001f) && tWorldVect.y > 0f) { cValue = tWorldVect.y-0.35f; } tWorldVect.y = cValue; }
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; }
private static void DoRectsDo(ref GSDSplineC tSpline,ref GSD.Roads.GSDTerraforming.TempTerrainData TTD) { float Sep = tSpline.tRoad.RoadWidth()*0.5f; float HeightSep = Sep + (tSpline.tRoad.opt_MatchHeightsDistance * 0.5f); List<TerrainBoundsMaker> TBMList = new List<TerrainBoundsMaker>(); // List<GSD.Roads.GSDRoadUtil.Construction3DTri> triList = new List<GSD.Roads.GSDRoadUtil.Construction3DTri>(); List<GSD.Roads.GSDRoadUtil.Construction2DRect> TreerectList = new List<GSD.Roads.GSDRoadUtil.Construction2DRect>(); float tStep = tSpline.tRoad.opt_RoadDefinition / tSpline.distance; // tStep *= 0.5f; //Start initializing the loop. Convuluted to handle special control nodes, so roads don't get rendered where they aren't supposed to, while still preserving the proper curvature. float FinalMax = 1f; float StartMin = 0f; if(tSpline.bSpecialEndControlNode){ //If control node, start after the control node: FinalMax = tSpline.mNodes[tSpline.GetNodeCount()-2].tTime; } if(tSpline.bSpecialStartControlNode){ //If ends in control node, end construction before the control node: StartMin = tSpline.mNodes[1].tTime; } // bool bFinalEnd = false; // float RoadConnection_StartMin1 = StartMin; //Storage of incremental start values for the road connection mesh construction at the end of this function. // float RoadConnection_FinalMax1 = FinalMax; //Storage of incremental end values for the road connection mesh construction at the end of this function. if(tSpline.bSpecialEndNode_IsStart_Delay){ StartMin += (tSpline.SpecialEndNodeDelay_Start / tSpline.distance); //If there's a start delay (in meters), delay the start of road construction: Due to special control nodes for road connections or 3 way intersections. }else if(tSpline.bSpecialEndNode_IsEnd_Delay){ FinalMax -= (tSpline.SpecialEndNodeDelay_End / tSpline.distance); //If there's a end delay (in meters), cut early the end of road construction: Due to special control nodes for road connections or 3 way intersections. } // float RoadConnection_StartMin2 = StartMin; //Storage of incremental start values for the road connection mesh construction at the end of this function. // float RoadConnection_FinalMax2 = FinalMax; //Storage of incremental end values for the road connection mesh construction at the end of this function. FinalMax = FinalMax + tStep; Vector3 tVect1 = default(Vector3); Vector3 tVect2 = default(Vector3); Vector3 POS1 = default(Vector3); Vector3 POS2 = default(Vector3); if(FinalMax > 1f){ FinalMax = 1f; } float tNext = 0f; float fValue1,fValue2; float fValueMod = tSpline.tRoad.opt_RoadDefinition / tSpline.distance; bool bIsPastInter = false; float tIntStrength = 0f; float tIntStrength2 = 0f; // bool bMaxIntersection = false; // bool bFirstInterNode = false; GSDSplineN xNode = null; float tIntHeight = 0f; float tIntHeight2 = 0f; GSDRoadIntersection GSDRI = null; float T1SUB = 0f; float T2SUB = 0f; bool bIntStr1_Full = false; bool bIntStr1_FullPrev = false; bool bIntStr1_FullNext = false; bool bIntStr2_Full = false; bool bIntStr2_FullPrev = false; bool bIntStr2_FullNext = false; Vector3 tVect3 = default(Vector3); // bool bStarted = false; // bool T3Added = false; List<int[]> tXYs = new List<int[]>(); float TreeClearDist = tSpline.tRoad.opt_ClearTreesDistance; if(TreeClearDist < tSpline.tRoad.RoadWidth()){ TreeClearDist = tSpline.tRoad.RoadWidth(); } GSD.Roads.GSDRoadUtil.Construction2DRect tRect = null; float tGrade = 0f; for(float i=StartMin;i<FinalMax;i+=tStep){ if(tSpline.tRoad.opt_HeightModEnabled){ if(i > 1f){ break; } tNext = i+tStep; if(tNext > 1f){ break; } tSpline.GetSplineValue_Both(i,out tVect1,out POS1); if(tNext <= 1f){ tSpline.GetSplineValue_Both(tNext,out tVect2,out POS2); }else{ tSpline.GetSplineValue_Both(1f,out tVect2,out POS2); } //Determine if intersection: bIsPastInter = false; //If past intersection tIntStrength = tSpline.IntersectionStrength(ref tVect1,ref tIntHeight, ref GSDRI, ref bIsPastInter, ref i, ref xNode); // if(IsApproximately(tIntStrength,1f,0.001f) || tIntStrength > 1f){ // bMaxIntersection = true; // }else{ // bMaxIntersection = false; // } // bFirstInterNode = false; tIntStrength2 = tSpline.IntersectionStrength(ref tVect2,ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref i, ref xNode); if(tIntStrength2 > 1f){ tIntStrength2 = 1f; } T1SUB = tVect1.y; T2SUB = tVect2.y; if(tIntStrength > 1f){ tIntStrength = 1f; } if(tIntStrength >= 0f){// || IsApproximately(tIntStrength,0f,0.01f)){ if(IsApproximately(tIntStrength,1f,0.01f)){ T1SUB = tIntHeight; bIntStr1_Full = true; bIntStr1_FullNext = false; }else{ bIntStr1_Full = false; bIntStr1_FullNext = (tIntStrength2 >= 1f); if(!IsApproximately(tIntStrength,0f,0.01f)){ T1SUB = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect1.y); } // if(tIntStrength <= 0f){ T1SUB = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect1.y); } } if((bIntStr1_Full && !bIntStr1_FullPrev) || (!bIntStr1_Full && bIntStr1_FullNext)){ tGrade = tSpline.GetCurrentNode(i).GradeToPrevValue; if(tGrade < 0f){ T1SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,(tGrade/20f)*-1f); }else{ T1SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,tGrade/20f); } // if(tGrade < 0f){ // T1SUB *= -1f; // } }else if(bIntStr1_Full && !bIntStr1_FullNext){ tGrade = tSpline.GetCurrentNode(i).GradeToNextValue; if(tGrade < 0f){ T1SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,(tGrade/20f)*-1f); }else{ T1SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,tGrade/20f); } // if(tGrade < 0f){ // T1SUB *= -1f; // } }else{ T1SUB -= 0.02f; } bIntStr1_FullPrev = bIntStr1_Full; } if(tIntStrength2 >= 0f || IsApproximately(tIntStrength2,0f,0.01f)){ // if(!IsApproximately(tIntStrength,1f,0.01f)){ if(IsApproximately(tIntStrength,1f,0.01f)){ bIntStr2_Full = true; T2SUB = tIntHeight2; }else{ bIntStr2_Full = false; if(!IsApproximately(tIntStrength2,0f,0.01f)){ T2SUB = (tIntStrength2*tIntHeight) + ((1-tIntStrength2)*tVect2.y); } // if(tIntStrength2 <= 0f){ T2SUB = (tIntStrength2*tIntHeight) + ((1-tIntStrength2)*tVect2.y); } } if((bIntStr2_Full && !bIntStr2_FullPrev)){ tGrade = tSpline.GetCurrentNode(i).GradeToPrevValue; if(tGrade < 0f){ T2SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,(tGrade/20f)*-1f); }else{ T2SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,tGrade/20f); } // T2SUB -= tIntHeight2 - tVect2.y; }else if(bIntStr2_Full && !bIntStr2_FullNext){ tGrade = tSpline.GetCurrentNode(i).GradeToNextValue; if(tGrade < 0f){ T2SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,(tGrade/20f)*-1f); }else{ T2SUB -= Mathf.Lerp(0.02f,GSDRI.GradeMod,tGrade/20f); } // if(tGrade < 0f){ // T2SUB *= -1f; // } // T2SUB -= tIntHeight2 - tVect2.y; }else if(!bIntStr2_Full){ if(tNext+tStep < 1f){ tVect3 = tSpline.GetSplineValue(tNext+tStep,false); tIntStrength2 = tSpline.IntersectionStrength(ref tVect3,ref tIntHeight2, ref GSDRI, ref bIsPastInter, ref i, ref xNode); }else{ tIntStrength2 = 0f; } if(tIntStrength2 >= 1f){ T2SUB -= 0.06f; }else{ T2SUB -= 0.02f; } }else{ T2SUB -= 0.02f; } bIntStr2_FullPrev = bIntStr2_Full; } fValue1=i - fValueMod; fValue2=i + fValueMod; if(fValue1 < 0){ fValue1 = 0; } if(fValue2 > 1){ fValue2 = 1; } tXYs.Add(CreateTris(fValue1,fValue2,ref tVect1,ref POS1,ref tVect2,ref POS2,Sep,ref TBMList,ref T1SUB, ref T2SUB, ref TTD, HeightSep)); //Details and trees: tRect = SetDetailCoords(i,ref tVect1,ref POS1,ref tVect2, ref POS2,tSpline.tRoad.opt_ClearDetailsDistance,TreeClearDist, ref TTD, ref tSpline); if(tSpline.tRoad.opt_TreeModEnabled && tRect != null){ TreerectList.Add(tRect); } }else{ if(i > 1f){ break; } tNext = i+tStep; if(tNext > 1f){ break; } tSpline.GetSplineValue_Both(i,out tVect1,out POS1); if(tNext <= 1f){ tSpline.GetSplineValue_Both(tNext,out tVect2,out POS2); }else{ tSpline.GetSplineValue_Both(1f,out tVect2,out POS2); } //Details and trees: tRect = SetDetailCoords(i,ref tVect1,ref POS1,ref tVect2, ref POS2,tSpline.tRoad.opt_ClearDetailsDistance,TreeClearDist, ref TTD, ref tSpline); if(tSpline.tRoad.opt_TreeModEnabled && tRect != null){ TreerectList.Add(tRect); } } } if(tSpline.tRoad.bProfiling){ Profiler.BeginSample("DoRectsTree"); } if(tSpline.tRoad.opt_TreeModEnabled && TreerectList != null && TreerectList.Count > 0){ int tCount = TTD.TreeSize; int jCount = TreerectList.Count; Vector3 tVect3D = default(Vector3); Vector2 tVect2D = default(Vector2); TreeInstance tTree; for(int i=0;i<tCount;i++){ tTree = TTD.TreesCurrent[i]; tVect3D = tTree.position; tVect3D.x *= TTD.TerrainSize.z; tVect3D.y *= TTD.TerrainSize.y; tVect3D.z *= TTD.TerrainSize.x; tVect3D += TTD.TerrainPos; tVect2D.x = tVect3D.x; tVect2D.y = tVect3D.z; for(int j=0;j<jCount;j++){ if(TreerectList[j].Contains(ref tVect2D)){ TTD.TreesOld.Add(TTD.TreesCurrent[i]); tTree = TTD.TreesCurrent[i]; tTree.prototypeIndex = -2; TTD.TreesCurrent[i] = tTree; TTD.TreesI+=1; break; } } } TTD.TreesCurrent.RemoveAll(item => item.prototypeIndex < -1); } if(tSpline.tRoad.bProfiling){ Profiler.EndSample(); } if(!tSpline.tRoad.opt_HeightModEnabled){ return; } // //Temp testing: // tSpline.mNodes[22].tTriList = new List<GSD.Roads.GSDRoadUtil.Construction3DTri>(); // int tCount = triList.Count; // for(int i=0;i<tCount;i++){ // tSpline.mNodes[22].tTriList.Add(triList[i]); // } // tSpline.mNodes[22].tHMList = new List<Vector3>(); float tFloat = -1f; Sep = tSpline.tRoad.RoadWidth()*1.5f; int k = 0; int[] tXY = null; int tXYsCount = tXYs.Count; bool bIsBridge = false; bool bIsTunnel = false; for(float i=StartMin;i<FinalMax;i+=tStep){ if(TBMList.Count > 0){ if(TBMList[0].MaxI < i){ CleanupTris(i,ref TBMList); } }else{ break; } //If in bridg mode: if(tSpline.IsInBridgeTerrain(i)){ bIsBridge = true; }else{ bIsBridge = false; } //If in tunnel mode: if(tSpline.IsInTunnelTerrain(i)){ bIsTunnel = true; }else{ bIsTunnel = false; } if(k < tXYsCount){ tXY = tXYs[k]; tFloat = ProcessCoordinateGrabber(ref i,ref tSpline,ref TTD, ref TBMList,ref tXY, bIsBridge, bIsTunnel); if(!IsApproximately(tFloat,0f,0.0001f)){ tSpline.HeightHistory.Add(new KeyValuePair<float,float>(i,tFloat)); } }else{ break; } k+=1; } }
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); } }
private static GSD.Roads.GSDRoadUtil.Construction2DRect SetDetailCoords(float param,ref Vector3 tVect1,ref Vector3 POS1,ref Vector3 tVect2,ref Vector3 POS2, float Sep, float TreeSep, ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, ref GSDSplineC tSpline) { Vector3 lVect1far = default(Vector3); Vector3 rVect1far = default(Vector3); Vector3 lVect2far = default(Vector3); Vector3 rVect2far = default(Vector3); bool bIsInBridge = tSpline.IsInBridgeTerrain(param); bool bIsInTunnel = tSpline.IsInTunnelTerrain(param); int x2,y2,x3,y3; GetTempHeights_Coordinates(ref tVect1,ref TTD,out x2,out y2); if(x2 >= TTD.HM){ x2=-1; } if(y2 >= TTD.HM){ y2=-1; } if(x2 < 0){ x2=-1; } if(y2 < 0){ y2=-1; } if(x2 == -1){ return null; } if(y2 == -1){ return null; } float tDiff1 = ((TTD.heights[x2,y2]*(float)TTD.TerrainSize.y) - tVect1.y); GetTempHeights_Coordinates(ref tVect2,ref TTD,out x3,out y3); if(x3 >= TTD.HM){ x3=-1; } if(y3 >= TTD.HM){ y3=-1; } if(x3 < 0){ x3=-1; } if(y3 < 0){ y3=-1; } if(x3 == -1){ return null; } if(y3 == -1){ return null; } float tDiff2 = ((TTD.heights[x3,y3]*(float)TTD.TerrainSize.y) - tVect2.y); GSD.Roads.GSDRoadUtil.Construction2DRect tRect = null; if(tSpline.tRoad.opt_TreeModEnabled){ bool bQuit = false; if(x2 == -1){ bQuit = true; } if(y2 == -1){ bQuit = true; } if(bIsInBridge && !bQuit){ if(tDiff1 < 0f){ tDiff1 *= -1f; } if(tDiff2 < 0f){ tDiff2 *= -1f; } if(tDiff1 > tSpline.tRoad.opt_ClearTreesDistanceHeight){ bQuit = true; } if(tDiff2 > tSpline.tRoad.opt_ClearTreesDistanceHeight){ bQuit = true; } } if(bIsInTunnel && !bQuit){ if(tDiff1 < 0f){ if((tDiff1*-1f) > tSpline.tRoad.opt_ClearTreesDistanceHeight){ bQuit = true; } }else{ if(tDiff1 > (tSpline.tRoad.opt_ClearTreesDistanceHeight*0.1f)){ bQuit = true; } } if(tDiff2 < 0f){ if((tDiff2*-1f) > tSpline.tRoad.opt_ClearTreesDistanceHeight){ bQuit = true; } }else{ if(tDiff2 > (tSpline.tRoad.opt_ClearTreesDistanceHeight*0.1f)){ bQuit = true; } } } if(!bQuit){ TreeSep = TreeSep * 0.5f; lVect1far = (tVect1 + new Vector3(TreeSep*-POS1.normalized.z,0,TreeSep*POS1.normalized.x)); rVect1far = (tVect1 + new Vector3(TreeSep*POS1.normalized.z,0,TreeSep*-POS1.normalized.x)); lVect2far = (tVect2 + new Vector3(TreeSep*-POS2.normalized.z,0,TreeSep*POS2.normalized.x)); rVect2far = (tVect2 + new Vector3(TreeSep*POS2.normalized.z,0,TreeSep*-POS2.normalized.x)); tRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(new Vector2(lVect1far.x,lVect1far.z),new Vector2(rVect1far.x,rVect1far.z),new Vector2(rVect2far.x,rVect2far.z),new Vector2(lVect2far.x,lVect2far.z),0f); } } if(tSpline.tRoad.opt_DetailModEnabled){ if(bIsInBridge || bIsInTunnel){ if(tDiff1 < 0f){ tDiff1 *= -1f; } if(tDiff2 < 0f){ tDiff2 *= -1f; } bool bQuit = false; if(x2 == -1){ bQuit = true; } if(y2 == -1){ bQuit = true; } if(tDiff1 > tSpline.tRoad.opt_ClearDetailsDistanceHeight){ bQuit = true; } if(tDiff2 > tSpline.tRoad.opt_ClearDetailsDistanceHeight){ bQuit = true; } if(bQuit){ return tRect; } } Sep = Sep * 0.5f; lVect1far = (tVect1 + new Vector3(Sep*-POS1.normalized.z,0,Sep*POS1.normalized.x)); rVect1far = (tVect1 + new Vector3(Sep*POS1.normalized.z,0,Sep*-POS1.normalized.x)); lVect2far = (tVect2 + new Vector3(Sep*-POS2.normalized.z,0,Sep*POS2.normalized.x)); rVect2far = (tVect2 + new Vector3(Sep*POS2.normalized.z,0,Sep*-POS2.normalized.x)); int[] Xs = new int[4]; int[] Ys = new int[4]; int x1,y1; GetTempDetails_Coordinates(ref lVect1far,ref TTD,out x1, out y1); Xs[0] = x1; Ys[0] = y1; GetTempDetails_Coordinates(ref lVect2far,ref TTD,out x1, out y1); Xs[1] = x1; Ys[1] = y1; GetTempDetails_Coordinates(ref rVect1far,ref TTD,out x1, out y1); Xs[2] = x1; Ys[2] = y1; GetTempDetails_Coordinates(ref rVect2far,ref TTD,out x1, out y1); Xs[3] = x1; Ys[3] = y1; // // if(TTD.DetailLayersCount == 1 && x1 > 0 && y1 > 0){ // Debug.Log(Xs[0]+","+Ys[0] + " " + Xs[1]+","+Ys[1]); // } int MinX = Mathf.Min(Xs); int MinY = Mathf.Min(Ys); int MaxX = Mathf.Max(Xs); int MaxY = Mathf.Max(Ys); if(MinX >= TTD.DetailMaxIndex){ MinX = TTD.DetailMaxIndex-1; } if(MinY >= TTD.DetailMaxIndex){ MinY = TTD.DetailMaxIndex-1; } if(MaxX >= TTD.DetailMaxIndex){ MaxX = TTD.DetailMaxIndex-1; } if(MaxY >= TTD.DetailMaxIndex){ MaxY = TTD.DetailMaxIndex-1; } if(MinX < 0){ MinX = 0; } if(MinY < 0){ MinY = 0; } if(MaxX < 0){ MaxX = 0; } if(MaxY < 0){ MaxY = 0; } // int DetailI = 0; if(tSpline.tRoad.bProfiling){ Profiler.BeginSample("Dorectsdetails"); } int tInt = 0; for(int i=MinX;i<=MaxX;i++){ for(int k=MinY;k<=MaxY;k++){ //Bitfield for identification: tInt = k; tInt = tInt << 16; tInt = tInt | (ushort)i; if(!TTD.DetailHasProcessed.Contains(tInt)){ // for(int h=0;h<TTD.DetailLayersCount;h++){ // if(TTD.DetailLayersSkip.Contains(h)){ continue; } // if(!TTD.DetailHasProcessed[h][i,k]){// && TTD.DetailValues[h][i,k] > 0){ TTD.MainDetailsX.Add((ushort)i); TTD.MainDetailsY.Add((ushort)k); // DetailI = TTD.DetailsI[h]; // TTD.DetailsX[h].Add((ushort)i); // TTD.DetailsY[h].Add((ushort)k); // TTD.DetailsX[h][DetailI] = (ushort)i; // TTD.DetailsY[h][DetailI] = (ushort)k; // TTD.OldDetailsValue[h][DetailI] = (ushort)TTD.DetailValues[h][i,k]; // TTD.DetailValues[h][i,k] = 0; // TTD.DetailsI[h]+=1; // } TTD.DetailHasProcessed.Add(tInt); } } } if(tSpline.tRoad.bProfiling){ Profiler.EndSample(); } } return tRect; }
private static 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; }
public static void RunMe(ref List<GSD.Roads.GSDTerraforming.TempTerrainData> TTDList, GSDSplineC tSpline, GSDRoad tRoad) { float Step = (tRoad.opt_RoadDefinition*0.4f) / tSpline.distance; if(Step > 2f){ Step = 2f; } if(Step < 1f){ Step = 1f; } // float tDistance = tRoad.RoadWidth()*2f; // Vector3 tVect,POS; foreach(GSD.Roads.GSDTerraforming.TempTerrainData TTD in TTDList){ // float PrevHeight = 0f; // float FinalMax = 1f; // float StartMin = 0f; // if(tSpline.bSpecialEndControlNode){ // FinalMax = tSpline.mNodes[tSpline.GetNodeCount()-2].tTime; // } // if(tSpline.bSpecialStartControlNode){ // StartMin = tSpline.mNodes[1].tTime; // } // if(tRoad.opt_MatchTerrain){ if(tRoad.bProfiling){ Profiler.BeginSample("DoRects"); } GSDTerraformingT.DoRects(tSpline,TTD); if(tRoad.bProfiling){ Profiler.EndSample(); } // }else{ // for(float i=StartMin;i<=FinalMax;i+=Step){ // if(tSpline.IsInBridgeTerrain(i)){ // float tFloat = tSpline.GetBridgeEnd(i); // if(IsApproximately(tFloat,1f,0.00001f) || tFloat > 1f){ continue; } // if(tFloat < 0f){ continue; } // i = tFloat; // } // tSpline.GetSplineValue_Both(i,out tVect,out POS); // PrevHeight = GSDTerraformingT.ProcessLineHeights(tSpline,ref tVect,ref POS,tDistance,TTD,PrevHeight); // tSpline.HeightHistory.Add(new KeyValuePair<float,float>(i,PrevHeight*TTD.TerrainSize.y)); // } // // for(int i=0;i<TTD.cI;i++){ // TTD.heights[TTD.cX[i],TTD.cY[i]] = TTD.cH[i]; // } // } } tSpline.HeightHistory.Sort(Compare1); }
public static void ProcessRoad_Terrain_Hook2(GSDSplineC tSpline,ref List<TempTerrainData> TTDList){ if(tSpline.tRoad.bProfiling){ Profiler.BeginSample("ProcessRoad_Terrain_Hook2"); } ProcessRoad_Terrain_Hook2_Do(ref tSpline, ref TTDList); if(tSpline.tRoad.bProfiling){ Profiler.EndSample(); } }
private static void ProcessRoad_Terrain_Hook1_Do(ref GSDSplineC tSpline,ref GSDRoad tRoad, bool bMultithreaded){ if(tRoad.bProfiling){ Profiler.BeginSample("ProcessRoad_Terrain_Hook1_Do"); } //First lets make sure all terrains have GSD shit on them: CheckAllTerrains(); //Reset the terrain: if(tRoad.bProfiling){ Profiler.BeginSample("TerrainsReset"); } GSDTerraforming.TerrainsReset(tRoad); if(tRoad.bProfiling){ Profiler.EndSample(); } float heightDistance = tRoad.opt_MatchHeightsDistance; // float treeDistance = tRoad.opt_ClearTreesDistance; float detailDistance = tRoad.opt_ClearDetailsDistance; Dictionary<Terrain,TempTerrainData> TempTerrainDict = new Dictionary<Terrain, TempTerrainData>(); //Populate dictionary: Object[] tTerrains = GameObject.FindObjectsOfType(typeof(Terrain)); GSDTerrain TID; int aSize = 0; int dSize = 0; TempTerrainData TTD; bool bContains = false; GSDRoadUtil.Construction2DRect tRect = null; // GSDRoadUtil.Construction2DRect rRect = null; foreach(Terrain tTerrain in tTerrains){ tRect = GetTerrainBounds(tTerrain); bContains = false; //Debug.Log(tTerrain.transform.name + " bounds: " + tRect.ToStringGSD()); //Debug.Log(" Road bounds: " + tSpline.RoadV0 + "," + tSpline.RoadV1 + "," + tSpline.RoadV2 + "," + tSpline.RoadV3); if (bContains != true && tRect.Contains(ref tSpline.RoadV0)) { bContains = true; } else if (bContains != true && tRect.Contains(ref tSpline.RoadV1)) { bContains = true; } else if (bContains != true && tRect.Contains(ref tSpline.RoadV2)) { bContains = true; } else if (bContains != true && tRect.Contains(ref tSpline.RoadV3)) { bContains = true; } else { int mCount3 = tRoad.GSDSpline.GetNodeCount(); Vector2 tVect2D_321 = default(Vector2); for (int i = 0; i < mCount3; i++) { tVect2D_321 = new Vector2(tRoad.GSDSpline.mNodes[i].pos.x, tRoad.GSDSpline.mNodes[i].pos.z); if (tRect.Contains(ref tVect2D_321)) { bContains = true; break; } } if (!bContains) { float tDef = 5f / tSpline.distance; Vector2 x2D = default(Vector2); Vector3 x3D = default(Vector3); for (float i = 0f; i <= 1f; i += tDef) { x3D = tSpline.GetSplineValue(i); x2D = new Vector2(x3D.x, x3D.z); if (tRect.Contains(ref x2D)) { bContains = true; break; } } } } // rRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(tSpline.RoadV0,tSpline.RoadV1,tSpline.RoadV2,tSpline.RoadV3); if(bContains && !TempTerrainDict.ContainsKey(tTerrain)){ TTD = new TempTerrainData(); TTD.HM = tTerrain.terrainData.heightmapResolution; TTD.HMHeight = tTerrain.terrainData.heightmapHeight; TTD.heights = tTerrain.terrainData.GetHeights(0,0,tTerrain.terrainData.heightmapWidth,tTerrain.terrainData.heightmapHeight); TTD.HMRatio = TTD.HM / tTerrain.terrainData.size.x; TTD.MetersPerHM = tTerrain.terrainData.size.x / tTerrain.terrainData.heightmapResolution; float DetailRatio = tTerrain.terrainData.detailResolution / tTerrain.terrainData.size.x; //Heights: if(tRoad.bProfiling){ Profiler.BeginSample("Heights"); } if(tRoad.opt_HeightModEnabled){ aSize = (int)tSpline.distance * ((int)(heightDistance*1.65f*TTD.HMRatio)+2); if(aSize > (tTerrain.terrainData.heightmapResolution * tTerrain.terrainData.heightmapResolution)){ aSize = tTerrain.terrainData.heightmapResolution * tTerrain.terrainData.heightmapResolution; } TTD.cX = new ushort[aSize]; TTD.cY = new ushort[aSize]; TTD.oldH = new float[aSize]; TTD.cH = new float[aSize]; TTD.cI = 0; TTD.TerrainMaxIndex = tTerrain.terrainData.heightmapResolution; TTD.TerrainSize = tTerrain.terrainData.size; TTD.TerrainPos = tTerrain.transform.position; TTD.tHeights = new bool[tTerrain.terrainData.heightmapWidth,tTerrain.terrainData.heightmapHeight]; TID = tTerrain.transform.gameObject.GetComponent<GSDTerrain>(); if(TID != null){ TTD.GSDID = TID.GSDID; TempTerrainDict.Add(tTerrain,TTD); } } if(tRoad.bProfiling){ Profiler.EndSample(); } //Details: if(tRoad.bProfiling){ Profiler.BeginSample("Details"); } if(tRoad.opt_DetailModEnabled){ // TTD.DetailValues = new Dictionary<int, int[,]>(); TTD.DetailLayersCount = tTerrain.terrainData.detailPrototypes.Length; // TTD.DetailHasProcessed = new Dictionary<int, bool[,]>(); TTD.DetailHasProcessed = new HashSet<int>(); TTD.MainDetailsX = new List<ushort>(); TTD.MainDetailsY = new List<ushort>(); TTD.DetailsI = new int[TTD.DetailLayersCount]; TTD.DetailToHeightRatio = (float)((float)tTerrain.terrainData.detailResolution) / ((float)tTerrain.terrainData.heightmapResolution); TTD.DetailMaxIndex = tTerrain.terrainData.detailResolution; TTD.DetailLayersSkip = new HashSet<int>(); // Get all of layer zero. // int[] mMinMaxDetailEntryCount = new int[TTD.DetailLayersCount]; // if(tRoad.bProfiling){ Profiler.BeginSample("DetailValues"); } // Vector3 bVect = default(Vector3); // Vector2 bVect2D = default(Vector2); // int DetailRes = tTerrain.terrainData.detailResolution; // for(int i=0;i<TTD.DetailLayersCount;i++){ // int[,] tInts = tTerrain.terrainData.GetDetailLayer(0,0,tTerrain.terrainData.detailWidth,tTerrain.terrainData.detailHeight,i); // int Length1 = tInts.GetLength(0); // int Length2 = tInts.GetLength(1); // for (int y=0;y < Length1;y++){ // for (int x=0;x < Length2;x++){ // if(tInts[x,y] > 0){ // bVect = new Vector3(((float)y/(float)DetailRes) * TTD.TerrainSize.x,0f,((float)x/(float)DetailRes) * TTD.TerrainSize.z); // bVect = tTerrain.transform.TransformPoint(bVect); // bVect2D = new Vector2(bVect.z,bVect.x); // if(rRect.Contains(ref bVect2D)){ // mMinMaxDetailEntryCount[i] += 1; // } // } // } // } // if(mMinMaxDetailEntryCount[i] < 1){ // TTD.DetailLayersSkip.Add(i); // tInts = null; // }else{ // TTD.DetailValues.Add(i,tInts); // TTD.DetailHasProcessed.Add(i,new bool[tTerrain.terrainData.detailWidth,tTerrain.terrainData.detailHeight]); // } // } // if(tRoad.bProfiling){ Profiler.EndSample(); } dSize = (int)tSpline.distance * ((int)(detailDistance*3f*DetailRatio)+2); if(dSize > (tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution)){ dSize = tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution; } // TTD.DetailsX = new List<ushort[]>(); // TTD.DetailsY = new List<ushort[]>(); // TTD.OldDetailsValue = new List<ushort[]>(); TTD.DetailsX = new List<List<ushort>>(); TTD.DetailsY = new List<List<ushort>>(); TTD.OldDetailsValue = new List<List<ushort>>(); // TTD.DetailHasProcessed = new List<List<bool>>(); for(int i=0;i<TTD.DetailLayersCount;i++){ // if(TTD.DetailLayersSkip.Contains(i)){ // TTD.DetailsX.Add(new ushort[0]); // TTD.DetailsY.Add(new ushort[0]); // TTD.OldDetailsValue.Add(new ushort[0]); // continue; // } // int detailentrycount = (int)((float)mMinMaxDetailEntryCount[i] * 1.5f); // int d_temp_Size = dSize; // if(d_temp_Size > detailentrycount){ d_temp_Size = detailentrycount; } // if(d_temp_Size < 1){ d_temp_Size = 1; } // if(d_temp_Size > (tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution)){ // d_temp_Size = tTerrain.terrainData.detailResolution * tTerrain.terrainData.detailResolution; // } // // TTD.DetailsX.Add(new ushort[d_temp_Size]); // TTD.DetailsY.Add(new ushort[d_temp_Size]); // TTD.OldDetailsValue.Add(new ushort[d_temp_Size]); TTD.DetailsX.Add(new List<ushort>()); TTD.DetailsY.Add(new List<ushort>()); TTD.OldDetailsValue.Add(new List<ushort>()); } // TTD.DetailsX = new ushort[TTD.DetailLayersCount,dSize]; // TTD.DetailsY = new ushort[TTD.DetailLayersCount,dSize]; // TTD.OldDetailsValue = new ushort[TTD.DetailLayersCount,dSize]; } if(tRoad.bProfiling){ Profiler.EndSample(); } //Trees: if(tRoad.bProfiling){ Profiler.BeginSample("Trees"); } if(tRoad.opt_TreeModEnabled){ // TTD.TreesCurrent = tTerrain.terrainData.treeInstances; TTD.TreesCurrent = new List<TreeInstance>(tTerrain.terrainData.treeInstances); TTD.TreeSize = TTD.TreesCurrent.Count; TTD.TreesI = 0; TTD.TreesOld = new List<TreeInstance>(); } if(tRoad.bProfiling){ Profiler.EndSample(); } } } //Figure out relevant TTD to spline: List<TempTerrainData> EditorTTDList = new List<TempTerrainData>(); if(TempTerrainDict != null){ foreach(Terrain tTerrain in tTerrains){ if(TempTerrainDict.ContainsKey(tTerrain)){ EditorTTDList.Add(TempTerrainDict[tTerrain]); } } } if(tRoad.bProfiling){ Profiler.EndSample(); } //Start job now, for each relevant TTD: tRoad.EditorTerrainCalcs(ref EditorTTDList); if(bMultithreaded){ GSD.Threaded.TerrainCalcs tJob = new GSD.Threaded.TerrainCalcs(); tJob.Setup(ref EditorTTDList,tSpline,tRoad); tRoad.TerrainCalcsJob = tJob; tJob.Start(); }else{ GSD.Threaded.TerrainCalcs_Static.RunMe(ref EditorTTDList,tSpline,tRoad); } }
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); } } }