Model Definition Structure
advanced scriptingVoxel Play 3 · Scripting / API
Overview
A Model Definition is a scriptable object that contains a list of voxel definitions and colors that form a building, tree, or any other placeable structure.
Data Fields
int sizeX / sizeY / sizeZ- Size of the model in integer units (e.g. 30x50x40)int offsetX / offsetY / offsetZ- Optional location offset when the model is placed (default 0,0,0)float buildDuration- Duration of the build animation in seconds. Voxels will be placed iteratively for that duration. A value of 0 places the model instantly. Default is 3.bool exclusiveTree- If true, no other tree will be placed on the same chunk after this model. Useful for large trees or constructions you don't want partially overwritten.bool treeRandomRotation- Whether the tree rotates randomly when placed (default true)bool fitToTerrain- If true, the model base extends down filling any hole/gap until the terrain surfaceModelBit[] bits- Array of ModelBit values containing the actual voxel definitions, indices, and colorsTorchBit[] torches- Array with optional torches included with the model
Properties
Vector3 size- Size as Vector3Vector3 offset- Offset as Vector3Bounds bounds- Real boundary of visible voxels
ModelBit Structure
[Serializable]
public struct ModelBit {
public int voxelIndex;
public VoxelDefinition voxelDefinition;
public bool isEmpty;
public Color32 color;
public float rotation;
public MicroVoxels microVoxels;
public Color32 finalColor;
}
voxelIndex- Position calculated as:y * (sizeX * sizeZ) + z * sizeX + xisEmpty- Prevents terrain generator from filling building interiors with terrain voxelsrotation- Only accepts 0, 90, 180, or 270 degrees (applies to side textures only)finalColor- Computed color combining bit and voxel tint (read-only)
ModelBit also supports custom properties:
SetProperty(string name, string/float value)- Set a custom propertyGetPropertyString(string name)/GetPropertyFloat(string name)- Get a custom property
Methods
static ModelDefinition Create(int sizeX, int sizeY, int sizeZ)- Create an empty modelstatic ModelDefinition Create(int sizeX, int sizeY, int sizeZ, List<VoxelDefinition> voxelDefinitions)- Create from voxel definitionsstatic ModelDefinition Create(int sizeX, int sizeY, int sizeZ, List<Voxel> voxels)- Create from voxelsstatic ModelDefinition Create(int sizeX, int sizeY, int sizeZ, VoxelDefinition vd, List<Color> colors)- Create from colorsvoid SetBits(ModelBit[] bits)- Set bits array and compute bounds/colorsint GetVoxelIndex(int x, int y, int z)- Get linear voxel index from coordinatesvoid ComputeBounds()- Compute bounds of visible voxels
Notes
Use ModelFillInside(model) method to mark empty voxels inside buildings. Positions without ModelBit entries remain unaltered when placed in the world.
Was this page helpful?
Suggest an improvement
Help us improve this documentation page.