ezEngine Release 26.9
Loading...
Searching...
No Matches
ezVoxelGrid Class Reference

#include <VoxelGrid.h>

Public Member Functions

void Initialize (const ezVec3U32 &vDimensions, const ezVec3 &vCenter, float fVoxelSize)
 
void ClearData ()
 Clears all voxel data (sets everything to free). Keeps allocated memory.
 
EZ_FORCE_INLINE ezVec3I32 WorldToCoord (const ezVec3 &vWorldPos) const
 Converts a world-space position to integer voxel coordinates.
 
EZ_FORCE_INLINE ezVec3 CoordToWorld (const ezVec3I32 &vCoord) const
 Converts integer voxel coordinates to the world-space center of that voxel.
 
EZ_FORCE_INLINE bool IsCoordValid (const ezVec3I32 &vCoord) const
 Returns true if the coordinate is inside the grid bounds.
 
void SetVoxel (const ezVec3I32 &vCoord, bool bSolid)
 Sets a voxel to occupied (true) or free (false).
 
bool IsVoxelSet (const ezVec3I32 &vCoord) const
 Returns whether the voxel at the given coordinate is occupied.
 
void SetVoxelsOnTriangle (const ezVec3 &v0, const ezVec3 &v1, const ezVec3 &v2, bool bSet=true)
 
bool CheckLineOfSight (const ezVec3I32 &vStart, const ezVec3I32 &vGoal) const
 
ezBoundingBox GetAABB () const
 Returns the world-space AABB of the entire grid.
 
ezUInt64 GetHeapMemoryUsage () const
 Returns the approximate memory usage in bytes.
 
void DebugDraw (const ezDebugRendererContext &context, const ezColor &color) const
 Draws a debug visualization of occupied surface voxels.
 
ezVec3U32 GetDimensions () const
 
float GetVoxelSize () const
 
const ezVec3GetOrigin () const
 
const ezVec3GetCenter () const
 

Detailed Description

Stores a 3D voxel grid using packed 4x4x4 bit blocks.

Each block is stored as a single ezUInt64 (64 bits = 4*4*4 voxels). A set bit means the voxel is occupied (solid). A cleared bit means the voxel is free (passable).

The grid has a fixed resolution and is centered at a configurable world position. Use WorldToCoord / CoordToWorld to convert between world space and voxel coordinates. Use InjectBox / InjectSphere to mark voxels as occupied based on world-space shapes.

Member Function Documentation

◆ CheckLineOfSight()

bool ezVoxelGrid::CheckLineOfSight ( const ezVec3I32 vStart,
const ezVec3I32 vGoal 
) const

Ray-march visibility test between two grid-space coordinates.

Returns true if no occupied voxel blocks the line of sight.

◆ Initialize()

void ezVoxelGrid::Initialize ( const ezVec3U32 vDimensions,
const ezVec3 vCenter,
float  fVoxelSize 
)

Initializes the grid with the given resolution (in voxels).

Each dimension is rounded up to a multiple of 4 internally. The grid is cleared to all-free after init.

◆ SetVoxelsOnTriangle()

void ezVoxelGrid::SetVoxelsOnTriangle ( const ezVec3 v0,
const ezVec3 v1,
const ezVec3 v2,
bool  bSet = true 
)

Rasterizes a world-space triangle into the grid, setting (or clearing) every voxel it overlaps.

Cost scales with the triangle's voxel-space bounding box, so rasterizing geometry that is large relative to the voxel size is expensive. Parts of the triangle outside the grid are ignored.


The documentation for this class was generated from the following files: