Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2015 21:21
Show Gist options
  • Save anonymous/780f06c505058788ed4a to your computer and use it in GitHub Desktop.
Save anonymous/780f06c505058788ed4a to your computer and use it in GitHub Desktop.
rounded_rect2_2015_02_17_22-20
import math
from math import sin, cos, pi
def sv_main(w=2.2, h=6.0, radius=0.3):
verts_out = []
faces_out = []
in_sockets = [
['s', 'width', w],
['s', 'height', h],
['s', 'radius', radius]
]
out_sockets = [
['v', 'verts', [verts_out]],
['s', 'faces', [faces_out]]
]
def offset(v2, vlist):
return [[v2[0]+v[0], v2[1]+v[1], v2[2]+v[2]] for v in vlist]
def make_rect(w, h, r):
r = 0 if r <= 0 else r
# define division here.
divs = 15
# this goes clockwise.
num_v = (4*divs)
if r > 0:
radial_verts = []
for v in range(num_v):
theta = v/num_v * 2 * pi
radial_verts.append((sin(theta)*r, cos(theta)*r, 0))
top_left = radial_verts[3*divs:] + [radial_verts[0]]
top_right = radial_verts[:divs+1]
bot_right = radial_verts[divs:(2*divs)+1]
bot_left = radial_verts[2*divs:(3*divs)+1]
local = []
local.extend(offset((r, -r, 0), top_left))
local.extend(offset((w-r, -r, 0), top_right))
local.extend(offset((w-r, -h+r, 0), bot_right))
local.extend(offset((r, -h+r, 0), bot_left))
verts_out.append(local)
fac = [i for i in range(num_v+3)]
faces_out.append([fac])
make_rect(w, h, radius)
return in_sockets, out_sockets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment