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

    Optimized geometry for static voxel maps using greedy meshing. More...

    Import Statement: import Clayground.Canvas3D

    Properties

    Methods

    Detailed Description

    VoxelMapGeometry generates efficient mesh geometry for voxel-based 3D structures. It uses a greedy meshing algorithm to combine adjacent voxels of the same color into larger quads, significantly reducing vertex count for large voxel maps.

    This geometry is used internally by StaticVoxelMap and is ideal for voxel structures that don't change frequently.

    Example usage:

    import QtQuick3D
    import Clayground.Canvas3D
    
    Model {
        geometry: VoxelMapGeometry {
            voxelCountX: 10
            voxelCountY: 10
            voxelCountZ: 10
            voxelSize: 1.0
        }
        materials: CustomMaterial { }
    }

    See also StaticVoxelMap and VoxelMapInstancing.

    Property Documentation

    spacing : real

    Gap between adjacent voxels in world units.

    Defaults to 0.0 for solid voxel structures.


    vertexCount : int [read-only]

    The current number of vertices in the generated geometry.

    Useful for monitoring mesh complexity after greedy meshing optimization.


    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 geometry regeneration after batch voxel operations.

    Call this once after multiple setVoxel or fill operations to update the mesh efficiently.


    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.

    Creates a rectangular region starting at (cx, cy, cz) with the specified dimensions. Colors are distributed according to colorDistribution weights.


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

    Fills a cylindrical region with voxels.

    Creates a cylinder with center base at (cx, cy, cz), radius r, and specified height. Colors are distributed according to colorDistribution weights.


    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. The colorDistribution parameter specifies colors and their weights. The noiseFactor adds randomness to the sphere surface.


    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().