Ejemplo n.º 1
0
    }                                                           //Time gap for each chest to run the animation;

    private void Awake()
    {
        IS = this;

        VP_Csize = 0.0f;

        LoadGameSetting(TGSData);
    }
        /// <summary>
        /// Handles most triangles and normals construction. In certain scenarios for efficiency reasons UV might also be processed.
        /// </summary>
        /// <param name='RCS'>
        /// The road construction buffer, by reference.
        /// </param>/
        public static void RoadJob1(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //Triangles and normals:
            //			if(RCS.tRoad.bProfiling){ Profiler.BeginSample("ProcessRoad_IntersectionCleanup"); }
            if(RCS.bInterseOn){ ProcessRoad_IntersectionCleanup(ref RCS); }
            //			if(RCS.tRoad.bProfiling){ Profiler.EndSample(); }

            ProcessRoad_Tris_Bulk(ref RCS);

            RCS.tris_ShoulderR = ProcessRoad_Tris_Shoulder(RCS.ShoulderR_Vectors.Count);
            RCS.tris_ShoulderL = ProcessRoad_Tris_Shoulder(RCS.ShoulderL_Vectors.Count);
            if(RCS.tRoad.opt_bShoulderCuts || RCS.tRoad.opt_bDynamicCuts){
                ProcessRoad_Tris_ShoulderCutsR(ref RCS);
                ProcessRoad_Tris_ShoulderCutsL(ref RCS);
            }

            ProcessRoad_Normals_Bulk(ref RCS);
            ProcessRoad_Normals_Shoulders(ref RCS);
        }
 private static void ProcessRoad_IntersectionCleanup(ref GSD.Roads.RoadConstructorBufferMaker RCS)
 {
     List<GSD.Roads.GSDRoadUtil.Construction2DRect> tList = RCS.tIntersectionBounds;
     int mCount = tList.Count;
     RCS.ShoulderR_Vectors = ProcessRoad_IntersectionCleanup_Helper(ref RCS.ShoulderR_Vectors,ref tList,mCount,ref RCS.ImmuneVects);
     RCS.ShoulderL_Vectors = ProcessRoad_IntersectionCleanup_Helper(ref RCS.ShoulderL_Vectors,ref tList,mCount,ref RCS.ImmuneVects);
 }
Ejemplo n.º 4
0
	public void Initialize(ref Rect tRect, WindowTypeEnum _tWindowType, GSDSplineN tNode, GSD.Roads.Splination.SplinatedMeshMaker SMM = null, GSD.Roads.EdgeObjects.EdgeObjectMaker EOM = null) {
		int Rheight = 300;
		int Rwidth = 360;
		float Rx = ((float)tRect.width/2f) - ((float)Rwidth/2f) + tRect.x;
		float Ry = ((float)tRect.height/2f) - ((float)Rheight/2f) + tRect.y;
		
		if(Rx < 0){ Rx = tRect.x; }
		if(Ry < 0){ Ry = tRect.y; }
		if(Rx > (tRect.width + tRect.x)){ Rx = tRect.x; }
		if(Ry > (tRect.height + tRect.y)){ Ry = tRect.y; }
		
		Rect fRect = new Rect(Rx,Ry,Rwidth,Rheight);

		if(fRect.width < 300){
			fRect.width = 300;
			fRect.x = tRect.x;
		}
		if(fRect.height < 300){
			fRect.height = 300;
			fRect.y = tRect.y;
		}

		position = fRect;
		tWindowType = _tWindowType;
        Show();
		title = "Save";
		if(tWindowType == WindowTypeEnum.Extrusion){
			TitleText =  "Save extrusion";
			tSMMs = new GSD.Roads.Splination.SplinatedMeshMaker[1];
			tSMMs[0] = SMM;
			if(SMM != null){
				tFilename = SMM.tName;
				tDisplayName = tFilename;
			}
		}else if(tWindowType == WindowTypeEnum.Edge){
			TitleText =  "Save edge object";
			tEOMs = new GSD.Roads.EdgeObjects.EdgeObjectMaker[1];
			tEOMs[0] = EOM;
			if(EOM != null){
				tFilename = EOM.tName;
				tDisplayName = tFilename;
			}
		}else if(tWindowType ==  WindowTypeEnum.BridgeWizard){
			bIsBridge = true;
			tSMMs = tNode.SplinatedObjects.ToArray();
			tEOMs = tNode.EdgeObjects.ToArray();
			TitleText = "Save group";
			tFilename = "Group" + Random.Range(0,10000).ToString();
			tDisplayName = tFilename;
		}
		
		if(xPath.Length < 5){
			xPath = GSDRootUtil.Dir_GetLibrary();
		}
		
		if(tWindowType == WindowTypeEnum.Edge){
			if(System.IO.File.Exists(xPath + "EOM"+tFilename+".gsd")){
				bFileExists = true;
			}else{
				bFileExists = false;	
			}
		}else if(tWindowType == WindowTypeEnum.Extrusion){
			if(System.IO.File.Exists(xPath + "ESO"+tFilename+".gsd")){
				bFileExists = true;
			}else{
				bFileExists = false;	
			}
		}else{
			if(System.IO.File.Exists(xPath + "B/"+tFilename+".gsd")){
				bFileExists = true;
			}else{
				bFileExists = false;	
			}
		}
    }
 public static void RunMe(ref GSD.Roads.RoadConstructorBufferMaker RCS)
 {
     GSDRoadCreationT.RoadJob2(ref RCS);
 }
 public void Setup(ref GSD.Roads.RoadConstructorBufferMaker _RCS, ref GSDRoad _tRoad)
 {
     RCS = _RCS;
     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;
        }
        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 ConvertTerrainCoordToWorldVect(int x, int y, float tHeight,ref GSD.Roads.GSDTerraforming.TempTerrainData TTD)
        {
            //Get the normalized position of this game object relative to the terrain:
            float x1 = x / ((float)TTD.HM-1f);
            x1 = x1 * TTD.TerrainSize.x;

            float z1 = y / ((float)TTD.HM-1f);
            z1 = z1 * TTD.TerrainSize.z;

            float y1 = tHeight * TTD.TerrainSize.y;

            Vector3 xVect = new Vector3(z1,y1,x1);
            xVect += TTD.TerrainPos;

            return xVect;
        }
Ejemplo n.º 10
0
        private static void ProcessRoad_Tris_ShoulderCutsR(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            int cCount = RCS.ShoulderCutsR.Count;
            int PrevRoadCutIndex = 0;
            int CurrentRoadCutIndex = 0;
            List<List<Vector3>> tVects = new List<List<Vector3>>();
            List<Vector3> tVectListSingle = null;
            Vector3 xVect = default(Vector3);
            for(int j=0;j<cCount;j++){
                CurrentRoadCutIndex = RCS.ShoulderCutsR[j];
                tVectListSingle = new List<Vector3>();
                RCS.cut_ShoulderR_VectorsHome.Add(RCS.ShoulderR_Vectors[PrevRoadCutIndex]);
                xVect = RCS.ShoulderR_Vectors[PrevRoadCutIndex];
                for(int i=PrevRoadCutIndex;i<CurrentRoadCutIndex;i++){
                    tVectListSingle.Add(RCS.ShoulderR_Vectors[i]-xVect);
                }
                tVects.Add(tVectListSingle);
                PrevRoadCutIndex = CurrentRoadCutIndex-8;
                if(PrevRoadCutIndex < 0){ PrevRoadCutIndex = 0; }
            }
            int mMax = RCS.ShoulderR_Vectors.Count;
            tVectListSingle = new List<Vector3>();
            RCS.cut_ShoulderR_VectorsHome.Add(RCS.ShoulderR_Vectors[PrevRoadCutIndex]);
            xVect = RCS.ShoulderR_Vectors[PrevRoadCutIndex];
            for(int i=PrevRoadCutIndex;i<mMax;i++){
                tVectListSingle.Add(RCS.ShoulderR_Vectors[i]-xVect);
            }
            tVects.Add(tVectListSingle);

            int vCount = tVects.Count;
            List<int[]> tTris = new List<int[]>();
            for(int i=0;i<vCount;i++){
                int[] tTriSingle = ProcessRoad_Tris_Shoulder(tVects[i].Count);
                tTris.Add(tTriSingle);
            }

            RCS.cut_ShoulderR_Vectors = tVects;
            RCS.cut_tris_ShoulderR = tTris;
        }
Ejemplo n.º 11
0
        private static void ProcessRoad_Tris_RoadCuts(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //Road cuts aren't working right for the special nodes on cuts
            int cCount = RCS.RoadCuts.Count;
            int PrevRoadCutIndex = 0;
            int CurrentRoadCutIndex = 0;
            List<List<Vector3>> tVects = new List<List<Vector3>>();
            List<Vector3> tVectListSingle = null;
            Vector3 xVect = default(Vector3);
            for(int j=0;j<cCount;j++){
                CurrentRoadCutIndex = RCS.RoadCuts[j];
                tVectListSingle = new List<Vector3>();
                RCS.cut_RoadVectorsHome.Add(RCS.RoadVectors[PrevRoadCutIndex]);
                xVect = RCS.RoadVectors[PrevRoadCutIndex];
                for(int i=PrevRoadCutIndex;i<CurrentRoadCutIndex;i++){
                    tVectListSingle.Add(RCS.RoadVectors[i]-xVect);
                }
                tVects.Add(tVectListSingle);
                PrevRoadCutIndex = CurrentRoadCutIndex-4;
                if(PrevRoadCutIndex < 0){ PrevRoadCutIndex = 0; }
            }
            int mMax = RCS.RoadVectors.Count;
            tVectListSingle = new List<Vector3>();
            RCS.cut_RoadVectorsHome.Add(RCS.RoadVectors[PrevRoadCutIndex]);
            xVect = RCS.RoadVectors[PrevRoadCutIndex];
            for(int i=PrevRoadCutIndex;i<mMax;i++){
                tVectListSingle.Add(RCS.RoadVectors[i]-xVect);
            }
            tVects.Add(tVectListSingle);

            int vCount = tVects.Count;
            List<int[]> tTris = new List<int[]>();
            for(int i=0;i<vCount;i++){
                int[] tTriSingle = ProcessRoad_Tris_Bulk_Helper(tVects[i].Count);
                tTris.Add(tTriSingle);
            }

            RCS.cut_RoadVectors = tVects;
            RCS.cut_tris = tTris;
        }
Ejemplo n.º 12
0
        private static void ProcessRoad_Tris_Bulk(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //, ref Mesh tShoulderR, ref Mesh tShoulderL){
            //Next come the triangles. Since we want two triangles, each defined by three integers, the triangles array will have six elements in total.
            //Remembering the clockwise rule for ordering the corners, the lower left triangle will use 0, 2, 1 as its corner indices, while the upper right one will use 2, 3, 1.

            RCS.tris = ProcessRoad_Tris_Bulk_Helper(RCS.RoadVectors.Count);
            if(RCS.tRoad.opt_bRoadCuts || RCS.tRoad.opt_bDynamicCuts){
                ProcessRoad_Tris_RoadCuts(ref RCS);
            }

            if(RCS.bInterseOn){
                //For intersection parts:
                //Back lanes:
                ProcessRoad_Tris_iProcessor(ref RCS.iBLane0s_tris,ref RCS.iBLane0s);
                ProcessRoad_Tris_iProcessor(ref RCS.iBLane1s_tris,ref RCS.iBLane1s);
                ProcessRoad_Tris_iProcessor(ref RCS.iBLane2s_tris,ref RCS.iBLane2s);
                ProcessRoad_Tris_iProcessor(ref RCS.iBLane3s_tris,ref RCS.iBLane3s);
                //Front lanes:
                ProcessRoad_Tris_iProcessor(ref RCS.iFLane0s_tris,ref RCS.iFLane0s);
                ProcessRoad_Tris_iProcessor(ref RCS.iFLane1s_tris,ref RCS.iFLane1s);
                ProcessRoad_Tris_iProcessor(ref RCS.iFLane2s_tris,ref RCS.iFLane2s);
                ProcessRoad_Tris_iProcessor(ref RCS.iFLane3s_tris,ref RCS.iFLane3s);
                //Main plates:
                ProcessRoad_Tris_iProcessor(ref RCS.iBMainPlates_tris,ref RCS.iBMainPlates);
                ProcessRoad_Tris_iProcessor(ref RCS.iFMainPlates_tris,ref RCS.iFMainPlates);
            }
        }
Ejemplo n.º 13
0
 private static void ProcessRoad_Normals_Shoulders(ref GSD.Roads.RoadConstructorBufferMaker RCS)
 {
     //A mesh with just the vertices and triangles set up will be visible in the editor but will not look very convincing since it is not correctly shaded without the normals.
     //The normals for the flat plane are very simple - they are all identical and point in the negative Z direction in the plane's local space.
     //With the normals added, the plane will be correctly shaded but remember that you need a light in the scene to see the effect.
     int MVL = RCS.ShoulderL_Vectors.Count;
     Vector3[] normals = new Vector3[MVL];
     //			Vector3 tVect = -Vector3.forward;
     //			for(int i=0;i<MVL;i++){
     //				normals[i] = tVect;
     //			}
     RCS.normals_ShoulderL = normals;
     //Right:
     MVL = RCS.ShoulderR_Vectors.Count;
     normals = new Vector3[MVL];
     //			tVect = -Vector3.forward;
     //			for(int i=0;i<MVL;i++){
     //				normals[i] = tVect;
     //			}
     RCS.normals_ShoulderR = normals;
 }
Ejemplo n.º 14
0
 private static void ProcessRoad_Normals_ShoulderCutsR(ref GSD.Roads.RoadConstructorBufferMaker RCS)
 {
     int cCount = RCS.cut_ShoulderR_Vectors.Count;
     for(int j=0;j<cCount;j++){
         int MVL = RCS.cut_ShoulderR_Vectors[j].Count;
         Vector3[] normals = new Vector3[MVL];
     //				Vector3 tVect = -Vector3.forward;
     //				for(int i=0;i<MVL;i++){
     //					normals[i] = tVect;
     //				}
         RCS.cut_normals_ShoulderR.Add(normals);
     }
 }
Ejemplo n.º 15
0
        private static void ProcessRoad_Normals_Bulk(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //A mesh with just the vertices and triangles set up will be visible in the editor but will not look very convincing since it is not correctly shaded without the normals.
            //The normals for the flat plane are very simple - they are all identical and point in the negative Z direction in the plane's local space.
            //With the normals added, the plane will be correctly shaded but remember that you need a light in the scene to see the effect.
            //Bridge normals are processed at same time as tris.
            int MVL = RCS.RoadVectors.Count;
            Vector3[] normals = new Vector3[MVL];
            //			Vector3 tVect = -Vector3.forward;
            //			for(int i=0;i<MVL;i++){
            //				normals[i] = tVect;
            //			}
            RCS.normals = normals;

            //Road cuts normals:
            if(RCS.tRoad.opt_bRoadCuts || RCS.tRoad.opt_bDynamicCuts){
                ProcessRoad_Normals_RoadCuts(ref RCS);
            }
            if(RCS.tRoad.opt_bShoulderCuts || RCS.tRoad.opt_bDynamicCuts){
                ProcessRoad_Normals_ShoulderCutsR(ref RCS);
                ProcessRoad_Normals_ShoulderCutsL(ref RCS);
            }

            //Intersection normals:
            if(RCS.bInterseOn){
                //For intersection parts:
                //Back lanes:
                ProcessRoad_Normals_iProcessor(ref RCS.iBLane0s_normals,ref RCS.iBLane0s);
                ProcessRoad_Normals_iProcessor(ref RCS.iBLane1s_normals,ref RCS.iBLane1s);
                ProcessRoad_Normals_iProcessor(ref RCS.iBLane2s_normals,ref RCS.iBLane2s);
                ProcessRoad_Normals_iProcessor(ref RCS.iBLane3s_normals,ref RCS.iBLane3s);
                //Front lanes:
                ProcessRoad_Normals_iProcessor(ref RCS.iFLane0s_normals,ref RCS.iFLane0s);
                ProcessRoad_Normals_iProcessor(ref RCS.iFLane1s_normals,ref RCS.iFLane1s);
                ProcessRoad_Normals_iProcessor(ref RCS.iFLane2s_normals,ref RCS.iFLane2s);
                ProcessRoad_Normals_iProcessor(ref RCS.iFLane3s_normals,ref RCS.iFLane3s);
                //Main plates:
                ProcessRoad_Normals_iProcessor(ref RCS.iBMainPlates_normals,ref RCS.iBMainPlates);
                ProcessRoad_Normals_iProcessor(ref RCS.iFMainPlates_normals,ref RCS.iFMainPlates);
                //Marker plates:
                ProcessRoad_Normals_iProcessor(ref RCS.iBMarkerPlates_normals,ref RCS.iBMarkerPlates);
                ProcessRoad_Normals_iProcessor(ref RCS.iFMarkerPlates_normals,ref RCS.iFMarkerPlates);
            }
        }
Ejemplo n.º 16
0
 //Privatized for obfuscate:
 public static void DoRects(GSDSplineC tSpline, GSD.Roads.GSDTerraforming.TempTerrainData TTD)
 {
     DoRectsDo(ref tSpline, ref TTD);
 }
Ejemplo n.º 17
0
        private static void ProcessRoad_UVs_Intersections(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            int tCount = -1;

            //Lanes:
            tCount = RCS.iBLane0s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBLane0s_uv.Add(ProcessRoad_UVs_Intersection_Lane0(ref RCS,RCS.iBLane0s[i]));
            }
            tCount = RCS.iBLane1s.Count;
            for(int i=0;i<tCount;i++){
                if(RCS.iBLane1s_IsMiddleLane[i]){
                    RCS.iBLane1s_uv.Add(ProcessRoad_UVs_Intersection_MiddleLane(ref RCS,RCS.iBLane1s[i]));
                }else{
                    RCS.iBLane1s_uv.Add(ProcessRoad_UVs_Intersection_FullLane(ref RCS,RCS.iBLane1s[i]));
                }
            }
            tCount = RCS.iBLane2s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBLane2s_uv.Add(ProcessRoad_UVs_Intersection_FullLane(ref RCS,RCS.iBLane2s[i]));
            }
            tCount = RCS.iBLane3s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBLane3s_uv.Add(ProcessRoad_UVs_Intersection_Lane4(ref RCS,RCS.iBLane3s[i]));
            }

            //Lanes:
            tCount = RCS.iFLane0s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFLane0s_uv.Add(ProcessRoad_UVs_Intersection_Lane0(ref RCS,RCS.iFLane0s[i]));
            }
            tCount = RCS.iFLane1s.Count;
            for(int i=0;i<tCount;i++){
                if(RCS.iFLane1s_IsMiddleLane[i]){
                    RCS.iFLane1s_uv.Add(ProcessRoad_UVs_Intersection_MiddleLane(ref RCS,RCS.iFLane1s[i]));
                }else{
                    RCS.iFLane1s_uv.Add(ProcessRoad_UVs_Intersection_FullLane(ref RCS,RCS.iFLane1s[i]));
                }
            }
            tCount = RCS.iFLane2s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFLane2s_uv.Add(ProcessRoad_UVs_Intersection_FullLane(ref RCS,RCS.iFLane2s[i]));
            }
            tCount = RCS.iFLane3s.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFLane3s_uv.Add(ProcessRoad_UVs_Intersection_Lane4(ref RCS,RCS.iFLane3s[i]));
            }

            //Main plates:
            tCount = RCS.iBMainPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBMainPlates_uv.Add(ProcessRoad_UVs_Intersection_MainPlate(ref RCS,RCS.iBMainPlates[i]));
            }
            tCount = RCS.iFMainPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFMainPlates_uv.Add(ProcessRoad_UVs_Intersection_MainPlate(ref RCS,RCS.iFMainPlates[i]));
            }
            tCount = RCS.iBMainPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBMainPlates_uv2.Add(ProcessRoad_UVs_Intersection_MainPlate2(ref RCS,RCS.iBMainPlates[i],RCS.iBMainPlates_tID[i]));
            }
            tCount = RCS.iFMainPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFMainPlates_uv2.Add(ProcessRoad_UVs_Intersection_MainPlate2(ref RCS,RCS.iFMainPlates[i],RCS.iFMainPlates_tID[i]));
            }

            //Marker plates:
            tCount = RCS.iBMarkerPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iBMarkerPlates_uv.Add(ProcessRoad_UVs_Intersection_MarkerPlate(ref RCS,RCS.iBMarkerPlates[i]));
            }
            tCount = RCS.iFMarkerPlates.Count;
            for(int i=0;i<tCount;i++){
                RCS.iFMarkerPlates_uv.Add(ProcessRoad_UVs_Intersection_MarkerPlate(ref RCS,RCS.iFMarkerPlates[i]));
            }
        }
Ejemplo n.º 18
0
        private static int[] CreateTris(float i, float i2,ref Vector3 tVect1,ref Vector3 POS1,ref Vector3 tVect2,ref Vector3 POS2, float Sep, ref List<TerrainBoundsMaker> tList, ref float T1SUB, ref float T2SUB,ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, float HeightSep)
        {
            Vector3 lVect1 = (tVect1 + new Vector3(Sep*-POS1.normalized.z,0,Sep*POS1.normalized.x));
            Vector3 rVect1 = (tVect1 + new Vector3(Sep*POS1.normalized.z,0,Sep*-POS1.normalized.x));
            Vector3 lVect2 = (tVect2 + new Vector3(Sep*-POS2.normalized.z,0,Sep*POS2.normalized.x));
            Vector3 rVect2 = (tVect2 + new Vector3(Sep*POS2.normalized.z,0,Sep*-POS2.normalized.x));

            lVect1.y = T1SUB;
            rVect1.y = T1SUB;
            lVect2.y = T2SUB;
            rVect2.y = T2SUB;

            TerrainBoundsMaker TBM = new TerrainBoundsMaker();
            TBM.triList = new List<GSD.Roads.GSDRoadUtil.Construction3DTri>();

            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(lVect1,rVect1,lVect2,i,i2));
            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(lVect2,rVect1,rVect2,i,i2));

            Vector3 lVect1far = (tVect1 + new Vector3(HeightSep*-POS1.normalized.z,0,HeightSep*POS1.normalized.x));
            Vector3 rVect1far = (tVect1 + new Vector3(HeightSep*POS1.normalized.z,0,HeightSep*-POS1.normalized.x));
            Vector3 lVect2far = (tVect2 + new Vector3(HeightSep*-POS2.normalized.z,0,HeightSep*POS2.normalized.x));
            Vector3 rVect2far = (tVect2 + new Vector3(HeightSep*POS2.normalized.z,0,HeightSep*-POS2.normalized.x));

            lVect1far.y = lVect1.y;
            lVect2far.y = lVect2.y;
            rVect1far.y = rVect1.y;
            rVect2far.y = rVect2.y;

            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(lVect1far,lVect1,lVect2far,i,i2));
            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(lVect2far,lVect1,lVect2,i,i2));
            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(rVect1,rVect1far,rVect2,i,i2));
            TBM.triList.Add(new GSD.Roads.GSDRoadUtil.Construction3DTri(rVect2,rVect1far,rVect2far,i,i2));

            TBM.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);
            //			tRect.MinI = i;
            //			tRect.MaxI = i2;

            TBM.MinI = i;
            TBM.MaxI = i2;

            tList.Add(TBM);

            int[] Xs = new int[4];
            int[] Ys = new int[4];

            int x1,y1;
            GetTempHeights_Coordinates(ref lVect1far,ref TTD,out x1, out y1);
            Xs[0] = x1;
            Ys[0] = y1;
            GetTempHeights_Coordinates(ref lVect2far,ref TTD,out x1, out y1);
            Xs[1] = x1;
            Ys[1] = y1;
            GetTempHeights_Coordinates(ref rVect1far,ref TTD,out x1, out y1);
            Xs[2] = x1;
            Ys[2] = y1;
            GetTempHeights_Coordinates(ref rVect2far,ref TTD,out x1, out y1);
            Xs[3] = x1;
            Ys[3] = y1;

            int Min = Mathf.Min(Xs);
            int Max = Mathf.Max(Xs);
            Xs[0] = Min-2;
            Xs[2] = Max+2;
            Min = Mathf.Min(Ys);
            Max = Mathf.Max(Ys);
            Xs[1] = Min-2;
            Xs[3] = Max+2;

            return Xs;
        }
