public RoadConstructorBufferMaker(GSDRoad _tRoad, RoadUpdateTypeEnum _tUpdateType){ tUpdateType = _tUpdateType; bRoadOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection || tUpdateType == RoadUpdateTypeEnum.Bridges); bTerrainOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection || tUpdateType == RoadUpdateTypeEnum.Bridges); bBridgesOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Bridges); bInterseOn = (tUpdateType == RoadUpdateTypeEnum.Full || tUpdateType == RoadUpdateTypeEnum.Intersection); tRoad = _tRoad; Nullify(); RoadVectors = new List<Vector3>(); ShoulderR_Vectors = new List<Vector3>(); ShoulderL_Vectors = new List<Vector3>(); normals_ShoulderR_averageStartIndexes = new List<int>(); normals_ShoulderL_averageStartIndexes = new List<int>(); cut_RoadVectors = new List<List<Vector3>>(); cut_RoadVectorsHome = new List<Vector3>(); cut_ShoulderR_Vectors = new List<List<Vector3>>(); cut_ShoulderL_Vectors = new List<List<Vector3>>(); cut_ShoulderR_VectorsHome = new List<Vector3>(); cut_ShoulderL_VectorsHome = new List<Vector3>(); cut_tris = new List<int[]>(); cut_tris_ShoulderR = new List<int[]>(); cut_tris_ShoulderL = new List<int[]>(); cut_normals = new List<Vector3[]>(); cut_normals_ShoulderR = new List<Vector3[]>(); cut_normals_ShoulderL = new List<Vector3[]>(); cut_uv = new List<Vector2[]>(); cut_uv_SR = new List<Vector2[]>(); cut_uv_SL = new List<Vector2[]>(); cut_tangents = new List<Vector4[]>(); cut_tangents_SR = new List<Vector4[]>(); cut_tangents_SL = new List<Vector4[]>(); cut_uv_world = new List<Vector2[]>(); cut_uv_SR_world = new List<Vector2[]>(); cut_uv_SL_world = new List<Vector2[]>(); cut_tangents_world = new List<Vector4[]>(); cut_tangents_SR_world = new List<Vector4[]>(); cut_tangents_SL_world = new List<Vector4[]>(); RoadCutNodes = new List<GSDSplineN>(); ShoulderCutsRNodes = new List<GSDSplineN>(); ShoulderCutsLNodes = new List<GSDSplineN>(); RoadConnections_verts = new List<Vector3[]>(); RoadConnections_tris = new List<int[]>(); RoadConnections_normals = new List<Vector3[]>(); RoadConnections_uv = new List<Vector2[]>(); RoadConnections_tangents = new List<Vector4[]>(); RoadCuts = new List<int>(); ShoulderCutsR = new List<int>(); ShoulderCutsL = new List<int>(); //if(bInterseOn){ //Back lanes: iBLane0s = new List<Vector3[]>(); iBLane1s = new List<Vector3[]>(); iBLane2s = new List<Vector3[]>(); iBLane3s = new List<Vector3[]>(); //Front lanes: iFLane0s = new List<Vector3[]>(); iFLane1s = new List<Vector3[]>(); iFLane2s = new List<Vector3[]>(); iFLane3s = new List<Vector3[]>(); //Main plates: iBMainPlates = new List<Vector3[]>(); iFMainPlates = new List<Vector3[]>(); //Marker plates: iBMarkerPlates = new List<Vector3[]>(); iFMarkerPlates = new List<Vector3[]>(); //Back lanes: iBLane0s_tris = new List<int[]>(); iBLane1s_tris = new List<int[]>(); iBLane2s_tris = new List<int[]>(); iBLane3s_tris = new List<int[]>(); //Front lanes: iFLane0s_tris = new List<int[]>(); iFLane1s_tris = new List<int[]>(); iFLane2s_tris = new List<int[]>(); iFLane3s_tris = new List<int[]>(); //Main plates: iBMainPlates_tris = new List<int[]>(); iFMainPlates_tris = new List<int[]>(); //Marker plates: iBMarkerPlates_tris = new List<int[]>(); iFMarkerPlates_tris = new List<int[]>(); //Back lanes: iBLane0s_normals = new List<Vector3[]>(); iBLane1s_normals = new List<Vector3[]>(); iBLane2s_normals = new List<Vector3[]>(); iBLane3s_normals = new List<Vector3[]>(); //Front lanes: iFLane0s_normals = new List<Vector3[]>(); iFLane1s_normals = new List<Vector3[]>(); iFLane2s_normals = new List<Vector3[]>(); iFLane3s_normals = new List<Vector3[]>(); //Main plates: iBMainPlates_normals = new List<Vector3[]>(); iFMainPlates_normals = new List<Vector3[]>(); //Marker plates: iBMarkerPlates_normals = new List<Vector3[]>(); iFMarkerPlates_normals = new List<Vector3[]>(); //Back lanes: iBLane0s_uv = new List<Vector2[]>(); iBLane1s_uv = new List<Vector2[]>(); iBLane2s_uv = new List<Vector2[]>(); iBLane3s_uv = new List<Vector2[]>(); //Front lanes: iFLane0s_uv = new List<Vector2[]>(); iFLane1s_uv = new List<Vector2[]>(); iFLane2s_uv = new List<Vector2[]>(); iFLane3s_uv = new List<Vector2[]>(); //Main plates: iBMainPlates_uv = new List<Vector2[]>(); iFMainPlates_uv = new List<Vector2[]>(); iBMainPlates_uv2 = new List<Vector2[]>(); iFMainPlates_uv2 = new List<Vector2[]>(); //Marker plates: iBMarkerPlates_uv = new List<Vector2[]>(); iFMarkerPlates_uv = new List<Vector2[]>(); //Back lanes: iBLane0s_tangents = new List<Vector4[]>(); iBLane1s_tangents = new List<Vector4[]>(); iBLane2s_tangents = new List<Vector4[]>(); iBLane3s_tangents = new List<Vector4[]>(); //Front lanes: iFLane0s_tangents = new List<Vector4[]>(); iFLane1s_tangents = new List<Vector4[]>(); iFLane2s_tangents = new List<Vector4[]>(); iFLane3s_tangents = new List<Vector4[]>(); //Main plates: iBMainPlates_tangents = new List<Vector4[]>(); iFMainPlates_tangents = new List<Vector4[]>(); iBMainPlates_tangents2 = new List<Vector4[]>(); iFMainPlates_tangents2 = new List<Vector4[]>(); //Marker plates: iBMarkerPlates_tangents = new List<Vector4[]>(); iFMarkerPlates_tangents = new List<Vector4[]>(); iFLane1s_IsMiddleLane = new List<bool>(); iBLane1s_IsMiddleLane = new List<bool>(); //Back lanes: iBLane0s_tID = new List<GSDRoadIntersection>(); iBLane1s_tID = new List<GSDRoadIntersection>(); iBLane2s_tID = new List<GSDRoadIntersection>(); iBLane3s_tID = new List<GSDRoadIntersection>(); //Front lanes: iFLane0s_tID = new List<GSDRoadIntersection>(); iFLane1s_tID = new List<GSDRoadIntersection>(); iFLane2s_tID = new List<GSDRoadIntersection>(); iFLane3s_tID = new List<GSDRoadIntersection>(); //Main plates: iBMainPlates_tID = new List<GSDRoadIntersection>(); iFMainPlates_tID = new List<GSDRoadIntersection>(); //Marker plates: iBMarkerPlates_tID = new List<GSDRoadIntersection>(); iFMarkerPlates_tID = new List<GSDRoadIntersection>(); iBLane0s_nID = new List<GSDSplineN>(); iBLane1s_nID = new List<GSDSplineN>(); iBLane2s_nID = new List<GSDSplineN>(); iBLane3s_nID = new List<GSDSplineN>(); //Front lanes: iFLane0s_nID = new List<GSDSplineN>(); iFLane1s_nID = new List<GSDSplineN>(); iFLane2s_nID = new List<GSDSplineN>(); iFLane3s_nID = new List<GSDSplineN>(); //Main plates: iBMainPlates_nID = new List<GSDSplineN>(); iFMainPlates_nID = new List<GSDSplineN>(); //Marker plates: iBMarkerPlates_nID = new List<GSDSplineN>(); iFMarkerPlates_nID = new List<GSDSplineN>(); //} tTerrain = null; tMesh = new Mesh(); tMesh_SR = new Mesh(); tMesh_SL = new Mesh(); tMesh_RoadCuts = new List<Mesh>(); tMesh_SRCuts = new List<Mesh>(); tMesh_SLCuts = new List<Mesh>(); tMesh_RoadCuts_world = new List<Mesh>(); tMesh_SRCuts_world = new List<Mesh>(); tMesh_SLCuts_world = new List<Mesh>(); tMesh_RoadConnections = new List<Mesh>(); //if(bInterseOn){ tMesh_iBLanes0 = new List<Mesh>(); tMesh_iBLanes1 = new List<Mesh>(); tMesh_iBLanes2 = new List<Mesh>(); tMesh_iBLanes3 = new List<Mesh>(); tMesh_iFLanes0 = new List<Mesh>(); tMesh_iFLanes1 = new List<Mesh>(); tMesh_iFLanes2 = new List<Mesh>(); tMesh_iFLanes3 = new List<Mesh>(); tMesh_iBMainPlates = new List<Mesh>(); tMesh_iFMainPlates = new List<Mesh>(); tMesh_iBMarkerPlates = new List<Mesh>(); tMesh_iFMarkerPlates = new List<Mesh>(); tIntersectionBounds = new List<GSD.Roads.GSDRoadUtil.Construction2DRect>(); ImmuneVects = new HashSet<Vector3>(); //} InitGameObjects(); }
public void UpdateRoad(RoadUpdateTypeEnum tUpdateType = RoadUpdateTypeEnum.Full){ if (!GSDRS.opt_bAllowRoadUpdates) { GSDSpline.Setup(); Editor_bIsConstructing = false; return; } if(Editor_bIsConstructing){ return; } SetupUniqueIdentifier(); if(bProfiling){ Profiler.BeginSample("UpdateRoadPrelim"); } opt_RoadDefinition = Mathf.Clamp(opt_RoadDefinition,1f,50f); opt_LaneWidth = Mathf.Clamp(opt_LaneWidth,0.2f,500f); EditorConstructionStartTime = Time.realtimeSinceStartup; EditorTitleString = "Updating " + transform.name + "..."; System.GC.Collect(); if(opt_SaveTerrainHistoryOnDisk){ ConstructRoad_LoadTerrainHistory(); } CheckMats(); EditorUtility.ClearProgressBar(); bProfiling = true; if(GSDRS.opt_bMultithreading){ bProfiling = false; } //Set all terrains to height 0: GSD.Roads.GSDTerraforming.CheckAllTerrainsHeight0(); EditorProgress = 20; bEditorProgressBar = true; if(Editor_bIsConstructing){ if(TerrainCalcsJob != null){ TerrainCalcsJob.Abort(); TerrainCalcsJob = null; } if(RoadCalcsJob1 != null){ RoadCalcsJob1.Abort(); RoadCalcsJob1 = null; } if(RoadCalcsJob2 != null){ RoadCalcsJob2.Abort(); RoadCalcsJob2 = null; } Editor_bIsConstructing = false; } // if(Application.isPlaying || !Application.isEditor){ return; } // if(Application.isEditor && UnityEditor.EditorApplication.isPlaying){ return; } // if(Application.isEditor && UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode){ return; } //In here for intersection patching purposes: int mCount = GSDSpline.GetNodeCount(); GSDSplineN tNode = null; GSDSplineN tNode1 = null; GSDSplineN tNode2 = null; if(GSDSpline.CheckInvalidNodeCount()){ GSDSpline.Setup(); mCount = GSDSpline.GetNodeCount(); } if(mCount > 1){ for(int i=0;i<mCount;i++){ // try{ tNode = GSDSpline.mNodes[i]; // }catch{ // Editor_bIsConstructing = false; // EditorUpdateMe = true; // return; // } //If node is intersection with an invalid GSDRI, mark it at non-intersection. Just-in-case. if(tNode.bIsIntersection && tNode.GSDRI == null){ tNode.bIsIntersection = false; tNode.id_intersection_othernode = -1; tNode.Intersection_OtherNode = null; } //If node is intersection, re-setup: if(tNode.bIsIntersection && tNode.GSDRI != null){ tNode1 = tNode.GSDRI.Node1; tNode2 = tNode.GSDRI.Node2; tNode.GSDRI.Setup(tNode1,tNode2); tNode.GSDRI.DeleteRelevantChildren(tNode, tNode.GSDSpline.tRoad.transform.name); //If primary node on intersection, do more re-setup: if(tNode.GSDRI.Node1 == tNode){ tNode.GSDRI.Lanes = opt_Lanes; tNode.GSDRI.name = tNode.GSDRI.transform.name; } //Setup construction objects: tNode.GSDRI.Node1.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); tNode.GSDRI.Node2.iConstruction = new GSD.Roads.GSDIntersections.iConstructionMaker(); } //Store materials and physical materials for road and or shoulder cuts on each node, if necessary: tNode.StoreCuts(); } } name = transform.name; GSDSpline.RoadWidth = RoadWidth(); // if(bProfiling){ Profiler.BeginSample("SplineSetup"); } GSDSpline.Setup(); // if(bProfiling){ Profiler.EndSample(); } mCount = GSDSpline.GetNodeCount(); if(GSDSpline == null || GSDSpline.mNodes == null){ MostRecentNodeCount = 0; }else{ MostRecentNodeCount = GSDSpline.GetNodeCount(); } if(opt_UseDefaultMaterials){ SetDefaultMats(); } if(opt_UseDefaultMaterials){ if(DetectInvalidDefaultMatsForUndo()){ SetAllCutsToCurrentMaterials(); } } //Hiding in hierarchy: for(int i=0;i<mCount;i++){ tNode = GSDSpline.mNodes[i]; if(tNode != null){ if(tNode.bIsIntersection || tNode.bSpecialEndNode){ tNode.ToggleHideFlags(true); }else{ tNode.ToggleHideFlags(false); } } } int cCount = transform.childCount; GameObject tMainMeshes = null; List<GameObject> tObjs = new List<GameObject>(); for(int i=0;i<cCount;i++){ if(transform.GetChild(i).transform.name.ToLower().Contains("mainmeshes")){ tMainMeshes = transform.GetChild(i).transform.gameObject; tObjs.Add(tMainMeshes); } } for(int i=(tObjs.Count-1);i>=0;i--){ tMainMeshes = tObjs[i]; Object.DestroyImmediate(tMainMeshes); } if(mCount < 2){ //Delete old objs and return: if(MainMeshes != null){ Object.DestroyImmediate(MainMeshes); } if(MeshRoad != null){ Object.DestroyImmediate(MeshRoad); } if(MeshShoR != null){ Object.DestroyImmediate(MeshShoR); } if(MeshShoL != null){ Object.DestroyImmediate(MeshShoL); } if(MeshiLanes != null){ Object.DestroyImmediate(MeshiLanes); } if(MeshiLanes0 != null){ Object.DestroyImmediate(MeshiLanes0); } if(MeshiLanes1 != null){ Object.DestroyImmediate(MeshiLanes1); } if(MeshiLanes2 != null){ Object.DestroyImmediate(MeshiLanes2); } if(MeshiLanes3 != null){ Object.DestroyImmediate(MeshiLanes3); } if(MeshiMainPlates != null){ Object.DestroyImmediate(MeshiMainPlates); } if(MeshiMarkerPlates != null){ Object.DestroyImmediate(MeshiMarkerPlates); } if(bProfiling){ Profiler.EndSample(); } return; } GSDSpline.HeightHistory = new List<KeyValuePair<float, float>>(); if(GSDRS == null){ GSDRS = transform.parent.GetComponent<GSDRoadSystem>(); } //Compatibility update. if(GSDRS.opt_bMultithreading){ Editor_bIsConstructing = true; }else{ Editor_bIsConstructing = false; } Editor_bConstructionID = 0; //Check if road takes place on only 1 terrain: Terrain tTerrain = GSD.Roads.GSDRoadUtil.GetTerrain(GSDSpline.mNodes[0].pos); bool bSameTerrain = true; for(int i=1;i<mCount;i++){ if(tTerrain != GSD.Roads.GSDRoadUtil.GetTerrain(GSDSpline.mNodes[0].pos)){ bSameTerrain = false; break; } } RCS = new RoadConstructorBufferMaker(this, tUpdateType); if(bSameTerrain){ RCS.tTerrain = tTerrain; }else{ RCS.tTerrain = null; } tTerrain = null; if(bProfiling){ Profiler.EndSample(); } if(GSDRS.opt_bMultithreading){ if(RCS.bTerrainOn || TerrainHistory == null){ GSDTerraforming.ProcessRoad_Terrain_Hook1(GSDSpline,this); }else{ ConstructRoad2(); } }else{ UpdateRoad_NoMultiThreading(); } }