Voxel Queries
advanced scriptingVoxel Play 3 · Scripting / API
VoxelPlayEnvironment. Access via VoxelPlayEnvironment.instance.
Basic Voxel Queries
Voxel GetVoxel(Vector3d position, bool createChunkIfNotExists = true, bool onlyRenderedVoxels = false)Returns the Voxel struct at the given world position.
- createChunkIfNotExists
- Create the chunk if it hasn't been generated yet.
- onlyRenderedVoxels
- Only return voxels from chunks that have been rendered.
bool IsVoxelAtPosition(Vector3d position)Returns true if a non-empty voxel exists at the given position.
bool IsEmptyAtPosition(Vector3d position)Returns true if the position contains no voxel (empty space).
bool IsWallAtPosition(Vector3d position)Returns true if a solid (opaque) block exists at the given position.
bool IsTerrainReadyAtPosition(Vector3d position, bool includeWater)Returns true if the terrain at the position has been rendered and has a collider ready.
Voxel Index Lookups
bool GetVoxelIndex(Vector3d position, out VoxelIndex index, bool createChunkIfNotExists = false)Gets the VoxelIndex struct for the voxel at the given position. Returns true if found.
void GetVoxelIndex(Vector3d position, out Vector3d chunkPosition, out int voxelIndex)Gets the chunk position and voxel array index for a world position.
bool GetVoxelIndex(Vector3d position, out VoxelChunk chunk, out int voxelIndex, bool createChunkIfNotExists = true)Gets the chunk and voxel index for a world position.
bool GetVoxelIndex(Vector3d position, out VoxelChunk chunk, out int px, out int py, out int pz, bool createChunkIfNotExists = true)Gets the chunk and local XYZ coordinates within the chunk.
bool GetVoxelIndex(ref VoxelIndex index, int offsetX, int offsetY, int offsetZ, out VoxelIndex otherIndex, bool createChunkIfNotExists = false)Gets a neighboring voxel index by applying an offset to an existing index. Handles chunk boundaries automatically.
int GetVoxelIndex(int px, int py, int pz)Calculates the flat array index from local chunk coordinates (0-15 for each axis).
bool GetVoxelIndex(VoxelChunk chunk, int voxelIndex, int offsetX, int offsetY, int offsetZ, out VoxelChunk otherChunk, out int otherVoxelIndex, bool createChunkIfNotExists = false)Gets a voxel in a neighboring chunk by offset. Handles cross-chunk boundary lookups.
Spatial Queries
int GetVoxelIndices(Vector3d boxMin, Vector3d boxMax, List<VoxelIndex> indices, byte minOpaque = 0, int hasContents = 1)Gets all voxel indices within an axis-aligned box volume. Returns the count.
- minOpaque
- Minimum opacity threshold (0 = include transparent).
- hasContents
- 1 = only non-empty voxels, 0 = only empty, -1 = all.
int GetVoxelIndices(Vector3d boxMin, Vector3d boxMax, List<VoxelIndex> indices, SDF sdf)Gets voxel indices within a box, further filtered by a Signed Distance Function. Useful for querying arbitrary shapes (spheres, capsules, custom volumes).
int GetVoxelIndices(Vector3d center, float radius, List<VoxelIndex> indices, byte minOpaque = 0, byte hasContents = 1)Gets all voxel indices within a sphere.
void GetVoxels(Vector3d boxMin, Vector3d boxMax, Voxel[,,] voxels)Copies voxels from a world volume into a 3D array. Useful for region capture or undo systems.
Neighborhood Queries
void GetVoxelNeighborhood(Vector3d position, ref VoxelIndex[] voxelIndices)Gets surrounding voxels (9 or 27 neighbors depending on array size). Pass a pre-allocated array of 9 (face neighbors) or 27 (all neighbors).
void GetVoxelNeighborhood(VoxelChunk chunk, int voxelIndex, ref VoxelIndex[] voxelIndices)Gets neighbors for a voxel referenced by chunk and index.
Position Calculations
Vector3d GetVoxelPosition(VoxelChunk chunk, int voxelIndex)Returns the world-space center position of a voxel.
Vector3d GetVoxelPosition(Vector3d position)Snaps a world position to the nearest voxel center.
Vector3 GetVoxelChunkPosition(int voxelIndex)Returns the local position of a voxel within its chunk (0-15 range per axis).
Vector3d GetVoxelPosition(Vector3d chunkPosition, int voxelIndex)Calculates world position from a chunk position and voxel index.
Vector3d GetVoxelPosition(Vector3d chunkPosition, int px, int py, int pz)Calculates world position from chunk position and local coordinates.
void GetVoxelChunkCoordinates(int voxelIndex, out int px, out int py, out int pz)Converts a flat array index to local XYZ coordinates within a chunk.
void GetVoxelChunkCoordinates(Vector3d position, out int px, out int py, out int pz)Converts a world position to local chunk coordinates.
Visibility Queries
bool GetVoxelVisibility(VoxelChunk chunk, int voxelIndex)Returns true if the voxel contributes to the rendered mesh (has at least one exposed face).
Voxel GetVoxelUnder(Vector3d position, bool includeWater = false, ColliderTypes colliderTypes = ColliderTypes.AnyCollider)Returns the first non-empty voxel below the given position. Useful for ground detection.
VoxelIndex GetVoxelUnderIndex(Vector3d position, bool includeWater = false, ColliderTypes colliderTypes = ColliderTypes.AnyCollider)Returns the index of the first non-empty voxel below the given position.
Voxel Definition Lookup
VoxelDefinition GetVoxelDefinition(string name)Returns the VoxelDefinition with the given name. Returns null if not found.
VoxelDefinition GetVoxelDefinition(int index)Returns the VoxelDefinition at the given registry index.
void AddVoxelDefinition(VoxelDefinition vd)Registers a new voxel definition at runtime. Must be called before placing voxels of this type.
void AddVoxelDefinitions(List<VoxelDefinition> vd)Registers a list of voxel definitions.
void AddVoxelDefinitions(ModelDefinition model)Registers all voxel definitions used by a model.
void AddVoxelDefinitions(params VoxelDefinition[] vd)Registers a variable number of voxel definitions.
Suggest an improvement
Help us improve this documentation page.