From e31beb920ecbaeb05243af5ad98344200500f4d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Lescaudey=20de=20Maneville?= Date: Wed, 25 Oct 2023 11:29:19 +0200 Subject: [PATCH] Fixed issue in positioned meshes --- examples/merged_columns.rs | 6 +++++- src/mesh/column_builder.rs | 5 +++-- src/mesh/plane_builder.rs | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/merged_columns.rs b/examples/merged_columns.rs index f579b67..bae0bb0 100644 --- a/examples/merged_columns.rs +++ b/examples/merged_columns.rs @@ -94,7 +94,11 @@ fn setup_grid( // We compute the merged mesh with all children columns let mesh = children.fold(MeshInfo::default(), |mut mesh, c| { let [min, max] = settings.column_heights; - let height = rng.gen_range(min..=max); + let height = if min < max { + rng.gen_range(min..=max) + } else { + min + }; let info = ColumnMeshBuilder::new(&layout, height) .at(c) .without_bottom_face() diff --git a/src/mesh/column_builder.rs b/src/mesh/column_builder.rs index 37226fe..5dbc4bb 100644 --- a/src/mesh/column_builder.rs +++ b/src/mesh/column_builder.rs @@ -183,13 +183,14 @@ impl<'l> ColumnMeshBuilder<'l> { .with_uv_options(self.caps_uv_options) .build(); // We store the offset to match the `self.pos` - let mut offset = self.layout.hex_to_world_pos(self.pos).extend(0.0); + let pos = self.layout.hex_to_world_pos(self.pos); + let mut offset = Vec3::new(pos.x, 0.0, pos.y); // We create the final mesh let mut mesh = MeshInfo::default(); // Column sides let subidivisions = self.subdivisions.unwrap_or(0).max(1); let delta = self.height / subidivisions as f32; - let [a, b, c, d, e, f] = self.layout.hex_corners(self.pos); + let [a, b, c, d, e, f] = self.layout.hex_corners(Hex::ZERO); let corners = [[a, b], [b, c], [c, d], [d, e], [e, f], [f, a]]; for [left, right] in corners { let normal = (left + right).normalize(); diff --git a/src/mesh/plane_builder.rs b/src/mesh/plane_builder.rs index 0ff57dc..e7ac546 100644 --- a/src/mesh/plane_builder.rs +++ b/src/mesh/plane_builder.rs @@ -91,7 +91,8 @@ impl<'l> PlaneMeshBuilder<'l> { // We compute the mesh at the origin to allow scaling let mut mesh = MeshInfo::hexagonal_plane(self.layout, Hex::ZERO); // We store the offset to match the `self.pos` - let mut offset = self.layout.hex_to_world_pos(self.pos).extend(0.0); + let pos = self.layout.hex_to_world_pos(self.pos); + let mut offset = Vec3::new(pos.x, 0.0, pos.y); // We apply optional scale if let Some(scale) = self.scale { mesh.vertices.iter_mut().for_each(|p| *p *= scale);