I want to create hexagonal tiles similar to Civilization that I can click on the tiles and move things in and out of them with a drag and drop system. The code I've written throws an error after I run the program:
Mesh is missing requested attribute: Vertex_Normal (MeshVertexAttributeId(1), pipeline type: Some("bevy_sprite::mesh2d::material::Material2dPipeline<bevy_sprite::mesh2d::color_material::ColorMaterial>"))
I'm unsure as to why this throws an error since the program runs fine when I create a basic mesh from quad (meshes.add(Mesh::from(shape::Quad::default())).into()
) but I want a 2D hexagon.
Here is my setup code:
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
asset_server: Res<AssetServer>
) {
let vertices = vec![
[-0.8660, 0.5000],
[ 0.8660, 0.5000],
[-1.0000, 0.0000],
[ 1.0000, 0.0000],
[-0.8660,-0.5000],
[ 0.8660,-0.5000]];
let indeces = Indices::U16(vec![
0, 1, 2,
1, 3, 2,
2, 3, 4,
3, 5, 4
]);
let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, vertices);
mesh.set_indices(Some(indeces));
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle(MaterialMesh2dBundle {
mesh: meshes.add(mesh).into(),
transform: Transform::default().with_scale(Vec3::splat(128.)),
material: materials.add(asset_server.load(TILE_SPRITE).into()),
..default()
});
}
This is my main:
const TILE_SPRITE: &str = "tile.png";
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.run();
}