Skip to content

Commit

Permalink
Make the near clipping plane editable in 2D views (#8348)
Browse files Browse the repository at this point in the history
### What
This adjusts the value to now be in physical scene units. I.e. for most
3d scenes in meters, the clip plane will be 10cm, which is a very
reasonable default.

Additionally, this gives users an escape hatch for scenes where the
default clipping plane causes their data to not be visible.

Test script:
```python
import rerun as rr
import rerun.blueprint as rrb
import numpy as np

rr.init("rerun_example_pinhole_perspective", spawn=True)

img = np.zeros((300, 300, 3), dtype=np.uint8)

cam_proj = [152.34006, 0, 175.5, 0, 152.34006, 175.5, 0, 0, 1]

rr.log(
    "world/cam",
    rr.Pinhole(
        image_from_camera=cam_proj, width=300, height=300, image_plane_distance=0.1
    ),
)

rr.log("world/cam", rr.Image(img))

rr.log(
    "world/points",
    rr.Points3D([(0.0, 0.5, 0.1), (0.1, 0.1, 0.3), (-0.1, -0.1, 0.5)], radii=0.025),
)
rr.log_file_from_path("examples/assets/example.gltf")
rr.log("examples/assets", rr.Transform3D(translation=[0, 0, 0.4], scale=0.05))

rr.send_blueprint(
    rrb.Horizontal(
        rrb.Spatial3DView(),
        rrb.Spatial2DView(
            origin="world/cam",
            contents="/**",
            visual_bounds=rrb.VisualBounds2D(
                near_clip_plane=0.01,
            ),
        ),
    )
)
```

### New issues:
- #8373
  • Loading branch information
jleibs authored Dec 9, 2024
1 parent 30298c6 commit 29c1f83
Show file tree
Hide file tree
Showing 25 changed files with 449 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ table VisualBounds2D (
///
/// Use this to control pan & zoom of the view.
range: rerun.blueprint.components.VisualBounds2D ("attr.rerun.component_required", order: 1000);

/// Controls the distance to the near clip plane in 3D scene units.
///
/// Content closer than this distance will not be visible.
near_clip_plane: rerun.blueprint.components.NearClipPlane ("attr.rerun.component_optional", order: 2000);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace rerun.blueprint.components;

// ---

/// Distance to the near clip plane used for `Spatial2DView`.
struct NearClipPlane (
"attr.rerun.scope": "blueprint",
"attr.rust.derive": "Copy, PartialEq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent",
"attr.docs.unreleased"
) {
/// Distance to the near clip plane in 3D scene units.
near_clip_plane: rerun.datatypes.Float32 (order: 100);
}
63 changes: 55 additions & 8 deletions crates/store/re_types/src/blueprint/archetypes/visual_bounds2d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/store/re_types/src/blueprint/components/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions crates/store/re_types/src/blueprint/components/near_clip_plane.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use re_types_core::datatypes::Float32;

use super::NearClipPlane;

impl Default for NearClipPlane {
#[inline]
fn default() -> Self {
// Default near clip plane to reasonable distance for common cameras
Self(Float32(0.1))
}
}
4 changes: 3 additions & 1 deletion crates/viewer/re_component_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ use datatype_uis::{

use re_types::{
blueprint::components::{
BackgroundKind, Corner2D, GridSpacing, LockRangeDuringZoom, MapProvider, ViewFit, Visible,
BackgroundKind, Corner2D, GridSpacing, LockRangeDuringZoom, MapProvider, NearClipPlane,
ViewFit, Visible,
},
components::{
AggregationPolicy, AlbedoFactor, AxisLength, Color, DepthMeter, DrawOrder, FillMode,
Expand Down Expand Up @@ -76,6 +77,7 @@ pub fn create_component_ui_registry() -> re_viewer_context::ComponentUiRegistry
registry.add_singleline_edit_or_view::<ImagePlaneDistance>(edit_f32_zero_to_max);
registry.add_singleline_edit_or_view::<MarkerSize>(edit_ui_points);
registry.add_singleline_edit_or_view::<StrokeWidth>(edit_ui_points);
registry.add_singleline_edit_or_view::<NearClipPlane>(edit_f32_zero_to_max);

// float min-max components:
registry.add_singleline_edit_or_view::<DrawOrder>(edit_f32_min_to_max_float);
Expand Down
Loading

0 comments on commit 29c1f83

Please sign in to comment.