Blender  V2.59
BKE_node.h
Go to the documentation of this file.
00001 /*
00002  * $Id: BKE_node.h 38092 2011-07-04 19:22:37Z jbakker $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. The Blender
00010  * Foundation also sells licenses for use in proprietary software under
00011  * the Blender License.  See http://www.blender.org/BL/ for information
00012  * about this.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00022  *
00023  * The Original Code is Copyright (C) 2005 Blender Foundation.
00024  * All rights reserved.
00025  *
00026  * The Original Code is: all of this file.
00027  *
00028  * Contributor(s): Bob Holcomb.
00029  *
00030  * ***** END GPL LICENSE BLOCK *****
00031  */
00032 
00033 #ifndef BKE_NODE_H
00034 #define BKE_NODE_H
00035 
00040 /* not very important, but the stack solver likes to know a maximum */
00041 #define MAX_SOCKET      64
00042 
00043 struct bContext;
00044 struct bNode;
00045 struct bNodeLink;
00046 struct bNodeSocket;
00047 struct bNodeStack;
00048 struct bNodeTree;
00049 struct GPUMaterial;
00050 struct GPUNode;
00051 struct GPUNodeStack;
00052 struct ID;
00053 struct ListBase;
00054 struct Main;
00055 struct MTex;
00056 struct PointerRNA;
00057 struct rctf;
00058 struct RenderData;
00059 struct Scene;
00060 struct Tex;
00061 struct uiLayout;
00062 
00063 
00064 /* ************** NODE TYPE DEFINITIONS ***** */
00065 
00066 typedef struct bNodeSocketType {
00067         int type, limit;
00068         const char *name;
00069         float val1, val2, val3, val4;   /* default alloc value for inputs */
00070         float min, max;                                 /* default range for inputs */
00071         
00072         /* after this line is used internal only */
00073         struct bNodeSocket *sock;               /* used during verify_types */
00074 } bNodeSocketType;
00075 
00076 typedef struct bNodeType {
00077         void *next,*prev;
00078         int type;
00079         const char *name; /* can be allocated too */
00080         float width, minwidth, maxwidth;
00081         short nclass, flag;
00082         
00083         bNodeSocketType *inputs, *outputs;
00084         
00085         char storagename[64];                   /* struct name for DNA */
00086         
00087         void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **);
00088         
00089         /* this line is set on startup of blender */
00090         void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
00091         void (*uifuncbut)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
00092         const char *(*labelfunc)(struct bNode *);
00093 
00094         void (*initfunc)(struct bNode *);
00095         void (*freestoragefunc)(struct bNode *);
00096         void (*copystoragefunc)(struct bNode *, struct bNode *);
00097         
00098         /* for use with dynamic typedefs */
00099         ID *id;
00100         void *pynode; /* holds pointer to python script */
00101         void *pydict; /* holds pointer to python script dictionary (scope)*/
00102 
00103         /* gpu */
00104         int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
00105 
00106 } bNodeType;
00107 
00108 /* node->exec, now in use for composites (#define for break is same as ready yes) */
00109 #define NODE_PROCESSING 1
00110 #define NODE_READY              2
00111 #define NODE_BREAK              2
00112 #define NODE_FINISHED   4
00113 #define NODE_FREEBUFS   8
00114 #define NODE_SKIPPED    16
00115 
00116 /* nodetype->nclass, for add-menu and themes */
00117 #define NODE_CLASS_INPUT                0
00118 #define NODE_CLASS_OUTPUT               1
00119 #define NODE_CLASS_OP_COLOR             3
00120 #define NODE_CLASS_OP_VECTOR    4
00121 #define NODE_CLASS_OP_FILTER    5
00122 #define NODE_CLASS_GROUP                6
00123 #define NODE_CLASS_FILE                 7
00124 #define NODE_CLASS_CONVERTOR    8
00125 #define NODE_CLASS_MATTE                9
00126 #define NODE_CLASS_DISTORT              10
00127 #define NODE_CLASS_OP_DYNAMIC   11
00128 #define NODE_CLASS_PATTERN 12
00129 #define NODE_CLASS_TEXTURE 13
00130 
00131 /* enum values for input/output */
00132 #define SOCK_IN         1
00133 #define SOCK_OUT        2
00134 
00135 /* ************** GENERIC API, TREES *************** */
00136 
00137 void                    ntreeVerifyTypes(struct bNodeTree *ntree);
00138 
00139 struct bNodeTree *ntreeAddTree(const char *name, int type, const short is_group);
00140 void                    ntreeInitTypes(struct bNodeTree *ntree);
00141 
00142 //void                  ntreeMakeGroupSockets(struct bNodeTree *ntree);
00143 void                    ntreeUpdateType(struct bNodeTree *ntree, struct bNodeType *ntype);
00144 void                    ntreeFreeTree(struct bNodeTree *ntree);
00145 struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree);
00146 void                    ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to);
00147 void                    ntreeMakeLocal(struct bNodeTree *ntree);
00148 
00149 void                    ntreeSocketUseFlags(struct bNodeTree *ntree);
00150 
00151 void                    ntreeSolveOrder(struct bNodeTree *ntree);
00152 
00153 void                    ntreeBeginExecTree(struct bNodeTree *ntree);
00154 void                    ntreeExecTree(struct bNodeTree *ntree, void *callerdata, int thread);
00155 void                    ntreeCompositExecTree(struct bNodeTree *ntree, struct RenderData *rd, int do_previews);
00156 void                    ntreeEndExecTree(struct bNodeTree *ntree);
00157 
00158 void                    ntreeInitPreview(struct bNodeTree *, int xsize, int ysize);
00159 void                    ntreeClearPreview(struct bNodeTree *ntree);
00160 
00161 void                    ntreeFreeCache(struct bNodeTree *ntree);
00162                                 
00163                                 /* calls allowing threaded composite */
00164 struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree);
00165 void                    ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree);
00166 void                    ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree);
00167 
00168 /* ************** GENERIC API, NODES *************** */
00169 
00170 void                    nodeVerifyType(struct bNodeTree *ntree, struct bNode *node);
00171 
00172 void                    nodeAddToPreview(struct bNode *, float *, int, int, int);
00173 
00174 void                    nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
00175 void                    nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
00176 void                    nodeAddSockets(struct bNode *node, struct bNodeType *ntype);
00177 struct bNode    *nodeAddNodeType(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup, struct ID *id);
00178 void                    nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ;
00179 void                    nodeUpdateType(struct bNodeTree *ntree, struct bNode* node, struct bNodeType *ntype);
00180 void                    nodeMakeDynamicType(struct bNode *node);
00181 int                             nodeDynamicUnlinkText(struct ID *txtid);
00182 void                    nodeFreeNode(struct bNodeTree *ntree, struct bNode *node);
00183 struct bNode    *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node);
00184 
00185 struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock);
00186 void                    nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
00187 void                    nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
00188 
00189 struct bNode    *nodeFindNodebyName(struct bNodeTree *ntree, const char *name);
00190 int                             nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex, int *in_out);
00191 
00192 struct bNodeLink *nodeFindLink(struct bNodeTree *ntree, struct bNodeSocket *from, struct bNodeSocket *to);
00193 int                             nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
00194 
00195 void                    nodeSetActive(struct bNodeTree *ntree, struct bNode *node);
00196 struct bNode    *nodeGetActive(struct bNodeTree *ntree);
00197 struct bNode    *nodeGetActiveID(struct bNodeTree *ntree, short idtype);
00198 int                             nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id);
00199 void                    nodeClearActiveID(struct bNodeTree *ntree, short idtype);
00200 
00201 void                    NodeTagChanged(struct bNodeTree *ntree, struct bNode *node);
00202 int                             NodeTagIDChanged(struct bNodeTree *ntree, struct ID *id);
00203 void                    ntreeClearTags(struct bNodeTree *ntree);
00204 
00205 /* ************** Groups ****************** */
00206 
00207 struct bNode    *nodeMakeGroupFromSelected(struct bNodeTree *ntree);
00208 int                             nodeGroupUnGroup(struct bNodeTree *ntree, struct bNode *gnode);
00209 
00210 void                    nodeGroupVerify(struct bNodeTree *ngroup);
00211 void                    nodeGroupSocketUseFlags(struct bNodeTree *ngroup);
00212 
00213 void                    nodeGroupCopy(struct bNode *gnode);
00214 
00215 struct bNodeSocket *nodeGroupAddSocket(struct bNodeTree *ngroup, const char *name, int type, int in_out);
00216 struct bNodeSocket *nodeGroupExposeSocket(struct bNodeTree *ngroup, struct bNodeSocket *sock, int in_out);
00217 void                    nodeGroupExposeAllSockets(struct bNodeTree *ngroup);
00218 void                    nodeGroupRemoveSocket(struct bNodeTree *ngroup, struct bNodeSocket *gsock, int in_out);
00219 
00220 /* ************** COMMON NODES *************** */
00221 
00222 /* Init a new node type struct with default values and callbacks */
00223 void                    node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag,
00224                                                            struct bNodeSocketType *inputs, struct bNodeSocketType *outputs);
00225 void                    node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth);
00226 void                    node_type_init(struct bNodeType *ntype, void (*initfunc)(struct bNode *));
00227 void                    node_type_storage(struct bNodeType *ntype,
00228                                                                   const char *storagename,
00229                                                                   void (*freestoragefunc)(struct bNode *),
00230                                                                   void (*copystoragefunc)(struct bNode *, struct bNode *));
00231 void                    node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **));
00232 void                    node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
00233 void                    node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *));
00234 
00235 #define NODE_GROUP              2
00236 #define NODE_GROUP_MENU         1000
00237 #define NODE_DYNAMIC_MENU       4000
00238 
00239 void register_node_type_group(ListBase *lb);
00240 
00241 /* ************** SHADER NODES *************** */
00242 
00243 struct ShadeInput;
00244 struct ShadeResult;
00245 
00246 /* note: types are needed to restore callbacks, don't change values */
00247 /* range 1 - 100 is reserved for common nodes */
00248 /* using toolbox, we add node groups by assuming the values below don't exceed NODE_GROUP_MENU for now */
00249 
00250 #define SH_NODE_OUTPUT          1
00251 
00252 #define SH_NODE_MATERIAL        100
00253 #define SH_NODE_RGB                     101
00254 #define SH_NODE_VALUE           102
00255 #define SH_NODE_MIX_RGB         103
00256 #define SH_NODE_VALTORGB        104
00257 #define SH_NODE_RGBTOBW         105
00258 #define SH_NODE_TEXTURE         106
00259 #define SH_NODE_NORMAL          107
00260 #define SH_NODE_GEOMETRY        108
00261 #define SH_NODE_MAPPING         109
00262 #define SH_NODE_CURVE_VEC       110
00263 #define SH_NODE_CURVE_RGB       111
00264 #define SH_NODE_CAMERA          114
00265 #define SH_NODE_MATH            115
00266 #define SH_NODE_VECT_MATH       116
00267 #define SH_NODE_SQUEEZE         117
00268 #define SH_NODE_MATERIAL_EXT    118
00269 #define SH_NODE_INVERT          119
00270 #define SH_NODE_SEPRGB          120
00271 #define SH_NODE_COMBRGB         121
00272 #define SH_NODE_HUE_SAT         122
00273 #define NODE_DYNAMIC            123
00274 
00275 /* custom defines options for Material node */
00276 #define SH_NODE_MAT_DIFF   1
00277 #define SH_NODE_MAT_SPEC   2
00278 #define SH_NODE_MAT_NEG    4
00279 /* custom defines: states for Script node. These are bit indices */
00280 #define NODE_DYNAMIC_READY      0 /* 1 */
00281 #define NODE_DYNAMIC_LOADED     1 /* 2 */
00282 #define NODE_DYNAMIC_NEW        2 /* 4 */
00283 #define NODE_DYNAMIC_UPDATED    3 /* 8 */
00284 #define NODE_DYNAMIC_ADDEXIST   4 /* 16 */
00285 #define NODE_DYNAMIC_ERROR      5 /* 32 */
00286 #define NODE_DYNAMIC_REPARSE    6 /* 64 */
00287 #define NODE_DYNAMIC_SET        15 /* sign */
00288 
00289 /* the type definitions array */
00290 extern struct ListBase node_all_shaders;
00291 
00292 /* API */
00293 
00294 void                    ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr);
00295 void                    ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode);
00296 void                    nodeShaderSynchronizeID(struct bNode *node, int copyto);
00297 
00298                                 /* switch material render loop */
00299 extern void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *);
00300 void                    set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *));
00301 
00302 void                    ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
00303 
00304 
00305 /* ************** COMPOSITE NODES *************** */
00306 
00307 /* output socket defines */
00308 #define RRES_OUT_IMAGE          0
00309 #define RRES_OUT_ALPHA          1
00310 #define RRES_OUT_Z                      2
00311 #define RRES_OUT_NORMAL         3
00312 #define RRES_OUT_UV                     4
00313 #define RRES_OUT_VEC            5
00314 #define RRES_OUT_RGBA           6
00315 #define RRES_OUT_DIFF           7
00316 #define RRES_OUT_SPEC           8
00317 #define RRES_OUT_SHADOW         9
00318 #define RRES_OUT_AO                     10
00319 #define RRES_OUT_REFLECT        11
00320 #define RRES_OUT_REFRACT        12
00321 #define RRES_OUT_INDIRECT       13
00322 #define RRES_OUT_INDEXOB        14
00323 #define RRES_OUT_INDEXMA        15
00324 #define RRES_OUT_MIST           16
00325 #define RRES_OUT_EMIT           17
00326 #define RRES_OUT_ENV            18
00327 
00328 /* note: types are needed to restore callbacks, don't change values */
00329 #define CMP_NODE_VIEWER         201
00330 #define CMP_NODE_RGB            202
00331 #define CMP_NODE_VALUE          203
00332 #define CMP_NODE_MIX_RGB        204
00333 #define CMP_NODE_VALTORGB       205
00334 #define CMP_NODE_RGBTOBW        206
00335 #define CMP_NODE_NORMAL         207
00336 #define CMP_NODE_CURVE_VEC      208
00337 #define CMP_NODE_CURVE_RGB      209
00338 #define CMP_NODE_ALPHAOVER      210
00339 #define CMP_NODE_BLUR           211
00340 #define CMP_NODE_FILTER         212
00341 #define CMP_NODE_MAP_VALUE      213
00342 #define CMP_NODE_TIME           214
00343 #define CMP_NODE_VECBLUR        215
00344 #define CMP_NODE_SEPRGBA        216
00345 #define CMP_NODE_SEPHSVA        217
00346 #define CMP_NODE_SETALPHA       218
00347 #define CMP_NODE_HUE_SAT        219
00348 #define CMP_NODE_IMAGE          220
00349 #define CMP_NODE_R_LAYERS       221
00350 #define CMP_NODE_COMPOSITE      222
00351 #define CMP_NODE_OUTPUT_FILE    223
00352 #define CMP_NODE_TEXTURE        224
00353 #define CMP_NODE_TRANSLATE      225
00354 #define CMP_NODE_ZCOMBINE       226
00355 #define CMP_NODE_COMBRGBA       227
00356 #define CMP_NODE_DILATEERODE    228
00357 #define CMP_NODE_ROTATE         229
00358 #define CMP_NODE_SCALE          230
00359 #define CMP_NODE_SEPYCCA        231
00360 #define CMP_NODE_COMBYCCA       232
00361 #define CMP_NODE_SEPYUVA        233
00362 #define CMP_NODE_COMBYUVA       234
00363 #define CMP_NODE_DIFF_MATTE     235
00364 #define CMP_NODE_COLOR_SPILL    236
00365 #define CMP_NODE_CHROMA_MATTE   237
00366 #define CMP_NODE_CHANNEL_MATTE  238
00367 #define CMP_NODE_FLIP           239
00368 #define CMP_NODE_SPLITVIEWER    240
00369 #define CMP_NODE_INDEX_MASK     241
00370 #define CMP_NODE_MAP_UV         242
00371 #define CMP_NODE_ID_MASK        243
00372 #define CMP_NODE_DEFOCUS        244
00373 #define CMP_NODE_DISPLACE       245
00374 #define CMP_NODE_COMBHSVA       246
00375 #define CMP_NODE_MATH           247
00376 #define CMP_NODE_LUMA_MATTE     248
00377 #define CMP_NODE_BRIGHTCONTRAST 249
00378 #define CMP_NODE_GAMMA          250
00379 #define CMP_NODE_INVERT         251
00380 #define CMP_NODE_NORMALIZE      252
00381 #define CMP_NODE_CROP           253
00382 #define CMP_NODE_DBLUR          254
00383 #define CMP_NODE_BILATERALBLUR  255
00384 #define CMP_NODE_PREMULKEY  256
00385 #define CMP_NODE_DIST_MATTE     257
00386 #define CMP_NODE_VIEW_LEVELS    258
00387 #define CMP_NODE_COLOR_MATTE 259
00388 #define CMP_NODE_COLORBALANCE 260
00389 #define CMP_NODE_HUECORRECT 261
00390 
00391 #define CMP_NODE_GLARE          301
00392 #define CMP_NODE_TONEMAP        302
00393 #define CMP_NODE_LENSDIST       303
00394 
00395 /* channel toggles */
00396 #define CMP_CHAN_RGB            1
00397 #define CMP_CHAN_A                      2
00398 #define CMP_CHAN_R                      4
00399 #define CMP_CHAN_G                      8
00400 #define CMP_CHAN_B                      16
00401 
00402 /* filter types */
00403 #define CMP_FILT_SOFT           0
00404 #define CMP_FILT_SHARP          1
00405 #define CMP_FILT_LAPLACE        2
00406 #define CMP_FILT_SOBEL          3
00407 #define CMP_FILT_PREWITT        4
00408 #define CMP_FILT_KIRSCH         5
00409 #define CMP_FILT_SHADOW         6
00410 
00411 /* scale node type, in custom1 */
00412 #define CMP_SCALE_RELATIVE              0
00413 #define CMP_SCALE_ABSOLUTE              1
00414 #define CMP_SCALE_SCENEPERCENT  2
00415 #define CMP_SCALE_RENDERPERCENT 3
00416 
00417 
00418 /* the type definitions array */
00419 extern struct ListBase node_all_composit;
00420 
00421 /* API */
00422 struct CompBuf;
00423 void ntreeCompositTagRender(struct Scene *sce);
00424 int ntreeCompositTagAnimated(struct bNodeTree *ntree);
00425 void ntreeCompositTagGenerators(struct bNodeTree *ntree);
00426 void ntreeCompositForceHidden(struct bNodeTree *ntree, struct Scene *scene);
00427 
00428 
00429 
00430 /* ************** TEXTURE NODES *************** */
00431 
00432 struct TexResult;
00433 
00434 #define TEX_NODE_OUTPUT     401
00435 #define TEX_NODE_CHECKER    402
00436 #define TEX_NODE_TEXTURE    403
00437 #define TEX_NODE_BRICKS     404
00438 #define TEX_NODE_MATH       405
00439 #define TEX_NODE_MIX_RGB    406
00440 #define TEX_NODE_RGBTOBW    407
00441 #define TEX_NODE_VALTORGB   408
00442 #define TEX_NODE_IMAGE      409
00443 #define TEX_NODE_CURVE_RGB  410
00444 #define TEX_NODE_INVERT     411
00445 #define TEX_NODE_HUE_SAT    412
00446 #define TEX_NODE_CURVE_TIME 413
00447 #define TEX_NODE_ROTATE     414
00448 #define TEX_NODE_VIEWER     415
00449 #define TEX_NODE_TRANSLATE  416
00450 #define TEX_NODE_COORD      417
00451 #define TEX_NODE_DISTANCE   418
00452 #define TEX_NODE_COMPOSE    419
00453 #define TEX_NODE_DECOMPOSE  420
00454 #define TEX_NODE_VALTONOR   421
00455 #define TEX_NODE_SCALE      422
00456 #define TEX_NODE_AT         423
00457 
00458 /* 501-599 reserved. Use like this: TEX_NODE_PROC + TEX_CLOUDS, etc */
00459 #define TEX_NODE_PROC      500
00460 #define TEX_NODE_PROC_MAX  600
00461 
00462 extern struct ListBase node_all_textures;
00463 
00464 /* API */
00465 int  ntreeTexTagAnimated(struct bNodeTree *ntree);
00466 void ntreeTexSetPreviewFlag(int);
00467 int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, float *coord, float *dxt, float *dyt, int osatex, short thread, struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
00468 void ntreeTexCheckCyclics(struct bNodeTree *ntree);
00469 char* ntreeTexOutputMenu(struct bNodeTree *ntree);
00470 
00471 
00472 
00473 
00474 void init_nodesystem(void);
00475 void free_nodesystem(void);
00476 
00477 
00478 
00479 void clear_scene_in_nodes(struct Main *bmain, struct Scene *sce);
00480 
00481 #endif