"""GRASS CUTTER - vending machines, what comes out of them, and the hands that hold it. SM_VendBeer retro "GRASS BEER" machine, 1.05 x 0.85 x 2.15 m, bottle green with cream and brass. Body plus Sign the arched backlit picture panel (slot 0 M_LightGreen, also M_LightAmber, M_Emissive, M_PaintDarkGreen) Hopper grass funnel on the upper right of the front, origin at the centre of its mouth (-0.30, -0.56, 1.80) Display little screen, origin at its centre (-0.30, -0.4435, 1.48) Button big red button, origin at its centre (-0.30, -0.456, 1.27), pushes in along +Y Tray the flap over the dispense opening, origin on its hinge (0.15, -0.413, 0.555), hinge axis X DropPoint empty on the floor of the dispense pocket (0.15, -0.31, 0.31) SM_VendSmoke wooden "HERB CIGARS" cabinet, 0.95 x 0.6 x 1.9 m (ashtray out to x = -0.67). Body plus Sign (round plaque on top, M_LightAmber), Glass, Knob0..Knob3 (Knob0 at Blender +X = the viewer's left), Drawer (origin at its front centre, slides out along -Y), DropPoint (in the drawer pulled out 0.25 m) SM_BeerCan 0.066 x 0.12 m can, origin at its centre, axis Blender Z. Body, Tab (origin on its rivet) SM_BeerCanCrushed the can squashed, origin at its centre. Body, Tab SM_Cigar 0.14 m cigar along Blender Y, origin at its centre. Body, Ember (origin at the lit tip, y = -0.07) SM_HandCan right hand round the can, in the can's frame. Hand, Can (with child Tab) SM_HandCigar right hand with the cigar between index and middle finger, in the cigar's frame, cigar along +X (Unity -X, the viewer's left). Hand, Cigar (rotated 90 deg about Z so its local frame is SM_Cigar's), Ember (child of Cigar, at the +X tip) The hands are built for a viewer at +Y looking along -Y (Unity camera looking along +Z, as SM_PhoneHand), arm down and to the right (Blender -X). Skin M_CrewSkin, sleeve M_PaintRed, which the game recolours per player. Unless a line above says otherwise: origin bottom centre at z = 0, front = -Y (Unity +Z), Unity +X = Blender -X. Run (one at a time, absolute paths): blender -b --factory-startup --python D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_vend.py -- [names] python -I D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_vend.py --contact (contact sheet) """ import sys, os, zlib, math HERE = os.path.dirname(os.path.abspath(__file__)) PREV = os.path.normpath(os.path.join(HERE, "..", "..", "Previews")) NAMES = ["SM_VendBeer", "SM_VendSmoke", "SM_BeerCan", "SM_BeerCanCrushed", "SM_Cigar", "SM_HandCan", "SM_HandCigar"] def contact_sheet(): from PIL import Image, ImageDraw cells = [] for n in NAMES: for tag in ("", "_back", "_close", "_side", "_view", "_front"): p = os.path.join(PREV, n + tag + ".png") if os.path.exists(p) and len([c for c in cells if c[0] == n]) < 3: cells.append((n, tag, p)) S, cols = 300, 6 rows = (len(cells) + cols - 1) // cols sheet = Image.new("RGB", (cols * S, rows * (S + 22)), (40, 44, 50)) d = ImageDraw.Draw(sheet) for i, (n, tag, p) in enumerate(cells): im = Image.open(p).convert("RGB").resize((S, S)) x, y = (i % cols) * S, (i // cols) * (S + 22) sheet.paste(im, (x, y + 22)) d.text((x + 6, y + 5), n + tag, fill=(235, 235, 220)) out = os.path.join(PREV, "vend_contact.png") sheet.save(out) print("contact sheet:", out, len(cells), "cells") if __name__ == "__main__" and "--contact" in sys.argv: contact_sheet() sys.exit(0) sys.path.insert(0, HERE) import random import common from gc_up_machines import * # noqa: F401,F403 (loft, px/py/pz, revm, cz/cx/cy, cyl_between, ptube, xf, soft, helpers) import gc_up_machines as UM import gc_up_kit as K from gc_up_kit import plain, nut import gc_farm_tools as FT import bpy, bmesh from mathutils import Matrix, Vector GREEN, CREAM, BRASS, DARK, STEEL = "M_PaintDarkGreen", "M_PaintCream", "M_Brass", "M_Soot", "M_Steel" RUBBER, REDP, TIMB, GLASS, LEAFG = "M_Rubber", "M_PaintRed", "M_Timber", "M_PackGlass", "M_PaintGreen" GLOW_G, GLOW_A, GLOW_W, SCREEN, EMBER = "M_LightGreen", "M_LightAmber", "M_Emissive", "M_Screen", "M_Ember" WRAP, WRAP2, WRAPD, GOLDM, FELT = "M_Leather", "M_Bark", "M_Patty", "M_Gold", "M_ClothRed" ASH, CHAR, CLIPS, SKIN, SLEEVE = "M_Concrete", "M_Charcoal", "M_GrassFill", "M_CrewSkin", "M_PaintRed" TAU = 2 * math.pi # ======================================================================= flat shapes and small helpers def rr2(cx, cy, w, h, r, n=3): """Rounded rectangle, counter-clockwise (a, b) points.""" x0, x1, y0, y1 = cx - w / 2, cx + w / 2, cy - h / 2, cy + h / 2 r = min(r, w / 2 - 1e-4, h / 2 - 1e-4) pts = [] for (ax, ay, a0) in ((x1 - r, y0 + r, -90), (x1 - r, y1 - r, 0), (x0 + r, y1 - r, 90), (x0 + r, y0 + r, 180)): for i in range(n + 1): a = math.radians(a0 + 90 * i / n) pts.append((ax + r * math.cos(a), ay + r * math.sin(a))) return pts def circ2(cx, cy, r, n=14, sx=1.0): return [(cx + r * sx * math.cos(TAU * i / n), cy + r * math.sin(TAU * i / n)) for i in range(n)] def arch2(x0, x1, z0, zs, rb=0.04, n_arc=16, n_c=3): """Round-topped panel outline: square bottom with rounded corners, a half circle on top (counter-clockwise in x, z).""" cx, R = (x0 + x1) / 2, (x1 - x0) / 2 pts = [] for i in range(n_c + 1): a = math.radians(180 + 90 * i / n_c) pts.append((x0 + rb + rb * math.cos(a), z0 + rb + rb * math.sin(a))) for i in range(n_c + 1): a = math.radians(270 + 90 * i / n_c) pts.append((x1 - rb + rb * math.cos(a), z0 + rb + rb * math.sin(a))) for i in range(n_arc + 1): a = math.pi * i / n_arc pts.append((cx + R * math.cos(a), zs + R * math.sin(a))) return pts def inside2(p, poly): x, y = p c = False n = len(poly) for i in range(n): x0, y0 = poly[i] x1, y1 = poly[(i + 1) % n] if (y0 > y) != (y1 > y) and x < x0 + (y - y0) * (x1 - x0) / (y1 - y0): c = not c return c def poly_obj(name, pts3, m, want): """One flat polygon (triangulated by ear clipping, so concave outlines survive Unity) facing `want`.""" bm = bmesh.new() vs = [bm.verts.new(p) for p in pts3] f = bm.faces.new(vs) bm.normal_update() if f.normal.dot(Vector(want)) < 0: f.normal_flip() if len(vs) > 4: bmesh.ops.triangulate(bm, faces=[f], quad_method="BEAUTY", ngon_method="EAR_CLIP") o = mesh_obj(name, bm) set_mats(o, m) return uv_wall(o) def strip_obj(name, pairs3, m, want): """Quads between consecutive (left, right) point pairs - a leaf, a ribbon - facing `want`.""" bm = bmesh.new() V = [(bm.verts.new(a), bm.verts.new(b)) for a, b in pairs3] for (a0, b0), (a1, b1) in zip(V, V[1:]): f = bm.faces.new((a0, b0, b1, a1)) bm.normal_update() if f.normal.dot(Vector(want)) < 0: f.normal_flip() bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-6) o = mesh_obj(name, bm) set_mats(o, m) return uv_wall(o) def ring_obj(name, c, r0, r1, m, plane, want, n=16, a0=0.0, a1=TAU): """Flat annulus (or a sector of one) in 2-D centre c, mapped to 3-D by plane(a, b).""" full = abs(a1 - a0) >= TAU - 1e-6 k = n if full else n + 1 pairs = [] for i in range(k + (1 if full else 0)): a = a0 + (a1 - a0) * (i % n if full else i) / n ca, sa = math.cos(a), math.sin(a) pairs.append((plane(c[0] + r0 * ca, c[1] + r0 * sa), plane(c[0] + r1 * ca, c[1] + r1 * sa))) return strip_obj(name, pairs, m, want) def leaf_pairs(base, L, W, ang, n=8, bend=0.12): d = Vector((math.cos(ang), math.sin(ang))) s = Vector((-d.y, d.x)) out = [] for i in range(n + 1): t = i / n c = Vector(base) + d * (L * t) + s * (bend * L * t * t) w = max(W * math.sin(math.pi * t) ** 0.75 * (1 - 0.3 * t), 0.0004 * (W / 0.02)) out.append((tuple(c - s * w), tuple(c + s * w))) return out def leaf_on(P, plane, want, base, L, W, ang, m, rib=None, n=8, name="leaf", bend=0.12): P.append(strip_obj(name, [(plane(*a), plane(*b)) for a, b in leaf_pairs(base, L, W, ang, n, bend)], m, want)) if rib: pr = leaf_pairs(base, L * 0.82, W * 0.12, ang, 5, bend * 0.8) P.append(strip_obj("rib", [(plane(*a), plane(*b)) for a, b in pr], rib, want)) def flat_on(P, plane, want, pts2, m, name="flat"): o = poly_obj(name, [plane(a, b) for a, b in pts2], m, want) P.append(o) return o def loop_tube(name, pts2, plane, nrm, r, m, segs=6): """Round tube along a closed outline drawn in one plane (pts2 mapped by plane, nrm the plane normal).""" nrm = Vector(nrm).normalized() Pp = [Vector(plane(a, b)) for a, b in pts2] n = len(Pp) bm = bmesh.new() rings = [] for i in range(n): t = (Pp[(i + 1) % n] - Pp[i - 1]).normalized() q = t.cross(nrm).normalized() rings.append([bm.verts.new(Pp[i] + (q * math.cos(TAU * k / segs) + nrm * math.sin(TAU * k / segs)) * r) for k in range(segs)]) for i in range(n): a, b = rings[i], rings[(i + 1) % n] for k in range(segs): bm.faces.new((a[k], a[(k + 1) % segs], b[(k + 1) % segs], b[k])) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return o def cut(o, cutter): md = o.modifiers.new("cut", "BOOLEAN") md.operation = "DIFFERENCE" md.object = cutter try: md.solver = "EXACT" except Exception: pass bake(o) d = cutter.data bpy.data.objects.remove(cutter) bpy.data.meshes.remove(d) return o def paint(o, m, test): names = [x.name for x in o.data.materials] if m not in names: o.data.materials.append(mat(m)) names.append(m) k = names.index(m) for p in o.data.polygons: if test(Vector(p.center), Vector(p.normal)): p.material_index = k def scale_about(o, c, s): c = Vector(c) for v in o.data.vertices: v.co = c + Vector(((v.co - c).x * s[0], (v.co - c).y * s[1], (v.co - c).z * s[2])) o.data.update() return o def rot_x(o, deg, t=(0, 0, 0)): return xf(o, rx=math.radians(deg), t=t) def tri_all(o): """Triangulate ngons (Unity would fan concave ones the wrong way).""" bm = bmesh.new() bm.from_mesh(o.data) ng = [f for f in bm.faces if len(f.verts) > 4] if ng: bmesh.ops.triangulate(bm, faces=ng, quad_method="BEAUTY", ngon_method="EAR_CLIP") bm.to_mesh(o.data) bm.free() return o def fin(P, name, origin=None, ang=38, wn=True): o = K.ffin(P, name, ang=ang, wn=wn) tri_all(o) if origin is not None: set_origin(o, origin) return o def name_it(o, name): o.name = name o.data.name = name return o # ======================================================================= SM_VendBeer BW, BD = 1.05, 0.85 FY = -BD / 2 # the front face XC = -0.30 # the right-hand column (viewer's right is Blender -X) SIGN = arch2(-0.12, 0.42, 0.80, 1.60, rb=0.045) SCX = 0.15 # sign centre x TRAY = (-0.08, 0.38, 0.30, 0.56) # dispense opening x0 x1 z0 z1 HOP = Vector((XC, -0.56, 1.80)) # hopper mouth centre HOP_TILT = 25.0 def fr(a, b): return (a, FY, b) def cab_ring(w, d, r, z, n=3): return [(x, y, z) for x, y in rr2(0, 0, w, d, r, n)] def beer_sign(): S = [] Y0 = FY + 0.0295 lay = lambda k: (lambda a, b: (a, Y0 - 0.0013 * k, b)) want = (0, -1, 0) flat_on(S, lay(0), want, SIGN, GLOW_G, "signbg") # sunburst: cream rays from behind the mug, clipped to the arch c = Vector((SCX, 1.27)) n = 16 for i in range(n): if i % 2: continue a0, a1 = TAU * (i - 0.42) / n + 0.1, TAU * (i + 0.42) / n + 0.1 pts = [tuple(c)] for a in (a0, (a0 + a1) / 2, a1): d = Vector((math.cos(a), math.sin(a))) lo, hi = 0.0, 1.2 for _ in range(24): mid = (lo + hi) / 2 if inside2(tuple(c + d * mid), SIGN): lo = mid else: hi = mid pts.append(tuple(c + d * (lo - 0.022))) flat_on(S, lay(1), want, pts, GLOW_W, "ray") # grass along the bottom of the panel flat_on(S, lay(2), want, [(-0.105, 0.815), (0.405, 0.815), (0.405, 0.86), (-0.105, 0.86)], GREEN, "turf") rng = random.Random(5) x = -0.1 while x < 0.39: h = rng.uniform(0.05, 0.11) lean = rng.uniform(-0.025, 0.025) flat_on(S, lay(2), want, [(x, 0.85), (x + 0.03, 0.85), (x + 0.015 + lean, 0.85 + h)], GREEN, "blade") x += rng.uniform(0.022, 0.034) # the mug: dark outline, handle, amber beer mx0, mx1, mz0, mz1 = SCX - 0.125, SCX + 0.125, 0.98, 1.36 flat_on(S, lay(3), want, rr2((mx0 + mx1) / 2, (mz0 + mz1) / 2, mx1 - mx0 + 0.03, mz1 - mz0 + 0.03, 0.05, 3), GREEN, "mugline") hc = (mx0 - 0.005, 1.18) S.append(ring_obj("handleline", hc, 0.042, 0.092, GREEN, lay(3), want, n=16, a0=math.pi / 2 - 0.15, a1=1.5 * math.pi + 0.15)) S.append(ring_obj("handle", hc, 0.056, 0.078, GLOW_A, lay(4), want, n=16, a0=math.pi / 2 - 0.05, a1=1.5 * math.pi + 0.05)) flat_on(S, lay(5), want, rr2((mx0 + mx1) / 2, (mz0 + mz1) / 2, mx1 - mx0, mz1 - mz0, 0.04, 3), GLOW_A, "mug") # glass ridges on the mug, bubbles, the leaf logo for xx in (mx0 + 0.055, mx0 + 0.125, mx0 + 0.195): flat_on(S, lay(6), want, rr2(xx, 1.13, 0.012, 0.2, 0.005, 2), GLOW_W, "ridge") for (bx_, bz_, br) in ((0.09, 1.04, 0.011), (0.12, 1.1, 0.008), (0.235, 1.06, 0.013), (0.21, 1.22, 0.009), (0.085, 1.27, 0.007), (0.245, 1.17, 0.006)): flat_on(S, lay(6), want, circ2(bx_, bz_, br, 10), GLOW_W, "bubble") leaf_on(S, lay(7), want, (SCX - 0.035, 1.07), 0.15, 0.04, math.radians(62), GREEN, rib=GLOW_A, n=9, bend=0.1) leaf_on(S, lay(7), want, (SCX - 0.03, 1.075), 0.1, 0.028, math.radians(118), GREEN, rib=GLOW_A, n=8, bend=-0.12) # foam heaped over the rim, with a drip down the side foam = [(-0.11, 1.37, 0.045), (-0.06, 1.405, 0.055), (0.005, 1.425, 0.06), (0.07, 1.41, 0.055), (0.115, 1.38, 0.045), (0.125, 1.34, 0.03), (-0.125, 1.34, 0.03)] for (dx, z, r) in foam: flat_on(S, lay(8), want, circ2(SCX + dx, z, r + 0.013, 16), GREEN, "foamline") flat_on(S, lay(8), want, rr2(SCX + 0.1, 1.29, 0.05, 0.12, 0.024, 3), GREEN, "dripline") for (dx, z, r) in foam: flat_on(S, lay(9), want, circ2(SCX + dx, z, r, 16), GLOW_W, "foam") flat_on(S, lay(9), want, rr2(SCX + 0.1, 1.29, 0.026, 0.096, 0.012, 3), GLOW_W, "drip") flat_on(S, lay(9), want, [(SCX - 0.125, 1.33), (SCX + 0.125, 1.33), (SCX + 0.125, 1.37), (SCX - 0.125, 1.37)], GLOW_W, "foamband") # a ribbon across the top of the arch (no lettering) rz0, rz1 = 1.6, 1.7 rib = [(-0.09, rz0 - 0.02), (-0.06, (rz0 + rz1) / 2 - 0.01), (-0.09, rz1 - 0.02), (-0.04, rz1 - 0.005), (SCX, rz1 + 0.02), (0.34, rz1 - 0.005), (0.39, rz1 - 0.02), (0.36, (rz0 + rz1) / 2 - 0.01), (0.39, rz0 - 0.02), (0.34, rz0 - 0.005), (SCX, rz0 + 0.02), (-0.04, rz0 - 0.005)] flat_on(S, lay(10), want, rib, GREEN, "ribbon") for k in range(7): flat_on(S, lay(11), want, circ2(-0.02 + k * 0.0283 * 1.45, (rz0 + rz1) / 2 + 0.012 - 0.012 * abs(k - 3) / 3 * 0.6, 0.011, 10), GLOW_A, "dot") o = fin(S, "Sign", wn=False) flat(o) set_origin(o, (SCX, Y0, 1.3)) return o def hopper(): H = [] prof = [(0.05, -0.2), (0.052, -0.17), (0.082, -0.1), (0.098, -0.062), (0.12, -0.012), (0.128, -0.005), (0.131, 0.004), (0.123, 0.009), (0.114, 0.0), (0.044, -0.165), (0.042, -0.2)] mats = [STEEL, STEEL, CREAM, STEEL, BRASS, BRASS, BRASS, BRASS, STEEL, STEEL, STEEL] H.append(revm("funnel", prof, mats, segs=20, closed=True)) # a wad of clippings stuffed down the throat, a few blades sticking up rng = random.Random(9) for k in range(6): a = TAU * k / 6 + rng.uniform(-0.3, 0.3) H.append(sphere("wad", 1.0, (0.022 * math.cos(a), 0.022 * math.sin(a), -0.125 + rng.uniform(-0.01, 0.01)), seg=8, rings=5, m=CLIPS, scale=(0.028, 0.028, 0.018))) for k in range(7): a = TAU * k / 7 + rng.uniform(-0.2, 0.2) b = Vector((0.03 * math.cos(a), 0.03 * math.sin(a), -0.12)) tip = b + Vector((0.025 * math.cos(a) + rng.uniform(-0.01, 0.01), 0.025 * math.sin(a), rng.uniform(0.05, 0.08))) side = Vector((-math.sin(a), math.cos(a), 0)) * 0.006 H.append(poly_obj("clip", [tuple(b - side), tuple(b + side), tuple(tip)], "M_Leaf", Vector((math.cos(a), math.sin(a), 0.2)))) H.append(poly_obj("clip", [tuple(b - side), tuple(b + side), tuple(tip)], "M_Leaf", -Vector((math.cos(a), math.sin(a), 0.2)))) for o in H: rot_x(o, HOP_TILT, tuple(HOP)) return fin(H, "Hopper", origin=tuple(HOP), ang=50) def vend_beer(): P = [] # ---- cabinet: rounded green box, cream skirt and crown, dark plinth, brass bun feet cab = UM.loft([cab_ring(BW - 0.03, BD - 0.03, 0.085, 0.14), cab_ring(BW, BD, 0.1, 0.165), cab_ring(BW, BD, 0.1, 1.985), cab_ring(BW - 0.02, BD - 0.02, 0.09, 2.0)], GREEN, name="cab") cut(cab, UM.py(SIGN, FY - 0.1, FY + 0.03, DARK, name="signcut")) cut(cab, plain(TRAY[0], TRAY[1], FY - 0.1, -0.2, TRAY[2], TRAY[3], DARK, "traycut")) paint(cab, DARK, lambda c, n: c.y > FY + 0.002 and TRAY[0] - 0.01 < c.x < TRAY[1] + 0.01 and TRAY[2] - 0.01 < c.z < TRAY[3] + 0.01) paint(cab, CREAM, lambda c, n: c.y > FY + 0.002 and c.z > 0.79 and c.y < FY + 0.031 and abs(n.y) < 0.5) uv_wall(cab) P.append(cab) P.append(UM.loft([cab_ring(BW - 0.05, BD - 0.05, 0.075, 0.04), cab_ring(BW - 0.05, BD - 0.05, 0.075, 0.145)], DARK, name="plinth")) for sx in (-1, 1): for sy in (-1, 1): P.append(revm("foot", [(0.0, 0.0), (0.04, 0.0), (0.05, 0.014), (0.046, 0.03), (0.034, 0.042), (0.0, 0.045)], BRASS, segs=12, loc=(sx * 0.4, sy * 0.3, 0))) P.append(UM.loft([cab_ring(BW + 0.012, BD + 0.012, 0.106, 0.165), cab_ring(BW + 0.012, BD + 0.012, 0.106, 0.255)], CREAM, name="skirt")) P.append(UM.loft([cab_ring(BW + 0.018, BD + 0.018, 0.109, 0.255), cab_ring(BW + 0.018, BD + 0.018, 0.109, 0.27)], BRASS, name="skirtline")) P.append(UM.loft([cab_ring(BW + 0.014, BD + 0.014, 0.107, 1.955), cab_ring(BW + 0.014, BD + 0.014, 0.107, 1.975)], BRASS, name="crownline")) P.append(UM.loft([cab_ring(BW + 0.02, BD + 0.02, 0.11, 1.975), cab_ring(BW + 0.04, BD + 0.04, 0.12, 1.995), cab_ring(BW + 0.04, BD + 0.04, 0.12, 2.07), cab_ring(BW + 0.012, BD + 0.012, 0.106, 2.115), cab_ring(BW - 0.07, BD - 0.07, 0.07, 2.15)], CREAM, name="crown")) # a row of amber bulbs along the front of the crown for k in range(7): P.append(sphere("bulb", 0.017, (-0.36 + k * 0.12, -(BD + 0.04) / 2 + 0.004, 2.033), seg=10, rings=5, m=GLOW_A)) P.append(cyl_between("bulbcup", (-0.36 + k * 0.12, -(BD + 0.04) / 2 + 0.006, 2.033), (-0.36 + k * 0.12, -(BD + 0.04) / 2 - 0.004, 2.033), 0.022, BRASS, v=10)) # brass bolts on the skirt and under the crown for x in (-0.42, -0.14, 0.14, 0.42): nut(P, (x, -(BD + 0.012) / 2, 0.21), (0, -1, 0), r=0.012, h=0.008, m=BRASS) for x in (-0.44, 0.44): for z in (0.4, 1.0, 1.6): nut(P, (x, FY, z), (0, -1, 0), r=0.011, h=0.008, m=BRASS) # ---- sign: cream frame round the arched recess, bolts on it P.append(loop_tube("signframe", SIGN, lambda a, b: (a, FY, b), (0, 1, 0), 0.024, CREAM, segs=8)) for (a, b) in ((-0.12, 0.85), (0.42, 0.85), (-0.12, 1.55), (0.42, 1.55), (SCX, 1.87)): nut(P, (a, FY - 0.02, b), (0, -1, 0), r=0.009, h=0.007, m=BRASS) sign = beer_sign() # ---- brass badge between the tray and the sign: an oval plate with a leaf bdg = cyl_between("badge", (SCX, FY + 0.004, 0.68), (SCX, FY - 0.01, 0.68), 0.06, BRASS, v=20, bev=0.003) scale_about(bdg, (SCX, 0, 0.68), (1.7, 1, 1)) P.append(bdg) pl = lambda a, b: (a, FY - 0.0105, b) leaf_on(P, pl, (0, -1, 0), (SCX - 0.05, 0.665), 0.1, 0.02, math.radians(14), GREEN, n=7, bend=0.15) leaf_on(P, pl, (0, -1, 0), (SCX - 0.05, 0.665), 0.07, 0.016, math.radians(52), GREEN, n=6, bend=-0.1) # ---- dispense pocket: brass rim, steel floor with ribs; the flap is the Tray tr = rr2((TRAY[0] + TRAY[1]) / 2, (TRAY[2] + TRAY[3]) / 2, TRAY[1] - TRAY[0], TRAY[3] - TRAY[2], 0.035, 3) P.append(loop_tube("trayrim", tr, lambda a, b: (a, FY - 0.004, b), (0, 1, 0), 0.02, BRASS, segs=8)) P.append(plain(TRAY[0], TRAY[1], FY + 0.002, -0.2, TRAY[2], TRAY[2] + 0.01, STEEL, "trayfloor")) for k in range(5): y = FY + 0.03 + k * 0.038 P.append(plain(TRAY[0] + 0.01, TRAY[1] - 0.01, y, y + 0.012, TRAY[2] + 0.01, TRAY[2] + 0.016, RUBBER, "rib")) # ---- right column: hopper (child) through a cream collar, display, button, coin slot, coin cup, louvres thr = HOP + Matrix.Rotation(math.radians(HOP_TILT), 3, "X") @ Vector((0, 0, -0.19)) P.append(cyl_between("throat", tuple(thr), (XC, FY + 0.03, thr.z - 0.03), 0.056, STEEL, v=16)) P.append(cyl_between("collar", (XC, FY + 0.004, thr.z - 0.026), (XC, FY - 0.018, thr.z - 0.028), 0.078, CREAM, v=18, bev=0.006)) for k in range(6): a = TAU * k / 6 + 0.3 nut(P, (XC + 0.064 * math.cos(a), FY - 0.018, thr.z - 0.028 + 0.064 * math.sin(a)), (0, -1, 0), r=0.007, h=0.005, m=BRASS) hop = hopper() # display bezel and screen P.append(bx(XC - 0.115, XC + 0.115, FY - 0.016, FY + 0.006, 1.41, 1.55, BRASS, bev=0.012, segs=2, name="bezel")) P.append(plain(XC - 0.095, XC + 0.095, FY - 0.0175, FY - 0.01, 1.43, 1.53, DARK, "bezelin")) for sx in (-1, 1): for z in (1.425, 1.535): nut(P, (XC + sx * 0.104, FY - 0.016, z), (0, -1, 0), r=0.006, h=0.004, m=STEEL) disp = plain(XC - 0.085, XC + 0.085, FY - 0.0195, FY - 0.0175, 1.44, 1.52, SCREEN, "Display") uv_box(disp, 4.0) disp = fin([disp], "Display", origin=(XC, FY - 0.0185, 1.48), wn=False) # button: brass cup bezel, red domed cap (the Button) bz = 1.27 bez = revm("btnbezel", [(0.06, 0.0), (0.092, 0.0), (0.095, 0.012), (0.088, 0.026), (0.066, 0.03), (0.06, 0.024)], BRASS, segs=24, closed=True) P.append(rot_x(bez, 90, (XC, FY, bz))) P.append(cyl_between("btnwell", (XC, FY + 0.002, bz), (XC, FY - 0.02, bz), 0.062, DARK, v=20)) cap = revm("cap", [(0.0, 0.0), (0.056, 0.0), (0.056, 0.03), (0.051, 0.043), (0.033, 0.051), (0.0, 0.054)], REDP, segs=24) rot_x(cap, 90, (XC, FY - 0.004, bz)) gl = poly_obj("glint", [(XC + 0.02 + 0.012 * math.cos(a), FY - 0.0575, bz + 0.022 + 0.007 * math.sin(a)) for a in [TAU * i / 8 for i in range(8)]], CREAM, (0, -1, 0)) btn = fin([cap, gl], "Button", origin=(XC, FY - 0.031, bz), ang=50) # coin slot plate, coin cup P.append(bx(XC - 0.05, XC + 0.05, FY - 0.012, FY + 0.004, 1.0, 1.15, BRASS, bev=0.008, segs=2, name="coinplate")) P.append(bx(XC - 0.016, XC + 0.016, FY - 0.02, FY - 0.008, 1.03, 1.12, BRASS, bev=0.004, segs=1, name="coinlip")) P.append(plain(XC - 0.0045, XC + 0.0045, FY - 0.0215, FY - 0.019, 1.045, 1.105, DARK, "coinslot")) for z in (1.01, 1.14): nut(P, (XC, FY - 0.012, z), (0, -1, 0), r=0.006, h=0.004, m=STEEL) P.append(bx(XC - 0.05, XC + 0.05, FY - 0.05, FY + 0.004, 0.88, 0.96, BRASS, bev=0.01, segs=2, name="coincup")) P.append(plain(XC - 0.036, XC + 0.036, FY - 0.0505, FY - 0.03, 0.89, 0.945, DARK, "cupmouth")) # louvres on the column under the coin cup P.append(bx(XC - 0.1, XC + 0.1, FY - 0.006, FY + 0.004, 0.58, 0.8, DARK, bev=0.006, name="louvreplate")) for k in range(5): z = 0.6 + k * 0.042 P.append(px([(FY - 0.006, z), (FY - 0.026, z + 0.004), (FY - 0.008, z + 0.03)], XC - 0.09, XC + 0.09, GREEN, name="louvre")) # ---- sides: louvres low down and the company leaf in a cream ring for s in (-1, 1): X = s * BW / 2 side = lambda a, b, X=X, s=s, k=0: (X + s * (0.0015 + 0.001 * k), a, b) P.append(ring_obj("sidering", (0.0, 1.32), 0.16, 0.185, CREAM, lambda a, b, X=X, s=s: (X + s * 0.0015, a, b), (s, 0, 0), n=28)) sp = lambda a, b, X=X, s=s: (X + s * 0.002, a, b) leaf_on(P, sp, (s, 0, 0), (-0.075, 1.225), 0.21, 0.055, math.radians(48), CREAM, n=10, bend=0.1) leaf_on(P, lambda a, b, X=X, s=s: (X + s * 0.0028, a, b), (s, 0, 0), (-0.06, 1.24), 0.16, 0.007, math.radians(50), GREEN, n=6, bend=0.08) leaf_on(P, sp, (s, 0, 0), (-0.11, 1.19), 0.06, 0.008, math.radians(45), CREAM, n=4, bend=0.0) P.append(bx(*sorted((X - s * 0.004, X + s * 0.006)), -0.2, 0.2, 0.34, 0.6, DARK, bev=0.006, name="sidevent")) for k in range(6): z = 0.355 + k * 0.04 P.append(py([(X + s * 0.006, z), (X + s * 0.024, z + 0.004), (X + s * 0.008, z + 0.028)], -0.19, 0.19, GREEN, name="louvre")) # ---- back: a vent and the power cord down to the floor P.append(bx(-0.3, 0.3, BD / 2 - 0.004, BD / 2 + 0.006, 1.3, 1.7, DARK, bev=0.006, name="backvent")) for k in range(8): z = 1.32 + k * 0.046 P.append(px([(BD / 2 + 0.006, z), (BD / 2 + 0.024, z + 0.004), (BD / 2 + 0.008, z + 0.03)], -0.29, 0.29, GREEN, name="louvre")) door = rr2(0.0, 1.05, 0.72, 1.6, 0.06, 3) P.append(loop_tube("backdoor", door, lambda a, b: (a, BD / 2, b), (0, 1, 0), 0.012, BRASS, segs=6)) for (a, b) in ((-0.33, 0.3), (0.33, 0.3), (-0.33, 1.8), (0.33, 1.8)): nut(P, (a, BD / 2, b), (0, 1, 0), r=0.012, h=0.008, m=BRASS) P.append(cyl_between("lockboss", (-0.3, BD / 2, 1.05), (-0.3, BD / 2 + 0.014, 1.05), 0.022, BRASS, v=10)) P.append(plain(-0.304, -0.296, BD / 2 + 0.013, BD / 2 + 0.0155, 1.04, 1.06, DARK, "keyslot")) P.append(cyl_between("cordboot", (0.32, BD / 2, 0.42), (0.32, BD / 2 + 0.04, 0.42), 0.022, RUBBER, v=10)) P.append(ptube("cord", soft([(0.32, BD / 2 + 0.03, 0.42), (0.33, BD / 2 + 0.1, 0.36), (0.36, BD / 2 + 0.14, 0.05), (0.42, BD / 2 + 0.2, 0.012), (0.55, BD / 2 + 0.16, 0.012), (0.6, BD / 2 + 0.05, 0.012)], 2), 0.011, RUBBER, segs=6)) P.append(bx(0.59, 0.66, BD / 2 + 0.02, BD / 2 + 0.08, 0.0, 0.04, DARK, bev=0.008, name="plug")) # ---- top: a little brass leaf on the crown fin(P, "Body", ang=38) # ---- the Tray flap: hinged on its top edge, rubber with a brass lip and hinge barrel hz = TRAY[3] - 0.005 T = [bx(TRAY[0] + 0.012, TRAY[1] - 0.012, FY + 0.006, FY + 0.018, TRAY[2] + 0.012, hz - 0.008, RUBBER, bev=0.004, name="flap"), cx("hinge", 0.009, TRAY[0] + 0.02, TRAY[1] - 0.02, FY + 0.012, hz, BRASS, v=10), cx("lip", 0.008, TRAY[0] + 0.04, TRAY[1] - 0.04, FY + 0.005, TRAY[2] + 0.03, BRASS, v=8)] pl = lambda a, b: (a, FY + 0.0055, b) leaf_on(T, pl, (0, -1, 0), (SCX - 0.02, 0.37), 0.09, 0.02, math.radians(75), CREAM, n=6, bend=0.12) fin(T, "Tray", origin=(SCX, FY + 0.012, hz), ang=40) common.empty("DropPoint", (SCX, -0.31, TRAY[2] + 0.01)) return [("", dict(elev=14, azim=-28)), ("_back", dict(elev=18, azim=150)), ("_close", dict(elev=8, azim=-18, dist_mul=0.5, target=(0.0, -0.4, 1.35))), ("_side", dict(elev=10, azim=-90)), ("_low", dict(elev=5, azim=-12, dist_mul=0.42, target=(0.1, -0.4, 0.5)))] # ======================================================================= the cigar (shared by SM_Cigar, the cabinet and the hand) CIG_L, CIG_R = 0.14, 0.0085 FOOT = -0.0635 def cigar_simple(band, segs=6): """Display-case cigar: the same outline in a dozen rings, no seal, no ember. Built along Y like SM_Cigar.""" r = CIG_R prof = [(0.0, FOOT), (r * 0.9, FOOT), (r, FOOT + 0.002), (r, 0.0), (r, 0.03), (r + 0.0006, 0.031), (r + 0.0006, 0.047), (r, 0.048), (r, 0.056), (0.0072, 0.065), (0.0, 0.0703)] mats = [WRAPD, WRAPD, WRAP, WRAP2, WRAP, band, GOLDM, WRAP, WRAP, WRAP] o = revm("dcigar", prof, mats, segs=segs) return xf(o, rx=-math.pi / 2) def cigar_parts(segs=12, band=CREAM, lit=True, rings=1.0): """Body (and Ember) in SM_Cigar's frame: axis along Y, the lit foot at -Y. Built about Z, turned at the end.""" r = CIG_R zs = [-0.05, -0.035, -0.02, -0.005, 0.01, 0.022] if rings >= 1 else [-0.03, 0.0, 0.02] prof = [(0.0, FOOT), (0.0078, FOOT), (0.0084, FOOT + 0.0007), (r, FOOT + 0.0025)] mats = [ASH if lit else WRAPD, ASH if lit else WRAPD, ASH if lit else WRAP] for z in zs: prof.append((r, z)) mats.append(WRAP) prof += [(r, 0.029), (r + 0.0006, 0.0298), (r + 0.0006, 0.0318), (r + 0.0006, 0.0462), (r + 0.0006, 0.0482), (r, 0.049), (r, 0.055), (0.0082, 0.06), (0.0074, 0.064), (0.0058, 0.0675), (0.0033, 0.0695), (0.0, 0.0703)] mats += [WRAP, GOLDM, GOLDM, band, GOLDM, GOLDM, WRAP, WRAP, WRAP, WRAP, WRAP, WRAP] body = revm("cigar", prof, mats, segs=segs) # spiral wrap: every other turn of the leaf a shade darker me = body.data names = [m.name for m in me.materials] if WRAP2 not in names: me.materials.append(mat(WRAP2)) names.append(WRAP2) iw, i2 = names.index(WRAP), names.index(WRAP2) for p in me.polygons: if p.material_index == iw and abs(p.normal.z) < 0.7: c = p.center t = math.atan2(c.y, c.x) / TAU + c.z / 0.034 if int(math.floor(t * 2)) % 2: p.material_index = i2 P = [body] # a little red seal on the band, facing up once the cigar lies along Y (built facing -Y about Z) P.append(cyl_between("seal", (0, -(r + 0.0002), 0.039), (0, -(r + 0.0012), 0.039), 0.0042, REDP, v=8)) P.append(cyl_between("sealdot", (0, -(r + 0.0010), 0.039), (0, -(r + 0.0016), 0.039), 0.0018, GOLDM, v=6)) for o in P: xf(o, rx=-math.pi / 2) # local +Z -> +Y: foot at -Y, seal facing +Z ember = None if lit: ember = revm("ember", [(0.0, FOOT + 0.0004), (0.0082, FOOT + 0.0004), (0.0084, FOOT - 0.002), (0.0077, FOOT - 0.0048), (0.0048, FOOT - 0.0062), (0.0, FOOT - 0.0067)], EMBER, segs=segs) # a few grey ash flecks on the ember xf(ember, rx=-math.pi / 2) return P, ember def cigar(): P, em = cigar_parts() fin(P, "Body", ang=50, wn=False) smooth(bpy.data.objects["Body"], 50) tip = Vector((0, -(-FOOT + 0.0067), 0)) em = fin([em], "Ember", origin=tuple(tip), ang=60, wn=False) return [("", dict(elev=25, azim=-35, radius=0.08)), ("_side", dict(elev=8, azim=-90, radius=0.08)), ("_close", dict(elev=20, azim=-150, radius=0.035, target=(0, -0.055, 0)))] # ======================================================================= SM_VendSmoke SW_, SD_ = 0.95, 0.6 SF = -0.27 # front face of the carcass GL = (-0.36, 0.36, 0.64, 1.4) # glass opening x0 x1 z0 z1 DR = (-0.27, 0.27, 0.165, 0.395) # drawer opening KX = (0.315, 0.105, -0.105, -0.315) # Knob0..3, from the viewer's left (Blender +X) to the right KZ = 0.5 DRAW_OPEN = 0.25 def timber_box(x0, x1, y0, y1, z0, z1, along, bev=0.01, name="tim"): o = bx(x0, x1, y0, y1, z0, z1, TIMB, bev=bev, name=name) return grain(o, along) def vend_smoke(): P = [] # ---- plinth on turned feet, the carcass, the cornice for sx in (-1, 1): for sy in (-1, 1): P.append(revm("foot", [(0.0, 0.0), (0.035, 0.0), (0.042, 0.012), (0.034, 0.03), (0.04, 0.05), (0.0, 0.05)], BRASS, segs=10, loc=(sx * 0.4, sy * 0.24, 0))) P.append(timber_box(-0.475, 0.475, -0.3, 0.3, 0.05, 0.14, (1, 0, 0), bev=0.018, name="plinth")) P.append(bx(-0.47, 0.47, -0.303, -0.29, 0.125, 0.14, BRASS, bev=0.003, name="plinthband")) car = bx(-0.45, 0.45, SF, 0.28, 0.14, 1.46, TIMB, bev=0.006, name="carcass") cut(car, plain(GL[0], GL[1], SF - 0.1, 0.22, GL[2], GL[3], DARK, "glasscut")) cut(car, plain(DR[0] - 0.005, DR[1] + 0.005, SF - 0.1, 0.12, DR[2] - 0.005, DR[3] + 0.005, DARK, "drawercut")) paint(car, FELT, lambda c, n: c.y > 0.2 and n.y < -0.5 and GL[2] < c.z < GL[3]) paint(car, DARK, lambda c, n: c.y > SF + 0.002 and DR[2] - 0.01 < c.z < DR[3] + 0.01 and abs(c.x) < DR[1] + 0.01) grain(car, (0, 0, 1)) P.append(car) # front frame: stiles, rails, brass corner strips P.append(timber_box(0.36, 0.45, SF - 0.022, SF + 0.01, 0.14, 1.46, (0, 0, 1), name="stile")) P.append(timber_box(-0.45, -0.36, SF - 0.022, SF + 0.01, 0.14, 1.46, (0, 0, 1), name="stile")) for z0, z1 in ((0.14, DR[2]), (DR[3], GL[2]), (GL[3], 1.46)): P.append(timber_box(-0.36, 0.36, SF - 0.018, SF + 0.01, z0, z1, (1, 0, 0), name="rail")) for s in (-1, 1): P.append(bx(*sorted((s * 0.448, s * 0.462)), SF - 0.03, SF - 0.016, 0.14, 1.46, BRASS, bev=0.004, name="cornerstrip")) P.append(bx(*sorted((s * 0.45, s * 0.464)), SF - 0.03, SF + 0.02, 0.14, 1.46, BRASS, bev=0.004, name="cornerstrip")) # glass surround: a brass bead and a timber moulding, hinges on the left, keyhole on the right gl = rr2((GL[0] + GL[1]) / 2, (GL[2] + GL[3]) / 2, GL[1] - GL[0] + 0.01, GL[3] - GL[2] + 0.01, 0.012, 2) P.append(loop_tube("glassbead", gl, lambda a, b: (a, SF - 0.02, b), (0, 1, 0), 0.011, BRASS, segs=6)) for z in (0.75, 1.29): P.append(cz("hinge", 0.012, z - 0.045, z + 0.045, 0.37, SF - 0.03, BRASS, v=8)) P.append(bx(-0.405, -0.375, SF - 0.03, SF - 0.018, 0.96, 1.04, BRASS, bev=0.004, name="keyplate")) P.append(plain(-0.3925, -0.3875, SF - 0.031, SF - 0.029, 0.985, 1.01, DARK, "keyhole")) # inside the case: four columns of cigars on three tiers, each tier a shelf with a brass rail and price cards P.append(plain(GL[0], GL[1], SF + 0.01, 0.22, GL[2], GL[2] + 0.01, TIMB, "floor")) bands = (CREAM, REDP, GREEN, GOLDM) tiers = (0.66, 0.9, 1.14) for k, xd in enumerate((-0.18, 0.0, 0.18)): P.append(grain(plain(xd - 0.006, xd + 0.006, -0.22, 0.2, GL[2], GL[3], TIMB, "divider"), (0, 0, 1))) for zt in tiers: P.append(grain(plain(GL[0], GL[1], -0.24, 0.2, zt, zt + 0.014, TIMB, "shelf"), (1, 0, 0))) P.append(cx("shelfrail", 0.006, GL[0], GL[1], -0.232, zt + 0.03, BRASS, v=6)) P.append(cx("backrail", 0.006, GL[0], GL[1], -0.13, zt + 0.15, BRASS, v=6)) for c in range(4): xc = 0.27 - c * 0.18 P.append(plain(xc - 0.035, xc + 0.035, -0.242, -0.238, zt - 0.03, zt - 0.002, CREAM, "pricecard")) for j in (-1, 0, 1): o = cigar_simple(bands[c], segs=7) scale_about(o, (0, 0, 0), (1.55, 1.2, 1.55)) xf(o, rx=math.radians(70), rz=math.radians(4 * j), t=(xc + j * 0.05, -0.18, zt + 0.014 + 0.08)) P.append(o) # ---- knob row: brass escutcheons with blank cards over them; the knobs are children for x in KX: P.append(bx(x - 0.05, x + 0.05, SF - 0.024, SF - 0.014, KZ - 0.055, KZ + 0.055, BRASS, bev=0.006, name="escutcheon")) P.append(bx(x - 0.036, x + 0.036, SF - 0.028, SF - 0.02, KZ + 0.065, KZ + 0.1, BRASS, bev=0.003, name="cardholder")) P.append(plain(x - 0.03, x + 0.03, SF - 0.0285, SF - 0.027, KZ + 0.07, KZ + 0.095, CREAM, "card")) for sx in (-1, 1): nut(P, (x + sx * 0.038, SF - 0.024, KZ - 0.04), (0, -1, 0), r=0.005, h=0.003, m=STEEL) # ---- cornice and the round lit plaque on top P.append(timber_box(-0.47, 0.47, -0.295, 0.3, 1.46, 1.5, (1, 0, 0), bev=0.008, name="cornice")) P.append(bx(-0.475, 0.475, -0.302, 0.302, 1.5, 1.515, BRASS, bev=0.003, name="corniceband")) P.append(timber_box(-0.49, 0.49, -0.315, 0.31, 1.515, 1.56, (1, 0, 0), bev=0.012, name="cornicetop")) # plaque stand: a timber block, scroll brackets, the brass ring SZ, SR, SYc = 1.74, 0.135, -0.05 P.append(timber_box(-0.12, 0.12, SYc - 0.05, SYc + 0.05, 1.56, 1.6, (1, 0, 0), bev=0.01, name="standblock")) for s in (-1, 1): P.append(prism("scroll", [(s * 0.1, 1.6), (s * 0.155, 1.6), (s * 0.14, 1.64), (s * 0.115, 1.66), (s * 0.09, 1.63)], "XZ", SYc - 0.02, SYc + 0.02, TIMB)) P.append(torus("plaquering", SR + 0.008, 0.013, (0, SYc, SZ), "Y", seg=32, rseg=6, m=BRASS)) P.append(cy("plaqueback", SR + 0.004, SYc - 0.006, SYc + 0.006, 0, SZ, BRASS, v=28)) for k in range(8): a = TAU * k / 8 + math.pi / 8 P.append(sphere("stud", 0.006, (SR * 1.06 * math.cos(a), SYc - 0.018, SZ + SR * 1.06 * math.sin(a)), seg=6, rings=3, m=BRASS)) # the lit discs, front and back (the Sign), a cigar with a curl of smoke painted on the front sg = [cy("disc", SR - 0.004, SYc - 0.012, SYc + 0.012, 0, SZ, GLOW_A, v=28)] sign = fin(sg, "Sign", origin=(0, SYc, SZ), wn=False) flat(sign) yp = SYc - 0.0125 pl = lambda a, b: (a, yp, b) flat_on(P, pl, (0, -1, 0), rr2(0.0, SZ - 0.025, 0.17, 0.034, 0.016, 3), WRAPD, "icigar") flat_on(P, lambda a, b: (a, yp - 0.0008, b), (0, -1, 0), [(0.03, SZ - 0.043), (0.05, SZ - 0.043), (0.05, SZ - 0.007), (0.03, SZ - 0.007)], REDP, "iband") flat_on(P, lambda a, b: (a, yp - 0.0008, b), (0, -1, 0), [(-0.085, SZ - 0.041), (-0.078, SZ - 0.041), (-0.078, SZ - 0.009), (-0.085, SZ - 0.009)], "M_HeatGlow", "itip") sm = [Vector((-0.081 + 0.012 * math.sin(t * 9.0), SZ - 0.004 + t * 0.105)) for t in [i / 16 for i in range(17)]] pairs = [] for i, c in enumerate(sm): d = (sm[min(i + 1, 16)] - sm[max(i - 1, 0)]).normalized() w = 0.0055 * (1 - 0.6 * i / 16) nn = Vector((-d.y, d.x)) * w pairs.append(((c - nn).x, (c - nn).y)), pairs.append(((c + nn).x, (c + nn).y)) pr = [(pairs[2 * i], pairs[2 * i + 1]) for i in range(17)] P.append(strip_obj("ismoke", [((a[0], yp - 0.0004, a[1]), (b[0], yp - 0.0004, b[1])) for a, b in pr], "M_PaintSlate", (0, -1, 0))) # ---- sides: raised panels (timber frames) with brass rosettes for s in (-1, 1): X = s * 0.45 for (z0, z1) in ((0.2, 0.6), (0.7, 1.4)): for (a0, a1, b0, b1) in ((-0.22, 0.22, z0, z0 + 0.04), (-0.22, 0.22, z1 - 0.04, z1), (-0.22, -0.18, z0, z1), (0.18, 0.22, z0, z1)): P.append(timber_box(*sorted((X, X + s * 0.014)), a0, a1, b0, b1, (0, 0, 1) if a1 - a0 < 0.1 else (0, 1, 0), bev=0.005, name="panelframe")) P.append(cyl_between("rosette", (X + s * 0.014, 0, (z0 + z1) / 2), (X + s * 0.022, 0, (z0 + z1) / 2), 0.025, BRASS, v=10, bev=0.002)) # ---- the standing ashtray on the right side (Blender -X): base, column, bracket, bowl, ash and a stub AX, AY = -0.6, -0.08 P.append(revm("trayfoot", [(0.0, 0.0), (0.07, 0.0), (0.072, 0.012), (0.05, 0.03), (0.018, 0.045), (0.0, 0.045)], BRASS, segs=16, loc=(AX, AY, 0))) P.append(cz("traypole", 0.012, 0.04, 0.86, AX, AY, BRASS, v=8)) P.append(cz("traycollar", 0.02, 0.45, 0.48, AX, AY, BRASS, v=8)) P.append(cyl_between("traybracket", (AX, AY, 0.465), (-0.45, AY, 0.465), 0.01, BRASS, v=6)) P.append(cyl_between("traybracket2", (AX, AY, 0.8), (-0.45, AY, 0.8), 0.01, BRASS, v=6)) for z in (0.465, 0.8): P.append(cyl_between("bracketfoot", (-0.452, AY, z), (-0.468, AY, z), 0.022, BRASS, v=8)) bowl = revm("bowl", [(0.0, 0.86), (0.05, 0.86), (0.085, 0.885), (0.092, 0.91), (0.084, 0.912), (0.07, 0.888), (0.0, 0.882)], BRASS, segs=20, closed=True, loc=(AX, AY, 0)) P.append(bowl) P.append(cz("ash", 0.07, 0.882, 0.889, AX, AY, ASH, v=16)) for k in range(3): a = TAU * k / 3 + 0.4 P.append(cyl_between("rest", (AX + 0.075 * math.cos(a), AY + 0.075 * math.sin(a), 0.905), (AX + 0.098 * math.cos(a), AY + 0.098 * math.sin(a), 0.92), 0.008, BRASS, v=6)) Q, _ = cigar_parts(segs=8, band=CREAM, lit=False, rings=0) for o in Q: scale_about(o, (0, 0, 0), (1, 0.45, 1)) xf(o, rz=math.radians(40), ry=math.radians(-10), t=(AX + 0.015, AY + 0.01, 0.894)) P += Q P.append(sphere("butt_ash", 0.008, (AX + 0.03, AY - 0.03, 0.89), seg=6, rings=3, m=CHAR)) fin(P, "Body", ang=36) # ---- Glass g = plain(GL[0] - 0.005, GL[1] + 0.005, SF - 0.012, SF - 0.008, GL[2] - 0.005, GL[3] + 0.005, GLASS, "Glass") uv_box(g, 2.0) fin([g], "Glass", origin=((GL[0] + GL[1]) / 2, SF - 0.01, (GL[2] + GL[3]) / 2), wn=False) # ---- Knob0..3: a steel rod (most of it hidden in the case) and a brass mushroom head for i, x in enumerate(KX): rod = cyl_between("rod", (x, SF + 0.12, KZ), (x, SF - 0.04, KZ), 0.009, STEEL, v=8) head = revm("head", [(0.0, 0.0), (0.012, 0.0), (0.013, 0.006), (0.028, 0.012), (0.03, 0.022), (0.024, 0.032), (0.0, 0.035)], BRASS, segs=14) rot_x(head, 90, (x, SF - 0.035, KZ)) fin([rod, head], "Knob%d" % i, origin=(x, SF - 0.052, KZ), ang=50) # ---- Drawer: timber front with a brass cup pull and a felt-lined box behind it yf0, yf1 = SF - 0.024, SF + 0.002 D = [timber_box(DR[0] + 0.004, DR[1] - 0.004, yf0, yf1, DR[2] + 0.004, DR[3] - 0.004, (1, 0, 0), bev=0.008, name="dfront")] D.append(bx(DR[0] + 0.02, DR[1] - 0.02, yf0 - 0.004, yf0 + 0.002, DR[2] + 0.02, DR[3] - 0.02, BRASS, bev=0.003, name="dbead")) D.append(timber_box(DR[0] + 0.03, DR[1] - 0.03, yf0 - 0.008, yf0 - 0.001, DR[2] + 0.03, DR[3] - 0.03, (1, 0, 0), bev=0.004, name="dpanel")) cup = revm("pull", [(0.045, 0.0), (0.05, 0.0), (0.05, 0.018), (0.045, 0.02)], BRASS, segs=16, closed=True, a0=180, a1=360) rot_x(cup, 90, (0, yf0 - 0.008, (DR[2] + DR[3]) / 2 + 0.01)) D.append(cup) D.append(bx(-0.06, 0.06, yf0 - 0.012, yf0 - 0.006, (DR[2] + DR[3]) / 2 + 0.005, (DR[2] + DR[3]) / 2 + 0.025, BRASS, bev=0.003, name="pullplate")) by0, by1 = yf1, 0.1 for s in (-1, 1): D.append(timber_box(*sorted((s * (DR[1] - 0.012), s * (DR[1] - 0.026))), by0, by1, DR[2] + 0.01, DR[3] - 0.04, (0, 1, 0), bev=0.003, name="dside")) D.append(timber_box(DR[0] + 0.012, DR[1] - 0.012, by1 - 0.014, by1, DR[2] + 0.01, DR[3] - 0.04, (1, 0, 0), bev=0.003, name="dback")) D.append(plain(DR[0] + 0.026, DR[1] - 0.026, by0, by1 - 0.014, DR[2] + 0.01, DR[2] + 0.022, FELT, "dfelt")) zc = (DR[2] + DR[3]) / 2 fin(D, "Drawer", origin=(0, yf0, zc), ang=36) common.empty("DropPoint", (0, -0.17 - DRAW_OPEN, DR[2] + 0.022)) return [("", dict(elev=14, azim=-28)), ("_back", dict(elev=18, azim=150)), ("_close", dict(elev=10, azim=-15, dist_mul=0.45, target=(0, -0.3, 1.0))), ("_side", dict(elev=10, azim=-90)), ("_top", dict(elev=8, azim=-20, dist_mul=0.3, target=(0, -0.1, 1.72)))] # ======================================================================= the can CR, CH = 0.033, 0.12 TOPZ = 0.0565 def can_parts(crushed=False): """Body parts and the Tab parts of the can, origin at the can's centre.""" zs = [i * 0.0058 for i in range(-8, 9)] if crushed else [] prof = [(0.0, -0.0565), (0.02, -0.0565), (0.024, -0.06), (0.0275, -0.0595), (0.031, -0.0555), (CR, -0.05)] mats = [STEEL, STEEL, STEEL, STEEL, STEEL] body_rings = [(-0.046, GREEN), (-0.022, GREEN), (-0.02, GOLDM), (-0.018, CREAM), (0.022, CREAM), (0.024, GOLDM), (0.026, GREEN), (0.044, GREEN)] if crushed: extra = [(z, None) for z in zs if -0.046 < z < 0.044 and all(abs(z - b[0]) > 0.0015 for b in body_rings)] body_rings = sorted(body_rings + extra) filled = [] last = GREEN for z, m in body_rings: if m is None: m = last if last != GOLDM else (CREAM if -0.018 < z < 0.022 else GREEN) filled.append((z, m)) last = m body_rings = filled for z, m in body_rings: prof.append((CR, z)) mats.append(m) prof += [(CR, 0.048), (0.0285, 0.0555), (0.0275, 0.0595), (0.0268, 0.0602), (0.0258, 0.0595), (0.0252, TOPZ), (0.0, TOPZ)] mats += [GREEN, STEEL, STEEL, STEEL, STEEL, STEEL, STEEL] body = revm("can", prof, mats, segs=16 if crushed else 24) B = [body] # the leaf logo on the cream band, front (-Y) and back (+Y) for a0 in (-math.pi / 2, math.pi / 2): for (base, L, W, ang, m, bend) in (((-0.004, -0.012), 0.032, 0.0075, math.radians(70), GREEN, 0.12), ((-0.002, -0.011), 0.022, 0.006, math.radians(118), LEAFG, -0.14)): pr = leaf_pairs(base, L, W, ang, 8, bend) if crushed: # split down the midrib so the leaf can follow the folds across its width mids = [((a[0] + b[0]) / 2, (a[1] + b[1]) / 2) for a, b in pr] halves = [[(a, c) for (a, b), c in zip(pr, mids)], [(c, b) for (a, b), c in zip(pr, mids)]] else: halves = [pr] o = join([strip_obj("logo", [((a[0], -CR, a[1]), (b[0], -CR, b[1])) for a, b in h], m, (0, -1, 0)) for h in halves], "logo") for v in o.data.vertices: x, z = v.co.x, v.co.z ph = a0 + x / CR rr = CR + (0.0005 if m == GREEN else 0.0008) + (0.0006 if crushed else 0.0) v.co = (rr * math.cos(ph), rr * math.sin(ph), z) o.data.update() for p in o.data.polygons: c = Vector(p.center) if Vector(p.normal).dot(Vector((c.x, c.y, 0))) < 0: p.flip() B.append(o) # little gold dots either side of the leaf for dx in (-0.016, 0.016): ph = a0 + dx / CR p = Vector((CR * math.cos(ph), CR * math.sin(ph), 0.002)) B.append(cyl_between("dot", p * 1.0, p + Vector((math.cos(ph), math.sin(ph), 0)) * 0.0008, 0.0022, GOLDM, v=6)) # the scored mouth on the lid, towards -Y B.append(ring_obj("mouth", (0.0, -0.0135), 0.0062, 0.0074, DARK, lambda a, b: (a, b if b > -0.0135 else -0.0135 + (b + 0.0135) * 1.35, TOPZ + 0.0003), (0, 0, 1), n=12)) # Tab: a rivet, the nose over the mouth, the ring towards +Y T = [cz("rivet", 0.0028, TOPZ, TOPZ + 0.0016, 0, 0, STEEL, v=8), bx(-0.0045, 0.0045, -0.009, 0.002, TOPZ + 0.0006, TOPZ + 0.0014, STEEL, bev=0.0004, name="nose")] ring = torus("ring", 0.0062, 0.0016, (0, 0, 0), "Z", seg=14, rseg=4, m=STEEL) scale_about(ring, (0, 0, 0), (1.0, 1.25, 0.5)) xf(ring, t=(0, 0.0105, TOPZ + 0.0012)) T.append(ring) return B, T def crush_fn(): rng = random.Random(77) ph = [rng.uniform(0, TAU) for _ in range(3)] def f(p): x, y, z = p r = math.hypot(x, y) th = math.atan2(y, x) mid = max(0.0, 1 - (z / 0.05) ** 2) # squash: the middle folds up like an accordion, the ends barely change zn = z * 0.5 + 0.0011 * math.sin(z / 0.0116 * math.pi + th * 2 + ph[0]) * mid k = 1 + 0.15 * mid + 0.05 * mid * math.sin(5 * th + z * 120 + ph[1]) + 0.035 * mid * math.sin(z / 0.0116 * math.pi + th) dent = 0.2 * math.exp(-((math.atan2(math.sin(th - 0.2), math.cos(th - 0.2))) / 0.7) ** 2 - ((z - 0.004) / 0.024) ** 2) k -= dent * mid rr = r * k # the top tilts over zn += 0.006 * (x / CR) * (z / 0.06) return Vector((rr * math.cos(th) + 0.003 * z / 0.06, rr * math.sin(th), zn)) return f def beer_can(crushed=False, body_name="Body"): B, T = can_parts(crushed) body = fin(B, body_name, ang=45, wn=False) tab = fin(T, "Tab", ang=50, wn=False) if crushed: f = crush_fn() for o in (body, tab): apply_xform(o) for v in o.data.vertices: v.co = f(v.co) o.data.update() # centre the whole crushed can on its bounds pts = [v.co for v in body.data.vertices] c = Vector([(max(p[i] for p in pts) + min(p[i] for p in pts)) / 2 for i in range(3)]) for o in (body, tab): o.data.transform(Matrix.Translation(-c)) set_origin(body, (0, 0, 0)) smooth(body, 45) set_origin(tab, tuple(f(Vector((0, 0, TOPZ))) - c)) else: set_origin(tab, (0, 0, TOPZ)) return body, tab def can_model(): beer_can(False) return [("", dict(elev=22, azim=-30, radius=0.075)), ("_back", dict(elev=22, azim=150, radius=0.075)), ("_close", dict(elev=60, azim=-20, radius=0.04, target=(0, 0, 0.05)))] def can_crushed(): beer_can(True) return [("", dict(elev=22, azim=-30, radius=0.07)), ("_back", dict(elev=30, azim=140, radius=0.07)), ("_side", dict(elev=5, azim=-90, radius=0.07))] # ======================================================================= hands def ell(name, c, half, basis, m=SKIN, seg=12, rings=8): """Ellipsoid with half sizes along the columns of basis (3 Vectors).""" o = sphere(name, 1.0, (0, 0, 0), seg=seg, rings=rings, m=m, scale=half) M = Matrix((basis[0], basis[1], basis[2])).transposed().to_4x4() o.data.transform(M) o.data.transform(Matrix.Translation(Vector(c))) if M.determinant() < 0: # a left-handed basis turns the sphere inside out bm = bmesh.new() bm.from_mesh(o.data) bmesh.ops.reverse_faces(bm, faces=bm.faces) bm.to_mesh(o.data) bm.free() return o def arm(P, root, way, r0=0.031): """Wrist, bare forearm and the shirt sleeve, as on SM_PhoneHand.""" root, way = Vector(root), Vector(way).normalized() p = lambda s: tuple(root + way * s) def part(name, s0, s1, a, b, m): P.append(FT.sweep_circle(name, [p(s0), p((s0 + s1) / 2), p(s1)], lambda t, l: a + (b - a) * t, segs=12, m=m, cap=True, smooth_ang=60)) part("forearm", -0.03, 0.26, r0 * 0.9, 0.042, SKIN) part("cuff", 0.25, 0.272, 0.05, 0.05, SLEEVE) part("sleeve", 0.266, 0.5, 0.048, 0.058, SLEEVE) def hand_can(): """Right hand round the can: palm on the back-right, fingers across the back and round the left edge (tips on the front-left), thumb up the right-front. The viewer is at +Y, so (u right, v up, w toward the viewer) -> Blender (-u, w, v).""" at = lambda u, v, w: Vector((-u, w, v)) def pol(a_deg, rho, v): a = math.radians(a_deg) return at(rho * math.cos(a), v, rho * math.sin(a)) P = [] rad = lambda a: Vector((-math.cos(math.radians(a)), math.sin(math.radians(a)), 0)) tan = lambda a: Vector((-math.sin(math.radians(a)), -math.cos(math.radians(a)), 0)) * -1 Z = Vector((0, 0, 1)) P.append(ell("palm", pol(-12, CR + 0.026, -0.006), (0.021, 0.042, 0.054), (rad(-12), tan(-12), Z))) P.append(ell("heel", pol(8, CR + 0.025, -0.058), (0.02, 0.034, 0.03), (rad(8), tan(8), Z))) P.append(ell("thenar", pol(30, CR + 0.017, -0.04), (0.017, 0.022, 0.034), (rad(30), tan(30), Z), seg=10, rings=6)) fingers = ((0.034, 0.0118, -186, 1.0), (0.0105, 0.0124, -192, 1.0), (-0.0135, 0.0118, -182, 0.95), (-0.0365, 0.0104, -166, 0.85)) for v, r, a_tip, ln in fingers: rho = CR + r * 1.02 pts = [pol(-22, CR + 0.03, v - 0.003), pol(-42, CR + 0.022, v - 0.002), pol(-62, rho + 0.002, v - 0.001), pol(-92, rho, v), pol(-122, rho, v + 0.001), pol(-150, rho, v + 0.002), pol(a_tip + 12, rho, v + 0.002), pol(a_tip, rho - 0.002, v + 0.002)] P.append(FT.digit("finger", pts, r, (0.04, 0.4, 0.7), m=SKIN)) rt = 0.0128 P.append(FT.digit("thumb", [pol(24, CR + 0.03, -0.062), pol(30, CR + 0.022, -0.042), pol(40, CR + rt, -0.018), pol(48, CR + rt * 0.95, 0.004), pol(53, CR + rt * 0.9, 0.018)], rt, (0.34, 0.68), m=SKIN)) arm(P, pol(6, CR + 0.03, -0.082), at(0.34, -0.8, 0.5)) FT.done(P, "Hand", uv=6.0, ang=60) # the can, as SM_BeerCan, its Tab a child of it can, tab = beer_can(False, body_name="Can") tab.parent = can tab.matrix_parent_inverse = Matrix.Identity(4) return [("", dict(elev=8, azim=160, radius=0.16, target=(-0.03, 0.03, -0.03))), ("_back", dict(elev=12, azim=-25, radius=0.13, target=(-0.02, 0, -0.02))), ("_side", dict(elev=10, azim=-100, radius=0.14, target=(-0.04, 0.02, -0.03))), ("_front", dict(elev=5, azim=180, radius=0.09, target=(0, 0, 0)))] def hand_cigar(): """Relaxed right hand, thumb up, palm towards +X; the cigar along X sits between the index and middle finger's first joints.""" F = Vector((0, -0.42, 0.9)).normalized() # along the fingers N = Vector((1, 0, 0)) # out of the palm A = N.cross(F) # across the knuckles, index -> little finger Kc = Vector((-0.024, 0, 0)) - F * 0.03 # knuckle centre: the cigar crosses 3 cm up the fingers H = lambda f, a, n: Kc + F * f + A * a + N * n P = [] P.append(ell("palm", H(-0.046, 0.021, -0.002), (0.046, 0.052, 0.0185), (A, F, N))) P.append(ell("heel", H(-0.088, 0.024, 0.0), (0.034, 0.026, 0.019), (A, F, N), seg=10, rings=6)) P.append(ell("thenar", H(-0.062, -0.024, 0.01), (0.019, 0.034, 0.016), (A, F, N), seg=10, rings=6)) for a in (-0.012, 0.012, 0.035, 0.056): P.append(ell("knuckle", H(0.0, a, -0.006), (0.011, 0.012, 0.011), (A, F, N), seg=8, rings=5)) rc = CIG_R ri, rm = 0.0112, 0.0118 idx = [H(-0.012, -0.011, -0.001), H(0.004, -0.013, 0.0), H(0.03, -(rc + ri) - 0.001, 0.0), H(0.048, -0.023, 0.004), H(0.062, -0.023, 0.013), H(0.071, -0.022, 0.022), H(0.077, -0.021, 0.033)] mid = [H(-0.012, 0.011, -0.001), H(0.004, 0.013, 0.0), H(0.03, rc + rm + 0.001, 0.0), H(0.05, 0.022, 0.005), H(0.065, 0.022, 0.016), H(0.074, 0.021, 0.027), H(0.079, 0.02, 0.039)] rng_ = [H(-0.014, 0.035, -0.001), H(0.002, 0.037, 0.0), H(0.03, 0.041, 0.007), H(0.045, 0.042, 0.02), H(0.05, 0.041, 0.034), H(0.047, 0.039, 0.046), H(0.04, 0.037, 0.052)] pnk = [H(-0.02, 0.056, -0.001), H(-0.006, 0.058, 0.002), H(0.017, 0.061, 0.01), H(0.029, 0.061, 0.022), H(0.032, 0.059, 0.034), H(0.028, 0.057, 0.043), H(0.021, 0.055, 0.047)] for pts, r in ((idx, ri), (mid, rm), (rng_, 0.0112), (pnk, 0.0098)): P.append(FT.digit("finger", pts, r, (0.05, 0.42, 0.72), m=SKIN)) rt = 0.0125 P.append(FT.digit("thumb", [H(-0.078, -0.028, 0.006), H(-0.058, -0.04, 0.018), H(-0.036, -0.046, 0.026), H(-0.014, -0.044, 0.032), H(0.004, -0.04, 0.034), H(0.016, -0.035, 0.034)], rt, (0.3, 0.64), m=SKIN)) arm(P, H(-0.1, 0.018, 0.0), Vector((-0.35, 0.5, -0.8)), r0=0.03) FT.done(P, "Hand", uv=6.0, ang=60) # the cigar: SM_Cigar's own frame turned 90 degrees about Z, so its lit -Y end points along +X Q, em = cigar_parts() cig = fin(Q, "Cigar", ang=50, wn=False) emb = fin([em], "Ember", ang=60, wn=False) set_origin(emb, (0, FOOT - 0.0067, 0)) emb.parent = cig emb.matrix_parent_inverse = Matrix.Identity(4) cig.rotation_euler = (0, 0, math.pi / 2) return [("", dict(elev=10, azim=150, radius=0.16, target=(-0.02, 0.02, -0.02))), ("_back", dict(elev=15, azim=-60, radius=0.13, target=(-0.03, 0.0, -0.02))), ("_side", dict(elev=20, azim=110, radius=0.11, target=(0, 0, 0)))] # ======================================================================= tables and the run BUILDERS = {"SM_VendBeer": vend_beer, "SM_VendSmoke": vend_smoke, "SM_BeerCan": can_model, "SM_BeerCanCrushed": can_crushed, "SM_Cigar": cigar, "SM_HandCan": hand_can, "SM_HandCigar": hand_cigar} BUDGET = {"SM_VendBeer": 15000, "SM_VendSmoke": 15000, "SM_BeerCan": 1500, "SM_BeerCanCrushed": 1500, "SM_Cigar": 1500, "SM_HandCan": 9000, "SM_HandCigar": 9000} def fbx_check(name): """Read the FBX back: every node, its parent, origin, bounds, materials; the whole model's bounds and tris.""" common.reset() bpy.ops.import_scene.fbx(filepath=os.path.join(common.MODELS, name + ".fbx")) bpy.context.view_layer.update() objs = list(bpy.context.scene.objects) meshes = [o for o in objs if o.type == "MESH"] pts = [o.matrix_world @ v.co for o in meshes for v in o.data.vertices] tris = sum(len(p.vertices) - 2 for o in meshes for p in o.data.polygons) bb = [(round(min(p[i] for p in pts), 4), round(max(p[i] for p in pts), 4)) for i in range(3)] print(f"CHK|{name} tris {tris} / {BUDGET.get(name)} {'OVER' if tris > BUDGET.get(name, 1 << 30) else 'ok'} bb {bb}", flush=True) for o in sorted(objs, key=lambda o: o.name): ex = "" if o.type == "MESH": ps = [o.matrix_world @ v.co for v in o.data.vertices] ex = f" tris {sum(len(p.vertices) - 2 for p in o.data.polygons)} bb {[(round(min(p[i] for p in ps), 3), round(max(p[i] for p in ps), 3)) for i in range(3)]} mats {[m.name for m in o.data.materials]}" print(f"CHK| {o.type:5s} {o.name:12s} parent {o.parent.name if o.parent else '-':10s} origin {tuple(round(v, 4) for v in o.matrix_world.translation)}" f" rot {tuple(round(math.degrees(a), 1) for a in o.matrix_world.to_euler())}{ex}", flush=True) if __name__ == "__main__": args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] for name in (args or list(BUILDERS)): common.reset() random.seed(zlib.crc32(name.encode()) & 0xffff) views = BUILDERS[name]() bpy.context.view_layer.update() sc = bpy.context.scene out = [o for o in sc.objects if not o.get("preview_only") and o.type in ("MESH", "EMPTY")] tris = tri_count([o for o in out if o.type == "MESH"]) print(f"[{name}] tris={tris} budget={BUDGET.get(name, '-')}", flush=True) print(f"[{name}] fbx={common.export(name)}", flush=True) for m in bpy.data.materials: m.use_backface_culling = True for tag, kw in views: common.preview(name + tag, **kw) fbx_check(name)