private IEnumerator SetMesh() { var mapParameters = _mapGenerator.parameters; mapParameters.noisePosition = new Vector2(transform.position.x, transform.position.z); var noiseGen = new ThreadedNoise {parameters = mapParameters}; noiseGen.Start(); yield return StartCoroutine(noiseGen.WaitFor()); var noiseMap = noiseGen.retNoiseMap; var mapMeshData = new MapMeshData(noiseMap, _mapGenerator.parameters.baseHeight, _mapGenerator.parameters.heightCurve, _mapGenerator.parameters.levelOfDetail); var generator = new ThreatedMeshGenerator {mapMeshData = mapMeshData}; generator.Start(); yield return StartCoroutine(generator.WaitFor()); var meshData = generator.meshData; var mesh = meshData.CreateMesh(); mesh.name = "Map Mesh"; _meshFilter.mesh = mesh; var meshBounds = mesh.bounds; var center = transform.position + new Vector3(_mapGenerator.parameters.size / 2, 0, _mapGenerator.parameters.size / 2); bounds = new Bounds(center, meshBounds.size); isMeshReady = true; }
private IEnumerator SetTexture() { var mapParameters = _mapGenerator.parameters; mapParameters.noisePosition = new Vector2(transform.position.x, transform.position.z); var noiseGen = new ThreadedNoise { parameters = mapParameters, isTexture = true }; noiseGen.Start(); yield return StartCoroutine(noiseGen.WaitFor()); var noiseMap = noiseGen.retNoiseMap; var textureParameters = new TextureParameters(noiseMap, _mapGenerator.parameters); var generator = new ThreadedTextureGenerator {parameters = textureParameters}; generator.Start(); yield return StartCoroutine(generator.WaitFor()); var colorMap = generator.colorMap; var textureSize = noiseMap.GetLength(0); var texture2D = new Texture2D(textureSize, textureSize); texture2D.SetPixels(colorMap); texture2D.filterMode = FilterMode.Point; texture2D.Apply(); var material = new Material(Shader.Find("Standard")) { mainTexture = texture2D, name = "Map Material" }; // Texture normalMap = TextureGenerator.NormalMap(texture2D, 0.5f); // material.SetTexture("_BumpMap", normalMap); _meshRenderer.material = material; isTextureReady = true; }
//Todo: Gerar o noiseMap somente para os valores utilizados private IEnumerator SetCollider() { var mapParameters = _mapGenerator.parameters; mapParameters.noisePosition = new Vector2(transform.position.x, transform.position.z); mapParameters.levelOfDetail = 6; var noiseGen = new ThreadedNoise {parameters = mapParameters}; noiseGen.Start(); yield return StartCoroutine(noiseGen.WaitFor()); var noiseMap = noiseGen.retNoiseMap; var mapMeshData = new MapMeshData(noiseMap, _mapGenerator.parameters.baseHeight, _mapGenerator.parameters.heightCurve, _mapGenerator.parameters.levelOfDetail); var generator = new ThreatedMeshGenerator {mapMeshData = mapMeshData}; generator.Start(); yield return StartCoroutine(generator.WaitFor()); var meshData = generator.meshData; var mesh = meshData.CreateMesh(); mesh.name = "Collider Mesh"; _meshCollider.sharedMesh = mesh; _meshCollider.material = _mapGenerator.defaultPhysicMaterial; isColliderReady = true; }