Split OrthographicProjection::default into 2d & 3d (Adopted)#15073
Split OrthographicProjection::default into 2d & 3d (Adopted)#15073alice-i-cecile merged 7 commits intobevyengine:mainfrom
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
janhohenheim
left a comment
There was a problem hiding this comment.
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.
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
|
@janhohenheim Thanks for the review! I removed the outdated comment & added docs to |
janhohenheim
left a comment
There was a problem hiding this comment.
Looks good now, thanks! Left some minor documentation suggestions, but nothing blocking :)
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
IQuick143
left a comment
There was a problem hiding this comment.
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
nearinOrthographicProjectionshould be different for 2d & 3d.For 2d using
near = -1000allows bevy users to build up scenes using backgroundz = 0, and foreground elementsz > 0similar to css. However in 3dnear = -1000results in objects behind the camera being rendered. Usingnear = 0works for 3d, but forces 2d users to assignz <= 0for rendered elements, putting the background at some arbitrary negative value.There is no common value for
nearthat 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::defaultintodefault_2danddefault_3d.Migration Guide
OrthographicProjection, change..default()to..OrthographicProjection::default_2d()or..OrthographicProjection::default_3d()Example: