public void SampleHeight() { for (int i = 0; i < g_customData.heightSamplerList.Count; i++) { HeightSampleData data = g_customData.heightSamplerList[i]; if (data.type == 0) { EPMPreDefinedTools.SampleHeightByPoint(m_terrain, data.number, data.radiusRange, data.curveMode, data.combineMode, (float)data.limitation); } else if (data.type == 1) { EPMPreDefinedTools.SampleHeightByLine(m_terrain, data.number, data.radiusRange, data.curveMode, data.combineMode, (float)data.limitation); } List <EPMPoint> plist = m_terrain.ExtractPoints_All(); for (int j = 0; j < plist.Count; j++) { plist[j].ApplyHeight(data.heightRange); } } }
public void RenderSingleGround(List <Vector2d> ground, EPMPoint.PointType type) { int groundEnums = EPMPoint.GetGroundEnums(); List <EPMPoint> plist = m_terrain.ExtractPoints_ByRegion(ground, null, groundEnums); for (int i = 0; i < plist.Count; i++) { plist[i].SetType(type); } List <EPMTriangle> triangleList = m_terrain.ExtractTriangles_ByVertex(plist); for (int i = 0; i < triangleList.Count; i++) { if (!triangleList[i].HasShapeType(groundEnums)) { continue; } triangleList[i].TryDetermineType(); } EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.GetGroundEnums(), EPMPoint.GenerateTypesInt(false, type), type); }
public GameObject CreateTerrain() { Init(); if (m_meshRoot == null) { m_meshRoot = new GameObject(); m_meshRoot.transform.SetParent(null); } m_meshRoot.name = g_customData.terrainName; m_terrain.InitGenerating(g_customData.terrainName, g_customData.seed, new Vector2d(0, 0), new Vector2d(g_customData.terrainWidth, g_customData.terrainLength), g_customData.islandLists); float time = Time.realtimeSinceStartup; //First, Generate Basic Terrain, If the map has island, surround the world with ocean. if (g_customData.islandLists.Count > 0) { m_terrain.GeneratingBase(g_customData.terrainWidth * g_customData.terrainLength / 50, EPMPoint.PointType.Ocean); } else { m_terrain.GeneratingBase(g_customData.terrainWidth * g_customData.terrainLength / 50, EPMPoint.PointType.Ground); } for (int i = 0; i < g_customData.islandLists.Count; i++) { GeneratingSingleIsland(g_customData.islandLists[i]); } SetIslandGround(); for (int i = 0; i < g_customData.hillLists.Count; i++) { GenerateSingleHill(g_customData.hillLists[i]); } for (int i = 0; i < g_customData.roadLists.Count; i++) { GenerateSingleRoad(g_customData.roadLists[i]); } for (int i = 0; i < g_customData.riverLists.Count; i++) { GenerateSingleRiver(g_customData.riverLists[i]); } for (int i = 0; i < g_customData.mountainLists.Count; i++) { GenerateSingleMountain(g_customData.mountainLists[i]); } Debug.Log("Initial Points Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; m_terrain.StartGenerating(); Debug.Log("Generating Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; //If two island intersect, remove the coastline where they intersect.The oceanSide tiles are tiles share at least one point with ocean tiles. EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.PointType.OceanSide, EPMPoint.PointType.Ocean, EPMPoint.PointType.OceanSide, EPMPoint.PointType.Ground, 1, false, true); //The coastline is the Ground tile and has at least one shared point with oceanSide tiles. EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.PointType.Ground, EPMPoint.PointType.OceanSide, EPMPoint.PointType.OceanSide, EPMPoint.PointType.Ground, 1, false, true); //Then check any abnormal ocean points, All the points belongs to Ocean tile must be Ocean points. The CheckAndSetTileTypeByNeighbor I use to solve the problem is overfitting, but it is convenient.... EPMPreDefinedTools.CheckAndSetTileTypeByNeighbor(m_terrain, EPMPoint.PointType.Ocean, EPMPoint.PointType.OceanSide, EPMPoint.PointType.Ocean, EPMPoint.PointType.Ocean, 1, false, true); EPMPreDefinedTools.ExtractSide(m_terrain, EPMPoint.PointType.Road, EPMPoint.PointType.RoadSide, m_roadHalfWidth * 0.5); EPMPreDefinedTools.ExtractCenter(m_terrain, g_customData.roadLists, EPMPoint.PointType.RoadSide, EPMPoint.PointType.Road, m_roadHalfWidth * 0.3); EPMPreDefinedTools.ExtractCenter(m_terrain, g_customData.riverLists, EPMPoint.PointType.RiverSide, EPMPoint.PointType.River, m_riverHalfWidth * 0.3); Debug.Log("Extracting Side Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; RenderRiver(); SmoothRiver(); RenderHill(); RenderMountain(); Debug.Log("Rendering Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; for (int i = 0; i < g_customData.sandGroundLists.Count; i++) { RenderSingleGround(g_customData.sandGroundLists[i], EPMPoint.PointType.Sand); } for (int i = 0; i < g_customData.soilGroundLists.Count; i++) { RenderSingleGround(g_customData.soilGroundLists[i], EPMPoint.PointType.Soil); } SampleHeight(); Debug.Log("SampleHeight Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; TwistTerrain(); RenderOcean(); Debug.Log("TwistTerrain Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; CreateMesh(); Debug.Log("CreateMesh Used:" + (Time.realtimeSinceStartup - time).ToString()); time = Time.realtimeSinceStartup; return(m_meshRoot); }