Created
December 29, 2017 17:03
-
-
Save zeffii/f94bbef4438b9ec85af2cf7ebd9b1450 to your computer and use it in GitHub Desktop.
polyhedra.py
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(polyIndex=0): | |
from math import sqrt | |
class PolyMesh(): | |
def __init__(self, vertices, faces): | |
self.vertices = vertices | |
self.faces = faces | |
polyhedra = [] | |
# Tetrahedron | |
polyhedra.append(PolyMesh( | |
[(1, 1, 1), (1, -1, -1), (-1, 1, -1), (-1, -1, 1)], | |
[[0, 3, 1], [0, 2, 3], [1, 3, 2], [0, 1, 2]])) | |
# Cube | |
polyhedra.append(PolyMesh( | |
[(i, j, k) for i in [1, -1] for j in [1, -1] for k in [1, -1]], | |
[[0, 2, 3, 1], [2, 6, 7, 3], [4, 5, 7, 6], | |
[0, 1, 5, 4], [0, 4, 6, 2], [1, 3, 7, 5]])) | |
# Octahedron | |
polyhedra.append(PolyMesh( | |
[(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)], | |
[[0, 3, 5], [0, 5, 2], [2, 5, 1], [1, 5, 3], | |
[0, 4, 3], [0, 2, 4], [1, 4, 2], [1, 3, 4]])) | |
# Dodecahedron | |
polyhedra.append(PolyMesh( | |
[k for row in | |
[[(0, i, j), (j, 0, i), (i, j, 0)] | |
for i in [(sqrt(5)-1)/2, -(sqrt(5)-1)/2] | |
for j in [(sqrt(5)+1)/2, -(sqrt(5)+1)/2]] for k in row] + | |
[(i, j, k) for i in [1, -1] for j in [1, -1] for k in [1, -1]], | |
[[0, 6, 14, 1, 12], [6, 0, 16, 4, 18], [6, 18, 11, 5, 14], | |
[0, 12, 2, 8, 16], [4, 16, 8, 17, 10], [12, 1, 7, 13, 2], | |
[18, 4, 10, 19, 11], [1, 14, 5, 15, 7], [2, 13, 3, 17, 8], | |
[5, 11, 19, 9, 15], [3, 9, 19, 10, 17], [3, 13, 7, 15, 9]])) | |
# Icosahedron | |
polyhedra.append(PolyMesh( | |
[k for row in [[(0, i, j), (j, 0, i), (i, j, 0)] | |
for i in [(sqrt(5)+1)/2, -(sqrt(5)+1)/2] | |
for j in [1, -1]] for k in row], | |
[[0, 1, 2], [0, 2, 3], [0, 3, 8], [0, 8, 4], [0, 4, 1], | |
[1, 4, 6], [1, 6, 5], [1, 5, 2], [2, 5, 7], [2, 7, 3], | |
[3, 7, 10], [3, 10, 8], [8, 10, 11], [8, 11, 4], [4, 11, 6], | |
[9, 5, 6], [9, 6, 11], [9, 11, 10], [9, 10, 7], [9, 7, 5]])) | |
in_sockets = [ | |
['s', 'Polyhedra Index', polyIndex]] | |
poly = polyIndex % len(polyhedra) | |
vertices = polyhedra[poly].vertices | |
faces = polyhedra[poly].faces | |
out_sockets = [ | |
['v', 'Verts', [vertices]], | |
['s', 'Faces', [faces]]] | |
return in_sockets, out_sockets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment