-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split OrthographicProjection::default into 2d & 3d (Adopted) #15073
Split OrthographicProjection::default into 2d & 3d (Adopted) #15073
Conversation
The default value for `near` in `OrthographicProjection` should be different for 2d & 3d. For 2d using `near = -1000` allows bevy users to build up scenes using background `z = 0`, and foreground elements `z > 0` similar to css. However in 3d `near = -1000` results in objects behind the camera being rendered. Using `near = 0` works for 3d, but forces 2d users to assign `z <= 0` for rendered elements, putting the background at some arbitrary negative value. There was discussion about other options in the discord [0], but this seemed like the lowest cost approach. This commit splits `OrthographicProjection::default` into `default_2d` and `default_3d`. [0]: https://discord.com/channels/691052431525675048/1154114310042292325
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me :) I would like to not add API without documentation, otherwise this looks good.
@@ -41,11 +41,7 @@ pub struct Camera2dBundle { | |||
|
|||
impl Default for Camera2dBundle { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
|
||
impl OrthographicProjection { | ||
pub fn default_2d() -> Self { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
} | ||
|
||
pub fn default_3d() -> Self { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@janhohenheim Thanks for the review! I removed the outdated comment & added docs to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, thanks! Left some minor documentation suggestions, but nothing blocking :)
Co-authored-by: Jan Hohenheim <[email protected]>
Co-authored-by: Jan Hohenheim <[email protected]>
Co-authored-by: Jan Hohenheim <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense for Default to default to default_3d (like FromWorld does)?
It would defeat the point, since beginners would keep writing
on their 2d cameras, ending up with a black screen. |
Adopted PR from dmlary, all credit to them! #9915
Original description:
Objective
The default value for
near
inOrthographicProjection
should be different for 2d & 3d.For 2d using
near = -1000
allows bevy users to build up scenes using backgroundz = 0
, and foreground elementsz > 0
similar to css. However in 3dnear = -1000
results in objects behind the camera being rendered. Usingnear = 0
works for 3d, but forces 2d users to assignz <= 0
for rendered elements, putting the background at some arbitrary negative value.There is no common value for
near
that doesn't result in a footgun or usability issue for either 2d or 3d, so they should have separate values.There was discussion about other options in the discord 0, but splitting
default()
intodefault_2d()
anddefault_3d()
seemed like the lowest cost approach.Related/past work #9138, #9214, #9310, #9537 (thanks to @Selene-Amanita for the list)
Solution
This commit splits
OrthographicProjection::default
intodefault_2d
anddefault_3d
.Migration Guide
OrthographicProjection
, change..default()
to..OrthographicProjection::default_2d()
or..OrthographicProjection::default_3d()
Example: