pub struct ChunkedSpaceMesh<M, const CHUNK_SIZE: GridCoordinate>where
M: DynamicMeshTypes,{ /* private fields */ }
Expand description
The large-scale and updatable form of SpaceMesh
: subdivides a Space
into
chunks which are individually recomputed as the space changes or
its contained blocks do.
Each chunk, a ChunkMesh
, owns a data value of type M::RenderData
, which is
initialized using Default
. This value may be a reference to a corresponding
GPU buffer, for example. It will usually need to be an Option
of something.
Additionally, to allow instanced rendering of complex blocks that would be overly large
if repeatedly copied into chunk meshes, render data is maintained for each individual block
that chunks may decide to omit from their meshes; it is accessed through
block_instance_mesh()
.
ChunkedSpaceMesh
manages all this data but does not demand a particular sequence of
rendering operations; it is your responsibility to render the chunk meshes and instances which
you can obtain by calling one of the iteration methods.
Implementations§
Source§impl<M, const CHUNK_SIZE: GridCoordinate> ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: GridCoordinate> ChunkedSpaceMesh<M, CHUNK_SIZE>
Sourcepub fn new(
space: Handle<Space>,
texture_allocator: M::Alloc,
interactive: bool,
) -> Self
pub fn new( space: Handle<Space>, texture_allocator: M::Alloc, interactive: bool, ) -> Self
Constructs a new ChunkedSpaceMesh
that will maintain a mesh representation of
the contents of the given space, within a requested viewing distance (specified
later).
If interactive
is true, will prioritize getting a rough view of the world over
a fully detailed one, by using placeholder block meshes on the first pass.
Sourcepub fn chunk_chart(&self) -> &ChunkChart<CHUNK_SIZE>
pub fn chunk_chart(&self) -> &ChunkChart<CHUNK_SIZE>
Returns a ChunkChart
for the view distance used by the most recent Self::update()
.
Sourcepub fn iter_chunks(&self) -> impl Iterator<Item = &ChunkMesh<M, CHUNK_SIZE>>
pub fn iter_chunks(&self) -> impl Iterator<Item = &ChunkMesh<M, CHUNK_SIZE>>
Iterates over all ChunkMesh
es owned by this ChunkedSpaceMesh
, in arbitrary order.
Sourcepub fn iter_in_view<'a>(
&'a self,
camera: &'a Camera,
) -> impl DoubleEndedIterator<Item = InViewChunkRef<'a, M, CHUNK_SIZE>> + 'a
pub fn iter_in_view<'a>( &'a self, camera: &'a Camera, ) -> impl DoubleEndedIterator<Item = InViewChunkRef<'a, M, CHUNK_SIZE>> + 'a
Iterates over the ChunkMesh
es that are in view from the given camera,
in front-to-back order. (Use .rev()
to iterate in back-to-front order.)
Uses camera
’s position, rotation, and options to decide which chunks to return.
Sourcepub fn chunk(
&self,
position: ChunkPos<CHUNK_SIZE>,
) -> Option<&ChunkMesh<M, CHUNK_SIZE>>
pub fn chunk( &self, position: ChunkPos<CHUNK_SIZE>, ) -> Option<&ChunkMesh<M, CHUNK_SIZE>>
Retrieves a ChunkMesh
for the specified chunk position, if one exists.
Call this while drawing, after Self::update()
has updated/created chunks.
Sourcepub fn block_instance_mesh(
&self,
block_index: BlockIndex,
) -> Option<&InstanceMesh<M>>
pub fn block_instance_mesh( &self, block_index: BlockIndex, ) -> Option<&InstanceMesh<M>>
Retrieves the mesh for a block which should be rendered according to
ChunkMesh::block_instances()
.
Sourcepub fn count_block_instances(&self, camera: &Camera) -> usize
pub fn count_block_instances(&self, camera: &Camera) -> usize
Calculates how many ChunkMesh::block_instances()
are present in chunks visible from the
camera.
Sourcepub fn update<F>(
&mut self,
camera: &Camera,
deadline: Deadline<M::Instant>,
render_data_updater: F,
) -> CsmUpdateInfo
pub fn update<F>( &mut self, camera: &Camera, deadline: Deadline<M::Instant>, render_data_updater: F, ) -> CsmUpdateInfo
Recompute meshes of blocks that need it and the nearest chunks that need it.
camera
’s view position is used to choose what to update and for depth ordering; its graphics options are used for triangulation and view distance.deadline
is the approximate time at which this should stop.render_data_updater
is called for every re-meshed or depth-sorted chunk or block. It may be called concurrently from multiple threads.
Returns performance information and the chunk the camera is located in.
Sourcepub fn job_queue(&self) -> &MeshJobQueue<M>
pub fn job_queue(&self) -> &MeshJobQueue<M>
Returns a handle to the job queue, which may be used by background tasks (which you supply)
to make progress in generating meshes separately from the Self::update()
operation.
Sourcepub fn view_chunk(&self) -> ChunkPos<CHUNK_SIZE>
pub fn view_chunk(&self) -> ChunkPos<CHUNK_SIZE>
Returns the chunk in which the camera from the most recent Self::update()
was located.
This may be used as the origin point to iterate over chunks in view.
Trait Implementations§
Source§impl<M, const CHUNK_SIZE: GridCoordinate> Debug for ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: GridCoordinate> Debug for ChunkedSpaceMesh<M, CHUNK_SIZE>
Auto Trait Implementations§
impl<M, const CHUNK_SIZE: i32> Freeze for ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: i32> !RefUnwindSafe for ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: i32> Send for ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: i32> Sync for ChunkedSpaceMesh<M, CHUNK_SIZE>
impl<M, const CHUNK_SIZE: i32> Unpin for ChunkedSpaceMesh<M, CHUNK_SIZE>where
<M as DynamicMeshTypes>::Instant: Unpin,
<M as MeshTypes>::Alloc: Unpin,
<M as DynamicMeshTypes>::RenderData: Unpin,
<M as MeshTypes>::Tile: Unpin,
<M as MeshTypes>::Vertex: Unpin,
impl<M, const CHUNK_SIZE: i32> !UnwindSafe for ChunkedSpaceMesh<M, CHUNK_SIZE>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.