Node Tools: Add mouse position node, wait for cursor option #121043

Merged
Hans Goudey merged 9 commits from HooglyBoogly/blender:node-tools-mouse-position into main 2024-04-26 20:14:36 +02:00
Member

Add a "Mouse Position" node that outputs the location of the mouse
cursor in region space and the overall size of the region, both in pixel
units. Both outputs are integers to help reflect their pixel units.
If there the mouse position is ever accessible in sub-pixels, they can
easily be changed to floats.

Also add a "Wait for Cursor" option similar to the one for some built-in
operators that delay's the operator's execution until there is a mouse
click in the viewport. That way the operator can be called from menus
even though it is interactive. This option is placed in the node editor
header. When there are more options, it will be part of an "Options"
popover panel similar to the existing "Modes" and "types" popovers.

Combined with the viewport transform node, and other nodes like Raycast,
these features can allow making tools that create geometry where you
click in the scene.


image
image

The blend file requires the viewport transform node too.

Add a "Mouse Position" node that outputs the location of the mouse cursor in region space and the overall size of the region, both in pixel units. Both outputs are integers to help reflect their pixel units. If there the mouse position is ever accessible in sub-pixels, they can easily be changed to floats. Also add a "Wait for Cursor" option similar to the one for some built-in operators that delay's the operator's execution until there is a mouse click in the viewport. That way the operator can be called from menus even though it is interactive. This option is placed in the node editor header. When there are more options, it will be part of an "Options" popover panel similar to the existing "Modes" and "types" popovers. Combined with the viewport transform node, and other nodes like Raycast, these features can allow making tools that create geometry where you click in the scene. --- ![image](/attachments/e86b43d2-7cc5-4eeb-8de2-ee2c5408030b) ![image](/attachments/0c9f8e63-97d8-419b-b563-5e890048c66e) The blend file requires the viewport transform node too.
Hans Goudey added 1 commit 2024-04-24 19:12:27 +02:00
e426d2df04 Node Tools: Add mouse potiion node, wait for cursor option
Add a "Mouse Position" node that outputs the location of the mouse
cursor in region space and the overall size of the region, both in pixel
units. Both outputs are integers to help reflect their pixel units.
If there the mouse position is ever accessible in sub-pixels, they can
easily be changed to floats.

Also add a "Wait for Cursor" option similar to the one for some built-in
operators that delay's the operator's execution until there is a mouse
click in the viewport. That way the operator can be called from menus
even though it is interactive. This option is placed in the node editor
header. When there are more options, it will be part of an "Options"
popover panel similar to the existing "Modes" and "types" popovers.

Combined with the viewport transform node, and other nodes like Raycast,
these features can allow making tools that create geometry where you
click in the scene.
Hans Goudey requested review from Jacques Lucke 2024-04-24 19:16:20 +02:00
Hans Goudey added the
Interest
Geometry Nodes
label 2024-04-24 19:16:24 +02:00
Hans Goudey added this to the Nodes & Physics project 2024-04-24 19:16:29 +02:00
Hans Goudey added this to the 4.2 LTS milestone 2024-04-24 19:17:31 +02:00
Hans Goudey added 1 commit 2024-04-24 19:19:10 +02:00
Iliya Katushenock changed title from Node Tools: Add mouse potiion node, wait for cursor option to Node Tools: Add mouse position node, wait for cursor option 2024-04-24 19:24:57 +02:00
First-time contributor

I realize better now how the scope of these additions to user-made tools (camera matrix, etc) is deeper than I thought. In this light, would you not expect to keep count of clicks explicitly? I understand these modal tools are meant to leverage the simulation zone? should the simulation zone provide a "click count" output socket when in "tool" mode? I suppose for this special case you could stall the simulation until the click count reaches 1. But I suppose this would call for a general way to expose listened keys

