"""v3: continuous belt kit (belt / turn / splitter / sorter) + warehouse dressing (mezzanine, stairs, crane, fan, banner, cage, duct, bollard). Authored in UNITY coordinates through v2.B(): Unity (x, y, z) == Blender (-x, -z, y). Run: blender -b --factory-startup --python v3_belts.py -- [names] ("_chain" renders a belt-chain test preview) """ import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from v2 import * import v2 BY = 0.35 # belt top HW = 0.42 # belt half width (0.84) # ======================================================================= helpers def u_transform(o, ang=0.0, t=(0, 0, 0)): """Rotate about Unity Y by ang ((x,z) -> (x cos - z sin, x sin + z cos)) then translate by unity t. Bakes into mesh.""" apply_xform(o) c, s = math.cos(ang), math.sin(ang) for v in o.data.vertices: x, y, z = -v.co.x, v.co.z, -v.co.y x, z = x * c - z * s, x * s + z * c x, y, z = x + t[0], y + t[1], z + t[2] v.co = (-x, -z, y) o.data.update() return o def uv_box_m(o, scale=1.0, mscale=None): """World box projection with a per-material scale override (e.g. hazard stripes).""" mscale = mscale or {} me = o.data names = [m.name if m else "" for m in me.materials] bm = bmesh.new() bm.from_mesh(me) uv = bm.loops.layers.uv.verify() for f in bm.faces: nm = names[f.material_index] if f.material_index < len(names) else "" sc = mscale.get(nm, scale) n = f.normal ax = max(range(3), key=lambda i: abs(n[i])) for l in f.loops: p = l.vert.co if ax == 0: u, v = (p.y if n.x > 0 else -p.y), p.z elif ax == 1: u, v = (-p.x if n.y > 0 else p.x), p.z else: u, v = p.x, (p.y if n.z > 0 else -p.y) l[uv].uv = (u * sc, v * sc) bm.to_mesh(me) bm.free() def fin(P, name, uv=1.0, ang=40, haz=4.0): o = join(P, name) uv_box_m(o, uv, {"M_Hazard": haz}) smooth(o, ang) return o def rrect(d0, d1, y0, y1, r, n=3): """Rounded rectangle polygon in (d, y), CCW.""" r = min(r, (d1 - d0) / 2 - 1e-4, (y1 - y0) / 2 - 1e-4) pts = [] for (cd, cy, a0) in ((d0 + r, y0 + r, 180), (d1 - r, y0 + r, 270), (d1 - r, y1 - r, 0), (d0 + r, y1 - r, 90)): for i in range(n + 1): a = math.radians(a0 + 90 * i / n) pts.append((cd + r * math.cos(a), cy + r * math.sin(a))) return pts def sweep(name, prof, path, m, cap=True): """prof: closed polygon of (d, y); path: [(px, pz, nx, nz)] reference points + outward unit normal in unity XZ.""" bm = bmesh.new() rings = [[bm.verts.new(B(px + nx * d, y, pz + nz * d)) for (d, y) in prof] for (px, pz, nx, nz) in path] n = len(prof) for a, b in zip(rings, rings[1:]): for i in range(n): j = (i + 1) % n bm.faces.new((a[i], a[j], b[j], b[i])) if cap: bm.faces.new(rings[0]) bm.faces.new(list(reversed(rings[-1]))) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return o def line_path(s, z0, z1, ref=HW): """straight side: reference line x = s*ref, outward normal (s, 0).""" return [(s * ref, z0, s, 0.0), (s * ref, z1, s, 0.0)] def prism_y(name, pts_xz, y0, y1, m): """Convex polygon in unity (x, z) extruded along Y.""" bm = bmesh.new() a = [bm.verts.new(B(x, y0, z)) for (x, z) in pts_xz] b = [bm.verts.new(B(x, y1, z)) for (x, z) in pts_xz] bm.faces.new(a) bm.faces.new(list(reversed(b))) n = len(pts_xz) for i in range(n): j = (i + 1) % n bm.faces.new((a[i], a[j], b[j], b[i])) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return o def chevron_xz(P, cx, cz, dirx, y0, y1, h=0.035, t=0.02, m="M_PaintWhite"): """flat chevron on a horizontal surface pointing along +X (dirx=1) or -X (dirx=-1); two convex arms.""" tx = cx + dirx * h / 2 for sz in (1, -1): pts = [(tx - dirx * h, sz * h), (tx - dirx * h + dirx * t, sz * h), (tx + dirx * t, 0.0), (tx, 0.0)] P.append(prism_y("chev", [(x, z + cz) for (x, z) in pts], y0, y1, m)) def chevron_xy(P, cx, cy, dirx, z0, z1, h=0.04, t=0.022, m="M_PaintWhite"): """chevron on a vertical (Z-facing) surface pointing along +-X.""" tx = cx + dirx * h / 2 for sy in (1, -1): pts = [(tx - dirx * h, cy + sy * h), (tx - dirx * h + dirx * t, cy + sy * h), (tx + dirx * t, cy), (tx, cy)] P.append(extrude_poly("chev", pts, "XY", z0, z1, m)) # ======================================================================= belt kit: shared profiles SIDE = rrect(0.003, 0.06, 0.24, 0.372, 0.016, 2) # side channel (yellow) SIDE_LOW = rrect(0.003, 0.06, 0.24, 0.345, 0.016, 2) # side channel lowered (sorter kick-out opening) STRIP = rrect(0.058, 0.066, 0.278, 0.336, 0.004, 1) # dark inset band on the outer face GUARD = rrect(-0.016, 0.06, 0.40, 0.468, 0.03, 3) # round-nosed guide rail, on brackets GUARD_CAP = rrect(-0.024, 0.068, 0.392, 0.476, 0.034, 3) # rubber end cap over the guide rail SIDE_CAP = rrect(-0.002, 0.066, 0.234, 0.378, 0.018, 2) # hazard end plate over the side channel PAN = [(-0.86, 0.232), (0.03, 0.232), (0.03, 0.247), (-0.86, 0.247)] DETAIL_STEP = 0.25 def side_run(P, path, guard=True, low=False, strip_m="M_DarkGrey"): P.append(sweep("beam", SIDE_LOW if low else SIDE, path, "M_PaintYellow")) P.append(sweep("strip", STRIP, path, strip_m)) if guard: P.append(sweep("guard", GUARD, path, "M_PaintYellow")) def side_bits(P, px, pz, nx, nz, nut=True, bracket=True, washer=True): """roller-axle nut on the outer band + guide-rail bracket, built at d-axis = +X and placed on the path.""" parts = [] if nut and washer: parts.append(ucyl("washer", 0.024, 0.006, (0.068, 0.307, 0), "X", verts=10, m="M_DarkGrey")) if nut: parts.append(ucyl("nut", 0.016, 0.014, (0.071, 0.307, 0), "X", verts=6, m="M_Metal")) if bracket: parts.append(ubox("brk", 0.01, 0.05, 0.366, 0.41, -0.02, 0.02, "M_DarkGrey")) parts.append(ucyl("bolt", 0.008, 0.01, (0.03, 0.47, 0), "Y", verts=6, m="M_Metal")) for o in parts: u_transform(o, math.atan2(nz, nx), (px, 0, pz)) P.append(o) def legs_pair(P, z=0.0, xs=(-0.45, 0.45), gusset=True): for x in xs: P.append(ubox("leg", x - 0.025, x + 0.025, 0.02, 0.242, z - 0.025, z + 0.025, "M_DarkGrey", bevel=0.006, segs=1)) P.append(ubox("foot", x - 0.05, x + 0.05, 0.0, 0.022, z - 0.05, z + 0.05, "M_Rubber", bevel=0.008, segs=1)) if gusset: for sz in (-1, 1): P.append(utube("gus", [(x, 0.14, z + sz * 0.02), (x, 0.236, z + sz * 0.13)], 0.011, "M_DarkGrey", res=1, segs=4)) P.append(ubox("brace", xs[0], xs[1], 0.085, 0.11, z - 0.013, z + 0.013, "M_DarkGrey")) def end_parts(roller=True): """End cap built for the entry end (z = -0.5, piece extends toward +Z). Symmetric in X.""" P = [] for s in (-1, 1): P.append(sweep("gcap", GUARD_CAP, line_path(s, -0.514, -0.488), "M_Rubber")) P.append(sweep("hplate", SIDE_CAP, line_path(s, -0.512, -0.497), "M_Hazard")) if roller: x = s * (HW + 0.066) P.append(ucyl("hub", 0.03, 0.006, (x + s * 0.003, BY - 0.035, -0.462), "X", verts=14, m="M_DarkGrey")) P.append(ucyl("hubnut", 0.018, 0.012, (x + s * 0.006, BY - 0.035, -0.462), "X", verts=6, m="M_Metal")) P.append(ubox("bumper", -HW + 0.005, HW - 0.005, 0.244, 0.282, -0.514, -0.482, "M_Rubber", bevel=0.012, segs=2)) return P def make_end(name, ang, roller=True): o = fin(end_parts(roller), name, haz=5.0) u_transform(o, ang) return o def belt_object(): b, half, r = belt_loop(1.0, r=0.035) # v2 loop: U 0..1 across, V in metres (same convention as v2 SM_Belt) return b def straight_frame(P, open_neg=None, open_pos=None): """Straight belt frame. open_neg/open_pos: (z0, z1) guard opening on the -X / +X side.""" for s, op in ((-1, open_neg), (1, open_pos)): if op is None: side_run(P, line_path(s, -0.5, 0.5)) else: z0, z1 = op side_run(P, line_path(s, -0.5, z0)) side_run(P, line_path(s, z1, 0.5)) low = s < 0 side_run(P, line_path(s, z0, z1), guard=False, low=low, strip_m="M_Hazard" if low else "M_DarkGrey") for zc, a, b in ((z0, z0 - 0.02, z0 + 0.012), (z1, z1 - 0.012, z1 + 0.02)): P.append(sweep("gcap", GUARD_CAP, line_path(s, a, b), "M_Rubber")) for k in range(4): z = -0.375 + k * DETAIL_STEP inside = op is not None and op[0] - 0.03 < z < op[1] + 0.03 side_bits(P, s * HW, z, s, 0, bracket=not inside) P.append(prism_y("pan", [(-0.45, -0.5), (0.45, -0.5), (0.45, 0.5), (-0.45, 0.5)], 0.232, 0.247, "M_DarkGrey")) legs_pair(P) # ======================================================================= 1. SM_Belt def belt(): belt_object() P = [] straight_frame(P) fin(P, "Frame") make_end("EndIn", 0.0) make_end("EndOut", math.pi) return dict(elev=30, azim=-40) # ======================================================================= 2. SM_BeltTurn TCX, TCZ, TRI, TRO = 0.5, -0.5, 0.08, 0.92 def turn_pt(rad, t): th = math.pi - (math.pi / 2) * t return TCX + rad * math.cos(th), TCZ + rad * math.sin(th), math.cos(th), math.sin(th) def turn_belt(): """Identical to v2 belt_turn's belt (arc centre (0.5,-0.5), radii 0.08..0.92, V = -metres along the flow).""" cx, cz = TCX, TCZ ri, ro = TRI, TRO nA, nR = 16, 2 arc_c = 0.5 * math.pi / 2 def pt(rad, t, y): th = math.pi - (math.pi / 2) * t return (cx + rad * math.cos(th), y, cz + rad * math.sin(th)) bm = bmesh.new() uvl = bm.loops.layers.uv.verify() top = [[bm.verts.new(B(*pt(ri + (ro - ri) * j / nR, i / nA, BELT_Y))) for j in range(nR + 1)] for i in range(nA + 1)] bot = [[bm.verts.new(B(*pt(ri + (ro - ri) * j / nR, i / nA, BELT_Y - 0.035))) for j in range(nR + 1)] for i in range(nA + 1)] for i in range(nA): for j in range(nR): f = bm.faces.new((top[i][j], top[i + 1][j], top[i + 1][j + 1], top[i][j + 1])) for l in f.loops: ii = i if l.vert in (top[i][j], top[i][j + 1]) else i + 1 jj = j if l.vert in (top[i][j], top[i + 1][j]) else j + 1 l[uvl].uv = (jj / nR, -arc_c * ii / nA) bm.faces.new((bot[i][j + 1], bot[i + 1][j + 1], bot[i + 1][j], bot[i][j])) bm.faces.new((top[i][0], bot[i][0], bot[i + 1][0], top[i + 1][0])) bm.faces.new((top[i + 1][nR], bot[i + 1][nR], bot[i][nR], top[i][nR])) for i in (0, nA): for j in range(nR): bm.faces.new((top[i][j], top[i][j + 1], bot[i][j + 1], bot[i][j])) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) bt = mesh_obj("Belt", bm) set_mats(bt, "M_ConveyorBelt") smooth(bt, 40) return bt def belt_turn(): turn_belt() P = [] nO, nI = 20, 6 outer = [] for i in range(nO + 1): x, z, nx, nz = turn_pt(TRO, i / nO) outer.append((x, z, nx, nz)) inner = [] for i in range(nI + 1): x, z, nx, nz = turn_pt(TRI, i / nI) inner.append((x, z, -nx, -nz)) side_run(P, outer) side_run(P, inner) P.append(sweep("pan", PAN, outer, "M_DarkGrey")) arc = TRO * math.pi / 2 k = int(round(arc / DETAIL_STEP)) for i in range(k): side_bits(P, *turn_pt(TRO, (i + 0.5) / k)) # legs: one under the outer rail at mid-arc, one at the inner corner, cross brace between them xo, zo, nx, nz = turn_pt(TRO + 0.03, 0.5) xi, zi, _, _ = turn_pt(0.075, 0.5) for (x, z) in ((xo, zo), (xi, zi)): P.append(ubox("leg", x - 0.025, x + 0.025, 0.02, 0.242, z - 0.025, z + 0.025, "M_DarkGrey", bevel=0.006, segs=1)) P.append(ubox("foot", x - 0.05, x + 0.05, 0.0, 0.022, z - 0.05, z + 0.05, "M_Rubber", bevel=0.008, segs=1)) L = math.dist((xo, zo), (xi, zi)) br = ubox("brace", -L / 2, L / 2, 0.085, 0.11, -0.013, 0.013, "M_DarkGrey") u_transform(br, math.atan2(zo - zi, xo - xi), ((xo + xi) / 2, 0, (zo + zi) / 2)) P.append(br) for sz in (-1, 1): a = ((xo, 0.14, zo), None) tx, tz = -nz * sz, nx * sz # tangent P.append(utube("gus", [(xo + tx * 0.02, 0.14, zo + tz * 0.02), (xo + tx * 0.13, 0.236, zo + tz * 0.13)], 0.011, "M_DarkGrey", res=1, segs=4)) fin(P, "Frame") make_end("EndIn", 0.0, roller=False) make_end("EndOut", math.pi / 2, roller=False) return dict(elev=40, azim=-30) # ======================================================================= 3. SM_BeltSplitter def belt_splitter(): P = [] # deck + free-ball transfer field P.append(prism_y("deck", [(-0.478, -0.478), (0.478, -0.478), (0.478, 0.44), (-0.478, 0.44)], 0.298, 0.325, "M_DarkGrey")) grid = (-0.325, -0.195, -0.065, 0.065, 0.195, 0.325) for x in grid: for z in grid: P.append(ucyl("cup", 0.036, 0.008, (x, 0.326, z), "Y", verts=8, m="M_Metal", cap=False)) ball = usphere("ball", 0.028, (x, 0.322, z), "M_Metal", seg=7, rings=4) bm = bmesh.new(); bm.from_mesh(ball.data) bmesh.ops.delete(bm, geom=[v for v in bm.verts if v.co.z < 0.318], context="VERTS") bm.to_mesh(ball.data); bm.free() P.append(ball) for cx in (0.13, 0.26, 0.39): for d in (1, -1): chevron_xz(P, d * cx, 0.0, d, 0.325, 0.332) # under-deck skirt on the three open edges (below deck top so neighbours' belts butt cleanly) P.append(ubox("skirt", -0.45, 0.45, 0.24, 0.3, -0.478, -0.422, "M_PaintYellow", bevel=0.012, segs=1)) for s in (-1, 1): P.append(ubox("skirt", min(s * 0.422, s * 0.478), max(s * 0.422, s * 0.478), 0.24, 0.3, -0.45, 0.44, "M_PaintYellow", bevel=0.012, segs=1)) # outer bands + nuts like the belts P.append(ubox("band", min(s * 0.478, s * 0.484), max(s * 0.478, s * 0.484), 0.255, 0.29, -0.4, 0.4, "M_DarkGrey")) for z in (-0.25, 0.0, 0.25): side_bits(P, s * 0.418, z, s, 0, bracket=False, washer=False) # corner posts where neighbouring belt side channels butt in for (x, z) in ((-0.45, -0.45), (0.45, -0.45)): P.append(ubox("post", x - 0.03, x + 0.03, 0.24, 0.43, z - 0.03, z + 0.03, "M_PaintYellow", bevel=0.012, segs=1)) P.append(ubox("pcap", x - 0.034, x + 0.034, 0.42, 0.45, z - 0.034, z + 0.034, "M_Rubber", bevel=0.012, segs=1)) P.append(prism_y("pan", [(-0.45, -0.5), (0.45, -0.5), (0.45, 0.5), (-0.45, 0.5)], 0.232, 0.247, "M_DarkGrey")) # back wall with bumper, arrows, actuator head and lamp P.append(ubox("wall", -0.5, 0.5, 0.24, 0.62, 0.44, 0.5, "M_PaintYellow", bevel=0.022, segs=2)) P.append(ubox("wbump", -0.45, 0.45, 0.35, 0.44, 0.422, 0.442, "M_Rubber", bevel=0.01, segs=1)) for d in (1, -1): for cx in (0.2, 0.32): chevron_xy(P, d * cx, 0.53, d, 0.432, 0.442) P.append(ubox("head", -0.09, 0.09, 0.53, 0.67, 0.23, 0.5, "M_DarkGrey", bevel=0.025, segs=2)) P.append(ucyl("motor", 0.06, 0.08, (0, 0.71, 0.4), "Y", verts=14, m="M_PaintBlue", bevel=0.012)) P.append(ucyl("motorcap", 0.045, 0.02, (0, 0.76, 0.4), "Y", verts=12, m="M_DarkGrey")) lamp = lamp_parts(P, 0.36, 0.62, 0.43) legs_pair(P) for x in (-0.45, 0.45): # extra legs under the back wall P.append(ubox("leg", x - 0.025, x + 0.025, 0.02, 0.242, 0.445, 0.495, "M_DarkGrey", bevel=0.006, segs=1)) P.append(ubox("foot", x - 0.04, x + 0.04, 0.0, 0.022, 0.43, 0.5, "M_Rubber", bevel=0.008, segs=1)) fin(P, "Frame") # EndIn: rubber nose + hazard plates on the front corner posts E = [ubox("bumper", -0.42, 0.42, 0.244, 0.29, -0.514, -0.48, "M_Rubber", bevel=0.012, segs=2)] for x in (-0.45, 0.45): E.append(ubox("hplate", x - 0.036, x + 0.036, 0.236, 0.42, -0.494, -0.478, "M_Hazard", bevel=0.006, segs=1)) fin(E, "EndIn", haz=5.0) # Paddle: pivot (0, 0.35, 0.32), points toward -Z, length 0.55, height 0.15 Q = [ucyl("barrel", 0.042, 0.18, (0, 0.44, 0.32), "Y", verts=14, m="M_DarkGrey", bevel=0.01)] Q.append(ucyl("collar", 0.05, 0.03, (0, 0.515, 0.32), "Y", verts=14, m="M_Metal")) flap = ubox("flap", -0.02, 0.02, 0.358, 0.5, -0.23, 0.31, "M_PaintRed", bevel=0.016, segs=2) Q.append(flap) Q.append(ubox("tip", -0.026, 0.026, 0.36, 0.5, -0.235, -0.19, "M_Rubber", bevel=0.018, segs=2)) for z in (-0.1, 0.05, 0.2): Q.append(ucyl("rivet", 0.012, 0.05, (0, 0.47, z), "X", verts=8, m="M_Metal")) pd = fin(Q, "Paddle") set_origin(pd, B(0, 0.35, 0.32)) return dict(elev=38, azim=145) # ======================================================================= 4. SM_BeltSorter def belt_sorter(): belt_object() P = [] straight_frame(P, open_neg=(-0.35, 0.35), open_pos=(-0.33, 0.33)) # gantry: chunky dark scanner arch at the entry, yellow support arch at the exit, top rails, rodless actuator along X for s in (-1, 1): x0, x1 = (0.43, 0.494) if s > 0 else (-0.494, -0.43) P.append(ubox("spost", x0, x1, 0.24, 1.0, -0.49, -0.37, "M_DarkGrey", bevel=0.02, segs=2)) P.append(ubox("strim", min(s * 0.494, s * 0.5), max(s * 0.494, s * 0.5), 0.3, 0.9, -0.47, -0.39, "M_PaintYellow")) x0, x1 = (0.44, 0.5) if s > 0 else (-0.5, -0.44) P.append(ubox("post", x0, x1, 0.24, 1.02, 0.39, 0.47, "M_PaintYellow", bevel=0.015, segs=2)) P.append(ubox("pfoot", x0 - 0.004, x1 + 0.004, 0.24, 0.29, 0.384, 0.476, "M_DarkGrey", bevel=0.008, segs=1)) P.append(ubox("rail", x0, x1, 1.02, 1.09, -0.37, 0.39, "M_PaintYellow", bevel=0.012, segs=2)) P.append(ubox("endblk", min(s * 0.47, s * 0.5), max(s * 0.47, s * 0.5), 0.9, 1.02, -0.05, 0.05, "M_DarkGrey", bevel=0.008, segs=1)) P.append(ubox("sarch", -0.5, 0.5, 0.92, 1.13, -0.495, -0.365, "M_DarkGrey", bevel=0.03, segs=2)) P.append(ubox("strim", -0.44, 0.44, 1.135, 1.15, -0.47, -0.39, "M_PaintYellow", bevel=0.005, segs=1)) for x in (-0.42, 0.42): P.append(ubox("haz", x - 0.05, x + 0.05, 0.95, 1.1, -0.5, -0.494, "M_Hazard")) P.append(ubox("arch", -0.5, 0.5, 1.0, 1.1, 0.385, 0.475, "M_PaintYellow", bevel=0.02, segs=2)) P.append(ucyl("actuator", 0.03, 0.94, (0, 0.94, 0), "X", verts=12, m="M_Metal")) # stop block behind the pusher plate (+X side) P.append(ubox("stop", 0.476, 0.5, 0.3, 0.44, -0.12, 0.12, "M_DarkGrey", bevel=0.01, segs=1)) fin(P, "Frame") S = [ubox("bar", -0.4, 0.4, 0.9, 0.925, -0.45, -0.41, "M_Emissive"), ubox("bar2", -0.32, 0.32, 1.0, 1.05, -0.5, -0.49, "M_Emissive")] sc = join(S, "Scanner") uv_box(sc, 1) make_end("EndIn", 0.0) make_end("EndOut", math.pi) # Pusher: plate facing -X + hanger rod + carriage riding the actuator. Origin (0.47, 0.42, 0) Q = [ubox("plate", 0.43, 0.47, 0.375, 0.555, -0.3, 0.3, "M_PaintRed", bevel=0.014, segs=2)] Q.append(ubox("pad", 0.418, 0.432, 0.39, 0.54, -0.28, 0.28, "M_Rubber", bevel=0.006, segs=1)) Q.append(ubox("rib", 0.465, 0.48, 0.4, 0.53, -0.04, 0.04, "M_DarkGrey")) Q.append(ubox("rod", 0.44, 0.462, 0.55, 0.9, -0.022, 0.022, "M_Metal", bevel=0.006, segs=1)) Q.append(ubox("arm", 0.3, 0.466, 0.88, 0.912, -0.03, 0.03, "M_DarkGrey", bevel=0.006, segs=1)) Q.append(ubox("carriage", 0.28, 0.37, 0.9, 0.985, -0.06, 0.06, "M_PaintRed", bevel=0.015, segs=2)) for z in (-0.12, 0.12): Q.append(utube("strut", [(0.451, 0.55, z * 1.6), (0.451, 0.7, 0.0)], 0.009, "M_Metal", res=1, segs=4)) pu = fin(Q, "Pusher") set_origin(pu, B(0.47, 0.42, 0)) return dict(elev=28, azim=140) # ======================================================================= 5. SM_WH_Mezzanine MZ_Y = 3.2 def mezz_rail(name, ang): e = 2.965 P = [] for x in (-e, -1.5, 0.0, 1.5, e): P.append(ubox("post", x - 0.03, x + 0.03, MZ_Y, MZ_Y + 1.03, e - 0.03, e + 0.03, "M_PaintYellow", bevel=0.008, segs=1)) P.append(ubox("pbase", x - 0.045, x + 0.045, MZ_Y, MZ_Y + 0.02, e - 0.035, e + 0.035, "M_DarkGrey")) P.append(ubox("top", -e - 0.03, e + 0.03, MZ_Y + 1.0, MZ_Y + 1.05, e - 0.035, e + 0.035, "M_PaintYellow", bevel=0.015, segs=2)) P.append(ubox("mid", -e, e, MZ_Y + 0.53, MZ_Y + 0.565, e - 0.018, e + 0.018, "M_PaintYellow", bevel=0.008, segs=1)) P.append(ubox("kick", -e, e, MZ_Y, MZ_Y + 0.12, e - 0.006, e + 0.006, "M_PaintYellow")) o = fin(P, name) u_transform(o, ang) return o def mezzanine(): D = [] h = 3.0 # yellow perimeter edge beams (C-channel look: web + flanges) for s in (-1, 1): D.append(ubox("edge", -h, h, 2.88, MZ_Y, min(s * h, s * (h - 0.16)), max(s * h, s * (h - 0.16)), "M_PaintYellow", bevel=0.012, segs=1)) D.append(ubox("edge", min(s * h, s * (h - 0.16)), max(s * h, s * (h - 0.16)), 2.88, MZ_Y, -h + 0.16, h - 0.16, "M_PaintYellow", bevel=0.012, segs=1)) D.append(ubox("flng", -h, h, 2.86, 2.9, min(s * h, s * (h - 0.2)), max(s * h, s * (h - 0.2)), "M_PaintYellow")) D.append(ubox("flng", min(s * h, s * (h - 0.2)), max(s * h, s * (h - 0.2)), 2.86, 2.9, -h, h, "M_PaintYellow")) # joists along X for z in (-1.5, 0.0, 1.5): D.append(ubox("joist", -h + 0.16, h - 0.16, 2.92, MZ_Y - 0.03, z - 0.05, z + 0.05, "M_DarkGrey")) D.append(ubox("jfl", -h + 0.16, h - 0.16, 2.9, 2.93, z - 0.07, z + 0.07, "M_DarkGrey")) # grating: bearing bars along Z + cross bars along X, panel bands every 1.5 m n = 56 for i in range(n + 1): x = -2.82 + 5.64 * i / n D.append(ubox("bar", x - 0.008, x + 0.008, MZ_Y - 0.035, MZ_Y, -h + 0.16, h - 0.16, "M_Metal")) for k in range(13): z = -2.7 + k * 0.45 D.append(ubox("xbar", -h + 0.16, h - 0.16, MZ_Y - 0.03, MZ_Y - 0.004, z - 0.006, z + 0.006, "M_DarkGrey")) for x in (-1.5, 0.0, 1.5): D.append(ubox("band", x - 0.025, x + 0.025, MZ_Y - 0.035, MZ_Y, -h + 0.16, h - 0.16, "M_DarkGrey")) fin(D, "Deck") C = [] c = 2.84 for sx in (-1, 1): for sz in (-1, 1): x, z = sx * c, sz * c C.append(ubox("col", x - 0.1, x + 0.1, 0.02, 2.86, z - 0.1, z + 0.1, "M_DarkGrey", bevel=0.012, segs=1)) C.append(ubox("haz", x - 0.104, x + 0.104, 0.1, 1.0, z - 0.104, z + 0.104, "M_Hazard")) C.append(ubox("base", x - 0.14, x + 0.14, 0.0, 0.03, z - 0.14, z + 0.14, "M_DarkGrey", bevel=0.01, segs=1)) for (bx, bz) in ((-0.105, -0.105), (0.105, -0.105), (-0.105, 0.105), (0.105, 0.105)): C.append(ucyl("bolt", 0.018, 0.04, (x + bx, 0.04, z + bz), "Y", verts=6, m="M_Metal")) C.append(ubox("cap", x - 0.14, x + 0.14, 2.84, 2.88, z - 0.14, z + 0.14, "M_DarkGrey")) # knee braces into both edge beams C.append(utube("knee", [(x, 2.25, z - sz * 0.08), (x, 2.86, z - sz * 0.7)], 0.03, "M_DarkGrey", res=1, segs=4)) C.append(utube("knee", [(x - sx * 0.08, 2.25, z), (x - sx * 0.7, 2.86, z)], 0.03, "M_DarkGrey", res=1, segs=4)) fin(C, "Columns", haz=2.0) mezz_rail("RailN", 0.0) mezz_rail("RailE", -math.pi / 2) mezz_rail("RailS", math.pi) mezz_rail("RailW", math.pi / 2) return dict(elev=22, azim=-35) # ======================================================================= 6. SM_WH_Stairs def stairs(): P = [] rise, run, N = 3.2, 5.2, 16 g, r = run / N, rise / N k = rise / run W = 0.6 poly = [(0.0, 0.0), (0.3 / k, 0.0), (run, run * k - 0.3), (run, rise), ((rise - 0.12) / k, rise), (0.0, 0.12)] for s in (-1, 1): x0, x1 = (W, W + 0.06) if s > 0 else (-W - 0.06, -W) P.append(extrude_poly("stringer", poly, "ZY", x0, x1, "M_PaintYellow")) P.append(ubox("sfoot", x0 - 0.03, x1 + 0.03, 0.0, 0.02, 0.0, 0.6, "M_DarkGrey")) for i in range(1, N): y, z = r * i, g * i P.append(ubox("tread", -W, W, y - 0.035, y - 0.005, z - 0.01, z + g - 0.01, "M_DarkGrey")) for j in range(4): zz = z + 0.06 + j * 0.065 P.append(ubox("grip", -W + 0.02, W - 0.02, y - 0.006, y, zz - 0.008, zz + 0.008, "M_Metal")) P.append(ubox("nose", -W, W, y - 0.045, y + 0.002, z - 0.025, z + 0.03, "M_PaintYellow", bevel=0.008, segs=1)) for s in (-1, 1): # tread hanger plates P.append(ubox("tab", min(s * (W - 0.03), s * W), max(s * (W - 0.03), s * W), y - 0.09, y - 0.035, z + 0.05, z + g - 0.05, "M_DarkGrey")) # landing lip at the top (flush with the mezzanine deck) P.append(ubox("lip", -W - 0.06, W + 0.06, rise - 0.035, rise, run - 0.02, run + 0.22, "M_DarkGrey")) P.append(ubox("lipnose", -W - 0.06, W + 0.06, rise - 0.05, rise + 0.003, run - 0.03, run + 0.03, "M_PaintYellow", bevel=0.008, segs=1)) P.append(ubox("lipedge", -W - 0.06, W + 0.06, rise - 0.08, rise - 0.03, run + 0.2, run + 0.24, "M_DarkGrey")) # handrails both sides xr = W + 0.09 for s in (-1, 1): x = s * xr posts = (0.35, 1.95, 3.55, 5.1) for z in posts: yb = z * k + 0.05 P.append(ubox("post", x - 0.025, x + 0.025, yb, yb + 0.95, z - 0.025, z + 0.025, "M_PaintYellow", bevel=0.006, segs=1)) P.append(ubox("pbr", min(x, s * (W + 0.06)), max(x, s * (W + 0.06)), yb, yb + 0.06, z - 0.03, z + 0.03, "M_DarkGrey")) z0, z1 = 0.2, run + 0.15 P.append(utube("top", [(x, z0 * k + 1.0, z0), (x, z1 * k + 1.0 if z1 < run else rise + 1.0, z1)], 0.028, "M_PaintYellow", res=1, segs=8)) P.append(utube("mid", [(x, z0 * k + 0.55, z0), (x, run * k + 0.55, run)], 0.02, "M_PaintYellow", res=1, segs=6)) # bottom return bend P.append(utube("ret", [(x, z0 * k + 1.0, z0), (x, 0.65, 0.05), (x, 0.3, 0.05)], 0.028, "M_PaintYellow", res=4, segs=8)) P.append(usphere("knob", 0.032, (x, run * k + 1.0, run + 0.15), "M_PaintYellow", seg=10, rings=5)) fin(P, "SM_WH_Stairs") return dict(elev=20, azim=-60) # ======================================================================= 7. SM_WH_Crane def crane(): P = [] L = 11.65 gz = 0.55 for sz in (-1, 1): z = sz * gz P.append(ubox("girder", -L, L, 0.03, 0.97, z - 0.21, z + 0.21, "M_PaintYellow", bevel=0.02, segs=1)) P.append(ubox("tfl", -L, L, 0.95, 1.0, z - 0.24, z + 0.24, "M_PaintYellow", bevel=0.01, segs=1)) P.append(ubox("bfl", -L, L, 0.0, 0.05, z - 0.24, z + 0.24, "M_PaintYellow", bevel=0.01, segs=1)) P.append(ubox("rail", -L + 0.2, L - 0.2, 1.0, 1.05, z - 0.03, z + 0.03, "M_Metal")) for i in range(15): x = -10.5 + i * 1.5 for f in (-1, 1): zz = z + f * 0.21 P.append(ubox("rib", x - 0.03, x + 0.03, 0.05, 0.95, min(zz, zz + f * 0.025), max(zz, zz + f * 0.025), "M_PaintYellow")) for sx in (-1, 1): xa, xb = sorted((sx * 10.6, sx * (L - 0.05))) P.append(ubox("haz", xa, xb, -0.005, 1.005, z - 0.245, z + 0.245, "M_Hazard")) # end trucks + wheels + drives for sx in (-1, 1): x = sx * 11.9 P.append(ubox("truck", x - 0.25, x + 0.25, -0.3, 0.5, -1.75, 1.75, "M_PaintYellow", bevel=0.04, segs=2)) P.append(ubox("tband", x - 0.255, x + 0.255, 0.1, 0.22, -1.755, 1.755, "M_DarkGrey")) for sz in (-1, 1): z = sz * 1.35 P.append(ucyl("wheel", 0.28, 0.16, (x, -0.32, z), "X", verts=20, m="M_DarkGrey", bevel=0.02)) P.append(ucyl("whub", 0.12, 0.2, (x, -0.32, z), "X", verts=12, m="M_Metal")) P.append(ubox("bump", x - 0.18, x + 0.18, -0.2, 0.3, min(sz * 1.75, sz * 1.86), max(sz * 1.75, sz * 1.86), "M_Rubber", bevel=0.04, segs=2)) P.append(ubox("hz", x - 0.256, x + 0.256, -0.3, 0.5, min(sz * 1.45, sz * 1.756), max(sz * 1.45, sz * 1.756), "M_Hazard")) xm = x - sx * 0.55 P.append(ubox("drive", xm - 0.25, xm + 0.25, -0.05, 0.35, 1.0, 1.4, "M_PaintBlue", bevel=0.04, segs=2)) P.append(ucyl("motor", 0.17, 0.4, (xm, 0.15, 1.6), "Z", verts=16, m="M_PaintBlue", bevel=0.02)) P.append(ucyl("mcap", 0.12, 0.06, (xm, 0.15, 1.82), "Z", verts=14, m="M_DarkGrey")) # walkway along -Z zw0, zw1 = -1.35, -0.8 P.append(ubox("walk", -11.2, 11.2, 0.02, 0.06, zw0, zw1, "M_DarkGrey")) for i in range(12): x = -11.0 + i * 2.0 P.append(ubox("wbrk", x - 0.03, x + 0.03, 0.0, 0.3, zw1, -gz - 0.24, "M_DarkGrey")) for i in range(12): x = -11.0 + i * 2.0 P.append(ubox("wpost", x - 0.025, x + 0.025, 0.06, 1.1, zw0, zw0 + 0.05, "M_PaintYellow")) P.append(ubox("wtop", -11.2, 11.2, 1.07, 1.11, zw0 - 0.005, zw0 + 0.055, "M_PaintYellow")) P.append(ubox("wmid", -11.2, 11.2, 0.58, 0.61, zw0 + 0.01, zw0 + 0.04, "M_PaintYellow")) P.append(ubox("wtoe", -11.2, 11.2, 0.06, 0.16, zw0, zw0 + 0.01, "M_PaintYellow")) # capacity sign on the outer (+Z) girder face P.append(ubox("sign", -1.2, 1.2, 0.2, 0.8, gz + 0.246, gz + 0.26, "M_PaintWhite", bevel=0.01, segs=1)) P.append(ubox("signb", -1.1, 1.1, 0.3, 0.7, gz + 0.258, gz + 0.264, "M_PaintRed")) fin(P, "Bridge", haz=0.5) # Trolley (origin = centre bottom, on top of the girders y = 1.0) T = [] for sz in (-1, 1): z = sz * gz T.append(ubox("side", -0.8, 0.8, 0.15, 0.36, z - 0.12, z + 0.12, "M_PaintBlue", bevel=0.02, segs=2)) for sx in (-1, 1): T.append(ucyl("wheel", 0.1, 0.09, (sx * 0.55, 0.15, z), "Z", verts=14, m="M_DarkGrey")) for sx in (-1, 1): T.append(ubox("end", sx * 0.68 - 0.1, sx * 0.68 + 0.1, 0.15, 0.36, -gz - 0.12, gz + 0.12, "M_PaintBlue", bevel=0.02, segs=2)) T.append(ubox("bump", min(sx * 0.78, sx * 0.88), max(sx * 0.78, sx * 0.88), 0.18, 0.33, -0.25, 0.25, "M_Rubber", bevel=0.03, segs=2)) for sz in (-1, 1): T.append(ubox("deck", -0.58, 0.58, 0.34, 0.38, min(sz * 0.16, sz * 0.67), max(sz * 0.16, sz * 0.67), "M_DarkGrey")) for sx in (-1, 1): T.append(ubox("drumsup", sx * 0.52 - 0.04, sx * 0.52 + 0.04, 0.36, 0.95, -0.28, 0.28, "M_PaintBlue", bevel=0.02, segs=2)) T.append(ucyl("drum", 0.22, 0.96, (0, 0.62, 0), "X", verts=20, m="M_Metal")) for i in range(7): T.append(ucyl("groove", 0.226, 0.02, (-0.36 + i * 0.12, 0.62, 0), "X", verts=20, m="M_DarkGrey")) T.append(ubox("gearbox", -0.85, -0.56, 0.38, 0.88, -0.26, 0.26, "M_DarkGrey", bevel=0.04, segs=2)) T.append(ucyl("motor", 0.17, 0.42, (0.78, 0.62, 0), "X", verts=16, m="M_PaintYellow", bevel=0.02)) T.append(ucyl("fan", 0.13, 0.06, (1.02, 0.62, 0), "X", verts=14, m="M_DarkGrey")) T.append(ubox("panel", -0.4, 0.2, 0.38, 0.75, 0.45, 0.62, "M_PaintWhite", bevel=0.02, segs=1)) T.append(lamp_parts(T, 0.3, 0.38, 0.5)) tr = fin(T, "Trolley") u_transform(tr, 0.0, (0, 1.0, 0)) # sits on the girder tops (y = 1.0) set_origin(tr, B(0, 1.0, 0)) # Hook (origin at cable top, under the drum) top = 1.4 H_ = [] for (cx, cz) in ((-0.06, -0.05), (0.06, -0.05), (-0.06, 0.05), (0.06, 0.05)): H_.append(ucyl("cable", 0.013, 1.5, (cx, top - 0.75, cz), "Y", verts=6, m="M_Metal")) yb = top - 1.5 H_.append(ubox("block", -0.2, 0.2, yb - 0.45, yb + 0.02, -0.13, 0.13, "M_PaintYellow", bevel=0.06, segs=3)) for f in (-1, 1): H_.append(ubox("bhaz", -0.17, 0.17, yb - 0.38, yb - 0.08, min(f * 0.128, f * 0.136), max(f * 0.128, f * 0.136), "M_Hazard")) H_.append(ucyl("sheave", 0.15, 0.3, (0, yb - 0.12, 0), "Z", verts=18, m="M_DarkGrey", bevel=0.02)) H_.append(ucyl("shank", 0.045, 0.16, (0, yb - 0.52, 0), "Y", verts=10, m="M_Metal")) H_.append(ucyl("swivel", 0.075, 0.05, (0, yb - 0.47, 0), "Y", verts=12, m="M_DarkGrey")) hk = [(0, yb - 0.58, 0), (0, yb - 0.72, 0), (-0.03, yb - 0.86, 0), (0.07, yb - 0.97, 0), (0.18, yb - 0.92, 0), (0.2, yb - 0.8, 0)] H_.append(utube("hook", hk, 0.05, "M_PaintRed", res=6, segs=10)) H_.append(utube("latch", [(0.02, yb - 0.64, 0), (0.19, yb - 0.78, 0)], 0.012, "M_Metal", res=1, segs=4)) for o in H_[4:]: apply_xform(o) piv = Vector(B(0, yb, 0)) for v in o.data.vertices: v.co = piv + (v.co - piv) * 1.4 hko = fin(H_, "Hook", haz=3.0) set_origin(hko, B(0, top, 0)) return dict(elev=-12, azim=-30) # ======================================================================= 8. SM_WH_Fan def fan(): H_ = [] H_.append(ubox("mount", -0.18, 0.18, -0.04, 0.0, -0.18, 0.18, "M_DarkGrey", bevel=0.01, segs=1)) for (x, z) in ((-0.13, -0.13), (0.13, -0.13), (-0.13, 0.13), (0.13, 0.13)): H_.append(ucyl("bolt", 0.015, 0.02, (x, -0.045, z), "Y", verts=6, m="M_Metal")) H_.append(ubox("yoke", -0.06, 0.06, -0.14, -0.04, -0.06, 0.06, "M_DarkGrey", bevel=0.015, segs=1)) H_.append(ucyl("rod", 0.045, 1.1, (0, -0.68, 0), "Y", verts=12, m="M_Metal")) H_.append(ucyl("collar", 0.07, 0.06, (0, -1.18, 0), "Y", verts=14, m="M_DarkGrey")) H_.append(ucyl("motor", 0.27, 0.16, (0, -1.27, 0), "Y", verts=24, m="M_PaintYellow", bevel=0.04, segs=3)) for k in range(12): a = 2 * math.pi * k / 12 H_.append(ubox("fin", -0.012, 0.012, -1.33, -1.21, -0.015, 0.015, "M_DarkGrey")) u_transform(H_[-1], a, (0.275 * math.cos(a), 0, 0.275 * math.sin(a))) H_.append(ucyl("gear", 0.2, 0.05, (0, -1.375, 0), "Y", verts=20, m="M_DarkGrey")) fin(H_, "Hub") BL = [] yc = -1.4 BL.append(ucyl("disc", 0.34, 0.05, (0, yc - 0.03, 0), "Y", verts=24, m="M_DarkGrey", bevel=0.012)) sp = usphere("spinner", 0.2, (0, yc - 0.055, 0), "M_PaintYellow", seg=16, rings=8, scale=(1, 0.55, 1)) bm = bmesh.new(); bm.from_mesh(sp.data) bmesh.ops.delete(bm, geom=[v for v in bm.verts if v.co.z > yc - 0.054], context="VERTS") bm.to_mesh(sp.data); bm.free() BL.append(sp) prof = [(-0.11, 0.0), (-0.075, 0.016), (0.0, 0.024), (0.07, 0.014), (0.11, 0.0), (0.07, -0.006), (0.0, -0.009), (-0.075, -0.006)] pitch = math.radians(8) for k in range(6): a = 2 * math.pi * k / 6 bm = bmesh.new() rings = [] for (x, droop) in ((0.3, 0.0), (1.6, 0.025), (3.0, 0.06)): ring = [] for (c, t) in prof: cc = c * math.cos(pitch) - t * math.sin(pitch) tt = c * math.sin(pitch) + t * math.cos(pitch) ring.append(bm.verts.new(B(x, yc - 0.03 + tt - droop, cc))) rings.append(ring) n = len(prof) for ra, rb in zip(rings, rings[1:]): for i in range(n): j = (i + 1) % n bm.faces.new((ra[i], ra[j], rb[j], rb[i])) bm.faces.new(rings[0]); bm.faces.new(list(reversed(rings[-1]))) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) bo = mesh_obj("blade", bm) set_mats(bo, "M_Metal") parts = [bo, ubox("clamp", 0.22, 0.5, yc - 0.065, yc + 0.005, -0.07, 0.07, "M_DarkGrey", bevel=0.012, segs=1), ubox("wing", 2.99, 3.03, yc - 0.2, yc - 0.07, -0.115, 0.115, "M_PaintYellow", bevel=0.012, segs=1)] for o in parts: u_transform(o, a) BL.append(o) bl = fin(BL, "Blades", ang=35) set_origin(bl, B(0, yc, 0)) return dict(elev=18, azim=-30) # ======================================================================= 9. SM_WH_Banner def banner(): w, y0, y1 = 1.0, -6.5, -1.5 bm = bmesh.new() uvl = bm.loops.layers.uv.verify() # front (+Z viewer: their right is -X -> U grows toward -X) zf = 0.002 vs = [bm.verts.new(B(*p)) for p in ((w, y0, zf), (-w, y0, zf), (-w, y1, zf), (w, y1, zf))] f = bm.faces.new(vs) for l, uv in zip(f.loops, ((0, 0), (1, 0), (1, 1), (0, 1))): l[uvl].uv = uv # back (-Z viewer: their right is +X -> U grows toward +X, image reads un-mirrored) zb = -0.002 vs = [bm.verts.new(B(*p)) for p in ((-w, y0, zb), (w, y0, zb), (w, y1, zb), (-w, y1, zb))] g = bm.faces.new(vs) for l, uv in zip(g.loops, ((0, 0), (1, 0), (1, 1), (0, 1))): l[uvl].uv = uv bm.normal_update() if f.normal.dot(Vector(B(0, 0, 1))) < 0: f.normal_flip() if g.normal.dot(Vector(B(0, 0, -1))) < 0: g.normal_flip() pn = mesh_obj("Panel", bm) set_mats(pn, "M_Banner") flat(pn) P = [] for (y, r) in ((y1, 0.032), (y0, 0.038)): P.append(ucyl("dowel", r, 2.16, (0, y, 0), "X", verts=12, m="M_DarkGrey")) for s in (-1, 1): P.append(ucyl("cap", r + 0.012, 0.05, (s * 1.1, y, 0), "X", verts=12, m="M_PaintYellow", bevel=0.01)) for s in (-1, 1): x = s * 0.9 P.append(ucyl("cable", 0.007, 1.5, (x, y1 / 2, 0), "Y", verts=6, m="M_Metal")) P.append(ucyl("clip", 0.04, 0.03, (x, -0.015, 0), "Y", verts=10, m="M_DarkGrey")) P.append(ucyl("eye", 0.018, 0.06, (x, y1 + 0.04, 0), "Y", verts=8, m="M_Metal")) fin(P, "Bars") return dict(elev=5, azim=-25) # ======================================================================= 10. SM_WH_Cage def mesh_panel(P, axis, c, a0, a1, y0, y1, step=0.15, t=0.006, m="M_Metal"): """wire mesh in a vertical plane. axis 'X' -> plane z=c spanning x a0..a1; axis 'Z' -> plane x=c spanning z a0..a1.""" def box(xa, xb, ya, yb): if axis == "X": return ubox("w", xa, xb, ya, yb, c - t, c + t, m) return ubox("w", c - t, c + t, ya, yb, xa, xb, m) na = max(1, int(round((a1 - a0) / step))) for i in range(1, na): a = a0 + (a1 - a0) * i / na P.append(box(a - t, a + t, y0, y1)) ny = max(1, int(round((y1 - y0) / step))) for j in range(1, ny): y = y0 + (y1 - y0) * j / ny P.append(box(a0, a1, y - t, y + t)) def cage(): P = [] hx, H_ = 1.5, 2.5 tb = 0.025 fm = "M_PaintBlue" posts = [(-hx, -hx), (hx, -hx), (-hx, hx), (hx, hx), (0, -hx), (-hx, 0), (hx, 0), (-0.5, hx), (0.5, hx)] for (x, z) in posts: P.append(ubox("post", x - tb, x + tb, 0.0, H_, z - tb, z + tb, fm, bevel=0.006, segs=1)) P.append(ubox("foot", x - 0.06, x + 0.06, 0.0, 0.012, z - 0.06, z + 0.06, "M_DarkGrey")) for y in (0.05, H_ - tb): for s in (-1, 1): P.append(ubox("rx", -hx, hx, y - tb, y + tb, s * hx - tb, s * hx + tb, fm)) P.append(ubox("rz", s * hx - tb, s * hx + tb, y - tb, y + tb, -hx, hx, fm)) # kick plates for s in (-1, 1): P.append(ubox("kick", -hx, hx, 0.0, 0.18, s * hx - 0.012, s * hx + 0.012, "M_DarkGrey")) if s < 0 else None P.append(ubox("kick", s * hx - 0.012, s * hx + 0.012, 0.0, 0.18, -hx, hx, "M_DarkGrey")) for (a, b) in ((-hx, -0.5), (0.5, hx)): P.append(ubox("kick", a, b, 0.0, 0.18, hx - 0.012, hx + 0.012, "M_DarkGrey")) # door header P.append(ubox("header", -0.5, 0.5, 2.12, 2.17, hx - tb, hx + tb, fm)) # mesh panels y0, y1 = 0.18, H_ - tb mesh_panel(P, "X", -hx, -hx, 0, y0, y1) mesh_panel(P, "X", -hx, 0, hx, y0, y1) for s in (-1, 1): mesh_panel(P, "Z", s * hx, -hx, 0, y0, y1) mesh_panel(P, "Z", s * hx, 0, hx, y0, y1) mesh_panel(P, "X", hx, -hx, -0.5, y0, y1) mesh_panel(P, "X", hx, 0.5, hx, y0, y1) mesh_panel(P, "X", hx, -0.5, 0.5, 2.17, y1, step=0.15) # roof mesh n = 20 for i in range(1, n): a = -hx + 2 * hx * i / n P.append(ubox("rf", a - 0.006, a + 0.006, H_ - 0.012, H_, -hx, hx, "M_Metal")) P.append(ubox("rf", -hx, hx, H_ - 0.024, H_ - 0.012, a - 0.006, a + 0.006, "M_Metal")) P.append(ubox("sign", 0.7, 1.3, 1.5, 1.8, hx + 0.012, hx + 0.02, "M_PaintYellow", bevel=0.006, segs=1)) P.append(ubox("signt", 0.76, 1.24, 1.6, 1.7, hx + 0.019, hx + 0.023, "M_DarkGrey")) fin(P, "Cage") # Door (hinge at x = -0.5, z = 1.5) D = [] dz = hx + 0.035 x0, x1, dy0, dy1 = -0.49, 0.49, 0.03, 2.1 for (a, b, c, d) in ((x0, x0 + 0.04, dy0, dy1), (x1 - 0.04, x1, dy0, dy1), (x0, x1, dy0, dy0 + 0.04), (x0, x1, dy1 - 0.04, dy1), (x0, x1, 1.0, 1.04)): D.append(ubox("df", a, b, c, d, dz - 0.018, dz + 0.018, fm, bevel=0.005, segs=1)) mesh_panel(D, "X", dz, x0 + 0.04, x1 - 0.04, dy0 + 0.04, dy1 - 0.04) for y in (0.3, 1.8): D.append(ucyl("hinge", 0.022, 0.12, (-0.5, y, dz), "Y", verts=8, m="M_Metal")) D.append(ubox("handle", 0.36, 0.4, 0.95, 1.1, dz + 0.02, dz + 0.06, "M_PaintYellow", bevel=0.01, segs=1)) D.append(ubox("lock", 0.32, 0.4, 0.86, 0.94, dz + 0.02, dz + 0.05, "M_PaintRed", bevel=0.01, segs=1)) do = fin(D, "Door") set_origin(do, B(-0.5, 0, dz)) return dict(elev=20, azim=-30) # ======================================================================= 11. SM_WH_Duct def duct(): P = [] R, L = 0.4, 4.0 body = ucyl("body", R, L - 0.12, (0, 0, 0), "X", verts=24, m="M_Metal") P.append(body) for s in (-1, 1): P.append(ucyl("coupling", R + 0.018, 0.08, (s * (L / 2 - 0.04), 0, 0), "X", verts=24, m="M_Metal", bevel=0.008)) P.append(ucyl("rim", R - 0.04, 0.005, (s * (L / 2 - 0.0025), 0, 0), "X", verts=24, m="M_DarkGrey")) # spiral lock-seam: exact helix swept with a small diamond section pitch, perturn = 0.32, 20 nP = int((L - 0.2) / pitch * perturn) sec = [(0.016, 0.0), (0.0, 0.013), (-0.006, 0.0), (0.0, -0.013)] # (radial, along X) bm = bmesh.new() rings = [] for i in range(nP + 1): a = 2 * math.pi * i / perturn x = -L / 2 + 0.1 + pitch * i / perturn cy, cz = math.sin(a), math.cos(a) rings.append([bm.verts.new(B(x + dx, (R + dr) * cy, (R + dr) * cz)) for (dr, dx) in sec]) for ra, rb in zip(rings, rings[1:]): for k in range(4): j = (k + 1) % 4 bm.faces.new((ra[k], ra[j], rb[j], rb[k])) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) seam = mesh_obj("seam", bm) set_mats(seam, "M_Metal") P.append(seam) for x in (-1.2, 1.2): P.append(ucyl("band", R + 0.012, 0.05, (x, 0, 0), "X", verts=24, m="M_DarkGrey", cap=False)) for s in (-1, 1): P.append(ubox("strap", x - 0.025, x + 0.025, 0.0, 1.4, min(s * (R + 0.008), s * (R + 0.016)), max(s * (R + 0.008), s * (R + 0.016)), "M_DarkGrey")) P.append(ubox("tbar", x - 0.03, x + 0.03, 1.36, 1.4, -R - 0.04, R + 0.04, "M_DarkGrey")) P.append(ucyl("rod", 0.012, 0.1, (x, 1.45, 0), "Y", verts=6, m="M_Metal")) P.append(ubox("clip", x - 0.06, x + 0.06, 1.48, 1.5, -0.06, 0.06, "M_DarkGrey")) fin(P, "SM_WH_Duct", ang=45) return dict(elev=20, azim=-30) # ======================================================================= 12. SM_WH_Bollard def bollard(): P = [] r = 0.08 P.append(ubox("plate", -0.15, 0.15, 0.0, 0.02, -0.15, 0.15, "M_DarkGrey", bevel=0.01, segs=1)) for (x, z) in ((-0.11, -0.11), (0.11, -0.11), (-0.11, 0.11), (0.11, 0.11)): P.append(ucyl("bolt", 0.014, 0.03, (x, 0.03, z), "Y", verts=6, m="M_Metal")) P.append(ucyl("weld", r + 0.012, 0.03, (0, 0.035, 0), "Y", verts=20, m="M_DarkGrey")) P.append(ucyl("pipe", r, 1.03, (0, 0.02 + 1.03 / 2, 0), "Y", verts=20, m="M_PaintYellow")) dome = usphere("dome", r, (0, 1.05, 0), "M_PaintYellow", seg=20, rings=10, scale=(1, 0.6, 1)) bm = bmesh.new(); bm.from_mesh(dome.data) bmesh.ops.delete(bm, geom=[v for v in bm.verts if v.co.z < 1.05 - 1e-4], context="VERTS") bm.to_mesh(dome.data); bm.free() P.append(dome) for (a, b) in ((0.72, 0.8), (0.88, 0.96)): P.append(ucyl("band", r + 0.003, b - a, (0, (a + b) / 2, 0), "Y", verts=20, m="M_Rubber", cap=False)) fin(P, "SM_WH_Bollard", ang=50) return dict(elev=15, azim=-30) # ======================================================================= chain test (not exported) def chain_test(): reset() placed = set() def place(fn, ang, t, hide=()): fn() for o in list(bpy.context.scene.objects): if o.name in placed or o.type != "MESH": continue if any(o.name.startswith(h) for h in hide): bpy.data.objects.remove(o) continue u_transform(o, ang, t) o.name = "c_" + o.name placed.add(o.name) place(belt, 0, (0, 0, 0), hide=("EndOut",)) place(belt, 0, (0, 0, 1), hide=("EndIn", "EndOut")) place(belt_turn, 0, (0, 0, 2), hide=("EndIn", "EndOut")) place(belt, -math.pi / 2, (1, 0, 2), hide=("EndIn",)) place(belt_sorter, 0, (-1.4, 0, 0.5)) place(belt_splitter, 0, (-1.4, 0, 2.2)) preview("_v3_chain", elev=38, azim=-45) preview("_v3_chain_close", elev=30, azim=-60, target=B(0.2, 0.35, 1.5), radius=0.9) preview("_v3_chain_low", elev=8, azim=-100, target=B(0.0, 0.3, 1.0), radius=1.0) if __name__ == "__main__": args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] if "_chain" in args: args.remove("_chain") chain_test() if not args: sys.exit(0) sys.argv = sys.argv[:sys.argv.index("--") + 1] + args run({ "SM_Belt": belt, "SM_BeltTurn": belt_turn, "SM_BeltSplitter": belt_splitter, "SM_BeltSorter": belt_sorter, "SM_WH_Mezzanine": mezzanine, "SM_WH_Stairs": stairs, "SM_WH_Crane": crane, "SM_WH_Fan": fan, "SM_WH_Banner": banner, "SM_WH_Cage": cage, "SM_WH_Duct": duct, "SM_WH_Bollard": bollard, })