2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spnode
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-07-15 11:00:23 +02:00
|
|
|
#include <algorithm>
|
2025-01-09 17:00:05 +01:00
|
|
|
#include <optional>
|
2021-07-15 11:00:23 +02:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_node_types.h"
|
2012-11-03 14:32:26 +00:00
|
|
|
#include "DNA_text_types.h"
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_world_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2024-02-09 19:29:34 +01:00
|
|
|
#include "BKE_callbacks.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2024-02-10 18:25:14 +01:00
|
|
|
#include "BKE_global.hh"
|
2024-11-12 15:21:59 +01:00
|
|
|
#include "BKE_image.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2025-01-13 15:03:24 +01:00
|
|
|
#include "BKE_main_invariants.hh"
|
2025-01-09 17:26:40 +01:00
|
|
|
#include "BKE_material.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-11-18 12:46:20 +01:00
|
|
|
#include "BKE_node_runtime.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_node_tree_update.hh"
|
2024-02-10 18:34:29 +01:00
|
|
|
#include "BKE_report.hh"
|
2024-02-10 19:16:25 +01:00
|
|
|
#include "BKE_scene.hh"
|
2024-02-09 10:19:24 +01:00
|
|
|
#include "BKE_scene_runtime.hh"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.h"
|
2024-12-04 08:52:37 -05:00
|
|
|
#include "BLI_math_vector.h"
|
2025-01-10 03:09:00 +01:00
|
|
|
#include "BLI_math_vector.hh"
|
2023-09-01 21:37:11 +02:00
|
|
|
#include "BLI_string.h"
|
2023-05-13 17:38:48 +10:00
|
|
|
#include "BLI_string_utf8.h"
|
|
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2022-08-29 14:25:18 +02:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
|
#include "DEG_depsgraph_build.hh"
|
2023-11-13 11:31:09 +01:00
|
|
|
#include "DEG_depsgraph_debug.hh"
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2017-06-08 10:14:53 +02:00
|
|
|
|
2012-11-03 14:32:26 +00:00
|
|
|
#include "RE_engine.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_image.hh"
|
2022-12-20 17:19:47 -06:00
|
|
|
#include "ED_node.hh" /* own include */
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_render.hh"
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.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"
|
2009-01-12 00:14:37 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_define.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2009-01-12 00:14:37 +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_view2d.hh"
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_capabilities.hh"
|
2024-02-01 10:40:24 -05:00
|
|
|
#include "GPU_material.hh"
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2024-01-18 22:50:23 +02:00
|
|
|
#include "IMB_imbuf_types.hh"
|
2013-03-07 17:47:30 +00:00
|
|
|
|
2023-10-16 10:45:54 +02:00
|
|
|
#include "NOD_composite.hh"
|
2023-06-23 22:15:42 +02:00
|
|
|
#include "NOD_geometry.hh"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_shader.h"
|
2023-07-02 21:01:57 +02:00
|
|
|
#include "NOD_socket.hh"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_texture.h"
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh" /* own include */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2024-12-25 08:38:28 +02:00
|
|
|
#include "COM_compositor.hh"
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
#include "COM_context.hh"
|
2024-05-28 08:13:46 +02:00
|
|
|
#include "COM_profiler.hh"
|
2024-02-09 10:19:24 +01:00
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
2012-08-15 11:31:04 +00:00
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
#define USE_ESC_COMPO
|
2021-12-03 16:25:17 -05:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Composite Job Manager
|
|
|
|
|
* \{ */
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2013-03-20 18:01:47 +00:00
|
|
|
enum {
|
|
|
|
|
COM_RECALC_COMPOSITE = 1,
|
2019-01-15 23:57:49 +11:00
|
|
|
COM_RECALC_VIEWER = 2,
|
2013-03-20 18:01:47 +00:00
|
|
|
};
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
struct CompoJob {
|
2019-06-03 14:47:44 +02:00
|
|
|
/* Input parameters. */
|
2018-06-11 15:40:37 +02:00
|
|
|
Main *bmain;
|
2009-01-27 17:12:40 +00:00
|
|
|
Scene *scene;
|
2019-06-03 14:47:44 +02:00
|
|
|
ViewLayer *view_layer;
|
2009-01-27 17:12:40 +00:00
|
|
|
bNodeTree *ntree;
|
2019-06-03 14:47:44 +02:00
|
|
|
int recalc_flags;
|
|
|
|
|
/* Evaluated state/ */
|
|
|
|
|
Depsgraph *compositor_depsgraph;
|
2009-01-27 17:12:40 +00:00
|
|
|
bNodeTree *localtree;
|
2023-06-05 12:08:30 +02:00
|
|
|
/* Render instance. */
|
|
|
|
|
Render *re;
|
2023-06-19 15:29:48 +02:00
|
|
|
/* Job system integration. */
|
2022-11-04 18:37:25 +11:00
|
|
|
const bool *stop;
|
|
|
|
|
bool *do_update;
|
2010-05-27 08:22:16 +00:00
|
|
|
float *progress;
|
2023-06-19 15:29:48 +02:00
|
|
|
bool cancelled;
|
2024-02-09 10:19:24 +01:00
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
compositor::Profiler profiler;
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
compositor::OutputTypes needed_outputs;
|
2021-06-02 17:19:36 +02:00
|
|
|
};
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
float node_socket_calculate_height(const bNodeSocket &socket)
|
2021-02-11 01:16:17 -06:00
|
|
|
{
|
2024-11-23 16:42:38 +01:00
|
|
|
float sock_height = NODE_SOCKSIZE;
|
2021-12-03 16:25:17 -05:00
|
|
|
if (socket.flag & SOCK_MULTI_INPUT) {
|
2022-11-23 10:42:03 +01:00
|
|
|
sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket.runtime->total_inputs,
|
|
|
|
|
NODE_SOCKSIZE);
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
|
|
|
|
return sock_height;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 17:12:46 -05:00
|
|
|
float2 node_link_calculate_multi_input_position(const float2 &socket_position,
|
|
|
|
|
const int index,
|
|
|
|
|
const int total_inputs)
|
2021-02-11 01:16:17 -06:00
|
|
|
{
|
2021-12-06 17:12:46 -05:00
|
|
|
const float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) *
|
|
|
|
|
0.5f;
|
2022-09-01 19:46:19 +02:00
|
|
|
return {socket_position.x, socket_position.y - offset + index * NODE_MULTI_INPUT_LINK_GAP};
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
|
|
|
|
|
2013-03-20 18:01:47 +00:00
|
|
|
static void compo_tag_output_nodes(bNodeTree *nodetree, int recalc_flags)
|
|
|
|
|
{
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : nodetree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == CMP_NODE_COMPOSITE) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (recalc_flags & COM_RECALC_COMPOSITE) {
|
2013-03-20 18:01:47 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT_RECALC;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-20 18:01:47 +00:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (node->type_legacy == CMP_NODE_VIEWER) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (recalc_flags & COM_RECALC_VIEWER) {
|
2013-03-20 18:01:47 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT_RECALC;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-20 18:01:47 +00:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (node->type_legacy == NODE_GROUP) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->id) {
|
2013-03-20 18:01:47 +00:00
|
|
|
compo_tag_output_nodes((bNodeTree *)node->id, recalc_flags);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-20 18:01:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int compo_get_recalc_flags(const bContext *C)
|
|
|
|
|
{
|
2013-04-30 06:03:17 +00:00
|
|
|
wmWindowManager *wm = CTX_wm_manager(C);
|
2013-03-20 18:01:47 +00:00
|
|
|
int recalc_flags = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
2020-04-03 14:23:21 +02:00
|
|
|
const bScreen *screen = WM_window_get_active_screen(win);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
2020-04-03 13:25:03 +02:00
|
|
|
if (area->spacetype == SPACE_IMAGE) {
|
2021-06-02 17:19:36 +02:00
|
|
|
SpaceImage *sima = (SpaceImage *)area->spacedata.first;
|
2013-04-30 06:03:17 +00:00
|
|
|
if (sima->image) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sima->image->type == IMA_TYPE_R_RESULT) {
|
2013-04-30 06:03:17 +00:00
|
|
|
recalc_flags |= COM_RECALC_COMPOSITE;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (sima->image->type == IMA_TYPE_COMPOSITE) {
|
2013-04-30 06:03:17 +00:00
|
|
|
recalc_flags |= COM_RECALC_VIEWER;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-04-30 06:03:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-03 13:25:03 +02:00
|
|
|
else if (area->spacetype == SPACE_NODE) {
|
2021-06-02 17:19:36 +02:00
|
|
|
SpaceNode *snode = (SpaceNode *)area->spacedata.first;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (snode->flag & SNODE_BACKDRAW) {
|
2013-03-20 18:01:47 +00:00
|
|
|
recalc_flags |= COM_RECALC_VIEWER;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-20 18:01:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-20 18:01:47 +00:00
|
|
|
return recalc_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Called by compositor, only to check job 'stop' value. */
|
2022-11-04 18:37:25 +11:00
|
|
|
static bool compo_breakjob(void *cjv)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Without G.is_break 'ESC' won't quit - which annoys users. */
|
2012-08-15 11:31:04 +00:00
|
|
|
return (*(cj->stop)
|
|
|
|
|
#ifdef USE_ESC_COMPO
|
|
|
|
|
|| G.is_break
|
|
|
|
|
#endif
|
|
|
|
|
);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Called by compositor, #wmJob sends notifier. */
|
2022-10-03 17:37:25 -05:00
|
|
|
static void compo_statsdrawjob(void *cjv, const char * /*str*/)
|
2012-11-30 09:12:10 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
*(cj->do_update) = true;
|
2012-11-30 09:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Called by compositor, wmJob sends notifier. */
|
2012-11-30 09:12:10 +00:00
|
|
|
static void compo_redrawjob(void *cjv)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
*(cj->do_update) = true;
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void compo_freejob(void *cjv)
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cj->localtree) {
|
2023-06-19 15:29:48 +02:00
|
|
|
/* Merge back node previews, only for completed jobs. */
|
|
|
|
|
if (!cj->cancelled) {
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_tree_local_merge(cj->bmain, cj->localtree, cj->ntree);
|
2023-06-19 15:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_tree_free_tree(cj->localtree);
|
2023-06-19 15:29:48 +02:00
|
|
|
MEM_freeN(cj->localtree);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
2024-02-09 10:19:24 +01:00
|
|
|
|
|
|
|
|
MEM_delete(cj);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Only now we copy the nodetree, so adding many jobs while
|
|
|
|
|
* sliding buttons doesn't frustrate. */
|
2009-01-27 17:12:40 +00:00
|
|
|
static void compo_initjob(void *cjv)
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2019-06-03 14:47:44 +02:00
|
|
|
Main *bmain = cj->bmain;
|
|
|
|
|
Scene *scene = cj->scene;
|
|
|
|
|
ViewLayer *view_layer = cj->view_layer;
|
|
|
|
|
|
2024-06-13 07:43:11 +02:00
|
|
|
bke::CompositorRuntime &compositor_runtime = scene->runtime->compositor;
|
|
|
|
|
|
|
|
|
|
if (!compositor_runtime.preview_depsgraph) {
|
|
|
|
|
compositor_runtime.preview_depsgraph = DEG_graph_new(
|
|
|
|
|
bmain, scene, view_layer, DAG_EVAL_RENDER);
|
|
|
|
|
DEG_debug_name_set(compositor_runtime.preview_depsgraph, "COMPOSITOR");
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 13:09:03 +01:00
|
|
|
/* Update the viewer layer of the compositor since it changed since the depsgraph was created. */
|
|
|
|
|
if (DEG_get_input_view_layer(compositor_runtime.preview_depsgraph) != view_layer) {
|
|
|
|
|
DEG_graph_replace_owners(compositor_runtime.preview_depsgraph, bmain, scene, view_layer);
|
|
|
|
|
DEG_graph_tag_relations_update(compositor_runtime.preview_depsgraph);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 07:43:11 +02:00
|
|
|
cj->compositor_depsgraph = compositor_runtime.preview_depsgraph;
|
2020-08-18 15:51:32 +02:00
|
|
|
DEG_graph_build_for_compositor_preview(cj->compositor_depsgraph, cj->ntree);
|
2019-06-27 16:21:18 +02:00
|
|
|
|
|
|
|
|
/* NOTE: Don't update animation to preserve unkeyed changes, this means can not use
|
|
|
|
|
* evaluate_on_framechange. */
|
2020-08-18 17:40:45 +02:00
|
|
|
DEG_evaluate_on_refresh(cj->compositor_depsgraph);
|
2019-06-03 14:47:44 +02:00
|
|
|
|
|
|
|
|
bNodeTree *ntree_eval = (bNodeTree *)DEG_get_evaluated_id(cj->compositor_depsgraph,
|
|
|
|
|
&cj->ntree->id);
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
cj->localtree = bke::node_tree_localize(ntree_eval, nullptr);
|
2013-03-20 18:01:47 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (cj->recalc_flags) {
|
2013-03-20 18:01:47 +00:00
|
|
|
compo_tag_output_nodes(cj->localtree, cj->recalc_flags);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2023-06-05 12:08:30 +02:00
|
|
|
|
2024-08-08 15:40:06 +02:00
|
|
|
cj->re = RE_NewInteractiveCompositorRender(scene);
|
2024-05-30 15:03:15 +02:00
|
|
|
if (scene->r.compositor_device == SCE_COMPOSITOR_DEVICE_GPU) {
|
|
|
|
|
RE_system_gpu_context_ensure(cj->re);
|
|
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Called before redraw notifiers, it moves finished previews over. */
|
2022-10-03 17:37:25 -05:00
|
|
|
static void compo_updatejob(void * /*cjv*/)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_main_add_notifier(NC_SCENE | ND_COMPO_RESULT, nullptr);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void compo_progressjob(void *cjv, float progress)
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
*(cj->progress) = progress;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Only this runs inside thread. */
|
2023-10-06 13:06:02 +02:00
|
|
|
static void compo_startjob(void *cjv, wmJobWorkerStatus *worker_status)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeTree *ntree = cj->localtree;
|
2024-06-03 16:50:15 +02:00
|
|
|
Scene *scene = DEG_get_evaluated_scene(cj->compositor_depsgraph);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (scene->use_nodes == false) {
|
2009-01-27 17:12:40 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-10-06 13:06:02 +02:00
|
|
|
cj->stop = &worker_status->stop;
|
|
|
|
|
cj->do_update = &worker_status->do_update;
|
|
|
|
|
cj->progress = &worker_status->progress;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-23 14:05:30 +01:00
|
|
|
ntree->runtime->test_break = compo_breakjob;
|
|
|
|
|
ntree->runtime->tbh = cj;
|
|
|
|
|
ntree->runtime->stats_draw = compo_statsdrawjob;
|
|
|
|
|
ntree->runtime->sdh = cj;
|
|
|
|
|
ntree->runtime->progress = compo_progressjob;
|
|
|
|
|
ntree->runtime->prh = cj;
|
|
|
|
|
ntree->runtime->update_draw = compo_redrawjob;
|
|
|
|
|
ntree->runtime->udh = cj;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-06-03 16:50:15 +02:00
|
|
|
BKE_callback_exec_id(cj->bmain, &cj->scene->id, BKE_CB_EVT_COMPOSITE_PRE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-06-03 16:50:15 +02:00
|
|
|
if ((scene->r.scemode & R_MULTIVIEW) == 0) {
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
COM_execute(cj->re, &scene->r, scene, ntree, "", nullptr, &cj->profiler, cj->needed_outputs);
|
2015-04-07 16:37:16 -03:00
|
|
|
}
|
|
|
|
|
else {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (SceneRenderView *, srv, &scene->r.views) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (BKE_scene_multiview_is_render_view_active(&scene->r, srv) == false) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
COM_execute(
|
|
|
|
|
cj->re, &scene->r, scene, ntree, srv->name, nullptr, &cj->profiler, cj->needed_outputs);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 14:05:30 +01:00
|
|
|
ntree->runtime->test_break = nullptr;
|
|
|
|
|
ntree->runtime->stats_draw = nullptr;
|
|
|
|
|
ntree->runtime->progress = nullptr;
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 10:22:43 +02:00
|
|
|
static void compo_canceljob(void *cjv)
|
|
|
|
|
{
|
|
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
|
|
|
|
Main *bmain = cj->bmain;
|
|
|
|
|
Scene *scene = cj->scene;
|
|
|
|
|
BKE_callback_exec_id(bmain, &scene->id, BKE_CB_EVT_COMPOSITE_CANCEL);
|
2023-06-19 15:29:48 +02:00
|
|
|
cj->cancelled = true;
|
2024-02-09 10:19:24 +01:00
|
|
|
|
2024-05-28 08:13:46 +02:00
|
|
|
scene->runtime->compositor.per_node_execution_time = cj->profiler.get_nodes_evaluation_times();
|
2022-05-31 10:22:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void compo_completejob(void *cjv)
|
|
|
|
|
{
|
|
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
|
|
|
|
Main *bmain = cj->bmain;
|
|
|
|
|
Scene *scene = cj->scene;
|
|
|
|
|
BKE_callback_exec_id(bmain, &scene->id, BKE_CB_EVT_COMPOSITE_POST);
|
2024-02-09 10:19:24 +01:00
|
|
|
|
2024-05-28 08:13:46 +02:00
|
|
|
scene->runtime->compositor.per_node_execution_time = cj->profiler.get_nodes_evaluation_times();
|
2022-05-31 10:22:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-05-25 12:46:55 +10:00
|
|
|
} // namespace blender::ed::space_node
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Composite Job C API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-12-01 16:16:19 +01:00
|
|
|
/* Identify if the compositor can run. Currently, this only checks if the compositor is set to GPU
|
|
|
|
|
* and the render size exceeds what can be allocated as a texture in it. */
|
|
|
|
|
static bool is_compositing_possible(const bContext *C)
|
|
|
|
|
{
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
/* CPU compositor can always run. */
|
2024-05-14 15:49:20 +02:00
|
|
|
if (scene->r.compositor_device != SCE_COMPOSITOR_DEVICE_GPU) {
|
2023-12-01 16:16:19 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
|
BKE_render_resolution(&scene->r, false, &width, &height);
|
|
|
|
|
const int max_texture_size = GPU_max_texture_size();
|
|
|
|
|
|
|
|
|
|
/* There is no way to know if the render size is too large except if we actually allocate a test
|
|
|
|
|
* texture, which we want to avoid due its cost. So we employ a heuristic that so far has worked
|
|
|
|
|
* with all known GPU drivers. */
|
|
|
|
|
if (size_t(width) * height > (size_t(max_texture_size) * max_texture_size) / 4) {
|
|
|
|
|
WM_report(RPT_ERROR, "Render size too large for GPU, use CPU compositor instead");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
/* Returns the compositor outputs that need to be computed because their result is visible to the
|
|
|
|
|
* user. */
|
|
|
|
|
static blender::compositor::OutputTypes get_compositor_needed_outputs(const bContext *C)
|
|
|
|
|
{
|
|
|
|
|
blender::compositor::OutputTypes needed_outputs = blender::compositor::OutputTypes::None;
|
|
|
|
|
|
|
|
|
|
wmWindowManager *window_manager = CTX_wm_manager(C);
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, window, &window_manager->windows) {
|
|
|
|
|
bScreen *screen = WM_window_get_active_screen(window);
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
SpaceLink *space_link = static_cast<SpaceLink *>(area->spacedata.first);
|
|
|
|
|
if (!space_link || !ELEM(space_link->spacetype, SPACE_NODE, SPACE_IMAGE)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (space_link->spacetype == SPACE_NODE) {
|
|
|
|
|
const SpaceNode *space_node = reinterpret_cast<const SpaceNode *>(space_link);
|
|
|
|
|
if (space_node->flag & SNODE_BACKDRAW) {
|
|
|
|
|
needed_outputs |= blender::compositor::OutputTypes::Viewer;
|
|
|
|
|
}
|
|
|
|
|
if (space_node->overlay.flag & SN_OVERLAY_SHOW_PREVIEWS) {
|
|
|
|
|
needed_outputs |= blender::compositor::OutputTypes::Previews;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (space_link->spacetype == SPACE_IMAGE) {
|
|
|
|
|
const SpaceImage *space_image = reinterpret_cast<const SpaceImage *>(space_link);
|
|
|
|
|
Image *image = ED_space_image(space_image);
|
|
|
|
|
if (!image || image->source != IMA_SRC_VIEWER) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (image->type == IMA_TYPE_R_RESULT) {
|
|
|
|
|
needed_outputs |= blender::compositor::OutputTypes::Composite;
|
|
|
|
|
}
|
|
|
|
|
else if (image->type == IMA_TYPE_COMPOSITE) {
|
|
|
|
|
needed_outputs |= blender::compositor::OutputTypes::Viewer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* All outputs are already needed, return early. */
|
|
|
|
|
if (needed_outputs ==
|
|
|
|
|
(blender::compositor::OutputTypes::Composite | blender::compositor::OutputTypes::Viewer |
|
|
|
|
|
blender::compositor::OutputTypes::Previews))
|
|
|
|
|
{
|
|
|
|
|
return needed_outputs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return needed_outputs;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
void ED_node_composite_job(const bContext *C, bNodeTree *nodetree, Scene *scene_owner)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
blender::compositor::OutputTypes needed_outputs = get_compositor_needed_outputs(C);
|
|
|
|
|
if (needed_outputs == blender::compositor::OutputTypes::None) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
using namespace blender::ed::space_node;
|
|
|
|
|
|
2018-06-11 15:40:37 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2014-04-30 18:12:55 +06:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2019-06-03 14:47:44 +02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2009-09-30 18:18:32 +00:00
|
|
|
|
2023-12-01 16:16:19 +01:00
|
|
|
if (!is_compositing_possible(C)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 14:37:16 +11:00
|
|
|
/* See #32272. */
|
2012-08-08 18:37:06 +00:00
|
|
|
if (G.is_rendering) {
|
2012-08-06 10:13:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-15 11:31:04 +00:00
|
|
|
#ifdef USE_ESC_COMPO
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false;
|
2012-08-15 11:31:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
2018-06-11 15:40:37 +02:00
|
|
|
BKE_image_backup_render(
|
2020-03-06 13:02:59 +11:00
|
|
|
scene, BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result"), false);
|
2014-04-30 18:12:55 +06:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
|
|
|
|
|
CTX_wm_window(C),
|
|
|
|
|
scene_owner,
|
|
|
|
|
"Compositing",
|
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS,
|
|
|
|
|
WM_JOB_TYPE_COMPOSITE);
|
2024-02-09 10:19:24 +01:00
|
|
|
CompoJob *cj = MEM_new<CompoJob>("compo job");
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Custom data for preview thread. */
|
2018-06-11 15:40:37 +02:00
|
|
|
cj->bmain = bmain;
|
2014-04-30 18:12:55 +06:00
|
|
|
cj->scene = scene;
|
2019-06-03 14:47:44 +02:00
|
|
|
cj->view_layer = view_layer;
|
2012-08-03 20:56:04 +00:00
|
|
|
cj->ntree = nodetree;
|
2013-03-20 18:01:47 +00:00
|
|
|
cj->recalc_flags = compo_get_recalc_flags(C);
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
cj->needed_outputs = needed_outputs;
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Set up job. */
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_customdata_set(wm_job, cj, compo_freejob);
|
2013-06-24 22:41:27 +00:00
|
|
|
WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT);
|
2022-05-31 10:22:43 +02:00
|
|
|
WM_jobs_callbacks_ex(wm_job,
|
|
|
|
|
compo_startjob,
|
|
|
|
|
compo_initjob,
|
|
|
|
|
compo_updatejob,
|
|
|
|
|
nullptr,
|
|
|
|
|
compo_completejob,
|
|
|
|
|
compo_canceljob);
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Composite Poll & Utility Functions
|
|
|
|
|
* \{ */
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool composite_node_active(bContext *C)
|
2011-01-17 18:38:44 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ED_operator_node_active(C)) {
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ED_node_is_compositor(snode)) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-01-17 18:38:44 +00:00
|
|
|
}
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
2011-01-17 18:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
bool composite_node_editable(bContext *C)
|
2013-06-05 19:06:33 +00:00
|
|
|
{
|
|
|
|
|
if (ED_operator_node_editable(C)) {
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ED_node_is_compositor(snode)) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-06-05 19:06:33 +00:00
|
|
|
}
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
2013-06-05 19:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
} // namespace blender::ed::space_node
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Editor Public API Functions
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2024-05-13 16:07:12 +02:00
|
|
|
void ED_node_set_tree_type(SpaceNode *snode, blender::bke::bNodeTreeType *typeinfo)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (typeinfo) {
|
2025-01-08 16:34:41 +01:00
|
|
|
STRNCPY(snode->tree_idname, typeinfo->idname.c_str());
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2013-03-18 16:34:57 +00:00
|
|
|
snode->tree_idname[0] = '\0';
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
Fix #121480: Cryptomatte shows some objects as black
The issue originates to the change in default view transform from Filmic
to AgX, which does slightly different clipping, and clips color to black
if there is any negative values.
This change implements an idea of skipping view transform for viewer
node when it is connected to the Pick output of the cryptomatte node.
It actually goes a bit deeper than this and any operation can tag its
result as a non-color data, and the viewer node will respect that.
It is achieved by passing some extra meta-data along the evaluation
pipeline. For the CPU compositor it is done via MetaData, and for the
GPU compositor it is done as part of Result.
Connecting any other node in-between of viewer and Cryptomatte's Pick
will treat the result as color values, and apply color management.
Connecting Pick to the Composite output will also consider it as color,
since there is no concept of non-color-managed render result.
An alternative approaches were tested, including:
- Doing negative value clamping at the viewer node.
It does not work for legacy cryptomatte node, as it needs to have
access to original non-modified Pick result.
- Change the order of components, and store ID in another channel.
Using one of other of Green or Blue channels might work for some view
transforms, but it does not work for AgX.
Using Alpha channel seemingly works better, but it is has different
issues caused by the fact that display transform de-associates alpha,
leading to over-exposed regions which are hard to see in the file from
the report. And might lead to the similar issues as the initial report
with other objects or view transforms.
- Use positive values in the Pick channel.
It does make things visible, but they are all white due to the nature
of how AgX works, making it not so useful as a result.
Pull Request: https://projects.blender.org/blender/blender/pulls/122177
2024-05-24 17:25:57 +02:00
|
|
|
bool ED_node_is_compositor(const SpaceNode *snode)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2025-01-08 16:34:41 +01:00
|
|
|
return snode->tree_idname == ntreeType_Composite->idname;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
bool ED_node_is_shader(SpaceNode *snode)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2025-01-08 16:34:41 +01:00
|
|
|
return snode->tree_idname == ntreeType_Shader->idname;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
bool ED_node_is_texture(SpaceNode *snode)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2025-01-08 16:34:41 +01:00
|
|
|
return snode->tree_idname == ntreeType_Texture->idname;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
bool ED_node_is_geometry(SpaceNode *snode)
|
2020-04-20 10:58:43 +02:00
|
|
|
{
|
2025-01-08 16:34:41 +01:00
|
|
|
return snode->tree_idname == ntreeType_Geometry->idname;
|
2020-04-20 10:58:43 +02:00
|
|
|
}
|
|
|
|
|
|
2023-07-12 16:14:12 +02:00
|
|
|
bool ED_node_supports_preview(SpaceNode *snode)
|
|
|
|
|
{
|
2023-08-08 17:36:06 +02:00
|
|
|
return ED_node_is_compositor(snode) ||
|
2024-12-13 11:21:39 +11:00
|
|
|
(USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) && ED_node_is_shader(snode));
|
2023-07-12 16:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void ED_node_shader_default(const bContext *C, ID *id)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2020-02-06 13:05:45 +01:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
if (GS(id->name) == ID_MA) {
|
|
|
|
|
/* Materials */
|
2020-03-17 14:41:48 +01:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2020-02-06 13:05:45 +01:00
|
|
|
Material *ma = (Material *)id;
|
2020-03-17 14:41:48 +01:00
|
|
|
Material *ma_default;
|
|
|
|
|
|
|
|
|
|
if (ob && ob->type == OB_VOLUME) {
|
|
|
|
|
ma_default = BKE_material_default_volume();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ma_default = BKE_material_default_surface();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
ma->nodetree = blender::bke::node_tree_copy_tree(bmain, ma_default->nodetree);
|
2022-11-07 15:48:32 +01:00
|
|
|
ma->nodetree->owner_id = &ma->id;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node_iter : ma->nodetree->all_nodes()) {
|
2023-05-13 17:38:48 +10:00
|
|
|
STRNCPY_UTF8(node_iter->name, DATA_(node_iter->name));
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_unique_name(ma->nodetree, node_iter);
|
2022-11-16 12:27:20 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 17:00:05 +01:00
|
|
|
BKE_ntree_update_after_single_tree_change(*bmain, *ma->nodetree);
|
2020-02-06 13:05:45 +01:00
|
|
|
}
|
|
|
|
|
else if (ELEM(GS(id->name), ID_WO, ID_LA)) {
|
|
|
|
|
/* Emission */
|
2024-08-19 20:27:37 +02:00
|
|
|
bNodeTree *ntree = blender::bke::node_tree_add_tree_embedded(
|
2022-09-05 15:46:00 +02:00
|
|
|
nullptr, id, "Shader Nodetree", ntreeType_Shader->idname);
|
2020-02-06 13:05:45 +01:00
|
|
|
bNode *shader, *output;
|
|
|
|
|
|
|
|
|
|
if (GS(id->name) == ID_WO) {
|
|
|
|
|
World *world = (World *)id;
|
|
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
shader = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_BACKGROUND);
|
|
|
|
|
output = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_OUTPUT_WORLD);
|
|
|
|
|
blender::bke::node_add_link(ntree,
|
|
|
|
|
shader,
|
|
|
|
|
blender::bke::node_find_socket(shader, SOCK_OUT, "Background"),
|
|
|
|
|
output,
|
|
|
|
|
blender::bke::node_find_socket(output, SOCK_IN, "Surface"));
|
2020-02-06 13:05:45 +01:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNodeSocket *color_sock = blender::bke::node_find_socket(shader, SOCK_IN, "Color");
|
2020-02-06 13:05:45 +01:00
|
|
|
copy_v3_v3(((bNodeSocketValueRGBA *)color_sock->default_value)->value, &world->horr);
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2020-02-06 13:05:45 +01:00
|
|
|
else {
|
2024-08-19 20:27:37 +02:00
|
|
|
shader = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_EMISSION);
|
|
|
|
|
output = blender::bke::node_add_static_node(nullptr, ntree, SH_NODE_OUTPUT_LIGHT);
|
|
|
|
|
blender::bke::node_add_link(ntree,
|
|
|
|
|
shader,
|
|
|
|
|
blender::bke::node_find_socket(shader, SOCK_OUT, "Emission"),
|
|
|
|
|
output,
|
|
|
|
|
blender::bke::node_find_socket(output, SOCK_IN, "Surface"));
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
shader->location[0] = 10.0f;
|
|
|
|
|
shader->location[1] = 300.0f;
|
|
|
|
|
output->location[0] = 300.0f;
|
|
|
|
|
output->location[1] = 300.0f;
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_set_active(ntree, output);
|
2025-01-09 17:00:05 +01:00
|
|
|
BKE_ntree_update_after_single_tree_change(*bmain, *ntree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2020-02-06 13:05:45 +01:00
|
|
|
else {
|
|
|
|
|
printf("ED_node_shader_default called on wrong ID type.\n");
|
|
|
|
|
return;
|
2011-11-08 11:38:16 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
void ED_node_composit_default(const bContext *C, Scene *sce)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
|
/* but lets check it anyway */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sce->nodetree) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (G.debug & G_DEBUG) {
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in composite initialize\n");
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
sce->nodetree = blender::bke::node_tree_add_tree_embedded(
|
2022-09-05 15:46:00 +02:00
|
|
|
nullptr, &sce->id, "Compositing Nodetree", ntreeType_Composite->idname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *out = blender::bke::node_add_static_node(C, sce->nodetree, CMP_NODE_COMPOSITE);
|
2024-12-11 21:06:41 +01:00
|
|
|
out->location[0] = 200.0f;
|
|
|
|
|
out->location[1] = 200.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *in = blender::bke::node_add_static_node(C, sce->nodetree, CMP_NODE_R_LAYERS);
|
2024-12-11 21:06:41 +01:00
|
|
|
in->location[0] = -200.0f;
|
|
|
|
|
in->location[1] = 200.0f;
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_set_active(sce->nodetree, in);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Links from color to color. */
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *fromsock = (bNodeSocket *)in->outputs.first;
|
|
|
|
|
bNodeSocket *tosock = (bNodeSocket *)out->inputs.first;
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_add_link(sce->nodetree, in, fromsock, out, tosock);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-09 17:00:05 +01:00
|
|
|
BKE_ntree_update_after_single_tree_change(*CTX_data_main(C), *sce->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
void ED_node_texture_default(const bContext *C, Tex *tex)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2020-09-04 20:59:13 +02:00
|
|
|
if (tex->nodetree) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (G.debug & G_DEBUG) {
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in texture initialize\n");
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
tex->nodetree = blender::bke::node_tree_add_tree_embedded(
|
2022-09-05 15:46:00 +02:00
|
|
|
nullptr, &tex->id, "Texture Nodetree", ntreeType_Texture->idname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *out = blender::bke::node_add_static_node(C, tex->nodetree, TEX_NODE_OUTPUT);
|
2024-12-11 21:06:41 +01:00
|
|
|
out->location[0] = 300.0f;
|
|
|
|
|
out->location[1] = 300.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *in = blender::bke::node_add_static_node(C, tex->nodetree, TEX_NODE_CHECKER);
|
2024-12-11 21:06:41 +01:00
|
|
|
in->location[0] = 10.0f;
|
|
|
|
|
in->location[1] = 300.0f;
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_set_active(tex->nodetree, in);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *fromsock = (bNodeSocket *)in->outputs.first;
|
|
|
|
|
bNodeSocket *tosock = (bNodeSocket *)out->inputs.first;
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_add_link(tex->nodetree, in, fromsock, out, tosock);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-09 17:00:05 +01:00
|
|
|
BKE_ntree_update_after_single_tree_change(*CTX_data_main(C), *tex->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
void snode_set_context(const bContext &C)
|
2009-10-07 22:05:30 +00:00
|
|
|
{
|
2024-11-02 17:27:09 +11:00
|
|
|
/* NOTE: Here we set the active tree(s), even called for each redraw now, so keep it fast :). */
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(&C);
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::bNodeTreeType *treetype = bke::node_tree_type_find(snode->tree_idname);
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeTree *ntree = snode->nodetree;
|
|
|
|
|
ID *id = snode->id, *from = snode->from;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Check the tree type. */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (!treetype || (treetype->poll && !treetype->poll(&C, treetype))) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Invalid tree type, skip.
|
2021-07-21 13:05:39 +10:00
|
|
|
* NOTE: not resetting the node path here, invalid #bNodeTreeType
|
|
|
|
|
* may still be registered at a later point. */
|
2013-03-18 16:34:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-26 16:03:11 +01:00
|
|
|
if (snode->nodetree && !STREQ(snode->nodetree->idname, snode->tree_idname)) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Current tree does not match selected type, clear tree path. */
|
2021-06-02 17:19:36 +02:00
|
|
|
ntree = nullptr;
|
|
|
|
|
id = nullptr;
|
|
|
|
|
from = nullptr;
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
if (!(snode->flag & SNODE_PIN) || ntree == nullptr) {
|
2013-03-19 10:42:33 +00:00
|
|
|
if (treetype->get_from_context) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Reset and update from context. */
|
2021-06-02 17:19:36 +02:00
|
|
|
ntree = nullptr;
|
|
|
|
|
id = nullptr;
|
|
|
|
|
from = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
treetype->get_from_context(&C, treetype, &ntree, &id, &from);
|
2013-03-19 10:42:33 +00:00
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-11 20:28:39 +02:00
|
|
|
if (snode->nodetree != ntree || snode->id != id || snode->from != from ||
|
2021-06-02 17:19:36 +02:00
|
|
|
(snode->treepath.last == nullptr && ntree))
|
|
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
ED_node_tree_start(snode, ntree, id, from);
|
2013-03-18 18:25:05 +00:00
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
} // namespace blender::ed::space_node
|
|
|
|
|
|
2021-07-05 10:46:00 +02:00
|
|
|
void ED_node_set_active(
|
|
|
|
|
Main *bmain, SpaceNode *snode, bNodeTree *ntree, bNode *node, bool *r_active_texture_changed)
|
2011-08-12 18:27:48 +00:00
|
|
|
{
|
2020-05-25 10:43:44 +02:00
|
|
|
if (r_active_texture_changed) {
|
|
|
|
|
*r_active_texture_changed = false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_set_active(ntree, node);
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == NODE_GROUP) {
|
2022-12-13 16:01:47 -06:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
const bool was_output = (node->flag & NODE_DO_OUTPUT) != 0;
|
|
|
|
|
bool do_update = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Generic node group output: set node as active output. */
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node->is_group_output()) {
|
2022-12-13 16:01:47 -06:00
|
|
|
for (bNode *node_iter : ntree->all_nodes()) {
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node_iter->is_group_output()) {
|
2022-12-13 16:01:47 -06:00
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
|
if (!was_output) {
|
|
|
|
|
do_update = true;
|
|
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Tree specific activate calls. */
|
2022-12-13 16:01:47 -06:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (ELEM(node->type_legacy,
|
2022-12-13 16:01:47 -06:00
|
|
|
SH_NODE_OUTPUT_MATERIAL,
|
|
|
|
|
SH_NODE_OUTPUT_WORLD,
|
|
|
|
|
SH_NODE_OUTPUT_LIGHT,
|
|
|
|
|
SH_NODE_OUTPUT_LINESTYLE))
|
|
|
|
|
{
|
|
|
|
|
for (bNode *node_iter : ntree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_iter->type_legacy == node->type_legacy) {
|
2022-12-13 16:01:47 -06:00
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
|
|
|
|
}
|
2021-12-21 15:18:56 +01:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2022-12-13 16:01:47 -06:00
|
|
|
|
2025-02-05 10:39:02 +01:00
|
|
|
if (node->flag & NODE_ACTIVE_TEXTURE) {
|
2023-08-21 10:05:45 +10:00
|
|
|
/* If active texture changed, free GLSL materials. */
|
2022-12-13 16:01:47 -06:00
|
|
|
LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
|
2024-08-19 20:27:37 +02:00
|
|
|
if (ma->nodetree && ma->use_nodes &&
|
|
|
|
|
blender::bke::node_tree_contains_tree(ma->nodetree, ntree))
|
2024-05-13 16:07:12 +02:00
|
|
|
{
|
2022-12-13 16:01:47 -06:00
|
|
|
GPU_material_free(&ma->gpumaterial);
|
|
|
|
|
|
|
|
|
|
/* Sync to active texpaint slot, otherwise we can end up painting on a different slot
|
|
|
|
|
* than we are looking at. */
|
|
|
|
|
if (ma->texpaintslot) {
|
|
|
|
|
if (node->id != nullptr && GS(node->id->name) == ID_IM) {
|
|
|
|
|
Image *image = (Image *)node->id;
|
|
|
|
|
for (int i = 0; i < ma->tot_slots; i++) {
|
|
|
|
|
if (ma->texpaintslot[i].ima == image) {
|
|
|
|
|
ma->paint_active_slot = i;
|
2021-06-04 10:24:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
LISTBASE_FOREACH (World *, wo, &bmain->worlds) {
|
2024-08-19 20:27:37 +02:00
|
|
|
if (wo->nodetree && wo->use_nodes &&
|
|
|
|
|
blender::bke::node_tree_contains_tree(wo->nodetree, ntree))
|
2024-05-13 16:07:12 +02:00
|
|
|
{
|
2022-12-13 16:01:47 -06:00
|
|
|
GPU_material_free(&wo->gpumaterial);
|
2021-06-04 10:37:00 +02:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
2021-06-04 10:37:00 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
/* Sync to Image Editor under the following conditions:
|
|
|
|
|
* - current image is not pinned
|
|
|
|
|
* - current image is not a Render Result or ViewerNode (want to keep looking at these) */
|
|
|
|
|
if (node->id != nullptr && GS(node->id->name) == ID_IM) {
|
|
|
|
|
Image *image = (Image *)node->id;
|
|
|
|
|
ED_space_image_sync(bmain, image, true);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
if (r_active_texture_changed) {
|
|
|
|
|
*r_active_texture_changed = true;
|
|
|
|
|
}
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2022-12-13 16:01:47 -06:00
|
|
|
WM_main_add_notifier(NC_IMAGE, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id);
|
|
|
|
|
}
|
|
|
|
|
else if (ntree->type == NTREE_COMPOSIT) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Make active viewer, currently only one is supported. */
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == CMP_NODE_VIEWER) {
|
2022-12-13 16:01:47 -06:00
|
|
|
for (bNode *node_iter : ntree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_iter->type_legacy == CMP_NODE_VIEWER) {
|
2022-12-13 16:01:47 -06:00
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2020-05-25 10:43:44 +02:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
|
if (was_output == 0) {
|
|
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-13 16:01:47 -06:00
|
|
|
/* Adding a node doesn't link this yet. */
|
|
|
|
|
node->id = (ID *)BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (node->type_legacy == CMP_NODE_COMPOSITE) {
|
2022-12-13 16:01:47 -06:00
|
|
|
if (was_output == 0) {
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node_iter : ntree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_iter->type_legacy == CMP_NODE_COMPOSITE) {
|
2020-12-14 17:19:43 -06:00
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2022-12-13 16:01:47 -06:00
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
else if (do_update) {
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2022-12-13 16:01:47 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ntree->type == NTREE_GEOMETRY) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == GEO_NODE_VIEWER) {
|
2022-12-13 16:01:47 -06:00
|
|
|
if ((node->flag & NODE_DO_OUTPUT) == 0) {
|
|
|
|
|
for (bNode *node_iter : ntree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_iter->type_legacy == GEO_NODE_VIEWER) {
|
2022-12-13 16:01:47 -06:00
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2021-07-05 10:46:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2021-07-05 10:46:00 +02:00
|
|
|
}
|
2022-12-13 16:01:47 -06:00
|
|
|
blender::ed::viewer_path::activate_geometry_node(*bmain, *snode, *node);
|
2021-07-05 10:46:00 +02:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
void ED_node_post_apply_transform(bContext * /*C*/, bNodeTree * /*ntree*/)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
/* XXX This does not work due to layout functions relying on node->block,
|
2024-12-13 16:51:56 +01:00
|
|
|
* which only exists during actual drawing. Can we rely on valid draw_bounds rects?
|
2011-09-05 21:01:50 +00:00
|
|
|
*/
|
|
|
|
|
/* make sure nodes have correct bounding boxes after transform */
|
2021-02-05 16:23:34 +11:00
|
|
|
// node_update_nodetree(C, ntree, 0.0f, 0.0f);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Generic
|
|
|
|
|
* \{ */
|
2009-09-15 11:35:10 +00:00
|
|
|
|
2022-09-02 17:03:48 -05:00
|
|
|
static bool socket_is_occluded(const float2 &location,
|
2022-08-21 10:12:50 +02:00
|
|
|
const bNode &node_the_socket_belongs_to,
|
2023-10-10 10:57:51 +02:00
|
|
|
const Span<bNode *> sorted_nodes)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2023-10-10 10:57:51 +02:00
|
|
|
for (bNode *node : sorted_nodes) {
|
2022-08-21 10:12:50 +02:00
|
|
|
if (node == &node_the_socket_belongs_to) {
|
|
|
|
|
/* Nodes after this one are underneath and can't occlude the socket. */
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rctf socket_hitbox;
|
|
|
|
|
const float socket_hitbox_radius = NODE_SOCKSIZE - 0.1f * U.widget_unit;
|
2022-09-02 17:03:48 -05:00
|
|
|
BLI_rctf_init_pt_radius(&socket_hitbox, location, socket_hitbox_radius);
|
2024-12-13 16:51:56 +01:00
|
|
|
if (BLI_rctf_inside_rctf(&node->runtime->draw_bounds, &socket_hitbox)) {
|
2022-08-21 10:12:50 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2022-08-21 10:12:50 +02:00
|
|
|
return false;
|
2009-09-15 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Size Widget Operator
|
|
|
|
|
* \{ */
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
struct NodeSizeWidget {
|
2012-08-01 19:11:17 +00:00
|
|
|
float mxstart, mystart;
|
|
|
|
|
float oldlocx, oldlocy;
|
|
|
|
|
float oldwidth, oldheight;
|
|
|
|
|
int directions;
|
2025-01-10 10:12:27 +01:00
|
|
|
bool precision, snap_to_grid;
|
2021-06-02 17:19:36 +02:00
|
|
|
};
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2022-03-18 13:13:45 +11:00
|
|
|
static void node_resize_init(
|
2022-09-02 14:09:32 -05:00
|
|
|
bContext *C, wmOperator *op, const float2 &cursor, const bNode *node, NodeResizeDirection dir)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2025-01-10 10:12:27 +01:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2021-12-24 22:17:49 -05:00
|
|
|
NodeSizeWidget *nsw = MEM_cnew<NodeSizeWidget>(__func__);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
op->customdata = nsw;
|
2022-03-18 13:13:45 +11:00
|
|
|
|
2022-09-02 14:09:32 -05:00
|
|
|
nsw->mxstart = cursor.x;
|
|
|
|
|
nsw->mystart = cursor.y;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* store old */
|
2024-12-11 21:06:41 +01:00
|
|
|
nsw->oldlocx = node->location[0];
|
|
|
|
|
nsw->oldlocy = node->location[1];
|
2012-08-01 19:11:17 +00:00
|
|
|
nsw->oldwidth = node->width;
|
|
|
|
|
nsw->oldheight = node->height;
|
|
|
|
|
nsw->directions = dir;
|
2025-01-10 10:12:27 +01:00
|
|
|
nsw->snap_to_grid = scene->toolsettings->snap_flag_node;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-09-06 22:34:29 +00:00
|
|
|
WM_cursor_modal_set(CTX_wm_window(C), node_get_resize_cursor(dir));
|
2010-04-07 17:06:22 +00:00
|
|
|
/* add modal handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-11 15:29:24 +01:00
|
|
|
static void node_resize_exit(bContext *C, wmOperator *op, bool cancel)
|
2011-01-31 14:42:55 +00:00
|
|
|
{
|
2013-09-06 22:34:29 +00:00
|
|
|
WM_cursor_modal_restore(CTX_wm_window(C));
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-02-11 15:29:24 +01:00
|
|
|
/* Restore old data on cancel. */
|
|
|
|
|
if (cancel) {
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *node = bke::node_get_active(snode->edittree);
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeSizeWidget *nsw = (NodeSizeWidget *)op->customdata;
|
2020-02-11 15:29:24 +01:00
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
node->location[0] = nsw->oldlocx;
|
|
|
|
|
node->location[1] = nsw->oldlocy;
|
2020-02-11 15:29:24 +01:00
|
|
|
node->width = nsw->oldwidth;
|
|
|
|
|
node->height = nsw->oldheight;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
MEM_freeN(op->customdata);
|
2021-06-02 17:19:36 +02:00
|
|
|
op->customdata = nullptr;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-10 10:12:27 +01:00
|
|
|
enum class NodeResizeAction : int {
|
|
|
|
|
Begin = 0,
|
|
|
|
|
Cancel = 1,
|
|
|
|
|
SnapInvertOn = 2,
|
|
|
|
|
SnapInvertOff = 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
wmKeyMap *node_resize_modal_keymap(wmKeyConfig *keyconf)
|
|
|
|
|
{
|
|
|
|
|
static const EnumPropertyItem modal_items[] = {
|
|
|
|
|
{int(NodeResizeAction::Begin), "BEGIN", 0, "Resize Node", ""},
|
|
|
|
|
{int(NodeResizeAction::Cancel), "CANCEL", 0, "Cancel", ""},
|
|
|
|
|
{int(NodeResizeAction::SnapInvertOn), "SNAP_INVERT_ON", 0, "Snap Invert", ""},
|
|
|
|
|
{int(NodeResizeAction::SnapInvertOff), "SNAP_INVERT_OFF", 0, "Snap Invert", ""},
|
|
|
|
|
{0, nullptr, 0, nullptr, nullptr},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Node Resize Modal Map");
|
|
|
|
|
|
|
|
|
|
if (keymap && keymap->modal_items) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keymap = WM_modalkeymap_ensure(keyconf, "Node Resize Modal Map", modal_items);
|
|
|
|
|
|
|
|
|
|
WM_modalkeymap_assign(keymap, "NODE_OT_resize");
|
|
|
|
|
|
|
|
|
|
return keymap;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 17:56:22 +01:00
|
|
|
/* Compute the nearest 1D coordinate corresponding to the nearest grid in node editors. */
|
2024-11-27 11:09:48 +01:00
|
|
|
static float nearest_node_grid_coord(float co)
|
|
|
|
|
{
|
2025-02-10 17:56:22 +01:00
|
|
|
/* Size and location of nodes are independent of UI scale, so grid size should be independent of
|
|
|
|
|
* UI scale as well. */
|
|
|
|
|
float grid_size = grid_size_get() / UI_SCALE_FAC;
|
2024-11-27 11:09:48 +01:00
|
|
|
float rest = fmod(co, grid_size);
|
|
|
|
|
float offset = rest - grid_size / 2 >= 0 ? grid_size : 0;
|
|
|
|
|
|
|
|
|
|
return co - rest + offset;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *node = bke::node_get_active(snode->edittree);
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeSizeWidget *nsw = (NodeSizeWidget *)op->customdata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-10 10:12:27 +01:00
|
|
|
if (event->type == EVT_MODAL_MAP) {
|
|
|
|
|
switch (NodeResizeAction(event->val)) {
|
|
|
|
|
case NodeResizeAction::Begin: {
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
case NodeResizeAction::Cancel: {
|
|
|
|
|
node_resize_exit(C, op, true);
|
|
|
|
|
ED_region_tag_redraw(region);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
case NodeResizeAction::SnapInvertOn:
|
|
|
|
|
case NodeResizeAction::SnapInvertOff: {
|
|
|
|
|
nsw->snap_to_grid = !nsw->snap_to_grid;
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-27 11:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
switch (event->type) {
|
2020-12-14 17:19:43 -06:00
|
|
|
case MOUSEMOVE: {
|
2022-09-02 14:09:32 -05:00
|
|
|
int2 mval;
|
2022-03-09 08:36:36 +11:00
|
|
|
WM_event_drag_start_mval(event, region, mval);
|
2020-12-14 17:19:43 -06:00
|
|
|
float mx, my;
|
2022-09-02 14:09:32 -05:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, mval.x, mval.y, &mx, &my);
|
2024-11-27 11:09:48 +01:00
|
|
|
float dx = (mx - nsw->mxstart) / UI_SCALE_FAC;
|
2023-03-17 04:19:05 +01:00
|
|
|
const float dy = (my - nsw->mystart) / UI_SCALE_FAC;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node) {
|
2020-12-14 17:19:43 -06:00
|
|
|
float *pwidth = &node->width;
|
|
|
|
|
float oldwidth = nsw->oldwidth;
|
|
|
|
|
float widthmin = node->typeinfo->minwidth;
|
|
|
|
|
float widthmax = node->typeinfo->maxwidth;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-09 08:51:37 +02:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
2014-05-09 08:51:37 +02:00
|
|
|
*pwidth = oldwidth + dx;
|
2024-11-27 11:09:48 +01:00
|
|
|
|
2025-01-10 10:12:27 +01:00
|
|
|
if (nsw->snap_to_grid) {
|
2024-11-27 11:09:48 +01:00
|
|
|
*pwidth = nearest_node_grid_coord(*pwidth);
|
|
|
|
|
}
|
2014-05-09 08:51:37 +02:00
|
|
|
CLAMP(*pwidth, widthmin, widthmax);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
2014-05-09 08:51:37 +02:00
|
|
|
float locmax = nsw->oldlocx + oldwidth;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-10 10:12:27 +01:00
|
|
|
if (nsw->snap_to_grid) {
|
2024-11-27 11:09:48 +01:00
|
|
|
dx = nearest_node_grid_coord(dx);
|
|
|
|
|
}
|
2024-12-11 21:06:41 +01:00
|
|
|
node->location[0] = nsw->oldlocx + dx;
|
|
|
|
|
CLAMP(node->location[0], locmax - widthmax, locmax - widthmin);
|
|
|
|
|
*pwidth = locmax - node->location[0];
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Height works the other way round. */
|
2012-08-01 19:11:17 +00:00
|
|
|
{
|
2023-03-17 04:19:05 +01:00
|
|
|
float heightmin = UI_SCALE_FAC * node->typeinfo->minheight;
|
|
|
|
|
float heightmax = UI_SCALE_FAC * node->typeinfo->maxheight;
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_TOP) {
|
|
|
|
|
float locmin = nsw->oldlocy - nsw->oldheight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-11 21:06:41 +01:00
|
|
|
node->location[1] = nsw->oldlocy + dy;
|
|
|
|
|
CLAMP(node->location[1], locmin + heightmin, locmin + heightmax);
|
|
|
|
|
node->height = node->location[1] - locmin;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_BOTTOM) {
|
|
|
|
|
node->height = nsw->oldheight - dy;
|
|
|
|
|
CLAMP(node->height, heightmin, heightmax);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_tag_redraw(region);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
2020-12-14 17:19:43 -06:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
case LEFTMOUSE:
|
|
|
|
|
case MIDDLEMOUSE:
|
2020-12-14 17:19:43 -06:00
|
|
|
case RIGHTMOUSE: {
|
2018-06-13 14:03:46 +02:00
|
|
|
if (event->val == KM_RELEASE) {
|
|
|
|
|
node_resize_exit(C, op, false);
|
|
|
|
|
ED_node_post_apply_transform(C, snode->edittree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-13 14:03:46 +02:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-12-14 17:19:43 -06:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
2009-02-06 16:34:05 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2024-08-19 20:27:37 +02:00
|
|
|
const bNode *node = bke::node_get_active(snode->edittree);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
if (node == nullptr) {
|
|
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
2019-03-20 19:13:56 +01:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Convert mouse coordinates to `v2d` space. */
|
2022-09-02 14:09:32 -05:00
|
|
|
float2 cursor;
|
|
|
|
|
int2 mval;
|
2022-03-09 08:36:36 +11:00
|
|
|
WM_event_drag_start_mval(event, region, mval);
|
2022-09-02 14:09:32 -05:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, mval.x, mval.y, &cursor.x, &cursor.y);
|
2023-06-03 12:45:12 +02:00
|
|
|
const NodeResizeDirection dir = node_get_resize_direction(*snode, node, cursor.x, cursor.y);
|
2021-12-03 16:25:17 -05:00
|
|
|
if (dir == NODE_RESIZE_NONE) {
|
|
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
|
2022-03-18 13:13:45 +11:00
|
|
|
node_resize_init(C, op, cursor, node, dir);
|
2021-12-03 16:25:17 -05:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-30 23:08:53 +00:00
|
|
|
static void node_resize_cancel(bContext *C, wmOperator *op)
|
2011-06-06 11:04:54 +00:00
|
|
|
{
|
2013-10-30 23:08:53 +00:00
|
|
|
node_resize_exit(C, op, true);
|
2011-06-06 11:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void NODE_OT_resize(wmOperatorType *ot)
|
2009-02-06 16:34:05 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->name = "Resize Node";
|
|
|
|
|
ot->idname = "NODE_OT_resize";
|
|
|
|
|
ot->description = "Resize a node";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
/* api callbacks */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->invoke = node_resize_invoke;
|
|
|
|
|
ot->modal = node_resize_modal;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->cancel = node_resize_cancel;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
/* flags */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Hidden Sockets
|
|
|
|
|
* \{ */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2020-09-02 19:10:18 +02:00
|
|
|
bool node_has_hidden_sockets(bNode *node)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sock->flag & SOCK_HIDDEN) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sock->flag & SOCK_HIDDEN) {
|
2020-09-02 19:10:18 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-02 19:10:18 +02:00
|
|
|
return false;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-04 14:55:20 +10:00
|
|
|
void node_set_hidden_sockets(bNode *node, int set)
|
2012-06-01 12:38:03 +00:00
|
|
|
{
|
2023-09-27 18:42:46 +02:00
|
|
|
/* The Reroute node is the socket itself, do not hide this. */
|
|
|
|
|
if (node->is_reroute()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (set == 0) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2012-08-01 19:11:17 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
2012-08-01 19:11:17 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Hide unused sockets. */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2021-06-02 17:19:36 +02:00
|
|
|
if (sock->link == nullptr) {
|
2012-08-01 19:11:17 +00:00
|
|
|
sock->flag |= SOCK_HIDDEN;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
2023-06-03 12:34:58 +02:00
|
|
|
if ((sock->flag & SOCK_IS_LINKED) == 0) {
|
2012-08-01 19:11:17 +00:00
|
|
|
sock->flag |= SOCK_HIDDEN;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-09 14:04:11 +02:00
|
|
|
bool node_is_previewable(const SpaceNode &snode, const bNodeTree &ntree, const bNode &node)
|
2023-08-08 17:36:06 +02:00
|
|
|
{
|
2023-08-09 14:04:11 +02:00
|
|
|
if (!(snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) ||
|
|
|
|
|
!(snode.overlay.flag & SN_OVERLAY_SHOW_PREVIEWS))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-08 17:36:06 +02:00
|
|
|
if (ntree.type == NTREE_SHADER) {
|
2024-12-13 11:21:39 +11:00
|
|
|
return USER_EXPERIMENTAL_TEST(&U, use_shader_node_previews) && !node.is_frame();
|
2023-08-08 17:36:06 +02:00
|
|
|
}
|
|
|
|
|
return node.typeinfo->flag & NODE_PREVIEW;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
static bool cursor_isect_multi_input_socket(const float2 &cursor, const bNodeSocket &socket)
|
2021-02-11 01:16:17 -06:00
|
|
|
{
|
|
|
|
|
const float node_socket_height = node_socket_calculate_height(socket);
|
2023-03-19 07:03:01 +01:00
|
|
|
const float2 location = socket.runtime->location;
|
2024-12-11 21:06:41 +01:00
|
|
|
/* `.xmax = socket->location[0] + NODE_SOCKSIZE * 5.5f`
|
2021-06-02 17:19:36 +02:00
|
|
|
* would be the same behavior as for regular sockets.
|
|
|
|
|
* But keep it smaller because for multi-input socket you
|
|
|
|
|
* sometimes want to drag the link to the other side, if you may
|
|
|
|
|
* accidentally pick the wrong link otherwise. */
|
2022-09-02 17:03:48 -05:00
|
|
|
rctf multi_socket_rect;
|
2021-06-02 17:19:36 +02:00
|
|
|
BLI_rctf_init(&multi_socket_rect,
|
2022-09-02 17:03:48 -05:00
|
|
|
location.x - NODE_SOCKSIZE * 4.0f,
|
|
|
|
|
location.x + NODE_SOCKSIZE * 2.0f,
|
|
|
|
|
location.y - node_socket_height,
|
|
|
|
|
location.y + node_socket_height);
|
2022-09-02 14:09:32 -05:00
|
|
|
if (BLI_rctf_isect_pt(&multi_socket_rect, cursor.x, cursor.y)) {
|
2021-02-11 01:16:17 -06:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 13:34:51 -05:00
|
|
|
bNodeSocket *node_find_indicated_socket(SpaceNode &snode,
|
2023-11-25 15:23:31 +01:00
|
|
|
ARegion ®ion,
|
2023-01-03 13:34:51 -05:00
|
|
|
const float2 &cursor,
|
|
|
|
|
const eNodeSocketInOut in_out)
|
2009-02-07 14:03:34 +00:00
|
|
|
{
|
2023-11-25 15:23:31 +01:00
|
|
|
const float view2d_scale = UI_view2d_scale_get_x(®ion.v2d);
|
|
|
|
|
const float max_distance = NODE_SOCKSIZE + std::clamp(20.0f / view2d_scale, 5.0f, 30.0f);
|
2023-11-27 10:14:49 +01:00
|
|
|
const float padded_socket_size = NODE_SOCKSIZE + 4;
|
2022-02-18 12:22:51 -06:00
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
bNodeTree &tree = *snode.edittree;
|
|
|
|
|
tree.ensure_topology_cache();
|
2023-10-10 10:57:51 +02:00
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
const Array<bNode *> sorted_nodes = tree_draw_order_calc_nodes_reversed(tree);
|
2023-10-10 10:57:51 +02:00
|
|
|
if (sorted_nodes.is_empty()) {
|
2023-01-19 15:49:49 -06:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
float best_distance = FLT_MAX;
|
|
|
|
|
bNodeSocket *best_socket = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
auto update_best_socket = [&](bNodeSocket *socket, const float distance) {
|
|
|
|
|
if (socket_is_occluded(socket->runtime->location, socket->owner_node(), sorted_nodes)) {
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2023-11-25 15:23:31 +01:00
|
|
|
if (distance < best_distance) {
|
|
|
|
|
best_distance = distance;
|
|
|
|
|
best_socket = socket;
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
for (bNode *node : sorted_nodes) {
|
2024-01-09 13:19:40 +01:00
|
|
|
const bool node_hidden = node->flag & NODE_HIDDEN;
|
2024-12-13 11:15:15 -05:00
|
|
|
if (!node->is_reroute() && !node_hidden &&
|
|
|
|
|
node->runtime->draw_bounds.ymax - cursor.y < NODE_DY)
|
|
|
|
|
{
|
2024-01-09 13:19:40 +01:00
|
|
|
/* Don't pick socket when cursor is over node header. This allows the user to always resize
|
|
|
|
|
* by dragging on the left and right side of the header. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (in_out & SOCK_IN) {
|
2023-11-25 15:23:31 +01:00
|
|
|
for (bNodeSocket *sock : node->input_sockets()) {
|
|
|
|
|
if (!node->is_socket_icon_drawn(*sock)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const float2 location = sock->runtime->location;
|
|
|
|
|
const float distance = math::distance(location, cursor);
|
2024-01-09 13:19:40 +01:00
|
|
|
if (sock->flag & SOCK_MULTI_INPUT && !node_hidden) {
|
2023-11-25 15:23:31 +01:00
|
|
|
if (cursor_isect_multi_input_socket(cursor, *sock)) {
|
|
|
|
|
update_best_socket(sock, distance);
|
|
|
|
|
continue;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-25 15:23:31 +01:00
|
|
|
if (distance < max_distance) {
|
|
|
|
|
update_best_socket(sock, distance);
|
|
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (in_out & SOCK_OUT) {
|
2023-11-25 15:23:31 +01:00
|
|
|
for (bNodeSocket *sock : node->output_sockets()) {
|
|
|
|
|
if (!node->is_socket_icon_drawn(*sock)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const float2 location = sock->runtime->location;
|
|
|
|
|
const float distance = math::distance(location, cursor);
|
|
|
|
|
if (distance < max_distance) {
|
2024-01-09 13:19:40 +01:00
|
|
|
if (node_hidden) {
|
2023-11-27 10:14:49 +01:00
|
|
|
if (location.x - cursor.x > padded_socket_size) {
|
|
|
|
|
/* Needed to be able to resize collapsed nodes. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-25 15:23:31 +01:00
|
|
|
update_best_socket(sock, distance);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-25 15:23:31 +01:00
|
|
|
return best_socket;
|
2021-07-15 11:00:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Link Dimming
|
|
|
|
|
* \{ */
|
2021-07-15 11:00:23 +02:00
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
float node_link_dim_factor(const View2D &v2d, const bNodeLink &link)
|
2021-07-15 11:00:23 +02:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
if (link.fromsock == nullptr || link.tosock == nullptr) {
|
2021-07-15 12:43:03 +02:00
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2024-05-23 19:52:37 +02:00
|
|
|
if (link.flag & NODE_LINK_INSERT_TARGET_INVALID) {
|
|
|
|
|
return 0.2f;
|
|
|
|
|
}
|
2021-07-15 12:43:03 +02:00
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
const float2 from = link.fromsock->runtime->location;
|
|
|
|
|
const float2 to = link.tosock->runtime->location;
|
2022-09-02 17:03:48 -05:00
|
|
|
|
2021-07-15 11:00:23 +02:00
|
|
|
const float min_endpoint_distance = std::min(
|
2022-09-02 17:03:48 -05:00
|
|
|
std::max(BLI_rctf_length_x(&v2d.cur, from.x), BLI_rctf_length_y(&v2d.cur, from.y)),
|
|
|
|
|
std::max(BLI_rctf_length_x(&v2d.cur, to.x), BLI_rctf_length_y(&v2d.cur, to.y)));
|
2021-07-15 11:00:23 +02:00
|
|
|
|
|
|
|
|
if (min_endpoint_distance == 0.0f) {
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2021-12-03 16:25:17 -05:00
|
|
|
const float viewport_width = BLI_rctf_size_x(&v2d.cur);
|
2021-07-15 11:00:23 +02:00
|
|
|
return std::clamp(1.0f - min_endpoint_distance / viewport_width * 10.0f, 0.05f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 07:03:01 +01:00
|
|
|
bool node_link_is_hidden_or_dimmed(const View2D &v2d, const bNodeLink &link)
|
2021-07-15 11:00:23 +02:00
|
|
|
{
|
2024-08-19 20:27:37 +02:00
|
|
|
return bke::node_link_is_hidden(&link) || node_link_dim_factor(v2d, link) < 0.5f;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Duplicate Operator
|
|
|
|
|
* \{ */
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2022-11-18 12:46:20 +01:00
|
|
|
static void node_duplicate_reparent_recursive(bNodeTree *ntree,
|
2022-12-20 17:19:47 -06:00
|
|
|
const Map<bNode *, bNode *> &node_map,
|
2021-12-22 08:47:46 -06:00
|
|
|
bNode *node)
|
2009-02-07 14:03:34 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *parent;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->flag |= NODE_TEST;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Find first selected parent. */
|
2012-08-01 19:11:17 +00:00
|
|
|
for (parent = node->parent; parent; parent = parent->parent) {
|
|
|
|
|
if (parent->flag & SELECT) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!(parent->flag & NODE_TEST)) {
|
2022-11-18 11:20:13 +01:00
|
|
|
node_duplicate_reparent_recursive(ntree, node_map, parent);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Reparent node copy to parent copy. */
|
2012-08-01 19:11:17 +00:00
|
|
|
if (parent) {
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_detach_node(ntree, node_map.lookup(node));
|
|
|
|
|
bke::node_attach_node(ntree, node_map.lookup(node), node_map.lookup(parent));
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2009-02-07 14:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-16 17:03:13 +02:00
|
|
|
void remap_node_pairing(bNodeTree &dst_tree, const Map<const bNode *, bNode *> &node_map)
|
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
|
|
|
{
|
|
|
|
|
/* We don't have the old tree for looking up output nodes by ID,
|
|
|
|
|
* so we have to build a map first to find copied output nodes in the new tree. */
|
2023-06-16 17:03:13 +02:00
|
|
|
Map<int32_t, bNode *> dst_output_node_map;
|
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
|
|
|
for (const auto &item : node_map.items()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (bke::all_zone_output_node_types().contains(item.key->type_legacy)) {
|
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
|
|
|
dst_output_node_map.add_new(item.key->identifier, item.value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (bNode *dst_node : node_map.values()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (bke::all_zone_input_node_types().contains(dst_node->type_legacy)) {
|
|
|
|
|
const bke::bNodeZoneType &zone_type = *bke::zone_type_by_node_type(dst_node->type_legacy);
|
2023-09-20 14:40:56 +02:00
|
|
|
int &output_node_id = zone_type.get_corresponding_output_id(*dst_node);
|
|
|
|
|
if (const bNode *output_node = dst_output_node_map.lookup_default(output_node_id, nullptr)) {
|
|
|
|
|
output_node_id = output_node->identifier;
|
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
|
|
|
}
|
2023-09-20 14:40:56 +02:00
|
|
|
else {
|
|
|
|
|
output_node_id = 0;
|
|
|
|
|
blender::nodes::update_node_declaration_and_sockets(dst_tree, *dst_node);
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static int node_duplicate_exec(bContext *C, wmOperator *op)
|
2012-02-27 17:38:16 +00:00
|
|
|
{
|
2018-06-09 15:16:44 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
|
2022-10-13 20:06:20 +02:00
|
|
|
bool linked = RNA_boolean_get(op->ptr, "linked") || ((U.dupflag & USER_DUP_NTREE) == 0);
|
|
|
|
|
const bool dupli_node_tree = !linked;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-09 15:16:44 +02:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-20 17:19:47 -06:00
|
|
|
Map<bNode *, bNode *> node_map;
|
2021-12-22 08:47:46 -06:00
|
|
|
Map<const bNodeSocket *, bNodeSocket *> socket_map;
|
2022-10-13 20:06:20 +02:00
|
|
|
Map<const ID *, ID *> duplicated_node_groups;
|
2021-12-22 08:47:46 -06:00
|
|
|
|
2024-09-23 01:30:40 +02:00
|
|
|
node_select_paired(*ntree);
|
|
|
|
|
|
2022-12-20 17:19:47 -06:00
|
|
|
for (bNode *node : get_selected_nodes(*ntree)) {
|
|
|
|
|
bNode *new_node = bke::node_copy_with_mapping(
|
|
|
|
|
ntree, *node, LIB_ID_COPY_DEFAULT, true, socket_map);
|
|
|
|
|
node_map.add_new(node, new_node);
|
|
|
|
|
|
|
|
|
|
if (node->id && dupli_node_tree) {
|
|
|
|
|
ID *new_group = duplicated_node_groups.lookup_or_add_cb(node->id, [&]() {
|
|
|
|
|
ID *new_group = BKE_id_copy(bmain, node->id);
|
|
|
|
|
/* Remove user added by copying. */
|
|
|
|
|
id_us_min(new_group);
|
|
|
|
|
return new_group;
|
|
|
|
|
});
|
|
|
|
|
id_us_plus(new_group);
|
|
|
|
|
id_us_min(new_node->id);
|
|
|
|
|
new_node->id = new_group;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-07-22 16:39:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-20 17:19:47 -06:00
|
|
|
if (node_map.is_empty()) {
|
2022-04-05 20:13:03 +10:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
/* Copy links between selected nodes. */
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeLink *lastlink = (bNodeLink *)ntree->links.last;
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* This creates new links between copied nodes. If keep_inputs is set, also copies input links
|
|
|
|
|
* from unselected (when fromnode is null)! */
|
2012-08-01 19:11:17 +00:00
|
|
|
if (link->tonode && (link->tonode->flag & NODE_SELECT) &&
|
|
|
|
|
(keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT))))
|
|
|
|
|
{
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeLink *newlink = MEM_cnew<bNodeLink>("bNodeLink");
|
2012-08-01 19:11:17 +00:00
|
|
|
newlink->flag = link->flag;
|
2021-12-22 08:47:46 -06:00
|
|
|
newlink->tonode = node_map.lookup(link->tonode);
|
|
|
|
|
newlink->tosock = socket_map.lookup(link->tosock);
|
2022-04-18 22:28:03 +02:00
|
|
|
|
|
|
|
|
if (link->tosock->flag & SOCK_MULTI_INPUT) {
|
2024-03-19 13:42:09 +01:00
|
|
|
newlink->multi_input_sort_id = link->multi_input_sort_id;
|
2022-04-18 22:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) {
|
2021-12-22 08:47:46 -06:00
|
|
|
newlink->fromnode = node_map.lookup(link->fromnode);
|
|
|
|
|
newlink->fromsock = socket_map.lookup(link->fromsock);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Input node not copied, this keeps the original input linked. */
|
2012-08-01 19:11:17 +00:00
|
|
|
newlink->fromnode = link->fromnode;
|
|
|
|
|
newlink->fromsock = link->fromsock;
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
BLI_addtail(&ntree->links, newlink);
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Make sure we don't copy new links again. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (link == lastlink) {
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +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
|
|
|
for (bNode *node : node_map.values()) {
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_declaration_ensure(ntree, node);
|
2024-05-25 14:55:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntree->ensure_topology_cache();
|
|
|
|
|
for (bNode *node : node_map.values()) {
|
2024-05-22 05:57:35 +02:00
|
|
|
update_multi_input_indices_for_removed_links(*node);
|
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
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Clear flags for recursive depth-first iteration. */
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : ntree->all_nodes()) {
|
2012-08-01 19:11:17 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Reparent copied nodes. */
|
2022-12-20 17:19:47 -06:00
|
|
|
for (bNode *node : node_map.keys()) {
|
|
|
|
|
if (!(node->flag & NODE_TEST)) {
|
2022-11-18 11:20:13 +01:00
|
|
|
node_duplicate_reparent_recursive(ntree, node_map, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-16 17:03:13 +02:00
|
|
|
{
|
|
|
|
|
/* Use temporary map that has const key, because that's what the function below expects. */
|
|
|
|
|
Map<const bNode *, bNode *> const_node_map;
|
|
|
|
|
for (const auto item : node_map.items()) {
|
|
|
|
|
const_node_map.add(item.key, item.value);
|
|
|
|
|
}
|
|
|
|
|
remap_node_pairing(*ntree, const_node_map);
|
|
|
|
|
}
|
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
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Deselect old nodes, select the copies instead. */
|
2022-12-20 17:19:47 -06:00
|
|
|
for (const auto item : node_map.items()) {
|
|
|
|
|
bNode *src_node = item.key;
|
|
|
|
|
bNode *dst_node = item.value;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_set_selected(src_node, false);
|
2022-12-20 17:19:47 -06:00
|
|
|
src_node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_TEXTURE);
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_set_selected(dst_node, true);
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-04-02 15:40:51 +02:00
|
|
|
tree_draw_order_update(*snode->edittree);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, snode->edittree->id);
|
2012-08-01 19:11:17 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void NODE_OT_duplicate(wmOperatorType *ot)
|
2011-07-22 15:28:50 +00:00
|
|
|
{
|
2022-10-13 20:06:20 +02:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Duplicate Nodes";
|
|
|
|
|
ot->description = "Duplicate selected nodes";
|
|
|
|
|
ot->idname = "NODE_OT_duplicate";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_duplicate_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
RNA_def_boolean(
|
2021-06-02 17:19:36 +02:00
|
|
|
ot->srna, "keep_inputs", false, "Keep Inputs", "Keep the input links to duplicated nodes");
|
2022-10-13 20:06:20 +02:00
|
|
|
|
|
|
|
|
prop = RNA_def_boolean(ot->srna,
|
|
|
|
|
"linked",
|
|
|
|
|
true,
|
|
|
|
|
"Linked",
|
|
|
|
|
"Duplicate node but not node trees, linking to the original data");
|
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Goes over all scenes, reads render layers. */
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_read_viewlayers_exec(bContext *C, wmOperator * /*op*/)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2020-12-14 17:19:43 -06:00
|
|
|
Scene *curscene = CTX_data_scene(C);
|
2022-12-02 11:12:51 -06:00
|
|
|
bNodeTree &edit_tree = *snode->edittree;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
2010-07-04 19:58:52 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* first tag scenes unread */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
|
2024-08-07 12:12:17 +02:00
|
|
|
scene->id.tag |= ID_TAG_DOIT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : edit_tree.all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if ((node->type_legacy == CMP_NODE_R_LAYERS) ||
|
|
|
|
|
(node->type_legacy == CMP_NODE_CRYPTOMATTE &&
|
|
|
|
|
node->custom1 == CMP_NODE_CRYPTOMATTE_SOURCE_RENDER))
|
Compositor: Redesign Cryptomatte node for better usability
In the current implementation, cryptomatte passes are connected to the node
and elements are picked by using the eyedropper tool on a special pick channel.
This design has two disadvantages - both connecting all passes individually
and always having to switch to the picker channel are tedious.
With the new design, the user selects the RenderLayer or Image from which the
Cryptomatte layers are directly loaded (the type of pass is determined by an
enum). This allows the node to automatically detect all relevant passes.
Then, when using the eyedropper tool, the operator looks up the selected
coordinates from the picked Image, Node backdrop or Clip and reads the picked
object directly from the Renderlayer/Image, therefore allowing to pick in any
context (e.g. by clicking on the Combined pass in the Image Viewer). The
sampled color is looked up in the metadata and the actual name is stored
in the cryptomatte node. This also allows to remove a hash by just removing
the name from the matte id.
Technically there is some loss of flexibility because the Cryptomatte pass
inputs can no longer be connected to other nodes, but since any compositing
done on them is likely to break the Cryptomatte system anyways, this isn't
really a concern in practise.
In the future, this would also allow to automatically translate values to names
by looking up the value in the associated metadata of the input, or to get a
better visualization of overlapping areas in the Pick output since we could
blend colors now that the output doesn't have to contain the exact value.
Idea + Original patch: Lucas Stockner
Reviewed By: Brecht van Lommel
Differential Revision: https://developer.blender.org/D3959
2021-03-16 07:37:30 +01:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
ID *id = node->id;
|
2021-06-02 17:19:36 +02:00
|
|
|
if (id == nullptr) {
|
Compositor: Redesign Cryptomatte node for better usability
In the current implementation, cryptomatte passes are connected to the node
and elements are picked by using the eyedropper tool on a special pick channel.
This design has two disadvantages - both connecting all passes individually
and always having to switch to the picker channel are tedious.
With the new design, the user selects the RenderLayer or Image from which the
Cryptomatte layers are directly loaded (the type of pass is determined by an
enum). This allows the node to automatically detect all relevant passes.
Then, when using the eyedropper tool, the operator looks up the selected
coordinates from the picked Image, Node backdrop or Clip and reads the picked
object directly from the Renderlayer/Image, therefore allowing to pick in any
context (e.g. by clicking on the Combined pass in the Image Viewer). The
sampled color is looked up in the metadata and the actual name is stored
in the cryptomatte node. This also allows to remove a hash by just removing
the name from the matte id.
Technically there is some loss of flexibility because the Cryptomatte pass
inputs can no longer be connected to other nodes, but since any compositing
done on them is likely to break the Cryptomatte system anyways, this isn't
really a concern in practise.
In the future, this would also allow to automatically translate values to names
by looking up the value in the associated metadata of the input, or to get a
better visualization of overlapping areas in the Pick output since we could
blend colors now that the output doesn't have to contain the exact value.
Idea + Original patch: Lucas Stockner
Reviewed By: Brecht van Lommel
Differential Revision: https://developer.blender.org/D3959
2021-03-16 07:37:30 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2024-08-07 12:12:17 +02:00
|
|
|
if (id->tag & ID_TAG_DOIT) {
|
2009-02-07 14:03:34 +00:00
|
|
|
RE_ReadRenderResult(curscene, (Scene *)id);
|
2008-12-24 10:33:10 +00:00
|
|
|
ntreeCompositTagRender((Scene *)id);
|
2024-08-07 12:12:17 +02:00
|
|
|
id->tag &= ~ID_TAG_DOIT;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, edit_tree.id);
|
2011-05-02 12:31:09 +00:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
void NODE_OT_read_viewlayers(wmOperatorType *ot)
|
2010-04-06 17:47:21 +00:00
|
|
|
{
|
2017-11-22 10:52:39 -02:00
|
|
|
ot->name = "Read View Layers";
|
|
|
|
|
ot->idname = "NODE_OT_read_viewlayers";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Read all render layers of all used scenes";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
ot->exec = node_read_viewlayers_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
int node_render_changed_exec(bContext *C, wmOperator * /*op*/)
|
2011-02-07 16:41:57 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Scene *sce = CTX_data_scene(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-07-01 12:52:58 +02:00
|
|
|
/* This is actually a test whether scene is used by the compositor or not.
|
|
|
|
|
* All the nodes are using same render result, so there is no need to do
|
|
|
|
|
* anything smart about check how exactly scene is used. */
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *node = nullptr;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node_iter : sce->nodetree->all_nodes()) {
|
2020-12-14 17:19:43 -06:00
|
|
|
if (node_iter->id == (ID *)sce) {
|
|
|
|
|
node = node_iter;
|
2011-02-07 16:41:57 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-01 12:52:58 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node) {
|
2021-06-02 17:19:36 +02:00
|
|
|
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&sce->view_layers, node->custom1);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
if (view_layer) {
|
2011-02-07 16:41:57 +00:00
|
|
|
PointerRNA op_ptr;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
|
2017-11-22 10:52:39 -02:00
|
|
|
RNA_string_set(&op_ptr, "layer", view_layer->name);
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_string_set(&op_ptr, "scene", sce->id.name + 2);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-03 10:46:16 +10:00
|
|
|
/* To keep keyframe positions. */
|
2011-02-07 18:09:27 +00:00
|
|
|
sce->r.scemode |= R_NO_FRAME_UPDATE;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-03-11 22:49:47 +11:00
|
|
|
WM_operator_name_call(C, "RENDER_OT_render", WM_OP_INVOKE_DEFAULT, &op_ptr, nullptr);
|
2011-02-07 16:41:57 +00:00
|
|
|
|
|
|
|
|
WM_operator_properties_free(&op_ptr);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_render_changed(wmOperatorType *ot)
|
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Render Changed Layer";
|
|
|
|
|
ot->idname = "NODE_OT_render_changed";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Render current scene, when input node's layer has been changed";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_render_changed_exec;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
2011-02-07 16:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Hide Operator
|
|
|
|
|
* \{ */
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/**
|
|
|
|
|
* Toggles the flag on all selected nodes. If the flag is set on all nodes it is unset.
|
|
|
|
|
* If the flag is not set on all nodes, it is set.
|
|
|
|
|
*/
|
2010-06-07 20:03:40 +00:00
|
|
|
static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
int tot_eq = 0, tot_neq = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-09 14:04:11 +02:00
|
|
|
if (toggle_flag == NODE_PREVIEW && !node_is_previewable(*snode, *snode->edittree, *node)) {
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (toggle_flag == NODE_OPTIONS &&
|
|
|
|
|
!(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex))
|
|
|
|
|
{
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->flag & toggle_flag) {
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_eq++;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_neq++;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-09 14:04:11 +02:00
|
|
|
if (toggle_flag == NODE_PREVIEW && !node_is_previewable(*snode, *snode->edittree, *node)) {
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
if (toggle_flag == NODE_OPTIONS &&
|
|
|
|
|
!(node->typeinfo->draw_buttons || node->typeinfo->draw_buttons_ex))
|
|
|
|
|
{
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((tot_eq && tot_neq) || tot_eq == 0) {
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag |= toggle_flag;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag &= ~toggle_flag;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_hide_toggle_exec(bContext *C, wmOperator * /*op*/)
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Sanity checking (poll callback checks this already). */
|
2021-06-02 17:19:36 +02:00
|
|
|
if ((snode == nullptr) || (snode->edittree == nullptr)) {
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
node_flag_toggle_exec(snode, NODE_HIDDEN);
|
2012-07-16 16:16:05 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2012-07-16 16:16:05 +00:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
void NODE_OT_hide_toggle(wmOperatorType *ot)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Hide";
|
|
|
|
|
ot->description = "Toggle hiding of selected nodes";
|
|
|
|
|
ot->idname = "NODE_OT_hide_toggle";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_hide_toggle_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_preview_toggle_exec(bContext *C, wmOperator * /*op*/)
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Sanity checking (poll callback checks this already). */
|
2021-06-02 17:19:36 +02:00
|
|
|
if ((snode == nullptr) || (snode->edittree == nullptr)) {
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
node_flag_toggle_exec(snode, NODE_PREVIEW);
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), snode->edittree->id);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-08 17:36:06 +02:00
|
|
|
static bool node_previewable(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
if (ED_operator_node_active(C)) {
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
if (ED_node_supports_preview(snode)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
void NODE_OT_preview_toggle(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Preview";
|
|
|
|
|
ot->description = "Toggle preview display for selected nodes";
|
|
|
|
|
ot->idname = "NODE_OT_preview_toggle";
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_preview_toggle_exec;
|
2023-08-08 17:36:06 +02:00
|
|
|
ot->poll = node_previewable;
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_deactivate_viewer_exec(bContext *C, wmOperator * /*op*/)
|
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
|
|
|
{
|
|
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
WorkSpace &workspace = *CTX_wm_workspace(C);
|
|
|
|
|
|
|
|
|
|
bNode *active_viewer = viewer_path::find_geometry_nodes_viewer(workspace.viewer_path, snode);
|
|
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode.edittree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (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
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!(node->flag & SELECT)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (node == active_viewer) {
|
|
|
|
|
node->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
BKE_ntree_update_tag_node_property(snode.edittree, node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), snode.edittree->id);
|
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
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_deactivate_viewer(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Deactivate Viewer Node";
|
|
|
|
|
ot->description = "Deactivate selected viewer node in geometry nodes";
|
|
|
|
|
ot->idname = __func__;
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_deactivate_viewer_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_options_toggle_exec(bContext *C, wmOperator * /*op*/)
|
2011-12-18 12:51:50 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Sanity checking (poll callback checks this already). */
|
2021-06-02 17:19:36 +02:00
|
|
|
if ((snode == nullptr) || (snode->edittree == nullptr)) {
|
2011-12-18 12:51:50 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
|
node_flag_toggle_exec(snode, NODE_OPTIONS);
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_options_toggle(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Options";
|
|
|
|
|
ot->description = "Toggle option buttons display for selected nodes";
|
|
|
|
|
ot->idname = "NODE_OT_options_toggle";
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_options_toggle_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_socket_toggle_exec(bContext *C, wmOperator * /*op*/)
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Sanity checking (poll callback checks this already). */
|
2021-06-02 17:19:36 +02:00
|
|
|
if ((snode == nullptr) || (snode->edittree == nullptr)) {
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2010-07-04 19:58:52 +00:00
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
/* Toggle for all selected nodes */
|
2020-12-14 17:19:43 -06:00
|
|
|
bool hidden = false;
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-04-16 10:50:57 +00:00
|
|
|
if (node_has_hidden_sockets(node)) {
|
2020-12-14 17:19:43 -06:00
|
|
|
hidden = true;
|
2010-06-07 20:03:40 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2023-06-04 14:55:20 +10:00
|
|
|
node_set_hidden_sockets(node, !hidden);
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), snode->edittree->id);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2023-09-21 12:05:08 +02:00
|
|
|
/* Hack to force update of the button state after drawing, see #112462. */
|
|
|
|
|
WM_event_add_mousemove(CTX_wm_window(C));
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_hide_socket_toggle(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Hidden Node Sockets";
|
|
|
|
|
ot->description = "Toggle unused node socket display";
|
|
|
|
|
ot->idname = "NODE_OT_hide_socket_toggle";
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_socket_toggle_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Mute Operator
|
|
|
|
|
* \{ */
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_mute_exec(bContext *C, wmOperator * /*op*/)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2018-06-09 15:16:44 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2018-06-09 15:16:44 +02:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
2010-07-04 19:58:52 +00:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : snode->edittree->all_nodes()) {
|
2021-11-17 11:52:44 +01:00
|
|
|
if ((node->flag & SELECT) && !node->typeinfo->no_muting) {
|
2012-02-27 17:38:16 +00:00
|
|
|
node->flag ^= NODE_MUTED;
|
2021-12-22 14:00:17 -06:00
|
|
|
BKE_ntree_update_tag_node_mute(snode->edittree, node);
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, snode->edittree->id);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
void NODE_OT_mute_toggle(wmOperatorType *ot)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Mute";
|
2023-01-09 17:14:06 -05:00
|
|
|
ot->description = "Toggle muting of selected nodes";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_mute_toggle";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_mute_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Delete Operator
|
|
|
|
|
* \{ */
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_delete_exec(bContext *C, wmOperator * /*op*/)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2018-06-09 15:16:44 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2016-02-05 01:39:42 +05:00
|
|
|
|
2018-06-09 15:16:44 +02:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
2010-07-04 19:58:52 +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
|
|
|
/* Delete paired nodes as well. */
|
|
|
|
|
node_select_paired(*snode->edittree);
|
|
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH_MUTABLE (bNode *, node, &snode->edittree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2024-08-19 20:27:37 +02:00
|
|
|
bke::node_remove_node(bmain, snode->edittree, node, true);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, snode->edittree->id);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void NODE_OT_delete(wmOperatorType *ot)
|
2010-05-12 04:25:33 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->name = "Delete";
|
2023-01-09 17:14:06 -05:00
|
|
|
ot->description = "Remove selected nodes";
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->idname = "NODE_OT_delete";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_delete_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
2009-01-12 00:14:37 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Delete with Reconnect Operator
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_delete_reconnect_exec(bContext *C, wmOperator * /*op*/)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2018-11-23 17:02:55 +01:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2012-08-01 19:11:17 +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
|
|
|
/* Delete paired nodes as well. */
|
|
|
|
|
node_select_paired(*snode->edittree);
|
|
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH_MUTABLE (bNode *, node, &snode->edittree->nodes) {
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node->flag & SELECT) {
|
2024-08-19 20:27:37 +02:00
|
|
|
blender::bke::node_internal_relink(snode->edittree, node);
|
|
|
|
|
bke::node_remove_node(bmain, snode->edittree, node, true);
|
2024-09-27 16:24:06 +02:00
|
|
|
|
|
|
|
|
/* Since this node might have been animated, and that animation data been
|
|
|
|
|
* deleted, a notifier call is necessary to redraw any animation editor. */
|
|
|
|
|
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, nullptr);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, snode->edittree->id);
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void NODE_OT_delete_reconnect(wmOperatorType *ot)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-01-27 07:23:58 +00:00
|
|
|
ot->name = "Delete with Reconnect";
|
2023-01-09 17:14:06 -05:00
|
|
|
ot->description = "Remove nodes and reconnect nodes as if deletion was muted";
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->idname = "NODE_OT_delete_reconnect";
|
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* api callbacks */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->exec = node_delete_reconnect_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node File Output Add Socket Operator
|
|
|
|
|
* \{ */
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
static int node_output_file_add_socket_exec(bContext *C, wmOperator *op)
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-04-24 16:59:56 +00:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeTree *ntree = nullptr;
|
|
|
|
|
bNode *node = nullptr;
|
2012-03-01 07:56:15 +00:00
|
|
|
char file_path[MAX_NAME];
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
if (ptr.data) {
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
ntree = (bNodeTree *)ptr.owner_id;
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
|
|
|
|
ntree = snode->edittree;
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!node || node->type_legacy != CMP_NODE_OUTPUT_FILE) {
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
RNA_string_get(op->ptr, "file_path", file_path);
|
|
|
|
|
ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format);
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), snode->edittree->id);
|
2012-08-01 19:11:17 +00:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
void NODE_OT_output_file_add_socket(wmOperatorType *ot)
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add File Node Socket";
|
|
|
|
|
ot->description = "Add a new input to a file output node";
|
|
|
|
|
ot->idname = "NODE_OT_output_file_add_socket";
|
2012-08-01 19:11:17 +00:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_output_file_add_socket_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = composite_node_editable;
|
2012-08-01 19:11:17 +00:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
RNA_def_string(
|
2020-12-24 13:11:22 -06:00
|
|
|
ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Subpath of the output file");
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Multi File Output Remove Socket Operator
|
|
|
|
|
* \{ */
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator * /*op*/)
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeTree *ntree = nullptr;
|
|
|
|
|
bNode *node = nullptr;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
if (ptr.data) {
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
ntree = (bNodeTree *)ptr.owner_id;
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
|
|
|
|
ntree = snode->edittree;
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!node || node->type_legacy != CMP_NODE_OUTPUT_FILE) {
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node)) {
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), ntree->id);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
void NODE_OT_output_file_remove_active_socket(wmOperatorType *ot)
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Remove File Node Socket";
|
2023-01-09 17:14:06 -05:00
|
|
|
ot->description = "Remove the active input from a file output node";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_output_file_remove_active_socket";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_output_file_remove_active_socket_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = composite_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
}
|
2012-05-02 07:18:51 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Multi File Output Move Socket Node
|
|
|
|
|
* \{ */
|
2012-05-02 07:18:51 +00:00
|
|
|
|
|
|
|
|
static int node_output_file_move_active_socket_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *node = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ptr.data) {
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)ptr.data;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!node || node->type_legacy != CMP_NODE_OUTPUT_FILE) {
|
2012-05-02 07:18:51 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *sock = (bNodeSocket *)BLI_findlink(&node->inputs, nimf->active_input);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sock) {
|
2012-05-02 07:18:51 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
int direction = RNA_enum_get(op->ptr, "direction");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (direction == 1) {
|
2012-05-02 07:18:51 +00:00
|
|
|
bNodeSocket *before = sock->prev;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!before) {
|
2012-05-02 07:18:51 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-02 07:18:51 +00:00
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
|
BLI_insertlinkbefore(&node->inputs, before, sock);
|
2012-08-22 16:44:32 +00:00
|
|
|
nimf->active_input--;
|
2012-05-02 07:18:51 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bNodeSocket *after = sock->next;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!after) {
|
2012-05-02 07:18:51 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-02 07:18:51 +00:00
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
|
BLI_insertlinkafter(&node->inputs, after, sock);
|
2012-08-22 16:44:32 +00:00
|
|
|
nimf->active_input++;
|
2012-05-02 07:18:51 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-01 13:22:44 +02:00
|
|
|
BKE_ntree_update_tag_node_property(snode->edittree, node);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), snode->edittree->id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_output_file_move_active_socket(wmOperatorType *ot)
|
|
|
|
|
{
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem direction_items[] = {
|
2021-06-02 17:19:36 +02:00
|
|
|
{1, "UP", 0, "Up", ""}, {2, "DOWN", 0, "Down", ""}, {0, nullptr, 0, nullptr, nullptr}};
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Move File Node Socket";
|
|
|
|
|
ot->description = "Move the active input of a file output node up or down the list";
|
|
|
|
|
ot->idname = "NODE_OT_output_file_move_active_socket";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_output_file_move_active_socket_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = composite_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
RNA_def_enum(ot->srna, "direction", direction_items, 2, "Direction", "");
|
|
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Copy Node Color Operator
|
|
|
|
|
* \{ */
|
2012-05-22 14:13:33 +00:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_copy_color_exec(bContext *C, wmOperator * /*op*/)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2022-01-18 13:32:36 -06:00
|
|
|
SpaceNode &snode = *CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree &ntree = *snode.edittree;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-08-19 20:27:37 +02:00
|
|
|
bNode *active_node = bke::node_get_active(&ntree);
|
2022-09-06 11:33:47 -05:00
|
|
|
if (!active_node) {
|
2012-05-22 14:13:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : ntree.all_nodes()) {
|
2022-09-06 11:33:47 -05:00
|
|
|
if (node->flag & NODE_SELECT && node != active_node) {
|
|
|
|
|
if (active_node->flag & NODE_CUSTOM_COLOR) {
|
|
|
|
|
node->flag |= NODE_CUSTOM_COLOR;
|
|
|
|
|
copy_v3_v3(node->color, active_node->color);
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else {
|
2022-09-06 11:33:47 -05:00
|
|
|
node->flag &= ~NODE_CUSTOM_COLOR;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_node_copy_color(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Copy Color";
|
|
|
|
|
ot->description = "Copy color to all selected nodes";
|
|
|
|
|
ot->idname = "NODE_OT_node_copy_color";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_copy_color_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2012-08-02 09:52:37 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Shader Script Update
|
|
|
|
|
* \{ */
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_shader_script_update_poll(bContext *C)
|
2012-11-03 14:32:26 +00:00
|
|
|
{
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2020-03-13 17:27:11 +11:00
|
|
|
const RenderEngineType *type = RE_engines_find(scene->r.engine);
|
2013-04-24 16:59:56 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Test if we have a render engine that supports shaders scripts. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!(type && type->update_script_node)) {
|
2021-06-02 17:19:36 +02:00
|
|
|
return false;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* See if we have a shader script node in context. */
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *node = (bNode *)CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript).data;
|
2013-04-24 16:59:56 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!node && snode && snode->edittree) {
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-04-24 16:59:56 +00:00
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node && node->type_legacy == SH_NODE_SCRIPT) {
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeShaderScript *nss = (NodeShaderScript *)node->storage;
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2012-11-03 15:35:03 +00:00
|
|
|
if (node->id || nss->filepath[0]) {
|
2013-06-10 20:10:03 +00:00
|
|
|
return ED_operator_node_editable(C);
|
2012-11-03 15:35:03 +00:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* See if we have a text datablock in context. */
|
2021-06-02 17:19:36 +02:00
|
|
|
Text *text = (Text *)CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (text) {
|
2021-06-02 17:19:36 +02:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* We don't check if text datablock is actually in use, too slow for poll. */
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
return false;
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* recursively check for script nodes in groups using this text and update */
|
2014-04-11 11:25:41 +10:00
|
|
|
static bool node_shader_script_update_text_recursive(RenderEngine *engine,
|
|
|
|
|
RenderEngineType *type,
|
|
|
|
|
bNodeTree *ntree,
|
2022-11-30 11:41:01 -06:00
|
|
|
Text *text,
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNodeTree *> &done_trees)
|
2012-11-03 14:32:26 +00:00
|
|
|
{
|
2014-04-11 11:25:41 +10:00
|
|
|
bool found = false;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2022-11-30 11:41:01 -06:00
|
|
|
done_trees.add_new(ntree);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Update each script that is using this text datablock. */
|
2022-12-02 11:12:51 -06:00
|
|
|
for (bNode *node : ntree->all_nodes()) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node->type_legacy == NODE_GROUP) {
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeTree *ngroup = (bNodeTree *)node->id;
|
2022-11-30 11:41:01 -06:00
|
|
|
if (ngroup && !done_trees.contains(ngroup)) {
|
|
|
|
|
found |= node_shader_script_update_text_recursive(engine, type, ngroup, text, done_trees);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
2025-01-09 15:28:57 +01:00
|
|
|
else if (node->type_legacy == SH_NODE_SCRIPT && node->id == &text->id) {
|
2013-03-18 16:34:57 +00:00
|
|
|
type->update_script_node(engine, ntree, node);
|
2014-04-01 11:34:00 +11:00
|
|
|
found = true;
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
return found;
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int node_shader_script_update_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2013-04-24 16:59:56 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-11-03 14:32:26 +00:00
|
|
|
PointerRNA nodeptr = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript);
|
2014-04-11 11:25:41 +10:00
|
|
|
bool found = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:26 +00:00
|
|
|
/* setup render engine */
|
2020-12-14 17:19:43 -06:00
|
|
|
RenderEngineType *type = RE_engines_find(scene->r.engine);
|
|
|
|
|
RenderEngine *engine = RE_engine_create(type);
|
2013-03-18 16:34:57 +00:00
|
|
|
engine->reports = op->reports;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeTree *ntree_base = nullptr;
|
|
|
|
|
bNode *node = nullptr;
|
2012-11-03 14:32:26 +00:00
|
|
|
if (nodeptr.data) {
|
2019-08-23 09:52:12 +02:00
|
|
|
ntree_base = (bNodeTree *)nodeptr.owner_id;
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)nodeptr.data;
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
2015-11-23 15:44:15 +11:00
|
|
|
ntree_base = snode->edittree;
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2013-04-24 16:59:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
if (node) {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Update single node. */
|
2015-11-23 15:44:15 +11:00
|
|
|
type->update_script_node(engine, ntree_base, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
found = true;
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Update all nodes using text datablock. */
|
2021-06-02 17:19:36 +02:00
|
|
|
Text *text = (Text *)CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (text) {
|
2022-11-30 11:41:01 -06:00
|
|
|
|
2022-12-02 13:20:40 -06:00
|
|
|
VectorSet<bNodeTree *> done_trees;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-30 15:22:01 +11:00
|
|
|
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
|
2013-03-18 16:34:57 +00:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
2022-11-30 11:41:01 -06:00
|
|
|
if (!done_trees.contains(ntree)) {
|
|
|
|
|
found |= node_shader_script_update_text_recursive(
|
|
|
|
|
engine, type, ntree, text, done_trees);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2018-11-30 15:22:01 +11:00
|
|
|
FOREACH_NODETREE_END;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!found) {
|
2012-11-07 14:56:53 +00:00
|
|
|
BKE_report(op->reports, RPT_INFO, "Text not used by any node, no update done");
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
RE_engine_free(engine);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-31 03:28:46 +00:00
|
|
|
return (found) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_shader_script_update(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Script Node Update";
|
|
|
|
|
ot->description = "Update shader script node with new sockets and options from the script";
|
|
|
|
|
ot->idname = "NODE_OT_shader_script_update";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_shader_script_update_exec;
|
|
|
|
|
ot->poll = node_shader_script_update_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Viewer Border
|
|
|
|
|
* \{ */
|
2013-03-07 17:47:30 +00:00
|
|
|
|
|
|
|
|
static void viewer_border_corner_to_backdrop(SpaceNode *snode,
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region,
|
2013-03-07 17:47:30 +00:00
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int backdrop_width,
|
|
|
|
|
int backdrop_height,
|
|
|
|
|
float *fx,
|
|
|
|
|
float *fy)
|
|
|
|
|
{
|
2020-12-14 17:19:43 -06:00
|
|
|
float bufx = backdrop_width * snode->zoom;
|
|
|
|
|
float bufy = backdrop_height * snode->zoom;
|
2013-03-07 17:47:30 +00:00
|
|
|
|
2022-09-25 18:33:28 +10:00
|
|
|
*fx = (bufx > 0.0f ? (float(x) - 0.5f * region->winx - snode->xof) / bufx + 0.5f : 0.0f);
|
|
|
|
|
*fy = (bufy > 0.0f ? (float(y) - 0.5f * region->winy - snode->yof) / bufy + 0.5f : 0.0f);
|
2013-03-07 17:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int viewer_border_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2018-06-11 15:40:37 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2013-03-07 17:47:30 +00:00
|
|
|
void *lock;
|
|
|
|
|
|
2018-06-11 15:40:37 +02:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
2013-03-07 17:47:30 +00:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
|
2021-06-02 17:19:36 +02:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
|
2013-03-07 17:47:30 +00:00
|
|
|
|
|
|
|
|
if (ibuf) {
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region = CTX_wm_region(C);
|
2013-03-07 17:47:30 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2013-04-24 15:39:19 +00:00
|
|
|
bNodeTree *btree = snode->nodetree;
|
2013-03-07 17:47:30 +00:00
|
|
|
rcti rect;
|
|
|
|
|
rctf rectf;
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Get border from operator. */
|
2013-03-07 17:47:30 +00:00
|
|
|
WM_operator_properties_border_to_rcti(op, &rect);
|
|
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Convert border to unified space within backdrop image. */
|
2013-03-07 17:47:30 +00:00
|
|
|
viewer_border_corner_to_backdrop(
|
2020-03-06 16:56:42 +01:00
|
|
|
snode, region, rect.xmin, rect.ymin, ibuf->x, ibuf->y, &rectf.xmin, &rectf.ymin);
|
2013-03-07 17:47:30 +00:00
|
|
|
|
|
|
|
|
viewer_border_corner_to_backdrop(
|
2020-03-06 16:56:42 +01:00
|
|
|
snode, region, rect.xmax, rect.ymax, ibuf->x, ibuf->y, &rectf.xmax, &rectf.ymax);
|
2013-03-07 17:47:30 +00:00
|
|
|
|
2023-01-03 20:02:01 -05:00
|
|
|
/* Clamp coordinates. */
|
2013-03-07 17:47:30 +00:00
|
|
|
rectf.xmin = max_ff(rectf.xmin, 0.0f);
|
|
|
|
|
rectf.ymin = max_ff(rectf.ymin, 0.0f);
|
|
|
|
|
rectf.xmax = min_ff(rectf.xmax, 1.0f);
|
|
|
|
|
rectf.ymax = min_ff(rectf.ymax, 1.0f);
|
|
|
|
|
|
|
|
|
|
if (rectf.xmin < rectf.xmax && rectf.ymin < rectf.ymax) {
|
|
|
|
|
btree->viewer_border = rectf;
|
|
|
|
|
|
|
|
|
|
if (rectf.xmin == 0.0f && rectf.ymin == 0.0f && rectf.xmax == 1.0f && rectf.ymax == 1.0f) {
|
|
|
|
|
btree->flag &= ~NTREE_VIEWER_BORDER;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
btree->flag |= NTREE_VIEWER_BORDER;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, btree->id);
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2013-03-07 17:47:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
btree->flag &= ~NTREE_VIEWER_BORDER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, lock);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_viewer_border(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2019-06-23 03:16:33 +02:00
|
|
|
ot->name = "Viewer Region";
|
2013-03-07 17:47:30 +00:00
|
|
|
ot->description = "Set the boundaries for viewer operations";
|
|
|
|
|
ot->idname = "NODE_OT_viewer_border";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->invoke = WM_gesture_box_invoke;
|
2013-03-07 17:47:30 +00:00
|
|
|
ot->exec = viewer_border_exec;
|
2018-10-05 10:27:04 +10:00
|
|
|
ot->modal = WM_gesture_box_modal;
|
|
|
|
|
ot->cancel = WM_gesture_box_cancel;
|
2013-03-07 17:47:30 +00:00
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
2020-10-13 15:43:21 +02:00
|
|
|
WM_operator_properties_gesture_box(ot);
|
2013-03-07 17:47:30 +00:00
|
|
|
}
|
2014-06-05 20:05:41 +06:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int clear_viewer_border_exec(bContext *C, wmOperator * /*op*/)
|
2014-06-05 20:05:41 +06:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *btree = snode->nodetree;
|
|
|
|
|
|
|
|
|
|
btree->flag &= ~NTREE_VIEWER_BORDER;
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), btree->id);
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2014-06-05 20:05:41 +06:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_clear_viewer_border(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2020-08-06 14:48:47 +02:00
|
|
|
ot->name = "Clear Viewer Region";
|
2014-06-05 20:05:41 +06:00
|
|
|
ot->description = "Clear the boundaries for viewer operations";
|
|
|
|
|
ot->idname = "NODE_OT_clear_viewer_border";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = clear_viewer_border_exec;
|
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
2018-07-18 13:03:09 +02:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Cryptomatte Add Socket
|
|
|
|
|
* \{ */
|
2018-07-18 13:03:09 +02:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator * /*op*/)
|
2018-07-18 13:03:09 +02:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeTree *ntree = nullptr;
|
|
|
|
|
bNode *node = nullptr;
|
2018-07-18 13:03:09 +02:00
|
|
|
|
|
|
|
|
if (ptr.data) {
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
ntree = (bNodeTree *)ptr.owner_id;
|
2018-07-18 13:03:09 +02:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
|
|
|
|
ntree = snode->edittree;
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2018-07-18 13:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!node || node->type_legacy != CMP_NODE_CRYPTOMATTE_LEGACY) {
|
2018-07-18 13:03:09 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntreeCompositCryptomatteAddSocket(ntree, node);
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), ntree->id);
|
2018-07-18 13:03:09 +02:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_cryptomatte_layer_add(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Cryptomatte Socket";
|
|
|
|
|
ot->description = "Add a new input layer to a Cryptomatte node";
|
|
|
|
|
ot->idname = "NODE_OT_cryptomatte_layer_add";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_cryptomatte_add_socket_exec;
|
|
|
|
|
ot->poll = composite_node_editable;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Cryptomatte Remove Socket
|
|
|
|
|
* \{ */
|
2018-07-18 13:03:09 +02:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator * /*op*/)
|
2018-07-18 13:03:09 +02:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeTree *ntree = nullptr;
|
|
|
|
|
bNode *node = nullptr;
|
2018-07-18 13:03:09 +02:00
|
|
|
|
|
|
|
|
if (ptr.data) {
|
2021-06-02 17:19:36 +02:00
|
|
|
node = (bNode *)ptr.data;
|
2019-08-23 09:52:12 +02:00
|
|
|
ntree = (bNodeTree *)ptr.owner_id;
|
2018-07-18 13:03:09 +02:00
|
|
|
}
|
|
|
|
|
else if (snode && snode->edittree) {
|
|
|
|
|
ntree = snode->edittree;
|
2024-08-19 20:27:37 +02:00
|
|
|
node = bke::node_get_active(snode->edittree);
|
2018-07-18 13:03:09 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (!node || node->type_legacy != CMP_NODE_CRYPTOMATTE_LEGACY) {
|
2018-07-18 13:03:09 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ntreeCompositCryptomatteRemoveSocket(ntree, node)) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*CTX_data_main(C), ntree->id);
|
2018-07-18 13:03:09 +02:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Remove Cryptomatte Socket";
|
2018-12-24 15:02:20 +01:00
|
|
|
ot->description = "Remove layer from a Cryptomatte node";
|
2018-07-18 13:03:09 +02:00
|
|
|
ot->idname = "NODE_OT_cryptomatte_layer_remove";
|
|
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
|
ot->exec = node_cryptomatte_remove_socket_exec;
|
|
|
|
|
ot->poll = composite_node_editable;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
2022-05-11 09:39:43 +10:00
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
} // namespace blender::ed::space_node
|