2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2007-04-04 13:58:12 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-04-04 13:58:12 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Nathan Letwory.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:13:22 +00:00
|
|
|
/** \file blender/nodes/intern/node_util.c
|
|
|
|
* \ingroup nodes
|
|
|
|
*/
|
|
|
|
|
2012-08-09 11:45:54 +00:00
|
|
|
#include <limits.h>
|
2013-03-18 16:34:57 +00:00
|
|
|
#include <string.h>
|
2011-02-27 20:13:22 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "DNA_action_types.h"
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2012-03-17 14:42:44 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_colortools.h"
|
|
|
|
#include "BKE_node.h"
|
2007-04-04 13:58:12 +00:00
|
|
|
|
2011-02-08 12:54:32 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "node_util.h"
|
|
|
|
|
|
|
|
/**** Storage Data ****/
|
|
|
|
|
2007-04-05 10:49:25 +00:00
|
|
|
void node_free_curves(bNode *node)
|
2007-04-04 13:58:12 +00:00
|
|
|
{
|
|
|
|
curvemapping_free(node->storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_free_standard_storage(bNode *node)
|
|
|
|
{
|
2012-05-21 08:10:37 +00:00
|
|
|
if (node->storage) {
|
|
|
|
MEM_freeN(node->storage);
|
|
|
|
}
|
2007-04-04 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void node_copy_curves(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node)
|
2007-04-04 13:58:12 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
dest_node->storage = curvemapping_copy(src_node->storage);
|
2007-04-04 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bNode *src_node)
|
2007-04-04 13:58:12 +00:00
|
|
|
{
|
2013-03-18 16:34:57 +00:00
|
|
|
dest_node->storage = MEM_dupallocN(src_node->storage);
|
2007-04-04 13:58:12 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNodeInstanceKey UNUSED(key))
|
2012-08-29 07:58:36 +00:00
|
|
|
{
|
|
|
|
curvemapping_initialize(node->storage);
|
|
|
|
return NULL; /* unused return */
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/**** Labels ****/
|
|
|
|
|
2011-02-08 12:54:32 +00:00
|
|
|
const char *node_blend_label(bNode *node)
|
|
|
|
{
|
|
|
|
const char *name;
|
2011-03-19 10:26:15 +00:00
|
|
|
RNA_enum_name(ramp_blend_items, node->custom1, &name);
|
2012-03-17 14:42:44 +00:00
|
|
|
return IFACE_(name);
|
2011-02-08 12:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *node_math_label(bNode *node)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
RNA_enum_name(node_math_items, node->custom1, &name);
|
2012-03-17 14:42:44 +00:00
|
|
|
return IFACE_(name);
|
2011-02-08 12:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *node_vect_math_label(bNode *node)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
RNA_enum_name(node_vec_math_items, node->custom1, &name);
|
2012-03-17 14:42:44 +00:00
|
|
|
return IFACE_(name);
|
2011-02-08 12:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *node_filter_label(bNode *node)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
RNA_enum_name(node_filter_items, node->custom1, &name);
|
2012-03-17 14:42:44 +00:00
|
|
|
return IFACE_(name);
|
2011-02-08 12:54:32 +00:00
|
|
|
}
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2012-10-25 16:49:06 +00:00
|
|
|
void node_update_internal_links_default(bNodeTree *ntree, bNode *node)
|
2011-11-20 16:38:23 +00:00
|
|
|
{
|
2013-09-02 17:08:03 +00:00
|
|
|
bNodeLink *link;
|
|
|
|
bNodeSocket *output, *input, *selected;
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2013-09-02 17:08:03 +00:00
|
|
|
/* sanity check */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ntree)
|
2012-10-25 16:49:06 +00:00
|
|
|
return;
|
2011-11-20 16:38:23 +00:00
|
|
|
|
2013-09-02 17:08:03 +00:00
|
|
|
/* use link pointer as a tag for handled sockets (for outputs is unused anyway) */
|
|
|
|
for (output = node->outputs.first; output; output = output->next)
|
|
|
|
output->link = NULL;
|
|
|
|
|
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
output = link->fromsock;
|
|
|
|
if (link->fromnode != node || output->link)
|
|
|
|
continue;
|
|
|
|
output->link = link; /* not really used, just for tagging handled sockets */
|
2012-03-22 16:07:41 +00:00
|
|
|
|
2013-09-02 17:08:03 +00:00
|
|
|
/* look for suitable input */
|
|
|
|
selected = NULL;
|
|
|
|
for (input = node->inputs.first; input; input = input->next) {
|
|
|
|
/* only use if same type */
|
|
|
|
if (input->type == output->type) {
|
|
|
|
if (!selected) {
|
|
|
|
selected = input;
|
2012-08-09 11:45:54 +00:00
|
|
|
}
|
2013-09-02 17:08:03 +00:00
|
|
|
else {
|
|
|
|
/* linked inputs preferred */
|
|
|
|
if (input->link && !selected->link)
|
|
|
|
selected = input;
|
2012-03-22 16:07:41 +00:00
|
|
|
}
|
2011-11-20 16:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-02 17:08:03 +00:00
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link");
|
|
|
|
ilink->fromnode = node;
|
|
|
|
ilink->fromsock = selected;
|
|
|
|
ilink->tonode = node;
|
|
|
|
ilink->tosock = output;
|
|
|
|
/* internal link is always valid */
|
|
|
|
ilink->flag |= NODE_LINK_VALID;
|
|
|
|
BLI_addtail(&node->internal_links, ilink);
|
2012-08-09 11:45:54 +00:00
|
|
|
}
|
2011-11-20 16:38:23 +00:00
|
|
|
}
|
2012-03-22 16:07:41 +00:00
|
|
|
|
2013-09-02 17:08:03 +00:00
|
|
|
/* clean up */
|
|
|
|
for (output = node->outputs.first; output; output = output->next)
|
|
|
|
output->link = NULL;
|
2011-11-20 16:38:23 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
float node_socket_get_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
return RNA_float_get(&ptr, "default_value");
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_socket_set_float(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
RNA_float_set(&ptr, "default_value", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_socket_get_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
RNA_float_get_array(&ptr, "default_value", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_socket_set_color(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
RNA_float_set_array(&ptr, "default_value", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_socket_get_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, float *value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
RNA_float_get_array(&ptr, "default_value", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void node_socket_set_vector(bNodeTree *ntree, bNode *UNUSED(node), bNodeSocket *sock, const float *value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
|
|
|
|
RNA_float_set_array(&ptr, "default_value", value);
|
|
|
|
}
|