|
Blender
V2.59
|
00001 /* 00002 * 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2006 Blender Foundation. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): Robin Allen 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00034 #include "../TEX_util.h" 00035 #include "TEX_node.h" 00036 00037 /* **************** COMPOSITE ******************** */ 00038 static bNodeSocketType inputs[]= { 00039 { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 00040 { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f}, 00041 { -1, 0, "" } 00042 }; 00043 00044 /* applies to render pipeline */ 00045 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **UNUSED(out)) 00046 { 00047 TexCallData *cdata = (TexCallData *)data; 00048 TexResult *target = cdata->target; 00049 00050 if(cdata->do_preview) { 00051 TexParams params; 00052 params_from_cdata(¶ms, cdata); 00053 00054 if(in[1] && in[1]->hasinput && !in[0]->hasinput) 00055 tex_input_rgba(&target->tr, in[1], ¶ms, cdata->thread); 00056 else 00057 tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); 00058 tex_do_preview(node, params.co, &target->tr); 00059 } 00060 else { 00061 /* 0 means don't care, so just use first */ 00062 if(cdata->which_output == node->custom1 || (cdata->which_output == 0 && node->custom1 == 1)) { 00063 TexParams params; 00064 params_from_cdata(¶ms, cdata); 00065 00066 tex_input_rgba(&target->tr, in[0], ¶ms, cdata->thread); 00067 00068 target->tin = (target->tr + target->tg + target->tb) / 3.0f; 00069 target->talpha = 1; 00070 00071 if(target->nor) { 00072 if(in[1] && in[1]->hasinput) 00073 tex_input_vec(target->nor, in[1], ¶ms, cdata->thread); 00074 else 00075 target->nor = NULL; 00076 } 00077 } 00078 } 00079 } 00080 00081 static void unique_name(bNode *node) 00082 { 00083 TexNodeOutput *tno = (TexNodeOutput *)node->storage; 00084 char *new_name = NULL; 00085 int new_len = 0; 00086 int suffix; 00087 bNode *i; 00088 char *name = tno->name; 00089 00090 i = node; 00091 while(i->prev) i = i->prev; 00092 for(; i; i=i->next) { 00093 if( 00094 i == node || 00095 i->type != TEX_NODE_OUTPUT || 00096 strcmp(name, ((TexNodeOutput*)(i->storage))->name) 00097 ) 00098 continue; 00099 00100 if(!new_name) { 00101 int len = strlen(name); 00102 if(len >= 4 && sscanf(name + len - 4, ".%03d", &suffix) == 1) { 00103 new_len = len; 00104 } else { 00105 suffix = 0; 00106 new_len = len + 4; 00107 if(new_len > 31) 00108 new_len = 31; 00109 } 00110 00111 new_name = MEM_mallocN(new_len + 1, "new_name"); 00112 strcpy(new_name, name); 00113 name = new_name; 00114 } 00115 sprintf(new_name + new_len - 4, ".%03d", ++suffix); 00116 } 00117 00118 if(new_name) { 00119 strcpy(tno->name, new_name); 00120 MEM_freeN(new_name); 00121 } 00122 } 00123 00124 static void assign_index(struct bNode *node) 00125 { 00126 bNode *tnode; 00127 int index = 1; 00128 00129 tnode = node; 00130 while(tnode->prev) 00131 tnode = tnode->prev; 00132 00133 check_index: 00134 for(; tnode; tnode= tnode->next) 00135 if(tnode->type == TEX_NODE_OUTPUT && tnode != node) 00136 if(tnode->custom1 == index) { 00137 index ++; 00138 goto check_index; 00139 } 00140 00141 node->custom1 = index; 00142 } 00143 00144 static void init(bNode *node) 00145 { 00146 TexNodeOutput *tno = MEM_callocN(sizeof(TexNodeOutput), "TEX_output"); 00147 node->storage= tno; 00148 00149 strcpy(tno->name, "Default"); 00150 unique_name(node); 00151 assign_index(node); 00152 } 00153 00154 static void copy(bNode *orig, bNode *new) 00155 { 00156 node_copy_standard_storage(orig, new); 00157 unique_name(new); 00158 assign_index(new); 00159 } 00160 00161 void register_node_type_tex_output(ListBase *lb) 00162 { 00163 static bNodeType ntype; 00164 00165 node_type_base(&ntype, TEX_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW|NODE_OPTIONS, 00166 inputs, NULL); 00167 node_type_size(&ntype, 150, 60, 200); 00168 node_type_init(&ntype, init); 00169 node_type_storage(&ntype, "TexNodeOutput", node_free_standard_storage, copy); 00170 node_type_exec(&ntype, exec); 00171 00172 nodeRegisterType(lb, &ntype); 00173 }