Toast Engine
Loading...
Searching...
No Matches
voxel_edit.hpp File Reference

Functions that allow the editing of Voxel Volumes. More...

#include "stamp.hpp"
#include "voxel_volume.hpp"
#include <array>
#include <cstdint>
#include <glm/glm.hpp>
#include <optional>
#include <span>
#include <toast/export.hpp>
#include <vector>
Include dependency graph for voxel_edit.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  voxel::EditBounds
struct  voxel::EditResult
struct  voxel::WriteBrush
struct  voxel::Region
struct  voxel::TileOptions
struct  voxel::VolumeHit

Enumerations

enum class  voxel::WriteMode : uint8_t { replace , empty_only , solid_only , match }
 Which voxels we should override. More...
enum class  TileFit : uint8_t { crop , stretch , center }
enum class  TileAnchor : uint8_t { min , center , max }

Functions

constexpr auto voxel::canWrite (uint8_t current, WriteMode mode, uint8_t match_id) noexcept -> bool
constexpr auto voxel::canAdd (uint8_t id, WriteMode mode, uint8_t match_id) noexcept -> bool
auto voxel::boxBounds (glm::ivec3 a, glm::ivec3 b) noexcept -> EditBounds
auto voxel::sphereBounds (glm::vec3 center, float radius) noexcept -> EditBounds
auto voxel::segmentBounds (glm::vec3 a, glm::vec3 b, float radius) noexcept -> EditBounds
auto voxel::placedBounds (glm::uvec3 piece_brick_dims, const LatticePlacement &placement) noexcept -> EditBounds
auto voxel::boundsUnion (const EditBounds &a, const EditBounds &b) noexcept -> EditBounds
auto voxel::occupiedBounds (const Volume &volume) -> std::optional< EditBounds >
auto voxel::fillBox (Volume &volume, glm::ivec3 a, glm::ivec3 b, const WriteBrush &brush) -> EditResult
auto voxel::fillSphere (Volume &volume, glm::vec3 center, float radius, const WriteBrush &brush) -> EditResult
auto voxel::fillCylinder (Volume &volume, glm::vec3 a, glm::vec3 b, float radius, const WriteBrush &brush) -> EditResult
auto voxel::fillCapsule (Volume &volume, glm::vec3 a, glm::vec3 b, float radius, const WriteBrush &brush) -> EditResult
auto voxel::replaceId (Volume &volume, uint8_t from, uint8_t to) -> EditResult
auto voxel::slice (Volume &volume, glm::vec3 point, glm::vec3 normal, int side) -> EditResult
auto voxel::collectFace (const Volume &volume, glm::ivec3 start, glm::ivec3 normal, size_t limit) -> std::vector< glm::ivec3 >
auto voxel::extrudeFace (Volume &volume, std::span< const glm::ivec3 > face, glm::ivec3 normal, int distance) -> EditResult
auto voxel::copyRegion (const Volume &volume, glm::ivec3 a, glm::ivec3 b) -> Region
auto voxel::pasteRegion (Volume &volume, const Region &region, glm::ivec3 at, WriteMode mode, uint8_t match_id) -> EditResult
auto voxel::stampVolume (Volume &target, const Volume &piece, const LatticePlacement &placement, const PaletteRemapTable &remap, WriteMode mode, uint8_t match_id) -> EditResult
auto voxel::carveVolume (Volume &target, const Volume &piece, const LatticePlacement &placement) -> EditResult
auto voxel::fillRoundBox (Volume &volume, glm::ivec3 a, glm::ivec3 b, float radius, const WriteBrush &brush) -> EditResult
auto voxel::fillEllipsoid (Volume &volume, glm::ivec3 a, glm::ivec3 b, const WriteBrush &brush) -> EditResult
auto voxel::clipByPlanes (Volume &volume, std::span< const glm::vec4 > planes) -> EditResult
auto voxel::complementPlane (glm::vec4 plane) noexcept -> glm::vec4
auto voxel::tileVolume (Volume &target, const Volume &pattern, glm::ivec3 a, glm::ivec3 b, const TileOptions &options, const PaletteRemapTable &remap, WriteMode mode, uint8_t match_id) -> EditResult
auto voxel::floodFill (Volume &volume, glm::ivec3 seed, uint8_t id) -> EditResult
auto voxel::raycast (const Volume &volume, glm::vec3 origin, glm::vec3 direction, float max_t) -> std::optional< VolumeHit >
auto voxel::idHistogram (const Volume &volume) -> std::array< uint32_t, k_palette_size >
auto voxel::snapOrientation (const glm::mat3 &rotation) noexcept -> LatticeOrientation
auto voxel::dominantAxis (glm::vec3 normal) noexcept -> glm::ivec3

