2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2005 Blender Foundation. All rights reserved. */
|
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>
|
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-02-27 12:34:56 +11:00
|
|
|
#include "DNA_light_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#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
|
|
|
|
2022-05-31 10:22:43 +02:00
|
|
|
#include "BKE_callbacks.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_image.h"
|
2022-03-11 18:21:05 +01:00
|
|
|
#include "BKE_image_format.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_main.h"
|
2020-02-06 13:05:45 +01:00
|
|
|
#include "BKE_material.h"
|
2012-08-06 08:41:45 +00:00
|
|
|
#include "BKE_node.h"
|
2021-12-21 15:18:56 +01:00
|
|
|
#include "BKE_node_tree_update.h"
|
2012-08-06 08:41:45 +00:00
|
|
|
#include "BKE_report.h"
|
2011-11-08 11:38:16 +00:00
|
|
|
#include "BKE_scene.h"
|
2021-04-08 17:35:06 +02:00
|
|
|
#include "BKE_workspace.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2022-08-29 14:25:18 +02:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
2019-06-03 14:47:44 +02:00
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
#include "DEG_depsgraph_query.h"
|
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"
|
|
|
|
|
|
2021-06-04 10:37:00 +02:00
|
|
|
#include "ED_image.h"
|
2012-08-01 20:39:14 +00:00
|
|
|
#include "ED_node.h" /* own include */
|
2010-07-04 19:58:52 +00:00
|
|
|
#include "ED_render.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "ED_screen.h"
|
|
|
|
|
#include "ED_select_utils.h"
|
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
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2009-01-12 00:14:37 +00:00
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-01-01 16:27:02 +00:00
|
|
|
#include "UI_view2d.h"
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "GPU_material.h"
|
|
|
|
|
|
2013-03-07 17:47:30 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_composite.h"
|
2020-12-02 13:25:25 +01:00
|
|
|
#include "NOD_geometry.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_shader.h"
|
|
|
|
|
#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
|
|
|
|
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;
|
2019-06-03 14:47:44 +02:00
|
|
|
/* Jon system integration. */
|
2014-04-27 00:22:49 +10:00
|
|
|
const short *stop;
|
2009-01-27 17:12:40 +00:00
|
|
|
short *do_update;
|
2010-05-27 08:22:16 +00:00
|
|
|
float *progress;
|
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
|
|
|
{
|
2022-02-28 18:05:12 -05:00
|
|
|
float sock_height = NODE_SOCKSIZE * NODE_SOCKSIZE_DRAW_MULIPLIER;
|
2021-12-03 16:25:17 -05:00
|
|
|
if (socket.flag & SOCK_MULTI_INPUT) {
|
|
|
|
|
sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket.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)
|
|
|
|
|
{
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &nodetree->nodes) {
|
2013-03-20 18:01:47 +00:00
|
|
|
if (node->type == 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
|
|
|
}
|
2020-11-06 12:30:59 +11:00
|
|
|
else if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
|
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
|
|
|
}
|
|
|
|
|
else if (node->type == 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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* called by compo, only to check job 'stop' value */
|
|
|
|
|
static int compo_breakjob(void *cjv)
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
CompoJob *cj = (CompoJob *)cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-06-22 10:42:32 -07: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
|
|
|
}
|
|
|
|
|
|
2015-03-27 18:21:39 +05:00
|
|
|
/* called by compo, 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
|
|
|
}
|
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* called by compo, 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) {
|
2018-06-11 15:40:37 +02:00
|
|
|
ntreeLocalMerge(cj->bmain, cj->localtree, cj->ntree);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
if (cj->compositor_depsgraph != nullptr) {
|
2019-06-03 14:47:44 +02:00
|
|
|
DEG_graph_free(cj->compositor_depsgraph);
|
|
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
MEM_freeN(cj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only now we copy the nodetree, so adding many jobs while
|
2012-03-03 16:31:46 +00:00
|
|
|
* 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;
|
|
|
|
|
|
2019-09-09 14:49:05 +02:00
|
|
|
cj->compositor_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
|
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
|
|
|
|
2019-06-03 14:47:44 +02:00
|
|
|
cj->localtree = ntreeLocalize(ntree_eval);
|
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
|
|
|
}
|
2009-01-27 17:12:40 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* only this runs inside thread */
|
2020-07-13 11:27:09 +02:00
|
|
|
static void compo_startjob(void *cjv,
|
|
|
|
|
/* Cannot be const, this function implements wm_jobs_start_callback.
|
|
|
|
|
* NOLINTNEXTLINE: readability-non-const-parameter. */
|
|
|
|
|
short *stop,
|
|
|
|
|
short *do_update,
|
|
|
|
|
float *progress)
|
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;
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
Scene *scene = cj->scene;
|
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
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->stop = stop;
|
|
|
|
|
cj->do_update = do_update;
|
|
|
|
|
cj->progress = progress;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree->test_break = compo_breakjob;
|
|
|
|
|
ntree->tbh = cj;
|
2012-11-30 09:12:10 +00:00
|
|
|
ntree->stats_draw = compo_statsdrawjob;
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree->sdh = cj;
|
|
|
|
|
ntree->progress = compo_progressjob;
|
|
|
|
|
ntree->prh = cj;
|
2012-11-30 09:12:10 +00:00
|
|
|
ntree->update_draw = compo_redrawjob;
|
|
|
|
|
ntree->udh = cj;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
// XXX BIF_store_spare();
|
2013-04-24 16:36:50 +00:00
|
|
|
/* 1 is do_previews */
|
2022-05-31 10:22:43 +02:00
|
|
|
BKE_callback_exec_id(cj->bmain, &scene->id, BKE_CB_EVT_COMPOSITE_PRE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-07 16:37:16 -03:00
|
|
|
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
|
2022-03-11 18:21:05 +01:00
|
|
|
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, "");
|
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;
|
|
|
|
|
}
|
2022-03-11 18:21:05 +01:00
|
|
|
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, false, true, srv->name);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
ntree->test_break = nullptr;
|
|
|
|
|
ntree->stats_draw = nullptr;
|
|
|
|
|
ntree->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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
* \{ */
|
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2020-09-30 20:09:02 +10:00
|
|
|
/* to fix bug: T32272. */
|
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);
|
2021-12-24 22:17:49 -05:00
|
|
|
CompoJob *cj = MEM_cnew<CompoJob>("compo job");
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* customdata 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);
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* setup 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
|
|
|
}
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
static void send_notifiers_after_tree_change(ID *id, bNodeTree *ntree)
|
2011-05-02 12:31:09 +00:00
|
|
|
{
|
2021-12-21 15:18:56 +01:00
|
|
|
WM_main_add_notifier(NC_NODE | NA_EDITED, nullptr);
|
2012-05-05 19:44:28 +00:00
|
|
|
|
2022-02-07 18:16:35 +01:00
|
|
|
if (ntree->type == NTREE_SHADER && id != nullptr) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (GS(id->name) == ID_MA) {
|
2014-11-24 17:18:56 +01:00
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (GS(id->name) == ID_LA) {
|
2014-11-24 17:18:56 +01:00
|
|
|
WM_main_add_notifier(NC_LAMP | ND_LIGHTING, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (GS(id->name) == ID_WO) {
|
2014-11-24 17:18:56 +01:00
|
|
|
WM_main_add_notifier(NC_WORLD | ND_WORLD, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2014-11-24 17:18:56 +01:00
|
|
|
}
|
2021-12-21 15:18:56 +01:00
|
|
|
else if (ntree->type == NTREE_COMPOSIT) {
|
|
|
|
|
WM_main_add_notifier(NC_SCENE | ND_NODES, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-12-21 15:18:56 +01:00
|
|
|
else if (ntree->type == NTREE_TEXTURE) {
|
|
|
|
|
WM_main_add_notifier(NC_TEXTURE | ND_NODES, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-12-21 15:18:56 +01:00
|
|
|
else if (ntree->type == NTREE_GEOMETRY) {
|
2020-12-02 13:25:25 +01:00
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, id);
|
|
|
|
|
}
|
2008-12-24 10:33:10 +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
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
void ED_node_tree_propagate_change(const bContext *C, Main *bmain, bNodeTree *root_ntree)
|
|
|
|
|
{
|
|
|
|
|
if (C != nullptr) {
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
if (snode != nullptr && root_ntree != nullptr) {
|
2022-01-20 10:36:56 -06:00
|
|
|
blender::ed::space_node::send_notifiers_after_tree_change(snode->id, root_ntree);
|
2021-12-21 15:18:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 14:32:22 -06:00
|
|
|
NodeTreeUpdateExtraParams params = {nullptr};
|
2022-10-03 17:37:25 -05:00
|
|
|
params.tree_changed_fn = [](ID *id, bNodeTree *ntree, void * /*user_data*/) {
|
2022-01-20 10:36:56 -06:00
|
|
|
blender::ed::space_node::send_notifiers_after_tree_change(id, ntree);
|
2021-12-24 13:39:50 +01:00
|
|
|
DEG_id_tag_update(&ntree->id, ID_RECALC_COPY_ON_WRITE);
|
2021-12-21 15:18:56 +01:00
|
|
|
};
|
2022-10-03 17:37:25 -05:00
|
|
|
params.tree_output_changed_fn = [](ID * /*id*/, bNodeTree *ntree, void * /*user_data*/) {
|
2021-12-21 15:18:56 +01:00
|
|
|
DEG_id_tag_update(&ntree->id, ID_RECALC_NTREE_OUTPUT);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BKE_ntree_update_main_tree(bmain, root_ntree, ¶ms);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void ED_node_set_tree_type(SpaceNode *snode, bNodeTreeType *typeinfo)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (typeinfo) {
|
2013-03-18 16:34:57 +00:00
|
|
|
BLI_strncpy(snode->tree_idname, typeinfo->idname, sizeof(snode->tree_idname));
|
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
|
|
|
}
|
|
|
|
|
|
2022-09-02 14:21:35 -05:00
|
|
|
bool ED_node_is_compositor(SpaceNode *snode)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2013-03-18 18:25:05 +00:00
|
|
|
return STREQ(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
|
|
|
{
|
2013-03-18 18:25:05 +00:00
|
|
|
return STREQ(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
|
|
|
{
|
2013-03-18 18:25:05 +00:00
|
|
|
return STREQ(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
|
|
|
{
|
2020-12-02 13:25:25 +01:00
|
|
|
return STREQ(snode->tree_idname, ntreeType_Geometry->idname);
|
2020-04-20 10:58:43 +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();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
ma->nodetree = ntreeCopyTree(bmain, ma_default->nodetree);
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_main_tree(bmain, ma->nodetree, nullptr);
|
2020-02-06 13:05:45 +01:00
|
|
|
}
|
|
|
|
|
else if (ELEM(GS(id->name), ID_WO, ID_LA)) {
|
|
|
|
|
/* Emission */
|
2022-09-05 15:46:00 +02:00
|
|
|
bNodeTree *ntree = ntreeAddTreeEmbedded(
|
|
|
|
|
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;
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
shader = nodeAddStaticNode(nullptr, ntree, SH_NODE_BACKGROUND);
|
|
|
|
|
output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_WORLD);
|
2020-02-06 13:05:45 +01:00
|
|
|
nodeAddLink(ntree,
|
|
|
|
|
shader,
|
|
|
|
|
nodeFindSocket(shader, SOCK_OUT, "Background"),
|
|
|
|
|
output,
|
|
|
|
|
nodeFindSocket(output, SOCK_IN, "Surface"));
|
|
|
|
|
|
|
|
|
|
bNodeSocket *color_sock = nodeFindSocket(shader, SOCK_IN, "Color");
|
|
|
|
|
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 {
|
2021-06-02 17:19:36 +02:00
|
|
|
shader = nodeAddStaticNode(nullptr, ntree, SH_NODE_EMISSION);
|
|
|
|
|
output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_LIGHT);
|
2020-02-06 13:05:45 +01:00
|
|
|
nodeAddLink(ntree,
|
|
|
|
|
shader,
|
|
|
|
|
nodeFindSocket(shader, SOCK_OUT, "Emission"),
|
|
|
|
|
output,
|
|
|
|
|
nodeFindSocket(output, SOCK_IN, "Surface"));
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
shader->locx = 10.0f;
|
|
|
|
|
shader->locy = 300.0f;
|
|
|
|
|
output->locx = 300.0f;
|
|
|
|
|
output->locy = 300.0f;
|
|
|
|
|
nodeSetActive(ntree, output);
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_main_tree(bmain, ntree, nullptr);
|
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
|
|
|
|
2022-09-05 15:46:00 +02:00
|
|
|
sce->nodetree = ntreeAddTreeEmbedded(
|
|
|
|
|
nullptr, &sce->id, "Compositing Nodetree", ntreeType_Composite->idname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
sce->nodetree->chunksize = 256;
|
|
|
|
|
sce->nodetree->edit_quality = NTREE_QUALITY_HIGH;
|
|
|
|
|
sce->nodetree->render_quality = NTREE_QUALITY_HIGH;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *out = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_COMPOSITE);
|
2012-06-21 13:19:19 +00:00
|
|
|
out->locx = 300.0f;
|
|
|
|
|
out->locy = 400.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *in = nodeAddStaticNode(C, sce->nodetree, CMP_NODE_R_LAYERS);
|
2012-06-21 13:19:19 +00:00
|
|
|
in->locx = 10.0f;
|
|
|
|
|
in->locy = 400.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(sce->nodetree, in);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2008-12-24 10:33:10 +00: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;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_main_tree(CTX_data_main(C), sce->nodetree, nullptr);
|
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
|
|
|
{
|
|
|
|
|
/* but lets check it anyway */
|
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
|
|
|
|
2022-09-05 15:46:00 +02:00
|
|
|
tex->nodetree = ntreeAddTreeEmbedded(
|
|
|
|
|
nullptr, &tex->id, "Texture Nodetree", ntreeType_Texture->idname);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *out = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_OUTPUT);
|
2012-06-21 13:19:19 +00:00
|
|
|
out->locx = 300.0f;
|
|
|
|
|
out->locy = 300.0f;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *in = nodeAddStaticNode(C, tex->nodetree, TEX_NODE_CHECKER);
|
2012-06-21 13:19:19 +00:00
|
|
|
in->locx = 10.0f;
|
|
|
|
|
in->locy = 300.0f;
|
2020-09-04 20:59:13 +02:00
|
|
|
nodeSetActive(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;
|
2020-09-04 20:59:13 +02:00
|
|
|
nodeAddLink(tex->nodetree, in, fromsock, out, tosock);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_main_tree(CTX_data_main(C), tex->nodetree, nullptr);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2021-12-09 00:55:11 +11:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
void snode_set_context(const bContext &C)
|
2009-10-07 22:05:30 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(&C);
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeTreeType *treetype = ntreeTypeFind(snode->tree_idname);
|
|
|
|
|
bNodeTree *ntree = snode->nodetree;
|
|
|
|
|
ID *id = snode->id, *from = snode->from;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* check the tree type */
|
2021-12-03 16:25:17 -05:00
|
|
|
if (!treetype || (treetype->poll && !treetype->poll(&C, treetype))) {
|
2013-07-08 11:38:09 +00: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)) {
|
2013-03-18 16:34:57 +00: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) {
|
|
|
|
|
/* 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
|
|
|
{
|
2014-01-28 03:52:21 +11:00
|
|
|
const bool was_active_texture = (node->flag & NODE_ACTIVE_TEXTURE) != 0;
|
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
|
|
|
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeSetActive(ntree, node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type != NODE_GROUP) {
|
2014-01-28 03:52:21 +11:00
|
|
|
const bool was_output = (node->flag & NODE_DO_OUTPUT) != 0;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool do_update = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* generic node group output: set node as active output */
|
|
|
|
|
if (node->type == NODE_GROUP_OUTPUT) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
|
if (node_iter->type == NODE_GROUP_OUTPUT) {
|
|
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!was_output) {
|
2021-06-02 17:19:36 +02:00
|
|
|
do_update = true;
|
2022-02-10 12:07:48 +01:00
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* tree specific activate calls */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if (ELEM(node->type,
|
|
|
|
|
SH_NODE_OUTPUT_MATERIAL,
|
2018-06-27 14:41:53 +02:00
|
|
|
SH_NODE_OUTPUT_WORLD,
|
|
|
|
|
SH_NODE_OUTPUT_LIGHT,
|
|
|
|
|
SH_NODE_OUTPUT_LINESTYLE)) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
|
if (node_iter->type == node->type) {
|
|
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-20 11:08:29 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2022-02-10 12:07:48 +01:00
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(nullptr, bmain, ntree);
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
|
2021-06-04 10:24:01 +02:00
|
|
|
/* If active texture changed, free glsl materials. */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (Material *, ma, &bmain->materials) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ma->nodetree && ma->use_nodes && ntreeHasTree(ma->nodetree, ntree)) {
|
2014-11-24 17:18:56 +01:00
|
|
|
GPU_material_free(&ma->gpumaterial);
|
2021-06-04 10:24:01 +02:00
|
|
|
|
|
|
|
|
/* Sync to active texpaint slot, otherwise we can end up painting on a different slot
|
|
|
|
|
* than we are looking at. */
|
|
|
|
|
if (ma->texpaintslot) {
|
2022-09-12 13:55:40 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-02-22 10:06:16 +01:00
|
|
|
LISTBASE_FOREACH (World *, wo, &bmain->worlds) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (wo->nodetree && wo->use_nodes && ntreeHasTree(wo->nodetree, ntree)) {
|
2014-11-24 17:18:56 +01:00
|
|
|
GPU_material_free(&wo->gpumaterial);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2021-06-04 10:37:00 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-22 10:07:03 +02: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) */
|
2022-09-12 13:55:40 +02:00
|
|
|
if (node->id != nullptr && GS(node->id->name) == ID_IM) {
|
|
|
|
|
Image *image = (Image *)node->id;
|
|
|
|
|
wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
|
|
|
|
|
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
|
|
|
|
|
const bScreen *screen = WM_window_get_active_screen(win);
|
|
|
|
|
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
|
|
|
|
LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
|
|
|
|
|
if (sl->spacetype != SPACE_IMAGE) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
SpaceImage *sima = (SpaceImage *)sl;
|
|
|
|
|
if (sima->pin) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (sima->image &&
|
|
|
|
|
ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ED_space_image_set(bmain, sima, image, true);
|
2021-06-04 10:37:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-25 10:43:44 +02:00
|
|
|
if (r_active_texture_changed) {
|
|
|
|
|
*r_active_texture_changed = true;
|
|
|
|
|
}
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(nullptr, bmain, ntree);
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_main_add_notifier(NC_IMAGE, nullptr);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (ntree->type == NTREE_COMPOSIT) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* make active viewer, currently only 1 supported... */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
|
if (ELEM(node_iter->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
|
|
|
|
|
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;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (was_output == 0) {
|
2022-02-10 12:07:48 +01:00
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(nullptr, bmain, ntree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-05 15:03:09 +10:00
|
|
|
/* Adding a node doesn't link this yet. */
|
2020-03-06 13:02:59 +11:00
|
|
|
node->id = (ID *)BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (node->type == CMP_NODE_COMPOSITE) {
|
|
|
|
|
if (was_output == 0) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
|
if (node_iter->type == CMP_NODE_COMPOSITE) {
|
|
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-21 13:25:19 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2022-02-10 12:07:48 +01:00
|
|
|
BKE_ntree_update_tag_active_output_changed(ntree);
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(nullptr, bmain, ntree);
|
2011-08-21 13:25:19 +00:00
|
|
|
}
|
2010-12-19 15:03:27 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else if (do_update) {
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(nullptr, bmain, ntree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (ntree->type == NTREE_TEXTURE) {
|
2009-10-07 22:05:30 +00:00
|
|
|
/* XXX */
|
|
|
|
|
#if 0
|
2019-05-31 23:21:16 +10:00
|
|
|
if (node->id) {
|
|
|
|
|
BIF_preview_changed(-1);
|
|
|
|
|
allqueue(REDRAWBUTSSHADING, 1);
|
|
|
|
|
allqueue(REDRAWIPO, 0);
|
|
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
#endif
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2021-07-05 10:46:00 +02:00
|
|
|
else if (ntree->type == NTREE_GEOMETRY) {
|
|
|
|
|
if (node->type == GEO_NODE_VIEWER) {
|
|
|
|
|
if ((node->flag & NODE_DO_OUTPUT) == 0) {
|
|
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
|
if (node_iter->type == GEO_NODE_VIEWER) {
|
|
|
|
|
node_iter->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
|
}
|
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
|
|
|
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,
|
|
|
|
|
* which only exists during actual drawing. Can we rely on valid totr rects?
|
|
|
|
|
*/
|
|
|
|
|
/* 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 Generic Operator Functions for Nodes
|
|
|
|
|
* \{ */
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2011-09-20 08:48:48 +00:00
|
|
|
#if 0 /* UNUSED */
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool edit_node_poll(bContext *C)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
return ED_operator_node_active(C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void edit_node_properties(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* XXX could node be a context pointer? */
|
2021-06-02 17:19:36 +02:00
|
|
|
RNA_def_string(ot->srna, "node", nullptr, MAX_NAME, "Node", "");
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_def_int(ot->srna, "socket", 0, 0, MAX_SOCKET, "Socket", "", 0, MAX_SOCKET);
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Side", "");
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int edit_node_invoke_properties(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "node")) {
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *node = CTX_data_pointer_get_type(C, "node", &RNA_Node).data;
|
2019-05-31 23:21:16 +10:00
|
|
|
if (!node) {
|
2011-09-05 21:01:50 +00:00
|
|
|
return 0;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_string_set(op->ptr, "node", node->name);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-05-31 23:21:16 +10:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "in_out")) {
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_enum_set(op->ptr, "in_out", SOCK_IN);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-05-31 23:21:16 +10:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "socket")) {
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_int_set(op->ptr, "socket", 0);
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 08:24:14 +02:00
|
|
|
static void edit_node_properties_get(
|
2020-03-25 17:58:58 +11:00
|
|
|
wmOperator *op, bNodeTree *ntree, bNode **r_node, bNodeSocket **r_sock, int *r_in_out)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
bNode *node;
|
2021-06-02 17:19:36 +02:00
|
|
|
bNodeSocket *sock = nullptr;
|
2012-01-11 08:51:06 +00:00
|
|
|
char nodename[MAX_NAME];
|
2011-09-05 21:01:50 +00:00
|
|
|
int sockindex;
|
|
|
|
|
int in_out;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_string_get(op->ptr, "node", nodename);
|
|
|
|
|
node = nodeFindNodebyName(ntree, nodename);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
sockindex = RNA_int_get(op->ptr, "socket");
|
|
|
|
|
switch (in_out) {
|
2019-04-17 08:24:14 +02:00
|
|
|
case SOCK_IN:
|
|
|
|
|
sock = BLI_findlink(&node->inputs, sockindex);
|
|
|
|
|
break;
|
|
|
|
|
case SOCK_OUT:
|
|
|
|
|
sock = BLI_findlink(&node->outputs, sockindex);
|
|
|
|
|
break;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-25 17:58:58 +11:00
|
|
|
if (r_node) {
|
|
|
|
|
*r_node = node;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2020-03-25 17:58:58 +11:00
|
|
|
if (r_sock) {
|
|
|
|
|
*r_sock = sock;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2020-03-25 17:58:58 +11:00
|
|
|
if (r_in_out) {
|
|
|
|
|
*r_in_out = in_out;
|
2019-05-31 23:21:16 +10:00
|
|
|
}
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
2011-09-20 08:48:48 +00:00
|
|
|
#endif
|
2009-11-20 21:04:41 +00:00
|
|
|
|
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,
|
|
|
|
|
const SpaceNode &snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->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);
|
2022-08-21 10:12:50 +02:00
|
|
|
if (BLI_rctf_inside_rctf(&node->totr, &socket_hitbox)) {
|
|
|
|
|
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 oldoffsetx, oldoffsety;
|
|
|
|
|
float oldwidth, oldheight;
|
|
|
|
|
int directions;
|
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
|
|
|
{
|
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 */
|
|
|
|
|
nsw->oldlocx = node->locx;
|
|
|
|
|
nsw->oldlocy = node->locy;
|
|
|
|
|
nsw->oldoffsetx = node->offsetx;
|
|
|
|
|
nsw->oldoffsety = node->offsety;
|
|
|
|
|
nsw->oldwidth = node->width;
|
|
|
|
|
nsw->oldheight = node->height;
|
|
|
|
|
nsw->directions = dir;
|
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);
|
|
|
|
|
bNode *node = nodeGetActive(snode->edittree);
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeSizeWidget *nsw = (NodeSizeWidget *)op->customdata;
|
2020-02-11 15:29:24 +01:00
|
|
|
|
|
|
|
|
node->locx = nsw->oldlocx;
|
|
|
|
|
node->locy = nsw->oldlocy;
|
|
|
|
|
node->offsetx = nsw->oldoffsetx;
|
|
|
|
|
node->offsety = nsw->oldoffsety;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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);
|
2013-03-18 16:34:57 +00:00
|
|
|
bNode *node = nodeGetActive(snode->edittree);
|
2021-06-02 17:19:36 +02:00
|
|
|
NodeSizeWidget *nsw = (NodeSizeWidget *)op->customdata;
|
2019-04-17 06:17:24 +02: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);
|
|
|
|
|
const float dx = (mx - nsw->mxstart) / UI_DPI_FAC;
|
|
|
|
|
const float dy = (my - nsw->mystart) / UI_DPI_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;
|
|
|
|
|
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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->locx = nsw->oldlocx + dx;
|
|
|
|
|
CLAMP(node->locx, locmax - widthmax, locmax - widthmin);
|
2014-05-09 08:51:37 +02:00
|
|
|
*pwidth = locmax - node->locx;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* height works the other way round ... */
|
|
|
|
|
{
|
|
|
|
|
float heightmin = UI_DPI_FAC * node->typeinfo->minheight;
|
|
|
|
|
float heightmax = UI_DPI_FAC * node->typeinfo->maxheight;
|
|
|
|
|
if (nsw->directions & NODE_RESIZE_TOP) {
|
|
|
|
|
float locmin = nsw->oldlocy - nsw->oldheight;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->locy = nsw->oldlocy + dy;
|
|
|
|
|
CLAMP(node->locy, locmin + heightmin, locmin + heightmax);
|
|
|
|
|
node->height = node->locy - 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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* XXX make callback? */
|
|
|
|
|
if (node->type == NODE_FRAME) {
|
|
|
|
|
/* keep the offset symmetric around center point */
|
|
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
|
|
|
|
node->locx = nsw->oldlocx + 0.5f * dx;
|
|
|
|
|
node->offsetx = nsw->oldoffsetx + 0.5f * dx;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
|
|
|
|
node->locx = nsw->oldlocx + 0.5f * dx;
|
|
|
|
|
node->offsetx = nsw->oldoffsetx - 0.5f * dx;
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_TOP) {
|
|
|
|
|
node->locy = nsw->oldlocy + 0.5f * dy;
|
|
|
|
|
node->offsety = nsw->oldoffsety + 0.5f * dy;
|
|
|
|
|
}
|
|
|
|
|
if (nsw->directions & NODE_RESIZE_BOTTOM) {
|
|
|
|
|
node->locy = nsw->oldlocy + 0.5f * dy;
|
|
|
|
|
node->offsety = nsw->oldoffsety - 0.5f * dy;
|
2011-09-05 21:01:50 +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;
|
|
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
if (event->val == KM_PRESS) {
|
2020-02-11 15:29:24 +01:00
|
|
|
node_resize_exit(C, op, true);
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_tag_redraw(region);
|
2020-02-11 15:29:24 +01:00
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2018-06-13 14:03:46 +02:00
|
|
|
break;
|
2020-12-14 17:19:43 -06:00
|
|
|
}
|
2022-07-26 16:03:43 -05:00
|
|
|
case EVT_ESCKEY:
|
|
|
|
|
node_resize_exit(C, op, true);
|
|
|
|
|
ED_region_tag_redraw(region);
|
|
|
|
|
return OPERATOR_CANCELLED;
|
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);
|
2021-12-03 16:25:17 -05:00
|
|
|
const bNode *node = nodeGetActive(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
|
|
|
|
2021-12-03 16:25:17 -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);
|
|
|
|
|
const NodeResizeDirection dir = node_get_resize_direction(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
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
|
2012-06-01 12:38:03 +00:00
|
|
|
{
|
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 {
|
|
|
|
|
/* 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) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (nodeCountSocketLinks(snode->edittree, sock) == 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* checks snode->mouse position, and returns found node/socket */
|
2022-09-02 14:09:32 -05: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);
|
2022-09-02 17:03:48 -05:00
|
|
|
const float2 location(socket.locx, socket.locy);
|
2021-06-26 21:35:18 +10:00
|
|
|
/* `.xmax = socket->locx + 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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
bool node_find_indicated_socket(SpaceNode &snode,
|
|
|
|
|
bNode **nodep,
|
|
|
|
|
bNodeSocket **sockp,
|
|
|
|
|
const float2 &cursor,
|
|
|
|
|
const eNodeSocketInOut in_out)
|
2009-02-07 14:03:34 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
rctf rect;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-02-18 12:22:51 -06:00
|
|
|
const float size_sock_padded = NODE_SOCKSIZE + 4;
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
*nodep = nullptr;
|
|
|
|
|
*sockp = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* check if we click in a socket */
|
2022-08-21 10:12:50 +02:00
|
|
|
LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) {
|
2022-02-18 12:22:51 -06:00
|
|
|
BLI_rctf_init_pt_radius(&rect, cursor, size_sock_padded);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (!(node->flag & NODE_HIDDEN)) {
|
|
|
|
|
/* extra padding inside and out - allow dragging on the text areas too */
|
|
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
|
rect.xmax += NODE_SOCKSIZE;
|
|
|
|
|
rect.xmin -= NODE_SOCKSIZE * 4;
|
|
|
|
|
}
|
|
|
|
|
else if (in_out == SOCK_OUT) {
|
|
|
|
|
rect.xmax += NODE_SOCKSIZE * 4;
|
|
|
|
|
rect.xmin -= NODE_SOCKSIZE;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (in_out & SOCK_IN) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2012-08-01 19:11:17 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
2022-09-02 17:03:48 -05:00
|
|
|
const float2 location(sock->locx, sock->locy);
|
2021-02-11 01:16:17 -06:00
|
|
|
if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
|
2021-12-03 16:25:17 -05:00
|
|
|
if (cursor_isect_multi_input_socket(cursor, *sock)) {
|
2022-09-02 17:03:48 -05:00
|
|
|
if (!socket_is_occluded(location, *node, snode)) {
|
2021-02-11 01:16:17 -06:00
|
|
|
*nodep = node;
|
|
|
|
|
*sockp = sock;
|
2021-11-16 17:20:31 -06:00
|
|
|
return true;
|
2021-02-11 01:16:17 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-02 17:03:48 -05:00
|
|
|
else if (BLI_rctf_isect_pt(&rect, location.x, location.y)) {
|
|
|
|
|
if (!socket_is_occluded(location, *node, snode)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
*nodep = node;
|
|
|
|
|
*sockp = sock;
|
2021-11-16 17:20:31 -06:00
|
|
|
return true;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (in_out & SOCK_OUT) {
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
2012-08-01 19:11:17 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
2022-09-02 17:03:48 -05:00
|
|
|
const float2 location(sock->locx, sock->locy);
|
|
|
|
|
if (BLI_rctf_isect_pt(&rect, location.x, location.y)) {
|
|
|
|
|
if (!socket_is_occluded(location, *node, snode)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
*nodep = node;
|
|
|
|
|
*sockp = sock;
|
2021-11-16 17:20:31 -06:00
|
|
|
return true;
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-11-16 17:20:31 -06:00
|
|
|
return false;
|
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
|
|
|
|
2021-12-03 16:25:17 -05: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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 17:03:48 -05:00
|
|
|
const float2 from(link.fromsock->locx, link.fromsock->locy);
|
|
|
|
|
const float2 to(link.tosock->locx, link.tosock->locy);
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 16:25:17 -05:00
|
|
|
bool node_link_is_hidden_or_dimmed(const View2D &v2d, const bNodeLink &link)
|
2021-07-15 11:00:23 +02:00
|
|
|
{
|
2021-12-03 16:25:17 -05:00
|
|
|
return nodeLinkIsHidden(&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
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
static void node_duplicate_reparent_recursive(const Map<const bNode *, bNode *> &node_map,
|
|
|
|
|
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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* find first selected parent */
|
|
|
|
|
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)) {
|
2021-12-22 08:47:46 -06:00
|
|
|
node_duplicate_reparent_recursive(node_map, parent);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* reparent node copy to parent copy */
|
|
|
|
|
if (parent) {
|
2021-12-22 08:47:46 -06:00
|
|
|
nodeDetachNode(node_map.lookup(node));
|
|
|
|
|
nodeAttachNode(node_map.lookup(node), node_map.lookup(parent));
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2009-02-07 14:03:34 +00: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;
|
2022-04-05 20:13:03 +10:00
|
|
|
bool changed = false;
|
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
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
Map<const bNode *, bNode *> node_map;
|
|
|
|
|
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
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *lastnode = (bNode *)ntree->nodes.last;
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2022-09-03 14:12:55 -05:00
|
|
|
bNode *new_node = bke::node_copy_with_mapping(
|
2021-12-22 08:47:46 -06:00
|
|
|
ntree, *node, LIB_ID_COPY_DEFAULT, true, socket_map);
|
|
|
|
|
node_map.add_new(node, new_node);
|
2022-10-13 20:06:20 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2022-04-05 20:13:03 +10:00
|
|
|
changed = true;
|
2011-07-22 16:39:06 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* make sure we don't copy new nodes again! */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node == lastnode) {
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
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-04-05 20:13:03 +10:00
|
|
|
if (!changed) {
|
|
|
|
|
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) {
|
2012-08-01 19:11:17 +00:00
|
|
|
/* This creates new links between copied nodes.
|
2021-06-02 17:19:36 +02:00
|
|
|
* If keep_inputs is set, also copies input links from unselected (when fromnode==nullptr)!
|
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) {
|
|
|
|
|
newlink->multi_input_socket_index = link->multi_input_socket_index;
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
|
|
|
|
/* input node not copied, this keeps the original input linked */
|
|
|
|
|
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
|
|
|
|
2012-08-01 19:11:17 +00: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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* clear flags for recursive depth-first iteration */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-08-01 19:11:17 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
/* reparent copied nodes */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((node->flag & SELECT) && !(node->flag & NODE_TEST)) {
|
2021-12-22 08:47:46 -06:00
|
|
|
node_duplicate_reparent_recursive(node_map, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* only has to check old nodes */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node == lastnode) {
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* deselect old nodes, select the copies instead */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-08-01 19:11:17 +00:00
|
|
|
/* has been set during copy above */
|
2021-12-22 08:47:46 -06:00
|
|
|
bNode *newnode = node_map.lookup(node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(node, false);
|
2020-05-25 10:43:44 +02:00
|
|
|
node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_TEXTURE);
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(newnode, true);
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* make sure we don't copy new nodes again! */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node == lastnode) {
|
2012-08-01 19:11:17 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
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
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/* XXX: some code needing updating to operators. */
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2010-04-06 17:47:21 +00: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);
|
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) {
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
scene->id.tag |= LIB_TAG_DOIT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
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
|
|
|
if ((node->type == CMP_NODE_R_LAYERS) ||
|
|
|
|
|
(node->type == CMP_NODE_CRYPTOMATTE && node->custom1 == CMP_CRYPTOMATTE_SRC_RENDER)) {
|
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;
|
|
|
|
|
}
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
if (id->tag & LIB_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);
|
Split id->flag in two, persistent flags and runtime tags.
This is purely internal sanitizing/cleanup, no change in behavior is expected at all.
This change was also needed because we were getting short on ID flags, and
future enhancement of 'user_one' ID behavior requires two new ones.
id->flag remains for persistent data (fakeuser only, so far!), this also allows us
100% backward & forward compatibility.
New id->tag is used for most flags. Though written in .blend files, its content
is cleared at read time.
Note that .blend file version was bumped, so that we can clear runtimeflags from
old .blends, important in case we add new persistent flags in future.
Also, behavior of tags (either status ones, or whether they need to be cleared before/after use)
has been added as comments to their declaration.
Reviewers: sergey, campbellbarton
Differential Revision: https://developer.blender.org/D1683
2015-12-27 11:53:50 +01:00
|
|
|
id->tag &= ~LIB_TAG_DOIT;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
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
|
|
|
{
|
2018-06-04 09:31:30 +02: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;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
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;
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &sce->nodetree->nodes) {
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-12-18 12:51:50 +00: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.
|
|
|
|
|
*/
|
2020-12-14 17:19:43 -06:00
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) {
|
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
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0) {
|
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
|
|
|
|
2010-06-07 20:03:40 +00: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
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
node_flag_toggle_exec(snode, NODE_PREVIEW);
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
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);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) {
|
|
|
|
|
if (node->type != GEO_NODE_VIEWER) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!(node->flag & SELECT)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (node == active_viewer) {
|
|
|
|
|
node->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
BKE_ntree_update_tag_node_property(snode.edittree, node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode.edittree);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-04-16 10:50:57 +00:00
|
|
|
node_set_hidden_sockets(snode, node, !hidden);
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
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);
|
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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->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
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
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";
|
|
|
|
|
ot->description = "Toggle muting of the nodes";
|
|
|
|
|
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
|
|
|
|
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) {
|
2019-03-16 18:54:00 +01:00
|
|
|
nodeRemoveNode(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
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
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";
|
|
|
|
|
ot->description = "Delete selected nodes";
|
|
|
|
|
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 Switch View
|
|
|
|
|
* \{ */
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_switch_view_poll(bContext *C)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (snode && snode->edittree) {
|
2015-04-06 10:40:12 -03:00
|
|
|
return true;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_switch_view_exec(bContext *C, wmOperator * /*op*/)
|
2015-04-06 10:40:12 -03:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH_MUTABLE (bNode *, node, &snode->edittree->nodes) {
|
2015-04-06 10:40:12 -03:00
|
|
|
if (node->flag & SELECT) {
|
|
|
|
|
/* call the update function from the Switch View node */
|
|
|
|
|
node->update = NODE_UPDATE_OPERATOR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_switch_view_update(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Update Views";
|
|
|
|
|
ot->description = "Update views of selected node";
|
|
|
|
|
ot->idname = "NODE_OT_switch_view_update";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_switch_view_exec;
|
|
|
|
|
ot->poll = node_switch_view_poll;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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) {
|
|
|
|
|
nodeInternalRelink(snode->edittree, node);
|
2019-03-16 18:54:00 +01:00
|
|
|
nodeRemoveNode(bmain, snode->edittree, node, true);
|
2012-08-01 19:11:17 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
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";
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->description = "Delete nodes; will reconnect nodes as if deletion was muted";
|
|
|
|
|
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;
|
|
|
|
|
node = nodeGetActive(snode->edittree);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!node || node->type != 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
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
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;
|
|
|
|
|
node = nodeGetActive(snode->edittree);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!node || node->type != 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
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
|
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";
|
|
|
|
|
ot->description = "Remove active input from a file output node";
|
|
|
|
|
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) {
|
2013-04-24 16:59:56 +00:00
|
|
|
node = nodeGetActive(snode->edittree);
|
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 || node->type != 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
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
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
|
|
|
|
2022-09-06 11:33:47 -05:00
|
|
|
bNode *active_node = nodeGetActive(&ntree);
|
|
|
|
|
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-09-06 11:33:47 -05:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
|
|
|
|
|
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 Copy to Clipboard Operator
|
|
|
|
|
* \{ */
|
2012-08-02 09:52:37 +00:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
static int node_clipboard_copy_exec(bContext *C, wmOperator * /*op*/)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* clear current clipboard */
|
2012-08-06 08:25:24 +00:00
|
|
|
BKE_node_clipboard_clear();
|
2012-08-06 08:41:45 +00:00
|
|
|
BKE_node_clipboard_init(ntree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
Map<const bNode *, bNode *> node_map;
|
|
|
|
|
Map<const bNodeSocket *, bNodeSocket *> socket_map;
|
|
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-08-02 09:52:37 +00:00
|
|
|
if (node->flag & SELECT) {
|
2019-04-22 00:18:34 +10:00
|
|
|
/* No ID refcounting, this node is virtual,
|
|
|
|
|
* detached from any actual Blender data currently. */
|
2022-09-03 14:12:55 -05:00
|
|
|
bNode *new_node = bke::node_copy_with_mapping(nullptr,
|
|
|
|
|
*node,
|
|
|
|
|
LIB_ID_CREATE_NO_USER_REFCOUNT |
|
|
|
|
|
LIB_ID_CREATE_NO_MAIN,
|
|
|
|
|
false,
|
|
|
|
|
socket_map);
|
2021-12-22 08:47:46 -06:00
|
|
|
node_map.add_new(node, new_node);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
for (bNode *new_node : node_map.values()) {
|
|
|
|
|
BKE_node_clipboard_add_node(new_node);
|
|
|
|
|
|
|
|
|
|
/* Parent pointer must be redirected to new node or detached if parent is not copied. */
|
|
|
|
|
if (new_node->parent) {
|
|
|
|
|
if (node_map.contains(new_node->parent)) {
|
|
|
|
|
new_node->parent = node_map.lookup(new_node->parent);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeDetachNode(new_node);
|
2012-08-03 10:18:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
/* Copy links between selected nodes. */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
2021-12-22 08:47:46 -06:00
|
|
|
BLI_assert(link->tonode);
|
|
|
|
|
BLI_assert(link->fromnode);
|
|
|
|
|
if (link->tonode->flag & NODE_SELECT && link->fromnode->flag & NODE_SELECT) {
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeLink *newlink = MEM_cnew<bNodeLink>(__func__);
|
2012-08-02 09:52:37 +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);
|
|
|
|
|
newlink->fromnode = node_map.lookup(link->fromnode);
|
|
|
|
|
newlink->fromsock = socket_map.lookup(link->fromsock);
|
2022-10-14 14:07:55 -05:00
|
|
|
newlink->multi_input_socket_index = link->multi_input_socket_index;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
BKE_node_clipboard_add_link(newlink);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_clipboard_copy(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-01-27 07:23:58 +00:00
|
|
|
ot->name = "Copy to Clipboard";
|
2012-08-02 09:52:37 +00:00
|
|
|
ot->description = "Copies selected nodes to the clipboard";
|
|
|
|
|
ot->idname = "NODE_OT_clipboard_copy";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_clipboard_copy_exec;
|
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Paste from Clipboard
|
|
|
|
|
* \{ */
|
2012-08-02 09:52:37 +00:00
|
|
|
|
2012-08-06 08:41:45 +00:00
|
|
|
static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-20 13:59:19 +00:00
|
|
|
/* validate pointers in the clipboard */
|
2020-12-14 17:19:43 -06:00
|
|
|
bool is_clipboard_valid = BKE_node_clipboard_validate();
|
|
|
|
|
const ListBase *clipboard_nodes_lb = BKE_node_clipboard_get_nodes();
|
|
|
|
|
const ListBase *clipboard_links_lb = BKE_node_clipboard_get_links();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
if (BLI_listbase_is_empty(clipboard_nodes_lb)) {
|
2012-08-20 13:59:19 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Clipboard is empty");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-06 08:41:45 +00:00
|
|
|
if (BKE_node_clipboard_get_type() != ntree->type) {
|
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Clipboard nodes are an incompatible type");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-20 13:59:19 +00:00
|
|
|
/* only warn */
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_clipboard_valid == false) {
|
2012-08-20 13:59:19 +00:00
|
|
|
BKE_report(op->reports,
|
|
|
|
|
RPT_WARNING,
|
|
|
|
|
"Some nodes references could not be restored, will be left empty");
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-03 09:10:29 +00:00
|
|
|
/* make sure all clipboard nodes would be valid in the target tree */
|
2020-12-14 17:19:43 -06:00
|
|
|
bool all_nodes_valid = true;
|
|
|
|
|
LISTBASE_FOREACH (bNode *, node, clipboard_nodes_lb) {
|
2021-06-02 17:19:36 +02:00
|
|
|
const char *disabled_hint = nullptr;
|
2021-04-12 18:43:23 +02:00
|
|
|
if (!node->typeinfo->poll_instance ||
|
|
|
|
|
!node->typeinfo->poll_instance(node, ntree, &disabled_hint)) {
|
2014-04-01 11:34:00 +11:00
|
|
|
all_nodes_valid = false;
|
2021-04-12 18:43:23 +02:00
|
|
|
if (disabled_hint) {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR,
|
|
|
|
|
"Cannot add node %s into node tree %s:\n %s",
|
|
|
|
|
node->name,
|
|
|
|
|
ntree->id.name + 2,
|
|
|
|
|
disabled_hint);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_reportf(op->reports,
|
|
|
|
|
RPT_ERROR,
|
|
|
|
|
"Cannot add node %s into node tree %s",
|
|
|
|
|
node->name,
|
|
|
|
|
ntree->id.name + 2);
|
|
|
|
|
}
|
2013-04-03 09:10:29 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!all_nodes_valid) {
|
2013-04-03 09:10:29 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-18 15:51:31 +01:00
|
|
|
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* deselect old nodes */
|
2021-12-03 16:25:17 -05:00
|
|
|
node_deselect_all(*snode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* calculate "barycenter" for placing on mouse cursor */
|
2022-09-02 14:09:32 -05:00
|
|
|
float2 center = {0.0f, 0.0f};
|
2020-12-14 17:19:43 -06:00
|
|
|
int num_nodes = 0;
|
|
|
|
|
LISTBASE_FOREACH_INDEX (bNode *, node, clipboard_nodes_lb, num_nodes) {
|
2022-09-02 14:09:32 -05:00
|
|
|
center.x += BLI_rctf_cent_x(&node->totr);
|
|
|
|
|
center.y += BLI_rctf_cent_y(&node->totr);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
2012-08-20 13:59:19 +00:00
|
|
|
mul_v2_fl(center, 1.0 / num_nodes);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
Map<const bNode *, bNode *> node_map;
|
|
|
|
|
Map<const bNodeSocket *, bNodeSocket *> socket_map;
|
|
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* copy nodes from clipboard */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, clipboard_nodes_lb) {
|
2022-09-03 14:12:55 -05:00
|
|
|
bNode *new_node = bke::node_copy_with_mapping(
|
2021-12-22 08:47:46 -06:00
|
|
|
ntree, *node, LIB_ID_COPY_DEFAULT, true, socket_map);
|
|
|
|
|
node_map.add_new(node, new_node);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
for (bNode *new_node : node_map.values()) {
|
2012-08-02 09:52:37 +00:00
|
|
|
/* pasted nodes are selected */
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(new_node, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-22 08:47:46 -06:00
|
|
|
/* The parent pointer must be redirected to new node. */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (new_node->parent) {
|
2021-12-22 08:47:46 -06:00
|
|
|
if (node_map.contains(new_node->parent)) {
|
|
|
|
|
new_node->parent = node_map.lookup(new_node->parent);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, clipboard_links_lb) {
|
2022-10-14 14:07:55 -05:00
|
|
|
bNodeLink *new_link = nodeAddLink(ntree,
|
|
|
|
|
node_map.lookup(link->fromnode),
|
|
|
|
|
socket_map.lookup(link->fromsock),
|
|
|
|
|
node_map.lookup(link->tonode),
|
|
|
|
|
socket_map.lookup(link->tosock));
|
|
|
|
|
new_link->multi_input_socket_index = link->multi_input_socket_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntree->ensure_topology_cache();
|
|
|
|
|
|
|
|
|
|
for (bNode *new_node : node_map.values()) {
|
|
|
|
|
/* Update multi input socket indices in case all connected nodes weren't copied. */
|
|
|
|
|
update_multi_input_indices_for_removed_links(*new_node);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-04 13:32:33 +01:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, snode->edittree);
|
2021-03-04 13:32:33 +01:00
|
|
|
/* Pasting nodes can create arbitrary new relations, because nodes can reference IDs. */
|
|
|
|
|
DEG_relations_tag_update(bmain);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_clipboard_paste(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-01-27 07:23:58 +00:00
|
|
|
ot->name = "Paste from Clipboard";
|
2012-08-02 09:52:37 +00:00
|
|
|
ot->description = "Pastes nodes from the clipboard to the active node tree";
|
|
|
|
|
ot->idname = "NODE_OT_clipboard_paste";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = node_clipboard_paste_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2012-08-02 09:52:37 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node-Tree Add Interface Socket Operator
|
|
|
|
|
* \{ */
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static bNodeSocket *ntree_get_active_interface_socket(ListBase *lb)
|
|
|
|
|
{
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, lb) {
|
|
|
|
|
if (socket->flag & SELECT) {
|
|
|
|
|
return socket;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-02 17:19:36 +02:00
|
|
|
return nullptr;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static int ntree_socket_add_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
PointerRNA ntree_ptr;
|
2013-03-18 16:34:57 +00:00
|
|
|
RNA_id_pointer_create((ID *)ntree, &ntree_ptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eNodeSocketInOut in_out = (eNodeSocketInOut)RNA_enum_get(op->ptr, "in_out");
|
2021-01-10 13:24:37 -06:00
|
|
|
ListBase *sockets = (in_out == SOCK_IN) ? &ntree->inputs : &ntree->outputs;
|
|
|
|
|
|
2022-08-29 14:25:18 +02:00
|
|
|
const char *default_name = (in_out == SOCK_IN) ? DATA_("Input") : DATA_("Output");
|
2021-01-10 13:24:37 -06:00
|
|
|
bNodeSocket *active_sock = ntree_get_active_interface_socket(sockets);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeSocket *sock;
|
2013-03-18 16:34:57 +00:00
|
|
|
if (active_sock) {
|
|
|
|
|
/* insert a copy of the active socket right after it */
|
|
|
|
|
sock = ntreeInsertSocketInterface(
|
|
|
|
|
ntree, in_out, active_sock->idname, active_sock->next, active_sock->name);
|
|
|
|
|
/* XXX this only works for actual sockets, not interface templates! */
|
2021-06-26 21:35:18 +10:00
|
|
|
// nodeSocketCopyValue(sock, &ntree_ptr, active_sock, &ntree_ptr);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* XXX TODO: define default socket type for a tree! */
|
2013-03-18 16:34:57 +00:00
|
|
|
sock = ntreeAddSocketInterface(ntree, in_out, "NodeSocketFloat", default_name);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-10 13:24:37 -06:00
|
|
|
/* Deactivate sockets. */
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket_iter, sockets) {
|
2020-12-14 17:19:43 -06:00
|
|
|
socket_iter->flag &= ~SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
/* make the new socket active */
|
|
|
|
|
sock->flag |= SELECT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_tree_socket_add(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->name = "Add Node Tree Interface Socket";
|
2013-03-18 18:43:22 +00:00
|
|
|
ot->description = "Add an input or output socket to the current node tree";
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->idname = "NODE_OT_tree_socket_add";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* api callbacks */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->exec = ntree_socket_add_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* flags */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", "");
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node-Tree Remove Interface Socket Operator
|
|
|
|
|
* \{ */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2021-01-10 13:24:37 -06:00
|
|
|
static int ntree_socket_remove_exec(bContext *C, wmOperator *op)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2021-06-02 17:19:36 +02:00
|
|
|
const eNodeSocketInOut in_out = (eNodeSocketInOut)RNA_enum_get(op->ptr, "in_out");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-01-10 13:24:37 -06:00
|
|
|
bNodeSocket *iosock = ntree_get_active_interface_socket(in_out == SOCK_IN ? &ntree->inputs :
|
|
|
|
|
&ntree->outputs);
|
2021-06-02 17:19:36 +02:00
|
|
|
if (iosock == nullptr) {
|
2013-03-18 16:34:57 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* preferably next socket becomes active, otherwise try previous socket */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeSocket *active_sock = (iosock->next ? iosock->next : iosock->prev);
|
2013-03-18 16:34:57 +00:00
|
|
|
ntreeRemoveSocketInterface(ntree, iosock);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* set active socket */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (active_sock) {
|
2013-03-18 16:34:57 +00:00
|
|
|
active_sock->flag |= SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
|
2019-04-16 02:29:22 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_tree_socket_remove(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->name = "Remove Node Tree Interface Socket";
|
2013-03-18 18:43:22 +00:00
|
|
|
ot->description = "Remove an input or output socket to the current node tree";
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->idname = "NODE_OT_tree_socket_remove";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* api callbacks */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->exec = ntree_socket_remove_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* flags */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2021-01-10 13:24:37 -06:00
|
|
|
RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", "");
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node-Tree Change Interface Socket Type Operator
|
|
|
|
|
* \{ */
|
2021-07-06 18:36:11 +01:00
|
|
|
|
|
|
|
|
static int ntree_socket_change_type_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
|
const eNodeSocketInOut in_out = (eNodeSocketInOut)RNA_enum_get(op->ptr, "in_out");
|
|
|
|
|
const bNodeSocketType *socket_type = rna_node_socket_type_from_enum(
|
|
|
|
|
RNA_enum_get(op->ptr, "socket_type"));
|
|
|
|
|
ListBase *sockets = (in_out == SOCK_IN) ? &ntree->inputs : &ntree->outputs;
|
|
|
|
|
|
|
|
|
|
Main *main = CTX_data_main(C);
|
|
|
|
|
|
|
|
|
|
bNodeSocket *iosock = ntree_get_active_interface_socket(sockets);
|
2021-07-07 12:20:00 +10:00
|
|
|
if (iosock == nullptr) {
|
2021-07-06 18:36:11 +01:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The type remains the same, so we don't need to change anything. */
|
|
|
|
|
if (iosock->typeinfo == socket_type) {
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 18:13:19 +10:00
|
|
|
/* Don't handle sub-types for now. */
|
2021-07-07 12:20:00 +10:00
|
|
|
nodeModifySocketType(ntree, nullptr, iosock, socket_type->idname);
|
2021-07-06 18:36:11 +01:00
|
|
|
|
|
|
|
|
/* Need the extra update here because the loop above does not check for valid links in the node
|
|
|
|
|
* group we're currently editing. */
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_tag_interface(ntree);
|
2021-07-06 18:36:11 +01:00
|
|
|
|
|
|
|
|
/* Deactivate sockets. */
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket_iter, sockets) {
|
|
|
|
|
socket_iter->flag &= ~SELECT;
|
|
|
|
|
}
|
|
|
|
|
/* Make the new socket active. */
|
|
|
|
|
iosock->flag |= SELECT;
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, main, ntree);
|
2021-07-06 18:36:11 +01:00
|
|
|
|
2021-07-07 12:20:00 +10:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2021-07-06 18:36:11 +01:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool socket_change_poll_type(void *userdata, bNodeSocketType *socket_type)
|
|
|
|
|
{
|
|
|
|
|
/* Check if the node tree supports the socket type. */
|
|
|
|
|
bNodeTreeType *ntreetype = (bNodeTreeType *)userdata;
|
|
|
|
|
if (ntreetype->valid_socket_type && !ntreetype->valid_socket_type(ntreetype, socket_type)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Only use basic socket types for this enum. */
|
|
|
|
|
if (socket_type->subtype != PROP_NONE) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const EnumPropertyItem *socket_change_type_itemf(bContext *C,
|
2022-10-03 17:37:25 -05:00
|
|
|
PointerRNA * /*ptr*/,
|
|
|
|
|
PropertyRNA * /*prop*/,
|
2021-07-06 18:36:11 +01:00
|
|
|
bool *r_free)
|
|
|
|
|
{
|
|
|
|
|
if (!C) {
|
|
|
|
|
return DummyRNA_NULL_items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
if (!snode || !snode->edittree) {
|
|
|
|
|
return DummyRNA_NULL_items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rna_node_socket_type_itemf(snode->edittree->typeinfo, socket_change_poll_type, r_free);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_tree_socket_change_type(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Change Node Tree Interface Socket Type";
|
|
|
|
|
ot->description = "Change the type of a socket of the current node tree";
|
|
|
|
|
ot->idname = "NODE_OT_tree_socket_change_type";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = WM_menu_invoke;
|
|
|
|
|
ot->exec = ntree_socket_change_type_exec;
|
|
|
|
|
ot->poll = ED_operator_node_editable;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", "");
|
|
|
|
|
prop = RNA_def_enum(ot->srna, "socket_type", DummyRNA_DEFAULT_items, 0, "Socket Type", "");
|
|
|
|
|
RNA_def_enum_funcs(prop, socket_change_type_itemf);
|
|
|
|
|
ot->prop = prop;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 09:39:43 +10:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node-Tree Move Interface Socket Operator
|
|
|
|
|
* \{ */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem move_direction_items[] = {
|
2013-03-18 16:34:57 +00:00
|
|
|
{1, "UP", 0, "Up", ""},
|
|
|
|
|
{2, "DOWN", 0, "Down", ""},
|
2021-06-02 17:19:36 +02:00
|
|
|
{0, nullptr, 0, nullptr, nullptr},
|
2013-03-18 16:34:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int ntree_socket_move_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
|
int direction = RNA_enum_get(op->ptr, "direction");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
const eNodeSocketInOut in_out = (eNodeSocketInOut)RNA_enum_get(op->ptr, "in_out");
|
2021-01-10 13:24:37 -06:00
|
|
|
ListBase *sockets = in_out == SOCK_IN ? &ntree->inputs : &ntree->outputs;
|
|
|
|
|
|
|
|
|
|
bNodeSocket *iosock = ntree_get_active_interface_socket(sockets);
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
if (iosock == nullptr) {
|
2013-03-18 16:34:57 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
switch (direction) {
|
2013-07-19 10:40:43 +00:00
|
|
|
case 1: { /* up */
|
|
|
|
|
bNodeSocket *before = iosock->prev;
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_remlink(sockets, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (before) {
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_insertlinkbefore(sockets, before, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_addhead(sockets, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2: { /* down */
|
|
|
|
|
bNodeSocket *after = iosock->next;
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_remlink(sockets, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (after) {
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_insertlinkafter(sockets, after, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2021-01-10 13:24:37 -06:00
|
|
|
BLI_addtail(sockets, iosock);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_tag_interface(ntree);
|
|
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NODE_OT_tree_socket_move(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->name = "Move Node Tree Socket";
|
2013-03-18 18:43:22 +00:00
|
|
|
ot->description = "Move a socket up or down in the current node tree's sockets stack";
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->idname = "NODE_OT_tree_socket_move";
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* api callbacks */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->exec = ntree_socket_move_exec;
|
2013-06-05 19:06:33 +00:00
|
|
|
ot->poll = ED_operator_node_editable;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* flags */
|
2013-03-18 18:25:05 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
RNA_def_enum(ot->srna, "direction", move_direction_items, 1, "Direction", "");
|
2021-01-10 13:24:37 -06:00
|
|
|
RNA_def_enum(ot->srna, "in_out", rna_enum_node_socket_in_out_items, SOCK_IN, "Socket Type", "");
|
2013-03-18 16:34:57 +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
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
/* 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) {
|
2013-04-24 16:59:56 +00:00
|
|
|
node = nodeGetActive(snode->edittree);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-04-24 16:59:56 +00:00
|
|
|
|
2012-11-03 15:35:03 +00:00
|
|
|
if (node && node->type == 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
/* we don't check if text datablock is actually in use, too slow for poll */
|
|
|
|
|
|
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,
|
|
|
|
|
Text *text)
|
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
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
ntree->done = true;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-11-03 14:32:26 +00:00
|
|
|
/* update each script that is using this text datablock */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-11-03 15:35:03 +00:00
|
|
|
if (node->type == NODE_GROUP) {
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeTree *ngroup = (bNodeTree *)node->id;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ngroup && !ngroup->done) {
|
2013-03-18 16:34:57 +00:00
|
|
|
found |= node_shader_script_update_text_recursive(engine, type, ngroup, text);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-11-03 14:32:26 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (node->type == SH_NODE_SCRIPT && node->id == &text->id) {
|
|
|
|
|
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
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
/* get node */
|
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;
|
2013-04-24 16:59:56 +00:00
|
|
|
node = nodeGetActive(snode->edittree);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
if (node) {
|
|
|
|
|
/* 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 {
|
|
|
|
|
/* 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) {
|
|
|
|
|
/* clear flags for recursion check */
|
2018-11-30 15:22:01 +11:00
|
|
|
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
2014-04-01 11:34:00 +11:00
|
|
|
ntree->done = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2018-11-30 15:22:01 +11:00
|
|
|
FOREACH_NODETREE_END;
|
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) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!ntree->done) {
|
2013-03-18 16:34:57 +00:00
|
|
|
found |= node_shader_script_update_text_recursive(engine, type, ntree, text);
|
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;
|
|
|
|
|
|
|
|
|
|
/* get border from operator */
|
|
|
|
|
WM_operator_properties_border_to_rcti(op, &rect);
|
|
|
|
|
|
|
|
|
|
/* convert border to unified space within backdrop image */
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/* clamp coordinates */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, bmain, btree);
|
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;
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), btree);
|
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;
|
|
|
|
|
node = nodeGetActive(snode->edittree);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if (!node || node->type != CMP_NODE_CRYPTOMATTE_LEGACY) {
|
2018-07-18 13:03:09 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntreeCompositCryptomatteAddSocket(ntree, node);
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
|
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;
|
|
|
|
|
node = nodeGetActive(snode->edittree);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if (!node || node->type != CMP_NODE_CRYPTOMATTE_LEGACY) {
|
2018-07-18 13:03:09 +02:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ntreeCompositCryptomatteRemoveSocket(ntree, node)) {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
ED_node_tree_propagate_change(C, CTX_data_main(C), ntree);
|
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
|