public static Int3 AddInvertTileOffset3(Int3 start, Int3 h2offset) { return(start.Add(InvertTileOffset3(start, h2offset))); }
public void CheckNeighbor(Int3 coord) { if (ShouldBlendNeighbor(coord, coord.Add(-1, 0, 0))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y, dimension, dimension); var heights = new float[dimension, dimension]; float heightBase = coord.y * cellSize / data.size.y; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { float t_y = (float)j / dimension; float h0_y = Mathf.Lerp(old_heights[0, i], old_heights[dimension - 1, i], t_y); heights[j, i] = Mathf.Min(old_heights[j, i], (h0_y - heightBase) * falloff.Evaluate(t_y) + heightBase); } } data.SetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y, heights); } if (ShouldBlendNeighbor(coord, coord.Add(1, 0, 0))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y, dimension, dimension); var heights = new float[dimension, dimension]; float heightBase = coord.y * cellSize / data.size.y; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { float t_y = (float)j / dimension; float h0_y = Mathf.Lerp(old_heights[0, i], old_heights[dimension - 1, i], t_y); heights[j, i] = Mathf.Min(old_heights[j, i], (h0_y - heightBase) * falloff.Evaluate(t_y) + heightBase); } } data.SetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y, heights); } if (ShouldBlendNeighbor(coord, coord.Add(0, 0, -1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x, heightMapCoord.y - dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; float heightBase = coord.y * cellSize / data.size.y; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { float t_x = (float)i / dimension; float h0_x = Mathf.Lerp(old_heights[j, 0], old_heights[j, dimension - 1], t_x); heights[j, i] = Mathf.Min(old_heights[j, i], (h0_x - heightBase) * falloff.Evaluate(t_x) + heightBase); } } data.SetHeights(heightMapCoord.x, heightMapCoord.y - dimension / 2, heights); } if (ShouldBlendNeighbor(coord, coord.Add(0, 0, 1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x, heightMapCoord.y + dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; float heightBase = coord.y * cellSize / data.size.y; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { float t_x = (float)i / dimension; float h0_x = Mathf.Lerp(old_heights[j, 0], old_heights[j, dimension - 1], t_x); heights[j, i] = Mathf.Min(old_heights[j, i], (h0_x - heightBase) * falloff.Evaluate(t_x) + heightBase); } } data.SetHeights(heightMapCoord.x, heightMapCoord.y + dimension / 2, heights); } // diagonal if (ShouldBlendNeighbor(coord, coord.Add(-1, 0, 0)) && ShouldBlendNeighbor(coord, coord.Add(0, 0, -1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y - dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { heights[j, i] = Mathf.Min(coord.y * cellSize / data.size.y, old_heights[j, i]); } } data.SetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y - dimension / 2, heights); } if (ShouldBlendNeighbor(coord, coord.Add(-1, 0, 0)) && ShouldBlendNeighbor(coord, coord.Add(0, 0, 1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y + dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { heights[j, i] = Mathf.Min(coord.y * cellSize / data.size.y, old_heights[j, i]); } } data.SetHeights(heightMapCoord.x - dimension / 2, heightMapCoord.y + dimension / 2, heights); } if (ShouldBlendNeighbor(coord, coord.Add(1, 0, 0)) && ShouldBlendNeighbor(coord, coord.Add(0, 0, -1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y - dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { heights[j, i] = Mathf.Min(coord.y * cellSize / data.size.y, old_heights[j, i]); } } data.SetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y - dimension / 2, heights); } if (ShouldBlendNeighbor(coord, coord.Add(1, 0, 0)) && ShouldBlendNeighbor(coord, coord.Add(0, 0, 1))) { var heightMapCoord = GetHeightMapCoord(coord); var dimension = heightMapCoord.z; var old_heights = data.GetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y + dimension / 2, dimension, dimension); var heights = new float[dimension, dimension]; for (int i = 0; i < dimension; i++) { for (int j = 0; j < dimension; j++) { heights[j, i] = Mathf.Min(coord.y * cellSize / data.size.y, old_heights[j, i]); } } data.SetHeights(heightMapCoord.x + dimension / 2, heightMapCoord.y + dimension / 2, heights); } }