import bpy
import random
# this assumes you have copied the vertexAccumulator.py script
# into another text buffer named 'vertexAccumulator'
exec(bpy.data.texts['vertexAccumulator.py'].as_string())
def randomSquareArray(name, nu, nv):
va = VertexAccumulator()
faces = []
for u in range(nu):
for v in range(nv):
z=random.randint(0,2)*0.5
v1 = va.idxFor( [u, v, z] )
v2 = va.idxFor( [u+1, v, z] )
v3 = va.idxFor( [u+1, v+1, z] )
v4 = va.idxFor( [u, v+1, z] )
faces.append( [v1, v2, v3, v4] )
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(va.verts(), [], faces)
mesh.validate(True)
obj = bpy.data.objects.new(name, mesh)
bpy.context.scene.objects.link(obj)
randomSquareArray("grid", 11, 7)
|
Blender python API quick-start
Syntax highlighting by Pygments.