Skip to content
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

Update to Bevy 0.12 #206

Merged
merged 24 commits into from
Mar 12, 2024
Merged

Update to Bevy 0.12 #206

merged 24 commits into from
Mar 12, 2024

Conversation

luca-della-vedova
Copy link
Member

@luca-della-vedova luca-della-vedova commented Feb 16, 2024

New feature implementation

Implemented feature

Closes #192, #128.
Update to Bevy 0.12.

Implementation description

Apart from the usual changed APIs, Bevy 0.12 introduced a virtual rewrite of the asset system that allowed a significant refactor and cleanup of the way we handle assets.

Specifically, the most important feature is support for multiple asset sources, which allows us to split the sources into separate structures, with two main consequences:

  • The asset source logic is a lot more modular, external plugins can register their sources without having to edit a monolythic piece of code.
  • The AssetSource enum is a lot cleaner, we can split out the sources that don't necessarily make sense for models (i.e. Bundled, used for icons and OSMTile used for open street map tiles) and put them in their own asset source.

Specifically for Bundled assets, the new asset system introduced a builtin embedded:// asset source that does exactly the same so we can get rid of more code.

Because of #128, it was necessary to move out of surf. Luckily a new crate came up recently, ehttp which is actively maintained, does the job perfectly fine and is very lightweight (our dependency count decreased by about 100 crates by switching!)

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova luca-della-vedova marked this pull request as draft February 19, 2024 09:41
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova
Copy link
Member Author

There is currently a regression in workcell editor mode where the cursor is always displayed, currently investigating

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova luca-della-vedova marked this pull request as ready for review February 26, 2024 03:12
@luca-della-vedova
Copy link
Member Author

This PR is now ready for review.

Since this migration added a lot more deprecation warnings with the deprecation of event.iter() I took the chance to clear out all the trivial warnings from the codebase so we can avoid introducing new ones (they would get drowned in the 100+ existing warnings).
The only remaining ones now are nameclash collisions (also introduced here, although not breaking, for now) and one unused field that sounded not trivial.

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
luca-della-vedova and others added 2 commits March 6, 2024 10:23
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Michael X. Grey <mxgrey@intrinsic.ai>
Copy link
Collaborator

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just leaving two very minor nitpicks around variable naming and documentation, and one suggestion for us to think about a Model bundle refactor in a future PR.

Thanks for the massive migration effort here, and for staying on top of these valuable developments in Bevy. It's great to see a PR that has an overall negative number of new lines.

@@ -305,7 +309,7 @@ impl FromWorld for CameraControls {
(2, HOVERED_OUTLINE_LAYER),
(3, XRAY_RENDER_LAYER),
]
.map(|(order, layer)| {
.map(|(order, _layer)| {
Copy link
Collaborator

@mxgrey mxgrey Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change actually flagged to me that we have a bug here. Inside this block is a line

.insert(RenderLayers::layer(XRAY_RENDER_LAYER))

That line should've been

.insert(RenderLayers::layer(layer))

As a result we weren't rendering outlines correctly in orthographic mode.

This is a good example of why we need to clean up the warnings in this codebase, so we're not drowning out things that could help us fix bugs 😬

I've pushed a fix for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! I did notice that outline were not rendered in ortographic mode but thought it was due to the top-down perspective, nice to have addressed that

load_context: &'a mut LoadContext<'b>,
uri: &'a str,
) -> Result<AssetSource, SdfError> {
let path = load_context.asset_path().to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes a lot of cognitive load when reading through this function to understand the differences between uri and path, and why they're used differently. It would be nice to give them more distinct variable names (e.g. asset_uri and sdf_model_path) and maybe a little documentation about what's going on here and why, e.g. an example input for each branch to make it clear what kind of case it's covering.

The terseness of the Rust language can be both a blessing and a curse at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I added examples in the documentation and did a minor cleanup (removing one else condition that would never happen) in 3ab3f03

fn spawn_geometry<'a, 'b>(
world: &'a mut World,
geometry: &'a SdfGeometry,
visual_name: &'a str,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be geometry_name since it also gets used for collisions, not just visuals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SdfGeometry::Mesh(mesh) => Some(
world
.spawn(Model {
name: NameInSite(visual_name.to_owned()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NameInSite was meant to represent names that are unique within the site. If I understand correctly this is parsing visual and collision geometries, which doesn't actually align very well with how the Model bundle was originally meant to be used.

We can leave this as-is for now since we don't yet have any particular need for NameInSites to be unique, but perhaps we can think about how to refactor the Model bundle in a future PR. We should probably introduce a NameInModel, or possibly a more general NameInTree { tree: Entity, name: String } component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fully agree, Model served well in the early days of the codebase when each model was a single GLB file but since we started to parse SDFs with hierarchies, include primitive shapes, split of collision and visual meshes, it became very complex.
Ideally the perfect design would allow granularity to encapsulate all the components of a Model into a top level object (for example to know where to fetch a model if it comes from fuel) but at the same time would allow inspecting its parts (toggling visual / collision meshes, plus some other features needed in workcells that work with individual submeshes)

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Copy link
Collaborator

@mxgrey mxgrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the added documentation! It's much more clear what's going on in sdf loading now.

@mxgrey mxgrey merged commit 7c93231 into main Mar 12, 2024
5 checks passed
@mxgrey mxgrey deleted the luca/bevy_0.12 branch March 12, 2024 08:46
reuben-thomas pushed a commit to reuben-thomas/rmf_site that referenced this pull request Jun 17, 2024
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Reuben Thomas <reubenthomas123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants