Skip to content

Commit

Permalink
0.14 chores (#145)
Browse files Browse the repository at this point in the history
## Work done

- [x] Enabled `dynamic_linking` to `bevy` dev-dependency for faster
example compile times
- [x] Made the orientation static data `const`
- [x] Small docs improvements
- [x] `MeshInfo::cheap_hexagonal_column` now returns a mesh with 12
vertices
- [x] Fixed `uv` generation for planes and column, correctly wrapped
between (0, 0) and (1, 1), as a result:
- [x] Deprecated `UVOptions::quad_default` in favor of `UVOptions::new`
  - [x] Deprecated `UVOptions::cap_default` in favor of `UVOptions::new`
- [x] Defined MSRV to be `1.72`  
- [x] Added gizmos to mesh builder example
  • Loading branch information
ManevilleF authored Feb 1, 2024
1 parent 5dd8f4b commit ec033c8
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
readme-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: install cargo-sync-readme
run: cargo install cargo-sync-readme
Expand Down
24 changes: 15 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build
run: cargo build --verbose
Expand All @@ -27,7 +27,7 @@ jobs:
needs: [ build, fmt ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: build examples
run: cargo build --examples --verbose
Expand All @@ -36,7 +36,7 @@ jobs:
needs: [ build, fmt ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test --tests --all-features
Expand All @@ -45,15 +45,15 @@ jobs:
needs: [ build, fmt ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run doctests
run: cargo test --doc --all-features

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: "rustfmt"
Expand All @@ -62,12 +62,18 @@ jobs:

clippy:
needs: [ build, fmt ]
strategy:
matrix:
version:
- stable
- 1.72.1 # MSRV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Cargo clippy installation
run: rustup component add clippy
with:
toolchain: ${{ matrix.version }}
components: clippy
- name: Run clippy default check
run: cargo clippy --all --tests -- -D warnings
- name: Run clippy all features check
Expand All @@ -79,7 +85,7 @@ jobs:
needs: [ build, fmt ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run rustdoc
run: cargo rustdoc --all-features -- -D warnings
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

## [Unreleased]

* Defined MSRV to be 1.72.1 (#145)
* Made internal `HexOrientationData` matrices `const` (#145)
* (**BREAKING**) Fixed `uv` generation for planes and columns (#145):
* UV coords, by default, will be correctly wrapped between (0, 0) and (1, 1)
* `MeshInfo::cheap_hexagonal_column` now returns a mesh with 12 vertices (#145)
* Added gizmos to `mesh_builder` example (#145)

### Deprecations

* Deprecated `UVOptions::quad_default` in favor of `UVOptions::new` (#145)
* Deprecated `UVOptions::cap_default` in favor of `UVOptions::new` (#145)

## 0.13.0

### algorithms
Expand Down Expand Up @@ -45,7 +57,7 @@ nodes instead of one, allowing for more use cases (#130, #128)
* Changed the order of operations in `alter_uvs` (#143)
* (**BREAKING**) Fixed quad generation which had upside down uvs (#143)

### Deprecation
### Deprecations

* Deprecated `MeshInfo::hexagonal_plane` in favor of `PlaneMeshBuilder` (#139)

Expand Down
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ categories = ["game-development", "mathematics"]
repository = "https://github.com/ManevilleF/hexx"
exclude = [".github"]
resolver = "2"
rust-version = "1.72.1"

[features]
default = ["algorithms", "mesh"]
Expand Down Expand Up @@ -55,10 +56,10 @@ features = [
"default_font",
"png",
"x11",
# The following features are required because of https://github.com/bevyengine/bevy/discussions/9100
"ktx2",
"zstd",
"tonemapping_luts",
"bevy_gizmos",
# Faster compilation
"dynamic_linking",
]
default-features = false

Expand Down
Binary file modified docs/mesh_builder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 40 additions & 9 deletions examples/mesh_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn main() {
.add_plugins(EguiPlugin)
.add_plugins(bevy_inspector_egui::DefaultInspectorConfigPlugin)
.add_systems(Startup, setup)
.add_systems(Update, (show_ui, animate, update_mesh))
.add_systems(Update, (show_ui, animate, update_mesh, gizmos))
.run();
}

Expand Down Expand Up @@ -124,7 +124,7 @@ fn setup(
asset_server: Res<AssetServer>,
) {
let texture = asset_server.load("uv_checker.png");
let transform = Transform::from_xyz(0.0, 0.0, 20.0).looking_at(Vec3::ZERO, Vec3::Y);
let transform = Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y);
commands.spawn(Camera3dBundle {
transform,
..default()
Expand Down Expand Up @@ -165,22 +165,53 @@ fn animate(
buttons: Res<Input<MouseButton>>,
time: Res<Time>,
) {
if buttons.pressed(MouseButton::Left) {
for event in motion_evr.read() {
for event in motion_evr.read() {
if buttons.pressed(MouseButton::Left) {
let mut transform = transforms.get_mut(info.mesh_entity).unwrap();
transform.rotate_y(event.delta.x * time.delta_seconds());
transform.rotate_x(event.delta.y * time.delta_seconds());
let axis = Vec3::new(event.delta.y, event.delta.x, 0.0).normalize();
let angle = event.delta.length() * time.delta_seconds();
let quaternion = Quat::from_axis_angle(axis, angle);
transform.rotate(quaternion);
}
}
}

fn gizmos(
mut draw: Gizmos,
info: Res<HexInfo>,
transforms: Query<&Transform>,
params: Res<BuilderParams>,
) {
let transform = transforms.get(info.mesh_entity).unwrap();
// Global axis
draw.line(Vec3::NEG_X * 100.0, Vec3::X * 100.0, Color::RED.with_a(0.4));
draw.line(
Vec3::NEG_Y * 100.0,
Vec3::Y * 100.0,
Color::GREEN.with_a(0.4),
);
draw.line(
Vec3::NEG_Z * 100.0,
Vec3::Z * 100.0,
Color::BLUE.with_a(0.4),
);
// Local axis
let radius = info.layout.hex_size.length() * params.scale.length();
draw.circle(Vec3::ZERO, transform.local_x(), radius, Color::RED)
.segments(64);
draw.circle(Vec3::ZERO, transform.local_y(), radius, Color::GREEN)
.segments(64);
draw.circle(Vec3::ZERO, transform.forward(), radius, Color::BLUE)
.segments(64);
}

fn update_mesh(params: Res<BuilderParams>, info: Res<HexInfo>, mut meshes: ResMut<Assets<Mesh>>) {
if !params.is_changed() {
return;
}
let mut new_mesh = ColumnMeshBuilder::new(&info.layout, params.height)
.with_subdivisions(params.subdivisions)
.with_offset(Vec3::NEG_Y * params.height / 2.0)
.with_offset(Vec3::NEG_Y * params.height / 2.0 * params.scale.y)
.with_scale(params.scale)
.with_caps_uv_options(params.caps_uvs)
.with_multi_sides_uv_options(match params.sides_uvs_mode {
Expand Down Expand Up @@ -216,8 +247,8 @@ impl Default for BuilderParams {
top_face: true,
bottom_face: true,
sides_uvs_mode: SideUVMode::Global,
sides_uvs: [UVOptions::quad_default().with_scale_factor(vec2(0.3, 1.0)); 6],
caps_uvs: UVOptions::cap_default().with_scale_factor(vec2(0.3, 0.3)),
sides_uvs: [UVOptions::new().with_scale_factor(vec2(0.3, 1.0)); 6],
caps_uvs: UVOptions::new(),
scale: Vec3::ONE,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl HexLayout {
#[must_use]
pub(crate) fn center_aligned_hex_corners(&self) -> [Vec2; 6] {
Direction::ALL_DIRECTIONS.map(|dir| {
let angle = dir.angle_pointy() + self.orientation.angle_offset;
let angle = dir.angle(self.orientation);
Vec2::new(self.hex_size.x * angle.cos(), self.hex_size.y * angle.sin())
})
}
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
Vec2::new(-5.0, 9.0),
Vec2::new(-10.0, -0.0),
Vec2::new(-5.0, -9.0),
Vec2::new(5.0, -9.0)
Vec2::new(5.0, -9.0),
]
);
}
Expand All @@ -184,12 +184,12 @@ mod tests {
assert_eq!(
corners,
[
Vec2::new(9.0, -5.0),
Vec2::new(9.0, 5.0),
Vec2::new(-0.0, 10.0),
Vec2::new(-9.0, 5.0),
Vec2::new(-9.0, -5.0),
Vec2::new(0.0, -10.0),
Vec2::new(9.0, -5.0)
]
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/column_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl<'l> ColumnMeshBuilder<'l> {
scale: None,
top_face: true,
bottom_face: true,
sides_uv_options: [UVOptions::quad_default(); 6],
caps_uv_options: UVOptions::cap_default(),
sides_uv_options: [UVOptions::new(); 6],
caps_uv_options: UVOptions::new(),
center_aligned: false,
}
}
Expand Down
Loading

0 comments on commit ec033c8

Please sign in to comment.