3

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?

Alexandre Marcati
  • 1,805
  • 8
  • 31
  • Similar to this question https://blender.stackexchange.com/questions/227082/assign-random-material-to-whole-object-using-geometry-nodes No real answer for now, though :) – Gorgious Jun 09 '21 at 15:15
  • 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... – Alexandre Marcati Jun 09 '21 at 15:18
  • 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? – Emir Jun 09 '21 at 16:15
  • 1
    @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 – Gorgious Jun 09 '21 at 16:43
  • @Gorgious got it. – Alexandre Marcati Jun 09 '21 at 17:25
  • @AlexandreMarcati: didn't work unfortunately. – Chris Jun 09 '21 at 19:28
  • Sorry, what didn't work? – Alexandre Marcati Jun 09 '21 at 19:28
  • Perhaps would be easier to just create a driver to use in each objects scale parameter, without using geometry nodes. – Alexandre Marcati Jun 09 '21 at 19:30
  • yes, i think so you. and this would be pretty easy. – Chris Jun 09 '21 at 19:31
  • Guess I was tryng to kill a fly with a handgun... – Alexandre Marcati Jun 09 '21 at 19:32
  • So, what you need is one geometry nodes to control 200 individual objects but every object should get a different value?... I think the only way to do something like this is if you use all those objects inside a collection and use Geometry nodes to make instances of the objects (like a grid) but i'm not sure if that works whit physics – Emir Jun 09 '21 at 19:52
  • "but every object should get a different value?" Yes. Since this is possible and trivial to do with shader nodes I assumed it would be equally easy to do with geometry nodes, but it seems I was wrong. – Alexandre Marcati Jun 09 '21 at 19:59

1 Answers1

3

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

Gorgious
  • 30,723
  • 2
  • 44
  • 101
  • 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? – Alexandre Marcati Jun 23 '21 at 14:06
  • 1
    @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 https://docs.python.org/3/library/functions.html#id – Gorgious Jun 23 '21 at 14:56
  • 1
    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 – Gorgious Jun 23 '21 at 14:59
  • 1
    Alternatively, with hash(self.id_data.name)%10000 the seed is based on the object's name. – Michael Butscher Jul 13 '22 at 09:11