3
$\begingroup$

In Geometry Nodes, I connect a the material socket of a 'Set Material' node to the 'Group Input' node.

Now, when the material socket in the modifier panel is empty, I want to use this fact to activate a switch node. For example, I want to trigger an 'Index Switch (material)' node to apply a different material.

How can I detect when the material socket is empty and convert that into a boolean?

enter image description here

$\endgroup$

2 Answers 2

2
$\begingroup$

If I understand correctly, you want to convert a material to boolean:

  • Material is present: TRUE
  • Material not present ("None"): FALSE

So the below overrides the material only if it's specified, otherwise uses the original material of provided geometry (and as you can see in the tooltip, this is the latter option):

Here's how I implemented this converter:

The reason it works is that any geometry created already has an empty material slot, and by setting a new material you add a material slot. I'm not sure the slot won't be overridden in the future, so you might want to create two triangles instead and only set the material on one of them (and read that triangle's material index).

$\endgroup$
2
  • $\begingroup$ Hi Markus, thank you very much for your solution! I plugged it into a switch and it works. :-) By creating an extra triangle, do you mean it like this (an extra unconnected triangle): imgur.com/a/e3nXywo $\endgroup$ Commented Sep 30 at 17:23
  • $\begingroup$ Yes, great Markus, your solution works perfectly! $\endgroup$
    – quellenform
    Commented Sep 30 at 17:24
1
$\begingroup$

To determine whether a material has been assigned via the Group Inputs, you can use the following setup:

Here I first apply the selected material to the geometry. Then I replace the selected material with an empty material.

Then I use Material Selection and Sample Index to check whether the geometry still contains the material defined at the beginning.

If not, then the slot was not empty and a new material can be assigned. If it is, then an alternative material is used.

The trick here is that if no specific material has been selected, both materials are empty when the check is done.

$\endgroup$
4
  • $\begingroup$ Thanks for your solution! I tried to recreate this, but I must be doing something wrong. In this setup: imgur.com/a/7VkP3mN ,when I select a material in the input in the modifier panel (material "yellow" in this case), it does not turn the switch to "true". I have now uploaded the file in my original question. $\endgroup$ Commented Sep 30 at 16:15
  • $\begingroup$ @PieterLéon Indeed! It's my fault. I obviously have not tested this solution extensively. It only works if the material assigned in the group input is the only one defined in the material properties. Otherwise, no selection is made and the solution does not work. $\endgroup$
    – quellenform
    Commented Sep 30 at 17:21
  • $\begingroup$ @PieterLéon I think after reviewing and correcting, I was able to crack the nut. $\endgroup$
    – quellenform
    Commented Oct 1 at 12:38
  • $\begingroup$ Great, thank you! :-) This works too! $\endgroup$ Commented Oct 2 at 6:57

You must log in to answer this question.

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