public void SetNeighbors(DynamicTerrainChunk left, DynamicTerrainChunk top, DynamicTerrainChunk right, DynamicTerrainChunk bottom) { // TODO: Fix the seams between chunks Terrain t = GetComponent <Terrain>(); Terrain leftTerrain = left == null ? null : left.terrain; Terrain topTerrain = top == null ? null : top.terrain; Terrain rightTerrain = right == null ? null : right.terrain; Terrain bottomTerrain = bottom == null ? null : bottom.terrain; // Hint to the terrain engine about how to improve LOD calculations t.SetNeighbors(leftTerrain, topTerrain, rightTerrain, bottomTerrain); t.Flush(); }
void RebuildChunks() { // This function (at first) will tell each chunk // who its neighbours are. // Loop through all of our existing chunks. for (int x = 0; x < numCols; x++) { for (int y = 0; y < numRows; y++) { DynamicTerrainChunk left = (x > 0) ? terrainChunks[x - 1, y] : null; DynamicTerrainChunk bottom = (y > 0) ? terrainChunks[x, y - 1] : null; DynamicTerrainChunk right = (x < numCols - 1) ? terrainChunks[x + 1, y] : null; DynamicTerrainChunk top = (y < numRows - 1) ? terrainChunks[x, y + 1] : null; terrainChunks[x, y].SetNeighbors( left, top, right, bottom ); } } }
DynamicTerrainChunk BuildChunk(Quaternion rotation, Vector3 position) { GameObject go = new GameObject(); go.transform.position = position; go.name = rotation.eulerAngles.ToString(); //position.ToString(); DynamicTerrainChunk dtc = go.AddComponent <DynamicTerrainChunk>(); dtc.HeightMapTexture = this.HeightMapTexture; dtc.StructureMapTexture = this.StructureMapTexture; dtc.Splats = this.Splats; dtc.ChunkRotation = rotation; dtc.DegreesPerChunk = DegreesPerChunk; dtc.WorldUnitsPerChunk = WorldUnitsPerChunk; dtc.StructureColors = StructureColors; dtc.BuildTerrain(); return(dtc); }
void BuildChunkArray() { if (terrainChunks[1, 1] == null) { Debug.LogError("No middle chunk!"); return; } for (int x = 0; x < numCols; x++) { for (int y = 0; y < numRows; y++) { if (terrainChunks[x, y] == null) { float xDir = x - 1; float yDir = y - 1; // Build the missing chunk DynamicTerrainChunk root = terrainChunks[1, 1]; Quaternion rotation = root.ChunkRotation; rotation *= Quaternion.Euler( DegreesPerChunk * yDir, DegreesPerChunk * xDir, 0 ); Vector3 position = root.transform.position; position += new Vector3( WorldUnitsPerChunk * xDir, 0, WorldUnitsPerChunk * yDir ); terrainChunks[x, y] = BuildChunk(rotation, position); } } } }