pub struct BuildingBlocks {
pub id: PickId,
pub obj_model: Model,
/* private fields */
}Expand description
A collection of identically-shaped building blocks.
Uses GPU instancing to efficiently render many copies of the same model with different transformations. Currently does not perform frustum culling or occlusion culling, so performance may degrade with very large numbers of blocks.
Fields§
§id: PickId§obj_model: ModelImplementations§
Source§impl BuildingBlocks
impl BuildingBlocks
pub async fn new( id: impl Into<PickId>, queue: &Queue, device: &Device, start_position: Vector3<f32>, start_rotation: Quaternion<f32>, amount: usize, obj_file: &str, ) -> Self
Sourcepub fn instances_mut(&mut self) -> &mut Vec<Instance>
pub fn instances_mut(&mut self) -> &mut Vec<Instance>
Returns a mutable reference to instances, assumes the instance size changes and recalculates buffers.
If you only mutate some values but don’t intend to change buffer sizes use instances_mut_size_unchanged
pub fn instances_mut_size_unchanged(&mut self) -> &mut [Instance]
pub fn add_instance(&mut self, instance: Instance)
pub fn add_instances(&mut self, instances: Vec<Instance>)
Sourcepub async fn mk_multiple(
queue: &Queue,
device: &Device,
amount: usize,
descr: &[(PickId, &'static str)],
) -> Vec<BuildingBlocks>
pub async fn mk_multiple( queue: &Queue, device: &Device, amount: usize, descr: &[(PickId, &'static str)], ) -> Vec<BuildingBlocks>
This constructor creates amount instances all located at (0.0, 0.0, 0.0).
TODO: pass iter fn to choose the transformation
Sourcepub fn to_clickable(&self, device: &Device, id: PickId) -> Self
pub fn to_clickable(&self, device: &Device, id: PickId) -> Self
This method creates a copy of the original Block (and instances) where only the fragment shader differs. The fragment shader is a U32 id referring to the object that was drawn.
This is used to draw a pick shader which allows identifying objects clicked on with a mouse pointer.
TODO: make this a trait if possible
pub fn clear_first(&mut self, amount: usize, ctx: &Context)
pub fn clear_at(&mut self, from: usize, to: usize, ctx: &Context)
Sourcepub fn to_instanced(&self) -> Instanced<'_>
pub fn to_instanced(&self) -> Instanced<'_>
Returns the inner instanced of the Default render for possible optimizations with Defaults
Trait Implementations§
Source§impl AsRef<BuildingBlocks> for BuildingBlocks
impl AsRef<BuildingBlocks> for BuildingBlocks
Source§fn as_ref(&self) -> &BuildingBlocks
fn as_ref(&self) -> &BuildingBlocks
Source§impl<'a, 'pass> From<&'a BuildingBlocks> for Render<'a, 'pass>
impl<'a, 'pass> From<&'a BuildingBlocks> for Render<'a, 'pass>
Source§fn from(blocks: &'a BuildingBlocks) -> Self
fn from(blocks: &'a BuildingBlocks) -> Self
Source§impl<'a, 'pass> GPUResource<'a, 'pass> for BuildingBlocks
impl<'a, 'pass> GPUResource<'a, 'pass> for BuildingBlocks
fn write_to_buffer(&mut self, queue: &Queue, device: &Device)
fn get_render(&'a self) -> Render<'a, 'pass>
Auto Trait Implementations§
impl Freeze for BuildingBlocks
impl !RefUnwindSafe for BuildingBlocks
impl Send for BuildingBlocks
impl Sync for BuildingBlocks
impl Unpin for BuildingBlocks
impl UnsafeUnpin for BuildingBlocks
impl !UnwindSafe for BuildingBlocks
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> 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more