Fix compositing normal node not properly showing vector XYZ values when opening
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 17 Nov 2012 16:11:02 +0000 (16:11 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 17 Nov 2012 16:11:02 +0000 (16:11 +0000)
socket menu, and make the normal animatable.

source/blender/compositor/nodes/COM_NormalNode.cpp
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/space_node/drawnode.c
source/blender/nodes/composite/nodes/node_composite_normal.c

index e00e71e50e956c791cfba3d1c453cac960d736cf..fbfff8386d065f6b53ee97ec1ffa302e3cd52bc7 100644 (file)
@@ -41,9 +41,14 @@ void NormalNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
        SetVectorOperation *operationSet = new SetVectorOperation();
        bNodeSocket *insock = (bNodeSocket *)editorNode->outputs.first;
        bNodeSocketValueVector *dval = (bNodeSocketValueVector *)insock->default_value;
-       operationSet->setX(dval->value[0]);
-       operationSet->setY(dval->value[1]);
-       operationSet->setZ(dval->value[2]);
+       float normal[3];
+
+       /* animation can break normalization, this restores it */
+       normalize_v3_v3(normal, dval->value);
+
+       operationSet->setX(normal[0]);
+       operationSet->setY(normal[1]);
+       operationSet->setZ(normal[2]);
        operationSet->setW(0.0f);
        
        outputSocket->relinkConnections(operationSet->getOutputSocket(0));
index 9eec7c195b26c0d588e589e210ea62f9964d8c92..e000265bb1e6b7fa49ee98e883733f4dd79807fa 100644 (file)
@@ -430,7 +430,7 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, const char *name, in
                                but->type = NUMSLI;
                }
        }
-       else if (subtype == PROP_DIRECTION) {
+       else if (subtype == PROP_DIRECTION && !expand) {
                uiDefButR_prop(block, BUT_NORMAL, 0, name, x, y, UI_UNIT_X * 3, UI_UNIT_Y * 3, ptr, prop, 0, 0, 0, -1, -1, NULL);
        }
        else {
index c836d62021e43561844d2e23cc05d4622a795829..527f383c837912cf8473e7201113fdcd233d753f 100644 (file)
@@ -2623,6 +2623,11 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
        
 }
 
+static void widget_normal(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
+{
+       ui_draw_but_NORMAL(but, wcol, rect);
+}
+
 static void widget_icon_has_anim(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti *rect, int state, int UNUSED(roundboxalign))
 {
        if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT)) {
@@ -3030,6 +3035,7 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
                        break;
                        
                case UI_WTYPE_NORMAL:
+                       wt.custom = widget_normal;
                        break;
 
                case UI_WTYPE_SCROLL:
@@ -3269,7 +3275,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
                                break;
                                
                        case BUT_NORMAL:
-                               ui_draw_but_NORMAL(but, &tui->wcol_regular, rect);
+                               wt = widget_type(UI_WTYPE_NORMAL);
                                break;
                                
                        case BUT_IMAGE:
index e842bb5f262705c2d901baff9d2336f7ad561f22..99bdb8d6fe9e15b49f0d398f5e50e8a511198362 100644 (file)
@@ -398,29 +398,15 @@ static void node_buts_curvecol(uiLayout *layout, bContext *UNUSED(C), PointerRNA
        uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0);
 }
 
-static void node_normal_cb(bContext *C, void *ntree_v, void *node_v)
-{
-       Main *bmain = CTX_data_main(C);
-
-       ED_node_generic_update(bmain, ntree_v, node_v);
-       WM_event_add_notifier(C, NC_NODE | NA_EDITED, ntree_v);
-}
-
 static void node_buts_normal(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
-       uiBlock *block = uiLayoutAbsoluteBlock(layout);
-       bNodeTree *ntree = ptr->id.data;
-       bNode *node = ptr->data;
-       rctf *butr = &node->butr;
+       bNodeTree *ntree = (bNodeTree*)ptr->id.data;
+       bNode *node = (bNode*)ptr->data;
        bNodeSocket *sock = node->outputs.first;     /* first socket stores normal */
-       float *nor = ((bNodeSocketValueVector *)sock->default_value)->value;
-       uiBut *bt;
-       
-       bt = uiDefButF(block, BUT_NORMAL, B_NODE_EXEC, "",
-                      (int)butr->xmin, (int)butr->xmin,
-                      (short)BLI_rctf_size_x(butr), (short)BLI_rctf_size_x(butr),
-                      nor, 0.0f, 1.0f, 0, 0, "");
-       uiButSetFunc(bt, node_normal_cb, ntree, node);
+       PointerRNA sockptr;
+
+       RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &sockptr);
+       uiItemR(layout, &sockptr, "default_value", 0, "", ICON_NONE);
 }
 #if 0 /* not used in 2.5x yet */
 static void node_browse_tex_cb(bContext *C, void *ntree_v, void *node_v)
index 93fd7ca1c1bd3b8c3a4a28b87b19f38c702b577d..d104e8f03e62a34f018e36a2e4ba3da5d9e474a7 100644 (file)
@@ -40,7 +40,7 @@ static bNodeSocketTemplate cmp_node_normal_in[] = {
 };
 
 static bNodeSocketTemplate cmp_node_normal_out[] = {
-       {       SOCK_VECTOR, 0, N_("Normal")},
+       {       SOCK_VECTOR, 0, N_("Normal"),   0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION},
        {       SOCK_FLOAT, 0, N_("Dot")},
        {       -1, 0, ""       }
 };