1
$\begingroup$

Is it possible and if so how could I create a piece of geometry for every material slot in an object using Geometry Nodes modifier?

For example let's say I have a cube and it has 5 different material slots with different materials and I want to duplicate the cube itself, move it to the side and assign the material for each material slot:

enter image description here

So if I decided to add another material in a new material slot, another copy of the cube with the material would be created by the geometry nodes.

$\endgroup$

1 Answer 1

1
$\begingroup$

Unfortunately, there is no way in Geometry Nodes to determine the currently assigned number of materials.

But if you can live with passing the number of materials via an integer value, then the following would be a solution:

enter image description here

  1. Here I use a Mesh Line, where the distance between the points is set with the value Offset. The number of points here is set via the Group Input, which uses the number of your materials.
  2. Then I simply instantiate the cube along these points.
  3. So that I can assign a different material to each instance by index, I first use the Capture Attribute node on the Instances domain.
  4. After I turn the instances into a mesh with Realize Instances, I can use this index directly in the node Set Material Index.

$\endgroup$
1
  • 1
    $\begingroup$ Cool! I can just add a driver to drive the modifier input field, create a variable out of object.material_slots and use len() function for that variable - that's exactly what I wanted. Thanks! $\endgroup$ Commented Jun 29, 2022 at 22:00

You must log in to answer this question.

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