Ejemplo n.º 1
0
		public GameObject GenerateMapChunk(Vector3 position, MapParameters mapParameters, float[,] noiseMap)
		{
			var heightMap = Noise.SimplifyNoiseMap(noiseMap, mapParameters.textureResolutionFactor);

			var meshData = MeshGenerator.GenerateMeshData(heightMap, mapParameters);
			var mesh = meshData.CreateMesh();
			mesh.name = "Map Mesh";

			GameObject meshGameObject;
			if (mapParameters.useMeshColor)
			{
				var simplification = mapParameters.levelOfDetail == 0 ? 1 : mapParameters.levelOfDetail * 2;
				var simpleHeightMap = Noise.SimplifyNoiseMap(heightMap, simplification);
				mesh.colors = GenerateMeshColorMap(simpleHeightMap);
				meshGameObject = MeshGenerator.CreateMeshGameObject(mesh, null, null);
			}
			else
			{
				var texture2D = GenerateTexture(noiseMap);
				texture2D.filterMode = FilterMode.Point;
				if (mapParameters.useNormalMap)
				{
					Texture2D normalMap = TextureGenerator.NormalMap(texture2D, mapParameters.normalMapStrength);
					meshGameObject = MeshGenerator.CreateMeshGameObject(mesh, texture2D, normalMap);
				}
				else
					meshGameObject = MeshGenerator.CreateMeshGameObject(mesh, texture2D, null);
			}

			meshGameObject.transform.position = position * mapParameters.mapScale;
			return meshGameObject;
		}
Ejemplo n.º 2
0
		public void OnNoiseMapGenerated(float[,] fullHeightMap)
		{
			_textureHeightMap = fullHeightMap;
			_textureMapSize = _textureHeightMap.GetLength(0);

			for (int y = 0; y < _textureMapSize; y++)
			for (int x = 0; x < _textureMapSize; x++)
			{
				var curveX = _fullMapParameters.heightCurveX.Evaluate((float) x / _textureMapSize);
				var curveY = _fullMapParameters.heightCurveY.Evaluate((float) y / _textureMapSize);

				_textureHeightMap[x, y] = Mathf.Clamp01(_textureHeightMap[x, y] * curveX * curveY);
				_textureHeightMap[x, y] = Mathf.Clamp01(_mapParameters.heightCurve.Evaluate(_textureHeightMap[x, y]));
			}

			_fullHeightMap = Noise.SimplifyNoiseMap(_textureHeightMap, _mapParameters.textureResolutionFactor);

			if (Application.isEditor)
				EditorCoroutine.Start(GenerateFullMesh());
			else
				StartCoroutine(GenerateFullMesh());
			
			ProgressBarAddAction(10);//50
		}