diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-03-28 14:32:04 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-03-28 14:32:04 +0400 |
commit | 4b5be1c097513eec1c5afe95b4ff70dfa0e9f8ac (patch) | |
tree | 1bfdc61c8194db73751d9988d1da6da0648d104d /source/blender | |
parent | c5c34ca65f7d53abea3bead809dc282d231010ca (diff) |
Fix for node groups, now exposing a socket will copy the default value from internal nodes again. Also this value can be changed in the node group Interface panel.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 47 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 93 | ||||
-rw-r--r-- | source/blender/nodes/NOD_socket.h | 1 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_common.c | 3 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_socket.c | 100 |
7 files changed, 242 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index e234d6c519e..fc1cd6e45d5 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -120,6 +120,7 @@ typedef struct bNodeSocketType { void (*interface_draw_color)(struct bContext *C, struct PointerRNA *ptr, float *r_color); void (*interface_register_properties)(struct bNodeTree *ntree, struct bNodeSocket *stemp, struct StructRNA *data_srna); void (*interface_init_socket)(struct bNodeTree *ntree, struct bNodeSocket *stemp, struct bNode *node, struct bNodeSocket *sock, const char *data_path); + void (*interface_verify_socket)(struct bNodeTree *ntree, struct bNodeSocket *stemp, struct bNode *node, struct bNodeSocket *sock, const char *data_path); void (*interface_from_socket)(struct bNodeTree *ntree, struct bNodeSocket *stemp, struct bNode *node, struct bNodeSocket *sock); /* RNA integration */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 7fcbc14a593..5cf8758aa1b 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1668,7 +1668,6 @@ static void node_socket_interface_free(bNodeTree *UNUSED(ntree), bNodeSocket *so MEM_freeN(sock->prop); } - /* can be left over from old files */ if (sock->default_value) MEM_freeN(sock->default_value); } @@ -2006,21 +2005,16 @@ void ntreeLocalMerge(bNodeTree *localtree, bNodeTree *ntree) /* ************ NODE TREE INTERFACE *************** */ -static bNodeSocket *make_socket_template(bNodeTree *ntree, int in_out, +static bNodeSocket *make_socket_interface(bNodeTree *ntree, int in_out, const char *idname, const char *name) { bNodeSocketType *stype = nodeSocketTypeFind(idname); bNodeSocket *sock; int own_index = ntree->cur_index++; - if (stype == NULL) { - printf("Error: node socket type '%s' undefined\n", idname); - return NULL; - } - sock = MEM_callocN(sizeof(bNodeSocket), "socket template"); - sock->typeinfo = stype; BLI_strncpy(sock->idname, stype->idname, sizeof(sock->idname)); + node_socket_set_typeinfo(ntree, sock, stype); sock->in_out = in_out; sock->type = SOCK_CUSTOM; /* int type undefined by default */ @@ -2073,7 +2067,7 @@ bNodeSocket *ntreeAddSocketInterface(bNodeTree *ntree, int in_out, const char *i { bNodeSocket *iosock; - iosock = make_socket_template(ntree, in_out, idname, name); + iosock = make_socket_interface(ntree, in_out, idname, name); if (in_out == SOCK_IN) { BLI_addtail(&ntree->inputs, iosock); ntree->update |= NTREE_UPDATE_GROUP_IN; @@ -2091,7 +2085,7 @@ bNodeSocket *ntreeInsertSocketInterface(bNodeTree *ntree, int in_out, const char { bNodeSocket *iosock; - iosock = make_socket_template(ntree, in_out, idname, name); + iosock = make_socket_interface(ntree, in_out, idname, name); if (in_out == SOCK_IN) { BLI_insertlinkbefore(&ntree->inputs, next_sock, iosock); ntree->update |= NTREE_UPDATE_GROUP_IN; diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index a413eb47140..5e5b2ece8c9 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -2872,10 +2872,57 @@ static void std_node_socket_draw(bContext *C, uiLayout *layout, PointerRNA *ptr, } } +static void std_node_socket_interface_draw(bContext *UNUSED(C), uiLayout *layout, PointerRNA *ptr) +{ + bNodeSocket *sock = ptr->data; + int type = sock->typeinfo->type; + /*int subtype = sock->typeinfo->subtype;*/ + + switch (type) { + case SOCK_FLOAT: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, "min", 0); + uiItemR(row, ptr, "max_value", 0, "max", 0); + break; + } + case SOCK_INT: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, "min", 0); + uiItemR(row, ptr, "max_value", 0, "max", 0); + break; + } + case SOCK_BOOLEAN: { + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + break; + } + case SOCK_VECTOR: { + uiLayout *row; + uiItemR(layout, ptr, "default_value", UI_ITEM_R_EXPAND, NULL, 0); + row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "min_value", 0, "min", 0); + uiItemR(row, ptr, "max_value", 0, "max", 0); + break; + } + case SOCK_RGBA: { + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + break; + } + case SOCK_STRING: { + uiItemR(layout, ptr, "default_value", 0, NULL, 0); + break; + } + } +} + void ED_init_standard_node_socket_type(bNodeSocketType *stype) { stype->draw = std_node_socket_draw; stype->draw_color = std_node_socket_draw_color; + stype->interface_draw = std_node_socket_interface_draw; stype->interface_draw_color = std_node_socket_interface_draw_color; } diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index d8dd9ff3c33..96e33accad1 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -6058,13 +6058,32 @@ static void rna_def_node_socket_float(BlenderRNA *brna, const char *idname, cons RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "Float Node Socket Interface", "Floating point number socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueFloat", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, subtype); + RNA_def_property_float_sdna(prop, NULL, "value"); + RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocketStandard_float_range"); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "min_value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "min"); + RNA_def_property_ui_text(prop, "Minimum Value", "Minimum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "max_value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "max"); + RNA_def_property_ui_text(prop, "Maximum Value", "Maximum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_int(BlenderRNA *brna, const char *identifier, const char *interface_idname, PropertySubType subtype) @@ -6085,13 +6104,32 @@ static void rna_def_node_socket_int(BlenderRNA *brna, const char *identifier, co RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "Integer Node Socket Interface", "Integer number socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueInt", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_INT, subtype); + RNA_def_property_int_sdna(prop, NULL, "value"); + RNA_def_property_int_funcs(prop, NULL, NULL, "rna_NodeSocketStandard_int_range"); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "min_value", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "min"); + RNA_def_property_ui_text(prop, "Minimum Value", "Minimum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "max_value", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "max"); + RNA_def_property_ui_text(prop, "Maximum Value", "Maximum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_bool(BlenderRNA *brna, const char *identifier, const char *interface_idname) @@ -6111,13 +6149,21 @@ static void rna_def_node_socket_bool(BlenderRNA *brna, const char *identifier, c RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "Boolean Node Socket Interface", "Boolean value socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueBoolean", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "value", 1); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_vector(BlenderRNA *brna, const char *identifier, const char *interface_idname, PropertySubType subtype) @@ -6138,13 +6184,32 @@ static void rna_def_node_socket_vector(BlenderRNA *brna, const char *identifier, RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "Vector Node Socket Interface", "3D vector socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueVector", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, subtype); + RNA_def_property_float_sdna(prop, NULL, "value"); + RNA_def_property_float_funcs(prop, NULL, NULL, "rna_NodeSocketStandard_vector_range"); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "min_value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "min"); + RNA_def_property_ui_text(prop, "Minimum Value", "Minimum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + prop = RNA_def_property(srna, "max_value", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "max"); + RNA_def_property_ui_text(prop, "Maximum Value", "Maximum value"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_color(BlenderRNA *brna, const char *identifier, const char *interface_idname) @@ -6164,13 +6229,21 @@ static void rna_def_node_socket_color(BlenderRNA *brna, const char *identifier, RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "Color Node Socket Interface", "RGBA color socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueRGBA", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_FLOAT, PROP_COLOR); + RNA_def_property_float_sdna(prop, NULL, "value"); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_string(BlenderRNA *brna, const char *identifier, const char *interface_idname) @@ -6190,13 +6263,21 @@ static void rna_def_node_socket_string(BlenderRNA *brna, const char *identifier, RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketStandard_value_update"); RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE); - /* XXX need to reset the from-type here, so subtype subclasses cast correctly! (RNA bug) */ RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); /* socket interface */ srna = RNA_def_struct(brna, interface_idname, "NodeSocketInterfaceStandard"); RNA_def_struct_ui_text(srna, "String Node Socket Interface", "String socket of a node"); RNA_def_struct_sdna(srna, "bNodeSocket"); + + RNA_def_struct_sdna_from(srna, "bNodeSocketValueString", "default_value"); + + prop = RNA_def_property(srna, "default_value", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "value"); + RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + + RNA_def_struct_sdna_from(srna, "bNodeSocket", NULL); } static void rna_def_node_socket_shader(BlenderRNA *brna, const char *identifier, const char *interface_idname) diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h index 5f7da1c3f4d..81230456193 100644 --- a/source/blender/nodes/NOD_socket.h +++ b/source/blender/nodes/NOD_socket.h @@ -50,6 +50,7 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struc void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node); void node_socket_init_default_value(struct bNodeSocket *sock); +void node_socket_copy_default_value(struct bNodeSocket *to, struct bNodeSocket *from); void register_standard_node_socket_types(void); #endif diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 54ffd3cd01c..3280672d5c2 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -124,6 +124,9 @@ static bNodeSocket *group_verify_socket(bNodeTree *ntree, bNode *gnode, bNodeSoc } if (sock) { strcpy(sock->name, iosock->name); + + if (iosock->typeinfo->interface_verify_socket) + iosock->typeinfo->interface_verify_socket(ntree, iosock, gnode, sock, "interface"); } else { sock = nodeAddSocket(ntree, gnode, in_out, iosock->idname, iosock->identifier, iosock->name); diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 86a8331e5dd..74d44fe5f53 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -260,11 +260,107 @@ void node_socket_init_default_value(bNodeSocket *sock) } } +void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from) +{ + /* sanity check */ + if (!STREQ(to->idname, from->idname)) + return; + + /* make sure both exist */ + if (!from->default_value) + return; + node_socket_init_default_value(to); + + switch (from->typeinfo->type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *toval = to->default_value; + bNodeSocketValueFloat *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *toval = to->default_value; + bNodeSocketValueInt *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_BOOLEAN: { + bNodeSocketValueBoolean *toval = to->default_value; + bNodeSocketValueBoolean *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_VECTOR: { + bNodeSocketValueVector *toval = to->default_value; + bNodeSocketValueVector *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_RGBA: { + bNodeSocketValueRGBA *toval = to->default_value; + bNodeSocketValueRGBA *fromval = from->default_value; + *toval = *fromval; + break; + } + case SOCK_STRING: { + bNodeSocketValueString *toval = to->default_value; + bNodeSocketValueString *fromval = from->default_value; + *toval = *fromval; + break; + } + } +} -static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), bNodeSocket *UNUSED(stemp), bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path)) +static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path)) { /* initialize the type value */ sock->type = sock->typeinfo->type; + + /* copy default_value settings */ + node_socket_copy_default_value(sock, stemp); +} + +/* copies settings that are not changed for each socket instance */ +static void standard_node_socket_interface_verify_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock, const char *UNUSED(data_path)) +{ + /* sanity check */ + if (!STREQ(sock->idname, stemp->idname)) + return; + + /* make sure both exist */ + if (!stemp->default_value) + return; + node_socket_init_default_value(sock); + + switch (stemp->typeinfo->type) { + case SOCK_FLOAT: { + bNodeSocketValueFloat *toval = sock->default_value; + bNodeSocketValueFloat *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + case SOCK_INT: { + bNodeSocketValueInt *toval = sock->default_value; + bNodeSocketValueInt *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + case SOCK_VECTOR: { + bNodeSocketValueVector *toval = sock->default_value; + bNodeSocketValueVector *fromval = stemp->default_value; + toval->min = fromval->min; + toval->max = fromval->max; + break; + } + } +} + +static void standard_node_socket_interface_from_socket(bNodeTree *UNUSED(ntree), bNodeSocket *stemp, bNode *UNUSED(node), bNodeSocket *sock) +{ + /* initialize settings */ + node_socket_copy_default_value(stemp, sock); } static bNodeSocketType *make_standard_socket_type(int type, int subtype) @@ -300,6 +396,8 @@ static bNodeSocketType *make_standard_socket_type(int type, int subtype) ED_init_standard_node_socket_type(stype); stype->interface_init_socket = standard_node_socket_interface_init_socket; + stype->interface_from_socket = standard_node_socket_interface_from_socket; + stype->interface_verify_socket = standard_node_socket_interface_verify_socket; return stype; } |