Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh Switch node #2359

Merged
merged 1 commit into from
Jan 26, 2019
Merged

Mesh Switch node #2359

merged 1 commit into from
Jan 26, 2019

Conversation

DolphinDream
Copy link
Collaborator

@DolphinDream DolphinDream commented Jan 25, 2019

The node allows to connect multiple mesh inputs (verts/edges/polys) and to select one of them to output. Useful for changing the input mesh model to be processed by a node tree.

The input sockets are added as new meshes are connected to allow the next mesh (verts/edges/polys) to be connected.

  • Code changes complete.
  • Code documentation complete.
  • Documentation for users complete (or not required, if user never sees these changes).
  • Manual testing done.
  • Unit-tests implemented.
  • Ready for merge.

sv-meshswitchnode-ui

sv-meshswitchnode-demo1

@DolphinDream
Copy link
Collaborator Author

When testing a particular node tree on a given mesh I often times needed a way to be able to change the mesh to see how the nodetree works on different models. For this I usually had to connect and disconnect the input verts/edges/polys.. hence the need for such a node where I could connect all the different meshes to the node once.. and be able to select through the meshes via a single input :)

Any thoughts, suggestions, critique are appreciated as usual.

It is perhaps arguable whetheer such node would necessarily need both the edges and polys sockets or whether a unified poly/edge socket would be sufficient. Having 3 sockets created for every connected mesh could grow the node tall pretty fast.

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Jan 25, 2019

And a demo with EdgePoly sockets.. any preference?

I would say that maybe the EdgePoly version not only makes the input socket list shorter but it makes it more powerful as it allows for combinations VE and VP inputs to be mixed.

sv-meshswitchnode-demo2

@DolphinDream
Copy link
Collaborator Author

Latest UI (EdgePoly input socket version)

sv-meshswitchnode-ui2

@DolphinDream DolphinDream changed the title Mesh Switch node (WIP) Mesh Switch node Jan 26, 2019
@DolphinDream
Copy link
Collaborator Author

And a frame driven switch demo :)

sv-meshswitchnode-demo3

The node allows to connect multiple mesh inputs (verts/edges/polys) and to select one of them to output. Useful for changing the input mesh model to be processed by a node tree.

New input sockets are added as new meshes are connected to allow the next mesh (verts/edges/polys) to be connected.
@DolphinDream DolphinDream merged commit 5e71cfc into nortikin:master Jan 26, 2019
@DolphinDream
Copy link
Collaborator Author

Btw, I added this node to the "modifier change" category. If there's a better category this should go into let me know.

@DolphinDream DolphinDream deleted the meshSwitchNode branch January 26, 2019 06:07
@enzyme69
Copy link
Collaborator

screen shot 2019-01-26 at 15 33 32

Kind of wish it can do this but then again .... List Join can do it?

@enzyme69
Copy link
Collaborator

Does Mesh Switch have ability to do this?
screen shot 2019-01-26 at 15 38 00

@enzyme69
Copy link
Collaborator

@enzyme69
Copy link
Collaborator

At the moment Monad seems to be the answer :D Still pretty magical every time I do this.

screen shot 2019-01-26 at 15 46 55

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Jan 26, 2019

@enzyme69 you mean.. can Mesh Switch node do this? 😃

sv-meshswitchnode-demo4

Well.. now it does :) The Selected input needed to take multiple inputs. I didn't think it needed to output more than one selection, but it makes sense for this sort of applications.

@vicdoval
Copy link
Collaborator

@DolphinDream Cool node!
An idea could be to expand/ generalise the node to be the new switch node. Right now the Switch node in the 'single' mode you can do the same task but just with two inputs groups. It would be great to combine the socket flexibility expanded to more groups as this node does and with vectorized selection
switch

@DolphinDream
Copy link
Collaborator Author

@vicdoval Hm.. This switch node is a bit confusing to me. Why is it "single" has multiple set of inputs and "multiple" has only one set of inputs? :)
You're right.. this node could be generalized to take arbitrary type of inputs. As a matter of fact even now you can feed any type of inputs to the nodes (though perhaps it may not work fine with matrixes I suspect). I'll give it another try to make it more general.

@vicdoval
Copy link
Collaborator

The multi mode would be like a element switch working on level 2. Maybe the name is a little bit confusing... There is no documentation about it but maybe is better to wait if you are going to merge both nodes.
Also I think it could be interesting if it could handle more than two inputs 😄
sverchok_switch_multi

@enzyme69
Copy link
Collaborator

enzyme69 commented Jan 27, 2019 via email

@DolphinDream
Copy link
Collaborator Author

@enzyme69 yeah. i was thinking the same. select a bunch of generator nodes + macro => links all generator V-EP outputs to the mesh switch node :)

@Durman
Copy link
Collaborator

Durman commented Jan 28, 2019

By the way, I made some improvements of the switch node while ago. It should become much more clever.))

#2217
documentation - https://github.com/nortikin/sverchok/blob/ef5de98b4a32548e56994cf69b444361af7cd853/docs/nodes/alpha_nodes/switch_MK2.rst

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Jan 31, 2019

Well.. here's my latest incarnation of the "switcher" node.. which is now generalized to not only take any input (not necessarily verts / edgePoly), but also to take an arbitrary number of what I call "bunches" :)

sv-meshswitchnode-demo5

Some improvement ideas and considerations:

  • allow the already connected inputs to still stay connected when changing the "bunch" number. currently, it just deletes all input nodes and recreates new ones. (same with the outputs).
  • Maybe the auto-generation of new inputs when connecting the last input is not as desirable when the number of bunches is large as it unnecessarily creates an empty bunch of inputs just to allow a new set of inputs to be connected and growing the node. Maybe a separate "number of bunches" parameter would be better as it will only create as many bunches as needed.
  • find a way to auto connect the output to the viewer draw
  • design the node in such a way that a macro can instantiate a node and connect a bunch of selected input generator nodes to it. I don't' know anything about macros in SV so I don't know what's required of a node to be able to play nice with macros. for instance, currently the new bunches are automatically created as the last bunch is connected.. so I'm not sure if a macro could still connect selected nodes to the switch node if the switch node doesn't have all the input sockets already available for connection.

@DolphinDream
Copy link
Collaborator Author

sv-meshswitchnode-generalized-example1

@DolphinDream
Copy link
Collaborator Author

Here are some other improvement ideas: (feel free to add yours)

  • Change the name of the outputs to the name o the selected input (e.g. Alpha, Beta etc), unless the Selected parameter is a list of selections in which case the output socket names can stay "Data"
  • Color the input socket nodules differently better visually separate the input sets
  • automatically link the output node sockets of a node to a set/bunch of input sockets of the switch node. Whenever the first output socket of a node is linked to the first input socket in a bunch, the second socket of the input node could also be automatically connected to the second input in the switch node in the same bunch (assuming the bunch number is at least two. The generators, in particular, could benefit from this since they usually have verts, edges, polys output sockets in this order.

Btw can we bet the Node Wrangler type of functionality with SV nodes? Like Ctrl+Cmd+LMB drag from one node to the switch node could automatically ask what output sockets to link (V, VE, VP, VEP) etc.

@DolphinDream
Copy link
Collaborator Author

Here's what it looks like for each input set/bunch to get its own socket color. (tried to keep the colors a bit different than the ones already designated for the other node types).

sv-meshswitchnode-demo6

@DolphinDream
Copy link
Collaborator Author

Btw, how does the "right click menu" command links the node to the viewer draw nodes ? I get the option when i CMD+click on the node but it only spawns the viewer draw node without connecting the sockets. Does this option look for a vertex socket in the input node to connect to the VD input verts socket?

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Feb 2, 2019

Btw.. I discovered that VDMK2 node has some issues .. when you feed it a list of meshes that are not all vert/poly or vert/edge. :) I posted this in a separate thread (see #2361 ). And it's not a mesh switcher node related, I even replicated that with regular list join nodes.

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Feb 3, 2019

Anyone knows (@zeffii) how to insert new input sockets without disconnecting the already connected sockets? E.g. If the switch node has two inputs per set (bunch = 2) and the first inputs in each set is connected (e.g. verts and edges inputs are both connected) when increasing the number of inputs to 3, each set would need to have a third socket added to the set, but I'd like to be able to keep the already connected sockets (1&2) connected.

Essentially go from:

Alpha 1  * (connected)
Alpha 2  * (connected)
 Beta 1  * (connected)
 Beta 2  * (connected)

to

Alpha 1  * (connected)
Alpha 2  * (connected)
Alpha 3    (unconnected, newly created)
 Beta 1  * (connected)
 Beta 2  * (connected) 
 Beta 3    (unconnected, newly created)

One way I can think of doing this (if possible) is to first query the nodes/sockets connected to each input sockets of the switch node.. then delete all input sockets (of the switch node), recreate them with larger number of inputs per set, and then reconnect the previously connected sockets of the external nodes to their sockets they were previously connected to.

Another way, though I don't think this is possible, is to directly INSERT sockets in between other sockets already created in the input sockets variable (which seems to be a prop collection).

@DolphinDream
Copy link
Collaborator Author

Example of the desired behavior when increasing the set size:

sv-inputswitchnode-demo2

@zeffii
Copy link
Collaborator

zeffii commented Feb 4, 2019

i do not like the idea of arbitrary colors at all. for input switch... so.. without lookingthe implementation, i'm not in favour. There must be some other way to differentiate the socket grouping.

@DolphinDream
Copy link
Collaborator Author

i do not like the idea of arbitrary colors at all. for input switch... so.. without lookingthe implementation, i'm not in favor. There must be some other way to differentiate the socket grouping.

OK.. any other ideas how to better differentiate between sets?

And how about the last issue i'm having about inserting sockets without disconnecting others?

@zeffii
Copy link
Collaborator

zeffii commented Feb 4, 2019

because we have limited options to control the layout of a socket ui, beyond color.. you could make a new dummy-like socket with an entirely transparent nodule, that would act as a faux-separator between sets.

regarding inserting sockets, it might be that the pynodes API is limited in our high need for dynamic ui.. i do not have a fast answer :/

@DolphinDream
Copy link
Collaborator Author

With a dummy fully transparent socket you'd still be able to connect to it, right? If so that would be a bit confusing, I think.

I would be cool if you could change the background color of a socket to make the group of sockets be like alternating row colors of sort.

@zeffii
Copy link
Collaborator

zeffii commented Feb 5, 2019

you can implement code that automatically disconnects any input into the 'separator' socket,, if that's a real issue... or automatically connect the link to the next appropriate socket.

it would be nice to be able to set the socket+label background colors, sadly it's not an option in the layout engine. but imagine for a moment..

  | switcher                        o |
  |                                 o |
  |                                 o |
  | [ link selected node ]            |     <-- operator in red, using "layout.warning"
  | o                                 |
  | o                                 | 
  | o                                 |
  | [ link selected node ]            |    
  | o                                 |
  | o                                 | 
  | o                                 |

@DolphinDream
Copy link
Collaborator Author

@zeffii I don't' know what you mean by "layout.warning"

@zeffii
Copy link
Collaborator

zeffii commented Feb 6, 2019

    row = self.layout.row()
    row.alert = True

any operator buttons on that row will be a different "warning" color.

@zeffii
Copy link
Collaborator

zeffii commented Feb 7, 2019

there's also socket.link_limit , which can be set to 0 - never tried it, but seems useful

@DolphinDream
Copy link
Collaborator Author

@zeffii cool. Thanks for the suggestions. Unfortunately, I don't find this hack appealing. I tried to see if layout.separator() inserted in the socket drawing level can space the sockets apart but I can't see any effect. maybe I 'm not putting it in the right place.

Another idea would be to add custom icons before socket labels? (alternating between white/black or something).

sv-socketgrouping-01

Ideally, I would like to have something like this (if possible) from left to right in the increasing order of preference.

inputswitch-backgroundcolors123

@DolphinDream
Copy link
Collaborator Author

Would alternating green colors for sockets, with slightly different shades of green be acceptable?

sv-socketgrouping-02

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Feb 8, 2019

@zeffii how could I remove a link automatically? I'm creating a faux SvSeparatorSocket and i want the socket to be disconnected if you try to connect to it.

class SvSeparatorSocket(NodeSocket, SvSocketCommon):
    ''' Separator Socket used to separate groups of sockets '''
    bl_idname = "SvSeparatorSocket"
    bl_label = "Separator Socket"

Could this auto-detach be done directly in the separator socket class? What method gets called in the socket class when a socket is connected?

Also.. can you make the socket completely transparent? Including the stroke?

sv-separatorsocket

@DolphinDream
Copy link
Collaborator Author

@zeffii I added this to my node's update method and it does the job of detaching any connection to Separator socket however I wonder if this could/should be done instead in the node_tree in the SvSeparatorNode class itself (if so what method?)

       for s in self.inputs:
            if s.bl_idname == "SvSeparatorSocket":
                if s.is_linked:
                    print("separator socket is linked")
                    for link in s.links:
                        s.id_data.links.remove(link)

@zeffii
Copy link
Collaborator

zeffii commented Feb 8, 2019

the more i think about this, the more it feels more appropriate to just keep it simple and use conventional sockets. which are sufficient to act as indicator of the group.

VerticesSocket   | verts a
StringsSocket    | edges a
StringsSocket    | faces a 
VerticesSocket   | verts b
StringsSocket    | edges b
StringsSocket    | faces b 
VerticesSocket   | verts c
StringsSocket    | edges c
StringsSocket    | faces c 

but i get your position, for this particular node the default ui/layout features are showing their sparsity.

@zeffii
Copy link
Collaborator

zeffii commented Feb 8, 2019

and if you really have to, insert the SvSeparatorSocket inbetween sets.

as for the update function, you could stick most of the working code for the disconnection into the socket definitino, and call it from within the node update function.

@DolphinDream
Copy link
Collaborator Author

I like the idea of putting the disconnection code in the SvSeparatorSocket class but unfortunately this is not going to be a lot of code since in my node I would still have to search for each socket and only call the disconnection code (two lines of code) if the socket is a separator type and is it’s connected. A more effective way (if possible) would be if the socket received a call whenever it’s connected and let the socket class automatically handle the disconnection without being prompted by the node. I assume this would be done at the lower level infrastructure.

@zeffii
Copy link
Collaborator

zeffii commented Feb 8, 2019

since the socket class doesn't have an update function, you might settle for

# ... socket class...
def remove_links(self):
    for link in self.links:
         self.id_data.links.remove(link)    

# ... in the node class ....
def update(   ):
    ... other stuff ...
    _ = [s.remove_links() for s in self.inputs if s.bl_idname == '....']

@DolphinDream DolphinDream mentioned this pull request Feb 9, 2019
6 tasks
@nortikin
Copy link
Owner

nortikin commented Feb 19, 2019

right side without colors rainbow. only boxes shading

inputswitch-backgroundcolors123

OMG. It is impossible

@zeffii zeffii added this to the 2.8 milestone Jun 19, 2019
@portnov
Copy link
Collaborator

portnov commented Nov 17, 2019

@DolphinDream , @Durman In which way this is supposed to be in 2.8x? Considering there is #2671 issue.

@DolphinDream
Copy link
Collaborator Author

This node was replaced by the Input Switch node So i don’t think it has to be ported to 2.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants