From 2649568bb4031eab5a8a412f4834901331b3eb37 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 5 Nov 2017 00:59:13 +0000 Subject: [PATCH] genscad Signed-off-by: Ian Jackson --- .gitignore | 1 + Makefile | 5 ++++ genscad | 61 +++++++++++++++++++++++++++++++++++++++++++++++ moebius-demo.scad | 3 +++ 4 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100755 genscad create mode 100644 moebius-demo.scad diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd6d815 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +moebius-core.scad diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bf04a5e --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ + +all: moebius-core.scad + +moebius-core.scad: genscad + ./$< >$@.tmp && mv -f $@.tmp $@ diff --git a/genscad b/genscad new file mode 100755 index 0000000..26a21e7 --- /dev/null +++ b/genscad @@ -0,0 +1,61 @@ +#!/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 = 40 +nw = 40 + +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() diff --git a/moebius-demo.scad b/moebius-demo.scad new file mode 100644 index 0000000..b25e489 --- /dev/null +++ b/moebius-demo.scad @@ -0,0 +1,3 @@ +include + +MoebiusCore(); -- 2.30.2