A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1166 lines
65 KiB
Python
1166 lines
65 KiB
Python
"""GRASS CUTTER - "Herbaria homestead" rebuild of the hand tools, gloves, crew and clipboard.
|
|
|
|
Cheerful chunky farmstead kit: timber, barn red, galvanised tin, iron, rope, burlap, leather. Replaces the output of
|
|
os_crew.py / gc_crew.py / v2.py for these models (run this script, not those, for the names below):
|
|
|
|
SM_Tool_HandPump Clip-Vac hedge clipper + burlap catch bag. `Plunger` = rear T-handle + push rod + the upper
|
|
comb: ViewModel slides it 7 cm back and forth, which is the comb's cutting stroke.
|
|
SM_Tool_SlurpGun Weed Whacker string trimmer: long shaft, two-stroke, spinning line head (`Fan`, tilted axis),
|
|
mix jar (`Fill`).
|
|
SM_Tool_HydroCannon Mulch Cannon petrol blower/mulcher on a timber carriage with a tin hopper, `Fan` in the throat.
|
|
SM_Tool_MegaSiphon Tornado Mower twin-handled rotary cutter: blade drum halves `Ring1` / `Ring2` on one crosswise axle.
|
|
SM_Glove_R / _L tan leather work gloves (same wrist origin and fist as before).
|
|
SM_Crew the provided creature in shirt + denim overalls, straw hat, burlap sack. Same rig as os_crew.
|
|
SM_Gadget_Tablet wooden clipboard with a paper field plan (`Screen` = the sheet).
|
|
|
|
Conventions: meters, Z-up, front = -Y, grip at the origin. Unity spins `Fan` / `Ring*` about the part's local Y and scales
|
|
`Fill` / `TankFill` along local Z, so a spinner that needs another axis gets an object rotation with local Y on that axis.
|
|
Run (from project root):
|
|
blender -b --factory-startup --python ArtSource/Blender/scripts/gc_farm_tools.py -- [SM_Tool_HandPump ...]
|
|
"""
|
|
import sys, os
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import os_crew as OC
|
|
from os_crew import * # noqa: F401,F403 (common helpers + loft/lathe/prism/sweep_circle/grid_slab/frame_on/...)
|
|
from os_decor import bx, ptube, bez, wobble, softbox
|
|
|
|
TAU = 2 * math.pi
|
|
Y_UP = Vector((0, 1, 0))
|
|
|
|
|
|
# ======================================================================= uv + assembly
|
|
|
|
def grain(o, along=(0, 1, 0), s=2.0, off=(0.0, 0.0)):
|
|
"""Box-style UV with texture V running along a straight axis (plank grain, corrugation ribs)."""
|
|
d = Vector(along).normalized()
|
|
a = d.orthogonal().normalized()
|
|
b = d.cross(a)
|
|
mw = o.matrix_world
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
uv = bm.loops.layers.uv.verify()
|
|
for f in bm.faces:
|
|
n = mw.to_3x3() @ f.normal
|
|
ua = a if abs(n.dot(a)) < abs(n.dot(b)) else b
|
|
for l in f.loops:
|
|
p = mw @ l.vert.co
|
|
l[uv].uv = (p.dot(ua) * s + off[0], p.dot(d) * s + off[1])
|
|
bm.to_mesh(o.data)
|
|
bm.free()
|
|
o["uv_done"] = True
|
|
return o
|
|
|
|
|
|
def around(o, center, axis=(0, 0, 1), nu=10.0, s=4.0):
|
|
"""Cylindrical UV around an axis through `center`: U wraps nu times, V runs along the axis (ribs follow the axis)."""
|
|
c = Vector(center)
|
|
d = Vector(axis).normalized()
|
|
a = d.orthogonal().normalized()
|
|
b = d.cross(a)
|
|
mw = o.matrix_world
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
uv = bm.loops.layers.uv.verify()
|
|
for f in bm.faces:
|
|
q = (mw @ f.calc_center_median()) - c
|
|
ac = math.atan2(q.dot(b), q.dot(a))
|
|
for l in f.loops:
|
|
p = (mw @ l.vert.co) - c
|
|
ang = math.atan2(p.dot(b), p.dot(a))
|
|
if ang - ac > math.pi:
|
|
ang -= TAU
|
|
elif ac - ang > math.pi:
|
|
ang += TAU
|
|
l[uv].uv = (ang / TAU * nu, p.dot(d) * s)
|
|
bm.to_mesh(o.data)
|
|
bm.free()
|
|
o["uv_done"] = True
|
|
return o
|
|
|
|
|
|
def join_uv(objs, name):
|
|
"""join() with one UV layer named UVMap on every part (mixed names split UVs on join)."""
|
|
objs = [o for o in objs if o is not None]
|
|
for o in objs:
|
|
me = o.data
|
|
if not me.uv_layers:
|
|
me.uv_layers.new(name="UVMap")
|
|
act = me.uv_layers.active or me.uv_layers[0]
|
|
for l in [l for l in me.uv_layers if l.name != act.name]:
|
|
me.uv_layers.remove(l)
|
|
me.uv_layers[0].name = "UVMap"
|
|
return join(objs, name)
|
|
|
|
|
|
def done(P, name, uv=3.0, ang=45):
|
|
"""Box-map every part that has no UV of its own, join them, shade."""
|
|
for q in P:
|
|
if q is not None and not q.get("uv_done"):
|
|
uv_box(q, uv)
|
|
o = join_uv(P, name)
|
|
smooth(o, ang)
|
|
return o
|
|
|
|
|
|
def spinner(P, name, loc, axis, uv=4.0, ang=40):
|
|
"""Join parts built about local Y at the origin into a part at `loc` whose local Y lies on world `axis`."""
|
|
o = done(P, name, uv=uv, ang=ang)
|
|
q = Y_UP.rotation_difference(Vector(axis).normalized())
|
|
o.matrix_world = Matrix.Translation(Vector(loc)) @ q.to_matrix().to_4x4()
|
|
return o
|
|
|
|
|
|
# ======================================================================= shared farm bits
|
|
|
|
def bar(name, p0, p1, r, m, verts=10, r1=None):
|
|
"""Round bar with softened ends."""
|
|
p0, p1 = Vector(p0), Vector(p1)
|
|
d = p1 - p0
|
|
L = d.length
|
|
r1 = r if r1 is None else r1
|
|
e = min(r * 0.35, L * 0.2)
|
|
prof = [(0.0, 0.0), (r * 0.75, 0.0), (r, e), (r1, L - e), (r1 * 0.75, L), (0.0, L)]
|
|
return lathe(name, prof, segs=verts, m=m, frame=frame_on(p0, d, up=(0, 0, 1)), smooth_ang=50)
|
|
|
|
|
|
def timber_bar(name, p0, p1, r, verts=10, s=2.2):
|
|
d = Vector(p1) - Vector(p0)
|
|
return grain(bar(name, p0, p1, r, "M_Timber", verts=verts), d, s)
|
|
|
|
|
|
def beam(x0, x1, y0, y1, z0, z1, along, m="M_Timber", bevel=0.009, s=2.0, off=(0.0, 0.0), name="beam"):
|
|
return grain(bx(x0, x1, y0, y1, z0, z1, m, bevel=bevel, segs=2, name=name), along, s, off)
|
|
|
|
|
|
def rivet(P, loc, n, r=0.0075, m="M_Navy"):
|
|
return bolt(P, loc, n, r=r, h=0.006, m=m, hexa=False)
|
|
|
|
|
|
def ring_on(P, loc, axis, r, t, m="M_Navy", seg=20):
|
|
o = torus("hoop", r, t, seg=seg, rseg=6, m=m)
|
|
o.data.transform(frame_on(loc, axis, up=(0, 0, 1)))
|
|
P.append(o)
|
|
return o
|
|
|
|
|
|
def grip(P, loc=(0, 0, 0), tilt=12.0, h0=-0.09, h1=0.06, rx=0.023, ry=0.03, whip=True):
|
|
"""Turned timber handle with a dark iron pommel, a leather wrap under the fingers and a ferrule at the top."""
|
|
fr = Matrix.Translation(Vector(loc)) @ Matrix.Rotation(DEG(tilt), 4, "X")
|
|
H = h1 - h0
|
|
rings = []
|
|
for k in range(7):
|
|
t = k / 6
|
|
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 = loft("grip", rings, segs=12, m="M_Timber", frame=fr, cap0=False, cap1=True, smooth_ang=70)
|
|
grain(g, fr.to_3x3() @ Vector((0, 0, 1)), 2.4)
|
|
P.append(g)
|
|
P.append(loft("pommel", [(0, 0, rx * 0.7, ry * 0.7, h0 - 0.012, 2.3), (0, 0, rx * 1.25, ry * 1.2, h0 - 0.006, 2.4),
|
|
(0, 0, rx * 1.3, ry * 1.25, h0 + 0.008, 2.4), (0, 0, rx * 1.02, ry * 1.02, h0 + 0.014, 2.3)],
|
|
segs=12, m="M_Navy", frame=fr, smooth_ang=60))
|
|
if whip:
|
|
P.append(loft("wrap", [(0, 0, rx * 1.09, ry * 1.09, h0 + H * 0.2, 2.3), (0, 0, rx * 1.15, ry * 1.15, h0 + H * 0.24, 2.3),
|
|
(0, 0, rx * 1.15, ry * 1.15, h0 + H * 0.66, 2.3), (0, 0, rx * 1.09, ry * 1.09, h0 + H * 0.7, 2.3)],
|
|
segs=12, m="M_Leather", frame=fr, cap0=False, cap1=False, smooth_ang=60))
|
|
P.append(loft("ferrule", [(0, 0, rx * 1.08, ry * 1.08, h1 - 0.016, 2.3), (0, 0, rx * 1.18, ry * 1.16, h1 - 0.012, 2.3),
|
|
(0, 0, rx * 1.18, ry * 1.16, h1 - 0.002, 2.3), (0, 0, rx * 1.08, ry * 1.08, h1 + 0.002, 2.3)],
|
|
segs=12, m="M_Navy", frame=fr, cap0=False, cap1=False, smooth_ang=60))
|
|
|
|
|
|
def trigger(P, y0=-0.03, z0=0.042, drop=0.05, m="M_PaintYellow"):
|
|
"""Throttle lever + wire guard in front of a grip at the origin."""
|
|
P.append(sweep_circle("trig", [(0, y0, z0), (0, y0 - 0.018, z0 - 0.022), (0, y0 - 0.019, z0 - 0.04), (0, y0 - 0.01, z0 - drop)],
|
|
lambda s, l: 0.0085 * (1 - 0.3 * s), segs=8, per=3, m=m))
|
|
P.append(sweep_circle("tguard", [(0, y0 - 0.05, z0), (0, y0 - 0.056, z0 - 0.04), (0, y0 - 0.034, z0 - 0.072), (0, y0 + 0.008, z0 - 0.078)],
|
|
lambda s, l: 0.0058, segs=6, per=3, m="M_Navy"))
|
|
|
|
|
|
def red_tank(E, c, rx, ry, h, m="M_PaintRed"):
|
|
"""Square-shouldered petrol tank: flat top and bottom, cream band, brass filler cap off to one side."""
|
|
c = Vector(c)
|
|
FR = Matrix.Translation(c)
|
|
E.append(loft("tank", [(0, 0, 0, 0, 0.0), (0, 0, rx * 0.86, ry * 0.86, 0.0, 3.4), (0, 0, rx * 0.97, ry * 0.97, 0.008, 3.4), (0, 0, rx, ry, 0.022, 3.4), (0, 0, rx, ry, h - 0.024, 3.4),
|
|
(0, 0, rx * 0.95, ry * 0.95, h - 0.008, 3.4), (0, 0, rx * 0.8, ry * 0.8, h, 3.4), (0, 0, 0, 0, h)], segs=16, m=m, frame=FR, smooth_ang=48))
|
|
body_band(E, FR, rx, ry, h * 0.42, h * 0.62, "M_PaintWhite", n=3.4, grow=0.0022, segs=16)
|
|
x = rx * 0.42
|
|
E.append(cyl("filler", 0.0165, 0.014, c + Vector((x, 0, h + 0.004)), verts=10, m="M_Navy"))
|
|
E.append(cyl("tcap", 0.0215, 0.016, c + Vector((x, 0, h + 0.016)), verts=10, m="M_Brass", bevel=0.004, segs=1))
|
|
|
|
|
|
def two_stroke(c, s=1.0, pull=1, tank=True, tilt=0.0, stack=False):
|
|
"""Little single-cylinder engine, cylinder up. Returns its parts, already placed.
|
|
c = crankcase centre, pull = which side (+X / -X) the recoil starter sits on, tilt = lean about X (deg)."""
|
|
E = []
|
|
# crankcase + sump
|
|
E.append(rbox("crank", (0.13, 0.13, 0.085), (0, 0, 0), bevel=0.02, segs=2, m="M_Navy"))
|
|
# cooling fins: the shape that says "engine" from any angle
|
|
E.append(cyl("core", 0.032, 0.11, (0, 0, 0.09), verts=12, m="M_Navy"))
|
|
for k in range(5):
|
|
w = 0.104 - 0.007 * k
|
|
E.append(rbox("fin", (w, w * 0.92, 0.0075), (0, 0, 0.056 + k * 0.0175), bevel=0.003, segs=1, m="M_Steel"))
|
|
E.append(rbox("head", (0.075, 0.07, 0.022), (0, 0, 0.15), bevel=0.009, segs=2, m="M_Navy"))
|
|
# spark plug + lead
|
|
E.append(cyl("plug", 0.0085, 0.028, (0, 0, 0.175), verts=8, m="M_Brass"))
|
|
E.append(cyl("boot", 0.012, 0.024, (0, 0, 0.2), verts=8, m="M_Rubber"))
|
|
E.append(ptube("lead", bez([(0, 0.0, 0.208), (-pull * 0.03, 0.018, 0.216), (-pull * 0.06, 0.03, 0.14), (-pull * 0.065, 0.02, 0.06)], 7),
|
|
0.0045, "M_Rubber"))
|
|
# recoil starter: domed red cover with a pull rope and a wooden T-knob
|
|
FX = M_axis("X" if pull > 0 else "-X", (pull * 0.064, 0, 0))
|
|
E.append(lathe("recoil", [(0.0, 0.02), (0.044, 0.02), (0.056, 0.016), (0.06, 0.008), (0.06, -0.004)], segs=16, m="M_PaintRed", frame=FX, smooth_ang=35))
|
|
E.append(lathe("rcbolt", [(0.0, 0.03), (0.016, 0.03), (0.02, 0.019)], segs=8, m="M_Navy", frame=FX, smooth_ang=30))
|
|
for a in (40, 110, 180, 250, 320):
|
|
p = FX @ Vector((0.041 * math.cos(DEG(a)), 0.041 * math.sin(DEG(a)), 0.0205))
|
|
E.append(rbox("rcvent", (0.011, 0.011, 0.006), tuple(p), bevel=0.002, segs=1, m="M_Navy"))
|
|
kp = Vector((pull * 0.118, 0.036, -0.03))
|
|
E.append(ptube("cord", bez([(pull * 0.08, 0.04, -0.012), (pull * 0.1, 0.044, -0.02), tuple(kp)], 5), 0.0035, "M_Rope"))
|
|
E.append(timber_bar("knob", kp + Vector((0, -0.028, -0.004)), kp + Vector((0, 0.028, -0.004)), 0.0105, verts=8))
|
|
# muffler on the other side
|
|
if stack:
|
|
ex = Vector((-pull * 0.083, 0, 0.012))
|
|
E.append(cyl("muff", 0.034, 0.1, ex + Vector((0, 0, 0.03)), verts=12, m="M_Steel", bevel=0.008, segs=1))
|
|
for dz in (-0.012, 0.07):
|
|
E.append(torus("mband", 0.035, 0.0045, loc=ex + Vector((0, 0, dz)), seg=12, rseg=4, m="M_Navy"))
|
|
E.append(cyl("stack", 0.0145, 0.1, ex + Vector((0, 0, 0.125)), verts=10, m="M_Navy"))
|
|
E.append(cyl("flue", 0.025, 0.02, ex + Vector((0, 0, 0.165)), verts=12, m="M_Navy", r2=0.017))
|
|
E.append(cyl("raincap", 0.012, 0.03, ex + Vector((0, 0, 0.198)), verts=12, m="M_Steel", r2=0.042))
|
|
E.append(cyl("cap2", 0.042, 0.022, ex + Vector((0, 0, 0.224)), verts=12, m="M_Steel", r2=0.01))
|
|
else:
|
|
E.append(rbox("muff", (0.042, 0.11, 0.062), (-pull * 0.082, 0, 0.012), bevel=0.012, segs=2, m="M_Steel"))
|
|
E.append(cyl("muffout", 0.012, 0.04, (-pull * 0.08, 0.064, 0.012), axis="Y", verts=8, m="M_Navy"))
|
|
for k in (-1, 1):
|
|
E.append(rbox("mband", (0.046, 0.009, 0.067), (-pull * 0.082, k * 0.03, 0.012), bevel=0.002, segs=1, m="M_Navy"))
|
|
# petrol tank behind the cylinder
|
|
if tank:
|
|
red_tank(E, (0, 0.098, 0.008), 0.064, 0.044, 0.09)
|
|
M = Matrix.Translation(Vector(c)) @ Matrix.Rotation(DEG(tilt), 4, "X") @ Matrix.Scale(s, 4)
|
|
for o in E:
|
|
apply_xform(o)
|
|
o.data.transform(M)
|
|
return E
|
|
|
|
|
|
def tie(P, c, axis, r, m="M_Twine", tails=None):
|
|
"""Twine wound round a sack neck with two loose ends."""
|
|
for k in (-1, 0, 1):
|
|
P.append(torus("wind", r, 0.0052, loc=(0, 0, 0), seg=14, rseg=4, m=m))
|
|
P[-1].data.transform(frame_on(Vector(c) + Vector(axis).normalized() * k * 0.008, axis, up=(0, 0, 1)))
|
|
for t in (tails or ()):
|
|
P.append(ptube("tail", bez(t, 6), 0.0045, m))
|
|
|
|
|
|
def pleats(o, c, axis, n=7, amp=0.16, t0=0.0, t1=1.0):
|
|
"""Gather a sack towards its neck: radial ruffle along `axis`, fading in between distances t0..t1."""
|
|
c = Vector(c)
|
|
d = Vector(axis).normalized()
|
|
a = d.orthogonal().normalized()
|
|
b = d.cross(a)
|
|
for v in o.data.vertices:
|
|
p = v.co - c
|
|
h = p.dot(d)
|
|
k = max(0.0, min(1.0, (h - t0) / max(1e-5, t1 - t0)))
|
|
if k > 0.0:
|
|
ang = math.atan2(p.dot(b), p.dot(a))
|
|
rad = p - d * h
|
|
v.co = c + d * h + rad * (1 + amp * k * math.sin(ang * n))
|
|
return o
|
|
|
|
|
|
def duct(name, pts, rf, m, segs=16, per=4, cap=False, nu=3.0, vs=4.0):
|
|
"""Oval sleeve along a path that stays in the YZ plane. rf(s) -> (half width X, half height across the path).
|
|
UV: V runs along the path, so corrugation ribs follow the sleeve even where it bends."""
|
|
C = catmull(pts, per)
|
|
L = [0.0]
|
|
for a, b in zip(C, C[1:]):
|
|
L.append(L[-1] + (b - a).length)
|
|
X = Vector((1, 0, 0))
|
|
bm = bmesh.new()
|
|
R = []
|
|
for i, c in enumerate(C):
|
|
T = (C[min(i + 1, len(C) - 1)] - C[max(i - 1, 0)]).normalized()
|
|
N = T.cross(X).normalized()
|
|
rx, rz = rf(L[i] / L[-1])
|
|
ring = []
|
|
for k in range(segs):
|
|
a = TAU * k / segs
|
|
cs, sn = math.cos(a), math.sin(a)
|
|
ring.append(bm.verts.new(c + X * rx * math.copysign(abs(cs) ** 0.7, cs) + N * rz * math.copysign(abs(sn) ** 0.7, sn)))
|
|
R.append(ring)
|
|
uvl = bm.loops.layers.uv.verify()
|
|
for r, (a, b) in enumerate(zip(R, R[1:])):
|
|
for i in range(segs):
|
|
j = (i + 1) % segs
|
|
f = bm.faces.new((a[i], a[j], b[j], b[i]))
|
|
for lp, (u, v) in zip(f.loops, ((i, L[r]), (i + 1, L[r]), (i + 1, L[r + 1]), (i, L[r + 1]))):
|
|
lp[uvl].uv = (u / segs * nu, v * vs)
|
|
if cap:
|
|
bm.faces.new(list(reversed(R[0])))
|
|
bm.faces.new(R[-1])
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
smooth(o, 60)
|
|
o["uv_done"] = True
|
|
return o
|
|
|
|
|
|
# ======================================================================= SM_Tool_HandPump = Clip-Vac
|
|
|
|
def comb_pts(y_rear, y_tip, n, ws, wt, phase=0.0):
|
|
"""Hedge-trimmer comb outline: spine half-width ws, teeth out to wt on both sides, nose at y_tip (x, y pairs)."""
|
|
p = (y_rear - y_tip - 0.03) / (n + 0.5)
|
|
R = [(ws, y_rear)]
|
|
for k in range(n):
|
|
y = y_rear - (k + phase) * p - 0.012
|
|
R += [(ws, y), (wt * 0.82, y - p * 0.42), (wt, y - p * 0.66), (wt * 0.92, y - p * 0.8), (ws, y - p * 0.92)]
|
|
R += [(ws * 0.9, y_tip + 0.03), (ws * 0.55, y_tip + 0.008), (0.0, y_tip)]
|
|
L = [(-x, y) for x, y in reversed(R[:-1])]
|
|
return R + L
|
|
|
|
|
|
ROLL = Matrix.Translation((0, 0, -0.02)) @ Matrix.Rotation(DEG(24), 4, "Y") @ Matrix.Translation((0, 0, 0.02))
|
|
|
|
|
|
def tool_handpump():
|
|
P = []
|
|
Z, YB = 0.072, 0.16
|
|
FR = M_fwd((0, YB - 0.005, Z))
|
|
# barn-red cast gearbox: a fat rounded barrel the grip hangs from
|
|
P.append(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=20, m="M_PaintRed", frame=FR, cap1=True, smooth_ang=60))
|
|
for d, m in ((0.044, "M_Navy"), (0.232, "M_Navy")):
|
|
body_band(P, FR, 0.054, 0.059, d, d + 0.024, m, n=3.0, grow=0.004, segs=20)
|
|
body_band(P, FR, 0.0555, 0.0595, 0.1, 0.112, "M_PaintYellow", n=3.0, grow=0.0025, segs=20)
|
|
body_band(P, FR, 0.0555, 0.0595, 0.18, 0.192, "M_PaintYellow", n=3.0, grow=0.0025, segs=20)
|
|
for sx in (-1, 1):
|
|
for dd in (0.056, 0.244):
|
|
rivet(P, (sx * 0.0585, YB - 0.005 - dd, Z), (sx, 0, 0), r=0.0065, m="M_Brass")
|
|
P.append(lathe("bush", [(0.012, -0.014), (0.019, -0.012), (0.02, 0.004), (0.014, 0.008)], segs=12, m="M_Brass", frame=M_fwd((0, YB, Z)), smooth_ang=40))
|
|
# iron neck dropping from the gearbox to the cutter bar
|
|
P.append(rbox("neck", (0.078, 0.082, 0.098), (0, -0.112, 0.021), bevel=0.016, segs=2, m="M_Navy"))
|
|
P.append(rbox("neckcap", (0.088, 0.03, 0.03), (0, -0.142, -0.008), bevel=0.01, segs=2, m="M_Navy"))
|
|
# fixed lower comb + dark guide bar on top of the moving comb. Teeth oversized, and the bar is rolled towards the
|
|
# player's eye (the tool is seen from behind and above in first person, a flat bar would be edge-on)
|
|
C = [prism("combL", comb_pts(-0.1, -0.56, 6, 0.03, 0.104), 0.0095, Matrix.Translation((0, 0, -0.033)), "M_Steel")]
|
|
C.append(bx(-0.015, 0.015, -0.53, -0.13, -0.0105, 0.0, "M_Navy", bevel=0.003, segs=1, name="guide"))
|
|
C.append(cyl("guidetip", 0.015, 0.0105, (0, -0.53, -0.00525), verts=10, m="M_Navy"))
|
|
for k in range(5):
|
|
C.append(cyl("gbolt", 0.0095, 0.009, (0, -0.2 - k * 0.075, 0.0015), verts=8, m="M_Brass", bevel=0.002, segs=1))
|
|
for o in C:
|
|
apply_xform(o)
|
|
o.data.transform(ROLL)
|
|
P += C
|
|
# pistol grip + iron clamp + lever
|
|
grip(P, (0, 0, 0), tilt=10, h1=0.032)
|
|
P.append(rbox("clamp", (0.062, 0.076, 0.02), (0, 0.0, 0.025), bevel=0.007, segs=2, m="M_Navy"))
|
|
trigger(P, y0=-0.03, z0=0.022, drop=0.05)
|
|
|
|
# short tin chute: scoops the clippings off the root of the cutter bar, up over the gearbox and into the bag
|
|
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)]
|
|
ch = duct("chute", cp, lambda s: (0.062 - 0.012 * s, 0.03 + 0.024 * s), "M_Tin", segs=16, nu=2.2, vs=5.0)
|
|
P.append(ch)
|
|
P.append(duct("mouth", [(0, -0.2355, 0.0292), (0, -0.2245, 0.0312)], lambda s: (0.067, 0.035), "M_Steel", segs=16, per=1))
|
|
bk = duct("chutein", [(0, -0.226, 0.031), (0, -0.21, 0.036)], lambda s: (0.056, 0.024), "M_Navy", segs=16, per=1, cap=True)
|
|
P.append(bk)
|
|
P.append(rbox("chutebrk", (0.02, 0.036, 0.05), (0, -0.142, 0.08), bevel=0.006, segs=1, m="M_Navy"))
|
|
# plump burlap catch bag lying on top of the gearbox, tied off at the back
|
|
bz = 0.19
|
|
BF = 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 = loft("bag", rings, segs=18, m="M_Burlap", frame=BF, cap0=True, cap1=True, smooth_ang=70)
|
|
pleats(bag, (0, -0.06, bz), (0, 1, 0), n=6, amp=0.12, t0=0.2, t1=0.27)
|
|
wobble(bag, 0.008, 9.0, seed=2.0)
|
|
around(bag, (0, -0.06, bz), (0, 1, 0), nu=3.6, s=7.0)
|
|
P.append(bag)
|
|
tie(P, (0, 0.23, bz - 0.002), (0, 1, 0), 0.0245, 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)]])
|
|
ring_on(P, (0, -0.058, bz), (0, 1, 0), 0.054, 0.0075, m="M_Steel")
|
|
# two leather straps holding the bag down, with brass buckles
|
|
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)]
|
|
st = ptube("strap", bez(pts, 13), 0.006, "M_Leather", rs=1)
|
|
st.data.transform(Matrix.Translation((0, yy, 0)) @ Matrix.Scale(2.1, 4, (0, 1, 0)) @ Matrix.Translation((0, -yy, 0)))
|
|
P.append(st)
|
|
P.append(rbox("buckle", (0.016, 0.03, 0.022), (0.091, yy, 0.185), bevel=0.004, segs=1, m="M_Brass"))
|
|
done(P, "Body", uv=4.0, ang=42)
|
|
|
|
# Plunger: T-handle + push rod + the moving upper comb, all one sliding part (ViewModel strokes it 7 cm backwards)
|
|
Q = [prism("combU", comb_pts(-0.16, -0.54, 5, 0.024, 0.1, phase=0.3), 0.0075, Matrix.Translation((0, 0, -0.0235)), "M_Blade")]
|
|
apply_xform(Q[0])
|
|
Q[0].data.transform(ROLL)
|
|
Q.append(rbox("linkU", (0.05, 0.05, 0.03), (0, -0.162, 0.0), bevel=0.006, segs=1, m="M_Navy"))
|
|
Q.append(cyl("rod", 0.0085, 0.24, (0, YB + 0.005, Z), axis="Y", verts=10, m="M_Steel")) # long enough to stay in the gearbox at full stroke
|
|
Q.append(cyl("rodcol", 0.0125, 0.016, (0, YB + 0.104, Z), axis="Y", verts=10, m="M_Brass"))
|
|
Q.append(timber_bar("thandle", (-0.082, YB + 0.126, Z), (0.082, YB + 0.126, Z), 0.0205, verts=10))
|
|
for sx in (-1, 1):
|
|
Q.append(cyl("tcap", 0.0215, 0.012, (sx * 0.066, YB + 0.126, Z), axis="X", verts=10, m="M_Navy"))
|
|
Q.append(rbox("tblock", (0.05, 0.05, 0.05), (0, YB + 0.126, Z), bevel=0.012, segs=2, m="M_PaintRed"))
|
|
pl = done(Q, "Plunger", uv=5.0)
|
|
set_origin(pl, (0, YB, Z))
|
|
empty("Nozzle", (0, -0.55, -0.018))
|
|
return dict(elev=26, azim=-40, extra=[("fp", dict(elev=20, azim=150), None), ("side", dict(elev=6, azim=-90), None)])
|
|
|
|
|
|
# ======================================================================= SM_Tool_SlurpGun = Weed Whacker
|
|
|
|
def tool_slurpgun():
|
|
P = []
|
|
# the long shaft: from the motor at the back, over the grip, down to the bent head
|
|
A = Vector((0, 0.17, 0.092))
|
|
Ax = Vector((0, 0.42, 0.907)).normalized() # spin axis of the head (points up the shaft end)
|
|
E = Vector((0, -0.655, -0.112)) # gearbox at the shaft end
|
|
D = E + Ax * 0.12
|
|
C = Vector((0, -0.5, -0.03))
|
|
sh = sweep_circle("shaft", [A, Vector((0, -0.1, 0.05)), Vector((0, -0.38, 0.003)), C, D, E + Ax * 0.03], lambda s, l: 0.0235, segs=10, per=5, m="M_Steel")
|
|
around(sh, (0, 0, 0.05), (0, 1, 0), nu=1.0, s=3.0)
|
|
P.append(sh)
|
|
for y, z in ((-0.1, 0.05), (-0.215, 0.031), (-0.5, -0.03)):
|
|
ring_on(P, (0, y, z), (0, 1, 0.16), 0.0265, 0.0075, m="M_Navy", seg=14)
|
|
# engine on the back of the shaft
|
|
P += two_stroke((0, 0.13, 0.157), s=0.92, pull=1, tank=False)
|
|
P.append(rbox("mount", (0.05, 0.1, 0.03), (0, 0.13, 0.102), bevel=0.008, segs=1, m="M_Navy"))
|
|
# red fuel tank carrying the mix jar
|
|
red_tank(P, (0, -0.065, 0.098), 0.072, 0.066, 0.09)
|
|
P.append(rbox("tbrk", (0.04, 0.06, 0.06), (0, -0.065, 0.08), bevel=0.008, segs=1, m="M_Navy"))
|
|
# mason jar of two-stroke mix, showing the fill level: origin of Fill stays on the old pivot
|
|
CF = Matrix.Translation((0, -0.065, 0.202))
|
|
P.append(lathe("jarbase", [(0.0, -0.016), (0.056, -0.016), (0.062, -0.01), (0.062, 0.004), (0.056, 0.006)], segs=16, m="M_Navy", frame=CF, smooth_ang=40))
|
|
P.append(lathe("jar", [(0.056, 0.0), (0.06, 0.012), (0.06, 0.09), (0.054, 0.108), (0.046, 0.118)], segs=16, m="M_Glass", frame=CF, smooth_ang=50))
|
|
P.append(lathe("lid", [(0.0, 0.142), (0.04, 0.142), (0.05, 0.138), (0.052, 0.13), (0.052, 0.114), (0.048, 0.112)], segs=16, m="M_Steel", frame=CF, smooth_ang=40))
|
|
P.append(cyl("cork", 0.017, 0.016, (0, -0.065, 0.352), verts=10, m="M_Timber"))
|
|
for sx in (-1, 1):
|
|
P.append(ptube("wire", [(sx * 0.0635, -0.065, 0.196), (sx * 0.0635, -0.065, 0.328), (sx * 0.05, -0.065, 0.338)], 0.0035, "M_Navy"))
|
|
fill = lathe("Fill", [(0.0, 0.0), (0.052, 0.0), (0.052, 0.106), (0.0, 0.106)], segs=14, m="M_GrassFill", frame=CF, smooth_ang=30)
|
|
P.append(ptube("fuel", bez([(0.05, -0.04, 0.2), (0.075, 0.0, 0.215), (0.07, 0.05, 0.19), (0.05, 0.09, 0.165)], 8), 0.0052, "M_Brass"))
|
|
# rear handle grip and throttle
|
|
grip(P, (0, 0, 0), tilt=12, h1=0.05)
|
|
P.append(rbox("clamp", (0.065, 0.085, 0.056), (0, 0.004, 0.056), bevel=0.012, segs=2, m="M_Navy"))
|
|
trigger(P, y0=-0.034, z0=0.03, drop=0.05)
|
|
# loop handle further up the shaft, timber grip on top
|
|
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)]
|
|
P.append(ptube("loop", bez(lp, 21), 0.011, "M_Navy", rs=1))
|
|
P.append(timber_bar("loopgrip", (-0.066, Ly, Lz + 0.183), (0.066, Ly, Lz + 0.183), 0.02, verts=10))
|
|
# gear head at the shaft end
|
|
GF = frame_on(E, Ax, up=(0, 1, 0))
|
|
P.append(lathe("gear", [(0.0, -0.03), (0.034, -0.03), (0.044, -0.022), (0.048, 0.0), (0.042, 0.032), (0.03, 0.056), (0.026, 0.078)], segs=14, m="M_Navy", frame=GF, smooth_ang=50))
|
|
# half-moon guard towards the operator: a dished red tin shell with a rolled steel rim, so the blade side stays open
|
|
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(grid_slab("guard", shell, 12, 3, 0.0045, -0.0045, "M_PaintRed", smooth_ang=50))
|
|
P.append(ptube("guardrim", [tuple(shell(i / 12, 1.0, 0.0)) for i in range(13)], 0.0105, "M_Steel"))
|
|
for vv in (0.45, 0.78):
|
|
P.append(ptube("guardrib", [tuple(shell(0.05 + 0.9 * i / 8, vv, 0.0055)) for i in range(9)], 0.0055, "M_PaintYellow"))
|
|
done(P, "Body", uv=4.0, ang=45)
|
|
|
|
# spinning line head, built about local Y (local -Y faces the ground). Line tips sweep just inside the guard.
|
|
Q = []
|
|
AX = M_axis("Y")
|
|
Q.append(lathe("spool", [(0.0, 0.0), (0.036, 0.002), (0.05, -0.006), (0.052, -0.02), (0.036, -0.026), (0.036, -0.042), (0.056, -0.048), (0.06, -0.06), (0.048, -0.07), (0.0, -0.072)],
|
|
segs=14, m="M_PaintYellow", frame=AX, smooth_ang=40))
|
|
Q.append(lathe("bump", [(0.028, -0.068), (0.03, -0.076), (0.024, -0.09), (0.011, -0.098), (0.0, -0.099)], segs=10, m="M_Navy", frame=AX, smooth_ang=50))
|
|
wnd = torus("wound", 0.04, 0.008, seg=14, rseg=4, m="M_PaintRed")
|
|
wnd.data.transform(AX @ Matrix.Translation((0, 0, -0.034)))
|
|
Q.append(wnd)
|
|
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)))
|
|
pts = [dirv * 0.04 + Y_UP * -0.034, dirv * 0.1 + Y_UP * -0.036 + tan * 0.004, dirv * 0.19 + Y_UP * -0.042 + tan * 0.022]
|
|
Q.append(sweep_circle("line", pts, lambda s, l: 0.0075 * (1 - 0.25 * s), segs=6, per=2, m="M_TrimLine"))
|
|
spinner(Q, "Fan", E - Ax * 0.03, Ax)
|
|
set_origin(fill, (0, -0.065, 0.202))
|
|
uv_box(fill, 4.0)
|
|
empty("Nozzle", tuple(E - Ax * 0.11))
|
|
return dict(elev=22, azim=-40, extra=[("fp", dict(elev=20, azim=155), None), ("side", dict(elev=6, azim=-90), None)])
|
|
|
|
|
|
# ======================================================================= SM_Tool_HydroCannon = Mulch Cannon
|
|
|
|
def tool_hydrocannon():
|
|
P = []
|
|
Z, YR = 0.143, 0.2
|
|
FR = M_fwd((0, YR, Z))
|
|
# galvanised blower tube with a flared mouth
|
|
tube = 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=24, m="M_Steel", frame=FR, smooth_ang=60)
|
|
around(tube, (0, YR, Z), (0, 1, 0), nu=3.0, s=2.0)
|
|
P.append(tube)
|
|
P.append(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=24, m="M_PaintRed", frame=FR, smooth_ang=70))
|
|
P.append(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=24, m="M_Navy", frame=FR))
|
|
for d in (0.05, 0.44):
|
|
body_band(P, FR, 0.102, 0.102, d, d + 0.044, "M_PaintRed", n=2.0, grow=0.004, segs=24)
|
|
body_band(P, FR, 0.102, 0.102, 0.585, 0.605, "M_Navy", n=2.0, grow=0.005, segs=24)
|
|
for k in range(10): # riveted seam along the tube, both sides of the hopper
|
|
d = 0.12 + k * 0.035
|
|
rivet(P, (0.0735, YR - d, Z + 0.0735), (0.7, 0, 0.7), r=0.0052, m="M_Navy")
|
|
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.795)), (0, -1, 0), r=0.0062, m="M_Brass")
|
|
# timber carriage: two saddles under the tube, rails along the sides
|
|
for y in (0.012, -0.33):
|
|
P.append(beam(-0.137, 0.137, y - 0.037, y + 0.037, 0.03, 0.09, (1, 0, 0), s=2.0, off=(0.13 if y > 0 else 0.4, 0.0)))
|
|
for sx in (-1, 1):
|
|
x0, x1 = sorted((sx * 0.112, sx * 0.158))
|
|
P.append(beam(x0, x1, -0.41, 0.16, 0.078, 0.128, (0, 1, 0), s=1.8, off=(0.14 * sx, 0.3)))
|
|
for y in (0.012, -0.33):
|
|
rivet(P, (sx * 0.135, y, 0.129), (0, 0, 1), r=0.0082, m="M_Navy")
|
|
# grips, both timber: rear with the throttle, fore grip where the left hand goes
|
|
grip(P, (0, 0, 0), tilt=12, h1=0.046)
|
|
trigger(P, y0=-0.033, z0=0.028, drop=0.05)
|
|
grip(P, (0, -0.33, 0), tilt=0, h0=-0.07, h1=0.04, whip=True)
|
|
# petrol engine on the back of the tube
|
|
P += two_stroke((0, 0.112, 0.295), s=0.92, pull=-1, tank=True, tilt=-6)
|
|
P.append(rbox("seat", (0.11, 0.13, 0.036), (0, 0.112, 0.252), bevel=0.01, segs=1, m="M_Navy"))
|
|
# tin feed hopper, leaning towards the operator so the throat is in view
|
|
HC = Vector((0, -0.145, 0.222))
|
|
HF = Matrix.Translation(HC) @ Matrix.Rotation(DEG(-12), 4, "X")
|
|
ho = 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=22, m="M_Tin", frame=HF, smooth_ang=70)
|
|
around(ho, HC, HF.to_3x3() @ Vector((0, 0, 1)), nu=3.0, s=6.0)
|
|
P.append(ho)
|
|
P.append(lathe("hin", [(0.15, 0.178), (0.122, 0.134), (0.09, 0.09), (0.06, 0.05), (0.0, 0.05)], segs=22, m="M_Navy", frame=HF))
|
|
t = torus("hrim", 0.155, 0.0105, seg=22, rseg=6, m="M_Steel")
|
|
t.data.transform(HF @ Matrix.Translation((0, 0, 0.18)))
|
|
P.append(t)
|
|
b = torus("hband", 0.0735, 0.0085, seg=18, rseg=6, m="M_PaintRed")
|
|
b.data.transform(HF @ Matrix.Translation((0, 0, 0.022)))
|
|
P.append(b)
|
|
for a in (35, 145):
|
|
ax = DEG(a)
|
|
pp = HF @ Vector((0.1 * math.cos(ax) * 1.4, 0.1 * math.sin(ax) * 1.4, 0.142))
|
|
P.append(rbox("hstrap", (0.016, 0.016, 0.1), tuple(pp), bevel=0.003, segs=1, m="M_Navy"))
|
|
# a heap of clippings waiting in the hopper
|
|
hp = sphere("heap", 0.122, (0, 0, 0), seg=14, rings=7, m="M_Clippings", scale=(1.0, 1.0, 0.5))
|
|
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)
|
|
done(P, "Body", uv=4.0, ang=45)
|
|
OC.fan_blades("Fan", (0, -0.435, Z), 0.08, 0.026, n=6, m_blade="M_Blade", m_hub="M_PaintRed")
|
|
empty("Nozzle", (0, -0.586, Z))
|
|
return dict(elev=24, azim=-40, extra=[("fp", dict(elev=20, azim=155), None), ("side", dict(elev=6, azim=-90), None), ("mouth", dict(elev=10, azim=-12), None)])
|
|
|
|
|
|
# ======================================================================= SM_Tool_MegaSiphon = Tornado Mower
|
|
|
|
def drum_half(name, A, sx, r=0.172):
|
|
"""One half of the blade drum, |x| 0.034..0.216, built about local Y. Local X = world -Y, local Z = world Z."""
|
|
Q = []
|
|
y0, y1 = sx * 0.034, sx * 0.216
|
|
FR = M_axis("Y" if sx > 0 else "-Y")
|
|
W = 0.182
|
|
Q.append(lathe("core", [(0.0, 0.034), (0.074, 0.034), (0.078, 0.04), (0.078, 0.196), (0.074, 0.204), (0.0, 0.204)], segs=20, m="M_Teal", frame=FR, smooth_ang=40))
|
|
Q.append(lathe("disc", [(0.0, 0.2), (0.11, 0.2), (0.128, 0.204), (0.128, 0.216), (0.11, 0.22), (0.05, 0.222), (0.0, 0.224)], segs=20, m="M_PaintRed", frame=FR, smooth_ang=40))
|
|
Q.append(lathe("flange", [(0.074, 0.112), (0.112, 0.112), (0.116, 0.118), (0.112, 0.124), (0.074, 0.124)], segs=20, m="M_Navy", frame=FR, smooth_ang=40))
|
|
Q.append(lathe("hubcap", [(0.0, 0.226), (0.03, 0.226), (0.034, 0.222)], segs=12, m="M_Navy", frame=FR))
|
|
for k in range(4):
|
|
th0 = TAU * k / 4 + (0.0 if sx > 0 else 0.4)
|
|
tw = 1.15 * sx
|
|
|
|
def fn(u, v, off, th0=th0):
|
|
rho = 0.07 + (r - 0.07) * v
|
|
a = th0 + tw * u - 0.55 * v * v + off / rho
|
|
return Vector((rho * math.cos(a), y0 + (y1 - y0) * u, rho * math.sin(a)))
|
|
Q.append(grid_slab("cut", fn, 7, 2, 0.0045, -0.0045, "M_Blade", smooth_ang=35))
|
|
# a strip of darker steel along the root of each blade
|
|
fn2 = lambda u, v, off, th0=th0: Vector(((0.078 + 0.03 * v) * math.cos(th0 + tw * u + off / 0.09), y0 + (y1 - y0) * u, (0.078 + 0.03 * v) * math.sin(th0 + tw * u + off / 0.09)))
|
|
Q.append(grid_slab("root", fn2, 7, 1, 0.009, -0.009, "M_Navy", smooth_ang=35))
|
|
return spinner(Q, name, A, (1, 0, 0), uv=4.0, ang=38)
|
|
|
|
|
|
def tool_megasiphon():
|
|
P = []
|
|
A = Vector((0, -0.445, 0.158)) # drum axle
|
|
# timber ladder frame: two side rails and cross rails, grips hang from the cross rails
|
|
for sx in (-1, 1):
|
|
x0, x1 = sorted((sx * 0.172, sx * 0.226))
|
|
P.append(beam(x0, x1, -0.26, 0.268, 0.09, 0.15, (0, 1, 0), s=1.6, off=(0.1 * sx, 0.2), bevel=0.011))
|
|
for y, w in ((0.0, 0.04), (-0.25, 0.04), (0.235, 0.032)):
|
|
P.append(beam(-0.176, 0.176, y - w, y + w, 0.074, 0.13, (1, 0, 0), s=1.6, off=(0.13 + y, 0.0), bevel=0.01))
|
|
for sx in (-1, 1):
|
|
for y in (0.0, -0.25, 0.235):
|
|
rivet(P, (sx * 0.199, y, 0.151), (0, 0, 1), r=0.009, m="M_Navy")
|
|
# plank deck the engine stands on
|
|
for k, x in enumerate((-0.126, -0.042, 0.042, 0.126)):
|
|
P.append(beam(x - 0.04, x + 0.04, -0.17, 0.21, 0.13, 0.152, (0, 1, 0), s=1.5, off=(0.25 * k, 0.15 * k), bevel=0.005))
|
|
grip(P, (0, 0, 0), tilt=12, h1=0.078)
|
|
trigger(P, y0=-0.034, z0=0.046, drop=0.05)
|
|
grip(P, (0, -0.25, 0), tilt=0, h0=-0.07, h1=0.078)
|
|
# engine off to the player's right, stack on the far side, so the line of sight to the drum stays open
|
|
P += two_stroke((-0.062, 0.05, 0.205), s=1.06, pull=1, tank=True, stack=True)
|
|
# chain case from the engine down to the drum gearbox
|
|
FX = frame_on((-0.022, 0, 0), (1, 0, 0), up=(0, 0, 1))
|
|
case = [(0.03, 0.21), (0.03, 0.156), (-0.33, 0.108), (-0.445 - 0.05, 0.11), (-0.445 - 0.078, 0.158), (-0.445 - 0.05, 0.208), (-0.445 + 0.03, 0.222), (-0.15, 0.226), (0.0, 0.236)]
|
|
P.append(prism("chaincase", case, 0.044, FX, "M_PaintRed", bevel=0.009, segs=1))
|
|
P.append(rbox("gearbox", (0.068, 0.1, 0.1), tuple(A), bevel=0.018, segs=2, m="M_Navy"))
|
|
for yy, zz in ((-0.1, 0.227), (-0.26, 0.2), (-0.44, 0.213)):
|
|
for sx in (-1, 1):
|
|
rivet(P, (sx * 0.0225, yy, zz), (sx, 0, 0), r=0.0065, m="M_Brass")
|
|
# red side arms carrying the axle, bolted to the outside of the rails
|
|
for sx in (-1, 1):
|
|
F = frame_on((sx * 0.226 if sx < 0 else 0.226, 0, 0), (1, 0, 0), up=(0, 0, 1))
|
|
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)]
|
|
P.append(prism("arm", arm, 0.018, F, "M_PaintRed", bevel=0.005, segs=1))
|
|
P.append(lathe("hub", [(0.0, 0.244), (0.03, 0.244), (0.046, 0.238), (0.05, 0.226), (0.05, 0.212)], segs=14, m="M_Navy",
|
|
frame=Matrix.Translation(A) @ (M_axis("X") if sx > 0 else M_axis("-X")), smooth_ang=45))
|
|
for y in (-0.1, -0.16, -0.25):
|
|
rivet(P, (sx * 0.2445, y, 0.135 if y > -0.2 else 0.13), (sx, 0, 0), r=0.0085, m="M_Navy")
|
|
# steel skid under each arm
|
|
P.append(ptube("skid", bez([(sx * 0.235, -0.27, 0.09), (sx * 0.235, -0.45, -0.004), (sx * 0.235, -0.58, 0.0), (sx * 0.235, -0.655, 0.05)], 9), 0.0115, "M_Steel"))
|
|
# low galvanised deflector behind the drum: the top of the drum stays in the operator's view
|
|
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 = grid_slab("deflector", defl, 6, 2, 0.004, -0.004, "M_Tin", smooth_ang=60)
|
|
grain(d, (0, 0.5, 0.5), 4.0)
|
|
P.append(d)
|
|
ptop = defl(1.0, 0.0, 0.0)
|
|
P.append(bar("deflrim", ptop, (-ptop.x, ptop.y, ptop.z), 0.0095, "M_Steel", verts=8))
|
|
done(P, "Body", uv=4.0, ang=45)
|
|
drum_half("Ring1", A, 1)
|
|
drum_half("Ring2", A, -1)
|
|
empty("Nozzle", (0, -0.656, 0.158))
|
|
return dict(elev=26, azim=-40, extra=[("fp", dict(elev=20, azim=155), None), ("side", dict(elev=6, azim=-90), None)])
|
|
|
|
|
|
# ======================================================================= first-person gloves
|
|
|
|
def stitches(P, pts, n, m="M_PaintWhite", size=(0.0058, 0.0022, 0.0022)):
|
|
"""Row of stitch dashes along a polyline of world points."""
|
|
C = [Vector(p) for p in pts]
|
|
L = [0.0]
|
|
for a, b in zip(C, C[1:]):
|
|
L.append(L[-1] + (b - a).length)
|
|
for k in range(n):
|
|
t = (k + 0.5) / n * L[-1]
|
|
i = max(j for j in range(len(C) - 1) if L[j] <= t + 1e-9)
|
|
f = (t - L[i]) / max(1e-9, L[i + 1] - L[i])
|
|
p = C[i].lerp(C[i + 1], f)
|
|
o = cube("st", (size[2], size[1], size[0]), (0, 0, 0), m)
|
|
o.data.transform(frame_on(p, C[i + 1] - C[i], up=(0, 0, 1)))
|
|
P.append(o)
|
|
|
|
|
|
def digit(name, pts, r, joints, m="M_GloveOrange"):
|
|
"""Leather finger: straight bones, soft swellings at the joints, a squared-off padded tip (not a sausage)."""
|
|
tip0 = 0.84
|
|
|
|
def rf(s, l):
|
|
k = (0.93 + 0.1 * sum(math.exp(-((s - j) / 0.06) ** 2) for j in joints)) * (1.04 - 0.14 * s)
|
|
if s > tip0:
|
|
t = (s - tip0) / (1 - tip0)
|
|
k *= math.sqrt(max(0.0, 1 - t ** 4)) * 0.94 + 0.06
|
|
return r * k
|
|
return sweep_circle(name, pts, rf, segs=10, per=3, m=m, cap=True, smooth_ang=70)
|
|
|
|
|
|
def fist_finger(z, ln):
|
|
"""One finger around the grip, wrist-side knuckle to fingertip (x, y fixed by the fist, z = row)."""
|
|
K = Vector((-0.003, -0.078, z))
|
|
PIP = Vector((0.0115, -0.131 - 0.006 * ln, z * 1.02))
|
|
DIP = Vector((0.056 * ln + 0.004, -0.149 - 0.004 * ln, z * 1.03))
|
|
TIP = Vector((0.098 * ln, -0.122 * ln - 0.012, z * 1.0))
|
|
return [K, K.lerp(PIP, 0.5), PIP, PIP.lerp(DIP, 0.5), DIP, DIP.lerp(TIP, 0.55), TIP]
|
|
|
|
|
|
def glove(name, side):
|
|
"""Right hand built; side=-1 mirrors to the left. Wrist at origin, fingers -Y, palm towards +X (R). Same fist as before,
|
|
so the placement in ViewModel still lands on the grips: fingers wrap the vertical handle, thumb across the top."""
|
|
P = []
|
|
FW = M_fwd()
|
|
P.append(loft("palm", [(0, 0, 0.036, 0.042, -0.012, 2.6), (0, 0, 0.04, 0.05, 0.025, 2.9), (0.003, 0.0, 0.041, 0.054, 0.06, 3.2),
|
|
(0.002, 0.0, 0.038, 0.055, 0.085, 3.2), (0.0, 0.0, 0.03, 0.05, 0.1, 2.8), (0, 0, 0, 0, 0.108)],
|
|
segs=20, m="M_GloveOrange", frame=FW, cap0=False, smooth_ang=70))
|
|
# four leather fingers, slightly different lengths
|
|
rows = ((0.0385, 0.0172, 0.97), (0.0132, 0.0178, 1.03), (-0.0122, 0.0172, 0.99), (-0.0362, 0.0156, 0.88))
|
|
for z, r, ln in rows:
|
|
P.append(digit("finger", fist_finger(z, ln), r, (0.02, 0.36, 0.68)))
|
|
# thumb and its pad
|
|
P.append(digit("thumb", [(0.016, -0.02, 0.03), (0.042, -0.044, 0.046), (0.07, -0.07, 0.056), (0.082, -0.084, 0.056), (0.106, -0.098, 0.05)], 0.0195, (0.1, 0.55)))
|
|
P.append(sphere("thenar", 0.034, (0.028, -0.036, 0.036), seg=10, rings=6, m="M_GloveOrange", scale=(0.8, 1.5, 0.9)))
|
|
# darker reinforcement: knuckle strap across the back, back-of-hand patch, seam stitching
|
|
for z, r, ln in rows:
|
|
f = fist_finger(z, ln)
|
|
c = f[0].lerp(f[2], 0.3) + Vector((-0.0118, -0.0015, 0))
|
|
P.append(sphere("kpad", r * 0.92, tuple(c), seg=8, rings=5, m="M_Leather", scale=(0.62, 1.1, 0.96)))
|
|
fr = frame_on((-0.0405, -0.047, 0.0), (-1, 0, 0), up=(0, -1, 0))
|
|
P.append(prism("patch", rrect_pts(0.062, 0.078, 0.018, 3), 0.0065, fr @ Matrix.Translation((0, 0, -0.003)), "M_Leather", bevel=0.002, segs=1))
|
|
for sz in (-0.03, 0.03):
|
|
stitches(P, [(-0.0478, -0.016, sz), (-0.0478, -0.078, sz)], 5)
|
|
# work-glove gauntlet: stiff flared dark cuff with a rolled edge, strap + buckle at the wrist, red shirt sleeve beyond
|
|
BK = M_axis("Y")
|
|
P.append(loft("wrist", [(0, 0, 0.0352, 0.0432, -0.016, 2.5), (0, 0, 0.038, 0.046, 0.004, 2.5), (0, 0, 0.038, 0.046, 0.016, 2.5)],
|
|
segs=20, m="M_GloveOrange", frame=BK, cap0=False, cap1=False, smooth_ang=70))
|
|
P.append(loft("gaunt", [(0, 0, 0.036, 0.044, 0.012, 2.4), (0, 0, 0.044, 0.052, 0.03, 2.4), (0, 0, 0.05, 0.058, 0.062, 2.3), (0, 0, 0.0545, 0.0625, 0.078, 2.3)],
|
|
segs=20, m="M_Leather", frame=BK, cap0=False, cap1=False, smooth_ang=70))
|
|
P.append(loft("cedge", [(0, 0, 0.0535, 0.0615, 0.074, 2.3), (0, 0, 0.0595, 0.068, 0.078, 2.3), (0, 0, 0.0595, 0.068, 0.086, 2.3), (0, 0, 0.05, 0.059, 0.09, 2.3)],
|
|
segs=20, m="M_GloveOrange", frame=BK, cap0=False, cap1=False, smooth_ang=60))
|
|
P.append(loft("strap", [(0, 0, 0.0375, 0.0455, 0.006, 2.5), (0, 0, 0.0405, 0.0485, 0.008, 2.5), (0, 0, 0.0415, 0.0495, 0.024, 2.5), (0, 0, 0.0395, 0.0475, 0.026, 2.5)],
|
|
segs=20, m="M_Leather", frame=BK, cap0=False, cap1=False, smooth_ang=60))
|
|
P.append(rbox("buckle", (0.008, 0.024, 0.026), (-0.0415, 0.0162, 0.0), bevel=0.002, segs=1, m="M_Brass"))
|
|
for k in range(10): # stitched line round the cuff, on the side the player sees
|
|
a = DEG(-108 + k * 24)
|
|
p0 = Vector((0.0545 * math.cos(a), 0.063, 0.0615 * math.sin(a)))
|
|
p1 = Vector((0.0545 * math.cos(a + DEG(10)), 0.063, 0.0615 * math.sin(a + DEG(10))))
|
|
stitches(P, [p0, p1], 1, size=(0.0065, 0.0024, 0.0024))
|
|
# a red forearm so no arm stub ever faces the camera. It bends towards the back of the hand: with the tools that swings
|
|
# the elbow out to the side of the screen, and the tablet's 80 degree glove roll turns the same bend straight down.
|
|
P.append(lathe("cuffroll", [(0.046, 0.07), (0.05, 0.092), (0.046, 0.104), (0.05, 0.118)], segs=14, m="M_PaintRed", frame=BK, smooth_ang=70))
|
|
P.append(sweep_circle("sleeve", [(0, 0.112, 0), (-0.004, 0.18, 0), (-0.042, 0.272, 0), (-0.13, 0.36, 0)], lambda t, l: 0.05 + 0.008 * t, segs=14, per=4, m="M_PaintRed", smooth_ang=70))
|
|
o = done(P, "Glove", uv=6.0, ang=60)
|
|
if side < 0:
|
|
mirror_x(o)
|
|
return o
|
|
|
|
|
|
def glove_r():
|
|
glove("Glove", 1)
|
|
return dict(elev=28, azim=150, extra=[("front", dict(elev=15, azim=-40), None), ("palm", dict(elev=10, azim=70), None), ("back", dict(elev=15, azim=-100), None)])
|
|
|
|
|
|
def glove_l():
|
|
glove("Glove", -1)
|
|
return dict(elev=28, azim=-150, extra=[("front", dict(elev=15, azim=40), None), ("palm", dict(elev=10, azim=-70), None)])
|
|
|
|
|
|
# ======================================================================= SM_Gadget_Tablet = clipboard
|
|
|
|
def flat(name, pts, y, m, t=0.0012):
|
|
"""A thin mark lying on the sheet (x, z outline), facing +Y."""
|
|
return prism(name, [(-x, z) for x, z in pts], t, frame_on((0, y, 0), (0, 1, 0), up=(0, 0, 1)), m)
|
|
|
|
|
|
def line_mark(P, p0, p1, w, y, m):
|
|
d = (Vector((p1[0] - p0[0], p1[1] - p0[1], 0))).normalized()
|
|
n = Vector((-d.y, d.x, 0)) * w / 2
|
|
P.append(flat("ln", [(p0[0] + n.x, p0[1] + n.y), (p1[0] + n.x, p1[1] + n.y), (p1[0] - n.x, p1[1] - n.y), (p0[0] - n.x, p0[1] - n.y)], y, m))
|
|
|
|
|
|
def gadget_tablet():
|
|
"""Clipboard faces +Y (towards the player), origin at the bottom centre of the old tablet, same width and height."""
|
|
P = []
|
|
Yf = 0.012
|
|
# the board
|
|
bd = prism("board", rrect_pts(0.352, 0.276, 0.022, 3), 0.024, frame_on((0, -0.012, 0.109), (0, 1, 0), up=(0, 0, 1)), "M_Timber", bevel=0.005, segs=1)
|
|
grain(bd, (0, 0, 1), 2.2, off=(0.06, 0.1))
|
|
P.append(bd)
|
|
# spare sheets peeking out under the plan
|
|
P.append(flat("under", [(-0.141, -0.009), (0.145, -0.012), (0.147, 0.214), (-0.139, 0.217)], Yf + 0.0002, "M_PaintCream", t=0.0012))
|
|
# big spring clip + wide tin backing plate at the top
|
|
P.append(rbox("clipbase", (0.15, 0.011, 0.044), (0, Yf + 0.004, 0.226), bevel=0.0045, segs=2, m="M_Steel"))
|
|
P.append(sweep_circle("clipjaw", [(-0.066, Yf + 0.01, 0.206), (0.0, Yf + 0.012, 0.204), (0.066, Yf + 0.01, 0.206)], lambda s, l: 0.0065, segs=6, per=4, m="M_Steel"))
|
|
for sx in (-1, 1):
|
|
P.append(cyl("rivet", 0.0085, 0.008, (sx * 0.056, Yf + 0.011, 0.234), axis="Y", verts=8, m="M_Brass", bevel=0.002, segs=1))
|
|
P.append(rbox("lever", (0.052, 0.012, 0.03), (0, Yf + 0.012, 0.246), bevel=0.005, segs=2, m="M_Navy"))
|
|
# the plan itself: drawn homestead, mowing strips, barn, a red X where the next job is
|
|
y = Yf + 0.0018
|
|
z0, z1, x0, x1 = 0.026, 0.158, -0.118, 0.052
|
|
n = 6
|
|
w = (x1 - x0) / n
|
|
for k in range(n):
|
|
P.append(flat("strip", [(x0 + k * w, z0), (x0 + (k + 1) * w, z0), (x0 + (k + 1) * w, z1), (x0 + k * w, z1)], y, "M_PaintGreen" if k % 2 == 0 else "M_Teal"))
|
|
for a, b in (((x0, z0), (x1, z0)), ((x1, z0), (x1, z1)), ((x1, z1), (x0, z1)), ((x0, z1), (x0, z0))):
|
|
line_mark(P, a, b, 0.0042, y + 0.0013, "M_Navy")
|
|
bx0, bz0 = -0.092, 0.092
|
|
P.append(flat("barn", [(bx0, bz0), (bx0 + 0.054, bz0), (bx0 + 0.054, bz0 + 0.032), (bx0 + 0.027, bz0 + 0.052), (bx0, bz0 + 0.032)], y + 0.0013, "M_PaintRed"))
|
|
P.append(flat("door", [(bx0 + 0.018, bz0), (bx0 + 0.036, bz0), (bx0 + 0.036, bz0 + 0.021), (bx0 + 0.018, bz0 + 0.021)], y + 0.0026, "M_PaintWhite"))
|
|
line_mark(P, (0.012, 0.05), (0.04, 0.078), 0.0085, y + 0.0013, "M_PaintRed")
|
|
line_mark(P, (0.04, 0.05), (0.012, 0.078), 0.0085, y + 0.0013, "M_PaintRed")
|
|
# checklist down the margin + a heading
|
|
for k, ln in enumerate((0.055, 0.04, 0.05, 0.034)):
|
|
zz = 0.14 - k * 0.032
|
|
P.append(flat("box", [(0.066, zz), (0.078, zz), (0.078, zz + 0.012), (0.066, zz + 0.012)], y, "M_PaintYellow" if k < 2 else "M_Rope", t=0.0012))
|
|
line_mark(P, (0.084, zz + 0.006), (0.084 + ln * 0.8, zz + 0.006), 0.0036, y, "M_Navy")
|
|
line_mark(P, (-0.118, 0.178), (0.03, 0.178), 0.0065, y, "M_Navy")
|
|
# stub of pencil on a bit of twine, tied to the clip
|
|
pa, pb = Vector((0.156, Yf + 0.0075, 0.17)), Vector((0.156, Yf + 0.0075, 0.03))
|
|
P.append(bar("pencil", pa, pa.lerp(pb, 0.82), 0.0075, "M_PaintYellow", verts=6))
|
|
P.append(cyl("eraser", 0.0078, 0.012, pa + Vector((0, 0, 0.003)), verts=6, m="M_PaintRed"))
|
|
P.append(bar("tipw", pa.lerp(pb, 0.82), pb, 0.0075, "M_Timber", verts=6, r1=0.0012))
|
|
P.append(ptube("twine", bez([(0.07, Yf + 0.012, 0.236), (0.12, Yf + 0.018, 0.24), (0.158, Yf + 0.016, 0.21), (0.156, Yf + 0.01, 0.176)], 7), 0.003, "M_Twine"))
|
|
# small rope loop at the bottom edge where the tablet's grip used to be
|
|
P.append(ptube("hang", bez([(-0.06, 0.0, -0.022), (-0.03, 0.0, -0.03), (0.03, 0.0, -0.03), (0.06, 0.0, -0.022)], 7), 0.0048, "M_Rope"))
|
|
done(P, "Body", uv=4.0, ang=40)
|
|
# the paper keeps the old part name; a little lift at one corner so it reads as a loose sheet
|
|
nu, nv = 5, 6
|
|
xa, xb, za, zb = -0.136, 0.136, -0.006, 0.21
|
|
verts, faces, uvs = [], [], []
|
|
for j in range(nv + 1):
|
|
for i in range(nu + 1):
|
|
u, v = i / nu, j / nv
|
|
lift = max(0.0, 0.3 - u) ** 2 * max(0.0, 0.25 - v) ** 2 * 1.2
|
|
verts.append((xa + (xb - xa) * (1 - u), Yf + 0.0016 + lift, za + (zb - za) * v))
|
|
uvs.append((u, v))
|
|
for j in range(nv):
|
|
for i in range(nu):
|
|
a = j * (nu + 1) + i
|
|
faces.append((a, a + 1, a + nu + 2, a + nu + 1))
|
|
sc = mesh_obj("Screen", verts=verts, faces=faces)
|
|
set_mats(sc, "M_PaintWhite")
|
|
sc.data.uv_layers.new(name="UVMap")
|
|
uvl = sc.data.uv_layers[0].data
|
|
for lp in sc.data.loops:
|
|
uvl[lp.index].uv = uvs[lp.vertex_index]
|
|
# normals towards +Y
|
|
bm = bmesh.new()
|
|
bm.from_mesh(sc.data)
|
|
bm.normal_update()
|
|
if sum(f.normal.y for f in bm.faces) < 0:
|
|
bmesh.ops.reverse_faces(bm, faces=list(bm.faces))
|
|
bm.to_mesh(sc.data)
|
|
bm.free()
|
|
smooth(sc, 40)
|
|
return dict(elev=10, azim=-160, extra=[("angle", dict(elev=30, azim=150), None)])
|
|
|
|
|
|
# ======================================================================= SM_Crew
|
|
|
|
def bfs(seed):
|
|
seen = {seed}
|
|
st = [seed]
|
|
while st:
|
|
x = st.pop()
|
|
for e in x.link_edges:
|
|
w = e.other_vert(x)
|
|
if w not in seen:
|
|
seen.add(w)
|
|
st.append(w)
|
|
return seen
|
|
|
|
|
|
def bisect_z(bm, seed_fn, z):
|
|
vs = bfs(seed_fn(bm))
|
|
es = {e for v in vs for e in v.link_edges}
|
|
fs = {f for v in vs for f in v.link_faces}
|
|
bmesh.ops.bisect_plane(bm, geom=list(vs) + list(es) + list(fs), plane_co=(0, 0, z), plane_no=(0, 0, 1))
|
|
|
|
|
|
WAIST, COLLAR = 0.38, 0.6
|
|
SL0, SL1, GL0, GL1 = 0.435, 0.455, 0.305, 0.325 # sleeve hem and glove cuff bands on the arms (source units)
|
|
|
|
|
|
def _seeds():
|
|
return (lambda b: max(b.verts, key=lambda v: v.co.z), lambda b: max(b.verts, key=lambda v: v.co.x), lambda b: min(b.verts, key=lambda v: v.co.x))
|
|
|
|
|
|
def dress_body(body):
|
|
"""Paint the outfit straight onto the creature (source units): it deforms exactly like the skin and costs almost no tris.
|
|
Cut clean hem lines with bisects and assign materials per band. The cloth is puffed out later by puff_body(): crew_rig
|
|
measures the arm bones from the arm vertices, which must still be in their original place then."""
|
|
me = body.data
|
|
if me.attributes.get("custom_normal"):
|
|
me.attributes.remove(me.attributes["custom_normal"])
|
|
for n in ("M_PaintRed", "M_Denim", "M_GloveOrange"):
|
|
me.materials.append(mat(n))
|
|
SKIN, SHIRT, DENIM, GLOVE = 0, 1, 2, 3
|
|
bm = bmesh.new()
|
|
bm.from_mesh(me)
|
|
main, armL, armR = _seeds()
|
|
for z in (0.3, WAIST - 0.018, WAIST, COLLAR):
|
|
bisect_z(bm, main, z)
|
|
for fn in (armL, armR):
|
|
for z in (GL0, GL1, SL0, SL1):
|
|
bisect_z(bm, fn, z)
|
|
vm, vl, vr = bfs(main(bm)), bfs(armL(bm)), bfs(armR(bm))
|
|
for f in bm.faces:
|
|
z = f.calc_center_median().z
|
|
vs0 = f.verts[0]
|
|
if vs0 in vm:
|
|
f.material_index = SKIN if z > COLLAR else (SHIRT if z > WAIST else DENIM)
|
|
elif vs0 in vl or vs0 in vr:
|
|
f.material_index = SHIRT if z > SL0 else (SKIN if z > GL1 else GLOVE)
|
|
bm.to_mesh(me)
|
|
bm.free()
|
|
if me.uv_layers:
|
|
me.uv_layers[0].name = "UVMap"
|
|
smooth(body, 70)
|
|
return body
|
|
|
|
|
|
def puff_body(body, k):
|
|
"""Push the cloth bands out along the normals (mesh already scaled by k = CREW_H, rig already measured)."""
|
|
me = body.data
|
|
bm = bmesh.new()
|
|
bm.from_mesh(me)
|
|
bm.normal_update()
|
|
main, armL, armR = _seeds()
|
|
vm, vl, vr = bfs(main(bm)), bfs(armL(bm)), bfs(armR(bm))
|
|
eps = 1e-4
|
|
move = {}
|
|
for v in vm:
|
|
z = v.co.z / k
|
|
if z < 0.2:
|
|
d = 0.0 # inside the boots, and it must not push through the ground
|
|
elif z < WAIST - 0.018 - eps:
|
|
d = 0.012
|
|
elif z < WAIST + eps:
|
|
d = 0.017 # waistband
|
|
elif z < COLLAR + eps:
|
|
d = 0.006
|
|
else:
|
|
d = 0.0
|
|
move[v] = d * k
|
|
for v in vl | vr:
|
|
z = v.co.z / k
|
|
if z > SL1 - eps:
|
|
d = 0.01 # sleeve
|
|
elif z > SL0 - eps:
|
|
d = 0.018 # rolled sleeve hem
|
|
elif z > GL1 + eps:
|
|
d = 0.0 # bare forearm
|
|
elif z > GL0 - eps:
|
|
d = 0.016 # glove cuff
|
|
else:
|
|
d = 0.007 # leather glove
|
|
move[v] = d * k
|
|
for v, d in move.items():
|
|
v.co += v.normal * d
|
|
bm.to_mesh(me)
|
|
bm.free()
|
|
smooth(body, 70)
|
|
|
|
|
|
def crew_kerchief(S, tilt):
|
|
"""`Vest` in the game code: CrewAvatar tints this renderer per player, so it is the neckerchief + hat band.
|
|
The shirt stays red and the overalls stay denim whoever is wearing them."""
|
|
P = []
|
|
# band round the neck, just under the eyes
|
|
band = lambda u, v, off: S.p(-268 + 356 * u, 0.586 + 0.034 * v, 0.03 + off + 0.008 * math.sin(math.pi * v))
|
|
P.append(grid_slab("band", band, 26, 2, 0.006, -0.008, "M_Teal", smooth_ang=60))
|
|
|
|
def tri(u, v, off):
|
|
w = (1 - v) ** 0.9 * 40.0 + 0.8
|
|
a = -90 + (u - 0.5) * 2 * w
|
|
z = 0.61 - 0.13 * v - 0.02 * abs(2 * u - 1) * (1 - v)
|
|
return S.p(a, z, 0.044 + 0.012 * math.sin(math.pi * v) * (1 - abs(2 * u - 1)) + off)
|
|
P.append(grid_slab("tri", tri, 9, 5, 0.004, -0.008, "M_Teal", smooth_ang=60))
|
|
# knot + two tails at the back of the neck
|
|
kn = S.p(90, 0.606, 0.046)
|
|
P.append(sphere("knot", 0.027, tuple(kn), seg=8, rings=5, m="M_Teal", scale=(1.2, 0.8, 1)))
|
|
for sx in (-1, 1):
|
|
pts = [(0, 0, 0), (sx * 0.022, 0.01, -0.03), (sx * 0.05, 0.016, -0.075), (sx * 0.062, 0.02, -0.105)]
|
|
P.append(ptube("ktail", [tuple(kn + Vector(p)) for p in bez(pts, 5)], 0.014, "M_Teal"))
|
|
# hat band (same renderer, so it carries the player colour too)
|
|
P.append(lathe("hatband", [(0.2345, 0.018), (0.2395, 0.024), (0.2395, 0.07), (0.2315, 0.076)], segs=28, m="M_Teal", frame=tilt, smooth_ang=50))
|
|
return done(P, "Vest", uv=3.0, ang=55)
|
|
|
|
|
|
def crew_hat(S, tilt):
|
|
"""Wide straw hat, same tilt and seat on the head as the old helmet. Bands of two straw tones give the woven look."""
|
|
P = []
|
|
crown = [(0.232, -0.012), (0.236, 0.02), (0.236, 0.06), (0.229, 0.1), (0.212, 0.135), (0.178, 0.162), (0.128, 0.182), (0.07, 0.196), (0.0, 0.2)]
|
|
for i, (a, b) in enumerate(zip(crown, crown[1:])):
|
|
P.append(lathe("crown", [a, b], segs=26, m="M_Hay" if i % 3 == 2 else "M_Straw", frame=tilt, smooth_ang=70))
|
|
|
|
def rim_z(a):
|
|
return 0.012 * math.cos(2 * a) + 0.006 * math.sin(5 * a)
|
|
rings = [(0.228, 0.0), (0.262, -0.0065), (0.3, -0.0165), (0.33, -0.0255), (0.352, -0.0345), (0.36, -0.039)]
|
|
|
|
def brim(i):
|
|
r0, z0 = rings[i]
|
|
r1, z1 = rings[i + 1]
|
|
return lambda a: [(r0 * (1 + 0.012 * math.sin(3 * a)), z0 + rim_z(a) * r0 / 0.36 + 0.004),
|
|
(r1 * (1 + 0.012 * math.sin(3 * a)), z1 + rim_z(a) * r1 / 0.36 + 0.004)]
|
|
for i in range(len(rings) - 1):
|
|
P.append(revolve_fn("brim", 34, brim(i), m="M_Hay" if i == 2 else "M_Straw", frame=tilt, smooth_ang=70))
|
|
P.append(revolve_fn("under", 34, lambda a: [(0.361 * (1 + 0.012 * math.sin(3 * a)), -0.039 + rim_z(a) + 0.004), (0.355 * (1 + 0.012 * math.sin(3 * a)), -0.052 + rim_z(a)), (0.228, -0.014)],
|
|
m="M_Straw", frame=tilt, smooth_ang=70))
|
|
# a few frayed straws at the edge
|
|
rnd = random.Random(8)
|
|
for k in range(14):
|
|
a = rnd.uniform(0, TAU)
|
|
rr = 0.36 * (1 + 0.012 * math.sin(3 * a))
|
|
p0 = tilt @ Vector((math.cos(a) * rr * 0.98, math.sin(a) * rr * 0.98, -0.036 + rim_z(a)))
|
|
p1 = tilt @ Vector((math.cos(a + rnd.uniform(-0.1, 0.1)) * (rr + rnd.uniform(0.025, 0.05)), math.sin(a + rnd.uniform(-0.1, 0.1)) * (rr + 0.03), -0.042 + rim_z(a)))
|
|
P.append(bar("fray", p0, p1, 0.0035, "M_Straw", verts=3))
|
|
return done(P, "Helmet", uv=4.0, ang=60)
|
|
|
|
|
|
def crew_gear(S):
|
|
"""`Backpack`: burlap grass sack with its fill window, rope straps, the overalls' bib and straps, the little lantern."""
|
|
P = []
|
|
GAP = 0.02
|
|
|
|
def bibf(u, v, off):
|
|
span = 66 - 18 * v
|
|
a = -90 + (u - 0.5) * span
|
|
z = 0.356 + (0.538 - 0.356) * v - 0.01 * v * (2 * u - 1) ** 2
|
|
return S.p(a, z, GAP + off)
|
|
P.append(grid_slab("bib", bibf, 10, 6, 0.007, -0.012, "M_Denim", smooth_ang=50))
|
|
|
|
def backf(u, v, off):
|
|
span = 74 - 34 * v
|
|
return S.p(90 + (u - 0.5) * span, 0.356 + 0.12 * v, GAP + off)
|
|
P.append(grid_slab("backp", backf, 8, 3, 0.007, -0.012, "M_Denim", smooth_ang=50))
|
|
|
|
# chest pocket with yellow contrast stitching
|
|
def pocket(u, v, off):
|
|
return S.p(-90 + (u - 0.5) * 30, 0.4 + 0.08 * v, GAP + 0.009 + off)
|
|
P.append(grid_slab("pocket", pocket, 5, 3, 0.005, -0.004, "M_Denim", smooth_ang=50))
|
|
us = (0, 0.25, 0.5, 0.75, 1)
|
|
loop = [pocket(0, 1, 0.0065)] + [pocket(u, 0, 0.0065) for u in us] + [pocket(u, 1, 0.0065) for u in reversed(us)]
|
|
P.append(ptube("pstitch", [tuple(p) for p in loop], 0.0034, "M_PaintYellow", rs=0))
|
|
edge = [bibf(0, 0.2, 0.0095), bibf(0, 0.6, 0.0095)] + [bibf(u, 1, 0.0095) for u in us] + [bibf(1, 0.6, 0.0095), bibf(1, 0.2, 0.0095)]
|
|
P.append(ptube("bstitch", [tuple(p) for p in edge], 0.0032, "M_PaintYellow", rs=0))
|
|
|
|
# shoulder straps: from the top corners of the bib, round under the hat, crossing on the back
|
|
def strap_fn(path, w):
|
|
C = catmull([(a, z, 0) for a, z in path], 6)
|
|
|
|
def f(u, v, off):
|
|
i = u * (len(C) - 1)
|
|
i0 = min(int(i), len(C) - 2)
|
|
t = i - i0
|
|
p = C[i0].lerp(C[i0 + 1], t)
|
|
tan = C[i0 + 1] - C[i0]
|
|
tan = Vector((tan.x * DEG(1) * 0.27, tan.y, 0)).normalized()
|
|
nrm = Vector((-tan.y, tan.x, 0))
|
|
a = p.x + nrm.x * (v - 0.5) * w / (DEG(1) * 0.27)
|
|
z = p.y + nrm.y * (v - 0.5) * w
|
|
return S.p(a, z, GAP + 0.004 + off)
|
|
return f, len(C)
|
|
for sx in (1, -1):
|
|
path = [(-90 + sx * 22, 0.532), (-90 + sx * 36, 0.568), (-90 + sx * 72, 0.59), (-90 + sx * 115, 0.585), (-90 + sx * 150, 0.53), (-90 + sx * 172, 0.47), (-90 + sx * 192, 0.42)]
|
|
f, nc = strap_fn(path, 0.05)
|
|
P.append(grid_slab("strap", f, nc, 1, 0.007, -0.006, "M_Denim"))
|
|
pb = S.p(-90 + sx * 21, 0.522, GAP + 0.012)
|
|
bolt(P, pb, (pb - Vector((0, S.cy, pb.z))).normalized(), r=0.019, h=0.012, m="M_Brass", hexa=False)
|
|
ps = S.p(-90 + sx * 62, 0.352, 0.03)
|
|
bolt(P, ps, (ps - Vector((0, S.cy, ps.z))).normalized(), r=0.015, h=0.01, m="M_Brass", hexa=False)
|
|
|
|
# ---- burlap grass sack on the back; the back surface sits where the old tank window did
|
|
cy_, zb, zt = 0.43, 0.285, 0.75
|
|
FB = Matrix.Translation((0, cy_, 0))
|
|
rx, ry = 0.205, 0.135
|
|
rings = [(0, 0, 0, 0, zb), (0, 0, rx * 0.72, ry * 0.7, zb + 0.004, 2.5), (0, 0, rx * 0.93, ry * 0.92, zb + 0.04, 2.5), (0, 0, rx * 1.04, ry * 1.02, zb + 0.13, 2.6), (0, 0, rx * 1.05, ry * 1.03, zb + 0.28, 2.6),
|
|
(0, 0, rx * 0.93, ry * 0.92, zt - 0.08, 2.4), (0, 0, rx * 0.66, ry * 0.68, zt - 0.02, 2.2), (0, 0, rx * 0.38, ry * 0.46, zt + 0.02, 2.0), (0, 0, rx * 0.21, ry * 0.28, zt + 0.045, 2.0),
|
|
(0, 0, rx * 0.2, ry * 0.27, zt + 0.06, 2.0), (0, 0, rx * 0.34, ry * 0.44, zt + 0.09, 2.0), (0, 0, rx * 0.4, ry * 0.5, zt + 0.115, 2.0), (0, 0, rx * 0.2, ry * 0.26, zt + 0.1, 2.0)]
|
|
sack = loft("sack", rings, segs=24, m="M_Burlap", frame=FB, smooth_ang=70)
|
|
pleats(sack, (0, cy_, 0), (0, 0, 1), n=8, amp=0.22, t0=zt - 0.08, t1=zt + 0.03)
|
|
wobble(sack, 0.012, 6.5, seed=3.0)
|
|
around(sack, (0, cy_, 0), (0, 0, 1), nu=4.5, s=4.6)
|
|
P.append(sack)
|
|
tie(P, (0, cy_, zt + 0.054), (0, 0, 1), 0.052, tails=[[(0.05, cy_ - 0.02, zt + 0.056), (0.09, cy_ - 0.05, zt + 0.05), (0.115, cy_ - 0.06, zt + 0.01), (0.12, cy_ - 0.05, zt - 0.03)]])
|
|
# grass poking out of the top
|
|
rnd = random.Random(4)
|
|
for k in range(11):
|
|
a = TAU * k / 11 + rnd.uniform(-0.2, 0.2)
|
|
r_ = rnd.uniform(0.02, 0.062)
|
|
p0 = Vector((math.cos(a) * r_, cy_ + math.sin(a) * r_ * 0.8, zt + 0.08))
|
|
p1 = p0 + Vector((math.cos(a) * rnd.uniform(0.03, 0.07), math.sin(a) * rnd.uniform(0.02, 0.05), rnd.uniform(0.08, 0.13)))
|
|
P.append(bar("blade", p0, p1, 0.019, rnd.choice(("M_PaintGreen", "M_Teal")), verts=4, r1=0.002))
|
|
# the fill window: a laced leather-edged slit on the back, stuffed with clippings
|
|
wz0, wz1, ww = 0.433, 0.767, 0.082
|
|
wc = (wz0 + wz1) / 2
|
|
F = frame_on((0, 0.566, wc), (0, 1, 0), up=(0, 0, 1))
|
|
P.append(ring_prism("wframe", rrect_pts(ww + 0.056, wz1 - wz0 + 0.056, 0.04, 4), rrect_pts(ww, wz1 - wz0, 0.03, 4), 0.022, F, "M_Leather", bevel=0.004))
|
|
P.append(prism("wback", rrect_pts(ww + 0.006, wz1 - wz0 + 0.006, 0.03, 4), 0.003, F, "M_Navy"))
|
|
for k in range(5): # twine lacing across the slit
|
|
z = wz0 + 0.035 + k * (wz1 - wz0 - 0.07) / 4
|
|
for s_ in (-1, 1):
|
|
P.append(ptube("lace", [(-(ww / 2 + 0.018), 0.589, z + s_ * 0.014), (0, 0.593, z), ((ww / 2 + 0.018), 0.589, z - s_ * 0.014)], 0.0042, "M_Twine"))
|
|
fill = prism("TankFill", rrect_pts(ww - 0.004, wz1 - wz0 - 0.004, 0.028, 4), 0.012, F @ Matrix.Translation((0, 0, 0.004)), "M_Clippings")
|
|
# two rope straps from the sack over the shoulders, knotted on the shirt
|
|
for sx in (1, -1):
|
|
pts = [(sx * 0.13, cy_ - 0.1, 0.7), (sx * 0.19, 0.26, 0.655), S.p(90 - sx * 72, 0.632, 0.034), S.p(90 - sx * 108, 0.612, 0.034), S.p(90 - sx * 130, 0.555, 0.034), S.p(90 - sx * 143, 0.47, 0.03)]
|
|
P.append(ptube("rope", bez([tuple(p) for p in pts], 13), 0.0135, "M_Rope"))
|
|
P.append(sphere("rknot", 0.021, tuple(S.p(90 - sx * 143, 0.465, 0.034)), seg=8, rings=5, m="M_Rope"))
|
|
# small brass lantern clipped to the strap
|
|
lc = S.p(-90 + 49, 0.47, 0.062) + Vector((0.012, -0.018, 0))
|
|
L = Matrix.Translation(lc)
|
|
P.append(lathe("lbase", [(0.0, -0.05), (0.032, -0.05), (0.038, -0.042), (0.032, -0.03), (0.028, -0.026)], segs=12, m="M_Brass", frame=L, smooth_ang=40))
|
|
P.append(lathe("ltop", [(0.028, 0.026), (0.034, 0.03), (0.036, 0.038), (0.02, 0.054), (0.012, 0.066), (0.0, 0.07)], segs=12, m="M_Brass", frame=L, smooth_ang=40))
|
|
for k in range(4):
|
|
a = DEG(45 + 90 * k)
|
|
P.append(cyl("lrod", 0.0042, 0.06, lc + Vector((0.032 * math.cos(a), 0.032 * math.sin(a), 0)), verts=6, m="M_Brass"))
|
|
ring_on(P, lc + Vector((0, 0, 0.082)), (0, 1, 0), 0.016, 0.0045, m="M_Navy", seg=10)
|
|
P.append(ptube("hook", [tuple(lc + Vector((0, 0, 0.096))), tuple(lc + Vector((-0.012, 0.018, 0.116)))], 0.0058, "M_Leather"))
|
|
lamp = lathe("Lamp", [(0.0, -0.03), (0.024, -0.03), (0.029, -0.012), (0.029, 0.012), (0.024, 0.03), (0.0, 0.03)], segs=12, m="M_Emissive", frame=L, smooth_ang=50)
|
|
bp = done(P, "Backpack", uv=4.0, ang=50)
|
|
set_origin(fill, (0, 0.57, wz0))
|
|
uv_box(fill, 3.0)
|
|
return bp, fill, lamp, lc
|
|
|
|
|
|
def work_boot(name, sx):
|
|
"""Chunky brown leather boot on a dark sole, denim turn-up above. Same footprint and height as the old boot."""
|
|
P = []
|
|
cx, cy = sx * 0.145, 0.012
|
|
P.append(loft("sole", [(cx, cy, 0, 0, 0.0), (cx, cy, 0.112, 0.142, 0.0, 3.0), (cx, cy, 0.124, 0.156, 0.008, 3.0), (cx, cy, 0.126, 0.158, 0.03, 3.0), (cx, cy, 0.121, 0.152, 0.042, 3.0)],
|
|
segs=24, m="M_Rubber", cap1=True, smooth_ang=45))
|
|
P.append(loft("welt", [(cx, cy, 0.127, 0.159, 0.03, 3.0), (cx, cy, 0.13, 0.162, 0.036, 3.0), (cx, cy, 0.128, 0.16, 0.046, 3.0), (cx, cy, 0.118, 0.148, 0.052, 3.0)],
|
|
segs=24, m="M_Timber", cap0=False, cap1=False, smooth_ang=50))
|
|
up = [(cx, cy - 0.002, 0.118, 0.148, 0.04, 2.8), (cx, cy - 0.004, 0.12, 0.15, 0.072, 2.6), (cx, cy + 0.006, 0.114, 0.138, 0.112, 2.4), (cx, cy + 0.02, 0.102, 0.114, 0.146, 2.2),
|
|
(cx, cy + 0.03, 0.096, 0.1, 0.176, 2.1), (cx, cy + 0.03, 0.096, 0.1, 0.21, 2.1)]
|
|
P.append(loft("upper", up, segs=24, m="M_Leather", cap0=False, cap1=True, smooth_ang=60))
|
|
# laces up the front
|
|
for k in range(4):
|
|
z = 0.112 + k * 0.024
|
|
y = cy - 0.096 + k * 0.012
|
|
P.append(bar("lace", (cx - 0.03, y, z), (cx + 0.03, y, z), 0.0072, "M_Rope", verts=5))
|
|
# denim turn-up where the overalls leg ends
|
|
P.append(lathe("turnup", [(0.095, 0.2), (0.106, 0.205), (0.11, 0.222), (0.106, 0.238), (0.09, 0.242)], segs=22, m="M_Denim", frame=Matrix.Translation((cx, cy + 0.03, 0)), smooth_ang=60))
|
|
P.append(lathe("turnst", [(0.1115, 0.21), (0.1125, 0.212), (0.1125, 0.2155), (0.1115, 0.218)], segs=22, m="M_PaintYellow", frame=Matrix.Translation((cx, cy + 0.03, 0)), smooth_ang=60))
|
|
return done(P, name, uv=4.0, ang=50)
|
|
|
|
|
|
def crew():
|
|
body = OC.load_creature()
|
|
S = OC.BodySurf(body)
|
|
ctr = Vector((0, 0.03, 0.885))
|
|
tilt = Matrix.Translation(ctr) @ Matrix.Rotation(DEG(-11), 4, "X")
|
|
vest = crew_kerchief(S, tilt)
|
|
hat = crew_hat(S, tilt)
|
|
bp, fill, lamp, lc = crew_gear(S)
|
|
bl = work_boot("Boot_L", 1)
|
|
br = work_boot("Boot_R", -1)
|
|
dress_body(body)
|
|
sc = Matrix.Scale(OC.CREW_H, 4)
|
|
for o in (body, vest, hat, lamp, bp, fill, bl, br):
|
|
o.data.transform(sc @ o.matrix_world)
|
|
o.matrix_world = Matrix.Identity(4)
|
|
set_origin(fill, sc @ Vector((0, 0.57, 0.433)))
|
|
set_origin(lamp, sc @ lc)
|
|
G = dict(body=body, vest=vest, helmet=hat, lamp=lamp, backpack=bp, fill=fill, boot_l=bl, boot_r=br)
|
|
rig = OC.crew_rig(G)
|
|
puff_body(body, OC.CREW_H)
|
|
OC.pose(rig, {})
|
|
return dict(elev=12, azim=-30, dist_mul=0.8, rigged=rig,
|
|
extra=[("pose", dict(elev=10, azim=-55), {"Leg_L": (DEG(30), 0, 0), "Leg_R": (DEG(-30), 0, 0), "Arm_L": (DEG(-30), 0, 0), "Arm_R": (DEG(35), 0, 0), "Body": (0, DEG(6), 0)}),
|
|
("back", dict(elev=15, azim=150), {}),
|
|
("side", dict(elev=8, azim=-90), {}),
|
|
("aim", dict(elev=8, azim=-50), {"Arm_R": (DEG(-80), 0, 0)})])
|
|
|
|
|
|
# ======================================================================= runner
|
|
|
|
BUILDERS = {
|
|
"SM_Tool_HandPump": tool_handpump,
|
|
"SM_Tool_SlurpGun": tool_slurpgun,
|
|
"SM_Tool_HydroCannon": tool_hydrocannon,
|
|
"SM_Tool_MegaSiphon": tool_megasiphon,
|
|
"SM_Glove_R": glove_r,
|
|
"SM_Glove_L": glove_l,
|
|
"SM_Crew": crew,
|
|
"SM_Gadget_Tablet": gadget_tablet,
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
for nm in (args or list(BUILDERS)):
|
|
reset()
|
|
random.seed(hash(nm) & 0xffff)
|
|
r = BUILDERS[nm]() or {}
|
|
OC.finish_x(nm, r)
|