import bpy
import bmesh
import math
def makeTile(name, x0,y0, coords, thickness, mat):
scales = ( 1, 0.8, 0.7)
zs = (0, thickness, thickness)
nu = len(coords)
nv = len(scales)
verts = []
faces = []
for v in range(nv):
for u in range(nu):
x = coords[u][0] * scales[v]
y = coords[u][1] * scales[v]
z = zs[v]
verts.append( [x,y,z] )
if (v+1 < nv):
v0 = u + v*nu
u1 = (u+1)%nu
v1 = u1 + v*nu
v2 = v0+nu
v3 = v1+nu
faces.append( [v0,v1, v3,v2] )
f2 = []
for u in range(nu):
f2.append( u + (nv-1)*nu)
faces.append(f2)
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(verts, [], faces)
#
mesh.materials.append(mat)
#
obj = bpy.data.objects.new(name, mesh)
obj.location=(x0,y0,0)
#
mod = obj.modifiers.new("roundy", "SUBSURF")
mod.levels=2
mod.render_levels=4
#
bm = bmesh.new()
bm.from_mesh(mesh)
cr = bm.edges.layers.crease.active
if cr is None:
cr = bm.edges.layers.crease.new()
for e in bm.edges:
i1 = e.verts[0].index
i2 = e.verts[1].index
if (i1 < nu and i2<nu # outside edge ring
or abs(i2-i1)==nu # inter-ring edges
or math.floor(i2/nu) == nv-1 and math.floor(i1/nu)==nv-1): # next-to-last ring
print( "crease %d,%d" %(e.verts[0].index, e.verts[1].index) )
e[cr] = 1
bm.to_mesh(mesh)
bpy.context.scene.objects.link(obj)
return obj
#
#
thickness = 0.2
mat = bpy.data.materials[0]
makeTile("science", -15.74745679709348,-0.4606170470102633, [
(1.768304689396432,-3.031247732542071),
(2.183217951748338,-0.797683011601334),
(2.3986194510274927,1.825145492744447),
(1.8806814533957539,2.299295081858279),
(-3.113111468761204,-1.879233791115971),
(-3.925333035436239,-2.8069322074180505),
(-3.1231678138802508,-3.2260911215115047),
(1.1437476334384193,-3.284721904235564),
(1.768304689396432,-3.03124773254207),
] , thickness, mat)
makeTile("superstition", 13.980640184908879,2.7826284960035927, [
(0.48352592071769607,-2.827132010369648),
(1.0205046757670893,1.1829375379236327),
(-1.505914511659931,1.538112182229531),
(-1.3148451990803327,-1.6767640040230187),
(0.4835259207176925,-2.827132010369649),
] , thickness, mat)
|
Blender python API quick-start
Syntax highlighting by Pygments.