Assets/Examples/Scripts/Chunk.cs
/// <summary>
/// Initializes the chunk and starts generating the mesh.
/// </summary>
/// <param name="chunkSize">The chunk's size. This represents the width, height and depth in Unity units.</param>
/// <param name="isolevel">The density level where a surface will be created. Densities below this will be inside the surface (solid), and densities above this will be outside the surface (air)</param>
/// <param name="coordinate">The chunk's coordinate</param>
Initializes the chunk and starts generating the mesh.
Initializes the chunk and starts generating the mesh .
public void Initialize(int chunkSize, float isolevel, int3 coordinate)
        {
            _isolevel = isolevel;
            Coordinate = coordinate;
            ChunkSize = chunkSize;
            transform.position = coordinate.ToVectorInt() * ChunkSize;
            name = $"Chunk_{coordinate.x}_{coordinate.y}_{coordinate.z}";
            Densities = new NativeArray<float>((ChunkSize + 1) * (ChunkSize + 1) * (ChunkSize + 1), Allocator.Persistent);
            _outputVertices = new NativeArray<Vector3>(15 * ChunkSize * ChunkSize * ChunkSize, Allocator.Persistent);
            _outputTriangles = new NativeArray<int>(15 * ChunkSize * ChunkSize * ChunkSize, Allocator.Persistent);
            StartDensityCalculation();
            StartMeshGeneration();
        }
public void Initialize ( int chunkSize , float isolevel , int3 coordinate ) { _isolevel = isolevel ; Coordinate = coordinate ; ChunkSize = chunkSize ; transform . position = coordinate . ToVectorInt ( ) * ChunkSize ; name = $" Chunk_ { coordinate . x } _ { coordinate . y } _ { coordinate . z } " ; Densities = new NativeArray < float > ( ( ChunkSize + 1 ) * ( ChunkSize + 1 ) * ( ChunkSize + 1 ) , Allocator . Persistent ) ; _outputVertices = new NativeArray < Vector3 > ( 15 * ChunkSize * ChunkSize * ChunkSize , Allocator . Persistent ) ; _outputTriangles = new NativeArray < int > ( 15 * ChunkSize * ChunkSize * ChunkSize , Allocator . Persistent ) ; StartDensityCalculation ( ) ; StartMeshGeneration ( ) ; }
Initializes the chunk and starts generating the mesh.
Initializes the chunk and starts generating the mesh .
chunkSize
int
The chunk's size. This represents the width, height and depth in Unity units.
The chunk ' s size . This represents the width height and depth in Unity units .
isolevel
float
The density level where a surface will be created. Densities below this will be inside the surface (solid), and densities above this will be outside the surface (air)
The density level where a surface will be created . Densities below this will be inside the surface ( solid ) and densities above this will be outside the surface ( air )
coordinate
int3
The chunk's coordinate
The chunk ' s coordinate