UI: Add eyedropper button to camera focus distance #121486

Merged
Falk David merged 8 commits from filedescriptor/blender:eyedropper-focus-distance into main 2024-05-13 11:02:10 +02:00
Member

Blender already had the ability to sample the depth with an eyedropper and fill the focus distance
(see "ui.eyedropper_depth"). But this feature is fairly hidden. You have to hover over the focal_distance property in the camera data panel and then press E.

This patch adds a prop_data_path property to the ui.eyedropper_depth operator to
allow specifying the property that should be filled with the depth value.

The idea for this is taken from wm.radial_control, which also uses this approach to write to a property.

This allows us to add the eyedropper as a button:
image

TODO:

  • Fix the poll function of ui.eyedropper_depth. This poll function was very specific and I noticed that without it, e.g. pressing E in the console editor no longer works.
Blender already had the ability to sample the depth with an eyedropper and fill the focus distance (see `"ui.eyedropper_depth"`). But this feature is fairly hidden. You have to hover over the `focal_distance` property in the camera data panel and then press `E`. This patch adds a `prop_data_path` property to the `ui.eyedropper_depth` operator to allow specifying the property that should be filled with the depth value. The idea for this is taken from `wm.radial_control`, which also uses this approach to write to a property. This allows us to add the eyedropper as a button: ![image](/attachments/1149a1a7-427f-4312-9822-61e0f99a4036) TODO: - [x] Fix the `poll` function of `ui.eyedropper_depth`. This poll function was very specific and I noticed that without it, e.g. pressing `E` in the console editor no longer works.
Falk David added 1 commit 2024-05-06 15:43:07 +02:00
Falk David added this to the User Interface project 2024-05-06 15:43:12 +02:00
Falk David added 1 commit 2024-05-06 17:28:05 +02:00
Falk David changed title from WIP: UI: Add eyedropper button to camera focus distance to UI: Add eyedropper button to camera focus distance 2024-05-07 16:53:58 +02:00
Falk David added 2 commits 2024-05-07 16:53:59 +02:00
Fix operator consuming events
Some checks failed
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
3ae218025a
Falk David requested review from Harley Acheson 2024-05-07 16:56:33 +02:00
Author
Member

@blender-bot build

@blender-bot build
Falk David added 1 commit 2024-05-07 17:12:19 +02:00
Member

You could leave the poll in by adding a coarse test for this situation. You can't get very specific so you'd still need your new (awesome) tests in depthdropper_init, but there might be some utility is having the poll for enabling/disabling buttons.

static bool depthdropper_poll(bContext *C)
{
  PointerRNA ptr;
  PropertyRNA *prop;
  int index_dummy;
  uiBut *but;

  /* check if there's an active button taking depth value */
  if ((CTX_wm_window(C) != nullptr) &&
      (but = UI_context_active_but_prop_get(C, &ptr, &prop, &index_dummy)))
  {
    if (but->icon == ICON_EYEDROPPER) {
      return true;
    }
    if ((but->type == UI_BTYPE_NUM) && (prop != nullptr) &&
        (RNA_property_type(prop) == PROP_FLOAT) &&
        (RNA_property_subtype(prop) & PROP_UNIT_LENGTH) &&
        (RNA_property_array_check(prop) == false))
    {
      return true;
    }
  }
  else {
    RegionView3D *rv3d = CTX_wm_region_view3d(C);
    if (rv3d && rv3d->persp == RV3D_CAMOB) {
      View3D *v3d = CTX_wm_view3d(C);
      if (v3d->camera && v3d->camera->data &&
          BKE_id_is_editable(CTX_data_main(C), static_cast<const ID *>(v3d->camera->data)))
      {
        return true;
      }
    }
  }

  return false;
}

