Page MenuHome

Hide unused sockets on math nodes
Needs RevisionPublic

Authored by Kevin Mossey (kdawg) on Mar 23 2015, 2:36 AM.

Details

Summary

When a user selects a math function from the math node such as sin() or abs() that only requires one input, there are still two sockets available. This could lead to some confusion as to which socket the user should use.

This patch hides the second socket for each of the following math functions: SIN, COS, TAN, ASIN, ACOS, ATAN, ROUND, and ABS. It replaces the second socket for any other math function. It also removes the code to check whether there is input in the first socket for each of the functions, as this is no longer needed since there is only one visible socket for each of these functions.

I have only done the shader math nodes in this patch, I'll work on the composite and texture throughout the week.

Diff Detail

Event Timeline

Kevin Mossey (kdawg) retitled this revision from to Hide unused sockets on math nodes.
Kevin Mossey (kdawg) updated this object.

I've fixed the code for the texture and composite nodes, as well, but I don't know how to replace/update this diff. Should I just create a new diff for those two files?

I've added the update to the composite and texture nodes as well now.

I think a single node_update_num_sockets() shared across the various node trees would be better.

source/blender/nodes/composite/nodes/node_composite_math.c
52

Avoid C++ style comment in the C code.

55–62

Could use the ELEM macro: https://developer.blender.org/diffusion/B/browse/master/source/blender/blenlib/BLI_utildefines.h$221

e.g.:

if (ELEM(operation, NODE_MATH_SIN, NODE_MATH_COS, ..)) {
    sock->flag |= SOCK_UNAVAIL;
}
else {
    sock->flag &= ~SOCK_UNAVAIL;
}

I added a function "node_update_num_math_sockets()" to node_util.c, and included the header node_util.h in each of shader, composite, and texture math node c files. I also replaced the long list of ||'s with the ELEM macro, and fixed the comments to be c style comments.

I did vary from kevindietrich's suggestion of naming the single function "node_update_num_sockets()" only because the function explicitly checks math operator state, and may not work as written for a non-math node, so I chose to be more specific.

Sergey Sharybin (sergey) requested changes to this revision.Mar 25 2015, 2:37 PM
Sergey Sharybin (sergey) edited edge metadata.

generally idea seems fine, but we cant' accept patch in the current state. Mainly because it'll break whatever setup which used to have connection to second socket (which was totally legit situation).

So in order to make this patch accepted connections are to be re-linked from second input to first one in the versioning code. But to make it correct you'll also need to re-map animation and driver paths.

This revision now requires changes to proceed.Mar 25 2015, 2:37 PM

Currently, in the patch as written, whatever is linked to the second node stays linked to the second node, and only disappears temporarily. If you go to an operation that only has one input (say, sin), and you have an input on the second node and then go back to a function that has two inputs (say, add), whatever was connected to the second node will reappear. This happens even if you save the .blend, quit, and reload.

See http://youtu.be/w2o_Krc8C14 for a quick 1:37 demonstration.

I can see advantages and disadvantages to having the input on the second switch to the first socket if you select a one-input function. The disadvantage is if you meant to go to a "subtract" or some other order-sensitive operation, and didn't have the first input plugged in, the user might plug in the first input into the second socket now. Advantage is it doesn't scare the user if their input suddenly disappears!

Before I proceed though, I want to clarify the logic you're asking for:

If user transitions from 2-input to 1-input function, and
   if there is are no inputs, do nothing, else
   if there is an input into the first socket, do nothing, else
   if there is an input into the second socket and no input in the first socket, 
       move the input to the first socket; update drivers, etc.
If user transitions from 1-input function to 2-input function, do nothing

if this is how you expect it to work, I can do the socket switching easily, however, I would need you to point me in the direction of the animation and driver paths.