added last part

This commit is contained in:
josch 2013-07-17 19:45:56 +02:00
parent b326f8f344
commit a4dcde887a

View file

@ -87,7 +87,7 @@ parts = [
("99301", "Slope Brick 33 3 x 3 Double Concave"), ("99301", "Slope Brick 33 3 x 3 Double Concave"),
("3675", "Slope Brick 33 3 x 3 Double Convex"), ("3675", "Slope Brick 33 3 x 3 Double Convex"),
("3297", "Slope Brick 33 3 x 4"), ("3297", "Slope Brick 33 3 x 4"),
("3048", "Slope Brick 45 2 x 1 Triple"), ("3048", "Slope Brick 45 1 x 2 Triple"),
("3040b", "Slope Brick 45 2 x 1"), ("3040b", "Slope Brick 45 2 x 1"),
("3044b", "Slope Brick 45 2 x 1 Double"), ("3044b", "Slope Brick 45 2 x 1 Double"),
("3665", "Slope Brick 45 2 x 1 Inverted"), ("3665", "Slope Brick 45 2 x 1 Inverted"),
@ -131,83 +131,153 @@ def drawstud(studsx, studsz, x, z, lines, triangles, quads):
lines.append(((p1[0], -4, p1[1]), (p2[0], -4, p2[1]))) lines.append(((p1[0], -4, p1[1]), (p2[0], -4, p2[1])))
lines.append(((p1[0], 0, p1[1]), (p2[0], 0, p2[1]))) lines.append(((p1[0], 0, p1[1]), (p2[0], 0, p2[1])))
def render(): def render_part(part):
for part in parts: partid, parttext = part[:2]
partid, parttext = part[:2] m = re.match(r"(?P<type>[A-Za-z0-9 ]+?) (?P<studsz>\d+)"+
m = re.match(r"(?P<type>[A-Za-z0-9 ]+?) (?P<studsz>\d+)"+ r" x (?P<studsx>\d+)(?: x (?P<height>\d+(?:/\d+)?))?"+
r" x (?P<studsx>\d+)(?: x (?P<height>\d+(?:/\d+)?))?"+ r"(?: (?P<corner>Corner)| "+
r"(?: (?P<corner>Corner)| "+ r"(?P<slope>(?:Double|Triple|Inverted|Concave|Convex| |/)+))?",
r"(?P<slope>(?:Double|Triple|Inverted|Concave|Convex| |/)+))?", parttext)
parttext) # sanity checks
# sanity checks if m.group('type') not in ['Brick', 'Plate', 'Slope Brick 18',
if m.group('type') not in ['Brick', 'Plate', 'Slope Brick 18', 'Slope Brick 31', 'Slope Brick 33', 'Slope Brick 45',
'Slope Brick 31', 'Slope Brick 33', 'Slope Brick 45', 'Slope Brick 65', 'Slope Brick 75']:
'Slope Brick 65', 'Slope Brick 75']: print "not supported part type: %s"%m.group('type')
print "not supported part type: %s"%m.group('type') exit(1)
exit(1) if m.group('type') == 'Plate' and m.group('height'):
if m.group('type') == 'Plate' and m.group('height'): print "plates can't have a height"
print "plates can't have a height" exit(1)
exit(1) if m.group('height') and m.group('corner'):
if m.group('height') and m.group('corner'): print "corners can't have a height"
print "corners can't have a height" exit(1)
exit(1) if m.group('corner') and (m.group('studsx') != m.group('studsz')):
if m.group('corner') and (m.group('studsx') != m.group('studsz')): print "corners must be squares"
print "corners must be squares" exit(1)
exit(1) lines = list()
lines = list() triangles = list()
triangles = list() quads = list()
quads = list() studsz = int(m.group('studsz'))
studsz = int(m.group('studsz')) studsx = int(m.group('studsx'))
studsx = int(m.group('studsx')) if m.group('type') in ['Brick', 'Slope Brick 18', 'Slope Brick 31',
if m.group('type') in ['Brick', 'Slope Brick 18', 'Slope Brick 31', 'Slope Brick 33', 'Slope Brick 45', 'Slope Brick 65',
'Slope Brick 33', 'Slope Brick 45', 'Slope Brick 65', 'Slope Brick 75']:
'Slope Brick 75']: if m.group('height'):
if m.group('height'): if m.group('height') == '2/3':
if m.group('height') == '2/3': height = 2
height = 2
else:
height = int(m.group('height'))*3
else: else:
height = 3 height = int(m.group('height'))*3
else: else:
height = 1 height = 3
if m.group('type') in ['Brick', 'Plate']: else:
# draw studs height = 1
for z in range(studsz): # convert plate height to LDraw units
for x in range(studsx): height *= 8
if not m.group('corner') or z >= studsz/2 or x >= studsx/2: if m.group('type') in ['Brick', 'Plate']:
drawstud(studsx, studsz, x, z, lines, triangles, quads) # draw studs
for z in range(studsz):
for x in range(studsx):
if not m.group('corner') or z >= studsz/2 or x >= studsx/2:
drawstud(studsx, studsz, x, z, lines, triangles, quads)
# create top, bottom, inner and outer rectangles
# in case of a corner, draw an L otherwise draw a square
if m.group('corner'):
coords = [(0,0),(1,0),(1,-1),(-1,-1),(-1,1),(0,1)]
else:
coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
outertopcoords = [(studsx*10*x, 0, studsz*10*z) for x,z in coords]
outerbottomcoords = [(x, height, z) for x,y,z in outertopcoords]
# walls are 4 LDU thick, use sign() in case x or y are zero
innertopcoords = [(studsx*10*x-sign(x)*4, 4, studsz*10*z-sign(z)*4) for x,z in coords]
innerbottomcoords = [(x, height, z) for x,y,z in innertopcoords]
# write outer top plate and lines
# in case of a corner draw two trapezoids, otherwise draw a rectangle
if m.group('corner'):
quads.append(outertopcoords[:4])
quads.append(outertopcoords[3:]+outertopcoords[:1])
else:
quads.append(outertopcoords)
for p1, p2 in wrap(outertopcoords):
lines.append((p1, p2))
# outer sides and lines
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# write inner top plate and lines
# in case of a corner draw two trapezoids, otherwise draw a rectangle
if m.group('corner'):
quads.append(innertopcoords[:4])
quads.append(innertopcoords[3:]+innertopcoords[:1])
else:
quads.append(innertopcoords)
for p1, p2 in wrap(innertopcoords):
lines.append((p1, p2))
# inner sides and lines
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# write out bottom with trapezoids and lines
for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
quads.append((p1, p2, p4, p3))
lines.append((p1, p2))
lines.append((p3, p4))
elif m.group('type') == 'Slope Brick 31':
# create top, bottom, inner and outer rectangles
coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
outertopcoords = [(studsx*10*x, 0 if z == 1 else height-4, studsz*10*z) for x,z in coords]
outerbottomcoords = [(x, height, z) for x,y,z in outertopcoords]
# walls are 4 LDU thick, use sign() in case x or y are zero
innertopcoords = [(studsx*10*x-sign(x)*4, height-4, studsz*10*z-sign(z)*4) for x,z in coords]
innerbottomcoords = [(x, height, z) for x,y,z in innertopcoords]
# write outer top plate and lines
quads.append(outertopcoords)
for p1, p2 in wrap(outertopcoords):
lines.append((p1, p2))
# outer sides and lines
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# write inner top plate and lines
quads.append(innertopcoords)
for p1, p2 in wrap(innertopcoords):
lines.append((p1, p2))
# inner sides and lines
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# write out bottom with trapezoids and lines
for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
quads.append((p1, p2, p4, p3))
lines.append((p1, p2))
lines.append((p3, p4))
elif m.group('type') in ['Slope Brick 18', 'Slope Brick 33',
'Slope Brick 45', 'Slope Brick 65', 'Slope Brick 75']:
# draw studs (draw an L if double concave)
coordsL = [(0,0),(0,-1),(-1,-1),(-1,1),(1,1),(1,0)]
coords = [(-1,-1),(-1,1),(1,1),(1,-1)]
if 'Double' == m.group('slope'):
# create top, bottom, inner and outer rectangles # create top, bottom, inner and outer rectangles
# in case of a corner, draw an L otherwise draw a square coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
if m.group('corner'): outertopcoords = [(studsx*10*x, 24-4, studsz*10*z) for x,z in coords]
coords = [(0,0),(1,0),(1,-1),(-1,-1),(-1,1),(0,1)] outerbottomcoords = [(x, 24, z) for x,y,z in outertopcoords]
else:
coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
outertopcoords = [(studsx*10*x, 0, studsz*10*z) for x,z in coords]
outerbottomcoords = [(x, height*8, z) for x,y,z in outertopcoords]
# walls are 4 LDU thick, use sign() in case x or y are zero # walls are 4 LDU thick, use sign() in case x or y are zero
innertopcoords = [(studsx*10*x-sign(x)*4, 4, studsz*10*z-sign(z)*4) for x,z in coords] innertopcoords = [(studsx*10*x-sign(x)*4, 24-4, studsz*10*z-sign(z)*4) for x,z in coords]
innerbottomcoords = [(x, height*8, z) for x,y,z in innertopcoords] innerbottomcoords = [(x, 24, z) for x,y,z in innertopcoords]
# write outer top plate and lines if m.group('type') == 'Slope Brick 45':
# in case of a corner draw two trapezoids, otherwise draw a rectangle ridge = [(studsx*10,0,0),(-studsx*10,0,0)]
if m.group('corner'): elif m.group('type') == 'Slope Brick 33':
quads.append(outertopcoords[:4]) ridge = [(studsx*10,24-14,0),(-studsx*10,24-14,0)]
quads.append(outertopcoords[3:]+outertopcoords[:1])
else: else:
quads.append(outertopcoords) print "unsupported slope type for double"
for p1, p2 in wrap(outertopcoords): exit(1)
lines.append((p1, p2)) # write outer top lines
lines.append(outertopcoords[1:3])
lines.append(outertopcoords[:1]+outertopcoords[-1:])
# outer sides and lines # outer sides and lines
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)): for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)):
quads.append((p1,p2,p4,p3)) quads.append((p1,p2,p4,p3))
lines.append((p1,p3)) lines.append((p1,p3))
# write inner top plate and lines # write inner top plate and lines
# in case of a corner draw two trapezoids, otherwise draw a rectangle quads.append(innertopcoords)
if m.group('corner'):
quads.append(innertopcoords[:4])
quads.append(innertopcoords[3:]+innertopcoords[:1])
else:
quads.append(innertopcoords)
for p1, p2 in wrap(innertopcoords): for p1, p2 in wrap(innertopcoords):
lines.append((p1, p2)) lines.append((p1, p2))
# inner sides and lines # inner sides and lines
@ -219,213 +289,289 @@ def render():
quads.append((p1, p2, p4, p3)) quads.append((p1, p2, p4, p3))
lines.append((p1, p2)) lines.append((p1, p2))
lines.append((p3, p4)) lines.append((p3, p4))
elif m.group('type') in ['Slope Brick 18', 'Slope Brick 31', # draw gables
'Slope Brick 33', 'Slope Brick 45', 'Slope Brick 65', triangles.append(ridge[:1]+outertopcoords[:2])
'Slope Brick 75']: triangles.append(ridge[-1:]+outertopcoords[2:])
# draw studs (draw an L if double concave) # draw slopes
coordsL = [(0,0),(0,-1),(-1,-1),(-1,1),(1,1),(1,0)] quads.append(ridge+outertopcoords[1:3])
coords = [(-1,-1),(-1,1),(1,1),(1,-1)] quads.append(ridge+outertopcoords[-1:]+outertopcoords[:1])
if m.group('type') != 'Slope Brick 31' \ # draw lines for ridge and rakes
and 'Double' != m.group('slope') \ lines.append(ridge)
and 'Triple' != m.group('slope') \ lines.append(ridge[:1]+outertopcoords[:1])
and 'Double Concave / Double Convex' != m.group('slope'): lines.append(ridge[:1]+outertopcoords[1:2])
if m.group('slope') in ['Inverted', 'Inverted Double Convex']: lines.append(ridge[-1:]+outertopcoords[-1:])
for z in range(studsz): lines.append(ridge[-1:]+outertopcoords[2:3])
for x in range(studsx): elif 'Triple' == m.group('slope'):
drawstud(studsx, studsz, x, z, lines, triangles, quads) # create top, bottom, inner and outer rectangles
elif m.group('slope') == 'Double Convex': coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
drawstud(studsx, studsz, studsx-1, 0, lines, triangles, quads) outertopcoords = [(studsx*10*x, 24-4, studsz*10*z) for x,z in coords]
elif m.group('slope') == 'Double Concave': outerbottomcoords = [(x, 24, z) for x,y,z in outertopcoords]
for z in range(studsz): # walls are 4 LDU thick, use sign() in case x or y are zero
for x in range(studsx): innertopcoords = [(studsx*10*x-sign(x)*4, 24-4, studsz*10*z-sign(z)*4) for x,z in coords]
if z == 0 or x == studsx-1: innerbottomcoords = [(x, 24, z) for x,y,z in innertopcoords]
drawstud(studsx, studsz, x, z, lines, triangles, quads) tip = (0,0,studsz*10)
else: # write outer top lines
for x in range(studsx): for p1, p2 in wrap(outertopcoords)[:-1]:
drawstud(studsx, studsz, x, 0, lines, triangles, quads) lines.append((p1, p2))
# create top, bottom, inner and outer rectangles # outer sides and lines
if m.group('slope') == 'Inverted Double Convex': for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)):
outertopcoords = [(studsx*10*x, 0, studsz*10*z) for x,z in coords] quads.append((p1,p2,p4,p3))
outertopcoords2 = [((x-studsx+1)*10, 0, (z+studsz-1)*10) for x,z in coords] # small lines.append((p1,p3))
outerbottomcoords = [((x-studsx+1)*10, height*8, (z+studsz-1)*10) for x,z in coords] # write inner top plate and lines
innertopcoords = [(6*x-(studsx-1)*10, 4, z*6+(studsz-1)*10) for x,z in coords] quads.append(innertopcoords)
innerbottomcoords = [(6*x-(studsx-1)*10, height*8, z*6+(studsz-1)*10) for x,z in coords] for p1, p2 in wrap(innertopcoords):
noseup1 = outertopcoords[:1]+outertopcoords[-1:] lines.append((p1, p2))
nosedown1 = [(x,4,z) for x,y,z in noseup1] # inner sides and lines
noseup2 = outertopcoords[-2:-1]+outertopcoords[-1:] for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
nosedown2 = [(x,4,z) for x,y,z in noseup2] quads.append((p1,p2,p4,p3))
elif m.group('slope') == 'Double Convex': lines.append((p1,p3))
outertopcoords = [((x-studsx+1)*10, 0, (z+studsz-1)*10) for x,z in coords] # write out bottom with trapezoids and lines
outerbottomcoords = [(studsx*10*x, height*8, studsz*10*z) for x,z in coords] # big for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
outerbottomcoords2 = [((x-studsx+1)*10, height*8, (z+studsz-1)*10) for x,z in coords] # small quads.append((p1, p2, p4, p3))
innerbottomcoords = [(studsx*10*x-sign(x)*4, height*8, studsz*10*z-sign(z)*4) for x,z in coords] lines.append((p1, p2))
innertopcoords = [(6*x-(studsx-1)*10, 4, z*6+(studsz-1)*10) for x,z in coords] lines.append((p3, p4))
nosedown1 = outerbottomcoords[:1]+outerbottomcoords[-1:] # write out slopes and lines
noseup1 = [(x,height*8-4,z) for x,y,z in nosedown1] for p1, p2 in wrap(outertopcoords):
nosedown2 = outerbottomcoords[-2:-1]+outerbottomcoords[-1:] triangles.append([p1,p2,tip])
noseup2 = [(x,height*8-4,z) for x,y,z in nosedown2] lines.append((p1,tip))
elif m.group('slope') == 'Double Concave': elif 'Double Concave / Double Convex' == m.group('slope'):
outertopcoords = [(studsx*10*x+(abs(x)-1)*(10*studsx-20), 0, studsz*10*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL] # create top, bottom, inner and outer rectangles
outerbottomcoords = [(studsx*10*x, height*8, studsz*10*z) for x,z in coords] # big coords = [(1,1),(1,-1),(-1,-1),(-1,1)]
outerbottomcoords2 = [(studsx*10*x+(abs(x)-1)*(10*studsx-20), height*8, studsz*10*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL] # small outertopcoords = [(studsx*10*x, 24-4, studsz*10*z) for x,z in coords]
innertopcoords = [((studsx*10-4)*x+(abs(x)-1)*(10*studsx-20), 4, (studsz*10-4)*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL] outerbottomcoords = [(x, 24, z) for x,y,z in outertopcoords]
innerbottomcoords = [((studsx*10-4)*x, height*8, (studsz*10-4)*z) for x,z in coords] # walls are 4 LDU thick, use sign() in case x or y are zero
tip = [(studsx*10,height*8,-studsz*10), (studsx*10,height*8-4,-studsz*10)] innertopcoords = [(studsx*10*x-sign(x)*4, 24-4, studsz*10*z-sign(z)*4) for x,z in coords]
else: innerbottomcoords = [(x, 24, z) for x,y,z in innertopcoords]
outertopcoords = [(studsx*10*x, 0, (z+studsz-1)*10) for x,z in coords] if m.group('type') != 'Slope Brick 45':
outerbottomcoords2 = [(studsx*10*x, height*8, (z+studsz-1)*10) for x,z in coords] # small print "unsupported slope type for double concave / double convex"
outerbottomcoords = [(studsx*10*x, height*8, studsz*10*z) for x,z in coords] # big exit(1)
innertopcoords = [((studsx*10-4)*x, 4, z*6+(studsz-1)*10) for x,z in coords] ridge1 = [(0,0,0),(-studsx*10,0,0)]
innerbottomcoords = [(studsx*10*x-sign(x)*4, height*8, studsz*10*z-sign(z)*4) for x,z in coords] ridge2 = [(0,0,studsz*10),(0,0,0)]
nosedown = outerbottomcoords[:1]+outerbottomcoords[-1:] # write outer top lines (eaves)
noseup = [(x,height*8-4,z) for x,y,z in nosedown] lines.append(outertopcoords[1:3])
# invert all the coordinates along the y axis lines.append(outertopcoords[:2])
if m.group('slope') == 'Inverted': # outer sides and lines
outertopcoords, outertopcoords2, outerbottomcoords = ( for (p1, p2), (p3, p4) in zip(wrap(outertopcoords), wrap(outerbottomcoords)):
[(x,0,z) for x,y,z in outerbottomcoords], quads.append((p1,p2,p4,p3))
[(x,0,z) for x,y,z in outerbottomcoords2], lines.append((p1,p3))
[(x,height*8,z) for x,y,z in outertopcoords]) # write inner top plate and lines
innertopcoords, innerbottomcoords = ( quads.append(innertopcoords)
[(x,4,z) for x,y,z in innertopcoords], for p1, p2 in wrap(innertopcoords):
[(x,height*8,z) for x,y,z in innertopcoords]) lines.append((p1, p2))
noseup = outertopcoords[:1]+outertopcoords[-1:] # inner sides and lines
nosedown = [(x,4,z) for x,y,z in noseup] for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
# write outer top plate and lines quads.append((p1,p2,p4,p3))
if m.group('slope') == 'Double Concave': lines.append((p1,p3))
quads.append(outertopcoords[:4]) # write out bottom with trapezoids and lines
quads.append(outertopcoords[3:]+outertopcoords[:1]) for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
else: quads.append((p1, p2, p4, p3))
quads.append(outertopcoords) lines.append((p1, p2))
for p1, p2 in wrap(outertopcoords): lines.append((p3, p4))
lines.append((p1, p2)) # draw gables
# outer sides and lines triangles.append(ridge1[-1:]+outertopcoords[2:])
if m.group('slope') == 'Inverted Double Convex': triangles.append(ridge2[:1]+outertopcoords[:1]+outertopcoords[-1:])
for (p1, p2), (p3, p4) in zip(wrap(outerbottomcoords)[:2], wrap(outertopcoords2)[:2]): # draw slopes
quads.append((p1,p2,p4,p3)) quads.append(ridge1+outertopcoords[1:3])
for (p1, p2), (p3, p4) in zip(wrap(outerbottomcoords)[1:2], wrap(outertopcoords2)[1:2]): quads.append(ridge2+outertopcoords[:2])
lines.append((p1,p3)) triangles.append(ridge1+outertopcoords[-1:])
elif m.group('slope') == 'Double Convex': triangles.append(ridge2+outertopcoords[-1:])
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[:2], wrap(outerbottomcoords2)[:2]): # draw ridges
quads.append((p1,p2,p4,p3)) lines.append(ridge1)
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:2], wrap(outerbottomcoords2)[1:2]): lines.append(ridge2)
lines.append((p1,p3)) # draw rakes
elif m.group('slope') == 'Double Concave': lines.append(ridge1[-1:]+outertopcoords[2:3])
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:5], wrap(outerbottomcoords2)[1:5]): lines.append(ridge1[-1:]+outertopcoords[-1:])
quads.append((p1,p2,p4,p3)) lines.append(ridge2[:1]+outertopcoords[:1])
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[2:5], wrap(outerbottomcoords2)[2:5]): lines.append(ridge2[:1]+outertopcoords[-1:])
lines.append((p1,p3)) # draw valley and hip
else: lines.append(((0,0,0),outertopcoords[-1]))
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[:3], wrap(outerbottomcoords2)[:3]): lines.append(((0,0,0),outertopcoords[1]))
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:3], wrap(outerbottomcoords2)[1:3]):
lines.append((p1,p3))
# draw nose
if m.group('slope') in ['Inverted Double Convex', 'Double Convex']:
quads.append(noseup1+[nosedown1[1]]+[nosedown1[0]])
quads.append(noseup2+[nosedown2[1]]+[nosedown2[0]])
elif m.group('slope') != 'Double Concave':
quads.append(noseup+[nosedown[1]]+[nosedown[0]])
# draw sides and lines to the nose
if m.group('slope') == 'Inverted Double Convex':
quads.append(outerbottomcoords[-2:-1]+outertopcoords2[-2:-1]+nosedown2[:1]+noseup2[:1])
quads.append(outerbottomcoords[:1]+outertopcoords2[:1]+nosedown1[:1]+noseup1[:1])
elif m.group('slope') == 'Double Convex':
quads.append(outertopcoords[-2:-1]+outerbottomcoords2[-2:-1]+noseup2[:1]+nosedown2[:1])
quads.append(outertopcoords[:1]+outerbottomcoords2[:1]+noseup1[:1]+nosedown1[:1])
elif m.group('slope') == 'Double Concave':
quads.append(outertopcoords[-1:]+outerbottomcoords2[-1:]+tip)
quads.append(outertopcoords[1:2]+outerbottomcoords2[1:2]+tip)
else:
quads.append(outertopcoords[-1:]+outerbottomcoords2[-1:]+nosedown[-1:]+noseup[-1:])
quads.append(outertopcoords[:1]+outerbottomcoords2[:1]+nosedown[:1]+noseup[:1])
if m.group('slope') in ['Inverted Double Convex', 'Double Convex']:
lines.append(noseup1[:1]+nosedown1[:1])
lines.append(noseup1[-1:]+nosedown1[-1:])
lines.append(noseup2[:1]+nosedown2[:1])
lines.append(noseup2[-1:]+nosedown2[-1:])
elif m.group('slope') == 'Double Concave':
lines.append(tip)
else:
lines.append(noseup[:1]+nosedown[:1])
lines.append(noseup[-1:]+nosedown[-1:])
# draw slope and lines around it
if m.group('slope') == 'Inverted':
quads.append(outerbottomcoords[-1:]+outerbottomcoords[:1]+[nosedown[1]]+[nosedown[0]])
lines.append(nosedown[:1]+outerbottomcoords[:1])
lines.append(nosedown[-1:]+outerbottomcoords[-1:])
lines.append(nosedown[:1]+nosedown[-1:])
elif m.group('slope') == 'Inverted Double Convex':
quads.append(outerbottomcoords[-1:]+outerbottomcoords[:1]+[nosedown1[1]]+[nosedown1[0]])
quads.append(outerbottomcoords[2:3]+outerbottomcoords[3:4]+[nosedown2[1]]+[nosedown2[0]])
lines.append(nosedown1[:1]+outerbottomcoords[:1])
lines.append(nosedown1[-1:]+outerbottomcoords[-1:])
lines.append(nosedown2[-2:-1]+outerbottomcoords[-2:-1])
lines.append(nosedown1[:1]+nosedown1[-1:])
lines.append(nosedown2[:1]+nosedown2[-1:])
elif m.group('slope') == 'Double Convex':
quads.append(outertopcoords[-1:]+outertopcoords[:1]+[noseup1[1]]+[noseup1[0]])
quads.append(outertopcoords[2:3]+outertopcoords[3:4]+[noseup2[1]]+[noseup2[0]])
lines.append(noseup1[:1]+outertopcoords[:1])
lines.append(noseup1[-1:]+outertopcoords[-1:])
lines.append(noseup2[-2:-1]+outertopcoords[-2:-1])
lines.append(noseup1[:1]+noseup1[-1:])
lines.append(noseup2[:1]+noseup2[-1:])
elif m.group('slope') == 'Double Concave':
triangles.append(outertopcoords[-1:]+outertopcoords[:1]+[tip[1]])
triangles.append(outertopcoords[:1]+outertopcoords[1:2]+[tip[1]])
lines.append(outertopcoords[-1:]+[tip[1]])
lines.append(outertopcoords[:1]+[tip[1]])
lines.append(outertopcoords[1:2]+[tip[1]])
else:
quads.append(outertopcoords[-1:]+outertopcoords[:1]+[noseup[1]]+[noseup[0]])
lines.append(noseup[:1]+outertopcoords[:1])
lines.append(noseup[-1:]+outertopcoords[-1:])
lines.append(noseup[:1]+noseup[-1:])
# write inner top plate and lines
if m.group('slope') == 'Double Concave':
quads.append(innertopcoords[:4])
quads.append(innertopcoords[3:]+innertopcoords[:1])
else:
quads.append(innertopcoords)
for p1, p2 in wrap(innertopcoords):
lines.append((p1, p2))
# inner sides and lines
if m.group('slope') == 'Double Concave':
# the quadrilateral sides
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords)[1:5],
wrap(innerbottomcoords)[-1:]+wrap(innerbottomcoords)[:4]):
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords)[2:5], wrap(innerbottomcoords)[:4]):
lines.append((p1,p3))
# the slopes
triangles.append(innertopcoords[-1:]+innertopcoords[:1]+innerbottomcoords[-1:])
triangles.append(innertopcoords[:1]+innertopcoords[1:2]+innerbottomcoords[-1:])
lines.append(innertopcoords[-1:]+innerbottomcoords[-1:])
lines.append(innertopcoords[:1]+innerbottomcoords[-1:])
lines.append(innertopcoords[1:2]+innerbottomcoords[-1:])
else:
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# write out bottom with trapezoids and lines
for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
quads.append((p1, p2, p4, p3))
lines.append((p1, p2))
lines.append((p3, p4))
else: else:
print "not supported part type: %s"%m.group('type') if m.group('slope') in ['Inverted', 'Inverted Double Convex']:
exit(1) for z in range(studsz):
outfile = open("parts/%s.dat"%partid, 'w') for x in range(studsx):
outfile.write("0 %s\n"%parttext) drawstud(studsx, studsz, x, z, lines, triangles, quads)
for (x1, y1, z1), (x2, y2, z2) in lines: elif m.group('slope') == 'Double Convex':
outfile.write("2 24 %f %f %f %f %f %f\n"%(x1, y1, z1, x2, y2, z2)) drawstud(studsx, studsz, studsx-1, 0, lines, triangles, quads)
for (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) in triangles: elif m.group('slope') == 'Double Concave':
outfile.write("3 16 %f %f %f %f %f %f %f %f %f\n"%( for z in range(studsz):
x1, y1, z1, x2, y2, z2, x3, y3, z3)) for x in range(studsx):
for (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) in quads: if z == 0 or x == studsx-1:
outfile.write("4 16 %f %f %f %f %f %f %f %f %f %f %f %f\n"%( drawstud(studsx, studsz, x, z, lines, triangles, quads)
x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)) else:
outfile.close() for x in range(studsx):
drawstud(studsx, studsz, x, 0, lines, triangles, quads)
# create top, bottom, inner and outer rectangles
if m.group('slope') in ['Double Convex', 'Inverted Double Convex']:
outertopcoords = [((x-studsx+1)*10, 0, (z+studsz-1)*10) for x,z in coords]
outerbottomcoords = [(studsx*10*x, height, studsz*10*z) for x,z in coords] # big
helpercoords = [((x-studsx+1)*10, height, (z+studsz-1)*10) for x,z in coords] # small
innerbottomcoords = [(studsx*10*x-sign(x)*4, height, studsz*10*z-sign(z)*4) for x,z in coords]
innertopcoords = [(6*x-(studsx-1)*10, 4, z*6+(studsz-1)*10) for x,z in coords]
nosedown1 = outerbottomcoords[:1]+outerbottomcoords[-1:]
noseup1 = [(x,height-4,z) for x,y,z in nosedown1]
nosedown2 = outerbottomcoords[-2:-1]+outerbottomcoords[-1:]
noseup2 = [(x,height-4,z) for x,y,z in nosedown2]
# if an inverted piece is requested, switch coordinates around
if m.group('slope') == 'Inverted Double Convex':
outerbottomcoords, helpercoords, outertopcoords = (
[(x,0,z) for x,y,z in outerbottomcoords],
[(x,0,z) for x,y,z in helpercoords],
[(x,height,z) for x,y,z in outertopcoords])
innertopcoords, innerbottomcoords = (
[(x,4,z) for x,y,z in innertopcoords],
[(x,height,z) for x,y,z in innertopcoords])
noseup1, nosedown1 = [(x,0,z) for x,y,z in nosedown1], [(x,4,z) for x,y,z in noseup1]
noseup2, nosedown2 = [(x,0,z) for x,y,z in nosedown2], [(x,4,z) for x,y,z in noseup2]
elif m.group('slope') == 'Double Concave':
outertopcoords = [(studsx*10*x+(abs(x)-1)*(10*studsx-20), 0, studsz*10*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL]
outerbottomcoords = [(studsx*10*x, height, studsz*10*z) for x,z in coords] # big
helpercoords = [(studsx*10*x+(abs(x)-1)*(10*studsx-20), height, studsz*10*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL] # small
innertopcoords = [((studsx*10-4)*x+(abs(x)-1)*(10*studsx-20), 4, (studsz*10-4)*z+(1-abs(z))*(10*studsz-20)) for x,z in coordsL]
innerbottomcoords = [((studsx*10-4)*x, height, (studsz*10-4)*z) for x,z in coords]
tip = [(studsx*10,height,-studsz*10), (studsx*10,height-4,-studsz*10)]
# there is somehow no inverted double concave piece
else:
outertopcoords = [(studsx*10*x, 0, (z+studsz-1)*10) for x,z in coords]
helpercoords = [(studsx*10*x, height, (z+studsz-1)*10) for x,z in coords] # small
outerbottomcoords = [(studsx*10*x, height, studsz*10*z) for x,z in coords] # big
innertopcoords = [((studsx*10-4)*x, 4, z*6+(studsz-1)*10) for x,z in coords]
innerbottomcoords = [(studsx*10*x-sign(x)*4, height, studsz*10*z-sign(z)*4) for x,z in coords]
nosedown = outerbottomcoords[:1]+outerbottomcoords[-1:]
noseup = [(x,height-4,z) for x,y,z in nosedown]
# if an inverted piece is requested, switch coordinates around
if m.group('slope') == 'Inverted':
outerbottomcoords, helpercoords, outertopcoords = (
[(x,0,z) for x,y,z in outerbottomcoords],
[(x,0,z) for x,y,z in helpercoords],
[(x,height,z) for x,y,z in outertopcoords])
innertopcoords, innerbottomcoords = (
[(x,4,z) for x,y,z in innertopcoords],
[(x,height,z) for x,y,z in innertopcoords])
noseup, nosedown = [(x,0,z) for x,y,z in nosedown], [(x,4,z) for x,y,z in noseup]
# outer sides and lines
if m.group('slope') in ['Double Convex', 'Inverted Double Convex']:
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[:2], wrap(helpercoords)[:2]):
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:2], wrap(helpercoords)[1:2]):
lines.append((p1,p3))
elif m.group('slope') == 'Double Concave':
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:5], wrap(helpercoords)[1:5]):
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[2:5], wrap(helpercoords)[2:5]):
lines.append((p1,p3))
else:
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[:3], wrap(helpercoords)[:3]):
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(outertopcoords)[1:3], wrap(helpercoords)[1:3]):
lines.append((p1,p3))
# draw nose
if m.group('slope') in ['Inverted Double Convex', 'Double Convex']:
quads.append(noseup1+[nosedown1[1]]+[nosedown1[0]])
quads.append(noseup2+[nosedown2[1]]+[nosedown2[0]])
elif m.group('slope') != 'Double Concave':
quads.append(noseup+[nosedown[1]]+[nosedown[0]])
# draw sides and lines to the nose
if m.group('slope') in ['Double Convex', 'Inverted Double Convex']:
quads.append(outertopcoords[-2:-1]+helpercoords[-2:-1]+noseup2[:1]+nosedown2[:1])
quads.append(outertopcoords[:1]+helpercoords[:1]+noseup1[:1]+nosedown1[:1])
elif m.group('slope') == 'Double Concave':
quads.append(outertopcoords[-1:]+helpercoords[-1:]+tip)
quads.append(outertopcoords[1:2]+helpercoords[1:2]+tip)
else:
quads.append(outertopcoords[-1:]+helpercoords[-1:]+nosedown[-1:]+noseup[-1:])
quads.append(outertopcoords[:1]+helpercoords[:1]+nosedown[:1]+noseup[:1])
if m.group('slope') in ['Inverted Double Convex', 'Double Convex']:
lines.append(noseup1[:1]+nosedown1[:1])
lines.append(noseup1[-1:]+nosedown1[-1:])
lines.append(noseup2[:1]+nosedown2[:1])
lines.append(noseup2[-1:]+nosedown2[-1:])
elif m.group('slope') == 'Double Concave':
lines.append(tip)
else:
lines.append(noseup[:1]+nosedown[:1])
lines.append(noseup[-1:]+nosedown[-1:])
# write inner top plate and lines
if m.group('slope') == 'Double Concave':
quads.append(innertopcoords[:4])
quads.append(innertopcoords[3:]+innertopcoords[:1])
else:
quads.append(innertopcoords)
for p1, p2 in wrap(innertopcoords):
lines.append((p1, p2))
# inner sides and lines
if m.group('slope') == 'Double Concave':
# the quadrilateral sides
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords)[1:5],
wrap(innerbottomcoords)[-1:]+wrap(innerbottomcoords)[:4]):
quads.append((p1,p2,p4,p3))
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords)[2:5], wrap(innerbottomcoords)[:4]):
lines.append((p1,p3))
# the slopes
triangles.append(innertopcoords[-1:]+innertopcoords[:1]+innerbottomcoords[-1:])
triangles.append(innertopcoords[:1]+innertopcoords[1:2]+innerbottomcoords[-1:])
lines.append(innertopcoords[-1:]+innerbottomcoords[-1:])
lines.append(innertopcoords[:1]+innerbottomcoords[-1:])
lines.append(innertopcoords[1:2]+innerbottomcoords[-1:])
else:
for (p1, p2), (p3, p4) in zip(wrap(innertopcoords), wrap(innerbottomcoords)):
quads.append((p1,p2,p4,p3))
lines.append((p1,p3))
# draw slope and lines around it
if m.group('slope') in ['Double Convex', 'Inverted Double Convex']:
if m.group('slope') == 'Inverted Double Convex':
noseup1, nosedown1, noseup2, nosedown2 = nosedown1, noseup1, nosedown2, noseup2
quads.append(outertopcoords[-1:]+outertopcoords[:1]+[noseup1[1]]+[noseup1[0]])
quads.append(outertopcoords[2:3]+outertopcoords[3:4]+[noseup2[1]]+[noseup2[0]])
lines.append(noseup1[:1]+outertopcoords[:1])
lines.append(noseup1[-1:]+outertopcoords[-1:])
lines.append(noseup2[-2:-1]+outertopcoords[-2:-1])
lines.append(noseup1[:1]+noseup1[-1:])
lines.append(noseup2[:1]+noseup2[-1:])
elif m.group('slope') == 'Double Concave':
triangles.append(outertopcoords[-1:]+outertopcoords[:1]+[tip[1]])
triangles.append(outertopcoords[:1]+outertopcoords[1:2]+[tip[1]])
lines.append(outertopcoords[-1:]+[tip[1]])
lines.append(outertopcoords[:1]+[tip[1]])
lines.append(outertopcoords[1:2]+[tip[1]])
else:
if m.group('slope') == 'Inverted':
noseup, nosedown = nosedown, noseup
quads.append(outertopcoords[-1:]+outertopcoords[:1]+[noseup[1]]+[noseup[0]])
lines.append(noseup[:1]+outertopcoords[:1])
lines.append(noseup[-1:]+outertopcoords[-1:])
lines.append(noseup[:1]+noseup[-1:])
# for drawing the top and bottom, switch the coords if necessary
if m.group('slope') in ['Inverted Double Convex', 'Inverted']:
outertopcoords, outerbottomcoords = outerbottomcoords, outertopcoords
# write out bottom with trapezoids and lines
for (p1, p2), (p3, p4) in zip(wrap(innerbottomcoords), wrap(outerbottomcoords)):
quads.append((p1, p2, p4, p3))
lines.append((p1, p2))
lines.append((p3, p4))
# write outer top plate and lines
if m.group('slope') == 'Double Concave':
quads.append(outertopcoords[:4])
quads.append(outertopcoords[3:]+outertopcoords[:1])
else:
quads.append(outertopcoords)
for p1, p2 in wrap(outertopcoords):
lines.append((p1, p2))
else:
print "not supported part type: %s"%m.group('type')
exit(1)
outfile = open("parts/%s.dat"%partid, 'w')
outfile.write("0 %s\n"%parttext)
for (x1, y1, z1), (x2, y2, z2) in lines:
outfile.write("2 24 %f %f %f %f %f %f\n"%(x1, y1, z1, x2, y2, z2))
for (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) in triangles:
outfile.write("3 16 %f %f %f %f %f %f %f %f %f\n"%(
x1, y1, z1, x2, y2, z2, x3, y3, z3))
for (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4) in quads:
outfile.write("4 16 %f %f %f %f %f %f %f %f %f %f %f %f\n"%(
x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4))
outfile.close()
if __name__ == "__main__": if __name__ == "__main__":
render() for part in parts:
render_part(part)