2
$\begingroup$

I come from this thread with a dilemma that I don't know how to properly solve and have presented a minimal reproducible example. Apparently it is expected behavior that Volume to Mesh node will add a hidden Empty Material that is white by default. So if you have 3 materials on your object, you will end up with 4 materials in the following GN setup without you ever knowing. So I'm currently adding 1 to the Material Index to remedy this problem, because that hidden material is disrupting my node setup. But that is very hacky.

So I was thinking maybe I can create a node setup that checks that if the material list is longer than the one I have initially defined, then that means there was something new added to the list. But the problem is it is possible for that new hidden material to be inserted on index zero and also possible to be added to the end of the list. See TICKET-119269. So how will I know when it is added to the top so that I can decide to add 1 to the material list? If it is added at the end of the list then I have no problem. So first I need to check if the list is longer by 1 then check if it is added to the top or bottom list.

enter image description here

Here demonstrating that adding 1 to material index "fixes" the problem.

enter image description here

The hidden material becomes visible once you apply the modifier and it can either appear at the top or bottom of the list:

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ I think there is a misconception about how Blender handles materials on objects in general and how GN handles materials specifically. It is not the Volume to Mesh modifier which adds a "hidden white material". All mesh primitives show a default when you don't put a real material on them. In GN, newly created geometry has no material like a new primitive. In GN you can set materials for geometry, even if they don't exist on the GN object itself. The problem is, once you apply the GN modifier, the created objects needs to have the materials, otherwise the materials could not be assigned. $\endgroup$ Commented Mar 10 at 7:47
  • 1
    $\begingroup$ And here comes the issue with the "hidden white material". An object needs no material to show the default white (light grey actually) and therefore no material slot. But as soon as you put just one material (and with it a slot) on it, by default all faces get this. To have some faces show other materials, you need to add them and assign them to faces - which the GN nodetree did. But if there are faces where GN did not assign, they cannot be left unassigned on the "real" mesh pnce other materials. Therefore it creates an empty slot (without material, not hidden) to assign to those faces. $\endgroup$ Commented Mar 10 at 7:53
  • 1
    $\begingroup$ To learn more on material slots and material assignment, you might read my answer here: something strange with material slots because that's how Blender basically works with materials on mesh objects... and this is what it comes down to when you apply the GN modifier. $\endgroup$ Commented Mar 10 at 8:11
  • 1
    $\begingroup$ Thank you Gordon for sharing! $\endgroup$
    – Megan Love
    Commented Mar 10 at 8:25

2 Answers 2

4
$\begingroup$

I'll write this as an answer to be able to illustrate this additionally to my comments and to show what is going on there.

The problem with your answer is, it works in this specific case, but it does not generally solve the problem. This answer is just to make you and maybe others coming across this question aware of what happens.

Every mesh object comes with a default "appearance", this dull light grey material, to have some kind of shading to be shown in the viewport. A mesh object shows it by default, it is no actual material, just an internal default how to shade surfaces without material and it does not need a material slot for it.

As soon as you add either an empty material slot or a material which automatically creates a slot, all faces of a mesh object will be assigned to this slot. Adding more slots do not get assigned to faces automatically, they have to be assigned manually.

In Geometry Nodes, original meshes keep their material like the base mesh if it has one, or objects brought in with Object Info node for example. All these can have new materials assigned with the Set Material.

New geometry generated inside the GN nodetree does not have a material and does not use the material from the base mesh. Therefore you have to assign materials with a Set Material node to them if you want them to appear different then the dull light grey default surface.

Now here comes the crucial point where your solution might get a problem in other cases than the specific one here: with the Set Material node you can assign any material that is in the scene to geometry in the nodetree. The base object holding the GN modifier does not need any material at all, the materials only have to be somewhere in the scene like on other objects for example, which do not have to be represented in GN with an Object Info or anything.

Like in the following image. The base object, a cube, has no materials and not even an empty material slot as you can see on the right side in the Material Properties. However, the three different objects I created in the nodetree all have their own material assigned to them, one red, one green and one blue.

These materials are on a different object in the scene and can be "stolen" by the Set Material node. The reason why you can have materials on the GN objects without any material slot is, they are "virtual" geometry, procedural, not yet "real" meshes.

no material slot for materials

When you now apply the GN modifier, the procedural geometry gets converted into a real mesh. A real mesh cannot have materials assigned to faces without having those materials stored in material slots. So either applying could remove all materials since the base object has no material slot, or - and this makes more sense since applying the modifier is supposed to result getting what you virtually have now as real geometry without changing the appearance - there have to be material slots created holding those materials. This should not come as a surprise, even without using GN, when you join two objects with Ctrl+J and they have two different materials in only one slot each, the joined object now has two slots, one for each material.

applied GN with added slots

And because the base object information is kept in the GN modifier to be available with a Group Input node even though it is not contributing to the output geometry, you will get an empty material slot here as well, because the now no longer visible faces of the original base mesh did not have a material assigned.

Whenever an object has at least one material and therefore a material slot, no face can be "unassigned" to a material slot. Each face is assigned to the default slot or manually to a different slot if existing.

Applying the GN modifier now preserves this unassigned part of the original base mesh by adding an empty material slot without any material. But since the original mesh is not contributing to the output, it is not plugged into a Join Geometry node and you cannot change its order for the output. In this case, the empty slot will always be on top of the materials at index 0.

$\endgroup$
2
  • 1
    $\begingroup$ Ah interesting thank you for sharing! So there is currently no solution? I see it was solved only in my case, but I realize that the order of joins like in this case doesn't matter and would still put the slot at the top which could potentially mess up the resulting output when dealing with other setups that tinker with material indices? $\endgroup$
    – Megan Love
    Commented Mar 10 at 9:56
  • 1
    $\begingroup$ Well, the problems I describe here are mostly just occuring as long as you are not aware they could occur. A solution could be, the base object needs to have a material, each geometry created in the nodetree contributing to the output needs to have a material assigned with the Set Material node, and all materials used by the Set Material have to be stored in material slots on the GN modifier's base object. And when all materials are already present in existing material slots, the order in the Join Geometry does not even matter since no new slots would be added. $\endgroup$ Commented Mar 10 at 10:23
1
$\begingroup$

Nevermind I realized a very simple solution was to swap the socketing of the noodles so the empty material gets added to the end of the list and thus not disrupting the node setup!

enter image description here

$\endgroup$

You must log in to answer this question.

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