5
$\begingroup$

One feature that I use frequently in shader editor, is an option to toggle between different shaders or textures. It can look like this:

enter image description here

Changing the value node on the left within the interval of 0.0 to 0.3 allows me to quickly change the used diffuse shader. This setup can be used for a lots of stuff.

How can I replicate this setup in geometry nodes with the intention of changing different geometries?

Let's say I have a cube, sphere and a monkey in my scene and I add a geometry nodes to the cube. The other two objects are loaded using object info nodes. Since Join Geometry node doesn't have a factor, I can't really switch between used geometry.

enter image description here

$\endgroup$
2
  • 3
    $\begingroup$ There is a "Switch" node in the latest 3.0 beta version : youtu.be/GLI1qluppFM?t=649 It has not yet been updated in the docs. I think it will not be available in the next 2.93 release. $\endgroup$
    – Gorgious
    Commented Apr 21, 2021 at 17:43
  • $\begingroup$ @Gorgious Yeah that's a good solution. I guess we will have to wait. $\endgroup$
    – Dalibor-P
    Commented Apr 21, 2021 at 17:50

3 Answers 3

2
$\begingroup$

You can do that quite easy with a Point Separate node.

enter image description here

In the image above I've created a mesh with a single vertex. The node network splits into two paths based on the attribute value do_monkey, which is set by the Attribute Fill node (or by anything else that you need).

$\endgroup$
2
  • $\begingroup$ It's kinda of an awkward solution, because it requires a single vertex to work, but it kinda works. I will use it in the future, until the switch node gets implemented. $\endgroup$
    – Dalibor-P
    Commented Apr 23, 2021 at 18:25
  • $\begingroup$ It might “feel” awkward but it’s totally fine :) In fact you will need points all the time to instantiate anything in procedural networks. Sometimes you’ll even create a complex invisible mesh just to grab some points from it. $\endgroup$
    – null
    Commented Apr 23, 2021 at 18:33
5
$\begingroup$

The Switch Node

The Switch Node can be set to receive the following input types:

  • Float
  • Integer
  • Boolean
  • Vector
  • String
  • Color
  • Object
  • Image
  • Geometry
  • Collection
  • Texture
  • Material

Here are two different approaches you can take: Switching between geometries, or switching between objects. If switching between objects, by using Relative transformations, you can also access Location/Rotation/Scale data.

Geometry Nodes - Switch Node basics: Switch the geometry, or the entire object

In this example, changing the Switch value from 0 to 1 will change the evaluation from FALSE to TRUE, resulting in a Cone being received from the Switch Node set to Geometry, and a Suzanne monkey mesh from the Switch Node set to Object.

Multi-switch

If you need to cycle through many different objects or geometries, you can create a Group Node that accepts multiple inputs, and select one as the output:

You can cycle through multiple Geometry Nodes objects or geometries by constructing a custom Group Node

Here's what's happening inside the group:

Geometry Nodes: The node tree of a multi-object switch

Yikes!

It's not as complex as is looks. Just a series of TRUE or FALSE evaluations, matching against the integer value of the "Select Object" input.

(It's not obvious from the screenshot, but the collapsed nodes are Math Nodes set to Add)

No, you don't need to reconstruct it: (Made using Blender 3.0.1)

Result:

Animated GIF of the Geometry Nodes result - switching mesh by input number

$\endgroup$
2
$\begingroup$

You can try a more modular approach. Start by creating a node group with a switch system. Checking if the modifier index is the same as the node group index. If yes, output the object geometry, if not, output empty geometry.

enter image description here

This lets you create intricate setups because you can use the node group index however you want. You can set an object to appear on two different indices, or two objects to appear on a single index.

enter image description here

Using this setup in the modifier :

enter image description here

enter image description here

BTW the setup in the shader example isn't linearly switching between the shaders. The blue diffuse shader has as much weight as all the other shaders combined. But for integer values it's okay. And I would clamp the Math nodes, mixing with a negative factor can get funky. :)

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .