#!/usr/bin/python from __future__ import print_function import signal signal.signal(signal.SIGINT, signal.SIG_DFL) from moebius import * nomsize = 20 thick = 2.5 nv = 80 nw = 80 m = Moebius(nv, nw) stl_points = [] stl_point_indices = {} stl_triangles = [] def stl_writeout(): print('module MoebiusCore(){ scale(%s) polyhedron(points=[' % nomsize) for p in stl_points: print(p, ',') print('],faces=[') for t in stl_triangles: print(repr(t), ',') print('],convexity=10); }') def stl_point(p): l = list(p) s = repr(l) try: ix = stl_point_indices[s] except KeyError: ix = len(stl_points) stl_points.append(s) stl_point_indices[s] = ix return ix def stl_triangle(a,b,c): ''' a b c are clockwise from inside ''' stl_triangles.append([ stl_point(p) for p in (a,b,c) ]) def stl_quad(cnrs): ''' cnrs[0] [1] [3] [2] are clockwise from inside ''' stl_triangle(cnrs[0], cnrs[1], cnrs[3]) stl_triangle(cnrs[0], cnrs[3], cnrs[2]) relthick = thick/(nomsize*2) for v in range(0, nv): for w in range(0, nw): stl_quad([ m.point_offset(v+a, w+b, relthick) for a in (0, 1) for b in (0, 1) ]) stl_quad([ m.point_offset(v+a, w+b, -relthick) for a in (1, 0) for b in (1, 0) ]) stl_writeout()