The node Set Material
assigns a material to a geometry. However, exactly one material.
Therefore the node Set Material Index
can only be applied to a geometry which has been assigned several materials before.
This can be either the geometry containing the Geometry Nodes modifier, but also geometry created in Geometry Nodes.
If you create geometry in Geometry Nodes, you have to assign several materials to it, which is possible by lining up several Set Material
nodes and then selecting the respective slot with Set Material Index
.
But this is not very flexible, because you would have to use many nodes in a row manually.
But there is a little trick:
Here you use the original geometry, to which several materials were assigned in the Material Properties before, as a base.
The trick is: By adding more objects afterwards with Join Geometry
, or as in this example with Geometry to Instances
, these inherit the materials of the base object.
In addition, these get their own index, which can be used here as Material Index at the same time.
The original geometry should not be used here in the end, so I mark it with the node Capture Attribute
and remove it afterwards. The captured materials as well as their material index are kept in the rest of the geometry.
In this way I can assign each object its own material index, and the materials defined by you are taken from the Material Properties.
(Blender 3.3+)