Your question lacks a lot of details, for example which version of bevy you are using, which shaders you defined, etc.
I am still trying to provide an answer for bevy = 0.4 and the default shaders.
The following code demonstrates how to
- Define vertecies for a
bevy::render::pipeline::PrimitiveTopology::TriangleList (because I suspect you are trying to do this...)
- Assign vertex normals to the positions
- Assign uv coordinates to the positions
It is heavily based on the built in shapes in bevy, which can be found here.
use bevy::prelude::*;
fn main() {
App::build()
.add_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();
}
/// set up a simple 3D scene
fn setup(
commands: &mut Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let vertices = [
([0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0]),
([1.0, 2.0, 1.0], [0.0, 1.0, 0.0], [1.0, 1.0]),
([2.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0]),
];
let indices = bevy::render::mesh::Indices::U32(vec![0, 2, 1, 0, 3, 2]);
let mut positions = Vec::new();
let mut normals = Vec::new();
let mut uvs = Vec::new();
for (position, normal, uv) in vertices.iter() {
positions.push(*position);
normals.push(*normal);
uvs.push(*uv);
}
let mut mesh = Mesh::new(bevy::render::pipeline::PrimitiveTopology::TriangleList);
mesh.set_indices(Some(indices));
mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, positions);
mesh.set_attribute(Mesh::ATTRIBUTE_NORMAL, normals);
mesh.set_attribute(Mesh::ATTRIBUTE_UV_0, uvs);
// add entities to the world
commands
// plane
.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
})
// light
.spawn(LightBundle {
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
..Default::default()
})
// camera
.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(-2.0, 2.5, 5.0))
.looking_at(Vec3::default(), Vec3::unit_y()),
..Default::default()
});
}
Obviously you will have to define positions, uvs and normals in such a way, that they make sense for your use case. Apart from that depending on your shader you might not need all of these Mesh attributes.