2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-24 10:33:10 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2009-01-01 16:27:02 +00:00
|
|
|
* Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory
|
2008-12-24 10:33:10 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_node/node_edit.c
|
|
|
|
* \ingroup spnode
|
|
|
|
*/
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_node_types.h"
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_context.h"
|
2011-05-02 12:31:09 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_image.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_node.h"
|
|
|
|
#include "BKE_material.h"
|
2009-08-16 19:50:00 +00:00
|
|
|
#include "BKE_paint.h"
|
2011-11-08 11:38:16 +00:00
|
|
|
#include "BKE_scene.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_texture.h"
|
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2012-08-01 20:39:14 +00:00
|
|
|
#include "ED_node.h" /* own include */
|
2009-01-12 00:14:37 +00:00
|
|
|
#include "ED_screen.h"
|
2010-07-04 19:58:52 +00:00
|
|
|
#include "ED_render.h"
|
2009-01-12 00:14:37 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2012-08-01 20:39:14 +00:00
|
|
|
#include "node_intern.h" /* own include */
|
2009-01-01 16:27:02 +00:00
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* ***************** composite job manager ********************** */
|
|
|
|
|
|
|
|
typedef struct CompoJob {
|
|
|
|
Scene *scene;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNodeTree *localtree;
|
|
|
|
short *stop;
|
|
|
|
short *do_update;
|
2010-05-27 08:22:16 +00:00
|
|
|
float *progress;
|
2009-01-27 17:12:40 +00:00
|
|
|
} CompoJob;
|
|
|
|
|
|
|
|
/* 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;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
return *(cj->stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called by compo, wmJob sends notifier */
|
2010-10-15 04:27:09 +00:00
|
|
|
static void compo_redrawjob(void *cjv, char *UNUSED(str))
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-05-19 13:28:19 +00: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) {
|
2009-01-27 17:12:40 +00:00
|
|
|
ntreeLocalMerge(cj->localtree, cj->ntree);
|
|
|
|
}
|
|
|
|
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;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->localtree = ntreeLocalize(cj->ntree);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called before redraw notifiers, it moves finished previews over */
|
|
|
|
static void compo_updatejob(void *cjv)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
ntreeLocalSync(cj->localtree, cj->ntree);
|
|
|
|
}
|
|
|
|
|
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;
|
2010-05-27 08:22:16 +00:00
|
|
|
|
|
|
|
*(cj->progress) = progress;
|
|
|
|
}
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
/* only this runs inside thread */
|
2010-05-27 08:22:16 +00:00
|
|
|
static void compo_startjob(void *cjv, 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;
|
2009-09-30 18:18:32 +00:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
if (cj->scene->use_nodes == FALSE)
|
2009-01-27 17:12:40 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->stop = stop;
|
|
|
|
cj->do_update = do_update;
|
|
|
|
cj->progress = progress;
|
|
|
|
|
|
|
|
ntree->test_break = compo_breakjob;
|
|
|
|
ntree->tbh = cj;
|
|
|
|
ntree->stats_draw = compo_redrawjob;
|
|
|
|
ntree->sdh = cj;
|
|
|
|
ntree->progress = compo_progressjob;
|
|
|
|
ntree->prh = cj;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
// XXX BIF_store_spare();
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntreeCompositExecTree(ntree, &cj->scene->r, 0, 1); /* 1 is do_previews */
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* \param sa_owner is the owner of the job,
|
|
|
|
* 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
|
|
|
{
|
2009-09-30 18:18:32 +00:00
|
|
|
wmJob *steve;
|
|
|
|
CompoJob *cj;
|
|
|
|
|
2012-08-03 20:56:04 +00:00
|
|
|
steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene_owner, "Compositing", WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS);
|
2012-06-21 13:19:19 +00:00
|
|
|
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 */
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->scene = CTX_data_scene(C);
|
2012-08-03 20:56:04 +00:00
|
|
|
cj->ntree = nodetree;
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* setup job */
|
|
|
|
WM_jobs_customdata(steve, cj, compo_freejob);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_jobs_timer(steve, 0.1, NC_SCENE, NC_SCENE | ND_COMPO_RESULT);
|
2010-04-15 10:28:32 +00:00
|
|
|
WM_jobs_callbacks(steve, compo_startjob, compo_initjob, compo_updatejob, NULL);
|
2012-08-03 20:56:04 +00:00
|
|
|
|
2009-06-07 11:12:35 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), steve);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
|
2011-01-17 18:38:44 +00:00
|
|
|
/* operator poll callback */
|
2012-08-01 19:11:17 +00:00
|
|
|
int 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);
|
|
|
|
if (snode->treetype == NTREE_COMPOSIT)
|
2011-01-17 18:38:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
/* also checks for edited groups */
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *editnode_get_active(bNodeTree *ntree)
|
2009-02-06 18:38:10 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* check for edited group */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(node))
|
2009-02-06 18:38:10 +00:00
|
|
|
break;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node)
|
2009-02-06 18:38:10 +00:00
|
|
|
return nodeGetActive((bNodeTree *)node->id);
|
|
|
|
else
|
|
|
|
return nodeGetActive(ntree);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-05-05 19:44:28 +00:00
|
|
|
static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
if (ntree == lookup)
|
|
|
|
return 1;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-05-05 19:44:28 +00:00
|
|
|
if (node->type == NODE_GROUP && node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
if (has_nodetree((bNodeTree *)node->id, lookup))
|
2012-05-05 19:44:28 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snode_dag_update_group(void *calldata, ID *owner_id, bNodeTree *ntree)
|
|
|
|
{
|
|
|
|
if (has_nodetree(ntree, calldata))
|
|
|
|
DAG_id_tag_update(owner_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
bNodeTreeType *tti = ntreeGetType(snode->edittree->type);
|
2012-05-05 19:44:28 +00:00
|
|
|
tti->foreach_nodetree(bmain, snode->edittree, snode_dag_update_group);
|
|
|
|
}
|
|
|
|
|
2011-05-02 12:31:09 +00:00
|
|
|
DAG_id_tag_update(snode->id, 0);
|
|
|
|
}
|
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
void snode_notify(bContext *C, SpaceNode *snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL);
|
2011-01-03 14:36:44 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype == NTREE_SHADER)
|
|
|
|
WM_event_add_notifier(C, NC_MATERIAL | ND_NODES, snode->id);
|
|
|
|
else if (snode->treetype == NTREE_COMPOSIT)
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_NODES, snode->id);
|
|
|
|
else if (snode->treetype == NTREE_TEXTURE)
|
|
|
|
WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, snode->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
bNode *node_tree_get_editgroup(bNodeTree *nodetree)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *gnode;
|
|
|
|
|
|
|
|
/* get the groupnode */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (gnode = nodetree->nodes.first; gnode; gnode = gnode->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(gnode))
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
|
|
|
return gnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
2011-11-08 11:38:16 +00:00
|
|
|
void ED_node_shader_default(Scene *scene, ID *id)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
2011-11-08 11:38:16 +00:00
|
|
|
bNodeSocket *fromsock, *tosock, *sock;
|
2011-11-02 18:55:32 +00:00
|
|
|
bNodeTree *ntree;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2011-11-02 18:55:32 +00:00
|
|
|
int output_type, shader_type;
|
2011-11-08 11:38:16 +00:00
|
|
|
float color[3], strength = 1.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree = ntreeAddTree("Shader Nodetree", NTREE_SHADER, 0);
|
2011-11-02 18:55:32 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (GS(id->name)) {
|
2011-11-02 18:55:32 +00:00
|
|
|
case ID_MA: {
|
2012-06-21 13:19:19 +00:00
|
|
|
Material *ma = (Material *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
ma->nodetree = ntree;
|
|
|
|
|
2012-05-05 14:33:36 +00:00
|
|
|
if (BKE_scene_use_new_shading_nodes(scene)) {
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_MATERIAL;
|
|
|
|
shader_type = SH_NODE_BSDF_DIFFUSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
output_type = SH_NODE_OUTPUT;
|
|
|
|
shader_type = SH_NODE_MATERIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_v3_v3(color, &ma->r);
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 0.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_WO: {
|
2012-06-21 13:19:19 +00:00
|
|
|
World *wo = (World *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
wo->nodetree = ntree;
|
|
|
|
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_WORLD;
|
|
|
|
shader_type = SH_NODE_BACKGROUND;
|
|
|
|
|
|
|
|
copy_v3_v3(color, &wo->horr);
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 1.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_LA: {
|
2012-06-21 13:19:19 +00:00
|
|
|
Lamp *la = (Lamp *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
la->nodetree = ntree;
|
|
|
|
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_LAMP;
|
|
|
|
shader_type = SH_NODE_EMISSION;
|
|
|
|
|
|
|
|
copy_v3_v3(color, &la->r);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA)
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 100.0f;
|
2011-11-08 11:38:16 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 1.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printf("ED_node_shader_default called on wrong ID type.\n");
|
|
|
|
return;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntemp.type = output_type;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(ntree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntemp.type = shader_type;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(ntree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 300.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
nodeSetActive(ntree, in);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* only a link from color to color */
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2011-11-02 18:55:32 +00:00
|
|
|
nodeAddLink(ntree, in, fromsock, out, tosock);
|
2011-11-08 11:38:16 +00:00
|
|
|
|
|
|
|
/* default values */
|
2012-05-05 14:33:36 +00:00
|
|
|
if (BKE_scene_use_new_shading_nodes(scene)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = in->inputs.first;
|
|
|
|
copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, color);
|
2011-11-08 11:38:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (strength != 0.0f) {
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = in->inputs.last;
|
|
|
|
((bNodeSocketValueFloat *)sock->default_value)->value = strength;
|
2011-11-08 11:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
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 */
|
2009-08-19 00:55:30 +00:00
|
|
|
void ED_node_composit_default(Scene *sce)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
|
|
|
bNodeSocket *fromsock, *tosock;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* but lets check it anyway */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sce->nodetree) {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG)
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in composite initialize\n");
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
sce->nodetree = ntreeAddTree("Compositing Nodetree", NTREE_COMPOSIT, 0);
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
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;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = CMP_NODE_COMPOSITE;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(sce->nodetree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 400.0f;
|
|
|
|
out->id = &sce->id;
|
2010-12-01 08:49:08 +00:00
|
|
|
id_us_plus(out->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = CMP_NODE_R_LAYERS;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(sce->nodetree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 400.0f;
|
|
|
|
in->id = &sce->id;
|
2010-12-01 08:49:08 +00:00
|
|
|
id_us_plus(in->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(sce->nodetree, in);
|
|
|
|
|
|
|
|
/* links from color to color */
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(sce->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-01-12 01:02:52 +00:00
|
|
|
// XXX ntreeCompositForceHidden(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 */
|
2009-08-19 00:55:30 +00:00
|
|
|
void ED_node_texture_default(Tex *tx)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
|
|
|
bNodeSocket *fromsock, *tosock;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* but lets check it anyway */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tx->nodetree) {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG)
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in texture initialize\n");
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
tx->nodetree = ntreeAddTree("Texture Nodetree", NTREE_TEXTURE, 0);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = TEX_NODE_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(tx->nodetree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = TEX_NODE_CHECKER;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(tx->nodetree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(tx->nodetree, in);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeAddLink(tx->nodetree, in, fromsock, out, tosock);
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(tx->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-01-08 19:12:42 +00:00
|
|
|
/* id is supposed to contain a node tree */
|
2009-10-07 22:05:30 +00:00
|
|
|
void node_tree_from_ID(ID *id, bNodeTree **ntree, bNodeTree **edittree, int *treetype)
|
|
|
|
{
|
2011-09-05 21:01:50 +00:00
|
|
|
if (id) {
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *node = NULL;
|
|
|
|
short idtype = GS(id->name);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (idtype == ID_NT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = (bNodeTree *)id;
|
|
|
|
if (treetype) *treetype = (*ntree)->type;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_MA) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Material *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_LA) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Lamp *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_WO) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((World *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_SCE) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Scene *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_COMPOSIT;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_TE) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Tex *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_TEXTURE;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
if (treetype) *treetype = 0;
|
2011-09-05 21:01:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find editable group */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (edittree) {
|
|
|
|
if (*ntree)
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = (*ntree)->nodes.first; node; node = node->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(node))
|
2011-09-05 21:01:50 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node && node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
*edittree = (bNodeTree *)node->id;
|
2011-09-05 21:01:50 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
*edittree = *ntree;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
2011-01-08 19:12:42 +00:00
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = NULL;
|
|
|
|
*edittree = NULL;
|
|
|
|
if (treetype) *treetype = 0;
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
|
|
|
|
void snode_set_context(SpaceNode *snode, Scene *scene)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Object *ob = OBACT;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->id = snode->from = NULL;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype == NTREE_SHADER) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* need active object, or we allow pinning... */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (snode->shaderfrom == SNODE_SHADER_OBJECT) {
|
|
|
|
if (ob) {
|
|
|
|
if (ob->type == OB_LAMP) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = &ob->id;
|
|
|
|
snode->id = ob->data;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
Material *ma = give_current_material(ob, ob->actcol);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = &ob->id;
|
|
|
|
snode->id = &ma->id;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* SNODE_SHADER_WORLD */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (scene->world) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = NULL;
|
|
|
|
snode->id = &scene->world->id;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->treetype == NTREE_COMPOSIT) {
|
|
|
|
snode->id = &scene->id;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-07 13:30:16 +00:00
|
|
|
/* update output sockets based on available layers */
|
|
|
|
ntreeCompositForceHidden(scene->nodetree, scene);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->treetype == NTREE_TEXTURE) {
|
|
|
|
Tex *tx = NULL;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->texfrom == SNODE_TEX_OBJECT) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob) {
|
2012-06-21 13:19:19 +00:00
|
|
|
tx = give_current_object_texture(ob);
|
2009-08-19 00:55:30 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->type == OB_LAMP)
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)ob->data;
|
2009-08-19 00:55:30 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)give_current_material(ob, ob->actcol);
|
2009-08-19 00:55:30 +00:00
|
|
|
|
|
|
|
/* from is not set fully for material nodes, should be ID + Node then */
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->id = &tx->id;
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->texfrom == SNODE_TEX_WORLD) {
|
|
|
|
tx = give_current_world_texture(scene->world);
|
|
|
|
snode->from = (ID *)scene->world;
|
|
|
|
snode->id = &tx->id;
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
struct Brush *brush = NULL;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob && (ob->mode & OB_MODE_SCULPT))
|
2012-06-21 13:19:19 +00:00
|
|
|
brush = paint_brush(&scene->toolsettings->sculpt->paint);
|
2009-08-17 04:40:59 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
brush = paint_brush(&scene->toolsettings->imapaint.paint);
|
2009-08-17 04:40:59 +00:00
|
|
|
|
2010-03-17 22:54:55 +00:00
|
|
|
if (brush) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)brush;
|
|
|
|
tx = give_current_brush_texture(brush);
|
|
|
|
snode->id = &tx->id;
|
2010-03-17 22:54:55 +00:00
|
|
|
}
|
2008-11-12 19:03:50 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
else {
|
|
|
|
if (snode->nodetree && snode->nodetree->type == snode->treetype)
|
|
|
|
snode->id = &snode->nodetree->id;
|
|
|
|
else
|
|
|
|
snode->id = NULL;
|
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
node_tree_from_ID(snode->id, &snode->nodetree, &snode->edittree, NULL);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
void snode_update(SpaceNode *snode, bNode *node)
|
2011-04-19 15:15:50 +00:00
|
|
|
{
|
|
|
|
bNode *gnode;
|
|
|
|
|
|
|
|
if (node)
|
2011-10-19 17:08:35 +00:00
|
|
|
nodeUpdate(snode->edittree, node);
|
2011-04-19 15:15:50 +00:00
|
|
|
|
|
|
|
/* if inside group, tag entire group */
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode)
|
2011-10-19 17:08:35 +00:00
|
|
|
nodeUpdateID(snode->nodetree, gnode->id);
|
2011-04-19 15:15:50 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 18:27:48 +00:00
|
|
|
void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2011-11-08 13:07:16 +00:00
|
|
|
int was_active_texture = (node->flag & NODE_ACTIVE_TEXTURE);
|
|
|
|
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeSetActive(ntree, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type != NODE_GROUP) {
|
|
|
|
int was_output = (node->flag & NODE_DO_OUTPUT);
|
2010-12-20 11:08:29 +00: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 */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id && ELEM3(GS(node->id->name), ID_MA, ID_LA, ID_WO))
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeClearActiveID(ntree, ID_TE);
|
2010-12-20 11:08:29 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type == SH_NODE_OUTPUT) {
|
2010-12-20 11:08:29 +00:00
|
|
|
bNode *tnode;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (tnode->type == SH_NODE_OUTPUT)
|
2010-12-20 11:08:29 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (was_output == 0)
|
2011-08-12 18:27:48 +00:00
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
2010-12-20 11:08:29 +00:00
|
|
|
}
|
2010-01-29 16:32:06 +00: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) {
|
2011-11-08 13:07:16 +00:00
|
|
|
Material *ma;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (ma = bmain->mat.first; ma; ma = ma->id.next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
|
2011-11-08 13:07:16 +00:00
|
|
|
GPU_material_free(ma);
|
2012-04-13 09:31:37 +00:00
|
|
|
|
|
|
|
WM_main_add_notifier(NC_IMAGE, NULL);
|
2011-11-08 13:07:16 +00: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)) {
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *tnode;
|
2010-12-20 11:08:29 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
|
2008-12-24 10:33:10 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (was_output == 0)
|
2011-08-12 18:27:48 +00:00
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* addnode() doesnt link this yet... */
|
2012-06-21 13:19:19 +00:00
|
|
|
node->id = (ID *)BKE_image_verify_viewer(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_R_LAYERS) {
|
2011-08-12 18:27:48 +00:00
|
|
|
Scene *scene;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (scene = bmain->scene.first; scene; scene = scene->id.next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (scene->nodetree && scene->use_nodes && has_nodetree(scene->nodetree, ntree)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->id == NULL || node->id == (ID *)scene) {
|
|
|
|
scene->r.actlay = node->custom1;
|
2011-08-12 18:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2011-08-21 13:25:19 +00:00
|
|
|
bNode *tnode;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (tnode->type == CMP_NODE_COMPOSITE)
|
2011-08-21 13:25:19 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
|
|
|
}
|
2010-12-19 15:03:27 +00: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
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
; // XXX BIF_preview_changed(-1);
|
2008-12-24 10:33:10 +00:00
|
|
|
// 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 */
|
2012-05-22 14:13:33 +00: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 */
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static int edit_node_poll(bContext *C)
|
|
|
|
{
|
|
|
|
return ED_operator_node_active(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void edit_node_properties(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* XXX could node be a context pointer? */
|
2012-01-11 08:51:06 +00:00
|
|
|
RNA_def_string(ot->srna, "node", "", 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);
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Side", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-09-05 21:01:50 +00:00
|
|
|
if (!node)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
RNA_string_set(op->ptr, "node", node->name);
|
|
|
|
}
|
|
|
|
|
2012-01-11 16:32:12 +00: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);
|
|
|
|
|
2012-01-11 16:32:12 +00: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);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **rnode, bNodeSocket **rsock, int *rin_out)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "node", nodename);
|
|
|
|
node = nodeFindNodebyName(ntree, nodename);
|
|
|
|
|
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
|
|
|
|
sockindex = RNA_int_get(op->ptr, "socket");
|
|
|
|
switch (in_out) {
|
2012-06-21 13:19:19 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
if (rnode)
|
|
|
|
*rnode = node;
|
|
|
|
if (rsock)
|
|
|
|
*rsock = sock;
|
|
|
|
if (rin_out)
|
|
|
|
*rin_out = in_out;
|
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
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
for (node = snode->edittree->nodes.last; node; node = node->prev) {
|
|
|
|
if (BLI_rctf_isect(&node->totr, rct, NULL))
|
|
|
|
break;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
return node;
|
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;
|
|
|
|
float oldminiwidth;
|
|
|
|
int directions;
|
|
|
|
} NodeSizeWidget;
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static void node_resize_init(bContext *C, wmOperator *op, 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);
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data");
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
op->customdata = nsw;
|
|
|
|
nsw->mxstart = snode->mx;
|
|
|
|
nsw->mystart = snode->my;
|
2008-12-24 10:33:10 +00: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->oldminiwidth = node->miniwidth;
|
|
|
|
nsw->directions = dir;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
WM_cursor_modal(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
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static void node_resize_exit(bContext *C, wmOperator *op, int UNUSED(cancel))
|
2011-01-31 14:42:55 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
WM_cursor_restore(CTX_wm_window(C));
|
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
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static int node_resize_modal(bContext *C, wmOperator *op, 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);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *node = editnode_get_active(snode->edittree);
|
|
|
|
NodeSizeWidget *nsw = op->customdata;
|
|
|
|
float mx, my, dx, dy;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE:
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my);
|
|
|
|
dx = mx - nsw->mxstart;
|
|
|
|
dy = my - nsw->mystart;
|
|
|
|
|
|
|
|
if (node) {
|
|
|
|
if (node->flag & NODE_HIDDEN) {
|
|
|
|
float widthmin = 0.0f;
|
|
|
|
float widthmax = 100.0f;
|
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
|
|
|
node->miniwidth = nsw->oldminiwidth + dx;
|
|
|
|
CLAMP(node->miniwidth, widthmin, widthmax);
|
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
|
|
|
float locmax = nsw->oldlocx + nsw->oldminiwidth;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->locx = nsw->oldlocx + dx;
|
|
|
|
CLAMP(node->locx, locmax - widthmax, locmax - widthmin);
|
|
|
|
node->miniwidth = locmax - node->locx;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-08-01 19:11:17 +00:00
|
|
|
float widthmin = UI_DPI_FAC * node->typeinfo->minwidth;
|
|
|
|
float widthmax = UI_DPI_FAC * node->typeinfo->maxwidth;
|
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
|
|
|
node->width = nsw->oldwidth + dx;
|
|
|
|
CLAMP(node->width, widthmin, widthmax);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
|
|
|
float locmax = nsw->oldlocx + nsw->oldwidth;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->locx = nsw->oldlocx + dx;
|
|
|
|
CLAMP(node->locx, locmax - widthmax, locmax - widthmin);
|
|
|
|
node->width = locmax - node->locx;
|
2008-12-24 10:33:10 +00: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;
|
2012-05-15 12:40:43 +00: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
|
|
|
}
|
2011-07-29 07:14:03 +00: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
|
|
|
}
|
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
break;
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE:
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node_resize_exit(C, op, 0);
|
|
|
|
ED_node_post_apply_transform(C, snode->edittree);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static int node_resize_invoke(bContext *C, wmOperator *op, 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);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *node = editnode_get_active(snode->edittree);
|
|
|
|
int dir;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (node) {
|
|
|
|
/* convert mouse coordinates to v2d space */
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
|
|
|
|
&snode->mx, &snode->my);
|
|
|
|
dir = node->typeinfo->resize_area_func(node, snode->mx, snode->my);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
static int node_resize_cancel(bContext *C, wmOperator *op)
|
2011-06-06 11:04:54 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
node_resize_exit(C, op, 1);
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
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";
|
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;
|
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-03-09 10:16:41 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* ********************** hidden sockets ******************** */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
int node_has_hidden_sockets(bNode *node)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
bNodeSocket *sock;
|
2010-01-04 04:26:28 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next)
|
|
|
|
if (sock->flag & SOCK_HIDDEN)
|
|
|
|
return 1;
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next)
|
|
|
|
if (sock->flag & SOCK_HIDDEN)
|
|
|
|
return 1;
|
2012-06-01 12:38:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bNodeSocket *sock;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (set == 0) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next)
|
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next)
|
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* hide unused sockets */
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (sock->link == NULL)
|
|
|
|
sock->flag |= SOCK_HIDDEN;
|
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (nodeCountSocketLinks(snode->edittree, sock) == 0)
|
|
|
|
sock->flag |= SOCK_HIDDEN;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* return 0, nothing done */
|
|
|
|
static int UNUSED_FUNCTION(node_mouse_groupheader) (SpaceNode * snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *gnode;
|
|
|
|
float mx = 0, my = 0;
|
|
|
|
// XXX int mval[2];
|
|
|
|
|
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
|
|
|
if (gnode == NULL) return 0;
|
|
|
|
|
|
|
|
// XXX getmouseco_areawin(mval);
|
|
|
|
// XXX areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
|
|
|
|
|
|
|
|
/* click in header or outside? */
|
|
|
|
if (BLI_in_rctf(&gnode->totr, mx, my) == 0) {
|
|
|
|
rctf rect = gnode->totr;
|
|
|
|
|
|
|
|
rect.ymax += NODE_DY;
|
|
|
|
if (BLI_in_rctf(&rect, mx, my) == 0)
|
|
|
|
snode_make_group_editable(snode, NULL); /* toggles, so exits editmode */
|
|
|
|
// else
|
|
|
|
// XXX transform_nodes(snode->nodetree, 'g', "Move group");
|
|
|
|
|
|
|
|
return 1;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-02-07 14:03:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* checks snode->mouse position, and returns found node/socket */
|
|
|
|
/* type is SOCK_IN and/or SOCK_OUT */
|
|
|
|
int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, int in_out)
|
2009-02-07 14:03:34 +00:00
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
rctf rect;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
*nodep = NULL;
|
|
|
|
*sockp = NULL;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* check if we click in a socket */
|
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
rect.xmin = snode->mx - (NODE_SOCKSIZE + 4);
|
|
|
|
rect.ymin = snode->my - (NODE_SOCKSIZE + 4);
|
|
|
|
rect.xmax = snode->mx + (NODE_SOCKSIZE + 4);
|
|
|
|
rect.ymax = snode->my + (NODE_SOCKSIZE + 4);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
if (in_out & SOCK_IN) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
if (node == visible_node(snode, &rect)) {
|
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (in_out & SOCK_OUT) {
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
if (node == visible_node(snode, &rect)) {
|
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* check group sockets
|
|
|
|
* NB: using ngroup->outputs as input sockets and vice versa here!
|
|
|
|
*/
|
|
|
|
if (in_out & SOCK_IN) {
|
|
|
|
for (sock = snode->edittree->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
*nodep = NULL; /* NULL node pointer indicates group socket */
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (in_out & SOCK_OUT) {
|
|
|
|
for (sock = snode->edittree->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
*nodep = NULL; /* NULL node pointer indicates group socket */
|
|
|
|
*sockp = sock;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
node->flag |= NODE_TEST;
|
2009-02-07 14:03:34 +00: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) {
|
|
|
|
if (!(parent->flag & NODE_TEST))
|
|
|
|
node_duplicate_reparent_recursive(parent);
|
|
|
|
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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2012-08-01 19:11:17 +00:00
|
|
|
bNode *node, *newnode, *lastnode;
|
|
|
|
bNodeLink *link, *newlink, *lastlink;
|
|
|
|
int keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
|
2012-02-27 17:38:16 +00:00
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
lastnode = ntree->nodes.last;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-08-01 19:11:17 +00:00
|
|
|
newnode = nodeCopyNode(ntree, node);
|
|
|
|
|
|
|
|
if (newnode->id) {
|
|
|
|
/* simple id user adjustment, node internal functions don't touch this
|
|
|
|
* but operators and readfile.c do. */
|
|
|
|
id_us_plus(newnode->id);
|
|
|
|
/* to ensure redraws or rerenders happen */
|
|
|
|
ED_node_changed_update(snode->id, newnode);
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2011-07-22 16:39:06 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
/* make sure we don't copy new nodes again! */
|
|
|
|
if (node == lastnode)
|
|
|
|
break;
|
2011-07-22 16:39:06 +00: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!
|
|
|
|
*/
|
|
|
|
lastlink = ntree->links.last;
|
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
/* 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))))
|
|
|
|
{
|
|
|
|
newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
|
|
|
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
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
BLI_addtail(&ntree->links, newlink);
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
/* make sure we don't copy new links again! */
|
|
|
|
if (link == lastlink)
|
|
|
|
break;
|
2012-03-08 12:04:06 +00:00
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* clear flags for recursive depth-first iteration */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
|
|
|
node->flag &= ~NODE_TEST;
|
|
|
|
/* reparent copied nodes */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if ((node->flag & SELECT) && !(node->flag & NODE_TEST))
|
|
|
|
node_duplicate_reparent_recursive(node);
|
|
|
|
|
|
|
|
/* only has to check old nodes */
|
|
|
|
if (node == lastnode)
|
|
|
|
break;
|
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* deselect old nodes, select the copies instead */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
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 */
|
|
|
|
newnode = node->new_node;
|
|
|
|
|
|
|
|
node_deselect(node);
|
|
|
|
node->flag &= ~NODE_ACTIVE;
|
|
|
|
node_select(newnode);
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
/* make sure we don't copy new nodes again! */
|
|
|
|
if (node == lastnode)
|
|
|
|
break;
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
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";
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_duplicate_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-07-22 15:28:50 +00: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
|
|
|
}
|
|
|
|
|
2012-08-01 13:28:19 +00:00
|
|
|
int ED_node_select_check(ListBase *lb)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
for (node = lb->first; node; node = node->next) {
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
|
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
|
|
|
|
2011-01-17 18:38:44 +00:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
/* goes over all scenes, reads render layers */
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_read_renderlayers_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);
|
|
|
|
Scene *curscene = CTX_data_scene(C), *scene;
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* first tag scenes unread */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (scene = bmain->scene.first; scene; scene = scene->id.next)
|
2008-12-24 10:33:10 +00:00
|
|
|
scene->id.flag |= LIB_DOIT;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->type == CMP_NODE_R_LAYERS) {
|
|
|
|
ID *id = node->id;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (id->flag & LIB_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);
|
|
|
|
id->flag &= ~LIB_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_read_renderlayers(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Read Render Layers";
|
|
|
|
ot->idname = "NODE_OT_read_renderlayers";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Read all render layers of all used scenes";
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_read_renderlayers_exec;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
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
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_read_fullsamplelayers_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);
|
|
|
|
Scene *curscene = CTX_data_scene(C);
|
|
|
|
Render *re = RE_NewRender(curscene->id.name);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-12-28 10:39:27 +00:00
|
|
|
WM_cursor_wait(1);
|
2010-10-31 11:51:10 +00:00
|
|
|
RE_MergeFullSample(re, bmain, curscene, snode->nodetree);
|
2010-12-28 10:39:27 +00:00
|
|
|
WM_cursor_wait(0);
|
2011-09-22 12:45:25 +00:00
|
|
|
|
|
|
|
/* note we are careful to send the right notifier, as otherwise the
|
2012-03-03 16:31:46 +00:00
|
|
|
* compositor would reexecute and overwrite the full sample result */
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_COMPO_RESULT, NULL);
|
2011-09-22 12:45:25 +00:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NODE_OT_read_fullsamplelayers(wmOperatorType *ot)
|
|
|
|
{
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Read Full Sample Layers";
|
|
|
|
ot->idname = "NODE_OT_read_fullsamplelayers";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Read all render layers of current scene, in full sample";
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_read_fullsamplelayers_exec;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
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);
|
2011-02-07 16:41:57 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = sce->nodetree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id == (ID *)sce && node->need_exec) {
|
2011-02-07 16:41:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node) {
|
2012-06-21 13:19:19 +00:00
|
|
|
SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (srl) {
|
2011-02-07 16:41:57 +00:00
|
|
|
PointerRNA op_ptr;
|
|
|
|
|
|
|
|
WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
|
|
|
|
RNA_string_set(&op_ptr, "layer", srl->name);
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_string_set(&op_ptr, "scene", sce->id.name + 2);
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2011-02-07 18:09:27 +00:00
|
|
|
/* to keep keypositions */
|
|
|
|
sce->r.scemode |= R_NO_FRAME_UPDATE;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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";
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_render_changed_exec;
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
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
|
|
|
{
|
|
|
|
bNode *node;
|
2012-06-21 13:19:19 +00:00
|
|
|
int tot_eq = 0, tot_neq = 0;
|
2010-06-07 20:03:40 +00: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.
|
|
|
|
*/
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0)
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0)
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & toggle_flag)
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_eq++;
|
2009-11-20 06:31:49 +00:00
|
|
|
else
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_neq++;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0)
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0)
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if ( (tot_eq && tot_neq) || tot_eq == 0)
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag |= toggle_flag;
|
2012-04-16 10:50:57 +00:00
|
|
|
else
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag &= ~toggle_flag;
|
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);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
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";
|
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) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
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) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2011-12-18 12:51:50 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
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
|
|
|
bNode *node;
|
2011-12-18 12:51:50 +00:00
|
|
|
int hidden;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
/* Toggle for all selected nodes */
|
|
|
|
hidden = 0;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
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)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
hidden = 1;
|
2010-06-07 20:03:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 06:31:49 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2011-11-20 16:38:23 +00:00
|
|
|
/* Only allow muting of nodes having a mute func! */
|
2012-02-27 17:38:16 +00:00
|
|
|
if ((node->flag & SELECT) && node->typeinfo->internal_connect) {
|
|
|
|
node->flag ^= NODE_MUTED;
|
|
|
|
snode_update(snode, node);
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
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";
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_mute_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 06:31:49 +00:00
|
|
|
bNode *node, *next;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = next) {
|
|
|
|
next = node->next;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2009-11-20 06:31:49 +00:00
|
|
|
/* check id user here, nodeFreeNode is called for free dbase too */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2012-08-01 19:11:17 +00:00
|
|
|
node->id->us--;
|
|
|
|
nodeFreeNode(snode->edittree, node);
|
|
|
|
}
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
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";
|
2010-05-12 04:25:33 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_delete_exec;
|
2012-03-24 07:36:32 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
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
|
|
|
|
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
|
|
|
{
|
2012-08-01 19:11:17 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNode *node, *next;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-08-01 19:11:17 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
|
|
|
for (node = snode->edittree->nodes.first; node; node = next) {
|
|
|
|
next = node->next;
|
|
|
|
if (node->flag & SELECT) {
|
|
|
|
nodeInternalRelink(snode->edittree, node);
|
|
|
|
|
|
|
|
/* check id user here, nodeFreeNode is called for free dbase too */
|
|
|
|
if (node->id)
|
|
|
|
node->id->us--;
|
|
|
|
nodeFreeNode(snode->edittree, node);
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-08-01 19:11:17 +00:00
|
|
|
|
|
|
|
ntreeUpdateTree(snode->edittree);
|
|
|
|
|
|
|
|
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 */
|
2012-08-01 19:11:17 +00:00
|
|
|
ot->name = "Delete with reconnect";
|
|
|
|
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;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
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-08-01 19:11:17 +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);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNode *node;
|
2012-03-01 07:56:15 +00:00
|
|
|
char file_path[MAX_NAME];
|
2012-08-01 19:11:17 +00:00
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
if (!ptr.data)
|
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;
|
2012-05-02 07:18:51 +00:00
|
|
|
node = ptr.data;
|
|
|
|
ntree = ptr.id.data;
|
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;
|
|
|
|
ot->poll = composite_node_active;
|
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(ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Sub-path 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");
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNode *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
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
if (!ptr.data)
|
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;
|
2012-05-02 07:18:51 +00:00
|
|
|
node = ptr.data;
|
|
|
|
ntree = ptr.id.data;
|
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
|
|
|
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;
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
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";
|
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;
|
|
|
|
ot->poll = composite_node_active;
|
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");
|
|
|
|
bNode *node;
|
|
|
|
NodeImageMultiFile *nimf;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
int direction;
|
|
|
|
|
|
|
|
if (!ptr.data)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
node = ptr.data;
|
|
|
|
nimf = node->storage;
|
|
|
|
|
|
|
|
sock = BLI_findlink(&node->inputs, nimf->active_input);
|
|
|
|
if (!sock)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
direction = RNA_enum_get(op->ptr, "direction");
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (direction == 1) {
|
2012-05-02 07:18:51 +00:00
|
|
|
bNodeSocket *before = sock->prev;
|
|
|
|
if (!before)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
BLI_insertlinkbefore(&node->inputs, before, sock);
|
|
|
|
--nimf->active_input;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bNodeSocket *after = sock->next;
|
|
|
|
if (!after)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
BLI_insertlinkafter(&node->inputs, after, sock);
|
|
|
|
++nimf->active_input;
|
|
|
|
}
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_output_file_move_active_socket(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
static EnumPropertyItem direction_items[] = {
|
|
|
|
{1, "UP", 0, "Up", ""},
|
2012-05-03 06:57:30 +00:00
|
|
|
{2, "DOWN", 0, "Down", ""},
|
2012-06-21 13:19:19 +00:00
|
|
|
{ 0, NULL, 0, NULL, NULL }
|
|
|
|
};
|
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";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = node_output_file_move_active_socket_exec;
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
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;
|
|
|
|
bNode *node, *tnode;
|
|
|
|
|
|
|
|
if (!ntree)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
node = nodeGetActive(ntree);
|
|
|
|
if (!node)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (tnode->flag & NODE_SELECT && tnode != node) {
|
|
|
|
if (node->flag & NODE_CUSTOM_COLOR) {
|
|
|
|
tnode->flag |= NODE_CUSTOM_COLOR;
|
|
|
|
copy_v3_v3(tnode->color, node->color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tnode->flag &= ~NODE_CUSTOM_COLOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* 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;
|
2012-08-03 10:51:29 +00:00
|
|
|
bNode *gnode = node_tree_get_editgroup(snode->nodetree);
|
|
|
|
float gnode_x = 0.0f, gnode_y = 0.0f;
|
|
|
|
bNode *node, *new_node;
|
2012-08-02 09:52:37 +00:00
|
|
|
bNodeLink *link, *newlink;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
|
|
|
/* clear current clipboard */
|
|
|
|
nodeClipboardClear();
|
|
|
|
|
2012-08-03 10:51:29 +00:00
|
|
|
/* get group node offset */
|
|
|
|
if (gnode)
|
|
|
|
nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y);
|
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->flag & SELECT) {
|
2012-08-03 10:51:29 +00:00
|
|
|
new_node = nodeCopyNode(NULL, node);
|
|
|
|
nodeClipboardAddNode(new_node);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-03 10:18:52 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->flag & SELECT) {
|
|
|
|
bNode *new_node = node->new_node;
|
2012-08-03 10:51:29 +00:00
|
|
|
|
|
|
|
/* ensure valid pointers */
|
2012-08-03 10:18:52 +00:00
|
|
|
if (new_node->parent) {
|
|
|
|
/* parent pointer must be redirected to new node or detached if parent is not copied */
|
|
|
|
if (new_node->parent->flag & NODE_SELECT) {
|
|
|
|
new_node->parent = new_node->parent->new_node;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nodeDetachNode(new_node);
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 10:51:29 +00:00
|
|
|
|
|
|
|
/* transform to basic view space. child node location is relative to parent */
|
|
|
|
if (!new_node->parent) {
|
|
|
|
new_node->locx += gnode_x;
|
|
|
|
new_node->locy += gnode_y;
|
|
|
|
}
|
2012-08-03 10:18:52 +00: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!
|
|
|
|
*/
|
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
/* This creates new links between copied nodes. */
|
|
|
|
if (link->tonode && (link->tonode->flag & NODE_SELECT) &&
|
|
|
|
link->fromnode && (link->fromnode->flag & NODE_SELECT))
|
|
|
|
{
|
|
|
|
newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
|
|
|
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;
|
|
|
|
|
|
|
|
nodeClipboardAddLink(newlink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_clipboard_copy(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Copy to clipboard";
|
|
|
|
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 ******************* */
|
|
|
|
|
|
|
|
static int node_clipboard_paste_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2012-08-03 10:51:29 +00:00
|
|
|
bNode *gnode = node_tree_get_editgroup(snode->nodetree);
|
|
|
|
float gnode_x = 0.0f, gnode_y = 0.0f;
|
2012-08-02 09:52:37 +00:00
|
|
|
bNode *node;
|
|
|
|
bNodeLink *link;
|
|
|
|
int num_nodes;
|
|
|
|
float centerx, centery;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
|
|
|
/* deselect old nodes */
|
|
|
|
node_deselect_all(snode);
|
|
|
|
|
2012-08-03 10:51:29 +00:00
|
|
|
/* get group node offset */
|
|
|
|
if (gnode)
|
|
|
|
nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y);
|
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* calculate "barycenter" for placing on mouse cursor */
|
|
|
|
num_nodes = 0;
|
|
|
|
centerx = centery = 0.0f;
|
|
|
|
for (node = nodeClipboardGetNodes()->first; node; node = node->next) {
|
|
|
|
++num_nodes;
|
2012-08-03 10:51:29 +00:00
|
|
|
centerx += 0.5f * (node->totr.xmin + node->totr.xmax);
|
|
|
|
centery += 0.5f * (node->totr.ymin + node->totr.ymax);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
centerx /= num_nodes;
|
|
|
|
centery /= num_nodes;
|
|
|
|
|
|
|
|
/* copy nodes from clipboard */
|
|
|
|
for (node = nodeClipboardGetNodes()->first; node; node = node->next) {
|
2012-08-03 10:18:52 +00:00
|
|
|
bNode *new_node = nodeCopyNode(ntree, node);
|
2012-08-02 09:52:37 +00:00
|
|
|
|
|
|
|
/* pasted nodes are selected */
|
2012-08-03 10:18:52 +00:00
|
|
|
node_select(new_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reparent copied nodes */
|
|
|
|
for (node = nodeClipboardGetNodes()->first; node; node = node->next) {
|
|
|
|
bNode *new_node = node->new_node;
|
|
|
|
if (new_node->parent)
|
|
|
|
new_node->parent = new_node->parent->new_node;
|
2012-08-03 10:51:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* place nodes around the mouse cursor. child nodes locations are relative to parent */
|
|
|
|
if (!new_node->parent) {
|
|
|
|
new_node->locx += snode->mx - centerx - gnode_x;
|
|
|
|
new_node->locy += snode->my - centery - gnode_y;
|
|
|
|
}
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (link = nodeClipboardGetLinks()->first; link; link = link->next) {
|
|
|
|
nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock,
|
|
|
|
link->tonode->new_node, link->tosock->new_sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
ntreeUpdateTree(snode->edittree);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_clipboard_paste_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
|
|
|
/* convert mouse coordinates to v2d space */
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my);
|
|
|
|
|
|
|
|
return node_clipboard_paste_exec(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_clipboard_paste(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Paste from clipboard";
|
|
|
|
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;
|
|
|
|
ot->invoke = node_clipboard_paste_invoke;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-08-04 12:54:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|