3
$\begingroup$

I've never used geometry nodes before, but in a project I'm working on I want to randomize the scale of about 200 copies of the same object so I figured I would try geometry nodes.

In shader nodes you can get a random number specific to the object from the "object info" node. It has a "random" output, so you can apply the same shader to different objects and the random number will be different for each one, creating random variation.

I want to do the same thing in geometry nodes, but the "object info" in geometry nodes doesn't have a "random" output.

Using the "Random float" node generates the same random number for all objects because the seed is always the same regardless of the object...

So, how can I get a different random number for each object in geometry nodes?

Basically this setup, but with a different seed for each object that is using this geometry nodes setup: enter image description here

Note: the objects will be animated in a rigid body simulation and their scale needs to be static, so getting a number from the object's location wouldn't work, because since the objects will be moving the scale would change with the animation and that's not what I want. I want a static random number for each object.

This is basically the same question but the solution in the answer is to get the object's location, so it doesn't work for my case: How can I get a new random seed for every object using the same geometry nodes?

$\endgroup$
12
  • $\begingroup$ Similar to this question blender.stackexchange.com/questions/227082/… No real answer for now, though :) $\endgroup$
    – Gorgious
    Commented Jun 9, 2021 at 15:15
  • $\begingroup$ It's something so simple to do in shader nodes, I wonder why it isn't implemented in geometry nodes. There's probably a technical reason, but it's still frustrating. Guess I'll start manually changing the scale of 200 or so objects... $\endgroup$ Commented Jun 9, 2021 at 15:18
  • $\begingroup$ I'm not sure if i'm getting your question correctly, but do you mean something like THIS , one object, random size, with a way to change the seed? $\endgroup$
    – Emir
    Commented Jun 9, 2021 at 16:15
  • 1
    $\begingroup$ @Emir The way I understood is they want to design a GN modifier to add to the modifier stack of a great number of existing objects, that should take care of non destructively randomizing their scale between a min and max value $\endgroup$
    – Gorgious
    Commented Jun 9, 2021 at 16:43
  • $\begingroup$ @Gorgious got it. $\endgroup$ Commented Jun 9, 2021 at 17:25

1 Answer 1

3
$\begingroup$

This is a workaround proposition that has some caveats. It requires a tiny bit of python knowledge and drivers.

Note : All the seeds will be randomized every time you load the file again so you can't rely on any particular disposition. However it should remain stable during an individual session.

The node tree is very simple :

enter image description here

It randomly changes the scale of the geometry, based on an input scale on the modifier.

Now, add a driver to the Seed field in the modifier. Remove the variable, check Use Self and paste the formula : hash(self.id_data)%10000.

enter image description here

This will create a semi-random number between 0 and 9999 which should theoretically be different for each GN modifier. The nice thing is, it is tied to the modifier and will update automatically if you duplicate the source object.

Note : You will have to enable automatic execution of python scripts for the driver to work. Be careful if working with 3d party files downloaded from the internet, they can contain harmful code. You can setup untrusted folders like /downloads where scripts won't get automatically executed.

enter image description here

Result :

enter image description here

You'll notice that if you use the Copy to Selected operation, the driver doesn't get copied over.

enter image description here

You can copy the drivers with Object > Link/Transfer Data > Link Animation Data or CTRL + L > Animation Data.

To update the drivers afterwards, nudge the objects a little bit with G pressed and cancel with Right Click.

enter image description here

$\endgroup$
4
  • $\begingroup$ Very good solution, thanks! I have a question: why is the result different every time you load the file? Doesn't the random number come from each object's ID, and shouldn't that be the same every time you load the file? Also: isn't there a way to generate a pseudo-random number with drivers without using python script? $\endgroup$ Commented Jun 23, 2021 at 14:06
  • 1
    $\begingroup$ @AlexandreMarcati Good questions ! :) In Blender ID is a type of object, not a number. Every time you load the file, everything gets dynamically placed and rearranged in the system memory. hash is tied to id (not the blender ID, the python default method :) ), which is the address of the object in memory. See docs.python.org/3/library/functions.html#id $\endgroup$
    – Gorgious
    Commented Jun 23, 2021 at 14:56
  • 1
    $\begingroup$ And for the random number generator in a driver, you could theoretically emulate it by using the transform values of an array of objects randomly displaced in 3D space instead of python properties, but it's hard to scale properly and very cumbersome compared to the benefits of a scripting language $\endgroup$
    – Gorgious
    Commented Jun 23, 2021 at 14:59
  • 1
    $\begingroup$ Alternatively, with hash(self.id_data.name)%10000 the seed is based on the object's name. $\endgroup$ Commented Jul 13, 2022 at 9:11

You must log in to answer this question.

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