-
How would I go about rendering a Example Code (using version use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// circular base
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Circle::new(4.0).into()),
material: materials.add(Color::WHITE.into()),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb_u8(255, 0, 0).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// cube 2
// How can this always be drawn on top?
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb_u8(0, 0, 255).into()),
transform: Transform::from_xyz(1.0, 0.0, -2.0),
..default()
});
// light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
});
// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
} |
Beta Was this translation helpful? Give feedback.
Answered by
negasora
Nov 9, 2023
Replies: 1 comment
-
Of course I found the answer just after posting this 😅 Using two cameras with different use bevy::{prelude::*, core_pipeline::clear_color::ClearColorConfig, render::view::RenderLayers};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// circular base
commands.spawn(PbrBundle {
mesh: meshes.add(shape::Circle::new(4.0).into()),
material: materials.add(Color::WHITE.into()),
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
..default()
});
// cube 1
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb_u8(255, 0, 0).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// cube 2
commands.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb_u8(0, 0, 255).into()),
transform: Transform::from_xyz(1.0, 0.0, -2.0),
..default()
}, RenderLayers::layer(1)));
// light
commands.spawn((
PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..default()
}, RenderLayers::all()));
// camera 1
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
// camera 2
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
..default()
},
camera: Camera {
order: 1,
..default()
},
..default()
}, RenderLayers::layer(1)));
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
negasora
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Of course I found the answer just after posting this 😅
Using two cameras with different
RenderLayers
and different ordering works for my use case.