Skip to main content

VoxelWorld

Struct VoxelWorld 

Source
pub struct VoxelWorld {
    pub seed: u64,
    pub chunk_blocks: [u32; 3],
    pub block_size: f32,
    pub view_radius: u32,
    pub impostor_radius: u32,
    pub impostor_step: u32,
    pub load_budget: u32,
    pub palette: Vec<AssetId>,
    pub material: Option<MaterialHandle>,
}
Expand description

An infinite, procedurally generated voxel world.

Where a VoxelChunk is one authored chunk compiled to a fixed mesh at build time, a VoxelWorld describes an unbounded world: chunks are generated on demand from seed as the camera moves and streamed in and out around it. The grid is infinite on X/Z and a single chunk tall on Y. Declaring one opts the world into chunk streaming; with no VoxelWorld present nothing changes.

The palette lists BlockType assets; the generator uses index 0 as air, index 1 as the surface block, and index 2 (when present) as the subsurface block. material supplies the textures and lighting shared by every chunk.

Fields§

§seed: u64

Deterministic terrain seed. The same seed always generates the same world, so a chunk regenerates identically each time it streams back in.

§chunk_blocks: [u32; 3]

Blocks per chunk [dx, dy, dz]. Y is the world’s fixed vertical extent.

§block_size: f32

World units per block edge.

§view_radius: u32

Chunk radius streamed around the camera at full voxel detail.

§impostor_radius: u32

Outer chunk radius streamed as cheap coarse impostors. Chunks farther than view_radius but within impostor_radius render as a low-detail surface mesh instead of full voxel geometry. 0 (the default) or any value <= view_radius disables impostors.

§impostor_step: u32

Coarse-grid step (in blocks) for distant-chunk impostors: the surface is sampled every impostor_step blocks. Higher = cheaper and coarser.

§load_budget: u32

Maximum number of chunks generated and loaded per frame.

§palette: Vec<AssetId>

BlockType asset names. Index 0 is air; 1 is the surface block; 2, when present, is the subsurface block.

§material: Option<MaterialHandle>

Material shared by every chunk: textures and lighting.

Implementations§

Source§

impl VoxelWorld

Source

pub fn chunk_blocks(&self) -> [u32; 3]

Blocks per chunk, each axis floored at 1 so a chunk is never degenerate.

Source

pub fn block_size(&self) -> f32

World units per block edge, floored at a small positive value.

Source

pub fn chunk_world_size(&self) -> (f32, f32)

World-space (x, z) size of one chunk.

Source

pub fn view_radius(&self) -> i32

View radius in chunks, floored at 0 and capped so a typo cannot ask for a multi-thousand-chunk window.

Source

pub fn impostor_radius(&self) -> i32

Effective impostor (far) radius in chunks. Capped well above the full-detail cap since impostors are cheap, and floored at view_radius (a smaller value disables impostors, there is no far band to fill).

Source

pub fn impostor_step(&self) -> u32

Coarse-grid step in blocks for distant impostors, floored at 1 and capped so a typo cannot collapse the whole surface to a single quad on a huge chunk (still valid, just degenerate).

Source

pub fn impostors_enabled(&self) -> bool

Whether the distant-impostor far band is active: an impostor radius strictly beyond the full-detail radius.

Source

pub fn load_budget(&self) -> usize

Per-frame chunk load budget as a usize, floored at 1 so a stray 0 cannot wedge streaming permanently.

Trait Implementations§

Source§

impl Clone for VoxelWorld

Source§

fn clone(&self) -> VoxelWorld

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for VoxelWorld

Source§

const NAME: &'static str = "VoxelWorld"

The registry name a world authors this component under.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_locator(&mut self, _locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

fn inject_name(&mut self, _id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

impl ComponentSlot for VoxelWorld

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for VoxelWorld

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VoxelWorld

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for VoxelWorld

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<VoxelWorld> for ComponentAsset

Source§

fn from(c: VoxelWorld) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for VoxelWorld

Source§

impl Serialize for VoxelWorld

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.