From ad692adeceae4998c84e27c04444a7ad5f21d1ce Mon Sep 17 00:00:00 2001 From: Matthias Wuketich Date: Tue, 3 Jun 2025 19:59:10 +0200 Subject: [PATCH 1/3] PlaneMeshBuilder how seperates its X and Z axis also updated docs --- crates/bevy_mesh/src/primitives/dim3/plane.rs | 66 ++++++++++++++++--- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/crates/bevy_mesh/src/primitives/dim3/plane.rs b/crates/bevy_mesh/src/primitives/dim3/plane.rs index fd892469be6af..4bad2f29cbd7c 100644 --- a/crates/bevy_mesh/src/primitives/dim3/plane.rs +++ b/crates/bevy_mesh/src/primitives/dim3/plane.rs @@ -13,12 +13,23 @@ pub struct PlaneMeshBuilder { /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// - /// 1 - is split by 1 line in the middle of the plane on both the X axis and the Z axis, resulting in a plane with 4 quads / 8 triangles. + /// 1 - is split by 1 line in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles. /// - /// 2 - is a plane split by 2 lines on both the X and Z axes, subdividing the plane into 3 equal sections along each axis, resulting in a plane with 9 quads / 18 triangles. + /// 2 - is a plane split by 2 lines on the X axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. /// /// and so on... - pub subdivisions: u32, + pub subdivisions_x: u32, + + /// The number of subdivisions in the mesh. + /// + /// 0 - is the original plane geometry, the 4 points in the XZ plane. + /// + /// 1 - is split by 1 line in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles. + /// + /// 2 - is a plane split by 2 lines on the Z axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// + /// and so on... + pub subdivisions_z: u32, } impl PlaneMeshBuilder { @@ -30,7 +41,8 @@ impl PlaneMeshBuilder { normal, half_size: size / 2.0, }, - subdivisions: 0, + subdivisions_x: 0, + subdivisions_z: 0, } } @@ -42,7 +54,8 @@ impl PlaneMeshBuilder { half_size: size / 2.0, ..Default::default() }, - subdivisions: 0, + subdivisions_x: 0, + subdivisions_z: 0, } } @@ -55,7 +68,8 @@ impl PlaneMeshBuilder { half_size: Vec2::splat(length) / 2.0, ..Default::default() }, - subdivisions: 0, + subdivisions_x: 0, + subdivisions_z: 0, } } @@ -88,15 +102,46 @@ impl PlaneMeshBuilder { /// equal sections along each axis, resulting in a plane with 9 quads / 18 triangles. #[inline] pub fn subdivisions(mut self, subdivisions: u32) -> Self { - self.subdivisions = subdivisions; + self.subdivisions_x = subdivisions; + self.subdivisions_z = subdivisions; + self + } + + #[inline] + /// The number of subdivisions in the mesh. + /// + /// 0 - is the original plane geometry, the 4 points in the XZ plane. + /// + /// 1 - is split by 1 line in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles. + /// + /// 2 - is a plane split by 2 lines on the X axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// + /// and so on... + pub fn subdivisions_x(mut self, subdivisions: u32) -> Self { + self.subdivisions_x = subdivisions; + self + } + + #[inline] + /// The number of subdivisions in the mesh. + /// + /// 0 - is the original plane geometry, the 4 points in the XZ plane. + /// + /// 1 - is split by 1 line in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles. + /// + /// 2 - is a plane split by 2 lines on the Z axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// + /// and so on... + pub fn subdivisions_z(mut self, subdivisions: u32) -> Self { + self.subdivisions_z = subdivisions; self } } impl MeshBuilder for PlaneMeshBuilder { fn build(&self) -> Mesh { - let z_vertex_count = self.subdivisions + 2; - let x_vertex_count = self.subdivisions + 2; + let z_vertex_count = self.subdivisions_z + 2; + let x_vertex_count = self.subdivisions_z + 2; let num_vertices = (z_vertex_count * x_vertex_count) as usize; let num_indices = ((z_vertex_count - 1) * (x_vertex_count - 1) * 6) as usize; @@ -148,7 +193,8 @@ impl Meshable for Plane3d { fn mesh(&self) -> Self::Output { PlaneMeshBuilder { plane: *self, - subdivisions: 0, + subdivisions_x: 0, + subdivisions_z: 0, } } } From 3b7f50ab1327f5fdb632b6f5a8a8873f5845c020 Mon Sep 17 00:00:00 2001 From: Matthias Wuketich Date: Tue, 3 Jun 2025 20:09:52 +0200 Subject: [PATCH 2/3] fixed Documentation errors --- crates/bevy_mesh/src/primitives/dim3/plane.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/bevy_mesh/src/primitives/dim3/plane.rs b/crates/bevy_mesh/src/primitives/dim3/plane.rs index 4bad2f29cbd7c..4bad946c66cb1 100644 --- a/crates/bevy_mesh/src/primitives/dim3/plane.rs +++ b/crates/bevy_mesh/src/primitives/dim3/plane.rs @@ -13,9 +13,9 @@ pub struct PlaneMeshBuilder { /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// - /// 1 - is split by 1 line in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles. + /// 1 - adds a vertex in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles, and a new edge along the Z axis. /// - /// 2 - is a plane split by 2 lines on the X axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// 2 - adds 2 vertices along the X axis, resulting in a plane with 3 quads / 6 triangles. /// /// and so on... pub subdivisions_x: u32, @@ -24,9 +24,9 @@ pub struct PlaneMeshBuilder { /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// - /// 1 - is split by 1 line in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles. + /// 1 - adds a vertex in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles, and a new edge along the X axis. /// - /// 2 - is a plane split by 2 lines on the Z axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// 2 - adds 2 vertices along the Z axis, resulting in a plane with 3 quads / 6 triangles. /// /// and so on... pub subdivisions_z: u32, @@ -112,9 +112,9 @@ impl PlaneMeshBuilder { /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// - /// 1 - is split by 1 line in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles. + /// 1 - adds a vertex in the middle of the X axis, resulting in a plane with 2 quads / 4 triangles, and a new edge along the Z axis. /// - /// 2 - is a plane split by 2 lines on the X axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// 2 - adds 2 vertices along the X axis, resulting in a plane with 3 quads / 6 triangles. /// /// and so on... pub fn subdivisions_x(mut self, subdivisions: u32) -> Self { @@ -127,9 +127,9 @@ impl PlaneMeshBuilder { /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// - /// 1 - is split by 1 line in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles. + /// 1 - adds a vertex in the middle of the Z axis, resulting in a plane with 2 quads / 4 triangles, and a new edge along the X axis. /// - /// 2 - is a plane split by 2 lines on the Z axis, subdividing the plane into 3 equal sections along that axis, resulting in a plane with 3 quads / 6 triangles. + /// 2 - adds 2 vertices along the Z axis, resulting in a plane with 3 quads / 6 triangles. /// /// and so on... pub fn subdivisions_z(mut self, subdivisions: u32) -> Self { @@ -141,7 +141,7 @@ impl PlaneMeshBuilder { impl MeshBuilder for PlaneMeshBuilder { fn build(&self) -> Mesh { let z_vertex_count = self.subdivisions_z + 2; - let x_vertex_count = self.subdivisions_z + 2; + let x_vertex_count = self.subdivisions_x + 2; let num_vertices = (z_vertex_count * x_vertex_count) as usize; let num_indices = ((z_vertex_count - 1) * (x_vertex_count - 1) * 6) as usize; From 6774d94ba9f99930c8bac7e3fda1485426fcf9b8 Mon Sep 17 00:00:00 2001 From: Matthias Wuketich Date: Tue, 3 Jun 2025 23:14:40 +0200 Subject: [PATCH 3/3] fixed doc oversight --- crates/bevy_mesh/src/primitives/dim3/plane.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_mesh/src/primitives/dim3/plane.rs b/crates/bevy_mesh/src/primitives/dim3/plane.rs index 4bad946c66cb1..e937905584f9a 100644 --- a/crates/bevy_mesh/src/primitives/dim3/plane.rs +++ b/crates/bevy_mesh/src/primitives/dim3/plane.rs @@ -9,7 +9,7 @@ use bevy_reflect::prelude::*; pub struct PlaneMeshBuilder { /// The [`Plane3d`] shape. pub plane: Plane3d, - /// The number of subdivisions in the mesh. + /// The number of subdivisions along the X axis. /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// @@ -20,7 +20,7 @@ pub struct PlaneMeshBuilder { /// and so on... pub subdivisions_x: u32, - /// The number of subdivisions in the mesh. + /// The number of subdivisions along the Z axis. /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// @@ -108,7 +108,7 @@ impl PlaneMeshBuilder { } #[inline] - /// The number of subdivisions in the mesh. + /// The number of subdivisions along the X axis. /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. /// @@ -123,7 +123,7 @@ impl PlaneMeshBuilder { } #[inline] - /// The number of subdivisions in the mesh. + /// The number of subdivisions along the Z axis. /// /// 0 - is the original plane geometry, the 4 points in the XZ plane. ///