Ejemplo n.º 19
0
        private static void AddIntersectionBounds(ref GSDRoad tRoad, ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            bool bIsBridge = false;
            bool bBridgeInitial = false; if(bBridgeInitial == false){ }
            bool bTempbridge = false;
            bool bBridgeLast = false; if(bBridgeLast == false){ }

            bool bIsTunnel = false;
            bool bTunnelInitial = false; if(bTunnelInitial == false){ }
            bool bTempTunnel = false;
            bool bTunnelLast = false; if(bTunnelLast == false){ }

            GSDRoadIntersection GSDRI = null;
            bool bIsPastInter = false;
            bool bMaxIntersection = false;
            bool bWasPrevMaxInter = false;
            Vector3 tVect = default(Vector3);
            Vector3 POS = default(Vector3);
            float tIntHeight = 0f;
            float tIntStrength = 0f;
            float tIntStrength_temp = 0f;
            //			float tIntDistCheck = 75f;
            bool bFirstInterNode = false;
            Vector3 tVect_Prev = default(Vector3); 		if(tVect_Prev == default(Vector3)){ }
            Vector3 rVect_Prev = default(Vector3); 		if(rVect_Prev == default(Vector3)){ }
            Vector3 lVect_Prev = default(Vector3); 		if(lVect_Prev == default(Vector3)){ }
            Vector3 rVect = default(Vector3);			if(rVect == default(Vector3)){ }
            Vector3 lVect = default(Vector3);			if(lVect == default(Vector3)){ }
            Vector3 ShoulderR_rVect = default(Vector3);	if(ShoulderR_rVect == default(Vector3)){ }
            Vector3 ShoulderR_lVect = default(Vector3);	if(ShoulderR_lVect == default(Vector3)){ }
            Vector3 ShoulderL_rVect = default(Vector3);	if(ShoulderL_rVect == default(Vector3)){ }
            Vector3 ShoulderL_lVect = default(Vector3);	if(ShoulderL_lVect == default(Vector3)){ }

            Vector3 RampR_R = default(Vector3);
            Vector3 RampR_L = default(Vector3);
            Vector3 RampL_R = default(Vector3);
            Vector3 RampL_L = default(Vector3);
            float ShoulderR_OuterAngle = 0f;	if(ShoulderR_OuterAngle < 0f){ }
            float ShoulderL_OuterAngle = 0f;	if(ShoulderL_OuterAngle < 0f){ }
            Vector3 ShoulderR_PrevLVect = default(Vector3); if(ShoulderR_PrevLVect == default(Vector3)){ }
            Vector3 ShoulderL_PrevRVect = default(Vector3); if(ShoulderL_PrevRVect == default(Vector3)){ }
            Vector3 ShoulderR_PrevRVect = default(Vector3); if(ShoulderR_PrevRVect == default(Vector3)){ }
            Vector3 ShoulderL_PrevLVect = default(Vector3); if(ShoulderL_PrevLVect == default(Vector3)){ }
            //			Vector3 ShoulderR_PrevRVect2 = default(Vector3);
            //			Vector3 ShoulderL_PrevLVect2 = default(Vector3);
            //			Vector3 ShoulderR_PrevRVect3 = default(Vector3);
            //			Vector3 ShoulderL_PrevLVect3 = default(Vector3);
            Vector3 RampR_PrevR = default(Vector3); if(RampR_PrevR == default(Vector3)){ }
            Vector3 RampR_PrevL = default(Vector3); if(RampR_PrevL == default(Vector3)){ }
            Vector3 RampL_PrevR = default(Vector3); if(RampL_PrevR == default(Vector3)){ }
            Vector3 RampL_PrevL = default(Vector3); if(RampL_PrevL == default(Vector3)){ }
            GSDSplineC tSpline = tRoad.GSDSpline;
            //Road width:
            float RoadWidth = tRoad.RoadWidth();
            float ShoulderWidth = tRoad.opt_ShoulderWidth;
            float RoadSeperation = RoadWidth / 2f;
            float RoadSeperation_NoTurn = RoadWidth / 2f;
            float ShoulderSeperation = RoadSeperation + ShoulderWidth;
            float LaneWidth = tRoad.opt_LaneWidth;
            float RoadSep1Lane = (RoadSeperation + (LaneWidth*0.5f));
            float RoadSep2Lane = (RoadSeperation + (LaneWidth*1.5f));
            float ShoulderSep1Lane = (ShoulderSeperation + (LaneWidth*0.5f));		if(ShoulderSep1Lane < 0f){ }
            float ShoulderSep2Lane = (ShoulderSeperation + (LaneWidth*1.5f));		if(ShoulderSep2Lane < 0f){ }

            //			float tAngle = 0f;
            //			float OrigStep = 0.06f;
            float Step = tRoad.opt_RoadDefinition / tSpline.distance;

            GSDSplineN xNode = null;
            float tInterSubtract = 4f;
            float tLastInterHeight = -4f;

            //			GameObject xObj = null;
            //			xObj = GameObject.Find("temp22");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22");
            //			}
            //			xObj = GameObject.Find("temp23");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp23");
            //			}
            //			xObj = GameObject.Find("temp22_RR");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_RR");
            //			}
            //			xObj = GameObject.Find("temp22_RL");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_RL");
            //			}
            //			xObj = GameObject.Find("temp22_LR");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_LR");
            //			}
            //			xObj = GameObject.Find("temp22_LL");
            //			while(xObj != null){
            //				Object.DestroyImmediate(xObj);
            //				xObj = GameObject.Find("temp22_LL");
            //			}

            bool bFinalEnd = false;
            float i = 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;
            }

            //			int StartIndex = tSpline.GetClosestRoadDefIndex(StartMin,true,false);
            //			int EndIndex = tSpline.GetClosestRoadDefIndex(FinalMax,false,true);
            //			float cDist = 0f;
            bool kSkip = true;
            bool kSkipFinal = false;
            int kCount = 0;
            int kFinalCount = tSpline.RoadDefKeysArray.Length;
            int spamcheckmax1 = 18000;
            int spamcheck1 = 0;

            if(IsApproximately(StartMin,0f,0.0001f)){
                kSkip = false;
            }
            if(IsApproximately(FinalMax,1f,0.0001f)){
                kSkipFinal = true;
            }

            while(!bFinalEnd && spamcheck1 < spamcheckmax1){
                spamcheck1++;

                if(kSkip){
                    i = StartMin;
                    kSkip = false;
                }else{
                    if(kCount >= kFinalCount){
                        i = FinalMax;
                        if(kSkipFinal){ break; }
                    }else{
                        i = tSpline.TranslateInverseParamToFloat(tSpline.RoadDefKeysArray[kCount]);
                        kCount+=1;
                    }
                }

                if(i > 1f){ break; }
                if(i < 0f){ i = 0f; }

                if(IsApproximately(i,FinalMax,0.00001f)){
                    bFinalEnd = true;
                }else if(i > FinalMax){
                    if(tSpline.bSpecialEndControlNode){
                        i = FinalMax;
                        bFinalEnd = true;
                    }else{
                        bFinalEnd = true;
                        break;
                    }
                }

                tSpline.GetSplineValue_Both(i,out tVect,out POS);
                bIsPastInter = false;
                tIntStrength = tSpline.IntersectionStrength(ref tVect,ref tIntHeight, ref GSDRI, ref bIsPastInter, ref i, ref xNode);
                if(IsApproximately(tIntStrength,1f,0.001f) || tIntStrength > 1f){
                    bMaxIntersection = true;
                }else{
                    bMaxIntersection = false;
                }

                if(bMaxIntersection){
                    if(string.Compare(xNode.UID,GSDRI.Node1.UID) == 0){
                        bFirstInterNode = true;
                    }else{
                        bFirstInterNode = false;
                    }

                    //Convoluted for initial trigger:
                    bBridgeInitial = false;
                    bBridgeLast = false;
                    bTempbridge = tSpline.IsInBridge(i);
                    if(!bIsBridge && bTempbridge){
                        bIsBridge = true;
                        bBridgeInitial = true;
                    }else if(bIsBridge && !bTempbridge){
                        bIsBridge = false;
                    }
                    //Check if this is the last bridge run for this bridge:
                    if(bIsBridge){
                        bTempbridge = tSpline.IsInBridge(i+Step);
                        if(!bTempbridge){
                            bBridgeLast = true;
                        }
                    }

                    //Convoluted for initial trigger:
                    bTunnelInitial = false;
                    bTunnelLast = false;
                    bTempTunnel = tSpline.IsInTunnel(i);
                    if(!bIsTunnel && bTempTunnel){
                        bIsTunnel = true;
                        bTunnelInitial = true;
                    }else if(bIsTunnel && !bTempTunnel){
                        bIsTunnel = false;
                    }
                    //Check if this is the last Tunnel run for this Tunnel:
                    if(bIsTunnel){
                        bTempTunnel = tSpline.IsInTunnel(i+Step);
                        if(!bTempTunnel){
                            bTunnelLast = true;
                        }
                    }

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        rVect = (tVect + new Vector3(RoadSeperation_NoTurn*POS.normalized.z,0,RoadSeperation_NoTurn*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation_NoTurn*-POS.normalized.z,0,RoadSeperation_NoTurn*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                        if(bIsPastInter){
                            rVect = (tVect + new Vector3(RoadSep1Lane*POS.normalized.z,0,RoadSep1Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep2Lane*-POS.normalized.z,0,RoadSep2Lane*POS.normalized.x));;
                        }else{
                            rVect = (tVect + new Vector3(RoadSep2Lane*POS.normalized.z,0,RoadSep2Lane*-POS.normalized.x));
                            lVect = (tVect + new Vector3(RoadSep1Lane*-POS.normalized.z,0,RoadSep1Lane*POS.normalized.x));
                        }
                    }else{
                        rVect = (tVect + new Vector3(RoadSeperation*POS.normalized.z,0,RoadSeperation*-POS.normalized.x));
                        lVect = (tVect + new Vector3(RoadSeperation*-POS.normalized.z,0,RoadSeperation*POS.normalized.x));
                    }

                    if(tIntStrength >= 1f){
                        tVect.y -= tInterSubtract;
                        tLastInterHeight = tVect.y;
                        rVect.y -= tInterSubtract;
                        lVect.y -= tInterSubtract;
                    }else{
                        if(!IsApproximately(tIntStrength,0f,0.001f)){ tVect.y = (tIntStrength*tIntHeight) + ((1-tIntStrength)*tVect.y); }
                        tIntStrength_temp = tRoad.GSDSpline.IntersectionStrength(ref rVect,ref tIntHeight, ref GSDRI,ref bIsPastInter,ref i, ref xNode);
                        if(!IsApproximately(tIntStrength_temp,0f,0.001f)){ rVect.y = (tIntStrength_temp*tIntHeight) + ((1-tIntStrength_temp)*rVect.y); ShoulderR_lVect = rVect; }
                    }

                    //Add bounds for later removal:
                    GSD.Roads.GSDRoadUtil.Construction2DRect vRect = null;
                    if(!bIsBridge && !bIsTunnel && bMaxIntersection && bWasPrevMaxInter){
                        bool bGoAhead = true;
                        if(xNode.bIsEndPoint){
                            if(xNode.idOnSpline == 1){
                                if(i < xNode.tTime){
                                    bGoAhead = false;
                                }
                            }else{
                                if(i > xNode.tTime){
                                    bGoAhead = false;
                                }
                            }
                        }
                        //Get this and prev lvect rvect rects:
                        if(Vector3.Distance(xNode.pos,tVect) < (3f * RoadWidth) && bGoAhead){
                            if(GSDRI.bFlipped && !bFirstInterNode){
                                vRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(
                                    new Vector2(rVect.x,rVect.z),
                                    new Vector2(lVect.x,lVect.z),
                                    new Vector2(rVect_Prev.x,rVect_Prev.z),
                                    new Vector2(lVect_Prev.x,lVect_Prev.z),
                                    tLastInterHeight
                                    );
                            }else{
                                 vRect = new GSD.Roads.GSDRoadUtil.Construction2DRect(
                                    new Vector2(lVect.x,lVect.z),
                                    new Vector2(rVect.x,rVect.z),
                                    new Vector2(lVect_Prev.x,lVect_Prev.z),
                                    new Vector2(rVect_Prev.x,rVect_Prev.z),
                                    tLastInterHeight
                                    );
                            }
            //							GameObject tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //							tObj.transform.position = lVect;
            //							tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //							tObj.transform.name = "temp22";
            //
            //							tObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //							tObj.transform.position = rVect;
            //							tObj.transform.localScale = new Vector3(0.2f,20f,0.2f);
            //							tObj.transform.name = "temp22";

                            RCS.tIntersectionBounds.Add(vRect);
                        }
                    }
                }

                bWasPrevMaxInter = bMaxIntersection;
                tVect_Prev = tVect;
                rVect_Prev = rVect;
                lVect_Prev = lVect;
                ShoulderR_PrevLVect = ShoulderR_lVect;
                ShoulderL_PrevRVect = ShoulderL_rVect;
            //				ShoulderR_PrevRVect3 = ShoulderR_PrevRVect2;
            //				ShoulderL_PrevLVect3 = ShoulderL_PrevLVect2;
            //				ShoulderR_PrevRVect2 = ShoulderR_PrevRVect;
            //				ShoulderL_PrevLVect2 = ShoulderL_PrevLVect;
                ShoulderR_PrevRVect = ShoulderR_rVect;
                ShoulderL_PrevLVect = ShoulderL_lVect;
                RampR_PrevR = RampR_R;
                RampR_PrevL = RampR_L;
                RampL_PrevR = RampL_R;
                RampL_PrevL = RampL_L;
            //				i+=Step;
            }
        }
