Last active
August 29, 2015 14:00
-
-
Save zeffii/11151647 to your computer and use it in GitHub Desktop.
node script example sin cos face vert poly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sv_main(height=4.0, radius=2.0, num_verts=10): | |
# in boilerplate - make your own sockets | |
in_sockets = [ | |
['s', 'Height', height], | |
['s', 'Radius', radius], | |
['s', 'Num Verts', num_verts] | |
] | |
# import libraries if you need. | |
from math import sin, cos, pi | |
# your code here | |
pi2 = 2*pi | |
# ---- Vertices | |
theta = pi2/num_verts | |
top, bottom = [], [] | |
for i in range(num_verts): | |
delta = theta*i | |
vec = [sin(delta)*radius, cos(delta)*radius, 0] | |
vec2 = [vec[0], vec[1], height] | |
top.append(vec2) | |
bottom.append(vec) | |
prime = [[0,0,0]] | |
prime.extend(bottom) | |
prime.extend(top) | |
prime.append([0,0,height]) | |
verts = prime | |
polys = [] | |
# ---- Polygons | |
polys = [] | |
for i in range(1, num_verts): | |
f = [i, i+1, i+1+num_verts, i+num_verts] | |
polys.append(f) | |
# fill gap (vertical) | |
polys.append([1, num_verts+1, 2*num_verts, num_verts]) | |
# cap bottom, then top | |
for i in range(num_verts-1): | |
polys.append([0, i+1, i+2]) | |
polys.append([1,0,num_verts]) | |
lvert = len(verts)-1 | |
for i in range(1, num_verts): | |
offset = num_verts+i | |
polys.append([lvert, offset, offset+1]) | |
polys.append([2*num_verts, num_verts+1, lvert]) | |
# out boilerplate - set your own sockets packet | |
out_sockets = [ | |
['v', 'Verts', verts], | |
['s', 'Polygons', polys] | |
] | |
return in_sockets, out_sockets | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment