3
$\begingroup$

Using 3.0.0 Beta, it looks like Instance on Points replaces the *Point InstanceU node, but using this with collections is stumping me.

I'd like random instances from a collection to be used at each point in some geometry. I see how to use *Collection Info and Pick Instance nodes. But the Instance Index confuses me; is there a way to get the size of a collection and use that to randomize selection? I happen to know my collection has 2 instances and I set the Random Value node accordingly, but I'd like a more general way to do this.

Here is a node tree that I created:

enter image description here

Is there a way to get the size of a collection?

$\endgroup$
2
  • 1
    $\begingroup$ if you set the max. Random Value to a large number, as far as I can see, it is taken to be Modulo(Number of Children) , so a near-as-doesn't-matter random selection can be made per-point. Is that good enough? $\endgroup$ Nov 6 '21 at 19:13
  • 1
    $\begingroup$ This is good enough, and you are correct. I went looking into the sources and found where it does use the modulo of the index, and it looks like my idea of the "size" of the collection may be too simplistic. It seems, with your suggestion I should make both the min and max random values higher than the size of the collection; if the random number is smaller than the collection size, the higher indices would be unselectable. $\endgroup$
    – stav_nan
    Nov 7 '21 at 12:58
3
$\begingroup$

Robin Betts had a good suggestion: exploit the modulo nature of the instance index input. This is my current solution:

enter image description here

$\endgroup$
2
  • $\begingroup$ Great! If that lookup into the code you mentioned is still handy, maybe you could include a link to it? np if it's too much trouble. $\endgroup$ Nov 7 '21 at 13:12
  • $\begingroup$ The source file is node_geo_instance_on_points.cc, function add_instances_from_component: const int index = mod_i(original_index, std::max(src_instances_amount, 1)); $\endgroup$
    – stav_nan
    Nov 8 '21 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.