Skip to main content

MeshBuilder

Struct MeshBuilder 

Source
pub struct MeshBuilder { /* private fields */ }
Expand description

A Mesh built from flat buffers in steps, for callers that must yield between chunks of work (the Worker builds large meshes this way).

The inputs arrive first, in chunks of any size (MeshBuilder::push_positions and MeshBuilder::push_indices); then MeshBuilder::step runs the same passes as Mesh::from_buffers_f64 (or Mesh::from_buffers_f64_with_origin with an explicit origin) a slice at a time: a finiteness scan, the bounding box (which sets the origin without one), the conversion to f32 offsets, and the index check with the triangle copy. MeshBuilder::finish gives the mesh: the same one, bit for bit, as the one-call build, or the same error, however the chunks and steps split the work.

Implementations§

Source§

impl MeshBuilder

Source

pub fn new( vertices: usize, triangles: usize, origin: Option<[f64; 3]>, ) -> Result<Self>

A build of a mesh of vertices vertices and triangles triangles, stored relative to origin (or the bounding-box centre without one), with nothing uploaded yet. All the memory is reserved here, so the pushes and steps allocate nothing except the small liveness bitsets.

§Errors

StoreError::InvalidArgument for a non-finite origin (as Mesh::from_buffers_f64_with_origin); StoreError::OutOfMemory.

Source

pub fn push_positions(&mut self, chunk: &[f64]) -> Result<()>

Appends a chunk of flat [x, y, z, ...] positions. Chunks may split anywhere; they only must add up to the declared vertices.

§Errors

StoreError::InvalidArgument for more than declared.

Source

pub fn push_indices(&mut self, chunk: &[u32]) -> Result<()>

Appends a chunk of flat [a, b, c, ...] indices; like MeshBuilder::push_positions, they must add up to the declared triangles.

§Errors

StoreError::InvalidArgument for more than declared.

Source

pub fn is_done(&self) -> bool

Whether the mesh is built.

Source

pub fn step(&mut self, budget: usize) -> Result<bool>

Runs up to budget more vertices (the positions passes) or triangles (the index pass) of the build — at least one while any pass still has vertices or triangles — and returns whether the mesh is built. The upload must be complete first.

§Errors

StoreError::InvalidArgument when the upload is incomplete; then the same errors as Mesh::from_buffers_f64: non-finite input, offsets that do not fit an f32, or StoreError::InvalidVertex for the first out-of-range index; StoreError::OutOfMemory. The build is unusable after an error.

Source

pub fn finish(self) -> Option<Mesh>

The mesh, once MeshBuilder::step returned true; None before.

Trait Implementations§

Source§

impl Debug for MeshBuilder

Source§

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

Formats the value using the given formatter. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.