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
impl MeshBuilder
Sourcepub fn new(
vertices: usize,
triangles: usize,
origin: Option<[f64; 3]>,
) -> Result<Self>
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.
Sourcepub fn push_positions(&mut self, chunk: &[f64]) -> Result<()>
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.
Sourcepub fn push_indices(&mut self, chunk: &[u32]) -> Result<()>
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.
Sourcepub fn step(&mut self, budget: usize) -> Result<bool>
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.
Sourcepub fn finish(self) -> Option<Mesh>
pub fn finish(self) -> Option<Mesh>
The mesh, once MeshBuilder::step returned true; None before.