Nathan's BPY Page
# import libraries import bpy import math import mathutils #set amplitude variable amp = 10 #nested for loop for i in range(0,10): for j in range(0,10): x = amp * i y = amp * j z = (amp * math.sin(i)) + (amp * math.cos(j)) pt = (x,y,z) # create an 'empty' object bpy.ops.object.add(type='EMPTY',location=pt)
Meshes
import bpy #Define vertices, faces, edges verts = [(-1,2,0),(1,2,0),(1,-2,0),(-1,-2,0),(0,2,1),(0,-2,1)] faces = [(0,1,2,3), (1,2,5,4), (0,3,5,4)] edges = [(1,2)] #Define mesh and object mesh = bpy.data.meshes.new("TriangleCube") object = bpy.data.objects.new("TriangleCube", mesh) #Set location and scene of object object.location = bpy.context.scene.cursor_location bpy.context.scene.objects.link(object) #Create mesh mesh.from_pydata(verts,[],faces) mesh.update(calc_edges=True)
import bpy import math # mesh variables verts = [] faces = [] edges = [] # wave variables amp = 1 scale = 5 freqX = 30 freqY = 30 #fill verts for i in range (0, freqX): for j in range(0,freqY): x = scale * i y = scale * j z = (scale*math.cos(i*amp))+(scale*math.sin(j*amp)) vert = (x,y,z) verts.append(vert) #fill faces count = 0 for i in range (0, freqY*(freqX-1)): if count < freqY-1: A = i B = i+1 C = (i+freqY)+1 D = (i+freqY) face = (A,B,C,D) faces.append(face) count = count + 1 else: count = 0 #create mesh and object mesh = bpy.data.meshes.new("wave") object = bpy.data.objects.new("wave",mesh) #set mesh location object.location = bpy.context.scene.cursor_location bpy.context.scene.objects.link(object) #create mesh from python data mesh.from_pydata(verts,edges,faces) mesh.update(calc_edges=True)
import bpy import math import random # mesh arrays verts = [] faces = [] edges = [] # wave variables freq = 1 amp = .5 scale = 1 freqX = 20 freqY = 20 #fill verts array for i in range (0, freqX): for j in range(0,freqY): x = scale * i y = scale * j z = (i*random.random())*amp #scale*((amp*math.cos(i*freq))+(amp*math.sin(j*freq))) vert = (x,y,z) verts.append(vert) #fill faces array count = 0 for i in range (0, freqY*(freqX-1)): if count < freqY-1: A = i B = i+1 C = (i+freqY)+1 D = (i+freqY) face = (A,B,C,D) faces.append(face) count = count + 1 else: count = 0 #create mesh and object mesh = bpy.data.meshes.new("wave") object = bpy.data.objects.new("wave",mesh) #set mesh location object.location = bpy.context.scene.cursor_location bpy.context.scene.objects.link(object) #create mesh from python data mesh.from_pydata(verts,edges,faces) mesh.update(calc_edges=True)