# How can I programmatically create a mesh similar to this one?

I am pretty good at manually modeling, but I would like to learn how to create meshes that are similar to the one in this video, specifically the one in the attached screenshot. I believe that it is possible to use nodes(?) or algorithms to generate things like this programmatically.

How would I go about learning to do something like this - are there tutorials/references someone can point me to? I am not sure what to search for. Thank you!

• Blender does not (yet) have nodes for editing geometry (though there are some addons for this and it is on the plan for future features). In the meantime modifiers can be used to non-destructively create or edit a mesh, but they are not quite as flexible as a node system would be. I think it should be possible to get a result similar to your screenshot though (perhaps with an ocean modifier).
– gandalf3
Jul 17 '14 at 2:43
• The Ocean Modifier does seem like the best place to start for this. If you look through the QuickTools Addon, there is some code in there that adds a Sub-D Modifier using Python. You may be able to adapt this to use an Ocean Modifier. github.com/CGCookie/script-bakery/tree/master/scripts/addons I've attached a screen capture that shows the node and modifier setup for my early attempt at making sand. pasteall.org/pic/74081 For adding nodes, you can try starting with this blender.stackexchange.com/questions/14097/… Jul 17 '14 at 11:46

Here's my attempt at simulating your reference image using modifiers:

All it is is a cube with some modifiers:

The ocean modifier generates the base mesh/distortions, and the waves are done with a displace modifier using a wood texture.

There was a project/challenge a while back called "default cubisim" with a lot of great examples of modifier art.

• The file doesn't seem to be here anymore, can you re-upload it somewhere, please? Mar 21 '16 at 6:14

If you are willing to fabricate a mesh by specifying the vertices and faces, it is relatively straightforward to use from_pydata(v,e,f). The hard part is imagining the math to make your vertices and faces accomplish the look you are targeting.

There are many examples available on the internet, but here are two links: triangle donut; bathymetry and a copy of the triangle donut code in case the internet is broken:

import bpy
import math

def triangleDonut(name, nChunks, r1, r2, z1, z2):
verts=[]
faces = []
for i in range(2*nChunks):
v1=i*3
v2 = v1+1
v3 = v1+2
v4 = v1+3
v5 = v1+4
v6 = v1+5
if (i+1 >= 2*nChunks): # connect the end to the start
v4=0
v5=1
v6=2
theta = i*math.pi/nChunks
if 0 == i%2:
z=z1
else:
z=z2
c = math.cos(theta)
s = math.sin(theta)
verts.append( [r1*c, r1*s, 0] )
verts.append( [r2*c, r2*s, z] )
verts.append( [r2*c, r2*s, -z] )
faces.append( [v1, v4, v5, v2] )
faces.append( [v2, v5, v6, v3] )
faces.append( [v3, v6, v4, v1] )

mesh = bpy.data.meshes.new(name);
mesh.from_pydata(verts, [], faces)
mesh.validate(True)
mesh.show_normal_face = True

obj = bpy.data.objects.new(name, mesh)
scn = bpy.context.scene