-
Hi there, What would be the best (simplest) way to render 3d points and lines? Like point clouds and wireframes. Thanks in advance! Update: I managed to draw lines with Example: use bevy::prelude::*;
fn main() {
App::build()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: 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::LineStrip);
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
// plane
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(mesh),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
// light
commands.spawn_bundle(LightBundle {
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)),
..Default::default()
});
// camera
commands.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_translation(Vec3::new(-2.0, 2.5, 5.0))
.looking_at(Vec3::default(), Vec3::unit_y()),
..Default::default()
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Unfortunatelly, you can't set line width and point size. Thats because you are using the graphics api with a thin layer here which does not support this approach. Setting width for something can't be a material, because a material typically does not alter the mesh. |
Beta Was this translation helpful? Give feedback.
-
You can also look at how I approached line drawing in https://github.com/ForesightMiningSoftwareCorporation/bevy_polyline |
Beta Was this translation helpful? Give feedback.
Unfortunatelly, you can't set line width and point size. Thats because you are using the graphics api with a thin layer here which does not support this approach. Setting width for something can't be a material, because a material typically does not alter the mesh.
But you can draw a stretched quad. A quad and its mesh are already implemented in bevy (
Mesh::from(mesh::shape::Quad)
). Just scale it to your needs. Now you can have a line with width. A thicker point can be also be achieved with triangles or any approximation.Im not familiar with PointList.