Model Definition Structure

advanced scripting

Voxel 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 surface
  • ModelBit[] bits - Array of ModelBit values containing the actual voxel definitions, indices, and colors
  • TorchBit[] torches - Array with optional torches included with the model

Properties

  • Vector3 size - Size as Vector3
  • Vector3 offset - Offset as Vector3
  • Bounds 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 + x
  • isEmpty - Prevents terrain generator from filling building interiors with terrain voxels
  • rotation - 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 property
  • GetPropertyString(string name) / GetPropertyFloat(string name) - Get a custom property

Methods

  • static ModelDefinition Create(int sizeX, int sizeY, int sizeZ) - Create an empty model
  • static ModelDefinition Create(int sizeX, int sizeY, int sizeZ, List<VoxelDefinition> voxelDefinitions) - Create from voxel definitions
  • static ModelDefinition Create(int sizeX, int sizeY, int sizeZ, List<Voxel> voxels) - Create from voxels
  • static ModelDefinition Create(int sizeX, int sizeY, int sizeZ, VoxelDefinition vd, List<Color> colors) - Create from colors
  • void SetBits(ModelBit[] bits) - Set bits array and compute bounds/colors
  • int GetVoxelIndex(int x, int y, int z) - Get linear voxel index from coordinates
  • void 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?