To create a map, provide the X Y and Z size of the map. The max size is currently `2048x2048x2048` but will likely be increased in a future version. ```cs var map = new AudioMap(32, 96, 64); ``` You can add and remove voxels of different materials using the following functions: ```cs map.AddVoxel(0, 0, 0, AudioVoxelType.Metal); map.RemoveVoxel(0, 0, 0); ``` > [[AudioVoxelType]] contains the full material list You can also query if voxels exist, or get the voxel data directly: ```cs if (m.IsVoxel(0, 0, 0)) { ... } if (m.NoVoxel(0, 0, 0)) { ... } // Voxel memory is unmanaged AudioVoxel* voxel = m.GetVoxel(0, 0, 0); var type = (AudioVoxelType)voxel->type; voxel->type = (byte)AudioVoxelType.Dirt; ``` ## Resizing You can safely increase the size of the map while the raytracing thread is running, but if you try to reduce the size of the map, it'll throw an exception if the raytracing thread is running. ```cs var map = new AudioMap(32, 32, 32); map.Resize(128, 64, 128); // Start raytracing context.Update(); // Must first stop raytracing context.FinishThreadsSafely(); // Then reduce the map size map.Resize(32, 32, 32); ``` To dispose a map, you must also ensure the raytracing thread isn't running by calling `context.FinishThreadsSafely()` before `map.Dispose()`. ## Chunk Storage Voxels are stored in chunks of `32x32x32` voxels. Empty chunks remain unallocated to save memory. `AddVoxel()` will allocate the chunk for you, and check if the xyz coordinates are within the map's range. This is handy, but also slow. For reading from chunk data, use the `GetChunkOrEmpty` function. This will return either: - An existing chunk - A chunk that's full of voxels, if the position is outside the map - An empty chunk, if the chunk isn't allocated. This ensures that you won't get access violations from reading data from null chunks ```cs AudioChunk* chunk = map.GetChunkOrEmpty(0, 0, 0); AudioVoxel* firstVoxel = chunk->voxels; ``` To modify chunk data, use the `InitChunk` function. This will allocate the chunk if it's empty: ```cs AudioChunk* chunk = map.InitChunk(0, 0, 0); AudioVoxel* firstVoxel = chunk->voxels; firstVoxel->type = (byte)AudioVoxelType.Concrete; ``` Read more about chunk data in the [[AudioChunk]] class file. ## Methods ```cs // Returns true if a voxel is out of bounds bool OutOfBounds(int x, int y, int z); ```