public static ITestInput CreateTestInput(GameObject go, IInlet <MatrixWorld> inlet, MatrixWorld matrix) { Terrain terrain = CreateTerrain(go); int terrainRes = Mathf.NextPowerOfTwo(matrix.rect.size.x - 1) + 1; float resFactor = 1f * terrainRes / matrix.rect.size.x; terrain.terrainData.heightmapResolution = terrainRes; float[,] arr2D = new float[terrainRes, terrainRes]; matrix.ExportHeights(arr2D); terrain.terrainData.SetHeights(0, 0, arr2D); terrain.transform.position = matrix.worldPos; terrain.terrainData.size = new Vector3(matrix.worldSize.x * resFactor, matrix.worldSize.y, matrix.worldSize.z * resFactor); //since terrainRes is usually about 2 times bigger TerrainInout terrIn = new TerrainInout() { terrain = terrain }; return(terrIn); }
public void Write(object result) { MatrixWorld matrix = (MatrixWorld)result; if (terrain == null) { return; } int terrainRes = Mathf.NextPowerOfTwo(matrix.rect.size.x - 1) + 1; float resFactor = 1f * terrainRes / matrix.rect.size.x; if (terrain.terrainData.heightmapResolution != terrainRes) { terrain.terrainData.heightmapResolution = terrainRes; } terrain.transform.position = matrix.worldPos; terrain.terrainData.size = new Vector3(matrix.worldSize.x * resFactor, matrix.worldSize.y, matrix.worldSize.z * resFactor); //since terrainRes is usually about 2 times bigger float[,] arr2D = new float[terrainRes, terrainRes]; matrix.ExportHeights(arr2D); terrain.terrainData.SetHeights(0, 0, arr2D); }