// Internal void GenerateChunkData(Vector2 inOffset, Chunk inChunk) { NoiseGenerator.Result noiseResult = _noiseGenerator.Generate(_parameters, inOffset); JobSystem.instance.DoThreaded(() => _meshGenerator.Generate(noiseResult), (o) => OnMeshDataRecieved(o, inChunk)); }
public Result Generate(NoiseGenerator.Result inHeightData) { Result result = new Result(); result.triangles = _triangles; // Generate vertices result.vertices = new Vector3[_vertexCount]; int vertexID = 0; for (int y = 0; y < _size; y++) { for (int x = 0; x < _size; x++) { result.vertices[vertexID].x = x; result.vertices[vertexID].y = inHeightData.heightMap[x, y] * 100; result.vertices[vertexID].z = y; result.vertices[vertexID + 1].x = x + 1; result.vertices[vertexID + 1].y = inHeightData.heightMap[x + 1, y] * 100; result.vertices[vertexID + 1].z = y; result.vertices[vertexID + _vertexSize].x = x; result.vertices[vertexID + _vertexSize].y = inHeightData.heightMap[x, y + 1] * 100; result.vertices[vertexID + _vertexSize].z = y + 1; result.vertices[vertexID + _vertexSize + 1].x = x + 1; result.vertices[vertexID + _vertexSize + 1].y = inHeightData.heightMap[x + 1, y + 1] * 100; result.vertices[vertexID + _vertexSize + 1].z = y + 1; vertexID += 2; } vertexID += _vertexSize; } // Generate UV2 (This is temporary) result.uv = new Vector2[_vertexCount]; result.uv2 = new Vector2[_vertexCount]; vertexID = 0; for (int y = 0; y < _size; y++) { for (int x = 0; x < _size; x++) { if (inHeightData.heightMap[x, y] < 0.8f) { int textureID = 2; result.uv2[vertexID] = new Vector2(textureID, textureID); result.uv2[vertexID + 1] = new Vector2(textureID, textureID); result.uv2[vertexID + _vertexSize] = new Vector2(textureID, textureID); result.uv2[vertexID + _vertexSize + 1] = new Vector2(textureID, textureID); } else { int textureID = 1; result.uv2[vertexID] = new Vector2(textureID, textureID + 1); result.uv2[vertexID + 1] = new Vector2(textureID, textureID + 1); result.uv2[vertexID + _vertexSize] = new Vector2(textureID, textureID + 1); result.uv2[vertexID + _vertexSize + 1] = new Vector2(textureID, textureID + 1); } vertexID += 2; } vertexID += _vertexSize; } return(result); }