4
$\begingroup$

This question has been asked in various ways but I can't find a specific solution to my problem.

I have created a geonodes "Tile Generator" that tiles 6 objects in a grid with random selection. In this case they are 6 primary colors to illustrate what I'm trying to do...

Using the image below as a reference, how would I replace the one specific instance (the Yellow cube) with a cube that is not part of the instanced collection (in this case the Black cube)?

enter image description here

PROJECT FILE

$\endgroup$
1
  • $\begingroup$ Interface: How would you like to tell GN which instance to change? $\endgroup$
    – Robin Betts
    Commented Oct 11, 2023 at 7:19

2 Answers 2

3
$\begingroup$

The implied (used when nothing is connected) input to the Instance Index is just Index. The node then takes the modulo (remainder of division) by domain size, so if you want to have even distribution, you need to make the maximum random number produce the maximum instance index. Assuming the Min is $0$ and you have $6$ instances, here's some good Max values: $5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101...$ (number of instances multiplied by some integer, minus $1$), but of course the most reasonable is $5$ (number of instances minus $1$).

This might not be visible in this case, but imagine that you have $100$ instances, and randomize the index in range $[0; 100]$ - the first instance will be picked for both the $0 \operatorname{mod} 100 = 0$ and $100 \operatorname{mod} 100 = 0$, so the first instance will be twice as common as all other instances.

So here's how you do it correctly:

Then, the most convenient way to introduce the black square is to add it in the beginning of the collection, update the Random node to start at $1$ (don't pick the black), and do whatever selection logic you want to resign from a random value and pick the black (index $0$):

$\endgroup$
1
  • 1
    $\begingroup$ Markus I love this solution, it is very precise and works in a way that gives me a lot of control. Thank you! $\endgroup$ Commented Oct 11, 2023 at 18:01
4
$\begingroup$

one possible way is this:

enter image description here

enter image description here

so i just separate the point/instance you wanna replace by index and instance on that a new instance and delete the original point.

$\endgroup$
3
  • $\begingroup$ Thanks Chris, I will have to experiment with this. In lieu of not getting my hands dirty with it yet... how do I choose which instance will be selected/deleted? For instance, if I have a grid of 100+ instances? $\endgroup$ Commented Oct 11, 2023 at 18:03
  • $\begingroup$ @GlenCandle in both are answers the logic for choosing the instance to be replaced is the same: we pick by index. Ultimately you need to choose a logic depending on your needs that you didn't explain: maybe you want to pick a random instance, or an instance closest to a particular point (in which case you would use an attribute statistic first, then separate out the instances that have the distance equal to the minimum in the statistic, then e.g. taking the index 0 of that separated group) etc. $\endgroup$ Commented Oct 11, 2023 at 18:21
  • $\begingroup$ Thanks @MarkusvonBroady. I have a lot to learn about working with indexes! $\endgroup$ Commented Oct 12, 2023 at 16:14

You must log in to answer this question.

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