Writing a rock generator script

So, i’ve been learning some Blender scripting and i’m trying to create a simple rock generator, inspired by this MaxScript:


It seems that he’s using voronoi cells for the rock shape and simplex noise for the displacement texture. I have some questions for the experienced scripters out there:

  • How can i displace a mesh dynamically?
  • Does Blender have built in functions for creating meshes from voronoi cells?
  • Would it be easier to start with a primitive, like a cylinder or box, and apply a voronoi cell to it’s vertexes and then displace with the noise?

How would you guys approach this?

would be easier to use the rock gen in addons contrib.

Oh, i’m not really interested in the final product. I’m interested in learning how much easier Blender can be for manipulating meshes. I have lot’s of experience with MaxScript and, the way i would do it in Max, would be:

  • Generate a box with random dimensions
  • Generate a voronoi cell map with cellular()
  • Make some noise with noise()
  • Add displacement modifiers to the box with cell and noise maps
  • Add some turbosmooth

So, i’m trying to make the same steps in Blender, but i’m new with it and would like to know if someone experienced can give me some guidelines. Like, where to look in the docs for applying displacement modifiers, smoothers, how to generate voronoi cells, how to generate simplex noise, etc.

Bumpit bump! :slight_smile:

i would look at the code for the current “rock generator” and reverse engineer that

the thread here on this site

another interesting approach is the “To Sphere” option in ANT Landscape.

The code for the existing rock generator is really really complex and follows a much more rich workflow. I was aiming for something simple, that i’m used to do in Max. It’s less powerful, but easier for me to understand and learn the Blender API.

Would it be better to create an iso sphere for the base rock?

I played around with a cube and 2 modifiers only… subsurf and displace, with a musgrave texture, very simple… of course you can automate those modifers / texture generation via bpy… there are operators for this in bpy.
Is that “rocky” enough ? The possibilities are really huge, even with onboard tools of blender.

Here is a simple blend:

rock.blend (85.4 KB)

Edit: here is an addon stub, which exactly replicates the result in python.
TODO would be useful randomization of default parameters, maybe a simpler “detail” control via the add operator…

create_rock.zip (1002 Bytes)

Did you notice that on the gif i sent the rock generator sometimes generates rocks with hard-edges on flat surfaces? That’s the voronoi being stronger in the random generation. In Blender, however, i’m not able to achieve that same with the same Voronoi noise. All rocks look like crap because they seem like Clouds + Simplex noise being displaced, they don’t have the hard edges and almost-flat surfaces.

Hmmmm, i think this kind of displacement you want is harder to achieve. You would need to exclude some edges from smoothing (would work with “Mark Sharp” and Edgesplit modifier or maybe per Autosmooth) and perhaps from displacement too by adding all faces you want to displace into a vertex group.

Closest i could get with my setup, turning up subdivision levels insanely high… i get some hard edges now, but no flat surfaces.

Edit: Alternatively, i came up with this…

That’s interesting. I’ve tried using a larger-scale voronoi on a highly subdivided UVSphere and achieved some harder edges. But it’s far from what i’m looking for, which is something like this:

I’m not able to achieve those flat planes with voronoi. The voronoi noise always makes something curve, either pointing outside or inside. Like a bubble.