Expand description
Hexx
Hexagonal tools lib in rust.
Inspired by this
RedBlobGames
article.
This lib allows you to:
- Manipulate hexagon coordinates
- Generate hexagonal maps with custom layouts and orientation
- Generate hexagon meshes (planes or columns)
I made the choice to use Axial Coordinates for performance and utility reasons,
but the Hex
type allows you to use computes Cubic coordinates. (See the hexagonal coordinate systems)
The Hex
type gives you access to most hexagonal arithmetics like:
- Distances
- Neighbors and directions
- Lines
- Ranges
- Rings
- Rotation
Example
cargo run --example hex_grid
Usage in bevy
If you want to generate 3D hexagonal mesh and use it in bevy you may do it this way:
use bevy::prelude::Mesh;
use bevy::render::{mesh::Indices, render_resource::PrimitiveTopology};
use hexx::{HexLayout, Hex, MeshInfo};
pub fn hexagonal_plane(hex: Hex, hex_layout: &HexLayout) -> Mesh {
let mesh_info = MeshInfo::hexagonal_plane(
hex_layout,
hex,
);
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, mesh_info.vertices.to_vec());
mesh.insert_attribute(Mesh::ATTRIBUTE_NORMAL, mesh_info.normals.to_vec());
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, mesh_info.uvs.to_vec());
mesh.set_indices(Some(Indices::U16(mesh_info.indices)));
mesh
}
Modules
Map shapes generation functions
Structs
Hexagonal coordinates
Hexagonal layout
Hexagon shaped map with wraparound utils.
Hexagonal orientation
Mesh information. The
const LEN
attribute ensures that there is the same number of vertices, normals and uvsEnums
All 6 possible directions in hexagonal space.