Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2007 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): Nathan Letwory. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "DNA_action_types.h" 00034 #include "DNA_node_types.h" 00035 00036 #include "BLI_listbase.h" 00037 #include "BLI_utildefines.h" 00038 00039 #include "BKE_colortools.h" 00040 #include "BKE_node.h" 00041 00042 #include "RNA_access.h" 00043 #include "RNA_enum_types.h" 00044 00045 #include "MEM_guardedalloc.h" 00046 00047 #include "node_util.h" 00048 00049 /**** Storage Data ****/ 00050 00051 void node_free_curves(bNode *node) 00052 { 00053 curvemapping_free(node->storage); 00054 } 00055 00056 void node_free_standard_storage(bNode *node) 00057 { 00058 MEM_freeN(node->storage); 00059 } 00060 00061 void node_copy_curves(bNode *orig_node, bNode *new_node) 00062 { 00063 new_node->storage= curvemapping_copy(orig_node->storage); 00064 } 00065 00066 void node_copy_standard_storage(bNode *orig_node, bNode *new_node) 00067 { 00068 new_node->storage= MEM_dupallocN(orig_node->storage); 00069 } 00070 00071 /**** Labels ****/ 00072 00073 const char *node_blend_label(bNode *node) 00074 { 00075 const char *name; 00076 RNA_enum_name(ramp_blend_items, node->custom1, &name); 00077 return name; 00078 } 00079 00080 const char *node_math_label(bNode *node) 00081 { 00082 const char *name; 00083 RNA_enum_name(node_math_items, node->custom1, &name); 00084 return name; 00085 } 00086 00087 const char *node_vect_math_label(bNode *node) 00088 { 00089 const char *name; 00090 RNA_enum_name(node_vec_math_items, node->custom1, &name); 00091 return name; 00092 } 00093 00094 const char *node_filter_label(bNode *node) 00095 { 00096 const char *name; 00097 RNA_enum_name(node_filter_items, node->custom1, &name); 00098 return name; 00099 } 00100 00101 /* Returns a list of mapping of some input bNodeStack, GPUNodeStack or bNodeSocket 00102 * to one or more outputs of the same type. 00103 * *ntree or (**nsin, **nsout) or (*gnsin, *gnsout) must not be NULL. */ 00104 ListBase node_mute_get_links(bNodeTree *ntree, bNode *node, bNodeStack **nsin, bNodeStack **nsout, 00105 GPUNodeStack *gnsin, GPUNodeStack *gnsout) 00106 { 00107 static int types[] = { SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA }; 00108 bNodeLink link = {NULL}; 00109 ListBase ret; 00110 LinkInOutsMuteNode *lnk; 00111 int in, out, i; 00112 00113 ret.first = ret.last = NULL; 00114 00115 /* Security check! */ 00116 if(!(ntree || (nsin && nsout) || (gnsin && gnsout))) 00117 return ret; 00118 00119 /* Connect the first input of each type with first output of the same type. */ 00120 00121 link.fromnode = link.tonode = node; 00122 for (i=0; i < 3; ++i) { 00123 /* find input socket */ 00124 for (in=0, link.fromsock=node->inputs.first; link.fromsock; in++, link.fromsock=link.fromsock->next) { 00125 if (link.fromsock->type==types[i] && (ntree ? nodeCountSocketLinks(ntree, link.fromsock) : nsin ? nsin[in]->hasinput : gnsin[in].hasinput)) 00126 break; 00127 } 00128 if (link.fromsock) { 00129 for (out=0, link.tosock=node->outputs.first; link.tosock; out++, link.tosock=link.tosock->next) { 00130 if (link.tosock->type==types[i] && (ntree ? nodeCountSocketLinks(ntree, link.tosock) : nsout ? nsout[out]->hasoutput : gnsout[out].hasoutput)) 00131 break; 00132 } 00133 if (link.tosock) { 00134 if(nsin && nsout) { 00135 lnk = MEM_mallocN(sizeof(LinkInOutsMuteNode), "Muting node: new in to outs link."); 00136 lnk->in = nsin[in]; 00137 lnk->outs = nsout[out]; 00138 lnk->num_outs = 1; 00139 BLI_addtail(&ret, lnk); 00140 } 00141 else if(gnsin && gnsout) { 00142 lnk = MEM_mallocN(sizeof(LinkInOutsMuteNode), "Muting node: new in to outs link."); 00143 lnk->in = &gnsin[in]; 00144 lnk->outs = &gnsout[out]; 00145 lnk->num_outs = 1; 00146 BLI_addtail(&ret, lnk); 00147 } 00148 else { 00149 lnk = MEM_mallocN(sizeof(LinkInOutsMuteNode), "Muting node: new in to outs link."); 00150 lnk->in = link.fromsock; 00151 lnk->outs = link.tosock; 00152 lnk->num_outs = 1; 00153 BLI_addtail(&ret, lnk); 00154 } 00155 } 00156 } 00157 } 00158 00159 return ret; 00160 }