pub struct MeshBuilder { /* private fields */ }Expand description
Reusable builder for a textured mesh at Earth scale.
Vertex layout is the eight-float stride x, y, z, nx, ny, nz, u, v that
Geometry3D::CustomTextured consumes.
Implementations§
Source§impl MeshBuilder
impl MeshBuilder
pub fn new() -> Self
Sourcepub fn with_capacity(vertices: usize, triangles: usize) -> Self
pub fn with_capacity(vertices: usize, triangles: usize) -> Self
Reserves capacity for vertices vertices and triangles triangles.
Sourcepub fn set_origin(&mut self, origin: DVec3)
pub fn set_origin(&mut self, origin: DVec3)
Sets the point subtracted before narrowing to f32.
Sourcepub fn vertex_capacity(&self) -> usize
pub fn vertex_capacity(&self) -> usize
Capacity currently held by the vertex buffer, in floats.
Sourcepub fn index_capacity(&self) -> usize
pub fn index_capacity(&self) -> usize
Capacity currently held by the index buffer, in indices.
pub fn vertex_count(&self) -> usize
pub fn triangle_count(&self) -> usize
Sourcepub fn index_count(&self) -> usize
pub fn index_count(&self) -> usize
Number of indices appended so far, for batching index ranges.
pub fn is_empty(&self) -> bool
Sourcepub fn push_vertex(
&mut self,
position: DVec3,
normal: [f32; 3],
uv: (f32, f32),
) -> u32
pub fn push_vertex( &mut self, position: DVec3, normal: [f32; 3], uv: (f32, f32), ) -> u32
Appends a vertex at world scale, relative to the builder origin, and returns its local index.
Sourcepub fn push_triangle(&mut self, a: u32, b: u32, c: u32)
pub fn push_triangle(&mut self, a: u32, b: u32, c: u32)
Appends a triangle. Degenerate index triplets are dropped.
Sourcepub fn push_grid(
&mut self,
heights: &[DVec3],
cols: usize,
rows: usize,
uv_rect: (f32, f32, f32, f32),
)
pub fn push_grid( &mut self, heights: &[DVec3], cols: usize, rows: usize, uv_rect: (f32, f32, f32, f32), )
Appends a terrain patch from a height field.
heights is a (cols x rows) grid of world-space positions in
row-major order; uv_rect is the tile’s sub-rectangle of the source
image, expressed in the quad’s own 0..1 space and mapped across the
patch. The patch is two triangles per grid cell.
Sourcepub fn push_grid_with_normals(
&mut self,
positions: &[DVec3],
normals: &[[f32; 3]],
cols: usize,
rows: usize,
uv_rect: (f32, f32, f32, f32),
)
pub fn push_grid_with_normals( &mut self, positions: &[DVec3], normals: &[[f32; 3]], cols: usize, rows: usize, uv_rect: (f32, f32, f32, f32), )
Appends a grid patch with explicit per-vertex normals.
Use this for relief, where the surface normal is derived from the height field rather than being the sphere radial.
Sourcepub fn push_wall(
&mut self,
top: &[DVec3],
bottom: &[DVec3],
uv_rect: (f32, f32, f32, f32),
)
pub fn push_wall( &mut self, top: &[DVec3], bottom: &[DVec3], uv_rect: (f32, f32, f32, f32), )
Appends a vertical relief wall from a top edge to a bottom edge.
This is the side skirt that hides the gap between a raised terrain tile
and the tile behind it. top and bottom are equal-length edge points.
Sourcepub fn push_skirt(
&mut self,
top: &[DVec3],
bottom: &[DVec3],
uvs: &[(f32, f32)],
)
pub fn push_skirt( &mut self, top: &[DVec3], bottom: &[DVec3], uvs: &[(f32, f32)], )
Appends a boundary skirt between a top edge and an extruded bottom edge.
Skirts occlude crack seams between adjacent tiles of differing LOD levels.
top and bottom must have equal lengths >= 2, and uvs must match top.len().
The triangles are wound counter-clockwise when viewed from the outside with outward normals.
Sourcepub fn push_grid_perimeter_skirts(
&mut self,
grid_positions: &[DVec3],
cols: usize,
rows: usize,
skirt_depth: f64,
uv_rect: (f32, f32, f32, f32),
)
pub fn push_grid_perimeter_skirts( &mut self, grid_positions: &[DVec3], cols: usize, rows: usize, skirt_depth: f64, uv_rect: (f32, f32, f32, f32), )
Appends vertical skirts along all four perimeter edges of a terrain grid (South, East, North, West).
grid_positions contains cols * rows vertices in row-major order (row 0 is South, col 0 is West).
skirt_depth specifies the vertical extrusion distance downward along the -Z axis (or radial inward).
uv_rect specifies (u0, v0, u1, v1) texture coordinates.
Sourcepub fn push_building(
&mut self,
base: DVec3,
half: (f64, f64),
height: f64,
facade_uv: (f32, f32, f32, f32),
roof_uv: (f32, f32, f32, f32),
)
pub fn push_building( &mut self, base: DVec3, half: (f64, f64), height: f64, facade_uv: (f32, f32, f32, f32), roof_uv: (f32, f32, f32, f32), )
Appends a building prism plus its roof cap.
base is the footprint centre on the ground, half the footprint half
extents in the local X and Z axes, and height the extrusion. Walls use
the side of facade_uv and the roof uses roof_uv, both sub-rectangles
of one atlas.
Sourcepub fn finish(&self) -> Option<Geometry3D>
pub fn finish(&self) -> Option<Geometry3D>
Freezes the builder into a scene geometry, narrowing to f32 after the
RTC subtraction. Returns None when nothing was appended.