2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-24 10:33:10 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-24 10:33:10 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-24 10:33:10 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup spnode
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_image.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"
|
|
|
|
#include "BKE_report.h"
|
2011-11-08 11:38:16 +00:00
|
|
|
#include "BKE_scene.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
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"
|
|
|
|
|
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"
|
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"
|
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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "node_intern.h" /* own include */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2012-08-15 11:31:04 +00:00
|
|
|
#define USE_ESC_COMPO
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* ***************** composite job manager ********************** */
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
typedef 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;
|
2009-01-27 17:12:40 +00:00
|
|
|
} CompoJob;
|
|
|
|
|
2021-02-11 01:16:17 -06:00
|
|
|
float node_socket_calculate_height(const bNodeSocket *socket)
|
|
|
|
{
|
|
|
|
float sock_height = NODE_SOCKSIZE * 2.0f;
|
|
|
|
if (socket->flag & SOCK_MULTI_INPUT) {
|
|
|
|
sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket->total_inputs, NODE_SOCKSIZE);
|
|
|
|
}
|
|
|
|
return sock_height;
|
|
|
|
}
|
|
|
|
|
2021-03-10 14:57:57 +01:00
|
|
|
void node_link_calculate_multi_input_position(const float socket_x,
|
|
|
|
const float socket_y,
|
|
|
|
const int index,
|
|
|
|
const int total_inputs,
|
|
|
|
float r[2])
|
2021-02-11 01:16:17 -06:00
|
|
|
{
|
2021-03-10 14:57:57 +01:00
|
|
|
float offset = (total_inputs * NODE_MULTI_INPUT_LINK_GAP - NODE_MULTI_INPUT_LINK_GAP) * 0.5;
|
|
|
|
r[0] = socket_x - NODE_SOCKSIZE * 0.5f;
|
|
|
|
r[1] = socket_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) {
|
|
|
|
SpaceImage *sima = 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) {
|
|
|
|
SpaceNode *snode = 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)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-15 11:31:04 +00:00
|
|
|
/* without G.is_break 'ESC' wont quit - which annoys users */
|
|
|
|
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 */
|
2015-03-28 02:36:00 +11:00
|
|
|
static void compo_statsdrawjob(void *cjv, const char *UNUSED(str))
|
2012-11-30 09:12:10 +00:00
|
|
|
{
|
|
|
|
CompoJob *cj = 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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = 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)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = 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
|
|
|
}
|
2019-06-03 14:47:44 +02:00
|
|
|
if (cj->compositor_depsgraph != NULL) {
|
|
|
|
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)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = 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 */
|
2015-03-27 18:23:11 +05:00
|
|
|
static void compo_updatejob(void *UNUSED(cjv))
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2013-06-24 22:41:27 +00:00
|
|
|
WM_main_add_notifier(NC_SCENE | ND_COMPO_RESULT, NULL);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void compo_progressjob(void *cjv, float progress)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = 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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
|
|
|
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 */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-07 16:37:16 -03:00
|
|
|
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
|
|
|
|
ntreeCompositExecTree(cj->scene,
|
|
|
|
ntree,
|
|
|
|
&cj->scene->r,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
&scene->view_settings,
|
|
|
|
&scene->display_settings,
|
|
|
|
"");
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2015-04-07 16:37:16 -03:00
|
|
|
ntreeCompositExecTree(cj->scene,
|
|
|
|
ntree,
|
|
|
|
&cj->scene->r,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
&scene->view_settings,
|
|
|
|
&scene->display_settings,
|
|
|
|
srv->name);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree->test_break = NULL;
|
|
|
|
ntree->stats_draw = NULL;
|
|
|
|
ntree->progress = NULL;
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2012-08-03 20:56:04 +00:00
|
|
|
/**
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param scene_owner: is the owner of the job,
|
2012-08-03 20:56:04 +00:00
|
|
|
* we don't use it for anything else currently so could also be a void pointer,
|
|
|
|
* but for now keep it an 'Scene' for consistency.
|
|
|
|
*
|
|
|
|
* \note only call from spaces `refresh` callbacks, not direct! - use with care.
|
|
|
|
*/
|
|
|
|
void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene *scene_owner)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
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);
|
|
|
|
CompoJob *cj = MEM_callocN(sizeof(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);
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_callbacks(wm_job, compo_startjob, compo_initjob, compo_updatejob, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
|
2011-01-17 18:38:44 +00:00
|
|
|
/* operator poll callback */
|
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
|
|
|
}
|
|
|
|
|
2013-06-05 19:06:33 +00:00
|
|
|
/* operator poll callback */
|
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
|
|
|
}
|
|
|
|
|
2012-05-05 19:44:28 +00:00
|
|
|
void snode_dag_update(bContext *C, SpaceNode *snode)
|
2011-05-02 12:31:09 +00:00
|
|
|
{
|
2012-05-05 19:44:28 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
|
|
|
/* for groups, update all ID's using this */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->edittree != snode->nodetree) {
|
2018-11-30 15:22:01 +11:00
|
|
|
FOREACH_NODETREE_BEGIN (bmain, tntree, id) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ntreeHasTree(tntree, snode->edittree)) {
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(id, 0);
|
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;
|
2012-05-05 19:44:28 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(snode->id, 0);
|
2020-12-02 13:25:25 +01:00
|
|
|
DEG_id_tag_update(&snode->nodetree->id, 0);
|
2011-05-02 12:31:09 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
void snode_notify(bContext *C, SpaceNode *snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2014-11-24 17:18:56 +01:00
|
|
|
ID *id = snode->id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-24 17:18:56 +01:00
|
|
|
if (ED_node_is_shader(snode)) {
|
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
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else if (ED_node_is_compositor(snode)) {
|
2014-11-24 17:18:56 +01:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_NODES, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
else if (ED_node_is_texture(snode)) {
|
2014-11-24 17:18:56 +01:00
|
|
|
WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-12-02 13:25:25 +01:00
|
|
|
else if (ED_node_is_geometry(snode)) {
|
|
|
|
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, id);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool ED_node_is_compositor(struct 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
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool ED_node_is_shader(struct 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
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool ED_node_is_texture(struct 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
|
|
|
}
|
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
bool ED_node_is_geometry(struct 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
|
|
|
}
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
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);
|
|
|
|
ntreeUpdateTree(bmain, ma->nodetree);
|
|
|
|
}
|
|
|
|
else if (ELEM(GS(id->name), ID_WO, ID_LA)) {
|
|
|
|
/* Emission */
|
|
|
|
bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", ntreeType_Shader->idname);
|
|
|
|
bNode *shader, *output;
|
|
|
|
|
|
|
|
if (GS(id->name) == ID_WO) {
|
|
|
|
World *world = (World *)id;
|
|
|
|
world->nodetree = ntree;
|
|
|
|
|
|
|
|
shader = nodeAddStaticNode(NULL, ntree, SH_NODE_BACKGROUND);
|
|
|
|
output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_WORLD);
|
|
|
|
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 {
|
|
|
|
Light *light = (Light *)id;
|
|
|
|
light->nodetree = ntree;
|
|
|
|
|
|
|
|
shader = nodeAddStaticNode(NULL, ntree, SH_NODE_EMISSION);
|
|
|
|
output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_LIGHT);
|
|
|
|
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);
|
|
|
|
ntreeUpdateTree(bmain, ntree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2020-02-06 13:05:45 +01:00
|
|
|
else {
|
|
|
|
printf("ED_node_shader_default called on wrong ID type.\n");
|
|
|
|
return;
|
2011-11-08 11:38:16 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
2013-03-18 16:34:57 +00:00
|
|
|
void ED_node_composit_default(const bContext *C, struct 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
|
|
|
|
2019-08-22 16:00:59 +02:00
|
|
|
sce->nodetree = ntreeAddTree(NULL, "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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeSocket *fromsock = in->outputs.first;
|
|
|
|
bNodeSocket *tosock = 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
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), sce->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
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
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
tex->nodetree = ntreeAddTree(NULL, "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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeSocket *fromsock = in->outputs.first;
|
|
|
|
bNodeSocket *tosock = 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
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), tex->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
|
|
|
|
void snode_set_context(const bContext *C)
|
2009-10-07 22:05:30 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
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 */
|
2013-03-18 18:25:05 +00:00
|
|
|
if (!treetype || (treetype->poll && !treetype->poll(C, treetype))) {
|
2013-07-08 11:38:09 +00:00
|
|
|
/* invalid tree type, skip
|
|
|
|
* NB: 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 */
|
|
|
|
ntree = NULL;
|
|
|
|
id = NULL;
|
|
|
|
from = NULL;
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (!(snode->flag & SNODE_PIN) || ntree == NULL) {
|
2013-03-19 10:42:33 +00:00
|
|
|
if (treetype->get_from_context) {
|
|
|
|
/* reset and update from context */
|
|
|
|
ntree = NULL;
|
|
|
|
id = NULL;
|
|
|
|
from = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00: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 ||
|
2017-05-15 14:58:55 +10:00
|
|
|
(snode->treepath.last == NULL && 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
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void snode_update(SpaceNode *snode, bNode *node)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX this only updates nodes in the current node space tree path.
|
|
|
|
* The function supposedly should update any potential group node linking to changed tree,
|
|
|
|
* this really requires a working depsgraph ...
|
|
|
|
*/
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* update all edited group nodes */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeTreePath *path = snode->treepath.last;
|
2013-03-18 16:34:57 +00:00
|
|
|
if (path) {
|
|
|
|
bNodeTree *ngroup = path->nodetree;
|
2013-03-18 18:25:05 +00:00
|
|
|
for (path = path->prev; path; path = path->prev) {
|
|
|
|
nodeUpdateID(path->nodetree, (ID *)ngroup);
|
2013-03-18 16:34:57 +00:00
|
|
|
ngroup = path->nodetree;
|
2008-11-12 19:03:50 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node) {
|
2011-10-19 17:08:35 +00:00
|
|
|
nodeUpdate(snode->edittree, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-04-19 15:15:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 10:43:44 +02:00
|
|
|
void ED_node_set_active(Main *bmain, 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) {
|
2013-03-18 16:34:57 +00:00
|
|
|
do_update = 1;
|
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) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* when we select a material, active texture is cleared, for buttons */
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->id && ELEM(GS(node->id->name), ID_MA, ID_LA, ID_WO)) {
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeClearActiveID(ntree, ID_TE);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (was_output == 0) {
|
2016-02-05 01:39:42 +05:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
2010-12-20 11:08:29 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else if (do_update) {
|
2016-02-05 01:39:42 +05:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
/* if active texture changed, free glsl materials */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
|
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);
|
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
|
|
|
}
|
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;
|
|
|
|
}
|
2018-06-14 15:30:06 +02:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
2012-04-13 09:31:37 +00:00
|
|
|
WM_main_add_notifier(NC_IMAGE, NULL);
|
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) {
|
2016-02-05 01:39:42 +05:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-27 15:49:59 +02:00
|
|
|
/* addnode() 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;
|
2016-02-05 01:39:42 +05:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
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) {
|
2016-02-05 01:39:42 +05:00
|
|
|
ED_node_tag_update_nodetree(bmain, ntree, node);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
void ED_node_post_apply_transform(bContext *UNUSED(C), bNodeTree *UNUSED(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
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************** generic operator functions for nodes ***************** */
|
|
|
|
|
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? */
|
2014-01-16 21:43:22 +11:00
|
|
|
RNA_def_string(ot->srna, "node", NULL, 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;
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeSocket *sock = NULL;
|
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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ************************** Node generic ************** */
|
2009-09-15 11:35:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* is rct in visible part of node? */
|
2012-08-05 20:40:26 +00:00
|
|
|
static bNode *visible_node(SpaceNode *snode, const rctf *rct)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2020-12-18 10:35:08 +01:00
|
|
|
LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode->edittree->nodes) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (BLI_rctf_isect(&node->totr, rct, NULL)) {
|
2020-12-14 17:19:43 -06:00
|
|
|
return node;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
return NULL;
|
2009-09-15 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ********************** size widget operator ******************** */
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
typedef struct NodeSizeWidget {
|
|
|
|
float mxstart, mystart;
|
|
|
|
float oldlocx, oldlocy;
|
|
|
|
float oldoffsetx, oldoffsety;
|
|
|
|
float oldwidth, oldheight;
|
|
|
|
int directions;
|
|
|
|
} NodeSizeWidget;
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static void node_resize_init(
|
|
|
|
bContext *C, wmOperator *op, const wmEvent *UNUSED(event), bNode *node, int dir)
|
2008-12-24 10:33:10 +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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
op->customdata = nsw;
|
2021-01-19 16:43:08 -06:00
|
|
|
nsw->mxstart = snode->runtime->cursor[0] * UI_DPI_FAC;
|
|
|
|
nsw->mystart = snode->runtime->cursor[1] * UI_DPI_FAC;
|
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);
|
|
|
|
NodeSizeWidget *nsw = op->customdata;
|
|
|
|
|
|
|
|
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);
|
2012-08-01 19:11:17 +00:00
|
|
|
op->customdata = NULL;
|
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);
|
2012-08-01 19:11:17 +00:00
|
|
|
NodeSizeWidget *nsw = 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: {
|
|
|
|
float mx, my;
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &mx, &my);
|
2020-12-14 17:19:43 -06:00
|
|
|
float dx = (mx - nsw->mxstart) / UI_DPI_FAC;
|
|
|
|
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
|
|
|
}
|
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);
|
2013-03-18 16:34:57 +00:00
|
|
|
bNode *node = nodeGetActive(snode->edittree);
|
2012-08-01 19:11:17 +00:00
|
|
|
int dir;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node) {
|
2019-03-20 19:13:56 +01:00
|
|
|
float cursor[2];
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* convert mouse coordinates to v2d space */
|
2020-03-06 16:56:42 +01:00
|
|
|
UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]);
|
2019-03-20 19:13:56 +01:00
|
|
|
dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]);
|
2012-08-01 19:11:17 +00:00
|
|
|
if (dir != 0) {
|
|
|
|
node_resize_init(C, op, event, node, dir);
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
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
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ********************** 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) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sock->link == NULL) {
|
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 */
|
2021-02-11 01:16:17 -06:00
|
|
|
static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSocket *socket)
|
|
|
|
{
|
|
|
|
const float node_socket_height = node_socket_calculate_height(socket);
|
|
|
|
const rctf multi_socket_rect = {
|
2021-03-26 17:29:10 +01:00
|
|
|
.xmin = socket->locx - NODE_SOCKSIZE * 4.0f,
|
|
|
|
.xmax = socket->locx + NODE_SOCKSIZE * 2.0f,
|
|
|
|
/*.xmax = socket->locx + NODE_SOCKSIZE * 5.5f
|
|
|
|
* 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. */
|
|
|
|
.ymin = socket->locy - node_socket_height * 0.5 - NODE_SOCKSIZE,
|
|
|
|
.ymax = socket->locy + node_socket_height * 0.5 + NODE_SOCKSIZE,
|
2021-02-11 01:16:17 -06:00
|
|
|
};
|
|
|
|
if (BLI_rctf_isect_pt(&multi_socket_rect, cursor[0], cursor[1])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* type is SOCK_IN and/or SOCK_OUT */
|
2013-09-05 13:03:03 +00:00
|
|
|
int node_find_indicated_socket(
|
2021-03-26 17:29:10 +01:00
|
|
|
SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, const float cursor[2], int 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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
*nodep = NULL;
|
|
|
|
*sockp = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* check if we click in a socket */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
|
2017-03-08 23:10:31 +11:00
|
|
|
BLI_rctf_init_pt_radius(&rect, cursor, NODE_SOCKSIZE + 4);
|
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)) {
|
2021-02-11 01:16:17 -06:00
|
|
|
if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) {
|
|
|
|
if (cursor_isect_multi_input_socket(cursor, sock)) {
|
|
|
|
if (node == visible_node(snode, &rect)) {
|
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node == visible_node(snode, &rect)) {
|
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)) {
|
2012-08-23 18:25:45 +00:00
|
|
|
if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node == visible_node(snode, &rect)) {
|
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
return 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ****************** Duplicate *********************** */
|
|
|
|
|
|
|
|
static void node_duplicate_reparent_recursive(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)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
node_duplicate_reparent_recursive(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) {
|
|
|
|
nodeDetachNode(node->new_node);
|
|
|
|
nodeAttachNode(node->new_node, parent->new_node);
|
|
|
|
}
|
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");
|
2016-02-05 01:39:42 +05:00
|
|
|
bool do_tag_update = 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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *lastnode = ntree->nodes.last;
|
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2020-12-14 17:19:43 -06:00
|
|
|
BKE_node_copy_store_new_pointers(ntree, node, LIB_ID_COPY_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-05 16:23:34 +11:00
|
|
|
/* To ensure redraws or re-renders happen. */
|
2019-02-13 14:58:38 +01:00
|
|
|
ED_node_tag_update_id(snode->id);
|
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
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* copy links between selected nodes
|
|
|
|
* NB: this depends on correct node->new_node and sock->new_sock pointers from above copy!
|
|
|
|
*/
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeLink *lastlink = ntree->links.last;
|
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
2012-08-01 19:11:17 +00:00
|
|
|
/* This creates new links between copied nodes.
|
|
|
|
* If keep_inputs is set, also copies input links from unselected (when fromnode==NULL)!
|
|
|
|
*/
|
|
|
|
if (link->tonode && (link->tonode->flag & NODE_SELECT) &&
|
|
|
|
(keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT)))) {
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeLink *newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
2012-08-01 19:11:17 +00:00
|
|
|
newlink->flag = link->flag;
|
|
|
|
newlink->tonode = link->tonode->new_node;
|
|
|
|
newlink->tosock = link->tosock->new_sock;
|
|
|
|
if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) {
|
|
|
|
newlink->fromnode = link->fromnode->new_node;
|
|
|
|
newlink->fromsock = link->fromsock->new_sock;
|
|
|
|
}
|
|
|
|
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)) {
|
2012-08-01 19:11:17 +00:00
|
|
|
node_duplicate_reparent_recursive(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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *newnode = node->new_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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-09 15:16:44 +02:00
|
|
|
do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, newnode));
|
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
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
snode_notify(C, snode);
|
2016-02-05 01:39:42 +05:00
|
|
|
if (do_tag_update) {
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
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
|
|
|
{
|
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(
|
|
|
|
ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes");
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 02:48:11 +11:00
|
|
|
bool ED_node_select_check(ListBase *lb)
|
2012-08-01 13:28:19 +00:00
|
|
|
{
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, lb) {
|
2012-08-01 13:28:19 +00:00
|
|
|
if (node->flag & NODE_SELECT) {
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2012-08-01 13:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-08-01 13:28:19 +00:00
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2019-03-05 18:30:06 +11:00
|
|
|
void ED_node_select_all(ListBase *lb, int action)
|
|
|
|
{
|
|
|
|
if (action == SEL_TOGGLE) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ED_node_select_check(lb)) {
|
2019-03-05 18:30:06 +11:00
|
|
|
action = SEL_DESELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
else {
|
2019-03-05 18:30:06 +11:00
|
|
|
action = SEL_SELECT;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-03-05 18:30:06 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, lb) {
|
2019-03-05 18:30:06 +11:00
|
|
|
switch (action) {
|
|
|
|
case SEL_SELECT:
|
|
|
|
nodeSetSelected(node, true);
|
|
|
|
break;
|
|
|
|
case SEL_DESELECT:
|
|
|
|
nodeSetSelected(node, false);
|
|
|
|
break;
|
|
|
|
case SEL_INVERT:
|
|
|
|
nodeSetSelected(node, !(node->flag & SELECT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-07 14:03:34 +00:00
|
|
|
/* ******************************** */
|
2009-11-20 06:31:49 +00: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 */
|
2017-11-22 10:52:39 -02:00
|
|
|
static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(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;
|
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 (id == NULL) {
|
|
|
|
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
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
int node_render_changed_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
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. */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *node = NULL;
|
|
|
|
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) {
|
2017-11-22 10:52:39 -02:00
|
|
|
ViewLayer *view_layer = 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
|
|
|
|
2011-02-07 18:09:27 +00:00
|
|
|
/* to keep keypositions */
|
|
|
|
sce->r.scemode |= R_NO_FRAME_UPDATE;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
WM_operator_name_call(C, "RENDER_OT_render", WM_OP_INVOKE_DEFAULT, &op_ptr);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* ****************** Hide operator *********************** */
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
static int node_hide_toggle_exec(bContext *C, wmOperator *UNUSED(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) */
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL)) {
|
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
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(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) */
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL)) {
|
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);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int node_options_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
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) */
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL)) {
|
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);
|
|
|
|
|
2012-07-16 16:16:05 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_socket_toggle_exec(bContext *C, wmOperator *UNUSED(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) */
|
2019-03-26 21:16:47 +11:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL)) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2012-07-16 16:16:05 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Mute operator *********************** */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_mute_exec(bContext *C, wmOperator *UNUSED(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
|
|
|
bool do_tag_update = false;
|
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) {
|
2011-11-20 16:38:23 +00:00
|
|
|
/* Only allow muting of nodes having a mute func! */
|
2012-10-25 16:49:06 +00:00
|
|
|
if ((node->flag & SELECT) && node->typeinfo->update_internal_links) {
|
2012-02-27 17:38:16 +00:00
|
|
|
node->flag ^= NODE_MUTED;
|
|
|
|
snode_update(snode, node);
|
2018-06-09 15:16:44 +02:00
|
|
|
do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node));
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
do_tag_update |= ED_node_is_geometry(snode);
|
2020-07-22 19:13:12 +02:00
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
snode_notify(C, snode);
|
2016-02-05 01:39:42 +05:00
|
|
|
if (do_tag_update) {
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Delete operator ******************* */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_delete_exec(bContext *C, wmOperator *UNUSED(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
|
|
|
bool do_tag_update = false;
|
|
|
|
|
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) {
|
2018-06-09 15:16:44 +02:00
|
|
|
do_tag_update |= (do_tag_update || node_connected_to_output(bmain, 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
|
|
|
}
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-12-02 13:25:25 +01:00
|
|
|
do_tag_update |= ED_node_is_geometry(snode);
|
2020-07-22 19:13:12 +02:00
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
snode_notify(C, snode);
|
2016-02-05 01:39:42 +05:00
|
|
|
if (do_tag_update) {
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
}
|
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
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* ****************** Switch View ******************* */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_switch_view_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ****************** Delete with reconnect ******************* */
|
|
|
|
static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(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
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), snode->edittree);
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
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
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
/* ****************** File Output Add Socket ******************* */
|
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");
|
|
|
|
bNodeTree *ntree = NULL;
|
|
|
|
bNode *node = NULL;
|
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) {
|
|
|
|
node = 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
|
|
|
|
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
|
|
|
snode_notify(C, snode);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Multi File Output Remove Socket ******************* */
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator *UNUSED(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");
|
2013-04-24 16:59:56 +00:00
|
|
|
bNodeTree *ntree = NULL;
|
|
|
|
bNode *node = NULL;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-24 16:59:56 +00:00
|
|
|
if (ptr.data) {
|
|
|
|
node = 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
|
|
|
|
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
|
|
|
snode_notify(C, snode);
|
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
|
|
|
|
|
|
|
/* ****************** Multi File Output Move Socket ******************* */
|
|
|
|
|
|
|
|
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");
|
2013-04-24 16:59:56 +00:00
|
|
|
bNode *node = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ptr.data) {
|
2013-04-24 16:59:56 +00:00
|
|
|
node = 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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
NodeImageMultiFile *nimf = node->storage;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeSocket *sock = 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
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
snode_notify(C, snode);
|
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[] = {
|
2012-05-03 06:57:30 +00:00
|
|
|
{1, "UP", 0, "Up", ""}, {2, "DOWN", 0, "Down", ""}, {0, NULL, 0, NULL, NULL}};
|
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
|
|
|
|
|
|
|
/* ****************** Copy Node Color ******************* */
|
|
|
|
|
|
|
|
static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!ntree) {
|
2012-05-22 14:13:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *node = nodeGetActive(ntree);
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!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
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node_iter, &ntree->nodes) {
|
|
|
|
if (node_iter->flag & NODE_SELECT && node_iter != node) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node->flag & NODE_CUSTOM_COLOR) {
|
2020-12-14 17:19:43 -06:00
|
|
|
node_iter->flag |= NODE_CUSTOM_COLOR;
|
|
|
|
copy_v3_v3(node_iter->color, node->color);
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else {
|
2020-12-14 17:19:43 -06:00
|
|
|
node_iter->flag &= ~NODE_CUSTOM_COLOR;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
|
|
|
|
/* ****************** Copy to clipboard ******************* */
|
|
|
|
|
|
|
|
static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
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
|
|
|
|
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. */
|
2019-06-03 17:08:25 +02:00
|
|
|
bNode *new_node = BKE_node_copy_store_new_pointers(
|
2019-12-07 19:35:52 +01:00
|
|
|
NULL, node, LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_MAIN);
|
2012-08-06 08:25:24 +00:00
|
|
|
BKE_node_clipboard_add_node(new_node);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2012-08-03 10:18:52 +00:00
|
|
|
if (node->flag & SELECT) {
|
|
|
|
bNode *new_node = node->new_node;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-03 10:51:29 +00:00
|
|
|
/* ensure valid pointers */
|
2012-08-03 10:18:52 +00:00
|
|
|
if (new_node->parent) {
|
2019-01-15 23:24:20 +11:00
|
|
|
/* parent pointer must be redirected to new node or detached if parent is
|
|
|
|
* not copied */
|
2012-08-03 10:18:52 +00:00
|
|
|
if (new_node->parent->flag & NODE_SELECT) {
|
|
|
|
new_node->parent = new_node->parent->new_node;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nodeDetachNode(new_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* copy links between selected nodes
|
|
|
|
* NB: this depends on correct node->new_node and sock->new_sock pointers from above copy!
|
|
|
|
*/
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
2012-08-02 09:52:37 +00:00
|
|
|
/* This creates new links between copied nodes. */
|
|
|
|
if (link->tonode && (link->tonode->flag & NODE_SELECT) && link->fromnode &&
|
|
|
|
(link->fromnode->flag & NODE_SELECT)) {
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeLink *newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
2012-08-02 09:52:37 +00:00
|
|
|
newlink->flag = link->flag;
|
|
|
|
newlink->tonode = link->tonode->new_node;
|
|
|
|
newlink->tosock = link->tosock->new_sock;
|
|
|
|
newlink->fromnode = link->fromnode->new_node;
|
|
|
|
newlink->fromsock = link->fromsock->new_sock;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Paste from clipboard ******************* */
|
|
|
|
|
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) {
|
2017-06-18 05:13:32 +02:00
|
|
|
if (!node->typeinfo->poll_instance || !node->typeinfo->poll_instance(node, ntree)) {
|
2014-04-01 11:34:00 +11:00
|
|
|
all_nodes_valid = false;
|
2013-04-04 02:05:11 +00:00
|
|
|
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 */
|
|
|
|
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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
float center[2] = {0.0f, 0.0f};
|
|
|
|
int num_nodes = 0;
|
|
|
|
LISTBASE_FOREACH_INDEX (bNode *, node, clipboard_nodes_lb, num_nodes) {
|
2012-09-15 11:48:20 +00:00
|
|
|
center[0] += BLI_rctf_cent_x(&node->totr);
|
|
|
|
center[1] += 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
|
|
|
|
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) {
|
2019-06-03 17:08:25 +02:00
|
|
|
bNode *new_node = BKE_node_copy_store_new_pointers(ntree, node, LIB_ID_COPY_DEFAULT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* pasted nodes are selected */
|
2014-04-01 11:34:00 +11:00
|
|
|
nodeSetSelected(new_node, true);
|
2012-08-03 10:18:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-03 10:18:52 +00:00
|
|
|
/* reparent copied nodes */
|
2020-12-14 17:19:43 -06:00
|
|
|
LISTBASE_FOREACH (bNode *, node, clipboard_nodes_lb) {
|
2012-08-03 10:18:52 +00:00
|
|
|
bNode *new_node = node->new_node;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (new_node->parent) {
|
2012-08-03 10:18:52 +00:00
|
|
|
new_node->parent = new_node->parent->new_node;
|
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) {
|
2012-08-02 09:52:37 +00:00
|
|
|
nodeAddLink(ntree,
|
|
|
|
link->fromnode->new_node,
|
|
|
|
link->fromsock->new_sock,
|
|
|
|
link->tonode->new_node,
|
|
|
|
link->tosock->new_sock);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-04 13:32:33 +01:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
ntreeUpdateTree(bmain, snode->edittree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
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
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/********************** 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
|
|
|
}
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
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-01-10 13:24:37 -06:00
|
|
|
const eNodeSocketInOut in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
ListBase *sockets = (in_out == SOCK_IN) ? &ntree->inputs : &ntree->outputs;
|
|
|
|
|
|
|
|
const char *default_name = (in_out == SOCK_IN) ? "Input" : "Output";
|
|
|
|
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! */
|
|
|
|
/*nodeSocketCopyValue(sock, &ntree_ptr, active_sock, &ntree_ptr);*/
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* XXX TODO define default socket type for a tree! */
|
|
|
|
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
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), ntree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-16 02:29:22 +02:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 18:27:28 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/********************** Remove interface socket operator *********************/
|
|
|
|
|
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-01-10 13:24:37 -06:00
|
|
|
const eNodeSocketInOut in_out = 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);
|
|
|
|
if (iosock == NULL) {
|
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
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), ntree);
|
2013-03-18 18:27:28 +00:00
|
|
|
|
2019-04-16 02:29:22 +02:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
2013-03-18 18:27:28 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/********************** Move interface socket operator *********************/
|
|
|
|
|
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", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
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-01-10 13:24:37 -06:00
|
|
|
const eNodeSocketInOut in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
ListBase *sockets = in_out == SOCK_IN ? &ntree->inputs : &ntree->outputs;
|
|
|
|
|
|
|
|
bNodeSocket *iosock = ntree_get_active_interface_socket(sockets);
|
|
|
|
|
|
|
|
if (iosock == NULL) {
|
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
|
|
|
|
2019-05-27 18:31:02 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_GROUP;
|
2013-05-07 15:28:42 +00:00
|
|
|
ntreeUpdateTree(CTX_data_main(C), ntree);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-16 02:29:22 +02:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 18:27:28 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ********************** 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)) {
|
2012-11-03 14:32:26 +00:00
|
|
|
return 0;
|
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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNode *node = 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) {
|
2012-11-03 14:32:26 +00:00
|
|
|
NodeShaderScript *nss = node->storage;
|
|
|
|
|
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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
Text *text = CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data;
|
2019-03-26 21:16:47 +11:00
|
|
|
if (text) {
|
2012-11-03 14:32:26 +00:00
|
|
|
return 1;
|
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 */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 */
|
2020-12-14 17:19:43 -06:00
|
|
|
bNodeTree *ntree_base = NULL;
|
|
|
|
bNode *node = NULL;
|
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;
|
2013-04-24 16:59:56 +00:00
|
|
|
node = nodeptr.data;
|
|
|
|
}
|
|
|
|
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 */
|
2013-03-18 16:34:57 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:47:30 +00:00
|
|
|
/* ********************** Viewer border ******************/
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-03-06 16:56:42 +01: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");
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &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;
|
|
|
|
}
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
static int clear_viewer_border_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *btree = snode->nodetree;
|
|
|
|
|
|
|
|
btree->flag &= ~NTREE_VIEWER_BORDER;
|
|
|
|
snode_notify(C, snode);
|
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* ****************** Cryptomatte Add Socket ******************* */
|
|
|
|
|
|
|
|
static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
bNodeTree *ntree = NULL;
|
|
|
|
bNode *node = NULL;
|
|
|
|
|
|
|
|
if (ptr.data) {
|
|
|
|
node = 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);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Cryptomatte Remove Socket ******************* */
|
|
|
|
|
|
|
|
static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
bNodeTree *ntree = NULL;
|
|
|
|
bNode *node = NULL;
|
|
|
|
|
|
|
|
if (ptr.data) {
|
|
|
|
node = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|