Assets/Scripts/MarchingCubesJob.cs
/// <summary>
/// The execute method required by the Unity Job System's IJobParallelFor
/// </summary>
/// <param name="index">The iteration index</param>
The execute method required by the Unity Job System's IJobParallelFor
The execute method required by the Unity Job System ' s IJobParallelFor
public void Execute(int index)
        {
            int3 voxelLocalPosition = new int3(
                index / (chunkSize * chunkSize),
                index / chunkSize % chunkSize,
                index % chunkSize);
            VoxelCorners<float> densities = GetDensities(voxelLocalPosition);
            int cubeIndex = CalculateCubeIndex(densities, isolevel);
            if (cubeIndex == 0 || cubeIndex == 255)
            {
                return;
            }
            VoxelCorners<int3> corners = GetCorners(voxelLocalPosition);
            int edgeIndex = LookupTables.EdgeTable[cubeIndex];
            VertexList vertexList = GenerateVertexList(densities, corners, edgeIndex, isolevel);
            int rowIndex = 15 * cubeIndex;
            for (int i = 0; LookupTables.TriangleTable[rowIndex+i] != -1 && i < 15; i += 3)
            {
                int triangleIndex = counter.Increment() * 3;
                vertices[triangleIndex + 0] = vertexList[LookupTables.TriangleTable[rowIndex + i + 0]];
                triangles[triangleIndex + 0] = triangleIndex + 0;
                vertices[triangleIndex + 1] = vertexList[LookupTables.TriangleTable[rowIndex + i + 1]];
                triangles[triangleIndex + 1] = triangleIndex + 1;
                vertices[triangleIndex + 2] = vertexList[LookupTables.TriangleTable[rowIndex + i + 2]];
                triangles[triangleIndex + 2] = triangleIndex + 2;
            }
        }
public void Execute ( int index ) { int3 voxelLocalPosition = new int3 ( index / ( chunkSize * chunkSize ) , index / chunkSize % chunkSize , index % chunkSize ) ; VoxelCorners < float > densities = GetDensities ( voxelLocalPosition ) ; int cubeIndex = CalculateCubeIndex ( densities , isolevel ) ; if ( cubeIndex == 0 || cubeIndex == 255 ) { return ; } VoxelCorners < int3 > corners = GetCorners ( voxelLocalPosition ) ; int edgeIndex = LookupTables . EdgeTable [ cubeIndex ] ; VertexList vertexList = GenerateVertexList ( densities , corners , edgeIndex , isolevel ) ; int rowIndex = 15 * cubeIndex ; for ( int i = 0 ; LookupTables . TriangleTable [ rowIndex + i ] != - 1 && i < 15 ; i += 3 ) { int triangleIndex = counter . Increment ( ) * 3 ; vertices [ triangleIndex + 0 ] = vertexList [ LookupTables . TriangleTable [ rowIndex + i + 0 ] ] ; triangles [ triangleIndex + 0 ] = triangleIndex + 0 ; vertices [ triangleIndex + 1 ] = vertexList [ LookupTables . TriangleTable [ rowIndex + i + 1 ] ] ; triangles [ triangleIndex + 1 ] = triangleIndex + 1 ; vertices [ triangleIndex + 2 ] = vertexList [ LookupTables . TriangleTable [ rowIndex + i + 2 ] ] ; triangles [ triangleIndex + 2 ] = triangleIndex + 2 ; } }
The execute method required by the Unity Job System's IJobParallelFor
The execute method required by the Unity Job System ' s IJobParallelFor
// Voxel's position inside the chunk. Goes from (0, 0, 0) to (chunkSize-1, chunkSize-1, chunkSize-1) // Index at the beginning of the row
index
int
The iteration index
The iteration index