Ejemplo n.º 20
0
        //        static Vector3 ProcessLineHeights_PrevVect = new Vector3(0f,0f,0f);
        //        public static float ProcessLineHeights(GSDSplineC tSpline, ref Vector3 tVect, ref Vector3 POS, float tDistance, GSD.Roads.GSDTerraforming.TempTerrainData TTD, float PrevDesiredHeight){
        //            Vector3 ShoulderR_rVect = new Vector3(0f,0f,0f);
        //            Vector3 ShoulderL_lVect = new Vector3(0f,0f,0f);
        //
        //            float DesiredHeight = ProcessLineHeights_GetDesiredHeight(tVect,ref TTD, ref tSpline);
        //            float nResult = 0f;
        //            bool bIntersection = tSpline.IsNearIntersection(ref tVect,ref nResult);
        //            if(bIntersection){
        //                if(nResult < tVect.y){
        //                    tVect.y = nResult;
        //                    DesiredHeight = ProcessLineHeights_GetDesiredHeight(tVect,ref TTD, ref tSpline);
        //                }
        //            }
        //
        //            int x1 = 0,y1 = 0;
        //            GetTempHeights_Coordinates(ref tVect,ref TTD,out x1,out y1);
        //                
        //            bool bOverride = false;
        //            int StepMod = (int)(1 / TTD.HMRatio);
        //            for(float i=tDistance;i>=1f;i-=StepMod){
        //                ShoulderR_rVect = (tVect + new Vector3(i*POS.normalized.z,0,i*-POS.normalized.x));
        //                GetTempHeights_Coordinates(ref ShoulderR_rVect,ref TTD,out x1,out y1);
        //                if(TTD.heights[x1,y1] > DesiredHeight){
        //                    bOverride = true;
        //                }
        //                if(bOverride || !TTD.tHeights[x1,y1]){
        //                    TTD.tHeights[x1,y1] = true;
        //                    TTD.cX[TTD.cI] = x1;
        //                    TTD.cY[TTD.cI] = y1;
        //                    TTD.cH[TTD.cI] = DesiredHeight;
        //                    TTD.oldH[TTD.cI] = TTD.heights[x1,y1];
        //                    TTD.cI += 1;
        //                }
        //                bOverride = false;
        //    
        //                ShoulderL_lVect = (tVect + new Vector3(i*-POS.normalized.z,0,i*POS.normalized.x));
        //                GetTempHeights_Coordinates(ref ShoulderL_lVect,ref TTD,out x1,out y1);
        //                if(TTD.heights[x1,y1] > DesiredHeight){
        //                    bOverride = true;
        //                }
        //                if(bOverride || !TTD.tHeights[x1,y1]){
        //                    TTD.tHeights[x1,y1] = true;
        //                    TTD.cX[TTD.cI] = x1;
        //                    TTD.cY[TTD.cI] = y1;
        //                    TTD.cH[TTD.cI] = DesiredHeight;
        //                    TTD.oldH[TTD.cI] = TTD.heights[x1,y1];
        //                    TTD.cI += 1;
        //                }
        //                bOverride=false;
        //            }
        //
        //            GetTempHeights_Coordinates(ref tVect,ref TTD,out x1,out y1);
        //            if(TTD.heights[x1,y1] > DesiredHeight || (tVect.y < ProcessLineHeights_PrevVect.y)){
        //                bOverride = true;
        //            }
        //            if(bOverride || !TTD.tHeights[x1,y1]){
        //                TTD.tHeights[x1,y1] = true;
        //                TTD.cX[TTD.cI] = x1;
        //                TTD.cY[TTD.cI] = y1;
        //                if(tDistance > 15f && TTD.HMRatio > 0.24f){
        //                    TTD.cH[TTD.cI] = DesiredHeight-0.0002f;
        //                }else{
        //                    TTD.cH[TTD.cI] = DesiredHeight;
        //                }
        //                TTD.oldH[TTD.cI] = TTD.heights[x1,y1];
        //                TTD.cI += 1;
        //            }
        //                
        //            ProcessLineHeights_PrevVect = tVect;
        //            return DesiredHeight;
        //        }
        //
        //        private static float ProcessLineHeights_GetDesiredHeight(Vector3 tVect, ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, ref GSDSplineC tSpline){
        //            return ((((tVect - TTD.TerrainPos).y)-tSpline.tRoad.opt_TerrainSubtract_Alt) / TTD.TerrainSize.y);
        //        }
        private static void GetTempHeights_Coordinates(ref Vector3 tVect,ref GSD.Roads.GSDTerraforming.TempTerrainData TTD, out int x, out int y)
        {
            //Get the normalized position of this game object relative to the terrain:
            Vector3 tempCoord = (tVect - TTD.TerrainPos);

            Vector3 coord;
            coord.x = tempCoord.x / TTD.TerrainSize.x;
            coord.y = tempCoord.y / TTD.TerrainSize.y;
            coord.z = tempCoord.z / TTD.TerrainSize.z;

            //Get the position of the terrain heightmap where this game object is:
            y = (int) (coord.x * TTD.HM);
            x = (int) (coord.z * TTD.HM);
        }
