To convert a 3D model to voxels, use the `AddModel` function on your [[AudioMap]].
```cs
var map = new AudioMap(32, 32, 32);
var cube = new VoxelisedCube(new Int3(4, 4, 4), new Int3(12, 16, 20));
map.AddModel(cube);
```
The model will be converted to voxels on a background thread.
There are many kinds of objects that can be voxelised, including:
- [[VoxelisedCube]] for simple 3D boxes
- [[VoxelisedPrism]] for rotated 3D boxes
- [[VoxelisedMesh]] for triangulated meshes
You can also provide your own class that derives from the [[VoxelisedModel]] class.
The properties of each object can be modified at any time. Their voxels will be updated on background threads the next time raytracing occurs.
```cs
var cube = new VoxelisedCube(...);
map.AddModel(cube);
cube.position = new Int3(2, 7, 1);
cube.size = new Int3(17, 14, 19);
```
Models can be disabled or removed completely:
```cs
var cube = new VoxelisedCube(...);
map.AddModel(cube);
// Disable it
cube.enabled = false;
// Completely remove it
map.RemoveModel(cube);
```
## Voxelisation Process
For efficiency, models are voxelised to their own [[AudioChunk]]s first, and then copied to your main [[AudioMap]]. This prevents the need to re-voxelise a model when another overlapping model is rotated.
## Overlapping Models
When multiple models overlap, models that were added later will overwrite the voxels of models that were added earlier.
Models will only be re-voxelised when they are moved/scaled/rotated. When this happens, the SDK will:
- Remove the voxels from the chunks that this model touched last time
- Remove the voxels from the chunks that we are about to copy to
- Re-voxelise all dirty models
- Copy voxels from all models that touch these affected chunks
## Custom Classes
To voxelise models yourself, create a class that derives from [[VoxelisedModel]].
This class must override the `Voxelise` function:
```cs
public class CustomModel : VoxelisedModel
{
public override void Voxelise()
{
// Get min and max world coordinates
Int3 min = ...;
Int3 max = ...;
// Allocate voxel chunks for this model
AllocateChunks(min, max);
// Add voxels in world space
AddVoxel(123, 74, 612, AudioVoxelType.Cloth);
}
}
```
To determine if this model needs to be re-voxelised, set the `voxelsDirty` flag to true. Other classes like [[VoxelisedMesh]] do this like using get/set accessors:
```cs
public unsafe class VoxelisedMesh : VoxelisedModel
{
Matrix4F _transform;
public Matrix4F transform
{
get
{
return _transform;
}
set
{
if (_transform != value)
voxelsDirty = true;
_transform = value;
}
}
}
```