2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2005-12-18 13:46:01 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2005-12-18 13:46:01 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-18 13:46:01 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
2011-02-21 13:47:49 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <limits.h>
|
2009-11-11 09:11:21 +00:00
|
|
|
#include <stddef.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdlib.h>
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
#include <string.h>
|
2005-12-18 13:46:01 +00:00
|
|
|
|
2011-11-02 19:24:30 +00:00
|
|
|
#include "DNA_action_types.h"
|
2010-01-27 05:42:17 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2019-02-27 12:34:56 +11:00
|
|
|
#include "DNA_light_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_linestyle_types.h"
|
2012-12-03 16:21:43 +00:00
|
|
|
#include "DNA_material_types.h"
|
2011-02-21 13:47:49 +00:00
|
|
|
#include "DNA_node_types.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2012-12-03 16:21:43 +00:00
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
2011-02-21 13:47:49 +00:00
|
|
|
|
2019-06-03 17:08:25 +02:00
|
|
|
#include "BLI_ghash.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_math.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BLI_path_util.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BLI_string_utils.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-01-27 05:42:17 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-03-17 14:42:44 +00:00
|
|
|
|
2020-04-03 13:07:36 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2010-12-29 11:51:53 +00:00
|
|
|
#include "BKE_animsys.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_global.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "BKE_idprop.h"
|
2020-03-06 14:57:26 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_main.h"
|
2011-02-07 09:33:36 +00:00
|
|
|
#include "BKE_node.h"
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "BLI_ghash.h"
|
2015-06-26 14:47:53 +02:00
|
|
|
#include "BLI_threads.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "RNA_access.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "RNA_define.h"
|
2007-03-24 18:41:54 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
#include "NOD_common.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "NOD_composite.h"
|
|
|
|
#include "NOD_shader.h"
|
2020-04-20 10:58:43 +02:00
|
|
|
#include "NOD_simulation.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "NOD_socket.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "NOD_texture.h"
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
|
2018-03-16 11:17:45 +01:00
|
|
|
#include "DEG_depsgraph.h"
|
2018-11-23 17:02:55 +01:00
|
|
|
#include "DEG_depsgraph_build.h"
|
2018-03-16 11:17:45 +01:00
|
|
|
|
2016-03-12 19:10:36 +01:00
|
|
|
#define NODE_DEFAULT_MAX_WIDTH 700
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
/* Fallback types for undefined tree, nodes, sockets */
|
2019-02-23 19:17:30 +11:00
|
|
|
static bNodeTreeType NodeTreeTypeUndefined;
|
2013-03-19 13:40:16 +00:00
|
|
|
bNodeType NodeTypeUndefined;
|
|
|
|
bNodeSocketType NodeSocketTypeUndefined;
|
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
static CLG_LogRef LOG = {"bke.node"};
|
2007-03-26 15:07:38 +00:00
|
|
|
|
2020-03-06 14:57:26 +01:00
|
|
|
static void ntree_set_typeinfo(bNodeTree *ntree, bNodeTreeType *typeinfo);
|
|
|
|
static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src, const int flag);
|
|
|
|
static void free_localized_node_groups(bNodeTree *ntree);
|
|
|
|
static void node_free_node(bNodeTree *ntree, bNode *node);
|
|
|
|
static void node_socket_interface_free(bNodeTree *UNUSED(ntree), bNodeSocket *sock);
|
|
|
|
|
|
|
|
static void ntree_init_data(ID *id)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = (bNodeTree *)id;
|
|
|
|
ntree_set_typeinfo(ntree, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ntree_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree_dst = (bNodeTree *)id_dst;
|
|
|
|
const bNodeTree *ntree_src = (const bNodeTree *)id_src;
|
|
|
|
bNodeSocket *sock_dst, *sock_src;
|
|
|
|
bNodeLink *link_dst;
|
|
|
|
|
|
|
|
/* We never handle usercount here for own data. */
|
|
|
|
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
|
|
|
|
|
|
|
|
/* in case a running nodetree is copied */
|
|
|
|
ntree_dst->execdata = NULL;
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ntree_dst->nodes);
|
|
|
|
BLI_listbase_clear(&ntree_dst->links);
|
|
|
|
|
|
|
|
/* Since source nodes and sockets are unique pointers we can put everything in a single map. */
|
|
|
|
GHash *new_pointers = BLI_ghash_ptr_new(__func__);
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (const bNode *, node_src, &ntree_src->nodes) {
|
2020-03-06 14:57:26 +01:00
|
|
|
bNode *new_node = BKE_node_copy_ex(ntree_dst, node_src, flag_subdata, true);
|
|
|
|
BLI_ghash_insert(new_pointers, (void *)node_src, new_node);
|
|
|
|
/* Store mapping to inputs. */
|
|
|
|
bNodeSocket *new_input_sock = new_node->inputs.first;
|
|
|
|
const bNodeSocket *input_sock_src = node_src->inputs.first;
|
|
|
|
while (new_input_sock != NULL) {
|
|
|
|
BLI_ghash_insert(new_pointers, (void *)input_sock_src, new_input_sock);
|
|
|
|
new_input_sock = new_input_sock->next;
|
|
|
|
input_sock_src = input_sock_src->next;
|
|
|
|
}
|
|
|
|
/* Store mapping to outputs. */
|
|
|
|
bNodeSocket *new_output_sock = new_node->outputs.first;
|
|
|
|
const bNodeSocket *output_sock_src = node_src->outputs.first;
|
|
|
|
while (new_output_sock != NULL) {
|
|
|
|
BLI_ghash_insert(new_pointers, (void *)output_sock_src, new_output_sock);
|
|
|
|
new_output_sock = new_output_sock->next;
|
|
|
|
output_sock_src = output_sock_src->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy links */
|
|
|
|
BLI_duplicatelist(&ntree_dst->links, &ntree_src->links);
|
|
|
|
for (link_dst = ntree_dst->links.first; link_dst; link_dst = link_dst->next) {
|
|
|
|
link_dst->fromnode = BLI_ghash_lookup_default(new_pointers, link_dst->fromnode, NULL);
|
|
|
|
link_dst->fromsock = BLI_ghash_lookup_default(new_pointers, link_dst->fromsock, NULL);
|
|
|
|
link_dst->tonode = BLI_ghash_lookup_default(new_pointers, link_dst->tonode, NULL);
|
|
|
|
link_dst->tosock = BLI_ghash_lookup_default(new_pointers, link_dst->tosock, NULL);
|
|
|
|
/* update the link socket's pointer */
|
|
|
|
if (link_dst->tosock) {
|
|
|
|
link_dst->tosock->link = link_dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy interface sockets */
|
|
|
|
BLI_duplicatelist(&ntree_dst->inputs, &ntree_src->inputs);
|
|
|
|
for (sock_dst = ntree_dst->inputs.first, sock_src = ntree_src->inputs.first; sock_dst != NULL;
|
|
|
|
sock_dst = sock_dst->next, sock_src = sock_src->next) {
|
|
|
|
node_socket_copy(sock_dst, sock_src, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_duplicatelist(&ntree_dst->outputs, &ntree_src->outputs);
|
|
|
|
for (sock_dst = ntree_dst->outputs.first, sock_src = ntree_src->outputs.first; sock_dst != NULL;
|
|
|
|
sock_dst = sock_dst->next, sock_src = sock_src->next) {
|
|
|
|
node_socket_copy(sock_dst, sock_src, flag_subdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy preview hash */
|
|
|
|
if (ntree_src->previews && (flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
|
|
|
bNodeInstanceHashIterator iter;
|
|
|
|
|
|
|
|
ntree_dst->previews = BKE_node_instance_hash_new("node previews");
|
|
|
|
|
|
|
|
NODE_INSTANCE_HASH_ITER (iter, ntree_src->previews) {
|
|
|
|
bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter);
|
|
|
|
bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter);
|
|
|
|
BKE_node_instance_hash_insert(ntree_dst->previews, key, BKE_node_preview_copy(preview));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ntree_dst->previews = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update node->parent pointers */
|
|
|
|
for (bNode *node_dst = ntree_dst->nodes.first, *node_src = ntree_src->nodes.first; node_dst;
|
|
|
|
node_dst = node_dst->next, node_src = node_src->next) {
|
|
|
|
if (node_dst->parent) {
|
|
|
|
node_dst->parent = BLI_ghash_lookup_default(new_pointers, node_dst->parent, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_ghash_free(new_pointers, NULL, NULL);
|
|
|
|
|
|
|
|
/* node tree will generate its own interface type */
|
|
|
|
ntree_dst->interface_type = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ntree_free_data(ID *id)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = (bNodeTree *)id;
|
|
|
|
bNode *node, *next;
|
|
|
|
bNodeSocket *sock, *nextsock;
|
|
|
|
|
|
|
|
/* XXX hack! node trees should not store execution graphs at all.
|
|
|
|
* This should be removed when old tree types no longer require it.
|
|
|
|
* Currently the execution data for texture nodes remains in the tree
|
|
|
|
* after execution, until the node tree is updated or freed.
|
|
|
|
*/
|
|
|
|
if (ntree->execdata) {
|
|
|
|
switch (ntree->type) {
|
|
|
|
case NTREE_SHADER:
|
|
|
|
ntreeShaderEndExecTree(ntree->execdata);
|
|
|
|
break;
|
|
|
|
case NTREE_TEXTURE:
|
|
|
|
ntreeTexEndExecTree(ntree->execdata);
|
|
|
|
ntree->execdata = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX not nice, but needed to free localized node groups properly */
|
|
|
|
free_localized_node_groups(ntree);
|
|
|
|
|
|
|
|
/* unregister associated RNA types */
|
|
|
|
ntreeInterfaceTypeFree(ntree);
|
|
|
|
|
|
|
|
BLI_freelistN(&ntree->links); /* do first, then unlink_node goes fast */
|
|
|
|
|
|
|
|
for (node = ntree->nodes.first; node; node = next) {
|
|
|
|
next = node->next;
|
|
|
|
node_free_node(ntree, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free interface sockets */
|
|
|
|
for (sock = ntree->inputs.first; sock; sock = nextsock) {
|
|
|
|
nextsock = sock->next;
|
|
|
|
node_socket_interface_free(ntree, sock);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
|
|
|
for (sock = ntree->outputs.first; sock; sock = nextsock) {
|
|
|
|
nextsock = sock->next;
|
|
|
|
node_socket_interface_free(ntree, sock);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free preview hash */
|
|
|
|
if (ntree->previews) {
|
|
|
|
BKE_node_instance_hash_free(ntree->previews, (bNodeInstanceValueFP)BKE_node_preview_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntree->id.tag & LIB_TAG_LOCALIZED) {
|
|
|
|
BKE_libblock_free_data(&ntree->id, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IDTypeInfo IDType_ID_NT = {
|
|
|
|
.id_code = ID_NT,
|
|
|
|
.id_filter = FILTER_ID_NT,
|
|
|
|
.main_listbase_index = INDEX_ID_NT,
|
|
|
|
.struct_size = sizeof(bNodeTree),
|
|
|
|
.name = "NodeTree",
|
|
|
|
.name_plural = "node_groups",
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_NODETREE,
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
.init_data = ntree_init_data,
|
|
|
|
.copy_data = ntree_copy_data,
|
|
|
|
.free_data = ntree_free_data,
|
|
|
|
.make_local = NULL,
|
|
|
|
};
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType *ntype)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocketTemplate *sockdef;
|
|
|
|
/* bNodeSocket *sock; */ /* UNUSED */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntype->inputs) {
|
|
|
|
sockdef = ntype->inputs;
|
|
|
|
while (sockdef->type != -1) {
|
|
|
|
/* sock = */ node_add_socket_from_template(ntree, node, sockdef, SOCK_IN);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sockdef++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ntype->outputs) {
|
|
|
|
sockdef = ntype->outputs;
|
|
|
|
while (sockdef->type != -1) {
|
|
|
|
/* sock = */ node_add_socket_from_template(ntree, node, sockdef, SOCK_OUT);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sockdef++;
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: This function is called to initialize node data based on the type.
|
|
|
|
* The bNodeType may not be registered at creation time of the node,
|
|
|
|
* so this can be delayed until the node type gets registered.
|
|
|
|
*/
|
|
|
|
static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeType *ntype = node->typeinfo;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntype == &NodeTypeUndefined) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* only do this once */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->flag & NODE_INIT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag = NODE_SELECT | NODE_OPTIONS | ntype->flag;
|
|
|
|
node->width = ntype->width;
|
|
|
|
node->miniwidth = 42.0f;
|
|
|
|
node->height = ntype->height;
|
|
|
|
node->color[0] = node->color[1] = node->color[2] = 0.608; /* default theme color */
|
|
|
|
/* initialize the node name with the node label.
|
|
|
|
* note: do this after the initfunc so nodes get their data set which may be used in naming
|
|
|
|
* (node groups for example) */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* XXX Do not use nodeLabel() here, it returns translated content for UI,
|
|
|
|
* which should *only* be used in UI, *never* in data...
|
|
|
|
* Data have their own translation option!
|
2019-04-17 06:17:24 +02:00
|
|
|
* This solution may be a bit rougher than nodeLabel()'s returned string, but it's simpler
|
|
|
|
* than adding "do_translate" flags to this func (and labelfunc() as well). */
|
|
|
|
BLI_strncpy(node->name, DATA_(ntype->ui_name), NODE_MAXSTR);
|
|
|
|
nodeUniqueName(ntree, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_add_sockets_from_type(ntree, node, ntype);
|
2013-12-01 21:56:52 +01:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntype->initfunc != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->initfunc(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-12-08 21:53:35 +01:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->node_add_init != NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->node_add_init(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-12-08 21:53:35 +01:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->id) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_plus(node->id);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* extra init callback */
|
|
|
|
if (ntype->initfunc_api) {
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX Warning: context can be NULL in case nodes are added in do_versions.
|
|
|
|
* Delayed init is not supported for nodes with context-based initfunc_api atm.
|
|
|
|
*/
|
|
|
|
BLI_assert(C != NULL);
|
|
|
|
ntype->initfunc_api(C, &ptr);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_INIT;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ntree_set_typeinfo(bNodeTree *ntree, bNodeTreeType *typeinfo)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (typeinfo) {
|
|
|
|
ntree->typeinfo = typeinfo;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* deprecated integer type */
|
|
|
|
ntree->type = typeinfo->type;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ntree->typeinfo = &NodeTreeTypeUndefined;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->init &= ~NTREE_TYPE_INIT;
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void node_set_typeinfo(const struct bContext *C,
|
|
|
|
bNodeTree *ntree,
|
|
|
|
bNode *node,
|
|
|
|
bNodeType *typeinfo)
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* for nodes saved in older versions storage can get lost, make undefined then */
|
|
|
|
if (node->flag & NODE_INIT) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (typeinfo && typeinfo->storagename[0] && !node->storage) {
|
2019-04-17 06:17:24 +02:00
|
|
|
typeinfo = NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (typeinfo) {
|
|
|
|
node->typeinfo = typeinfo;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* deprecated integer type */
|
|
|
|
node->type = typeinfo->type;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* initialize the node if necessary */
|
|
|
|
node_init(C, ntree, node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->typeinfo = &NodeTypeUndefined;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->init &= ~NTREE_TYPE_INIT;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void node_socket_set_typeinfo(bNodeTree *ntree,
|
|
|
|
bNodeSocket *sock,
|
|
|
|
bNodeSocketType *typeinfo)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (typeinfo) {
|
|
|
|
sock->typeinfo = typeinfo;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* deprecated integer type */
|
|
|
|
sock->type = typeinfo->type;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sock->default_value == NULL) {
|
|
|
|
/* initialize the default_value pointer used by standard socket types */
|
|
|
|
node_socket_init_default_value(sock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sock->typeinfo = &NodeSocketTypeUndefined;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->init &= ~NTREE_TYPE_INIT;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set specific typeinfo pointers in all node trees on register/unregister */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void update_typeinfo(Main *bmain,
|
|
|
|
const struct bContext *C,
|
|
|
|
bNodeTreeType *treetype,
|
|
|
|
bNodeType *nodetype,
|
|
|
|
bNodeSocketType *socktype,
|
|
|
|
bool unregister)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!bmain) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
|
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
|
|
ntree->init |= NTREE_TYPE_INIT;
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (treetype && STREQ(ntree->idname, treetype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree_set_typeinfo(ntree, unregister ? NULL : treetype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* initialize nodes */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (nodetype && STREQ(node->idname, nodetype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_set_typeinfo(C, ntree, node, unregister ? NULL : nodetype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* initialize node sockets */
|
2019-04-22 09:39:35 +10:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (socktype && STREQ(sock->idname, socktype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, unregister ? NULL : socktype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (socktype && STREQ(sock->idname, socktype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, unregister ? NULL : socktype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize tree sockets */
|
2019-04-22 09:39:35 +10:00
|
|
|
for (sock = ntree->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (socktype && STREQ(sock->idname, socktype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, unregister ? NULL : socktype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (sock = ntree->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (socktype && STREQ(sock->idname, socktype->idname)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, unregister ? NULL : socktype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
FOREACH_NODETREE_END;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to initialize all typeinfo in a node tree.
|
2019-04-27 12:07:07 +10:00
|
|
|
* NB: In general undefined typeinfo is a perfectly valid case,
|
|
|
|
* the type may just be registered later.
|
2013-03-18 16:34:57 +00:00
|
|
|
* In that case the update_typeinfo function will set typeinfo on registration
|
|
|
|
* and do necessary updates.
|
|
|
|
*/
|
|
|
|
void ntreeSetTypes(const struct bContext *C, bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->init |= NTREE_TYPE_INIT;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree_set_typeinfo(ntree, ntreeTypeFind(ntree->idname));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
node_set_typeinfo(C, ntree, node, nodeTypeFind(node->idname));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(sock->idname));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(sock->idname));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (sock = ntree->inputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(sock->idname));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
for (sock = ntree->outputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(sock->idname));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
static GHash *nodetreetypes_hash = NULL;
|
|
|
|
static GHash *nodetypes_hash = NULL;
|
|
|
|
static GHash *nodesockettypes_hash = NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
bNodeTreeType *ntreeTypeFind(const char *idname)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeTreeType *nt;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (idname[0]) {
|
|
|
|
nt = BLI_ghash_lookup(nodetreetypes_hash, idname);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (nt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return nt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
void ntreeTypeAdd(bNodeTreeType *nt)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_insert(nodetreetypes_hash, nt->idname, nt);
|
|
|
|
/* XXX pass Main to register function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, nt, NULL, NULL, false);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* callback for hash value free function */
|
|
|
|
static void ntree_free_type(void *treetype_v)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeTreeType *treetype = treetype_v;
|
|
|
|
/* XXX pass Main to unregister function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, treetype, NULL, NULL, true);
|
|
|
|
MEM_freeN(treetype);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 12:39:39 +10:00
|
|
|
void ntreeTypeFreeLink(const bNodeTreeType *nt)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_remove(nodetreetypes_hash, nt->idname, NULL, ntree_free_type);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
bool ntreeIsRegistered(bNodeTree *ntree)
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ntree->typeinfo != &NodeTreeTypeUndefined);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
GHashIterator *ntreeTypeGetIterator(void)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghashIterator_new(nodetreetypes_hash);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeType *nodeTypeFind(const char *idname)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeType *nt;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (idname[0]) {
|
|
|
|
nt = BLI_ghash_lookup(nodetypes_hash, idname);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (nt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return nt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void free_dynamic_typeinfo(bNodeType *ntype)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntype->type == NODE_DYNAMIC) {
|
|
|
|
if (ntype->inputs) {
|
|
|
|
MEM_freeN(ntype->inputs);
|
|
|
|
}
|
|
|
|
if (ntype->outputs) {
|
|
|
|
MEM_freeN(ntype->outputs);
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* callback for hash value free function */
|
|
|
|
static void node_free_type(void *nodetype_v)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeType *nodetype = nodetype_v;
|
|
|
|
/* XXX pass Main to unregister function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, NULL, nodetype, NULL, true);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX deprecated */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (nodetype->type == NODE_DYNAMIC) {
|
2019-04-17 06:17:24 +02:00
|
|
|
free_dynamic_typeinfo(nodetype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-02-28 13:28:16 +01:00
|
|
|
/* Can be NULL when the type is not dynamically allocated. */
|
|
|
|
if (nodetype->free_self) {
|
|
|
|
nodetype->free_self(nodetype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nodeRegisterType(bNodeType *nt)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* debug only: basic verification of registered types */
|
|
|
|
BLI_assert(nt->idname[0] != '\0');
|
|
|
|
BLI_assert(nt->poll != NULL);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_insert(nodetypes_hash, nt->idname, nt);
|
|
|
|
/* XXX pass Main to register function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, NULL, nt, NULL, false);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
void nodeUnregisterType(bNodeType *nt)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_remove(nodetypes_hash, nt->idname, NULL, node_free_type);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
bool nodeIsRegistered(bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (node->typeinfo != &NodeTypeUndefined);
|
2013-03-19 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
GHashIterator *nodeTypeGetIterator(void)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghashIterator_new(nodetypes_hash);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bNodeSocketType *nodeSocketTypeFind(const char *idname)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocketType *st;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (idname[0]) {
|
|
|
|
st = BLI_ghash_lookup(nodesockettypes_hash, idname);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (st) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return st;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* callback for hash value free function */
|
|
|
|
static void node_free_socket_type(void *socktype_v)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocketType *socktype = socktype_v;
|
|
|
|
/* XXX pass Main to unregister function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, NULL, NULL, socktype, true);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-02-28 13:28:16 +01:00
|
|
|
socktype->free_self(socktype);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2008-02-09 23:17:15 +00:00
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
void nodeRegisterSocketType(bNodeSocketType *st)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_insert(nodesockettypes_hash, (void *)st->idname, st);
|
|
|
|
/* XXX pass Main to register function? */
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Probably not. It is pretty much expected we want to update G_MAIN here I think -
|
|
|
|
* or we'd want to update *all* active Mains, which we cannot do anyway currently. */
|
2019-04-17 06:17:24 +02:00
|
|
|
update_typeinfo(G_MAIN, NULL, NULL, NULL, st, false);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
void nodeUnregisterSocketType(bNodeSocketType *st)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_remove(nodesockettypes_hash, st->idname, NULL, node_free_socket_type);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
bool nodeSocketIsRegistered(bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (sock->typeinfo != &NodeSocketTypeUndefined);
|
2013-03-19 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
GHashIterator *nodeSocketTypeGetIterator(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghashIterator_new(nodesockettypes_hash);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct bNodeSocket *nodeFindSocket(bNode *node, int in_out, const char *identifier)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *sock = (in_out == SOCK_IN ? node->inputs.first : node->outputs.first);
|
|
|
|
for (; sock; sock = sock->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (STREQ(sock->identifier, identifier)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return sock;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find unique socket identifier */
|
|
|
|
static bool unique_identifier_check(void *arg, const char *identifier)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct ListBase *lb = arg;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
for (sock = lb->first; sock; sock = sock->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (STREQ(sock->identifier, identifier)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return false;
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bNodeSocket *make_socket(bNodeTree *ntree,
|
|
|
|
bNode *UNUSED(node),
|
|
|
|
int in_out,
|
|
|
|
ListBase *lb,
|
|
|
|
const char *idname,
|
|
|
|
const char *identifier,
|
|
|
|
const char *name)
|
2008-02-09 23:17:15 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *sock;
|
|
|
|
char auto_identifier[MAX_NAME];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (identifier && identifier[0] != '\0') {
|
|
|
|
/* use explicit identifier */
|
|
|
|
BLI_strncpy(auto_identifier, identifier, sizeof(auto_identifier));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* if no explicit identifier is given, assign a unique identifier based on the name */
|
|
|
|
BLI_strncpy(auto_identifier, name, sizeof(auto_identifier));
|
|
|
|
}
|
|
|
|
/* make the identifier unique */
|
|
|
|
BLI_uniquename_cb(
|
|
|
|
unique_identifier_check, lb, "socket", '.', auto_identifier, sizeof(auto_identifier));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sock = MEM_callocN(sizeof(bNodeSocket), "sock");
|
|
|
|
sock->in_out = in_out;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(sock->identifier, auto_identifier, NODE_MAXSTR);
|
|
|
|
sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(sock->name, name, NODE_MAXSTR);
|
|
|
|
sock->storage = NULL;
|
|
|
|
sock->flag |= SOCK_COLLAPSED;
|
|
|
|
sock->type = SOCK_CUSTOM; /* int type undefined by default */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(sock->idname, idname, sizeof(sock->idname));
|
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(idname));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sock;
|
2008-02-09 23:17:15 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void nodeModifySocketType(
|
|
|
|
bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, int type, int subtype)
|
2018-01-20 01:04:07 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *idname = nodeStaticSocketType(type, subtype);
|
2018-01-20 01:04:07 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!idname) {
|
|
|
|
CLOG_ERROR(&LOG, "static node socket type %d undefined", type);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-20 01:04:07 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sock->default_value) {
|
|
|
|
MEM_freeN(sock->default_value);
|
|
|
|
sock->default_value = NULL;
|
|
|
|
}
|
2018-01-20 01:04:07 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sock->type = type;
|
|
|
|
BLI_strncpy(sock->idname, idname, sizeof(sock->idname));
|
|
|
|
node_socket_set_typeinfo(ntree, sock, nodeSocketTypeFind(idname));
|
2018-01-20 01:04:07 +01:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *nodeAddSocket(bNodeTree *ntree,
|
|
|
|
bNode *node,
|
|
|
|
int in_out,
|
|
|
|
const char *idname,
|
|
|
|
const char *identifier,
|
|
|
|
const char *name)
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase *lb = (in_out == SOCK_IN ? &node->inputs : &node->outputs);
|
|
|
|
bNodeSocket *sock = make_socket(ntree, node, in_out, lb, idname, identifier, name);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_remlink(lb, sock); /* does nothing for new socket */
|
|
|
|
BLI_addtail(lb, sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->update |= NODE_UPDATE;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sock;
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *nodeInsertSocket(bNodeTree *ntree,
|
|
|
|
bNode *node,
|
|
|
|
int in_out,
|
|
|
|
const char *idname,
|
|
|
|
bNodeSocket *next_sock,
|
|
|
|
const char *identifier,
|
|
|
|
const char *name)
|
2011-02-21 13:47:49 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase *lb = (in_out == SOCK_IN ? &node->inputs : &node->outputs);
|
|
|
|
bNodeSocket *sock = make_socket(ntree, node, in_out, lb, idname, identifier, name);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_remlink(lb, sock); /* does nothing for new socket */
|
|
|
|
BLI_insertlinkbefore(lb, next_sock, sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->update |= NODE_UPDATE;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sock;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
const char *nodeStaticSocketType(int type, int subtype)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (type) {
|
|
|
|
case SOCK_FLOAT:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_UNSIGNED:
|
|
|
|
return "NodeSocketFloatUnsigned";
|
|
|
|
case PROP_PERCENTAGE:
|
|
|
|
return "NodeSocketFloatPercentage";
|
|
|
|
case PROP_FACTOR:
|
|
|
|
return "NodeSocketFloatFactor";
|
|
|
|
case PROP_ANGLE:
|
|
|
|
return "NodeSocketFloatAngle";
|
|
|
|
case PROP_TIME:
|
|
|
|
return "NodeSocketFloatTime";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketFloat";
|
|
|
|
}
|
|
|
|
case SOCK_INT:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_UNSIGNED:
|
|
|
|
return "NodeSocketIntUnsigned";
|
|
|
|
case PROP_PERCENTAGE:
|
|
|
|
return "NodeSocketIntPercentage";
|
|
|
|
case PROP_FACTOR:
|
|
|
|
return "NodeSocketIntFactor";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketInt";
|
|
|
|
}
|
|
|
|
case SOCK_BOOLEAN:
|
|
|
|
return "NodeSocketBool";
|
|
|
|
case SOCK_VECTOR:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_TRANSLATION:
|
|
|
|
return "NodeSocketVectorTranslation";
|
|
|
|
case PROP_DIRECTION:
|
|
|
|
return "NodeSocketVectorDirection";
|
|
|
|
case PROP_VELOCITY:
|
|
|
|
return "NodeSocketVectorVelocity";
|
|
|
|
case PROP_ACCELERATION:
|
|
|
|
return "NodeSocketVectorAcceleration";
|
|
|
|
case PROP_EULER:
|
|
|
|
return "NodeSocketVectorEuler";
|
|
|
|
case PROP_XYZ:
|
|
|
|
return "NodeSocketVectorXYZ";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketVector";
|
|
|
|
}
|
|
|
|
case SOCK_RGBA:
|
|
|
|
return "NodeSocketColor";
|
|
|
|
case SOCK_STRING:
|
|
|
|
return "NodeSocketString";
|
|
|
|
case SOCK_SHADER:
|
|
|
|
return "NodeSocketShader";
|
|
|
|
}
|
|
|
|
return NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *nodeStaticSocketInterfaceType(int type, int subtype)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (type) {
|
|
|
|
case SOCK_FLOAT:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_UNSIGNED:
|
|
|
|
return "NodeSocketInterfaceFloatUnsigned";
|
|
|
|
case PROP_PERCENTAGE:
|
|
|
|
return "NodeSocketInterfaceFloatPercentage";
|
|
|
|
case PROP_FACTOR:
|
|
|
|
return "NodeSocketInterfaceFloatFactor";
|
|
|
|
case PROP_ANGLE:
|
|
|
|
return "NodeSocketInterfaceFloatAngle";
|
|
|
|
case PROP_TIME:
|
|
|
|
return "NodeSocketInterfaceFloatTime";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketInterfaceFloat";
|
|
|
|
}
|
|
|
|
case SOCK_INT:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_UNSIGNED:
|
|
|
|
return "NodeSocketInterfaceIntUnsigned";
|
|
|
|
case PROP_PERCENTAGE:
|
|
|
|
return "NodeSocketInterfaceIntPercentage";
|
|
|
|
case PROP_FACTOR:
|
|
|
|
return "NodeSocketInterfaceIntFactor";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketInterfaceInt";
|
|
|
|
}
|
|
|
|
case SOCK_BOOLEAN:
|
|
|
|
return "NodeSocketInterfaceBool";
|
|
|
|
case SOCK_VECTOR:
|
|
|
|
switch (subtype) {
|
|
|
|
case PROP_TRANSLATION:
|
|
|
|
return "NodeSocketInterfaceVectorTranslation";
|
|
|
|
case PROP_DIRECTION:
|
|
|
|
return "NodeSocketInterfaceVectorDirection";
|
|
|
|
case PROP_VELOCITY:
|
|
|
|
return "NodeSocketInterfaceVectorVelocity";
|
|
|
|
case PROP_ACCELERATION:
|
|
|
|
return "NodeSocketInterfaceVectorAcceleration";
|
|
|
|
case PROP_EULER:
|
|
|
|
return "NodeSocketInterfaceVectorEuler";
|
|
|
|
case PROP_XYZ:
|
|
|
|
return "NodeSocketInterfaceVectorXYZ";
|
|
|
|
case PROP_NONE:
|
|
|
|
default:
|
|
|
|
return "NodeSocketInterfaceVector";
|
|
|
|
}
|
|
|
|
case SOCK_RGBA:
|
|
|
|
return "NodeSocketInterfaceColor";
|
|
|
|
case SOCK_STRING:
|
|
|
|
return "NodeSocketInterfaceString";
|
|
|
|
case SOCK_SHADER:
|
|
|
|
return "NodeSocketInterfaceShader";
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bNodeSocket *nodeAddStaticSocket(bNodeTree *ntree,
|
|
|
|
bNode *node,
|
|
|
|
int in_out,
|
|
|
|
int type,
|
|
|
|
int subtype,
|
|
|
|
const char *identifier,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
const char *idname = nodeStaticSocketType(type, subtype);
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
|
|
if (!idname) {
|
|
|
|
CLOG_ERROR(&LOG, "static node socket type %d undefined", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = nodeAddSocket(ntree, node, in_out, idname, identifier, name);
|
|
|
|
sock->type = type;
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
|
|
|
bNodeSocket *nodeInsertStaticSocket(bNodeTree *ntree,
|
|
|
|
bNode *node,
|
|
|
|
int in_out,
|
|
|
|
int type,
|
|
|
|
int subtype,
|
|
|
|
bNodeSocket *next_sock,
|
|
|
|
const char *identifier,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
const char *idname = nodeStaticSocketType(type, subtype);
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
|
|
if (!idname) {
|
|
|
|
CLOG_ERROR(&LOG, "static node socket type %d undefined", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = nodeInsertSocket(ntree, node, in_out, idname, next_sock, identifier, name);
|
|
|
|
sock->type = type;
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void node_socket_free(bNodeTree *UNUSED(ntree),
|
|
|
|
bNodeSocket *sock,
|
|
|
|
bNode *UNUSED(node),
|
|
|
|
const bool do_id_user)
|
|
|
|
{
|
|
|
|
if (sock->prop) {
|
2019-05-16 14:17:11 +02:00
|
|
|
IDP_FreePropertyContent_ex(sock->prop, do_id_user);
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(sock->prop);
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sock->default_value) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(sock->default_value);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock)
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link, *next;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = next) {
|
|
|
|
next = link->next;
|
|
|
|
if (link->fromsock == sock || link->tosock == sock) {
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* this is fast, this way we don't need an in_out argument */
|
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
BLI_remlink(&node->outputs, sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_free(ntree, sock, node, true);
|
|
|
|
MEM_freeN(sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->update |= NODE_UPDATE;
|
2011-02-08 09:14:18 +00:00
|
|
|
}
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node)
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *sock, *sock_next;
|
|
|
|
bNodeLink *link, *next;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = next) {
|
|
|
|
next = link->next;
|
|
|
|
if (link->fromnode == node || link->tonode == node) {
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock_next) {
|
|
|
|
sock_next = sock->next;
|
|
|
|
node_socket_free(ntree, sock, node, true);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
|
|
|
BLI_listbase_clear(&node->inputs);
|
2016-11-19 12:16:14 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock_next) {
|
|
|
|
sock_next = sock->next;
|
|
|
|
node_socket_free(ntree, sock, node, true);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
|
|
|
BLI_listbase_clear(&node->outputs);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->update |= NODE_UPDATE;
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
}
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
|
2009-12-17 04:55:15 +00:00
|
|
|
/* finds a node based on its name */
|
|
|
|
bNode *nodeFindNodebyName(bNodeTree *ntree, const char *name)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_findstring(&ntree->nodes, name, offsetof(bNode, name));
|
2009-12-17 04:55:15 +00:00
|
|
|
}
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
|
2007-12-27 10:17:33 +00:00
|
|
|
/* finds a node based on given socket */
|
2013-03-18 16:34:57 +00:00
|
|
|
int nodeFindNode(bNodeTree *ntree, bNodeSocket *sock, bNode **nodep, int *sockindex)
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int in_out = sock->in_out;
|
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *tsock;
|
|
|
|
int index = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
tsock = (in_out == SOCK_IN ? node->inputs.first : node->outputs.first);
|
|
|
|
for (index = 0; tsock; tsock = tsock->next, index++) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tsock == sock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tsock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2007-12-27 10:17:33 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node) {
|
|
|
|
*nodep = node;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sockindex) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*sockindex = index;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*nodep = NULL;
|
|
|
|
return 0;
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
}
|
Orange; daily noodler update commit.
- Adding execution code for Node trees. Was a bit a puzzle, since I want
it to be multithreading by design. This now is solved by defining a
stack per tree for all data that's being written into. This stack, which
resides now in the NodeTree itself, then can be allocated per thread.
- For testing pleasure, I've added a 'mix node' and a 'show node', so
you can already see it do something. :)
- reshuffled structure, to put things nice together, and have easier node
adding. Current state is still WIP though, structure might change.
For the record; new file node_shaders.c will contain all shader node
definitions, apart from the drawing callbacks.
Next: I'm going to check on Andrea's work on icons now, since this is very
much needed for true shader/composit work.
Now back to release work...
2005-12-21 14:24:51 +00:00
|
|
|
|
2015-08-01 16:16:16 +02:00
|
|
|
/**
|
|
|
|
* \note Recursive
|
|
|
|
*/
|
|
|
|
bNode *nodeFindRootParent(bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->parent) {
|
|
|
|
return nodeFindRootParent(node->parent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return node->type == NODE_FRAME ? node : NULL;
|
|
|
|
}
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \returns true if \a child has \a parent as a parent/grandparent/...
|
|
|
|
* \note Recursive
|
|
|
|
*/
|
|
|
|
bool nodeIsChildOf(const bNode *parent, const bNode *child)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (parent == child) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (child->parent) {
|
|
|
|
return nodeIsChildOf(parent, child->parent);
|
|
|
|
}
|
|
|
|
return false;
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over a chain of nodes, starting with \a node_start, executing
|
|
|
|
* \a callback for each node (which can return false to end iterator).
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param reversed: for backwards iteration
|
2015-08-01 16:16:16 +02:00
|
|
|
* \note Recursive
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void nodeChainIter(const bNodeTree *ntree,
|
|
|
|
const bNode *node_start,
|
|
|
|
bool (*callback)(bNode *, bNode *, void *, const bool),
|
|
|
|
void *userdata,
|
|
|
|
const bool reversed)
|
|
|
|
{
|
|
|
|
bNodeLink *link;
|
|
|
|
|
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
if ((link->flag & NODE_LINK_VALID) == 0) {
|
|
|
|
/* Skip links marked as cyclic. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (link->tonode && link->fromnode) {
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Is the link part of the chain meaning node_start == fromnode
|
|
|
|
* (or tonode for reversed case)? */
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((reversed && (link->tonode == node_start)) ||
|
|
|
|
(!reversed && link->fromnode == node_start)) {
|
|
|
|
if (!callback(link->fromnode, link->tonode, userdata, reversed)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nodeChainIter(
|
|
|
|
ntree, reversed ? link->fromnode : link->tonode, callback, userdata, reversed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
2019-09-30 13:09:39 +02:00
|
|
|
static void iter_backwards_ex(const bNodeTree *ntree,
|
|
|
|
const bNode *node_start,
|
|
|
|
bool (*callback)(bNode *, bNode *, void *),
|
2019-10-10 00:31:47 +02:00
|
|
|
void *userdata,
|
|
|
|
char recursion_mask)
|
2019-09-30 13:09:39 +02:00
|
|
|
{
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node_start->inputs) {
|
|
|
|
bNodeLink *link = sock->link;
|
|
|
|
if (link == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((link->flag & NODE_LINK_VALID) == 0) {
|
|
|
|
/* Skip links marked as cyclic. */
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-10 00:31:47 +02:00
|
|
|
if (link->fromnode->iter_flag & recursion_mask) {
|
2019-09-30 13:09:39 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
2019-10-10 00:31:47 +02:00
|
|
|
link->fromnode->iter_flag |= recursion_mask;
|
2019-09-30 13:09:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!callback(link->fromnode, link->tonode, userdata)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-10 00:31:47 +02:00
|
|
|
iter_backwards_ex(ntree, link->fromnode, callback, userdata, recursion_mask);
|
2019-09-30 13:09:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over a chain of nodes, starting with \a node_start, executing
|
|
|
|
* \a callback for each node (which can return false to end iterator).
|
|
|
|
*
|
|
|
|
* Faster than nodeChainIter. Iter only once per node.
|
2019-10-10 00:31:47 +02:00
|
|
|
* Can be called recursively (using another nodeChainIterBackwards) by
|
|
|
|
* setting the recursion_lvl accordingly.
|
2019-09-30 13:09:39 +02:00
|
|
|
*
|
|
|
|
* \note Needs updated socket links (ntreeUpdateTree).
|
|
|
|
* \note Recursive
|
|
|
|
*/
|
|
|
|
void nodeChainIterBackwards(const bNodeTree *ntree,
|
|
|
|
const bNode *node_start,
|
|
|
|
bool (*callback)(bNode *, bNode *, void *),
|
2019-10-10 00:31:47 +02:00
|
|
|
void *userdata,
|
|
|
|
int recursion_lvl)
|
2019-09-30 13:09:39 +02:00
|
|
|
{
|
2019-10-02 12:50:14 +02:00
|
|
|
if (!node_start) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-10 00:31:47 +02:00
|
|
|
/* Limited by iter_flag type. */
|
|
|
|
BLI_assert(recursion_lvl < 8);
|
|
|
|
char recursion_mask = (1 << recursion_lvl);
|
|
|
|
|
2019-09-30 13:09:39 +02:00
|
|
|
/* Reset flag. */
|
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-10-10 00:31:47 +02:00
|
|
|
node->iter_flag &= ~recursion_mask;
|
2019-09-30 13:09:39 +02:00
|
|
|
}
|
|
|
|
|
2019-10-10 00:31:47 +02:00
|
|
|
iter_backwards_ex(ntree, node_start, callback, userdata, recursion_mask);
|
2019-09-30 13:09:39 +02:00
|
|
|
}
|
|
|
|
|
2015-08-01 16:16:16 +02:00
|
|
|
/**
|
2019-04-27 12:07:07 +10:00
|
|
|
* Iterate over all parents of \a node, executing \a callback for each parent
|
|
|
|
* (which can return false to end iterator)
|
2018-06-01 18:19:39 +02:00
|
|
|
*
|
2015-08-01 16:16:16 +02:00
|
|
|
* \note Recursive
|
|
|
|
*/
|
|
|
|
void nodeParentsIter(bNode *node, bool (*callback)(bNode *, void *), void *userdata)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->parent) {
|
|
|
|
if (!callback(node->parent, userdata)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nodeParentsIter(node->parent, callback, userdata);
|
|
|
|
}
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* ************** Add stuff ********** */
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* Find the first available, non-duplicate name for a given node */
|
|
|
|
void nodeUniqueName(bNodeTree *ntree, bNode *node)
|
2009-11-11 09:11:21 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_uniquename(
|
|
|
|
&ntree->nodes, node, DATA_("Node"), '.', offsetof(bNode, name), sizeof(node->name));
|
2009-11-11 09:11:21 +00:00
|
|
|
}
|
2008-02-09 23:17:15 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
bNode *nodeAddNode(const struct bContext *C, bNodeTree *ntree, const char *idname)
|
2008-02-09 23:17:15 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node = MEM_callocN(sizeof(bNode), "new node");
|
|
|
|
BLI_addtail(&ntree->nodes, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(node->idname, idname, sizeof(node->idname));
|
|
|
|
node_set_typeinfo(C, ntree, node, nodeTypeFind(idname));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_NODES;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return node;
|
2008-02-09 23:17:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
bNode *nodeAddStaticNode(const struct bContext *C, bNodeTree *ntree, int type)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *idname = NULL;
|
|
|
|
|
|
|
|
NODE_TYPES_BEGIN (ntype) {
|
|
|
|
/* do an extra poll here, because some int types are used
|
|
|
|
* for multiple node types, this helps find the desired type
|
|
|
|
*/
|
|
|
|
if (ntype->type == type && (!ntype->poll || ntype->poll(ntype, ntree))) {
|
|
|
|
idname = ntype->idname;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NODE_TYPES_END;
|
|
|
|
if (!idname) {
|
|
|
|
CLOG_ERROR(&LOG, "static node type %d undefined", type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return nodeAddNode(C, ntree, idname);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-03 17:08:25 +02:00
|
|
|
static void node_socket_copy(bNodeSocket *sock_dst, const bNodeSocket *sock_src, const int flag)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sock_src->prop) {
|
|
|
|
sock_dst->prop = IDP_CopyProperty_ex(sock_src->prop, flag);
|
|
|
|
}
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sock_src->default_value) {
|
|
|
|
sock_dst->default_value = MEM_dupallocN(sock_src->default_value);
|
|
|
|
}
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sock_dst->stack_index = 0;
|
|
|
|
/* XXX some compositor node (e.g. image, render layers) still store
|
|
|
|
* some persistent buffer data here, need to clear this to avoid dangling pointers.
|
|
|
|
*/
|
|
|
|
sock_dst->cache = NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
/* keep socket listorder identical, for copying links */
|
|
|
|
/* ntree is the target tree */
|
2020-01-16 15:04:06 +01:00
|
|
|
/* unique_name needs to be true. It's only disabled for speed when doing GPUnodetrees. */
|
|
|
|
bNode *BKE_node_copy_ex(bNodeTree *ntree,
|
|
|
|
const bNode *node_src,
|
|
|
|
const int flag,
|
|
|
|
const bool unique_name)
|
2005-12-18 23:08:22 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node_dst = MEM_callocN(sizeof(bNode), "dupli node");
|
|
|
|
bNodeSocket *sock_dst, *sock_src;
|
|
|
|
bNodeLink *link_dst, *link_src;
|
|
|
|
|
|
|
|
*node_dst = *node_src;
|
|
|
|
/* can be called for nodes outside a node tree (e.g. clipboard) */
|
|
|
|
if (ntree) {
|
2020-01-16 15:04:06 +01:00
|
|
|
if (unique_name) {
|
|
|
|
nodeUniqueName(ntree, node_dst);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BLI_addtail(&ntree->nodes, node_dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_duplicatelist(&node_dst->inputs, &node_src->inputs);
|
|
|
|
for (sock_dst = node_dst->inputs.first, sock_src = node_src->inputs.first; sock_dst != NULL;
|
|
|
|
sock_dst = sock_dst->next, sock_src = sock_src->next) {
|
|
|
|
node_socket_copy(sock_dst, sock_src, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_duplicatelist(&node_dst->outputs, &node_src->outputs);
|
|
|
|
for (sock_dst = node_dst->outputs.first, sock_src = node_src->outputs.first; sock_dst != NULL;
|
|
|
|
sock_dst = sock_dst->next, sock_src = sock_src->next) {
|
|
|
|
node_socket_copy(sock_dst, sock_src, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node_src->prop) {
|
|
|
|
node_dst->prop = IDP_CopyProperty_ex(node_src->prop, flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_duplicatelist(&node_dst->internal_links, &node_src->internal_links);
|
|
|
|
for (link_dst = node_dst->internal_links.first, link_src = node_src->internal_links.first;
|
|
|
|
link_dst != NULL;
|
|
|
|
link_dst = link_dst->next, link_src = link_src->next) {
|
2019-06-03 17:08:25 +02:00
|
|
|
/* This is a bit annoying to do index lookups in a list, but is likely to be faster than
|
|
|
|
* trying to create a hash-map. At least for usual nodes, which only have so much sockets
|
|
|
|
* and internal links. */
|
|
|
|
const int from_sock_index = BLI_findindex(&node_src->inputs, link_src->fromsock);
|
|
|
|
const int to_sock_index = BLI_findindex(&node_src->outputs, link_src->tosock);
|
|
|
|
BLI_assert(from_sock_index != -1);
|
|
|
|
BLI_assert(to_sock_index != -1);
|
2019-04-17 06:17:24 +02:00
|
|
|
link_dst->fromnode = node_dst;
|
|
|
|
link_dst->tonode = node_dst;
|
2019-06-03 17:08:25 +02:00
|
|
|
link_dst->fromsock = BLI_findlink(&node_dst->inputs, from_sock_index);
|
|
|
|
link_dst->tosock = BLI_findlink(&node_dst->outputs, to_sock_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
|
|
|
|
id_us_plus(node_dst->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node_src->typeinfo->copyfunc) {
|
|
|
|
node_src->typeinfo->copyfunc(ntree, node_dst, node_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
node_dst->new_node = NULL;
|
|
|
|
|
2019-12-07 19:35:52 +01:00
|
|
|
/* Only call copy function when a copy is made for the main database, not
|
|
|
|
* for cases like the dependency graph and localization. */
|
|
|
|
if (node_dst->typeinfo->copyfunc_api && !(flag & LIB_ID_CREATE_NO_MAIN)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_Node, node_dst, &ptr);
|
|
|
|
|
|
|
|
node_dst->typeinfo->copyfunc_api(&ptr, node_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntree) {
|
|
|
|
ntree->update |= NTREE_UPDATE_NODES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return node_dst;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
|
|
|
|
2019-06-07 17:45:31 +02:00
|
|
|
static void node_set_new_pointers(bNode *node_src, bNode *new_node)
|
2019-06-03 17:08:25 +02:00
|
|
|
{
|
|
|
|
/* Store mapping to the node itself. */
|
|
|
|
node_src->new_node = new_node;
|
|
|
|
/* Store mapping to inputs. */
|
|
|
|
bNodeSocket *new_input_sock = new_node->inputs.first;
|
|
|
|
bNodeSocket *input_sock_src = node_src->inputs.first;
|
|
|
|
while (new_input_sock != NULL) {
|
|
|
|
input_sock_src->new_sock = new_input_sock;
|
|
|
|
new_input_sock = new_input_sock->next;
|
|
|
|
input_sock_src = input_sock_src->next;
|
|
|
|
}
|
|
|
|
/* Store mapping to outputs. */
|
|
|
|
bNodeSocket *new_output_sock = new_node->outputs.first;
|
|
|
|
bNodeSocket *output_sock_src = node_src->outputs.first;
|
|
|
|
while (new_output_sock != NULL) {
|
|
|
|
output_sock_src->new_sock = new_output_sock;
|
|
|
|
new_output_sock = new_output_sock->next;
|
|
|
|
output_sock_src = output_sock_src->next;
|
|
|
|
}
|
2019-06-07 17:45:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bNode *BKE_node_copy_store_new_pointers(bNodeTree *ntree, bNode *node_src, const int flag)
|
|
|
|
{
|
2020-01-16 15:04:06 +01:00
|
|
|
bNode *new_node = BKE_node_copy_ex(ntree, node_src, flag, true);
|
2019-06-07 17:45:31 +02:00
|
|
|
node_set_new_pointers(node_src, new_node);
|
2019-06-03 17:08:25 +02:00
|
|
|
return new_node;
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:45:31 +02:00
|
|
|
bNodeTree *ntreeCopyTree_ex_new_pointers(const bNodeTree *ntree,
|
|
|
|
Main *bmain,
|
|
|
|
const bool do_id_user)
|
|
|
|
{
|
2019-08-22 16:00:59 +02:00
|
|
|
bNodeTree *new_ntree = ntreeCopyTree_ex(ntree, bmain, do_id_user);
|
2019-06-07 17:45:31 +02:00
|
|
|
bNode *new_node = new_ntree->nodes.first;
|
|
|
|
bNode *node_src = ntree->nodes.first;
|
|
|
|
while (new_node != NULL) {
|
|
|
|
node_set_new_pointers(node_src, new_node);
|
|
|
|
new_node = new_node->next;
|
|
|
|
node_src = node_src->next;
|
|
|
|
}
|
|
|
|
return new_ntree;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:16:08 +00:00
|
|
|
/* also used via rna api, so we check for proper input output direction */
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *nodeAddLink(
|
|
|
|
bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, bNode *tonode, bNodeSocket *tosock)
|
|
|
|
{
|
|
|
|
bNodeLink *link = NULL;
|
|
|
|
|
|
|
|
/* test valid input */
|
|
|
|
BLI_assert(fromnode);
|
|
|
|
BLI_assert(tonode);
|
|
|
|
|
|
|
|
if (fromsock->in_out == SOCK_OUT && tosock->in_out == SOCK_IN) {
|
|
|
|
link = MEM_callocN(sizeof(bNodeLink), "link");
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(&ntree->links, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
link->fromnode = fromnode;
|
|
|
|
link->fromsock = fromsock;
|
|
|
|
link->tonode = tonode;
|
|
|
|
link->tosock = tosock;
|
|
|
|
}
|
|
|
|
else if (fromsock->in_out == SOCK_IN && tosock->in_out == SOCK_OUT) {
|
|
|
|
/* OK but flip */
|
|
|
|
link = MEM_callocN(sizeof(bNodeLink), "link");
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(&ntree->links, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
link->fromnode = tonode;
|
|
|
|
link->fromsock = tosock;
|
|
|
|
link->tonode = fromnode;
|
|
|
|
link->tosock = fromsock;
|
|
|
|
}
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return link;
|
2005-12-18 23:08:22 +00:00
|
|
|
}
|
2005-12-18 13:46:01 +00:00
|
|
|
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
void nodeRemLink(bNodeTree *ntree, bNodeLink *link)
|
2005-12-20 15:43:55 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* can be called for links outside a node tree (e.g. clipboard) */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_remlink(&ntree->links, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-08-02 09:52:37 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->tosock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->tosock->link = NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(link);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 04:26:28 +00:00
|
|
|
void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link, *next;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = next) {
|
|
|
|
next = link->next;
|
|
|
|
if (link->fromsock == sock || link->tosock == sock) {
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2010-01-04 04:26:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 19:54:28 +11:00
|
|
|
bool nodeLinkIsHidden(bNodeLink *link)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return nodeSocketIsHidden(link->fromsock) || nodeSocketIsHidden(link->tosock);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2012-02-27 17:38:16 +00:00
|
|
|
void nodeInternalRelink(bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link, *link_next;
|
|
|
|
|
|
|
|
/* store link pointers in output sockets, for efficient lookup */
|
2019-04-22 09:39:35 +10:00
|
|
|
for (link = node->internal_links.first; link; link = link->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->tosock->link = link;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* redirect downstream links */
|
|
|
|
for (link = ntree->links.first; link; link = link_next) {
|
|
|
|
link_next = link->next;
|
|
|
|
|
|
|
|
/* do we have internal link? */
|
|
|
|
if (link->fromnode == node) {
|
|
|
|
if (link->fromsock->link) {
|
|
|
|
/* get the upstream input link */
|
|
|
|
bNodeLink *fromlink = link->fromsock->link->fromsock->link;
|
|
|
|
/* skip the node */
|
|
|
|
if (fromlink) {
|
|
|
|
link->fromnode = fromlink->fromnode;
|
|
|
|
link->fromsock = fromlink->fromsock;
|
|
|
|
|
|
|
|
/* if the up- or downstream link is invalid,
|
|
|
|
* the replacement link will be invalid too.
|
|
|
|
*/
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!(fromlink->flag & NODE_LINK_VALID)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->flag &= ~NODE_LINK_VALID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeRemLink(ntree, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeRemLink(ntree, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove remaining upstream links */
|
|
|
|
for (link = ntree->links.first; link; link = link_next) {
|
|
|
|
link_next = link->next;
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->tonode == node) {
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeRemLink(ntree, link);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-02-27 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
void nodeToView(bNode *node, float x, float y, float *rx, float *ry)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->parent) {
|
|
|
|
nodeToView(node->parent, x + node->locx, y + node->locy, rx, ry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*rx = x + node->locx;
|
|
|
|
*ry = y + node->locy;
|
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nodeFromView(bNode *node, float x, float y, float *rx, float *ry)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->parent) {
|
|
|
|
nodeFromView(node->parent, x, y, rx, ry);
|
|
|
|
*rx -= node->locx;
|
|
|
|
*ry -= node->locy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*rx = x - node->locx;
|
|
|
|
*ry = y - node->locy;
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
bool nodeAttachNodeCheck(bNode *node, bNode *parent)
|
2012-08-05 20:40:26 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *parent_recurse;
|
|
|
|
for (parent_recurse = node; parent_recurse; parent_recurse = parent_recurse->parent) {
|
|
|
|
if (parent_recurse == parent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-08-05 20:40:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2012-08-05 20:40:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void nodeAttachNode(bNode *node, bNode *parent)
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float locx, locy;
|
2012-08-05 20:40:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(parent->type == NODE_FRAME);
|
|
|
|
BLI_assert(nodeAttachNodeCheck(parent, node) == false);
|
2012-08-05 20:40:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeToView(node, 0.0f, 0.0f, &locx, &locy);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->parent = parent;
|
|
|
|
/* transform to parent space */
|
|
|
|
nodeFromView(parent, locx, locy, &node->locx, &node->locy);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2010-12-03 03:44:39 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void nodeDetachNode(struct bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float locx, locy;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->parent) {
|
2012-08-05 20:40:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(node->parent->type == NODE_FRAME);
|
2012-08-05 20:40:26 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* transform to view space */
|
|
|
|
nodeToView(node, 0.0f, 0.0f, &locx, &locy);
|
|
|
|
node->locx = locx;
|
|
|
|
node->locy = locy;
|
|
|
|
node->parent = NULL;
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void nodePositionRelative(bNode *from_node,
|
|
|
|
bNode *to_node,
|
|
|
|
bNodeSocket *from_sock,
|
|
|
|
bNodeSocket *to_sock)
|
2018-09-20 19:53:16 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float offset_x;
|
|
|
|
int tot_sock_idx;
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Socket to plug into. */
|
|
|
|
if (SOCK_IN == to_sock->in_out) {
|
|
|
|
offset_x = -(from_node->typeinfo->width + 50);
|
|
|
|
tot_sock_idx = BLI_listbase_count(&to_node->outputs);
|
|
|
|
tot_sock_idx += BLI_findindex(&to_node->inputs, to_sock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
offset_x = to_node->typeinfo->width + 50;
|
|
|
|
tot_sock_idx = BLI_findindex(&to_node->outputs, to_sock);
|
|
|
|
}
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(tot_sock_idx != -1);
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
float offset_y = U.widget_unit * tot_sock_idx;
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Output socket. */
|
|
|
|
if (from_sock) {
|
|
|
|
if (SOCK_IN == from_sock->in_out) {
|
|
|
|
tot_sock_idx = BLI_listbase_count(&from_node->outputs);
|
|
|
|
tot_sock_idx += BLI_findindex(&from_node->inputs, from_sock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tot_sock_idx = BLI_findindex(&from_node->outputs, from_sock);
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(tot_sock_idx != -1);
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
offset_y -= U.widget_unit * tot_sock_idx;
|
2018-09-20 19:53:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
from_node->locx = to_node->locx + offset_x;
|
|
|
|
from_node->locy = to_node->locy - offset_y;
|
2018-09-20 19:53:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void nodePositionPropagate(bNode *node)
|
|
|
|
{
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (nsock->link != NULL) {
|
|
|
|
bNodeLink *link = nsock->link;
|
|
|
|
nodePositionRelative(link->fromnode, link->tonode, link->fromsock, link->tosock);
|
|
|
|
nodePositionPropagate(link->fromnode);
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 19:53:16 +02:00
|
|
|
}
|
|
|
|
|
2019-08-22 16:00:59 +02:00
|
|
|
bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeTree *ntree;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* trees are created as local trees for compositor, material or texture nodes,
|
|
|
|
* node groups and other tree types are created as library data.
|
|
|
|
*/
|
|
|
|
if (bmain) {
|
|
|
|
ntree = BKE_libblock_alloc(bmain, ID_NT, name, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ntree = MEM_callocN(sizeof(bNodeTree), "new node tree");
|
2020-03-11 12:47:25 +01:00
|
|
|
ntree->id.flag |= LIB_EMBEDDED_DATA;
|
2019-04-17 06:17:24 +02:00
|
|
|
*((short *)ntree->id.name) = ID_NT;
|
|
|
|
BLI_strncpy(ntree->id.name + 2, name, sizeof(ntree->id.name));
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Types are fully initialized at this point,
|
|
|
|
* if an undefined node is added later this will be reset.
|
|
|
|
*/
|
|
|
|
ntree->init |= NTREE_TYPE_INIT;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(ntree->idname, idname, sizeof(ntree->idname));
|
|
|
|
ntree_set_typeinfo(ntree, ntreeTypeFind(idname));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ntree;
|
2005-12-20 15:43:55 +00:00
|
|
|
}
|
2005-12-18 13:46:01 +00:00
|
|
|
|
2019-08-22 16:00:59 +02:00
|
|
|
bNodeTree *ntreeCopyTree_ex(const bNodeTree *ntree, Main *bmain, const bool do_id_user)
|
2012-08-22 08:54:18 +00:00
|
|
|
{
|
2019-08-22 16:00:59 +02:00
|
|
|
bNodeTree *ntree_copy;
|
2020-01-05 16:46:11 +01:00
|
|
|
const int flag = do_id_user ? 0 : LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_MAIN;
|
2019-08-22 16:00:59 +02:00
|
|
|
BKE_id_copy_ex(bmain, (ID *)ntree, (ID **)&ntree_copy, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
return ntree_copy;
|
2012-08-22 08:54:18 +00:00
|
|
|
}
|
2019-08-22 16:00:59 +02:00
|
|
|
bNodeTree *ntreeCopyTree(Main *bmain, const bNodeTree *ntree)
|
2012-07-05 12:50:50 +00:00
|
|
|
{
|
2019-08-22 16:00:59 +02:00
|
|
|
return ntreeCopyTree_ex(ntree, bmain, true);
|
2012-07-05 12:50:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* *************** Node Preview *********** */
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX this should be removed eventually ...
|
2017-11-05 14:33:18 +11:00
|
|
|
* Currently BKE functions are modeled closely on previous code,
|
2013-03-18 16:34:57 +00:00
|
|
|
* using BKE_node_preview_init_tree to set up previews for a whole node tree in advance.
|
|
|
|
* This should be left more to the individual node tree implementations.
|
|
|
|
*/
|
|
|
|
int BKE_node_preview_used(bNode *node)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX check for closed nodes? */
|
|
|
|
return (node->typeinfo->flag & NODE_PREVIEW) != 0;
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodePreview *BKE_node_preview_verify(
|
|
|
|
bNodeInstanceHash *previews, bNodeInstanceKey key, int xsize, int ysize, bool create)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodePreview *preview;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
preview = BKE_node_instance_hash_lookup(previews, key);
|
|
|
|
if (!preview) {
|
|
|
|
if (create) {
|
|
|
|
preview = MEM_callocN(sizeof(bNodePreview), "node preview");
|
|
|
|
BKE_node_instance_hash_insert(previews, key, preview);
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* node previews can get added with variable size this way */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (xsize == 0 || ysize == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return preview;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* sanity checks & initialize */
|
|
|
|
if (preview->rect) {
|
|
|
|
if (preview->xsize != xsize || preview->ysize != ysize) {
|
|
|
|
MEM_freeN(preview->rect);
|
|
|
|
preview->rect = NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (preview->rect == NULL) {
|
|
|
|
preview->rect = MEM_callocN(4 * xsize + xsize * ysize * sizeof(char) * 4, "node preview rect");
|
|
|
|
preview->xsize = xsize;
|
|
|
|
preview->ysize = ysize;
|
|
|
|
}
|
|
|
|
/* no clear, makes nicer previews */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return preview;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bNodePreview *BKE_node_preview_copy(bNodePreview *preview)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodePreview *new_preview = MEM_dupallocN(preview);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (preview->rect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
new_preview->rect = MEM_dupallocN(preview->rect);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return new_preview;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_free(bNodePreview *preview)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (preview->rect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(preview->rect);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(preview);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void node_preview_init_tree_recursive(bNodeInstanceHash *previews,
|
|
|
|
bNodeTree *ntree,
|
|
|
|
bNodeInstanceKey parent_key,
|
|
|
|
int xsize,
|
|
|
|
int ysize,
|
|
|
|
int create)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_node_preview_used(node)) {
|
|
|
|
node->preview_xsize = xsize;
|
|
|
|
node->preview_ysize = ysize;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_preview_verify(previews, key, xsize, ysize, create);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->type == NODE_GROUP && node->id) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_preview_init_tree_recursive(previews, (bNodeTree *)node->id, key, xsize, ysize, create);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void BKE_node_preview_init_tree(bNodeTree *ntree, int xsize, int ysize, int create_previews)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->previews = BKE_node_instance_hash_new("node previews");
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_preview_init_tree_recursive(
|
|
|
|
ntree->previews, ntree, NODE_INSTANCE_KEY_BASE, xsize, ysize, create_previews);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void node_preview_tag_used_recursive(bNodeInstanceHash *previews,
|
|
|
|
bNodeTree *ntree,
|
|
|
|
bNodeInstanceKey parent_key)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (BKE_node_preview_used(node)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_instance_hash_tag_key(previews, key);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->type == NODE_GROUP && node->id) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_preview_tag_used_recursive(previews, (bNodeTree *)node->id, key);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_remove_unused(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree || !ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* use the instance hash functions for tagging and removing unused previews */
|
|
|
|
BKE_node_instance_hash_clear_tags(ntree->previews);
|
|
|
|
node_preview_tag_used_recursive(ntree->previews, ntree, NODE_INSTANCE_KEY_BASE);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_instance_hash_remove_untagged(ntree->previews,
|
|
|
|
(bNodeInstanceValueFP)BKE_node_preview_free);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_free_tree(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->previews) {
|
|
|
|
BKE_node_instance_hash_free(ntree->previews, (bNodeInstanceValueFP)BKE_node_preview_free);
|
|
|
|
ntree->previews = NULL;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_clear(bNodePreview *preview)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (preview && preview->rect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(preview->rect, 0, MEM_allocN_len(preview->rect));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_clear_tree(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashIterator iter;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree || !ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-21 04:40:16 +10:00
|
|
|
NODE_INSTANCE_HASH_ITER (iter, ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter);
|
|
|
|
BKE_node_preview_clear(preview);
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void node_preview_sync(bNodePreview *to, bNodePreview *from)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* sizes should have been initialized by BKE_node_preview_init_tree */
|
|
|
|
BLI_assert(to->xsize == from->xsize && to->ysize == from->ysize);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* copy over contents of previews */
|
|
|
|
if (to->rect && from->rect) {
|
|
|
|
int xsize = to->xsize;
|
|
|
|
int ysize = to->ysize;
|
|
|
|
memcpy(to->rect, from->rect, xsize * ysize * sizeof(char) * 4);
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_preview_sync_tree(bNodeTree *to_ntree, bNodeTree *from_ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHash *from_previews = from_ntree->previews;
|
|
|
|
bNodeInstanceHash *to_previews = to_ntree->previews;
|
|
|
|
bNodeInstanceHashIterator iter;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!from_previews || !to_previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-21 04:40:16 +10:00
|
|
|
NODE_INSTANCE_HASH_ITER (iter, from_previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter);
|
|
|
|
bNodePreview *from = BKE_node_instance_hash_iterator_get_value(&iter);
|
|
|
|
bNodePreview *to = BKE_node_instance_hash_lookup(to_previews, key);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (from && to) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node_preview_sync(to, from);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 10:34:52 +00:00
|
|
|
void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, bool remove_old)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (remove_old || !to_ntree->previews) {
|
|
|
|
/* free old previews */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (to_ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_instance_hash_free(to_ntree->previews, (bNodeInstanceValueFP)BKE_node_preview_free);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* transfer previews */
|
|
|
|
to_ntree->previews = from_ntree->previews;
|
|
|
|
from_ntree->previews = NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clean up, in case any to_ntree nodes have been removed */
|
|
|
|
BKE_node_preview_remove_unused(to_ntree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bNodeInstanceHashIterator iter;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (from_ntree->previews) {
|
2019-04-21 04:40:16 +10:00
|
|
|
NODE_INSTANCE_HASH_ITER (iter, from_ntree->previews) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter);
|
|
|
|
bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* replace existing previews */
|
|
|
|
BKE_node_instance_hash_remove(
|
|
|
|
to_ntree->previews, key, (bNodeInstanceValueFP)BKE_node_preview_free);
|
|
|
|
BKE_node_instance_hash_insert(to_ntree->previews, key, preview);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Note: NULL free function here,
|
|
|
|
* because pointers have already been moved over to to_ntree->previews! */
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_instance_hash_free(from_ntree->previews, NULL);
|
|
|
|
from_ntree->previews = NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
/* hack warning! this function is only used for shader previews, and
|
2013-03-18 16:34:57 +00:00
|
|
|
* since it gets called multiple times per pixel for Ztransp we only
|
|
|
|
* add the color once. Preview gets cleared before it starts render though */
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_node_preview_set_pixel(
|
|
|
|
bNodePreview *preview, const float col[4], int x, int y, bool do_manage)
|
|
|
|
{
|
|
|
|
if (preview) {
|
|
|
|
if (x >= 0 && y >= 0) {
|
|
|
|
if (x < preview->xsize && y < preview->ysize) {
|
|
|
|
unsigned char *tar = preview->rect + 4 * ((preview->xsize * y) + x);
|
|
|
|
|
|
|
|
if (do_manage) {
|
|
|
|
linearrgb_to_srgb_uchar4(tar, col);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rgba_float_to_uchar(tar, col);
|
|
|
|
}
|
|
|
|
}
|
2019-05-01 11:09:22 +10:00
|
|
|
// else printf("prv out bound x y %d %d\n", x, y);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-01 11:09:22 +10:00
|
|
|
// else printf("prv out bound x y %d %d\n", x, y);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2006-12-30 16:35:46 +00:00
|
|
|
/* ************** Free stuff ********** */
|
2005-12-18 13:46:01 +00:00
|
|
|
|
|
|
|
/* goes over entire tree */
|
2007-12-27 10:17:33 +00:00
|
|
|
void nodeUnlinkNode(bNodeTree *ntree, bNode *node)
|
2005-12-18 13:46:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link, *next;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
ListBase *lb;
|
|
|
|
|
|
|
|
for (link = ntree->links.first; link; link = next) {
|
|
|
|
next = link->next;
|
|
|
|
|
|
|
|
if (link->fromnode == node) {
|
|
|
|
lb = &node->outputs;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->tonode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->tonode->update |= NODE_UPDATE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else if (link->tonode == node) {
|
2019-04-17 06:17:24 +02:00
|
|
|
lb = &node->inputs;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
lb = NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (lb) {
|
|
|
|
for (sock = lb->first; sock; sock = sock->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->fromsock == sock || link->tosock == sock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (sock) {
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-18 13:46:01 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static void node_unlink_attached(bNodeTree *ntree, bNode *parent)
|
2006-01-28 15:21:04 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->parent == parent) {
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeDetachNode(node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2006-01-28 15:21:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:54:00 +01:00
|
|
|
/* Free the node itself. ID user refcounting is up the caller,
|
|
|
|
* that does not happen here. */
|
|
|
|
static void node_free_node(bNodeTree *ntree, bNode *node)
|
2005-12-18 13:46:01 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *sock, *nextsock;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* since it is called while free database, node->id is undefined */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* can be called for nodes outside a node tree (e.g. clipboard) */
|
|
|
|
if (ntree) {
|
|
|
|
/* remove all references to this node */
|
|
|
|
nodeUnlinkNode(ntree, node);
|
|
|
|
node_unlink_attached(ntree, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_remlink(&ntree->nodes, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->free_node_cache) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->free_node_cache(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* texture node has bad habit of keeping exec data around */
|
|
|
|
if (ntree->type == NTREE_TEXTURE && ntree->execdata) {
|
|
|
|
ntreeTexEndExecTree(ntree->execdata);
|
|
|
|
ntree->execdata = NULL;
|
|
|
|
}
|
|
|
|
}
|
2017-07-11 11:06:36 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->typeinfo->freefunc) {
|
|
|
|
node->typeinfo->freefunc(node);
|
|
|
|
}
|
2017-07-11 11:06:36 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (sock = node->inputs.first; sock; sock = nextsock) {
|
|
|
|
nextsock = sock->next;
|
|
|
|
/* Remember, no ID user refcount management here! */
|
|
|
|
node_socket_free(ntree, sock, node, false);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = nextsock) {
|
|
|
|
nextsock = sock->next;
|
|
|
|
/* Remember, no ID user refcount management here! */
|
|
|
|
node_socket_free(ntree, sock, node, false);
|
|
|
|
MEM_freeN(sock);
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelistN(&node->internal_links);
|
2012-10-25 16:49:06 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->prop) {
|
|
|
|
/* Remember, no ID user refcount management here! */
|
2019-05-16 14:17:11 +02:00
|
|
|
IDP_FreePropertyContent_ex(node->prop, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(node->prop);
|
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_NODES;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-12-18 13:46:01 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:54:00 +01:00
|
|
|
void ntreeFreeLocalNode(bNodeTree *ntree, bNode *node)
|
2013-12-05 15:02:17 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* For removing nodes while editing localized node trees. */
|
|
|
|
BLI_assert((ntree->id.tag & LIB_TAG_LOCALIZED) != 0);
|
|
|
|
node_free_node(ntree, node);
|
2018-11-23 17:02:55 +01:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:54:00 +01:00
|
|
|
void nodeRemoveNode(Main *bmain, bNodeTree *ntree, bNode *node, bool do_id_user)
|
2018-11-23 17:02:55 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* This function is not for localized node trees, we do not want
|
|
|
|
* do to ID user refcounting and removal of animdation data then. */
|
|
|
|
BLI_assert((ntree->id.tag & LIB_TAG_LOCALIZED) == 0);
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (do_id_user) {
|
|
|
|
/* Free callback for NodeCustomGroup. */
|
|
|
|
if (node->typeinfo->freefunc_api) {
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr);
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->typeinfo->freefunc_api(&ptr);
|
|
|
|
}
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Do user counting. */
|
|
|
|
if (node->id) {
|
|
|
|
id_us_min(node->id);
|
|
|
|
}
|
|
|
|
}
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Remove animation data. */
|
|
|
|
char propname_esc[MAX_IDPROP_NAME * 2];
|
|
|
|
char prefix[MAX_IDPROP_NAME * 2];
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strescape(propname_esc, node->name, sizeof(propname_esc));
|
|
|
|
BLI_snprintf(prefix, sizeof(prefix), "nodes[\"%s\"]", propname_esc);
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BKE_animdata_fix_paths_remove((ID *)ntree, prefix)) {
|
|
|
|
if (bmain != NULL) {
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
}
|
2019-03-16 18:54:00 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Free node itself. */
|
|
|
|
node_free_node(ntree, node);
|
2013-12-05 15:02:17 +01:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void node_socket_interface_free(bNodeTree *UNUSED(ntree), bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (sock->prop) {
|
|
|
|
IDP_FreeProperty(sock->prop);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (sock->default_value) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(sock->default_value);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 09:29:56 +00:00
|
|
|
static void free_localized_node_groups(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Only localized node trees store a copy for each node group tree.
|
|
|
|
* Each node group tree in a localized node tree can be freed,
|
|
|
|
* since it is a localized copy itself (no risk of accessing free'd
|
|
|
|
* data in main, see [#37939]).
|
|
|
|
*/
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!(ntree->id.tag & LIB_TAG_LOCALIZED)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if ((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id) {
|
|
|
|
bNodeTree *ngroup = (bNodeTree *)node->id;
|
|
|
|
ntreeFreeTree(ngroup);
|
|
|
|
MEM_freeN(ngroup);
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 09:29:56 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:54:00 +01:00
|
|
|
/* Free (or release) any data used by this nodetree. Does not free the
|
|
|
|
* nodetree itself and does no ID user counting. */
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
void ntreeFreeTree(bNodeTree *ntree)
|
2005-12-18 13:46:01 +00:00
|
|
|
{
|
2020-03-06 14:57:26 +01:00
|
|
|
ntree_free_data(&ntree->id);
|
2020-03-09 18:40:06 +01:00
|
|
|
BKE_animdata_free(&ntree->id, false);
|
2018-12-14 15:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ntreeFreeNestedTree(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeFreeTree(ntree);
|
|
|
|
BKE_libblock_free_data(&ntree->id, true);
|
2018-12-14 15:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ntreeFreeLocalTree(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->id.tag & LIB_TAG_LOCALIZED) {
|
|
|
|
ntreeFreeTree(ntree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ntreeFreeTree(ntree);
|
|
|
|
BKE_libblock_free_data(&ntree->id, true);
|
|
|
|
}
|
2005-12-18 13:46:01 +00:00
|
|
|
}
|
|
|
|
|
2006-02-08 17:30:28 +00:00
|
|
|
void ntreeFreeCache(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->free_cache) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->free_cache(ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2006-02-11 23:17:41 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void ntreeSetOutput(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* find the active outputs, might become tree type dependent handler */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) {
|
|
|
|
bNode *tnode;
|
|
|
|
int output = 0;
|
|
|
|
|
|
|
|
/* we need a check for which output node should be tagged like this, below an exception */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->type == CMP_NODE_OUTPUT_FILE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* there is more types having output class, each one is checked */
|
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
|
|
|
|
if (tnode->typeinfo->nclass == NODE_CLASS_OUTPUT) {
|
|
|
|
|
|
|
|
if (ntree->type == NTREE_COMPOSIT) {
|
|
|
|
|
|
|
|
/* same type, exception for viewer */
|
|
|
|
if (tnode->type == node->type ||
|
|
|
|
(ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER) &&
|
|
|
|
ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))) {
|
|
|
|
if (tnode->flag & NODE_DO_OUTPUT) {
|
|
|
|
output++;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (output > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* same type */
|
|
|
|
if (tnode->type == node->type) {
|
|
|
|
if (tnode->flag & NODE_DO_OUTPUT) {
|
|
|
|
output++;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (output > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
if (output == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* group node outputs use this flag too */
|
|
|
|
if (node->type == NODE_GROUP_OUTPUT) {
|
|
|
|
bNode *tnode;
|
|
|
|
int output = 0;
|
|
|
|
|
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
|
|
|
|
if (tnode->type == NODE_GROUP_OUTPUT) {
|
|
|
|
if (tnode->flag & NODE_DO_OUTPUT) {
|
|
|
|
output++;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (output > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
if (output == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* here we could recursively set which nodes have to be done,
|
|
|
|
* might be different for editor or for "real" use... */
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 16:24:19 +01:00
|
|
|
/** Get address of potential nodetree pointer of given ID.
|
|
|
|
*
|
|
|
|
* \warning Using this function directly is potentially dangerous, if you don't know or are not
|
|
|
|
* sure, please use `ntreeFromID()` instead. */
|
|
|
|
bNodeTree **BKE_ntree_ptr_from_id(ID *id)
|
2012-12-03 16:21:43 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_MA:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((Material *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_LA:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((Light *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_WO:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((World *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_TE:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((Tex *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_SCE:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((Scene *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID_LS:
|
2020-02-06 16:24:19 +01:00
|
|
|
return &((FreestyleLineStyle *)id)->nodetree;
|
2019-04-17 06:17:24 +02:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-12-03 16:21:43 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 16:24:19 +01:00
|
|
|
/* Returns the private NodeTree object of the datablock, if it has one. */
|
|
|
|
bNodeTree *ntreeFromID(ID *id)
|
|
|
|
{
|
|
|
|
bNodeTree **nodetree = BKE_ntree_ptr_from_id(id);
|
|
|
|
return (nodetree != NULL) ? *nodetree : NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-22 20:43:19 +03:00
|
|
|
/* Finds and returns the datablock that privately owns the given tree, or NULL. */
|
|
|
|
ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree)
|
|
|
|
{
|
|
|
|
ListBase *lists[] = {&bmain->materials,
|
|
|
|
&bmain->lights,
|
|
|
|
&bmain->worlds,
|
|
|
|
&bmain->textures,
|
|
|
|
&bmain->scenes,
|
|
|
|
&bmain->linestyles,
|
|
|
|
NULL};
|
|
|
|
|
|
|
|
for (int i = 0; lists[i] != NULL; i++) {
|
|
|
|
LISTBASE_FOREACH (ID *, id, lists[i]) {
|
|
|
|
if (ntreeFromID(id) == ntree) {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
int ntreeNodeExists(bNodeTree *ntree, bNode *testnode)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node = ntree->nodes.first;
|
2019-04-22 09:39:35 +10:00
|
|
|
for (; node; node = node->next) {
|
|
|
|
if (node == testnode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ntreeOutputExists(bNode *node, bNodeSocket *testsock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *sock = node->outputs.first;
|
2019-04-22 09:39:35 +10:00
|
|
|
for (; sock; sock = sock->next) {
|
|
|
|
if (sock == testsock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2015-08-01 16:16:16 +02:00
|
|
|
void ntreeNodeFlagSet(const bNodeTree *ntree, const int flag, const bool enable)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node = ntree->nodes.first;
|
2015-08-01 16:16:16 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (; node; node = node->next) {
|
|
|
|
if (enable) {
|
|
|
|
node->flag |= flag;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->flag &= ~flag;
|
|
|
|
}
|
|
|
|
}
|
2015-08-01 16:16:16 +02:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* returns localized tree for execution in threads */
|
|
|
|
bNodeTree *ntreeLocalize(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree) {
|
|
|
|
bNodeTree *ltree;
|
|
|
|
bNode *node;
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Make full copy outside of Main database.
|
|
|
|
* Note: previews are not copied here.
|
|
|
|
*/
|
|
|
|
BKE_id_copy_ex(
|
|
|
|
NULL, &ntree->id, (ID **)<ree, (LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA));
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ltree->id.tag |= LIB_TAG_LOCALIZED;
|
2019-03-20 18:17:24 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ltree->nodes.first; node; node = node->next) {
|
|
|
|
if ((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id) {
|
|
|
|
node->id = (ID *)ntreeLocalize((bNodeTree *)node->id);
|
|
|
|
}
|
|
|
|
}
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ensures only a single output node is enabled */
|
|
|
|
ntreeSetOutput(ntree);
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-06-03 17:08:25 +02:00
|
|
|
bNode *node_src = ntree->nodes.first;
|
|
|
|
bNode *node_local = ltree->nodes.first;
|
|
|
|
while (node_src != NULL) {
|
|
|
|
node_local->original = node_src;
|
|
|
|
node_src = node_src->next;
|
|
|
|
node_local = node_local->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->localize) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->localize(ltree, ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2015-06-26 14:47:53 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ltree;
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* sync local composite with real tree */
|
|
|
|
/* local tree is supposed to be running, be careful moving previews! */
|
2018-09-24 17:27:41 +02:00
|
|
|
/* is called by jobs manager, outside threads, so it doesn't happen during draw */
|
2013-03-18 16:34:57 +00:00
|
|
|
void ntreeLocalSync(bNodeTree *localtree, bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (localtree && ntree) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->local_sync) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->local_sync(localtree, ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* merge local tree results back, and free local tree */
|
|
|
|
/* we have to assume the editor already changed completely */
|
2018-06-11 15:40:37 +02:00
|
|
|
void ntreeLocalMerge(Main *bmain, bNodeTree *localtree, bNodeTree *ntree)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree && localtree) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->local_merge) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->local_merge(bmain, localtree, ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeFreeTree(localtree);
|
|
|
|
MEM_freeN(localtree);
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************ NODE TREE INTERFACE *************** */
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bNodeSocket *make_socket_interface(bNodeTree *ntree,
|
|
|
|
int in_out,
|
|
|
|
const char *idname,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
bNodeSocketType *stype = nodeSocketTypeFind(idname);
|
|
|
|
bNodeSocket *sock;
|
|
|
|
int own_index = ntree->cur_index++;
|
|
|
|
|
|
|
|
if (stype == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = MEM_callocN(sizeof(bNodeSocket), "socket template");
|
|
|
|
BLI_strncpy(sock->idname, stype->idname, sizeof(sock->idname));
|
|
|
|
node_socket_set_typeinfo(ntree, sock, stype);
|
|
|
|
sock->in_out = in_out;
|
|
|
|
sock->type = SOCK_CUSTOM; /* int type undefined by default */
|
|
|
|
|
|
|
|
/* assign new unique index */
|
|
|
|
own_index = ntree->cur_index++;
|
|
|
|
/* use the own_index as socket identifier */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (in_out == SOCK_IN) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_snprintf(sock->identifier, MAX_NAME, "Input_%d", own_index);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_snprintf(sock->identifier, MAX_NAME, "Output_%d", own_index);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(sock->name, name, NODE_MAXSTR);
|
|
|
|
sock->storage = NULL;
|
|
|
|
sock->flag |= SOCK_COLLAPSED;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return sock;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeSocket *ntreeFindSocketInterface(bNodeTree *ntree, int in_out, const char *identifier)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *iosock = (in_out == SOCK_IN ? ntree->inputs.first : ntree->outputs.first);
|
2019-04-22 09:39:35 +10:00
|
|
|
for (; iosock; iosock = iosock->next) {
|
|
|
|
if (STREQ(iosock->identifier, identifier)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return iosock;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *ntreeAddSocketInterface(bNodeTree *ntree,
|
|
|
|
int in_out,
|
|
|
|
const char *idname,
|
|
|
|
const char *name)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *iosock;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
iosock = make_socket_interface(ntree, in_out, idname, name);
|
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
BLI_addtail(&ntree->inputs, iosock);
|
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_IN;
|
|
|
|
}
|
|
|
|
else if (in_out == SOCK_OUT) {
|
|
|
|
BLI_addtail(&ntree->outputs, iosock);
|
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_OUT;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return iosock;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *ntreeInsertSocketInterface(
|
|
|
|
bNodeTree *ntree, int in_out, const char *idname, bNodeSocket *next_sock, const char *name)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *iosock;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
iosock = make_socket_interface(ntree, in_out, idname, name);
|
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
BLI_insertlinkbefore(&ntree->inputs, next_sock, iosock);
|
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_IN;
|
|
|
|
}
|
|
|
|
else if (in_out == SOCK_OUT) {
|
|
|
|
BLI_insertlinkbefore(&ntree->outputs, next_sock, iosock);
|
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_OUT;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return iosock;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
struct bNodeSocket *ntreeAddSocketInterfaceFromSocket(bNodeTree *ntree,
|
|
|
|
bNode *from_node,
|
|
|
|
bNodeSocket *from_sock)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *iosock = ntreeAddSocketInterface(
|
|
|
|
ntree, from_sock->in_out, from_sock->idname, from_sock->name);
|
|
|
|
if (iosock) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (iosock->typeinfo->interface_from_socket) {
|
2019-04-17 06:17:24 +02:00
|
|
|
iosock->typeinfo->interface_from_socket(ntree, iosock, from_node, from_sock);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return iosock;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
struct bNodeSocket *ntreeInsertSocketInterfaceFromSocket(bNodeTree *ntree,
|
|
|
|
bNodeSocket *next_sock,
|
|
|
|
bNode *from_node,
|
|
|
|
bNodeSocket *from_sock)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocket *iosock = ntreeInsertSocketInterface(
|
|
|
|
ntree, from_sock->in_out, from_sock->idname, next_sock, from_sock->name);
|
|
|
|
if (iosock) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (iosock->typeinfo->interface_from_socket) {
|
2019-04-17 06:17:24 +02:00
|
|
|
iosock->typeinfo->interface_from_socket(ntree, iosock, from_node, from_sock);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return iosock;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void ntreeRemoveSocketInterface(bNodeTree *ntree, bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* this is fast, this way we don't need an in_out argument */
|
|
|
|
BLI_remlink(&ntree->inputs, sock);
|
|
|
|
BLI_remlink(&ntree->outputs, sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_socket_interface_free(ntree, sock);
|
|
|
|
MEM_freeN(sock);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->update |= NTREE_UPDATE_GROUP;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* generates a valid RNA identifier from the node tree name */
|
|
|
|
static void ntree_interface_identifier_base(bNodeTree *ntree, char *base)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* generate a valid RNA identifier */
|
|
|
|
sprintf(base, "NodeTreeInterface_%s", ntree->id.name + 2);
|
|
|
|
RNA_identifier_sanitize(base, false);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* check if the identifier is already in use */
|
|
|
|
static bool ntree_interface_unique_identifier_check(void *UNUSED(data), const char *identifier)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (RNA_struct_find(identifier) != NULL);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* generates the actual unique identifier and ui name and description */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void ntree_interface_identifier(bNodeTree *ntree,
|
|
|
|
const char *base,
|
|
|
|
char *identifier,
|
|
|
|
int maxlen,
|
|
|
|
char *name,
|
|
|
|
char *description)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* There is a possibility that different node tree names get mapped to the same identifier
|
2019-07-02 17:38:36 +10:00
|
|
|
* after sanitation (e.g. "SomeGroup_A", "SomeGroup.A" both get sanitized to "SomeGroup_A").
|
2019-04-17 06:17:24 +02:00
|
|
|
* On top of the sanitized id string add a number suffix if necessary to avoid duplicates.
|
|
|
|
*/
|
|
|
|
identifier[0] = '\0';
|
|
|
|
BLI_uniquename_cb(ntree_interface_unique_identifier_check, NULL, base, '_', identifier, maxlen);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
sprintf(name, "Node Tree %s Interface", ntree->id.name + 2);
|
|
|
|
sprintf(description, "Interface properties of node group %s", ntree->id.name + 2);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ntree_interface_type_create(bNodeTree *ntree)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
StructRNA *srna;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
/* strings are generated from base string + ID name, sizes are sufficient */
|
|
|
|
char base[MAX_ID_NAME + 64], identifier[MAX_ID_NAME + 64], name[MAX_ID_NAME + 64],
|
|
|
|
description[MAX_ID_NAME + 64];
|
|
|
|
|
|
|
|
/* generate a valid RNA identifier */
|
|
|
|
ntree_interface_identifier_base(ntree, base);
|
|
|
|
ntree_interface_identifier(ntree, base, identifier, sizeof(identifier), name, description);
|
|
|
|
|
|
|
|
/* register a subtype of PropertyGroup */
|
|
|
|
srna = RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup);
|
|
|
|
RNA_def_struct_ui_text(srna, name, description);
|
|
|
|
RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna);
|
|
|
|
|
|
|
|
/* associate the RNA type with the node tree */
|
|
|
|
ntree->interface_type = srna;
|
|
|
|
RNA_struct_blender_type_set(srna, ntree);
|
|
|
|
|
|
|
|
/* add socket properties */
|
|
|
|
for (sock = ntree->inputs.first; sock; sock = sock->next) {
|
|
|
|
bNodeSocketType *stype = sock->typeinfo;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (stype && stype->interface_register_properties) {
|
2019-04-17 06:17:24 +02:00
|
|
|
stype->interface_register_properties(ntree, sock, srna);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
for (sock = ntree->outputs.first; sock; sock = sock->next) {
|
|
|
|
bNodeSocketType *stype = sock->typeinfo;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (stype && stype->interface_register_properties) {
|
2019-04-17 06:17:24 +02:00
|
|
|
stype->interface_register_properties(ntree, sock, srna);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, int create)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->interface_type) {
|
|
|
|
/* strings are generated from base string + ID name, sizes are sufficient */
|
|
|
|
char base[MAX_ID_NAME + 64], identifier[MAX_ID_NAME + 64], name[MAX_ID_NAME + 64],
|
|
|
|
description[MAX_ID_NAME + 64];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* A bit of a hack: when changing the ID name, update the RNA type identifier too,
|
|
|
|
* so that the names match. This is not strictly necessary to keep it working,
|
|
|
|
* but better for identifying associated NodeTree blocks and RNA types.
|
|
|
|
*/
|
|
|
|
StructRNA *srna = ntree->interface_type;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree_interface_identifier_base(ntree, base);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* RNA identifier may have a number suffix, but should start with the idbase string */
|
|
|
|
if (!STREQLEN(RNA_struct_identifier(srna), base, sizeof(base))) {
|
|
|
|
/* generate new unique RNA identifier from the ID name */
|
|
|
|
ntree_interface_identifier(ntree, base, identifier, sizeof(identifier), name, description);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* rename the RNA type */
|
|
|
|
RNA_def_struct_free_pointers(&BLENDER_RNA, srna);
|
|
|
|
RNA_def_struct_identifier(&BLENDER_RNA, srna, identifier);
|
|
|
|
RNA_def_struct_ui_text(srna, name, description);
|
|
|
|
RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (create) {
|
|
|
|
ntree_interface_type_create(ntree);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ntree->interface_type;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void ntreeInterfaceTypeFree(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->interface_type) {
|
|
|
|
RNA_struct_free(&BLENDER_RNA, ntree->interface_type);
|
|
|
|
ntree->interface_type = NULL;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void ntreeInterfaceTypeUpdate(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX it would be sufficient to just recreate all properties
|
|
|
|
* instead of re-registering the whole struct type,
|
|
|
|
* but there is currently no good way to do this in the RNA functions.
|
|
|
|
* Overhead should be negligible.
|
|
|
|
*/
|
|
|
|
ntreeInterfaceTypeFree(ntree);
|
|
|
|
ntree_interface_type_create(ntree);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2006-02-07 15:50:55 +00:00
|
|
|
|
2006-12-30 16:35:46 +00:00
|
|
|
/* ************ find stuff *************** */
|
2005-12-18 23:08:22 +00:00
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
bNode *ntreeFindType(const bNodeTree *ntree, int type)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree) {
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->type == type) {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2016-06-14 11:31:00 +02:00
|
|
|
}
|
|
|
|
|
2014-01-27 20:17:56 +11:00
|
|
|
bool ntreeHasType(const bNodeTree *ntree, int type)
|
2006-06-03 09:19:10 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ntreeFindType(ntree, type) != NULL;
|
2006-06-03 09:19:10 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 20:17:56 +11:00
|
|
|
bool ntreeHasTree(const bNodeTree *ntree, const bNodeTree *lookup)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2014-01-27 20:17:56 +11:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == lookup) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-01-27 20:17:56 +11:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) {
|
|
|
|
if (ntreeHasTree((bNodeTree *)node->id, lookup)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-27 20:17:56 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2014-01-27 20:17:56 +11:00
|
|
|
}
|
|
|
|
|
2005-12-18 23:08:22 +00:00
|
|
|
bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->fromsock == from && link->tosock == to) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return link;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (link->fromsock == to && link->tosock == from) { /* hrms? */
|
2019-04-17 06:17:24 +02:00
|
|
|
return link;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
2005-12-18 23:08:22 +00:00
|
|
|
}
|
|
|
|
|
2005-12-20 15:43:55 +00:00
|
|
|
int nodeCountSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link;
|
|
|
|
int tot = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->fromsock == sock || link->tosock == sock) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tot++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return tot;
|
2005-12-20 15:43:55 +00:00
|
|
|
}
|
|
|
|
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
bNode *nodeGetActive(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->flag & NODE_ACTIVE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bNode *node_get_active_id_recursive(bNodeInstanceKey active_key,
|
|
|
|
bNodeInstanceKey parent_key,
|
|
|
|
bNodeTree *ntree,
|
|
|
|
short idtype)
|
|
|
|
{
|
|
|
|
if (parent_key.value == active_key.value || active_key.value == 0) {
|
|
|
|
bNode *node;
|
2019-04-22 09:39:35 +10:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id && GS(node->id->name) == idtype) {
|
|
|
|
if (node->flag & NODE_ACTIVE_ID) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return node;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
bNode *node, *tnode;
|
|
|
|
/* no node with active ID in this tree, look inside groups */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->type == NODE_GROUP) {
|
|
|
|
bNodeTree *group = (bNodeTree *)node->id;
|
|
|
|
if (group) {
|
|
|
|
bNodeInstanceKey group_key = BKE_node_instance_key(parent_key, ntree, node);
|
|
|
|
tnode = node_get_active_id_recursive(active_key, group_key, group, idtype);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tnode) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return tnode;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 15:42:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 15:06:18 +00:00
|
|
|
/* two active flags, ID nodes have special flag for buttons display */
|
|
|
|
bNode *nodeGetActiveID(bNodeTree *ntree, short idtype)
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return node_get_active_id_recursive(
|
|
|
|
ntree->active_viewer_key, NODE_INSTANCE_KEY_BASE, ntree, idtype);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-05-16 15:06:18 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 18:25:05 +00:00
|
|
|
bool nodeSetActiveID(bNodeTree *ntree, short idtype, ID *id)
|
2009-10-06 15:31:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
bool ok = false;
|
2009-10-06 15:31:25 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return ok;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-10-06 15:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id && GS(node->id->name) == idtype) {
|
|
|
|
if (id && ok == false && node->id == id) {
|
|
|
|
node->flag |= NODE_ACTIVE_ID;
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->flag &= ~NODE_ACTIVE_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-06 15:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update all groups linked from here
|
|
|
|
* if active ID node has been found already,
|
|
|
|
* just pass NULL so other matching nodes are deactivated.
|
|
|
|
*/
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->type == NODE_GROUP) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ok |= nodeSetActiveID((bNodeTree *)node->id, idtype, (ok == false ? id : NULL));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ok;
|
2009-10-06 15:31:25 +00:00
|
|
|
}
|
|
|
|
|
2005-12-30 11:25:15 +00:00
|
|
|
/* two active flags, ID nodes have special flag for buttons display */
|
|
|
|
void nodeClearActiveID(bNodeTree *ntree, short idtype)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id && GS(node->id->name) == idtype) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag &= ~NODE_ACTIVE_ID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2005-12-30 11:25:15 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 23:39:08 +11:00
|
|
|
void nodeSetSelected(bNode *node, bool select)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (select) {
|
|
|
|
node->flag |= NODE_SELECT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bNodeSocket *sock;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag &= ~NODE_SELECT;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* deselect sockets too */
|
2019-04-22 09:39:35 +10:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sock->flag &= ~NODE_SELECT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
sock->flag &= ~NODE_SELECT;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 18:43:48 +00:00
|
|
|
void nodeClearActive(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2012-06-11 18:43:48 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-06-11 18:43:48 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_ID);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-06-11 18:43:48 +00:00
|
|
|
}
|
|
|
|
|
More node goodies!
First note; this is a WIP project, some commits might change things that
make formerly saved situations not to work identically... like now!
------ New Material integration ------
Until now, the Node system worked on top of the 'current' Material, just
like how the Material Layers worked. That's quite confusing in practice,
especially to see what Material is a Node, or what is the "base material"
Best solution is to completely separate the two. This has been implemented
as follows now;
- The confusing "Input" node has been removed.
- When choosing a Material in Blender, you can define this Material to be
either 'normal' (default) or be the root of a Node tree.
- If a Material is a Node tree, you have to add Nodes in the tree to see
something happen. An empty Node tree doesn't do anything (black).
- If a Material is a Node Tree, the 'data browse' menus show it with an
'N' mark before the name. The 'data block' buttons display it with the
suffix 'NT' (instead of 'MA').
- In a Node Tree, any Material can be inserted, including itself. Only in
that case the Material is being used itself for shading.
UI changes:
Added a new Panel "Links", which shows:
- where the Material is linked to (Object, Mesh, etc)
- if the Material is a NodeTree or not
- the actual active Material in the Tree
The "Node" Panel itself now only shows buttons from the other nodes, when
they are active.
Further the Material Nodes themselves allow browsing and renaming or adding
new Materials now too.
Second half of today's work was cleaning up selection when the Nodes
overlap... it was possible to drag links from invisible sockets, or click
headers for invisible nodes, etc. This because the mouse input code was
not checking for visibility yet.
Works now even for buttons. :)
2005-12-29 18:08:01 +00:00
|
|
|
/* two active flags, ID nodes have special flag for buttons display */
|
|
|
|
void nodeSetActive(bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *tnode;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make sure only one node is active, and only one per ID type */
|
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
|
|
|
|
tnode->flag &= ~NODE_ACTIVE;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->id && tnode->id) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (GS(node->id->name) == GS(tnode->id->name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tnode->flag &= ~NODE_ACTIVE_ID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tnode->flag &= ~NODE_ACTIVE_TEXTURE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_ACTIVE;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->id) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_ACTIVE_ID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->flag |= NODE_ACTIVE_TEXTURE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 10:23:19 +00:00
|
|
|
int nodeSocketIsHidden(bNodeSocket *sock)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((sock->flag & (SOCK_HIDDEN | SOCK_UNAVAIL)) != 0);
|
2012-03-01 07:56:15 +00:00
|
|
|
}
|
|
|
|
|
2019-08-18 11:16:04 +02:00
|
|
|
void nodeSetSocketAvailability(bNodeSocket *sock, bool is_available)
|
|
|
|
{
|
|
|
|
if (is_available) {
|
|
|
|
sock->flag &= ~SOCK_UNAVAIL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sock->flag |= SOCK_UNAVAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Nodes: Support storing socket link limits in bNodeSocketType
Currently the link limit of sockets is stored in bNodeSocket->limit.
This allows for a lot of flexibility, but is also very redundant.
In every case I've had to deal with so far, it would have "more correct"
to set the link limit per socket type and not per socket. I did not enforce
this constraint yet, because the link limit is exposed in the Python API,
which I did not want to break here.
In the future it might even make sense to only support only three kinds of link limits:
a) no links, b) at most one link, c) an arbitrary number links links. The other link
limits usually don't work well with tools (e.g. which link should be removed when a new
one is connected?) and is not used in practice. However, that is for another day.
Eventually, I would like to get rid of bNodeSocket->limit completely and replace it
either with fixed link limits or a callback in bNodeSocketType.
This patch consists of three parts:
**1. Support defining link limit in socket type**
This introduces a new `nodeSocketLinkLimit` function that serves as an indirection to
hide where the link limit of a socket is defined.
**2. Define link limits for builtin sockets on socket type**
Data sockets: one input, many outputs
Virtual sockets: one input, one output
Undefined sockets: many inputs, many outputs (to avoid that links are removed when the type of the socket is not known)
**3. Remove `bNodeSocketTemplate->limit`**
This wasn't used anymore after the second commit. Removing it simplifies socket definitions
in hundreds of places and removes a lot of redundancy.
Differential Revision: https://developer.blender.org/D7038
Reviewers: brecht
2020-03-06 12:20:05 +01:00
|
|
|
int nodeSocketLinkLimit(struct bNodeSocket *sock)
|
|
|
|
{
|
|
|
|
bNodeSocketType *stype = sock->typeinfo;
|
|
|
|
if (stype != NULL && stype->use_link_limits_of_type) {
|
|
|
|
int limit = (sock->in_out == SOCK_IN) ? stype->input_link_limit : stype->output_link_limit;
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return sock->limit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
/* ************** Node Clipboard *********** */
|
|
|
|
|
2012-08-20 13:51:25 +00:00
|
|
|
#define USE_NODE_CB_VALIDATE
|
|
|
|
|
|
|
|
#ifdef USE_NODE_CB_VALIDATE
|
|
|
|
/**
|
|
|
|
* This data structure is to validate the node on creation,
|
|
|
|
* otherwise we may reference missing data.
|
|
|
|
*
|
|
|
|
* Currently its only used for ID's, but nodes may one day
|
2012-08-24 23:22:34 +00:00
|
|
|
* reference other pointers which need validation.
|
2012-08-20 13:51:25 +00:00
|
|
|
*/
|
|
|
|
typedef struct bNodeClipboardExtraInfo {
|
2019-04-17 06:17:24 +02:00
|
|
|
struct bNodeClipboardExtraInfo *next, *prev;
|
|
|
|
ID *id;
|
|
|
|
char id_name[MAX_ID_NAME];
|
|
|
|
char library_name[FILE_MAX];
|
2012-08-20 13:51:25 +00:00
|
|
|
} bNodeClipboardExtraInfo;
|
2019-04-17 06:17:24 +02:00
|
|
|
#endif /* USE_NODE_CB_VALIDATE */
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2012-08-02 09:52:37 +00:00
|
|
|
typedef struct bNodeClipboard {
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase nodes;
|
2012-08-20 13:51:25 +00:00
|
|
|
|
|
|
|
#ifdef USE_NODE_CB_VALIDATE
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase nodes_extra_info;
|
2012-08-20 13:51:25 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ListBase links;
|
|
|
|
int type;
|
2012-08-02 09:52:37 +00:00
|
|
|
} bNodeClipboard;
|
|
|
|
|
2013-03-22 05:34:10 +00:00
|
|
|
static bNodeClipboard node_clipboard = {{NULL}};
|
2012-08-02 09:52:37 +00:00
|
|
|
|
2012-08-06 08:41:45 +00:00
|
|
|
void BKE_node_clipboard_init(struct bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
node_clipboard.type = ntree->type;
|
2012-08-06 08:41:45 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
void BKE_node_clipboard_clear(void)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node, *node_next;
|
|
|
|
bNodeLink *link, *link_next;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = node_clipboard.links.first; link; link = link_next) {
|
|
|
|
link_next = link->next;
|
|
|
|
nodeRemLink(NULL, link);
|
|
|
|
}
|
|
|
|
BLI_listbase_clear(&node_clipboard.links);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = node_clipboard.nodes.first; node; node = node_next) {
|
|
|
|
node_next = node->next;
|
|
|
|
node_free_node(NULL, node);
|
|
|
|
}
|
|
|
|
BLI_listbase_clear(&node_clipboard.nodes);
|
2012-08-20 13:51:25 +00:00
|
|
|
|
|
|
|
#ifdef USE_NODE_CB_VALIDATE
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelistN(&node_clipboard.nodes_extra_info);
|
2012-08-20 13:51:25 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
/* return false when one or more ID's are lost */
|
2014-01-28 03:52:21 +11:00
|
|
|
bool BKE_node_clipboard_validate(void)
|
2012-08-20 13:51:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool ok = true;
|
2012-08-20 13:51:25 +00:00
|
|
|
|
|
|
|
#ifdef USE_NODE_CB_VALIDATE
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeClipboardExtraInfo *node_info;
|
|
|
|
bNode *node;
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* lists must be aligned */
|
|
|
|
BLI_assert(BLI_listbase_count(&node_clipboard.nodes) ==
|
|
|
|
BLI_listbase_count(&node_clipboard.nodes_extra_info));
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = node_clipboard.nodes.first, node_info = node_clipboard.nodes_extra_info.first; node;
|
|
|
|
node = node->next, node_info = node_info->next) {
|
|
|
|
/* validate the node against the stored node info */
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* re-assign each loop since we may clear,
|
|
|
|
* open a new file where the ID is valid, and paste again */
|
|
|
|
node->id = node_info->id;
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* currently only validate the ID */
|
|
|
|
if (node->id) {
|
|
|
|
/* We want to search into current blend file, so using G_MAIN is valid here too. */
|
|
|
|
ListBase *lb = which_libbase(G_MAIN, GS(node_info->id_name));
|
|
|
|
BLI_assert(lb != NULL);
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BLI_findindex(lb, node_info->id) == -1) {
|
|
|
|
/* may assign NULL */
|
|
|
|
node->id = BLI_findstring(lb, node_info->id_name + 2, offsetof(ID, name) + 2);
|
2012-08-20 13:59:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->id == NULL) {
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* USE_NODE_CB_VALIDATE */
|
2012-08-20 13:51:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ok;
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
void BKE_node_clipboard_add_node(bNode *node)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
2012-08-20 13:51:25 +00:00
|
|
|
#ifdef USE_NODE_CB_VALIDATE
|
2019-04-17 06:17:24 +02:00
|
|
|
/* add extra info */
|
|
|
|
bNodeClipboardExtraInfo *node_info = MEM_mallocN(sizeof(bNodeClipboardExtraInfo),
|
|
|
|
"bNodeClipboardExtraInfo");
|
|
|
|
|
|
|
|
node_info->id = node->id;
|
|
|
|
if (node->id) {
|
|
|
|
BLI_strncpy(node_info->id_name, node->id->name, sizeof(node_info->id_name));
|
|
|
|
if (ID_IS_LINKED(node->id)) {
|
|
|
|
BLI_strncpy(
|
|
|
|
node_info->library_name, node->id->lib->filepath, sizeof(node_info->library_name));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node_info->library_name[0] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node_info->id_name[0] = '\0';
|
|
|
|
node_info->library_name[0] = '\0';
|
|
|
|
}
|
|
|
|
BLI_addtail(&node_clipboard.nodes_extra_info, node_info);
|
|
|
|
/* end extra info */
|
|
|
|
#endif /* USE_NODE_CB_VALIDATE */
|
|
|
|
|
|
|
|
/* add node */
|
|
|
|
BLI_addtail(&node_clipboard.nodes, node);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
void BKE_node_clipboard_add_link(bNodeLink *link)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(&node_clipboard.links, link);
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
const ListBase *BKE_node_clipboard_get_nodes(void)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return &node_clipboard.nodes;
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:25:24 +00:00
|
|
|
const ListBase *BKE_node_clipboard_get_links(void)
|
2012-08-02 09:52:37 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return &node_clipboard.links;
|
2012-08-02 09:52:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:41:45 +00:00
|
|
|
int BKE_node_clipboard_get_type(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return node_clipboard.type;
|
2012-08-06 08:41:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:54:00 +01:00
|
|
|
void BKE_node_clipboard_free(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_clipboard_validate();
|
|
|
|
BKE_node_clipboard_clear();
|
2019-03-16 18:54:00 +01:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
/* Node Instance Hash */
|
|
|
|
|
|
|
|
/* magic number for initial hash key */
|
|
|
|
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE = {5381};
|
2013-04-24 16:36:50 +00:00
|
|
|
const bNodeInstanceKey NODE_INSTANCE_KEY_NONE = {0};
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
/* Generate a hash key from ntree and node names
|
|
|
|
* Uses the djb2 algorithm with xor by Bernstein:
|
|
|
|
* http://www.cse.yorku.ca/~oz/hash.html
|
|
|
|
*/
|
|
|
|
static bNodeInstanceKey node_hash_int_str(bNodeInstanceKey hash, const char *str)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char c;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
while ((c = *str++)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
hash.value = ((hash.value << 5) + hash.value) ^ c; /* (hash * 33) ^ c */
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* separator '\0' character, to avoid ambiguity from concatenated strings */
|
|
|
|
hash.value = (hash.value << 5) + hash.value; /* hash * 33 */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return hash;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bNodeInstanceKey BKE_node_instance_key(bNodeInstanceKey parent_key, bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceKey key;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
key = node_hash_int_str(parent_key, ntree->id.name + 2);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node) {
|
2019-04-17 06:17:24 +02:00
|
|
|
key = node_hash_int_str(key, node->name);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return key;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int node_instance_hash_key(const void *key)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((const bNodeInstanceKey *)key)->value;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 06:15:52 +10:00
|
|
|
static bool node_instance_hash_key_cmp(const void *a, const void *b)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
unsigned int value_a = ((const bNodeInstanceKey *)a)->value;
|
|
|
|
unsigned int value_b = ((const bNodeInstanceKey *)b)->value;
|
2014-09-25 06:15:52 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (value_a != value_b);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bNodeInstanceHash *BKE_node_instance_hash_new(const char *info)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHash *hash = MEM_mallocN(sizeof(bNodeInstanceHash), info);
|
|
|
|
hash->ghash = BLI_ghash_new(
|
|
|
|
node_instance_hash_key, node_instance_hash_key_cmp, "node instance hash ghash");
|
|
|
|
return hash;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_instance_hash_free(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_free(hash->ghash, NULL, (GHashValFreeFP)valfreefp);
|
|
|
|
MEM_freeN(hash);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_instance_hash_insert(bNodeInstanceHash *hash, bNodeInstanceKey key, void *value)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashEntry *entry = value;
|
|
|
|
entry->key = key;
|
|
|
|
entry->tag = 0;
|
|
|
|
BLI_ghash_insert(hash->ghash, &entry->key, value);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *BKE_node_instance_hash_lookup(bNodeInstanceHash *hash, bNodeInstanceKey key)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghash_lookup(hash->ghash, &key);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BKE_node_instance_hash_remove(bNodeInstanceHash *hash,
|
|
|
|
bNodeInstanceKey key,
|
|
|
|
bNodeInstanceValueFP valfreefp)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghash_remove(hash->ghash, &key, NULL, (GHashValFreeFP)valfreefp);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_instance_hash_clear(bNodeInstanceHash *hash, bNodeInstanceValueFP valfreefp)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_clear(hash->ghash, NULL, (GHashValFreeFP)valfreefp);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *BKE_node_instance_hash_pop(bNodeInstanceHash *hash, bNodeInstanceKey key)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghash_popkey(hash->ghash, &key, NULL);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BKE_node_instance_hash_haskey(bNodeInstanceHash *hash, bNodeInstanceKey key)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghash_haskey(hash->ghash, &key);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BKE_node_instance_hash_size(bNodeInstanceHash *hash)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BLI_ghash_len(hash->ghash);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_instance_hash_clear_tags(bNodeInstanceHash *hash)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashIterator iter;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-21 04:40:16 +10:00
|
|
|
NODE_INSTANCE_HASH_ITER (iter, hash) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashEntry *value = BKE_node_instance_hash_iterator_get_value(&iter);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
value->tag = 0;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_node_instance_hash_tag(bNodeInstanceHash *UNUSED(hash), void *value)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashEntry *entry = value;
|
|
|
|
entry->tag = 1;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 23:39:08 +11:00
|
|
|
bool BKE_node_instance_hash_tag_key(bNodeInstanceHash *hash, bNodeInstanceKey key)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashEntry *entry = BKE_node_instance_hash_lookup(hash, key);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (entry) {
|
|
|
|
entry->tag = 1;
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash,
|
|
|
|
bNodeInstanceValueFP valfreefp)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* NOTE: Hash must not be mutated during iterating!
|
|
|
|
* Store tagged entries in a separate list and remove items afterward.
|
|
|
|
*/
|
|
|
|
bNodeInstanceKey *untagged = MEM_mallocN(sizeof(bNodeInstanceKey) *
|
|
|
|
BKE_node_instance_hash_size(hash),
|
|
|
|
"temporary node instance key list");
|
|
|
|
bNodeInstanceHashIterator iter;
|
|
|
|
int num_untagged, i;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
num_untagged = 0;
|
2019-04-21 04:40:16 +10:00
|
|
|
NODE_INSTANCE_HASH_ITER (iter, hash) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeInstanceHashEntry *value = BKE_node_instance_hash_iterator_get_value(&iter);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!value->tag) {
|
2019-04-17 06:17:24 +02:00
|
|
|
untagged[num_untagged++] = BKE_node_instance_hash_iterator_get_key(&iter);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (i = 0; i < num_untagged; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_node_instance_hash_remove(hash, untagged[i], valfreefp);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(untagged);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* ************** dependency stuff *********** */
|
|
|
|
|
|
|
|
/* node is guaranteed to be not checked before */
|
2012-10-09 17:30:33 +00:00
|
|
|
static int node_get_deplist_recurs(bNodeTree *ntree, bNode *node, bNode ***nsort)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *fromnode;
|
|
|
|
bNodeLink *link;
|
|
|
|
int level = 0xFFF;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node->done = true;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check linked nodes */
|
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
if (link->tonode == node) {
|
|
|
|
fromnode = link->fromnode;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fromnode->done == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
fromnode->level = node_get_deplist_recurs(ntree, fromnode, nsort);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (fromnode->level <= level) {
|
2019-04-17 06:17:24 +02:00
|
|
|
level = fromnode->level - 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check parent node */
|
|
|
|
if (node->parent) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->parent->done == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->parent->level = node_get_deplist_recurs(ntree, node->parent, nsort);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (node->parent->level <= level) {
|
2019-04-17 06:17:24 +02:00
|
|
|
level = node->parent->level - 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (nsort) {
|
|
|
|
**nsort = node;
|
|
|
|
(*nsort)++;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return level;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node, **nsort;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*totnodes = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first clear data */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
node->done = false;
|
|
|
|
(*totnodes)++;
|
|
|
|
}
|
|
|
|
if (*totnodes == 0) {
|
|
|
|
*deplist = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
nsort = *deplist = MEM_callocN((*totnodes) * sizeof(bNode *), "sorted node array");
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* recursive check */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->done == 0) {
|
|
|
|
node->level = node_get_deplist_recurs(ntree, node, &nsort);
|
|
|
|
}
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
|
|
|
|
2012-03-07 12:30:29 +00:00
|
|
|
/* only updates node->level for detecting cycles links */
|
|
|
|
static void ntree_update_node_level(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first clear tag */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
node->done = false;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* recursive check */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->done == 0) {
|
|
|
|
node->level = node_get_deplist_recurs(ntree, node, NULL);
|
|
|
|
}
|
|
|
|
}
|
2012-03-07 12:30:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-14 11:14:21 +01:00
|
|
|
void ntreeTagUsedSockets(bNodeTree *ntree)
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
bNodeLink *link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first clear data */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
sock->flag &= ~SOCK_IN_USE;
|
|
|
|
}
|
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
|
|
|
sock->flag &= ~SOCK_IN_USE;
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
link->fromsock->flag |= SOCK_IN_USE;
|
|
|
|
link->tosock->flag |= SOCK_IN_USE;
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
}
|
Three-in-one commit:
- Compositor now is threaded
Enable it with the Scene buttons "Threads". This will handle over nodes to
individual threads to be calculated. However, if nodes depend on others
they have to wait. The current system only threads per entire node, not for
calculating results in parts.
I've reshuffled the node execution code to evaluate 'changed' events, and
prepare the entire tree to become simply parsed for open jobs with a call
to node = getExecutableNode()
By default, even without 'thread' option active, all node execution is
done within a separate thread.
Also fixed issues in yesterdays commit for 'event based' calculations, it
didn't do animated images, or execute (on rendering) the correct nodes
when you don't have Render-Result nodes included.
- Added generic Thread support in blenlib/ module
The renderer and the node system now both use same code for controlling the
threads. This has been moved to a new C file in blenlib/intern/threads.c.
Check this c file for an extensive doc and example how to use it.
The current implementation for Compositing allows unlimited amount of
threads. For rendering it is still tied to two threads, although it is
pretty easy to extend to 4 already. People with giant amounts of cpus can
poke me once for tests. :)
- Bugfix in creating group nodes
Group node definitions demand a clear separation of 'internal sockets' and
'external sockets'. The first are sockets being linked internally, the latter
are sockets exposed as sockets for the group itself.
When sockets were linked both internal and external, Blender crashed. It is
solved now by removing the external link(s).
2006-01-29 11:36:33 +00:00
|
|
|
|
2015-01-14 11:14:21 +01:00
|
|
|
static void ntree_update_link_pointers(bNodeTree *ntree)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
bNodeLink *link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first clear data */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
sock->link = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-01-14 11:14:21 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
link->tosock->link = link;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeTagUsedSockets(ntree);
|
2015-01-14 11:14:21 +01:00
|
|
|
}
|
|
|
|
|
2011-09-16 08:20:21 +00:00
|
|
|
static void ntree_validate_links(bNodeTree *ntree)
|
2007-03-24 18:41:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeLink *link;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
link->flag |= NODE_LINK_VALID;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (link->fromnode && link->tonode && link->fromnode->level <= link->tonode->level) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->flag &= ~NODE_LINK_VALID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else if (ntree->typeinfo->validate_link) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree->typeinfo->validate_link(ntree, link)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
link->flag &= ~NODE_LINK_VALID;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2007-03-24 18:41:54 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
void ntreeUpdateAllNew(Main *main)
|
2007-03-24 18:41:54 +00:00
|
|
|
{
|
2019-04-20 20:25:22 +02:00
|
|
|
/* Update all new node trees on file read or append, to add/remove sockets
|
|
|
|
* in groups nodes if the group changed, and handle any update flags that
|
|
|
|
* might have been set in file reading or versioning. */
|
2019-04-17 06:17:24 +02:00
|
|
|
FOREACH_NODETREE_BEGIN (main, ntree, owner_id) {
|
2019-04-20 20:25:22 +02:00
|
|
|
if (owner_id->tag & LIB_TAG_NEW) {
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-04-20 20:25:22 +02:00
|
|
|
if (node->typeinfo->group_update_func) {
|
|
|
|
node->typeinfo->group_update_func(ntree, node);
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
ntreeUpdateTree(NULL, ntree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FOREACH_NODETREE_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ntreeUpdateAllUsers(Main *main, ID *ngroup)
|
|
|
|
{
|
|
|
|
/* Update all users of ngroup, to add/remove sockets as needed. */
|
|
|
|
FOREACH_NODETREE_BEGIN (main, ntree, owner_id) {
|
|
|
|
bool need_update = false;
|
|
|
|
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-04-20 20:25:22 +02:00
|
|
|
if (node->id == ngroup) {
|
|
|
|
if (node->typeinfo->group_update_func) {
|
|
|
|
node->typeinfo->group_update_func(ntree, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
need_update = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
}
|
2019-04-20 20:25:22 +02:00
|
|
|
|
|
|
|
if (need_update) {
|
|
|
|
ntreeUpdateTree(NULL, ntree);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
FOREACH_NODETREE_END;
|
2007-03-24 18:41:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 15:28:42 +00:00
|
|
|
void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
|
2010-01-27 05:42:17 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ntree) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-30 17:06:28 +10:00
|
|
|
/* Avoid re-entrant updates, can be caused by RNA update callbacks. */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->is_updating) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = true;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) {
|
|
|
|
/* set the bNodeSocket->link pointers */
|
|
|
|
ntree_update_link_pointers(ntree);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update individual nodes */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
/* node tree update tags override individual node update flags */
|
|
|
|
if ((node->update & NODE_UPDATE) || (ntree->update & NTREE_UPDATE)) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->typeinfo->updatefunc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->typeinfo->updatefunc(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeUpdateInternalLinks(ntree, node);
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* generic tree update callback */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->typeinfo->update) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->typeinfo->update(ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX this should be moved into the tree type update callback for tree supporting node groups.
|
|
|
|
* Currently the node tree interface is still a generic feature of the base NodeTree type.
|
|
|
|
*/
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->update & NTREE_UPDATE_GROUP) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeInterfaceTypeUpdate(ntree);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX hack, should be done by depsgraph!! */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (bmain) {
|
2019-04-20 20:25:22 +02:00
|
|
|
ntreeUpdateAllUsers(bmain, &ntree->id);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) {
|
|
|
|
/* node updates can change sockets or links, repeat link pointer update afterward */
|
|
|
|
ntree_update_link_pointers(ntree);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update the node level from link dependencies */
|
|
|
|
ntree_update_node_level(ntree);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check link validity */
|
|
|
|
ntree_validate_links(ntree);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clear update flags */
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
node->update = 0;
|
|
|
|
}
|
|
|
|
ntree->update = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = false;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2010-01-27 05:42:17 +00:00
|
|
|
|
2011-10-19 17:08:35 +00:00
|
|
|
void nodeUpdate(bNodeTree *ntree, bNode *node)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-09-30 17:06:28 +10:00
|
|
|
/* Avoid re-entrant updates, can be caused by RNA update callbacks. */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->is_updating) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = true;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->typeinfo->updatefunc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->typeinfo->updatefunc(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
nodeUpdateInternalLinks(ntree, node);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clear update flag */
|
|
|
|
node->update = 0;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = false;
|
2010-01-27 05:42:17 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
bool nodeUpdateID(bNodeTree *ntree, ID *id)
|
2007-03-24 18:41:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
bool changed = false;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ELEM(NULL, id, ntree)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return changed;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-30 17:06:28 +10:00
|
|
|
/* Avoid re-entrant updates, can be caused by RNA update callbacks. */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ntree->is_updating) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return changed;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = true;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id == id) {
|
|
|
|
changed = true;
|
|
|
|
node->update |= NODE_UPDATE_ID;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->typeinfo->updatefunc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->typeinfo->updatefunc(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clear update flag */
|
|
|
|
node->update = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
nodeUpdateInternalLinks(ntree, node);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntree->is_updating = false;
|
|
|
|
return changed;
|
2007-03-24 18:41:54 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 16:49:06 +00:00
|
|
|
void nodeUpdateInternalLinks(bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_freelistN(&node->internal_links);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (node->typeinfo && node->typeinfo->update_internal_links) {
|
2019-04-17 06:17:24 +02:00
|
|
|
node->typeinfo->update_internal_links(ntree, node);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-10-25 16:49:06 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* ************* node type access ********** */
|
|
|
|
|
2013-11-12 18:18:04 +00:00
|
|
|
void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen)
|
2011-02-07 16:41:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
label[0] = '\0';
|
2018-01-07 22:29:25 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->label[0] != '\0') {
|
|
|
|
BLI_strncpy(label, node->label, maxlen);
|
|
|
|
}
|
|
|
|
else if (node->typeinfo->labelfunc) {
|
|
|
|
node->typeinfo->labelfunc(ntree, node, label, maxlen);
|
|
|
|
}
|
2018-01-07 22:29:25 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* The previous methods (labelfunc) could not provide an adequate label for the node. */
|
|
|
|
if (label[0] == '\0') {
|
|
|
|
/* Kind of hacky and weak... Ideally would be better to use RNA here. :| */
|
|
|
|
const char *tmp = CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, node->typeinfo->ui_name);
|
|
|
|
if (tmp == node->typeinfo->ui_name) {
|
|
|
|
tmp = IFACE_(node->typeinfo->ui_name);
|
|
|
|
}
|
|
|
|
BLI_strncpy(label, tmp, maxlen);
|
|
|
|
}
|
2011-02-07 16:41:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 15:31:40 +00:00
|
|
|
/* Get node socket label if it is set */
|
|
|
|
const char *nodeSocketLabel(const bNodeSocket *sock)
|
|
|
|
{
|
|
|
|
return (sock->label[0] != '\0') ? sock->label : sock->name;
|
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void node_type_base_defaults(bNodeType *ntype)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* default size values */
|
|
|
|
node_type_size_preset(ntype, NODE_SIZE_DEFAULT);
|
|
|
|
ntype->height = 100;
|
|
|
|
ntype->minheight = 30;
|
|
|
|
ntype->maxheight = FLT_MAX;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* allow this node for any tree type */
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *UNUSED(ntree))
|
2008-11-12 22:03:11 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* use the basic poll function */
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_poll_instance_default(bNode *node, bNodeTree *ntree)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return node->typeinfo->poll(node->typeinfo, ntree);
|
2008-11-12 22:03:11 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Use static type info header to map static int type to identifier string and RNA struct type.
|
|
|
|
* Associate the RNA struct type with the bNodeType.
|
|
|
|
* Dynamically registered nodes will create an RNA type at runtime
|
|
|
|
* and call RNA_struct_blender_type_set, so this only needs to be done for old RNA types
|
|
|
|
* created in makesrna, which can not be associated to a bNodeType immediately,
|
|
|
|
* since bNodeTypes are registered afterward ...
|
|
|
|
*/
|
2013-12-22 14:11:10 +11:00
|
|
|
#define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \
|
2019-04-17 06:17:24 +02:00
|
|
|
case ID: \
|
|
|
|
BLI_strncpy(ntype->idname, #Category #StructName, sizeof(ntype->idname)); \
|
2020-04-03 18:24:08 +02:00
|
|
|
ntype->rna_ext.srna = RNA_struct_find(#Category #StructName); \
|
|
|
|
BLI_assert(ntype->rna_ext.srna != NULL); \
|
|
|
|
RNA_struct_blender_type_set(ntype->rna_ext.srna, ntype); \
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (type) {
|
2013-12-22 14:11:10 +11:00
|
|
|
#include "NOD_static_types.h"
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make sure we have a valid type (everything registered) */
|
|
|
|
BLI_assert(ntype->idname[0] != '\0');
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->type = type;
|
|
|
|
BLI_strncpy(ntype->ui_name, name, sizeof(ntype->ui_name));
|
|
|
|
ntype->nclass = nclass;
|
|
|
|
ntype->flag = flag;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_type_base_defaults(ntype);
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->poll = node_poll_default;
|
|
|
|
ntype->poll_instance = node_poll_instance_default;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2007-03-26 15:07:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_base_custom(
|
|
|
|
bNodeType *ntype, const char *idname, const char *name, short nclass, short flag)
|
2011-02-07 09:33:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(ntype->idname, idname, sizeof(ntype->idname));
|
|
|
|
ntype->type = NODE_CUSTOM;
|
|
|
|
BLI_strncpy(ntype->ui_name, name, sizeof(ntype->ui_name));
|
|
|
|
ntype->nclass = nclass;
|
|
|
|
ntype->flag = flag;
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_type_base_defaults(ntype);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static bool unique_socket_template_identifier_check(void *arg, const char *name)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocketTemplate *ntemp;
|
|
|
|
struct {
|
|
|
|
bNodeSocketTemplate *list;
|
|
|
|
bNodeSocketTemplate *ntemp;
|
|
|
|
} *data = arg;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (ntemp = data->list; ntemp->type >= 0; ntemp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ntemp != data->ntemp) {
|
|
|
|
if (STREQ(ntemp->identifier, name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void unique_socket_template_identifier(bNodeSocketTemplate *list,
|
|
|
|
bNodeSocketTemplate *ntemp,
|
|
|
|
const char defname[],
|
|
|
|
char delim)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct {
|
|
|
|
bNodeSocketTemplate *list;
|
|
|
|
bNodeSocketTemplate *ntemp;
|
|
|
|
} data;
|
|
|
|
data.list = list;
|
|
|
|
data.ntemp = ntemp;
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_uniquename_cb(unique_socket_template_identifier_check,
|
|
|
|
&data,
|
|
|
|
defname,
|
|
|
|
delim,
|
|
|
|
ntemp->identifier,
|
|
|
|
sizeof(ntemp->identifier));
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_socket_templates(struct bNodeType *ntype,
|
|
|
|
struct bNodeSocketTemplate *inputs,
|
|
|
|
struct bNodeSocketTemplate *outputs)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeSocketTemplate *ntemp;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->inputs = inputs;
|
|
|
|
ntype->outputs = outputs;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* automatically generate unique identifiers */
|
|
|
|
if (inputs) {
|
|
|
|
/* clear identifier strings (uninitialized memory) */
|
2019-09-08 00:12:26 +10:00
|
|
|
for (ntemp = inputs; ntemp->type >= 0; ntemp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntemp->identifier[0] = '\0';
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (ntemp = inputs; ntemp->type >= 0; ntemp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(ntemp->identifier, ntemp->name, sizeof(ntemp->identifier));
|
|
|
|
unique_socket_template_identifier(inputs, ntemp, ntemp->identifier, '_');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outputs) {
|
|
|
|
/* clear identifier strings (uninitialized memory) */
|
2019-09-08 00:12:26 +10:00
|
|
|
for (ntemp = outputs; ntemp->type >= 0; ntemp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntemp->identifier[0] = '\0';
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-09-08 00:12:26 +10:00
|
|
|
for (ntemp = outputs; ntemp->type >= 0; ntemp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(ntemp->identifier, ntemp->name, sizeof(ntemp->identifier));
|
|
|
|
unique_socket_template_identifier(outputs, ntemp, ntemp->identifier, '_');
|
|
|
|
}
|
|
|
|
}
|
2011-02-07 09:33:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_init(struct bNodeType *ntype,
|
|
|
|
void (*initfunc)(struct bNodeTree *ntree, struct bNode *node))
|
2011-02-08 09:02:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->initfunc = initfunc;
|
2011-02-08 09:02:16 +00:00
|
|
|
}
|
|
|
|
|
2011-02-07 09:33:36 +00:00
|
|
|
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->width = width;
|
|
|
|
ntype->minwidth = minwidth;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (maxwidth <= minwidth) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->maxwidth = FLT_MAX;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->maxwidth = maxwidth;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-02-07 09:33:36 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 10:46:27 +00:00
|
|
|
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (size) {
|
|
|
|
case NODE_SIZE_DEFAULT:
|
|
|
|
node_type_size(ntype, 140, 100, NODE_DEFAULT_MAX_WIDTH);
|
|
|
|
break;
|
|
|
|
case NODE_SIZE_SMALL:
|
|
|
|
node_type_size(ntype, 100, 80, NODE_DEFAULT_MAX_WIDTH);
|
|
|
|
break;
|
|
|
|
case NODE_SIZE_MIDDLE:
|
|
|
|
node_type_size(ntype, 150, 120, NODE_DEFAULT_MAX_WIDTH);
|
|
|
|
break;
|
|
|
|
case NODE_SIZE_LARGE:
|
|
|
|
node_type_size(ntype, 240, 140, NODE_DEFAULT_MAX_WIDTH);
|
|
|
|
break;
|
|
|
|
}
|
2013-02-22 10:46:27 +00:00
|
|
|
}
|
|
|
|
|
2015-10-30 10:49:22 +11:00
|
|
|
/**
|
|
|
|
* \warning Nodes defining a storage type _must_ allocate this for new nodes.
|
|
|
|
* Otherwise nodes will reload as undefined (T46619).
|
|
|
|
*/
|
2013-03-18 16:34:57 +00:00
|
|
|
void node_type_storage(bNodeType *ntype,
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *storagename,
|
|
|
|
void (*freefunc)(struct bNode *node),
|
|
|
|
void (*copyfunc)(struct bNodeTree *dest_ntree,
|
|
|
|
struct bNode *dest_node,
|
2019-06-03 17:08:25 +02:00
|
|
|
const struct bNode *src_node))
|
2011-02-07 09:33:36 +00:00
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (storagename) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(ntype->storagename, storagename, sizeof(ntype->storagename));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->storagename[0] = '\0';
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->copyfunc = copyfunc;
|
|
|
|
ntype->freefunc = freefunc;
|
2011-02-07 09:33:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_label(
|
|
|
|
struct bNodeType *ntype,
|
|
|
|
void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen))
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->labelfunc = labelfunc;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void node_type_update(struct bNodeType *ntype,
|
2019-04-20 20:25:22 +02:00
|
|
|
void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->updatefunc = updatefunc;
|
2019-04-20 20:25:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void node_type_group_update(struct bNodeType *ntype,
|
|
|
|
void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node))
|
|
|
|
{
|
|
|
|
ntype->group_update_func = group_update_func;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_exec(struct bNodeType *ntype,
|
|
|
|
NodeInitExecFunction initexecfunc,
|
|
|
|
NodeFreeExecFunction freeexecfunc,
|
|
|
|
NodeExecFunction execfunc)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->initexecfunc = initexecfunc;
|
|
|
|
ntype->freeexecfunc = freeexecfunc;
|
|
|
|
ntype->execfunc = execfunc;
|
2011-11-20 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpufunc)
|
2011-02-07 09:33:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->gpufunc = gpufunc;
|
2011-02-07 09:33:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void node_type_internal_links(bNodeType *ntype,
|
|
|
|
void (*update_internal_links)(bNodeTree *, bNode *))
|
2011-02-08 12:54:32 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntype->update_internal_links = update_internal_links;
|
2011-02-08 12:54:32 +00:00
|
|
|
}
|
2011-02-07 09:33:36 +00:00
|
|
|
|
2013-03-19 13:40:16 +00:00
|
|
|
/* callbacks for undefined types */
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool node_undefined_poll(bNodeType *UNUSED(ntype), bNodeTree *UNUSED(nodetree))
|
2013-03-19 13:40:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* this type can not be added deliberately, it's just a placeholder */
|
|
|
|
return false;
|
2013-03-19 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* register fallback types used for undefined tree, nodes, sockets */
|
|
|
|
static void register_undefined_types(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Note: these types are not registered in the type hashes,
|
|
|
|
* they are just used as placeholders in case the actual types are not registered.
|
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
strcpy(NodeTreeTypeUndefined.idname, "NodeTreeUndefined");
|
|
|
|
strcpy(NodeTreeTypeUndefined.ui_name, N_("Undefined"));
|
|
|
|
strcpy(NodeTreeTypeUndefined.ui_description, N_("Undefined Node Tree Type"));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
node_type_base_custom(&NodeTypeUndefined, "NodeUndefined", "Undefined", 0, 0);
|
|
|
|
NodeTypeUndefined.poll = node_undefined_poll;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(NodeSocketTypeUndefined.idname,
|
|
|
|
"NodeSocketUndefined",
|
|
|
|
sizeof(NodeSocketTypeUndefined.idname));
|
|
|
|
/* extra type info for standard socket types */
|
|
|
|
NodeSocketTypeUndefined.type = SOCK_CUSTOM;
|
|
|
|
NodeSocketTypeUndefined.subtype = PROP_NONE;
|
Nodes: Support storing socket link limits in bNodeSocketType
Currently the link limit of sockets is stored in bNodeSocket->limit.
This allows for a lot of flexibility, but is also very redundant.
In every case I've had to deal with so far, it would have "more correct"
to set the link limit per socket type and not per socket. I did not enforce
this constraint yet, because the link limit is exposed in the Python API,
which I did not want to break here.
In the future it might even make sense to only support only three kinds of link limits:
a) no links, b) at most one link, c) an arbitrary number links links. The other link
limits usually don't work well with tools (e.g. which link should be removed when a new
one is connected?) and is not used in practice. However, that is for another day.
Eventually, I would like to get rid of bNodeSocket->limit completely and replace it
either with fixed link limits or a callback in bNodeSocketType.
This patch consists of three parts:
**1. Support defining link limit in socket type**
This introduces a new `nodeSocketLinkLimit` function that serves as an indirection to
hide where the link limit of a socket is defined.
**2. Define link limits for builtin sockets on socket type**
Data sockets: one input, many outputs
Virtual sockets: one input, one output
Undefined sockets: many inputs, many outputs (to avoid that links are removed when the type of the socket is not known)
**3. Remove `bNodeSocketTemplate->limit`**
This wasn't used anymore after the second commit. Removing it simplifies socket definitions
in hundreds of places and removes a lot of redundancy.
Differential Revision: https://developer.blender.org/D7038
Reviewers: brecht
2020-03-06 12:20:05 +01:00
|
|
|
|
|
|
|
NodeSocketTypeUndefined.use_link_limits_of_type = true;
|
|
|
|
NodeSocketTypeUndefined.input_link_limit = 0xFFF;
|
|
|
|
NodeSocketTypeUndefined.output_link_limit = 0xFFF;
|
2013-03-19 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void registerCompositNodes(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_cmp_group();
|
|
|
|
|
|
|
|
register_node_type_cmp_rlayers();
|
|
|
|
register_node_type_cmp_image();
|
|
|
|
register_node_type_cmp_texture();
|
|
|
|
register_node_type_cmp_value();
|
|
|
|
register_node_type_cmp_rgb();
|
|
|
|
register_node_type_cmp_curve_time();
|
|
|
|
register_node_type_cmp_movieclip();
|
|
|
|
|
|
|
|
register_node_type_cmp_composite();
|
|
|
|
register_node_type_cmp_viewer();
|
|
|
|
register_node_type_cmp_splitviewer();
|
|
|
|
register_node_type_cmp_output_file();
|
|
|
|
register_node_type_cmp_view_levels();
|
|
|
|
|
|
|
|
register_node_type_cmp_curve_rgb();
|
|
|
|
register_node_type_cmp_mix_rgb();
|
|
|
|
register_node_type_cmp_hue_sat();
|
|
|
|
register_node_type_cmp_brightcontrast();
|
|
|
|
register_node_type_cmp_gamma();
|
|
|
|
register_node_type_cmp_invert();
|
|
|
|
register_node_type_cmp_alphaover();
|
|
|
|
register_node_type_cmp_zcombine();
|
|
|
|
register_node_type_cmp_colorbalance();
|
|
|
|
register_node_type_cmp_huecorrect();
|
|
|
|
|
|
|
|
register_node_type_cmp_normal();
|
|
|
|
register_node_type_cmp_curve_vec();
|
|
|
|
register_node_type_cmp_map_value();
|
|
|
|
register_node_type_cmp_map_range();
|
|
|
|
register_node_type_cmp_normalize();
|
|
|
|
|
|
|
|
register_node_type_cmp_filter();
|
|
|
|
register_node_type_cmp_blur();
|
|
|
|
register_node_type_cmp_dblur();
|
|
|
|
register_node_type_cmp_bilateralblur();
|
|
|
|
register_node_type_cmp_vecblur();
|
|
|
|
register_node_type_cmp_dilateerode();
|
|
|
|
register_node_type_cmp_inpaint();
|
|
|
|
register_node_type_cmp_despeckle();
|
|
|
|
register_node_type_cmp_defocus();
|
|
|
|
register_node_type_cmp_sunbeams();
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
register_node_type_cmp_denoise();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
register_node_type_cmp_valtorgb();
|
|
|
|
register_node_type_cmp_rgbtobw();
|
|
|
|
register_node_type_cmp_setalpha();
|
|
|
|
register_node_type_cmp_idmask();
|
|
|
|
register_node_type_cmp_math();
|
|
|
|
register_node_type_cmp_seprgba();
|
|
|
|
register_node_type_cmp_combrgba();
|
|
|
|
register_node_type_cmp_sephsva();
|
|
|
|
register_node_type_cmp_combhsva();
|
|
|
|
register_node_type_cmp_sepyuva();
|
|
|
|
register_node_type_cmp_combyuva();
|
|
|
|
register_node_type_cmp_sepycca();
|
|
|
|
register_node_type_cmp_combycca();
|
|
|
|
register_node_type_cmp_premulkey();
|
|
|
|
|
|
|
|
register_node_type_cmp_diff_matte();
|
|
|
|
register_node_type_cmp_distance_matte();
|
|
|
|
register_node_type_cmp_chroma_matte();
|
|
|
|
register_node_type_cmp_color_matte();
|
|
|
|
register_node_type_cmp_channel_matte();
|
|
|
|
register_node_type_cmp_color_spill();
|
|
|
|
register_node_type_cmp_luma_matte();
|
|
|
|
register_node_type_cmp_doubleedgemask();
|
|
|
|
register_node_type_cmp_keyingscreen();
|
|
|
|
register_node_type_cmp_keying();
|
|
|
|
register_node_type_cmp_cryptomatte();
|
|
|
|
|
|
|
|
register_node_type_cmp_translate();
|
|
|
|
register_node_type_cmp_rotate();
|
|
|
|
register_node_type_cmp_scale();
|
|
|
|
register_node_type_cmp_flip();
|
|
|
|
register_node_type_cmp_crop();
|
|
|
|
register_node_type_cmp_displace();
|
|
|
|
register_node_type_cmp_mapuv();
|
|
|
|
register_node_type_cmp_glare();
|
|
|
|
register_node_type_cmp_tonemap();
|
|
|
|
register_node_type_cmp_lensdist();
|
|
|
|
register_node_type_cmp_transform();
|
|
|
|
register_node_type_cmp_stabilize2d();
|
|
|
|
register_node_type_cmp_moviedistortion();
|
|
|
|
|
|
|
|
register_node_type_cmp_colorcorrection();
|
|
|
|
register_node_type_cmp_boxmask();
|
|
|
|
register_node_type_cmp_ellipsemask();
|
|
|
|
register_node_type_cmp_bokehimage();
|
|
|
|
register_node_type_cmp_bokehblur();
|
|
|
|
register_node_type_cmp_switch();
|
|
|
|
register_node_type_cmp_switch_view();
|
|
|
|
register_node_type_cmp_pixelate();
|
|
|
|
|
|
|
|
register_node_type_cmp_mask();
|
|
|
|
register_node_type_cmp_trackpos();
|
|
|
|
register_node_type_cmp_planetrackdeform();
|
|
|
|
register_node_type_cmp_cornerpin();
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
static void registerShaderNodes(void)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_sh_group();
|
|
|
|
|
|
|
|
register_node_type_sh_camera();
|
|
|
|
register_node_type_sh_gamma();
|
|
|
|
register_node_type_sh_brightcontrast();
|
|
|
|
register_node_type_sh_value();
|
|
|
|
register_node_type_sh_rgb();
|
|
|
|
register_node_type_sh_wireframe();
|
|
|
|
register_node_type_sh_wavelength();
|
|
|
|
register_node_type_sh_blackbody();
|
|
|
|
register_node_type_sh_mix_rgb();
|
|
|
|
register_node_type_sh_valtorgb();
|
|
|
|
register_node_type_sh_rgbtobw();
|
|
|
|
register_node_type_sh_shadertorgb();
|
|
|
|
register_node_type_sh_normal();
|
|
|
|
register_node_type_sh_mapping();
|
|
|
|
register_node_type_sh_curve_vec();
|
|
|
|
register_node_type_sh_curve_rgb();
|
2019-08-13 16:29:32 +02:00
|
|
|
register_node_type_sh_map_range();
|
2019-08-13 22:22:15 +02:00
|
|
|
register_node_type_sh_clamp();
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_sh_math();
|
|
|
|
register_node_type_sh_vect_math();
|
2020-02-17 15:15:46 +00:00
|
|
|
register_node_type_sh_vector_rotate();
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_sh_vect_transform();
|
|
|
|
register_node_type_sh_squeeze();
|
|
|
|
register_node_type_sh_invert();
|
|
|
|
register_node_type_sh_seprgb();
|
|
|
|
register_node_type_sh_combrgb();
|
|
|
|
register_node_type_sh_sephsv();
|
|
|
|
register_node_type_sh_combhsv();
|
|
|
|
register_node_type_sh_sepxyz();
|
|
|
|
register_node_type_sh_combxyz();
|
|
|
|
register_node_type_sh_hue_sat();
|
|
|
|
|
|
|
|
register_node_type_sh_attribute();
|
|
|
|
register_node_type_sh_bevel();
|
|
|
|
register_node_type_sh_displacement();
|
|
|
|
register_node_type_sh_vector_displacement();
|
|
|
|
register_node_type_sh_geometry();
|
|
|
|
register_node_type_sh_light_path();
|
|
|
|
register_node_type_sh_light_falloff();
|
|
|
|
register_node_type_sh_object_info();
|
|
|
|
register_node_type_sh_fresnel();
|
|
|
|
register_node_type_sh_layer_weight();
|
|
|
|
register_node_type_sh_tex_coord();
|
|
|
|
register_node_type_sh_particle_info();
|
|
|
|
register_node_type_sh_bump();
|
2019-09-12 17:42:13 +02:00
|
|
|
register_node_type_sh_vertex_color();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
register_node_type_sh_background();
|
|
|
|
register_node_type_sh_bsdf_anisotropic();
|
|
|
|
register_node_type_sh_bsdf_diffuse();
|
|
|
|
register_node_type_sh_bsdf_principled();
|
|
|
|
register_node_type_sh_bsdf_glossy();
|
|
|
|
register_node_type_sh_bsdf_glass();
|
|
|
|
register_node_type_sh_bsdf_translucent();
|
|
|
|
register_node_type_sh_bsdf_transparent();
|
|
|
|
register_node_type_sh_bsdf_velvet();
|
|
|
|
register_node_type_sh_bsdf_toon();
|
|
|
|
register_node_type_sh_bsdf_hair();
|
|
|
|
register_node_type_sh_bsdf_hair_principled();
|
|
|
|
register_node_type_sh_emission();
|
|
|
|
register_node_type_sh_holdout();
|
|
|
|
register_node_type_sh_volume_absorption();
|
|
|
|
register_node_type_sh_volume_scatter();
|
|
|
|
register_node_type_sh_volume_principled();
|
|
|
|
register_node_type_sh_subsurface_scattering();
|
|
|
|
register_node_type_sh_mix_shader();
|
|
|
|
register_node_type_sh_add_shader();
|
|
|
|
register_node_type_sh_uvmap();
|
|
|
|
register_node_type_sh_uvalongstroke();
|
|
|
|
register_node_type_sh_eevee_specular();
|
|
|
|
|
|
|
|
register_node_type_sh_output_light();
|
|
|
|
register_node_type_sh_output_material();
|
|
|
|
register_node_type_sh_output_world();
|
|
|
|
register_node_type_sh_output_linestyle();
|
2019-12-04 19:57:28 +01:00
|
|
|
register_node_type_sh_output_aov();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
register_node_type_sh_tex_image();
|
|
|
|
register_node_type_sh_tex_environment();
|
|
|
|
register_node_type_sh_tex_sky();
|
|
|
|
register_node_type_sh_tex_noise();
|
|
|
|
register_node_type_sh_tex_wave();
|
|
|
|
register_node_type_sh_tex_voronoi();
|
|
|
|
register_node_type_sh_tex_musgrave();
|
|
|
|
register_node_type_sh_tex_gradient();
|
|
|
|
register_node_type_sh_tex_magic();
|
|
|
|
register_node_type_sh_tex_checker();
|
|
|
|
register_node_type_sh_tex_brick();
|
|
|
|
register_node_type_sh_tex_pointdensity();
|
|
|
|
register_node_type_sh_tex_ies();
|
2019-08-21 20:04:09 +02:00
|
|
|
register_node_type_sh_tex_white_noise();
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void registerTextureNodes(void)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_tex_group();
|
|
|
|
|
|
|
|
register_node_type_tex_math();
|
|
|
|
register_node_type_tex_mix_rgb();
|
|
|
|
register_node_type_tex_valtorgb();
|
|
|
|
register_node_type_tex_rgbtobw();
|
|
|
|
register_node_type_tex_valtonor();
|
|
|
|
register_node_type_tex_curve_rgb();
|
|
|
|
register_node_type_tex_curve_time();
|
|
|
|
register_node_type_tex_invert();
|
|
|
|
register_node_type_tex_hue_sat();
|
|
|
|
register_node_type_tex_coord();
|
|
|
|
register_node_type_tex_distance();
|
|
|
|
register_node_type_tex_compose();
|
|
|
|
register_node_type_tex_decompose();
|
|
|
|
|
|
|
|
register_node_type_tex_output();
|
|
|
|
register_node_type_tex_viewer();
|
|
|
|
register_node_type_sh_script();
|
|
|
|
register_node_type_sh_tangent();
|
|
|
|
register_node_type_sh_normal_map();
|
|
|
|
register_node_type_sh_hair_info();
|
2019-08-21 20:22:24 +02:00
|
|
|
register_node_type_sh_volume_info();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
register_node_type_tex_checker();
|
|
|
|
register_node_type_tex_texture();
|
|
|
|
register_node_type_tex_bricks();
|
|
|
|
register_node_type_tex_image();
|
|
|
|
register_node_type_sh_bsdf_refraction();
|
|
|
|
register_node_type_sh_ambient_occlusion();
|
|
|
|
|
|
|
|
register_node_type_tex_rotate();
|
|
|
|
register_node_type_tex_translate();
|
|
|
|
register_node_type_tex_scale();
|
|
|
|
register_node_type_tex_at();
|
|
|
|
|
|
|
|
register_node_type_tex_proc_voronoi();
|
|
|
|
register_node_type_tex_proc_blend();
|
|
|
|
register_node_type_tex_proc_magic();
|
|
|
|
register_node_type_tex_proc_marble();
|
|
|
|
register_node_type_tex_proc_clouds();
|
|
|
|
register_node_type_tex_proc_wood();
|
|
|
|
register_node_type_tex_proc_musgrave();
|
|
|
|
register_node_type_tex_proc_noise();
|
|
|
|
register_node_type_tex_proc_stucci();
|
|
|
|
register_node_type_tex_proc_distnoise();
|
2008-02-09 23:17:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 10:58:43 +02:00
|
|
|
static void registerSimulationNodes(void)
|
|
|
|
{
|
|
|
|
register_node_type_sim_group();
|
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
void init_nodesystem(void)
|
2007-03-26 15:07:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
nodetreetypes_hash = BLI_ghash_str_new("nodetreetypes_hash gh");
|
|
|
|
nodetypes_hash = BLI_ghash_str_new("nodetypes_hash gh");
|
|
|
|
nodesockettypes_hash = BLI_ghash_str_new("nodesockettypes_hash gh");
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
register_undefined_types();
|
2013-03-19 13:40:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
register_standard_node_socket_types();
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_tree_type_cmp();
|
|
|
|
register_node_tree_type_sh();
|
|
|
|
register_node_tree_type_tex();
|
2020-04-20 10:58:43 +02:00
|
|
|
register_node_tree_type_sim();
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
register_node_type_frame();
|
|
|
|
register_node_type_reroute();
|
|
|
|
register_node_type_group_input();
|
|
|
|
register_node_type_group_output();
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
registerCompositNodes();
|
|
|
|
registerShaderNodes();
|
|
|
|
registerTextureNodes();
|
2020-04-20 10:58:43 +02:00
|
|
|
registerSimulationNodes();
|
2007-03-26 15:07:38 +00:00
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
void free_nodesystem(void)
|
2007-03-26 15:07:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (nodetypes_hash) {
|
|
|
|
NODE_TYPES_BEGIN (nt) {
|
2020-04-03 18:24:08 +02:00
|
|
|
if (nt->rna_ext.free) {
|
|
|
|
nt->rna_ext.free(nt->rna_ext.data);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NODE_TYPES_END;
|
|
|
|
|
|
|
|
BLI_ghash_free(nodetypes_hash, NULL, node_free_type);
|
|
|
|
nodetypes_hash = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodesockettypes_hash) {
|
|
|
|
NODE_SOCKET_TYPES_BEGIN (st) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (st->ext_socket.free) {
|
2019-04-17 06:17:24 +02:00
|
|
|
st->ext_socket.free(st->ext_socket.data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
if (st->ext_interface.free) {
|
2019-04-17 06:17:24 +02:00
|
|
|
st->ext_interface.free(st->ext_interface.data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
NODE_SOCKET_TYPES_END;
|
|
|
|
|
|
|
|
BLI_ghash_free(nodesockettypes_hash, NULL, node_free_socket_type);
|
|
|
|
nodesockettypes_hash = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodetreetypes_hash) {
|
|
|
|
NODE_TREE_TYPES_BEGIN (nt) {
|
2020-04-03 18:24:08 +02:00
|
|
|
if (nt->rna_ext.free) {
|
|
|
|
nt->rna_ext.free(nt->rna_ext.data);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
NODE_TREE_TYPES_END;
|
|
|
|
|
|
|
|
BLI_ghash_free(nodetreetypes_hash, NULL, ntree_free_type);
|
|
|
|
nodetreetypes_hash = NULL;
|
|
|
|
}
|
2007-03-26 15:07:38 +00:00
|
|
|
}
|
2009-08-15 16:43:03 +00:00
|
|
|
|
2013-03-26 22:37:41 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
2018-11-30 15:22:01 +11:00
|
|
|
/* NodeTree Iterator Helpers (FOREACH_NODETREE_BEGIN) */
|
2013-03-26 22:37:41 +00:00
|
|
|
|
|
|
|
void BKE_node_tree_iter_init(struct NodeTreeIterStore *ntreeiter, struct Main *bmain)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ntreeiter->ngroup = bmain->nodetrees.first;
|
|
|
|
ntreeiter->scene = bmain->scenes.first;
|
|
|
|
ntreeiter->mat = bmain->materials.first;
|
|
|
|
ntreeiter->tex = bmain->textures.first;
|
|
|
|
ntreeiter->light = bmain->lights.first;
|
|
|
|
ntreeiter->world = bmain->worlds.first;
|
|
|
|
ntreeiter->linestyle = bmain->linestyles.first;
|
2013-03-26 22:37:41 +00:00
|
|
|
}
|
|
|
|
bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
|
2019-04-17 06:17:24 +02:00
|
|
|
bNodeTree **r_nodetree,
|
|
|
|
struct ID **r_id)
|
|
|
|
{
|
|
|
|
if (ntreeiter->ngroup) {
|
|
|
|
*r_nodetree = ntreeiter->ngroup;
|
|
|
|
*r_id = (ID *)ntreeiter->ngroup;
|
|
|
|
ntreeiter->ngroup = ntreeiter->ngroup->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->scene) {
|
|
|
|
*r_nodetree = ntreeiter->scene->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->scene;
|
|
|
|
ntreeiter->scene = ntreeiter->scene->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->mat) {
|
|
|
|
*r_nodetree = ntreeiter->mat->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->mat;
|
|
|
|
ntreeiter->mat = ntreeiter->mat->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->tex) {
|
|
|
|
*r_nodetree = ntreeiter->tex->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->tex;
|
|
|
|
ntreeiter->tex = ntreeiter->tex->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->light) {
|
|
|
|
*r_nodetree = ntreeiter->light->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->light;
|
|
|
|
ntreeiter->light = ntreeiter->light->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->world) {
|
|
|
|
*r_nodetree = ntreeiter->world->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->world;
|
|
|
|
ntreeiter->world = ntreeiter->world->id.next;
|
|
|
|
}
|
|
|
|
else if (ntreeiter->linestyle) {
|
|
|
|
*r_nodetree = ntreeiter->linestyle->nodetree;
|
|
|
|
*r_id = (ID *)ntreeiter->linestyle;
|
|
|
|
ntreeiter->linestyle = ntreeiter->linestyle->id.next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-03-26 22:37:41 +00:00
|
|
|
}
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/* NodeTree kernel functions */
|
|
|
|
|
|
|
|
void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(layer_index != -1);
|
2020-04-03 19:15:01 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
|
|
|
|
if (node->custom1 == layer_index) {
|
|
|
|
node->custom1 = 0;
|
|
|
|
}
|
|
|
|
else if (node->custom1 > layer_index) {
|
|
|
|
node->custom1--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
}
|
2017-08-29 12:20:55 +02:00
|
|
|
|
2018-05-02 11:46:56 +02:00
|
|
|
void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph,
|
2017-08-29 12:51:56 +02:00
|
|
|
bNodeTree *ntree_dst,
|
|
|
|
const bNodeTree *ntree_src)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_debug_print_eval(depsgraph, __func__, ntree_src->id.name, ntree_dst);
|
2017-08-29 12:51:56 +02:00
|
|
|
}
|