"""Editable Sovereignty CC0 asset recipe. Run with a Blender Python or blender --background --python recipe.py -- <arguments>."""
import argparse
import json
import math
import sys
from pathlib import Path

import bpy
from mathutils import Matrix, Vector

PI = math.pi
MATERIALS = {}


def material(name, rgb, metallic=0.55, emission=0):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = (*rgb, 1)
    mat.use_nodes = True
    shader = mat.node_tree.nodes.get('Principled BSDF')
    for prop, val in [('Base Color', (*rgb,1)), ('Metallic', metallic), ('Roughness', .36),
                      ('Emission Color', (*rgb,1)), ('Emission Strength', emission)]:
        shader.inputs[prop].default_value = val
    MATERIALS[name] = mat


def finish(obj, name, color, bevel=0):
    obj.name = name
    obj.data.materials.append(MATERIALS[color])
    if bevel:
        edge = obj.modifiers.new('Machined chamfer', 'BEVEL')
        edge.width = bevel
        edge.segments = 2
        obj.modifiers.new('Panel normals', 'WEIGHTED_NORMAL')
    return obj


def box(name, pos, dims, color='Slate', bevel=.07):
    bpy.ops.mesh.primitive_cube_add(size=1, location=pos)
    obj = bpy.context.object
    obj.dimensions = dims
    bpy.ops.object.transform_apply(location=False,rotation=False,scale=True)
    return finish(obj, name, color, min(bevel, min(dims)/4))


def cylinder(name, pos, radius, depth, color='Steel', axis='Z', radius2=None, vertices=24):
    rotation = {'X':(0,PI/2,0), 'Y':(PI/2,0,0), 'Z':(0,0,0)}[axis]
    bpy.ops.mesh.primitive_cone_add(vertices=vertices, radius1=radius, radius2=radius if radius2 is None else radius2,
                                    depth=depth, location=pos, rotation=rotation)
    return finish(bpy.context.object, name, color, .025)


def beam(name, start, end, width, color='Steel'):
    a,b=Vector(start),Vector(end)
    obj=box(name,(a+b)/2,(width,width,(b-a).length),color)
    obj.rotation_euler=(b-a).to_track_quat('Z','Y').to_euler()
    return obj


def ring(name, pos, radius, tube, color, axis='Z'):
    bpy.ops.mesh.primitive_torus_add(location=pos, major_segments=32, minor_segments=8, major_radius=radius,minor_radius=tube,
                                    rotation={'X':(0,PI/2,0),'Y':(PI/2,0,0),'Z':(0,0,0)}[axis])
    return finish(bpy.context.object,name,color)


def pod(x, y, z):
    box('Removable freight pod',(x,y,z),(.94,1.14,.76),'Ivory',.13)
    for dy in (-.36,.36):
        box('Cargo tie-down',(x,y+dy,z),(.98,.085,.80),'Ochre')
    box('Manifest status',(x,y-.577,z),(.36,.025,.10),'Cyan')


def engine(x,y,z,scale=1):
    cylinder('Propulsion bell',(x,y,z),.63*scale,1.1*scale,'Graphite','Y',.43*scale)
    ring('Exhaust ceramic rim',(x,y+.56*scale,z),.52*scale,.085*scale,'Steel','Y')
    cylinder('Ion throat',(x,y+.57*scale,z),.43*scale,.035*scale,'Cyan','Y')
    for d in (0,.28):
        ring('Engine cooling band',(x,y-d*scale,z),(.51-.04*d)*scale,.058*scale,'Ochre','Y')


def tender():
    for side in (-1,1):
        x=2.0*side
        box('Service hull pontoon',(x,.2,0),(1.16,7.4,1.16),'Teal',.26)
        prow=box('Sloped bow cheek',(x,-3.68,.04),(.94,1.25,.85),'Ivory',.21)
        prow.rotation_euler.x=-.18
        for y in (-2.65,-1.35,-.05):
            pod(x,y,.93)
        engine(x,3.94,0)
        for y in (1.22,1.72,2.22):
            box('Service-bay deck stripe',(x-side*.5,y,.58),(.15,.20,.06),'Ochre')
        beam('Gantry leg',(x,-1.3,.54),(x,-1.1,2.45),.24,'Ochre')
        beam('Bay entrance brace',(x,-1.22,2.38),(x-side*.55,-1.22,2.75),.18,'Steel')
    box('Open center service floor',(0,-.03,-.50),(3.18,4.65,.24),'Graphite')
    for x in (-1.05,1.05):
        box('Illuminated alignment rail',(x,-.2,-.34),(.08,3.9,.055),'Cyan')
    box('Overhead crane bridge',(0,-1.2,2.55),(4.55,.31,.27),'Ochre')
    box('Mobile hoist carriage',(-.56,-1.2,2.31),(.74,.52,.34),'Graphite')
    cylinder('Retracted grapple',(-.56,-1.2,1.88),.13,.55,'Steel')
    box('Aft engineering block',(0,2.54,.34),(3.25,2.1,1.65),'Ivory',.21)
    box('Raised bridge',(0,2.06,1.35),(2.35,1.42,.67),'Teal',.17)
    box('Bridge glazing',(0,1.33,1.42),(1.79,.12,.25),'Cyan')
    for x in (-.70,0,.70):
        box('Aft heat exchanger',(x,3.10,1.24),(.34,.84,.22),'Graphite')
    cylinder('Communications mast',(.68,2.48,2.16),.065,1.2,'Steel')
    cylinder('Mast beacon',(.68,2.48,2.78),.11,.14,'Amber')


def drone():
    box('Armored keel',(0,0,0),(2.45,3.1,.83),'Graphite',.28)
    box('Ochre instrument brow',(0,-1.08,.53),(2.12,1.22,.65),'Ochre',.22)
    cylinder('Stereo survey lens',(0,-1.74,.51),.33,.20,'Steel','Y')
    cylinder('Survey lens glass',(0,-1.855,.51),.225,.055,'Cyan','Y')
    box('Ore hopper floor',(0,.75,.44),(1.55,1.67,.16),'Steel')
    for side in (-1,1):
        rim=box('Flared hopper side',(side*.82,.74,.84),(.18,1.87,.86),'Ochre')
        rim.rotation_euler.y=side*.21
        beam('Cutter shoulder',(side*.85,-.66,.12),(side*1.56,-1.12,-.05),.36,'Steel')
        beam('Cutter drive arm',(side*1.56,-1.12,-.05),(side*1.72,-2.41,-.21),.31,'Ochre')
        cylinder('Cutter drive axle',(side*1.72,-2.41,-.2),.28,.68,'Graphite','X')
        cylinder('Rotary extraction wheel',(side*1.91,-2.47,-.19),.66,.21,'Steel','X',vertices=32)
        for angle in range(12):
            a=angle*PI/6
            tooth=box('Replaceable cutting tooth',(side*1.91,-2.47+.68*math.sin(a),-.19+.68*math.cos(a)),(.30,.22,.26),'Ivory')
            tooth.rotation_euler.x=-a+.29
        for y in (-.40,1.20):
            beam('Thruster outrigger',(side*.9,y,-.12),(side*1.67,y,-.18),.2,'Graphite')
            cylinder('Maneuvering thruster',(side*1.61,y,-.24),.34,.52,'Steel','Z',.24)
            cylinder('Thruster exit',(side*1.61,y,-.52),.22,.045,'Cyan')
    for y in (-.1,1.59):
        box('Hopper end wall',(0,y,.81),(1.78,.13,.78),'Teal')
    for x,y,z,r in ((-.39,.58,.69,.34),(.26,.84,.68,.31),(.34,.29,.65,.24),(-.24,1.18,.67,.29)):
        bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1,radius=r,location=(x,y,z))
        finish(bpy.context.object,'Ore sample','Copper')


def replicator():
    box('Fabrication bed',(0,0,0),(4.2,3.25,.42),'Graphite')
    box('Pattern projection grid',(0,0,.25),(3.35,2.50,.10),'Cyan')
    for x in (-1.87,1.87):
        for y in (-1.35,1.35):
            beam('Chamber rail',(x,y,.20),(x,y,3.35),.26,'Ivory')
        box('Gantry runway',(x,0,3.32),(.4,3.1,.24),'Teal')
    box('Tool traverse',(0,.32,3.24),(3.8,.37,.32),'Ochre')
    beam('Tool arm',(-.56,.32,3.1),(-.26,.12,2.12),.30,'Steel')
    beam('Articulated head',(-.26,.12,2.12),(.43,-.30,1.50),.24,'Ochre')
    cylinder('Emitter nozzle',(.43,-.30,1.27),.11,.50,'Copper','Z',.23)


def cargo_mule():
    box('Rover chassis',(0,0,.60),(2.5,4.8,.58),'Ochre',.20)
    cab=box('Forward cab',(0,-1.65,1.34),(2.2,1.38,1.2),'Ivory',.19)
    box('Pilot windscreen',(0,-2.35,1.50),(1.67,.10,.54),'Teal')
    for side in (-1,1):
        for y in (-1.65,0,1.65):
            cylinder('Traction wheel',(side*1.35,y,.38),.59,.47,'Graphite','X')
            cylinder('Axle cap',(side*1.61,y,.38),.26,.09,'Steel','X')
        for y in (.02,1.28): pod(side*.55,y,1.28)


def cooling():
    cylinder('Coolant plinth',(0,0,.18),1.6,.36,'Graphite',vertices=8)
    cylinder('Pressure column',(0,0,2.5),.77,4.55,'Steel')
    for k in range(11):
        cylinder('Radial heat fins',(0,0,.63+k*.36),1.31,.12,'Teal',vertices=16)
    for x in (-1.25,1.25):
        cylinder('Visible return pipe',(x,0,2.55),.13,4.15,'Copper')
        beam('Return manifold',(x,0,.50),(0,0,.50),.19,'Steel')
    ring('Service walkway',(0,0,4.70),1.06,.15,'Ochre')
    cylinder('Top vent',(0,0,4.98),.83,.25,'Graphite')


def bottle():
    cylinder('Containment sleeve',(0,0,1.1),.74,1.67,'Teal','Z',.74)
    for z in (.23,1.96):
        cylinder('Impact collar',(0,0,z),.89,.33,'Graphite',vertices=8)
    for a in range(6):
        t=a*PI/3
        beam('Magnetic rail',(.76*math.cos(t),.76*math.sin(t),.34),(.76*math.cos(t),.76*math.sin(t),1.82),.105,'Ochre')
    cylinder('Fuel interlock',(0,0,2.22),.38,.26,'Copper')
    ring('Interlock status',(0,0,2.36),.28,.038,'Cyan')


def coil():
    for z in (-1.25,1.25):
        ring('Coil cage hoop',(0,0,z),1.55,.17,'Steel')
    for k in range(16): ring('Insulated copper winding',(0,0,-1.05+k*.14),1.12,.092,'Copper')
    for k in range(6):
        a=k*PI/3
        beam('Cage stay',(1.55*math.cos(a),1.55*math.sin(a),-1.25),(1.55*math.cos(a),1.55*math.sin(a),1.25),.16,'Teal')


def thruster():
    cylinder('Pressure vessel',(0,0,0),.98,1.70,'Steel','Y')
    cylinder('Expanding exhaust',(0,1.42,0),1.23,1.15,'Graphite','Y',.72)
    ring('Exhaust liner',(0,2,0),1.07,.10,'Copper','Y')
    cylinder('Luminous exhaust throat',(0,2.02,0),.80,.07,'Cyan','Y')
    for side in (-1,1):
        box('Mounting shoe',(side*.88,-.15,-.40),(.48,1.25,.45),'Ochre')
    for i in range(6):
        a=i*PI/3; x,z=math.cos(a),math.sin(a)
        beam('Cooling return',(x*.91,-.7,z*.91),(x*.91,.60,z*.91),.12,'Copper')


def probe():
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1,radius=.84,location=(0,0,0))
    finish(bpy.context.object,'Instrument bus','Ochre')
    for i in range(3):
        a=i*2*PI/3; x,y=math.cos(a),math.sin(a)
        beam('Antenna boom',(x*.63,y*.63,0),(x*2.12,y*2.12,.32),.09,'Steel')
        panel=box('Fold-out detector segment',(x*1.45,y*1.45,.14),(1.16,.54,.08),'Teal');panel.rotation_euler.z=a
        cylinder('Attitude nozzle',(x*.50,y*.50,-.61),.15,.29,'Graphite','Z',.09)
    cylinder('Signal mast',(0,0,1.06),.07,.93,'Steel')
    ring('Telemetry loop',(0,0,1.58),.32,.045,'Copper','X')


def dish():
    # Lathed open parabolic reflector with an offset feed. Each ring is editable.
    ribs,steps=32,6
    verts=[(0,0,.58)]
    for s in range(1,steps+1):
        r=2.1*s/steps
        for i in range(ribs):
            a=2*PI*i/ribs
            verts.append((math.cos(a)*r,math.sin(a)*r,.58+.17*r*r))
    faces=[(0,1+i,1+(i+1)%ribs) for i in range(ribs)]
    for s in range(steps-1):
        a=1+s*ribs;b=a+ribs
        for i in range(ribs):
            n=(i+1)%ribs;faces.append((a+i,b+i,b+n,a+n))
    mesh=bpy.data.meshes.new('Reflector petals');mesh.from_pydata(verts,[],faces);mesh.update()
    panel=bpy.data.objects.new('Deep-space deflector dish',mesh);bpy.context.collection.objects.link(panel);finish(panel,panel.name,'Copper')
    plate=panel.modifiers.new('Bowl thickness','SOLIDIFY');plate.thickness=.055
    ring('Retaining rim',(0,0,1.34),2.1,.08,'Ivory')
    cylinder('Gimbal pedestal',(0,0,0),.77,1.2,'Graphite')
    for a in (0,2*PI/3,4*PI/3):beam('Receiver strut',(1.92*math.cos(a),1.92*math.sin(a),1.24),(0,0,2.12),.09,'Steel')
    cylinder('Field feed',(0,0,2.18),.20,.45,'Cyan')


def tug():
    box('Towing spine',(0,0,.06),(1.66,5.2,1.14),'Teal',.24)
    box('Pilot blister',(0,-1.58,.85),(1.55,1.47,.84),'Ivory',.19)
    box('Pilot glass',(0,-2.31,.94),(1.08,.12,.38),'Cyan')
    for side in (-1,1):
        engine(side*1.12,2.12,-.05,1.02)
        beam('Swing boom',(side*.72,-.12,.21),(side*1.92,-1.69,.29),.37,'Ochre')
        beam('Inward grapple',(side*1.92,-1.69,.29),(side*1.46,-2.65,.26),.22,'Steel')
    cylinder('Cable drum',(0,1.19,.88),.62,1.19,'Copper','X')
    for x in (-.58,.58):cylinder('Winch flange',(x,1.19,.88),.72,.10,'Graphite','X')


def shuttle():
    box('Pressurized freight volume',(0,.25,.30),(2.72,4.3,1.83),'Ivory',.35)
    nose=box('Sloping forward cab',(0,-2.06,.18),(2.08,1.58,1.26),'Teal',.26)
    nose.rotation_euler.x=-.15
    box('Flight deck glazing',(0,-2.85,.40),(1.39,.12,.43),'Cyan')
    ramp=box('Hinged loading ramp',(0,2.98,-.48),(1.96,1.72,.16),'Ochre');ramp.rotation_euler.x=-.25
    box('Hold bulkhead',(0,2.41,.38),(2.22,.11,1.24),'Graphite')
    for x in (-.74,.74):
        for y in (-1.55,1.45):
            beam('Landing strut',(x,y,-.31),(x*1.27,y,-1.05),.17,'Steel')
            box('Landing skid',(x*1.27,y,-1.1),(.38,.76,.14),'Graphite')
    for side in (-1,1):engine(side*1.49,.96,.14,.66)


def hub():
    cylinder('Octagonal pressure module',(0,0,0),1.72,1.92,'Ivory',vertices=8)
    cylinder('Operations cupola',(0,0,1.18),1.03,.56,'Teal',vertices=8)
    for i in range(6):
        a=i*PI/3;x,y=math.cos(a),math.sin(a)
        spine=box('Expansion tunnel',(x*2.05,y*2.05,-.04),(1.54,.78,.64),'Graphite');spine.rotation_euler.z=a
        rim=box('Standard docking flange',(x*2.75,y*2.75,-.04),(.22,1.02,.85),'Ochre');rim.rotation_euler.z=a
        light=box('Approach beacon',(x*2.88,y*2.88,.14),(.06,.47,.08),'Cyan');light.rotation_euler.z=a
    ring('Pressure seam',(0,0,.49),1.65,.07,'Copper')


def freighter():
    box('Bent lower keel',(0,0,-.5),(1.4,6.5,.4),'Graphite')
    for i,y in enumerate((-2.6,-1.7,-.8,.1,1,1.9,2.8)):
        for side in (-1,1):
            beam('Exposed rib',(side*.56,y,-.48),(side*1.30,y,.69),.14,'Copper')
            if (i+int(side))%3:
                plate=box('Torn cargo plating',(side*1.06,y,.09),(.22,.75,1.09),'Steel')
                plate.rotation_euler.y=side*(.31 if i!=4 else .79)
    box('Forward bulkhead',(0,-2.8,.24),(2.25,.42,1.44),'Ochre')
    engine(-.67,3.05,-.12,.69)
    for i in range(3):beam('Severed conduit',(.4+i*.18,1.4,.2),(.55+i*.21,2.96,.91-i*.17),.06,'Copper')


def rock(name,pos,size,seed,color):
    import random
    rng=random.Random(seed)
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=2,radius=size,location=pos)
    obj=bpy.context.object
    for vert in obj.data.vertices:
        f=rng.uniform(.86,1.12);vert.co.x*=1.28*f;vert.co.y*=.84*f;vert.co.z*=f
    finish(obj,name,color)
    return obj


def asteroid():
    rock('Fractured parent body',(0,0,0),1.65,308,'Basalt')
    for i,(x,y,z) in enumerate(((-1,.15,1.13),(-.57,.15,1.48),(0,.15,1.6),(.44,.18,1.53),(.83,.17,1.46))):
        vert=rock('Exposed mineral seam',(x,y,z),.27,403+i,'Copper');vert.scale=(1.4,.7,.55)
    for i in range(3):
        crystal=cylinder('Surface crystal',(-.58+i*.19,-.75,1.17+i*.06),.13,.53,'Teal','Z',0,vertices=5)
        crystal.rotation_euler.y=.23*i


def belt():
    for i,(x,y,z,r) in enumerate(((-2.2,-.6,.21,.89),(-.53,.45,-.21,.61),(.63,-.8,.1,.50),(1.91,.5,.23,.79),(.69,1.26,.41,.33))):
        rock('Floating belt fragment '+str(i+1),(x,y,z),r,813+i,'Basalt' if i%2==0 else 'Stone')


def pad():
    cylinder('Landing apron',(0,0,0),3.3,.34,'Graphite',vertices=8)
    ring('Touchdown circle',(0,0,.20),1.69,.055,'Ochre')
    for i in range(8):
        a=i*PI/4;x,y=math.cos(a),math.sin(a)
        box('Perimeter beacon',(x*2.88,y*2.88,.23),(.22,.22,.2),'Cyan')
    for x in (-.42,.42):box('Landing alignment bars',(x,0,.20),(.11,1.38,.04),'Ivory')
    box('Touchdown crossbar',(0,0,.20),(.90,.11,.04),'Ivory')
    box('Approach service kiosk',(2.28,.41,.53),(.53,.76,.80),'Teal')


def deck():
    box('Interlocking support plate',(0,0,0),(3.98,3.98,.26),'Graphite')
    for x in (-.98,.98):
        for y in (-.98,.98):
            box('Armored tile quadrant',(x,y,.18),(1.82,1.82,.14),'Slate',.12)
            for dx in (-.66,.66):
                for dy in (-.66,.66):
                    cylinder('Countersunk panel stud',(x+dx,y+dy,.259),.056,.016,'Steel',vertices=8)
    for a in (-1.20,1.20):
        box('Inset service light',(0,a,.185),(.05,.71,.035),'Cyan')
        box('Hazard marker',(a,0,.185),(.61,.08,.035),'Ochre')


def planet(mode):
    from mathutils import noise
    bpy.ops.mesh.primitive_uv_sphere_add(segments=64,ring_count=36,radius=2)
    o=bpy.context.object;o.name=mode
    colors={'Temperate colony':['Ocean','Land','Forest','Cloud','Ice'],'Scarred mining moon':['Basalt','Stone','Copper'],
            'Ringed gas giant':['Cloud','Ochre','Sand','Ivory']}[mode]
    for c in colors:o.data.materials.append(MATERIALS[c])
    for poly in o.data.polygons:
        p=poly.center.normalized();n=noise.noise_vector(p*3.2).x
        if mode=='Temperate colony':
            field=n+.25*noise.noise_vector(p*8).x
            idx=4 if abs(p.z)>.87 else 3 if noise.noise_vector(p*6+Vector((2,1,4))).z>.51 else 0 if field<.12 else 1 if field<.40 else 2
        elif mode=='Scarred mining moon':idx=2 if abs(n)<.021 and p.z>-.5 else int(n>.03)
        else:idx=int((p.z+.10*n+1)*10)%4
        poly.material_index=idx;poly.use_smooth=True
    if mode=='Ringed gas giant':
        for i in range(7):
            obj=ring('Ring band',(0,0,0),2.65+i*.11,.053,'Sand' if i%3 else 'Copper')
            obj.scale.z=.22;obj.rotation_euler.y=.28
    if mode=='Scarred mining moon':
        for x,y,r in ((-.80,-.74,.32),(.60,-.35,.24),(-.22,.91,.39)):
            v=Vector((x,y,(4-x*x-y*y)**.5))
            crater=ring('Impact rim',v*.994,r,.05,'Stone');crater.rotation_euler=v.to_track_quat('Z','Y').to_euler()
    if mode=='Temperate colony':
        for x,y in ((.29,-.82),(.38,-.79),(.43,-.73),(-.62,-.65),(-.68,-.63)):
            v=Vector((x,y,.48)).normalized()*2.005
            cylinder('Colony light',v,.022,.022,'Amber',vertices=6)


def carrier():
    box('Broad flight deck',(0,0,.54),(4.7,6.8,.43),'Slate',.34)
    box('Lower hangar hull',(0,.31,-.21),(3.82,5.84,1.18),'Teal',.31)
    for x in (-1.12,1.12):
        box('Split hangar entrance',(x,-2.67,-.13),(1.66,.18,.82),'Graphite')
        box('Illuminated hangar lintel',(x,-2.78,.25),(1.65,.07,.055),'Cyan')
        box('Flight deck centerline',(x,.1,.77),(.07,4.81,.035),'Ivory')
        for y in (-2.48,-1.32,1.36,2.58):
            box('Deck landing marker',(x,y,.79),(.51,.078,.04),'Ochre')
        engine(x,3.05,-.2,.79)
    box('Raised starboard island',(1.80,1.05,1.17),(.82,1.94,.82),'Ivory',.14)
    box('Flight control windows',(1.76,.051,1.21),(.62,.07,.19),'Cyan')
    cylinder('Signal mast',(1.80,1.43,2.03),.065,1.05,'Steel')
    box('Antenna array',(1.80,1.43,2.52),(.91,.1,.13),'Ochre')
    for y in (-1.35,-.2,.95):
        box('Port-side service sponson',(-2.29,y,.08),(.73,.89,.48),'Ivory',.10)


def salvage_drone():
    cylinder('Recovery drone drum',(0,0,0),.94,1.35,'Teal','X')
    ring('Tow shackle',(0,1.26,.06),.41,.10,'Ochre','X')
    box('Tow anchor',(0,.87,.01),(.58,.66,.39),'Graphite')
    for side in (-1,1):
        beam('Manipulator shoulder',(side*.54,-.44,0),(side*1.20,-1.23,.16),.22,'Ochre')
        beam('Manipulator forearm',(side*1.20,-1.23,.16),(side*.92,-1.95,-.12),.15,'Steel')
        engine(side*.77,.60,-.1,.43)
    cylinder('Salvage torch',(-.92,-2.09,-.1),.14,.43,'Copper','Y',.07)
    for dx in (-.18,.18):
        beam('Salvage gripper',(.92,-1.9,-.12),(.92+dx,-2.29,-.14),.085,'Steel')


def hull(name, sections, color):
    vertices = []
    faces = []
    for y, half_width, floor, roof in sections:
        vertices.extend([(-half_width * .72, y, floor), (half_width * .72, y, floor),
                         (half_width, y, roof * .56), (half_width * .62, y, roof),
                         (-half_width * .62, y, roof), (-half_width, y, roof * .56)])
    faces.append(tuple(range(6)))
    for offset in range(0, len(vertices) - 6, 6):
        for edge in range(6):
            current = offset + edge
            following = offset + (edge + 1) % 6
            faces.append((current, current + 6, following + 6, following))
    faces.append(tuple(reversed(range(len(vertices) - 6, len(vertices)))))
    mesh = bpy.data.meshes.new(name)
    mesh.from_pydata(vertices, [], faces)
    mesh.update()
    panel = bpy.data.objects.new(name, mesh)
    bpy.context.collection.objects.link(panel)
    return finish(panel, name, color, .055)


def iron_choir():
    hull('Processional hull', [(-4.6,.27,-.25,.35),(-2.90,1.70,-.62,.91),
        (.35,2.03,-.80,1.12),(2.90,1.78,-.63,1.03),(3.55,1.18,-.42,.83)], 'Basalt')
    for side in (-1,1):
        for y in (-1.88,-.46,.96,2.17):
            beam('Vaulted copper rib',(side*1.97,y,-.01),(side*.60,y+.29,1.16),.25,'Copper')
            beam('Amber clerestory',(side*1.60,y-.18,.56),(side*.98,y-.01,.93),.10,'Amber')
        beam('Split prow fin',(side*1.48,-2.35,.18),(side*.73,-4.73,-.11),.31,'Steel')
        engine(side*1.16,3.28,-.04,1.02)
    for y,height in ((-.55,.89),(.58,1.36),(1.69,.90)):
        cylinder('Octagonal tower',(0,y,1.10+height/2),.43,height,'Graphite',vertices=8)
        cylinder('Crown',(0,y,1.10+height+.18),.49,.38,'Copper',radius2=.14,vertices=8)
        cylinder('Crown light',(0,y,1.10+height+.41),.092,.16,'Amber')


def torpedo_corvette():
    hull('Needle hull',[(-3.82,.12,-.14,.17),(-1.15,.99,-.50,.73),
        (1.42,.91,-.48,.60),(2.70,.58,-.30,.39)],'Ivory')
    hull('Cockpit canopy',[(-1.96,.10,.31,.40),(-.90,.53,.38,1.02),(.25,.43,.44,.86)],'Teal')
    engine(0,2.72,-.08,.77)
    for side in (-1,1):
        x=side*1.18
        beam('Swept outrigger',(side*.47,.98,.06),(x,-.26,.09),.32,'Copper')
        cylinder('Sealed flux nacelle',(x,-.24,.06),.42,3.28,'Teal','Y',vertices=8)
        cylinder('Nacelle nose',(x,-1.99,.06),.32,.26,'Graphite','Y',vertices=8)
        ring('Luminous octant',(x,-2.14,.06),.24,.047,'Cyan','Y')
        for y in (-.87,.38,1.11):
            cylinder('Nacelle collar',(x,y,.06),.46,.105,'Ivory','Y',vertices=8)
        beam('V-tail',(x,.91,.21),(x*1.72,2.15,.89),.19,'Teal')


def flux_housing():
    for x in (-.86,.86):
        box('Mounting foot',(x,0,.03),(.64,3.26,.26),'Steel')
        box('Outer sill',(x,0,.33),(.27,3.42,.44),'Ochre')
    cylinder('Faceted equipment housing',(0,0,.96),.99,2.80,'Graphite','Y',vertices=8)
    for y in (-1.36,-.62,.29,1.38):
        cylinder('Ceramic jacket',(0,y,.96),1.07,.22,'Ivory','Y',vertices=8)
    cylinder('Recessed field lens',(0,-1.50,.96),.68,.06,'Teal','Y',vertices=12)
    ring('Flux halo',(0,-1.55,.96),.54,.067,'Cyan','Y')
    ring('Inner aperture marker',(0,-1.57,.96),.30,.038,'Copper','Y')
    for x in (-.44,.44):
        box('Top guide',(x,.04,1.91),(.15,2.68,.17),'Ochre')
    box('Rear service cover',(0,1.47,.96),(1.18,.22,1.40),'Steel',.12)
    for z in (.64,.95,1.26):
        box('Service marking',(1.01,.39,z),(.05,.49,.07),'Amber')



def hydroponic_bay():
    box('Habitat pressure deck',(0,0,0),(4.9,7.0,.42),'Ivory',.18)
    for x in (-2.17,2.17):
        box('Fluid service trunk',(x,0,.34),(.48,6.70,.36),'Teal')
        for y in (-3.05,0,3.05):
            beam('Pressure frame upright',(x,y,.2),(x,y,2.45),.18,'Steel')
            beam('Roof rafter',(x,y,2.45),(0,y,3.5),.18,'Ivory')
        beam('Continuous roof sill',(x,-3.05,2.45),(x,3.05,2.45),.16,'Steel')
    beam('Roof spine',(0,-3.05,3.5),(0,3.05,3.5),.19,'Ivory')
    for x in (-1.18,1.18):
        for y in (-2.1,0,2.1):
            box('Cultivation trough',(x,y,.62),(1.55,1.83,.65),'Teal',.12)
            box('Growing substrate',(x,y,.97),(1.33,1.61,.08),'Basalt')
            for dx in (-.43,0,.43):
                for dy in (-.5,0,.5):
                    cylinder('Plant stem',(x+dx,y+dy,1.12),.037,.23,'Land',vertices=6)
                    for side in (-1,1):
                        leaf=box('Crop leaf',(x+dx+side*.085,y+dy,1.28),(.23,.12,.045),'Forest',.016)
                        leaf.rotation_euler.y=side*.48
        beam('Irrigation feed',(x,-2.95,.53),(x,2.95,.53),.09,'Copper')
        box('Grow-light rail',(x,0,2.52),(.22,5.6,.12),'Steel')
        box('Grow-light face',(x,0,2.44),(.15,5.5,.035),'Cyan')
    for y in (-3.25,3.25):
        ring('Habitat transfer flange',(0,y,1.4),.82,.14,'Steel','Y')
    cylinder('Nutrient reservoir',(1.8,2.65,1.30),.27,1.3,'Ivory',vertices=16)
    box('Crop monitoring console',(-1.80,-2.72,1.03),(.48,.56,.91),'Graphite')
    box('Console status',(-1.80,-3.02,1.30),(.32,.04,.18),'Cyan')


def pressure_airlock():
    box('Deck interface',(0,0,-1.36),(3.50,4.6,.35),'Slate')
    for y in (-1.85,-.65,.65,1.85):
        for k in range(8):
            a=k*PI/4
            b=(k+1)*PI/4
            beam('Octagonal pressure frame',(1.42*math.cos(a),y,1.42*math.sin(a)),(1.42*math.cos(b),y,1.42*math.sin(b)),.19,'Steel')
    for side in (-1,1):
        box('Side pressure shell',(side*1.39,0,0),(.21,3.8,1.9),'Ivory')
        box('Internal utility raceway',(side*1.13,0,-.74),(.19,3.3,.27),'Teal')
        box('Pressure status strip',(side*1.13,0,.82),(.075,2.9,.13),'Cyan')
        for y in (-1.85,1.85):
            box('Recessed sliding door leaf',(side*.93,y,.05),(.49,.21,2.16),'Graphite',.12)
            box('Door safety edge',(side*.69,y,.05),(.07,.25,2.02),'Ochre')
    box('Walking threshold',(0,0,-1.13),(2.05,4.10,.14),'Graphite')
    for y in (-1.96,1.96):
        box('Threshold marker',(0,y,-1.04),(1.35,.14,.045),'Amber')
        box('Header',(0,y,1.30),(2.5,.28,.26),'Ivory')
    for x in (-.54,.54):
        box('Ceiling service channel',(x,0,1.20),(.18,3.7,.16),'Teal')
    box('Atmosphere control cabinet',(1.03,.43,.10),(.44,.65,.92),'Ochre')
    box('Pressure display',(.78,.43,.34),(.05,.45,.18),'Cyan')
    for y in (-.35,.1,.55):
        cylinder('Vent intake',(-1.23,y,.31),.13,.08,'Graphite','X',vertices=12)
    beam('Overhead equalization line',(-1.15,-1.6,1.03),(-1.15,1.6,1.03),.09,'Copper')


def solar_power_array():
    cylinder('Mounting pedestal',(0,0,.32),.67,.64,'Graphite',vertices=16)
    cylinder('Azimuth gimbal',(0,0,.76),.48,.29,'Copper',vertices=16)
    box('Central distribution bus',(0,0,1.18),(1.20,2.5,.57),'Ivory')
    for y in (-.82,.82):
        cylinder('Pitch hinge',(0,y,1.37),.27,1.65,'Steel','X',vertices=16)
    for side in (-1,1):
        for section in range(3):
            x=side*(1.60+section*2.05)
            box('Panel perimeter backplate',(x,0,1.35),(1.94,2.55,.16),'Graphite',.04)
            for dy in (-1.16,1.16):
                box('Panel edge rail',(x,dy,1.46),(1.95,.11,.12),'Steel',.02)
            for dx in (-.90,.90):
                box('Cell frame end',(x+dx,0,1.46),(.10,2.45,.12),'Steel',.02)
            for i in range(4):
                for j in range(6):
                    px=x+(i-1.5)*.42
                    py=(j-2.5)*.37
                    box('Photovoltaic cell',(px,py,1.47),(.385,.338,.055),'Ocean',.008)
                    box('Cell busbar',(px,py,1.502),(.025,.31,.012),'Copper',.002)
            if section<2:
                cylinder('Fold axis',(x+side*1.025,0,1.35),.11,2.64,'Copper','Y',vertices=12)
        beam('Rear deployment spar',(side*.55,0,1.1),(side*6.56,0,1.1),.12,'Teal')
        box('Wing tip telemetry',(side*6.57,0,1.46),(.15,.35,.09),'Cyan')
    box('Power junction',(0,0,.99),(.70,.82,.28),'Teal')
    box('Output status',(0,-1.27,1.21),(.48,.055,.19),'Amber')



def water_reclamation_skid():
    box('Skid frame',(0,0,.18),(4.8,3.6,.36),'Graphite')
    for x in (-1.25,1.25):
        cylinder('Vertical filtration vessel',(x,.28,1.35),.66,2.18,'Ivory',vertices=16)
        cylinder('Removable filter cap',(x,.28,2.50),.72,.19,'Steel',vertices=16)
        for z in (.68,1.95):
            ring('Vessel clamp',(x,.28,z),.66,.055,'Teal')
        beam('Water return',(x,.28,.45),(x,-1.28,.45),.14,'Copper')
        cylinder('Return valve',(x,-1.28,.64),.19,.32,'Ochre',vertices=12)
    box('Membrane control cabinet',(0,-1.25,1.15),(1.05,.68,1.46),'Teal')
    box('Water quality display',(0,-1.61,1.45),(.66,.04,.24),'Cyan')
    for x in (-.35,.35):
        cylinder('Clean-water outlet',(x,-1.65,.65),.14,.40,'Steel','Y')
    beam('Upper distribution pipe',(-1.25,.28,2.72),(1.25,.28,2.72),.14,'Copper')
    for x in (-1.25,1.25):
        beam('Top riser',(x,.28,2.55),(x,.28,2.72),.14,'Copper')
    for x in (-2.12,2.12):
        box('Forklift access channel',(x,0,.39),(.25,3.1,.17),'Ochre')


def cargo_elevator():
    box('Foundation',(0,0,.15),(4.6,4.2,.3),'Graphite')
    for x in (-1.85,1.85):
        for y in (-1.62,1.62):
            beam('Tower upright',(x,y,.3),(x,y,6.4),.28,'Steel')
        for z in (2.0,4.0,6.1):
            beam('Crossmember',(x,-1.62,z),(x,1.62,z),.22,'Teal')
        for i in range(3):
            beam('Diagonal brace',(x,-1.62,.4+i*1.9),(x,1.62,2.0+i*1.9),.13,'Steel')
        box('Guide track',(x,0,3.34),(.21,.30,5.95),'Copper')
    for y in (-1.62,1.62):
        beam('Crown girder',(-1.85,y,6.4),(1.85,y,6.4),.32,'Ochre')
    box('Cargo platform',(0,0,2.10),(3.38,3.02,.35),'Slate')
    for x in (-1.52,1.52):
        box('Safety curb',(x,0,2.40),(.19,2.95,.26),'Ochre')
        beam('Hoist cable',(x,0,2.4),(x,0,6.15),.045,'Steel')
    cylinder('Hoist drum',(0,0,6.15),.35,2.20,'Graphite','X',vertices=16)
    box('Lift control pedestal',(2.04,-1.2,.88),(.48,.46,1.15),'Teal')
    box('Lift call indicator',(2.04,-1.45,1.12),(.24,.04,.19),'Amber')


def crew_quarters_cutaway():
    box('Habitat deck',(0,0,.15),(4.8,6.2,.3),'Slate')
    box('Rear pressure bulkhead',(0,2.93,1.58),(4.8,.28,2.85),'Ivory')
    box('Port pressure bulkhead',(-2.26,0,1.58),(.28,5.6,2.85),'Ivory')
    for x in (-1.28,1.28):
        box('Bunk frame',(x,1.86,.66),(1.18,1.9,.38),'Teal')
        box('Lower sleeping pad',(x,1.86,.91),(1.08,1.77,.18),'Sand')
        box('Pillow',(x,2.47,1.05),(.82,.35,.15),'Ivory')
        box('Upper bunk frame',(x,1.86,1.98),(1.18,1.9,.22),'Steel')
        box('Upper sleeping pad',(x,1.86,2.17),(1.08,1.77,.18),'Sand')
        for y in (.96,2.75):
            beam('Bunk support',(x-.56,y,.45),(x-.56,y,2.2),.10,'Steel')
        for z in (.55,.88,1.21,1.54,1.87):
            beam('Bunk ladder rung',(x-.52,.83,z),(x-.12,.83,z),.06,'Ochre')
    box('Galley cabinet',(-1.68,-1.28,.75),(1.05,1.7,1.2),'Teal')
    box('Galley worktop',(-1.68,-1.28,1.39),(1.12,1.82,.12),'Steel')
    box('Fold-down table',(.64,-1.26,.89),(1.2,1.2,.12),'Ivory')
    beam('Table leg',(.64,-1.26,.3),(.64,-1.26,.83),.15,'Steel')
    for y in (-2.12,-.40):
        box('Seat cushion',(.64,y,.58),(.91,.42,.22),'Teal')
        box('Seat base',(.64,y,.35),(.78,.36,.30),'Graphite')
    box('Viewport inset',(0,2.76,2.25),(.9,.055,.48),'Ocean')
    box('Ceiling light housing',(0,2.64,2.82),(1.55,.30,.15),'Steel')
    box('Ceiling light strip',(0,2.45,2.78),(1.35,.06,.09),'Cyan')



def medical_triage_bay():
    box('Triage deck',(0,0,.14),(5.6,5.4,.28),'Slate')
    box('Rear bulkhead',(0,2.56,1.57),(5.6,.28,2.86),'Ivory')
    box('Partition',(-2.66,.45,1.57),(.28,3.95,2.86),'Ivory')
    for x in (-1.43,1.43):
        box('Treatment bed base',(x,.38,.52),(.72,1.65,.54),'Graphite')
        box('Treatment bed frame',(x,.38,.88),(1.05,2.22,.19),'Steel')
        box('Sterile mattress',(x,.38,1.02),(.92,2.08,.18),'Ivory')
        box('Head cushion',(x,1.14,1.17),(.78,.42,.12),'Teal')
        for y in (-.3,.63):
            beam('Bed safety rail',(x-.54,y,.99),(x-.54,y,1.28),.055,'Steel')
        box('Bedside monitor pedestal',(x+.76,1.18,.75),(.32,.36,1.25),'Teal')
        box('Monitor housing',(x+.76,1.18,1.43),(.53,.28,.39),'Graphite')
        box('Vitals screen',(x+.76,1.025,1.43),(.43,.035,.25),'Cyan',.01)
    for x in (-1.78,0,1.78):
        box('Rear medical locker',(x,2.15,1.12),(1.12,.55,1.92),'Teal')
        box('Locker pull',(x,1.85,1.27),(.23,.07,.05),'Steel')
    for x in (-.5,.5):
        box('Triage station counter',(x,-1.9,.94),(.92,.62,.18),'Ivory')
        box('Counter support',(x,-1.9,.48),(.67,.49,.77),'Steel')
    for x in (-1.8,1.8):
        box('Overhead examination light',(x,.4,2.72),(.82,.52,.15),'Steel')
        beam('Examination light mount',(x,2.47,2.78),(x,.4,2.78),.10,'Steel')
        box('Examination diffuser',(x,.4,2.62),(.67,.4,.04),'Cyan')


def cryogenic_freight_vault():
    box('Refrigerated container skid',(0,0,.2),(4.3,5.0,.4),'Graphite')
    for x in (-2.0,2.0):
        box('Insulated vault sidewall',(x,0,1.62),(.26,4.9,2.48),'Ivory')
        for y in (-1.8,-.9,0,.9,1.8):
            box('Structural wall rib',(x,y,1.64),(.38,.13,2.55),'Steel')
    box('Insulated roof',(0,0,2.92),(4.28,4.95,.26),'Ivory')
    box('Rear refrigeration bulkhead',(0,2.31,1.6),(3.85,.36,2.47),'Teal')
    for x in (-1.05,1.05):
        cylinder('Refrigerant pressure reservoir',(x,2.59,1.6),.32,1.55,'Steel',vertices=16)
        ring('Reservoir mounting clamp',(x,2.59,1.21),.32,.045,'Copper')
    beam('External coolant header',(-1.05,2.59,2.44),(1.05,2.59,2.44),.13,'Copper')
    for x in (-1.40,1.40):
        box('Interior cold storage shelf',(x,.15,.82),(.84,3.7,.19),'Steel')
        box('Interior upper shelf',(x,.15,1.85),(.84,3.7,.19),'Steel')
        for y in (-1.20,.05,1.30):
            box('Sealed cold freight case',(x,y,1.14),(.71,1.08,.45),'Ocean')
            box('Cold freight status',(x,y-.55,1.14),(.38,.025,.09),'Cyan')
    for x in (-1.47,1.47):
        leaf=box('Open insulated door leaf',(x,-2.93,1.62),(1.08,.22,2.40),'Teal')
        leaf.rotation_euler.z=(-1 if x<0 else 1)*.73
    box('Temperature controller',(1.91,-2.49,1.82),(.36,.18,.47),'Graphite')
    box('Temperature status',(1.91,-2.60,1.88),(.25,.04,.15),'Cyan')


def atmospheric_processor():
    cylinder('Anchored foundation',(0,0,.20),2.05,.40,'Graphite',vertices=32)
    cylinder('Central compression housing',(0,0,1.40),.84,2.08,'Teal',vertices=24)
    cylinder('Filter stack',(0,0,2.89),.70,1.19,'Ivory',vertices=24)
    for z in (.55,1.72,2.55,3.35):
        ring('Compression casing seam',(0,0,z),.84 if z<2.5 else .7,.075,'Steel')
    for i in range(4):
        angle=i*PI/2
        x,y=1.35*math.cos(angle),1.35*math.sin(angle)
        cylinder('Radial intake tower',(x,y,1.2),.38,1.75,'Ivory',vertices=16)
        cylinder('Intake plenum',(x,y,2.13),.48,.32,'Graphite',vertices=16)
        for z in (1.98,2.08,2.18,2.28):
            ring('Intake grille ring',(x,y,z),.47,.034,'Steel')
        beam('Intake pipe',(x,y,.63),(x*.46,y*.46,.63),.17,'Copper')
        beam('Compression brace',(x,y,.32),(x*.45,y*.45,1.65),.13,'Steel')
    cylinder('Purified gas exhaust',(0,0,3.68),.41,.57,'Steel',vertices=24)
    ring('Exhaust aperture rim',(0,0,3.97),.42,.08,'Ochre')
    cylinder('Exhaust aperture',(0,0,3.98),.32,.035,'Graphite',vertices=24)
    box('Environmental control cabinet',(.65,-1.20,.80),(.70,.58,1.15),'Teal')
    box('Air-quality status',(.65,-1.51,1.05),(.48,.035,.22),'Cyan')
    for i in range(8):
        a=i*PI/4
        cylinder('Anchor bolt',(1.88*math.cos(a),1.88*math.sin(a),.45),.08,.13,'Ochre',vertices=8)



def surface_drill_rig():
    box('Tracked foundation frame',(0,0,.32),(4.8,5.8,.48),'Graphite')
    for x in (-1.95,1.95):
        box('Crawler tread chassis',(x,0,.45),(.78,5.0,.82),'Slate',.24)
        for y in (-1.95,-1.25,-.55,.15,.85,1.55):
            cylinder('Crawler road wheel',(x*1.16,y,.44),.29,.16,'Steel','X',vertices=16)
        for y in (-2.65,2.65):
            box('Outrigger jack foot',(x,y,.12),(.86,.68,.18),'Ochre')
            cylinder('Leveling jack',(x,y,.50),.13,.65,'Steel',vertices=16)
    box('Rotary table deck',(0,.62,.77),(2.45,2.35,.35),'Teal')
    ring('Bore aperture',(0,.62,1.0),.58,.12,'Steel')
    for x in (-.88,.88):
        for y in (.0,1.24):
            beam('Drill mast upright',(x,y,.95),(x*.67,y,5.45),.18,'Ochre')
        for z in (1.4,2.65,3.9):
            beam('Mast diagonal brace',(x,0,z),(x*.85,1.24,z+1.18),.10,'Steel')
    box('Crown block',(0,.62,5.46),(1.48,1.57,.32),'Slate')
    cylinder('Hoist drum',(0,.62,5.17),.27,1.05,'Copper','X',vertices=20)
    cylinder('Drill string',(0,.62,2.45),.17,4.60,'Steel',vertices=16)
    cylinder('Rotary drive head',(0,.62,3.70),.42,.54,'Teal')
    for z in (1.35,2.20,3.05):
        ring('Threaded tool coupling',(0,.62,z),.19,.045,'Copper')
    cylinder('Cutting bit',(0,.62,.25),.30,.54,'Graphite',radius2=.16,vertices=12)
    box('Operator control cabin',(-.95,-1.88,1.63),(1.30,1.45,1.52),'Ivory')
    box('Cabin forward window',(-.95,-2.62,1.89),(1.05,.06,.57),'Teal')
    box('Drive power pack',(1.05,-1.76,1.36),(1.65,1.72,1.02),'Ochre')
    for y in (-2.2,-1.9,-1.6,-1.3):
        box('Power cooling grille',(1.89,y,1.4),(.04,.11,.61),'Graphite')
    for x in (-.8,.8):
        box('Mast work lamp',(x,-.08,5.10),(.32,.20,.16),'Cyan')


def communications_relay_satellite():
    cylinder('Octagonal relay bus',(0,0,0),.77,1.95,'Ivory','Y',vertices=8)
    for y in (-.88,.88):
        cylinder('Bus end flange',(0,y,0),.83,.13,'Graphite','Y',vertices=8)
    for x in (-1,1):
        beam('Antenna outrigger',(x*.55,0,0),(x*2.68,0,0),.13,'Steel')
        cylinder('Array gimbal',(x*1.35,0,0),.21,.35,'Copper','X',vertices=16)
        box('Phased array panel',(x*2.10,0,.12),(1.52,1.48,.15),'Graphite')
        for i in range(5):
            for j in range(5):
                box('Radiating patch',(x*2.10+(i-2)*.265,(j-2)*.25,.223),(.20,.19,.05),'Copper',.01)
        box('Array electronics spine',(x*2.1,0,-.03),(.32,1.40,.16),'Teal')
    for side in (-1,1):
        a=side*.58
        beam('Crosslink antenna strut',(a,.58,.35),(side*.95,1.18,1.20),.10,'Steel')
        cylinder('Crosslink transmitter',(side*.95,1.18,1.20),.22,.38,'Teal','Z',vertices=16)
        cylinder('Crosslink face',(side*.95,1.18,1.41),.16,.045,'Cyan',vertices=16)
    beam('High gain feed mast',(0,-.72,.45),(0,-1.45,1.38),.09,'Steel')
    cylinder('High gain antenna aperture',(0,-1.48,1.45),.48,.18,'Ivory','Y',.24,32)
    ring('Aperture rim',(0,-1.60,1.45),.42,.05,'Steel','Y')
    cylinder('Aperture receiver',(0,-1.69,1.45),.13,.15,'Cyan','Y')
    for x in (-.45,.45):
        cylinder('Attitude control nozzle',(x,1.07,-.23),.16,.25,'Graphite','Y',.09,12)
    box('Relay status stripe',(0,-.99,-.32),(.55,.04,.12),'Amber')


def emergency_escape_capsule():
    cylinder('Capsule heat shield',(0,0,.18),1.40,.36,'Graphite',radius2=1.22,vertices=32)
    cylinder('Pressure shell lower',(0,0,.87),1.22,1.08,'Ivory',radius2=1.02,vertices=24)
    cylinder('Tapered upper cabin',(0,0,1.70),1.02,.58,'Ochre',radius2=.67,vertices=24)
    cylinder('Recovery nose cap',(0,0,2.13),.67,.28,'Ivory',radius2=.40,vertices=24)
    ring('Separation collar',(0,0,.40),1.23,.06,'Copper')
    ring('Cabin join seam',(0,0,1.37),1.04,.05,'Steel')
    box('Side escape hatch',(0,-1.08,1.03),(.82,.19,1.12),'Slate',.15)
    box('Hatch rescue marking',(0,-1.19,.81),(.58,.025,.14),'Ochre')
    cylinder('Hatch porthole frame',(0,-1.18,1.29),.24,.11,'Steel','Y',vertices=24)
    cylinder('Porthole glazing',(0,-1.25,1.29),.17,.045,'Teal','Y',vertices=24)
    beam('External hatch handle',(-.18,-1.23,.99),(.18,-1.23,.99),.065,'Steel')
    for i in range(3):
        a=PI/2+i*2*PI/3
        x,y=math.cos(a),math.sin(a)
        beam('Landing leg',(x*.93,y*.93,.56),(x*1.67,y*1.67,.20),.15,'Steel')
        beam('Landing brace',(x*.76,y*.76,1.0),(x*1.50,y*1.50,.28),.09,'Ochre')
        box('Landing foot',(x*1.67,y*1.67,.10),(.40,.40,.18),'Graphite')
        cylinder('Rescue beacon',(x*.73,y*.73,1.82),.11,.15,'Amber',vertices=12)
    cylinder('Recovery transponder',(0,0,2.35),.10,.25,'Steel')
    cylinder('Transponder indicator',(0,0,2.50),.14,.09,'Cyan')
    for x in (-.55,.55):
        cylinder('Descent thruster nozzle',(x,.80,.47),.19,.32,'Steel','Y',.12,16)



def observation_dome():
    # Open cutaway with a curved observation canopy and an unobstructed entry.
    cylinder('Octagonal habitat foundation',(0,0,.15),3.15,.30,'Graphite',vertices=12)
    cylinder('Observation floor',(0,0,.34),2.89,.10,'Slate',vertices=12)
    for i in range(9):
        a=(i+1)*PI/6
        x,y=math.cos(a),math.sin(a)
        for j in range(5):
            p=j*PI/10;q=(j+1)*PI/10
            beam('Canopy meridian',(2.85*x*math.cos(p),2.85*y*math.cos(p),.4+2.65*math.sin(p)),
                 (2.85*x*math.cos(q),2.85*y*math.cos(q),.4+2.65*math.sin(q)),.095,'Ivory')
    for i in range(1,9):
        a=i*PI/6;b=(i+1)*PI/6
        for p in (.26,.78,1.30):
            q=p+.25
            verts=[(2.79*math.cos(t)*math.cos(v),2.79*math.sin(t)*math.cos(v),.4+2.62*math.sin(v))
                   for t,v in ((a,p),(b,p),(b,q),(a,q))]
            mesh=bpy.data.meshes.new('Canopy glazing');mesh.from_pydata(verts,[],[(0,1,2,3)]);mesh.update()
            obj=bpy.data.objects.new('Tinted observation pane',mesh);bpy.context.collection.objects.link(obj)
            finish(obj,obj.name,'Teal')
    cylinder('Central observation plinth',(0,0,.55),.65,.32,'Steel',vertices=12)
    cylinder('Star chart projection',(0,0,.73),.51,.05,'Cyan',vertices=24)
    for a in (PI/3,PI,5*PI/3):
        x,y=1.72*math.cos(a),1.72*math.sin(a)
        seat=box('Observation bench',(x,y,.72),(1.25,.42,.22),'Ivory')
        seat.rotation_euler.z=a+PI/2
        box('Bench support',(x,y,.50),(.32,.32,.36),'Graphite')
    for x in (-.9,.9):
        box('Entry jamb',(x,-2.48,1.06),(.18,.25,1.44),'Ochre')
    box('Entry lintel',(0,-2.48,1.82),(1.98,.25,.17),'Ochre')


def freight_rail_junction():
    # Three separate track branches, central switch linkage and freight signal.
    box('Ballast slab',(0,0,.10),(7.4,7.6,.20),'Basalt')
    for y in (-3.5,-2.9,-2.3,-1.7,-1.1,-.5,.1,.7,1.3,1.9,2.5,3.1):
        shift=max(0,y)*.58
        box('Main track sleeper',(0,y,.27),(1.70,.22,.16),'Slate')
        if y>.1:
            box('Branch track sleeper',(shift,y,.27),(1.7,.22,.16),'Slate')
            box('Branch track sleeper',(-shift,y,.27),(1.7,.22,.16),'Slate')
    for x in (-.55,.55):
        beam('Straight rail',(x,-3.75,.43),(x,3.75,.43),.14,'Steel')
        for side in (-1,1):
            beam('Diverging branch rail',(x,-.7,.43),(x+side*2.18,3.75,.43),.14,'Steel')
    box('Switch drive housing',(1.32,-.80,.53),(.60,.96,.55),'Ochre')
    beam('Switch actuator',(1.32,-.80,.55),(.12,-.80,.43),.09,'Copper')
    for x in (-2.70,2.70):
        box('Signal pedestal',(x,-2.40,.38),(.47,.47,.36),'Graphite')
        cylinder('Signal mast',(x,-2.40,1.22),.085,1.65,'Steel')
        box('Signal head',(x,-2.40,2.05),(.31,.25,.56),'Graphite')
        cylinder('Signal lens',(x,-2.545,2.15),.10,.05,'Cyan','Y')
        cylinder('Signal lens',(x,-2.545,1.95),.10,.05,'Amber','Y')
    for x in (-3.1,3.1):
        box('Maintenance walkway',(x,.20,.29),(.40,6.8,.18),'Graphite')
        for y in (-2.6,-1.3,0,1.3,2.6):
            box('Walkway edge marker',(x,y,.39),(.36,.08,.03),'Ochre')


def geothermal_station():
    # Closed-loop settlement generator with wellheads, turbine and heat rejection.
    box('Plant foundation',(0,0,.12),(7.0,5.4,.24),'Graphite')
    for x in (-2.40,2.40):
        cylinder('Wellhead pressure collar',(x,-1.55,.52),.55,.64,'Steel',vertices=16)
        cylinder('Wellhead casing',(x,-1.55,1.08),.31,.65,'Copper')
        ring('Wellhead control wheel',(x,-1.55,1.49),.31,.045,'Ochre')
        beam('Vertical brine pipe',(x,-1.55,1.28),(x,-1.55,2.05),.23,'Copper')
        beam('Brine pipe header',(x,-1.55,2.05),(x,.35,2.05),.23,'Copper')
        beam('Brine downcomer',(x,.35,2.05),(x,.35,1.20),.23,'Copper')
    box('Turbine mounting frame',(0,.10,.47),(3.65,2.40,.45),'Slate')
    cylinder('Turbine housing',(0,.12,1.25),.80,2.60,'Teal','X')
    for x in (-1.29,1.29):
        ring('Turbine bolted flange',(x,.12,1.25),.81,.085,'Steel','X')
    cylinder('Generator end bell',(1.55,.12,1.25),.58,.50,'Ochre','X')
    for x in (-2.4,2.4):
        beam('Turbine supply manifold',(x,.35,1.20),(x/2,.35,1.20),.23,'Copper')
    for x in (-1.8,0,1.8):
        box('Air-cooled heat exchanger',(x,1.88,1.28),(1.38,.58,1.68),'Steel')
        for z in (.62,.87,1.12,1.37,1.62,1.87):
            box('Radiator fin',(x,1.55,z),(1.28,.11,.095),'Graphite')
        beam('Return line',(x,1.88,.46),(x,.67,.46),.16,'Copper')
    box('Switchgear cabinet',(0,-1.65,.87),(1.08,.64,1.25),'Ivory')
    box('Generator status display',(0,-1.985,1.03),(.66,.04,.25),'Cyan')
    for x in (-.30,0,.30):
        box('Isolation switch',(x,-1.985,.73),(.12,.045,.16),'Ochre')



def habitat_command_center():
    box('Raised operations deck',(0,0,.18),(7.8,6.2,.36),'Graphite')
    for x in (-3.65,3.65):
        box('Side bulkhead',(x,.85,1.45),(.25,4.1,2.5),'Slate')
        for y in (-.9,1.9):
            box('Bulkhead rib',(x,y,1.48),(.42,.23,2.58),'Steel')
    box('Rear bulkhead',(0,2.86,1.45),(7.4,.26,2.5),'Slate')
    box('Operations display wall',(0,2.66,1.79),(5.6,.15,1.6),'Graphite')
    for x in (-1.82,0,1.82):
        box('Mission status screen',(x,2.56,1.88),(1.68,.055,1.16),'Teal')
        for z,w in ((1.51,1.27),(1.77,.74),(2.04,1.38)):
            box('Illuminated status track',(x,2.515,z),(w,.025,.045),'Cyan',0)
    cylinder('Circular command table',(0,.2,.9),1.18,.18,'Ivory',vertices=32)
    cylinder('Table pedestal',(0,.2,.57),.38,.62,'Graphite')
    ring('Tactical projection rim',(0,.2,1.02),.91,.055,'Cyan')
    for i in range(6):
        a=i*PI/3
        cylinder('Map marker',(.67*math.cos(a),.2+.67*math.sin(a),1.07),.065,.09,'Amber',vertices=12)
    for x in (-2.3,2.3):
        for y in (-1.7,.95):
            box('Operator console base',(x,y,.65),(.78,.65,.65),'Slate')
            panel=box('Angled operator console',(x,y,.99),(1.17,.80,.15),'Ivory')
            panel.rotation_euler.x=.18
            screen=box('Console interface',(x,y-.06,1.085),(.83,.38,.05),'Cyan')
            screen.rotation_euler.x=.18
            box('Operator seat',(x,y-.8,.62),(.47,.47,.13),'Teal')
            box('Seat back',(x,y-1.02,.88),(.47,.12,.49),'Graphite')
            cylinder('Seat pedestal',(x,y-.8,.40),.12,.42,'Steel')
    for x in (-1.4,1.4):
        box('Access lane strip',(x,-2.5,.38),(.08,1.0,.04),'Ochre')
    for x in (-3.28,3.28):
        box('Overhead light rail',(x,.8,2.60),(.10,3.8,.09),'Cyan')


def surface_weather_station():
    box('Instrument foundation',(0,0,.15),(4.8,4.2,.30),'Slate')
    box('Weather electronics cabinet',(-1.22,.72,.85),(1.35,1.12,1.32),'Ivory')
    box('Cabinet telemetry display',(-1.22,.13,1.04),(.74,.05,.30),'Cyan')
    for x in (-1.6,-.85):
        box('Cabinet latch',(x,.10,.64),(.075,.08,.25),'Ochre')
    cylinder('Meteorological tower',(.88,.56,2.12),.10,3.85,'Steel')
    for a in (0,2*PI/3,4*PI/3):
        p=(.88+1.12*math.cos(a),.56+1.12*math.sin(a),.32)
        beam('Tower diagonal brace',p,(.88,.56,2.35),.09,'Ochre')
    cylinder('Anemometer shaft',(.88,.56,4.12),.065,.34,'Graphite')
    for a in (0,2*PI/3,4*PI/3):
        p=(.88+.47*math.cos(a),.56+.47*math.sin(a),4.30)
        beam('Wind rotor spoke',(.88,.56,4.30),p,.055,'Steel')
        cylinder('Rotor cup',p,.13,.17,'Ochre',vertices=16)
    beam('Wind vane cross arm',(.88,.56,3.53),(1.79,.56,3.53),.075,'Steel')
    box('Wind vane tail',(1.74,.56,3.66),(.28,.08,.36),'Ivory')
    beam('Radiation sensor arm',(.88,.56,2.64),(.18,.56,2.64),.075,'Steel')
    cylinder('Radiometer',(.18,.56,2.75),.18,.18,'Cyan',vertices=20)
    cylinder('Precipitation collector',(1.45,-1.1,.95),.34,1.24,'Steel',radius2=.43)
    ring('Collector rim',(1.45,-1.1,1.59),.43,.055,'Ochre')
    for z in (.78,.94,1.10,1.26,1.42):
        cylinder('Ventilated temperature shield',(-.25,-.95,z),.31,.075,'Ivory',radius2=.25)
    cylinder('Temperature sensor support',(-.25,-.95,.62),.07,.65,'Steel')
    box('Ground monitoring panel',(-1.1,-1.42,.53),(1.1,.70,.14),'Teal')
    for x in (-1.48,-1.10,-.72):
        box('Panel cell stripe',(x,-1.42,.61),(.035,.62,.025),'Copper')


def orbital_fuel_depot():
    cylinder('Depot axial bus',(0,0,0),.66,7.8,'Graphite','Y')
    for y in (-3.4,0,3.4):
        ring('Axial reinforcement flange',(0,y,0),.78,.14,'Steel','Y')
    for side in (-1,1):
        x=side*1.88
        for y in (-1.76,1.76):
            cylinder('Cryogenic propellant tank',(x,y,0),.85,2.65,'Ivory','Y',vertices=32)
            for dy in (-1.33,1.33):
                cylinder('Tank dished end',(x,y+dy,0),.85,.30,'Steel','Y',radius2=.64,vertices=32)
                ring('Tank retaining band',(x,y+dy*.72,0),.88,.09,'Ochre','Y')
            beam('Tank mounting truss',(side*.45,y,-.48),(x,y,-.48),.22,'Slate')
            beam('Tank upper mounting truss',(side*.45,y,.48),(x,y,.48),.22,'Slate')
            beam('Propellant transfer line',(x,y,.85),(side*.56,y,.85),.13,'Copper')
            cylinder('Isolating valve',(side*1.10,y,.85),.19,.20,'Ochre','X')
        box('Radiator spine',(side*3.0,0,0),(.25,5.6,.20),'Slate')
        for y in (-1.8,0,1.8):
            box('Radiator support',(side*2.70,y,0),(.75,.15,.18),'Steel')
            box('Thermal rejection panel',(side*3.22,y,0),(.62,1.58,.10),'Teal')
            for dy in (-.52,-.26,0,.26,.52):
                box('Radiator fin',(side*3.22,y+dy,.07),(.58,.035,.045),'Copper',0)
    for y in (-4.05,4.05):
        cylinder('Transfer docking collar',(0,y,0),.74,.37,'Steel','Y')
        ring('Docking guide rim',(0,y+math.copysign(.22,y),0),.57,.105,'Cyan','Y')
        cylinder('Recessed transfer port',(0,y+math.copysign(.20,y),0),.40,.08,'Graphite','Y')
    box('Depot telemetry module',(0,0,1.02),(1.02,1.50,.64),'Teal')
    box('Telemetry status strip',(0,-.77,1.02),(.65,.06,.18),'Cyan')
    cylinder('Navigation beacon',(0,0,1.62),.10,.62,'Steel')
    cylinder('Beacon light',(0,0,1.98),.14,.12,'Amber')



def regolith_sintering_kiln():
    # Surface construction materials: open feed hopper, continuous belt, insulated furnace and cooling rack.
    box('Kiln skid',(0,0,.18),(8.4,3.8,.36),'Graphite')
    for x in (-3.4,-2.0,0,2.0,3.4):
        for y in (-.76,.76):
            box('Conveyor pedestal',(x,y,.55),(.20,.24,.50),'Steel')
    box('Continuous conveyor bed',(0,0,.85),(7.6,1.62,.22),'Slate')
    for x in (-3.55,-3.18,-2.81,-2.44,-2.07,2.07,2.44,2.81,3.18,3.55):
        cylinder('Conveyor roller',(x,0,1.00),.095,1.49,'Steel','Y',vertices=12)
    for y in (-.83,.83):
        box('Conveyor guard',(0,y,1.05),(7.55,.10,.24),'Ochre')
        box('Hopper side plate',(-2.8,y*.87,1.85),(1.62,.16,1.10),'Ochre').rotation_euler.x=y*.29
    for x in (-3.60,-2.00):
        box('Hopper end plate',(x,0,1.85),(.15,1.48,1.10),'Steel').rotation_euler.y=(x+2.8)*.27
    for x,y,r in ((-3.1,-.22,.28),(-2.7,.27,.32),(-2.45,-.25,.24)):
        bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1,radius=r,location=(x,y,1.65))
        finish(bpy.context.object,'Unprocessed regolith','Stone')
    for y in (-1.12,1.12):
        box('Insulated furnace wall',(0,y,1.92),(3.35,.43,2.08),'Ivory',.13)
        for x in (-1.35,-.45,.45,1.35):
            box('Thermal jacket rib',(x,y*1.17,1.92),(.13,.15,1.88),'Steel')
    box('Refractory furnace roof',(0,0,3.02),(3.35,2.65,.36),'Teal')
    for x in (-1.61,1.61):
        box('Portal lintel',(x,0,2.42),(.22,2.12,.45),'Graphite')
        box('Furnace heat indicator',(x,0,2.12),(.23,1.42,.08),'Amber')
    cylinder('Filtered exhaust stack',(.55,.46,3.53),.25,.94,'Steel')
    cylinder('Exhaust hood',(.55,.46,4.04),.37,.18,'Ochre')
    for x in (2.25,2.95,3.50):
        for y in (-.36,.36):
            box('Sintered construction brick',(x,y,1.19),(.52,.56,.26),'Sand',.035)
    box('Kiln controller',(0,-1.62,1.0),(1.05,.46,1.35),'Slate')
    box('Process monitor',(0,-1.87,1.27),(.65,.05,.32),'Cyan')
    for x in (-.29,0,.29):
        cylinder('Control switch',(x,-1.89,.85),.065,.06,'Amber','Y',vertices=12)


def sample_analysis_laboratory():
    # Walk-in assay room: open front, microscopes, glovebox and sample carousel.
    box('Laboratory raised floor',(0,0,.15),(6.8,5.4,.30),'Slate')
    box('Rear service bulkhead',(0,2.58,1.48),(6.8,.24,2.66),'Ivory')
    for x in (-3.29,3.29):
        box('Side service bulkhead',(x,1.1,1.48),(.22,3.1,2.66),'Ivory')
        box('Utility channel',(x,1.1,2.48),(.30,3.0,.16),'Teal')
    for x in (-1.80,1.80):
        box('Laboratory bench cabinet',(x,1.66,.72),(2.75,1.10,.84),'Teal')
        box('Chemical-resistant countertop',(x,1.66,1.19),(2.86,1.24,.12),'Graphite')
        for dx in (-.86,0,.86):
            box('Cabinet door',(x+dx,1.08,.72),(.78,.055,.64),'Ivory')
            box('Cabinet pull',(x+dx,1.03,.89),(.19,.08,.05),'Steel')
    for x in (-2.48,-1.42):
        cylinder('Microscope stage',(x,1.54,1.34),.25,.15,'Steel')
        beam('Microscope support',(x,1.85,1.34),(x,1.82,1.96),.15,'Ivory')
        beam('Optical head',(x,1.82,1.96),(x,1.44,1.83),.19,'Teal')
        cylinder('Objective lens',(x,1.44,1.63),.09,.20,'Graphite')
        box('Sample slide',(x,1.54,1.45),(.22,.16,.025),'Cyan')
    box('Glovebox housing',(1.8,1.66,1.72),(2.45,1.02,1.04),'Slate')
    box('Observation window',(1.8,1.125,1.84),(2.16,.055,.59),'Teal')
    for x in (1.29,2.31):
        ring('Glove port',(x,1.07,1.57),.18,.045,'Steel','Y')
        cylinder('Glove port seal',(x,1.06,1.57),.15,.07,'Graphite','Y')
    box('Sample island base',(0,-.62,.66),(2.6,1.38,.72),'Ivory')
    box('Sample island worktop',(0,-.62,1.09),(2.75,1.50,.14),'Graphite')
    cylinder('Indexing sample carousel',(0,-.62,1.26),.56,.18,'Steel',vertices=32)
    for i in range(8):
        a=i*PI/4
        x,y=.40*math.cos(a),-.62+.40*math.sin(a)
        cylinder('Sealed sample vial',(x,y,1.46),.075,.26,'Cyan' if i%2 else 'Copper',vertices=12)
        cylinder('Sample vial cap',(x,y,1.61),.082,.05,'Ivory',vertices=12)
    for x in (-2.5,2.5):
        box('Instrument readout',(x,2.42,2.02),(1.10,.10,.57),'Graphite')
        box('Assay display',(x,2.35,2.02),(.94,.045,.43),'Cyan')
    for x in (-2.8,2.8):
        box('Overhead laboratory light',(x,1.0,2.78),(.12,2.4,.10),'Cyan')


def modular_footbridge():
    # Open pedestrian span with landing interfaces, guardrails and under-deck trusses.
    for x in (-3.65,3.65):
        box('Habitat connection landing',(x,0,.22),(1.4,2.7,.44),'Slate')
        for y in (-.9,.9):
            box('Landing foot',(x,y,-.16),(.68,.65,.32),'Graphite')
        box('Connection threshold',(x,0,.46),(1.12,2.35,.06),'Ochre')
    for y in (-1.04,1.04):
        beam('Upper span chord',(-3.0,y,.38),(3.0,y,.38),.21,'Steel')
        beam('Lower span chord',(-3.0,y,-.62),(3.0,y,-.62),.19,'Teal')
        for i in range(6):
            x=-3.0+i
            beam('Truss web diagonal',(x,y,-.62 if i%2==0 else .38),(x+1,y,.38 if i%2==0 else -.62),.14,'Steel')
        for x in (-3,-2,-1,0,1,2,3):
            beam('Guardrail upright',(x,y,.47),(x,y,1.57),.11,'Ivory')
        beam('Continuous handrail',(-3.2,y,1.56),(3.2,y,1.56),.13,'Ivory')
        beam('Intermediate guardrail',(-3.0,y,1.0),(3.0,y,1.0),.09,'Steel')
        for x in (-2.5,-.5,1.5,2.5):
            box('Edge marker lamp',(x,y,.58),(.29,.12,.10),'Cyan')
    for i in range(12):
        x=-2.75+.50*i
        box('Replaceable walking deck panel',(x,0,.40),(.48,2.02,.18),'Graphite',.02)
        box('Anti-slip tread',(x,0,.51),(.10,1.70,.028),'Steel',0)
    for x in (-2.5,-.5,1.5,2.5):
        beam('Underdeck cross brace',(x,-1.04,-.62),(x,1.04,-.62),.15,'Steel')
    for x in (-3.65,3.65):
        for y in (-1.14,1.14):
            cylinder('Landing bollard',(x,y,.77),.10,.58,'Ochre',vertices=12)
            cylinder('Landing marker',(x,y,1.08),.085,.08,'Amber',vertices=12)



def deepwater_survey_submersible():
    # Compact science vehicle; forward viewport, ballast tanks, skids and a sample arm.
    body=cylinder('Pressure vessel',(0,0,0),.90,3.25,'Ivory','Y',vertices=32)
    cylinder('Forward pressure cap',(0,-1.68,0),.90,.42,'Teal','Y',.65,vertices=32)
    ring('Viewport retaining flange',(0,-1.94,0),.47,.09,'Steel','Y')
    cylinder('Forward observation glass',(0,-2.00,0),.43,.12,'Cyan','Y',vertices=32)
    for side in (-1,1):
        x=side*1.10
        cylinder('Ballast cylinder',(x,.12,.12),.39,2.65,'Ochre','Y',vertices=24)
        for y in (-.85,.85):
            ring('Ballast retaining band',(x,y,.12),.40,.052,'Graphite','Y')
            beam('Ballast bracket',(side*.64,y,.12),(x,y,.12),.17,'Steel')
        cylinder('Shrouded water thruster',(x,1.60,.12),.39,.52,'Graphite','Y')
        ring('Thruster guard',(x,1.89,.12),.31,.055,'Steel','Y')
        for i in range(4):
            a=i*PI/2
            beam('Impeller blade',(x,1.9,.12),(x+.25*math.cos(a),1.9,.12+.25*math.sin(a)),.075,'Teal')
        box('Seabed skid',(side*.82,0,-1.02),(.26,3.5,.18),'Steel',.06)
        for y in (-1.13,1.13):
            beam('Skid stanchion',(side*.82,y,-1),(side*.57,y,-.46),.14,'Steel')
        cylinder('Survey floodlight',(side*.65,-1.75,.49),.16,.18,'Graphite','Y')
        cylinder('Floodlight lens',(side*.65,-1.86,.49),.13,.055,'Ivory','Y')
    cylinder('Dorsal hatch',(0,.43,.92),.34,.17,'Steel')
    cylinder('Acoustic beacon',(0,.43,1.23),.09,.46,'Amber')
    beam('Sampler shoulder',(.53,-1.19,-.55),(1.06,-1.82,-.63),.20,'Ochre')
    beam('Sampler elbow',(1.06,-1.82,-.63),(.81,-2.38,-.95),.15,'Steel')
    cylinder('Sampler wrist',(.81,-2.38,-.95),.13,.18,'Graphite','Y')
    for x in (.70,.92):
        beam('Sample claw',(x,-2.42,-.95),(x,-2.68,-1.08),.075,'Steel')
    box('Sample basket',(-.70,-1.14,-.69),(.66,.72,.33),'Teal')
    for y in (-1.37,-.91):
        box('Basket rim',(-.70,y,-.47),(.70,.08,.10),'Steel')


def orbital_optical_observatory():
    # Long open optical truss, primary mirror assembly, instrument bus and sunshade.
    cylinder('Instrument bus',(0,0,-.90),1.12,1.1,'Slate',vertices=12)
    cylinder('Primary mirror support',(0,0,-.22),1.45,.36,'Steel',vertices=48)
    for i in range(18):
        a=2*PI*i/18
        x,y=1.04*math.cos(a),1.04*math.sin(a)
        tile=cylinder('Segmented primary mirror',(x,y,.02),.28,.08,'Copper',vertices=6)
        tile.rotation_euler.z=a
    cylinder('Central optical aperture',(0,0,.06),.31,.08,'Graphite',vertices=32)
    for i in range(6):
        a=2*PI*i/6
        x,y=1.38*math.cos(a),1.38*math.sin(a)
        beam('Optical truss spar',(x,y,-.13),(x,y,2.55),.10,'Ivory')
        b=a+PI/3
        beam('Diagonal truss brace',(x,y,.15),(1.38*math.cos(b),1.38*math.sin(b),2.55),.075,'Steel')
    ring('Aperture ring',(0,0,2.55),1.38,.075,'Teal')
    for i in range(3):
        a=2*PI*i/3
        beam('Secondary mirror spider',(1.38*math.cos(a),1.38*math.sin(a),2.55),(0,0,2.25),.075,'Graphite')
    cylinder('Secondary mirror',(0,0,2.25),.30,.12,'Copper',vertices=24)
    for side in (-1,1):
        beam('Sunshade support',(side*.75,0,-.9),(side*2.35,0,-.9),.17,'Steel')
        box('Thermal shade panel',(side*2.45,0,-.9),(1.65,2.40,.11),'Ivory',.04)
        for y in (-.9,-.3,.3,.9):
            box('Shade stiffener',(side*2.45,y,-.82),(1.55,.045,.05),'Steel',0)
    for i in range(4):
        a=i*PI/2
        cylinder('Attitude control pod',(1.03*math.cos(a),1.03*math.sin(a),-1.23),.18,.34,'Graphite')
    box('Science telemetry transceiver',(0,-1.10,-.83),(.65,.27,.44),'Teal')
    box('Telemetry indicator',(0,-1.25,-.83),(.34,.035,.14),'Cyan')


def habitat_recreation_court():
    # Open, walkable low-gravity sports court with goals, spectator benches and scoreboard.
    box('Court structural slab',(0,0,.14),(9.0,5.8,.28),'Slate')
    box('Resilient playing surface',(0,0,.30),(8.1,4.3,.06),'Teal',.02)
    for x in (-3.92,3.92):
        box('End boundary stripe',(x,0,.345),(.065,4.0,.025),'Ivory',0)
    for y in (-1.98,1.98):
        box('Sideline stripe',(0,y,.345),(7.9,.065,.025),'Ivory',0)
    box('Center line',(0,0,.345),(.065,4.0,.025),'Ivory',0)
    ring('Center circle',(0,0,.348),.69,.026,'Ivory')
    for side in (-1,1):
        x=side*3.76
        for y in (-.78,.78):
            beam('Goal upright',(x,y,.36),(x,y,1.85),.13,'Ochre')
            beam('Goal rear stay',(x,y,1.85),(x+side*.54,y,.36),.09,'Steel')
        beam('Goal crossbar',(x,-.78,1.85),(x,.78,1.85),.13,'Ochre')
        for y in (-.60,-.30,0,.30,.60):
            beam('Goal net cord',(x,y,1.80),(x+side*.54,y,.40),.025,'Ivory')
        box('Goal padded backstop',(x+side*.59,0,.58),(.13,1.68,.45),'Graphite')
    for x in (-2.50,0,2.50):
        box('Spectator seat',(x,2.57,.68),(2.15,.45,.16),'Ivory')
        for dx in (-.78,.78):
            box('Seat mounting foot',(x+dx,2.57,.48),(.12,.36,.34),'Steel')
        box('Seat back',(x,2.77,.98),(2.15,.10,.38),'Slate')
    for x in (-3.45,3.45):
        beam('Court lighting post',(x,2.66,.32),(x,2.66,2.70),.14,'Steel')
        box('Court floodlight',(x,2.49,2.65),(.75,.35,.18),'Cyan')
    beam('Scoreboard support',(0,2.78,.32),(0,2.78,2.44),.14,'Steel')
    box('Scoreboard enclosure',(0,2.65,2.53),(2.10,.27,.65),'Graphite')
    for x in (-.57,.57):
        box('Score display',(x,2.49,2.53),(.78,.04,.43),'Cyan')
    box('Court equipment rack',(0,-2.61,.59),(1.8,.46,.53),'Slate')
    for x in (-.55,0,.55):
        bpy.ops.mesh.primitive_uv_sphere_add(segments=16,ring_count=8,radius=.17,location=(x,-2.61,.98))
        finish(bpy.context.object,'Training ball','Ochre')



def habitat_market_hall():
    box('Market foundation',(0,0,.12),(10.0,6.8,.24),'Graphite',.10)
    box('Public concourse',(0,-.65,.27),(9.7,4.9,.12),'Slate',.025)
    for i,x in enumerate((-3.25,0,3.25)):
        hue=('Teal','Ochre','Copper')[i]
        box('Vendor counter',(x,.65,.90),(2.50,.68,1.02),'Ivory')
        box('Counter worktop',(x,.65,1.46),(2.70,.82,.14),hue)
        box('Rear shelving frame',(x,2.42,1.43),(2.65,.30,2.60),'Graphite')
        for z in (.80,1.44,2.08):
            box('Stock shelf',(x,2.15,z),(2.40,.55,.10),'Steel')
            for k in range(4):
                box('Stock carton',(x-.87+k*.58,2.10,z+.18),(.42,.40,.26),('Ivory','Ochre','Teal','Slate')[(i+k)%4],.035)
        for dx in (-1.40,1.40):
            beam('Canopy pillar',(x+dx,.65,.30),(x+dx,.65,3.12),.13,'Steel')
        canopy=box('Colored canopy',(x,1.52,3.12),(2.85,2.15,.14),hue)
        canopy.rotation_euler.x=-.08
        box('Vendor illuminated sign',(x,.42,2.88),(1.58,.10,.25),'Cyan')
        box('Payment terminal',(x+.88,.57,1.61),(.28,.26,.20),'Graphite')
    cylinder('Exchange kiosk pedestal',(0,-2.05,.70),.54,.80,'Teal',vertices=8)
    cylinder('Exchange information desk',(0,-2.05,1.15),.78,.16,'Ivory',vertices=8)
    for side in (-1,1):
        box('Exchange display',(side*.30,-2.05,1.40),(.10,.48,.36),'Cyan')
        box('Concourse edge light',(side*4.75,-.70,.35),(.07,3.8,.04),'Cyan',0)
        box('Waiting bench',(side*3.15,-2.35,.58),(1.65,.55,.16),'Ivory')
        for dx in (-.55,.55):
            box('Bench leg',(side*3.15+dx,-2.35,.42),(.12,.42,.28),'Steel')


def surface_seismic_array():
    cylinder('Recorder foundation',(0,0,.14),.98,.28,'Basalt',vertices=12)
    cylinder('Sealed recorder cabinet',(0,0,.68),.62,.85,'Ivory',vertices=8)
    box('Recorder display',(0,-.58,.79),(.50,.09,.32),'Cyan')
    cylinder('Central survey mast',(0,0,1.92),.11,2.40,'Steel')
    ring('Antenna loop',(0,0,3.10),.41,.045,'Copper','X')
    cylinder('Telemetry beacon',(0,0,3.42),.10,.19,'Amber')
    for i in range(3):
        a=2*PI*i/3+PI/6
        x,y=3.25*math.cos(a),3.25*math.sin(a)
        cylinder('Seismic anchor plate',(x,y,.08),.62,.16,'Graphite',vertices=12)
        cylinder('Ground-coupled spike',(x,y,-.24),.18,.48,'Steel','Z',.32,vertices=12)
        cylinder('Sensor suspension',(x,y,.32),.31,.42,'Copper',vertices=16)
        cylinder('Seismometer enclosure',(x,y,.65),.44,.34,'Ochre',vertices=12)
        cylinder('Level bubble',(x,y,.85),.13,.06,'Cyan')
        for j in range(3):
            t=a+2*PI*j/3
            ex,ey=x+.75*math.cos(t),y+.75*math.sin(t)
            beam('Ground contact leg',(x+.32*math.cos(t),y+.32*math.sin(t),.47),(ex,ey,.10),.09,'Steel')
            cylinder('Contact foot',(ex,ey,.06),.12,.12,'Graphite',vertices=12)
        beam('Protected data conduit',(x*.21,y*.21,.09),(x*.83,y*.83,.09),.09,'Copper')
        for f in (.35,.55,.75):
            box('Cable retaining clip',(x*f,y*f,.12),(.20,.20,.12),'Slate')
        marker=box('Survey index flag',(x*.78,y*.78,.54),(.30,.08,.23),'Ivory')
        marker.rotation_euler.z=a


def orbital_passenger_ferry():
    # Two end vestibules flank an extended civilian passenger pressure cabin.
    cylinder('Passenger pressure hull',(0,0,0),1.20,6.60,'Ivory','Y',vertices=32)
    for side in (-1,1):
        y=side*3.75
        cylinder('Tapered vestibule',(0,y,0),.84,.94,'Teal','Y',1.18 if side<0 else .84,vertices=24)
        ring('Docking collar',(0,side*4.25,0),.69,.11,'Steel','Y')
        cylinder('Pressure hatch',(0,side*4.28,0),.54,.12,'Graphite','Y',vertices=24)
        for i in range(4):
            a=i*PI/2
            box('Docking alignment lug',(.75*math.cos(a),side*4.31,.75*math.sin(a)),(.18,.20,.18),'Ochre')
        for y in (-2.40,-1.60,-.80,0,.80,1.60,2.40):
            box('Passenger window surround',(side*1.10,y,.36),(.20,.61,.42),'Graphite',.08)
            box('Panoramic cabin glazing',(side*1.21,y,.36),(.05,.48,.28),'Cyan',.025)
        beam('Nacelle mounting spar',(side*.82,.98,-.55),(side*2.05,1.24,-.44),.34,'Steel')
        box('Civilian propulsion nacelle',(side*2.02,1.23,-.42),(.91,2.68,.82),'Teal',.20)
        cylinder('Nacelle forward cap',(side*2.02,-.19,-.42),.37,.23,'Ivory','Y',vertices=24)
        engine(side*2.02,2.66,-.42,.68)
        box('Passenger service stripe',(side*1.19,0,-.32),(.07,5.25,.14),'Ochre')
        for y in (-1.86,1.86):
            box('Equipment access hatch',(side*.72,y,-.94),(.55,.72,.12),'Slate')
    for y in (-2.92,2.92):
        ring('Pressure section seam',(0,y,0),1.18,.055,'Steel','Y')
    box('Dorsal equipment spine',(0,.52,1.20),(.74,2.80,.28),'Teal')
    beam('Navigation aerial',(0,-2.2,1.05),(0,-2.2,1.83),.08,'Steel')
    cylinder('Navigation beacon',(0,-2.2,1.86),.13,.12,'Amber')



def surface_storm_shelter():
    # Buried-looking ribbed shell with visible protected entrance and open cutaway.
    box('Anchored foundation',(0,0,.12),(6.4,5.2,.24),'Graphite')
    box('Interior deck',(0,0,.28),(5.6,4.5,.18),'Slate')
    for y in (-1.9,-.95,0,.95,1.9):
        points=[(-2.55,y,.35),(-2.55,y,1.4),(-1.8,y,2.45),(-.8,y,2.9),(.8,y,2.9),(1.8,y,2.45),(2.55,y,1.4),(2.55,y,.35)]
        for a,b in zip(points,points[1:]): beam('Pressure shell rib',a,b,.19,'Steel')
        for x in (-2.65,2.65):
            box('Ground anchor',(x,y,.22),(.48,.45,.22),'Ochre')
    for y in (-1.4,-.5,.4,1.3):
        box('Overhead dust armor',(0,y,2.98),(1.7,.88,.12),'Ivory')
        for x in (-2.58,2.58): box('Shielded lower wall',(x,y,.9),(.18,.88,1.02),'Teal')
    for x in (-1.65,1.65):
        box('Emergency supply locker',(x,1.55,.91),(.68,.64,1.05),'Ochre')
        box('Locker handle',(x,1.19,.95),(.18,.08,.08),'Graphite')
        box('Fold-down bench',(x,-.7,.68),(.7,1.55,.15),'Ivory')
        for y in (-1.28,-.1): box('Bench bracket',(x,y,.45),(.15,.15,.42),'Steel')
    box('Rear protective bulkhead',(0,2.2,1.35),(5.0,.24,2.12),'Teal')
    box('Entrance threshold',(0,-2.38,.32),(2.1,.55,.14),'Ochre')
    for x in (-1.08,1.08): box('Entrance jamb',(x,-2.24,1.28),(.23,.38,2.05),'Ivory')
    box('Entrance header',(0,-2.24,2.3),(2.4,.38,.32),'Ivory')
    box('Shelter beacon',(0,-2.45,2.48),(.64,.15,.15),'Amber')
    box('Emergency control console',(1.35,1.38,1.48),(.45,.25,.30),'Graphite')
    box('Control display',(1.35,1.23,1.48),(.30,.04,.16),'Cyan')


def material_recovery_line():
    # Open sorting conveyor with three independent collection bins and overhead optical scanner.
    box('Sorting line base',(0,0,.13),(6.2,3.8,.26),'Graphite')
    for x in (-2.4,-.8,.8,2.4):
        for y in (-.60,.60): box('Conveyor support',(x,y,.55),(.22,.22,.85),'Steel')
    box('Belt bed',(0,0,.99),(5.55,1.6,.20),'Teal')
    box('Continuous belt',(0,0,1.13),(5.35,1.34,.08),'Graphite')
    for i in range(15): cylinder('Belt roller',(-2.55+i*.36,0,1.18),.075,1.38,'Slate','Y',vertices=12)
    for x in (-1.75,0,1.75):
        box('Recovery bin floor',(x,1.36,.32),(1.42,1.12,.14),'Ivory')
        for dx in (-.67,.67): box('Bin side',(x+dx,1.36,.69),(.12,1.12,.68),'Teal')
        box('Bin face',(x,1.90,.69),(1.42,.12,.68),'Teal')
        box('Sorting class indicator',(x,1.98,.82),(.42,.05,.16),'Amber' if x==0 else 'Cyan')
        ramp=box('Drop chute',(x,.8,1.05),(1.08,.70,.12),'Steel');ramp.rotation_euler.x=-.30
        for y in (-.82,.82): box('Scanner upright',(x,y,1.7),(.17,.17,1.45),'Ochre')
        box('Scanner bridge',(x,0,2.43),(.40,1.85,.22),'Ochre')
        box('Optical head',(x,0,2.23),(.35,.53,.19),'Graphite')
        box('Detector window',(x,0,2.12),(.25,.40,.04),'Cyan')
    for i in range(5):
        obj=box('Unsorted material',(-2.3+i*.42,(-1)**i*.24,1.34),(.26,.29,.18),'Copper' if i%2 else 'Ivory');obj.rotation_euler.z=i*.47
    box('Control pedestal',(2.35,-1.32,.79),(.44,.54,1.23),'Graphite')
    box('Sort status display',(2.35,-1.61,1.30),(.30,.06,.20),'Cyan')


def habitat_archive_room():
    # Open public reading room with individually editable shelving and archive terminals.
    box('Public reading deck',(0,0,.12),(7.6,5.8,.24),'Slate')
    box('Rear archive wall',(0,2.66,1.55),(7.5,.18,2.85),'Ivory')
    for x in (-2.65,0,2.65):
        for dx in (-1.02,1.02): box('Archive shelf upright',(x+dx,2.25,1.50),(.13,.66,2.55),'Teal')
        for z in (.40,1.03,1.66,2.29):
            box('Archive shelf',(x,2.25,z),(2.12,.66,.10),'Steel')
            for i in range(5):
                h=.30+.05*((i+int(z*10))%3)
                box('Catalog cartridge',(x-.76+i*.36,2.12,z+.06+h/2),(.27,.38,h),('Ivory','Ochre','Teal','Copper','Slate')[i],.025)
    for x in (-1.83,1.83):
        box('Reading table',(x,-.35,.86),(2.0,1.35,.13),'Ivory')
        for dx in (-.78,.78):
            for dy in (-.47,.47): box('Table leg',(x+dx,-.35+dy,.47),(.12,.12,.68),'Steel')
        for y in (-1.45,.75):
            box('Reader seat',(x,y,.52),(.58,.58,.14),'Teal')
            box('Seat pedestal',(x,y,.32),(.20,.20,.33),'Graphite')
            box('Seat back',(x,y+(-.25 if y<0 else .25),.83),(.58,.12,.59),'Teal')
        for dx in (-.52,.52):
            box('Reader terminal base',(x+dx,-.35,.97),(.42,.38,.08),'Graphite')
            screen=box('Reader display',(x+dx,-.26,1.22),(.44,.08,.43),'Cyan');screen.rotation_euler.x=-.18
    cylinder('Central index pedestal',(0,-1.83,.63),.38,.98,'Teal',vertices=12)
    box('Index display',(0,-1.83,1.18),(.70,.54,.12),'Cyan')
    for x in (-3.43,3.43):
        box('Reading area lamp post',(x,-1.5,1.55),(.12,.12,2.65),'Steel')
        box('Reading area luminaire',(x,-1.5,2.9),(.68,.36,.14),'Ivory')
        box('Reading light diffuser',(x,-1.5,2.80),(.52,.26,.05),'Cyan')



def surface_cargo_cableway():
    # Twin braced pylons support a hanging freight gondola and moving cable.
    for x in (-3.8,3.8):
        box('Pylon foundation',(x,0,.15),(1.75,2.4,.3),'Graphite')
        for y in (-.75,.75):
            beam('Tapered pylon leg',(x,y,.3),(x,y*.37,3.9),.24,'Ivory')
            beam('Diagonal pylon brace',(x,y,.8),(x,-y*.4,3.1),.13,'Steel')
        box('Sheave crosshead',(x,0,4),(1.1,1.65,.32),'Ochre')
        for y in (-.48,.48):
            cylinder('Cable return sheave',(x,y,4.18),.45,.19,'Steel','Y',vertices=24)
            cylinder('Sheave hub',(x,y-.12,4.18),.13,.08,'Copper','Y')
        box('Safety beacon',(x,0,4.38),(.22,.25,.22),'Amber')
    for y in (-.48,.48):
        for x1,x2 in zip((-3.8,-1.9,0,1.9),(-1.9,0,1.9,3.8)):
            z=lambda x:3.96+.22*(x/3.8)**2
            beam('Tensioned aerial cable',(x1,y,z(x1)),(x2,y,z(x2)),.055,'Graphite')
    box('Gondola travel carriage',(0,0,3.78),(1.0,1.25,.24),'Ochre')
    for x in (-.44,.44):
        beam('Suspension strut',(x,0,3.68),(x,0,2.3),.16,'Steel')
    box('Suspended freight bed',(0,0,1.77),(1.72,1.6,.24),'Teal')
    for x in (-.72,.72):
        box('Retention rail',(x,0,2.13),(.12,1.6,.64),'Ochre')
    for x in (-.39,.39):
        box('Freight cassette',(x,0,2.09),(.66,1.16,.48),'Ivory')
    box('Delivery indicator',(0,-.84,1.92),(.38,.05,.10),'Cyan')


def eva_suit_service_bay():
    # Open-front maintenance alcove with three independent suit-support stands.
    box('Service deck',(0,0,.13),(6.6,4.1,.26),'Slate')
    box('Utility backplane',(0,1.84,1.55),(6.6,.24,2.85),'Ivory')
    for x in (-2.05,0,2.05):
        box('Suit locker frame',(x,1.48,2.75),(1.7,.58,.25),'Teal')
        for dx in (-.79,.79):
            box('Locking upright',(x+dx,1.48,1.5),(.13,.58,2.5),'Steel')
        cylinder('Turntable foot',(x,.75,.35),.63,.18,'Graphite',vertices=16)
        box('Backpack shell',(x,1.12,1.64),(.70,.42,.92),'Ochre',.10)
        box('Chest pressure shell',(x,.75,1.65),(.79,.50,.82),'Ivory',.17)
        bpy.ops.mesh.primitive_uv_sphere_add(segments=20,ring_count=12,radius=.33,location=(x,.72,2.32))
        finish(bpy.context.object,'Helmet pressure shell','Ivory')
        visor=box('Helmet visor',(x,.40,2.34),(.49,.17,.25),'Teal',.07)
        for side in (-1,1):
            beam('Upper sleeve',(x+side*.38,.76,1.88),(x+side*.60,.62,1.48),.20,'Ivory')
            beam('Glove assembly',(x+side*.60,.62,1.48),(x+side*.58,.45,1.20),.17,'Graphite')
            beam('Pressure trouser',(x+side*.19,.75,1.23),(x+side*.24,.75,.65),.29,'Ivory')
            box('Magnetic boot',(x+side*.24,.62,.53),(.33,.57,.22),'Graphite')
        box('Oxygen and battery monitor',(x,1.19,2.65),(.63,.10,.18),'Cyan')
    box('Service bench',(0,-1.1,.83),(2.5,.65,.15),'Ivory')
    for x in (-1.03,1.03):
        box('Bench pedestal',(x,-1.1,.46),(.18,.48,.64),'Steel')
    for x in (-.7,0,.7):
        cylinder('Spare oxygen cartridge',(x,-1.1,1.04),.12,.31,'Copper',vertices=16)


def aquaculture_nursery():
    # Open raceway tanks with visible aeration, filter banks and feed hoppers.
    box('Wet service deck',(0,0,.12),(7.8,5.8,.24),'Slate')
    for x in (-2.1,2.1):
        box('Raceway floor',(x,0,.42),(2.35,4.5,.20),'Ivory')
        for dx in (-1.15,1.15):
            box('Raceway long wall',(x+dx,0,.91),(.18,4.5,.88),'Teal')
            box('Non-slip rim',(x+dx,0,1.36),(.25,4.6,.13),'Steel')
        for y in (-2.16,2.16):
            box('Raceway end wall',(x,y,.91),(2.28,.18,.88),'Teal')
        box('Water surface representation',(x,0,1.13),(2.07,4.08,.035),'Ocean',0)
        for i in range(6):
            y=-1.65+i*.61
            fish=box('Juvenile fish silhouette',(x+(-1)**i*.43,y,1.17),(.18,.40,.07),'Ivory',.025)
            fish.rotation_euler.z=(-1)**i*.35
            tail=box('Juvenile tail',(x+(-1)**i*.43,y+.23,1.17),(.19,.10,.04),'Sand',.012)
            tail.rotation_euler.z=.4
        for y in (-1.4,0,1.4):
            cylinder('Aeration diffuser',(x,y,1.18),.15,.045,'Cyan',vertices=12)
        cylinder('Feed silo',(x,2.42,1.79),.35,.72,'Ochre',radius2=.26,vertices=16)
        beam('Feed nozzle',(x,2.42,1.43),(x,1.83,1.35),.12,'Copper')
    for x in (-.43,.43):
        cylinder('Biofilter column',(x,2.15,1.2),.30,1.8,'Ivory',vertices=16)
        ring('Filter service collar',(x,2.15,1.9),.28,.04,'Ochre')
        beam('Circulation return',(x,2.15,.5),(x*4.7,2.15,.5),.15,'Copper')
    box('Water quality console',(0,-1.9,.83),(.60,.47,1.14),'Graphite')
    box('Water quality display',(0,-2.16,1.22),(.45,.05,.24),'Cyan')



def surface_crawler_crane():
    # Mobile heavy-lift chassis, elevated lattice boom and freely inspectable hook.
    box('Slewing chassis',(0,0,.72),(2.8,4.8,.60),'Graphite',.18)
    for side in (-1,1):
        x=side*1.47
        box('Track belt',(x,0,.45),(.68,4.75,.72),'Graphite',.20)
        for y in (-1.86,-1.24,-.62,0,.62,1.24,1.86):
            cylinder('Track road wheel',(x+side*.34,y,.45),.30,.12,'Steel','X',vertices=16)
        for j in range(18):
            y=-2.16+j*.254
            box('Track top grouser',(x,y,.84),(.72,.12,.09),'Steel',.015)
        beam('Outrigger beam',(side*.95,.9,.72),(side*2.3,.9,.72),.23,'Ochre')
        cylinder('Outrigger jack',(side*2.3,.9,.42),.14,.70,'Steel')
        box('Outrigger foot',(side*2.3,.9,.10),(.54,.54,.16),'Graphite')
    cylinder('Slew bearing',(0,.25,1.15),.98,.35,'Steel',vertices=32)
    box('Rotating upper works',(0,.40,1.56),(2.1,2.1,.60),'Ochre',.14)
    box('Operator cab',(-.78,-.25,2.03),(.72,1.12,.85),'Ivory',.10)
    box('Cab windscreen',(-.78,-.83,2.13),(.56,.045,.42),'Teal')
    box('Counterweight',(0,1.35,1.75),(1.76,.66,.83),'Graphite')
    for x in (-.34,.34):
        beam('Lattice boom lower chord',(x,-.24,1.84),(x,-3.78,5.34),.15,'Ochre')
        beam('Lattice boom upper chord',(x,.16,2.24),(x,-3.38,5.74),.15,'Ochre')
        for i in range(5):
            t=i/5
            beam('Lattice diagonal',(x,-.24-3.54*t,1.84+3.50*t),(x,.16-3.54*(t+.2),2.24+3.50*(t+.2)),.09,'Steel')
    for i in range(6):
        t=i/5
        beam('Cross member',(-.34,-.24-3.54*t,1.84+3.50*t),(.34,-.24-3.54*t,1.84+3.50*t),.11,'Steel')
    cylinder('Winch drum',(0,.75,2.0),.29,.78,'Copper','X')
    cylinder('Head sheave',(0,-3.62,5.54),.25,.32,'Steel','X')
    beam('Load line',(0,-3.75,5.45),(0,-3.75,2.95),.045,'Graphite')
    box('Hook block',(0,-3.75,2.82),(.32,.32,.26),'Ochre')
    ring('Load attachment',(0,-3.75,2.51),.20,.065,'Steel','X')


def habitat_fire_suppression_station():
    # Open-front emergency utility alcove with pumps, hose reels and accessible controls.
    box('Service plinth',(0,0,.12),(5.8,3.4,.24),'Slate')
    box('Utility backplane',(0,1.48,1.55),(5.8,.24,2.9),'Ivory')
    for x in (-2.68,2.68):
        box('Side pilaster',(x,1.23,1.54),(.32,.66,2.85),'Graphite')
        box('Emergency marker',(x,.87,2.63),(.20,.05,.32),'Amber')
    for x in (-1.95,-.95):
        cylinder('Suppression reservoir',(x,.73,1.28),.40,1.9,'Ochre',vertices=24)
        cylinder('Reservoir valve',(x,.73,2.34),.12,.24,'Copper')
        ring('Reservoir retaining strap',(x,.73,1.68),.40,.045,'Steel')
        beam('Reservoir feed',(x,.73,2.44),(x,.73,2.69),.11,'Copper')
    beam('Shared feed header',(-1.95,.73,2.69),(1.93,.73,2.69),.13,'Copper')
    for x in (.63,1.92):
        cylinder('Hose reel hub',(x,1.12,1.83),.49,.26,'Graphite','Y',vertices=24)
        for j in range(4):
            ring('Wound hose',(x,.98-j*.085,1.83),.38,.052,'Ochre','Y')
        cylinder('Reel face',(x,.62,1.83),.45,.065,'Steel','Y',vertices=24)
        beam('Hose drop',(x,.68,1.47),(x,.68,.68),.095,'Ochre')
        cylinder('Hose nozzle',(x,.68,.52),.09,.25,'Steel')
    box('Pump skid',(0,.68,.35),(1.10,1.24,.25),'Graphite')
    cylinder('Pump motor',(0,.64,.77),.31,.68,'Teal','Y')
    cylinder('Pump volute',(0,.15,.77),.41,.29,'Steel','Y')
    box('Emergency isolation console',(-.52,-.76,.93),(.75,.55,1.35),'Graphite')
    box('Isolation display',(-.52,-1.06,1.40),(.48,.04,.24),'Cyan')
    for i in range(3):
        cylinder('Status button',(-.72+i*.20,-1.07,1.13),.065,.06,'Amber','Y',vertices=12)
    box('Overhead alert panel',(0,1.25,2.83),(1.25,.11,.24),'Ochre')
    box('Alert light strip',(0,1.18,2.83),(.82,.035,.10),'Amber')


def orbital_gravity_centrifuge():
    # Open mechanical ring with opposite laboratory capsules and an axial service hub.
    cylinder('Axial mounting hub',(0,0,0),.78,2.6,'Graphite','Y',vertices=16)
    for y in (-1.35,1.35):
        ring('Axial bearing collar',(0,y,0),.70,.10,'Copper','Y')
        cylinder('Service hatch',(0,y*1.06,0),.46,.08,'Ivory','Y',vertices=16)
    for y in (-.42,.42):
        ring('Outer centrifuge rail',(0,y,0),3.40,.16,'Steel','Y')
        ring('Inner centrifuge rail',(0,y,0),2.89,.10,'Teal','Y')
    for i in range(16):
        a=i*2*PI/16
        x,z=math.cos(a),math.sin(a)
        beam('Ring cross brace',(x*3.40,-.42,z*3.40),(x*3.40,.42,z*3.40),.13,'Ochre')
        beam('Radial web',(x*2.89,-.42,z*2.89),(x*3.40,.42,z*3.40),.10,'Steel')
    for side in (-1,1):
        for y in (-.42,.42):
            beam('Radial structural spoke',(side*.68,y,0),(side*2.78,y,0),.21,'Ivory')
            beam('Spoke diagonal',(side*.68,y,0),(side*2.78,-y,.40),.12,'Steel')
        box('Laboratory capsule',(side*3.12,0,0),(.86,1.38,1.18),'Ivory',.18)
        box('Laboratory window',(side*3.12,-.71,.16),(.57,.055,.40),'Teal',.05)
        box('Capsule power bus',(side*3.62,0,0),(.18,.94,.70),'Ochre')
        box('Capsule identification lamp',(side*3.12,-.75,-.30),(.32,.04,.10),'Cyan')
    for z in (-1.20,1.20):
        box('Hub avionics rack',(0,0,z),(.84,.86,.42),'Teal')
        box('Hub status panel',(0,-.46,z),(.42,.05,.15),'Cyan')



def colony_tram():
    # Low-floor shuttle, two independent bogies, walk-through doors and overhead power pickup.
    box('Low floor chassis',(0,0,.63),(2.15,6.5,.42),'Graphite',.15)
    box('Passenger roof',(0,0,2.55),(2.16,6.3,.32),'Ivory',.16)
    for y in (-2.35,2.35):
        box('Bogie frame',(0,y,.38),(1.64,1.05,.24),'Slate')
        for dy in (-.38,.38):
            cylinder('Wheel axle',(0,y+dy,.37),.10,2.06,'Steel','X',vertices=16)
            for x in (-.96,.96):
                cylinder('Rail wheel',(x,y+dy,.37),.34,.22,'Graphite','X',vertices=20)
                cylinder('Wheel hub',(x*1.13,y+dy,.37),.16,.05,'Steel','X',vertices=12)
    for side in (-1,1):
        x=side*1.03
        box('Side lower sill',(x,0,1.03),(.14,5.9,.45),'Teal')
        for y in (-2.3,-1.48,1.48,2.3):
            box('Passenger window',(x,y,1.90),(.095,.69,.74),'Cyan',.05)
        for y in (-2.82,-1.90,-.98,.98,1.90,2.82):
            box('Window mullion',(x,y,1.93),(.15,.13,1.1),'Ivory')
        for y in (-.47,.47):
            box('Sliding door leaf',(x,y,1.68),(.16,.89,1.65),'Steel')
            box('Door window',(x*1.09,y,2.0),(.045,.59,.54),'Teal')
        box('Door boarding step',(x*1.13,0,.68),(.27,1.84,.13),'Ochre')
    for side in (-1,1):
        y=side*3.0
        box('Driver cab end',(0,y,1.57),(2.06,.55,1.84),'Ivory',.21)
        box('Driver windscreen',(0,side*3.29,2.02),(1.48,.06,.58),'Teal',.10)
        for x in (-.66,.66):
            box('Marker lamp',(x,side*3.31,1.13),(.25,.08,.15),'Cyan')
        box('Coupler',(0,side*3.48,.68),(.40,.52,.25),'Steel')
    box('Power pickup base',(0,0,2.79),(.82,1.14,.20),'Graphite')
    for x in (-.28,.28):
        beam('Pantograph lower link',(x,-.45,2.86),(x,.22,3.35),.09,'Ochre')
        beam('Pantograph upper link',(x,.22,3.35),(x,-.08,3.82),.09,'Steel')
    box('Collector strip',(0,-.08,3.84),(1.64,.20,.09),'Graphite')


def orbital_tether_spool():
    # Exposed cable drum suspended within a load-bearing frame with controlled payout guide.
    box('Mounting keel',(0,0,-1.68),(4.7,3.3,.38),'Slate')
    for x in (-1.92,1.92):
        for y in (-1.25,1.25):
            beam('Bearing tower leg',(x,y,-1.48),(x,0,.10),.32,'Ivory')
            box('Deck mounting foot',(x,y,-1.45),(.63,.62,.15),'Ochre')
        cylinder('Axle bearing',(x,0,0),.53,.38,'Steel','X')
    cylinder('Tether reel barrel',(0,0,0),1.02,2.95,'Graphite','X',vertices=32)
    for x in (-1.57,1.57):
        cylinder('Drum flange',(x,0,0),1.37,.18,'Teal','X',vertices=32)
        ring('Flange reinforcement',(x,0,0),1.24,.07,'Steel','X')
        cylinder('Axle cap',(x*1.30,0,0),.29,.22,'Ochre','X',vertices=16)
    for i in range(21):
        ring('Wound tether turn',(-1.38+i*.138,0,0),1.09,.061,'Copper','X')
    for x in (-1.6,1.6):
        beam('Payout guide support',(x,1.15,-1.46),(x,1.81,.78),.19,'Steel')
    beam('Guide traversal rail',(-1.72,1.81,.78),(1.72,1.81,.78),.15,'Ochre')
    box('Traversing payout carriage',(.6,1.81,.78),(.48,.48,.45),'Graphite')
    ring('Tether guide eye',(.6,2.08,.78),.16,.055,'Steel','Y')
    beam('Paid out tether',(.60,.80,.75),(.60,2.1,.78),.045,'Copper')
    box('Motor controller',(-1.0,-1.20,-1.09),(.9,.55,.62),'Ivory')
    box('Controller status',(-1.0,-1.49,-.98),(.56,.05,.17),'Cyan')


def habitat_seed_bank():
    # Walkable conservation vault with individual cold-storage drawers and inventory station.
    box('Vault deck',(0,0,-.14),(6.2,5.6,.28),'Slate')
    box('Rear insulated wall',(0,2.55,1.42),(6.2,.25,2.84),'Ivory')
    for side in (-1,1):
        x=side*2.46
        box('Storage rack frame',(x,.45,1.36),(1.0,3.9,2.72),'Graphite',.09)
        for i in range(4):
            for j in range(3):
                y=-.91+j*1.28; z=.47+i*.61
                box('Sealed seed drawer',(x-side*.04,y,z),(.86,1.12,.48),'Teal',.06)
                box('Drawer index plate',(x-side*.49,y,z+.09),(.04,.38,.12),'Cyan')
                box('Recessed pull',(x-side*.53,y,z-.11),(.10,.40,.07),'Steel')
        box('Rack thermal manifold',(x,2.45,1.48),(.40,.32,2.54),'Steel')
    box('Inventory desk',(0,1.50,.91),(1.58,.80,.20),'Ivory')
    for x in (-.59,.59):
        box('Desk leg',(x,1.50,.44),(.17,.60,.88),'Steel')
    box('Inventory terminal',(0,1.67,1.28),(.75,.24,.51),'Graphite')
    box('Terminal display',(0,1.53,1.30),(.60,.04,.35),'Cyan')
    for x in (-.55,.55):
        cylinder('Sample vial',(x,1.37,1.10),.08,.18,'Teal',vertices=16)
        cylinder('Vial cap',(x,1.37,1.21),.09,.04,'Ochre',vertices=16)
    for x in (-1.1,1.1):
        box('Aisle lighting strip',(x,0,.025),(.08,4.8,.04),'Cyan')
    box('Cold storage compressor',(0,2.20,2.22),(1.65,.50,.58),'Steel')
    for x in (-.55,0,.55):
        box('Compressor vent',(x,1.93,2.23),(.36,.06,.36),'Graphite')



def atmospheric_balloon_probe():
    # Free-floating atmospheric survey platform, segmented lifting envelope and suspended instrument gondola.
    bpy.ops.mesh.primitive_uv_sphere_add(segments=32,ring_count=16,location=(0,0,4.8))
    envelope=bpy.context.object
    envelope.scale=(1.55,1.55,2.02)
    bpy.ops.object.transform_apply(location=False,rotation=False,scale=True)
    finish(envelope,'Lifting envelope','Ivory')
    for i in range(8):
        a=i*PI/4
        for j in range(10):
            t0=.12+j*(PI-.24)/10; t1=.12+(j+1)*(PI-.24)/10
            def pt(t): return (1.56*math.sin(t)*math.cos(a),1.56*math.sin(t)*math.sin(a),4.8+2.03*math.cos(t))
            beam('Envelope load tape',pt(t0),pt(t1),.055,'Ochre')
        beam('Suspension line',(.50*math.cos(a),.50*math.sin(a),2.83),(.65*math.cos(a),.65*math.sin(a),1.31),.045,'Steel')
    cylinder('Envelope valve',(0,0,2.78),.32,.20,'Teal')
    box('Gondola chassis',(0,0,1.02),(1.52,1.22,.34),'Graphite')
    box('Instrument enclosure',(0,0,1.29),(1.15,.85,.45),'Teal',.10)
    for x in (-.92,.92):
        box('Solar wing',(x,0,1.1),(.58,1.20,.10),'Steel')
        for y in (-.38,0,.38):
            box('Photovoltaic cell',(x,y,1.17),(.48,.32,.035),'Ocean')
    cylinder('Sampling inlet',(0,-.59,.80),.13,.44,'Copper','Y')
    beam('Instrument boom',(0,0,.87),(0,0,-.05),.07,'Steel')
    cylinder('Pressure sensor',(0,0,-.12),.19,.21,'Ochre')
    cylinder('Telemetry beacon',(0,.34,1.69),.10,.22,'Cyan')


def habitat_communal_galley():
    # Open walkable kitchen with preparation island, ovens, sinks and a serving pass.
    box('Galley floor',(0,0,-.12),(7.2,5.6,.24),'Slate')
    box('Rear utility wall',(0,2.66,1.45),(7.2,.22,2.90),'Ivory')
    box('Service counter',(0,1.96,.48),(6.45,1.02,.96),'Graphite')
    box('Stainless worktop',(0,1.96,1.01),(6.55,1.10,.14),'Steel')
    for x in (-2.25,-1.23,-.21):
        box('Oven face',(x,1.38,.57),(.87,.10,.72),'Ivory')
        box('Oven inspection window',(x,1.30,.64),(.60,.06,.34),'Teal')
        box('Oven handle',(x,1.23,.91),(.56,.09,.07),'Steel')
        cylinder('Cooking zone',(x,1.96,1.10),.31,.04,'Graphite')
    for x in (1.2,2.2):
        box('Sink inset',(x,1.96,1.09),(.70,.74,.05),'Graphite')
        beam('Faucet riser',(x,2.34,1.09),(x,2.34,1.53),.08,'Steel')
        beam('Faucet spout',(x,2.34,1.53),(x,2.0,1.53),.08,'Steel')
    box('Prep island',(0,-.25,.45),(2.75,1.25,.90),'Teal')
    box('Island worktop',(0,-.25,.96),(2.90,1.39,.12),'Steel')
    for x in (-.94,-.34,.26,.86):
        box('Ingredient drawer',(x,-.90,.48),(.49,.07,.44),'Ivory')
        box('Drawer pull',(x,-.96,.58),(.29,.08,.06),'Ochre')
    box('Serving pass',(2.72,-1.05,.51),(1.25,2.3,1.02),'Graphite')
    box('Serving counter',(2.72,-1.05,1.08),(1.38,2.45,.12),'Steel')
    for y in (-1.75,-1.08,-.41):
        cylinder('Stacked serving plates',(2.72,y,1.19),.24,.13,'Ivory')
    for x in (-2.4,-.9,.6,2.1):
        box('Overhead cabinet',(x,2.42,2.12),(1.30,.52,.60),'Teal')
        box('Task lamp',(x,2.20,1.78),(1.0,.12,.05),'Cyan')


def subsea_cable_repeater():
    # Seabed telecommunications node on a protective sled with dual cable termination cones.
    for x in (-1.2,1.2):
        box('Seabed skid runner',(x,0,.18),(.28,5.1,.36),'Ochre')
        for y in (-2.05,2.05):
            beam('Runner nose',(x,y,.20),(x,y*1.23,.50),.24,'Ochre')
    for y in (-1.65,0,1.65):
        box('Sled crossmember',(0,y,.37),(2.65,.30,.26),'Steel')
    cylinder('Pressure repeater body',(0,0,1.10),.68,2.85,'Teal','Y',vertices=32)
    for y in (-1.25,1.25):
        ring('Pressure flange',(0,y,1.10),.68,.10,'Steel','Y')
        cylinder('Cable strain relief',(0,y*1.48,1.10),.34,.75,'Graphite','Y',.22)
        beam('Protected cable',(0,y*1.75,1.10),(0,y*2.30,.78),.12,'Copper')
    for x in (-.98,.98):
        for y in (-1.45,1.45):
            beam('Protective cage upright',(x,y,.43),(x,y,1.95),.15,'Ochre')
        beam('Cage top rail',(x,-1.45,1.95),(x,1.45,1.95),.15,'Ochre')
    for y in (-1.45,1.45):
        beam('Cage roof crossbrace',(-.98,y,1.95),(.98,y,1.95),.15,'Steel')
    box('ROV service panel',(0,-.36,1.84),(.82,.71,.21),'Ivory')
    for x in (-.25,0,.25):
        cylinder('Wet-mate connector',(x,-.36,1.99),.08,.17,'Copper')
    box('Repeater status strip',(0,-.76,1.86),(.60,.05,.13),'Cyan')



def surface_medical_rover():
    # Six-wheel rescue vehicle with an accessible rear patient compartment.
    box('Rescue chassis',(0,0,.72),(2.65,5.2,.48),'Graphite',.15)
    box('Cab shell',(0,-1.63,1.45),(2.35,1.55,1.35),'Ivory',.18)
    box('Windscreen',(0,-2.43,1.73),(1.92,.08,.55),'Ocean')
    box('Cab light bar',(0,-1.52,2.2),(1.45,.25,.16),'Cyan')
    box('Patient deck',(0,.88,1.02),(2.27,3.12,.15),'Steel')
    box('Patient roof',(0,.88,2.54),(2.42,3.24,.17),'Ivory')
    for side in (-1,1):
        x=side*1.38
        for y in (-1.75,0,1.76):
            cylinder('All terrain tire',(x,y,.54),.54,.42,'Graphite','X')
            cylinder('Wheel hub',(x+side*.23,y,.54),.25,.09,'Steel','X')
            for k in range(10):
                a=k*PI/5
                tread=box('Tread block',(x,y+.53*math.cos(a),.54+.53*math.sin(a)),(.40,.15,.11),'Slate')
                tread.rotation_euler.x=a-PI/2
        for y in (-.50,2.27):
            beam('Cabin corner post',(side*1.11,y,1.10),(side*1.11,y,2.54),.13,'Ivory')
        box('Lower patient wall',(side*1.12,.90,1.43),(.13,2.80,.63),'Ivory')
        box('Rescue stripe',(side*1.205,.90,1.44),(.045,2.65,.19),'Ochre')
        box('Cab side glass',(side*1.19,-1.68,1.75),(.07,.88,.46),'Ocean')
        box('Side marker',(side*1.22,1.92,2.4),(.08,.25,.12),'Amber')
    box('Stretcher cushion',(-.45,.98,1.43),(.66,1.95,.19),'Teal')
    for y in (.25,1.72):
        beam('Stretcher mount',(-.45,y,1.09),(-.45,y,1.34),.16,'Steel')
    box('Medical monitor',(.72,.05,1.83),(.40,.15,.31),'Cyan')
    ramp=box('Lowered loading ramp',(0,2.95,.66),(1.52,1.52,.12),'Steel')
    ramp.rotation_euler.x=-.53
    for x in (-.65,.65):
        beam('Ramp edge',(x,2.29,1.03),(x,3.61,.29),.09,'Ochre')


def tidal_control_gate():
    # Two independent sluice leaves with exposed rack drives and elevated service walkway.
    box('Concrete sill',(0,0,.16),(8.4,3.25,.32),'Stone')
    for x in (-3.88,0,3.88):
        box('Reinforced pier',(x,0,1.85),(.60,2.35,3.7),'Stone',.12)
        box('Pier cap',(x,0,3.79),(.82,2.54,.24),'Steel')
        for y in (-.85,.85):
            beam('Pier edge reinforcement',(x,y,.38),(x,y,3.55),.14,'Steel')
    for x,z in ((-1.94,1.05),(1.94,2.10)):
        box('Independent sluice leaf',(x,0,z),(3.25,.22,1.95),'Teal',.035)
        for dz in (-.73,0,.73):
            box('Leaf horizontal stiffener',(x,-.18,z+dz),(3.12,.16,.14),'Steel')
        for dx in (-1.42,1.42):
            box('Gate guide',(x+dx,.07,1.78),(.14,.37,3.0),'Graphite')
            beam('Lift rack',(x+dx*.65,0,z+.78),(x+dx*.65,0,4.16),.14,'Steel')
            for k in range(8):
                box('Rack tooth',(x+dx*.65,-.09,3.0+k*.15),(.16,.09,.055),'Copper')
            cylinder('Drive pinion',(x+dx*.65,-.20,4.04),.24,.21,'Ochre','Y')
        box('Motor bridge',(x,0,4.00),(3.45,.72,.25),'Graphite')
        cylinder('Drive motor',(x,.17,4.26),.23,.70,'Teal','X')
    box('Service catwalk',(0,-1.15,3.78),(8.35,.77,.14),'Steel')
    for x in range(-4,5):
        beam('Guard post',(x,-1.49,3.87),(x,-1.49,4.66),.07,'Ochre')
    beam('Continuous safety rail',(-4,-1.49,4.66),(4,-1.49,4.66),.09,'Ochre')
    box('Gate control cabinet',(3.86,-.97,4.24),(.43,.34,.66),'Ivory')
    box('Gate position display',(3.86,-1.16,4.36),(.28,.04,.18),'Cyan')


def orbital_debris_net():
    # Concave triangulated debris capture net with an independent powered retrieval bus.
    box('Recovery avionics bus',(0,0,-1.26),(1.48,1.28,.82),'Ivory',.12)
    cylinder('Retrieval capstan',(0,0,-.66),.40,.38,'Copper')
    for x in (-.64,.64):
        cylinder('Stationkeeping nozzle',(x,0,-1.79),.21,.32,'Graphite','Z',.14)
        cylinder('Nozzle status',(x,0,-1.96),.12,.025,'Cyan')
    for i in range(6):
        a=i*PI/3
        p=(2.9*math.cos(a),2.9*math.sin(a),.82)
        q=(2.9*math.cos(a+PI/3),2.9*math.sin(a+PI/3),.82)
        beam('Capture frame perimeter',p,q,.15,'Ochre')
        beam('Deployable radial strut',(.55*math.cos(a),.55*math.sin(a),-.93),p,.13,'Steel')
        cylinder('Hinge actuator',p,.15,.23,'Graphite')
        box('Capture beacon',(p[0],p[1],1.01),(.19,.19,.12),'Cyan')
    def net_point(radius,i):
        a=i*PI/3
        return (radius*math.cos(a),radius*math.sin(a),-.36+1.18*(radius/2.9)**2)
    for k in range(1,6):
        radius=2.9*k/5
        for i in range(6):
            p=net_point(radius,i);q=net_point(radius,i+1)
            beam('Net circumferential strand',p,q,.045,'Copper')
            beam('Net radial strand',net_point(radius-2.9/5,i),p,.045,'Steel')
            if k>1:
                beam('Net diagonal strand',net_point(radius-2.9/5,i),q,.034,'Steel')
    for x in (-1.02,1.02):
        box('Power panel',(x,0,-1.12),(.45,1.18,.10),'Ocean')
        for y in (-.4,0,.4):
            box('Photovoltaic strip',(x,y,-1.055),(.37,.31,.035),'Teal')




def surface_ice_harvester():
    # Low, wide tracked machine with a forward ice shaving drum and insulated rear melt vessel.
    box('Tracked chassis',(0,0,.64),(3.0,4.65,.42),'Graphite')
    for x in (-1.53,1.53):
        box('Track belt',(x,0,.45),(.62,4.25,.76),'Graphite',.19)
        for y in (-1.65,-.82,0,.82,1.65):
            cylinder('Road wheel',(x,y,.45),.34,.68,'Steel','X')
            cylinder('Wheel hub',(x*1.24,y,.45),.12,.06,'Ochre','X')
        for y in [i*.25 for i in range(-7,8)]:
            box('Ice grip tread',(x,y,.86),(.66,.12,.09),'Slate')
    box('Insulated melt tank housing',(0,1.02,1.49),(2.68,2.05,1.2),'Ivory',.18)
    for x in (-.74,.74):
        cylinder('Melt circuit riser',(x,1.44,2.17),.16,.30,'Copper')
        ring('Service coupling',(x,1.44,2.35),.13,.04,'Teal')
    box('Operator cab',(0,-.56,1.57),(1.72,1.17,1.16),'Ochre',.12)
    box('Cab glazing',(0,-1.16,1.72),(1.42,.07,.49),'Ocean')
    for x in (-1.31,1.31):
        beam('Cutter deployment arm',(x,-1.15,1.13),(x,-2.7,.58),.23,'Steel')
        cylinder('Cutter end bearing',(x,-2.7,.58),.29,.24,'Ochre','X')
    cylinder('Ice shaving drum',(0,-2.7,.58),.52,2.45,'Steel','X',vertices=32)
    for k in range(12):
        a=k*PI/6
        for x in (-.91,-.30,.30,.91):
            tooth=box('Staggered carbide tooth',(x,-2.7+.53*math.cos(a),.58+.53*math.sin(a)),(.22,.16,.16),'Ivory')
            tooth.rotation_euler.x=a
    box('Ice collection chute',(0,-1.93,.76),(2.27,.64,.31),'Teal')
    box('Melt status panel',(0,2.07,1.55),(.82,.07,.26),'Cyan')


def habitat_transit_turnstile():
    # Three lanes including a wider, step-free access gate; no enclosing room geometry.
    box('Concourse deck',(0,0,.10),(6.7,3.4,.2),'Slate')
    for x in (-2.8,-1.25,.24,2.68):
        box('Gate pedestal',(x,0,.69),(.40,1.18,1.18),'Ivory',.08)
        box('Pedestal cap',(x,0,1.30),(.45,1.23,.12),'Teal')
        box('Fare reader',(x,-.37,1.39),(.25,.30,.07),'Graphite')
        box('Reader light',(x,-.37,1.435),(.18,.19,.025),'Cyan')
    for x in (-2.60,-1.05,.44):
        beam('Swing gate leaf',(x,0,.77),(x+.85,0,.77),.10,'Ochre')
        beam('Swing gate lower bar',(x,0,.44),(x+.85,0,.44),.07,'Steel')
        beam('Leaf outer upright',(x+.85,0,.44),(x+.85,0,.77),.075,'Steel')
    for x in (.44,2.48):
        d=1 if x<1 else -1
        box('Accessible lane leaf',(x+d*.38,.28,.84),(.76,.10,.59),'Ocean',.025)
    for x in (-3.05,3.05):
        beam('Wayfinding post',(x,1.05,.21),(x,1.05,2.8),.13,'Steel')
    box('Overhead wayfinding sign',(0,1.05,2.70),(6.1,.22,.48),'Graphite')
    for x in (-2.0,-.5,1.45):
        box('Lane indicator',(x,.925,2.7),(.46,.035,.15),'Cyan')
        for y in (-1.2,1.2):
            box('Approach floor stripe',(x,y,.215),(.66,.11,.025),'Ochre')


def orbital_solar_sail_tug():
    # Four individually editable triangular sail membranes on a square deployable truss.
    box('Cargo bus',(0,0,-.68),(1.25,1.25,.88),'Ivory',.11)
    cylinder('Payload coupling',(0,0,-1.23),.46,.23,'Steel',vertices=16)
    ring('Docking alignment rim',(0,0,-1.37),.41,.055,'Ochre')
    cylinder('Sail mast',(0,0,.1),.16,1.5,'Steel')
    corners=[(-3.7,-3.7,.52),(3.7,-3.7,.52),(3.7,3.7,.52),(-3.7,3.7,.52)]
    hub=(0,0,1.05)
    for i,p in enumerate(corners):
        q=corners[(i+1)%4]
        beam('Deployment boom',hub,p,.085,'Graphite')
        beam('Tensioned perimeter',p,q,.052,'Steel')
        # Mesh with nonzero thickness and double-sided material via solidify.
        mesh=bpy.data.meshes.new('Triangular sail membrane')
        mesh.from_pydata([hub,p,q],[],[(0,1,2)]);mesh.update()
        ob=bpy.data.objects.new('Reflective sail quadrant '+str(i+1),mesh)
        bpy.context.collection.objects.link(ob)
        finish(ob,ob.name,'Ivory')
        ob.modifiers.new('Membrane thickness','SOLIDIFY').thickness=.016
        for t in (.33,.66):
            a=tuple(hub[j]+t*(p[j]-hub[j]) for j in range(3))
            b=tuple(hub[j]+t*(q[j]-hub[j]) for j in range(3))
            beam('Sail reinforcement tape',a,b,.025,'Copper')
        box('Corner beacon',p,(.17,.17,.12),'Cyan')
    for x in (-.75,.75):
        cylinder('Attitude thruster',(x,0,-.80),.17,.30,'Graphite','X')
        box('Bus telemetry panel',(x,0,-.43),(.08,.52,.25),'Teal')



def habitat_laundry_module():
    # Open service room: stacked front-load machines, folding island and wheeled baskets.
    box('Laundry deck',(0,0,.10),(5.8,4.2,.20),'Slate')
    for x in (-1.85,0,1.85):
        for z in (.77,1.98):
            box('Washer dryer cabinet',(x,1.17,z),(1.48,1.26,1.15),'Ivory',.09)
            cylinder('Recessed drum window',(x,.52,z),.43,.09,'Graphite','Y')
            ring('Door gasket',(x,.455,z),.39,.065,'Steel','Y')
            cylinder('Tinted inspection glass',(x,.44,z),.32,.028,'Ocean','Y')
            box('Cycle controller',(x+.38,.51,z+.43),(.35,.08,.14),'Teal')
            box('Cycle display',(x+.38,.46,z+.43),(.22,.02,.07),'Cyan')
        beam('Water supply riser',(x,1.87,.26),(x,1.87,2.55),.13,'Copper')
    box('Folding island',(0,-.82,.95),(2.45,.92,.12),'Ivory')
    for x in (-1.08,1.08):
        for y in (-1.16,-.48): box('Island leg',(x,y,.53),(.13,.13,.78),'Steel')
    for x in (-1.96,1.96):
        box('Basket frame',(x,-.94,.52),(.69,.72,.12),'Teal')
        for dx in (-.33,.33):
            for dy in (-.34,.34):
                beam('Basket upright',(x+dx,-.94+dy,.56),(x+dx,-.94+dy,1.05),.055,'Steel')
                cylinder('Caster',(x+dx,-.94+dy,.30),.10,.10,'Graphite','X')
        for z in (.66,.84,1.05):
            for dy in (-.34,.34): beam('Basket rail',(x-.33,-.94+dy,z),(x+.33,-.94+dy,z),.05,'Steel')
            for dx in (-.33,.33): beam('Basket rail',(x+dx,-1.28,z),(x+dx,-.60,z),.05,'Steel')


def surface_cable_trencher():
    # Wheeled utility installer: inclined chain boom, cutting teeth and cable reel.
    box('Utility chassis',(0,0,.82),(2.6,4.2,.55),'Ochre',.12)
    for x in (-1.39,1.39):
        for y in (-1.47,1.47):
            cylinder('All terrain tire',(x,y,.56),.55,.48,'Graphite','X')
            cylinder('Wheel rim',(x*1.19,y,.56),.24,.08,'Steel','X')
    box('Enclosed cab',(0,-1.35,1.65),(1.94,1.25,1.10),'Ivory')
    box('Cab windshield',(0,-2.0,1.82),(1.62,.06,.53),'Ocean')
    for x in (-.79,.79):
        box('Reel bearing stand',(x,.35,1.45),(.22,.70,1.12),'Steel')
        cylinder('Cable reel flange',(x,.35,1.91),.72,.11,'Ochre','X')
    cylinder('Reel core',(0,.35,1.91),.39,1.40,'Graphite','X')
    for x in [i*.12 for i in range(-5,6)]:
        ring('Coiled conduit',(x,.35,1.91),.53,.055,'Copper','X')
    a=(0,1.75,1.15);b=(0,3.65,.25)
    beam('Inclined trenching boom',a,b,.36,'Steel')
    for y,z in ((1.75,1.15),(3.65,.25)):
        cylinder('Chain sprocket',(0,y,z),.31,.55,'Graphite','X')
    for i in range(12):
        t=i/11
        for side in (-1,1):
            tooth=box('Replaceable chain cutter',(side*.20,1.75+1.9*t,1.38-.9*t),(.16,.17,.16),'Ivory')
            tooth.rotation_euler.x=-.44
    beam('Cable placement guide',(0,1.1,1.55),(0,3.97,.46),.10,'Teal')


def orbital_cargo_carousel():
    # Rotating pallet magazine with open central drive and eight separate freight cassettes.
    cylinder('Station mounting flange',(0,0,-.48),1.35,.38,'Graphite',vertices=16)
    cylinder('Carousel bearing',(0,0,-.13),.72,.36,'Steel')
    ring('Rotary track',(0,0,.12),2.18,.14,'Steel')
    cylinder('Indexer hub',(0,0,.43),.75,.70,'Teal',vertices=12)
    for i in range(8):
        a=i*PI/4; x=2.18*math.cos(a);y=2.18*math.sin(a)
        beam('Pallet radial support',(.68*math.cos(a),.68*math.sin(a),.18),(x,y,.18),.19,'Ochre')
        pallet=box('Independent cassette cradle',(x,y,.37),(1.14,1.08,.18),'Graphite')
        pallet.rotation_euler.z=a
        cassette=box('Freight cassette',(x,y,.84),(.94,.90,.72),'Ivory',.10)
        cassette.rotation_euler.z=a
        for t in (-.31,.31):
            dx=-math.sin(a)*t;dy=math.cos(a)*t
            strap=box('Cassette restraint',(x+dx,y+dy,.84),(.99,.075,.76),'Ochre')
            strap.rotation_euler.z=a
        box('Position beacon',(2.80*math.cos(a),2.80*math.sin(a),.50),(.13,.13,.13),'Cyan')
    cylinder('Axial docking socket',(0,0,1.03),.48,.38,'Graphite')
    ring('Dock alignment rim',(0,0,1.25),.44,.055,'Cyan')
    box('Index drive service panel',(0,-.78,.48),(.45,.12,.28),'Copper')



def surface_wind_turbine():
    # Three tapered airfoils with independently named pitch roots and an accessible base.
    cylinder('Foundation plinth',(0,0,.18),1.18,.36,'Slate',vertices=12)
    cylinder('Tapered tower',(0,0,3.65),.50,6.7,'Ivory',radius2=.28,vertices=24)
    ring('Tower service collar',(0,0,.72),.54,.06,'Steel')
    box('Access hatch',(0,-.48,.99),(.46,.12,.78),'Graphite',.05)
    box('Generator nacelle',(0,.14,7.08),(.90,1.85,.83),'Teal',.19)
    cylinder('Yaw bearing',(0,0,6.72),.39,.22,'Steel')
    cylinder('Rotor hub',(0,-.91,7.12),.44,.56,'Ivory','Y',radius2=.30)
    for i in range(3):
        a=i*2*PI/3
        radial=Vector((math.sin(a),0,math.cos(a)))
        tangent=Vector((math.cos(a),0,-math.sin(a)))
        center=Vector((0,-1.23,7.12))
        cylinder('Blade pitch bearing',center+radial*.40,.20,.32,'Steel','Z').rotation_euler=radial.to_track_quat('Z','Y').to_euler()
        verts=[]
        for radius,chord,sweep,thickness in ((.51,.32,0,.13),(1.15,.78,.10,.15),(2.05,.56,.22,.10),(3.20,.23,.36,.055),(3.50,.055,.45,.025)):
            base=center+radial*radius+tangent*sweep
            for u,v in ((-.5,0),(0,-1),(.5,0),(0,1)):
                verts.append(tuple(base+tangent*(u*chord)+Vector((0,v*thickness,0))))
        faces=[(3,2,1,0),(16,17,18,19)]
        for j in range(4):
            for k in range(4):
                faces.append((4*j+k,4*j+(k+1)%4,4*(j+1)+(k+1)%4,4*(j+1)+k))
        mesh=bpy.data.meshes.new('Tapered swept airfoil');mesh.from_pydata(verts,[],faces);mesh.update()
        ob=bpy.data.objects.new('Rotor blade '+str(i+1),mesh);bpy.context.collection.objects.link(ob);finish(ob,ob.name,'Ivory')
        beam('Blade tip recognition stripe',center+radial*3.13+tangent*.30,center+radial*3.36+tangent*.39,.065,'Ochre')
    for x in (-.36,.36):
        box('Nacelle cooling grille',(x,.51,7.08),(.06,.53,.33),'Graphite')
    box('Service disconnect cabinet',(.88,.45,.62),(.65,.62,1.03),'Ochre')
    box('Power status',(.88,.12,.86),(.27,.045,.13),'Cyan')
    beam('Base conduit',(.56,.44,.26),(.88,.45,.25),.13,'Copper')


def habitat_music_studio():
    # Open recording room: isolated vocal booth, console, monitors and instrument station.
    box('Studio floating deck',(0,0,.10),(6.6,4.7,.20),'Slate')
    for x in (-2.95,-1.70,-.45,.80,2.05,2.95):
        box('Rear acoustic absorber',(x,2.13,1.42),(.80,.22,2.40),'Graphite',.035)
        for z in (.58,1.04,1.50,1.96,2.42):
            box('Absorber slat',(x,1.99,z),(.65,.08,.12),'Copper')
    for x in (-2.65,-.55):
        beam('Vocal booth corner post',(x,.10,.21),(x,.10,2.62),.11,'Steel')
        beam('Booth ceiling rail',(x,.10,2.62),(x,1.96,2.62),.13,'Steel')
    box('Vocal booth side glazing',(-2.65,1.03,1.49),(.08,1.60,1.72),'Ocean',.025)
    box('Booth raised floor',(-1.60,1.02,.24),(1.90,1.75,.08),'Graphite')
    cylinder('Microphone base',(-1.62,.90,.34),.27,.08,'Steel')
    beam('Mic stand',(-1.62,.90,.38),(-1.62,.90,1.51),.065,'Steel')
    beam('Mic boom',(-1.62,.90,1.50),(-1.37,.68,1.66),.065,'Steel')
    cylinder('Vocal microphone',(-1.37,.68,1.74),.09,.19,'Graphite')
    ring('Pop screen',(-1.37,.49,1.70),.13,.025,'Steel','Y')
    box('Mixing desk',(1.35,.48,.93),(2.56,1.16,.17),'Teal',.08)
    for x in (.24,2.46):box('Console support',(x,.49,.55),(.18,.94,.72),'Graphite')
    for i in range(12):
        x=.32+i*.17
        box('Channel fader slot',(x,.20,1.03),(.052,.35,.035),'Graphite')
        box('Channel fader',(x,.13+(i%4)*.045,1.065),(.095,.075,.055),'Ivory')
        cylinder('Channel gain knob',(x,.58,1.06),.045,.05,'Ochre',vertices=12)
    for x in (.45,2.25):
        box('Nearfield speaker',(x,1.03,1.42),(.42,.39,.68),'Graphite',.07)
        cylinder('Monitor woofer',(x,.81,1.30),.135,.045,'Steel','Y')
        cylinder('Monitor tweeter',(x,.81,1.60),.063,.04,'Cyan','Y')
    box('Mix display',(1.35,1.03,1.39),(1.19,.12,.53),'Graphite')
    box('Meter display',(1.35,.955,1.39),(1.04,.02,.39),'Cyan')
    box('Keyboard workstation',(-1.58,-1.20,.88),(1.92,.64,.17),'Graphite')
    for x in (-2.34,-.82):beam('Keyboard support',(x,-1.20,.22),(x,-1.20,.81),.09,'Steel')
    for i in range(28):
        x=-2.45+i*.064
        box('White key',(x,-1.30,.99),(.059,.40,.06),'Ivory',.008)
        if i%7 in (0,1,3,4,5):box('Raised black key',(x+.032,-1.17,1.04),(.036,.23,.06),'Graphite',.005)


def orbital_traffic_beacon():
    # Independent orbital wayfinding marker: three-direction coded optical heads, power and service bus.
    cylinder('Beacon central bus',(0,0,0),.57,1.72,'Teal',vertices=8)
    for z in (-.79,.79):
        ring('Impact bumper',(0,0,z),.57,.095,'Ochre')
    cylinder('Service docking stem',(0,0,-1.05),.26,.50,'Steel')
    ring('Service socket',(0,0,-1.33),.26,.05,'Graphite')
    for i in range(3):
        a=i*2*PI/3
        u=Vector((math.cos(a),math.sin(a),0));v=Vector((-math.sin(a),math.cos(a),0))
        base=u*.72+Vector((0,0,.38))
        beam('Optical head mount',u*.49+Vector((0,0,.38)),u*1.00+Vector((0,0,.38)),.19,'Steel')
        axis=u.to_track_quat('Z','Y').to_euler()
        for name,r,d,off,mat in (('Lamp housing',.33,.47,1.04,'Graphite'),('Lens shroud',.30,.10,1.31,'Ochre'),('Coded optical face',.24,.045,1.39,'Cyan')):
            ob=cylinder(name,u*off+Vector((0,0,.38)),r,d,mat,vertices=24);ob.rotation_euler=axis
        for side in (-1,1):
            p=u*1.42+v*.16*side+Vector((0,0,.61))
            box('Identification marker',p,(.10,.10,.08),'Amber')
        for j in range(3):
            z=-.55+j*.17
            beam('Radiator rib',u*.61+v*.28+Vector((0,0,z)),u*.61-v*.28+Vector((0,0,z)),.055,'Steel')
    for side in (-1,1):
        x=side*1.52
        beam('Solar wing spar',(side*.48,0,-.38),(side*2.45,0,-.38),.09,'Steel')
        box('Solar wing frame',(x,0,-.38),(1.78,.92,.10),'Graphite',.035)
        for i in range(6):
            for j in range(3):
                box('Solar cell',(x-.73+i*.29,-.29+j*.29,-.31),(.25,.25,.035),'Ocean',.008)
    cylinder('Timing antenna mast',(0,0,1.18),.065,.66,'Steel')
    ring('Timing loop',(0,0,1.58),.20,.035,'Copper','Y')


def surface_salt_evaporation_works():
    # Open shallow brine pans with independent berms and a harvesting lane.
    box('Graded salt works foundation',(0,0,.0),(10.8,7.8,.25),'Sand',.04)
    for x in (-2.75,2.75):
        box('Lined evaporation basin',(x,.25,.16),(4.55,5.3,.10),'Teal',.03)
        for dx in (-2.35,2.35):
            box('Long containment berm',(x+dx,.25,.37),(.24,5.65,.46),'Stone')
        for y in (-2.51,3.01):
            box('End containment berm',(x,y,.37),(4.8,.24,.46),'Stone')
        for i in range(6):
            for j in range(3):
                yy=-1.75+i*.76;xx=x-1.30+j*1.26
                crystal=box('Crystallized salt patch',(xx,yy,.24),(.58,.42,.10),'Ivory',.03)
                crystal.rotation_euler.z=.14*(i-j)
        for y in (-1.65,1.60):
            box('Basin level gauge',(x+1.92,y,.74),(.14,.20,.48),'Steel')
            box('Gauge indicator',(x+1.92,y-.11,.80),(.08,.03,.14),'Cyan')
        cylinder('Brine transfer standpipe',(x,-3.05,.63),.14,1.0,'Copper')
        beam('Brine feed pipe',(x,-3.05,.64),(x,-2.15,.64),.18,'Copper')
        ring('Manual isolation valve',(x,-3.05,1.18),.19,.035,'Ochre','X')
    box('Central harvesting lane',(0,.1,.19),(.52,5.9,.08),'Graphite')
    box('Brine pump skid',(0,-3.25,.32),(1.4,.82,.28),'Graphite')
    cylinder('Pump motor',(0,-3.25,.69),.32,.88,'Steel','X')
    for side in (-1,1):
        beam('Supply header',(side*.40,-3.25,.72),(side*2.75,-3.25,.72),.16,'Copper')
    for x in (-4.6,4.6):
        box('Harvested salt tote',(x,3.50,.54),(.85,.63,.7),'Ivory')
        box('Tote restraint',(x,3.50,.55),(.90,.11,.74),'Ochre')


def habitat_classroom():
    # Open classroom with a teaching wall and accessible central aisle.
    box('Classroom floor',(0,0,0),(8.6,7.4,.22),'Slate')
    box('Teaching wall',(0,3.58,1.72),(8.6,.22,3.4),'Ivory')
    box('Side partition',(-4.18,.1,1.40),(.24,6.8,2.8),'Ivory')
    box('Teaching display',(0,3.40,2.05),(4.65,.14,1.75),'Graphite')
    box('Teaching display panel',(0,3.31,2.05),(4.35,.035,1.48),'Teal')
    for i in range(5):
        box('Display diagram line',(-1.52+i*.76,3.28,2.15),(.46,.025,.065),'Cyan')
    box('Demonstration bench',(0,2.05,.90),(2.65,.82,.18),'Steel')
    for x in (-1.05,1.05):
        box('Bench pedestal',(x,2.05,.49),(.23,.65,.73),'Graphite')
    for x in (-2.8,-1.4,1.4,2.8):
        for y in (-2.35,-.70,.95):
            box('Individual desk',(x,y,.83),(1.12,.70,.13),'Ivory')
            for dx in (-.42,.42):
                box('Desk support',(x+dx,y,.46),(.10,.56,.64),'Steel')
            box('Learning tablet',(x,y+.08,.93),(.45,.30,.055),'Graphite')
            box('Tablet display',(x,y+.08,.964),(.39,.24,.017),'Cyan')
            box('Seat',(x,y-.69,.46),(.52,.52,.12),'Teal')
            box('Seat back',(x,y-.94,.74),(.52,.12,.56),'Teal')
            cylinder('Seat pedestal',(x,y-.69,.25),.075,.31,'Steel')
    for y in (-2.6,-1.45,-.30):
        box('Equipment storage cabinet',(-3.93,y,1.18),(.38,.94,2.05),'Teal')
        box('Cabinet pull',(-3.70,y,1.20),(.07,.20,.06),'Steel')
    for x in (-2.75,2.75):
        box('Overhead task light',(x,3.33,3.15),(1.55,.22,.12),'Cyan')


def orbital_sample_return_canister():
    # Sealed scientific sample container with an ablative entry shell and recovery fittings.
    cylinder('Ablative heat shield',(0,0,-.70),1.14,.29,'Basalt','Z',1.28,vertices=48)
    cylinder('Tapered entry shell',(0,0,.05),1.26,1.24,'Ivory','Z',.67,vertices=48)
    cylinder('Recovery crown',(0,0,.81),.69,.29,'Teal',vertices=32)
    ring('Crown separation seam',(0,0,.68),.71,.045,'Graphite')
    ring('Heat shield separation seam',(0,0,-.52),1.23,.055,'Copper')
    cylinder('Sealed sample hatch',(0,0,.99),.43,.12,'Graphite')
    ring('Hatch locking rim',(0,0,1.06),.40,.045,'Steel')
    for i in range(8):
        a=i*PI/4; x,y=math.cos(a),math.sin(a)
        beam('Entry shell reinforcement',(x*1.23,y*1.23,-.42),(x*.73,y*.73,.55),.055,'Steel')
        lock=box('Shield retention latch',(x*1.16,y*1.16,-.35),(.24,.13,.20),'Ochre')
        lock.rotation_euler.z=a
    for i in range(3):
        a=i*2*PI/3; x,y=math.cos(a),math.sin(a)
        cylinder('Tracking transponder',(x*.51,y*.51,.99),.10,.16,'Steel')
        cylinder('Recovery light',(x*.51,y*.51,1.09),.071,.055,'Amber')
        beam('Recovery sling fitting',(x*.44,y*.44,1.05),(x*.30,y*.30,1.27),.085,'Steel')
        ring('Sling eye',(x*.30,y*.30,1.27),.10,.026,'Ochre','Y')
    box('Sample identity panel',(0,-.98,.18),(.47,.07,.25),'Graphite')
    box('Sample status strip',(0,-1.02,.18),(.32,.025,.075),'Cyan')



def surface_rockfall_barrier():
    # A freestanding, visibly tensioned catch fence with segmented foundations.
    for i in range(5):
        x=(i-2)*2.25
        box('Anchor foundation',(x,0,.12),(.82,1.15,.35),'Stone')
        beam('Inclined impact post',(x,0,.28),(x,.42,3.30),.19,'Steel')
        beam('Rear diagonal stay',(x,.42,2.7),(x,1.7,.22),.12,'Graphite')
        box('Rear ground anchor',(x,1.72,.12),(.51,.59,.24),'Stone')
        for z in (.55,1.83,3.11):
            ring('Energy absorbing cable loop',(x,.14+z*.085,z),.16,.034,'Copper','Y')
        cylinder('Reflective post cap',(x,.42,3.35),.14,.16,'Ochre')
    for j in range(4):
        x0=-4.5+j*2.25
        for z in (.50,1.15,1.80,2.45,3.10):
            beam('Horizontal tension cable',(x0,.10+z*.10,z),(x0+2.25,.10+z*.10,z),.045,'Steel')
        for k in range(4):
            x=x0+k*.5625
            for l in range(4):
                z=.50+l*.65
                beam('Diamond net rising strand',(x,.10+z*.10,z),(x+.5625,.10+(z+.65)*.10,z+.65),.035,'Graphite')
                beam('Diamond net falling strand',(x,.10+(z+.65)*.10,z+.65),(x+.5625,.10+z*.10,z),.035,'Graphite')
    for x,y,r in ((-2.8,-.8,.35),(-.8,-.55,.25),(2.1,-.72,.43)):
        bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1,radius=r,location=(x,y,r*.8))
        finish(bpy.context.object,'Caught rock fragment','Basalt')


def habitat_textile_loom():
    # Shuttle weaving machine with separately editable warp threads and fabric.
    box('Loom base',(0,0,.12),(4.6,3.65,.24),'Slate')
    for x in (-1.94,1.94):
        for y in (-1.30,1.30):
            beam('Loom frame upright',(x,y,.24),(x,y,2.65),.22,'Teal')
        box('Side frame rail',(x,0,2.55),(.22,2.85,.23),'Steel')
        box('Drive cabinet',(x,.8,.85),(.55,.82,1.18),'Graphite')
    for y,z in ((1.30,1.85),(-1.30,1.00)):
        cylinder('Warp or cloth roller',(0,y,z),.25,3.62,'Steel','X',vertices=32)
        for x in (-1.79,1.79):
            cylinder('Roller bearing',(x,y,z),.34,.18,'Ochre','X')
    cylinder('Warp thread spool',(0,1.30,1.85),.32,2.93,'Ivory','X',vertices=32)
    cylinder('Finished cloth roll',(0,-1.30,1.00),.31,2.92,'Teal','X',vertices=32)
    for i in range(24):
        x=-1.39+i*.121
        beam('Individual warp thread',(x,1.20,2.12),(x,.03,1.63),.023,'Ivory')
        beam('Thread through heddle',(x,.03,1.63),(x,-.53,1.40),.023,'Ivory')
        if i%2==0:
            beam('Heddle eye support',(x,.03,1.63),(x,.03,2.30),.028,'Steel')
    cloth=box('Woven fabric span',(0,-.87,1.29),(2.91,.83,.045),'Teal',.008)
    cloth.rotation_euler.x=.26
    for y in (-.56,-.40):
        box('Shuttle race',(0,y,1.47),(3.70,.10,.12),'Steel')
    box('Weft shuttle',(.57,-.48,1.59),(.52,.20,.16),'Ochre',.05)
    box('Heddle support bar',(0,.03,2.30),(3.72,.16,.13),'Graphite')
    box('Operator console',(1.63,-1.6,1.62),(.65,.28,.45),'Graphite')
    box('Weave status display',(1.63,-1.76,1.66),(.42,.026,.23),'Cyan')
    for i in range(4):
        cylinder('Control button',(1.43+i*.13,-1.76,1.48),.037,.025,'Amber','Y')


def orbital_crystal_growth_rack():
    # Three separate thermally isolated scientific growth cells, open service frame.
    box('Instrument rack base',(0,0,.15),(4.8,2.35,.30),'Graphite')
    for x in (-2.20,2.20):
        for y in (-.90,.90):
            beam('Rack upright',(x,y,.30),(x,y,2.85),.19,'Steel')
        box('Rack cross brace',(x,0,2.82),(.20,2.05,.19),'Teal')
    for z in (.52,2.75):
        box('Rack instrument rail',(0,.8,z),(4.52,.21,.15),'Teal')
    for x in (-1.45,0,1.45):
        cylinder('Thermal cell lower jacket',(x,0,.74),.48,.55,'Teal',vertices=32)
        cylinder('Thermal cell upper jacket',(x,0,2.14),.48,.46,'Teal',vertices=32)
        for z in (1.02,1.90):
            ring('Sealed ampoule collar',(x,0,z),.38,.065,'Copper')
        for dx in (-.38,.38):
            beam('Ampoule frame rail',(x+dx,0,1.04),(x+dx,0,1.91),.075,'Steel')
        crystal=cylinder('Faceted crystal specimen',(x,0,1.46),.23,.66,'Ice','Z',.12,vertices=6)
        cylinder('Crystal substrate',(x,0,1.12),.29,.09,'Slate',vertices=16)
        cylinder('Optical measurement head',(x,-.54,1.46),.19,.23,'Graphite','Y')
        cylinder('Optical aperture',(x,-.67,1.46),.12,.035,'Cyan','Y')
        beam('Instrument return line',(x,.48,.76),(x,.78,.76),.095,'Copper')
        beam('Instrument vertical line',(x,.78,.76),(x,.78,2.22),.095,'Copper')
        box('Cell controller',(x,-.60,.59),(.58,.25,.29),'Ivory')
        box('Cell status display',(x,-.74,.61),(.35,.025,.11),'Cyan')
        for j in range(5):
            box('Heat dissipation fin',(x,.28+j*.09,2.48),(.72,.045,.22),'Steel')
    box('Shared experiment processor',(0,.64,2.48),(1.75,.31,.41),'Graphite')
    box('Processor status panel',(0,.46,2.48),(.91,.025,.18),'Cyan')


def surface_road_grader():
    # Articulated six-wheel grader: road levelling, not excavation.
    box('Rear power chassis',(0,1.75,.94),(2.05,2.25,.50),'Ochre')
    box('Engine housing',(0,2.03,1.48),(1.55,1.66,.88),'Slate')
    box('Forward spine',(0,-.9,1.30),(.50,3.8,.48),'Ochre')
    cylinder('Articulation pivot',(0,.53,1.11),.29,.52,'Steel')
    for y in (-2.68,1.12,2.52):
        cylinder('Axle',(0,y,.60),.17,2.35,'Steel','X')
        for x in (-1.17,1.17):
            cylinder('Industrial tire',(x,y,.61),.59,.39,'Graphite','X',vertices=32)
            cylinder('Wheel rim',(x*1.16,y,.61),.30,.10,'Steel','X')
            for i in range(12):
                a=2*PI*i/12
                tread=box('Tire tread',(x,y+.57*math.cos(a),.61+.57*math.sin(a)),(.38,.13,.14),'Graphite',.015)
                tread.rotation_euler.x=a
    box('Operator cab base',(0,.83,1.78),(1.5,1.24,.22),'Ochre')
    box('Operator cab roof',(0,.83,2.97),(1.66,1.35,.16),'Ochre')
    for x in (-.69,.69):
        for y in (.27,1.39):
            beam('Cab corner frame',(x,y,1.89),(x,y,2.90),.085,'Steel')
        box('Side window',(x,.83,2.40),(.045,.96,.88),'Teal')
    box('Forward window',(0,.26,2.40),(1.23,.04,.88),'Teal')
    cylinder('Blade circle drive',(0,-.83,1.01),.73,.15,'Graphite',vertices=32)
    ring('Blade slew ring',(0,-.83,.88),.66,.075,'Steel')
    for i in range(9):
        x=(i-4)*.36;y=-.84+.32*x
        panel=box('Curved blade segment',(x,y,.49),(.40,.18,.65),'Ochre',.035)
        panel.rotation_euler.z=.31
        edge=box('Replaceable cutting edge',(x,y-.08,.19),(.40,.10,.10),'Steel',.012)
        edge.rotation_euler.z=.31
    for x in (-.64,.64):
        beam('Blade lift ram',(x,-.36,1.56),(x,-.82,.84),.115,'Steel')
    for x in (-.58,.58):
        box('Front work lamp',(x,-2.89,1.17),(.24,.14,.19),'Cyan')
    for i in range(6):
        box('Engine cooling louver',(0,1.48+i*.17,1.94),(1.04,.065,.05),'Graphite')


def habitat_sanitation_module():
    # Open cutaway with accessible bathing stall, hygiene stations and utility chase.
    box('Wet room floor',(0,0,.11),(5.7,4.2,.22),'Slate')
    box('Utility back wall',(0,1.98,1.48),(5.7,.24,2.74),'Ivory')
    for x in (-2.73,2.73):
        box('Side return wall',(x,.92,1.35),(.20,2.12,2.49),'Ivory')
    for x in (-1.65,.0,1.65):
        box('Shower privacy panel',(x,.75,1.36),(.09,1.96,2.30),'Teal')
        box('Non-slip shower tray',(x+.65,1.05,.26),(1.19,1.65,.10),'Steel')
        cylinder('Floor drain',(x+.65,1.07,.32),.095,.026,'Graphite')
        beam('Shower supply riser',(x+.65,1.78,.45),(x+.65,1.78,2.44),.07,'Copper')
        beam('Shower arm',(x+.65,1.78,2.44),(x+.65,1.28,2.44),.065,'Steel')
        cylinder('Shower head',(x+.65,1.28,2.35),.16,.10,'Steel')
        cylinder('Water control',(x+.65,1.80,1.25),.11,.075,'Ochre','Y')
    box('Accessible fold-down seat',(-2.36,.77,.73),(.64,.62,.12),'Ivory')
    beam('Accessible grab rail',(-2.62,.4,1.03),(-2.62,1.48,1.03),.065,'Steel')
    for x in (-1.68,.0,1.68):
        box('Wash station pedestal',(x,-1.39,.61),(1.16,.72,.80),'Teal')
        box('Wash counter',(x,-1.39,1.05),(1.30,.85,.14),'Ivory')
        ring('Basin rim',(x,-1.39,1.13),.28,.055,'Steel')
        cylinder('Basin interior',(x,-1.39,1.11),.25,.045,'Graphite')
        beam('Faucet upright',(x,-1.08,1.12),(x,-1.08,1.38),.065,'Steel')
        beam('Faucet spout',(x,-1.08,1.38),(x,-1.32,1.38),.055,'Steel')
        box('Hygiene dispenser',(x+.42,-1.10,1.28),(.16,.17,.27),'Ivory')
    for i in range(6):
        box('Floor drainage grate',(-2.20+i*.87,-.40,.23),(.68,.11,.035),'Graphite')
    box('Water recovery controller',(2.30,1.87,2.46),(.58,.20,.49),'Graphite')
    box('Recovery status',(2.30,1.75,2.48),(.38,.025,.22),'Cyan')


def orbital_starshade():
    # Free-flying coronagraph: opaque central screen with twelve tapered petals.
    cylinder('Service bus',(0,0,-.46),.91,.65,'Slate',vertices=32)
    cylinder('Central occulting screen',(0,0,0),2.15,.12,'Graphite',vertices=64)
    ring('Screen structural rim',(0,0,-.10),2.04,.08,'Steel')
    for i in range(12):
        a=2*PI*i/12
        def polar(r,w,z):
            return (r*math.cos(a)-w*math.sin(a),r*math.sin(a)+w*math.cos(a),z)
        stations=[(2.0,.49),(2.9,.48),(3.8,.33),(4.7,.17),(5.25,.025)]
        verts=[polar(r,side*w,0) for r,w in stations for side in (-1,1)]
        faces=[(2*j,2*j+1,2*j+3,2*j+2) for j in range(len(stations)-1)]
        mesh=bpy.data.meshes.new('Occulter petal mesh');mesh.from_pydata(verts,[],faces);mesh.update()
        obj=bpy.data.objects.new('Independent occulting petal %02d'%(i+1),mesh)
        bpy.context.collection.objects.link(obj);finish(obj,obj.name,'Graphite')
        obj.modifiers.new('Opaque membrane thickness','SOLIDIFY').thickness=.025
        for side in (-1,1):
            for j in range(len(stations)-1):
                r,w=stations[j];r2,w2=stations[j+1]
                beam('Petal perimeter spar',polar(r,side*w,-.045),polar(r2,side*w2,-.045),.048,'Steel')
        beam('Deployment spine',polar(1.0,0,-.18),polar(5.1,0,-.065),.075,'Slate')
        cylinder('Root hinge',polar(2.05,0,-.16),.115,.12,'Ochre')
    for i in range(4):
        a=i*PI/2
        x,y=.77*math.cos(a),.77*math.sin(a)
        cylinder('Formation flight thruster',(x,y,-.84),.18,.27,'Steel','Z',.12)
        cylinder('Thruster aperture',(x,y,-.99),.11,.035,'Graphite')
    for x in (-.55,.55):
        box('Navigation sensor',(x,-.48,-.81),(.30,.24,.18),'Ivory')
        box('Sensor aperture',(x,-.48,-.92),(.15,.13,.028),'Cyan')


def surface_dust_decontamination_portal():
    # Drive-through exterior cleaning bay; open access from both ends.
    box('Raised wash platform',(0,0,.12),(4.8,6.0,.24),'Slate')
    for y in (-3.05,3.05):
        ramp=box('Approach ramp',(0,y,.08),(4.0,.7,.16),'Steel');ramp.rotation_euler.x=.12 if y<0 else -.12
    for x in (-2.05,2.05):
        box('Drainage trench',(x,0,.26),(.25,5.6,.055),'Graphite')
        for j in range(18):
            box('Drain grate',(x,-2.55+j*.30,.31),(.28,.065,.045),'Steel')
        for y in (-1.75,1.75):
            box('Portal pillar',(x,y,1.78),(.38,.45,3.28),'Ivory')
            for z in (.75,1.35,1.95,2.55):
                cylinder('Directed cleaning nozzle',(x*.91,y,z),.07,.25,'Copper','X',vertices=12)
            box('Safety lamp',(x,y,3.43),(.24,.25,.13),'Amber')
        beam('Fluid supply manifold',(x,-1.75,3.35),(x,1.75,3.35),.14,'Copper')
    for y in (-1.75,1.75):
        box('Overhead service bridge',(0,y,3.40),(4.45,.48,.34),'Teal')
        for x in (-1.4,-.7,0,.7,1.4):
            cylinder('Downward spray head',(x,y,3.15),.12,.20,'Steel',vertices=12)
    box('Side filter and pump housing',(2.72,.65,.89),(.92,2.14,1.48),'Ochre')
    for y in (.05,.65,1.25):
        cylinder('Replaceable filter cartridge',(2.72,y,1.72),.20,.40,'Steel')
    box('Control display',(2.70,-.46,1.21),(.52,.07,.32),'Cyan')


def habitat_ceramics_workshop():
    # Open civilian craft room with pottery wheels, kiln and drying racks.
    box('Workshop deck',(0,0,.11),(6.2,4.8,.22),'Slate')
    box('Rear utility wall',(0,2.28,1.45),(6.2,.22,2.65),'Ivory')
    for x in (-1.95,0,1.95):
        box('Pottery workstation',(x,-.90,.57),(1.38,1.0,.80),'Teal')
        box('Work surface',(x,-.90,1.02),(1.46,1.08,.12),'Steel')
        cylinder('Pottery wheel',(x,-.90,1.13),.38,.12,'Graphite',vertices=32)
        cylinder('Clay vessel foot',(x,-.90,1.24),.15,.15,'Sand')
        cylinder('Clay vessel body',(x,-.90,1.43),.20,.30,'Sand','Z',.29)
        ring('Vessel mouth',(x,-.90,1.59),.25,.045,'Stone')
        cylinder('Stool pedestal',(x,-1.87,.43),.12,.62,'Steel')
        cylinder('Stool seat',(x,-1.87,.79),.27,.15,'Ochre')
    box('Kiln insulated body',(-2.08,1.35,1.12),(1.52,1.45,1.80),'Graphite',.18)
    cylinder('Kiln door',(-2.08,.60,1.23),.56,.18,'Steel','Y',vertices=32)
    ring('Kiln seal',(-2.08,.49,1.23),.45,.055,'Ochre','Y')
    box('Kiln controller',(-1.52,.55,1.72),(.24,.12,.22),'Cyan')
    cylinder('Kiln exhaust',(-2.08,1.35,2.18),.19,.55,'Copper')
    for x in (.45,2.6):
        for y in (1.04,2.02):
            beam('Drying rack upright',(x,y,.22),(x,y,2.48),.075,'Steel')
    for z in (.50,1.08,1.66,2.24):
        box('Drying rack shelf',(1.53,1.53,z),(2.3,1.02,.09),'Teal')
        for i in range(5):
            x=.70+i*.39
            cylinder('Drying ceramic cup',(x,1.53,z+.19),.12,.28,'Sand','Z',.15,vertices=16)
            ring('Cup lip',(x,1.53,z+.34),.13,.025,'Stone')


def orbital_radiator_wing():
    # Spacecraft thermal rejection module; two folding fin banks with fluid manifolds.
    box('Ship mounting spine',(0,0,0),(1.38,2.9,.62),'Graphite')
    for y in (-.96,.96):
        cylinder('Mounting flange',(0,y,-.45),.43,.27,'Steel',vertices=24)
        ring('Flange gasket',(0,y,-.60),.31,.055,'Ochre')
    for side in (-1,1):
        for j in range(3):
            x=side*(1.7+j*2.0)
            box('Radiator panel substrate',(x,0,0),(1.88,2.7,.16),'Slate')
            for k in range(12):
                y=-1.18+k*.215
                box('Thermal rejection fin',(x,y,.14),(1.68,.11,.18),'Ivory',.018)
            for y in (-1.24,1.24):
                box('Panel perimeter rail',(x,y,.03),(1.90,.12,.24),'Steel')
                beam('Coolant manifold',(x-.87,y,-.16),(x+.87,y,-.16),.10,'Copper')
            for y in (-.86,.86):
                cylinder('Deployment hinge',(side*(.70+j*2),y,-.02),.14,.32,'Ochre','Y',vertices=16)
        for y in (-.56,.56):
            beam('Root coolant feed',(side*.35,y,-.36),(side*1.15,y,-.16),.13,'Copper')
        box('Temperature telemetry',(side*.52,-1.48,.16),(.27,.09,.18),'Cyan')


def surface_lightning_protection_mast():
    # Isolated colony lightning arrestor with a visible down-conductor and grounding grid.
    box('Grounding plinth',(0,0,.14),(3.8,3.8,.28),'Slate')
    for x in (-1.55,1.55):
        for y in (-1.55,1.55):
            box('Ground anchor block',(x,y,.30),(.46,.46,.28),'Stone')
            beam('Buried-grid access strip',(x,y,.32),(0,0,.32),.095,'Copper')
            beam('Tower leg',(x*.58,y*.58,.33),(x*.12,y*.12,5.2),.14,'Steel')
    for k in range(4):
        z=.75+k*1.1; a=1.55*.58*(1-(z-.33)/6.1)
        for x in (-a,a):
            beam('Lattice cross brace',(x,-a,z),(x,a,z+.94),.08,'Steel')
        for y in (-a,a):
            beam('Lattice cross brace',(-a,y,z),(a,y,z+.94),.08,'Steel')
        box('Lattice tie frame',(0,0,z),(2*a+.12,2*a+.12,.09),'Graphite',.02)
    cylinder('Insulated apex mount',(0,0,5.22),.31,.55,'Ivory',vertices=16)
    cylinder('Air terminal',(0,0,6.03),.10,1.35,'Copper','Z',.025,vertices=16)
    for y in (-.28,.28):
        beam('Down conductor',(0,y,5.06),(.92,y,.39),.07,'Copper')
    box('Surge monitor',(1.33,0,.75),(.52,.64,.78),'Teal')
    box('Surge monitor status',(1.33,-.33,.89),(.30,.035,.17),'Cyan')
    cylinder('Warning beacon',(1.33,0,1.22),.13,.15,'Amber')


def habitat_optical_fabrication_bench():
    # Precision lens grinding and alignment workstation, usable as a repair/crafting station.
    box('Workshop deck',(0,0,.10),(5.5,3.8,.20),'Slate')
    box('Rear clean-room partition',(0,1.76,1.48),(5.5,.18,2.76),'Ivory')
    for x in (-1.78,0,1.78):
        box('Vibration-isolated cabinet',(x,.44,.59),(1.62,1.34,.80),'Teal')
        box('Optical worktop',(x,.44,1.03),(1.65,1.40,.16),'Steel')
        box('Drawer handle',(x,-.25,.70),(.50,.08,.06),'Graphite')
    cylinder('Lapping platen',(-1.78,.44,1.22),.48,.25,'Graphite',vertices=32)
    cylinder('Grinding blank',(-1.78,.44,1.38),.31,.08,'Ice',vertices=32)
    beam('Polishing arm',(-2.25,.96,1.12),(-2.25,.96,1.92),.16,'Steel')
    beam('Polishing arm',(-2.25,.96,1.92),(-1.78,.44,1.92),.13,'Steel')
    cylinder('Polishing head',(-1.78,.44,1.67),.19,.47,'Ochre')
    for y in (.12,.77):
        beam('Alignment rail',(-.74,y,1.18),(.74,y,1.18),.095,'Graphite')
    for x in (-.54,.04,.59):
        box('Adjustable optical pedestal',(x,.44,1.34),(.19,.28,.26),'Ochre')
        ring('Lens retaining ring',(x,.44,1.68),.25,.045,'Steel','X')
        cylinder('Optical test element',(x,.44,1.68),.20,.065,'Ice','X',vertices=32)
    box('Metrology hood',(1.78,.44,1.71),(1.16,.97,1.22),'Graphite',.12)
    cylinder('Interferometer aperture',(1.78,-.07,1.72),.29,.13,'Cyan','Y',vertices=32)
    box('Metrology display',(1.78,-.09,2.04),(.68,.05,.20),'Cyan')
    for x in (-1.9,-1.3,-.7,.7,1.3,1.9):
        ring('Spare lens blank',(x,1.62,2.11),.20,.045,'Ice','Y')
    box('Storage shelf',(0,1.39,1.85),(4.75,.52,.10),'Steel')


def orbital_flywheel_energy_buffer():
    # Counter-rotating mechanical storage rotors in an open service cage.
    for x in (-1.75,1.75):
        box('End mounting plate',(x,0,0),(.30,2.78,2.78),'Graphite',.13)
        cylinder('Magnetic bearing',(x*.83,0,0),.59,.43,'Steel','X',vertices=32)
        ring('Bearing status ring',(x*.72,0,0),.46,.055,'Cyan','X')
    for y in (-1.22,1.22):
        for z in (-1.22,1.22):
            beam('Structural cage rail',(-1.72,y,z),(1.72,y,z),.16,'Ochre')
    cylinder('Axial shaft',(0,0,0),.26,3.04,'Steel','X')
    for x in (-.77,.77):
        cylinder('Flywheel rotor hub',(x,0,0),.44,.45,'Steel','X',vertices=32)
        ring('Composite flywheel rim',(x,0,0),.92,.19,'Graphite','X')
        for i in range(8):
            a=i*PI/4
            beam('Rotor spoke',(x,.33*math.cos(a),.33*math.sin(a)),(x,.86*math.cos(a),.86*math.sin(a)),.12,'Teal')
        for j in (-1,1):
            ring('Rotor reinforcement',(x+j*.15,0,0),.93,.055,'Steel','X')
    for x in (-1.18,1.18):
        ring('Stator winding',(x,0,0),.77,.12,'Copper','X')
    box('Power conditioning enclosure',(0,0,-1.36),(1.90,1.05,.37),'Teal')
    for x in (-.61,0,.61):
        cylinder('Power bus connector',(x,-.60,-1.36),.13,.23,'Copper','Y')
    box('Energy telemetry display',(0,-.56,-1.16),(.48,.05,.18),'Cyan')



def surface_irrigation_pivot():
    box('Pivot foundation',(0,0,.13),(2.2,2.2,.26),'Stone')
    cylinder('Water supply pedestal',(0,0,.85),.34,1.5,'Steel')
    ring('Rotary swivel coupling',(0,0,1.55),.35,.075,'Copper')
    cylinder('Pivot riser',(0,0,2.4),.13,1.6,'Teal')
    box('Pump cabinet',(-.64,.62,.58),(.73,.65,.88),'Ochre')
    box('Pump status panel',(-.64,.27,.66),(.30,.05,.20),'Cyan')
    for side in (-1,1):
        beam('Pivot brace',(side*.78,0,.3),(0,0,2.9),.14,'Steel')
    beam('Main irrigation pipe',(0,0,3.05),(12.3,0,3.05),.23,'Teal')
    for i in range(6):
        x=i*2.0+.2
        for y in (-.45,.45):
            beam('Lower truss rail',(x,y,2.38),(x+2,y,2.38),.09,'Steel')
            beam('Diagonal span stay',(x,y,2.38),(x+1,0,3.05),.07,'Steel')
            beam('Diagonal span stay',(x+1,0,3.05),(x+2,y,2.38),.07,'Steel')
        beam('Cross tie',(x,-.45,2.38),(x,.45,2.38),.08,'Steel')
        for k in (.5,1.5):
            cylinder('Sprinkler drop',(x+k,0,2.52),.045,1.00,'Copper',vertices=12)
            cylinder('Sprinkler distribution head',(x+k,0,2.00),.15,.09,'Ochre',vertices=12)
    for x in (6.2,12.2):
        for y in (-.82,.82):
            beam('Mobile tower support',(x,y,.62),(x,0,3.05),.14,'Ochre')
            cylinder('Field tire',(x,y,.52),.50,.30,'Graphite','X',vertices=24)
            cylinder('Wheel hub',(x+.17,y,.52),.24,.08,'Steel','X')
        beam('Axle cross member',(x,-.82,.58),(x,.82,.58),.20,'Steel')
        box('Drive control enclosure',(x,0,.94),(.48,.52,.38),'Ivory')
    cylinder('End pressure regulator',(12.3,0,3.05),.22,.25,'Ochre','X')


def habitat_prosthetics_fitting_lab():
    box('Accessible floor',(0,0,.10),(5.8,4.6,.20),'Slate')
    box('Rear wall',(0,2.22,1.48),(5.8,.16,2.76),'Ivory')
    box('Work counter',(1.63,1.35,.98),(2.10,1.10,.16),'Teal')
    for x in (.75,2.51):
        box('Counter leg',(x,1.35,.56),(.17,.92,.77),'Steel')
    for z in (.42,.68):
        box('Supply drawer',(2.22,1.15,z),(.53,.57,.19),'Ivory')
        box('Drawer pull',(2.22,.84,z),(.29,.06,.05),'Steel')
    box('Fitting chair base',(-1.38,.30,.29),(1.20,1.30,.25),'Graphite')
    cylinder('Adjustable chair pedestal',(-1.38,.30,.61),.21,.50,'Steel')
    box('Padded fitting seat',(-1.38,.30,.91),(.99,.88,.23),'Teal')
    back=box('Padded backrest',(-1.38,.77,1.37),(.99,.19,.80),'Teal')
    back.rotation_euler.x=-.13
    for x in (-1.91,-.85):
        beam('Armrest upright',(x,.4,.95),(x,.4,1.22),.09,'Steel')
        box('Armrest',(x,.30,1.26),(.15,.62,.12),'Graphite')
    box('Adjustable foot platform',(-1.38,-.42,.28),(.79,.52,.09),'Ochre')
    for x in (-.57,.57):
        beam('Parallel gait rail',(x,-1.83,1.13),(x,-.47,1.13),.09,'Steel')
        for y in (-1.83,-.47):
            beam('Gait rail post',(x,y,.2),(x,y,1.13),.09,'Steel')
    box('Pressure measurement mat',(0,-1.15,.23),(.87,1.72,.055),'Graphite')
    for y in (-1.67,-1.38,-1.09,-.80):
        box('Measurement strip',(0,y,.267),(.73,.035,.016),'Cyan')
    for x in (1.07,1.90):
        cylinder('Limb display base',(x,1.36,1.11),.26,.11,'Graphite')
        cylinder('Prosthetic socket',(x,1.36,1.92),.23,.42,'Ivory','Z',.17)
        ring('Socket interface',(x,1.36,1.70),.16,.043,'Copper')
        beam('Assistive limb pylon',(x,1.36,1.63),(x,1.29,1.23),.10,'Steel')
        box('Articulated foot',(x,1.18,1.17),(.24,.43,.10),'Graphite')
    box('Measurement monitor',(0,2.08,1.88),(1.25,.12,.74),'Graphite')
    box('Measurement display',(0,1.999,1.88),(1.12,.035,.61),'Cyan')
    box('Tool rail',(1.73,2.07,1.52),(1.55,.12,.09),'Steel')
    for x in (1.17,1.45,1.73,2.01,2.29):
        box('Fitting tool',(x,1.99,1.36),(.09,.09,.24),'Ochre')


def orbital_inspection_crawler():
    box('Low-profile crawler chassis',(0,0,.54),(1.52,2.20,.34),'Teal',.13)
    box('Instrument housing',(0,.22,.82),(1.22,1.44,.36),'Ivory',.10)
    for s in (-1,1):
        for y in (-.76,.76):
            beam('Independent bogie arm',(s*.61,y,.48),(s*.98,y,.34),.18,'Ochre')
            cylinder('Magnetic traction wheel',(s*.98,y,.32),.31,.29,'Graphite','X',vertices=28)
            cylinder('Magnetic hub',(s*1.15,y,.32),.22,.065,'Steel','X')
            for j in range(10):
                a=j*PI/5
                p=box('Replaceable traction lug',(s*.98,y+.31*math.cos(a),.32+.31*math.sin(a)),(.28,.115,.075),'Steel',.014)
                p.rotation_euler.x=a-PI/2
        box('Side worklight',(s*.49,-1.06,.65),(.24,.10,.12),'Cyan')
    cylinder('Azimuth turret',(0,.45,1.06),.29,.22,'Graphite')
    beam('Sensor arm shoulder',(0,.45,1.15),(0,.20,1.72),.17,'Ochre')
    cylinder('Shoulder joint',(0,.20,1.72),.15,.27,'Steel','X')
    beam('Sensor arm elbow',(0,.20,1.72),(.18,-.51,1.54),.13,'Teal')
    cylinder('Elbow joint',(.18,-.51,1.54),.13,.22,'Steel','X')
    beam('Wrist linkage',(.18,-.51,1.54),(.18,-.88,1.07),.10,'Ochre')
    box('Multispectral scan head',(.18,-.95,1.05),(.55,.33,.29),'Graphite')
    for x in (.02,.34):
        cylinder('Scan optics',(x,-1.13,1.05),.11,.07,'Steel','Y')
        cylinder('Optical aperture',(x,-1.18,1.05),.075,.04,'Cyan','Y')
    cylinder('Ultrasonic contact probe',(.18,-.95,.86),.08,.15,'Copper')
    ring('Recovery tether eye',(0,1.11,.67),.18,.045,'Steel','X')
    beam('Folded antenna',(-.45,.77,1.01),(-.60,1.14,1.48),.045,'Steel')
    box('Power status',(0,.88,1.02),(.38,.07,.08),'Amber')


def surface_grain_harvester():
    # Grounded combine harvester; header, conveyor, threshing enclosure and grain tank.
    box('Main chassis',(0,.15,.96),(3.05,5.15,.48),'Graphite',.16)
    for s in (-1,1):
        for y,r in ((-1.5,.92),(1.72,.62)):
            cylinder('Agricultural tire',(s*1.52,y,r),r,.70,'Graphite','X',vertices=32)
            cylinder('Wheel hub',(s*1.91,y,r),r*.43,.12,'Ochre','X')
            for j in range(14):
                a=j*2*PI/14
                tread=box('Chevron tire cleat',(s*1.52,y+r*math.cos(a),r+r*math.sin(a)),(.66,.18,.12),'Slate',.025)
                tread.rotation_euler.x=a-PI/2
        box('Threshing side service hatch',(s*1.27,.53,1.73),(.19,2.30,.97),'Teal')
        box('Hatch latch',(s*1.39,.08,1.78),(.08,.24,.09),'Steel')
    box('Threshing enclosure',(0,.52,1.76),(2.6,3.22,1.18),'Ochre',.18)
    box('Grain tank',(0,.91,2.58),(2.45,2.02,.82),'Ivory',.12)
    box('Tank upper recess',(0,.91,3.0),(2.12,1.70,.07),'Sand')
    box('Operator cab',(0,-1.5,2.43),(1.67,1.32,1.42),'Teal',.12)
    box('Cab front glazing',(0,-2.17,2.57),(1.47,.05,.89),'Cyan')
    box('Cab roof',(0,-1.5,3.19),(1.85,1.48,.13),'Ivory')
    beam('Feeder conveyor', (0,-2.04,1.47),(0,-3.26,.61),.68,'Graphite')
    box('Header trough',(0,-3.63,.46),(5.60,.87,.27),'Ochre')
    cylinder('Header cross auger',(0,-3.61,.66),.22,5.28,'Steel','X')
    for i in range(24):
        x=-2.62+i*.224
        box('Cutter finger',(x,-4.09,.38),(.10,.46,.09),'Steel',.018)
    for s in (-1,1):
        box('Crop divider',(s*2.78,-3.93,.57),(.15,.91,.36),'Ivory')
        beam('Reel arm',(s*2.57,-3.23,.70),(s*2.57,-3.95,1.18),.12,'Teal')
        ring('Reel end frame',(s*2.53,-3.95,1.18),.50,.055,'Steel','X')
    cylinder('Reel axle',(0,-3.95,1.18),.07,5.15,'Graphite','X')
    for j in range(6):
        a=j*PI/3;y=-3.95+.50*math.cos(a);z=1.18+.50*math.sin(a)
        beam('Crop gathering bat',(-2.53,y,z),(2.53,y,z),.065,'Teal')
        for s in (-1,1):
            beam('Reel spoke',(s*2.53,-3.95,1.18),(s*2.53,y,z),.045,'Steel')
    cylinder('Unloading auger pivot',(1.12,1.25,2.77),.20,.44,'Steel')
    beam('Grain discharge auger',(1.12,1.25,2.9),(3.32,2.6,2.9),.23,'Ochre')
    box('Discharge spout',(3.32,2.6,2.74),(.28,.31,.32),'Graphite')


def habitat_fermentation_plant():
    box('Washable production slab',(0,0,.12),(6.8,5.3,.24),'Slate')
    box('Rear service wall',(0,2.53,1.56),(6.8,.17,2.88),'Ivory')
    for x in (-2.05,0,2.05):
        for dx in (-.55,.55):
            for dy in (-.48,.48):
                beam('Sanitary tank support',(x+dx,1.0+dy,.24),(x+dx,1.0+dy,.76),.12,'Steel')
        cylinder('Fermentation cone',(x,1.0,.90),.24,.62,'Steel','Z',.72,32)
        cylinder('Jacketed fermenter',(x,1.0,1.72),.72,1.10,'Steel',vertices=32)
        cylinder('Dished tank crown',(x,1.0,2.38),.72,.24,'Steel','Z',.34,32)
        for z in (1.30,2.12):
            ring('Insulation seam',(x,1.0,z),.73,.032,'Teal')
        cylinder('Sanitary top port',(x,1.0,2.62),.13,.24,'Copper')
        beam('Cooling return line',(x,1.0,2.74),(x,2.29,2.74),.09,'Copper')
        box('Fermentation status panel',(x,.26,1.75),(.33,.07,.24),'Graphite')
        box('Active batch indicator',(x,.216,1.75),(.25,.02,.13),'Cyan')
        cylinder('Sampling valve',(x,.23,1.22),.085,.20,'Copper','Y')
        ring('Valve handwheel',(x,.08,1.22),.12,.025,'Ochre','Y')
    beam('Common thermal header',(-2.8,2.29,2.74),(2.8,2.29,2.74),.13,'Teal')
    box('Clean-in-place skid',(-2.38,-1.57,.38),(1.58,1.33,.28),'Graphite')
    for x in (-2.76,-2.02):
        cylinder('Wash solution vessel',(x,-1.57,.87),.30,.75,'Ivory')
        cylinder('Sanitary pump motor',(x,-1.10,.52),.17,.29,'Teal','Y')
    box('Packaging bench',(1.50,-1.47,1.00),(2.61,1.01,.16),'Steel')
    for x in (.32,2.68):
        box('Bench support',(x,-1.47,.57),(.12,.82,.74),'Steel')
    for i in range(6):
        x=.48+i*.38
        cylinder('Finished culture jar',(x,-1.48,1.25),.14,.35,'Sand',vertices=20)
        cylinder('Jar closure',(x,-1.48,1.45),.15,.06,'Teal')
    box('Batch record terminal',(2.48,-1.36,1.57),(.45,.29,.52),'Graphite')
    box('Batch record display',(2.48,-1.52,1.60),(.35,.025,.30),'Cyan')
    box('Central floor drain',(0,-.40,.25),(.44,.44,.04),'Graphite')
    for x in (-.16,-.08,0,.08,.16):
        box('Drain grate',(x,-.40,.28),(.025,.39,.025),'Steel')


def orbital_particle_spectrometer():
    # Open instrument geometry: opposed detector heads, magnetic yoke and calibration bus.
    box('Instrument bus',(0,0,-.42),(2.20,2.05,.54),'Graphite',.15)
    box('Electronics enclosure',(0,.56,-.06),(1.65,.72,.35),'Ivory')
    for x in (-.69,.69):
        box('Detector support tower',(x,0,.29),(.31,1.77,.59),'Teal')
        for y in (-.56,.56):
            beam('Instrument brace',(x,y,-.14),(x*1.55,y,.68),.10,'Steel')
    for s in (-1,1):
        x=s*.91
        cylinder('Magnetic pole casing',(x,0,.96),.68,.50,'Graphite','X',vertices=32)
        cylinder('Pole face',(s*.63,0,.96),.52,.10,'Steel','X',vertices=32)
        for dx in (-.15,0,.15):
            ring('Magnet winding',(x+dx,0,.96),.58,.055,'Copper','X')
        box('Cryocooler housing',(s*1.16,.60,.42),(.53,.54,.64),'Ivory')
        for i in range(7):
            box('Cryocooler radiator fin',(s*1.16,.88,.17+i*.08),(.61,.28,.035),'Steel')
    for y in (-1.03,1.03):
        cylinder('Directional particle aperture',(0,y,.96),.39,.25,'Teal','Y')
        ring('Aperture flange',(0,y*1.13,.96),.36,.055,'Ochre','Y')
        for x in (-.14,0,.14):
            beam('Collimator grid',(x,y*1.14,.70),(x,y*1.14,1.22),.025,'Graphite')
    for x in (-.30,0,.30):
        box('Segmented detector tile',(x,.38,.30),(.26,.32,.09),'Cyan')
    for side in (-1,1):
        beam('Calibration rail',(side*.38,-.75,.32),(side*.38,.75,.32),.055,'Steel')
        ring('Launch restraint eye',(side*.88,-.92,-.28),.13,.037,'Ochre','X')
    box('Calibration carriage',(0,-.43,.42),(.52,.30,.14),'Ochre')
    cylinder('Calibration target',(0,-.43,.55),.13,.15,'Ivory')
    box('Telemetry status strip',(0,.96,-.06),(.62,.045,.10),'Cyan')



def surface_rock_crusher():
    box('Foundation skid',(0,0,.16),(4.9,6.5,.32),'Graphite')
    for x in (-1.55,1.55):
        for y in (-1.6,.5):
            beam('Crusher support leg',(x,y,.25),(x,y,2.02),.24,'Steel')
        beam('Skid diagonal brace',(x,-1.6,.35),(x,.5,1.9),.17,'Teal')
        box('Jaw side plate',(x,-.48,2.27),(.28,2.76,1.68),'Ochre',.12)
        cylinder('Eccentric axle',(x*1.13,-.28,2.48),.18,.52,'Steel','X')
        cylinder('Drive flywheel',(x*1.31,-.28,2.48),.76,.20,'Graphite','X',vertices=32)
        ring('Flywheel rim',(x*1.39,-.28,2.48),.66,.075,'Ochre','X')
        for k in range(5):
            a=k*2*PI/5
            beam('Flywheel spoke',(x*1.40,-.28,2.48),(x*1.40,-.28+.58*math.cos(a),2.48+.58*math.sin(a)),.11,'Steel')
        for s in (-1,1):
            wall=box('Hopper flared side',(x*.92,-.75+s*.66,3.53),(.18,1.34,1.03),'Ivory')
            wall.rotation_euler.y=x*.18
    for y,tilt in ((-1.13,-.28),(.18,.28)):
        jaw=box('Inclined crushing jaw',(0,y,2.39),(2.55,.29,1.60),'Steel')
        jaw.rotation_euler.x=tilt
        for i in range(9):
            tooth=box('Replaceable jaw corrugation',(-1.06+i*.265,y+(.19 if y<0 else -.19),2.42),(.095,.15,1.25),'Graphite')
            tooth.rotation_euler.x=tilt
    for y in (-1.91,.53):
        panel=box('Hopper end wall',(0,y,3.56),(3.15,.16,.94),'Ivory')
        panel.rotation_euler.x=.25 if y>0 else -.25
    for x in (-.79,.79):
        beam('Discharge conveyor frame',(x,.12,.58),(x,3.56,1.64),.14,'Teal')
        beam('Conveyor support',(x,2.9,.25),(x,2.9,1.40),.15,'Steel')
    belt=box('Inclined rubber belt',(0,1.84,1.16),(1.40,3.65,.13),'Graphite')
    belt.rotation_euler.x=.30
    for i in range(10):
        y=.25+i*.35
        cylinder('Conveyor idler',(0,y,.60+(y-.12)*.308),.10,1.65,'Steel','X')
    box('Motor control enclosure',(-1.85,.85,.90),(.58,.62,1.19),'Teal')
    box('Motor control display',(-1.85,.52,1.1),(.38,.035,.25),'Cyan')


