/// <summary>
 /// Starts a mesh generation job
 /// </summary>
 /// <param name="voxelDataStore">The store where to retrieve the voxel data from</param>
 /// <param name="voxelColorStore">The store where to retrieve the voxels' color 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 abstract JobHandleWithData <IMesherJob> CreateMesh(VoxelDataStore voxelDataStore, VoxelColorStore voxelColorStore, int3 chunkCoordinate);
Exemple #2
0
        /// <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);
        }