Compositor: Added a basic "Time Node".
authorTon Roosendaal <ton@blender.org>
Sat, 4 Feb 2006 14:38:51 +0000 (14:38 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 4 Feb 2006 14:38:51 +0000 (14:38 +0000)
Just indicate start/end frame, and node outputs with Curve a value between
0.0 and 1.0.

source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/node_composite.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/src/drawnode.c
source/blender/src/editnode.c

index 80393db65c02fd4aee9cf591b0755953a24bc7e8..2b6a2f7f73ff70858ec75435a96dedb29f7781b2 100644 (file)
@@ -769,6 +769,11 @@ bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup)
                        node->storage= curvemapping_add(3, -1.0f, -1.0f, 1.0f, 1.0f);
                else if(type==CMP_NODE_CURVE_RGB)
                        node->storage= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
+               else if(type==CMP_NODE_TIME) {
+                       node->custom1= G.scene->r.sfra;
+                       node->custom2= G.scene->r.efra;
+                       node->storage= curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
+               }
                else if(type==CMP_NODE_MAP_VALUE)
                        node->storage= add_mapping();
                else if(type==CMP_NODE_BLUR)
@@ -927,7 +932,7 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node)
                                MEM_freeN(node->storage);
                }
                else if(ntree->type==NTREE_COMPOSIT) {
-                       if(node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB)
+                       if(ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB))
                                curvemapping_free(node->storage);
                        else 
                                MEM_freeN(node->storage);
index 8a04f37bb3a6f0bd298b2082fec5c40fb2c218ba..41fa770c3b93c00cfd2ed8b360f5129e0630349e 100644 (file)
@@ -950,6 +950,36 @@ static bNodeType cmp_node_normal= {
        
 };
 
+/* **************** CURVE Time  ******************** */
+
+/* custom1 = sfra, custom2 = efra */
+static bNodeSocketType cmp_node_time_out[]= {
+       {       SOCK_VALUE, 0, "Fac",   1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f},
+       {       -1, 0, ""       }
+};
+
+static void node_composit_exec_time(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
+{
+       /* stack order output: fac */
+       float fac= 0.0f;
+       
+       if(node->custom1 < node->custom2)
+               fac= (G.scene->r.cfra - node->custom1)/(float)(node->custom2-node->custom1);
+       
+       out[0]->vec[0]= curvemapping_evaluateF(node->storage, 0, fac);
+}
+
+static bNodeType cmp_node_time= {
+       /* type code   */       CMP_NODE_TIME,
+       /* name        */       "Time",
+       /* width+range */       140, 100, 320,
+       /* class+opts  */       NODE_CLASS_GENERATOR, NODE_OPTIONS,
+       /* input sock  */       NULL,
+       /* output sock */       cmp_node_time_out,
+       /* storage     */       "CurveMapping",
+       /* execfunc    */       node_composit_exec_time
+};
+
 /* **************** CURVE VEC  ******************** */
 static bNodeSocketType cmp_node_curve_vec_in[]= {
        {       SOCK_VECTOR, 1, "Vector",       0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
@@ -2184,6 +2214,7 @@ bNodeType *node_all_composit[]= {
        &cmp_node_normal,
        &cmp_node_curve_vec,
        &cmp_node_curve_rgb,
+       &cmp_node_time,
        &cmp_node_image,
        &cmp_node_rresult,
        &cmp_node_alphaover,
@@ -2222,5 +2253,7 @@ void ntreeCompositTagAnimated(bNodeTree *ntree)
                        if(node->storage)
                                NodeTagChanged(ntree, node);
                }
+               else if(node->type==CMP_NODE_TIME)
+                       NodeTagChanged(ntree, node);
        }
 }
index 96828d0faa46998b72edf680c41d22c984ca7f54..c3642b8de6360adab02c03cf1f42252e61b5c9a1 100644 (file)
@@ -1267,10 +1267,10 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree)
                node->storage= newdataadr(fd, node->storage);
                if(node->storage) {
                        
-                       /* could be handlerized at some point, now only 1 exception still */
+                       /* could be handlerized at some point */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                direct_link_curvemapping(fd, node->storage);
-                       else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB))
+                       else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_TIME || node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB))
                                direct_link_curvemapping(fd, node->storage);
                        
                }
index ccd9314d4fdcf63a6191deab2eabcdd97fb25e92..f00e238314b9c04a282d2e76a4e51a65ee5fe29d 100644 (file)
@@ -392,7 +392,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree)
                        /* could be handlerized at some point, now only 1 exception still */
                        if(ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB))
                                write_curvemapping(wd, node->storage);
-                       else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB))
+                       else if(ntree->type==NTREE_COMPOSIT && (node->type==CMP_NODE_TIME || node->type==CMP_NODE_CURVE_VEC || node->type==CMP_NODE_CURVE_RGB))
                                write_curvemapping(wd, node->storage);
                        else
                                writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
index c510c34c9a1cf3ddfc23be9e8c1a0a1545a06a28..d330d33a83e7e44b0bd915116363b501902b736c 100644 (file)
@@ -774,13 +774,13 @@ static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node
                
                uiBlockBeginAlign(block);
                sprintf(str, "Filter Type%%t|Flat %%x%d|Tent %%x%d|Quad %%x%d|Cubic %%x%d|Gauss %%x%d|CatRom %%x%d|Mitch %%x%d", R_FILTER_BOX, R_FILTER_TENT, R_FILTER_QUAD, R_FILTER_CUBIC, R_FILTER_GAUSS, R_FILTER_CATROM, R_FILTER_MITCH);
-               uiDefButS(block, MENU, B_NODE_EXEC,str,         
+               uiDefButS(block, MENU, B_NODE_EXEC+node->nr,str,                
                                  butr->xmin, dy, dx3, 19, 
                                  &nbd->filtertype, 0, 0, 0, 0, "Set sampling filter for blur");
-               uiDefButC(block, TOG, B_NODE_EXEC, "Bokeh",             
+               uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Bokeh",            
                                  butr->xmin+dx3, dy, dx3, 19, 
                                  &nbd->bokeh, 0, 0, 0, 0, "Uses circular filter, warning it's slow!");
-               uiDefButC(block, TOG, B_NODE_EXEC, "Gamma",             
+               uiDefButC(block, TOG, B_NODE_EXEC+node->nr, "Gamma",            
                                  butr->xmin+2*dx3, dy, dx3, 19, 
                                  &nbd->gamma, 0, 0, 0, 0, "Applies filter on gamma corrected values");
                
@@ -832,6 +832,28 @@ static int node_composit_buts_map_value(uiBlock *block, bNodeTree *ntree, bNode
        return 80;
 }
 
+static int node_composit_buts_time(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
+{
+       if(block) {
+               short dx= (butr->xmax-butr->xmin)/2;
+               
+               uiDefBut(block, BUT_CURVE, B_NODE_EXEC+node->nr, "", 
+                                butr->xmin, butr->ymin+24, butr->xmax-butr->xmin, butr->ymax-butr->ymin-24, 
+                                node->storage, 0.0f, 1.0f, 0, 0, "");
+               
+               uiBlockBeginAlign(block);
+               uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "Sta:",
+                                 butr->xmin, butr->ymin, dx, 19, 
+                                 &node->custom1, 1.0, 20000.0, 0, 0, "Start frame");
+               uiDefButS(block, NUM, B_NODE_EXEC+node->nr, "End:",
+                                 butr->xmin+dx, butr->ymin, dx, 19, 
+                                 &node->custom2, 1.0, 20000.0, 0, 0, "End frame");
+               
+       }
+       
+       return node->width-NODE_DY;
+}
+
 
 /* only once called */
 static void node_composit_set_butfunc(bNodeType *ntype)
@@ -876,6 +898,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
                case CMP_NODE_MAP_VALUE:
                        ntype->butfunc= node_composit_buts_map_value;
                        break;
+               case CMP_NODE_TIME:
+                       ntype->butfunc= node_composit_buts_time;
+                       break;
                default:
                        ntype->butfunc= NULL;
        }
index 2aca3e7d4bc2c05e0b84c0cd72bf64566bc4760f..3e4a66f30d0291860d5e6ac8509d2747d73c6ba1 100644 (file)
@@ -1186,7 +1186,7 @@ static void node_add_menu(SpaceNode *snode)
        }
        else if(snode->treetype==NTREE_COMPOSIT) {
                /* compo menu, still hardcoded defines... solve */
-               event= pupmenu("Add Node%t|Render Result %x221|Composite %x222|Viewer%x201|Image %x220|RGB Curves%x209|AlphaOver %x210|Blur %x211|Vector Blur %x215|Filter %x212|Value %x203|Color %x202|Mix %x204|ColorRamp %x205|Color to BW %x206|Map Value %x213|Normal %x207");
+               event= pupmenu("Add Node%t|Render Result %x221|Composite %x222|Viewer%x201|Image %x220|RGB Curves%x209|AlphaOver %x210|Blur %x211|Vector Blur %x215|Filter %x212|Value %x203|Color %x202|Mix %x204|ColorRamp %x205|Color to BW %x206|Map Value %x213|Time %x214|Normal %x207");
                if(event<1) return;
        }
        else return;