summaryrefslogtreecommitdiff
path: root/engine/src/mesh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/mesh.rs')
-rw-r--r--engine/src/mesh.rs41
1 files changed, 26 insertions, 15 deletions
diff --git a/engine/src/mesh.rs b/engine/src/mesh.rs
index c1c0f77..771f7bd 100644
--- a/engine/src/mesh.rs
+++ b/engine/src/mesh.rs
@@ -17,13 +17,26 @@ pub struct Mesh
impl Mesh
{
+ #[must_use]
pub fn cube(size: Dimens3<f32>) -> Self
{
Self::cube_with_options(CubeOptions::default().size(size))
}
+ #[must_use]
pub fn cube_with_options(options: CubeOptions) -> Self
{
+ #[inline]
+ fn vertex(pos: [f32; 3], uv: [f32; 2], normal: Vec3<f32>) -> [f32; 8]
+ {
+ let [pos_x, pos_y, pos_z] = pos;
+ let [uv_x, uv_y] = uv;
+
+ [
+ pos_x, pos_y, pos_z, uv_x, uv_y, normal.x, normal.y, normal.z,
+ ]
+ }
+
let CubeOptions {
size,
top_face:
@@ -62,17 +75,6 @@ impl Mesh
let half_h = size.height / 2.0;
let half_d = size.depth / 2.0;
- #[inline(always)]
- fn vertex(pos: [f32; 3], uv: [f32; 2], normal: Vec3<f32>) -> [f32; 8]
- {
- let [pos_x, pos_y, pos_z] = pos;
- let [uv_x, uv_y] = uv;
-
- [
- pos_x, pos_y, pos_z, uv_x, uv_y, normal.x, normal.y, normal.z,
- ]
- }
-
let top_vertices = [
(
[half_w, half_h, half_d],
@@ -235,11 +237,13 @@ impl Mesh
.build()
}
+ #[must_use]
pub fn builder() -> Builder
{
Builder::default()
}
+ #[must_use]
pub fn vertex_buf(&self) -> &vertex_buffer::VertexBuffer
{
&self.vertex_buf
@@ -264,22 +268,22 @@ impl Mesh
pub fn set_indices(&mut self, indices: impl IntoIterator<Item = u32>)
{
- let curr_indices = self.indices.get_or_insert_with(|| Vec::new());
+ let curr_indices = self.indices.get_or_insert_with(Vec::new);
curr_indices.clear();
- curr_indices.extend(indices.into_iter());
+ curr_indices.extend(indices);
}
/// Finds the vertex positions that are furthest in every 3D direction. Keep in mind
/// that this can be quite time-expensive if the mesh has many vertices.
+ #[must_use]
pub fn find_furthest_vertex_positions(&self) -> DirectionPositions
{
let mut pos_iter = self
.vertex_buf()
.iter::<[f32; 3]>(VertexLabel::Position)
- .map(|vertex_pos| Vec3::from(*vertex_pos))
- .into_iter();
+ .map(|vertex_pos| Vec3::from(*vertex_pos));
let first_pos = pos_iter.next().unwrap();
@@ -318,23 +322,27 @@ pub struct Builder
impl Builder
{
+ #[must_use]
pub fn new() -> Self
{
Self::default()
}
+ #[must_use]
pub fn vertices(mut self, vertices_bytes: vertex_buffer::VertexBuffer) -> Self
{
self.vertex_buf = vertices_bytes;
self
}
+ #[must_use]
pub fn indices(mut self, indices: impl IntoIterator<Item = u32>) -> Self
{
self.indices = Some(indices.into_iter().collect());
self
}
+ #[must_use]
pub fn build(self) -> Mesh
{
Mesh {
@@ -356,6 +364,7 @@ pub enum VertexAttrType
impl VertexAttrType
{
+ #[must_use]
pub fn layout(&self) -> Layout
{
match self {
@@ -469,6 +478,7 @@ impl CubeFaceOptions
/// would be on the upper left of the face.
///
/// The default is `(0, 0)`
+ #[must_use]
pub fn uv_upper_left(mut self, uv_upper_left: Vec2<f32>) -> Self
{
self.uv_upper_left = uv_upper_left;
@@ -479,6 +489,7 @@ impl CubeFaceOptions
/// would be on the lower right of the face.
///
/// The default is `(1, 1)`
+ #[must_use]
pub fn uv_lower_right(mut self, uv_lower_right: Vec2<f32>) -> Self
{
self.uv_lower_right = uv_lower_right;