void RefreshTextures() { requestRefresh = false; proposedMaxX = Mathf.Max(proposedMinX + 1, proposedMaxX); proposedMaxZ = Mathf.Max(proposedMinZ + 1, proposedMaxZ); proposedSliceZ = Mathf.Clamp(proposedSliceZ, proposedMinZ, proposedMaxZ); minX = proposedMinX; maxX = proposedMaxX; minZ = proposedMinZ; maxZ = proposedMaxZ; sliceZ = proposedSliceZ; if (tg == null || tg != world.terrainGenerator) { tg = world.terrainGenerator; if (tg == null) { return; } } if (!tg.isInitialized) { tg.Initialize(); } RefreshTerrainTexture(); RefreshMoistureTexture(); RefreshBiomeTexture(); }
/// <summary> /// Gets heightmap info for 16x16 positions in a chunk /// </summary> /// <returns>The height map info.</returns> /// <param name="x">The x coordinate of the left-most position of the chunk.</param> /// <param name="z">The z coordinate of the back-most position of the chunk.</param> /// <param name="heightChunkData">An array of HeightMapInfo structs to be filled with data. The size of the array must be 16*16.</param> public void GetHeightMapInfoFast(float x, float z, HeightMapInfo[] heightChunkData) { int ix = FastMath.FloorToInt(x); int iz = FastMath.FloorToInt(z); VoxelPlayTerrainGenerator tg = world.terrainGenerator; HeightMapInfo[] heights; int heightsIndex; for (int zz = 0; zz < 16; zz++) { for (int xx = 0; xx < 16; xx++) { if (!heightMapCache.TryGetValue(ix + xx, iz + zz, out heights, out heightsIndex)) { float altitude, moisture; tg.GetHeightAndMoisture(ix + xx, iz + zz, out altitude, out moisture); if (altitude > 1f) { altitude = 1f; } else if (altitude < 0f) { altitude = 0f; } if (moisture > 1f) { moisture = 1f; } else if (moisture < 0f) { moisture = 0f; } int biomeIndex = (int)(altitude * 20) * 21 + (int)(moisture * 20f); heights [heightsIndex].groundLevel = (int)(altitude * tg.maxHeight); heights [heightsIndex].moisture = moisture; heights [heightsIndex].biome = biomeLookUp [biomeIndex]; } heightChunkData [zz * 16 + xx] = heights [heightsIndex]; } } }
/// <summary> /// Gets heightmap info on a given position. This method only works at runtime. Use GetTerainInfo() in Editor. /// </summary> /// <returns>The height map info.</returns> /// <param name="x">The x coordinate.</param> /// <param name="z">The z coordinate.</param> public HeightMapInfo GetHeightMapInfoFast(float x, float z) { int ix = FastMath.FloorToInt(x); int iz = FastMath.FloorToInt(z); HeightMapInfo[] heights; int heightsIndex; if (!heightMapCache.TryGetValue(ix, iz, out heights, out heightsIndex)) { float altitude, moisture; VoxelPlayTerrainGenerator tg = world.terrainGenerator; tg.GetHeightAndMoisture(x, z, out altitude, out moisture); if (altitude > 1f) { altitude = 1f; } else if (altitude < 0f) { altitude = 0f; } if (moisture > 1f) { moisture = 1f; } else if (moisture < 0f) { moisture = 0f; } int biomeIndex = (int)(altitude * 20) * 21 + (int)(moisture * 20f); heights [heightsIndex].groundLevel = (int)(altitude * tg.maxHeight); heights [heightsIndex].moisture = moisture; heights [heightsIndex].biome = biomeLookUp [biomeIndex]; } return(heights [heightsIndex]); }