Skip to content

Commit

Permalink
Paint closest labels on top of labels further away (#5124)
Browse files Browse the repository at this point in the history
`arkit_scenes` is a good test for this

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5124/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5124/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5124/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5124)
- [Docs
preview](https://rerun.io/preview/7a18b744035e22282df68d04268bae0a974ee35a/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/7a18b744035e22282df68d04268bae0a974ee35a/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
emilk authored Feb 8, 2024
1 parent 3db5638 commit ee0c8d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions crates/re_space_view_spatial/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{text::TextWrapping, NumExt, WidgetText};
use egui::{epaint::util::OrderedFloat, text::TextWrapping, NumExt, WidgetText};
use macaw::BoundingBox;

use re_data_ui::{image_meaning_for_entity, item_ui, DataUi};
Expand Down Expand Up @@ -272,7 +272,7 @@ fn size_ui(
}

pub fn create_labels(
labels: &[UiLabel],
mut labels: Vec<UiLabel>,
ui_from_canvas: egui::emath::RectTransform,
eye3d: &Eye,
parent_ui: &egui::Ui,
Expand All @@ -281,11 +281,20 @@ pub fn create_labels(
) -> (Vec<egui::Shape>, Vec<PickableUiRect>) {
re_tracing::profile_function!();

let ui_from_world_3d = eye3d.ui_from_world(*ui_from_canvas.to());

// Closest last (painters algorithm)
labels.sort_by_key(|label| {
if let UiLabelTarget::Position3D(pos) = label.target {
OrderedFloat::try_from(-ui_from_world_3d.transform_point3(pos).z).ok()
} else {
Default::default()
}
});

let mut label_shapes = Vec::with_capacity(labels.len() * 2);
let mut ui_rects = Vec::with_capacity(labels.len());

let ui_from_world_3d = eye3d.ui_from_world(*ui_from_canvas.to());

for label in labels {
let (wrap_width, text_anchor_pos) = match label.target {
UiLabelTarget::Rect(rect) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/ui_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub fn view_2d(

// Create labels now since their shapes participate are added to scene.ui for picking.
let (label_shapes, ui_rects) = create_labels(
&collect_ui_labels(&parts),
collect_ui_labels(&parts),
ui_from_canvas,
&eye,
ui,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub fn view_3d(

// Create labels now since their shapes participate are added to scene.ui for picking.
let (label_shapes, ui_rects) = create_labels(
&collect_ui_labels(&parts),
collect_ui_labels(&parts),
RectTransform::from_to(rect, rect),
&eye,
ui,
Expand Down

0 comments on commit ee0c8d5

Please sign in to comment.