def habitat_pollinator_vivarium():
    box('Cleanable floor',(0,0,.12),(6.2,5.0,.24),'Slate')
    box('Rear utility wall',(0,2.4,1.55),(6.2,.16,2.86),'Ivory')
    for x in (-2.86,-.30):
        for y in (-1.95,2.15):
            beam('Flight enclosure post',(x,y,.24),(x,y,2.65),.11,'Teal')
        beam('Flight enclosure roof rail',(x,-1.95,2.65),(x,2.15,2.65),.09,'Teal')
        for i in range(12):
            y=-1.95+i*4.1/11
            beam('Flight mesh vertical',(x,y,.28),(x,y,2.62),.018,'Steel')
        for z in (.65,1.05,1.45,1.85,2.25):
            beam('Flight mesh horizontal',(x,-1.95,z),(x,2.15,z),.018,'Steel')
    for y in (-1.95,2.15):
        beam('Cross enclosure rail',(-2.86,y,2.65),(-.30,y,2.65),.09,'Teal')
        if y>0:
            for i in range(10):
                x=-2.86+i*2.56/9
                beam('Rear enclosure mesh',(x,y,.27),(x,y,2.65),.018,'Steel')
    for y in (-1.3,0,1.3):
        box('Hive stand',(-1.77,y,.58),(1.03,.72,.65),'Graphite')
        for z in (.99,1.24,1.49):
            box('Removable brood super',(-1.77,y,z),(.88,.66,.24),'Sand')
            box('Brood frame grip',(-1.31,y,z),(.055,.28,.065),'Steel')
        box('Insulated hive lid',(-1.77,y,1.68),(.96,.74,.13),'Ochre')
        box('Landing board',(-1.20,y,.89),(.27,.45,.07),'Ivory')
    for y in (-1.3,.1,1.5):
        cylinder('Nectar feeder pedestal',(-.67,y,.57),.13,.67,'Steel')
        cylinder('Nectar feeder tray',(-.67,y,.96),.31,.12,'Teal',vertices=24)
        cylinder('Feeder reservoir',(-.67,y,1.16),.19,.32,'Ivory')
    box('Husbandry worktop',(1.65,1.65,1.03),(2.40,.82,.13),'Steel')
    for x in (.62,2.68):
        box('Worktop cabinet',(x,1.65,.63),(.34,.73,.74),'Teal')
    for x in (.85,1.35,1.85):
        box('Transport colony cassette',(x,1.65,1.30),(.40,.55,.38),'Sand')
        for z in (1.21,1.32,1.43):
            box('Cassette ventilation slot',(x,1.36,z),(.31,.025,.045),'Graphite')
    box('Environmental controller',(2.5,2.22,1.66),(.70,.23,.65),'Graphite')
    box('Environmental display',(2.5,2.09,1.75),(.52,.025,.27),'Cyan')


def orbital_inflatable_habitat():
    # Build a continuous ribbed membrane from an original revolved cross section.
    profile=[(-3.5,1.05),(-3.15,1.44),(-2.75,2.12),(-2.25,2.55),(-1.6,2.73),(-.8,2.78),(0,2.80),(.8,2.78),(1.6,2.73),(2.25,2.55),(2.75,2.12),(3.15,1.44),(3.5,1.05)]
    n=48
    verts=[(r*math.cos(2*PI*j/n),y,r*math.sin(2*PI*j/n)) for y,r in profile for j in range(n)]
    faces=[(i*n+j,(i+1)*n+j,(i+1)*n+(j+1)%n,i*n+(j+1)%n) for i in range(len(profile)-1) for j in range(n)]
    mesh=bpy.data.meshes.new('Woven pressure envelope mesh')
    mesh.from_pydata(verts,[],faces);mesh.update()
    obj=bpy.data.objects.new('Expandable pressure envelope',mesh);bpy.context.collection.objects.link(obj)
    finish(obj,'Expandable pressure envelope','Ivory')
    for poly in mesh.polygons: poly.use_smooth=True
    for y,r in profile[1:-1]:
        ring('Circumferential restraint band',(0,y,0),r+.015,.055,'Teal','Y')
    for k in range(12):
        a=k*2*PI/12
        for (y0,r0),(y1,r1) in zip(profile[:-1],profile[1:]):
            beam('Longitudinal webbing',((r0+.045)*math.cos(a),y0,(r0+.045)*math.sin(a)),((r1+.045)*math.cos(a),y1,(r1+.045)*math.sin(a)),.075,'Sand')
    for s in (-1,1):
        cylinder('Rigid end bulkhead',(0,s*3.55,0),1.13,.35,'Steel','Y',vertices=32)
        cylinder('Docking neck',(0,s*3.99,0),.78,.58,'Graphite','Y')
        ring('Docking seal',(0,s*4.32,0),.66,.095,'Ochre','Y')
        cylinder('Docking hatch',(0,s*4.34,0),.54,.08,'Teal','Y')
        for k in range(4):
            a=k*PI/2
            box('Docking guide',( .80*math.cos(a),s*4.32,.80*math.sin(a)),(.16,.18,.16),'Ivory')
    for x in (-.53,.53):
        beam('External utility trunk',(x,-2.45,2.67),(x,2.45,2.67),.16,'Graphite')
        for y in (-1.8,0,1.8):
            box('Utility trunk standoff',(x,y,2.74),(.31,.23,.29),'Steel')
    box('Pressure monitoring pack',(0,0,3.02),(.92,.88,.31),'Ochre')
    box('Monitoring telemetry strip',(0,-.46,3.02),(.55,.04,.12),'Cyan')



def surface_snowplow():
    box('Tracked chassis',(0,0,.65),(2.75,4.5,.55),'Graphite',.15)
    box('Insulated operator cab',(0,-.75,1.58),(2.12,1.62,1.43),'Ivory',.18)
    box('Heated windscreen',(0,-1.57,1.85),(1.66,.09,.60),'Teal')
    for s in (-1,1):
        x=s*1.44
        box('Continuous track belt',(x,.15,.47),(.56,3.76,.78),'Graphite',.24)
        for y in (-1.33,-.65,0,.65,1.33):
            cylinder('Track road wheel',(x+s*.29,y,.44),.32,.09,'Steel','X')
        for i in range(14):
            y=-1.60+i*.25
            for z in (.08,.86):
                box('Traction cleat',(x,y,z),(.63,.12,.075),'Slate',.015)
        beam('Blade lift arm',(s*.81,-1.6,.79),(s*1.1,-2.64,.63),.25,'Ochre')
        beam('Lift cylinder',(s*.94,-1.58,1.2),(s*1.1,-2.64,.80),.15,'Steel')
        box('Side observation window',(s*1.07,-.70,1.91),(.05,.94,.50),'Teal')
        cylinder('Roof warning beacon',(s*.82,-.73,2.37),.12,.19,'Amber')
    # Curved moldboard: nine cross sections with a swept cutting edge.
    w=1.85
    profile=[(-2.79,.25),(-2.96,.52),(-2.97,.85),(-2.81,1.15),(-2.60,1.39)]
    verts=[(x,y+.24*x,z) for x in (-w,w) for y,z in profile]
    faces=[(i,i+1,i+6,i+5) for i in range(4)]
    mesh=bpy.data.meshes.new('Swept moldboard');mesh.from_pydata(verts,[],faces);mesh.update()
    obj=bpy.data.objects.new('Curved snow moldboard',mesh);bpy.context.collection.objects.link(obj);finish(obj,obj.name,'Ochre')
    obj.modifiers.new('Plate thickness','SOLIDIFY').thickness=.065
    beam('Replaceable cutting edge',(-w,-2.79-.24*w,.25),(w,-2.79+.24*w,.25),.12,'Steel')
    for x in (-1.5,-.75,0,.75,1.5):
        for (y0,z0),(y1,z1) in zip(profile[:-1],profile[1:]):
            beam('Moldboard rib',(x,y0+.24*x+.08,z0),(x,y1+.24*x+.08,z1),.075,'Steel')
    box('Rear grit hopper',(0,1.02,1.24),(2.14,1.63,.87),'Teal',.14)
    cylinder('Grit spreader',(0,2.03,.69),.39,.13,'Steel')
    box('Engine vent',(0,1.84,1.4),(1.42,.07,.33),'Graphite')


def habitat_print_shop():
    box('Workshop floor',(0,0,.12),(6.4,5.2,.24),'Slate')
    box('Rear wall',(0,2.5,1.48),(6.4,.18,2.72),'Ivory')
    box('Digital press base',(-1.48,.25,.68),(2.42,1.58,.88),'Teal')
    for x in (-2.38,-1.93,-1.48,-1.03,-.58):
        cylinder('Paper feed roller',(x,.25,1.2),.14,1.34,'Steel','Y')
    box('Press bridge',(-1.48,.25,1.88),(2.44,1.42,.48),'Graphite')
    for x in (-2.50,-.46):
        box('Press side frame',(x,.25,1.53),(.24,1.48,.75),'Ivory')
    for i,col in enumerate(('Cyan','Copper','Ochre','Graphite')):
        box('Removable ink cartridge',(-2.22+i*.49,-.51,1.86),(.35,.19,.32),col)
    box('Output tray',(.04,.25,1.13),(.81,1.24,.10),'Steel')
    for i in range(6):
        box('Printed sheet',(.04,.25,1.20+i*.018),(.62,.89,.014),'Ivory',.002)
    box('Finishing worktable',(1.78,-.72,.98),(2.12,1.2,.15),'Steel')
    for x in (.93,2.63):
        for y in (-1.18,-.26):
            beam('Worktable leg',(x,y,.24),(x,y,.91),.11,'Graphite')
    box('Paper trimmer',(1.72,-.72,1.10),(.90,.75,.11),'Teal')
    beam('Raised cutter lever',(2.13,-1.03,1.17),(2.13,-.35,1.58),.085,'Ochre')
    for x in (-2.18,-.99,.20,1.39,2.58):
        box('Paper stock cabinet',(x,2.10,.89),(1.08,.66,1.28),'Graphite')
        for z in (.53,.86,1.19):
            box('Indexed paper drawer',(x,1.74,z),(.95,.09,.27),'Sand')
            box('Drawer grip',(x,1.67,z),(.24,.065,.055),'Steel')
    box('Layout monitor',(2.43,.85,1.64),(.73,.13,.50),'Graphite')
    box('Page layout display',(2.43,.76,1.64),(.61,.025,.38),'Cyan')
    beam('Monitor stand',(2.43,.85,1.39),(2.43,.85,1.04),.12,'Steel')
    box('Layout desk',(2.05,.85,.98),(1.47,.70,.13),'Ivory')


def orbital_robotic_arm():
    cylinder('Station mounting flange',(0,0,.16),.92,.32,'Graphite',vertices=32)
    cylinder('Azimuth bearing',(0,0,.48),.63,.32,'Steel')
    ring('Bearing service collar',(0,0,.49),.65,.07,'Ochre')
    for k in range(8):
        a=k*PI/4
        cylinder('Flange captive bolt',(.77*math.cos(a),.77*math.sin(a),.34),.075,.13,'Steel',vertices=12)
    points=[(0,0,.84),(0,.15,1.53),(.18,1.26,3.28),(.44,2.82,3.91),(.44,3.52,3.30)]
    for i,(a,b) in enumerate(zip(points[:-1],points[1:])):
        aa,bb=Vector(a),Vector(b)
        direction=(bb-aa).normalized()
        cross=Vector((1,0,0))
        for side in (-1,1):
            beam('Paired articulated boom',(aa+cross*.19*side),(bb+cross*.19*side),.24,'Ivory')
        for t in (.27,.72):
            pos=aa.lerp(bb,t)
            beam('Boom cross tie',pos-cross*.29,pos+cross*.29,.13,'Teal')
        beam('External cable conduit',aa+Vector((-.32,0,.04)),bb+Vector((-.32,0,.04)),.065,'Copper')
    for i,pos in enumerate(points):
        cylinder('Rotary actuator',pos,.29 if i<4 else .23,.65 if i<4 else .48,'Graphite','X')
        for s in (-1,1):
            end=Vector(pos)+Vector((s*(.34 if i<4 else .25),0,0))
            cylinder('Actuator endplate',end,.24 if i<4 else .19,.10,'Ochre','X')
    x,y,z=points[-1]
    cylinder('Tool quick-change collar',(x,y+.25,z-.14),.24,.23,'Steel','Y')
    box('End effector body',(x,y+.48,z-.14),(.62,.34,.38),'Teal')
    for s in (-1,1):
        a=(x+s*.25,y+.57,z-.14);b=(x+s*.40,y+.98,z-.14);d=(x+s*.23,y+1.19,z-.14)
        beam('Grapple finger proximal',a,b,.14,'Steel')
        beam('Grapple finger tip',b,d,.12,'Ochre')
        box('Non-marring contact pad',(x+s*.22,y+1.19,z-.14),(.09,.18,.18),'Graphite')
    box('Wrist camera housing',(x,y+.50,z+.14),(.28,.22,.22),'Graphite')
    cylinder('Wrist camera lens',(x,y+.63,z+.14),.08,.07,'Cyan','Y')


def surface_mobile_batch_mixer():
    box('Towable plant chassis',(0,0,.55),(2.55,5.2,.48),'Graphite',.13)
    for s in (-1,1):
        for y in (.85,1.8):
            cylinder('Transport wheel',(s*1.35,y,.45),.45,.35,'Graphite','X')
            cylinder('Wheel hub',(s*1.54,y,.45),.19,.08,'Steel','X')
        for y in (-1.95,2.2):
            beam('Stabilizer leg',(s*1.07,y,.72),(s*1.48,y,.14),.18,'Ochre')
            box('Stabilizer foot',(s*1.48,y,.10),(.42,.48,.12),'Steel')
        beam('Hopper frame',(s*1.02,1.4,.78),(s*1.02,1.4,2.1),.16,'Steel')
        beam('Drawbar',(s*.75,-2.45,.58),(0,-3.45,.48),.19,'Ochre')
    ring('Tow eye',(0,-3.51,.48),.16,.04,'Steel')
    # Rotating mixer drum, on a shallow incline, with external reinforcing bands.
    drum=cylinder('Mixing drum',(0,-.67,1.52),.94,2.12,'Teal','Y',.75,32)
    drum.rotation_euler.x-=.20
    for y,z,r in ((-1.45,1.69,.85),(-.58,1.52,.93),(.19,1.37,.84)):
        collar=ring('Drum stiffener',(0,y,z),r,.055,'Steel','Y')
        collar.rotation_euler.x-=.20
    cylinder('Mixer drive',(0,-1.83,1.78),.35,.48,'Graphite','Y')
    box('Electric drive cabinet',(.84,-1.65,.98),(.56,.74,.62),'Ivory')
    box('Control interface',(.84,-2.03,1.04),(.35,.035,.24),'Cyan')
    # Two open feed bins with inclined sidewalls and separate metering gates.
    for x in (-.54,.54):
        box('Aggregate bin floor',(x,1.44,1.65),(.77,.92,.12),'Steel')
        for side in (-1,1):
            plate=box('Flared bin side',(x+side*.42,1.44,2.04),(.10,1.13,.80),'Ochre')
            plate.rotation_euler.y=side*.20
        for y in (.88,2.00):
            box('Bin end plate',(x,y,2.04),(.84,.10,.78),'Ochre')
        box('Metering slide',(x,1.44,1.53),(.71,.66,.09),'Graphite')
    beam('Feed chute', (0,1.14,1.65),(0,.43,1.48),.38,'Steel')
    box('Discharge chute floor',(0,-2.26,1.14),(.67,.84,.10),'Steel').rotation_euler.x=.23
    for s in (-1,1):
        box('Discharge chute side',(s*.34,-2.26,1.27),(.09,.84,.22),'Ochre').rotation_euler.x=.23


def habitat_dental_clinic():
    box('Clinic floor',(0,0,.12),(5.8,5.1,.24),'Slate')
    box('Rear hygiene wall',(0,2.45,1.46),(5.8,.17,2.68),'Ivory')
    cylinder('Chair pedestal',(-.52,-.2,.40),.43,.34,'Steel')
    box('Adjustable seat',(-.52,-.2,.84),(.72,.77,.20),'Teal',.08)
    back=box('Reclining backrest',(-.52,.45,1.13),(.70,.86,.18),'Teal',.07)
    back.rotation_euler.x=.56
    box('Padded headrest',(-.52,.88,1.42),(.44,.34,.17),'Teal')
    leg=box('Leg rest',(-.52,-.91,.72),(.64,.71,.16),'Teal')
    leg.rotation_euler.x=.22
    for s in (-1,1):
        beam('Armrest support',(-.52+s*.44,-.25,.77),(-.52+s*.44,-.25,1.04),.08,'Steel')
        box('Patient armrest',(-.52+s*.44,-.25,1.08),(.15,.48,.10),'Ivory')
    beam('Exam light upright',(1.0,.86,.24),(1.0,.86,2.37),.12,'Steel')
    beam('Pivoted light boom',(1.0,.86,2.37),(-.23,.45,2.37),.11,'Steel')
    beam('Light head linkage',(-.23,.45,2.37),(-.52,.20,2.04),.09,'Steel')
    box('Examination light housing',(-.52,.20,2.00),(.55,.34,.13),'Ivory')
    box('Examination light diffuser',(-.52,.20,1.92),(.44,.24,.035),'Cyan')
    box('Instrument console',(1.12,-.60,1.12),(.71,.57,.17),'Ivory')
    beam('Console arm',(1.0,.86,1.14),(1.12,-.60,1.14),.10,'Steel')
    for i in range(4):
        x=.90+i*.14
        cylinder('Handpiece grip',(x,-.64,1.25),.035,.20,'Steel','Y',vertices=12)
        beam('Handpiece cord',(x,-.74,1.18),(x,-.81,.67),.025,'Graphite')
    box('Sterilization counter',(1.69,1.97,1.04),(2.10,.74,.16),'Steel')
    box('Cabinet bank',(1.69,1.97,.60),(2.05,.68,.75),'Teal')
    box('Sterilizer chamber',(1.87,1.97,1.38),(.74,.58,.50),'Ivory')
    cylinder('Sterilizer door',(1.87,1.66,1.38),.21,.07,'Graphite','Y')
    box('Sink counter',(-1.85,1.97,1.04),(1.42,.74,.16),'Steel')
    box('Recessed sink basin',(-1.85,1.97,1.13),(.58,.38,.05),'Graphite')
    beam('Faucet',(-1.85,2.23,1.13),(-1.85,2.23,1.49),.06,'Steel')
    beam('Spout',(-1.85,2.23,1.49),(-1.85,1.97,1.49),.06,'Steel')
    cylinder('Clinician stool seat',(-1.64,-.35,.70),.25,.10,'Teal')
    cylinder('Stool column',(-1.64,-.35,.46),.055,.38,'Steel')


def orbital_whipple_shield_rack():
    # An open cutaway of spaced sacrificial bumper and rear pressure-wall coupons.
    for x in (-1.68,1.68):
        for z in (.25,2.50):
            beam('Structural longitudinal rail',(x,-1.35,z),(x,1.35,z),.18,'Graphite')
        for y in (-1.35,1.35):
            beam('Rack upright',(x,y,.25),(x,y,2.50),.18,'Steel')
        beam('Side brace',(x,-1.35,.25),(x,1.35,2.50),.10,'Steel')
    for y in (-1.35,1.35):
        for z in (.25,2.50):
            beam('Rack crossmember',(-1.68,y,z),(1.68,y,z),.18,'Graphite')
    # Four independent removable coupons per layer, with visible gaps between layers.
    for y,color,thick,label in ((-.92,'Ivory',.055,'Sacrificial bumper'),(-.12,'Sand',.16,'Intermediate fabric coupon'),(.85,'Teal',.20,'Rear wall coupon')):
        for x in (-.72,.72):
            for z in (.85,1.90):
                box(label,(x,y,z),(1.32,thick,.95),color,.025)
                for s in (-1,1):
                    box('Coupon edge clamp',(x+s*.61,y,z),(.12,thick+.12,.96),'Ochre')
                    for dz in (-.34,.34):
                        cylinder('Captive clamp bolt',(x+s*.61,y-thick/2-.07,z+dz),.045,.07,'Steel','Y',vertices=12)
        for x in (-1.54,1.54):
            beam('Layer mounting upright',(x,y,.25),(x,y,2.50),.12,'Steel')
    box('Instrumentation enclosure',(0,1.30,.53),(1.17,.42,.43),'Graphite')
    box('Coupon telemetry display',(0,1.07,.54),(.77,.035,.23),'Cyan')
    for x in (-1.22,1.22):
        beam('Sensor conduit',(x,.85,.40),(x,1.30,.40),.05,'Copper')
        beam('Sensor return',(x,1.30,.40),(0,1.30,.40),.05,'Copper')
    for x in (-1.1,1.1):
        cylinder('Rack mounting boss',(x,0,.06),.23,.18,'Steel',vertices=16)


def surface_tunnel_lining_gantry():
    # Rail-mounted ring-segment installation carriage; tunnel section is a cutaway.
    for x in (-1.42,1.42):
        box('Portable rail',(x,0,.10),(.16,4.8,.16),'Steel')
        box('Carriage sill',(x,0,.47),(.54,3.0,.35),'Graphite')
        for y in (-1.1,1.1):
            cylinder('Flanged rail wheel',(x,y,.27),.25,.23,'Steel','X')
        beam('Gantry upright',(x,0,.64),(x,0,2.75),.26,'Ochre')
        beam('Diagonal bracing',(x,-1.25,.65),(x,0,2.15),.14,'Steel')
        beam('Diagonal bracing',(x,1.25,.65),(x,0,2.15),.14,'Steel')
    box('Carriage cross beam',(0,0,.50),(3.0,.42,.27),'Graphite')
    # Open upper arc with individually removable curved liner segments.
    for i in range(13):
        a=PI*i/12
        x=1.76*math.cos(a);z=.48+1.76*math.sin(a)
        segment=box('Precast tunnel liner segment',(x,.95,z),(.41,.84,.19),'Ivory',.025)
        segment.rotation_euler.y=-a+PI/2
        for side in (-1,1):
            bolt=cylinder('Liner anchor',(x, .95+side*.30,z),.046,.23,'Steel',vertices=12)
            bolt.rotation_euler.y=PI/2-a
    for i in range(9):
        a=PI*i/8
        beam('Curved erection frame chord',(1.42*math.cos(a),0,.62+1.42*math.sin(a)),
             (1.42*math.cos(a+PI/8),0,.62+1.42*math.sin(a+PI/8)),.17,'Ochre') if i<8 else None
    box('Slewing carriage',(0,-.12,1.72),(.62,.62,.37),'Teal')
    cylinder('Rotary joint',(0,-.52,1.72),.28,.20,'Steel','Y')
    beam('Segment lifting arm',(0,-.52,1.72),(.68,.08,2.06),.22,'Ochre')
    box('Segment clamp',(.68,.20,2.12),(.42,.26,.20),'Graphite')
    box('Operator console',(-1.08,-1.04,1.12),(.52,.41,.70),'Teal')
    box('Console screen',(-1.08,-1.27,1.34),(.30,.035,.22),'Cyan')


def habitat_childcare_playroom():
    # Open-front cutaway: circulation stays clear between play stations.
    box('Resilient floor',(0,0,.12),(6.4,5.4,.24),'Slate')
    box('Rear partition',(0,2.59,1.43),(6.4,.16,2.62),'Ivory')
    for x,color in ((-2.1,'Teal'),(-.7,'Sand'),(.7,'Ochre'),(2.1,'Teal')):
        box('Soft floor tile',(x,-.30,.26),(1.32,1.65,.07),color,.02)
    for x in (-2.4,-1.7,-1.0):
        box('Low storage cabinet',(x,2.10,.56),(.63,.64,.64),'Teal')
        for z in (.44,.70):
            box('Rounded bin front',(x,1.75,z),(.51,.08,.20),'Ivory')
            box('Bin pull',(x,1.69,z),(.19,.06,.05),'Ochre')
    # Small climbing platform with stairs and handrails.
    box('Play platform',(2.10,1.72,.83),(1.35,1.40,.19),'Ochre')
    for i in range(3):
        box('Soft stair',(1.40-i*.33,1.72,.30+i*.0+.11*(2-i)),(.33,.85,.14+.22*(2-i)),'Teal')
    for y in (1.09,2.35):
        beam('Guardrail',(2.75,y,.90),(2.75,y,1.35),.07,'Ivory')
        beam('Guardrail cap',(2.75,y,1.35),(1.60,y,1.35),.07,'Ivory')
    slide=box('Slide chute',(2.10,.36,.63),(.70,1.64,.13),'Teal',.055)
    slide.rotation_euler.x=.40
    for x in (1.71,2.49):
        beam('Slide edge',(x,-.38,.31),(x,1.10,.97),.07,'Ivory')
    cylinder('Activity table top',(-1.70,-.33,.74),.55,.10,'Ivory')
    for i in range(3):
        a=i*2*PI/3
        cylinder('Table leg',(-1.70+.34*math.cos(a),-.33+.34*math.sin(a),.46),.07,.48,'Steel')
    for x,y in ((-2.46,-.33),(-.94,-.33),(-1.70,-1.11)):
        cylinder('Child stool',(x,y,.43),.23,.12,'Ochre')
        cylinder('Stool base',(x,y,.30),.19,.15,'Teal')
    for x,z,color in ((-.32,.45,'Ochre'),(.18,.45,'Ivory'),(.68,.45,'Teal')):
        box('Stacking block',(x,-1.78,z),(.36,.36,.36),color,.06)
    box('Wall activity panel',(0,2.47,1.24),(1.08,.13,.78),'Teal')
    for i in range(5):
        cylinder('Activity panel dial',(-.4+.2*i,2.36,1.25),.073,.06,'Ochre','Y',vertices=12)


def orbital_fluid_separator():
    # Compact microgravity liquid-gas separation skid with independent flow paths.
    box('Equipment base',(0,0,.14),(3.6,2.1,.28),'Graphite')
    for x in (-1.55,1.55):
        for y in (-.85,.85):
            beam('Mounting frame',(x,y,.22),(x,y,1.95),.12,'Steel')
        beam('Frame top rail',(x,-.85,1.95),(x,.85,1.95),.12,'Steel')
        beam('Frame diagonal',(x,-.85,.30),(x,.85,1.95),.09,'Steel')
    for z in (.30,1.95):
        for y in (-.85,.85):
            beam('Transverse frame rail',(-1.55,y,z),(1.55,y,z),.12,'Steel')
    cylinder('Rotor pressure housing',(-.42,0,1.10),.62,1.32,'Teal','X',vertices=32)
    for x in (-1.04,.20):
        ring('Housing flange',(x,0,1.10),.62,.065,'Steel','X')
        for i in range(8):
            a=i*PI/4
            cylinder('Captive flange bolt',(x,.60*math.cos(a),1.10+.60*math.sin(a)),.045,.13,'Ivory','X',vertices=12)
    cylinder('Drive motor',(-1.21,0,1.10),.36,.37,'Graphite','X')
    cylinder('Inspection port',(.27,0,1.10),.23,.12,'Steel','X')
    cylinder('Inspection glazing',(.34,0,1.10),.18,.03,'Cyan','X')
    for y,color,label in ((-.55,'Copper','Liquid return'),(.55,'Ivory','Gas return')):
        cylinder(label+' accumulator',(.98,y,.94),.27,1.10,color)
        cylinder(label+' cap',(.98,y,1.52),.18,.12,'Steel')
        beam(label+' pipe',(.02,y,1.45),(.98,y,1.45),.09,color)
        beam(label+' intake',(.02,0,1.45),(.02,y,1.45),.09,color)
        ring(label+' connection',(.98,y,1.64),.12,.045,'Steel')
        cylinder(label+' valve',(.55,y,1.45),.13,.12,'Steel','X')
    box('Controller enclosure',(0,-.81,.56),(1.10,.28,.46),'Ivory')
    box('Telemetry screen',(0,-.97,.62),(.65,.035,.20),'Cyan')
    for i in range(3):
        cylinder('Status lamp',(-.25+i*.25,-.98,.46),.045,.035,'Amber','Y',vertices=12)


def surface_asphalt_paver():
    # Continuous road surfacing: front receiving hopper, tracked chassis and trailing screed.
    box('Main chassis',(0,0,.72),(2.25,3.35,.46),'Graphite')
    for x in (-1.06,1.06):
        box('Crawler belt',(x,.20,.42),(.55,2.55,.72),'Graphite',.15)
        for y in (-.83,.20,1.23):
            cylinder('Bogie roller',(x*1.22,y,.42),.31,.12,'Steel','X')
        for i in range(12):
            box('Track shoe',(x,-.91+i*.20,.79),(.57,.13,.075),'Steel',.015)
        wall=box('Tilting hopper wing',(x,-1.59,1.28),(.16,1.63,.90),'Ochre')
        wall.rotation_euler.y=x*.28
    box('Hopper floor',(0,-1.72,.82),(2.13,1.64,.18),'Steel')
    box('Hopper forward lip',(0,-2.48,.98),(2.62,.17,.32),'Ochre')
    for x in (-.34,.34):
        box('Feed conveyor',(x,-1.48,.96),(.56,1.58,.12),'Graphite')
        for i in range(9):
            box('Conveyor flight',(x,-2.15+i*.16,1.04),(.55,.05,.10),'Steel')
    box('Engine enclosure',(0,.15,1.40),(1.85,1.35,.80),'Ochre')
    for i in range(7):
        box('Engine vent',(0,-.35+i*.14,1.83),(1.22,.055,.045),'Graphite')
    box('Operator platform',(0,1.02,1.34),(1.95,.79,.20),'Steel')
    for x in (-.78,.78):
        beam('Canopy support',(x,.70,1.40),(x,.70,2.76),.09,'Steel')
        beam('Screed tow arm',(x,.62,.90),(x,2.25,.43),.15,'Ochre')
    box('Operator canopy',(0,.97,2.78),(2.05,1.35,.14),'Ochre')
    box('Control console',(-.64,.63,1.72),(.48,.30,.44),'Teal')
    box('Console screen',(-.64,.46,1.84),(.29,.04,.17),'Cyan')
    box('Seat cushion',(.38,1.10,1.61),(.52,.48,.16),'Graphite')
    box('Seat back',(.38,1.35,1.89),(.52,.14,.45),'Graphite')
    cylinder('Distribution auger shaft',(0,1.90,.43),.09,2.55,'Steel','X')
    for i in range(13):
        plate=box('Auger paddle',(-1.14+i*.19,1.90,.43),(.08,.45,.12),'Steel')
        plate.rotation_euler.x=i*.55
    box('Heated finishing screed',(0,2.30,.30),(3.38,.79,.20),'Graphite')
    for x in (-1.52,1.52):
        box('Screed end gate',(x,2.30,.52),(.10,.80,.43),'Ochre')