You could leave the poll in by adding a coarse test for this situation. You can't get very specific so you'd still need your new (awesome) tests in depthdropper_init, but there might be some utility is having the poll for enabling/disabling buttons. ```Cpp static bool depthdropper_poll(bContext *C) { PointerRNA ptr; PropertyRNA *prop; int index_dummy; uiBut *but; /* check if there's an active button taking depth value */ if ((CTX_wm_window(C) != nullptr) && (but = UI_context_active_but_prop_get(C, &ptr, &prop, &index_dummy))) { if (but->icon == ICON_EYEDROPPER) { return true; } if ((but->type == UI_BTYPE_NUM) && (prop != nullptr) && (RNA_property_type(prop) == PROP_FLOAT) && (RNA_property_subtype(prop) & PROP_UNIT_LENGTH) && (RNA_property_array_check(prop) == false)) { return true; } } else { RegionView3D *rv3d = CTX_wm_region_view3d(C); if (rv3d && rv3d->persp == RV3D_CAMOB) { View3D *v3d = CTX_wm_view3d(C); if (v3d->camera && v3d->camera->data && BKE_id_is_editable(CTX_data_main(C), static_cast<const ID *>(v3d->camera->data))) { return true; } } } return false; } ```
Author
Member

@Harley But the poll function will always be false for a button next to the focus distance since 1) we're not hovering over a float value (which we are not if we're pressing the eyedropper button), and 2) because the properties editor doesn't have a 3D viewport.

@Harley But the poll function will always be false for a button next to the focus distance since 1) we're not hovering over a float value (which we are not if we're pressing the eyedropper button), and 2) because the properties editor doesn't have a 3D viewport.
Member

@Harley But the poll function will always be false for a button next to the focus distance since 1) we're not hovering over a float value (which we are not if we're pressing the eyedropper button), and 2) because the properties editor doesn't have a 3D viewport.

I swear that I tested the poll function above and it worked correctly with focus distance. If it has a window and an icon of ICON_EYEDROPPER it will return true. That is a little broad but then it still has to go through your improved tests in depthdropper_init.

> @Harley But the poll function will always be false for a button next to the focus distance since 1) we're not hovering over a float value (which we are not if we're pressing the eyedropper button), and 2) because the properties editor doesn't have a 3D viewport. I swear that I tested the poll function above and it worked correctly with focus distance. If it has a window and an icon of ICON_EYEDROPPER it will return true. That is a little broad but then it still has to go through your improved tests in depthdropper_init.
Author
Member

@Harley Oh! I missed the icon case. This whole poll function just seems incredible hackish 😅 But if others are fine with it, I guess it's ok.

@Harley Oh! I missed the icon case. This whole poll function just seems incredible hackish 😅 But if others are fine with it, I guess it's ok.
Member

This whole poll function just seems incredible hackish 😅

Yes, it definitely seems hacky and my change certainly wouldn't help it. I only offered that in case you wanted it.

My own gut feeling is we should do it as you propose here and remove that poll.

> This whole poll function just seems incredible hackish 😅 Yes, it definitely seems hacky and my change certainly wouldn't help it. I only offered that in case you wanted it. My own gut feeling is we should do it as you propose here and remove that poll.
Harley Acheson requested changes 2024-05-10 17:47:27 +02:00
Dismissed
@ -73,1 +77,4 @@
const char *prop_path,
PointerRNA *r_ptr,
PropertyRNA **r_prop)
{
Member

This function could return bool?

This function could return bool?
filedescriptor marked this conversation as resolved
@ -74,0 +84,4 @@
if (r_prop) {
*r_prop = nullptr;
}
return 1;
Member

I'm unsure why this state is returning true. It looks like it would cause problems later if this happened.

I'm unsure why this state is returning true. It looks like it would cause problems later if this happened.
Author
Member

It does catch it later, but you're right, we can just return false here.

It does catch it later, but you're right, we can just return false here.
filedescriptor marked this conversation as resolved
Falk David added 3 commits 2024-05-10 18:30:10 +02:00
Merge branch 'main' into eyedropper-focus-distance
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
19eb39ee14
Falk David requested review from Harley Acheson 2024-05-10 18:30:22 +02:00
Harley Acheson approved these changes 2024-05-10 19:36:04 +02:00
Harley Acheson left a comment
Member

This is awesome. Our ancestors will be singing your praises for generations...

This is awesome. Our ancestors will be singing your praises for generations...
Author
Member

@blender-bot build

@blender-bot build
Falk David merged commit 7f8d4df410 into main 2024-05-13 11:02:10 +02:00
Falk David deleted branch eyedropper-focus-distance 2024-05-13 11:02:12 +02:00
Author
Member
Also added this to the release notes in https://developer.blender.org/docs/release_notes/4.2/user_interface/
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121486
No description provided.