gc_up5_tools (blades: scythes, shears, sickle, hammer, nail scissors), gc_up5_machines (lawn mower and the four farm machines), gc_up5_props (hand can, cigar, phone, phone hand, beer cans) and gc_up5_check (verify against the game FBX, previews, review scene). Output in ArtSource/Blender/remaster_v3_tools with Hand_Tools_v3_Review.blend; the hand items review scene from round 1. Preview half-panels are ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2475 lines
149 KiB
Python
2475 lines
149 KiB
Python
"""GRASS CUTTER - fifth round, the hand-held machines: a detail pass on the round-5 pilot's level (gc_up5_tools.py).
|
|
|
|
Items, and the generator each one's game FBX really came from (names, children, origins, bounds, triangle counts and slots match
|
|
exactly when that generator is run again):
|
|
|
|
SM_Tool_LawnMower gc_stage17.lawn_mower Body, Blade, Wheel_FL/FR/RL/RR, Fill P_ slots -> M_Pack, Fill M_Clippings
|
|
SM_Tool_HandPump gc_farm_tools.tool_handpump Body, Plunger, Nozzle M_ slots (the farm palette)
|
|
SM_Tool_SlurpGun gc_farm_tools.tool_slurpgun Body, Fan (tilted axis), Fill, Nozzle
|
|
SM_Tool_HydroCannon gc_farm_tools.tool_hydrocannon Body, Fan, Nozzle
|
|
SM_Tool_MegaSiphon gc_farm_tools.tool_megasiphon Body, Ring1, Ring2, Nozzle
|
|
(os_crew.py / gc_crew.py build an older look of the same four names: other sizes, other slots. Not used.)
|
|
In the game today only the mower is driven by code (CrewAvatar.HoldMower: Blade, Wheel_*, Fill); the four farm machines have no
|
|
ToolId and are only rendered by Editor/IconStudio. Their frames are kept all the same; the first-person shots use their old
|
|
ViewModel holds (verify_farm_tools.RIGS).
|
|
|
|
Every frame is kept: object names, origins, the pivot and axis of every moving part (Blade spins about local Z, wheels about local X,
|
|
Fan / Ring* about local Y, Plunger slides along Y, Fill scales on local Z), grip points, overall size, material slot names.
|
|
No new game material: the mower keeps P_ swatches (-> M_Pack) plus M_Clippings; the farm machines keep their own M_ slots.
|
|
Nothing from the Synty pack is used.
|
|
|
|
What changes is the detail, for first person up close:
|
|
engines finned cylinder and head, head bolts, a spark plug (hex, ribbed ceramic, terminal) with a rubber boot and an HT lead,
|
|
a recoil starter with vents, a rope guide, the rope and a moulded pull handle, a fuel tank with a crimped seam
|
|
and a knurled cap, a muffler with a perforated heat shield, a carburettor and air filter
|
|
decks a pressed shell: rolled lip, edge rib, crowned top with ribs following the outline, recessed engine panel, height levers in notched
|
|
quadrants, moulded height pads, decals; lugged tyres with sidewall ring and lettering on spoked rims, axle nuts showing
|
|
handles tube bends, flattened tube ends bolted into brackets with knob nuts, foam grips with end caps, a bail lever
|
|
in moulded pivot clips, a control cable held by clips
|
|
bags a catcher with a hard tray, panels bulging between piped corner seams, a hem rolled over the frame, rows of stitching
|
|
hardware bolts with washers and nuts, threads showing, welded brackets with beads, rivets
|
|
|
|
Output never goes to Assets: ArtSource/Blender/remaster_v3_tools/<name>.blend, fbx/<name>.fbx (export settings of common.py),
|
|
previews/<name>_<view>.png (game left, round 5 right).
|
|
Run (absolute paths):
|
|
blender -b --factory-startup --python C:/Github/Grass-Cutters/ArtSource/Blender/scripts/gc_up5_machines.py -- [build] [names]
|
|
blender -b --factory-startup --python .../gc_up5_machines.py -- verify [names] names, parents, origins, axes, bounds, slots
|
|
blender -b --factory-startup --python .../gc_up5_machines.py -- views [names] old | new panels, $GC5_VIEWS=tag,tag to limit
|
|
python .../gc_up5_machines.py compose [names] panels -> previews/<name>_<tag>.png
|
|
"""
|
|
import sys, os, math, time
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT = os.path.normpath(os.path.join(HERE, "..", "..", ".."))
|
|
OUT = os.path.join(ROOT, "ArtSource", "Blender", "remaster_v3_tools")
|
|
GAME = os.path.join(ROOT, "Assets", "Art", "Models")
|
|
PANELS = os.path.join(OUT, "previews", "_panels")
|
|
NAMES = ["SM_Tool_LawnMower", "SM_Tool_HandPump", "SM_Tool_SlurpGun", "SM_Tool_HydroCannon", "SM_Tool_MegaSiphon"]
|
|
sys.path.insert(0, HERE)
|
|
|
|
try:
|
|
import bpy # noqa: F401
|
|
IN_BLENDER = True
|
|
except ImportError:
|
|
IN_BLENDER = False
|
|
|
|
if IN_BLENDER:
|
|
for _try in range(8): # gc_up5_tools belongs to another agent and may be mid-edit: wait and retry
|
|
try:
|
|
from gc_up5_tools import * # noqa: F401,F403 (sweep, bprism, washer, hexnut, thread, bolt5, rivet, bead, ... + round 4 / 3 kits)
|
|
import gc_up5_tools as T5
|
|
break
|
|
except Exception as _e: # noqa: BLE001
|
|
print("gc_up5_machines: import gc_up5_tools failed, retrying in 60 s:", repr(_e), flush=True)
|
|
time.sleep(60)
|
|
else:
|
|
raise RuntimeError("gc_up5_tools would not import")
|
|
import common
|
|
import gc_up_machines as UM
|
|
import gc_farm_tools as FT
|
|
from mathutils import Vector, Matrix
|
|
from os_crew import revolve_fn # noqa: F401
|
|
|
|
TAU = 2 * math.pi
|
|
DEG = math.radians
|
|
|
|
|
|
# ======================================================================= palettes
|
|
|
|
class Pal(dict):
|
|
__getattr__ = dict.__getitem__
|
|
|
|
|
|
PK = Pal(muff="P_G1", red="P_RED", redd="P_REDD", white="P_WHITE", black="P_BLACK", rub="P_BLACK", plast="P_DGREY", d1="P_G1", d2="P_G2", st="P_G3",
|
|
hw="P_G4", br="P_G5", fab="P_CAB", thr="P_CREAM", gold="P_GOLD", tube="P_G3", brass="P_GOLD")
|
|
FM = Pal(muff="M_Steel", red="M_PaintRed", white="M_PaintWhite", black="M_Navy", rub="M_Rubber", plast="M_Navy", d1="M_Navy", d2="M_Steel", st="M_Steel",
|
|
hw="M_Steel", br="M_Blade", fab="M_Burlap", thr="M_Twine", gold="M_PaintYellow", tube="M_Steel", brass="M_Brass", tim="M_Timber",
|
|
lea="M_Leather", rope="M_Rope", tin="M_Tin", yel="M_PaintYellow", glass="M_Glass", teal="M_Teal", trim="M_TrimLine",
|
|
clip="M_Clippings")
|
|
|
|
|
|
# ======================================================================= lighter hardware (open where it sits on a surface)
|
|
# These shadow the gc_up5_tools versions for the calls made here (bolt5 inside gc_up5_tools keeps its own): the face that sits on
|
|
# the part is left out, a dome has 8 sides, which roughly halves the cost of the dozens of heads, rivets, washers and nuts.
|
|
|
|
def head(P, c, n, r, kind="hex", m="P_G4", ref=None):
|
|
"""A bolt head sitting on c, facing n. r: shank radius."""
|
|
if kind == "hex":
|
|
R, h = r * 1.85, r * 1.25
|
|
P.append(rev("bolthead", [(R, 0.0), (R, h * 0.7), (R * 0.84, h), (0.0, h * 1.04)], c, n, [m], segs=6, ref=ref, ang=20))
|
|
elif kind == "square":
|
|
R, h = r * 1.9, r * 1.3
|
|
P.append(rev("bolthead", [(R, 0.0), (R, h * 0.72), (R * 0.82, h), (0.0, h * 1.03)], c, n, [m], segs=4, ref=ref, ang=20))
|
|
else: # dome: a carriage bolt or a rivet
|
|
R, h = r * 1.75, r * 1.05
|
|
P.append(rev("bolthead", [(R, 0.0), (R * 0.95, h * 0.32), (R * 0.78, h * 0.7), (R * 0.45, h * 0.95), (0.0, h)], c, n, [m], segs=8, ref=ref, ang=40))
|
|
|
|
|
|
def rivet(P, c, n, r, m="M_Brass", tail=None, L=0.0):
|
|
head(P, c, n, r, "dome", m=m)
|
|
|
|
|
|
def washer(P, c, n, r, t, m="P_G4", segs=None, ref=None):
|
|
segs = segs or (8 if r < 0.016 else 10)
|
|
ch = t * 0.4
|
|
P.append(rev("washer", [(r, 0.0), (r, t - ch), (r - ch, t), (0.0, t)], c, n, [m], segs=segs, ref=ref, ang=30))
|
|
return Vector(c) + Vector(n).normalized() * t
|
|
|
|
|
|
def hexnut(P, c, n, R, h, m="P_G4", ref=None, name="nut"):
|
|
ch = min(h * 0.22, R * 0.2)
|
|
P.append(rev(name, [(R - ch, 0.0), (R, ch), (R, h - ch), (R - ch, h), (0.0, h)], c, n, [m], segs=6, ref=ref, ang=20))
|
|
return Vector(c) + Vector(n).normalized() * h
|
|
|
|
|
|
# ======================================================================= small geometry
|
|
|
|
def V(*a):
|
|
return Vector(a[0]) if len(a) == 1 else Vector(a)
|
|
|
|
|
|
def rev(name, prof, c, axis, mats, segs=16, ref=None, mod=None, colfn=None, ang=40, cap0=False, cap1=False):
|
|
"""A lathe about `axis` through c from a profile [(r, z)] (r = 0: a pole). mod(i, a) scales the radius of profile point i at angle a
|
|
(knurls, ribs, vents); colfn(i, j) -> slot of the band from profile point i to i + 1."""
|
|
F = fz(c, axis, ref)
|
|
rings = []
|
|
for i, (r, z) in enumerate(prof):
|
|
if r <= 1e-7:
|
|
rings.append([F @ Vector((0.0, 0.0, z))])
|
|
continue
|
|
ring = []
|
|
for k in range(segs):
|
|
a = TAU * k / segs
|
|
rr = r * (mod(i, a) if mod else 1.0)
|
|
ring.append(F @ Vector((rr * math.cos(a), rr * math.sin(a), z)))
|
|
rings.append(ring)
|
|
return rings_mesh(name, rings, mats if isinstance(mats, (list, tuple)) else [mats], colfn=colfn, cap0=cap0, cap1=cap1, ang=ang)
|
|
|
|
|
|
def fillet(pts, r, n=4):
|
|
"""Round every inner corner of a polyline by a bend of radius r (quadratic arcs), like a bent tube."""
|
|
P_ = [Vector(p) for p in pts]
|
|
out = [P_[0]]
|
|
for i in range(1, len(P_) - 1):
|
|
a, b, c = P_[i - 1], P_[i], P_[i + 1]
|
|
d0, d1 = (a - b), (c - b)
|
|
if d0.length < 1e-9 or d1.length < 1e-9:
|
|
continue
|
|
d0.normalize()
|
|
d1.normalize()
|
|
ang = d0.angle(d1)
|
|
if ang > PI - 1e-3:
|
|
out.append(b)
|
|
continue
|
|
t = min(r / max(1e-6, math.tan(ang / 2)), (a - b).length * 0.48, (c - b).length * 0.48)
|
|
p0, p1 = b + d0 * t, b + d1 * t
|
|
for j in range(n + 1):
|
|
u = j / n
|
|
out.append((1 - u) ** 2 * p0 + 2 * (1 - u) * u * b + u ** 2 * p1)
|
|
out.append(P_[-1])
|
|
return out
|
|
|
|
|
|
def densify(pts, step):
|
|
"""Extra stations along straight runs, so a section can change along a path."""
|
|
P_ = [Vector(p) for p in pts]
|
|
out = [P_[0]]
|
|
for a, b in zip(P_, P_[1:]):
|
|
n = max(1, int(math.ceil((b - a).length / step)))
|
|
for k in range(1, n + 1):
|
|
out.append(a.lerp(b, k / n))
|
|
return out
|
|
|
|
|
|
def rr_pts(hw, hd, rc, nc=3, nf=(2, 2)):
|
|
"""Rounded rectangle with nf = (points along X sides, along Y sides) between corners. [(x, y, flat)] where flat runs 0 at a
|
|
corner to 1 in the middle of a side: what bulges or sags between corner seams."""
|
|
rc = min(rc, hw * 0.98, hd * 0.98)
|
|
out = []
|
|
corners = ((hw - rc, hd - rc, 0), (-(hw - rc), hd - rc, 90), (-(hw - rc), -(hd - rc), 180), (hw - rc, -(hd - rc), 270))
|
|
for ci, (cx, cy, a0) in enumerate(corners):
|
|
for j in range(nc + 1):
|
|
a = DEG(a0 + 90 * j / nc)
|
|
out.append((cx + rc * math.cos(a), cy + rc * math.sin(a), 0.0))
|
|
nx = corners[(ci + 1) % 4]
|
|
m_ = nf[0] if ci in (0, 2) else nf[1]
|
|
ex = (cx + rc * math.cos(DEG(a0 + 90)), cy + rc * math.sin(DEG(a0 + 90)))
|
|
nxs = (nx[0] + rc * math.cos(DEG(nx[2])), nx[1] + rc * math.sin(DEG(nx[2])))
|
|
for k in range(1, m_ + 1):
|
|
f = k / (m_ + 1)
|
|
out.append((ex[0] + (nxs[0] - ex[0]) * f, ex[1] + (nxs[1] - ex[1]) * f, math.sin(PI * f)))
|
|
return out
|
|
|
|
|
|
def rr_ring(hw, hd, rc, z, c=(0.0, 0.0), nc=3, nf=(2, 2), bulge=0.0):
|
|
"""A ring of rr_pts at height z round c; bulge pushes the middle of each side outwards."""
|
|
pts = rr_pts(hw, hd, rc, nc, nf)
|
|
out = []
|
|
for x, y, f in pts:
|
|
d = Vector((x / max(hw, 1e-6) ** 2, y / max(hd, 1e-6) ** 2, 0.0))
|
|
d = d.normalized() if d.length > 1e-9 else Vector((1, 0, 0))
|
|
out.append(Vector((c[0] + x, c[1] + y, z)) + d * bulge * f)
|
|
return out
|
|
|
|
|
|
def slot(P, c, n, along, L, w, h, m, sink=0.0006, bev=True):
|
|
"""A stamped slot or louvre: a stadium of L x w standing h off a surface (normal n) at c, its long side along `along`."""
|
|
out = [(L / 2 - w / 2 + w / 2 * math.cos(a), w / 2 * math.sin(a)) for a in [DEG(-90 + 180 * k / 2) for k in range(3)]]
|
|
out += [(-(L / 2 - w / 2) + w / 2 * math.cos(a), w / 2 * math.sin(a)) for a in [DEG(90 + 180 * k / 2) for k in range(3)]]
|
|
P.append(bprism("slot", out, -sink, h, [m], bev=min(h * 0.45, w * 0.3) if bev else 0.0, segs=1, frame=fz(c, n, along), ang=50))
|
|
|
|
|
|
def stitches(name, pts, nrm, m, step=0.016, L=0.0075, w=0.0022, lift=0.0009, phase=0.0):
|
|
"""A row of stitches along a polyline lying on a surface: each a small domed dash, nrm(p) the surface's outward normal."""
|
|
C = [Vector(p) for p in pts]
|
|
Ls = arclen(C)
|
|
tot = Ls[-1]
|
|
bm = bmesh.new()
|
|
s = step * (0.5 + phase)
|
|
while s < tot - step * 0.3:
|
|
i = next((q for q in range(len(Ls) - 1) if Ls[q + 1] >= s), len(Ls) - 2)
|
|
f = (s - Ls[i]) / max(1e-9, Ls[i + 1] - Ls[i])
|
|
p = C[i].lerp(C[i + 1], f)
|
|
t = (C[i + 1] - C[i]).normalized()
|
|
n = Vector(nrm(p)).normalized()
|
|
u = n.cross(t).normalized()
|
|
t = u.cross(n)
|
|
base = p + n * lift
|
|
ring = [base + t * (L / 2), base + u * (w / 2), base - t * (L / 2), base - u * (w / 2)]
|
|
vs = [bm.verts.new(q) for q in ring]
|
|
top = bm.verts.new(base + n * w * 0.45)
|
|
for k in range(4):
|
|
bm.faces.new((vs[k], vs[(k + 1) % 4], top))
|
|
s += step
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
smooth(o, 80)
|
|
# every dash must face away from the surface
|
|
me = o.data
|
|
me.update()
|
|
return o
|
|
|
|
|
|
def tube5(name, pts, r, m, segs=10, bend=0.03, ang=40, ref=None, cap0=True, cap1=True, rf=None, step=None, nb=5):
|
|
"""A bent tube: the polyline's corners turned into bends of radius `bend`. rf(s) -> radius along it (default r)."""
|
|
C = fillet(pts, bend, n=nb)
|
|
if step:
|
|
C = densify(C, step)
|
|
return sweep(name, C, lambda s, i: circ(rf(s) if rf else r, segs), [m], cap0=cap0, cap1=cap1, ang=ang, ref=ref)
|
|
|
|
|
|
def knob_nut(P, c, n, R, m, ref=None, lobes=4):
|
|
"""A star knob screwed onto a bolt: a moulded lobed disc, a domed top, a boss towards the work."""
|
|
def mod(i, a):
|
|
return 1.0 + 0.22 * max(0.0, math.cos(lobes * a)) ** 2 if 1 <= i <= 4 else 1.0
|
|
P.append(rev("knob", [(R * 0.5, 0.0), (R * 0.82, R * 0.32), (R * 0.95, R * 0.45), (R * 0.95, R * 0.85), (R * 0.82, R * 1.0),
|
|
(R * 0.4, R * 1.12), (0.0, R * 1.15)], c, n, [m], segs=lobes * 3, ref=ref, mod=mod, ang=45))
|
|
|
|
|
|
def clip_band(P, c, t, r, w, m, ear=None, screw_m=None):
|
|
"""A strap clip round a tube (axis t, radius r) at c: a band with rounded edges, a tab with a screw on the `ear` side."""
|
|
t = Vector(t).normalized()
|
|
prof = [(r + 0.0004, -w / 2), (r + 0.0026, -w / 2 + 0.0012), (r + 0.0026, w / 2 - 0.0012), (r + 0.0004, w / 2)]
|
|
P.append(rev("clip", prof, c, t, [m], segs=10, ang=45))
|
|
if ear is not None:
|
|
e = (Vector(ear) - t * Vector(ear).dot(t)).normalized()
|
|
P.append(rev("clipboss", [(0.0042, -0.0005), (0.0046, 0.003), (0.0038, 0.0052), (0.0, 0.0056)], Vector(c) + e * (r + 0.0015), e, [m], segs=8))
|
|
head(P, Vector(c) + e * (r + 0.0068), e, 0.0018, "dome", m=screw_m or m)
|
|
|
|
|
|
# ======================================================================= hardware kit for the machines
|
|
|
|
def crimp_seam(P, ring, n_out, m, r=0.0022):
|
|
"""A crimped seam flange running round a closed ring of points (a tank's two halves)."""
|
|
pts = [Vector(p) for p in ring] + [Vector(ring[0]), Vector(ring[1])]
|
|
P.append(sweep("seam", pts, lambda s, i: [(0.0, -r * 0.55), (r * 1.4, -r * 0.45), (r * 1.9, 0.0), (r * 1.4, r * 0.45), (0.0, r * 0.55)],
|
|
[m], cap0=False, cap1=False, ang=50, frm=_ring_frames(pts, n_out)))
|
|
|
|
|
|
def _ring_frames(pts, up):
|
|
"""Frames along a closed ring lying roughly in a plane normal to `up`: N outward, B along `up`."""
|
|
up = Vector(up).normalized()
|
|
n = len(pts)
|
|
T, N, B = [], [], []
|
|
for i in range(n):
|
|
t = (pts[min(i + 1, n - 1)] - pts[max(i - 1, 0)]).normalized()
|
|
b = up
|
|
nn = t.cross(b).normalized()
|
|
T.append(t)
|
|
N.append(nn)
|
|
B.append(b)
|
|
# the cross product may point inwards: make N point away from the centre
|
|
cen = sum(pts, Vector()) / n
|
|
if N[0].dot(pts[0] - cen) < 0:
|
|
N = [-x for x in N]
|
|
return T, N, B
|
|
|
|
|
|
def spark_plug(P, base, d, M, lead=None, boot=True):
|
|
"""A spark plug screwed into a head at `base` along d: a washer, a hex, a ribbed white ceramic, the terminal; a rubber boot pushed
|
|
over it and an HT lead along `lead` (points) from the boot back to the coil."""
|
|
d = Vector(d).normalized()
|
|
q = washer(P, base, d, 0.0105, 0.0016, m=M.hw)
|
|
q = hexnut(P, q, d, 0.0105, 0.0085, m=M.hw, name="plughex")
|
|
P.append(rev("ceramic", [(0.0078, -0.001), (0.0078, 0.002), (0.0062, 0.004), (0.0066, 0.007), (0.0058, 0.009), (0.0063, 0.012), (0.0055, 0.014),
|
|
(0.0059, 0.017), (0.0048, 0.02), (0.0042, 0.024), (0.0, 0.0245)], q, d, [M.white], segs=12, ang=50))
|
|
e = q + d * 0.024
|
|
if boot:
|
|
P.append(rev("boot", [(0.0048, -0.008), (0.0068, -0.006), (0.0072, 0.0), (0.0066, 0.004), (0.0071, 0.007), (0.0064, 0.011), (0.0068, 0.014),
|
|
(0.0058, 0.02), (0.0042, 0.026), (0.0036, 0.029)], e, d, [M.rub], segs=12, ang=50))
|
|
if lead:
|
|
pts = [e + d * 0.027] + [Vector(p) for p in lead]
|
|
P.append(tube5("lead", pts, 0.0034, M.rub, segs=6, bend=0.02, ang=50, nb=3))
|
|
else:
|
|
P.append(rev("terminal", [(0.002, 0.0), (0.0032, 0.001), (0.0032, 0.005), (0.0, 0.006)], e, d, [M.hw], segs=8))
|
|
|
|
|
|
def fin_stack(P, c, axis, ref, w0, h0, rc, n, pitch, t, shrink, m, core=None, mat_core=None):
|
|
"""Cooling fins: n thin plates (rounded rectangles w x h, bevelled edges) stacked along `axis` from c, each smaller by `shrink`,
|
|
on a core block (hw, hh) that fills the gaps."""
|
|
axis = Vector(axis).normalized()
|
|
for k in range(n):
|
|
w, h = w0 - shrink * k, h0 - shrink * k * 0.9
|
|
F = fz(Vector(c) + axis * (k * pitch), axis, ref)
|
|
P.append(bprism("fin", rrect(w / 2, h / 2, rc, 1), -t / 2, t / 2, [m], bev=t * 0.42, segs=1, frame=F, min_ang=30, ang=40))
|
|
if core:
|
|
hw, hh = core
|
|
F = fz(Vector(c) - axis * pitch * 0.4, axis, ref)
|
|
P.append(bprism("core", rrect(hw, hh, min(hw, hh) * 0.5, 2), 0.0, pitch * (n - 0.2), [mat_core or m], bev=0.002, segs=1, frame=F))
|
|
|
|
|
|
def recoil(P, c, n, R, H, M, ref=None, vents=10, cover=None, cap=None):
|
|
"""A recoil starter: a pressed dome cover (radius R, height H along n from c) with a rolled foot, stamped vent slots round the
|
|
crown, a centre cap held by three screws."""
|
|
n = Vector(n).normalized()
|
|
cover = cover or M.white
|
|
prof = [(R * 0.97, -0.004), (R, -0.002), (R * 1.01, 0.0015), (R * 0.99, H * 0.32), (R * 0.96, H * 0.55), (R * 0.88, H * 0.78), (R * 0.72, H * 0.93),
|
|
(R * 0.5, H), (0.0, H * 1.01)]
|
|
P.append(rev("recoil", prof, c, n, [cover], segs=22, ref=ref, ang=38))
|
|
P.append(rev("recfoot", [(R * 1.005, -0.0045), (R * 1.04, -0.0035), (R * 1.05, -0.001), (R * 1.03, 0.001), (R * 1.0, 0.0012)], c, n, [M.d1], segs=12, ref=ref, ang=50))
|
|
F = fz(c, n, ref)
|
|
for k in range(vents):
|
|
a = TAU * (k + 0.5) / vents
|
|
rr = R * 0.79
|
|
zc = H * 0.86
|
|
p = F @ Vector((rr * math.cos(a), rr * math.sin(a), zc))
|
|
nrm = (F.to_3x3() @ Vector((math.cos(a) * 0.55, math.sin(a) * 0.55, 1.0))).normalized()
|
|
al = (F.to_3x3() @ Vector((math.cos(a), math.sin(a), -0.5))).normalized()
|
|
slot(P, p, nrm, al, R * 0.2, R * 0.065, 0.0012, M.black, bev=False)
|
|
cp = Vector(c) + n * H
|
|
P.append(rev("reccap", [(R * 0.4, -0.001), (R * 0.42, 0.002), (R * 0.4, 0.0045), (R * 0.3, 0.0065), (0.0, 0.007)], cp, n, [cap or M.d2], segs=16, ang=40))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.3
|
|
p = F @ Vector((R * 0.32 * math.cos(a), R * 0.32 * math.sin(a), H + 0.006))
|
|
head(P, p, n, 0.0022, "dome", m=M.hw)
|
|
|
|
|
|
def pull_handle(P, c, d, M, L=0.06, r=0.0085, m=None):
|
|
"""A moulded pull-start handle across d at c: a fat grip swelling in the middle, finger ridges underneath, the rope knotted in a boss."""
|
|
d = Vector(d).normalized()
|
|
a, b = Vector(c) - d * L / 2, Vector(c) + d * L / 2
|
|
C = [a.lerp(b, k / 6) for k in range(7)]
|
|
|
|
def sec(s, i):
|
|
rr = r * (0.82 + 0.3 * math.sin(PI * s) - 0.08 * (1 if 0.25 < s < 0.75 and i % 2 else 0))
|
|
return circ((rr * 1.15, rr), 8)
|
|
P.append(sweep("pullh", C, sec, [m or M.black], ang=50, ref=(0, 0, 1)))
|
|
|
|
|
|
def rope_line(P, pts, r, m, segs=5):
|
|
"""A rope or cord with a twist: a slightly lobed section rolled along the run."""
|
|
C = densify(fillet(pts, 0.03, 3), max(r * 10, 0.025))
|
|
Lt = arclen([Vector(p) for p in C])[-1]
|
|
|
|
def sec(s, i):
|
|
return [(r * (1 + 0.14 * math.cos(3 * (q * TAU / segs) - s * Lt / (r * 5.0))) * math.cos(q * TAU / segs),
|
|
r * (1 + 0.14 * math.cos(3 * (q * TAU / segs) - s * Lt / (r * 5.0))) * math.sin(q * TAU / segs)) for q in range(segs)]
|
|
P.append(sweep("rope", C, sec, [m], ang=60))
|
|
|
|
|
|
def muffler(P, c, axis, R, L, M, shield=True, ref=None, spout=None, holes=True):
|
|
"""A muffler can along `axis` from c: rolled end seams, bolts on the flange, a perforated heat shield over the top half, a spout."""
|
|
axis = Vector(axis).normalized()
|
|
prof = [(0.0, 0.0), (R * 0.82, 0.0), (R * 0.95, 0.003), (R, 0.007), (R * 1.04, 0.009), (R, 0.011), (R, L - 0.011), (R * 1.04, L - 0.009), (R, L - 0.007),
|
|
(R * 0.95, L - 0.003), (R * 0.8, L), (0.0, L)]
|
|
P.append(rev("muff", prof, c, axis, [M.muff], segs=12, ref=ref, ang=40))
|
|
if shield:
|
|
F = fz(c, axis, ref)
|
|
rr = R + 0.0045
|
|
|
|
def fn(u, v, off):
|
|
a = DEG(-20 + 220 * v)
|
|
return F @ Vector(((rr + off) * math.cos(a), (rr + off) * math.sin(a), 0.006 + (L - 0.012) * u))
|
|
P.append(FT.grid_slab("shield", fn, 4, 8, 0.0011, -0.0011, M.black, smooth_ang=50))
|
|
for i in range(3 if holes else 0):
|
|
for j in range(2):
|
|
a = DEG(20 + 140 * (j + 0.5) / 2 + (14 if i % 2 else 0))
|
|
p = F @ Vector(((rr + 0.0012) * math.cos(a), (rr + 0.0012) * math.sin(a), 0.012 + (L - 0.024) * (i + 0.5) / 3))
|
|
nrm = (F.to_3x3() @ Vector((math.cos(a), math.sin(a), 0))).normalized()
|
|
P.append(rev("hole", [(0.0035, -0.0004), (0.0028, 0.0002), (0.0, 0.0001)], p, nrm, [M.d1], segs=8, ang=60))
|
|
if spout:
|
|
a, b = Vector(spout[0]), Vector(spout[1])
|
|
P.append(tube5("spout", [a, b], R * 0.3, M.d1, segs=10, cap1=False))
|
|
P.append(rev("spoutlip", [(R * 0.24, -0.001), (R * 0.33, 0.0), (R * 0.35, 0.004), (R * 0.26, 0.005)], b, (b - a), [M.d1], segs=10))
|
|
|
|
|
|
def tread_tyre(P, M, out, R=0.1, W=0.044, pitches=10, rim_m=None, hub_m=None):
|
|
"""A small treaded tyre about local X at the origin (out = +1 / -1: which side faces out). The carcass and its tread are one
|
|
surface: chevron lugs stand out of the crown with steep walls and wrap over the shoulders, so the outline reads as a tyre. A raised
|
|
ring and moulded lettering on the outer sidewall, a bead ridge where the tyre meets the rim's rolled lip, a spoked rim, a bearing
|
|
boss, the axle nut on its washer with the thread showing."""
|
|
hw = W / 2
|
|
X = Vector((out, 0, 0))
|
|
F = fz(Vector(), X, (0, 0, 1))
|
|
Rc = R - 0.0058
|
|
# profile across the tyre (inner side first): (r, z along the axle, lug lift weight, chevron lean)
|
|
pr = [(0.645 * R, -0.9 * hw, 0.0, -1), (0.82 * R, -1.08 * hw, 0.0, -1), (Rc - 0.0035, -0.99 * hw, 0.45, -1),
|
|
(Rc, -0.8 * hw, 1.0, -1), (Rc, 0.0, 1.0, 0), (Rc, 0.8 * hw, 1.0, 1), (Rc - 0.0035, 0.99 * hw, 0.45, 1), (0.855 * R, 1.07 * hw, 0.0, 1),
|
|
(0.79 * R, 1.13 * hw, 0.0, 1), (0.745 * R, 1.07 * hw, 0.0, 1), (0.695 * R, 1.09 * hw, 0.0, 1), (0.645 * R, 0.9 * hw, 0.0, 1)]
|
|
ph = (0.0, 0.075, 0.5, 0.575) # per pitch: wall foot, lug top, lug top, wall foot; then the groove
|
|
rings = []
|
|
for r, z, w, lean in pr:
|
|
sh = 0.32 * abs(lean)
|
|
ring = []
|
|
for k in range(pitches):
|
|
for j, p in enumerate(ph):
|
|
a = TAU * (k + p + sh) / pitches
|
|
rr = r + (R - Rc) * w * (1.0 if j in (1, 2) else 0.0)
|
|
ring.append(F @ Vector((rr * math.cos(a), rr * math.sin(a), z)))
|
|
rings.append(ring)
|
|
P.append(rings_mesh("tyre", rings, [M.rub], cap0=False, cap1=False, ang=48))
|
|
# moulded lettering on the outer sidewall: one arc of raised strokes
|
|
glyphs = {"H": [(-1.5, 0, 0.45, 3), (1.5, 0, 0.45, 3)], "T": [(0, -0.4, 0.45, 2.6), (0, 2.6, 2.0, 0.45)], "L": [(-1.0, 0, 0.45, 3), (0.6, -2.6, 1.5, 0.45)],
|
|
"I": [(0, 0, 0.45, 3)], "E": [(-1.3, 0, 0.45, 3), (0.4, 2.6, 1.5, 0.45), (0.4, -2.6, 1.5, 0.45)]}
|
|
rl, zl = 0.886 * R, 1.03 * hw
|
|
nrm2 = Vector((0.27, 0.96)) # the sidewall's slope there, (radial, axial)
|
|
for k, g in enumerate("HTLIHT"):
|
|
a0 = 0.9 + k * 0.072
|
|
for du, dv, hu, hv in glyphs[g]:
|
|
a = a0 + du * 0.001 / rl
|
|
rad = Vector((math.cos(a), math.sin(a), 0.0))
|
|
c = F @ (rad * (rl + dv * 0.001) + Vector((0, 0, zl - dv * 0.001 * 0.28)))
|
|
n = (F.to_3x3() @ (rad * nrm2.x + Vector((0, 0, nrm2.y)))).normalized()
|
|
tg = (F.to_3x3() @ Vector((-math.sin(a), math.cos(a), 0.0))).normalized()
|
|
outl = [(-hu * 0.001, -hv * 0.001), (hu * 0.001, -hv * 0.001), (hu * 0.001, hv * 0.001), (-hu * 0.001, hv * 0.001)]
|
|
P.append(bprism("letter", outl, -0.0005, 0.001, [M.rub], segs=1, frame=fz(c, n, tg)))
|
|
# the rim: a dished steel wheel, its lip rolled over the tyre's bead, four spokes to the hub
|
|
rim = rim_m or M.white
|
|
P.append(rev("rimseat", [(0.6 * R, -0.9 * hw), (0.668 * R, -0.93 * hw), (0.678 * R, -0.86 * hw), (0.648 * R, -0.72 * hw), (0.648 * R, 0.72 * hw),
|
|
(0.678 * R, 0.86 * hw), (0.668 * R, 0.93 * hw), (0.6 * R, 0.9 * hw)], Vector(), X, [rim], segs=12, ref=(0, 0, 1), ang=40))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + 0.3
|
|
rad = Vector((0.0, math.cos(a), math.sin(a)))
|
|
tng = Vector((0.0, -math.sin(a), math.cos(a)))
|
|
C = [rad * R * 0.2 + X * hw * 0.35, rad * R * 0.6 + X * hw * 0.05]
|
|
P.append(sweep("spoke", C, lambda s, i: rrect(0.0055 + 0.002 * s, 0.003, 0.0018, 1), [rim], ref=tuple(tng), ang=40))
|
|
hub = hub_m or M.d2
|
|
P.append(rev("hub", [(0.0, -hw * 0.75), (R * 0.12, -hw * 0.78), (R * 0.2, -hw * 0.6), (R * 0.22, hw * 0.1), (R * 0.2, hw * 0.4), (R * 0.15, hw * 0.48),
|
|
(R * 0.12, hw * 0.5), (0.0, hw * 0.5)], Vector(), X, [hub], segs=8, ref=(0, 0, 1), ang=40))
|
|
# the axle nut on its washer outside the hub, the thread end showing
|
|
q = washer(P, X * hw * 0.5, X, 0.0115, 0.0016, m=M.hw)
|
|
q = hexnut(P, q, X, 0.0092, 0.0062, m=M.hw, ref=(0, 0, 1))
|
|
P.append(rev("axend", [(0.0042, -0.001), (0.0042, 0.0022), (0.0034, 0.0034), (0.0, 0.0036)], q, X, [M.st], segs=8))
|
|
|
|
|
|
def fill5(x0, x1, y0, y1, z0, z_edge, z_top, seed=1717, name="Fill", m="M_Clippings", nx=11, ny=8, strands=24):
|
|
"""Clippings heaped in the catcher: a soft mound over a rounded footprint, lumps and hollows where it fell in, loose blades of
|
|
grass standing out of it. Origin at the bottom (the game scales it on local Z)."""
|
|
rnd = random.Random(seed)
|
|
cx, cy, hx, hy = (x0 + x1) / 2, (y0 + y1) / 2, (x1 - x0) / 2, (y1 - y0) / 2
|
|
blobs = [(rnd.uniform(-0.7, 0.7), rnd.uniform(-0.6, 0.6), rnd.uniform(-0.6, 1.0), rnd.uniform(0.18, 0.34)) for _ in range(7)]
|
|
span = z_top - z_edge
|
|
|
|
def sq(u, v):
|
|
"""The square (u, v) in -1..1 pulled into a squircle, and its radius 0..1."""
|
|
mx = max(abs(u), abs(v))
|
|
if mx < 1e-9:
|
|
return 0.0, 0.0, 0.0
|
|
k = mx / (abs(u) ** 4 + abs(v) ** 4) ** 0.25
|
|
return u * k, v * k, mx
|
|
|
|
def hgt(u, v, rs):
|
|
z = z_edge + span * 0.62 * (1.0 - rs ** 2.4)
|
|
for bu, bv, a, sg in blobs:
|
|
z += span * 0.22 * a * math.exp(-((u - bu) ** 2 + (v - bv) ** 2) / (2 * sg * sg)) * (1.0 - rs ** 3)
|
|
z += span * 0.06 * math.sin(7.3 * u + 2.1) * math.sin(6.1 * v + 0.7) * (1.0 - rs ** 2)
|
|
return min(z, z_top - 0.0015)
|
|
bm = bmesh.new()
|
|
G = []
|
|
for i in range(nx):
|
|
row = []
|
|
for j in range(ny):
|
|
u, v = -1 + 2 * i / (nx - 1), -1 + 2 * j / (ny - 1)
|
|
su, sv, rs = sq(u, v)
|
|
row.append(bm.verts.new((cx + hx * su, cy + hy * sv, hgt(u, v, rs))))
|
|
G.append(row)
|
|
for i in range(nx - 1):
|
|
for j in range(ny - 1):
|
|
bm.faces.new((G[i][j], G[i + 1][j], G[i + 1][j + 1], G[i][j + 1]))
|
|
rim = [G[i][0] for i in range(nx)] + [G[nx - 1][j] for j in range(1, ny)] + [G[i][ny - 1] for i in range(nx - 2, -1, -1)] + [G[0][j] for j in range(ny - 2, 0, -1)]
|
|
low = [bm.verts.new((v.co.x, v.co.y, z0)) for v in rim]
|
|
for k in range(len(rim)):
|
|
j = (k + 1) % len(rim)
|
|
bm.faces.new((rim[k], rim[j], low[j], low[k]))
|
|
bm.faces.new(list(reversed(low)))
|
|
# loose blades: thin three-sided spikes leaning out of the heap
|
|
for _ in range(strands):
|
|
u, v = rnd.uniform(-0.85, 0.85), rnd.uniform(-0.8, 0.8)
|
|
su, sv, rs = sq(u, v)
|
|
p = Vector((cx + hx * su, cy + hy * sv, hgt(u, v, rs) - 0.002))
|
|
a = rnd.uniform(0, TAU)
|
|
L = rnd.uniform(0.012, 0.022)
|
|
d = Vector((math.cos(a) * 0.8, math.sin(a) * 0.8, rnd.uniform(0.35, 0.9))).normalized()
|
|
tip = p + d * L
|
|
tip.z = min(tip.z, z_top - 0.0008)
|
|
side = d.cross(Vector((0, 0, 1)))
|
|
side = side.normalized() if side.length > 1e-6 else Vector((1, 0, 0))
|
|
b = [bm.verts.new(p + side * 0.0026), bm.verts.new(p - side * 0.0026), bm.verts.new(p + d.cross(side).normalized() * 0.0012)]
|
|
t = bm.verts.new(tip)
|
|
for q in range(3):
|
|
bm.faces.new((b[q], b[(q + 1) % 3], t))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
bmesh.ops.triangulate(bm, faces=[f for f in bm.faces if len(f.verts) > 4], ngon_method="EAR_CLIP")
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
uv_box(o, 1.0)
|
|
UM.one_uv(o)
|
|
smooth(o, 60)
|
|
set_origin(o, (cx, cy, z0))
|
|
return o
|
|
|
|
|
|
# ======================================================================= SM_Tool_LawnMower
|
|
|
|
def lawn_mower():
|
|
M = PK
|
|
G, YC, HW, HD = -0.95, -0.80, 0.53, 0.36
|
|
P = []
|
|
# ---- the deck: one pressed shell. From the rolled skirt a stiffening rib runs round the edge; inside it the crown rises in two
|
|
# more ribs that follow the outline, then steps down into a recessed panel round the engine mount. The skirt is rolled out into
|
|
# a bead at the bottom.
|
|
ZR = -0.7302 # floor of the engine panel
|
|
RX, RY, RRC, RCY = 0.205, 0.165, 0.05, -0.83 # the panel: half width, half depth, corner radius, centre y
|
|
|
|
def rec_ring(inset, z):
|
|
return [Vector((x, RCY + y, z)) for x, y, _ in rr_pts(RX - inset, RY - inset, max(0.004, RRC - inset), nc=3, nf=(2, 1))]
|
|
z0 = -0.7275
|
|
outer = [Vector((x, YC + y, z0)) for x, y, _ in rr_pts(HW - 0.105, HD - 0.105, 0.015, nc=3, nf=(2, 1))]
|
|
inner = rec_ring(0.0, z0)
|
|
dist = [(a - b).length for a, b in zip(outer, inner)]
|
|
# across the band from the plateau edge (s 0) to the panel edge (s 1): (s, crown rise, rib)
|
|
S = [(1.0, 0.004, 0), (0.93, 0.0075, 0), (0.82, 0.0105, 0), (0.71, 0.012, 0), (0.66, 0.0122, 1), (0.61, 0.012, 0), (0.48, 0.0122, 0),
|
|
(0.35, 0.0102, 0), (0.3, 0.0098, 1), (0.25, 0.0092, 0), (0.12, 0.0055, 0)]
|
|
pre = rec_ring(0.04, ZR), rec_ring(0.008, ZR), rec_ring(0.0035, ZR + 0.0022)
|
|
pre = list(pre)
|
|
for s_, rise, rib in S:
|
|
ring = []
|
|
for a, b, dd in zip(outer, inner, dist):
|
|
cr = min(1.0, dd / 0.12) # the crown is lower where the band is narrow (in front of the engine)
|
|
kr = max(0.0, min(1.0, (dd - 0.075) / 0.04)) # no room for the ribs there
|
|
ring.append(a.lerp(b, s_) + Vector((0, 0, rise * cr * 1.35 + 0.0075 * rib * kr)))
|
|
pre.append(ring)
|
|
prof = [(-0.105, -0.7275), (-0.076, -0.728), (-0.067, -0.7222), (-0.057, -0.7222), (-0.048, -0.729),
|
|
(-0.038, -0.734), (-0.024, -0.745), (-0.012, -0.761), (-0.004, -0.779), (0.0, -0.8), (0.0, -0.866)]
|
|
cx_, cz_, rr_ = 0.0042, -0.8755, 0.0076
|
|
for a in (110, 20, -70, -175):
|
|
prof.append((cx_ + rr_ * math.cos(DEG(a)), cz_ + rr_ * math.sin(DEG(a))))
|
|
prof += [(-0.0032, -0.866), (-0.0032, -0.8), (-0.03, -0.741), (-0.105, -0.7318)]
|
|
rings = pre + [[Vector((x, YC + y, z)) for x, y, _ in rr_pts(HW + d, HD + d, 0.12 + d, nc=3, nf=(2, 1))] for d, z in prof]
|
|
npre = len(pre)
|
|
deck = rings_mesh("deck", rings, [M.red, M.redd], colfn=lambda i, j: 1 if (i < 2 or 11 + npre <= i <= 14 + npre) else 0, ang=34)
|
|
P.append(deck)
|
|
from mathutils.bvhtree import BVHTree
|
|
bpy.context.view_layer.update()
|
|
bvh = BVHTree.FromObject(deck, bpy.context.evaluated_depsgraph_get())
|
|
|
|
def on_deck(x, y):
|
|
hit = bvh.ray_cast(Vector((x, y, -0.5)), Vector((0, 0, -1)))
|
|
return (hit[0], hit[1]) if hit[0] is not None else (Vector((x, y, z0)), Vector((0, 0, 1)))
|
|
|
|
def plate(name, out, c, h, m, rings_=(0.55,), inset=0.0012, sink=0.0006, walls=True):
|
|
"""A transfer or a pressed pad lying on the deck: its outline (2D, round c) dropped onto the surface, a bevelled edge, a top
|
|
that follows the crown."""
|
|
c = Vector(c)
|
|
bm = bmesh.new()
|
|
RR = []
|
|
cen2 = Vector((c.x, c.y))
|
|
for ri, (f, up) in enumerate([(1.0, -sink)] + [(1.0, h)] + [(k, h) for k in rings_]):
|
|
if not walls and ri == 0:
|
|
continue
|
|
row = []
|
|
for u, v in out:
|
|
q = Vector((u, v))
|
|
if ri == 1:
|
|
q = q - q.normalized() * inset if q.length > inset * 2 else q
|
|
q = cen2 + q * f
|
|
p, n = on_deck(q.x, q.y)
|
|
row.append(bm.verts.new(p + n * up))
|
|
RR.append(row)
|
|
p, n = on_deck(c.x, c.y)
|
|
vc = bm.verts.new(p + n * h)
|
|
nn = len(out)
|
|
for a in range(len(RR) - 1):
|
|
for j in range(nn):
|
|
bm.faces.new((RR[a][j], RR[a][(j + 1) % nn], RR[a + 1][(j + 1) % nn], RR[a + 1][j]))
|
|
for j in range(nn):
|
|
bm.faces.new((RR[-1][j], RR[-1][(j + 1) % nn], vc))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
for f_ in bm.faces:
|
|
f_.normal_update()
|
|
if sum(f_.normal.z for f_ in bm.faces) < 0:
|
|
bmesh.ops.reverse_faces(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
smooth(o, 40)
|
|
P.append(o)
|
|
# a white bead pressed round the skirt
|
|
zb = [-0.846, -0.843, -0.818, -0.815]
|
|
db = [0.0004, 0.0032, 0.0032, 0.0004]
|
|
rings = [[Vector((x, YC + y, z)) for x, y, _ in rr_pts(HW + d, HD + d, 0.12 + d, nc=3, nf=(2, 1))] for d, z in zip(db, zb)]
|
|
P.append(rings_mesh("deckband", rings, [M.white], cap0=False, cap1=False, ang=50))
|
|
# decal panels on the crown between the ribs: white transfers, the maker's name on the right, the cutting heights on the left
|
|
for sx in (-1, 1):
|
|
cx = sx * 0.322
|
|
plate("decal", rrect(0.026, 0.15, 0.012, 2), (cx, YC - 0.03), 0.0009, M.white)
|
|
for k, (L, dy) in enumerate(((0.09, 0.06), (0.06, 0.02), (0.075, -0.035), (0.04, -0.075)) if sx > 0 else ((0.11, 0.05), (0.03, -0.02), (0.03, -0.06))):
|
|
plate("dtxt", rrect(0.0042 if k == 0 else 0.0028, L / 2, 0.0015, 1), (cx + (0.008 if k else 0.0) * (1 if k % 2 else -1), YC - 0.03 + dy), 0.0013,
|
|
M.red if sx > 0 else M.black, rings_=(), inset=0.0, walls=False)
|
|
# a warning transfer on the front of the deck
|
|
LB = (-0.3, -1.022)
|
|
plate("label", rrect(0.05, 0.022, 0.006, 2), LB, 0.0009, M.gold)
|
|
plate("labtri", rounded_outline([(0.0, 0.013), (-0.012, -0.008), (0.012, -0.008)], 0.0025, 1), (LB[0] - 0.026, LB[1]), 0.0014, M.black, rings_=(),
|
|
inset=0.0, walls=False)
|
|
for k in range(2):
|
|
plate("labtxt", rrect(0.018 - 0.005 * k, 0.002, 0.0012, 1), (LB[0] + 0.014, LB[1] + 0.005 - 0.01 * k), 0.0014, M.black, rings_=(), inset=0.0,
|
|
walls=False)
|
|
# the moulded height-adjust pads on the shoulder at each wheel, a white tick for each notch of the quadrant below
|
|
for x, y in ((0.57, -1.08), (-0.57, -1.08), (0.57, -0.52), (-0.57, -0.52)):
|
|
s = 1 if x > 0 else -1
|
|
py = y + (0.02 if y < -0.8 else -0.02)
|
|
plate("hpad", rrect(0.019, 0.04, 0.01, 2), (s * 0.49, py), 0.0022, M.redd, inset=0.0025)
|
|
for k in range(5):
|
|
plate("htick", rrect(0.0075 - (0.002 if k % 2 else 0.0), 0.0013, 0.0008, 1), (s * (0.493 + (0.002 if k % 2 else 0.0)), py - 0.028 + 0.014 * k), 0.0028,
|
|
M.white, rings_=(), inset=0.0, walls=False)
|
|
|
|
# ---- the engine: a vertical-shaft engine under a black shroud, cylinder head with fins and the plug poking out the front
|
|
sc = Vector((0.0, -0.83, 0.0))
|
|
srings = []
|
|
for hw, hd, rc, z in ((0.168, 0.148, 0.045, -0.736), (0.17, 0.15, 0.048, -0.725), (0.17, 0.15, 0.05, -0.645), (0.168, 0.148, 0.048, -0.641),
|
|
(0.17, 0.15, 0.05, -0.637), (0.17, 0.15, 0.05, -0.59), (0.167, 0.147, 0.049, -0.575), (0.159, 0.139, 0.046, -0.565),
|
|
(0.148, 0.128, 0.042, -0.5605), (0.13, 0.11, 0.036, -0.5595)):
|
|
srings.append([Vector((x, sc.y + y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(2, 2))])
|
|
P.append(rings_mesh("shroud", srings, [M.black], ang=36))
|
|
# cooling-air louvres in the shroud's front beside the head, a red primer bulb on the left, a maker's plate on the right
|
|
for k in range(4):
|
|
slot(P, Vector((0.1 + 0.014 * k, -0.9805, -0.632)), (0, -1, 0), (0, 0, 1), 0.05, 0.0072, 0.0014, M.plast)
|
|
|
|
P.append(rev("primer", [(0.0125, 0.003), (0.0135, 0.007), (0.0125, 0.012), (0.009, 0.0158), (0.0, 0.017)], Vector((-0.1705, -0.76, -0.612)), (-1, 0, 0), [M.red],
|
|
segs=12, ang=60))
|
|
P.append(bprism("badge", rrect(0.045, 0.018, 0.006, 1), -0.0006, 0.0016, [M.red], bev=0.0006, segs=1, frame=fz(Vector((0.1702, -0.85, -0.615)), (1, 0, 0), (0, 1, 0))))
|
|
P.append(bprism("badgeline", rrect(0.034, 0.0028, 0.0015, 1), 0.0016, 0.0024, [M.white], bev=0.0003, segs=1, frame=fz(Vector((0.1702, -0.85, -0.615)), (1, 0, 0), (0, 1, 0))))
|
|
# the engine's mounting bolts in the recessed panel, each on a washer
|
|
for sx in (-1, 1):
|
|
for yy in (-0.965, -0.695):
|
|
q = washer(P, Vector((sx * 0.185, yy, ZR - 0.0003)), (0, 0, 1), 0.0105, 0.0016, m=M.hw)
|
|
head(P, q, (0, 0, 1), 0.0052, "hex", m=M.hw, ref=(1, 0.3, 0))
|
|
# recoil starter on top: pressed white cover, vents, cap; the rope out of a guide on its side
|
|
recoil(P, Vector((0.0, -0.83, -0.5592)), (0, 0, 1), 0.108, 0.029, M, ref=(1, 0, 0), vents=5, cover=M.white, cap=M.d2)
|
|
ga = DEG(38)
|
|
gp = Vector((0.106 * math.cos(ga), -0.83 + 0.106 * math.sin(ga), -0.5465))
|
|
gn = Vector((math.cos(ga), math.sin(ga), 0.0))
|
|
P.append(rev("ropeguide", [(0.0068, -0.004), (0.0078, 0.0), (0.0074, 0.0035), (0.0052, 0.0052), (0.0034, 0.0045), (0.003, 0.0)], gp, gn, [M.d2], segs=12))
|
|
# fuel tank: two pressed halves crimped together, a filler neck, a knurled cap with a breather tab
|
|
tc = Vector((0.145, -0.685, 0.0))
|
|
tr = []
|
|
for hw, hd, rc, z in ((0.046, 0.056, 0.016, -0.662), (0.053, 0.063, 0.02, -0.656), (0.055, 0.065, 0.021, -0.645), (0.055, 0.065, 0.021, -0.618),
|
|
(0.055, 0.065, 0.021, -0.612), (0.055, 0.065, 0.021, -0.585), (0.051, 0.061, 0.019, -0.575), (0.042, 0.052, 0.015, -0.5705)):
|
|
tr.append([Vector((tc.x + x, tc.y + y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(1, 1))])
|
|
P.append(rings_mesh("tank", tr, [M.red], ang=40))
|
|
crimp_seam(P, [Vector((tc.x + x, tc.y + y, -0.615)) for x, y, _ in rr_pts(0.055, 0.065, 0.021, nc=3, nf=(1, 1))], (0, 0, 1), M.red, r=0.0021)
|
|
P.append(rev("neck", [(0.0125, -0.0035), (0.0125, 0.004), (0.0135, 0.0055), (0.0125, 0.007)], Vector((0.145, -0.685, -0.571)), (0, 0, 1), [M.d2], segs=14))
|
|
|
|
def knurl(i, a):
|
|
return 1.0 + (0.07 * math.cos(12 * a) if 1 <= i <= 3 else 0.0)
|
|
P.append(rev("tankcap", [(0.0135, 0.0), (0.0175, 0.0008), (0.0182, 0.004), (0.0182, 0.0125), (0.0168, 0.0158), (0.009, 0.0178), (0.0, 0.0182)],
|
|
Vector((0.145, -0.685, -0.5645)), (0, 0, 1), [M.black], segs=16, mod=knurl, ang=45))
|
|
P.append(bprism("captab", rounded_outline([(-0.004, -0.009), (0.004, -0.009), (0.004, 0.009), (-0.004, 0.009)], 0.0025, 1), 0.0, 0.007, [M.black],
|
|
bev=0.0012, segs=1, frame=Matrix.Translation((0.145, -0.685, -0.5475))))
|
|
# air filter on the front left: a cover with a ribbed lid and a screw, on a base, a hose to the carburettor
|
|
fc = Vector((-0.17, -0.885, 0.0))
|
|
fr = []
|
|
for hw, hd, rc, z in ((0.049, 0.064, 0.017, -0.682), (0.05, 0.065, 0.018, -0.656), (0.053, 0.068, 0.019, -0.654),
|
|
(0.053, 0.068, 0.019, -0.648), (0.05, 0.065, 0.018, -0.646), (0.049, 0.064, 0.018, -0.612), (0.045, 0.06, 0.016, -0.603),
|
|
(0.036, 0.051, 0.012, -0.6)):
|
|
fr.append([Vector((fc.x + x, fc.y + y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(1, 1))])
|
|
P.append(rings_mesh("filter", fr, [M.d2, M.d1], colfn=lambda i, j: 1 if i in (1, 2, 3) else 0, ang=40))
|
|
for k in range(4):
|
|
y0 = fc.y - 0.045 + 0.03 * k
|
|
C = [Vector((fc.x - 0.032, y0, -0.6005)), Vector((fc.x + 0.032, y0, -0.6005))]
|
|
P.append(sweep("frib", C, lambda s, i: [(0.0028, -0.0006), (0.0018, 0.0022), (-0.0018, 0.0022), (-0.0028, -0.0006)], [M.d2], ref=(0, 1, 0), ang=50))
|
|
P.append(rev("fscrew", [(0.0, 0.0), (0.009, 0.0), (0.0095, 0.003), (0.007, 0.006), (0.0, 0.0065)], Vector((fc.x, fc.y, -0.6005)), (0, 0, 1), [M.black], segs=8,
|
|
mod=lambda i, a: 1.0 + (0.12 * math.cos(6 * a) if i in (1, 2) else 0.0)))
|
|
# muffler at the back left, its shield, a spout pointing down and back
|
|
muffler(P, Vector((-0.17, -0.705, -0.66)), (0, 1, 0), 0.029, 0.075, M, ref=(0, 0, 1), spout=((-0.17, -0.632, -0.668), (-0.17, -0.618, -0.688)), holes=False)
|
|
|
|
# the cylinder: fins on the barrel and the head poking out of the front of the shroud, head bolts, the plug and its lead
|
|
fin_stack(P, Vector((0.0, -0.986, -0.668)), (0, -1, 0), (1, 0, 0), 0.13, 0.092, 0.012, 5, 0.0082, 0.0034, 0.004, M.d1,
|
|
core=(0.05, 0.034), mat_core=M.d1)
|
|
hc = Vector((0.0, -1.03, -0.668))
|
|
P.append(bprism("head", rrect(0.056, 0.04, 0.014, 3), 0.0, 0.012, [M.d1, M.d2], bev=0.003, segs=2, frame=fz(hc + Vector((0, 0.012, 0)), (0, -1, 0), (1, 0, 0)), bev_slot=1))
|
|
for sx in (-1, 1):
|
|
for sz in (-1, 1):
|
|
head(P, hc + Vector((sx * 0.04, -0.0005, sz * 0.025)), (0, -1, 0), 0.0034, "hex", m=M.hw, ref=(1, 0, 0))
|
|
spark_plug(P, hc + Vector((0.0, -0.001, 0.009)), (0, -1, 0.42), M,
|
|
lead=[(0.0, -1.075, -0.636), (-0.03, -1.07, -0.62), (-0.075, -1.0, -0.6), (-0.095, -0.985, -0.605)])
|
|
P.append(rev("grommet", [(0.0042, -0.002), (0.0068, 0.0), (0.007, 0.003), (0.0042, 0.004)], Vector((-0.095, -0.979, -0.605)), (0, -1, 0), [M.rub], segs=10))
|
|
# control bracket on the back of the shroud: a plate, the lever the cable pulls, a spring, the cable clamp
|
|
cb = Vector((-0.085, -0.678, -0.612))
|
|
P.append(bprism("ctlplate", rounded_outline([(-0.022, -0.018), (0.022, -0.018), (0.022, 0.016), (-0.022, 0.016)], 0.006, 1), -0.0015, 0.0015, [M.d2],
|
|
bev=0.0, segs=1, frame=fz(cb, (0, 1, 0), (1, 0, 0))))
|
|
|
|
P.append(tube5("ctllever", [cb + Vector((0.004, 0.004, 0.0)), cb + Vector((0.016, 0.006, 0.012)), cb + Vector((0.02, 0.006, 0.026))], 0.0026, M.hw, segs=8, bend=0.006))
|
|
# ---- the deck's rear chute into the bag: a rounded tunnel with a flange round its mouth, bolted
|
|
C = [Vector((0.0, -0.468, -0.792)), Vector((0.0, -0.43, -0.792)), Vector((0.0, -0.392, -0.79))]
|
|
|
|
def chsec(s, i):
|
|
return rrect(0.168 - 0.002 * s, 0.066 - 0.002 * s, 0.03, 3)
|
|
P.append(sweep("chute", C, chsec, [M.d1], ref=(1, 0, 0), ang=40))
|
|
fl = [Vector((0.0, -0.392, -0.79)), Vector((0.0, -0.384, -0.79))]
|
|
P.append(sweep("chflange", fl, lambda s, i: rrect(0.18, 0.078, 0.036, 3), [M.d1, M.d2], colfn=lambda i, j: 1 if j < 0 else 0, ref=(1, 0, 0), ang=40))
|
|
|
|
# a hinged flap over the chute's top, its rod in two knuckles and a coil spring
|
|
hz = -0.718
|
|
P.append(tube5("hingerod", [(-0.19, -0.462, hz), (0.19, -0.462, hz)], 0.0038, M.hw, segs=8))
|
|
for sx in (-1, 1):
|
|
P.append(rev("knuckle", [(0.0048, -0.008), (0.0068, -0.007), (0.0072, 0.0), (0.0068, 0.007), (0.0048, 0.008)], Vector((sx * 0.175, -0.462, hz)), (1, 0, 0),
|
|
[M.d1], segs=8))
|
|
|
|
flap = [Vector((0.0, -0.462, hz)), Vector((0.0, -0.44, hz - 0.002)), Vector((0.0, -0.41, hz - 0.004))]
|
|
P.append(sweep("flap", flap, lambda s, i: rrect(0.172, 0.0022, 0.0018, 1), [M.d1], ref=(1, 0, 0), ang=40))
|
|
|
|
# ---- wheels' stub axles and the height levers in notched quadrants on the skirt
|
|
hubs = {"Wheel_FL": (0.57, -1.08), "Wheel_FR": (-0.57, -1.08), "Wheel_RL": (0.57, -0.52), "Wheel_RR": (-0.57, -0.52)}
|
|
R = 0.1
|
|
for n_, (x, y) in hubs.items():
|
|
s = 1 if x > 0 else -1
|
|
zc = G + R
|
|
X = Vector((s, 0, 0))
|
|
P.append(tube5("axle", [(s * 0.5, y, zc), (s * 0.556, y, zc)], 0.0085, M.hw, segs=6))
|
|
# the quadrant: a plate bolted to the skirt, five notches along its arc
|
|
Fq = Matrix((Vector((0, 1, 0)), Vector((0, 0, 1)), X)).transposed().to_4x4()
|
|
Fq.translation = Vector((s * 0.5345, y, zc))
|
|
arc = []
|
|
for k in range(6):
|
|
a = DEG(40 + 70 * k / 5)
|
|
rr = 0.105 - (0.007 if k in (2, 4) else 0.0)
|
|
|
|
arc.append((rr * math.cos(a), rr * math.sin(a)))
|
|
out = [(0.03, -0.012), (0.03, 0.03)] + arc + [(-0.012, 0.03), (-0.012, -0.012)]
|
|
Fl = Fq @ Matrix.Diagonal((1, 1, s, 1)) if s < 0 else Fq
|
|
P.append(bprism("quadrant", out, -0.0035, 0.0, [M.d2, M.st], bev=0.0009, segs=1, frame=Fl, bev_slot=1, min_ang=30))
|
|
for p in ((0.018, 0.0),):
|
|
head(P, Fq @ Vector((p[0], p[1], 0.0)), X, 0.0034, "hex", m=M.hw, ref=(0, 1, 0))
|
|
# the lever: a flat bar from the axle up through the notch, a moulded knob, a washer and nut on the pivot
|
|
tip = Vector((s * 0.5395, y + 0.05, zc + 0.104))
|
|
lv = [Vector((s * 0.5395, y, zc)), Vector((s * 0.5395, y + 0.03, zc + 0.065)), tip]
|
|
P.append(sweep("lever", fillet(lv, 0.05, 2), lambda sf, i: rrect(0.0022, 0.0075, 0.0018, 1), [M.st], ref=(1, 0, 0), ang=40))
|
|
q = washer(P, Vector((s * 0.5418, y, zc)), X, 0.012, 0.0016, m=M.hw)
|
|
hexnut(P, q, X, 0.0105, 0.0065, m=M.hw, ref=(0, 1, 0))
|
|
d = (tip - lv[1]).normalized()
|
|
P.append(rev("leverknob", [(0.0, -0.002), (0.0085, 0.0), (0.0125, 0.008), (0.0125, 0.022), (0.0095, 0.029), (0.0, 0.031)],
|
|
tip - d * 0.004, d, [M.black], segs=6, ang=50))
|
|
|
|
|
|
# ---- the handle
|
|
# grip bar: a tube, foam grips with flared collars, pivot clips for the bail past their ends, end plugs
|
|
P.append(tube5("gripbar", [(-0.296, 0.0, 0.0), (0.296, 0.0, 0.0)], 0.0155, M.tube, segs=14, cap0=False, cap1=False))
|
|
for sg in (-1, 1):
|
|
def gm(i, a):
|
|
return 1.0
|
|
xs = [0.094, 0.098, 0.104, 0.108] + [0.112 + 0.0105 * k for k in range(14)] + [0.255, 0.258]
|
|
prof = [(0.0158, 0.0), (0.0235, 0.002), (0.0245, 0.006), (0.0215, 0.011)]
|
|
for k in range(9):
|
|
prof.append((0.0212 + (0.0015 if k % 2 == 0 else 0.0) + 0.0012 * math.sin(PI * k / 8), 0.016 + 0.017 * k))
|
|
prof += [(0.0222, 0.157), (0.0175, 0.159)]
|
|
P.append(rev("grip", prof, Vector((sg * 0.094, 0.0, 0.0)), (sg, 0, 0), [M.rub], segs=10, ang=50))
|
|
# bail pivot clip: a moulded block clamped round the bar, a screw through it
|
|
cpos = Vector((sg * 0.27, 0.0, 0.0))
|
|
P.append(rev("pclip", [(0.0158, -0.012), (0.0195, -0.011), (0.0215, -0.008), (0.0218, 0.008), (0.0195, 0.011), (0.0158, 0.012)], cpos, (1, 0, 0),
|
|
[M.black], segs=8, ang=40))
|
|
P.append(bprism("pclipboss", rounded_outline([(-0.012, -0.004), (0.012, -0.004), (0.012, 0.024), (-0.012, 0.024)], 0.008, 1), -0.009, 0.009, [M.black],
|
|
bev=0.002, segs=1, frame=fz(cpos + Vector((0, 0, -0.008)), (1, 0, 0), (0, -1, -0.6))))
|
|
head(P, cpos + Vector((sg * 0.0, -0.016, -0.026)) + Vector((-sg * 0.0095, 0, 0)), (-sg, 0, 0), 0.0024, "dome", m=M.hw)
|
|
P.append(rev("endplug", [(0.0, 0.0), (0.0158, 0.0), (0.0168, 0.002), (0.0165, 0.0065), (0.012, 0.0095), (0.0, 0.0105)], Vector((sg * 0.296, 0.0, 0.0)),
|
|
(sg, 0, 0), [M.black], segs=8, ang=50))
|
|
# the tee: a cast sleeve on the bar, a socket down the shaft, a bolt through
|
|
sh0, J = Vector((0.0, -0.02, -0.02)), Vector((0.0, -0.38, -0.56))
|
|
dsh = (J - sh0).normalized()
|
|
P.append(rev("teesleeve", [(0.0156, -0.042), (0.0215, -0.041), (0.0242, -0.036), (0.0248, 0.0), (0.0242, 0.036), (0.0215, 0.041), (0.0156, 0.042)],
|
|
Vector((0, 0, 0)), (1, 0, 0), [M.d1], segs=12, ang=40))
|
|
|
|
P.append(rev("teesock", [(0.0225, -0.002), (0.0232, 0.012), (0.0218, 0.046), (0.0228, 0.05), (0.0228, 0.056), (0.0198, 0.06)], sh0 - dsh * 0.0, dsh,
|
|
[M.d1], segs=12, ang=40))
|
|
nb = dsh.cross(Vector((1, 0, 0))).normalized()
|
|
bolt5(P, sh0 + dsh * 0.04 + Vector((0.0235, 0, 0)), (1, 0, 0), 0.047, 0.0042, kind="hex", m=M.hw, ref=nb, thr=0.004)
|
|
# shaft, yoke and the two lower arms, bends, flattened ends into brackets with knob nuts
|
|
P.append(tube5("shaft", [sh0 + dsh * 0.03, J], 0.019, M.tube, segs=14, cap0=False))
|
|
P.append(rev("yokesock", [(0.0205, -0.05), (0.0232, -0.046), (0.0238, -0.01), (0.026, 0.0), (0.03, 0.012)], J, dsh, [M.d1], segs=12, ang=40))
|
|
P.append(bprism("yoke", rounded_outline([(-0.05, -0.03), (0.05, -0.03), (0.05, 0.02), (-0.05, 0.02)], 0.016, 2), -0.022, 0.022, [M.d1, M.d2],
|
|
bev=0.0045, segs=1, frame=fz(J + Vector((0, -0.004, -0.012)), (0, -0.25, 1), (1, 0, 0)), bev_slot=1))
|
|
for sx in (-1, 1):
|
|
head(P, J + Vector((sx * 0.032, -0.03, 0.008)), (0, -0.55, 0.85), 0.0042, "hex", m=M.hw, ref=(1, 0, 0))
|
|
for s in (-1, 1):
|
|
A0 = J + Vector((s * 0.04, -0.008, -0.022))
|
|
end = Vector((s * 0.42, -0.488, -0.708))
|
|
pts = [A0, Vector((s * 0.2, -0.42, -0.62)), end]
|
|
C = densify(fillet(pts, 0.12, 4), 0.08)
|
|
Lc = arclen(C)[-1]
|
|
|
|
def armsec(sf, i, Lc=Lc):
|
|
x = sf * Lc
|
|
k = max(0.0, min(1.0, (x - (Lc - 0.06)) / 0.04)) # flattened over the last 4-6 cm
|
|
ci = circ(0.015, 10)
|
|
fl = rrect(0.0055, 0.0175, 0.005, 2)
|
|
return [(a * (1 - k) + c_ * k, b * (1 - k) + d_ * k) for (a, b), (c_, d_) in zip(ci, fl)]
|
|
P.append(sweep("arm", C, armsec, [M.tube], ref=(1, 0, 0), ang=45))
|
|
# the bracket: a base plate on the deck, two lugs welded on (beads), a bolt across with a star knob
|
|
bc = Vector((s * 0.42, -0.488, -0.7268))
|
|
P.append(bprism("brkbase", rounded_outline([(-0.032, -0.03), (0.032, -0.03), (0.032, 0.03), (-0.032, 0.03)], 0.01, 1), 0.0, 0.004, [M.d1, M.d2],
|
|
bev=0.0012, segs=1, frame=Matrix.Translation(bc), bev_slot=1))
|
|
|
|
eye = Vector((s * 0.42, -0.488, -0.7))
|
|
hp, Lb = clevis(P, eye, (0, 0, 1), (1, 0, 0), 0.03, 0.004, 0.024, 0.012, 0.0118, m=M.d1, bead_m=M.d2, bead_at=0.022)
|
|
q = washer(P, hp if s > 0 else hp - Vector((Lb, 0, 0)), (s, 0, 0), 0.008, 0.0014, m=M.hw)
|
|
head(P, q, (s, 0, 0), 0.0046, "hex", m=M.hw, ref=(0, 0, 1))
|
|
far = (hp - Vector((Lb, 0, 0))) if s > 0 else hp
|
|
q = washer(P, far, (-s, 0, 0), 0.008, 0.0014, m=M.hw)
|
|
knob_nut(P, q, (-s, 0, 0), 0.016, M.black, ref=(0, 0, 1))
|
|
# the bail: a red bar in front of the grips, its legs turning back into the pivot clips, a tab where the cable hooks on
|
|
BY_, BZ_ = -0.074, -0.03
|
|
bail = [(-0.27, -0.006, -0.024), (-0.273, -0.05, -0.033), (-0.266, BY_, BZ_), (0.266, BY_, BZ_), (0.273, -0.05, -0.033), (0.27, -0.006, -0.024)]
|
|
P.append(tube5("bail", bail, 0.0092, M.red, segs=8, bend=0.02, nb=3))
|
|
for sg in (-1, 1):
|
|
P.append(rev("bailend", [(0.0092, 0.0), (0.0104, 0.002), (0.0098, 0.0048), (0.0, 0.0054)], Vector((sg * 0.27, -0.006, -0.024)), (0, 1, 0.5),
|
|
[M.black], segs=10))
|
|
# a moulded rubber grip on the bail in front of each hand grip: end collars, a fat ribbed middle
|
|
gp_ = [(0.0098, 0.0), (0.0128, 0.002), (0.0132, 0.008), (0.0118, 0.012)]
|
|
for k in range(4):
|
|
z_ = 0.024 + 0.027 * k
|
|
gp_ += [(0.0124, z_ - 0.004), (0.0131, z_), (0.0124, z_ + 0.004)]
|
|
gp_ += [(0.0118, 0.118), (0.0132, 0.122), (0.0128, 0.128), (0.0098, 0.13)]
|
|
P.append(rev("bailgrip", gp_, Vector((sg * 0.243, BY_, BZ_)), (-sg, 0, 0), [M.rub], segs=7, ang=50))
|
|
tab = Vector((0.03, BY_, BZ_))
|
|
P.append(bprism("bailtab", rounded_outline([(-0.008, 0.0), (0.008, 0.0), (0.006, 0.022), (-0.006, 0.022)], 0.004, 2), -0.0016, 0.0016, [M.d2],
|
|
bev=0.0007, segs=1, frame=fz(tab, (1, 0, 0), (0, 0.2, -1)) @ Matrix.Rotation(DEG(90), 4, "Z")))
|
|
# the cable: from the tab back along the shaft, held by clips, out to the control bracket on the engine
|
|
cp = [tab + Vector((0.0, 0.002, -0.02)), Vector((0.03, -0.06, -0.075)), Vector((0.028, -0.1, -0.14))]
|
|
cp += [sh0 + dsh * k + Vector((0.026, 0.0, 0.0)) for k in (0.2, 0.32, 0.45, 0.55)]
|
|
cp += [Vector((0.03, -0.39, -0.555)), Vector((0.012, -0.47, -0.6)), Vector((-0.04, -0.6, -0.6)), Vector((-0.08, -0.665, -0.61))]
|
|
Cc = resample(cp, 20)
|
|
P.append(sweep("cable", Cc, lambda s, i: circ(0.0036, 6), [M.black], ang=60))
|
|
P.append(rev("cablend", [(0.0036, -0.006), (0.0052, -0.004), (0.0052, 0.004), (0.0036, 0.006)], Cc[-1] + Vector((0.0, 0.0, 0.0)), (Cc[-1] - Cc[-2]), [M.hw], segs=10))
|
|
for k in (0.24, 0.42):
|
|
c = sh0 + dsh * k
|
|
clip_band(P, c, dsh, 0.019, 0.012, M.black, ear=(1, 0, 0), screw_m=M.hw)
|
|
# the cable runs through the clip's tab
|
|
# a rope guide on the shaft with the pull handle resting in it; the rope from the starter's guide
|
|
rg = sh0 + dsh * 0.36
|
|
clip_band(P, rg, dsh, 0.019, 0.014, M.black)
|
|
hook = rg + Vector((-0.031, 0.0, 0.0))
|
|
P.append(bprism("rguide", rounded_outline([(-0.012, -0.007), (0.012, -0.007), (0.012, 0.007), (-0.012, 0.007)], 0.005, 1), -0.004, 0.004, [M.black],
|
|
bev=0.0015, segs=1, frame=fz(rg + Vector((-0.024, 0, 0)), (1, 0, 0), dsh)))
|
|
P.append(rev("rguide_eye", [(0.0042, -0.0045), (0.0072, -0.004), (0.0078, 0.0), (0.0072, 0.004), (0.0042, 0.0045)], hook, dsh, [M.black], segs=12))
|
|
ph = hook - dsh * 0.022
|
|
rope_line(P, [gp + gn * 0.006, gp + gn * 0.03 + Vector((0, 0.04, 0.02)), hook - dsh * 0.03 + Vector((-0.004, 0.0, -0.01)), hook + dsh * 0.004], 0.0034, M.white, segs=5)
|
|
pull_handle(P, ph + Vector((-0.004, 0.0, -0.006)), (1, 0, 0), M, L=0.07, r=0.0095, m=M.black)
|
|
|
|
# ---- the bag hanger: a bar under the shaft, welded on, the catcher's hooks hanging from it
|
|
hgc = sh0 + dsh * 0.5 + Vector((0, 0, -0.028))
|
|
P.append(tube5("hanger", [hgc + Vector((-0.165, 0, 0)), hgc + Vector((0.165, 0, 0))], 0.0065, M.d2, segs=10))
|
|
P.append(bprism("hangerplate", rounded_outline([(-0.018, -0.03), (0.018, -0.03), (0.018, 0.012), (-0.018, 0.012)], 0.008, 1), -0.003, 0.003, [M.d2],
|
|
bev=0.0, segs=1, frame=fz(sh0 + dsh * 0.5 + Vector((0, 0, -0.012)), (1, 0, 0), (0, 0, 1))))
|
|
|
|
|
|
# ---- the catcher: a hard tray, fabric walls bulging between piped corner seams, the hem rolled over the frame, stitching
|
|
BX, BY0, BY1, BZ0, BZ1 = 0.23, -0.37, -0.05, -0.9, -0.62
|
|
bc = (BY0 + BY1) / 2
|
|
hd = (BY1 - BY0) / 2
|
|
NF = (2, 1)
|
|
|
|
tray = [(BX - 0.03, hd - 0.03, 0.04, BZ0, 0.0), (BX - 0.012, hd - 0.012, 0.05, BZ0 + 0.003, 0.0), (BX - 0.002, hd - 0.002, 0.056, BZ0 + 0.013, 0.0),
|
|
(BX + 0.002, hd + 0.002, 0.058, -0.862, 0.0), (BX + 0.005, hd + 0.005, 0.06, -0.858, 0.0), (BX + 0.005, hd + 0.005, 0.06, -0.853, 0.0),
|
|
(BX - 0.004, hd - 0.004, 0.056, -0.852, 0.0)]
|
|
rings = [rr_ring(a, b, c, z, (0.0, bc), nc=3, nf=NF, bulge=g) for a, b, c, z, g in tray]
|
|
P.append(rings_mesh("tray", rings, [M.plast], ang=40, cap1=False))
|
|
wall = [(BX - 0.002, -0.857, 0.0), (BX + 0.003, -0.84, 0.006), (BX + 0.006, -0.8, 0.012), (BX + 0.006, -0.74, 0.012), (BX + 0.004, -0.68, 0.009),
|
|
(BX + 0.001, -0.64, 0.004), (BX + 0.0, -0.628, 0.0)]
|
|
hem = [(BX + 0.012, -0.622, 0.0), (BX + 0.013, -0.61, 0.0), (BX + 0.004, -0.6035, 0.0), (BX - 0.008, -0.606, 0.0), (BX - 0.013, -0.618, 0.0)]
|
|
inner = [(BX - 0.012, -0.64, 0.0), (BX - 0.016, -0.84, 0.0)]
|
|
|
|
seq = wall + hem + inner
|
|
rings = []
|
|
for w, z, g in seq:
|
|
dw = w - BX
|
|
rings.append(rr_ring(BX + dw, hd + dw, 0.06 + dw * 0.5, z, (0.0, bc), nc=3, nf=NF, bulge=g))
|
|
P.append(rings_mesh("bag", rings, [M.fab], ang=55, cap0=False))
|
|
# piping down the four corners, stitched both sides
|
|
for cx_s, cy_s in ((1, 1), (-1, 1), (-1, -1), (1, -1)):
|
|
q = []
|
|
for w, z, g in wall:
|
|
dw = w - BX
|
|
ex, ey, r_ = BX + dw, hd + dw, 0.06 + dw * 0.5
|
|
q.append(Vector((cx_s * (ex - r_ + r_ * 0.7071 + 0.0008), bc + cy_s * (ey - r_ + r_ * 0.7071 + 0.0008), z)))
|
|
q = [qq for qq in q if qq.z < -0.632]
|
|
P.append(sweep("piping", q, lambda s, i: circ(0.0042, 5), [M.fab], ref=(0, 0, 1), ang=60))
|
|
# stitching under the hem and above the tray
|
|
for z, lift in ((-0.634, 0.0055), (-0.846, 0.003)):
|
|
pts = [Vector((x, bc + y, z)) for x, y, _ in rr_pts(BX + lift, hd + lift, 0.06 + lift * 0.5, nc=4, nf=(6, 4))]
|
|
pts.append(pts[0])
|
|
P.append(stitches("stitch", pts, lambda p, bc=bc: Vector((p.x, p.y - bc, 0.0)), M.thr, step=0.04 if z > -0.7 else 0.05))
|
|
|
|
|
|
# the label on the back panel, stitched round
|
|
lb = Vector((0.0, BY1 + 0.0172, -0.742))
|
|
P.append(bprism("baglabel", rrect(0.095, 0.034, 0.01, 2), -0.004, 0.0018, [M.red], bev=0.0008, segs=1, frame=fz(lb, (0, 1, 0), (1, 0, 0))))
|
|
P.append(bprism("labelband", rrect(0.07, 0.006, 0.003, 2), 0.0018, 0.0026, [M.white], bev=0.0004, segs=1, frame=fz(lb, (0, 1, 0), (1, 0, 0))))
|
|
pts = [lb + Vector((x, 0.0021, z)) for x, z in [(p[0], p[1]) for p in rrect(0.088, 0.027, 0.007, 2)]]
|
|
|
|
pts.append(pts[0])
|
|
P.append(stitches("lstitch", pts, lambda p: (0, 1, 0), M.thr, step=0.015, L=0.0065, w=0.0018, lift=0.0005))
|
|
# the frame shows where the hooks come out of the hem; the hooks run up to the hanger
|
|
for s in (-1, 1):
|
|
a = Vector((s * 0.15, BY0 + 0.004, BZ1 + 0.018))
|
|
b = hgc + Vector((s * 0.15, 0.0, 0.0))
|
|
pts = [a, a + Vector((0, 0, 0.04)), b + Vector((0, -0.006, -0.03)), b + Vector((0, 0.0, -0.0075)), b + Vector((0, 0.009, 0.0)), b + Vector((0, 0.003, 0.0085))]
|
|
P.append(tube5("baghook", pts, 0.0034, M.d2, segs=4, bend=0.008, nb=2))
|
|
P.append(rev("hookferrule", [(0.0035, -0.006), (0.0058, -0.005), (0.006, 0.004), (0.0035, 0.006)], a + Vector((0, 0, 0.006)), (0, 0, 1), [M.black], segs=8))
|
|
parts_report(P, "Body")
|
|
o = tfin4(P, "Body", uv=2.4, ang=32)
|
|
|
|
# ---- Blade: a bar, ground edges at both ends, sails bent up at the trailing edge, a boss adapter, the centre bolt and washer
|
|
zb = -0.895
|
|
B = []
|
|
B.append(rev("adapter", [(0.0, -0.0075), (0.05, -0.0075), (0.056, -0.0045), (0.058, 0.0), (0.04, 0.003), (0.03, 0.008), (0.024, 0.0122), (0.0, 0.0122)],
|
|
Vector((0.0, YC, zb)), (0, 0, 1), [M.d2], segs=12, ang=40))
|
|
for sg in (-1, 1):
|
|
rings_b = []
|
|
n = 8
|
|
for i in range(n + 1):
|
|
u = i / n
|
|
x = sg * (0.03 + 0.3 * u)
|
|
w = 0.025
|
|
lift = 0.0 if u < 0.72 else (u - 0.72) / 0.28
|
|
sail = 0.026 * lift ** 1.5
|
|
edge_k = 0.0 if u < 0.55 else min(1.0, (u - 0.55) / 0.06)
|
|
# section across Y: leading edge (towards the spin) ground thin, trailing edge bent up into the sail
|
|
le = -sg # the blade spins +Z: at +X the leading side is +Y... keep it simple: leading on -sg*Y
|
|
t = 0.003
|
|
pts = []
|
|
pts.append((YC + le * w, zb + t * (1 - 0.85 * edge_k)))
|
|
pts.append((YC + le * w * (1 - 0.35 * edge_k), zb + t))
|
|
pts.append((YC - le * w * 0.55, zb + t))
|
|
pts.append((YC - le * w * (0.9), zb + t + sail * 0.55))
|
|
pts.append((YC - le * w * (1.0 + 0.1 * lift), zb + t + sail))
|
|
pts.append((YC - le * w * (1.0 + 0.1 * lift) - le * 0.0008, zb + sail - 0.0005))
|
|
pts.append((YC - le * w * 0.86, zb - t + sail * 0.5))
|
|
pts.append((YC - le * w * 0.5, zb - t))
|
|
pts.append((YC + le * w * (1 - 0.35 * edge_k), zb - t))
|
|
pts.append((YC + le * w, zb - t * (1 - 0.85 * edge_k)))
|
|
rings_b.append([Vector((x, y, z)) for y, z in pts])
|
|
tipr = [Vector((r.x + sg * 0.0025, r.y, r.z)) for r in rings_b[-1]]
|
|
rings_b.append(tipr)
|
|
B.append(rings_mesh("blade", rings_b, [M.st, M.br], colfn=lambda i, j, n=n: 1 if (j in (0, 8, 9) and i > n * 0.55) else 0, ang=30))
|
|
q = washer(B, Vector((0.0, YC, zb - 0.0035)), (0, 0, -1), 0.024, 0.003, m=M.hw)
|
|
head(B, q, (0, 0, -1), 0.008, "hex", m=M.hw, ref=(1, 0, 0))
|
|
blade = tfin4(B, "Blade", uv=2.4, ang=30)
|
|
set_origin(blade, (0, YC, zb))
|
|
|
|
# ---- wheels
|
|
for n_, (x, y) in hubs.items():
|
|
W_ = []
|
|
tread_tyre(W_, M, 1 if x > 0 else -1, R=R, W=0.044, pitches=10)
|
|
w = tfin4(W_, n_, uv=2.4, ang=34)
|
|
w.location = (x, y, G + R)
|
|
|
|
# ---- Fill: the clippings heaped in the catcher, origin on its floor
|
|
fill5(-BX + 0.04, BX - 0.04, BY0 + 0.04, BY1 - 0.04, BZ0 + 0.045, BZ1 - 0.035, BZ1 + 0.008)
|
|
return {}
|
|
|
|
|
|
# ======================================================================= farm machines: shared parts
|
|
|
|
def parts_report(P, name):
|
|
if os.environ.get("GC_PARTS"): # triangle count per part, for trimming
|
|
cnt = {}
|
|
for q in P:
|
|
if q is not None:
|
|
k = q.name.split(".")[0]
|
|
cnt[k] = cnt.get(k, 0) + sum(len(f.vertices) - 2 for f in q.data.polygons)
|
|
print("PARTS", name, sum(cnt.values()), sorted(cnt.items(), key=lambda kv: -kv[1]))
|
|
|
|
|
|
def ffin(P, name, uv=4.0, ang=42):
|
|
"""gc_farm_tools.done (box UVs for parts without their own, one UV layer, join) plus weighted normals for the bevels."""
|
|
if os.environ.get("GC_PARTS"): # triangle count per part, for trimming
|
|
cnt = {}
|
|
for q in P:
|
|
if q is not None:
|
|
k = q.name.split(".")[0]
|
|
cnt[k] = cnt.get(k, 0) + sum(len(f.vertices) - 2 for f in q.data.polygons)
|
|
print("PARTS", name, sorted(cnt.items(), key=lambda kv: -kv[1]))
|
|
o = FT.done([q for q in P if q is not None], name, uv=uv, ang=ang)
|
|
weighted(o)
|
|
return o
|
|
|
|
|
|
def place(parts, M4):
|
|
for o in parts:
|
|
apply_xform(o)
|
|
o.data.transform(M4)
|
|
return parts
|
|
|
|
|
|
def timber(o, along, s=2.4):
|
|
FT.grain(o, along, s)
|
|
return o
|
|
|
|
|
|
def hbolt(P, M, a, n, L, r, ref=None, nut=True, thr=None, w_head=True):
|
|
"""bolt5 in the farm palette: steel washers, head and nut, the thread poking out."""
|
|
bolt5(P, a, n, L, r, kind="hex", m=M.hw, m_nut=M.hw, m_thr=M.st, w_head=w_head, nut=nut, thr=thr, ref=ref)
|
|
|
|
|
|
def dome8(P, c, n, r, m):
|
|
"""A low domed head (carriage bolt, rivet), cheaper than head(..., "dome")."""
|
|
P.append(rev("dome", [(r * 1.75, -0.0004), (r * 1.62, r * 0.42), (r * 1.1, r * 0.86), (0.0, r * 1.02)], c, n, [m], segs=8, ang=50))
|
|
|
|
|
|
def cbolt(P, M, a, n, r, L=None, m=None):
|
|
"""A carriage bolt through timber: a domed head on n, a square neck sunk in the wood; the nut and washer on the far side if L."""
|
|
dome8(P, a, n, r, m or M.hw)
|
|
if L:
|
|
n = Vector(n).normalized()
|
|
b = Vector(a) - n * L
|
|
q = washer(P, b, -n, r * 2.1, r * 0.35, m=M.hw)
|
|
q = hexnut(P, q, -n, r * 1.8, r * 1.4, m=M.hw)
|
|
thread(P, q - (-n) * 0.002, -n, r * 0.9, r * 1.2 + 0.002, m=M.st)
|
|
|
|
|
|
def grain5(o, along, c, s=2.0, board=0, v0=0.5):
|
|
"""gc_farm_tools.grain measured from the timber's own centre: across the part U stays inside one of the texture's four boards
|
|
(no board line down a face), along it V stays inside one tile of the texture (no seam half way along)."""
|
|
d = Vector(along).normalized()
|
|
a = d.orthogonal().normalized()
|
|
b = d.cross(a)
|
|
c = Vector(c)
|
|
u0 = 0.125 + 0.25 * (board % 4)
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
uv = bm.loops.layers.uv.verify()
|
|
for f in bm.faces:
|
|
ua = a if abs(f.normal.dot(a)) < abs(f.normal.dot(b)) else b
|
|
for l in f.loops:
|
|
q = l.vert.co - c
|
|
l[uv].uv = (u0 + q.dot(ua) * s, v0 + q.dot(d) * s)
|
|
bm.to_mesh(o.data)
|
|
bm.free()
|
|
o["uv_done"] = True
|
|
return o
|
|
|
|
|
|
def timber5(P, M, lo, hi, axis, ch=0.004, ends=(True, True), s=2.0, off=(0.0, 0.0), seed=0, bow=0.0012, name="beam"):
|
|
"""A sawn timber from corner lo to corner hi, its grain along `axis` (0 = X, 1 = Y): every long edge chamfered, a slight bow and
|
|
twist (no timber is dead straight), the sawn ends closed by end grain (growth rings round a pith off to one side)."""
|
|
lo, hi = Vector(lo), Vector(hi)
|
|
c = (lo + hi) / 2
|
|
hs = (hi - lo) / 2
|
|
a_ax = 1 - axis if axis in (0, 1) else 0 # the other horizontal axis
|
|
ha, hb = hs[a_ax], hs[2]
|
|
ch = min(ch, ha * 0.4, hb * 0.4)
|
|
sec = [(ha, -hb + ch), (ha, hb - ch), (ha - ch, hb), (-ha + ch, hb), (-ha, hb - ch), (-ha, -hb + ch), (-ha + ch, -hb), (ha - ch, -hb)]
|
|
rnd = random.Random(seed)
|
|
ph = rnd.uniform(0, TAU)
|
|
A = Vector((0, 0, 0))
|
|
A[axis] = 1.0
|
|
Bv = Vector((0, 0, 0))
|
|
Bv[a_ax] = 1.0
|
|
Z = Vector((0, 0, 1))
|
|
n = 4
|
|
rings = []
|
|
for k in range(n + 1):
|
|
t = k / n
|
|
w = math.sin(PI * t)
|
|
cc = c + A * (hs[axis] * (2 * t - 1)) + Bv * (bow * w * math.cos(ph)) + Z * (bow * 0.6 * w * math.sin(ph))
|
|
tw = 0.012 * (t - 0.5) * math.cos(ph * 1.7) # a little twist
|
|
ring = []
|
|
for u, v in sec:
|
|
uu, vv = u * math.cos(tw) - v * math.sin(tw), u * math.sin(tw) + v * math.cos(tw)
|
|
ring.append(cc + Bv * uu + Z * vv)
|
|
rings.append(ring)
|
|
o = rings_mesh(name, rings, [M.tim], cap0=not ends[0], cap1=not ends[1], ang=30)
|
|
L = hs[axis] * 2
|
|
s = min(s, 0.9 / max(L, 1e-6))
|
|
P.append(grain5(o, A, c, s, board=seed, v0=0.5 + 0.04 * math.sin(seed)))
|
|
for e, ring, sg in ((ends[0], rings[0], -1), (ends[1], rings[-1], 1)):
|
|
if not e:
|
|
continue
|
|
cen = sum(ring, Vector()) / len(ring)
|
|
pith = cen + Bv * (ha * rnd.uniform(-1.6, 1.6)) + Z * (hb * rnd.choice((-1.5, 1.5)))
|
|
P.append(endgrain_cap("endgrain", [Vector(p) for p in ring], cen, A * sg, 0.0006, pith, m=M.tim))
|
|
return o
|
|
|
|
|
|
def strap_u(P, M, pts, w, th, ref, m=None, bend=0.004):
|
|
"""A forged iron strap bent along pts (a flat bar w wide, th thick, its width along ref)."""
|
|
C = fillet([Vector(p) for p in pts], bend, n=2)
|
|
P.append(sweep("strap", C, lambda s, i: rrect(w / 2, th / 2, min(th * 0.45, w * 0.2), 1), [m or M.d1], ref=ref, ang=35))
|
|
|
|
|
|
def hull2d(pts):
|
|
"""Convex hull of 2D points, counter-clockwise."""
|
|
P_ = sorted(set((round(x, 7), round(y, 7)) for x, y in pts))
|
|
if len(P_) < 3:
|
|
return P_
|
|
|
|
def cross(o, a, b):
|
|
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
|
|
lower, upper = [], []
|
|
for p in P_:
|
|
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
|
|
lower.pop()
|
|
lower.append(p)
|
|
for p in reversed(P_):
|
|
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
|
|
upper.pop()
|
|
upper.append(p)
|
|
return lower[:-1] + upper[:-1]
|
|
|
|
|
|
def offset2d(pts, d):
|
|
"""Offset a convex counter-clockwise outline outwards by d (vertex normals)."""
|
|
n = len(pts)
|
|
out = []
|
|
for i in range(n):
|
|
a, b, c = Vector(pts[i - 1]), Vector(pts[i]), Vector(pts[(i + 1) % n])
|
|
t0, t1 = (b - a).normalized(), (c - b).normalized()
|
|
n0, n1 = Vector((t0.y, -t0.x)), Vector((t1.y, -t1.x))
|
|
nm = (n0 + n1)
|
|
nm = nm.normalized() if nm.length > 1e-9 else n0
|
|
k = max(0.5, nm.dot(n0))
|
|
out.append((b.x + nm.x * d / k, b.y + nm.y * d / k))
|
|
return out
|
|
|
|
|
|
def densify2d(pts, step):
|
|
out = []
|
|
n = len(pts)
|
|
for i in range(n):
|
|
a, b = Vector(pts[i]), Vector(pts[(i + 1) % n])
|
|
m = max(1, int(math.ceil((b - a).length / step)))
|
|
for k in range(m):
|
|
q = a.lerp(b, k / m)
|
|
out.append((q.x, q.y))
|
|
return out
|
|
|
|
|
|
def rclamp(P, M, c, t, r, w=0.014, th=0.0035, ear=(1, 0, 0), m=None, bolt=True):
|
|
"""A forged clamp round a round bar (axis t, radius r) at c: a band with rolled edges, two pinch ears on the `ear` side, a bolt
|
|
through them with a washer and a nut."""
|
|
m = m or M.d1
|
|
t = Vector(t).normalized()
|
|
prof = [(r + 0.0003, -w / 2), (r + th * 0.8, -w / 2 + 0.0008), (r + th, -w / 2 + 0.0022), (r + th, w / 2 - 0.0022), (r + th * 0.8, w / 2 - 0.0008),
|
|
(r + 0.0003, w / 2)]
|
|
P.append(rev("rclamp", prof, c, t, [m], segs=14, ang=45))
|
|
if ear is None:
|
|
return
|
|
e = (Vector(ear) - t * Vector(ear).dot(t)).normalized()
|
|
b = t.cross(e)
|
|
gap = 0.004
|
|
for sz in (-1, 1):
|
|
Fm = Matrix((e, t, b)).transposed().to_4x4()
|
|
Fm.translation = Vector(c) + e * (r - 0.002) + b * sz * (gap / 2 + th / 2)
|
|
out = rounded_outline([(0.0, -w * 0.46), (0.02, -w * 0.46), (0.02, w * 0.46), (0.0, w * 0.46)], 0.005, 2)
|
|
P.append(bprism("ear", out, -th / 2, th / 2, [m], bev=0.0009, segs=1, frame=Fm))
|
|
if bolt:
|
|
bc = Vector(c) + e * (r + 0.011)
|
|
hbolt(P, M, bc + b * (gap / 2 + th), b, gap + 2 * th, 0.0034, ref=t, thr=0.004)
|
|
|
|
|
|
def oval_wrap(name, fr, z0, z1, rxf, ryf, pitch, depth, m, segs=18, rows=3, n=2.3):
|
|
"""A strip wound in a helix round an oval handle (frame fr, axis local Z, radii rxf(z), ryf(z)), each turn lapped over the last."""
|
|
turns = (z1 - z0) / pitch
|
|
nph = int(math.ceil(turns * segs)) + 1
|
|
prof = [0.5, 0.82, 1.0, 0.9] if rows == 3 else [0.5 + 0.5 * (q / rows) ** 0.8 for q in range(rows + 1)]
|
|
bm = bmesh.new()
|
|
G = []
|
|
for k in range(nph + 1):
|
|
ph = TAU * k / segs
|
|
base = z0 + pitch * (k / segs) - pitch
|
|
row = []
|
|
for q in range(rows + 1):
|
|
z = base + pitch * q / rows
|
|
inside = z0 - 1e-6 <= z <= z1 + 1e-6
|
|
zc = min(max(z, z0), z1)
|
|
d = depth * prof[q] * (1.0 if inside else 0.2)
|
|
c_, s_ = math.cos(ph), math.sin(ph)
|
|
sx_, sy_ = math.copysign(abs(c_) ** (2.0 / n), c_), math.copysign(abs(s_) ** (2.0 / n), s_)
|
|
row.append(bm.verts.new(tuple(fr @ Vector(((rxf(zc) + d) * sx_, (ryf(zc) + d) * sy_, zc)))))
|
|
G.append(row)
|
|
for k in range(nph):
|
|
for q in range(rows):
|
|
bm.faces.new((G[k][q], G[k + 1][q], G[k + 1][q + 1], G[k][q + 1]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
f0 = bm.faces[len(bm.faces) // 2]
|
|
f0.normal_update()
|
|
cax = fr @ Vector((0, 0, (z0 + z1) / 2))
|
|
if f0.normal.dot(f0.calc_center_median() - cax) < 0:
|
|
bmesh.ops.reverse_faces(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
smooth(o, 55)
|
|
return o
|
|
|
|
|
|
def grip5(P, M, loc=(0, 0, 0), tilt=12.0, h0=-0.09, h1=0.06, rx=0.023, ry=0.03, wrap=True):
|
|
"""The farm pistol grip on the same frame as gc_farm_tools.grip: a turned oval timber handle swelling under the palm, finger
|
|
ridges down its front, a leather strip wound round it, an iron pommel cap held by a nut, a brass ferrule with two rivets."""
|
|
fr = Matrix.Translation(Vector(loc)) @ Matrix.Rotation(DEG(tilt), 4, "X")
|
|
H = h1 - h0
|
|
rings = []
|
|
for k in range(15):
|
|
t = k / 14
|
|
waist = 1.0 + 0.1 * math.sin(math.pi * min(1.0, t * 1.15))
|
|
rings.append((0, 0, rx * waist, ry * waist, h0 + H * t, 2.3))
|
|
g = FT.loft("grip", rings, segs=14, m=M.tim, frame=fr, cap0=False, cap1=True, smooth_ang=70)
|
|
# finger ridges on the front (-Y) face where the wrap leaves off
|
|
me = g.data
|
|
finv = fr.inverted()
|
|
for v in me.vertices:
|
|
p = finv @ v.co
|
|
if p.y < -ry * 0.5 and h0 + H * 0.05 < p.z < h0 + H * 0.2:
|
|
v.co = fr @ (p + Vector((0, -0.0018 * math.sin((p.z - h0) / (H * 0.15) * PI * 2) ** 2, 0)))
|
|
P.append(timber(g, fr.to_3x3() @ Vector((0, 0, 1)), 2.4))
|
|
wf = lambda z: 1.0 + 0.1 * math.sin(math.pi * min(1.0, (z - h0) / H * 1.15))
|
|
if wrap:
|
|
za, zb = h0 + H * 0.24, h0 + H * 0.68
|
|
P.append(oval_wrap("wrap", fr, za, zb, lambda z: rx * wf(z) * 1.005, lambda z: ry * wf(z) * 1.005, 0.0135, 0.0026, M.lea))
|
|
for zz in (za - 0.002, zb + 0.002):
|
|
k = wf(zz)
|
|
P.append(FT.loft("welt", [(0, 0, rx * k * 1.0, ry * k * 1.0, zz - 0.0035, 2.3), (0, 0, rx * k * 1.1, ry * k * 1.08, zz - 0.0018, 2.3),
|
|
(0, 0, rx * k * 1.12, ry * k * 1.1, zz, 2.3), (0, 0, rx * k * 1.1, ry * k * 1.08, zz + 0.0018, 2.3),
|
|
(0, 0, rx * k * 1.0, ry * k * 1.0, zz + 0.0035, 2.3)], segs=12, m=M.brass, frame=fr, cap0=False, cap1=False, smooth_ang=60))
|
|
|
|
# pommel: an iron cap over the bottom, a domed nut on the tie rod
|
|
P.append(FT.loft("pommel", [(0, 0, rx * 0.72, ry * 0.72, h0 - 0.013, 2.3), (0, 0, rx * 1.18, ry * 1.14, h0 - 0.009, 2.4), (0, 0, rx * 1.26, ry * 1.22, h0 - 0.003, 2.4),
|
|
(0, 0, rx * 1.26, ry * 1.22, h0 + 0.006, 2.4), (0, 0, rx * 1.12, ry * 1.1, h0 + 0.011, 2.3), (0, 0, rx * 1.02, ry * 1.02, h0 + 0.013, 2.3)],
|
|
segs=14, m=M.d1, frame=fr, smooth_ang=60))
|
|
bn = fr @ Vector((0, 0, h0 - 0.013))
|
|
ax = (fr.to_3x3() @ Vector((0, 0, -1))).normalized()
|
|
q = washer(P, bn, ax, 0.008, 0.0012, m=M.hw)
|
|
P.append(rev("pnut", [(0.0, 0.0), (0.0058, 0.0), (0.0062, 0.002), (0.0058, 0.005), (0.0035, 0.0072), (0.0, 0.0078)], q, ax, [M.hw], segs=6, ang=30))
|
|
# ferrule at the top, rolled rims, two rivets
|
|
P.append(FT.loft("ferrule", [(0, 0, rx * 1.06, ry * 1.06, h1 - 0.017, 2.3), (0, 0, rx * 1.15, ry * 1.13, h1 - 0.015, 2.3), (0, 0, rx * 1.12, ry * 1.1, h1 - 0.012, 2.3),
|
|
(0, 0, rx * 1.12, ry * 1.1, h1 - 0.004, 2.3), (0, 0, rx * 1.16, ry * 1.14, h1 - 0.002, 2.3), (0, 0, rx * 1.06, ry * 1.06, h1 + 0.001, 2.3)],
|
|
segs=14, m=M.brass, frame=fr, cap0=False, cap1=False, smooth_ang=60))
|
|
for sx in (-1, 1):
|
|
p = fr @ Vector((sx * rx * 1.12, 0, h1 - 0.008))
|
|
head(P, p, (fr.to_3x3() @ Vector((sx, 0, 0))).normalized(), 0.0022, "dome", m=M.brass)
|
|
return fr
|
|
|
|
|
|
def trigger5(P, M, y0=-0.03, z0=0.042, drop=0.05, m=None):
|
|
"""A throttle trigger in front of the grip: a curved lever with finger ridges on a pivot pin, a lock-out lever behind the grip's top,
|
|
a bent guard loop. Returns where the throttle cable leaves the grip."""
|
|
m = m or M.yel
|
|
C = fillet([(0, y0, z0), (0, y0 - 0.018, z0 - 0.022), (0, y0 - 0.019, z0 - 0.04), (0, y0 - 0.01, z0 - drop)], 0.012, 4)
|
|
|
|
def sec(s, i):
|
|
w = 0.0062 * (1 - 0.25 * s)
|
|
h = 0.0085 * (1 - 0.3 * s) * (1.0 + (0.12 if (i % 3 == 1 and s > 0.35) else 0.0))
|
|
return rrect(w, h, min(w, h) * 0.7, 2)
|
|
P.append(sweep("trig", C, sec, [m], ref=(1, 0, 0), ang=45))
|
|
pv = Vector((0, y0 + 0.002, z0 - 0.003))
|
|
for sx in (-1, 1):
|
|
head(P, pv + Vector((sx * 0.0064, 0, 0)), (sx, 0, 0), 0.0024, "dome", m=M.hw)
|
|
# the guard: a bent iron loop from the grip's front down round the trigger and back into the grip
|
|
P.append(tube5("tguard", [(0, y0 - 0.002, z0 + 0.004), (0, y0 - 0.05, z0), (0, y0 - 0.056, z0 - 0.04), (0, y0 - 0.034, z0 - 0.072), (0, y0 + 0.012, z0 - 0.078)],
|
|
0.0052, M.d1, segs=8, bend=0.014, nb=4))
|
|
# the lock-out: a short flat lever sticking back off the top of the grip, pivoting in a boss, a ribbed pad where the palm presses it
|
|
pv2 = Vector((0, 0.022, z0 - 0.012))
|
|
P.append(rev("lockboss", [(0.0042, -0.0072), (0.0052, -0.0064), (0.0055, 0.0), (0.0052, 0.0064), (0.0042, 0.0072)], pv2, (1, 0, 0), [M.d1], segs=10, ang=45))
|
|
for sx in (-1, 1):
|
|
dome8(P, pv2 + Vector((sx * 0.0072, 0, 0)), (sx, 0, 0), 0.0015, M.hw)
|
|
tipv = pv2 + Vector((0, 0.03, 0.002))
|
|
|
|
def lsec(s, i):
|
|
w = 0.0062 * (1.0 - 0.25 * max(0.0, s - 0.75) / 0.25)
|
|
return rrect(w, 0.0019, 0.0014, 1)
|
|
P.append(sweep("lockout", [pv2 + Vector((0, 0.002, 0.0015)), pv2.lerp(tipv, 0.5) + Vector((0, 0, 0.002)), tipv], lsec, [M.d1], ref=(1, 0, 0), ang=40))
|
|
for k in range(3):
|
|
q = pv2.lerp(tipv, 0.55 + 0.15 * k) + Vector((0, 0, 0.0032 - 0.0003 * k))
|
|
P.append(bprism("lockrib", [(-0.0048, -0.0007), (0.0048, -0.0007), (0.0048, 0.0007), (-0.0048, 0.0007)], -0.0006, 0.0012, [M.lea], segs=1,
|
|
frame=fz(q, (0, -0.2, 1), (1, 0, 0))))
|
|
return Vector((0, y0 - 0.008, z0 + 0.012))
|
|
|
|
|
|
def cable5(P, M, pts, clips=(), r=0.0032, m=None, n=40):
|
|
"""A throttle cable along pts with clips at the given point indices (each clip: a strap round the cable and what it is held to)."""
|
|
C = resample([Vector(p) for p in pts], n)
|
|
P.append(sweep("cable", C, lambda s, i: circ(r, 6), [m or M.black], ang=60))
|
|
for c, t, rr in clips:
|
|
rclamp(P, M, c, t, rr + r * 2.2, w=0.008, th=0.0018, ear=None, m=m or M.black)
|
|
for e, d in ((C[0], C[0] - C[1]), (C[-1], C[-1] - C[-2])):
|
|
P.append(rev("ferr", [(r * 0.9, -0.006), (r * 1.4, -0.0045), (r * 1.4, 0.003), (r * 0.6, 0.0045)], e, d, [M.brass], segs=8))
|
|
return C
|
|
|
|
|
|
def tank5(P, M, c, rx, ry, h, cap_x=None, band=True):
|
|
"""A pressed petrol tank: flat top and bottom with rolled shoulders, two halves crimped together round the middle, a painted band,
|
|
a filler neck and a knurled brass cap (off centre at cap_x)."""
|
|
tr = []
|
|
rc = min(rx, ry) * 0.48
|
|
for k, (fx, z) in enumerate(((0.88, 0.0), (0.97, 0.004), (1.0, 0.012), (1.0, h * 0.5 - 0.003), (1.0, h * 0.5 + 0.003), (1.0, h - 0.012), (0.97, h - 0.004),
|
|
(0.86, h))):
|
|
tr.append([Vector((c[0] + x, c[1] + y, c[2] + z)) for x, y, _ in rr_pts(rx * fx, ry * fx, rc * fx, nc=3, nf=(1, 1))])
|
|
P.append(rings_mesh("tank", tr, [M.red], ang=40))
|
|
crimp_seam(P, [Vector((c[0] + x, c[1] + y, c[2] + h * 0.5)) for x, y, _ in rr_pts(rx, ry, rc, nc=3, nf=(2, 1))], (0, 0, 1), M.red, r=0.0019)
|
|
if band:
|
|
br = [[Vector((c[0] + x, c[1] + y, c[2] + z)) for x, y, _ in rr_pts(rx + d, ry + d, rc + d, nc=3, nf=(1, 1))]
|
|
for d, z in ((0.0002, h * 0.6), (0.0014, h * 0.6 + 0.0012), (0.0014, h * 0.8 - 0.0012), (0.0002, h * 0.8))]
|
|
P.append(rings_mesh("tband", br, [M.white], cap0=False, cap1=False, ang=50))
|
|
if cap_x is not None:
|
|
fc = Vector((c[0] + cap_x, c[1], c[2] + h - 0.0005))
|
|
P.append(rev("neck", [(0.0135, -0.002), (0.0135, 0.005), (0.015, 0.0065), (0.0135, 0.008)], fc, (0, 0, 1), [M.d1], segs=12))
|
|
|
|
def knurl(i, a):
|
|
return 1.0 + (0.07 * math.cos(12 * a) if 1 <= i <= 3 else 0.0)
|
|
P.append(rev("tcap", [(0.014, 0.0065), (0.019, 0.007), (0.0205, 0.0105), (0.0205, 0.0185), (0.0185, 0.0215), (0.01, 0.0235), (0.0, 0.024)], fc, (0, 0, 1),
|
|
[M.brass], segs=24, mod=knurl, ang=45))
|
|
head(P, fc + Vector((0, 0, 0.0238)), (0, 0, 1), 0.0025, "dome", m=M.d1)
|
|
|
|
|
|
def engine5(c, M, s=1.0, pull=1, tank=True, tilt=0.0, stack=False):
|
|
"""gc_farm_tools.two_stroke on the same layout and size, as a real little engine: crankcase split by a bolted flange, a finned barrel
|
|
and head with head bolts, the plug, boot and lead to the coil, a pressed recoil starter on the pull side with the rope out of a grommet
|
|
to a turned toggle, a muffler (shielded can, or a vertical can with a stack, flue and rain cap), a carburettor with a pancake air filter
|
|
and choke lever at the front, a crimped tank behind with a knurled cap and a fuel line. Returns (parts, carb lever point in world)."""
|
|
E = []
|
|
X = Vector((pull, 0, 0))
|
|
rings = []
|
|
for hw, rc, z in ((0.054, 0.02, -0.0425), (0.062, 0.024, -0.038), (0.064, 0.026, -0.03), (0.064, 0.026, -0.005), (0.0675, 0.028, -0.0035),
|
|
(0.0675, 0.028, 0.0035), (0.064, 0.026, 0.005), (0.064, 0.026, 0.03), (0.06, 0.023, 0.038), (0.048, 0.017, 0.0425)):
|
|
rings.append([Vector((x, y, z)) for x, y, _ in rr_pts(hw, hw, rc, nc=2, nf=(1, 1))])
|
|
E.append(rings_mesh("crank", rings, [M.d1], ang=40))
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
head(E, Vector((sx * 0.052, sy * 0.052, 0.0035)), (0, 0, 1), 0.0034, "hex", m=M.hw, ref=(1, 0, 0))
|
|
# the barrel and its fins, the head
|
|
E.append(rev("barrel", [(0.03, 0.038), (0.03, 0.14)], Vector(), (0, 0, 1), [M.d1], segs=14))
|
|
fin_stack(E, Vector((0, 0, 0.052)), (0, 0, 1), (1, 0, 0), 0.104, 0.096, 0.014, 7, 0.0128, 0.0042, 0.0055, M.st)
|
|
E.append(bprism("head", rrect(0.04, 0.037, 0.012, 2), 0.137, 0.158, [M.d1, M.st], bev=0.004, segs=2, bev_slot=1))
|
|
for sy in (-1, 1):
|
|
E.append(bprism("hfin", rrect(0.036, 0.0022, 0.0018, 1), 0.157, 0.165, [M.d1], bev=0.001, segs=1, frame=Matrix.Translation((0, sy * 0.021, 0))))
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
q = washer(E, Vector((sx * 0.03, sy * 0.029, 0.158)), (0, 0, 1), 0.0055, 0.0011, m=M.hw)
|
|
head(E, q, (0, 0, 1), 0.0032, "hex", m=M.hw, ref=(1, 0, 0))
|
|
coil = Vector((pull * 0.032, -0.054, 0.057))
|
|
E.append(bprism("coil", rrect(0.013, 0.0145, 0.005, 2), -0.0075, 0.0075, [M.d1], bev=0.0025, segs=1, frame=fz(coil, (0, -1, 0), (1, 0, 0))))
|
|
for sx in (-1, 1):
|
|
head(E, coil + Vector((sx * 0.0085, -0.0075, -0.006)), (0, -1, 0), 0.0022, "hex", m=M.hw, ref=(1, 0, 0))
|
|
spark_plug(E, Vector((0, 0, 0.1585)), (0, 0, 1), M, lead=[(pull * 0.012, -0.004, 0.2275), (pull * 0.03, -0.04, 0.2), (pull * 0.034, -0.064, 0.12),
|
|
coil + Vector((0, -0.003, 0.0155))])
|
|
# recoil on the pull side; rope from a grommet at its foot to a turned toggle
|
|
recoil(E, X * 0.066, X, 0.054, 0.02, M, ref=(0, 0, 1), vents=5, cover=M.red, cap=M.d1)
|
|
|
|
gp = Vector((pull * 0.08, 0.038, -0.022))
|
|
E.append(rev("grommet", [(0.003, -0.003), (0.0058, -0.002), (0.006, 0.002), (0.0038, 0.003)], gp, (pull * 0.3, 0.5, -0.8), [M.brass], segs=10))
|
|
kp = Vector((pull * 0.118, 0.036, -0.034))
|
|
rope_line(E, [gp, gp + Vector((pull * 0.022, 0.002, -0.008)), kp + Vector((-pull * 0.004, 0.0, 0.012)), kp + Vector((0, 0, 0.004))], 0.0022, M.rope)
|
|
tg = rev("toggle", [(0.0, -0.028), (0.0062, -0.0275), (0.0095, -0.024), (0.0104, -0.016), (0.009, -0.01), (0.0106, -0.004), (0.0106, 0.004),
|
|
(0.009, 0.01), (0.0104, 0.016), (0.0095, 0.024), (0.0062, 0.0275), (0.0, 0.028)], kp + Vector((0, 0, -0.004)), (0, 1, 0), [M.tim], segs=10)
|
|
E.append(timber(tg, (0, 1, 0)))
|
|
E.append(rev("knot", [(0.0, -0.004), (0.004, -0.003), (0.0048, 0.0), (0.004, 0.003), (0.0, 0.004)], kp + Vector((0, 0, 0.0075)), (0, 0, 1), [M.rope], segs=8))
|
|
# muffler on the far side
|
|
if stack:
|
|
ex = Vector((-pull * 0.083, 0, 0.012))
|
|
muffler(E, ex + Vector((0, 0, -0.02)), (0, 0, 1), 0.034, 0.1, M, ref=(1, 0, 0), shield=True)
|
|
E.append(tube5("stack", [ex + Vector((0, 0, 0.078)), ex + Vector((0, 0, 0.205))], 0.0145, M.d1, segs=12, cap1=False))
|
|
rclamp(E, M, ex + Vector((0, 0, 0.12)), (0, 0, 1), 0.0145, w=0.01, th=0.003, ear=(pull, 0, 0))
|
|
E.append(rev("flue", [(0.0142, -0.004), (0.0152, 0.0), (0.02, 0.008), (0.025, 0.017), (0.0262, 0.022), (0.0236, 0.0235), (0.019, 0.018), (0.0142, 0.012)],
|
|
ex + Vector((0, 0, 0.198)), (0, 0, 1), [M.d1], segs=14))
|
|
hc = ex + Vector((0, 0, 0.231))
|
|
E.append(rev("raincap", [(0.0, 0.016), (0.012, 0.0145), (0.027, 0.009), (0.0335, 0.0035), (0.0335, 0.0005), (0.029, 0.0015), (0.012, 0.006), (0.0, 0.007)],
|
|
hc, (0, 0, 1), [M.st], segs=16))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.4
|
|
p0 = ex + Vector((0.024 * math.cos(a), 0.024 * math.sin(a), 0.22))
|
|
E.append(tube5("capleg", [p0, p0 + Vector((0.004 * math.cos(a), 0.004 * math.sin(a), 0.015))], 0.0018, M.st, segs=5))
|
|
else:
|
|
mc = Vector((-pull * 0.082, -0.055, 0.012))
|
|
muffler(E, mc, (0, 1, 0), 0.03, 0.11, M, ref=(0, 0, 1), spout=((-pull * 0.082, 0.055, 0.006), (-pull * 0.082, 0.071, -0.002)))
|
|
E.append(tube5("expipe", [(-pull * 0.03, -0.012, 0.062), (-pull * 0.06, -0.012, 0.06), (-pull * 0.074, -0.012, 0.04)], 0.0085, M.d1, segs=10, bend=0.012))
|
|
E.append(bprism("exflange", rrect(0.016, 0.012, 0.004, 1), -0.0025, 0.0025, [M.d1], bev=0.001, segs=1,
|
|
frame=fz(Vector((-pull * 0.033, -0.012, 0.062)), (-pull, 0, 0), (0, 0, 1))))
|
|
for sy in (-1, 1):
|
|
head(E, Vector((-pull * 0.0358, -0.012 + sy * 0.01, 0.062)), (-pull, 0, 0), 0.0026, "hex", m=M.hw, ref=(0, 0, 1))
|
|
# carburettor and air filter at the front, the choke lever, the throttle lever the cable pulls
|
|
cb = Vector((0.0, -0.072, 0.012))
|
|
E.append(bprism("carb", rrect(0.016, 0.014, 0.005, 2), -0.009, 0.009, [M.d1], bev=0.0025, segs=1, frame=fz(cb, (0, -1, 0), (1, 0, 0))))
|
|
fc = cb + Vector((0, -0.009, 0))
|
|
E.append(rev("filter", [(0.0, -0.001), (0.024, -0.001), (0.0285, 0.002), (0.029, 0.006), (0.0285, 0.012), (0.026, 0.0145), (0.012, 0.016), (0.0, 0.0165)], fc,
|
|
(0, -1, 0), [M.st], segs=18, mod=lambda i, a: 1.0 + (0.035 * math.cos(16 * a) if i in (3, 4) else 0.0), ang=45))
|
|
E.append(rev("wingnut", [(0.0, 0.0), (0.0065, 0.0), (0.007, 0.003), (0.005, 0.0055), (0.0, 0.006)], fc + Vector((0, -0.0163, 0)), (0, -1, 0), [M.d1], segs=8,
|
|
mod=lambda i, a: 1.0 + (0.45 * max(0.0, math.cos(a)) ** 4 + 0.45 * max(0.0, -math.cos(a)) ** 4 if i in (1, 2) else 0.0)))
|
|
lv = cb + Vector((pull * 0.017, -0.002, 0.004))
|
|
E.append(sweep("choke", [lv, lv + Vector((pull * 0.006, -0.004, 0.014))], lambda s, i: rrect(0.0025, 0.0016, 0.001, 1), [M.yel], ref=(0, 1, 0)))
|
|
tl = cb + Vector((-pull * 0.017, 0.0, 0.0))
|
|
E.append(rev("tlever", [(0.0, -0.002), (0.0055, -0.002), (0.0055, 0.002), (0.0, 0.002)], tl, (pull, 0, 0), [M.st], segs=8))
|
|
if tank:
|
|
tank5(E, M, (0.0, 0.098, 0.008), 0.064, 0.044, 0.09, cap_x=0.027)
|
|
tap = Vector((-pull * 0.035, 0.054, 0.014))
|
|
E.append(rev("tap", [(0.0, 0.0), (0.0045, 0.0), (0.0045, 0.008), (0.0035, 0.012), (0.0, 0.012)], tap + Vector((0, 0.002, 0)), (0, -1, 0), [M.brass], segs=8))
|
|
E.append(tube5("fuel", [tap + Vector((0, -0.01, 0)), tap + Vector((-pull * 0.01, -0.03, -0.022)), tap + Vector((-pull * 0.01, -0.1, -0.03)),
|
|
cb + Vector((-pull * 0.012, 0.004, -0.012))], 0.0028, M.brass, segs=6, bend=0.014, nb=3))
|
|
Mx = Matrix.Translation(Vector(c)) @ Matrix.Rotation(DEG(tilt), 4, "X") @ Matrix.Scale(s, 4)
|
|
place(E, Mx)
|
|
return E, Mx @ (tl + Vector((-pull * 0.002, 0, 0)))
|
|
|
|
|
|
# ======================================================================= SM_Tool_HandPump (Clip-Vac)
|
|
|
|
def comb5(name, pts, t, M, m, edge, frame):
|
|
"""A cutter comb from gc_farm_tools.comb_pts: a plate with every edge bevelled and the bevels ground bright."""
|
|
o = FT.prism(name, pts, t, frame, m)
|
|
o.data.materials.append(common.mat(edge))
|
|
b = o.modifiers.new("bev", "BEVEL")
|
|
b.width = min(0.0024, t * 0.3)
|
|
b.segments = 1
|
|
b.limit_method = "ANGLE"
|
|
b.angle_limit = DEG(30)
|
|
b.material = 1
|
|
common.bake(o)
|
|
smooth(o, 35)
|
|
return o
|
|
|
|
|
|
|
|
def plate_normals(o, zmid):
|
|
"""A thin concave plate can come out of recalc_face_normals with its big faces turned in: point every face away from the mid plane."""
|
|
me = o.data
|
|
for p in me.polygons:
|
|
c = p.center
|
|
if abs(p.normal.z) > 0.7 and (p.normal.z > 0) != (c.z > zmid):
|
|
p.flip()
|
|
me.update()
|
|
|
|
|
|
def hand_pump():
|
|
M = FM
|
|
P = []
|
|
Z, YB = 0.072, 0.16
|
|
FR = FT.M_fwd((0, YB - 0.005, Z))
|
|
# ---- the cast gearbox barrel (the old loft, finer), cast ribs along its top, a parting flange down each side with bolts
|
|
P.append(FT.loft("case", [(0, 0, 0, 0, -0.002), (0, 0, 0.03, 0.034, 0.0, 2.6), (0, 0, 0.046, 0.05, 0.012, 2.8), (0, 0, 0.053, 0.058, 0.04, 3.0),
|
|
(0, 0, 0.056, 0.06, 0.16, 3.0), (0, 0, 0.054, 0.058, 0.25, 3.0), (0, 0, 0.044, 0.05, 0.29, 2.8)],
|
|
segs=24, m=M.red, frame=FR, cap1=True, smooth_ang=60))
|
|
# the barrel is cast in two halves bolted together through a pair of flanges round its middle: the flanges stand proud of the
|
|
# barrel, a parting line between them, six bolts through both, heads in front and nuts behind
|
|
DF = 0.146
|
|
rings = []
|
|
for dz, g in ((-0.0135, 0.0004), (-0.0122, 0.0086), (-0.0102, 0.0112), (-0.0016, 0.0112), (-0.0005, 0.0094), (0.0005, 0.0094), (0.0016, 0.0112),
|
|
(0.0102, 0.0112), (0.0122, 0.0086), (0.0135, 0.0004)):
|
|
rings.append((0, 0, 0.056 + g, 0.06 + g, DF + dz, 3.0))
|
|
P.append(FT.loft("flange", rings, segs=24, m=M.red, frame=FR, cap0=False, cap1=False, smooth_ang=40))
|
|
FAX = (FR.to_3x3() @ Vector((0, 0, 1))).normalized()
|
|
for k in range(6):
|
|
a = TAU * k / 6 + TAU / 12
|
|
c_, s_ = math.cos(a), math.sin(a)
|
|
ex, ey = math.copysign(abs(c_) ** (2.0 / 3.0), c_), math.copysign(abs(s_) ** (2.0 / 3.0), s_)
|
|
bp = FR @ Vector(((0.056 + 0.0062) * ex, (0.06 + 0.0062) * ey, DF))
|
|
out_ = (FR.to_3x3() @ Vector((ex, ey, 0.0))).normalized()
|
|
q = washer(P, bp + FAX * 0.0102, FAX, 0.0062, 0.0011, m=M.hw, ref=out_)
|
|
head(P, q, FAX, 0.0029, "hex", m=M.hw, ref=out_)
|
|
q = hexnut(P, bp - FAX * 0.0102, -FAX, 0.0054, 0.0041, m=M.hw, ref=out_)
|
|
thread(P, q + FAX * 0.002, -FAX, 0.0026, 0.004, m=M.st)
|
|
for sx in (-1, 1):
|
|
C = [FR @ Vector((sx * 0.02, 0.0605, d)) for d in (0.06, 0.12, 0.18, 0.226)]
|
|
|
|
def ribsec(s, i):
|
|
k = min(1.0, s * 6, (1 - s) * 6)
|
|
return [(0.0045, -0.003), (0.0034, 0.0026 * k + 0.0004), (0.0, 0.0036 * k + 0.0004), (-0.0034, 0.0026 * k + 0.0004), (-0.0045, -0.003)]
|
|
P.append(sweep("castrib", C, ribsec, [M.red], ref=(1, 0, 0), ang=50))
|
|
# strap bands (navy) bolted under the barrel, painted yellow lines between them
|
|
for d in (0.044, 0.232):
|
|
FT.body_band(P, FR, 0.054, 0.059, d, d + 0.024, M.d1, n=3.0, grow=0.004, segs=24)
|
|
for sx in (-1, 1):
|
|
P.append(bprism("bear", rounded_outline([(-0.004, 0.0), (0.004, 0.0), (0.004, 0.018), (-0.004, 0.018)], 0.003, 2), -0.0022, 0.0022, [M.d1],
|
|
bev=0.0008, segs=1, frame=fz(FR @ Vector((sx * 0.004, -0.058, d + 0.012)), (1, 0, 0), (0, 0, -1)) @ Matrix.Rotation(DEG(90), 4, "Z")))
|
|
hbolt(P, M, FR @ Vector((0.0062, -0.066, d + 0.012)), (1, 0, 0), 0.0124, 0.0026, ref=(0, 0, 1), thr=0.003)
|
|
for d in (0.1, 0.18):
|
|
FT.body_band(P, FR, 0.0555, 0.0595, d, d + 0.012, M.yel, n=3.0, grow=0.0018, segs=24)
|
|
# bearing boss at the back where the push rod goes in: a brass bush, a felt seal lip, three screws
|
|
P.append(rev("bush", [(0.0105, -0.016), (0.019, -0.014), (0.0205, -0.012), (0.0205, 0.003), (0.0175, 0.006), (0.0115, 0.0075), (0.0098, 0.004)],
|
|
Vector((0, YB, Z)), (0, 1, 0), [M.brass], segs=16))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.5
|
|
head(P, Vector((0.0158 * math.cos(a), YB + 0.003, Z + 0.0158 * math.sin(a))), (0, 1, 0), 0.0017, "dome", m=M.hw)
|
|
# ---- the neck down to the cutter bar: a casting with fillets, a flange bolted onto the bar, an oil plug
|
|
nr = []
|
|
for hw, hd, rc, z in ((0.046, 0.017, 0.012, -0.024), (0.046, 0.017, 0.012, -0.018), (0.04, 0.042, 0.014, -0.015), (0.039, 0.041, 0.016, 0.02),
|
|
(0.041, 0.043, 0.016, 0.05), (0.047, 0.047, 0.02, 0.066), (0.05, 0.05, 0.022, 0.07)):
|
|
nr.append([Vector((x, -0.112 + y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(1, 1))])
|
|
P.append(rings_mesh("neck", nr, [M.d1], ang=40))
|
|
P.append(bprism("neckcap", rrect(0.044, 0.015, 0.006, 2), -0.023, 0.007, [M.d1, M.st], bev=0.003, segs=1, bev_slot=1, frame=Matrix.Translation((0, -0.142, 0))))
|
|
for sx in (-1, 1):
|
|
q = washer(P, Vector((sx * 0.032, -0.142, 0.007)), (0, 0, 1), 0.0062, 0.0012, m=M.hw)
|
|
head(P, q, (0, 0, 1), 0.0036, "hex", m=M.hw, ref=(1, 0, 0))
|
|
P.append(rev("oilplug", [(0.0, 0.0), (0.0085, 0.0), (0.009, 0.002), (0.0085, 0.004), (0.0058, 0.0045), (0.0058, 0.0085), (0.0, 0.009)],
|
|
Vector((0.0, -0.154, 0.035)), (0, -1, 0.2), [M.brass], segs=6, ang=30))
|
|
# ---- the cutter bar (rolled towards the eye like the old one): fixed comb with ground edges, guide bar, bolts with spacers and nuts
|
|
C = []
|
|
C.append(comb5("combL", FT.comb_pts(-0.1, -0.56, 6, 0.03, 0.104), 0.0095, M, M.st, M.br, Matrix.Translation((0, 0, -0.033))))
|
|
C.append(bprism("guide", rrect(0.015, 0.2, 0.006, 2), -0.0105, 0.0, [M.d1, M.st], bev=0.0025, segs=1, bev_slot=1, frame=Matrix.Translation((0, -0.33, 0))))
|
|
C.append(rev("guidetip", [(0.0, -0.0105), (0.0135, -0.0105), (0.015, -0.0085), (0.015, -0.002), (0.0135, 0.0), (0.0, 0.0)], Vector((0, -0.53, 0)), (0, 0, 1),
|
|
[M.d1], segs=14))
|
|
for k in range(5):
|
|
c = Vector((0, -0.2 - k * 0.075, 0.0))
|
|
q = washer(C, c, (0, 0, 1), 0.0098, 0.0016, m=M.brass)
|
|
head(C, q, (0, 0, 1), 0.0055, "hex", m=M.hw, ref=(1, 0.3, 0))
|
|
q = washer(C, c - Vector((0, 0, 0.0425)), (0, 0, -1), 0.0085, 0.0014, m=M.hw)
|
|
q = hexnut(C, q, (0, 0, -1), 0.0095, 0.007, m=M.hw)
|
|
thread(C, q + Vector((0, 0, 0.002)), (0, 0, -1), 0.0045, 0.005, m=M.st)
|
|
place(C, FT.ROLL)
|
|
P += C
|
|
# ---- grip, clamp and trigger
|
|
grip5(P, M, (0, 0, 0), tilt=10, h1=0.032)
|
|
cr = []
|
|
for hw, hd, rc, z in ((0.027, 0.034, 0.012, 0.015), (0.031, 0.038, 0.014, 0.018), (0.031, 0.038, 0.014, 0.032), (0.027, 0.034, 0.012, 0.035)):
|
|
cr.append([Vector((x, y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(1, 1))])
|
|
P.append(rings_mesh("clamp", cr, [M.d1], ang=40))
|
|
for sy in (-1, 1):
|
|
head(P, Vector((0.031, sy * 0.022, 0.025)), (1, 0, 0), 0.0034, "hex", m=M.hw, ref=(0, 0, 1))
|
|
trigger5(P, M, y0=-0.03, z0=0.022, drop=0.05)
|
|
# ---- the tin chute: scoops the clippings off the bar root and up into the bag; a rolled lip at its mouth, a riveted seam, a bracket
|
|
cp = [(0, -0.232, 0.03), (0, -0.19, 0.05), (0, -0.14, 0.098), (0, -0.092, 0.165), (0, -0.05, 0.19)]
|
|
P.append(FT.duct("chute", cp, lambda s: (0.062 - 0.012 * s, 0.03 + 0.024 * s), M.tin, segs=20, nu=2.2, vs=5.0))
|
|
P.append(FT.duct("mouth", [(0, -0.2365, 0.0292), (0, -0.2255, 0.0312)], lambda s: (0.0675 + 0.002 * math.sin(s * PI), 0.0355), M.st, segs=20, per=2))
|
|
P.append(FT.duct("chutein", [(0, -0.226, 0.031), (0, -0.21, 0.036)], lambda s: (0.056, 0.024), M.d1, segs=16, per=1, cap=True))
|
|
Cc = catmull([Vector(p) for p in cp], 4)
|
|
for k in range(2, len(Cc) - 2, 2):
|
|
a, b = Cc[k - 1], Cc[k + 1]
|
|
T_ = (b - a).normalized()
|
|
N_ = T_.cross(Vector((1, 0, 0))).normalized()
|
|
s = k / (len(Cc) - 1)
|
|
hz = 0.03 + 0.024 * s
|
|
p = Cc[k] + N_ * (hz * 1.0 + 0.0008) * (1 if N_.z > 0 else -1)
|
|
rivet(P, p, (N_ if N_.z > 0 else -N_), 0.0028, m=M.brass)
|
|
P.append(sweep("chutebrk", fillet([Vector((0, -0.142, 0.026)), Vector((0, -0.142, 0.07)), Vector((0, -0.125, 0.105))], 0.02, 3),
|
|
lambda s, i: rrect(0.016, 0.0025, 0.0018, 1), [M.d1], ref=(1, 0, 0), ang=40))
|
|
hbolt(P, M, Vector((0.0, -0.1375, 0.06)), (0, 1, 0), 0.0075, 0.003, ref=(1, 0, 0), thr=0.003)
|
|
# ---- the burlap catch bag (the old one), a seam down its top in twine stitches, the gathered neck tied off, a clamped steel ring,
|
|
# two leather straps with stitched edges and real buckles
|
|
bz = 0.19
|
|
BF = FT.M_axis("Y", (0, -0.06, bz))
|
|
rings = [(0, 0, 0.05, 0.05, -0.012), (0, 0, 0.056, 0.054, 0.0), (0, 0.002, 0.074, 0.068, 0.03), (0, 0.004, 0.087, 0.076, 0.075), (0, 0.003, 0.09, 0.078, 0.13),
|
|
(0, 0.0, 0.085, 0.074, 0.185), (0, -0.002, 0.066, 0.058, 0.232), (0, -0.002, 0.04, 0.036, 0.262), (0, -0.002, 0.024, 0.022, 0.28), (0, -0.002, 0.022, 0.02, 0.29),
|
|
(0, -0.002, 0.03, 0.026, 0.302), (0, -0.002, 0.036, 0.03, 0.316), (0, -0.002, 0.022, 0.02, 0.312)]
|
|
bag = FT.loft("bag", rings, segs=22, m=M.fab, frame=BF, cap0=True, cap1=True, smooth_ang=70)
|
|
FT.pleats(bag, (0, -0.06, bz), (0, 1, 0), n=6, amp=0.12, t0=0.2, t1=0.27)
|
|
FT.wobble(bag, 0.008, 9.0, seed=2.0)
|
|
FT.around(bag, (0, -0.06, bz), (0, 1, 0), nu=3.6, s=7.0)
|
|
P.append(bag)
|
|
# the seam: a raised ridge along the top of the sack, stitched in twine
|
|
bvh = None
|
|
from mathutils.bvhtree import BVHTree
|
|
bpy.context.view_layer.update()
|
|
bvh = BVHTree.FromObject(bag, bpy.context.evaluated_depsgraph_get())
|
|
seam = []
|
|
for k in range(22):
|
|
y = -0.045 + 0.215 * k / 21
|
|
hit = bvh.ray_cast(Vector((0.0, y, bz + 0.2)), Vector((0, 0, -1)))
|
|
if hit[0] is not None:
|
|
seam.append(hit[0] - Vector((0, 0, 0.0015)))
|
|
if len(seam) > 3:
|
|
P.append(sweep("seam", seam, lambda s, i: [(0.0036, -0.001), (0.002, 0.0028), (-0.002, 0.0028), (-0.0036, -0.001)], [M.fab], ref=(1, 0, 0), ang=60))
|
|
for sx in (-1, 1):
|
|
row = []
|
|
for p in seam[1:-1]:
|
|
hit = bvh.ray_cast(p + Vector((sx * 0.009, 0, 0.05)), Vector((0, 0, -1)))
|
|
if hit[0] is not None:
|
|
row.append(hit[0])
|
|
if len(row) > 2:
|
|
P.append(stitches("stitch", row, lambda p, bz=bz: Vector((p.x, 0.0, p.z - bz)), M.thr, step=0.012, L=0.0065, w=0.0022, lift=0.0008))
|
|
FT.tie(P, (0, 0.23, bz - 0.002), (0, 1, 0), 0.0245, m=M.thr,
|
|
tails=[[(0.02, 0.234, bz + 0.012), (0.05, 0.242, bz + 0.01), (0.07, 0.232, bz - 0.03), (0.075, 0.236, bz - 0.06)]])
|
|
rclamp(P, M, Vector((0, -0.058, bz)), (0, 1, 0), 0.051, w=0.012, th=0.0035, ear=(0, 0, -1), m=M.st)
|
|
for yy in (0.03, 0.135):
|
|
pts = [(0.056, yy, 0.09), (0.082, yy, 0.13), (0.09, yy, 0.19), (0.068, yy, 0.243), (0.0, yy, 0.27), (-0.068, yy, 0.243), (-0.09, yy, 0.19), (-0.082, yy, 0.13),
|
|
(-0.056, yy, 0.09)]
|
|
C = resample([Vector(p) for p in pts], 26)
|
|
sc = []
|
|
for p in C:
|
|
hit = bvh.ray_cast(Vector((0, yy, bz)) + (p - Vector((0, yy, bz))) * 1.6, -(p - Vector((0, yy, bz))).normalized())
|
|
sc.append(hit[0] + (p - Vector((0, yy, bz))).normalized() * 0.0028 if hit[0] is not None else p)
|
|
P.append(sweep("strap", sc, lambda s, i: [(-0.0028, -0.0125), (0.0, -0.0128), (0.0028, -0.0125), (0.0032, 0.0), (0.0028, 0.0125), (0.0, 0.0128),
|
|
(-0.0028, 0.0125), (-0.0032, 0.0)], [M.lea], ref=(0, 1, 0), ang=50))
|
|
for side in (-1, 1):
|
|
row = [p + Vector((0, side * 0.0092, 0)) + (p - Vector((0, yy, bz))).normalized() * 0.0028 for p in sc[1:-1]]
|
|
P.append(stitches("lstitch", row, lambda p, yy=yy: Vector((p.x, 0.0, p.z - bz)), M.thr, step=0.011, L=0.006, w=0.0018, lift=0.0004))
|
|
# the buckle: a brass frame with a bar and a tongue, the strap's end through a keeper loop
|
|
bkc = Vector((0.0915, yy, 0.185))
|
|
Fb = fz(bkc, (1, 0, 0), (0, 0, 1))
|
|
ring = [Vector((0.0, 0.0, 0.0))]
|
|
frm = [Fb @ Vector((x, y, 0.0)) for x, y in rrect(0.016, 0.017, 0.006, 2)]
|
|
frm.append(frm[0])
|
|
frm.append(frm[1])
|
|
P.append(sweep("buckle", frm, lambda s, i: circ(0.0022, 6), [M.brass], cap0=False, cap1=False, ang=60))
|
|
P.append(tube5("bbar", [Fb @ Vector((0.0, -0.017, 0.0)), Fb @ Vector((0.0, 0.017, 0.0))], 0.0018, M.brass, segs=6))
|
|
P.append(tube5("tongue", [Fb @ Vector((0.0, 0.0, 0.0)), Fb @ Vector((0.014, 0.0, 0.0025)), Fb @ Vector((0.018, 0.0, 0.001))], 0.0014, M.brass, segs=6, bend=0.004))
|
|
P.append(bprism("keeper", rrect(0.004, 0.0145, 0.0025, 2), -0.0015, 0.0045, [M.lea], bev=0.0008, segs=1, frame=fz(bkc + Vector((0, 0, -0.026)), (1, 0, 0), (0, 0, 1))))
|
|
body = ffin(P, "Body")
|
|
|
|
# ---- Plunger: T-handle + push rod + the moving upper comb
|
|
Q = []
|
|
cU = comb5("combU", FT.comb_pts(-0.16, -0.54, 5, 0.024, 0.1, phase=0.3), 0.0075, M, M.st, M.br, Matrix.Translation((0, 0, -0.0235)))
|
|
|
|
place([cU], FT.ROLL)
|
|
Q.append(cU)
|
|
lk = []
|
|
for hw, hd, rc, z in ((0.022, 0.022, 0.008, -0.015), (0.025, 0.025, 0.01, -0.012), (0.025, 0.025, 0.01, 0.012), (0.022, 0.022, 0.008, 0.015)):
|
|
lk.append([Vector((x, -0.162 + y, z)) for x, y, _ in rr_pts(hw, hd, rc, nc=2, nf=(1, 1))])
|
|
Q.append(rings_mesh("linkU", lk, [M.d1], ang=40))
|
|
for sx in (-1, 1):
|
|
head(Q, Vector((sx * 0.01, -0.162, 0.015)), (0, 0, 1), 0.0032, "hex", m=M.hw, ref=(1, 0, 0))
|
|
Q.append(rev("rod", [(0.0, -0.115), (0.0078, -0.114), (0.0085, -0.11), (0.0085, 0.11), (0.0078, 0.114), (0.0, 0.115)], Vector((0, YB + 0.005, Z)), (0, 1, 0),
|
|
[M.st], segs=12))
|
|
Q.append(rev("rodcol", [(0.0085, -0.009), (0.0118, -0.008), (0.0128, -0.005), (0.0128, 0.005), (0.0118, 0.008), (0.0085, 0.009)], Vector((0, YB + 0.104, Z)),
|
|
(0, 1, 0), [M.brass], segs=14))
|
|
head(Q, Vector((0, YB + 0.104, Z + 0.0128)), (0, 0, 1), 0.0022, "hex", m=M.hw)
|
|
# the T: a turned timber cross handle with grooves, iron end ferrules with a domed rivet, a red cast tee with a bolt through
|
|
for sx in (-1, 1):
|
|
prof = [(0.0, 0.0), (0.012, 0.0), (0.0165, 0.006), (0.0205, 0.012), (0.0198, 0.02), (0.0208, 0.026), (0.0212, 0.04), (0.0205, 0.05), (0.0185, 0.054)]
|
|
h_ = rev("thandle", prof, Vector((sx * 0.026, YB + 0.126, Z)), (sx, 0, 0), [M.tim], segs=14, cap1=True)
|
|
Q.append(timber(h_, (1, 0, 0)))
|
|
Q.append(rev("tcap", [(0.0178, -0.003), (0.0222, -0.002), (0.0228, 0.006), (0.0215, 0.01), (0.012, 0.0125), (0.0, 0.013)],
|
|
Vector((sx * 0.08, YB + 0.126, Z)), (sx, 0, 0), [M.d1], segs=14))
|
|
tb = []
|
|
for hw, hd, rc, z in ((0.02, 0.02, 0.008, -0.025), (0.025, 0.025, 0.011, -0.021), (0.025, 0.025, 0.011, 0.021), (0.02, 0.02, 0.008, 0.025)):
|
|
tb.append([Vector((z, YB + 0.126 + y, Z + x)) for x, y, _ in rr_pts(hw, hd, rc, nc=3, nf=(1, 1))])
|
|
Q.append(rings_mesh("tblock", tb, [M.red], ang=40))
|
|
hbolt(Q, M, Vector((0, YB + 0.126, Z + 0.025)), (0, 0, 1), 0.05, 0.0034, ref=(1, 0, 0), thr=0.004)
|
|
pl = ffin(Q, "Plunger", uv=5.0)
|
|
set_origin(pl, (0, YB, Z))
|
|
empty("Nozzle", (0, -0.55, -0.018))
|
|
return {}
|
|
|
|
|
|
|
|
|
|
def near(C, p):
|
|
"""Index, point and tangent of polyline C nearest to p."""
|
|
p = Vector(p)
|
|
i = min(range(len(C)), key=lambda k: (C[k] - p).length)
|
|
t = (C[min(i + 1, len(C) - 1)] - C[max(i - 1, 0)]).normalized()
|
|
return i, C[i], t
|
|
|
|
|
|
def cast_block(name, c, hw, hd, h, m, rc=None, z0=None, flare=0.0):
|
|
"""A casting: a rounded block hw x hd, h high above c (or from z0), its edges eased, a little draft (flare) towards the bottom."""
|
|
rc = rc if rc is not None else min(hw, hd) * 0.4
|
|
zb = c[2] if z0 is None else z0
|
|
rings = []
|
|
for k, (f, dz) in enumerate(((0.9, 0.0), (1.0 + flare, 0.0025), (1.0 + flare * 0.6, h * 0.3), (1.0, h - 0.004), (0.92, h - 0.0008), (0.8, h))):
|
|
rings.append([Vector((c[0] + x, c[1] + y, zb + dz)) for x, y, _ in rr_pts(hw * f, hd * f, rc * f, nc=2, nf=(1, 1))])
|
|
return rings_mesh(name, rings, [m], ang=40)
|
|
|
|
|
|
# ======================================================================= SM_Tool_SlurpGun (Weed Whacker)
|
|
|
|
def slurp_gun():
|
|
M = FM
|
|
P = []
|
|
A = Vector((0, 0.17, 0.092))
|
|
Ax = Vector((0, 0.42, 0.907)).normalized()
|
|
E = Vector((0, -0.655, -0.112))
|
|
D = E + Ax * 0.12
|
|
Cp = Vector((0, -0.5, -0.03))
|
|
Cs = resample([A, Vector((0, -0.1, 0.05)), Vector((0, -0.38, 0.003)), Cp, D, E + Ax * 0.03], 64, per=5)
|
|
P.append(sweep("shaft", Cs, lambda s, i: circ(0.0235, 14), [M.st], ref=(1, 0, 0), ang=40))
|
|
# shaft clamps (the old hoops), bolted
|
|
for p in ((0, -0.1, 0.05), (0, -0.5, -0.03)):
|
|
i, c, t = near(Cs, p)
|
|
rclamp(P, M, c, t, 0.0235, w=0.016, th=0.004, ear=(1, 0, 0))
|
|
# ---- the engine on the back of the shaft, a cast saddle under it with two clamps round the shaft
|
|
E5, carb = engine5((0, 0.13, 0.157), M, s=0.92, pull=1, tank=False)
|
|
P += E5
|
|
P.append(cast_block("mount", (0, 0.13, 0.0), 0.027, 0.052, 0.02, M.d1, z0=0.1, flare=0.08))
|
|
for y in (0.095, 0.165):
|
|
i, c, t = near(Cs, (0, y, 0.09))
|
|
rclamp(P, M, c, t, 0.0235, w=0.014, th=0.0035, ear=(-1, 0, 0))
|
|
# ---- the red fuel tank carrying the mix jar, its bracket clamped to the shaft
|
|
tank5(P, M, (0, -0.065, 0.098), 0.072, 0.066, 0.09, cap_x=None)
|
|
P.append(cast_block("tbrk", (0, -0.065, 0.0), 0.022, 0.032, 0.036, M.d1, z0=0.063, flare=0.15))
|
|
i, c, t = near(Cs, (0, -0.065, 0.045))
|
|
rclamp(P, M, c, t, 0.0235, w=0.016, th=0.004, ear=(1, 0, 0))
|
|
# the jar: a knurled base ring, glass with a moulded thread at the neck, a knurled lid, a turned cork, a wire bail over it
|
|
CF = Vector((0, -0.065, 0.202))
|
|
|
|
def kn(i, a):
|
|
return 1.0 + (0.025 * math.cos(20 * a) if i in (2, 3) else 0.0)
|
|
P.append(rev("jarbase", [(0.0, -0.016), (0.056, -0.016), (0.061, -0.013), (0.062, -0.008), (0.062, 0.002), (0.058, 0.005), (0.056, 0.006)], CF, (0, 0, 1),
|
|
[M.d1], segs=28, mod=kn, ang=40))
|
|
jar = [(0.056, 0.0), (0.0595, 0.006), (0.06, 0.014), (0.06, 0.088), (0.0555, 0.104), (0.047, 0.112), (0.047, 0.115), (0.049, 0.117), (0.047, 0.119),
|
|
(0.049, 0.121), (0.047, 0.123)]
|
|
P.append(rev("jar", jar, CF, (0, 0, 1), [M.glass], segs=24, ang=50))
|
|
P.append(rev("lid", [(0.0, 0.142), (0.038, 0.142), (0.048, 0.139), (0.0515, 0.134), (0.0515, 0.118), (0.049, 0.113), (0.0465, 0.112)], CF, (0, 0, 1), [M.st],
|
|
segs=28, mod=lambda i, a: 1.0 + (0.03 * math.cos(24 * a) if i in (3, 4) else 0.0), ang=45))
|
|
ck = rev("cork", [(0.0, 0.0), (0.0145, 0.0), (0.0165, 0.003), (0.017, 0.012), (0.0158, 0.016), (0.0, 0.0168)], CF + Vector((0, 0, 0.1415)), (0, 0, 1), [M.tim], segs=12)
|
|
P.append(timber(ck, (0, 0, 1)))
|
|
for sx in (-1, 1):
|
|
P.append(rev("bailpivot", [(0.0, 0.0), (0.0045, 0.0), (0.005, 0.003), (0.0, 0.0045)], CF + Vector((sx * 0.062, 0, -0.006)), (sx, 0, 0), [M.d1], segs=8))
|
|
bail = [CF + Vector((-0.0635, 0, -0.006)), CF + Vector((-0.0635, 0, 0.122)), CF + Vector((-0.045, 0.026, 0.148)), CF + Vector((0.045, 0.026, 0.148)),
|
|
CF + Vector((0.0635, 0, 0.122)), CF + Vector((0.0635, 0, -0.006))]
|
|
P.append(tube5("bail", bail, 0.0024, M.d1, segs=6, bend=0.014, nb=4))
|
|
fill = FT.lathe("Fill", [(0.0, 0.0), (0.052, 0.0), (0.052, 0.106), (0.0, 0.106)], segs=18, m="M_GrassFill", frame=Matrix.Translation(CF), smooth_ang=30)
|
|
# fuel line from a nipple on the tank top to the carburettor, held by a clip on the engine mount
|
|
P.append(rev("nipple", [(0.0, 0.0), (0.006, 0.0), (0.006, 0.004), (0.004, 0.006), (0.0042, 0.012), (0.0035, 0.014)], Vector((0.045, -0.02, 0.1875)), (0, 0, 1),
|
|
[M.brass], segs=8))
|
|
P.append(tube5("fuel", [(0.045, -0.02, 0.2), (0.055, 0.0, 0.215), (0.06, 0.04, 0.2), (0.03, 0.062, 0.175), carb + Vector((0.01, 0.004, -0.012))],
|
|
0.0032, M.brass, segs=6, bend=0.016, nb=3))
|
|
# ---- the rear grip, its cast clamp onto the shaft, the trigger; the throttle cable from the grip up to the carburettor
|
|
grip5(P, M, (0, 0, 0), tilt=12, h1=0.05)
|
|
P.append(cast_block("clamp", (0, 0.004, 0.0), 0.0325, 0.0425, 0.056, M.d1, z0=0.028, flare=0.06))
|
|
i, c, t = near(Cs, (0, 0.004, 0.07))
|
|
for sx in (-1, 1):
|
|
hbolt(P, M, Vector((sx * 0.0325, 0.022 * sx, 0.06)), (sx, 0, 0), 0.065, 0.0034, ref=(0, 0, 1), nut=False)
|
|
ce = trigger5(P, M, y0=-0.034, z0=0.03, drop=0.05)
|
|
cable5(P, M, [ce, (0.02, -0.05, 0.058), (0.042, -0.03, 0.08), (0.05, 0.02, 0.11), (0.04, 0.05, 0.15), carb + Vector((0.004, -0.002, 0.0))],
|
|
clips=[(Vector((0.05, 0.02, 0.11)), (0, 1, 0.6), 0.0)], n=30)
|
|
# ---- the loop handle: a bent tube loop out of a cast clamp on the shaft, a turned timber grip across its top in brass ferrules
|
|
Ly, Lz = -0.215, 0.031
|
|
lp = [(0.0, Ly, Lz), (0.05, Ly, Lz + 0.03), (0.098, Ly, Lz + 0.1), (0.075, Ly, Lz + 0.17), (0.0, Ly, Lz + 0.19), (-0.075, Ly, Lz + 0.17), (-0.098, Ly, Lz + 0.1),
|
|
(-0.05, Ly, Lz + 0.03), (0.0, Ly, Lz)]
|
|
loop = resample([Vector(p) for p in lp], 44, per=6)
|
|
loop[0] = loop[-1] = Vector((0.0, Ly, Lz))
|
|
for half in (loop[:23], loop[22:]):
|
|
P.append(sweep("loop", half, lambda s, i: circ(0.011, 10), [M.d1], ref=(0, 1, 0), ang=40))
|
|
P.append(cast_block("loopclamp", (0, Ly, 0.0), 0.034, 0.024, 0.05, M.d1, z0=Lz - 0.012, flare=0.1))
|
|
i, c, t = near(Cs, (0, Ly, Lz))
|
|
rclamp(P, M, c, t, 0.0235, w=0.022, th=0.004, ear=None)
|
|
knob_nut(P, Vector((0.035, Ly, Lz + 0.02)), (1, 0, 0), 0.016, M.d1, ref=(0, 0, 1))
|
|
head(P, Vector((-0.035, Ly, Lz + 0.02)), (-1, 0, 0), 0.004, "hex", m=M.hw, ref=(0, 0, 1))
|
|
gz = Lz + 0.183
|
|
for sx in (-1, 1):
|
|
prof = [(0.0, 0.0), (0.0165, 0.0), (0.0195, 0.006), (0.0205, 0.014), (0.0192, 0.022), (0.0206, 0.03), (0.0208, 0.046), (0.019, 0.054), (0.0175, 0.056)]
|
|
g = rev("loopgrip", prof, Vector((0.0, Ly, gz)), (sx, 0, 0), [M.tim], segs=12, cap1=True)
|
|
P.append(timber(g, (1, 0, 0)))
|
|
P.append(rev("lferrule", [(0.0168, -0.006), (0.0206, -0.005), (0.0214, -0.002), (0.0214, 0.004), (0.0206, 0.006), (0.0168, 0.007)],
|
|
Vector((sx * 0.06, Ly, gz)), (sx, 0, 0), [M.brass], segs=12))
|
|
# ---- the gear head at the shaft's end: a ribbed casting, a clamp collar with its bolt, a grease nipple; the guard bolted to it
|
|
GF = FT.frame_on(E, Ax, up=(0, 1, 0))
|
|
P.append(rev("gear", [(0.0, -0.03), (0.03, -0.031), (0.038, -0.028), (0.044, -0.022), (0.048, -0.006), (0.048, 0.004), (0.044, 0.026), (0.034, 0.05),
|
|
(0.029, 0.058), (0.029, 0.068), (0.031, 0.07), (0.031, 0.08), (0.026, 0.083), (0.0, 0.083)], E, Ax, [M.d1], segs=20, ref=(0, 1, 0),
|
|
mod=lambda i, a: 1.0 + (0.07 * max(0.0, math.cos(4 * a)) ** 6 if 4 <= i <= 7 else 0.0), ang=40))
|
|
hbolt(P, M, GF @ Vector((0.034, 0.012, 0.074)), (GF.to_3x3() @ Vector((0, -1, 0))).normalized(), 0.026, 0.003, nut=True, thr=0.003)
|
|
P.append(rev("grease", [(0.0, 0.0), (0.0045, 0.0), (0.0045, 0.004), (0.0032, 0.0055), (0.0032, 0.008), (0.0038, 0.009), (0.0, 0.0105)],
|
|
GF @ Vector((0.046, 0.0, 0.0)), (GF.to_3x3() @ Vector((1, 0, 0))).normalized(), [M.brass], segs=6))
|
|
gr = 0.158
|
|
|
|
def shell(u, v, off):
|
|
a = DEG(28 + 124 * u)
|
|
rr = 0.032 + (gr - 0.032) * v
|
|
return GF @ Vector((rr * math.cos(a), rr * math.sin(a), 0.03 - 0.045 * v * v + off))
|
|
P.append(FT.grid_slab("guard", shell, 16, 4, 0.0035, -0.0035, M.red, smooth_ang=50))
|
|
P.append(sweep("guardrim", [shell(i / 20, 1.0, 0.0) for i in range(21)], lambda s, i: circ(0.0082, 8), [M.st], ang=50))
|
|
for vv in (0.45, 0.78):
|
|
P.append(sweep("guardrib", [shell(0.05 + 0.9 * i / 12, vv, 0.0035) for i in range(13)],
|
|
lambda s, i: [(0.004, -0.001), (0.0026, 0.0028), (-0.0026, 0.0028), (-0.004, -0.001)], [M.yel], ang=50,
|
|
ref=tuple((GF.to_3x3() @ Vector((0, 0, 1))).normalized())))
|
|
for u in (0.2, 0.8):
|
|
p = shell(u, 0.12, 0.0035)
|
|
n = (GF.to_3x3() @ Vector((0, 0, 1))).normalized()
|
|
q = washer(P, p, n, 0.0062, 0.0012, m=M.hw)
|
|
head(P, q, n, 0.0036, "hex", m=M.hw)
|
|
# the line cutter: a small toothed blade riveted to the guard's rim where the line sweeps past
|
|
p0, p1 = shell(0.93, 0.93, 0.0), shell(1.0, 0.93, 0.0)
|
|
nrm = (GF.to_3x3() @ Vector((0, 0, 1))).normalized()
|
|
Fb = fz((p0 + p1) / 2, nrm, (p1 - p0))
|
|
teeth = [(-0.012, -0.006), (0.012, -0.006), (0.012, 0.004)] + [(0.012 - 0.024 * k / 6 - (0.002 if k % 2 else 0.0), 0.007 + (0.003 if k % 2 else 0.0)) for k in range(7)]
|
|
P.append(bprism("cutter", teeth, -0.0045, -0.0025, [M.st, M.d1], bev=0.0006, segs=1, frame=Fb, bev_slot=1))
|
|
for xx in (-0.006, 0.006):
|
|
head(P, Fb @ Vector((xx, -0.002, -0.0025)), -nrm, 0.0018, "dome", m=M.hw)
|
|
body = ffin(P, "Body")
|
|
|
|
# ---- Fan: the line head, built about local Y (local -Y to the ground): a spool with flanges and the wound line showing,
|
|
# eyelets the four lines come out of, a ribbed bump knob
|
|
Q = []
|
|
AX = FT.M_axis("Y")
|
|
Q.append(FT.lathe("spool", [(0.0, 0.0), (0.03, 0.002), (0.046, -0.002), (0.051, -0.006), (0.052, -0.011), (0.047, -0.014), (0.034, -0.015), (0.034, -0.03),
|
|
(0.05, -0.031), (0.058, -0.036), (0.0615, -0.046), (0.06, -0.06), (0.05, -0.069), (0.0, -0.072)], segs=24, m=M.yel, frame=AX, smooth_ang=40))
|
|
for k in range(2):
|
|
t = FT.torus("wound", 0.039, 0.0062, seg=20, rseg=6, m=M.red)
|
|
t.data.transform(AX @ Matrix.Translation((0, 0, -0.0192 - 0.007 * k)))
|
|
Q.append(t)
|
|
Q.append(rev("bump", [(0.028, -0.068), (0.0305, -0.074), (0.029, -0.082), (0.024, -0.09), (0.016, -0.096), (0.0, -0.0995)], Vector(), (0, 1, 0), [M.d1], segs=16,
|
|
mod=lambda i, a: 1.0 + (0.06 * math.cos(8 * a) if 1 <= i <= 3 else 0.0), ang=50))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + 0.4
|
|
dirv = Vector((math.cos(a), 0, math.sin(a)))
|
|
tan = Vector((-math.sin(a), 0, math.cos(a)))
|
|
ey = dirv * 0.0605 + FT.Y_UP * -0.043
|
|
Q.append(rev("eyelet", [(0.0038, -0.003), (0.0062, -0.0025), (0.0066, 0.0), (0.0062, 0.0025), (0.0038, 0.003)], ey, dirv, [M.d1], segs=10))
|
|
pts = [dirv * 0.05 + FT.Y_UP * -0.043, dirv * 0.1 + FT.Y_UP * -0.045 + tan * 0.004, dirv * 0.19 + FT.Y_UP * -0.05 + tan * 0.022]
|
|
Q.append(sweep("line", resample(pts, 10, per=3), lambda s, i: circ(0.0068 * (1 - 0.2 * s), 6), [M.trim], ang=60))
|
|
fan = FT.spinner(Q, "Fan", E - Ax * 0.03, Ax)
|
|
weighted(fan)
|
|
set_origin(fill, (0, -0.065, 0.202))
|
|
uv_box(fill, 4.0)
|
|
empty("Nozzle", tuple(E - Ax * 0.11))
|
|
return {}
|
|
|
|
|
|
# ======================================================================= SM_Tool_HydroCannon (Mulch Cannon)
|
|
|
|
def fan5(name, loc, r, hub, n, M, m_blade, m_hub, pitch=32.0):
|
|
"""A cast fan spinning about the forward axis (Blender -Y): a domed hub with a nose nut and bolts, twisted blades with rounded tips
|
|
and a thinner trailing edge, a shroud ring round the tips."""
|
|
Q = []
|
|
FR = FT.M_fwd(loc)
|
|
loc = Vector(loc)
|
|
Q.append(FT.lathe("hub", [(0.0, -0.016), (hub * 0.7, -0.016), (hub, -0.009), (hub * 1.02, 0.002), (hub, 0.008), (hub * 0.78, 0.014), (hub * 0.42, 0.019),
|
|
(0.0, 0.0205)], segs=18, m=m_hub, frame=FR, cap0=True, smooth_ang=40))
|
|
fwd = Vector((0, -1, 0))
|
|
q = hexnut(Q, loc + fwd * 0.0195, fwd, 0.0075, 0.006, m=m_blade, ref=(1, 0, 0))
|
|
P_ = Q
|
|
for k in range(3):
|
|
a = TAU * (k + 0.5) / 3
|
|
p = FR @ Vector((hub * 0.6 * math.cos(a), hub * 0.6 * math.sin(a), 0.0165))
|
|
head(P_, p, fwd, 0.0022, "hex", m=m_blade)
|
|
for k in range(n):
|
|
th0 = TAU * k / n
|
|
rings = []
|
|
nu, nv = 6, 5
|
|
for i in range(nu + 1):
|
|
u = i / nu
|
|
rho = hub * 0.85 + (r - hub * 0.85) * u
|
|
span = 0.55 + 0.22 * u
|
|
tip = 1.0 if u < 0.8 else math.sqrt(max(0.0, 1 - ((u - 0.8) / 0.2) ** 2)) * 0.75 + 0.25
|
|
ring = []
|
|
for side in (1, -1):
|
|
vs = [j / nv for j in range(nv + 1)]
|
|
if side < 0:
|
|
vs = vs[::-1]
|
|
for v in vs:
|
|
vv = 0.5 + (v - 0.5) * tip
|
|
th = th0 + (vv - 0.5) * span
|
|
ax = (vv - 0.5) * rho * span * math.tan(DEG(pitch * (1.1 - 0.4 * u)))
|
|
t = 0.0026 * (0.35 + 0.65 * math.sin(PI * min(1.0, max(0.0, v * 0.9 + 0.1))))
|
|
ring.append(FR @ Vector((rho * math.cos(th), rho * math.sin(th), ax + side * t)))
|
|
rings.append(ring)
|
|
Q.append(rings_mesh("blade", rings, [m_blade], ang=40))
|
|
Q.append(FT.lathe("shroud", [(r + 0.002, -0.009), (r + 0.006, -0.0085), (r + 0.0085, -0.004), (r + 0.0085, 0.004), (r + 0.006, 0.0085), (r + 0.002, 0.009)],
|
|
segs=32, m=m_hub, frame=FR, cap0=False, cap1=False, smooth_ang=50))
|
|
o = ffin(Q, name, uv=6.0)
|
|
set_origin(o, loc)
|
|
return o
|
|
|
|
|
|
def hydro_cannon():
|
|
M = FM
|
|
P = []
|
|
Z, YR = 0.143, 0.2
|
|
FR = FT.M_fwd((0, YR, Z))
|
|
tube = FT.lathe("tube", [(0.0, -0.002), (0.066, 0.0), (0.096, 0.028), (0.102, 0.06), (0.102, 0.52), (0.1, 0.61), (0.11, 0.655), (0.14, 0.712), (0.178, 0.752),
|
|
(0.194, 0.776)], segs=32, m=M.st, frame=FR, smooth_ang=60)
|
|
FT.around(tube, (0, YR, Z), (0, 1, 0), nu=3.0, s=2.0)
|
|
P.append(tube)
|
|
P.append(FT.lathe("rim", [(0.186, 0.768), (0.2, 0.77), (0.212, 0.782), (0.204, 0.794), (0.186, 0.792), (0.178, 0.782)], segs=32, m=M.red, frame=FR, smooth_ang=70))
|
|
P.append(FT.lathe("throat", [(0.18, 0.784), (0.15, 0.742), (0.112, 0.694), (0.094, 0.652), (0.09, 0.61), (0.03, 0.604), (0.0, 0.604)], segs=32, m=M.d1, frame=FR))
|
|
for d in (0.05, 0.44):
|
|
FT.body_band(P, FR, 0.102, 0.102, d, d + 0.044, M.red, n=2.0, grow=0.004, segs=32)
|
|
FT.body_band(P, FR, 0.102, 0.102, 0.585, 0.605, M.d1, n=2.0, grow=0.005, segs=32)
|
|
# the lap seam along the tube (a strip on the 45 degree line), domed rivets through it
|
|
a45 = Vector((0.7071, 0, 0.7071))
|
|
C = [Vector((0, YR - d, Z)) + a45 * 0.1022 for d in (0.1, 0.25, 0.4, 0.5)]
|
|
P.append(sweep("lapseam", C, lambda s, i: [(-0.0005, -0.009), (0.0014, -0.0085), (0.0018, 0.0), (0.0014, 0.0085), (-0.0005, 0.009)], [M.st],
|
|
ref=tuple(a45), ang=50))
|
|
for k in range(10):
|
|
d = 0.12 + k * 0.035
|
|
rivet(P, Vector((0, YR - d, Z)) + a45 * 0.1035, a45, 0.0034, m=M.brass)
|
|
for k in range(10):
|
|
a = TAU * (k + 0.5) / 10
|
|
rivet(P, FR @ Vector((0.203 * math.cos(a), 0.203 * math.sin(a), 0.7955)), (0, -1, 0), 0.0042, m=M.brass)
|
|
# ---- the timber carriage: saddles across, rails along, carriage bolts through, steel straps over the tube into the saddles
|
|
for y in (0.012, -0.33):
|
|
timber5(P, M, (-0.137, y - 0.037, 0.03), (0.137, y + 0.037, 0.09), 0, ch=0.006, s=2.0, off=(0.13 if y > 0 else 0.4, 0.0), seed=31 if y > 0 else 32)
|
|
C = [Vector((x, y, Z + 0.1045 * math.sqrt(max(0.0, 1 - (x / 0.1045) ** 2)) if abs(x) < 0.1045 else 0.088)) for x in [-0.118 + 0.236 * k / 16 for k in range(17)]]
|
|
for k, x in enumerate([-0.118 + 0.236 * k / 16 for k in range(17)]):
|
|
if abs(x) < 0.1045:
|
|
a = math.acos(max(-1.0, min(1.0, x / 0.1045)))
|
|
C[k] = Vector((0.1045 * math.cos(a), y, Z + 0.1045 * math.sin(a)))
|
|
else:
|
|
C[k] = Vector((x, y, 0.091))
|
|
C[0].z = C[-1].z = 0.091
|
|
P.append(sweep("saddlestrap", C, lambda s, i: rrect(0.0025, 0.012, 0.0018, 1), [M.d1], ref=(0, 0, 1), ang=35))
|
|
for sx in (-1, 1):
|
|
cbolt(P, M, Vector((sx * 0.112, y, 0.0935)), (0, 0, 1), 0.0042, L=0.0635)
|
|
for sx in (-1, 1):
|
|
x0, x1 = sorted((sx * 0.112, sx * 0.158))
|
|
timber5(P, M, (x0, -0.41, 0.078), (x1, 0.16, 0.128), 1, ch=0.0055, s=1.8, off=(0.14 * sx, 0.3), seed=40 + sx)
|
|
# a forged strap over the rail where it sits on each bearer, bolted through the rail
|
|
for y in (0.012, -0.33):
|
|
yy = y + 0.026
|
|
strap_u(P, M, [(sx * 0.1093, yy, 0.0905), (sx * 0.1093, yy, 0.1292), (sx * 0.1607, yy, 0.1292), (sx * 0.1607, yy, 0.0905)], 0.02, 0.0026, (0, 1, 0),
|
|
bend=0.003)
|
|
head(P, Vector((sx * 0.162, yy, 0.108)), (sx, 0, 0), 0.0036, "hex", m=M.hw, ref=(0, 0, 1))
|
|
dome8(P, Vector((sx * 0.1080, yy, 0.108)), (-sx, 0, 0), 0.0032, M.hw)
|
|
for y in (0.012, -0.33):
|
|
cbolt(P, M, Vector((sx * 0.135, y, 0.128)), (0, 0, 1), 0.0055, L=0.098)
|
|
for y in (-0.385, 0.135):
|
|
cbolt(P, M, Vector((sx * 0.135, y, 0.128)), (0, 0, 1), 0.0045)
|
|
# ---- grips; the throttle cable from the rear grip along the carriage, clipped, up to the carburettor
|
|
grip5(P, M, (0, 0, 0), tilt=12, h1=0.046)
|
|
ce = trigger5(P, M, y0=-0.033, z0=0.028, drop=0.05)
|
|
grip5(P, M, (0, -0.33, 0), tilt=0, h0=-0.07, h1=0.04)
|
|
E5, carb = engine5((0, 0.112, 0.295), M, s=0.92, pull=-1, tank=True, tilt=-6)
|
|
P += E5
|
|
cp = [ce, (0.02, -0.05, 0.04), (0.06, -0.04, 0.06), (0.105, -0.01, 0.1), (0.112, 0.03, 0.17), (0.095, 0.05, 0.235), (0.05, 0.05, 0.27), carb + Vector((0.004, 0, 0))]
|
|
cable5(P, M, cp, clips=[], n=36)
|
|
for p, n in (((0.1062, -0.005, 0.12), (0.72, 0, -0.1)), ((0.1005, 0.035, 0.19), (0.5, 0, 0.6))):
|
|
head(P, Vector(p) - Vector(n).normalized() * 0.001, n, 0.0022, "dome", m=M.hw)
|
|
# the engine plate on the tube: a saddle casting, four bolts, a strap round the tube on each side
|
|
P.append(cast_block("seat", (0, 0.112, 0.0), 0.055, 0.065, 0.032, M.d1, z0=0.236, flare=0.06))
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
q = washer(P, Vector((sx * 0.045, 0.112 + sy * 0.054, 0.268)), (0, 0, 1), 0.006, 0.0012, m=M.hw)
|
|
head(P, q, (0, 0, 1), 0.0034, "hex", m=M.hw, ref=(1, 0, 0))
|
|
# ---- the tin hopper, leaning towards the operator: a riveted seam up its side, a rolled rim, a clamped neck band, two braces
|
|
HC = Vector((0, -0.145, 0.222))
|
|
HF = Matrix.Translation(HC) @ Matrix.Rotation(DEG(-12), 4, "X")
|
|
hax = (HF.to_3x3() @ Vector((0, 0, 1))).normalized()
|
|
ho = FT.lathe("hopper", [(0.066, 0.0), (0.068, 0.032), (0.096, 0.075), (0.128, 0.128), (0.15, 0.17), (0.153, 0.178)], segs=28, m=M.tin, frame=HF, smooth_ang=70)
|
|
FT.around(ho, HC, hax, nu=3.0, s=6.0)
|
|
P.append(ho)
|
|
P.append(FT.lathe("hin", [(0.15, 0.178), (0.122, 0.134), (0.09, 0.09), (0.06, 0.05), (0.0, 0.05)], segs=28, m=M.d1, frame=HF))
|
|
P.append(rev("hrim", [(0.149, -0.004), (0.157, -0.0055), (0.1635, -0.002), (0.165, 0.004), (0.161, 0.0095), (0.154, 0.0105), (0.149, 0.007)],
|
|
HF @ Vector((0, 0, 0.18)), hax, [M.st], segs=28, ang=50))
|
|
P.append(rev("hband", [(0.066, -0.009), (0.072, -0.008), (0.0745, -0.004), (0.0745, 0.004), (0.072, 0.008), (0.066, 0.009)], HF @ Vector((0, 0, 0.022)), hax,
|
|
[M.red], segs=24, ang=50))
|
|
ang_s = DEG(250)
|
|
sp = [HF @ Vector(((rr + 0.001) * math.cos(ang_s), (rr + 0.001) * math.sin(ang_s), z)) for rr, z in ((0.068, 0.035), (0.096, 0.075), (0.128, 0.128), (0.15, 0.168))]
|
|
P.append(sweep("hseam", resample(sp, 8), lambda s, i: [(-0.0004, -0.006), (0.0012, -0.0055), (0.0015, 0.0), (0.0012, 0.0055), (-0.0004, 0.006)], [M.tin],
|
|
ref=tuple(hax), ang=50))
|
|
for k in range(5):
|
|
p = resample(sp, 4)[k]
|
|
nrm = (p - (HF @ Vector((0, 0, (HF.inverted() @ p).z)))).normalized()
|
|
rivet(P, p + nrm * 0.0012, nrm, 0.0026, m=M.brass)
|
|
for a in (35, 145):
|
|
ax = DEG(a)
|
|
top = HF @ Vector((0.156 * math.cos(ax), 0.156 * math.sin(ax), 0.17))
|
|
bot = HF @ Vector((0.094 * math.cos(ax), 0.094 * math.sin(ax), 0.06))
|
|
bot2 = Vector((bot.x * 1.08, bot.y, Z + 0.06))
|
|
P.append(sweep("hbrace", fillet([top, bot, bot2], 0.02, 3), lambda s, i: rrect(0.009, 0.0022, 0.0016, 1), [M.d1], ref=(0, 1, 0), ang=40))
|
|
for p in (top, bot2):
|
|
head(P, p + Vector((0, 0, 0.003)), (0, 0, 1), 0.0028, "hex", m=M.hw)
|
|
hp = FT.sphere("heap", 0.122, (0, 0, 0), seg=16, rings=8, m=M.clip, scale=(1.0, 1.0, 0.5))
|
|
FT.wobble(hp, 0.018, 16.0, seed=1.0)
|
|
hp.data.transform(HF @ Matrix.Translation((0, 0, 0.158)))
|
|
uv_box(hp, 3.0)
|
|
hp["uv_done"] = True
|
|
P.append(hp)
|
|
ffin(P, "Body")
|
|
fan5("Fan", (0, -0.435, Z), 0.08, 0.026, 6, M, M.br, M.red)
|
|
empty("Nozzle", (0, -0.586, Z))
|
|
return {}
|
|
|
|
|
|
# ======================================================================= SM_Tool_MegaSiphon (Tornado Mower)
|
|
|
|
def ring5(name, A, sx, M, r=0.172):
|
|
"""One half of the blade drum, |x| 0.034..0.216, built about local Y: a teal core with rolled ends, a red end disc with six bolts and
|
|
a domed hub nut, a navy flange with bolts, four helical blades (a real section, thin at the tip) bolted to root strips."""
|
|
Q = []
|
|
y0, y1 = sx * 0.034, sx * 0.216
|
|
FR = FT.M_axis("Y" if sx > 0 else "-Y")
|
|
ax = Vector((0, sx, 0))
|
|
Q.append(FT.lathe("core", [(0.0, 0.034), (0.072, 0.034), (0.077, 0.037), (0.078, 0.042), (0.078, 0.194), (0.077, 0.2), (0.072, 0.204), (0.0, 0.204)],
|
|
segs=18, m=M.teal, frame=FR, smooth_ang=40))
|
|
Q.append(FT.lathe("disc", [(0.0, 0.2), (0.108, 0.2), (0.124, 0.2025), (0.128, 0.207), (0.128, 0.214), (0.122, 0.2185), (0.108, 0.22), (0.05, 0.222), (0.0, 0.224)],
|
|
segs=22, m=M.red, frame=FR, smooth_ang=40))
|
|
Q.append(FT.lathe("flange", [(0.074, 0.111), (0.11, 0.111), (0.1155, 0.114), (0.1165, 0.118), (0.1155, 0.122), (0.11, 0.125), (0.074, 0.125)],
|
|
segs=18, m=M.d1, frame=FR, smooth_ang=40))
|
|
for k in range(6):
|
|
a = TAU * (k + 0.5) / 6
|
|
head(Q, FR @ Vector((0.085 * math.cos(a), 0.085 * math.sin(a), 0.2205)), ax, 0.0042, "hex", m=M.d1, ref=(1, 0, 0))
|
|
hexnut(Q, FR @ Vector((0, 0, 0.2235)), ax, 0.016, 0.0035, m=M.d1, ref=(1, 0, 0))
|
|
|
|
for k in range(4):
|
|
th0 = TAU * k / 4 + (0.0 if sx > 0 else 0.4)
|
|
tw = 1.15 * sx
|
|
rings = []
|
|
nu, nv = 6, 4
|
|
for i in range(nu + 1):
|
|
u = i / nu
|
|
ring = []
|
|
for side in (1, -1):
|
|
vs = [j / nv for j in range(nv + 1)]
|
|
if side < 0:
|
|
vs = vs[::-1]
|
|
for v in vs:
|
|
rho = 0.07 + (r - 0.07) * v
|
|
t = 0.0048 * (1 - 0.8 * v ** 2.2) + 0.0004
|
|
a = th0 + tw * u - 0.55 * v * v + side * t / rho
|
|
ring.append(FR @ Vector((rho * math.cos(a), rho * math.sin(a), 0.034 + 0.182 * u)))
|
|
rings.append(ring)
|
|
Q.append(rings_mesh("cut", rings, [M.br], ang=38))
|
|
|
|
def fn2(u, v, off, th0=th0, tw=tw):
|
|
rr = 0.078 + 0.03 * v
|
|
return FR @ Vector((rr * math.cos(th0 + tw * u + off / 0.09), rr * math.sin(th0 + tw * u + off / 0.09), 0.034 + 0.182 * u))
|
|
Q.append(FT.grid_slab("root", fn2, 6, 1, 0.0095, -0.0095, M.d1, smooth_ang=35))
|
|
for u in (0.25, 0.75):
|
|
|
|
p = fn2(u, 0.62, 0.0)
|
|
c = FR @ Vector((0, 0, 0.034 + 0.182 * u))
|
|
tang = (fn2(u, 0.62, 0.001) - p).normalized()
|
|
head(Q, p + tang * 0.0098, tang, 0.0032, "hex", m=M.d1)
|
|
o = FT.spinner(Q, name, A, (1, 0, 0), uv=4.0, ang=38)
|
|
weighted(o)
|
|
return o
|
|
|
|
|
|
def mega_siphon():
|
|
M = FM
|
|
P = []
|
|
A = Vector((0, -0.445, 0.158))
|
|
# ---- the timber chassis: two side rails, three cross bearers under them, a deck of four planks; chamfered edges, end grain at
|
|
# the sawn ends, the planks' chamfers meeting in V seams; forged straps over the rails at the bearers, bolted
|
|
for sx in (-1, 1):
|
|
x0, x1 = sorted((sx * 0.172, sx * 0.226))
|
|
timber5(P, M, (x0, -0.26, 0.09), (x1, 0.268, 0.15), 1, ch=0.006, s=1.6, off=(0.1 * sx, 0.2), seed=3 + sx)
|
|
for y, w in ((0.0, 0.04), (-0.25, 0.04), (0.235, 0.032)):
|
|
timber5(P, M, (-0.176, y - w, 0.074), (0.176, y + w, 0.13), 0, ch=0.005, s=1.6, off=(0.13 + y, 0.0), seed=int(y * 100) + 9, ends=(False, False))
|
|
for sx in (-1, 1):
|
|
for y in (0.0, 0.235):
|
|
strap_u(P, M, [(sx * 0.18, y, 0.1514), (sx * 0.2275, y, 0.1514), (sx * 0.2275, y, 0.094)], 0.024, 0.0028, (0, 1, 0), bend=0.003)
|
|
head(P, Vector((sx * 0.2289, y, 0.112)), (sx, 0, 0), 0.0042, "hex", m=M.hw, ref=(0, 0, 1))
|
|
for y in (0.0, -0.25, 0.235):
|
|
cbolt(P, M, Vector((sx * 0.199, y, 0.15 + (0.0028 if y > -0.1 else 0.0))), (0, 0, 1), 0.0062)
|
|
for k, x in enumerate((-0.126, -0.042, 0.042, 0.126)):
|
|
timber5(P, M, (x - 0.0398, -0.17, 0.13), (x + 0.0398, 0.21, 0.152), 1, ch=0.0032, s=1.5, off=(0.25 * k, 0.15 * k), seed=20 + k, bow=0.0007)
|
|
for y in (-0.15, 0.19):
|
|
if abs(x) > 0.1 or y > 0:
|
|
dome8(P, Vector((x, y, 0.152)), (0, 0, 1), 0.0032, M.hw)
|
|
grip5(P, M, (0, 0, 0), tilt=12, h1=0.078)
|
|
ce = trigger5(P, M, y0=-0.034, z0=0.046, drop=0.05)
|
|
grip5(P, M, (0, -0.25, 0), tilt=0, h0=-0.07, h1=0.078)
|
|
E5, carb = engine5((-0.062, 0.05, 0.205), M, s=1.06, pull=1, tank=True, stack=True)
|
|
P += E5
|
|
cable5(P, M, [ce, (0.02, -0.05, 0.07), (0.035, -0.06, 0.12), (0.03, -0.05, 0.16), (0.0, -0.04, 0.18), (-0.03, -0.035, 0.2), carb + Vector((0.004, 0, 0))],
|
|
clips=[], n=24)
|
|
# ---- chain case: a cast cover over the chain from the engine's sprocket down to the drum's. The two halves meet at a flange
|
|
# round the edge, bolted; each side is domed over the sprockets, stiffened by two ribs along the run, an inspection cover between.
|
|
# At the drum the case runs into the round sprocket housing, bolted round its face, a breather on top.
|
|
Cr, rr0 = (-0.005, 0.196), 0.04
|
|
Cf, rf0 = (A.y, A.z), 0.058
|
|
circ_pts = [(Cr[0] + rr0 * math.cos(TAU * k / 20), Cr[1] + rr0 * math.sin(TAU * k / 20)) for k in range(20)]
|
|
circ_pts += [(Cf[0] + rf0 * math.cos(TAU * k / 24), Cf[1] + rf0 * math.sin(TAU * k / 24)) for k in range(24)]
|
|
base = densify2d(hull2d(circ_pts), 0.06)
|
|
Fx = Matrix(((0, 0, 1, 0), (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 1))) # local (y, z) outline, x -> world
|
|
|
|
def ring_at(out, x):
|
|
return [Vector((x, u, v)) for u, v in out]
|
|
lip, sh1, sh2 = offset2d(base, 0.006), offset2d(base, -0.005), offset2d(base, -0.009)
|
|
rings = [ring_at(sh2, -0.0165), ring_at(sh1, -0.0152), ring_at(base, -0.008), ring_at(base, -0.0055), ring_at(lip, -0.0045), ring_at(lip, 0.0045),
|
|
ring_at(base, 0.0055), ring_at(base, 0.008), ring_at(sh1, 0.0152), ring_at(sh2, 0.0165)]
|
|
P.append(rings_mesh("chaincase", rings, [M.red], ang=40))
|
|
# bolts through the flange, heads on the near side, nuts on the far
|
|
nb_ = len(base)
|
|
for k in range(0, nb_, max(1, nb_ // 9)):
|
|
u, v = offset2d(base, 0.0032)[k]
|
|
if math.hypot(u - A.y, v - A.z) < 0.185:
|
|
continue # inside the drum, among the blades
|
|
for sx in (-1, 1):
|
|
if sx > 0:
|
|
head(P, Vector((0.0045, u, v)), (1, 0, 0), 0.0021, "hex", m=M.hw, ref=(0, 0, 1))
|
|
else:
|
|
hexnut(P, Vector((-0.0045, u, v)), (-1, 0, 0), 0.0038, 0.0028, m=M.hw, ref=(0, 0, 1))
|
|
# the domes over the rear sprocket, a bearing cap and its screws
|
|
for sx in (-1, 1):
|
|
c = Vector((sx * 0.0162, Cr[0], Cr[1]))
|
|
P.append(rev("sdome", [(rr0 * 0.86, -0.001), (rr0 * 0.84, 0.0022), (rr0 * 0.7, 0.0048), (rr0 * 0.45, 0.0062), (rr0 * 0.36, 0.0064)], c, (sx, 0, 0),
|
|
[M.red], segs=16, ref=(0, 0, 1), ang=45))
|
|
P.append(rev("scap", [(rr0 * 0.36, 0.006), (rr0 * 0.34, 0.0085), (rr0 * 0.26, 0.0098), (0.0, 0.01)], c, (sx, 0, 0), [M.d1], segs=12, ref=(0, 0, 1), ang=45))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.5
|
|
dome8(P, c + Vector((sx * 0.0087, 0.0, 0.0)) + Vector((0, rr0 * 0.22 * math.cos(a), rr0 * 0.22 * math.sin(a))), (sx, 0, 0), 0.0012, M.hw)
|
|
# two stiffening ribs along the run, from the dome to the drum housing, faded in at their ends
|
|
d_ = Vector((0, Cf[0] - Cr[0], Cf[1] - Cr[1])).normalized()
|
|
nrm_ = Vector((0, -d_.z, d_.y))
|
|
for off in (-0.017, 0.017):
|
|
p0 = Vector((sx * 0.0162, Cr[0], Cr[1])) + d_ * (rr0 * 0.95) + nrm_ * off
|
|
p1 = Vector((sx * 0.0162, Cf[0], Cf[1])) - d_ * (rf0 * 1.02) + nrm_ * off * 1.2
|
|
C = [p0.lerp(p1, k / 4) for k in range(5)]
|
|
|
|
def ribsec(s, i):
|
|
k = min(1.0, s * 6, (1 - s) * 6)
|
|
hh = 0.0035 * k + 0.0003
|
|
return [(0.0042, -0.0006), (0.0026, hh * 0.8), (0.0, hh), (-0.0026, hh * 0.8), (-0.0042, -0.0006)]
|
|
P.append(sweep("crib", C, lambda s, i: [(q[1], q[0]) for q in ribsec(s, i)], [M.red], ref=(sx, 0, 0), ang=50))
|
|
# the inspection cover between the ribs, four screws
|
|
cv = Vector((sx * 0.0162, -0.2, 0.0)) + Vector((0, 0, Cr[1] + (Cf[1] - Cr[1]) * ((-0.2 - Cr[0]) / (Cf[0] - Cr[0]))))
|
|
P.append(bprism("inspect", rounded_outline([(-0.028, -0.011), (0.028, -0.011), (0.028, 0.011), (-0.028, 0.011)], 0.007, 2), -0.0005, 0.0026,
|
|
[M.d1, M.st], bev=0.0008, segs=1, bev_slot=1, frame=fz(cv, (sx, 0, 0), d_)))
|
|
for du in (-0.021, 0.021):
|
|
for dv in (-0.0055, 0.0055):
|
|
dome8(P, cv + Vector((sx * 0.0026, 0, 0)) + d_ * du + nrm_ * dv, (sx, 0, 0), 0.0013, M.hw)
|
|
P.append(rev("filler", [(0.0, 0.0), (0.009, 0.0), (0.0095, 0.004), (0.0085, 0.008), (0.0, 0.0085)], Vector((0, -0.08, 0.2335)), (0, 0.08, 1), [M.brass], segs=10,
|
|
mod=lambda i, a: 1.0 + (0.08 * math.cos(8 * a) if i in (1, 2) else 0.0)))
|
|
# the drum's sprocket housing: a round casting about the drum axis, a rolled rim, six bolts round each face, a breather on top
|
|
P.append(rev("gearbox", [(0.0, -0.027), (0.046, -0.027), (0.054, -0.025), (0.059, -0.019), (0.061, -0.012), (0.061, 0.012), (0.059, 0.019), (0.054, 0.025),
|
|
(0.046, 0.027), (0.0, 0.027)], A, (1, 0, 0), [M.d1], segs=20, ref=(0, 0, 1), ang=40))
|
|
for sx in (-1, 1):
|
|
for k in range(6):
|
|
a = TAU * (k + 0.5) / 6
|
|
head(P, A + Vector((sx * 0.027, 0.047 * math.cos(a), 0.047 * math.sin(a))), (sx, 0, 0), 0.0024, "hex", m=M.hw, ref=(0, 0, 1))
|
|
P.append(rev("breather", [(0.0, 0.0), (0.004, 0.0), (0.004, 0.008), (0.0075, 0.009), (0.0075, 0.013), (0.0, 0.014)], A + Vector((0, 0.012, 0.0595)), (0, 0, 1),
|
|
[M.brass], segs=8))
|
|
# ---- the red side arms bolted outside the rails, bearing housings with three bolts and a grease nipple, skids on bolted hangers
|
|
arm = [(-0.08, 0.158), (-0.08, 0.082), (-0.2, 0.082), (-0.445 + 0.03, 0.1), (-0.445 + 0.052, 0.13), (-0.445 + 0.06, 0.16), (-0.445 + 0.04, 0.2), (-0.445, 0.218),
|
|
(-0.445 - 0.042, 0.2), (-0.445 - 0.06, 0.158), (-0.445 - 0.042, 0.116), (-0.445 - 0.01, 0.1), (-0.32, 0.17), (-0.2, 0.172)]
|
|
ao = rounded_outline(arm, 0.01, 2)
|
|
for sx in (-1, 1):
|
|
P.append(bprism("arm", ao, 0.226 * sx, 0.244 * sx, [M.red, M.red], bev=0.0035, segs=1, frame=Fx))
|
|
P.append(rev("bearing", [(0.0, 0.243), (0.03, 0.243), (0.046, 0.2445), (0.05, 0.2475), (0.05, 0.25), (0.044, 0.2525), (0.028, 0.2535), (0.02, 0.2565), (0.0, 0.257)],
|
|
Vector((0, A.y, A.z)), (sx, 0, 0), [M.d1], segs=14))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.5
|
|
head(P, Vector((sx * 0.2533, A.y + 0.037 * math.cos(a), A.z + 0.037 * math.sin(a))), (sx, 0, 0), 0.003, "hex", m=M.hw, ref=(0, 0, 1))
|
|
P.append(rev("grease", [(0.0, 0.0), (0.0035, 0.0), (0.0035, 0.004), (0.0025, 0.0055), (0.0025, 0.008), (0.003, 0.009), (0.0, 0.0105)],
|
|
Vector((sx * 0.247, A.y, A.z + 0.049)), (0, 0, 1), [M.brass], segs=6))
|
|
for y in (-0.1, -0.16, -0.25):
|
|
hbolt(P, M, Vector((sx * 0.2445, y, 0.135 if y > -0.2 else 0.13)), (sx, 0, 0), 0.0725, 0.0042, ref=(0, 0, 1), nut=False)
|
|
sk = [Vector((sx * 0.235, -0.27, 0.09)), Vector((sx * 0.235, -0.45, -0.004)), Vector((sx * 0.235, -0.58, 0.0)), Vector((sx * 0.235, -0.655, 0.05))]
|
|
P.append(sweep("skid", resample(sk, 16, per=6), lambda s, i: circ(0.0115, 8), [M.st], ref=(1, 0, 0), ang=40))
|
|
hk = resample(sk, 16, per=6)[7]
|
|
|
|
P.append(sweep("hanger", [hk + Vector((0, 0, 0.004)), Vector((sx * 0.235, hk.y + 0.02, 0.085))], lambda s, i: rrect(0.003, 0.01, 0.002, 1), [M.d1],
|
|
ref=(1, 0, 0), ang=40))
|
|
hbolt(P, M, Vector((sx * 0.2445, hk.y + 0.02, 0.09)), (sx, 0, 0), 0.0125, 0.0034, ref=(0, 0, 1), thr=0.003)
|
|
# ---- the deflector behind the drum: tin, a rolled top rim, rivets along its ends, stays bolted to the arms
|
|
D_R = 0.19
|
|
|
|
def defl(u, v, off):
|
|
a = DEG(-34 + 54 * u)
|
|
rr = D_R + off
|
|
return Vector((-0.216 + 0.432 * v, A.y + rr * math.cos(a), A.z + rr * math.sin(a)))
|
|
d = FT.grid_slab("deflector", defl, 8, 6, 0.0025, -0.0025, M.tin, smooth_ang=60)
|
|
FT.grain(d, (0, 0.5, 0.5), 4.0)
|
|
P.append(d)
|
|
ptop = defl(1.0, 0.0, 0.0)
|
|
P.append(tube5("deflrim", [ptop + Vector((-0.004, 0, 0)), Vector((-ptop.x + 0.004, ptop.y, ptop.z))], 0.0085, M.st, segs=10))
|
|
for v in (0.0, 1.0):
|
|
for u in (0.15, 0.5, 0.85):
|
|
p = defl(u, v, 0.003)
|
|
nrm = (p - Vector((p.x, A.y, A.z))).normalized()
|
|
rivet(P, p + Vector((0.006 if v == 0 else -0.006, 0, 0)), nrm, 0.0026, m=M.brass)
|
|
ffin(P, "Body")
|
|
ring5("Ring1", A, 1, M)
|
|
ring5("Ring2", A, -1, M)
|
|
empty("Nozzle", (0, -0.656, 0.158))
|
|
return {}
|
|
|
|
|
|
# ======================================================================= main: build
|
|
|
|
BUILDERS = {"SM_Tool_LawnMower": lawn_mower, "SM_Tool_HandPump": hand_pump, "SM_Tool_SlurpGun": slurp_gun, "SM_Tool_HydroCannon": hydro_cannon,
|
|
"SM_Tool_MegaSiphon": mega_siphon}
|
|
BUDGET = {"SM_Tool_LawnMower": 25000, "SM_Tool_HandPump": 25000, "SM_Tool_SlurpGun": 25000, "SM_Tool_HydroCannon": 25000, "SM_Tool_MegaSiphon": 25000}
|
|
|
|
|
|
def build(names):
|
|
import zlib
|
|
common.MODELS = os.path.join(OUT, "fbx")
|
|
common.BLENDS = OUT
|
|
common.PREVIEWS = os.path.join(OUT, "previews")
|
|
for d in (common.MODELS, common.PREVIEWS):
|
|
os.makedirs(d, exist_ok=True)
|
|
for n in names:
|
|
common.reset()
|
|
random.seed(zlib.crc32(n.encode()) & 0xffff)
|
|
BUILDERS[n]()
|
|
bpy.context.view_layer.update()
|
|
t = tri_count()
|
|
for o in sorted(bpy.context.scene.objects, key=lambda o: o.name):
|
|
mats = sorted(set(m.name for m in o.data.materials if m)) if o.type == "MESH" else []
|
|
print(f"[{n}] {o.type:6s} {o.name:10s} tris={tri_count([o]) if o.type == 'MESH' else '-':>6} loc={tuple(round(v, 4) for v in o.location)}"
|
|
f" rot={tuple(round(math.degrees(v), 2) for v in o.rotation_euler)} mats={mats}")
|
|
print(f"[{n}] tris={t} budget={BUDGET.get(n)} {'OVER' if t > BUDGET.get(n, 1 << 30) else 'ok'}", flush=True)
|
|
common.export(n)
|
|
common.save_blend(n)
|
|
print(f"[{n}] done", flush=True)
|
|
|
|
|
|
# ======================================================================= review: verify, views, compose
|
|
|
|
# object -> bounding box tolerance (m) per side against the game model
|
|
BB_TOL = {"Body": 0.02}
|
|
BB_TOL_PART = 0.012
|
|
|
|
|
|
def _K():
|
|
for _ in range(8):
|
|
try:
|
|
import gc_up5_check as K
|
|
return K
|
|
except Exception as e: # noqa: BLE001
|
|
print("gc_up5_machines: import gc_up5_check failed, retrying in 60 s:", repr(e), flush=True)
|
|
time.sleep(60)
|
|
raise RuntimeError("gc_up5_check would not import")
|
|
|
|
|
|
def snap(path):
|
|
"""objects -> (type, parent, loc, rot (deg), scale, bbox min, bbox max, tris, slots, local axes)"""
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
bpy.ops.import_scene.fbx(filepath=path)
|
|
bpy.context.view_layer.update()
|
|
out = {}
|
|
for o in bpy.context.scene.objects:
|
|
mw = o.matrix_world
|
|
if o.type == "MESH":
|
|
ws = [mw @ v.co for v in o.data.vertices]
|
|
mn = Vector([min(w[i] for w in ws) for i in range(3)])
|
|
mx = Vector([max(w[i] for w in ws) for i in range(3)])
|
|
tris = sum(len(p.vertices) - 2 for p in o.data.polygons)
|
|
mats = sorted(set(m.name.split(".")[0] for m in o.data.materials if m))
|
|
else:
|
|
mn = mx = mw.translation.copy()
|
|
tris, mats = 0, []
|
|
R = mw.to_3x3().normalized()
|
|
out[o.name.split(".")[0]] = dict(type=o.type, parent=o.parent.name.split(".")[0] if o.parent else None, loc=mw.translation.copy(),
|
|
rot=Vector([math.degrees(a) for a in mw.to_euler()]), scale=mw.to_scale(), mn=mn, mx=mx, tris=tris, mats=mats,
|
|
axes=[R.col[i].copy() for i in range(3)])
|
|
return out
|
|
|
|
|
|
def verify(names):
|
|
bad_total = 0
|
|
for n in names:
|
|
old = snap(os.path.join(GAME, n + ".fbx"))
|
|
new = snap(os.path.join(OUT, "fbx", n + ".fbx"))
|
|
bad = 0
|
|
print(f"VM|{n}")
|
|
if set(old) != set(new):
|
|
print(f"VM| FAIL objects differ: old {sorted(old)} new {sorted(new)}")
|
|
bad += 1
|
|
allowed = set(m for o in old.values() for m in o["mats"])
|
|
for k in sorted(set(old) & set(new)):
|
|
o, w = old[k], new[k]
|
|
dloc = (o["loc"] - w["loc"]).length
|
|
drot = max(abs(a - b) for a, b in zip(o["rot"], w["rot"]))
|
|
dsc = max(abs(a - b) for a, b in zip(o["scale"], w["scale"]))
|
|
dax = max((a - b).length for a, b in zip(o["axes"], w["axes"]))
|
|
ok = o["type"] == w["type"] and o["parent"] == w["parent"] and dloc < 1e-4 and drot < 1e-3 and dsc < 1e-4 and dax < 1e-4
|
|
print(f"VM| {'ok ' if ok else 'FAIL'} {k:<9} {w['type']:<5} parent {w['parent']} origin {tuple(round(x, 4) for x in w['loc'])} (d {dloc:.1e}) "
|
|
f"rot {tuple(round(x, 2) for x in w['rot'])} (d {drot:.1e}) scale d {dsc:.1e} axes d {dax:.1e}")
|
|
bad += 0 if ok else 1
|
|
if w["type"] == "MESH":
|
|
tol = BB_TOL.get(k, BB_TOL_PART)
|
|
dmn = [b - a for a, b in zip(o["mn"], w["mn"])]
|
|
dmx = [b - a for a, b in zip(o["mx"], w["mx"])]
|
|
worst = max(abs(x) for x in dmn + dmx)
|
|
okb = worst <= tol
|
|
bad += 0 if okb else 1
|
|
f = lambda v: "(" + ", ".join(f"{x:+.3f}" for x in v) + ")"
|
|
print(f"VM| {'ok ' if okb else 'FAIL'} bbox old {tuple(round(x, 3) for x in o['mn'])}..{tuple(round(x, 3) for x in o['mx'])}")
|
|
print(f"VM| new {tuple(round(x, 3) for x in w['mn'])}..{tuple(round(x, 3) for x in w['mx'])} d min {f(dmn)} d max {f(dmx)} (tol {tol})")
|
|
extra = sorted(set(w["mats"]) - set(o["mats"]))
|
|
foreign = sorted(set(w["mats"]) - allowed)
|
|
nomat = sorted(m for m in w["mats"] if not os.path.exists(os.path.join(ROOT, "Assets", "Art", "Materials", m + ".mat")))
|
|
print(f"VM| tris {o['tris']} -> {w['tris']} slots {w['mats']}")
|
|
print(f"VM| slots new to this object: {extra or 'none'} new to the model: {foreign or 'none'} without a .mat: {nomat or 'none'}")
|
|
if nomat or any(m.startswith("P_") for m in w["mats"]):
|
|
bad += 1
|
|
tot_o = sum(o["tris"] for o in old.values())
|
|
tot_n = sum(o["tris"] for o in new.values())
|
|
over = tot_n > BUDGET.get(n, 1 << 30)
|
|
bad += 1 if over else 0
|
|
print(f"VM| total tris {tot_o} -> {tot_n} (budget {BUDGET.get(n)}) {'OVER' if over else 'ok'}")
|
|
print(f"VM| {n}: {'OK' if bad == 0 else f'{bad} problem(s)'}")
|
|
bad_total += bad
|
|
print("VM|RESULT|" + ("OK" if bad_total == 0 else f"{bad_total} problem(s)"))
|
|
|
|
|
|
# (tag, target or None for the whole model, radius, elev, azim)
|
|
VIEWS = {
|
|
"SM_Tool_LawnMower": [("full", None, None, 28, -38), ("back", None, None, 30, 145), ("engine", (0.0, -0.86, -0.6), 0.2, 35, -35),
|
|
("plug", (0.0, -1.0, -0.65), 0.08, 25, -30), ("grip", (0.18, -0.04, -0.02), 0.13, 30, 160),
|
|
("wheel", (0.57, -1.08, -0.85), 0.12, 15, 70), ("lever", (0.54, -0.5, -0.8), 0.12, 20, 110),
|
|
("bracket", (0.4, -0.47, -0.71), 0.09, 35, 140), ("bag", (0.05, -0.2, -0.75), 0.24, 25, 160),
|
|
("under", (0.0, -0.8, -0.89), 0.4, -40, -20), ("deck", (0.0, -0.78, -0.72), 0.34, 42, -150),
|
|
("deck_f", (0.1, -0.95, -0.72), 0.22, 30, -20)],
|
|
"SM_Tool_HandPump": [("full", None, None, 28, -40), ("back", None, None, 22, 150), ("gearbox", (0.0, 0.02, 0.07), 0.12, 30, 60),
|
|
("bar", (0.0, -0.3, -0.03), 0.16, 40, -60), ("bar_under", (0.0, -0.3, -0.03), 0.16, -35, -50), ("bag", (0.0, 0.08, 0.2), 0.13, 35, 50),
|
|
("buckle", (0.09, 0.08, 0.18), 0.07, 15, 75), ("grip", (0.0, 0.0, 0.0), 0.09, 10, -70), ("grip_b", (0.0, 0.02, 0.02), 0.08, 25, 140),
|
|
("flange", (0.06, 0.06, 0.07), 0.09, 20, 70), ("handle", (0.0, 0.27, 0.07), 0.1, 30, 160)],
|
|
"SM_Tool_SlurpGun": [("full", None, None, 22, -40), ("back", None, None, 20, 155), ("engine", (0.0, 0.13, 0.2), 0.12, 25, 60),
|
|
("engine_l", (0.0, 0.13, 0.19), 0.12, 20, -70), ("plug", (0.0, 0.13, 0.32), 0.06, 35, 30), ("jar", (0.0, -0.065, 0.25), 0.11, 20, -40),
|
|
("grip", (0.0, 0.0, 0.02), 0.09, 10, -80), ("head", (0.0, -0.66, -0.12), 0.16, 30, -50), ("head_under", (0.0, -0.66, -0.15), 0.16, -40, -30),
|
|
("loop", (0.0, -0.215, 0.14), 0.12, 25, 140)],
|
|
"SM_Tool_HydroCannon": [("full", None, None, 24, -40), ("back", None, None, 20, 155), ("engine", (0.0, 0.11, 0.38), 0.13, 25, 120),
|
|
("engine_r", (0.0, 0.11, 0.37), 0.13, 20, -70), ("hopper", (0.0, -0.15, 0.36), 0.18, 40, 150), ("mouth", (0.0, -0.5, 0.143), 0.2, 10, -15),
|
|
("carriage", (0.135, -0.33, 0.11), 0.09, 30, 60), ("rails", (0.0, -0.15, 0.08), 0.26, 35, 130)
|
|
, ("grip", (0.0, -0.02, 0.0), 0.09, 10, -80), ("fan", (0.0, -0.44, 0.143), 0.1, 5, -5), ("lockout", (0.0, 0.03, 0.02), 0.05, 15, -120)],
|
|
"SM_Tool_MegaSiphon": [("full", None, None, 26, -40), ("back", None, None, 22, 155), ("engine", (-0.06, 0.05, 0.3), 0.15, 25, 120),
|
|
("stack", (-0.15, 0.05, 0.38), 0.08, 20, 140), ("drum", (0.0, -0.45, 0.16), 0.2, 20, -40), ("hub", (0.24, -0.445, 0.158), 0.09, 15, 80),
|
|
("chain", (0.0, -0.2, 0.18), 0.17, 30, -70), ("chain_r", (0.0, -0.15, 0.19), 0.12, 25, 80), ("rail", (0.2, 0.18, 0.13), 0.1, 30, 130), ("grip", (0.0, -0.02, 0.02), 0.09, 10, -80), ("deck", (0.08, 0.05, 0.16), 0.16, 50, -30)],
|
|
}
|
|
# first-person cameras: (eye, look-at, vertical fov) in the model's own frame
|
|
FPV = {"SM_Tool_LawnMower": [("fpv", (0.0, 0.33, 0.47), (0.0, -1.1, -0.5), 60)]}
|
|
# the old ViewModel holds of the four farm machines (verify_farm_tools.RIGS): Unity position, euler, scale
|
|
HOLDS = {"SM_Tool_HandPump": ((0.19, -0.2, 0.46), (-2, -4, 0), 0.6), "SM_Tool_SlurpGun": ((0.2, -0.21, 0.48), (-2, -4, 0), 0.56),
|
|
"SM_Tool_HydroCannon": ((0.2, -0.22, 0.5), (-1, -4, 0), 0.5), "SM_Tool_MegaSiphon": ((0.21, -0.23, 0.54), (-1, -4, 0), 0.46)}
|
|
|
|
|
|
def studio_world(strength=0.6):
|
|
"""Replace gc_up5_check's flat sky-blue world with a studio one: a dark floor below the horizon, a cool sky above. Polished steel
|
|
then reflects something other than the backdrop behind it (in the flat world the combs vanished against it)."""
|
|
w = bpy.context.scene.world
|
|
nt = w.node_tree
|
|
bg = nt.nodes.get("Background")
|
|
tc = nt.nodes.new("ShaderNodeTexCoord")
|
|
sep = nt.nodes.new("ShaderNodeSeparateXYZ")
|
|
mr = nt.nodes.new("ShaderNodeMapRange")
|
|
mr.inputs["From Min"].default_value = -1.0
|
|
mr.inputs["From Max"].default_value = 1.0
|
|
ramp = nt.nodes.new("ShaderNodeValToRGB")
|
|
el = ramp.color_ramp.elements
|
|
el[0].position, el[0].color = 0.46, (0.085, 0.08, 0.075, 1)
|
|
el[1].position, el[1].color = 1.0, (0.62, 0.72, 0.84, 1)
|
|
e2 = el.new(0.52)
|
|
e2.color = (0.36, 0.38, 0.4, 1)
|
|
nt.links.new(tc.outputs["Generated"], sep.inputs[0])
|
|
nt.links.new(sep.outputs[2], mr.inputs["Value"])
|
|
nt.links.new(mr.outputs[0], ramp.inputs[0])
|
|
nt.links.new(ramp.outputs[0], bg.inputs[0])
|
|
bg.inputs[1].default_value = strength
|
|
|
|
|
|
def views(names):
|
|
K = _K()
|
|
os.makedirs(PANELS, exist_ok=True)
|
|
tags = os.environ.get("GC5_VIEWS")
|
|
only = os.environ.get("GC5_ONLY")
|
|
for n in names:
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
objs = K.load_fbx(os.path.join(OUT, "fbx", n + ".fbx"))
|
|
mn, mx = K.bounds(objs)
|
|
full = ((mn + mx) / 2, (mx - mn).length / 2 * 0.72)
|
|
for which, path in (("old", os.path.join(GAME, n + ".fbx")), ("new", os.path.join(OUT, "fbx", n + ".fbx"))):
|
|
if only and which != only:
|
|
continue
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
K.load_fbx(path)
|
|
K.lights()
|
|
studio_world()
|
|
for tag, tgt, rad, el, az in VIEWS.get(n, []):
|
|
if tags and tag not in tags.split(","):
|
|
continue
|
|
t, r = (full if tgt is None else (Vector(tgt), rad))
|
|
K.shoot(os.path.join(PANELS, f"{n}_{tag}_{which}.png"), t, r, el, az)
|
|
for tag, eye, look, fov in FPV.get(n, []):
|
|
if tags and tag not in tags.split(","):
|
|
continue
|
|
sc = bpy.context.scene
|
|
cd = bpy.data.cameras.new("c")
|
|
cd.sensor_fit = "VERTICAL"
|
|
cd.angle = math.radians(fov)
|
|
cd.clip_start = 0.01
|
|
cam = common.link(bpy.data.objects.new("c", cd))
|
|
cam.location = Vector(eye)
|
|
cam.rotation_euler = (Vector(look) - Vector(eye)).to_track_quat("-Z", "Y").to_euler()
|
|
sc.camera = cam
|
|
sc.render.resolution_x, sc.render.resolution_y = 1280, 720
|
|
sc.render.filepath = os.path.join(PANELS, f"{n}_{tag}_{which}.png")
|
|
bpy.ops.render.render(write_still=True)
|
|
bpy.data.objects.remove(cam)
|
|
if n in HOLDS and (not tags or "fpv" in tags.split(",")):
|
|
hold_shot(n, path, os.path.join(PANELS, f"{n}_fpv_{which}.png"))
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
K.load_fbx(path)
|
|
K.lights()
|
|
studio_world()
|
|
|
|
|
|
def hold_shot(n, path, out):
|
|
"""The tool where the old ViewModel held it: the overlay camera at the origin looking down Blender -Y (Unity +Z), 62 degrees."""
|
|
K = _K()
|
|
pos, eu, sc_ = HOLDS[n]
|
|
Mc = Matrix(((-1, 0, 0, 0), (0, 0, -1, 0), (0, 1, 0, 0), (0, 0, 0, 1)))
|
|
rig = Matrix.Translation(Vector(pos)) @ (Matrix.Rotation(math.radians(eu[1]), 4, "Y") @ Matrix.Rotation(math.radians(eu[0]), 4, "X")
|
|
@ Matrix.Rotation(math.radians(eu[2]), 4, "Z")) @ Matrix.Scale(sc_, 4)
|
|
W = Mc @ rig @ Mc.inverted()
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
K.load_fbx(path, W)
|
|
K.lights((0.55, 0.72, 0.42), 0.7)
|
|
studio_world(0.7)
|
|
sc = bpy.context.scene
|
|
cd = bpy.data.cameras.new("c")
|
|
cd.sensor_fit = "VERTICAL"
|
|
cd.angle = math.radians(62)
|
|
cd.clip_start = 0.01
|
|
cam = common.link(bpy.data.objects.new("c", cd))
|
|
cam.rotation_euler = (math.radians(90), 0, math.pi)
|
|
sc.camera = cam
|
|
sc.render.resolution_x, sc.render.resolution_y = 1280, 720
|
|
sc.render.filepath = out
|
|
bpy.ops.render.render(write_still=True)
|
|
|
|
|
|
def compose(names):
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
try:
|
|
font = ImageFont.truetype("arial.ttf", 26)
|
|
small = ImageFont.truetype("arial.ttf", 20)
|
|
except Exception: # noqa: BLE001
|
|
font = small = ImageFont.load_default()
|
|
made = []
|
|
for fn in sorted(os.listdir(PANELS)):
|
|
if not fn.endswith("_new.png") or not any(fn.startswith(n + "_") for n in names):
|
|
continue
|
|
key = fn[:-len("_new.png")]
|
|
b = os.path.join(PANELS, fn)
|
|
a = os.path.join(PANELS, key + "_old.png")
|
|
B = Image.open(b).convert("RGB")
|
|
A = Image.open(a).convert("RGB") if os.path.exists(a) else Image.new("RGB", B.size, (40, 40, 40))
|
|
w, h = B.size
|
|
bar = 44
|
|
im = Image.new("RGB", (w * 2 + 8, h + bar), (30, 32, 36))
|
|
im.paste(A, (0, bar))
|
|
im.paste(B, (w + 8, bar))
|
|
d = ImageDraw.Draw(im)
|
|
d.text((14, 9), "game", fill=(230, 230, 230), font=font)
|
|
d.text((w + 22, 9), "round 5", fill=(255, 214, 120), font=font)
|
|
d.text((w * 2 + 8 - 14 - d.textlength(key, font=small), 13), key, fill=(170, 170, 170), font=small)
|
|
out = os.path.join(OUT, "previews", key + ".png")
|
|
im.save(out)
|
|
made.append(out)
|
|
print("\n".join(made))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else sys.argv[1:]
|
|
mode = args[0] if args and args[0] in ("build", "verify", "views", "compose") else "build"
|
|
names = [a for a in args if a in NAMES] or ([n for n in NAMES if n in BUILDERS] if IN_BLENDER else NAMES)
|
|
if mode == "compose":
|
|
compose(names)
|
|
elif mode == "verify":
|
|
verify(names)
|
|
elif mode == "views":
|
|
views(names)
|
|
else:
|
|
build([n for n in names if n in BUILDERS])
|