Detailed Description

Functions that allow the editing of Voxel Volumes.

Author
Xein
Date
25 Sep 2026

Enumeration Type Documentation

◆ WriteMode

enum class voxel::WriteMode : uint8_t
strong

Which voxels we should override.

Note
On lua this is called VoxelWrite
Enumerator
replace 

Everything.

empty_only 

Only empty space.

solid_only 

Only non-empty space.

match 

Only voxels with the match id.

Function Documentation

◆ carveVolume()

TOAST_API auto voxel::carveVolume ( Volume & target,
const Volume & piece,
const LatticePlacement & placement ) -> EditResult

Empties every target voxel the piece has a solid voxel on

Note
The carve counterpart of stampVolume

◆ clipByPlanes()

TOAST_API auto voxel::clipByPlanes ( Volume & volume,
std::span< const glm::vec4 > planes ) -> EditResult

Empties every voxel that is on the wrong side of any plane

◆ collectFace()

TOAST_API auto voxel::collectFace ( const Volume & volume,
glm::ivec3 start,
glm::ivec3 normal,
size_t limit = size_t {1}<< 20 ) -> std::vector< glm::ivec3 >
nodiscard

Returns the voxels with the same normal

◆ complementPlane()

TOAST_API auto voxel::complementPlane ( glm::vec4 plane) -> glm::vec4
nodiscardnoexcept

The plane that keeps what plane drops

◆ extrudeFace()

TOAST_API auto voxel::extrudeFace ( Volume & volume,
std::span< const glm::ivec3 > face,
glm::ivec3 normal,
int distance ) -> EditResult

Pushes a face out along its normal, carves when negative distance

◆ fillEllipsoid()

TOAST_API auto voxel::fillEllipsoid ( Volume & volume,
glm::ivec3 a,
glm::ivec3 b,
const WriteBrush & brush ) -> EditResult

Fills the ellipsoid that touches every face of the box from a to b

◆ fillRoundBox()

TOAST_API auto voxel::fillRoundBox ( Volume & volume,
glm::ivec3 a,
glm::ivec3 b,
float radius,
const WriteBrush & brush ) -> EditResult

Fills the box from a to b with its edges rounded by radius

◆ floodFill()

TOAST_API auto voxel::floodFill ( Volume & volume,
glm::ivec3 seed,
uint8_t id ) -> EditResult

Repaints the solid voxels connected to seed that share its id

◆ idHistogram()

TOAST_API auto voxel::idHistogram ( const Volume & volume) -> std::array< uint32_t, k_palette_size >
nodiscard

How many voxels hold each palette id

◆ raycast()

TOAST_API auto voxel::raycast ( const Volume & volume,
glm::vec3 origin,
glm::vec3 direction,
float max_t ) -> std::optional< VolumeHit >
nodiscard

Walks a ray through the volume one voxel at a time

Parameters
originIn voxels, a voxel spans [v, v + 1]
Returns
the first solid voxel within max_t

◆ replaceId()

TOAST_API auto voxel::replaceId ( Volume & volume,
uint8_t from,
uint8_t to ) -> EditResult

Replaces all of the nodes of one ID to another

Parameters
fromTarget palette ID
toNew palette ID

◆ slice()

TOAST_API auto voxel::slice ( Volume & volume,
glm::vec3 point,
glm::vec3 normal,
int side ) -> EditResult

Cuts a volume by a plane

Parameters
pointPoint of the plane
normalNormal of the plane
side+1 (normal direction) or -1 (antinormal direction)

◆ tileVolume()

TOAST_API auto voxel::tileVolume ( Volume & target,
const Volume & pattern,
glm::ivec3 a,
glm::ivec3 b,
const TileOptions & options,
const PaletteRemapTable & remap,
WriteMode mode = WriteMode::replace,
uint8_t match_id = k_empty_palette_index ) -> EditResult

Repeats the solid part of pattern across the box from a to b

Parameters
remapMaps pattern ids to target ids and 0 skips the voxel