Ejemplo n.º 21
0
        private static Vector2[] ProcessRoad_UVs_Intersection_MainPlate(ref GSD.Roads.RoadConstructorBufferMaker RCS, Vector3[] tVerts)
        {
            //Finally, adding texture coordinates to the mesh will enable it to display a material correctly.
            //Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture.
            //int MVL = tMesh.vertices.Length;
            int MVL = tVerts.Length;
            Vector2[] uv = new Vector2[MVL];
            int i=0;
            //			bool bOddToggle = true;
            //			float tDistance= 0f;
            //			float tDistanceLeft = 0f;
            //			float tDistanceRight = 0f;
            //			float tDistanceLeftSum = 0f;
            //			float tDistanceRightSum = 0f;
            //			float tDistanceSum = 0f;
            //			float DistRepresent = 5f;

            //			float mDistanceL = Vector3.Distance(tVerts[i],tVerts[tVerts.Length-3]);
            //			float mDistanceR = Vector3.Distance(tVerts[i+2],tVerts[tVerts.Length-1]);

            for(i=0;i<MVL;i++){
                uv[i] = new Vector2(tVerts[i].x*0.2f, tVerts[i].z*0.2f);
            }
            return uv;

            //			while(i+6 < MVL){
            //				tDistanceLeft = Vector3.Distance(tVerts[i],tVerts[i+4]);
            //				tDistanceRight = Vector3.Distance(tVerts[i+2],tVerts[i+6]);
            //
            //				tDistanceLeft = tDistanceLeft / 5f;
            //				tDistanceRight = tDistanceRight / 5f;
            //
            ////				if(i==0){
            ////					uv[i] = new Vector2(0.25f, tDistanceLeftSum);
            ////					uv[i+2] = new Vector2(1.25f, tDistanceRightSum);
            ////					uv[i+4] = new Vector2(0f, tDistanceLeft+tDistanceLeftSum);
            ////					uv[i+6] = new Vector2(2f, tDistanceRight+tDistanceRightSum);
            ////				}else{
            ////					uv[i] = new Vector2(0f, tDistanceLeftSum);
            ////					uv[i+2] = new Vector2(2f, tDistanceRightSum);
            ////					uv[i+4] = new Vector2(0f, tDistanceLeft+tDistanceLeftSum);
            ////					uv[i+6] = new Vector2(2f, tDistanceRight+tDistanceRightSum);
            ////				}
            //
            //				uv[i] = new Vector2(tVerts[i].x/5f, tVerts[i].z/5f);
            //				uv[i+2] = new Vector2(tVerts[i+2].x/5f, tVerts[i+2].z/5f);
            //				uv[i+4] = new Vector2(tVerts[i+4].x/5f, tVerts[i+4].z/5f);
            //				uv[i+6] = new Vector2(tVerts[i+6].x/5f, tVerts[i+6].z/5f);
            //
            //				//Last segment needs adjusted due to double vertices:
            //				if((i+7) == MVL){
            //					if(bOddToggle){
            //						//First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
            //						uv[MVL-3] = uv[i+4];
            //						uv[MVL-1] = uv[i+6];
            //					}else{
            //						//Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
            //						uv[MVL-4] = uv[i+4];
            //						uv[MVL-2] = uv[i+6];
            //					}
            //				}
            //
            //				if(bOddToggle){
            //					i+=5;
            //				}else{
            //					i+=3;
            //				}
            //
            //				tDistanceLeftSum+=tDistanceLeft;
            //				tDistanceRightSum+=tDistanceRight;
            //				//tDistanceSum+=tDistance;
            //				bOddToggle = !bOddToggle;
            //			}
            //			return uv;
        }
Ejemplo n.º 22
0
        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;
        }
Ejemplo n.º 23
0
        private static Vector2[] ProcessRoad_UVs_Intersection_MainPlate2(ref GSD.Roads.RoadConstructorBufferMaker RCS, Vector3[] tVerts, GSDRoadIntersection GSDRI)
        {
            //Finally, adding texture coordinates to the mesh will enable it to display a material correctly.
            //Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture.
            //int MVL = tMesh.vertices.Length;
            int MVL = tVerts.Length;
            Vector2[] uv = new Vector2[MVL];
            int i=0;
            bool bOddToggle = true;
            //			float tDistance= 0f;
            float tDistanceLeft = 0f;
            float tDistanceRight = 0f;
            float tDistanceLeftSum = 0f;
            float tDistanceRightSum = 0f;
            //			float tDistanceSum = 0f;
            //			float DistRepresent = 5f;

            float mDistanceL = Vector3.Distance(tVerts[i+4],tVerts[tVerts.Length-3]);
            float mDistanceR = Vector3.Distance(tVerts[i+6],tVerts[tVerts.Length-1]);
            mDistanceL = mDistanceL * 1.125f;
            mDistanceR = mDistanceR * 1.125f;

            //			int bHitMaxL = 0;
            //			int bHitMaxR = 0;

            float tAdd1;
            float tAdd2;
            float tAdd3;
            float tAdd4;

            float RoadWidth = RCS.tRoad.RoadWidth();
            float LaneWidth = RCS.tRoad.opt_LaneWidth;
            float iWidth = -1;
            if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){
                iWidth = RoadWidth + (LaneWidth*2f);
            }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                iWidth = RoadWidth + (LaneWidth*1f);
            }else{
                iWidth = RoadWidth;
            }

            while(i+6 < MVL){
                if(i==0){

                    if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.BothTurnLanes){

                        //(Lane width / 2)/roadwidth
                        //1-((lanewidth / 2)/roadwidth)

                        uv[i] = new Vector2((LaneWidth * 0.5f)/iWidth, 0f);
                        uv[i+2] = new Vector2(1f-(((LaneWidth * 0.5f) + LaneWidth)/iWidth), 0f);
                        //Debug.Log (GSDRI.tName + " " + uv[i+2].x);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.TurnLane){
                        uv[i] = new Vector2((LaneWidth * 0.5f)/iWidth, 0f);
                        uv[i+2] = new Vector2(1f-((LaneWidth * 0.5f)/iWidth), 0f);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }else if(GSDRI.rType == GSDRoadIntersection.RoadTypeEnum.NoTurnLane){
                        uv[i] = new Vector2(0f, 0f);
                        uv[i+2] = new Vector2(1f, 0f);
                        uv[i+4] = new Vector2(0f, 0.125f);
                        uv[i+6] = new Vector2(1f, 0.125f);
                    }
                    tDistanceLeft = 0.125f;
                    tDistanceRight = 0.125f;
                }else{
                    tDistanceLeft = Vector3.Distance(tVerts[i],tVerts[i+4]);
                    tDistanceRight = Vector3.Distance(tVerts[i+2],tVerts[i+6]);
                    tDistanceLeft = tDistanceLeft / mDistanceL;
                    tDistanceRight = tDistanceRight / mDistanceR;

            //					if(bHitMaxL > 0 || (tDistanceLeftSum+tDistanceLeft) > 1f){
            //						tDistanceLeftSum = 0.998f + (0.0001f*bHitMaxL);
            //						tDistanceLeft = 0.001f;
            //						bHitMaxL+=1;
            //					}
            //					if(bHitMaxR > 0 || (tDistanceRightSum+tDistanceRight) > 1f){
            //						tDistanceRightSum = 0.998f + (0.0001f*bHitMaxR);
            //						tDistanceRight = 0.001f;
            //						bHitMaxR+=1;
            //					}

                    tAdd1 = tDistanceLeftSum; 					if(tAdd1 > 1f){ tAdd1 = 1f; }
                    tAdd2 = tDistanceRightSum; 					if(tAdd2 > 1f){ tAdd2 = 1f; }
                    tAdd3 = tDistanceLeft+tDistanceLeftSum; 	if(tAdd3 > 1f){ tAdd3 = 1f; }
                    tAdd4 = tDistanceRight+tDistanceRightSum; 	if(tAdd4 > 1f){ tAdd4 = 1f; }

                    uv[i] = new Vector2(0f, tAdd1);
                    uv[i+2] = new Vector2(1f, tAdd2);
                    uv[i+4] = new Vector2(0f, tAdd3);
                    uv[i+6] = new Vector2(1f, tAdd4);
                    //Debug.Log (tAdd3 + " R:"+ tAdd4 + " RLoc: " + tVerts[i+6]);
                }

                //Debug.Log ("1.0 R:1.0 RLoc: " + tVerts[i+6]);

                //Last segment needs adjusted due to double vertices:
                if((i+7) == MVL){
                    if(bOddToggle){
                        //First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-3] = uv[i+4];
                        uv[MVL-1] = uv[i+6];
                    }else{
                        //Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-4] = uv[i+4];
                        uv[MVL-2] = uv[i+6];
                    }
                }

                if(bOddToggle){
                    i+=5;

                    if(i+6 >= MVL){
                        uv[i+4-5] = new Vector2(0f, 1f);
                        uv[i+6-5] = new Vector2(1f, 1f);
                    }

                }else{
                    i+=3;

                    if(i+6 >= MVL){
                        uv[i+4-3] = new Vector2(0f, 1f);
                        uv[i+6-3] = new Vector2(1f, 1f);
                    }
                }

                tDistanceLeftSum+=tDistanceLeft;
                tDistanceRightSum+=tDistanceRight;
                //tDistanceSum+=tDistance;
                bOddToggle = !bOddToggle;
            }

            //			uv[MVL-1].y = 1f;
            //			uv[MVL-2].y = 1f;
            //			uv[MVL-3].y = 1f;
            //			uv[MVL-4].y = 1f;

            return uv;
        }
