switch node with more inputs

pete's Avatar

pete

16 Oct, 2017 07:06 PM

hello everyone.
i'm making a random face generator using Switch nodes to choose from a few svg face parts.
it works great, but i want to have more face parts in the mix. when i create a Switch node, i'm only getting 6 inputs. is there a way to get more? or do i have to combine multiple switches?
thanks!
-pete

  1. Support Staff 1 Posted by john on 16 Oct, 2017 11:08 PM

    john's Avatar

    Hi Pete,

    You could combine multiple switches, but I wouldn't recommend it. I think there is a simpler and more elegant way that will let you easily expand and change face parts without having to rewire your network each time.

    What you need to do is build your own little table. At minimum this table will have two columns: svg_ID and type (where type is eyes, nose, mouth, hair, etc.). Once you have that you can filter it to show you just svg_IDs for a certain type (e.g. type = 'nose'), get a count, and choose one at random or whatever.

    The ID is whatever you need to identify a particular SVG. If each SVG is in a separate file (maybe some in a Noses folder, some in a Mouths folder, etc.) you could use the actual file path as an ID and, once you identify the one you need, just lookup the file path name and import it using an import SVG node. In this case you would need to maintain your own spreadsheet and then import it using an Import CSV node.

    If you read in all your SVGs at once and then assemble them into different piles within NodeBox, your master list will be a single combined list of paths or geometries. In that case, once your master list is assembled, you could build up your own internal table using my MAKE_TABLE subnetwork (http://support.nodebox.net/discussions/show-your-work/224-make-table) and use the index numbers to your master list as ID numbers.

    For example, suppose you have a list of 5 noses paths, 7 eyes paths, and 8 mouth paths (20 in all, 0 to 19). IDs 0 - 4 would be your noses, 5 - 11 your eyes, and 12 - 19 your mouths. So when you filter your table and select, say, a mouth with ID 14, all you then have to do is take a slice from your master list with start index of 14 and a size of 1. Voila!

    The beauty of this system is that it's completely data driven. To add more noses or mouths all you have to do is add new SVG files into some folder and update your own spreadsheet, or add them into a single SVG file for each part type and let NodeBox import them, and dynamically build an ID table for you. No switches or rewiring required. You could have a thousand different noses if you wanted.

    I hope this makes sense. Please feel free to ask me more questions. NodeBox is a great solution for this type of thing.

    John

  2. 2 Posted by pete on 16 Oct, 2017 11:21 PM

    pete's Avatar

    wow! thanks john! that seems like a great, robust solution. i'll have to really dig into that. it's currently beyond my skillset :)

    i do love the idea of building a bunch of creature generators in nodebox, so it will be certainly worth getting this stuff right.

    thanks again!
    -pete

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

18 Nov, 2017 01:04 PM
18 Nov, 2017 12:08 AM
17 Nov, 2017 11:15 AM
16 Nov, 2017 09:06 AM
15 Nov, 2017 05:18 PM

 

15 Nov, 2017 04:59 PM
15 Nov, 2017 04:32 PM
15 Nov, 2017 04:30 PM
15 Nov, 2017 04:29 PM
15 Nov, 2017 04:28 PM
13 Nov, 2017 10:53 PM