I realize better now how the scope of these additions to user-made tools (camera matrix, etc) is deeper than I thought. In this light, would you not expect to keep count of clicks explicitly? I understand these modal tools are meant to leverage the simulation zone? should the simulation zone provide a "click count" output socket when in "tool" mode? I suppose for this special case you could stall the simulation until the click count reaches 1. But I suppose this would call for a general way to expose listened keys
Author
Member

There is nothing modal going on yet. That's a separate project that we probably won't work on for a few months. So you only get the one click and mouse position here. I do expect this to be the basis for a lot of the modal interaction like you mention though. For that, the node group would execute in the simulation zone whenever there is an event. The event might be a mouse move or a click, and you could do whatever you want with it.

There is nothing modal going on yet. That's a separate project that we probably won't work on for a few months. So you only get the one click and mouse position here. I do expect this to be the basis for a lot of the modal interaction like you mention though. For that, the node group would execute in the simulation zone whenever there is an event. The event might be a mouse move or a click, and you could do whatever you want with it.
Jacques Lucke requested changes 2024-04-25 11:15:41 +02:00
Jacques Lucke left a comment
Member
  • Why is the size part of this node? Seems quite unrelated. If you want to keep it, it should be more obvious what size this is exactly (region vs. area vs. window vs. screen).
* Why is the size part of this node? Seems quite unrelated. If you want to keep it, it should be more obvious what size this is exactly (region vs. area vs. window vs. screen).
@ -171,6 +171,7 @@ class NODE_HT_header(Header):
if snode.node_tree:
layout.popover(panel="NODE_PT_geometry_node_tool_object_types", text="Types")
layout.popover(panel="NODE_PT_geometry_node_tool_mode", text="Modes")
layout.prop(snode.node_tree, "use_wait_for_cursor")
Member

I think when we talked about this last time, we said that this option should be displayed this prominently. It's kind of unusual to have such a checkbox in a header.

Related meeting notes: https://devtalk.blender.org/t/2024-03-19-nodes-physics-module-meeting/33867
Also note that we mentioned it should be called e.g. "Wait for Click" instead of "Wait for Cursor".

I think when we talked about this last time, we said that this option should be displayed this prominently. It's kind of unusual to have such a checkbox in a header. Related meeting notes: https://devtalk.blender.org/t/2024-03-19-nodes-physics-module-meeting/33867 Also note that we mentioned it should be called e.g. "Wait for Click" instead of "Wait for Cursor".
Author
Member

I mentioned this in the description:

This option is placed in the node editor header. When there are more options, it will be part of an "Options" popover panel similar to the existing "Modes" and "types" popovers.

I could just move it to an options popover already?

Also note that we mentioned it should be called e.g. "Wait for Click" instead of "Wait for Cursor".

I started with that here, but then I thought "Click" sounded wrong for pen or touch input. Not sure.. I'll ask in the UI module to see if others have ideas.

I mentioned this in the description: >This option is placed in the node editor header. When there are more options, it will be part of an "Options" popover panel similar to the existing "Modes" and "types" popovers. I could just move it to an options popover already? > Also note that we mentioned it should be called e.g. "Wait for Click" instead of "Wait for Cursor". I started with that here, but then I thought "Click" sounded wrong for pen or touch input. Not sure.. I'll ask in the UI module to see if others have ideas.
Author
Member

Actually I just renamed it to "Wait for Click". It can always be renamed in the future, and it seems more consistent with existing terminology than I thought.

Actually I just renamed it to "Wait for Click". It can always be renamed in the future, and it seems more consistent with existing terminology than I thought.
HooglyBoogly marked this conversation as resolved
@ -471,2 +472,4 @@
operator_eval_data.self_object_orig = object;
operator_eval_data.scene_orig = scene;
RNA_int_get_array(op->ptr, "mouse_position", operator_eval_data.mouse_position);
operator_eval_data.region_size = int2(region->sizex, region->sizey);
Member

Would be good to check if this still works if the operator is run without ui (as part of a script). Obviously, we can't get a meaningful mouse position and region size in this case, but the operator should still work I think (especially if those inputs are not used in the node group).