Ejemplo n.º 24
0
 public void Setup(ref GSD.Roads.RoadConstructorBufferMaker _RCS)
 {
     RCS = _RCS;
 }
Ejemplo n.º 25
0
        private static Vector2[] ProcessRoad_UVs_Intersection_MiddleLane(ref GSD.Roads.RoadConstructorBufferMaker RCS, Vector3[] tVerts)
        {
            //Finally, adding texture coordinates to the mesh will enable it to display a material correctly.
            //Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture.
            //int MVL = tMesh.vertices.Length;
            int MVL = tVerts.Length;
            Vector2[] uv = new Vector2[MVL];
            int i=0;
            bool bOddToggle = true;
            float tDistance= 0f;
            float tDistanceLeft = 0f;
            float tDistanceRight = 0f;
            float tDistanceLeftSum = 0f;
            float tDistanceRightSum = 0f;
            float tDistanceSum = 0f;

            while(i+6 < MVL){
                tDistance = Vector3.Distance(tVerts[i],tVerts[i+4]);
                tDistance = tDistance / 5f;

                if(i==0){
                    uv[i] = new Vector2(0f, tDistanceSum);
                    uv[i+2] = new Vector2(0.05f, tDistanceSum);
                    uv[i+4] = new Vector2(0f, tDistance+tDistanceSum);
                    uv[i+6] = new Vector2(1f, tDistance+tDistanceSum);
                }else{
                    uv[i] = new Vector2(0f, tDistanceSum);
                    uv[i+2] = new Vector2(1f, tDistanceSum);
                    uv[i+4] = new Vector2(0f, tDistance+tDistanceSum);
                    uv[i+6] = new Vector2(1f, tDistance+tDistanceSum);
                }

                //Last segment needs adjusted due to double vertices:
                if((i+7) == MVL){
                    if(bOddToggle){
                        //First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-3] = uv[i+4];
                        uv[MVL-1] = uv[i+6];
                    }else{
                        //Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-4] = uv[i+4];
                        uv[MVL-2] = uv[i+6];
                    }
                }

                if(bOddToggle){
                    i+=5;
                }else{
                    i+=3;
                }

                tDistanceLeftSum+=tDistanceLeft;
                tDistanceRightSum+=tDistanceRight;
                tDistanceSum+=tDistance;
                bOddToggle = !bOddToggle;
            }
            return uv;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Handles most UV and tangent construction. Some scenarios might involve triangles and normals or lack UV construction for efficiency reasons.
        /// </summary>
        /// <param name='RCS'>
        /// The road construction buffer, by reference.
        /// </param>
        public static void RoadJob2(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //Bridge UV is processed with tris and normals.

            //For one big road mesh:
            if(RCS.bRoadOn){
                if(!RCS.tMeshSkip){ RCS.uv = ProcessRoad_UVs(RCS.RoadVectors.ToArray()); }
                if(!RCS.tMesh_SRSkip){ RCS.uv_SR = ProcessRoad_UVs_Shoulder(RCS.ShoulderR_Vectors.ToArray()); }
                if(!RCS.tMesh_SLSkip){ RCS.uv_SL = ProcessRoad_UVs_Shoulder(RCS.ShoulderL_Vectors.ToArray()); }

                //UVs for pavement:
                if(!RCS.tMeshSkip){
                    int vCount = RCS.RoadVectors.Count;
                    RCS.uv2 = new Vector2[vCount];
                    for(int i=0;i<vCount;i++){
                        RCS.uv2[i] = new Vector2(RCS.RoadVectors[i].x*0.2f,RCS.RoadVectors[i].z*0.2f);
                    }
                }
            }

            //For road cuts:
            if(RCS.tRoad.opt_bRoadCuts || RCS.tRoad.opt_bDynamicCuts){
                ProcessRoad_UVs_RoadCuts(ref RCS);
                int cCount = RCS.cut_RoadVectors.Count;
                for(int i=0;i<cCount;i++){
                    RCS.cut_tangents.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[i], RCS.cut_normals[i], RCS.cut_uv[i], RCS.cut_RoadVectors[i].ToArray()));
                    RCS.cut_tangents_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris[i], RCS.cut_normals[i], RCS.cut_uv_world[i], RCS.cut_RoadVectors[i].ToArray()));
                }
            }
            if(RCS.tRoad.opt_bShoulderCuts || RCS.tRoad.opt_bDynamicCuts){
                int rCount = RCS.cut_ShoulderR_Vectors.Count;
                for(int i=0;i<rCount;i++){
                    ProcessRoad_UVs_ShoulderCut(ref RCS,false,i);
                    RCS.cut_tangents_SR.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[i], RCS.cut_normals_ShoulderR[i], RCS.cut_uv_SR[i], RCS.cut_ShoulderR_Vectors[i].ToArray()));
                    RCS.cut_tangents_SR_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderR[i], RCS.cut_normals_ShoulderR[i], RCS.cut_uv_SR_world[i], RCS.cut_ShoulderR_Vectors[i].ToArray()));
                }
                int lCount = RCS.cut_ShoulderL_Vectors.Count;
                for(int i=0;i<lCount;i++){
                    ProcessRoad_UVs_ShoulderCut(ref RCS,true,i);
                    RCS.cut_tangents_SL.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[i], RCS.cut_normals_ShoulderL[i], RCS.cut_uv_SL[i], RCS.cut_ShoulderL_Vectors[i].ToArray()));
                    RCS.cut_tangents_SL_world.Add(GSDRootUtil.ProcessTangents(RCS.cut_tris_ShoulderL[i], RCS.cut_normals_ShoulderL[i], RCS.cut_uv_SL_world[i], RCS.cut_ShoulderL_Vectors[i].ToArray()));
                }
            }
            if(RCS.bInterseOn){
                ProcessRoad_UVs_Intersections(ref RCS);
            }

            //						throw new System.Exception("FFFFFFFF");

            if(RCS.bRoadOn){
                if(!RCS.tMeshSkip){ RCS.tangents = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv, RCS.RoadVectors.ToArray()); }
                if(!RCS.tMeshSkip){ RCS.tangents2 = GSDRootUtil.ProcessTangents(RCS.tris, RCS.normals, RCS.uv2, RCS.RoadVectors.ToArray()); }
                if(!RCS.tMesh_SRSkip){ RCS.tangents_SR = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderR, RCS.normals_ShoulderR, RCS.uv_SR, RCS.ShoulderR_Vectors.ToArray()); }
                if(!RCS.tMesh_SLSkip){ RCS.tangents_SL = GSDRootUtil.ProcessTangents(RCS.tris_ShoulderL, RCS.normals_ShoulderL, RCS.uv_SL, RCS.ShoulderL_Vectors.ToArray()); }
                for(int i=0;i<RCS.tMesh_RoadConnections.Count;i++){
                    RCS.RoadConnections_tangents.Add(GSDRootUtil.ProcessTangents(RCS.RoadConnections_tris[i], RCS.RoadConnections_normals[i], RCS.RoadConnections_uv[i], RCS.RoadConnections_verts[i]));
                }
            }

            if(RCS.bInterseOn){
                //Back lanes:
                int vCount = RCS.iBLane0s.Count;
                for(int i=0;i<vCount;i++){
                 	RCS.iBLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane0s_tris[i],RCS.iBLane0s_normals[i],RCS.iBLane0s_uv[i],RCS.iBLane0s[i]));
                }
                vCount = RCS.iBLane1s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iBLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane1s_tris[i],RCS.iBLane1s_normals[i],RCS.iBLane1s_uv[i],RCS.iBLane1s[i]));
                }
                vCount = RCS.iBLane2s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iBLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane2s_tris[i],RCS.iBLane2s_normals[i],RCS.iBLane2s_uv[i],RCS.iBLane2s[i]));
                }
                vCount = RCS.iBLane3s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iBLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBLane3s_tris[i],RCS.iBLane3s_normals[i],RCS.iBLane3s_uv[i],RCS.iBLane3s[i]));
                }
                //Front lanes:
                vCount = RCS.iFLane0s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFLane0s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane0s_tris[i],RCS.iFLane0s_normals[i],RCS.iFLane0s_uv[i],RCS.iFLane0s[i]));
                }
                vCount = RCS.iFLane1s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFLane1s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane1s_tris[i],RCS.iFLane1s_normals[i],RCS.iFLane1s_uv[i],RCS.iFLane1s[i]));
                }
                vCount = RCS.iFLane2s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFLane2s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane2s_tris[i],RCS.iFLane2s_normals[i],RCS.iFLane2s_uv[i],RCS.iFLane2s[i]));
                }
                vCount = RCS.iFLane3s.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFLane3s_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFLane3s_tris[i],RCS.iFLane3s_normals[i],RCS.iFLane3s_uv[i],RCS.iFLane3s[i]));
                }
                //Main plates:
                vCount = RCS.iBMainPlates.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iBMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[i],RCS.iBMainPlates_normals[i],RCS.iBMainPlates_uv[i],RCS.iBMainPlates[i]));
                }
                vCount = RCS.iBMainPlates.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iBMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iBMainPlates_tris[i],RCS.iBMainPlates_normals[i],RCS.iBMainPlates_uv2[i],RCS.iBMainPlates[i]));
                }
                vCount = RCS.iFMainPlates.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFMainPlates_tangents.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[i],RCS.iFMainPlates_normals[i],RCS.iFMainPlates_uv[i],RCS.iFMainPlates[i]));
                }
                vCount = RCS.iFMainPlates.Count;
                for(int i=0;i<vCount;i++){
                    RCS.iFMainPlates_tangents2.Add(GSDRootUtil.ProcessTangents(RCS.iFMainPlates_tris[i],RCS.iFMainPlates_normals[i],RCS.iFMainPlates_uv2[i],RCS.iFMainPlates[i]));
                }
            }
        }
