Skip to content

Commit

Permalink
fix examples compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz committed Oct 31, 2024
1 parent 8a3a4d4 commit a5d827e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 65 deletions.
19 changes: 9 additions & 10 deletions examples/render_egui_to_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,20 @@ fn setup_worldspace(
output_texture
});

commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0).mesh()),
material: materials.add(StandardMaterial {
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0).mesh())),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: Color::WHITE,
base_color_texture: Some(Handle::clone(&output_texture)),
alpha_mode: AlphaMode::Blend,
// Remove this if you want it to use the world's lighting.
unlit: true,
..default()
}),
..default()
});
})),
));
commands.spawn(EguiRenderToTextureHandle(output_texture));
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::new(0., 0., 0.), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_xyz(1.5, 1.5, 1.5).looking_at(Vec3::new(0., 0., 0.), Vec3::Y),
));
}
57 changes: 27 additions & 30 deletions examples/render_to_image_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,36 @@ fn setup(

// The cube that will be rendered to the texture.
commands
.spawn(PbrBundle {
mesh: cube_handle,
material: preview_material_handle,
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
..default()
})
.spawn((
Mesh3d(cube_handle),
MeshMaterial3d(preview_material_handle),
Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
))
.insert(PreviewPassCube)
.insert(preview_pass_layer.clone());

// The same light is reused for both passes,
// you can specify different lights for preview and main pass by setting appropriate RenderLayers.
commands
.spawn(PointLightBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)),
..default()
})
.spawn((
PointLight::default(),
Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)),
))
.insert(RenderLayers::default().with(1));

commands
.spawn(Camera3dBundle {
camera: Camera {
.spawn((
Camera3d::default(),
Camera {
// render before the "main pass" camera
order: -1,
target: RenderTarget::Image(image_handle),
clear_color: ClearColorConfig::Custom(Color::srgba(1.0, 1.0, 1.0, 0.0)),
..default()
},
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..default()
})
))
.insert(preview_pass_layer);

let cube_size = 4.0;
Expand All @@ -122,30 +121,28 @@ fn setup(

// Main pass cube.
commands
.spawn(PbrBundle {
mesh: cube_handle,
material: main_material_handle,
transform: Transform {
.spawn((
Mesh3d(cube_handle),
MeshMaterial3d(main_material_handle),
Transform {
translation: Vec3::new(0.0, 0.0, 1.5),
rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0),
..default()
},
..default()
})
))
.insert(MainPassCube);

// The main pass camera.
commands.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..default()
});
commands.spawn((
Camera3d::default(),
Transform::from_translation(Vec3::new(0.0, 0.0, 15.0)).looking_at(Vec3::default(), Vec3::Y),
));
}

fn render_to_image_example_system(
cube_preview_image: Res<CubePreviewImage>,
preview_cube_query: Query<&Handle<StandardMaterial>, With<PreviewPassCube>>,
main_cube_query: Query<&Handle<StandardMaterial>, With<MainPassCube>>,
preview_cube_query: Query<&MeshMaterial3d<StandardMaterial>, With<PreviewPassCube>>,
main_cube_query: Query<&MeshMaterial3d<StandardMaterial>, With<MainPassCube>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut contexts: EguiContexts,
) {
Expand Down Expand Up @@ -225,7 +222,7 @@ fn rotator_system(
mut query: Query<&mut Transform, Or<(With<PreviewPassCube>, With<MainPassCube>)>>,
) {
for mut transform in &mut query {
transform.rotate_x(1.5 * time.delta_seconds());
transform.rotate_z(1.3 * time.delta_seconds());
transform.rotate_x(1.5 * time.delta_secs());
transform.rotate_z(1.3 * time.delta_secs());
}
}
34 changes: 14 additions & 20 deletions examples/side_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,36 +88,30 @@ fn setup_system(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..Default::default()
});
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});
commands.spawn(PointLightBundle {
point_light: PointLight {
commands.spawn((
Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))),
MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
));
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))),
Transform::from_xyz(0.0, 0.5, 0.0),
));
commands.spawn((
PointLight {
intensity: 1500.0,
shadows_enabled: true,
..Default::default()
},
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
Transform::from_xyz(4.0, 8.0, 4.0),
));

let camera_pos = Vec3::new(-2.0, 2.5, 5.0);
let camera_transform =
Transform::from_translation(camera_pos).looking_at(CAMERA_TARGET, Vec3::Y);
commands.insert_resource(OriginalCameraTransform(camera_transform));

commands.spawn(Camera3dBundle {
transform: camera_transform,
..Default::default()
});
commands.spawn((Camera3d::default(), camera_transform));
}

fn update_camera_transform_system(
Expand Down
10 changes: 5 additions & 5 deletions examples/two_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ fn create_new_window_system(mut commands: Commands) {
.id();

// second window camera
commands.spawn(Camera3dBundle {
camera: Camera {
commands.spawn((
Camera3d::default(),
Camera {
target: RenderTarget::Window(WindowRef::Entity(second_window_id)),
..Default::default()
},
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

fn load_assets_system(mut commands: Commands, assets: Res<AssetServer>) {
Expand Down

0 comments on commit a5d827e

Please sign in to comment.