Closed
Description
Bevy version
0.16
(commit 199c978)
What you did
Raised by Krzysiu
on Discord
Modify the simple_picking
example to add a Viewport
with an offset:
- Add the following import
use bevy_render::camera::Viewport;
- Add the
window_query: Query<&Window>
parameter to thesetup_scene
system - Replace
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
with
let window = window_query.single().unwrap();
commands.spawn((
Camera {
viewport: Some(Viewport {
physical_position: UVec2::new(250, 0),
physical_size: window.physical_size(),
..default()
}),
..default()
},
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
What went wrong
- Picking on the text works as expected to spawn cubes
- Picking the cubes to rotate them is broken. The user needs to pick 250 px to the right of the cubes.
Additional information
- Setting the offset value to something greater like 450, causing the displaced picking zone to land outside of the initial window, means that picking won't work at all on the cubes, even if the window is resized horizontally. (Edit: I guess that this is expected and due to the viewport being clamped to the window size. Shouldn't it try to expand to its original
physical_size
though ?) Krzysiu
created another repro (original discovery) with a setup a bit more involved https://github.com/KrzysztofZywiecki/WFCIt creates two cameras with different viewports and a rectangle that's visible on both. Left camera picks the square correctly, right one does not, and in the console I'm printing rays dictionary that shows weird ray origin on right camera
- Vaguely related issue, but for sprites:
Trigger<Pointer<_>>
events are triggered for different position when using 2 cameras withRenderLayers
#18005, with an ongoing sprite related fix PR UseRayMap
andRenderLayers
inbevy_sprite/picking_backend
#18069