2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spnode
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
#include <array>
|
|
|
|
|
#include <cstdlib>
|
2025-05-05 18:09:22 +02:00
|
|
|
#include <fmt/format.h>
|
2013-04-02 03:51:42 +00:00
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "DNA_node_types.h"
|
2020-05-25 10:43:44 +02:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2024-03-05 10:23:11 -05:00
|
|
|
#include "BLI_lasso_2d.hh"
|
2020-04-03 17:38:58 +02:00
|
|
|
#include "BLI_listbase.h"
|
2024-12-04 08:52:37 -05:00
|
|
|
#include "BLI_math_vector.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_rect.h"
|
2013-04-01 15:07:22 +00:00
|
|
|
#include "BLI_string.h"
|
2014-07-04 14:17:54 +02:00
|
|
|
#include "BLI_string_utf8.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2025-05-12 04:37:52 +02:00
|
|
|
#include "BKE_main_invariants.hh"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2025-01-09 20:03:08 +01:00
|
|
|
#include "BKE_node_legacy_types.hh"
|
2022-09-06 11:53:46 -05:00
|
|
|
#include "BKE_node_runtime.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_node_tree_update.hh"
|
2025-01-26 20:08:00 +01:00
|
|
|
#include "BKE_viewer_path.hh"
|
2024-04-12 17:03:18 -04:00
|
|
|
#include "BKE_workspace.hh"
|
2013-01-24 21:57:13 +00:00
|
|
|
|
2022-12-13 12:21:44 +11:00
|
|
|
#include "ED_node.hh" /* own include */
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_select_utils.hh"
|
|
|
|
|
#include "ED_view3d.hh"
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
#include "ED_viewer_path.hh"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_define.hh"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
#include "WM_types.hh"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2023-09-25 10:56:12 +02:00
|
|
|
#include "UI_string_search.hh"
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_view2d.hh"
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
2020-05-11 10:29:41 -03:00
|
|
|
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh" /* own include */
|
2010-01-06 03:00:19 +00:00
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
2021-12-03 16:25:17 -05:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
static bool is_event_over_node_or_socket(const bContext &C, const wmEvent &event);
|
2022-05-18 14:25:05 +10:00
|
|
|
|
2021-01-20 15:15:38 +11:00
|
|
|
/**
|
|
|
|
|
* Function to detect if there is a visible view3d that uses workbench in texture mode.
|
2023-02-12 14:37:16 +11:00
|
|
|
* This function is for fixing #76970 for Blender 2.83. The actual fix should add a mechanism in
|
2020-05-25 10:43:44 +02:00
|
|
|
* the depsgraph that can be used by the draw engines to check if they need to be redrawn.
|
|
|
|
|
*
|
|
|
|
|
* We don't want to add these risky changes this close before releasing 2.83 without good testing
|
|
|
|
|
* hence this workaround. There are still cases were too many updates happen. For example when you
|
|
|
|
|
* have both a Cycles and workbench with textures viewport.
|
2021-01-20 15:15:38 +11:00
|
|
|
*/
|
2020-05-25 10:43:44 +02:00
|
|
|
static bool has_workbench_in_texture_color(const wmWindowManager *wm,
|
|
|
|
|
const Scene *scene,
|
|
|
|
|
const Object *ob)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
|
|
|
|
if (win->scene != scene) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
if (area->spacetype == SPACE_VIEW3D) {
|
2021-06-02 17:19:36 +02:00
|
|
|
const View3D *v3d = (const View3D *)area->spacedata.first;
|
2020-05-25 10:43:44 +02:00
|
|
|
|
|
|
|
|
if (ED_view3d_has_workbench_in_texture_color(scene, ob, v3d)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Public Node Selection API
|
|
|
|
|
* \{ */
|
2010-01-06 03:00:19 +00:00
|
|
|
|
2023-06-03 12:45:12 +02:00
|
|
|
rctf node_frame_rect_inside(const SpaceNode &snode, const bNode &node)
|
2022-01-05 12:32:00 +01:00
|
|
|
{
|
2023-06-03 12:45:12 +02:00
|
|
|
const float margin = 4.0f * NODE_RESIZE_MARGIN * math::max(snode.runtime->aspect, 1.0f);
|
2022-01-05 12:32:00 +01:00
|
|
|
rctf frame_inside = {
|
2024-12-13 16:51:56 +01:00
|
|
|
node.runtime->draw_bounds.xmin,
|
|
|
|
|
node.runtime->draw_bounds.xmax,
|
|
|
|
|
node.runtime->draw_bounds.ymin,
|
|
|
|
|
node.runtime->draw_bounds.ymax,
|
2022-01-05 12:32:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BLI_rctf_pad(&frame_inside, -margin, -margin);
|
|
|
|
|
|
|
|
|
|
return frame_inside;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
bool node_or_socket_isect_event(const bContext &C, const wmEvent &event)
|
2022-05-18 14:25:05 +10:00
|
|
|
{
|
|
|
|
|
return is_event_over_node_or_socket(C, event);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 12:45:12 +02:00
|
|
|
static bool node_frame_select_isect_mouse(const SpaceNode &snode,
|
|
|
|
|
const bNode &node,
|
|
|
|
|
const float2 &mouse)
|
2022-01-05 12:32:00 +01:00
|
|
|
{
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other nodes -
|
|
|
|
|
* would prevent e.g. box selection of nodes inside that frame). */
|
2023-06-03 12:45:12 +02:00
|
|
|
const rctf frame_inside = node_frame_rect_inside(snode, node);
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect_pt(&node.runtime->draw_bounds, mouse.x, mouse.y) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_isect_pt(&frame_inside, mouse.x, mouse.y))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 12:45:12 +02:00
|
|
|
static bNode *node_under_mouse_select(const SpaceNode &snode, const float2 mouse)
|
2010-01-06 03:00:19 +00:00
|
|
|
{
|
2023-10-10 10:57:51 +02:00
|
|
|
for (bNode *node : tree_draw_order_calc_nodes_reversed(*snode.edittree)) {
|
2025-01-09 15:28:57 +01:00
|
|
|
switch (node->type_legacy) {
|
2022-01-05 12:32:00 +01:00
|
|
|
case NODE_FRAME: {
|
2023-06-03 12:45:12 +02:00
|
|
|
if (node_frame_select_isect_mouse(snode, *node, mouse)) {
|
2022-01-05 12:32:00 +01:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect_pt(&node->runtime->draw_bounds, int(mouse.x), int(mouse.y))) {
|
2022-01-05 12:32:00 +01:00
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
return nullptr;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
static bool is_position_over_node_or_socket(SpaceNode &snode, ARegion ®ion, const float2 &mouse)
|
2018-12-20 10:55:30 +01:00
|
|
|
{
|
2024-11-13 14:51:08 +01:00
|
|
|
if (node_under_mouse_select(snode, mouse)) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2023-11-25 15:23:31 +01:00
|
|
|
if (node_find_indicated_socket(snode, region, mouse, SOCK_IN | SOCK_OUT)) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
static bool is_event_over_node_or_socket(const bContext &C, const wmEvent &event)
|
2018-12-20 10:55:30 +01:00
|
|
|
{
|
2022-09-02 16:38:08 -05:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
ARegion ®ion = *CTX_wm_region(&C);
|
2022-03-09 08:36:36 +11:00
|
|
|
|
2022-09-02 14:09:32 -05:00
|
|
|
int2 mval;
|
2022-09-02 16:38:08 -05:00
|
|
|
WM_event_drag_start_mval(&event, ®ion, mval);
|
2022-03-09 08:36:36 +11:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
float2 mouse;
|
|
|
|
|
UI_view2d_region_to_view(®ion.v2d, mval.x, mval.y, &mouse.x, &mouse.y);
|
2023-11-25 15:23:31 +01:00
|
|
|
return is_position_over_node_or_socket(snode, region, mouse);
|
2018-12-20 10:55:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_socket_select(bNode *node, bNodeSocket &sock)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
sock.flag |= SELECT;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* select node too */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag |= SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_socket_deselect(bNode *node, bNodeSocket &sock, const bool deselect_node)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
sock.flag &= ~SELECT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
if (node && deselect_node) {
|
2021-06-02 17:19:36 +02:00
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if no selected sockets remain, also deselect the node */
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) {
|
|
|
|
|
if (input->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, output, &node->outputs) {
|
|
|
|
|
if (output->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
static void node_socket_toggle(bNode *node, bNodeSocket &sock, bool deselect_node)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
if (sock.flag & SELECT) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node_socket_deselect(node, sock, deselect_node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-09 10:16:41 +00:00
|
|
|
node_socket_select(node, sock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2024-05-02 01:43:45 +02:00
|
|
|
bool node_deselect_all(bNodeTree &node_tree)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2024-05-02 01:43:45 +02:00
|
|
|
bool changed = false;
|
2022-12-20 17:14:34 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
changed |= bke::node_set_selected(*node, false);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2024-05-02 01:43:45 +02:00
|
|
|
return changed;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
void node_deselect_all_input_sockets(bNodeTree &node_tree, const bool deselect_nodes)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
|
|
|
|
/* XXX not calling node_socket_deselect here each time, because this does iteration
|
|
|
|
|
* over all node sockets internally to check if the node stays selected.
|
|
|
|
|
* We can do that more efficiently here.
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2021-12-03 16:33:14 -05:00
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
|
|
|
|
|
socket->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* If no selected sockets remain, also deselect the node. */
|
2012-03-09 10:16:41 +00:00
|
|
|
if (deselect_nodes) {
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
|
|
|
|
|
if (socket->flag & SELECT) {
|
|
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
void node_deselect_all_output_sockets(bNodeTree &node_tree, const bool deselect_nodes)
|
2012-03-09 10:16:41 +00:00
|
|
|
{
|
|
|
|
|
/* XXX not calling node_socket_deselect here each time, because this does iteration
|
|
|
|
|
* over all node sockets internally to check if the node stays selected.
|
|
|
|
|
* We can do that more efficiently here.
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2014-02-03 18:55:59 +11:00
|
|
|
bool sel = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
|
|
|
|
|
socket->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if no selected sockets remain, also deselect the node */
|
|
|
|
|
if (deselect_nodes) {
|
2021-12-03 16:33:14 -05:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
|
|
|
|
|
if (socket->flag & SELECT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
sel = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sel) {
|
2012-03-09 10:16:41 +00:00
|
|
|
node->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
void node_select_paired(bNodeTree &node_tree)
|
|
|
|
|
{
|
2024-07-14 12:32:17 +02:00
|
|
|
node_tree.ensure_topology_cache();
|
2023-09-20 17:21:18 +02:00
|
|
|
for (const bke::bNodeZoneType *zone_type : bke::all_zone_types()) {
|
|
|
|
|
for (bNode *input_node : node_tree.nodes_by_type(zone_type->input_idname)) {
|
|
|
|
|
if (bNode *output_node = zone_type->get_corresponding_output(node_tree, *input_node)) {
|
|
|
|
|
if (input_node->flag & NODE_SELECT) {
|
|
|
|
|
output_node->flag |= NODE_SELECT;
|
|
|
|
|
}
|
|
|
|
|
if (output_node->flag & NODE_SELECT) {
|
|
|
|
|
input_node->flag |= NODE_SELECT;
|
|
|
|
|
}
|
2023-07-11 22:36:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.
A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.
The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.
The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
to initialize the simulation state. In later frames these sockets are not
evaluated anymore. The `Delta Time` at the first frame is zero, but the
simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
state of the previous frame. Nodes in the simulation zone can edit that
data in arbitrary ways, also taking into account the `Delta Time`. The new
simulation state has to be passed to the `Simulation Output` node where it
is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
zone are not evaluated, because the `Simulation Output` node can return
the previously cached data directly.
It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.
Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.
There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.
All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.
The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.
Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.
Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNode *> get_selected_nodes(bNodeTree &node_tree)
|
2022-09-06 12:11:04 -05:00
|
|
|
{
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNode *> selected_nodes;
|
2022-09-06 12:11:04 -05:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
|
selected_nodes.add(node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return selected_nodes;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Grouped Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* Return true if we need redraw, otherwise false. */
|
|
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_type(bNodeTree &node_tree, bNode &node_act)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2014-07-05 17:58:21 +02:00
|
|
|
bool changed = false;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2014-07-04 14:17:54 +02:00
|
|
|
if ((node->flag & SELECT) == 0) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == node_act.type_legacy) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2014-07-04 14:17:54 +02:00
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2014-07-04 14:17:54 +02:00
|
|
|
return changed;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_color(bNodeTree &node_tree, bNode &node_act)
|
2014-07-04 14:17:54 +02:00
|
|
|
{
|
|
|
|
|
bool changed = false;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2014-07-04 14:17:54 +02:00
|
|
|
if ((node->flag & SELECT) == 0) {
|
2022-01-18 13:32:36 -06:00
|
|
|
if (compare_v3v3(node->color, node_act.color, 0.005f)) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2014-07-04 14:17:54 +02:00
|
|
|
changed = true;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2014-07-04 14:17:54 +02:00
|
|
|
}
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
static bool node_select_grouped_name(bNodeTree &node_tree, bNode &node_act, const bool from_right)
|
2014-07-04 14:17:54 +02:00
|
|
|
{
|
|
|
|
|
bool changed = false;
|
2020-04-03 16:21:24 +11:00
|
|
|
const uint delims[] = {'.', '-', '_', '\0'};
|
2014-09-24 20:26:21 +02:00
|
|
|
size_t pref_len_act, pref_len_curr;
|
2015-06-27 11:00:47 +02:00
|
|
|
const char *sep, *suf_act, *suf_curr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-27 10:22:29 +02:00
|
|
|
pref_len_act = BLI_str_partition_ex_utf8(
|
2022-01-18 13:32:36 -06:00
|
|
|
node_act.name, nullptr, delims, &sep, &suf_act, from_right);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: in case we are searching for suffix, and found none, use whole name as suffix. */
|
2014-09-24 20:26:21 +02:00
|
|
|
if (from_right && !(sep && suf_act)) {
|
|
|
|
|
pref_len_act = 0;
|
2022-01-18 13:32:36 -06:00
|
|
|
suf_act = node_act.name;
|
2014-09-24 20:26:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2014-09-24 20:26:21 +02:00
|
|
|
if (node->flag & SELECT) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-06-27 10:22:29 +02:00
|
|
|
pref_len_curr = BLI_str_partition_ex_utf8(
|
2021-06-02 17:19:36 +02:00
|
|
|
node->name, nullptr, delims, &sep, &suf_curr, from_right);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-24 20:26:21 +02:00
|
|
|
/* Same as with active node name! */
|
|
|
|
|
if (from_right && !(sep && suf_curr)) {
|
|
|
|
|
pref_len_curr = 0;
|
|
|
|
|
suf_curr = node->name;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-09-24 20:26:21 +02:00
|
|
|
if ((from_right && STREQ(suf_act, suf_curr)) ||
|
|
|
|
|
(!from_right && (pref_len_act == pref_len_curr) &&
|
2022-01-18 13:32:36 -06:00
|
|
|
STREQLEN(node_act.name, node->name, pref_len_act)))
|
|
|
|
|
{
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2014-09-24 20:26:21 +02:00
|
|
|
changed = true;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
return changed;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
enum {
|
|
|
|
|
NODE_SELECT_GROUPED_TYPE = 0,
|
|
|
|
|
NODE_SELECT_GROUPED_COLOR = 1,
|
|
|
|
|
NODE_SELECT_GROUPED_PREFIX = 2,
|
|
|
|
|
NODE_SELECT_GROUPED_SUFIX = 3,
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_grouped_exec(bContext *C, wmOperator *op)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2025-02-19 13:44:11 +01:00
|
|
|
bNode *node_act = bke::node_get_active(*snode.edittree);
|
2021-03-18 16:47:14 +01:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
if (node_act == nullptr) {
|
2021-03-18 16:47:14 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
bool changed = false;
|
|
|
|
|
const bool extend = RNA_boolean_get(op->ptr, "extend");
|
|
|
|
|
const int type = RNA_enum_get(op->ptr, "type");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
if (!extend) {
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2014-07-04 14:17:54 +02:00
|
|
|
}
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node_act, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
switch (type) {
|
|
|
|
|
case NODE_SELECT_GROUPED_TYPE:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_type(node_tree, *node_act);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_COLOR:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_color(node_tree, *node_act);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_PREFIX:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_name(node_tree, *node_act, false);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
case NODE_SELECT_GROUPED_SUFIX:
|
2022-01-18 13:32:36 -06:00
|
|
|
changed = node_select_grouped_name(node_tree, *node_act, true);
|
2014-07-04 14:17:54 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2011-12-18 12:51:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
if (changed) {
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2014-07-04 14:17:54 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
void NODE_OT_select_grouped(wmOperatorType *ot)
|
|
|
|
|
{
|
2021-08-25 17:59:47 +10:00
|
|
|
PropertyRNA *prop;
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem prop_select_grouped_types[] = {
|
2014-07-04 14:17:54 +02:00
|
|
|
{NODE_SELECT_GROUPED_TYPE, "TYPE", 0, "Type", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_COLOR, "COLOR", 0, "Color", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_PREFIX, "PREFIX", 0, "Prefix", ""},
|
|
|
|
|
{NODE_SELECT_GROUPED_SUFIX, "SUFFIX", 0, "Suffix", ""},
|
2021-06-02 17:19:36 +02:00
|
|
|
{0, nullptr, 0, nullptr, nullptr},
|
2014-07-04 14:17:54 +02:00
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Grouped";
|
|
|
|
|
ot->description = "Select nodes with similar properties";
|
|
|
|
|
ot->idname = "NODE_OT_select_grouped";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2014-07-04 14:17:54 +02:00
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
|
ot->exec = node_select_grouped_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-04 14:17:54 +02:00
|
|
|
/* properties */
|
2021-08-25 17:59:47 +10:00
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
|
"extend",
|
|
|
|
|
false,
|
|
|
|
|
"Extend",
|
|
|
|
|
"Extend selection instead of deselecting everything first");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2014-07-04 14:17:54 +02:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select (Cursor Pick) Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void node_select_single(bContext &C, bNode &node)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
Main *bmain = CTX_data_main(&C);
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(&C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2021-12-03 16:25:17 -05:00
|
|
|
const Object *ob = CTX_data_active_object(&C);
|
|
|
|
|
const Scene *scene = CTX_data_scene(&C);
|
|
|
|
|
const wmWindowManager *wm = CTX_wm_manager(&C);
|
2020-05-25 10:43:44 +02:00
|
|
|
bool active_texture_changed = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node_iter : node_tree.all_nodes()) {
|
2022-01-18 13:32:36 -06:00
|
|
|
if (node_iter != &node) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node_iter, false);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(node, true);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-01-18 13:32:36 -06:00
|
|
|
ED_node_set_active(bmain, &snode, &node_tree, &node, &active_texture_changed);
|
|
|
|
|
ED_node_set_active_viewer_key(&snode);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2020-05-25 10:43:44 +02:00
|
|
|
if (active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) {
|
2024-02-19 15:54:08 +01:00
|
|
|
DEG_id_tag_update(&node_tree.id, ID_RECALC_SYNC_TO_EVAL);
|
2020-05-25 10:43:44 +02:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
WM_event_add_notifier(&C, NC_NODE | NA_SELECTED, nullptr);
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
static bool node_mouse_select(bContext *C,
|
|
|
|
|
wmOperator *op,
|
2022-09-02 14:09:32 -05:00
|
|
|
const int2 mval,
|
2025-05-08 13:50:14 +10:00
|
|
|
const SelectPick_Params ¶ms)
|
2008-12-28 00:08:34 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
Main &bmain = *CTX_data_main(C);
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
2022-12-20 17:14:34 -06:00
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2021-12-03 16:25:17 -05:00
|
|
|
ARegion ®ion = *CTX_wm_region(C);
|
2020-05-25 10:43:44 +02:00
|
|
|
const Object *ob = CTX_data_active_object(C);
|
|
|
|
|
const Scene *scene = CTX_data_scene(C);
|
|
|
|
|
const wmWindowManager *wm = CTX_wm_manager(C);
|
2023-01-03 13:34:51 -05:00
|
|
|
bNode *node = nullptr;
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *sock = nullptr;
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Always do socket_select when extending selection. */
|
2025-05-08 13:50:14 +10:00
|
|
|
const bool socket_select = (params.sel_op == SEL_OP_XOR) ||
|
2022-05-10 22:57:00 +10:00
|
|
|
RNA_boolean_get(op->ptr, "socket_select");
|
|
|
|
|
bool changed = false;
|
|
|
|
|
bool found = false;
|
|
|
|
|
bool node_was_selected = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Get mouse coordinates in view2d space. */
|
2022-09-02 16:38:08 -05:00
|
|
|
float2 cursor;
|
2022-09-02 14:09:32 -05:00
|
|
|
UI_view2d_region_to_view(®ion.v2d, mval.x, mval.y, &cursor.x, &cursor.y);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* First do socket selection, these generally overlap with nodes. */
|
2019-03-22 17:03:02 +01:00
|
|
|
if (socket_select) {
|
2022-05-10 22:57:00 +10:00
|
|
|
/* NOTE: unlike nodes #SelectPick_Params isn't fully supported. */
|
2025-05-08 13:50:14 +10:00
|
|
|
const bool extend = (params.sel_op == SEL_OP_XOR);
|
2023-11-25 15:23:31 +01:00
|
|
|
sock = node_find_indicated_socket(snode, region, cursor, SOCK_IN);
|
2023-01-03 13:34:51 -05:00
|
|
|
if (sock) {
|
|
|
|
|
node = &sock->owner_node();
|
2022-05-10 22:57:00 +10:00
|
|
|
found = true;
|
|
|
|
|
node_was_selected = node->flag & SELECT;
|
|
|
|
|
|
2019-05-06 20:34:01 +02:00
|
|
|
/* NOTE: SOCK_IN does not take into account the extend case...
|
|
|
|
|
* This feature is not really used anyway currently? */
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_toggle(node, *sock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
if (!changed) {
|
2023-11-25 15:23:31 +01:00
|
|
|
sock = node_find_indicated_socket(snode, region, cursor, SOCK_OUT);
|
2023-01-03 13:34:51 -05:00
|
|
|
if (sock) {
|
|
|
|
|
node = &sock->owner_node();
|
|
|
|
|
found = true;
|
|
|
|
|
node_was_selected = node->flag & SELECT;
|
|
|
|
|
|
|
|
|
|
if (sock->flag & SELECT) {
|
|
|
|
|
if (extend) {
|
|
|
|
|
node_socket_deselect(node, *sock, true);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
else {
|
|
|
|
|
/* Only allow one selected output per node, for sensible linking.
|
|
|
|
|
* Allow selecting outputs from different nodes though, if extend is true. */
|
|
|
|
|
for (bNodeSocket *tsock : node->output_sockets()) {
|
2019-05-06 20:34:01 +02:00
|
|
|
if (tsock == sock) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
node_socket_deselect(node, *tsock, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
changed = true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
if (!extend) {
|
|
|
|
|
for (bNode *tnode : node_tree.all_nodes()) {
|
|
|
|
|
if (tnode == node) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for (bNodeSocket *tsock : tnode->output_sockets()) {
|
|
|
|
|
node_socket_deselect(tnode, *tsock, true);
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-03 13:34:51 -05:00
|
|
|
node_socket_select(node, *sock);
|
|
|
|
|
changed = true;
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-22 17:03:02 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-23 16:23:44 +02:00
|
|
|
if (!sock) {
|
2022-05-10 22:57:00 +10:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Find the closest visible node. */
|
2023-06-03 12:45:12 +02:00
|
|
|
node = node_under_mouse_select(snode, cursor);
|
2022-05-10 22:57:00 +10:00
|
|
|
found = (node != nullptr);
|
|
|
|
|
node_was_selected = node && (node->flag & SELECT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-08 13:50:14 +10:00
|
|
|
if (params.sel_op == SEL_OP_SET) {
|
|
|
|
|
if ((found && params.select_passthrough) && (node->flag & SELECT)) {
|
2022-05-10 22:57:00 +10:00
|
|
|
found = false;
|
2021-03-24 12:13:14 +01:00
|
|
|
}
|
2025-05-08 13:50:14 +10:00
|
|
|
else if (found || params.deselect_all) {
|
2022-05-10 22:57:00 +10:00
|
|
|
/* Deselect everything. */
|
2024-05-02 01:43:45 +02:00
|
|
|
changed = node_deselect_all(node_tree);
|
2019-05-14 15:51:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
if (found) {
|
2025-05-08 13:50:14 +10:00
|
|
|
switch (params.sel_op) {
|
2023-01-03 20:02:01 -05:00
|
|
|
case SEL_OP_ADD:
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
break;
|
2023-01-03 20:02:01 -05:00
|
|
|
case SEL_OP_SUB:
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, false);
|
2022-05-10 22:57:00 +10:00
|
|
|
break;
|
|
|
|
|
case SEL_OP_XOR: {
|
|
|
|
|
/* Check active so clicking on an inactive node activates it. */
|
|
|
|
|
bool is_selected = (node->flag & NODE_SELECT) && (node->flag & NODE_ACTIVE);
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, !is_selected);
|
2022-05-10 22:57:00 +10:00
|
|
|
break;
|
|
|
|
|
}
|
2023-01-03 20:02:01 -05:00
|
|
|
case SEL_OP_SET:
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2022-05-10 22:57:00 +10:00
|
|
|
break;
|
2023-01-03 20:02:01 -05:00
|
|
|
case SEL_OP_AND:
|
|
|
|
|
/* Doesn't make sense for picking. */
|
|
|
|
|
BLI_assert_unreachable();
|
2022-05-10 22:57:00 +10:00
|
|
|
break;
|
2013-03-18 18:25:05 +00:00
|
|
|
}
|
2022-05-10 22:57:00 +10:00
|
|
|
|
|
|
|
|
changed = true;
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
if (RNA_boolean_get(op->ptr, "clear_viewer")) {
|
|
|
|
|
if (node == nullptr) {
|
|
|
|
|
/* Disable existing active viewer. */
|
|
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
|
|
|
|
BKE_viewer_path_clear(&workspace->viewer_path);
|
|
|
|
|
WM_event_add_notifier(C, NC_VIEWER_PATH, nullptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 18:21:04 -05:00
|
|
|
if (!(changed || found)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2022-09-12 18:21:04 -05:00
|
|
|
bool active_texture_changed = false;
|
|
|
|
|
bool viewer_node_changed = false;
|
2025-05-08 13:50:14 +10:00
|
|
|
if ((node != nullptr) && (node_was_selected == false || params.select_passthrough == false)) {
|
2025-01-09 15:28:57 +01:00
|
|
|
viewer_node_changed = (node->flag & NODE_DO_OUTPUT) == 0 &&
|
|
|
|
|
node->type_legacy == GEO_NODE_VIEWER;
|
2022-09-12 18:21:04 -05:00
|
|
|
ED_node_set_active(&bmain, &snode, snode.edittree, node, &active_texture_changed);
|
|
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (node != nullptr && node->type_legacy == GEO_NODE_VIEWER) {
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
viewer_path::activate_geometry_node(bmain, snode, *node);
|
2022-09-06 12:13:15 -05:00
|
|
|
}
|
2022-09-12 18:21:04 -05:00
|
|
|
ED_node_set_active_viewer_key(&snode);
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2022-09-12 18:21:04 -05:00
|
|
|
if ((active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) ||
|
|
|
|
|
viewer_node_changed)
|
|
|
|
|
{
|
2024-02-19 15:54:08 +01:00
|
|
|
DEG_id_tag_update(&snode.edittree->id, ID_RECALC_SYNC_TO_EVAL);
|
2022-09-12 18:21:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_NODE_GIZMO, nullptr);
|
2022-09-06 12:13:15 -05:00
|
|
|
|
2025-05-12 04:37:52 +02:00
|
|
|
BKE_main_ensure_invariants(bmain, node_tree.id);
|
|
|
|
|
|
2022-09-12 18:21:04 -05:00
|
|
|
return true;
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_exec(bContext *C, wmOperator *op)
|
2008-12-28 00:08:34 +00:00
|
|
|
{
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Get settings from RNA properties for operator. */
|
2022-09-02 14:09:32 -05:00
|
|
|
int2 mval;
|
2022-05-10 22:57:00 +10:00
|
|
|
RNA_int_get_array(op->ptr, "location", mval);
|
|
|
|
|
|
2025-05-08 13:50:14 +10:00
|
|
|
const SelectPick_Params params = ED_select_pick_params_from_operator(op->ptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Perform the selection. */
|
2025-05-08 13:50:14 +10:00
|
|
|
const bool changed = node_mouse_select(C, op, mval, params);
|
2019-05-14 15:51:49 +02:00
|
|
|
|
2022-05-10 22:57:00 +10:00
|
|
|
if (changed) {
|
|
|
|
|
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
|
|
|
|
|
}
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Nothing selected, just pass through. */
|
2022-05-10 22:57:00 +10:00
|
|
|
return OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2022-05-10 22:57:00 +10:00
|
|
|
{
|
|
|
|
|
RNA_int_set_array(op->ptr, "location", event->mval);
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
const wmOperatorStatus retval = node_select_exec(C, op);
|
2022-05-10 22:57:00 +10:00
|
|
|
|
|
|
|
|
return WM_operator_flag_only_pass_through_on_press(retval, event);
|
2019-05-14 15:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
void NODE_OT_select(wmOperatorType *ot)
|
|
|
|
|
{
|
2019-10-04 15:19:30 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Select";
|
|
|
|
|
ot->idname = "NODE_OT_select";
|
|
|
|
|
ot->description = "Select the node under the cursor";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2013-07-12 08:31:39 +00:00
|
|
|
ot->exec = node_select_exec;
|
2022-05-10 22:57:00 +10:00
|
|
|
ot->invoke = node_select_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2022-05-13 16:09:04 +10:00
|
|
|
ot->get_name = ED_select_pick_get_name;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-20 04:19:57 +00:00
|
|
|
/* properties */
|
2022-05-10 22:57:00 +10:00
|
|
|
WM_operator_properties_mouse_select(ot);
|
|
|
|
|
|
|
|
|
|
prop = RNA_def_int_vector(ot->srna,
|
|
|
|
|
"location",
|
|
|
|
|
2,
|
2022-05-15 19:04:07 +02:00
|
|
|
nullptr,
|
2022-05-10 22:57:00 +10:00
|
|
|
INT_MIN,
|
|
|
|
|
INT_MAX,
|
|
|
|
|
"Location",
|
|
|
|
|
"Mouse location",
|
|
|
|
|
INT_MIN,
|
|
|
|
|
INT_MAX);
|
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
|
|
|
|
|
2019-03-22 17:03:02 +01:00
|
|
|
RNA_def_boolean(ot->srna, "socket_select", false, "Socket Select", "");
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"clear_viewer",
|
|
|
|
|
false,
|
|
|
|
|
"Clear Viewer",
|
|
|
|
|
"Deactivate geometry nodes viewer when clicking in empty space");
|
2008-12-28 00:08:34 +00:00
|
|
|
}
|
2009-01-05 23:53:04 +00:00
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Box Select Operator
|
|
|
|
|
* \{ */
|
2009-01-05 23:53:04 +00:00
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_box_select_exec(bContext *C, wmOperator *op)
|
2009-01-05 23:53:04 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
|
|
|
|
const ARegion ®ion = *CTX_wm_region(C);
|
2009-01-05 23:53:04 +00:00
|
|
|
rctf rectf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-21 16:47:16 +10:00
|
|
|
WM_operator_properties_border_to_rctf(op, &rectf);
|
2022-01-18 13:32:36 -06:00
|
|
|
UI_view2d_region_to_view_rctf(®ion.v2d, &rectf, &rectf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eSelectOp sel_op = (eSelectOp)RNA_enum_get(op->ptr, "mode");
|
2019-03-07 20:33:57 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2019-03-07 20:33:57 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2022-01-05 12:32:00 +01:00
|
|
|
bool is_inside = false;
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
switch (node->type_legacy) {
|
2022-01-05 12:32:00 +01:00
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of other nodes inside that frame. */
|
2023-06-03 12:45:12 +02:00
|
|
|
const rctf frame_inside = node_frame_rect_inside(snode, *node);
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect(&rectf, &node->runtime->draw_bounds, nullptr) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_inside_rctf(&frame_inside, &rectf))
|
|
|
|
|
{
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2022-01-05 12:32:00 +01:00
|
|
|
is_inside = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2024-12-13 16:51:56 +01:00
|
|
|
is_inside = BLI_rctf_isect(&rectf, &node->runtime->draw_bounds, nullptr);
|
2022-01-05 12:32:00 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2015-10-24 01:06:28 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-16 21:58:51 +11:00
|
|
|
if (is_inside) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2009-01-05 23:53:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-05 23:53:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_box_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2010-01-06 03:00:19 +00:00
|
|
|
{
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool tweak = RNA_boolean_get(op->ptr, "tweak");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
if (tweak && is_event_over_node_or_socket(*C, *event)) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
return WM_gesture_box_invoke(C, op, event);
|
2010-01-06 03:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-05 10:27:04 +10:00
|
|
|
void NODE_OT_select_box(wmOperatorType *ot)
|
2009-01-05 23:53:04 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->name = "Box Select";
|
|
|
|
|
ot->idname = "NODE_OT_select_box";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->description = "Use box selection to select nodes";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->invoke = node_box_select_invoke;
|
|
|
|
|
ot->exec = node_box_select_exec;
|
|
|
|
|
ot->modal = WM_gesture_box_modal;
|
|
|
|
|
ot->cancel = WM_gesture_box_cancel;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 20:33:57 +11:00
|
|
|
/* properties */
|
2010-01-06 03:00:19 +00:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"tweak",
|
2021-06-02 17:19:36 +02:00
|
|
|
false,
|
2010-01-06 03:00:19 +00:00
|
|
|
"Tweak",
|
2021-02-24 13:25:44 -06:00
|
|
|
"Only activate when mouse is not over a node (useful for tweak gesture)");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 20:33:57 +11:00
|
|
|
WM_operator_properties_gesture_box(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2009-01-16 23:53:11 +00:00
|
|
|
}
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Circle Select Operator
|
|
|
|
|
* \{ */
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_circleselect_exec(bContext *C, wmOperator *op)
|
2013-11-06 19:21:42 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2022-12-20 17:14:34 -06:00
|
|
|
bNodeTree &node_tree = *snode->edittree;
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2017-10-16 21:58:51 +11:00
|
|
|
int x, y, radius;
|
2022-09-02 14:09:32 -05:00
|
|
|
float2 offset;
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2025-01-26 20:08:00 +01:00
|
|
|
float zoom = float(BLI_rcti_size_x(®ion->winrct)) / BLI_rctf_size_x(®ion->v2d.cur);
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eSelectOp sel_op = ED_select_op_modal(
|
|
|
|
|
(eSelectOp)RNA_enum_get(op->ptr, "mode"),
|
|
|
|
|
WM_gesture_is_modal_first((const wmGesture *)op->customdata));
|
2019-03-05 22:26:45 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2019-03-05 22:26:45 +11:00
|
|
|
}
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
/* get operator properties */
|
|
|
|
|
x = RNA_int_get(op->ptr, "x");
|
|
|
|
|
y = RNA_int_get(op->ptr, "y");
|
|
|
|
|
radius = RNA_int_get(op->ptr, "radius");
|
|
|
|
|
|
2022-09-02 14:09:32 -05:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, x, y, &offset.x, &offset.y);
|
2013-11-06 19:21:42 +00:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
switch (node->type_legacy) {
|
2022-01-05 12:32:00 +01:00
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of _only_ other nodes inside that frame. */
|
2023-06-03 12:45:12 +02:00
|
|
|
rctf frame_inside = node_frame_rect_inside(*snode, *node);
|
2022-09-25 18:33:28 +10:00
|
|
|
const float radius_adjusted = float(radius) / zoom;
|
2022-01-05 12:32:00 +01:00
|
|
|
BLI_rctf_pad(&frame_inside, -2.0f * radius_adjusted, -2.0f * radius_adjusted);
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect_circle(&node->runtime->draw_bounds, offset, radius_adjusted) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_isect_circle(&frame_inside, offset, radius_adjusted))
|
|
|
|
|
{
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2022-01-05 12:32:00 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect_circle(&node->runtime->draw_bounds, offset, radius / zoom)) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2022-01-05 12:32:00 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-11-06 19:21:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_circle(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Circle Select";
|
|
|
|
|
ot->idname = "NODE_OT_select_circle";
|
|
|
|
|
ot->description = "Use circle selection to select nodes";
|
|
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2013-11-06 19:21:42 +00:00
|
|
|
ot->invoke = WM_gesture_circle_invoke;
|
|
|
|
|
ot->exec = node_circleselect_exec;
|
|
|
|
|
ot->modal = WM_gesture_circle_modal;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2022-05-13 16:09:04 +10:00
|
|
|
ot->get_name = ED_select_circle_get_name;
|
2013-11-06 19:21:42 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
2017-10-16 15:32:09 +11:00
|
|
|
/* properties */
|
2019-03-05 22:26:45 +11:00
|
|
|
WM_operator_properties_gesture_circle(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2013-11-06 19:21:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Lasso Select Operator
|
|
|
|
|
* \{ */
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_lasso_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2018-12-20 10:55:30 +01:00
|
|
|
{
|
|
|
|
|
const bool tweak = RNA_boolean_get(op->ptr, "tweak");
|
|
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
if (tweak && is_event_over_node_or_socket(*C, *event)) {
|
2018-12-20 10:55:30 +01:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WM_gesture_lasso_invoke(C, op, event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 11:29:04 -05:00
|
|
|
static bool do_lasso_select_node(bContext *C, const Span<int2> mcoords, eSelectOp sel_op)
|
2012-08-22 13:34:06 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2022-12-20 17:14:34 -06:00
|
|
|
bNodeTree &node_tree = *snode->edittree;
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
|
|
|
|
rcti rect;
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2019-03-07 23:41:32 +11:00
|
|
|
const bool select = (sel_op != SEL_OP_SUB);
|
|
|
|
|
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2019-03-07 23:41:32 +11:00
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Get rectangle from operator. */
|
2024-03-05 11:29:04 -05:00
|
|
|
BLI_lasso_boundbox(&rect, mcoords);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2022-12-20 17:14:34 -06:00
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2019-03-07 23:41:32 +11:00
|
|
|
if (select && (node->flag & NODE_SELECT)) {
|
2018-05-13 09:37:53 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
switch (node->type_legacy) {
|
2022-01-05 12:32:00 +01:00
|
|
|
case NODE_FRAME: {
|
|
|
|
|
/* Frame nodes are selectable by their borders (including their whole rect - as for other
|
|
|
|
|
* nodes - would prevent selection of other nodes inside that frame. */
|
|
|
|
|
rctf rectf;
|
|
|
|
|
BLI_rctf_rcti_copy(&rectf, &rect);
|
|
|
|
|
UI_view2d_region_to_view_rctf(®ion->v2d, &rectf, &rectf);
|
2023-06-03 12:45:12 +02:00
|
|
|
const rctf frame_inside = node_frame_rect_inside(*snode, *node);
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_isect(&rectf, &node->runtime->draw_bounds, nullptr) &&
|
2022-01-05 12:32:00 +01:00
|
|
|
!BLI_rctf_inside_rctf(&frame_inside, &rectf))
|
|
|
|
|
{
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2022-01-05 12:32:00 +01:00
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: {
|
2022-09-02 14:09:32 -05:00
|
|
|
int2 screen_co;
|
2024-12-13 16:51:56 +01:00
|
|
|
const float2 center = {BLI_rctf_cent_x(&node->runtime->draw_bounds),
|
|
|
|
|
BLI_rctf_cent_y(&node->runtime->draw_bounds)};
|
2022-01-05 12:32:00 +01:00
|
|
|
|
|
|
|
|
/* marker in screen coords */
|
|
|
|
|
if (UI_view2d_view_to_region_clip(
|
2022-09-02 14:09:32 -05:00
|
|
|
®ion->v2d, center.x, center.y, &screen_co.x, &screen_co.y) &&
|
|
|
|
|
BLI_rcti_isect_pt(&rect, screen_co.x, screen_co.y) &&
|
2024-03-05 11:29:04 -05:00
|
|
|
BLI_lasso_is_point_inside(mcoords, screen_co.x, screen_co.y, INT_MAX))
|
2022-09-02 14:09:32 -05:00
|
|
|
{
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, select);
|
2022-01-05 12:32:00 +01:00
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
if (changed) {
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_lasso_select_exec(bContext *C, wmOperator *op)
|
2012-08-22 13:34:06 +00:00
|
|
|
{
|
2024-03-05 11:29:04 -05:00
|
|
|
const Array<int2> mcoords = WM_gesture_lasso_path_to_array(C, op);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2024-03-05 11:29:04 -05:00
|
|
|
if (mcoords.is_empty()) {
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
2019-03-07 23:41:32 +11:00
|
|
|
|
2024-03-05 11:29:04 -05:00
|
|
|
const eSelectOp sel_op = (eSelectOp)RNA_enum_get(op->ptr, "mode");
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2024-03-05 11:29:04 -05:00
|
|
|
do_lasso_select_node(C, mcoords, sel_op);
|
2012-08-22 13:34:06 +00:00
|
|
|
|
2024-03-05 11:29:04 -05:00
|
|
|
return OPERATOR_FINISHED;
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_lasso(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Lasso Select";
|
|
|
|
|
ot->description = "Select nodes using lasso selection";
|
|
|
|
|
ot->idname = "NODE_OT_select_lasso";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2018-12-20 10:55:30 +01:00
|
|
|
ot->invoke = node_lasso_select_invoke;
|
2012-08-22 13:34:06 +00:00
|
|
|
ot->modal = WM_gesture_lasso_modal;
|
|
|
|
|
ot->exec = node_lasso_select_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
ot->cancel = WM_gesture_lasso_cancel;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* flags */
|
2021-09-17 12:09:26 +10:00
|
|
|
ot->flag = OPTYPE_UNDO | OPTYPE_DEPENDS_ON_CURSOR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-22 13:34:06 +00:00
|
|
|
/* properties */
|
2018-12-20 10:55:30 +01:00
|
|
|
RNA_def_boolean(ot->srna,
|
|
|
|
|
"tweak",
|
2021-06-02 17:19:36 +02:00
|
|
|
false,
|
2018-12-20 10:55:30 +01:00
|
|
|
"Tweak",
|
2021-02-24 13:25:44 -06:00
|
|
|
"Only activate when mouse is not over a node (useful for tweak gesture)");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-07 23:41:32 +11:00
|
|
|
WM_operator_properties_gesture_lasso(ot);
|
|
|
|
|
WM_operator_properties_select_operation_simple(ot);
|
2012-08-22 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name (De)select All Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2022-09-06 11:53:46 -05:00
|
|
|
static bool any_node_selected(const bNodeTree &node_tree)
|
|
|
|
|
{
|
|
|
|
|
for (const bNode *node : node_tree.all_nodes()) {
|
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_all_exec(bContext *C, wmOperator *op)
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
2022-09-06 11:53:46 -05:00
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
|
|
|
|
|
|
|
|
|
node_tree.ensure_topology_cache();
|
|
|
|
|
|
2012-08-01 13:28:19 +00:00
|
|
|
int action = RNA_enum_get(op->ptr, "action");
|
2022-09-06 11:53:46 -05:00
|
|
|
if (action == SEL_TOGGLE) {
|
|
|
|
|
if (any_node_selected(node_tree)) {
|
|
|
|
|
action = SEL_DESELECT;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
action = SEL_SELECT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2022-09-06 11:53:46 -05:00
|
|
|
switch (action) {
|
|
|
|
|
case SEL_SELECT:
|
|
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, true);
|
2022-09-06 11:53:46 -05:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SEL_DESELECT:
|
2022-12-20 17:14:34 -06:00
|
|
|
node_deselect_all(node_tree);
|
2022-09-06 11:53:46 -05:00
|
|
|
break;
|
|
|
|
|
case SEL_INVERT:
|
|
|
|
|
for (bNode *node : node_tree.all_nodes()) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(*node, !(node->flag & SELECT));
|
2022-09-06 11:53:46 -05:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-08-01 13:28:19 +00:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
Geometry Nodes: support attaching gizmos to input values
This adds support for attaching gizmos for input values. The goal is to make it
easier for users to set input values intuitively in the 3D viewport.
We went through multiple different possible designs until we settled on the one
implemented here. We picked it for it's flexibility and ease of use when using
geometry node assets. The core principle in the design is that **gizmos are
attached to existing input values instead of being the input value themselves**.
This actually fits the existing concept of gizmos in Blender well, but may be a
bit unintutitive in a node setup at first. The attachment is done using links in
the node editor.
The most basic usage of the node is to link a Value node to the new Linear Gizmo
node. This attaches the gizmo to the input value and allows you to change it
from the 3D view. The attachment is indicated by the gizmo icon in the sockets
which are controlled by a gizmo as well as the back-link (notice the double
link) when the gizmo is active.
The core principle makes it straight forward to control the same node setup from
the 3D view with gizmos, or by manually changing input values, or by driving the
input values procedurally.
If the input value is controlled indirectly by other inputs, it's often possible
to **automatically propagate** the gizmo to the actual input.
Backpropagation does not work for all nodes, although more nodes can be
supported over time.
This patch adds the first three gizmo nodes which cover common use cases:
* **Linear Gizmo**: Creates a gizmo that controls a float or integer value using
a linear movement of e.g. an arrow in the 3D viewport.
* **Dial Gizmo**: Creates a circular gizmo in the 3D viewport that can be
rotated to change the attached angle input.
* **Transform Gizmo**: Creates a simple gizmo for location, rotation and scale.
In the future, more built-in gizmos and potentially the ability for custom
gizmos could be added.
All gizmo nodes have a **Transform** geometry output. Using it is optional but
it is recommended when the gizmo is used to control inputs that affect a
geometry. When it is used, Blender will automatically transform the gizmos
together with the geometry that they control. To achieve this, the output should
be merged with the generated geometry using the *Join Geometry* node. The data
contained in *Transform* output is not visible geometry, but just internal
information that helps Blender to give a better user experience when using
gizmos.
The gizmo nodes have a multi-input socket. This allows **controlling multiple
values** with the same gizmo.
Only a small set of **gizmo shapes** is supported initially. It might be
extended in the future but one goal is to give the gizmos used by different node
group assets a familiar look and feel. A similar constraint exists for
**colors**. Currently, one can choose from a fixed set of colors which can be
modified in the theme settings.
The set of **visible gizmos** is determined by a multiple factors because it's
not really feasible to show all possible gizmos at all times. To see any of the
geometry nodes gizmos, the "Active Modifier" option has to be enabled in the
"Viewport Gizmos" popover. Then all gizmos are drawn for which at least one of
the following is true:
* The gizmo controls an input of the active modifier of the active object.
* The gizmo controls a value in a selected node in an open node editor.
* The gizmo controls a pinned value in an open node editor. Pinning works by
clicking the gizmo icon next to the value.
Pull Request: https://projects.blender.org/blender/blender/pulls/112677
2024-07-10 16:18:47 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_NODE_GIZMO, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_all(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-17 19:14:08 +00:00
|
|
|
ot->name = "(De)select All";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "(De)select all nodes";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_all";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->exec = node_select_all_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-08-01 13:28:19 +00:00
|
|
|
|
|
|
|
|
WM_operator_properties_select_all(ot);
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Linked To Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_linked_to_exec(bContext *C, wmOperator * /*op*/)
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-06 12:11:04 -05:00
|
|
|
node_tree.ensure_topology_cache();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNode *> initial_selection = get_selected_nodes(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-06 12:11:04 -05:00
|
|
|
for (bNode *node : initial_selection) {
|
|
|
|
|
for (bNodeSocket *output_socket : node->output_sockets()) {
|
|
|
|
|
if (!output_socket->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for (bNodeSocket *input_socket : output_socket->directly_linked_sockets()) {
|
|
|
|
|
if (!input_socket->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(input_socket->owner_node(), true);
|
2022-09-06 12:11:04 -05:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_linked_to(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Linked To";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Select nodes linked to the selected ones";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_linked_to";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->exec = node_select_linked_to_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Linked From Operator
|
|
|
|
|
* \{ */
|
2009-09-14 08:47:13 +00:00
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_linked_from_exec(bContext *C, wmOperator * /*op*/)
|
2009-09-14 08:47:13 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &node_tree = *snode.edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-06 12:11:04 -05:00
|
|
|
node_tree.ensure_topology_cache();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNode *> initial_selection = get_selected_nodes(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-06 12:11:04 -05:00
|
|
|
for (bNode *node : initial_selection) {
|
|
|
|
|
for (bNodeSocket *input_socket : node->input_sockets()) {
|
|
|
|
|
if (!input_socket->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for (bNodeSocket *output_socket : input_socket->directly_linked_sockets()) {
|
|
|
|
|
if (!output_socket->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_selected(output_socket->owner_node(), true);
|
2022-09-06 12:11:04 -05:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-10 10:57:51 +02:00
|
|
|
tree_draw_order_update(node_tree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
|
2009-09-14 08:47:13 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_select_linked_from(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Select Linked From";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Select nodes linked from the selected ones";
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->idname = "NODE_OT_select_linked_from";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2009-09-14 08:47:13 +00:00
|
|
|
ot->exec = node_select_linked_from_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-09-14 08:47:13 +00:00
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-09-14 08:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Select Same Type Step Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2022-11-20 13:55:36 -06:00
|
|
|
static bool nodes_are_same_type_for_select(const bNode &a, const bNode &b)
|
|
|
|
|
{
|
2025-01-09 15:28:57 +01:00
|
|
|
return a.type_legacy == b.type_legacy;
|
2022-11-20 13:55:36 -06:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_select_same_type_step_exec(bContext *C, wmOperator *op)
|
2013-03-27 17:22:12 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2022-11-20 13:55:36 -06:00
|
|
|
const bool prev = RNA_boolean_get(op->ptr, "prev");
|
2025-02-19 13:44:11 +01:00
|
|
|
bNode *active_node = bke::node_get_active(*snode->edittree);
|
2024-05-01 14:48:12 +02:00
|
|
|
|
|
|
|
|
if (active_node == nullptr) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-20 13:55:36 -06:00
|
|
|
bNodeTree &node_tree = *snode->edittree;
|
|
|
|
|
node_tree.ensure_topology_cache();
|
|
|
|
|
if (node_tree.all_nodes().size() == 1) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-20 13:55:36 -06:00
|
|
|
const Span<const bNode *> toposort = node_tree.toposort_left_to_right();
|
2024-05-01 14:48:12 +02:00
|
|
|
const int index = toposort.first_index(active_node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-20 13:55:36 -06:00
|
|
|
int new_index = index;
|
|
|
|
|
while (true) {
|
|
|
|
|
new_index += (prev ? -1 : 1);
|
|
|
|
|
if (!toposort.index_range().contains(new_index)) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2024-05-01 14:48:12 +02:00
|
|
|
if (nodes_are_same_type_for_select(*toposort[new_index], *active_node)) {
|
2022-11-20 13:55:36 -06:00
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2022-11-20 13:55:36 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-11 20:23:18 -06:00
|
|
|
bNode *new_active_node = node_tree.all_nodes()[toposort[new_index]->index()];
|
2024-05-01 14:48:12 +02:00
|
|
|
if (new_active_node == active_node) {
|
2022-11-20 13:55:36 -06:00
|
|
|
return OPERATOR_CANCELLED;
|
2013-03-27 17:22:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-20 13:55:36 -06:00
|
|
|
node_select_single(*C, *new_active_node);
|
|
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
if (!BLI_rctf_inside_rctf(®ion->v2d.cur, &new_active_node->runtime->draw_bounds)) {
|
2022-11-20 13:55:36 -06:00
|
|
|
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
|
|
|
|
|
space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-27 17:22:12 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 18:28:25 +00:00
|
|
|
void NODE_OT_select_same_type_step(wmOperatorType *ot)
|
2013-03-27 17:22:12 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-03-27 18:28:25 +00:00
|
|
|
ot->name = "Activate Same Type Next/Prev";
|
|
|
|
|
ot->description = "Activate and view same node type, step by step";
|
|
|
|
|
ot->idname = "NODE_OT_select_same_type_step";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2013-03-27 17:22:12 +00:00
|
|
|
ot->exec = node_select_same_type_step_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
/* flags */
|
2013-03-27 17:22:12 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_def_boolean(ot->srna, "prev", false, "Previous", "");
|
2013-03-27 17:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-08 16:59:48 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Find Node by Name Operator
|
|
|
|
|
* \{ */
|
2013-04-01 15:07:22 +00:00
|
|
|
|
2025-05-05 18:09:22 +02:00
|
|
|
static std::string node_find_create_label(const bNodeTree &ntree, const bNode &node)
|
2020-09-09 13:44:39 +02:00
|
|
|
{
|
2025-05-05 18:09:22 +02:00
|
|
|
std::string label = bke::node_label(ntree, node);
|
|
|
|
|
if (label == node.name) {
|
|
|
|
|
return label;
|
2020-09-09 13:44:39 +02:00
|
|
|
}
|
2025-05-05 18:09:22 +02:00
|
|
|
return fmt::format("{} ({})", label, node.name);
|
2020-09-09 13:44:39 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-23 16:56:00 +10:00
|
|
|
/* Generic search invoke. */
|
2022-09-02 14:21:35 -05:00
|
|
|
static void node_find_update_fn(const bContext *C,
|
2022-10-03 17:37:25 -05:00
|
|
|
void * /*arg*/,
|
2020-05-08 12:01:35 +10:00
|
|
|
const char *str,
|
UI: Expose an "is first search" boolean to search button callbacks
Currently when you open an RNA collection search button, like a
vertex group selector, the search filter isn't applied until you
start typing, in order to display every option at the start.
Otherwise they wouldn't be visible, since the search filter would
run for the current text.
Currently this check happens in one place, but it relies on the
`changed` value of `uiBut`. This is fine in the interface directory,
but anywhere else it would require exposing `uiBut.changed`, which
is probably too low-level to expose.
The solution is adding an `is_first` argument to the search callbacks,
which is nice for a few reasons:
- They work at a higher level of abstraction, meaning they don't
have to worry about how exactly to tell if this is the first
search.
- It makes it easier to do special behavior when the search menu
is first opened.
- Then, obviously, it makes that state accessible without including
`interface_intern.h`.
Needed for attribute search: T85658
Differential Revision: https://developer.blender.org/D10528
2021-03-02 11:42:05 -06:00
|
|
|
uiSearchItems *items,
|
2022-10-03 17:37:25 -05:00
|
|
|
const bool /*is_first*/)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-25 10:56:12 +02:00
|
|
|
ui::string_search::StringSearch<bNode> search;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-05 18:09:22 +02:00
|
|
|
const bNodeTree &ntree = *snode->edittree;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2025-05-05 18:09:22 +02:00
|
|
|
const std::string name = node_find_create_label(ntree, *node);
|
2023-08-05 10:54:23 +02:00
|
|
|
search.add(name, node);
|
2020-09-09 13:44:39 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-05 10:54:23 +02:00
|
|
|
const Vector<bNode *> filtered_nodes = search.query(str);
|
2020-09-09 13:44:39 +02:00
|
|
|
|
2023-08-05 10:54:23 +02:00
|
|
|
for (bNode *node : filtered_nodes) {
|
2025-05-05 18:09:22 +02:00
|
|
|
const std::string name = node_find_create_label(ntree, *node);
|
2020-09-09 13:44:39 +02:00
|
|
|
if (!UI_search_item_add(items, name, node, ICON_NONE, 0, 0)) {
|
|
|
|
|
break;
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static void node_find_exec_fn(bContext *C, void * /*arg1*/, void *arg2)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *active = (bNode *)arg2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
if (active) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2021-12-03 16:25:17 -05:00
|
|
|
node_select_single(*C, *active);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-13 16:51:56 +01:00
|
|
|
if (!BLI_rctf_inside_rctf(®ion->v2d.cur, &active->runtime->draw_bounds)) {
|
2021-12-03 16:25:17 -05:00
|
|
|
space_node_view_flag(*C, *snode, *region, NODE_SELECT, U.smooth_viewtx);
|
2013-04-01 15:07:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 21:21:39 +02:00
|
|
|
static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_optype)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
|
|
|
|
static char search[256] = "";
|
|
|
|
|
uiBlock *block;
|
|
|
|
|
uiBut *but;
|
2024-05-27 21:21:39 +02:00
|
|
|
wmOperatorType *optype = (wmOperatorType *)arg_optype;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-31 00:36:46 +02:00
|
|
|
block = UI_block_begin(C, region, "_popup", blender::ui::EmbossType::Emboss);
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
|
2018-09-11 10:56:08 +10:00
|
|
|
UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-05-10 04:48:30 +02:00
|
|
|
const int box_width = UI_searchbox_size_x_guess(C, node_find_update_fn);
|
|
|
|
|
|
2025-05-07 02:32:13 +02:00
|
|
|
but = uiDefSearchBut(
|
2025-05-10 04:48:30 +02:00
|
|
|
block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, box_width, UI_UNIT_Y, "");
|
2021-04-14 11:11:51 -05:00
|
|
|
UI_but_func_search_set(
|
2024-05-27 21:21:39 +02:00
|
|
|
but, nullptr, node_find_update_fn, optype, false, nullptr, node_find_exec_fn, nullptr);
|
2019-03-22 00:54:07 +11:00
|
|
|
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Fake button holds space for search items. */
|
2025-05-07 02:32:13 +02:00
|
|
|
const int height = UI_searchbox_size_y() - UI_SEARCHBOX_BOUNDS;
|
2025-05-10 04:48:30 +02:00
|
|
|
uiDefBut(
|
|
|
|
|
block, UI_BTYPE_LABEL, 0, "", 0, -height, box_width, height, nullptr, 0, 0, std::nullopt);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-13 16:35:24 +11:00
|
|
|
/* Move it downwards, mouse over button. */
|
2021-06-02 17:19:36 +02:00
|
|
|
std::array<int, 2> bounds_offset = {0, -UI_UNIT_Y};
|
2025-05-07 02:32:13 +02:00
|
|
|
UI_block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, bounds_offset.data());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-01 15:07:22 +00:00
|
|
|
return block;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 21:11:06 +00:00
|
|
|
static wmOperatorStatus node_find_node_invoke(bContext *C,
|
|
|
|
|
wmOperator *op,
|
|
|
|
|
const wmEvent * /*event*/)
|
2013-04-01 15:07:22 +00:00
|
|
|
{
|
2024-05-27 21:21:39 +02:00
|
|
|
UI_popup_block_invoke(C, node_find_menu, op->type, nullptr);
|
2013-04-01 15:07:22 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_find_node(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Find Node";
|
2020-11-18 16:14:48 -05:00
|
|
|
ot->description = "Search for a node by name and focus and select it";
|
2013-04-01 15:07:22 +00:00
|
|
|
ot->idname = "NODE_OT_find_node";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-05-17 09:18:03 +10:00
|
|
|
/* API callbacks. */
|
2013-04-01 15:07:22 +00:00
|
|
|
ot->invoke = node_find_node_invoke;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* flags */
|
2013-04-01 15:07:22 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
2019-03-08 16:59:48 +11:00
|
|
|
|
|
|
|
|
/** \} */
|
2022-01-20 10:36:56 -06:00
|
|
|
|
2022-01-24 21:15:25 +11:00
|
|
|
} // namespace blender::ed::space_node
|