chiark / gitweb /
scad.py: no-oply skip writing empty polyhedrons
[moebius3.git] / meshscad
1 #!/usr/bin/python
2
3 from __future__ import print_function
4
5 import signal
6 signal.signal(signal.SIGINT, signal.SIG_DFL)
7
8 from moebius import *
9 from scad import *
10
11 nomsize = 30;
12 wire = 3.0;
13
14 # number of wires
15 kv = 10
16 kw = 10
17
18 # resolution
19 nv = 40
20 nw = 40
21 ns = 10 # around tube
22
23 nv += -nv % kv
24 nw += -hw % kw
25
26 each_v = nv / kv
27 each_w = nw / kw
28
29 m = Moebius(nv, nw)
30
31 def round_wire(p, vec_surfacenormal, vec_acrosswire, sigma):
32   return (p +
33           wire * (vec_surfacenormal * sin(sigma) +
34                   vec_acrosswire * cos*(sigma)))
35
36 def make_moebius(objname):
37   print('module %s(){' % objname)
38   extents = ScadObject() # wires along extents
39   travers = ScadObject(): # wires along traverses
40   for v in range(0, nv):
41     for w in range(0, nw):
42       for s in range(0, ns):
43         sigmas = [ (s + sx)/ns * tau for sigma in 0,1 ]
44         eq = []
45         if not w % each_w:
46           extents[w].quad([ round_wire(p, norm, trav, sigmas[sx])
47                             for p, norm, extt, trav in m.details(v+a, w)
48                             for sx in 0,1
49                             for a in 0,1 ])
50         if not v % each_v:
51           travers[v].quad([ round_wire(p, norm, extt, sigmas[sx])
52                             for p, norm, extt, trav in m.details(v, w+b)
53                             for sx in 0,1
54                             for b in 0,1 ])
55   for v in range(0, nv):
56     travers[v].writeout_core()
57   for w in range(0, nw):
58     travers[w].writeout_core()
59   print '}'
60
61 make_moebius('MoebiusMesh')
62 print('moebiuscore_nomsize=%s;' % repr(nomsize))