diff options
Diffstat (limited to 'engine/src/mesh.rs')
| -rw-r--r-- | engine/src/mesh.rs | 179 |
1 files changed, 134 insertions, 45 deletions
diff --git a/engine/src/mesh.rs b/engine/src/mesh.rs index fff5804..c1c0f77 100644 --- a/engine/src/mesh.rs +++ b/engine/src/mesh.rs @@ -28,33 +28,33 @@ impl Mesh size, top_face: CubeFaceOptions { - uv_max: top_uv_max, - uv_min: top_uv_min, + uv_upper_left: top_uv_upper_left, + uv_lower_right: top_uv_lower_right, }, bottom_face: CubeFaceOptions { - uv_max: bot_uv_max, - uv_min: bot_uv_min, + uv_upper_left: bot_uv_upper_left, + uv_lower_right: bot_uv_lower_right, }, left_face: CubeFaceOptions { - uv_max: left_uv_max, - uv_min: left_uv_min, + uv_upper_left: left_uv_upper_left, + uv_lower_right: left_uv_lower_right, }, right_face: CubeFaceOptions { - uv_max: right_uv_max, - uv_min: right_uv_min, + uv_upper_left: right_uv_upper_left, + uv_lower_right: right_uv_lower_right, }, back_face: CubeFaceOptions { - uv_max: back_uv_max, - uv_min: back_uv_min, + uv_upper_left: back_uv_upper_left, + uv_lower_right: back_uv_lower_right, }, front_face: CubeFaceOptions { - uv_max: front_uv_max, - uv_min: front_uv_min, + uv_upper_left: front_uv_upper_left, + uv_lower_right: front_uv_lower_right, }, } = options; @@ -74,50 +74,122 @@ impl Mesh } let top_vertices = [ - ([half_w, half_h, half_d], [top_uv_max.x, top_uv_max.y]), - ([-half_w, half_h, half_d], [top_uv_min.x, top_uv_max.y]), - ([half_w, half_h, -half_d], [top_uv_max.x, top_uv_min.y]), - ([-half_w, half_h, -half_d], [top_uv_min.x, top_uv_min.y]), + ( + [half_w, half_h, half_d], + [top_uv_upper_left.x, top_uv_upper_left.y], + ), + ( + [-half_w, half_h, half_d], + [top_uv_lower_right.x, top_uv_upper_left.y], + ), + ( + [half_w, half_h, -half_d], + [top_uv_upper_left.x, top_uv_lower_right.y], + ), + ( + [-half_w, half_h, -half_d], + [top_uv_lower_right.x, top_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::UP)); let bottom_vertices = [ - ([half_w, -half_h, half_d], [bot_uv_max.x, bot_uv_max.y]), - ([-half_w, -half_h, half_d], [bot_uv_min.x, bot_uv_max.y]), - ([half_w, -half_h, -half_d], [bot_uv_max.x, bot_uv_min.y]), - ([-half_w, -half_h, -half_d], [bot_uv_min.x, bot_uv_min.y]), + ( + [half_w, -half_h, half_d], + [bot_uv_upper_left.x, bot_uv_upper_left.y], + ), + ( + [-half_w, -half_h, half_d], + [bot_uv_lower_right.x, bot_uv_upper_left.y], + ), + ( + [half_w, -half_h, -half_d], + [bot_uv_upper_left.x, bot_uv_lower_right.y], + ), + ( + [-half_w, -half_h, -half_d], + [bot_uv_lower_right.x, bot_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::DOWN)); let left_vertices = [ - ([-half_w, half_h, half_d], [left_uv_max.x, left_uv_max.y]), - ([-half_w, half_h, -half_d], [left_uv_min.x, left_uv_max.y]), - ([-half_w, -half_h, half_d], [left_uv_max.x, left_uv_min.y]), - ([-half_w, -half_h, -half_d], [left_uv_min.x, left_uv_min.y]), + ( + [-half_w, half_h, half_d], + [left_uv_upper_left.x, left_uv_upper_left.y], + ), + ( + [-half_w, half_h, -half_d], + [left_uv_lower_right.x, left_uv_upper_left.y], + ), + ( + [-half_w, -half_h, half_d], + [left_uv_upper_left.x, left_uv_lower_right.y], + ), + ( + [-half_w, -half_h, -half_d], + [left_uv_lower_right.x, left_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::LEFT)); let right_vertices = [ - ([half_w, half_h, half_d], [right_uv_max.x, right_uv_max.y]), - ([half_w, half_h, -half_d], [right_uv_min.x, right_uv_max.y]), - ([half_w, -half_h, half_d], [right_uv_max.x, right_uv_min.y]), - ([half_w, -half_h, -half_d], [right_uv_min.x, right_uv_min.y]), + ( + [half_w, half_h, half_d], + [right_uv_upper_left.x, right_uv_upper_left.y], + ), + ( + [half_w, half_h, -half_d], + [right_uv_lower_right.x, right_uv_upper_left.y], + ), + ( + [half_w, -half_h, half_d], + [right_uv_upper_left.x, right_uv_lower_right.y], + ), + ( + [half_w, -half_h, -half_d], + [right_uv_lower_right.x, right_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::RIGHT)); let back_vertices = [ - ([half_w, half_h, -half_d], [back_uv_max.x, back_uv_max.y]), - ([-half_w, half_h, -half_d], [back_uv_min.x, back_uv_max.y]), - ([half_w, -half_h, -half_d], [back_uv_max.x, back_uv_min.y]), - ([-half_w, -half_h, -half_d], [back_uv_min.x, back_uv_min.y]), + ( + [half_w, half_h, -half_d], + [back_uv_upper_left.x, back_uv_upper_left.y], + ), + ( + [-half_w, half_h, -half_d], + [back_uv_lower_right.x, back_uv_upper_left.y], + ), + ( + [half_w, -half_h, -half_d], + [back_uv_upper_left.x, back_uv_lower_right.y], + ), + ( + [-half_w, -half_h, -half_d], + [back_uv_lower_right.x, back_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::BACK)); let front_vertices = [ - ([half_w, half_h, half_d], [front_uv_max.x, front_uv_max.y]), - ([-half_w, half_h, half_d], [front_uv_min.x, front_uv_max.y]), - ([half_w, -half_h, half_d], [front_uv_max.x, front_uv_min.y]), - ([-half_w, -half_h, half_d], [front_uv_min.x, front_uv_min.y]), + ( + [half_w, half_h, half_d], + [front_uv_upper_left.x, front_uv_upper_left.y], + ), + ( + [-half_w, half_h, half_d], + [front_uv_lower_right.x, front_uv_upper_left.y], + ), + ( + [half_w, -half_h, half_d], + [front_uv_upper_left.x, front_uv_lower_right.y], + ), + ( + [-half_w, -half_h, half_d], + [front_uv_lower_right.x, front_uv_lower_right.y], + ), ] .map(|(pos, uv)| vertex(pos, uv, Vec3::FRONT)); @@ -132,7 +204,7 @@ impl Mesh byte_offset: 0, }, VertexAttrProperties { - label: VertexLabel::Uv, + label: VertexLabel::UvFromTopLeft, ty: VertexAttrType::Float32Array { length: 2 }, layout: Layout::new::<[f32; 2]>(), byte_offset: size_of::<[f32; 3]>(), @@ -378,21 +450,38 @@ impl Default for CubeOptions #[non_exhaustive] pub struct CubeFaceOptions { - pub uv_max: Vec2<f32>, - pub uv_min: Vec2<f32>, + /// Seeing the face head on, this is the texture coordinate for the corner that + /// would be on the upper left of the face. + /// + /// The default is `(0, 0)` + pub uv_upper_left: Vec2<f32>, + + /// Seeing the face head on, this is the texture coordinate for the corner that + /// would be on the lower right of the face. + /// + /// The default is `(1, 1)` + pub uv_lower_right: Vec2<f32>, } impl CubeFaceOptions { - pub fn uv_max(mut self, uv_max: Vec2<f32>) -> Self + /// Seeing the face head on, this is the texture coordinate for the corner that + /// would be on the upper left of the face. + /// + /// The default is `(0, 0)` + pub fn uv_upper_left(mut self, uv_upper_left: Vec2<f32>) -> Self { - self.uv_max = uv_max; + self.uv_upper_left = uv_upper_left; self } - pub fn uv_min(mut self, uv_min: Vec2<f32>) -> Self + /// Seeing the face head on, this is the texture coordinate for the corner that + /// would be on the lower right of the face. + /// + /// The default is `(1, 1)` + pub fn uv_lower_right(mut self, uv_lower_right: Vec2<f32>) -> Self { - self.uv_min = uv_min; + self.uv_lower_right = uv_lower_right; self } } @@ -402,8 +491,8 @@ impl Default for CubeFaceOptions fn default() -> Self { Self { - uv_max: Vec2 { x: 1.0, y: 1.0 }, - uv_min: Vec2 { x: 0.0, y: 0.0 }, + uv_upper_left: Vec2 { x: 0.0, y: 0.0 }, + uv_lower_right: Vec2 { x: 1.0, y: 1.0 }, } } } |
