← Back to Docs
  • index.html
  • Clayground
  • Clayground.Canvas3D
  • VoxelMap
  • Clayground 2026.7
  • VoxelMap QML Type

    Base type for voxel-based 3D structures. More...

    Import Statement: import Clayground.Canvas3D
    Inherited By:

    DynamicVoxelMap and StaticVoxelMap

    Properties

    Methods

    Detailed Description

    VoxelMap is the abstract base type for StaticVoxelMap and DynamicVoxelMap. It provides common properties and methods for working with voxel grids, including edge rendering, toon shading, and shape filling operations.

    Use StaticVoxelMap for large, unchanging voxel structures, or DynamicVoxelMap for voxels that change frequently.

    See also StaticVoxelMap and DynamicVoxelMap.

    Property Documentation

    autoCommit : bool

    Whether to automatically commit changes.

    Defaults to true.


    depth : real [read-only]

    Total depth of the voxel map in world units.


    edgeColor : color

    The edge color, as an absolute color rather than a factor.

    Wins over edgeColorFactor as soon as it has a visible alpha, which is what counts as set here - a fully transparent edge has no meaning, so it serves as the unset sentinel and leaves opaque black reachable.

    StaticVoxelMap {
        edgeColor: "#2f3437"    // dark grey borders, whatever the voxel
    }

    edgeColorFactor : real

    Darkening factor for edges.

    Defaults to 1.0. Ignored once edgeColor is set.


    edgeThickness : real

    Thickness of grid edge lines, in pixels.

    Screen-space, so an edge keeps its weight as the camera moves, and the same unit Box3D::edgeThickness uses: a cell border comes out this many pixels wide, half on either side of the border.

    Defaults to 1.0, a one pixel hairline.


    height : real [read-only]

    Total height of the voxel map in world units.


    model : var

    The underlying voxel data model.


    showEdges : bool

    Whether to render voxel grid lines.

    Defaults to true.


    spacing : real

    Gap between adjacent voxels in world units.

    Defaults to 0.0 for solid voxel structures.


    useToonShading : bool

    Enables cartoon-style rendering.

    Creates a Minecraft-like aesthetic with distinct light/shadow boundaries. Works best with strong directional light shadows.


    voxelCountX : int

    Number of voxels along the X axis.


    voxelCountY : int

    Number of voxels along the Y axis (height).


    voxelCountZ : int

    Number of voxels along the Z axis.


    voxelOffset : vector3d

    Offset applied to voxel edge calculations.


    voxelSize : real

    Size of each voxel cube in world units.

    Defaults to 1.0.


    width : real [read-only]

    Total width of the voxel map in world units.

    Computed as: voxelCountX * (voxelSize + spacing) - spacing


    Method Documentation

    void fill(var shapes)

    Fills the voxel map with shapes.

    Accepts a single shape or an array of shapes. Each shape can be specified as an object or array with type and parameters.

    Supported shapes: "sphere", "cylinder", "box"

    A colour may be written as a string or as a color value - a bound property, a Qt.rgba(), anything - and both forms accept the same spellings of colors:

    Example:

    fill([
        { sphere: { pos: Qt.vector3d(5,5,5), radius: 3, colors: ["red"] } },
        ["box", [0, 0, 0, 10, 1, 10, "green"]]
    ])

    color get(int x, int y, int z)

    Returns the color of the voxel at the specified coordinates.


    void load(string path)

    Loads voxel data from a file.


    void save(string path)

    Saves voxel data to a file.


    void set(int x, int y, int z, color color)

    Sets the color of the voxel at the specified coordinates.