diff options
author | Charlie Jolly <charlie> | 2020-02-11 18:31:40 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2020-02-11 19:09:25 +0300 |
commit | 7b0aca2a530fb1a42367eebf595a1c6ca93dba7d (patch) | |
tree | f439158ad17e09591daba9ae10c6a3a9f83ed531 /source | |
parent | 64e65442a1857033a9f139893eaff56b53cbd667 (diff) |
Nodes: Add dynamic label support for Math Nodes
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D6375
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 9 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 5 | ||||
-rw-r--r-- | source/blender/nodes/composite/nodes/node_composite_math.c | 39 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_socket.c | 5 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_util.c | 96 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_util.h | 5 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_math.c | 39 | ||||
-rw-r--r-- | source/blender/nodes/texture/nodes/node_texture_math.c | 39 |
11 files changed, 129 insertions, 118 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 1c479c92ef5..278e8ec1d89 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -740,6 +740,7 @@ void BKE_node_preview_set_pixel( * \{ */ void nodeLabel(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); +const char *nodeSocketLabel(const struct bNodeSocket *sock); int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 64897d05c96..2a8c9f2a40b 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3574,6 +3574,12 @@ void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen) } } +/* Get node socket label if it is set */ +const char *nodeSocketLabel(const bNodeSocket *sock) +{ + return (sock->label[0] != '\0') ? sock->label : sock->name; +} + static void node_type_base_defaults(bNodeType *ntype) { /* default size values */ diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 2202eee3a53..755e2cc1618 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -354,6 +354,8 @@ void node_from_view(struct bNode *node, float x, float y, float *rx, float *ry) nodeFromView(node, x, y, rx, ry); } + + /* based on settings in node, sets drawing rect info. each redraw! */ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) { @@ -409,8 +411,8 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) /* align output buttons to the right */ row = uiLayoutRow(layout, 1); uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); - - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); + const char *socket_label = nodeSocketLabel(nsock); + nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label)); UI_block_align_end(node->block); UI_block_layout_resolve(node->block, NULL, &buty); @@ -535,7 +537,8 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) row = uiLayoutRow(layout, 1); - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(nsock->name)); + const char *socket_label = nodeSocketLabel(nsock); + nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label)); UI_block_align_end(node->block); UI_block_layout_resolve(node->block, NULL, &buty); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 22202717b0c..559048ab8cf 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -116,6 +116,9 @@ typedef struct bNodeSocket { char display_shape; char _pad[3]; + /** Custom dynamic defined label, MAX_NAME. */ + char label[64]; + /** Cached data from execution. */ void *cache; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 68e3e522dff..180bf96dd90 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -7891,6 +7891,11 @@ static void rna_def_node_socket(BlenderRNA *brna) RNA_def_struct_name_property(srna, prop); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocket_update"); + prop = RNA_def_property(srna, "label", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "label"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Label", "Custom dynamic defined socket label"); + prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "identifier"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/nodes/composite/nodes/node_composite_math.c b/source/blender/nodes/composite/nodes/node_composite_math.c index 741c0e48806..3efb650c6eb 100644 --- a/source/blender/nodes/composite/nodes/node_composite_math.c +++ b/source/blender/nodes/composite/nodes/node_composite_math.c @@ -32,43 +32,6 @@ static bNodeSocketTemplate cmp_node_math_in[] = { static bNodeSocketTemplate cmp_node_math_out[] = {{SOCK_FLOAT, 0, N_("Value")}, {-1, 0, ""}}; -static void node_shader_update_math(bNodeTree *UNUSED(ntree), bNode *node) -{ - bNodeSocket *sock = BLI_findlink(&node->inputs, 1); - nodeSetSocketAvailability(sock, - !ELEM(node->custom1, - NODE_MATH_SQRT, - NODE_MATH_SIGN, - NODE_MATH_CEIL, - NODE_MATH_SINE, - NODE_MATH_ROUND, - NODE_MATH_FLOOR, - NODE_MATH_COSINE, - NODE_MATH_ARCSINE, - NODE_MATH_TANGENT, - NODE_MATH_ABSOLUTE, - NODE_MATH_RADIANS, - NODE_MATH_DEGREES, - NODE_MATH_FRACTION, - NODE_MATH_ARCCOSINE, - NODE_MATH_ARCTANGENT) && - !ELEM(node->custom1, - NODE_MATH_INV_SQRT, - NODE_MATH_TRUNC, - NODE_MATH_EXPONENT, - NODE_MATH_COSH, - NODE_MATH_SINH, - NODE_MATH_TANH)); - bNodeSocket *sock2 = BLI_findlink(&node->inputs, 2); - nodeSetSocketAvailability(sock2, - ELEM(node->custom1, - NODE_MATH_COMPARE, - NODE_MATH_MULTIPLY_ADD, - NODE_MATH_WRAP, - NODE_MATH_SMOOTH_MIN, - NODE_MATH_SMOOTH_MAX)); -} - void register_node_type_cmp_math(void) { static bNodeType ntype; @@ -76,7 +39,7 @@ void register_node_type_cmp_math(void) cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTOR, 0); node_type_socket_templates(&ntype, cmp_node_math_in, cmp_node_math_out); node_type_label(&ntype, node_math_label); - node_type_update(&ntype, node_shader_update_math); + node_type_update(&ntype, node_math_update); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 3485bd41660..13f9039379d 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -276,6 +276,11 @@ void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from) } node_socket_init_default_value(to); + /* use label instead of name if it has been set */ + if (from->label[0] != '\0') { + BLI_strncpy(to->name, from->label, NODE_MAXSTR); + } + switch (from->typeinfo->type) { case SOCK_FLOAT: { bNodeSocketValueFloat *toval = to->default_value; diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index b16c814ade9..7d029e7a400 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -77,6 +77,102 @@ void *node_initexec_curves(bNodeExecContext *UNUSED(context), return NULL; /* unused return */ } +/**** Updates ****/ + +void node_sock_label(bNodeSocket *sock, const char *name) +{ + BLI_strncpy(sock->label, name, MAX_NAME); +} + +void node_math_update(bNodeTree *UNUSED(ntree), bNode *node) +{ + bNodeSocket *sock1 = BLI_findlink(&node->inputs, 0); + bNodeSocket *sock2 = BLI_findlink(&node->inputs, 1); + bNodeSocket *sock3 = BLI_findlink(&node->inputs, 2); + nodeSetSocketAvailability(sock2, + !ELEM(node->custom1, + NODE_MATH_SQRT, + NODE_MATH_SIGN, + NODE_MATH_CEIL, + NODE_MATH_SINE, + NODE_MATH_ROUND, + NODE_MATH_FLOOR, + NODE_MATH_COSINE, + NODE_MATH_ARCSINE, + NODE_MATH_TANGENT, + NODE_MATH_ABSOLUTE, + NODE_MATH_RADIANS, + NODE_MATH_DEGREES, + NODE_MATH_FRACTION, + NODE_MATH_ARCCOSINE, + NODE_MATH_ARCTANGENT) && + !ELEM(node->custom1, + NODE_MATH_INV_SQRT, + NODE_MATH_TRUNC, + NODE_MATH_EXPONENT, + NODE_MATH_COSH, + NODE_MATH_SINH, + NODE_MATH_TANH)); + nodeSetSocketAvailability(sock3, + ELEM(node->custom1, + NODE_MATH_COMPARE, + NODE_MATH_MULTIPLY_ADD, + NODE_MATH_WRAP, + NODE_MATH_SMOOTH_MIN, + NODE_MATH_SMOOTH_MAX)); + + if (sock1->label[0] != '\0') { + sock1->label[0] = '\0'; + } + if (sock2->label[0] != '\0') { + sock2->label[0] = '\0'; + } + if (sock3->label[0] != '\0') { + sock3->label[0] = '\0'; + } + + switch (node->custom1) { + case NODE_MATH_WRAP: + node_sock_label(sock2, "Min"); + node_sock_label(sock3, "Max"); + break; + case NODE_MATH_MULTIPLY_ADD: + node_sock_label(sock2, "Multiplier"); + node_sock_label(sock3, "Addend"); + break; + case NODE_MATH_LESS_THAN: + case NODE_MATH_GREATER_THAN: + node_sock_label(sock2, "Threshold"); + break; + case NODE_MATH_PINGPONG: + node_sock_label(sock2, "Scale"); + break; + case NODE_MATH_SNAP: + node_sock_label(sock2, "Increment"); + break; + case NODE_MATH_POWER: + node_sock_label(sock1, "Base"); + node_sock_label(sock2, "Exponent"); + break; + case NODE_MATH_LOGARITHM: + node_sock_label(sock2, "Base"); + break; + case NODE_MATH_DEGREES: + node_sock_label(sock1, "Radians"); + break; + case NODE_MATH_RADIANS: + node_sock_label(sock1, "Degrees"); + break; + case NODE_MATH_COMPARE: + node_sock_label(sock3, "Epsilon"); + break; + case NODE_MATH_SMOOTH_MAX: + case NODE_MATH_SMOOTH_MIN: + node_sock_label(sock3, "Distance"); + break; + } +} + /**** Labels ****/ void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen) diff --git a/source/blender/nodes/intern/node_util.h b/source/blender/nodes/intern/node_util.h index 49117b38aba..a7f09d24a70 100644 --- a/source/blender/nodes/intern/node_util.h +++ b/source/blender/nodes/intern/node_util.h @@ -66,8 +66,11 @@ extern void *node_initexec_curves(struct bNodeExecContext *context, struct bNode *node, bNodeInstanceKey key); -/**** Labels ****/ +/**** Updates ****/ +void node_sock_label(struct bNodeSocket *sock, const char *name); +void node_math_update(struct bNodeTree *ntree, struct bNode *node); +/**** Labels ****/ void node_blend_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); void node_image_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); void node_math_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index 5d9da7788ee..c2bb48068ac 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -101,43 +101,6 @@ static int gpu_shader_math(GPUMaterial *mat, } } -static void node_shader_update_math(bNodeTree *UNUSED(ntree), bNode *node) -{ - bNodeSocket *sock = BLI_findlink(&node->inputs, 1); - nodeSetSocketAvailability(sock, - !ELEM(node->custom1, - NODE_MATH_SQRT, - NODE_MATH_SIGN, - NODE_MATH_CEIL, - NODE_MATH_SINE, - NODE_MATH_ROUND, - NODE_MATH_FLOOR, - NODE_MATH_COSINE, - NODE_MATH_ARCSINE, - NODE_MATH_TANGENT, - NODE_MATH_ABSOLUTE, - NODE_MATH_RADIANS, - NODE_MATH_DEGREES, - NODE_MATH_FRACTION, - NODE_MATH_ARCCOSINE, - NODE_MATH_ARCTANGENT) && - !ELEM(node->custom1, - NODE_MATH_INV_SQRT, - NODE_MATH_TRUNC, - NODE_MATH_EXPONENT, - NODE_MATH_COSH, - NODE_MATH_SINH, - NODE_MATH_TANH)); - bNodeSocket *sock2 = BLI_findlink(&node->inputs, 2); - nodeSetSocketAvailability(sock2, - ELEM(node->custom1, - NODE_MATH_COMPARE, - NODE_MATH_MULTIPLY_ADD, - NODE_MATH_WRAP, - NODE_MATH_SMOOTH_MIN, - NODE_MATH_SMOOTH_MAX)); -} - void register_node_type_sh_math(void) { static bNodeType ntype; @@ -146,7 +109,7 @@ void register_node_type_sh_math(void) node_type_socket_templates(&ntype, sh_node_math_in, sh_node_math_out); node_type_label(&ntype, node_math_label); node_type_gpu(&ntype, gpu_shader_math); - node_type_update(&ntype, node_shader_update_math); + node_type_update(&ntype, node_math_update); nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/texture/nodes/node_texture_math.c b/source/blender/nodes/texture/nodes/node_texture_math.c index 310300df204..8abe638216c 100644 --- a/source/blender/nodes/texture/nodes/node_texture_math.c +++ b/source/blender/nodes/texture/nodes/node_texture_math.c @@ -336,43 +336,6 @@ static void exec(void *data, tex_output(node, execdata, in, out[0], &valuefn, data); } -static void node_shader_update_math(bNodeTree *UNUSED(ntree), bNode *node) -{ - bNodeSocket *sock = BLI_findlink(&node->inputs, 1); - nodeSetSocketAvailability(sock, - !ELEM(node->custom1, - NODE_MATH_SQRT, - NODE_MATH_SIGN, - NODE_MATH_CEIL, - NODE_MATH_SINE, - NODE_MATH_ROUND, - NODE_MATH_FLOOR, - NODE_MATH_COSINE, - NODE_MATH_ARCSINE, - NODE_MATH_TANGENT, - NODE_MATH_ABSOLUTE, - NODE_MATH_RADIANS, - NODE_MATH_DEGREES, - NODE_MATH_FRACTION, - NODE_MATH_ARCCOSINE, - NODE_MATH_ARCTANGENT) && - !ELEM(node->custom1, - NODE_MATH_INV_SQRT, - NODE_MATH_TRUNC, - NODE_MATH_EXPONENT, - NODE_MATH_COSH, - NODE_MATH_SINH, - NODE_MATH_TANH)); - bNodeSocket *sock2 = BLI_findlink(&node->inputs, 2); - nodeSetSocketAvailability(sock2, - ELEM(node->custom1, - NODE_MATH_COMPARE, - NODE_MATH_MULTIPLY_ADD, - NODE_MATH_WRAP, - NODE_MATH_SMOOTH_MIN, - NODE_MATH_SMOOTH_MAX)); -} - void register_node_type_tex_math(void) { static bNodeType ntype; @@ -382,7 +345,7 @@ void register_node_type_tex_math(void) node_type_label(&ntype, node_math_label); node_type_storage(&ntype, "", NULL, NULL); node_type_exec(&ntype, NULL, NULL, exec); - node_type_update(&ntype, node_shader_update_math); + node_type_update(&ntype, node_math_update); nodeRegisterType(&ntype); } |