Skip to content

Commit

Permalink
Fixed issue in positioned meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Oct 25, 2023
1 parent 9f36228 commit e31beb9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion examples/merged_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/mesh/column_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/plane_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e31beb9

Please sign in to comment.