def habitat_barber_shop():
    # Open civilian grooming room with two independent service stations.
    box('Cleanable floor',(0,0,.12),(5.5,4.3,.24),'Slate')
    box('Back partition',(0,2.04,1.43),(5.5,.19,2.65),'Ivory')
    for x in (-1.45,1.45):
        box('Work counter',(x,1.65,.95),(1.87,.63,.17),'Teal')
        box('Drawer pedestal',(x,1.68,.55),(.55,.55,.72),'Graphite')
        for z in (.43,.67):
            box('Drawer face',(x,1.37,z),(.47,.06,.18),'Ivory')
            box('Drawer pull',(x,1.32,z),(.23,.05,.045),'Steel')
        box('Mirror frame',(x,1.91,1.76),(1.22,.12,1.16),'Steel')
        box('Mirror surface',(x,1.83,1.76),(1.09,.035,1.02),'Cyan',.02)
        for dx in (-.68,.68):
            box('Vanity light',(x+dx,1.82,1.76),(.075,.08,.90),'Ivory')
        cylinder('Hydraulic chair base',(x,.14,.30),.38,.13,'Steel')
        cylinder('Adjustable pedestal',(x,.14,.61),.13,.58,'Steel')
        box('Chair seat',(x,.14,.97),(.71,.65,.19),'Teal',.07)
        back=box('Reclining chair back',(x,-.17,1.30),(.68,.18,.62),'Teal',.07)
        back.rotation_euler.x=-.12
        box('Headrest',(x,-.21,1.70),(.34,.18,.19),'Graphite')
        for dx in (-.43,.43):
            beam('Armrest support',(x+dx,.12,.98),(x+dx,.12,1.21),.08,'Steel')
            box('Armrest',(x+dx,.13,1.23),(.14,.48,.12),'Graphite')
        beam('Footrest support',(x,.39,.91),(x,.72,.49),.09,'Steel')
        box('Footrest',(x,.74,.48),(.57,.28,.08),'Steel')
        for dx in (-.58,-.43,-.28):
            cylinder('Grooming bottle',(x+dx,1.56,1.13),.052,.22,'Ochre',vertices=16)
    box('Waiting bench',(-1.25,-1.62,.53),(1.95,.47,.16),'Ochre')
    for x in (-2.04,-.46):
        beam('Bench leg',(x,-1.62,.21),(x,-1.62,.48),.13,'Steel')
    box('Clean towel cabinet',(2.14,-1.49,.76),(.64,.68,1.03),'Teal')
    for z in (.46,.76,1.06):
        box('Towel shelf',(2.14,-1.86,z),(.51,.08,.20),'Ivory')


def orbital_docking_seal_test_fixture():
    # Grounded service skid for pressure-seal inspection, not a docking port itself.
    box('Service skid',(0,0,.14),(4.2,2.8,.28),'Graphite')
    for x in (-1.65,1.65):
        box('Longitudinal guide rail',(x,0,.42),(.22,2.44,.22),'Steel')
        for y in (-.85,.85):
            beam('Frame upright',(x,y,.43),(x,y,2.41),.17,'Steel')
        beam('Frame header',(x,-.85,2.41),(x,.85,2.41),.17,'Steel')
    for y in (-.85,.85):
        beam('Transverse header',(-1.65,y,2.41),(1.65,y,2.41),.17,'Steel')
    for y in (-.44,.44):
        ring('Machined fixture flange',(0,y,1.31),.85,.13,'Steel','Y')
        ring('Replaceable elastomer seal',(0,y*.78,1.31),.72,.055,'Ochre','Y')
        for i in range(12):
            a=i*PI/6
            cylinder('Flange captive fastener',(.85*math.cos(a),y,1.31+.85*math.sin(a)),.052,.32,'Graphite','Y',vertices=12)
    for x in (-1.36,1.36):
        cylinder('Linear actuator body',(x,.36,1.31),.19,.83,'Teal','Y')
        cylinder('Actuator piston',(x,-.34,1.31),.075,.72,'Steel','Y')
        beam('Flange carrier',(x,-.62,1.31),(x*.66,-.62,1.31),.19,'Ochre')
    box('Vacuum pump',(-1.0,1.02,.57),(.78,.61,.57),'Teal')
    cylinder('Pump motor',(-1.0,1.14,.96),.20,.40,'Graphite','X')
    beam('Vacuum line',(-1.0,.83,.93),(-.62,.44,1.07),.09,'Copper')
    box('Pressure monitor',(1.08,-1.10,.79),(.62,.42,.94),'Ivory')
    box('Pressure display',(1.08,-1.34,1.02),(.46,.04,.26),'Cyan')
    for x in (.91,1.08,1.25):
        cylinder('Status indicator',(x,-1.35,.76),.045,.04,'Amber','Y',vertices=12)



def surface_rotary_snow_sweeper():
    # Airport-style rotary brush on a compact articulated utility tractor.
    box('Rear power chassis',(0,.8,.65),(2.1,2.8,.65),'Ochre',.17)
    box('Forward articulated frame',(0,-1.1,.58),(1.45,1.5,.42),'Graphite')
    cylinder('Articulation pivot',(0,-.35,.72),.30,.42,'Steel')
    box('Insulated cab',(0,.10,1.57),(1.65,1.30,1.28),'Ivory',.16)
    box('Wraparound windscreen',(0,-.57,1.76),(1.42,.08,.60),'Teal')
    for side in (-1,1):
        box('Side cab glass',(side*.84,.04,1.76),(.06,.92,.58),'Teal')
        for y in (-1.20,1.67):
            cylinder('Winter traction tyre',(side*1.02,y,.53),.53,.36,'Graphite','X',vertices=32)
            cylinder('Wheel hub',(side*1.22,y,.53),.23,.09,'Steel','X')
            for k in range(12):
                a=k*PI/6
                lug=box('Tyre tread lug',(side*1.02,y+.51*math.cos(a),.53+.51*math.sin(a)),(.39,.15,.09),'Slate')
                lug.rotation_euler.x=a
        beam('Brush support arm',(side*.61,-1.43,.67),(side*1.16,-2.26,.51),.18,'Steel')
    cylinder('Rotary brush core',(0,-2.35,.48),.25,2.55,'Steel','X')
    for j in range(10):
        x=-1.14+j*.253
        for k in range(8):
            a=k*PI/4+j*.19
            beam('Replaceable brush strip',(x,-2.35+.24*math.cos(a),.48+.24*math.sin(a)),(x,-2.35+.48*math.cos(a),.48+.48*math.sin(a)),.075,'Ochre')
    for k in range(9):
        a=k*PI/8
        strip=box('Segmented brush guard',(0,-2.35+.55*math.cos(a),.48+.55*math.sin(a)),(2.75,.22,.06),'Teal')
        strip.rotation_euler.x=a
    box('Rear cooling grille',(0,2.21,.99),(1.56,.08,.52),'Graphite')
    cylinder('Cab beacon',(0,.12,2.29),.13,.17,'Amber')


def habitat_courier_post_office():
    # Open counter and parcel sorting room; clear central customer circulation.
    box('Modular floor',(0,0,.12),(6.4,4.8,.24),'Slate')
    box('Rear partition',(0,2.30,1.48),(6.4,.16,2.75),'Ivory')
    for x in (-2.65,-1.45,-.25,.95):
        box('Parcel locker column',(x,1.97,1.48),(1.06,.54,2.40),'Teal')
        for z in (.65,1.22,1.79,2.36):
            box('Individual locker door',(x,1.67,z),(.94,.075,.50),'Ivory')
            box('Locker latch',(x+.31,1.62,z),(.13,.05,.10),'Graphite')
            box('Locker status',(x-.32,1.62,z),(.08,.04,.045),'Cyan')
    box('Accessible service counter',(1.94,-.02,.58),(2.02,.95,.94),'Teal')
    box('Counter worktop',(1.94,-.02,1.10),(2.17,1.07,.14),'Steel')
    box('Parcel weighing platform',(1.43,-.05,1.24),(.54,.54,.12),'Graphite')
    box('Scale readout',(1.43,.20,1.43),(.35,.10,.22),'Cyan')
    box('Sorting bench',(-1.95,.79,.87),(2.0,.72,.14),'Steel')
    for x in (-2.79,-1.11):
        for y in (.51,1.07):
            beam('Sorting bench leg',(x,y,.24),(x,y,.81),.09,'Graphite')
    for x,z in ((-2.48,1.10),(-1.92,1.07),(-1.36,1.15)):
        box('Sealed parcel',(x,.78,z),(.42,.47,.34),'Sand')
        box('Parcel tape',(x,.78,z+.18),(.075,.47,.025),'Ochre')
    for x in (-2.48,-1.80,-1.12):
        box('Waiting seat',(x,-1.83,.75),(.59,.61,.12),'Teal')
        box('Seat back',(x,-2.10,1.09),(.59,.13,.61),'Teal')
        beam('Seat pedestal',(x,-1.83,.24),(x,-1.83,.69),.15,'Steel')
    for x in (.65,2.85):
        cylinder('Queue post',(x,-1.40,.76),.065,1.04,'Steel')
        cylinder('Queue post foot',(x,-1.40,.28),.18,.08,'Graphite')
    beam('Queue rail',(.65,-1.40,1.17),(2.85,-1.40,1.17),.06,'Ochre')
    box('Service status panel',(2.36,2.16,2.16),(1.30,.10,.55),'Graphite')
    for x in (1.99,2.36,2.73):
        box('Service indicator',(x,2.09,2.16),(.25,.035,.31),'Cyan')


def orbital_micrometeoroid_dust_collector():
    # Fold-out passive sample capture trays on a compact scientific bus.
    box('Instrument avionics bus',(0,0,0),(1.36,1.46,.78),'Ivory',.15)
    box('Telemetry face',(0,-.76,.10),(1.03,.06,.40),'Teal')
    for x in (-.35,0,.35):
        box('Telemetry status',(x,-.80,.11),(.18,.025,.17),'Cyan')
    cylinder('Station attachment collar',(0,0,-.56),.40,.36,'Steel',vertices=32)
    ring('Collar locking ring',(0,0,-.72),.40,.07,'Ochre')
    for side in (-1,1):
        cylinder('Deployment hinge',(side*.72,0,.18),.19,1.10,'Steel','Y')
        for y in (-.58,.58):
            beam('Collector frame boom',(side*.78,y,.18),(side*2.83,y,.48),.11,'Graphite')
        for x in (1.02,1.64,2.26,2.88):
            beam('Tray cross rail',(side*x,-.64,.40),(side*x,.64,.40),.09,'Ochre')
        for j in range(3):
            x=side*(1.33+j*.62)
            box('Removable sample cassette',(x,0,.47),(.55,1.15,.13),'Steel')
            for y in (-.39,0,.39):
                box('Passive aerogel capture cell',(x,y,.56),(.44,.33,.05),'Ice',.018)
                box('Indexed sample tab',(x+side*.21,y,.59),(.06,.12,.07),'Copper')
            box('Cassette release handle',(x,-.60,.51),(.28,.10,.11),'Ochre')
        for y in (-.55,.55):
            beam('Deployable diagonal brace',(side*.55,y,-.22),(side*2.54,y,.36),.075,'Teal')
    cylinder('Camera mast',(0,.32,.70),.08,.74,'Steel')
    box('Sample survey camera',(0,.32,1.08),(.44,.45,.30),'Graphite')
    cylinder('Camera lens',(0,.04,1.08),.13,.13,'Cyan','Y')
    for x in (-.46,.46):
        cylinder('Service connector',(x,.77,.04),.13,.16,'Copper','Y')



def surface_floodwater_pump_trailer():
    # Open twin-pump trailer with large suction and discharge connections.
    box('Trailer deck',(0,0,.64),(2.28,3.8,.22),'Slate',.08)
    for side in (-1,1):
        beam('Drawbar',(side*.8,-1.75,.59),(0,-2.85,.51),.18,'Steel')
        for y in (-.93,.93):
            cylinder('Trailer tyre',(side*1.15,y,.42),.42,.27,'Graphite','X',vertices=32)
            cylinder('Wheel hub',(side*1.31,y,.42),.19,.08,'Steel','X')
            beam('Stabilizer arm',(side*.95,y,.57),(side*1.48,y,.24),.13,'Steel')
            box('Stabilizer pad',(side*1.48,y,.10),(.38,.38,.13),'Ochre')
    cylinder('Tow eye',(0,-2.87,.52),.13,.12,'Steel')
    for y in (-.96,.65):
        box('Pump mounting bed',(0,y,.82),(1.77,1.22,.18),'Graphite')
        cylinder('Centrifugal casing',(-.38,y,1.27),.49,.39,'Teal','X',vertices=48)
        cylinder('Suction flange',(-.70,y,1.27),.27,.12,'Steel','X')
        cylinder('Suction opening',(-.77,y,1.27),.18,.025,'Graphite','X')
        cylinder('Motor housing',(.38,y,1.27),.34,.85,'Ochre','X',vertices=32)
        for k in range(7):
            cylinder('Motor cooling fin',(.05+k*.10,y,1.27),.37,.045,'Steel','X',vertices=24)
        beam('Discharge riser',(-.37,y,1.50),(-.37,y,1.95),.32,'Teal')
        cylinder('Discharge flange',(-.37,y,1.96),.22,.08,'Steel')
        cylinder('Discharge opening',(-.37,y,2.01),.15,.025,'Graphite')
    for side in (-1,1):
        cylinder('Hose reel core',(side*.65,1.64,1.18),.29,.48,'Graphite','X')
        for dx in (-.26,.26):
            cylinder('Hose reel cheek',(side*.65+dx,1.64,1.18),.40,.06,'Ochre','X')
    box('Weatherproof control cabinet',(0,-1.66,1.25),(.8,.32,.70),'Ivory')
    box('Control screen',(0,-1.84,1.43),(.42,.025,.23),'Cyan')
    for x in (-.22,0,.22):
        cylinder('Control button',(x,-1.84,1.13),.048,.04,'Amber','Y',vertices=12)


def habitat_community_theater():
    # Open-front cutaway with a clear central aisle and accessible front row.
    box('Venue floor',(0,0,.10),(7.6,7.4,.20),'Slate')
    box('Rear stage partition',(0,3.57,1.70),(7.6,.16,3.2),'Graphite')
    box('Raised stage',(0,2.49,.36),(7.05,2.0,.34),'Sand')
    box('Stage fascia',(0,1.49,.40),(7.05,.12,.35),'Teal')
    for side in (-1,1):
        for k in range(8):
            x=side*(2.16+k*.19)
            box('Folded stage curtain',(x,3.34+.06*(k%2),1.87),(.26,.22,2.48),'Teal')
        beam('Lighting truss upright',(side*3.38,2.1,.54),(side*3.38,2.1,3.55),.16,'Steel')
        for row in range(3):
            y=-.48-row*1.07
            z=.20+row*.18
            box('Stepped seating platform',(side*2.06,y,z),(3.30,.98,.20+row*.36),'Slate')
            for k in range(4):
                x=side*(.82+k*.79)
                if row==0 and k==0: continue
                box('Seat cushion',(x,y,z+.44),(.67,.55,.14),'Teal',.06)
                box('Seat back',(x,y-.27,z+.78),(.67,.13,.60),'Teal',.06)
                beam('Seat pedestal',(x,y,z+.10),(x,y,z+.40),.14,'Steel')
    for y in (1.97,2.24):
        beam('Overhead truss chord',(-3.38,y,3.55),(3.38,y,3.55),.12,'Steel')
    for x in (-2.8,-1.4,0,1.4,2.8):
        cylinder('Stage luminaire',(x,2.0,3.36),.18,.29,'Graphite')
        cylinder('Lamp face',(x,2.0,3.20),.14,.04,'Amber')
    box('Stage monitor',(0,1.76,.70),(.66,.44,.33),'Graphite')
    beam('Microphone stand',(0,2.15,.54),(0,2.15,1.66),.055,'Steel')
    cylinder('Microphone',(0,2.15,1.69),.07,.17,'Graphite','Y')
    for y in (-2.7,-1.64,-.57):
        box('Aisle edge guide',(0,y,.22),(.18,.18,.025),'Cyan')


def orbital_plasma_contactor():
    # Charge neutralizer with twin hollow cathode heads and replaceable feed assembly.
    box('Spacecraft interface plate',(0,0,.10),(2.3,2.7,.20),'Slate',.07)
    box('Power conditioning enclosure',(-.52,-.36,.49),(1.0,1.55,.65),'Ivory',.10)
    for k in range(8):
        box('Thermal fin',(-.52,-.96+k*.17,.86),(1.02,.06,.23),'Steel')
    box('Control connector bank',(-.52,-1.18,.50),(.82,.12,.38),'Graphite')
    for x in (-.80,-.52,-.24):
        cylinder('Harness connector',(x,-1.27,.50),.08,.12,'Copper','Y',vertices=16)
    cylinder('Xenon feed reservoir',(.59,-.35,.62),.35,1.25,'Steel','Y',vertices=40)
    for y in (-.93,.23):
        cylinder('Reservoir end cap',(.59,y,.62),.36,.09,'Teal','Y')
    box('Flow regulation block',(.59,.58,.49),(.62,.38,.49),'Ochre')
    for x in (-.57,.57):
        box('Cathode mounting riser',(x,.96,.55),(.74,.55,.67),'Graphite')
        cylinder('Ceramic isolator',(x,.96,1.02),.32,.30,'Ivory',vertices=32)
        cylinder('Emitter outer shield',(x,.96,1.30),.24,.42,'Steel',vertices=40)
        cylinder('Emitter face',(x,.96,1.53),.19,.07,'Graphite',vertices=32)
        cylinder('Hollow cathode aperture',(x,.96,1.58),.075,.025,'Copper',vertices=24)
        for k in range(8):
            a=k*PI/4
            cylinder('Insulated grid standoff',(x+.28*math.cos(a),.96+.28*math.sin(a),1.38),.038,.39,'Ivory',vertices=12)
        beam('Feed tube',(.59,.58,.77),(x,.96,.77),.065,'Copper')
    for x in (-.92,.92):
        for y in (-1.13,1.13):
            cylinder('Mounting bolt',(x,y,.24),.095,.09,'Steel',vertices=12)



MODELS={'fleet-tender':tender,'mining-drone':drone,'industrial-replicator':replicator,
        'cargo-mule':cargo_mule,'coolant-exchange-tower':cooling,'antimatter-containment-bottle':bottle,
        'warp-field-coil':coil,'impulse-thruster-module':thruster,'survey-probe':probe,'navigational-deflector':dish,'fleet-salvage-tug':tug,'cargo-shuttle':shuttle,
        'modular-station-hub':hub,'derelict-freighter':freighter,'resource-asteroid':asteroid,'asteroid-set':belt,
        'shuttle-landing-pad':pad,'armored-station-deck-tile':deck,'salvage-drone':salvage_drone,'light-carrier':carrier,
        'temperate-colony-planet':lambda:planet('Temperate colony'),'scarred-mining-moon':lambda:planet('Scarred mining moon'),
        'ringed-gas-giant':lambda:planet('Ringed gas giant'),
        'iron-choir-drakken-warship':iron_choir,'torpedo-corvette':torpedo_corvette,'flux-launcher-housing':flux_housing,
        'hydroponic-bay':hydroponic_bay,'pressure-airlock':pressure_airlock,'solar-power-array':solar_power_array,
        'water-reclamation-skid':water_reclamation_skid,'cargo-elevator':cargo_elevator,'crew-quarters-cutaway':crew_quarters_cutaway,
        'medical-triage-bay':medical_triage_bay,'cryogenic-freight-vault':cryogenic_freight_vault,'atmospheric-processor':atmospheric_processor,
        'surface-drill-rig':surface_drill_rig,'communications-relay-satellite':communications_relay_satellite,'emergency-escape-capsule':emergency_escape_capsule,
        'habitat-observation-dome':observation_dome,'surface-freight-rail-junction':freight_rail_junction,'geothermal-power-station':geothermal_station,
        'habitat-command-center':habitat_command_center,'surface-weather-station':surface_weather_station,'orbital-fuel-depot':orbital_fuel_depot,
        'regolith-sintering-kiln':regolith_sintering_kiln,'sample-analysis-laboratory':sample_analysis_laboratory,'modular-footbridge':modular_footbridge,
        'deepwater-survey-submersible':deepwater_survey_submersible,'orbital-optical-observatory':orbital_optical_observatory,'habitat-recreation-court':habitat_recreation_court,
        'habitat-market-hall':habitat_market_hall,'surface-seismic-array':surface_seismic_array,'orbital-passenger-ferry':orbital_passenger_ferry,
        'surface-storm-shelter':surface_storm_shelter,'material-recovery-line':material_recovery_line,'habitat-archive-room':habitat_archive_room,
        'surface-cargo-cableway':surface_cargo_cableway,'eva-suit-service-bay':eva_suit_service_bay,'aquaculture-nursery':aquaculture_nursery,
        'surface-crawler-crane':surface_crawler_crane,'habitat-fire-suppression-station':habitat_fire_suppression_station,'orbital-gravity-centrifuge':orbital_gravity_centrifuge,
        'colony-tram':colony_tram,'orbital-tether-spool':orbital_tether_spool,'habitat-seed-bank':habitat_seed_bank,
        'atmospheric-balloon-probe':atmospheric_balloon_probe,'habitat-communal-galley':habitat_communal_galley,'subsea-cable-repeater':subsea_cable_repeater,
        'surface-medical-rover':surface_medical_rover,'tidal-control-gate':tidal_control_gate,'orbital-debris-net':orbital_debris_net,
        'surface-ice-harvester':surface_ice_harvester,'habitat-transit-turnstile':habitat_transit_turnstile,'orbital-solar-sail-tug':orbital_solar_sail_tug,
        'habitat-laundry-module':habitat_laundry_module,'surface-cable-trencher':surface_cable_trencher,'orbital-cargo-carousel':orbital_cargo_carousel,
        'surface-wind-turbine':surface_wind_turbine,'habitat-music-studio':habitat_music_studio,'orbital-traffic-beacon':orbital_traffic_beacon,
        'surface-salt-evaporation-works':surface_salt_evaporation_works,
        'habitat-classroom':habitat_classroom,
        'orbital-sample-return-canister':orbital_sample_return_canister,
        'surface-rockfall-barrier':surface_rockfall_barrier,
        'habitat-textile-loom':habitat_textile_loom,
        'orbital-crystal-growth-rack':orbital_crystal_growth_rack,
        'surface-road-grader':surface_road_grader,
        'habitat-sanitation-module':habitat_sanitation_module,
        'orbital-starshade':orbital_starshade,
        'surface-dust-decontamination-portal':surface_dust_decontamination_portal,
        'habitat-ceramics-workshop':habitat_ceramics_workshop,
        'orbital-radiator-wing':orbital_radiator_wing,
        'surface-lightning-protection-mast':surface_lightning_protection_mast,
        'habitat-optical-fabrication-bench':habitat_optical_fabrication_bench,
        'orbital-flywheel-energy-buffer':orbital_flywheel_energy_buffer,
        'surface-irrigation-pivot':surface_irrigation_pivot,
        'habitat-prosthetics-fitting-lab':habitat_prosthetics_fitting_lab,
        'orbital-inspection-crawler':orbital_inspection_crawler,
        'surface-grain-harvester':surface_grain_harvester,
        'habitat-fermentation-plant':habitat_fermentation_plant,
        'orbital-particle-spectrometer':orbital_particle_spectrometer,
        'surface-rock-crusher':surface_rock_crusher,
        'habitat-pollinator-vivarium':habitat_pollinator_vivarium,
        'orbital-inflatable-habitat':orbital_inflatable_habitat,
        'surface-snowplow':surface_snowplow,
        'habitat-print-shop':habitat_print_shop,
        'orbital-robotic-arm':orbital_robotic_arm,
        'surface-mobile-batch-mixer':surface_mobile_batch_mixer,
        'habitat-dental-clinic':habitat_dental_clinic,
        'orbital-whipple-shield-rack':orbital_whipple_shield_rack,
        'surface-tunnel-lining-gantry':surface_tunnel_lining_gantry,
        'habitat-childcare-playroom':habitat_childcare_playroom,
        'orbital-fluid-separator':orbital_fluid_separator,
        'surface-asphalt-paver':surface_asphalt_paver,
        'habitat-barber-shop':habitat_barber_shop,
        'orbital-docking-seal-test-fixture':orbital_docking_seal_test_fixture,
        'surface-rotary-snow-sweeper':surface_rotary_snow_sweeper,
        'habitat-courier-post-office':habitat_courier_post_office,
        'orbital-micrometeoroid-dust-collector':orbital_micrometeoroid_dust_collector,
        'surface-floodwater-pump-trailer':surface_floodwater_pump_trailer,
        'habitat-community-theater':habitat_community_theater,
        'orbital-plasma-contactor':orbital_plasma_contactor}


def bounds(objects):
    bpy.context.view_layer.update()
    pts=[o.matrix_world @ Vector(x) for o in objects if o.type=='MESH' for x in o.bound_box]
    return [Vector([fn(v[i] for v in pts) for i in range(3)]) for fn in (min,max)]


def stats(objects):
    lo,hi=bounds(objects)
    meshes=[o for o in objects if o.type=='MESH']
    for o in meshes: o.data.calc_loop_triangles()
    return {'meshObjects':len(meshes),'vertices':sum(len(o.data.vertices) for o in meshes),
            'triangles':sum(len(o.data.loop_triangles) for o in meshes),'materials':len({m.name for o in meshes for m in o.data.materials if m}),
            'dimensions':[round(v,4) for v in hi-lo]}


def render(objects, path):
    lo,hi=bounds(objects); center=(lo+hi)/2; span=max(hi-lo)
    scene=bpy.context.scene
    scene.render.engine='CYCLES';scene.cycles.device='CPU';scene.cycles.samples=12;scene.cycles.use_denoising=True
    scene.render.threads_mode='FIXED';scene.render.threads=3
    scene.world=bpy.data.worlds.new('Studio ambience'); scene.world.color=(.26,.30,.35)
    def face(obj): obj.rotation_euler=(center-obj.location).to_track_quat('-Z','Y').to_euler()
    for name,offset,power,color,size in [('Softbox',(2,-4,6),195,(.84,.91,1),3.5),('Warm edge',(-4,3,3),230,(1,.74,.47),2.3),('Fill',(-4,-2,1.5),88,(.50,.8,1),3)]:
        bpy.ops.object.light_add(type='AREA',location=center+Vector(offset)*span/2)
        lamp=bpy.context.object;lamp.name=name;lamp.data.energy=power*span**2;lamp.data.color=color;lamp.data.shape='DISK';lamp.data.size=size*span/2;face(lamp)
    bpy.ops.object.camera_add(location=center+Vector((1.12,-1.53,1.02))*span)
    camera=bpy.context.object;face(camera);scene.camera=camera;camera.data.type='ORTHO'
    bpy.context.view_layer.update()
    proj=[camera.matrix_world.inverted() @ (obj.matrix_world @ Vector(vertex)) for obj in objects if obj.type=='MESH' for vertex in obj.bound_box]
    w=max(p.x for p in proj)-min(p.x for p in proj);h=max(p.y for p in proj)-min(p.y for p in proj)
    camera.data.ortho_scale=max(w,h*1.2)*1.18;camera.data.clip_end=max(1000,span*8)
    scene.render.resolution_x=960;scene.render.resolution_y=800;scene.render.resolution_percentage=100
    scene.render.film_transparent=True;scene.render.image_settings.color_mode='RGBA';scene.render.image_settings.file_format='PNG'
    scene.render.filepath=str(path);bpy.ops.render.render(write_still=True)


def set_ports(count):
    assemblies=sorted((o for o in bpy.context.scene.objects if o.get('role')=='docking-port'),key=lambda o:o['port'])
    if not assemblies: raise ValueError('Reference has no authored docking assemblies')
    if len(assemblies)==count: return
    first=assemblies[0]
    for obj in assemblies[1:]:
        for child in list(obj.children_recursive): bpy.data.objects.remove(child,do_unlink=True)
        bpy.data.objects.remove(obj,do_unlink=True)
    for n in range(2,count+1):
        group=first.copy(); bpy.context.collection.objects.link(group)
        group.name=f'Docking Port {n} Assembly';group['port']=n
        group.matrix_local=Matrix.Rotation(-2*PI*(n-1)/count,4,'Y') @ first.matrix_local
        for base in first.children:
            child=base.copy();bpy.context.collection.objects.link(child);child.parent=group
            child.name=base.name.replace(' 1',' '+str(n))
            if child.get('name'): child['name']=str(child['name']).replace(' 1',' '+str(n))


def build(slug,dest,reference=None,scale=1,lod=1,paint=None,ports=None):
    dest.mkdir(parents=True,exist_ok=True)
    bpy.ops.wm.read_factory_settings(use_empty=True)
    for name,rgb,em in [('Graphite',(.040,.065,.083),0),('Slate',(.12,.18,.22),0),('Steel',(.33,.42,.46),0),
                        ('Teal',(.043,.25,.26),0),('Ivory',(.75,.79,.71),0),('Ochre',(.88,.39,.045),0),
                        ('Basalt',(.095,.072,.061),0),('Stone',(.34,.28,.23),0),('Sand',(.66,.51,.32),0),
                        ('Ocean',(.012,.14,.31),0),('Land',(.24,.40,.18),0),('Forest',(.035,.23,.12),0),
                        ('Ice',(.70,.82,.87),0),('Cloud',(.59,.66,.68),0),('Cyan',(.05,.64,.75),1.7),('Amber',(.98,.29,.035),1.4),('Copper',(.61,.25,.11),0)]:
        material(name,rgb,emission=em)
    if reference:
        bpy.ops.import_scene.gltf(filepath=str(reference))
    else:
        MODELS[slug]()
    if ports is not None: set_ports(ports)
    originals=list(bpy.context.scene.objects)
    meshes=[o for o in originals if o.type=='MESH']
    assert meshes
    if ports is not None:
        assert sorted(o.get('port') for o in originals if o.get('role')=='docking-port') == list(range(1,ports+1))
    root=bpy.data.objects.new('Sovereignty asset',None);bpy.context.collection.objects.link(root)
    for o in originals:
        if not o.parent:o.parent=root
    if reference:
        lo,hi=bounds(meshes)
        if (hi-lo).y < min((hi-lo).x,(hi-lo).z)*.84: root.rotation_euler.x=PI/2
    root.scale=(scale,)*3
    if paint:
        mat=next((slot.material for o in meshes for slot in o.material_slots if slot.material),None)
        rgb=tuple(int(paint[i:i+2],16)/255 for i in (0,2,4))
        mat.diffuse_color=(*rgb,1);mat.node_tree.nodes.get('Principled BSDF').inputs['Base Color'].default_value=(*rgb,1)
    if lod<1:
        for o in meshes:
            if len(o.data.polygons)>12: o.modifiers.new('LOD reduction','DECIMATE').ratio=lod
    bpy.context.view_layer.update()
    bpy.ops.object.select_all(action='DESELECT')
    for o in [root,*originals]: o.select_set(True)
    bpy.ops.export_scene.gltf(filepath=str(dest/'export.glb'),export_format='GLB',use_selection=True,export_apply=True,export_extras=True,
                              export_texcoords=True,export_cameras=False,export_lights=False)
    report=stats(meshes)
    render(meshes,dest/'preview.png')
    bpy.context.preferences.filepaths.save_version=0
    bpy.ops.wm.save_as_mainfile(filepath=str(dest/'model.blend'),compress=True)
    bpy.ops.wm.open_mainfile(filepath=str(dest/'model.blend'))
    assert stats(list(bpy.context.scene.objects))['meshObjects']==report['meshObjects']
    bpy.ops.wm.read_factory_settings(use_empty=True)
    bpy.ops.import_scene.gltf(filepath=str(dest/'export.glb'))
    loaded=stats(list(bpy.context.scene.objects))
    assert loaded['triangles']>0 and min(loaded['dimensions'])>0
    if ports is not None:
        assert len([o for o in bpy.context.scene.objects if o.get('role')=='docking-port'])==ports
    (dest/'specs.json').write_text(json.dumps({**loaded,'blender':bpy.app.version_string,'ports':ports,'preview':'Cycles CPU render of model.blend'},indent=2)+'\n')


if __name__=='__main__':
    args=sys.argv[sys.argv.index('--')+1:] if '--' in sys.argv else sys.argv[1:]
    p=argparse.ArgumentParser(description=__doc__)
    p.add_argument('--model',required=True);p.add_argument('--output',required=True,type=Path);p.add_argument('--reference',type=Path)
    p.add_argument('--ports',type=int,choices=[4,6]);p.add_argument('--scale',type=float,default=1);p.add_argument('--lod',type=float,default=1)
    p.add_argument('--paint',help='Hex RGB for the primary material')
    a=p.parse_args(args)
    if not (0<a.scale<=100 and 0<a.lod<=1):p.error('Scale and LOD must be positive and within range')
    build(a.model,a.output.resolve(),a.reference,a.scale,a.lod,a.paint,a.ports)
