FVoxelGrid
A solid as a grid of voxels for destruction: voxelized from a mesh or a primitive, carved by spheres, split into what still stands and what fell off, and meshed as its exposed faces.
- Module
- Destruction
- Header
#include "Destruction/VoxelGrid.h"- Namespace
Mowo
Public functions
| Returns | Name | Description |
|---|---|---|
bool | Init | |
FVoxelGrid | FromTriangles | A closed triangle mesh (local space): every voxel whose centre is inside (parity along +X) or whose box a triangle passes through. |
FVoxelGrid | FromBox | |
FVoxelGrid | FromSphere | |
bool | IsValid | |
uint32_t | SizeX | |
uint32_t | SizeY | |
uint32_t | SizeZ | |
float | CellSize | |
const Vec3& | Origin | |
uint32_t | Index | |
bool | Get | |
bool | GetIndex | |
void | Set | |
void | Coordinates | |
Vec3 | VoxelCenter | |
uint32_t | SolidCount | |
uint32_t | Carve | Removes the solid voxels whose centres lie within the sphere (local space); their indices go to removed. |
std::vector<FVoxelIsland> | DetachIslands | Whatever no longer connects (face to face) to the anchor — the floor layer, or with no floor anchor the largest piece — leaves the grid as islands, largest first. |
std::vector<FVoxelIsland> | Chunk | Splits loose voxels into chunks of chunk voxels a side: the rubble a carve throws out. |
TerrainChunkMesh | BuildMesh | The exposed faces of every solid voxel (or of an island's voxels alone). |
TerrainChunkMesh | BuildIslandMesh |
Function details
Init
bool Init(const Vec3& origin, float cellSize, uint32_t nx, uint32_t ny, uint32_t nz)FromTriangles
static FVoxelGrid FromTriangles(const std::vector<Vec3>& vertices, const std::vector<uint32_t>& indices, float cellSize, uint32_t maxDim = 256)A closed triangle mesh (local space): every voxel whose centre is inside (parity along +X) or whose box a triangle passes through.
FromBox
static FVoxelGrid FromBox(const Vec3& halfExtents, float cellSize)FromSphere
static FVoxelGrid FromSphere(float radius, float cellSize)IsValid
bool IsValid() constSizeX
uint32_t SizeX() constSizeY
uint32_t SizeY() constSizeZ
uint32_t SizeZ() constCellSize
float CellSize() constOrigin
const Vec3& Origin() constIndex
uint32_t Index(uint32_t x, uint32_t y, uint32_t z) constGet
bool Get(uint32_t x, uint32_t y, uint32_t z) constGetIndex
bool GetIndex(uint32_t index) constSet
void Set(uint32_t x, uint32_t y, uint32_t z, bool solid)Coordinates
void Coordinates(uint32_t index, uint32_t& x, uint32_t& y, uint32_t& z) constVoxelCenter
Vec3 VoxelCenter(uint32_t index) constSolidCount
uint32_t SolidCount() constCarve
uint32_t Carve(const Vec3& center, float radius, std::vector<uint32_t>* removed = nullptr)Removes the solid voxels whose centres lie within the sphere (local space); their indices go to removed. Returns how many.
DetachIslands
std::vector<FVoxelIsland> DetachIslands(bool anchorFloor)Whatever no longer connects (face to face) to the anchor — the floor layer, or with no floor anchor the largest piece — leaves the grid as islands, largest first.
Chunk
std::vector<FVoxelIsland> Chunk(const std::vector<uint32_t>& voxels, uint32_t chunk) constSplits loose voxels into chunks of chunk voxels a side: the rubble a carve throws out.
BuildMesh
TerrainChunkMesh BuildMesh(const Vec4& color) constThe exposed faces of every solid voxel (or of an island's voxels alone).
BuildIslandMesh
TerrainChunkMesh BuildIslandMesh(const FVoxelIsland& island, const Vec3& pivot, const Vec4& color) const