← Back to Docs
  • index.html
  • Clayground
  • Clayground.Canvas3D
  • VoxelMapInstancing
  • Clayground 2025.2
  • VoxelMapInstancing QML Type

    GPU instancing for dynamic voxel maps with per-voxel colors. More...

    Import Statement: import Clayground.Canvas3D

    Properties

    Methods

    Detailed Description

    VoxelMapInstancing provides efficient rendering of voxel maps using GPU instancing. Each non-transparent voxel is rendered as an instance of a base geometry, with per-instance color and position data.

    This is ideal for voxel maps that change frequently, as updating individual voxels doesn't require regenerating the entire mesh.

    This instancing is used internally by DynamicVoxelMap.

    Example usage:

    import QtQuick3D
    import Clayground.Canvas3D
    
    Model {
        geometry: Box3DGeometry { size: Qt.vector3d(1, 1, 1) }
        instancing: VoxelMapInstancing {
            voxelCountX: 10
            voxelCountY: 10
            voxelCountZ: 10
            voxelSize: 1.0
        }
        materials: CustomMaterial { }
    }

    See also DynamicVoxelMap and VoxelMapGeometry.

    Property Documentation

    spacing : real

    Gap between adjacent voxels in world units.

    Defaults to 0.0 for solid voxel structures.


    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.


    voxelSize : real

    Size of each voxel cube in world units.

    Defaults to 1.0.


    Method Documentation

    void commit()

    Triggers instance buffer update after batch voxel operations.

    Call this once after multiple setVoxel or fill operations.


    void fillBox(int cx, int cy, int cz, int width, int height, int depth, list colorDistribution, real noiseFactor)

    Fills a box-shaped region with voxels.


    void fillCylinder(int cx, int cy, int cz, int r, int height, list colorDistribution, real noiseFactor)

    Fills a cylindrical region with voxels.


    void fillSphere(int cx, int cy, int cz, int r, list colorDistribution, real noiseFactor)

    Fills a spherical region with voxels.

    Creates a sphere centered at (cx, cy, cz) with radius r.


    bool loadFromFile(string path)

    Loads a voxel map from a text file.

    Returns true if the load was successful.


    bool saveToFile(string path)

    Saves the voxel map to a text file.

    Returns true if the save was successful.


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

    Sets the color of the voxel at the specified coordinates.

    Setting a voxel to transparent removes it from the map.

    See also voxel().


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

    Returns the color of the voxel at the specified coordinates.

    Returns transparent if the coordinates are out of bounds or the voxel is empty.

    See also setVoxel().