//------------------------------------------------------------------ private void CalculateCenterHeightmapColors2D() { _previewTextureUpdateInProgress = true; float x, y, z; Vector3 point; EasyTerrain.TerrainSample terrainSample; float nTiles = _nTiles; float tileSize = _tileSize; float tileMaxHeight = _tileMaxHeight; for (int i = 0; i < _previewTexturePixelSize; i++) { for (int j = 0; j < _previewTexturePixelSize; j++) { x = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f); y = 0f; z = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f); point = new Vector3(x, y, z); terrainSample = EasyTerrain.GetTerrainSample(point); terrainSample.height /= tileMaxHeight; _previewTextureColors[i, j] = new Color(terrainSample.height, terrainSample.height, terrainSample.height); } } _previewTextureUpdateInProgress = false; }
//------------------------------------------------------------------ private void CalculateCenterGrassmapColors2D() { _previewTextureUpdateInProgress = true; float x, y, z; Vector3 point; EasyTerrain.TerrainSample terrainSample; float nTiles = _nTiles; float tileSize = _tileSize; float tileMaxHeight = _tileMaxHeight; for (int i = 0; i < _previewTexturePixelSize; i++) { for (int j = 0; j < _previewTexturePixelSize; j++) { x = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f); y = 0f; z = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f); point = new Vector3(x, y, z); terrainSample = EasyTerrain.GetTerrainSample(point); terrainSample.height /= tileMaxHeight; _previewTextureColors[i, j] = Color.black; Color clr = Color.green; for (int index = 0; index < _splatmapPreviewBlendCurves.Length; index++) { if (_applyToSplatTexture[index]) { if (_splatmapPreviewBlendColors[index] != Color.white) { _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.height); } else { _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.steepness); } } } } } _previewTextureUpdateInProgress = false; }
//------------------------------------------------------------------ private void CalculateGameObjectsMapColors2D() { _previewTextureUpdateInProgress = true; float x, y, z; Vector3 point; EasyTerrain.TerrainSample terrainSample; float nTiles = _nTiles; float tileSize = _tileSize; float tileMaxHeight = _tileMaxHeight; for (int i = 0; i < _previewTexturePixelSize; i++) { for (int j = 0; j < _previewTexturePixelSize; j++) { x = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f); y = 0f; z = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f); point = new Vector3(x, y, z); terrainSample = EasyTerrain.GetTerrainSample(point); terrainSample.height /= tileMaxHeight; _previewTextureColors[i, j] = Color.black; float noiseValue; Color clr = Color.green; for (int index = 0; index < _splatmapPreviewBlendCurves.Length; index++) { if (_applyToSplatTexture[index]) { if (_splatmapPreviewBlendColors[index] != Color.white) { _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.height); } else { _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.steepness); } } } if (_useNoiseLayer) { point.x -= _noiseOffsetX; point.y = _noiseOffsetY; point.z -= _noiseOffsetZ; NoiseGenerator.NoiseSample noiseSample; noiseSample = NoiseGenerator.Sum( NoiseGenerator.methods[(int)NoiseGenerator.NoiseMethodType.Perlin3D], point, _noiseFrequency, 1, 1f, 1f); noiseValue = noiseSample.value; noiseValue = (noiseValue + 1f) * 0.5f; AnimationCurve animc = new AnimationCurve( new Keyframe(0f, 0f, 0f, 0f), new Keyframe(_threshold, 0f, 0f, 0f), new Keyframe(Mathf.Lerp(_threshold, 1f, _falloff), 1f, 0f, 0f), new Keyframe(1f, 1f, 0f, 0f)); _previewTextureColors[i, j] *= animc.Evaluate(noiseValue); } } } _previewTextureUpdateInProgress = false; }