"""Author the launcher's permanent outlet with the straight chute's mouth profile.""" from math import cos, pi, sin def build_outlet(radius, mesh_object, outline, mats): # The last cross-section uses the same 32 facets as the adjoining chute. groove = [(radius * sin(i*pi/32), radius * (1-cos(i*pi/32))) for i in range(-16, 17)] profile = [(-.5, radius), *groove, (.5, radius)] start = -.375 def rise(x, depth): u = min(1, max(0, (x-start)/(.5-start))) return depth * u*u*(3-2*u) vertices, faces = [], [] for i in range(25): x = -.5+i/24 ring = [(x, y, 1+rise(x, depth)) for y, depth in profile] vertices.extend([*ring, (x,.5,0), (x,-.5,0)]) width = len(profile)+2 for row in range(24): for col in range(width): a = row*width+col b = row*width+(col+1)%width faces.append((a,b,b+width,a+width)) # Blender triangulates the concave end caps on export. faces.extend([tuple(reversed(range(width))), tuple(range(24*width,25*width))]) body = mesh_object('directional_boost',vertices,faces) for key in ['wall','wall_top']: body.data.materials.append(mats[key]) for face in body.data.polygons: face.material_index = int(face.normal.z>0.001) group = [body,outline(body)] # Sample the graphic along the same cross-section so it lies on the wood. for suffix,scale,lift,color in [('border',1,.003,'ink'),('fill',.82,.005,'red')]: verts, polys = [], [] # Separate bands at the arrow shoulders to keep their sharp corners. for low,high,shaft in [(-.28,-.12,False),(-.12,.12,True),(.12,.28,False)]: cuts = [(low*scale,None),*((y,d) for y,d in groove if low*scale < y < high*scale),(high*scale,None)] for y, depth in cuts: if depth is None: for (ya,da),(yb,db) in zip(groove,groove[1:]): if ya<=y<=yb: depth=da+(db-da)*(y-ya)/(yb-ya) break left = (-.34 if shaft else .04)*scale right = .36*scale-.32*abs(y)/.28 for j in range(9): x=left+(right-left)*j/8 verts.append((x,y,1+rise(x,depth)+lift)) band_start=len(verts)-9*len(cuts) for i in range(len(cuts)-1): for j in range(8): a=band_start+9*i+j polys.append((a,a+1,a+10,a+9)) arrow=mesh_object('ink_boost_arrow_'+suffix,verts,polys) arrow.data.materials.append(mats[color]) group.append(arrow) return group