public EdgeObjectMaker AddEdgeObject() { EdgeObjectMaker EOM = new EdgeObjectMaker(); EOM.tNode = this; EOM.SetDefaultTimes(bIsEndPoint, tTime, NextTime, idOnSpline, GSDSpline.distance); EOM.StartPos = GSDSpline.GetSplineValue(EOM.StartTime); EOM.EndPos = GSDSpline.GetSplineValue(EOM.EndTime); EdgeObjects.Add(EOM); return(EOM); }
// Update is called once per frame void Update() { timer += Time.deltaTime; if (reset) { reset = false; timer = 0.0f; } float posAlongSpline = timer / spline.distance; transform.position = spline.GetSplineValue((posAlongSpline * speed) % 1); transform.LookAt(spline.GetSplineValue((posAlongSpline * speed + 0.01f) % 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 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 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 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; }
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; } }
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 Vector3 TrafficLightBase_GetRot_LL(GSDRoadIntersection GSDRI, GSDSplineC tSpline, float DistFromCorner, bool bOverrideRegular = false){ Vector3 POS = default(Vector3); if(!GSDRI.bRegularPoleAlignment && !bOverrideRegular){ // float tDist = ((Vector3.Distance(GSDRI.CornerLL,GSDRI.CornerRL) / 2f) + DistFromCorner) / tSpline.distance;; float p = Mathf.Clamp(GSDRI.Node2.tTime,0f,1f); POS = tSpline.GetSplineValue(p,true); POS = Vector3.Cross(POS,Vector3.up); if(GSDRI.bFlipped){ POS = POS*-1; } }else{ POS = GSDRI.CornerRL - GSDRI.CornerRR; } return POS * -1; }
private static 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 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 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); } } }