/// <summary> /// Starts a mesh generation job /// </summary> /// <param name="voxelDataStore">The store where to retrieve the voxel data from</param> /// <param name="chunkCoordinate">The coordinate of the chunk that will be generated</param> /// <returns>The job handle and the actual mesh generation job</returns> public override JobHandleWithData <IMesherJob> CreateMesh(VoxelDataStore voxelDataStore, int3 chunkCoordinate) { if (!voxelDataStore.TryGetVoxelDataChunk(chunkCoordinate, out VoxelDataVolume boundsVoxelData)) { return(null); } NativeCounter vertexCountCounter = new NativeCounter(Allocator.TempJob); int voxelCount = (boundsVoxelData.Width - 1) * (boundsVoxelData.Height - 1) * (boundsVoxelData.Depth - 1); int maxLength = 15 * voxelCount; NativeArray <MeshingVertexData> outputVertices = new NativeArray <MeshingVertexData>(maxLength, Allocator.TempJob); NativeArray <ushort> outputTriangles = new NativeArray <ushort>(maxLength, Allocator.TempJob); MarchingCubesJob marchingCubesJob = new MarchingCubesJob { VoxelData = boundsVoxelData, Isolevel = Isolevel, VertexCountCounter = vertexCountCounter, OutputVertices = outputVertices, OutputTriangles = outputTriangles }; JobHandle jobHandle = marchingCubesJob.Schedule(voxelCount, 128); JobHandleWithData <IMesherJob> jobHandleWithData = new JobHandleWithData <IMesherJob>(); jobHandleWithData.JobHandle = jobHandle; jobHandleWithData.JobData = marchingCubesJob; return(jobHandleWithData); }
/// <inheritdoc/> public override JobHandleWithData <IMesherJob> CreateMesh(VoxelDataStore voxelDataStore, VoxelColorStore voxelColorStore, int3 chunkCoordinate) { if (!voxelDataStore.TryGetDataChunk(chunkCoordinate, out VoxelDataVolume <byte> boundsVoxelData)) { return(null); } if (!voxelColorStore.TryGetDataChunk(chunkCoordinate, out VoxelDataVolume <Color32> boundsVoxelColors)) { return(null); } NativeCounter vertexCountCounter = new NativeCounter(Allocator.TempJob); int voxelCount = VoxelWorld.WorldSettings.ChunkSize.x * VoxelWorld.WorldSettings.ChunkSize.y * VoxelWorld.WorldSettings.ChunkSize.z; int maxLength = 15 * voxelCount; NativeArray <MeshingVertexData> outputVertices = new NativeArray <MeshingVertexData>(maxLength, Allocator.TempJob); NativeArray <ushort> outputTriangles = new NativeArray <ushort>(maxLength, Allocator.TempJob); MarchingCubesJob marchingCubesJob = new MarchingCubesJob { VoxelData = boundsVoxelData, VoxelColors = boundsVoxelColors, Isolevel = Isolevel, VertexCountCounter = vertexCountCounter, OutputVertices = outputVertices, OutputTriangles = outputTriangles }; JobHandle jobHandle = marchingCubesJob.Schedule(); JobHandleWithData <IMesherJob> jobHandleWithData = new JobHandleWithData <IMesherJob> { JobHandle = jobHandle, JobData = marchingCubesJob }; return(jobHandleWithData); }