7
$\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
  • 2
    $\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$ Commented Nov 6, 2021 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$ Commented Nov 7, 2021 at 12:58

2 Answers 2

7
$\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$ Commented Nov 7, 2021 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$ Commented Nov 8, 2021 at 12:49
3
$\begingroup$

Size of Collection in Blender 3.2 (maybe older verisons too). It should work on any geometry type with a Point domain.

Use the Collection Info Node as above and connect its Geometry with a Domain Size Node. Then change the option to Instances and it should output the number of objects in your collection.

Node tree connection between Collection Info Node and Domain Size Node to get the size of a collection

From what I've tested it counts metaballs and subcollections too which could be a problem for some. It does not count the objects in the subcollections.

$\endgroup$
1
  • $\begingroup$ And don't forget to subtract 1 for the max Random Value $\endgroup$ Commented Aug 22, 2024 at 23:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.