-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node Tools: Add mouse position 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. Pull Request: https://projects.blender.org/blender/blender/pulls/121043
- Loading branch information
1 parent
b306b3b
commit ce224fe
Showing
10 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
source/blender/nodes/geometry/nodes/node_geo_mouse_position.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* SPDX-FileCopyrightText: 2024 Blender Authors | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
|
||
#include "node_geometry_util.hh" | ||
|
||
namespace blender::nodes::node_geo_mouse_position_cc { | ||
|
||
static void node_declare(NodeDeclarationBuilder &b) | ||
{ | ||
b.add_output<decl::Int>("Mouse X").description( | ||
"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"); | ||
b.add_output<decl::Int>("Region Height").description("The total Y size of the region in pixels"); | ||
} | ||
|
||
static void node_geo_exec(GeoNodeExecParams params) | ||
{ | ||
if (!check_tool_context_and_error(params)) { | ||
return; | ||
} | ||
const int2 mouse = params.user_data()->call_data->operator_data->mouse_position; | ||
const int2 size = params.user_data()->call_data->operator_data->region_size; | ||
params.set_output("Mouse X", mouse.x); | ||
params.set_output("Mouse Y", mouse.y); | ||
params.set_output("Region Width", size.x); | ||
params.set_output("Region Height", size.y); | ||
} | ||
|
||
static void node_register() | ||
{ | ||
static bNodeType ntype; | ||
geo_node_type_base(&ntype, GEO_NODE_TOOL_MOUSE_POSITION, "Mouse Position", NODE_CLASS_INPUT); | ||
ntype.declare = node_declare; | ||
ntype.geometry_node_execute = node_geo_exec; | ||
ntype.gather_link_search_ops = search_link_ops_for_tool_node; | ||
nodeRegisterType(&ntype); | ||
} | ||
NOD_REGISTER_NODE(node_register) | ||
|
||
} // namespace blender::nodes::node_geo_mouse_position_cc |