// Alloc data for chunkJob and schedule it public JobHandle GenerateMeshData() { _meshData = new GenerateMeshData.MeshData { vertices = new NativeList <int3>(Allocator.Persistent), triangles = new NativeList <int>(Allocator.Persistent), uvs = new NativeList <Vector2>(Allocator.Persistent) }; _chunkJob = new GenerateMeshData { meshData = _meshData, chunkData = new GenerateMeshData.ChunkData { blocks = _chunkData.blocks }, blockData = new GenerateMeshData.BlockData { vertices = BlockData.Vertices, triangles = BlockData.Triangles, uvs = BlockData.UVs } }; JobHandle _jobHandle = _chunkJob.Schedule(); return(_jobHandle); }
override protected JobHandle StartGeneration(JobHandle dependOn) { var gridCells = new NativeList <GridCell>(Allocator.TempJob); AddTemp(gridCells); var borderIndices = new NativeList <int>(2 * resolution * dataExtents.XZ, Allocator.TempJob); AddTemp(borderIndices); var tempRowBuffer = new NativeArray <int>(dataExtents.X, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); AddTemp(tempRowBuffer); var generateGroundGridCells = new GenerateMeshGridCells { resolution = resolution, volumeExtent = dataExtents, data = data.Data, filledValue = filledValue, cells = gridCells, bottomRowBuffer = tempRowBuffer, borderIndices = borderIndices, bufferLengths = meshArrayLengths }; dependOn = generateGroundGridCells.Schedule(dependOn); dependOn.Complete(); int vertexLength = meshArrayLengths[VertexLengthIndex]; int triLength = meshArrayLengths[TriangleLengthIndex]; meshData = new MeshData(vertexLength, triLength, Allocator.TempJob, MeshDataBufferFlags); AddTemp(meshData); var generateMeshData = new GenerateMeshData { // cell properties cellResolution = resolution, cellSize = cellSize, stepX = cellSize.x / resolution, stepZ = cellSize.z / resolution, stepU = 1f / resolution, stepV = 1f / resolution, stepTriangle = resolution * resolution * 2 * 3, // mods uvScale = (uvMode == UVMode.Normalized) ? new float2(1f / data.XLength, 1f / data.ZLength) : new float2(1, 1), positionOffset = positionOffset, // input data volumeExtent = dataExtents, cells = gridCells, borderIndices = borderIndices, // output data meshVertices = meshData.Vertices, meshUVs = meshData.UVs, meshTriangles = meshData.Triangles }; dependOn = generateMeshData.Schedule(gridCells.Length, 64, dependOn); if (HeightMap != null) { bool normalizedUV = uvMode == UVMode.Normalized; float uScale = normalizedUV ? 1f : 1f / data.XLength; float vScale = normalizedUV ? 1f : 1f / data.ZLength; dependOn = HeightMap.StartGeneration(meshData, uScale, vScale, resolution, dataExtents, gridCells, borderIndices, dependOn); } return(dependOn); }