Would be good to check if this still works if the operator is run without ui (as part of a script). Obviously, we can't get a meaningful mouse position and region size in this case, but the operator should still work I think (especially if those inputs are not used in the node group).
Author
Member

I don't see why this wouldn't work-- it would just get the default RNA property value which would be 0,0

I don't see why this wouldn't work-- it would just get the default RNA property value which would be 0,0
Member

I'm more talking about region->sizex, not sure if region can be null.

I'm more talking about `region->sizex`, not sure if `region` can be null.
Author
Member

Oh indeed, thanks! I think that's possible in scripts. I'll add a null check and output 0 in that case too.

Oh indeed, thanks! I think that's possible in scripts. I'll add a null check and output 0 in that case too.
HooglyBoogly marked this conversation as resolved
@ -0,0 +8,4 @@
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_output<decl::Int>("Mouse X");
Member

All these sockets need descriptions.
For Y it's especially important because it's not obvious if 0 is at the top or bottom.

All these sockets need descriptions. For Y it's especially important because it's not obvious if 0 is at the top or bottom.
HooglyBoogly marked this conversation as resolved
Author
Member

Why is the size part of this node? Seems quite unrelated. If you want to keep it, it should be more obvious what size this is exactly (region vs. area vs. window vs. screen).

I wouldn't say it's unrelated. For most uses (everything I've thought of anyway) you have to use both the region size and the mouse position. Exposing the two properties is still the most intuitive way to expose the data IMO. It could be separate but I don't really see any benefit

I'll change the name of the output sockets to Region Size X/Y.

> Why is the size part of this node? Seems quite unrelated. If you want to keep it, it should be more obvious what size this is exactly (region vs. area vs. window vs. screen). I wouldn't say it's unrelated. For most uses (everything I've thought of anyway) you have to use both the region size and the mouse position. Exposing the two properties is still the most intuitive way to expose the data IMO. It could be separate but I don't really see any benefit I'll change the name of the output sockets to `Region Size X/Y`.
Member

How about Region Width and Region Height?

How about `Region Width` and `Region Height`?
Hans Goudey added 2 commits 2024-04-26 17:43:23 +02:00
Hans Goudey added 1 commit 2024-04-26 17:45:06 +02:00
Author
Member

How about Region Width and Region Height?

Oh, good idea!

> How about `Region Width` and `Region Height`? Oh, good idea!
Hans Goudey added 2 commits 2024-04-26 17:48:52 +02:00
Hans Goudey added 1 commit 2024-04-26 17:52:26 +02:00
Hans Goudey requested review from Jacques Lucke 2024-04-26 17:53:13 +02:00
Jacques Lucke approved these changes 2024-04-26 18:43:22 +02:00
@ -0,0 +12,4 @@
"The region-space mouse X location, in pixels, increasing from 0 at the left");
b.add_output<decl::Int>("Mouse Y").description(
"The region-space mouse Y location, in pixels, increasing from 0 at the bottom");
b.add_output<decl::Int>("Region Width").description("The total X size of the region in pixels");
Member

Not sure if it's better, but maybe the descriptions should use "width" and "height" too.

Not sure if it's better, but maybe the descriptions should use "width" and "height" too.
Author
Member

It does sound a bit better that way, but I think it feels a little better to follow the typical advice of "don't repeat the name in the description"

It does sound a bit better that way, but I think it feels a little better to follow the typical advice of "don't repeat the name in the description"
JacquesLucke marked this conversation as resolved
Hans Goudey added 1 commit 2024-04-26 19:55:45 +02:00
Hans Goudey merged commit ce224fe401 into main 2024-04-26 20:14:36 +02:00
Hans Goudey deleted branch node-tools-mouse-position 2024-04-26 20:14:39 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
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
EEVEE & Viewport
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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
EEVEE & Viewport
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
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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 Assignees
3 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#121043
No description provided.