Ejemplo n.º 27
0
        private static void ProcessRoad_UVs_RoadCuts(ref GSD.Roads.RoadConstructorBufferMaker RCS)
        {
            //Finally, adding texture coordinates to the mesh will enable it to display a material correctly.
            //Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture.
            //int MVL = tMesh.vertices.Length;

            int cCount = RCS.cut_RoadVectors.Count;
            float tDistance= 0f;
            float tDistanceLeft = 0f;
            float tDistanceRight = 0f;
            float tDistanceLeftSum = 0f;
            float tDistanceRightSum = 0f;
            float tDistanceSum = 0f;
            for(int j=0;j<cCount;j++){
                Vector3[] tVerts = RCS.cut_RoadVectors[j].ToArray();
                int MVL = tVerts.Length;
                Vector2[] uv = new Vector2[MVL];
                Vector2[] uv_world = new Vector2[MVL];
                int i=0;
                bool bOddToggle = true;
                while(i+6 < MVL){
                    tDistance = Vector3.Distance(tVerts[i],tVerts[i+4]);
                    tDistance = tDistance / 5f;
                    uv[i] = new Vector2(0f, tDistanceSum);
                    uv[i+2] = new Vector2(1f, tDistanceSum);
                    uv[i+4] = new Vector2(0f, tDistance+tDistanceSum);
                    uv[i+6] = new Vector2(1f, tDistance+tDistanceSum);

                    //Last segment needs adjusted due to double vertices:
                    if((i+7) == MVL){
                        if(bOddToggle){
                            //First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                            uv[MVL-3] = uv[i+4];
                            uv[MVL-1] = uv[i+6];
                        }else{
                            //Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                            uv[MVL-4] = uv[i+4];
                            uv[MVL-2] = uv[i+6];
                        }
                    }

                    if(bOddToggle){
                        i+=5;
                    }else{
                        i+=3;
                    }

                    tDistanceLeftSum+=tDistanceLeft;
                    tDistanceRightSum+=tDistanceRight;
                    tDistanceSum+=tDistance;
                    bOddToggle = !bOddToggle;
                }
                for(i=0;i<MVL;i++){
                    uv_world[i] = new Vector2(tVerts[i].x*0.2f,tVerts[i].z*0.2f);
                }
                RCS.cut_uv_world.Add(uv_world);
                RCS.cut_uv.Add(uv);
            }
        }
Ejemplo n.º 28
0
        private static void ProcessRoad_UVs_ShoulderCut(ref GSD.Roads.RoadConstructorBufferMaker RCS, bool bIsLeft, int j)
        {
            int i=0;
            Vector3[] tVerts;
            if(bIsLeft){
                tVerts = RCS.cut_ShoulderL_Vectors[j].ToArray();
            }else{
                tVerts = RCS.cut_ShoulderR_Vectors[j].ToArray();
            }
            int MVL = tVerts.Length;

            //World:
            Vector2[] uv_world = new Vector2[MVL];
            for(i=0;i<MVL;i++){
                uv_world[i] = new Vector2(tVerts[i].x*0.2f,tVerts[i].z*0.2f);
            }
            if(bIsLeft){
                RCS.cut_uv_SL_world.Add(uv_world);
            }else{
                RCS.cut_uv_SR_world.Add(uv_world);
            }

            //Marks:
            float tDistance= 0f;
            float tDistanceSum = 0f;
            Vector2[] uv = new Vector2[MVL];
            float rDistance1 = 0f;
            float rDistance2 = 0f;
            bool bOddToggle = true;
            float fDistance = Vector3.Distance(tVerts[0],tVerts[2]);
            float xDistance = 0f;
            i=0;
            float TheOne = RCS.tRoad.opt_ShoulderWidth /  RCS.tRoad.opt_RoadDefinition;
            while(i+8 < MVL){
                tDistance = Vector3.Distance(tVerts[i],tVerts[i+8]) * 0.2f;

                uv[i] = new Vector2(0f, tDistanceSum);
                uv[i+2] = new Vector2(TheOne, tDistanceSum);
                uv[i+8] = new Vector2(0f, tDistance+tDistanceSum);
                uv[i+10] = new Vector2(TheOne, tDistance+tDistanceSum);

                rDistance1 = (Vector3.Distance(tVerts[i+4],tVerts[i+6]));
                rDistance2 = (Vector3.Distance(tVerts[i+12],tVerts[i+14]));

                if(!bIsLeft){
                    //Right
                    //8	   10   12   14
                    //0		2	 4	  6
                    //0f   1f	1f	  X

                    xDistance = TheOne + (rDistance1 / fDistance);
                    uv[i+4] = uv[i+2];
                    uv[i+6] = new Vector2(xDistance, tDistanceSum);

                    xDistance = TheOne + (rDistance2 / fDistance);
                    uv[i+12] = uv[i+10];
                    uv[i+14] = new Vector2(xDistance, tDistance+tDistanceSum);
                }else{
                    //Left:
                    //12,13	   14,15    8,9    10,11
                    //4,5		6,7		0,1		2,3
                    //0f-X	     0f	 	 0f		1f

                    xDistance = 0f - (rDistance1 / fDistance);
                    uv[i+4] = new Vector2(xDistance, tDistanceSum);
                    uv[i+6] = uv[i];
                    xDistance = 0f - (rDistance2 / fDistance);
                    uv[i+12] = new Vector2(xDistance, tDistance+tDistanceSum);
                    uv[i+14] = uv[i+8];
                }

                //Last segment needs adjusted due to double vertices:
                if((i+11) == MVL){
                    if(bOddToggle){
                        //First set: Debug.Log ("+5:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-3] = uv[i+4];
                        uv[MVL-1] = uv[i+6];
                    }else{
                        //Last set: Debug.Log ("+3:"+i+" "+(i+2)+" "+(i+4)+" "+(i+6));
                        uv[MVL-4] = uv[i+4];
                        uv[MVL-2] = uv[i+6];
                    }
                }

                if(bOddToggle){
                    i+=9;
                }else{
                    i+=7;
                }

                tDistanceSum+=tDistance;
                bOddToggle = !bOddToggle;
            }

            if(bIsLeft){
                RCS.cut_uv_SL.Add(uv);
            }else{
                RCS.cut_uv_SR.Add(uv);
            }
        }
Ejemplo n.º 29
0
	private void ExtrudeHelper(string tPath, string tName, float DefaultHoriz, GSD.Roads.Splination.AxisTypeEnum tAxis = GSD.Roads.Splination.AxisTypeEnum.Z, bool bHorizOverride = false, float tHorizSep = 0f, bool bVertOverride = false, float tVertRaise = 0f, bool bFlipRot = false){
		SMM = tNode.AddSplinatedObject();
		SMM.CurrentSplination = (GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath(tPath, typeof(GameObject));
		
		if(bHorizOverride){
			SMM.HorizontalSep = tHorizSep;
		}else{
			SMM.HorizontalSep = ((tNode.GSDSpline.tRoad.RoadWidth()/2) + tNode.GSDSpline.tRoad.opt_ShoulderWidth)*-1f;
		}
		
		if(bVertOverride){
			SMM.VerticalRaise = tVertRaise;
		}else{
			if(tNode.bIsBridgeStart){ SMM.VerticalRaise = -0.01f; }
		}
		
		SMM.bFlipRotation = bFlipRot;
		SMM.Axis = tAxis;
		if(SMM.StartTime < tNode.MinSplination){ SMM.StartTime = tNode.MinSplination; }
		if(SMM.EndTime > tNode.MaxSplination){ SMM.EndTime = tNode.MaxSplination; }
		SMM.tName = tName;
	}