Files
grass-cutters/ArtSource/Blender/scripts/os_crew.py
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
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>
2026-11-06 18:44:40 +06:00

1317 lines
65 KiB
Python

"""GRASS CUTTER - crew character, first-person gloves and suction tools.
Assets: SM_Crew (rigged creature + GreenHaul work outfit), SM_Glove_R, SM_Glove_L,
SM_Tool_HandPump, SM_Tool_SlurpGun, SM_Tool_HydroCannon, SM_Tool_MegaSiphon.
Blender coords: meters, Z-up, front = -Y (Unity +Z). Character's left = Blender +X.
Run (from project root):
blender -b --factory-startup --python ArtSource/Blender/scripts/os_crew.py -- [names]
Source creature: ArtSource/Blender/source/Creature_src.fbx (texture -> Assets/Art/Textures/T_CrewBody.png).
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from common import *
from mathutils.bvhtree import BVHTree
SRC_FBX = os.path.join(ROOT, "ArtSource", "Blender", "source", "Creature_src.fbx")
CREW_H = 1.30 # final height of the creature (source is 1.0)
HIP = 0.0 # metres of extra leg: everything from the hips up stands this much higher
DEG = math.radians
# ======================================================================= generic geometry helpers
def M_fwd(loc=(0, 0, 0)):
"""Local frame whose +Z points forward (Blender -Y), local +Y = up."""
return Matrix.Translation(Vector(loc)) @ Matrix.Rotation(DEG(90), 4, "X")
def M_axis(axis, loc=(0, 0, 0)):
"""Local +Z -> given world axis ('X','-X','Y','-Y','Z','-Z')."""
r = {"Z": Matrix.Identity(4), "-Z": Matrix.Rotation(DEG(180), 4, "X"),
"-Y": Matrix.Rotation(DEG(90), 4, "X"), "Y": Matrix.Rotation(DEG(-90), 4, "X"),
"X": Matrix.Rotation(DEG(90), 4, "Y"), "-X": Matrix.Rotation(DEG(-90), 4, "Y")}[axis]
return Matrix.Translation(Vector(loc)) @ r
def sup_pts(rx, ry, n, segs, a0=0.0):
pts = []
for i in range(segs):
t = a0 + 2 * math.pi * i / segs
c, s = math.cos(t), math.sin(t)
pts.append((rx * math.copysign(abs(c) ** (2.0 / n), c), ry * math.copysign(abs(s) ** (2.0 / n), s)))
return pts
def _bridge(bm, R, segs):
for a, b in zip(R, R[1:]):
if len(a) == 1 and len(b) == 1:
continue
if len(a) == 1:
for i in range(segs):
bm.faces.new((a[0], b[i], b[(i + 1) % segs]))
elif len(b) == 1:
for i in range(segs):
bm.faces.new((a[i], a[(i + 1) % segs], b[0]))
else:
for i in range(segs):
bm.faces.new((a[i], a[(i + 1) % segs], b[(i + 1) % segs], b[i]))
def loft(name, rings, segs=32, n=2.0, m=None, cap0=True, cap1=True, frame=None, smooth_ang=60):
"""rings: (cx, cy, rx, ry, z[, n]) bottom -> top in a local frame (rx<=0 -> pole).
Superellipse cross sections (n=2 circle, n>2 squarer). frame: 4x4 local->world."""
bm = bmesh.new()
R = []
for r in rings:
cx, cy, rx, ry, z = r[:5]
nn = r[5] if len(r) > 5 else n
if rx <= 1e-6:
R.append([bm.verts.new((cx, cy, z))])
else:
R.append([bm.verts.new((cx + x, cy + y, z)) for x, y in sup_pts(rx, ry, nn, segs)])
_bridge(bm, R, segs)
if cap0 and len(R[0]) > 1:
bm.faces.new(list(reversed(R[0])))
if cap1 and len(R[-1]) > 1:
bm.faces.new(R[-1])
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
if frame is not None:
bmesh.ops.transform(bm, matrix=frame, verts=bm.verts)
o = mesh_obj(name, bm)
if m:
set_mats(o, m)
smooth(o, smooth_ang)
return o
def lathe(name, prof, segs=32, m=None, frame=None, cap0=False, cap1=False, smooth_ang=50, n=2.0, sx=1.0):
"""prof: [(r, z)] along local Z. Poles where r == 0."""
return loft(name, [(0, 0, r * sx, r, z, n) for r, z in prof], segs=segs, m=m, cap0=cap0, cap1=cap1,
frame=frame, smooth_ang=smooth_ang)
def revolve_fn(name, segs, fn, m=None, frame=None, smooth_ang=50):
"""fn(angle_rad) -> [(r, z)] (same length for all angles). Closed around, profile ends open."""
bm = bmesh.new()
cols = []
for i in range(segs):
a = 2 * math.pi * i / segs
cols.append([bm.verts.new((r * math.cos(a), r * math.sin(a), z)) for r, z in fn(a)])
k = len(cols[0])
for i in range(segs):
A, Bc = cols[i], cols[(i + 1) % segs]
for j in range(k - 1):
bm.faces.new((A[j], Bc[j], Bc[j + 1], A[j + 1]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
if frame is not None:
bmesh.ops.transform(bm, matrix=frame, verts=bm.verts)
o = mesh_obj(name, bm)
if m:
set_mats(o, m)
smooth(o, smooth_ang)
return o
def prism(name, pts, depth, frame, m, bevel=0.0, segs=2):
"""2D polygon (x, y) extruded along local +Z from 0..depth, placed by frame."""
bm = bmesh.new()
f0 = [bm.verts.new((x, y, 0)) for x, y in pts]
f1 = [bm.verts.new((x, y, depth)) for x, y in pts]
caps = [bm.faces.new(list(reversed(f0))), bm.faces.new(f1)]
n = len(pts)
for i in range(n):
j = (i + 1) % n
bm.faces.new((f0[i], f0[j], f1[j], f1[i]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
if n > 4:
bmesh.ops.triangulate(bm, faces=caps)
bmesh.ops.transform(bm, matrix=frame, verts=bm.verts)
o = mesh_obj(name, bm)
set_mats(o, m)
if bevel > 0:
b = o.modifiers.new("bev", "BEVEL")
b.width = bevel
b.segments = segs
b.limit_method = "ANGLE"
b.angle_limit = DEG(30)
bake(o)
smooth(o, 35)
return o
def ring_prism(name, outer, inner, depth, frame, m, bevel=0.0):
"""Flat frame between two outlines with equal point counts, extruded along local +Z."""
bm = bmesh.new()
n = len(outer)
o0 = [bm.verts.new((x, y, 0)) for x, y in outer]
o1 = [bm.verts.new((x, y, depth)) for x, y in outer]
i0 = [bm.verts.new((x, y, 0)) for x, y in inner]
i1 = [bm.verts.new((x, y, depth)) for x, y in inner]
for k in range(n):
j = (k + 1) % n
bm.faces.new((o0[k], o0[j], o1[j], o1[k]))
bm.faces.new((i0[j], i0[k], i1[k], i1[j]))
bm.faces.new((o1[k], o1[j], i1[j], i1[k]))
bm.faces.new((o0[j], o0[k], i0[k], i0[j]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
bmesh.ops.transform(bm, matrix=frame, verts=bm.verts)
o = mesh_obj(name, bm)
set_mats(o, m)
if bevel > 0:
b = o.modifiers.new("bev", "BEVEL")
b.width = bevel
b.segments = 2
b.limit_method = "ANGLE"
b.angle_limit = DEG(50)
bake(o)
smooth(o, 35)
return o
def rrect_pts(w, h, r, n=4):
r = min(r, w / 2 - 1e-4, h / 2 - 1e-4)
pts = []
for cx, cy, a0 in ((w / 2 - r, h / 2 - r, 0), (-w / 2 + r, h / 2 - r, 90), (-w / 2 + r, -h / 2 + r, 180), (w / 2 - r, -h / 2 + r, 270)):
for i in range(n + 1):
a = DEG(a0 + 90 * i / n)
pts.append((cx + r * math.cos(a), cy + r * math.sin(a)))
return pts
def drop_pts(r, n=14):
"""Water-drop outline, round bottom at (0,0), tip at (0, 2.1r)."""
pts = [(r * math.cos(DEG(a)), r * math.sin(DEG(a))) for a in [30 - 240 * i / n for i in range(n + 1)]]
pts.append((0.0, 2.1 * r))
return pts
def catmull(pts, per=8):
P = [Vector(p) for p in pts]
P = [P[0] * 2 - P[1]] + P + [P[-1] * 2 - P[-2]]
out = []
for i in range(1, len(P) - 2):
p0, p1, p2, p3 = P[i - 1], P[i], P[i + 1], P[i + 2]
for k in range(per):
t = k / per
t2, t3 = t * t, t * t * t
out.append(0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3))
out.append(P[-2])
return out
def sweep_circle(name, pts, rfun, segs=10, per=8, m=None, cap=True, smooth_ang=70, step=None):
"""Tube along a catmull-rom path; rfun(s01, arclen) -> radius. Parallel-transport frames.
step: resample the path at this arc-length spacing (rings land exactly on corrugation peaks/valleys)."""
C = catmull(pts, per)
L = [0.0]
for a, b in zip(C, C[1:]):
L.append(L[-1] + (b - a).length)
if step:
tot = L[-1]
n = max(2, int(round(tot / step)))
C2, j = [], 0
for i in range(n + 1):
t = tot * i / n
while j < len(L) - 2 and L[j + 1] < t:
j += 1
f = (t - L[j]) / max(1e-9, L[j + 1] - L[j])
C2.append(C[j].lerp(C[j + 1], min(1.0, max(0.0, f))))
C = C2
L = [tot * i / n for i in range(n + 1)]
tot = L[-1]
T = [(C[min(i + 1, len(C) - 1)] - C[max(i - 1, 0)]).normalized() for i in range(len(C))]
up = Vector((0, 0, 1)) if abs(T[0].z) < 0.9 else Vector((1, 0, 0))
N = (up - T[0] * up.dot(T[0])).normalized()
bm = bmesh.new()
R = []
for i, c in enumerate(C):
if i > 0:
N = (N - T[i] * N.dot(T[i])).normalized()
Bn = T[i].cross(N)
r = rfun(L[i] / tot, L[i])
R.append([bm.verts.new(c + (N * math.cos(2 * math.pi * k / segs) + Bn * math.sin(2 * math.pi * k / segs)) * r) for k in range(segs)])
_bridge(bm, R, segs)
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)
if m:
set_mats(o, m)
smooth(o, smooth_ang)
return o
def hose(name, pts, r, m="M_DarkGrey", rib=0.022, depth=0.16, segs=10, per=10):
"""Corrugated hose: rings alternate crest / groove every half rib, with flat cuffs at both ends."""
def rf(s, l):
k = int(round(l / (rib / 2)))
return r * (1.0 if k % 2 == 0 else 1.0 - depth)
return sweep_circle(name, pts, rf, segs=segs, per=12, m=m, step=rib / 2, smooth_ang=80)
def grid_slab(name, fn, nu, nv, t_out, t_in, m, smooth_ang=50):
"""Closed slab over a parametric patch fn(u, v, off) -> Vector, u, v in [0, 1]."""
bm = bmesh.new()
top = [[bm.verts.new(fn(i / nu, j / nv, t_out)) for j in range(nv + 1)] for i in range(nu + 1)]
bot = [[bm.verts.new(fn(i / nu, j / nv, t_in)) for j in range(nv + 1)] for i in range(nu + 1)]
for i in range(nu):
for j in range(nv):
bm.faces.new((top[i][j], top[i + 1][j], top[i + 1][j + 1], top[i][j + 1]))
bm.faces.new((bot[i][j], bot[i][j + 1], bot[i + 1][j + 1], bot[i + 1][j]))
loop = [(i, 0) for i in range(nu)] + [(nu, j) for j in range(nv)] + [(i, nv) for i in range(nu, 0, -1)] + [(0, j) for j in range(nv, 0, -1)]
for p, q in zip(loop, loop[1:] + loop[:1]):
bm.faces.new((top[p[0]][p[1]], bot[p[0]][p[1]], bot[q[0]][q[1]], top[q[0]][q[1]]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
o = mesh_obj(name, bm)
set_mats(o, m)
smooth(o, smooth_ang)
return o
def pillow(name, fn, nu, nv, m):
"""Puffy closed pad: fn(u, v, k) with k=1 outer (puffed) / k=0 inner; borders shared (stitched seam)."""
bm = bmesh.new()
top = [[bm.verts.new(fn(i / nu, j / nv, 1)) for j in range(nv + 1)] for i in range(nu + 1)]
bot = [[top[i][j] if (i in (0, nu) or j in (0, nv)) else bm.verts.new(fn(i / nu, j / nv, 0))
for j in range(nv + 1)] for i in range(nu + 1)]
for i in range(nu):
for j in range(nv):
bm.faces.new((top[i][j], top[i + 1][j], top[i + 1][j + 1], top[i][j + 1]))
bm.faces.new((bot[i][j], bot[i][j + 1], bot[i + 1][j + 1], bot[i + 1][j]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
o = mesh_obj(name, bm)
set_mats(o, m)
smooth(o, 80)
return o
def bolt(P, loc, normal, r=0.008, h=0.006, m="M_Steel", hexa=True):
n = Vector(normal).normalized()
q = Vector((0, 0, 1)).rotation_difference(n)
fr = Matrix.Translation(Vector(loc)) @ q.to_matrix().to_4x4()
o = lathe("bolt", [(r, -h * 0.3), (r, h * 0.55), (r * 0.8, h), (0, h * 1.05)], segs=6 if hexa else 10, m=m, frame=fr,
cap0=True, smooth_ang=30)
P.append(o)
return o
def flat_shade_cap(o):
return o
def fin(P, name, uv=2.0, ang=40):
if os.environ.get("TRIDBG"):
agg = {}
for q in P:
if q is not None:
k = q.name.split(".")[0]
agg[k] = agg.get(k, 0) + sum(len(f.vertices) - 2 for f in q.data.polygons)
print("TRIDBG", name, sorted(agg.items(), key=lambda kv: -kv[1]))
o = join(P, name)
uv_box(o, uv)
smooth(o, ang)
return o
def place(o, mat4):
o.data.transform(mat4)
return o
# ======================================================================= SM_Crew
class BodySurf:
"""Ray-cast access to the creature's torso surface (main island only)."""
def __init__(self, obj, cy=0.03):
bm = bmesh.new()
bm.from_mesh(obj.data)
bm.verts.ensure_lookup_table()
top = max(bm.verts, key=lambda v: v.co.z)
keep = {top.index}
st = [top]
while st:
x = st.pop()
for e in x.link_edges:
w = e.other_vert(x)
if w.index not in keep:
keep.add(w.index)
st.append(w)
bmesh.ops.delete(bm, geom=[v for v in bm.verts if v.index not in keep], context="VERTS")
self.bvh = BVHTree.FromBMesh(bm)
bm.free()
self.cy = cy
def r(self, a, z):
d = Vector((math.cos(DEG(a)), math.sin(DEG(a)), 0))
hit = self.bvh.ray_cast(Vector((0, self.cy, z)), d, 2.0)
return (hit[0] - Vector((0, self.cy, z))).length if hit[0] is not None else 0.25
def p(self, a, z, off=0.0):
d = Vector((math.cos(DEG(a)), math.sin(DEG(a)), 0))
return Vector((0, self.cy, z)) + d * (self.r(a, z) + off)
def islands(me):
bm = bmesh.new()
bm.from_mesh(me)
bm.verts.ensure_lookup_table()
seen = set()
out = []
for v in bm.verts:
if v.index in seen:
continue
isl = [v.index]
seen.add(v.index)
st = [v]
while st:
x = st.pop()
for e in x.link_edges:
w = e.other_vert(x)
if w.index not in seen:
seen.add(w.index)
st.append(w)
isl.append(w.index)
out.append(isl)
bm.free()
return out
def smoothstep(e0, e1, x):
t = max(0.0, min(1.0, (x - e0) / (e1 - e0)))
return t * t * (3 - 2 * t)
def crew_vest(S):
"""Padded GreenHaul work/life vest around the lower torso. Source units (1.0 tall)."""
P = []
GAP = 0.012
def pad(name, a0, a1, z0, z1, t, mat_="M_CrewVest", nu=14, nv=9, zfront=None):
def fn(u, v, k):
a = a0 + (a1 - a0) * u
top = z1 if zfront is None else zfront(a)
z = z0 + (top - z0) * v
f = t * (math.sin(math.pi * u) ** 0.32) * (math.sin(math.pi * v) ** 0.32)
return S.p(a, z, GAP + f * k)
P.append(pillow(name, fn, nu, nv, mat_))
return fn
# front pads (left/right of the zip) with a gentle V neckline, back pad taller
neck = lambda a: 0.585 - 0.03 * math.cos(DEG(a + 90)) ** 6
fR = pad("padR", -86, -18, 0.255, 0.585, 0.052, zfront=lambda a: 0.555 + 0.03 * smoothstep(-86, -40, a))
fL = pad("padL", -162, -94, 0.255, 0.585, 0.052, zfront=lambda a: 0.555 + 0.03 * (1 - smoothstep(-140, -94, a)))
fB = pad("padB", 18, 162, 0.255, 0.70, 0.045, nu=20, nv=10)
# side gussets hidden behind the arms (keep the vest reading as one piece)
for a0, a1 in ((-20, 20), (160, 200)):
pad("gus", a0, a1, 0.27, 0.5, 0.02, nu=6, nv=6)
# reflective strips across each front pad and the back pad
def strip(fn, u0, u1, v0, v1, nu=12):
P.append(grid_slab("refl", lambda u, v, off: _on(fn, u0 + (u1 - u0) * u, v0 + (v1 - v0) * v, off), nu, 1, 0.005, -0.006,
"M_Reflective", smooth_ang=60))
def _on(fn, u, v, off):
p = fn(u, v, 1)
c = Vector((0, S.cy, p.z))
return p + (p - c).normalized() * off
for fn in (fR, fL):
strip(fn, 0.06, 0.94, 0.20, 0.30)
strip(fn, 0.06, 0.94, 0.52, 0.62)
strip(fB, 0.04, 0.96, 0.20, 0.27, nu=20)
# zip strip + pull
zp = lambda u, v, off: S.p(-90 + (v - 0.5) * 7.0, 0.25 + 0.31 * u, GAP + 0.012 + off)
P.append(grid_slab("zip", zp, 8, 1, 0.006, -0.01, "M_DarkGrey"))
pz = S.p(-90, 0.53, GAP + 0.03)
P.append(rbox("pull", (0.018, 0.008, 0.034), (pz.x, pz.y, pz.z - 0.01), bevel=0.004, segs=1, m="M_Teal"))
# waist belt (webbing) + front buckles
belt = lambda u, v, off: S.p(-178 + 356 * u, 0.25 + 0.035 * v, GAP + 0.016 + off)
P.append(grid_slab("belt", belt, 48, 1, 0.006, -0.004, "M_DarkGrey"))
for a in (-62, -118):
b = S.p(a, 0.2675, GAP + 0.03)
n = (b - Vector((0, S.cy, b.z))).normalized()
q = Vector((0, 0, 1)).rotation_difference(n)
fr = Matrix.Translation(b) @ q.to_matrix().to_4x4()
P.append(prism("buckle", rrect_pts(0.05, 0.042, 0.01, 2), 0.012, fr @ Matrix.Translation((0, 0, -0.006)), "M_Teal", bevel=0.003, segs=1))
P.append(prism("buckle2", rrect_pts(0.03, 0.022, 0.006, 2), 0.006, fr @ Matrix.Translation((0, 0, 0.005)), "M_Steel"))
# chest badge (left chest = Blender +X... character's left is +X; badge on its left chest)
b = fR(0.62, 0.78, 1)
c = Vector((0, S.cy, b.z))
n = (b - c).normalized()
q = Vector((0, 0, 1)).rotation_difference(n)
# keep badge upright: rotate around n so local Y ~ world Z
fr = Matrix.Translation(b + n * 0.002) @ q.to_matrix().to_4x4()
ly = fr.to_3x3() @ Vector((0, 1, 0))
tgt = (Vector((0, 0, 1)) - n * n.z).normalized()
ang = ly.angle(tgt) * (1 if ly.cross(tgt).dot(n) > 0 else -1)
fr = fr @ Matrix.Rotation(ang, 4, "Z")
P.append(prism("badge", rrect_pts(0.075, 0.062, 0.02, 3), 0.008, fr @ Matrix.Translation((0, 0, -0.004)), "M_HullWhite", bevel=0.003, segs=1))
P.append(prism("badgeR", rrect_pts(0.075, 0.012, 0.005), 0.004, fr @ Matrix.Translation((0, -0.02, 0.004)), "M_Teal"))
P.append(prism("drop", [(x, y - 0.016) for x, y in drop_pts(0.011)], 0.004, fr @ Matrix.Translation((0, 0.0, 0.004)), "M_Teal"))
v = fin(P, "Vest", uv=3.0, ang=60)
return v
def crew_helmet(S):
P = []
ctr = Vector((0, 0.03, 0.885))
tilt = Matrix.Translation(ctr) @ Matrix.Rotation(DEG(-11), 4, "X")
shell = [(0.226, -0.012), (0.232, 0.02), (0.232, 0.06), (0.228, 0.10), (0.205, 0.142), (0.17, 0.178), (0.12, 0.203),
(0.062, 0.216), (0.0, 0.219)]
P.append(lathe("shell", shell, segs=32, m="M_HullWhite", frame=tilt, cap0=True, smooth_ang=70))
# brim with a forward peak, rounded lip
def brim(a):
s = math.sin(a)
R = 0.255 + 0.07 * max(0.0, -s) ** 2.2
return [(0.2, -0.004), (R - 0.012, -0.018), (R, -0.006), (R - 0.004, 0.006), (R - 0.03, 0.014), (0.2, 0.02)]
P.append(revolve_fn("brim", 40, brim, m="M_HullWhite", frame=tilt @ Matrix.Translation((0, 0, -0.005)), smooth_ang=60))
# orange stripe band
P.append(lathe("stripe", [(0.2345, 0.024), (0.2375, 0.03), (0.2365, 0.058), (0.23, 0.064)], segs=32, m="M_PaintOrange",
frame=tilt, smooth_ang=60))
# three crest ribs over the top (front -> back)
def shell_r(z):
for (r0, z0), (r1, z1) in zip(shell, shell[1:]):
if z0 <= z <= z1:
return r0 + (r1 - r0) * (z - z0) / (z1 - z0)
return 0.0
for xo, rr in ((0.0, 0.016), (-0.085, 0.011), (0.085, 0.011)):
prof =[(r, z) for r, z in shell if r > abs(xo) + 0.02 and z > 0.07]
pts = []
for r, z in prof:
pts.append((xo, -math.sqrt(r * r - xo * xo), z))
pts.append((xo, 0.0, shell_r(0.216) * 0 + 0.219 - (0.012 if xo else 0) + 0.0))
for r, z in reversed(prof):
pts.append((xo, math.sqrt(r * r - xo * xo), z))
pts = [Vector(p) for p in pts]
# push outward along the profile normal a little
pts2 = []
for p in pts:
d = Vector((p.x * 0.3, p.y, (p.z - 0.04) * 1.2)).normalized()
pts2.append(p + d * rr * (0.55 if xo == 0 else 0.3))
o = sweep_circle("rib", pts2, lambda s, l, rr=rr: rr * (0.55 + 0.45 * math.sin(math.pi * s) ** 0.3), segs=8, per=2,
m="M_HullWhite" if xo else "M_PaintOrange")
o.data.transform(tilt)
P.append(o)
# headlamp housing + strap clip on the front of the crown
hz = 0.095
hy = -shell_r(hz)
hfr = tilt @ Matrix.Translation((0, hy - 0.006, hz)) @ Matrix.Rotation(DEG(-8), 4, "X")
P.append(prism("lampplate", rrect_pts(0.12, 0.07, 0.025, 3), 0.016, hfr @ M_fwd((0, 0, 0)), "M_DarkGrey", bevel=0.004, segs=1))
hous = lathe("lamphous", [(0.0, 0.0), (0.046, 0.0), (0.05, 0.012), (0.05, 0.034), (0.046, 0.042), (0.038, 0.044)],
segs=24, m="M_Teal", frame=hfr @ M_fwd() @ Matrix.Translation((0, 0, 0.012)), smooth_ang=40)
P.append(hous)
P.append(lathe("lampbezel", [(0.04, 0.04), (0.044, 0.046), (0.036, 0.05), (0.03, 0.047)], segs=24, m="M_Steel",
frame=hfr @ M_fwd() @ Matrix.Translation((0, 0, 0.012)), smooth_ang=40))
lamp = lathe("Lamp", [(0.039, 0.0), (0.039, 0.006), (0.033, 0.013), (0.018, 0.017), (0.0, 0.018)], segs=24,
m="M_Emissive", frame=hfr @ M_fwd() @ Matrix.Translation((0, 0, 0.05)), cap0=True)
# GreenHaul side badges
for sx in (1, -1):
bz = 0.085
br = shell_r(bz)
q = Vector((0, 0, 1)).rotation_difference(Vector((sx, 0, 0)))
fr = tilt @ Matrix.Translation((sx * (br - 0.004), 0.0, bz)) @ q.to_matrix().to_4x4()
# keep drop tip pointing up: local y -> world z
ly = fr.to_3x3() @ Vector((0, 1, 0))
fr = fr @ Matrix.Rotation(ly.angle(Vector((0, 0, 1))) * (-1 if sx > 0 else 1), 4, "Z")
P.append(lathe("hbadge", [(0.0, 0.0), (0.042, 0.0), (0.045, 0.006), (0.04, 0.011), (0.0, 0.011)], segs=24,
m="M_Teal", frame=fr, smooth_ang=40))
P.append(prism("hdrop", [(x, y - 0.02) for x, y in drop_pts(0.014)], 0.004, fr @ Matrix.Translation((0, 0, 0.009)),
"M_HullWhite"))
h = fin(P, "Helmet", uv=3.0, ang=50)
uv_box(lamp, 4.0)
return h, lamp, tilt
def crew_backpack(S):
P = []
cx, cy = 0.0, 0.455
z0, z1 = 0.33, 0.86
rx, ry = 0.175, 0.105
def ring(z, s=1.0, n=3.2):
return (cx, cy, rx * s, ry * s, z, n)
rings = [(cx, cy, 0, 0, z0 - 0.004), ring(z0, 0.86), ring(z0 + 0.012, 0.95), ring(z0 + 0.035, 1.0),
ring(z1 - 0.035, 1.0), ring(z1 - 0.012, 0.95), ring(z1, 0.86), (cx, cy, 0, 0, z1 + 0.004)]
tank = loft("tank", rings, segs=32, m="M_HullWhite", smooth_ang=55)
P.append(tank)
# teal side shells (the two sides) - bands wrapping the tank sides
for sx in (1, -1):
def side(u, v, off, sx=sx):
# u: around the side from front(-) to back(+), v: height
t = DEG(-70 + 140 * u)
ex, ey = sup_pts(1, 1, 3.2, 1, 0)[0]
c, s = math.cos(t), math.sin(t)
x = rx * math.copysign(abs(c) ** (2 / 3.2), c)
y = ry * math.copysign(abs(s) ** (2 / 3.2), s)
nrm = Vector((x / rx ** 2, y / ry ** 2, 0)).normalized()
z = z0 + 0.06 + (z1 - z0 - 0.12) * v
return Vector((cx + sx * x, cy + y, z)) + Vector((sx * nrm.x, nrm.y, 0)) * off
P.append(grid_slab("side", side, 12, 4, 0.012, -0.004, "M_Teal", smooth_ang=60))
# rubber bumper caps top and bottom
for zc, d in ((z0 + 0.02, -1), (z1 - 0.02, 1)):
P.append(loft("bump", [(cx, cy, rx * 1.02, ry * 1.06, zc - 0.02, 3.2), (cx, cy, rx * 1.05, ry * 1.1, zc - 0.008, 3.2),
(cx, cy, rx * 1.05, ry * 1.1, zc + 0.008, 3.2), (cx, cy, rx * 1.02, ry * 1.06, zc + 0.02, 3.2)],
segs=32, m="M_Rubber", cap0=False, cap1=False, smooth_ang=60))
# orange stripe across the back face
yb = cy + ry
# window frame on the back face (+Y side), vertical strip
wz0, wz1, ww = 0.43, 0.77, 0.07
frb = Matrix.Translation((0, yb - 0.004, 0)) @ Matrix.Rotation(DEG(-90), 4, "X") # local Z -> +Y (out of the back)
wc = (wz0 + wz1) / 2
fr = frb @ Matrix.Translation((0, -0, 0))
# local frame: x -> X, y -> -Z? Rotation(-90,X): y -> (0,0,-1)? build explicit instead
F = Matrix(((1, 0, 0, 0), (0, 0, 1, yb - 0.004), (0, 1, 0, 0), (0, 0, 0, 1))) # local x->X, y->Z, z->+Y
outer = rrect_pts(ww + 0.05, wz1 - wz0 + 0.05, 0.04, 5)
P.append(ring_prism("wframe", [(x, y + wc) for x, y in outer], [(x, y + wc) for x, y in rrect_pts(ww, wz1 - wz0, 0.03, 5)],
0.03, F, "M_DarkGrey", bevel=0.005))
glass = prism("glass", [(x, y + wc) for x, y in rrect_pts(ww, wz1 - wz0, 0.03, 5)], 0.006, F @ Matrix.Translation((0, 0, 0.026)),
"M_Glass")
P.append(glass)
back = prism("wback", [(x, y + wc) for x, y in rrect_pts(ww + 0.004, wz1 - wz0 + 0.004, 0.03, 5)], 0.002,
F @ Matrix.Translation((0, 0, 0.012)), "M_Navy")
P.append(back)
# level ticks beside the window
for k in range(5):
z = wz0 + 0.04 + k * (wz1 - wz0 - 0.08) / 4
P.append(rbox("tick", (0.022 if k % 2 == 0 else 0.014, 0.006, 0.007), (ww / 2 + 0.042, yb + 0.0, z), bevel=0.002,
segs=1, m="M_PaintOrange"))
# fill (inside window, between back plate and glass), origin at its bottom
fill = prism("TankFill", [(x, y + wc) for x, y in rrect_pts(ww - 0.006, wz1 - wz0 - 0.006, 0.027, 5)], 0.01,
F @ Matrix.Translation((0, 0, 0.014)), "M_WaterFill", bevel=0.0)
# top cap: screw cap + handle
P.append(lathe("cap", [(0.0, 0.0), (0.05, 0.0), (0.052, 0.012), (0.05, 0.03), (0.046, 0.034), (0.0, 0.036)], segs=20,
m="M_PaintOrange", frame=Matrix.Translation((0.07, cy + 0.01, z1 - 0.004)), smooth_ang=40))
P.append(revolve_fn("knurl", 40, lambda a: [(0.05, 0.004), (0.053 + 0.004 * (math.cos(10 * a) > 0), 0.01),
(0.053 + 0.004 * (math.cos(10 * a) > 0), 0.026), (0.047, 0.032)],
m="M_PaintOrange", frame=Matrix.Translation((0.07, cy + 0.01, z1 - 0.004)), smooth_ang=30))
P.append(sweep_circle("handle", [(-0.12, cy, z1 - 0.01), (-0.11, cy, z1 + 0.045), (-0.03, cy, z1 + 0.055), (0.0, cy, z1 - 0.01)],
lambda s, l: 0.012, segs=8, per=4, m="M_DarkGrey"))
# side hose loop (corrugated) from bottom valve to top
P.append(hose("hose", [(-0.19, cy - 0.03, z0 + 0.06), (-0.235, cy + 0.0, z0 + 0.2), (-0.23, cy + 0.02, z1 - 0.2),
(-0.19, cy + 0.0, z1 - 0.07)], 0.019, m="M_DarkGrey", rib=0.016, segs=8, per=7))
for zz in (z0 + 0.06, z1 - 0.07):
P.append(cyl("valve", 0.026, 0.03, (-0.178, cy - 0.03 if zz < 0.5 else cy, zz), axis="X", verts=12, bevel=0.005, segs=1, m="M_Brass"))
# bolts on the bumper bands
for zz in (z0 + 0.02, z1 - 0.02):
for sx in (-1, 1):
bolt(P, (sx * 0.1, cy + ry * 1.1 + 0.0, zz), (0, 1, 0), r=0.008, h=0.008)
# mounting saddle against the vest + shoulder straps
P.append(loft("saddle", [(0, cy - ry - 0.02, 0.14, 0.035, z0 + 0.05, 3), (0, cy - ry - 0.02, 0.15, 0.04, z0 + 0.1, 3),
(0, cy - ry - 0.02, 0.15, 0.04, z1 - 0.1, 3), (0, cy - ry - 0.02, 0.14, 0.035, z1 - 0.05, 3)],
segs=24, m="M_DarkGrey"))
GAP = 0.016
def strap_fn(path, w):
# path: [(a_deg, z)] on the body surface; v across width
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.006 + 0.03 * (1 - math.sin(math.pi * u)) ** 2 + off)
return f, len(C)
for sx in (1, -1):
path = [(90 - sx * 52, 0.8), (90 - sx * 78, 0.7), (90 - sx * 98, 0.62), (90 - sx * 112, 0.58)]
f, nc = strap_fn(path, 0.058)
P.append(grid_slab("strap", f, nc, 1, 0.007, -0.006, "M_DarkGrey"))
e = f(1.0, 0.5, 0.01)
P.append(rbox("clip", (0.04, 0.03, 0.03), tuple(e), bevel=0.008, segs=1, m="M_Teal"))
bp = fin(P, "Backpack", uv=3.0, ang=50)
set_origin(fill, (0, yb - 0.004 + 0.014, wz0 + 0.003))
uv_box(fill, 4.0)
return bp, fill
def crew_boot(name, sx):
P = []
cx, cy = sx * 0.145, 0.012
sole = [(cx, cy, 0.112, 0.142, 0.0, 3.0), (cx, cy, 0.122, 0.152, 0.008, 3.0), (cx, cy, 0.124, 0.154, 0.03, 3.0),
(cx, cy, 0.12, 0.15, 0.04, 3.0)]
so = loft("sole", [(cx, cy, 0, 0, 0.0)] + sole, segs=32, m="M_PaintOrange", cap1=True, smooth_ang=45)
for v in so.data.vertices: # sole wraps up over the toe and heel (bumper cap)
if v.co.z > 0.02:
v.co.z += 0.045 * smoothstep(cy - 0.04, cy - 0.14, v.co.y) + 0.018 * smoothstep(cy + 0.08, cy + 0.15, v.co.y)
P.append(so)
# dark tread band around the sole
P.append(loft("tread", [(cx, cy, 0.123, 0.153, 0.004, 3.0), (cx, cy, 0.127, 0.157, 0.011, 3.0),
(cx, cy, 0.127, 0.157, 0.017, 3.0), (cx, cy, 0.124, 0.154, 0.022, 3.0)],
segs=32, m="M_Rubber", cap0=False, cap1=False, smooth_ang=50))
# tread grooves under the toe: dark ribs on the sole side
up = [(cx, cy - 0.002, 0.116, 0.146, 0.036, 2.8), (cx, cy - 0.004, 0.118, 0.148, 0.07, 2.6),
(cx, cy + 0.006, 0.112, 0.136, 0.11, 2.4), (cx, cy + 0.02, 0.1, 0.112, 0.145, 2.2),
(cx, cy + 0.03, 0.094, 0.098, 0.175, 2.1), (cx, cy + 0.03, 0.094, 0.098, 0.2, 2.1)]
P.append(loft("upper", up, segs=32, m="M_Rubber", cap0=False, cap1=True, smooth_ang=60))
# rolled cuff
P.append(torus("cuff", 0.096, 0.017, loc=(0, 0, 0), seg=28, rseg=8, m="M_PaintOrange"))
P[-1].data.transform(Matrix.Translation((cx, cy + 0.03, 0.2)) @ Matrix.Scale(1.0, 4))
# pull tab at the back + two rivets
P.append(rbox("tab", (0.04, 0.012, 0.05), (cx, cy + 0.03 + 0.1, 0.205), bevel=0.005, segs=1, m="M_PaintOrange"))
for s in (-1, 1):
bolt(P, (cx + s * 0.1, cy + 0.03, 0.15), (s, 0, 0), r=0.008, h=0.006, m="M_Steel")
return fin(P, name, uv=4.0, ang=50)
def load_creature():
bpy.ops.import_scene.fbx(filepath=SRC_FBX)
src = [o for o in bpy.context.scene.objects if o.type == "MESH"][0]
for o in list(bpy.context.scene.objects):
if o is not src:
bpy.data.objects.remove(o)
src.parent = None
apply_xform(src)
src.name = "CrewBody"
src.data.name = "CrewBody"
old = list(src.data.materials)
src.data.materials.clear()
src.data.materials.append(mat("M_CrewBody"))
for m in old:
if m and m.users == 0:
bpy.data.materials.remove(m)
if src.data.uv_layers:
src.data.uv_layers[0].name = "UVMap"
return src
def build_crew_geo():
body = load_creature()
S = BodySurf(body)
vest = crew_vest(S)
helmet, lamp, tilt = crew_helmet(S)
bp, fill = crew_backpack(S)
bl = crew_boot("Boot_L", 1)
br = crew_boot("Boot_R", -1)
objs = [body, vest, helmet, lamp, bp, fill, bl, br]
# scale everything from source units (1.0 tall) to CREW_H, pivots scale about the world origin
sc = Matrix.Scale(CREW_H, 4)
for o in objs:
o.data.transform(sc @ o.matrix_world)
o.matrix_world = Matrix.Identity(4)
set_origin(fill, sc @ Vector((0, 0.455 + 0.105 - 0.004 + 0.014, 0.43 + 0.003)))
vs = [v.co for v in lamp.data.vertices]
set_origin(lamp, sum(vs, Vector()) / len(vs))
return dict(body=body, vest=vest, helmet=helmet, lamp=lamp, backpack=bp, fill=fill, boot_l=bl, boot_r=br)
def crew_rig(G):
body = G["body"]
sc = CREW_H
# find arm islands -> shoulder/hand points
me = body.data
isl = islands(me)
arms = {}
for ix in isl:
pts = [me.vertices[i].co for i in ix]
xs = [p.x for p in pts]
mn, mx = min(xs), max(xs)
if len(ix) > 600 and (mn > 0.1 * sc or mx < -0.1 * sc):
side = "L" if mn > 0 else "R"
zt = max(p.z for p in pts)
zb = min(p.z for p in pts)
top = [p for p in pts if p.z > zt - 0.06 * sc]
bot = [p for p in pts if p.z < zb + 0.05 * sc]
sh = sum(top, Vector()) / len(top)
hd = sum(bot, Vector()) / len(bot)
arms[side] = (set(ix), Vector((sh.x * 0.92, sh.y, zt - 0.06 * sc)), hd)
rd = bpy.data.armatures.new("Rig")
rig = link(bpy.data.objects.new("Rig", rd))
bpy.context.view_layer.objects.active = rig
rig.select_set(True)
bpy.ops.object.mode_set(mode="EDIT")
eb = rd.edit_bones
def bone(name, h, t, parent=None):
b = eb.new(name)
b.head = Vector(h)
b.tail = Vector(t)
b.roll = 0.0
if parent:
b.parent = eb[parent]
b.use_connect = False
return b
bone("Root", (0, 0, 0), (0, 0.0, 0.18 * sc))
bone("Body", (0, 0.03 * sc, 0.5 * sc + HIP), (0, 0.03 * sc, 0.92 * sc + HIP), "Root")
for side, sx in (("L", 1), ("R", -1)):
bone("Leg_" + side, (sx * 0.145 * sc, 0.01 * sc, 0.21 * sc + HIP), (sx * 0.145 * sc, 0.01 * sc, 0.02 * sc), "Body")
_, sh, hd = arms[side]
bone("Arm_" + side, sh, (sh.x, sh.y, hd.z), "Body") # vertical -> clean X swing axis
bpy.ops.object.mode_set(mode="OBJECT")
rig.show_in_front = True
# ---- body weights (geometric; arms are separate islands, legs blend into the torso)
vg = {n: body.vertex_groups.new(name=n) for n in ("Body", "Leg_L", "Leg_R", "Arm_L", "Arm_R")}
armset = {"L": arms["L"][0], "R": arms["R"][0]}
for v in me.vertices:
i = v.index
p = v.co
if i in armset["L"]:
vg["Arm_L"].add([i], 1.0, "REPLACE"); continue
if i in armset["R"]:
vg["Arm_R"].add([i], 1.0, "REPLACE"); continue
wl = (1 - smoothstep(0.16 * sc, 0.27 * sc, p.z)) * smoothstep(0.004 * sc, 0.055 * sc, abs(p.x))
if wl > 0.001:
vg["Leg_L" if p.x > 0 else "Leg_R"].add([i], wl, "REPLACE")
if wl < 0.999:
vg["Body"].add([i], 1 - wl, "REPLACE")
def skin(o, bone_name):
o.vertex_groups.clear()
g = o.vertex_groups.new(name=bone_name)
g.add(list(range(len(o.data.vertices))), 1.0, "REPLACE")
o.parent = rig
o.parent_type = "OBJECT"
md = o.modifiers.new("Armature", "ARMATURE")
md.object = rig
for k, b in (("body", None), ("vest", "Body"), ("helmet", "Body"), ("backpack", "Body"), ("boot_l", "Leg_L"), ("boot_r", "Leg_R")):
o = G[k]
if b is None:
o.parent = rig
md = o.modifiers.new("Armature", "ARMATURE")
md.object = rig
else:
skin(o, b)
# TankFill + Lamp: rigid children of the Body bone (plain MeshRenderers in Unity, so TankFill's
# local Y scale and Lamp's transform follow the animated Body bone)
bpy.context.view_layer.update()
for k in ("fill", "lamp"):
o = G[k]
mw = o.matrix_world.copy()
o.parent = rig
o.parent_type = "BONE"
o.parent_bone = "Body"
bpy.context.view_layer.update()
o.matrix_world = mw
bpy.context.view_layer.update()
return rig
def export_rigged(name):
os.makedirs(MODELS, exist_ok=True)
path = os.path.join(MODELS, name + ".fbx")
for o in bpy.context.scene.objects:
o.select_set(o.type in ("MESH", "EMPTY", "ARMATURE") and not o.get("preview_only"))
bpy.ops.export_scene.fbx(filepath=path, use_selection=True, axis_forward="-Z", axis_up="Y",
apply_scale_options="FBX_SCALE_ALL", bake_space_transform=False,
use_mesh_modifiers=False, mesh_smooth_type="FACE", add_leaf_bones=False,
object_types={"MESH", "EMPTY", "ARMATURE"}, use_armature_deform_only=False,
armature_nodetype="NULL", primary_bone_axis="Y", secondary_bone_axis="X",
bake_anim=False, path_mode="STRIP", use_custom_props=False)
return path
def pose(rig, rots):
for pb in rig.pose.bones:
pb.rotation_mode = "XYZ"
pb.rotation_euler = rots.get(pb.name, (0, 0, 0))
bpy.context.view_layer.update()
def crew():
G = build_crew_geo()
rig = crew_rig(G)
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, DEG(0)),
"Body": (0, DEG(6), 0)}),
("back", dict(elev=15, azim=150), {}),
("pose2", dict(elev=5, azim=0), {"Arm_L": (0, 0, DEG(-35)), "Arm_R": (0, 0, DEG(35)),
"Leg_L": (DEG(-30), 0, 0), "Leg_R": (DEG(30), 0, 0)}),
("legs", dict(elev=5, azim=90, target=(0, 0, 0.45), radius=0.85),
{"Leg_L": (DEG(30), 0, 0), "Leg_R": (DEG(-30), 0, 0), "Arm_L": (DEG(-30), 0, 0), "Arm_R": (DEG(30), 0, 0)}),
("head", dict(elev=8, azim=-25, target=(0, 0, 1.1), radius=0.35), {})])
# ======================================================================= shared bits for gloves / tools
def frame_on(loc, n, up=(0, 0, 1)):
"""4x4 frame at loc with local Z = n, local Y ~ up."""
z = Vector(n).normalized()
u = Vector(up)
if abs(u.normalized().dot(z)) > 0.95:
u = Vector((0, -1, 0))
x = u.cross(z).normalized()
y = z.cross(x)
m = Matrix((x, y, z)).transposed().to_4x4()
m.translation = Vector(loc)
return m
def drop_decal(P, loc, n, r=0.012, m="M_Teal", plate=None, plate_m="M_HullWhite", up=(0, 0, 1)):
fr = frame_on(loc, n, up)
if plate:
P.append(prism("dplate", rrect_pts(plate[0], plate[1], min(plate) * 0.3, 3), 0.004, fr @ Matrix.Translation((0, 0, -0.002)),
plate_m))
P.append(prism("drop", [(x, y - 1.05 * r) for x, y in drop_pts(r)], 0.003,
fr @ Matrix.Translation((0, 0, 0.001 if not plate else 0.002)), m))
def mirror_x(o):
o.data.transform(Matrix.Scale(-1, 4, (1, 0, 0)))
o.data.flip_normals()
return o
def part_obj(P, name, origin=None, uv=3.0, ang=45):
o = fin(P, name, uv=uv, ang=ang)
if origin is not None:
set_origin(o, origin)
return o
def pistol_grip(P, loc=(0, 0, 0), tilt=14.0, h0=-0.085, h1=0.05, rx=0.021, ry=0.028, m="M_Rubber", cap_m="M_PaintOrange"):
"""Rubber pistol grip with front finger ridges; top leans forward by `tilt` degrees."""
fr = Matrix.Translation(Vector(loc)) @ Matrix.Rotation(DEG(tilt), 4, "X")
rings = []
n = 8
for k in range(n + 1):
t = k / n
z = h0 + 0.012 + (h1 - h0 - 0.012) * t
bump = math.sin(math.pi * min(1.0, t * 1.25) * 3) ** 2 if t < 0.8 else 0.0
rings.append((0, -0.004 * bump, rx * (1 + 0.05 * bump), ry * (1 + 0.1 * bump), z, 2.4))
P.append(loft("grip", rings, segs=16, m=m, frame=fr, cap0=False, cap1=False, smooth_ang=70))
P.append(loft("pommel", [(0, 0.004, rx * 0.75, ry * 0.8, h0 - 0.006, 2.4), (0, 0.004, rx * 1.2, ry * 1.2, h0, 2.6),
(0, 0.004, rx * 1.25, ry * 1.25, h0 + 0.01, 2.6), (0, 0.0, rx * 1.02, ry * 1.02, h0 + 0.016, 2.4)],
segs=16, m=cap_m, frame=fr, smooth_ang=60))
def fan_blades(name, loc, r, hub, n=5, m_blade="M_Teal", m_hub="M_Steel", pitch=32.0, depth=0.016):
"""Fan spinning about the forward axis (Blender -Y); origin at its centre."""
P = []
FR = M_fwd(loc)
P.append(lathe("hub", [(0.0, -depth), (hub * 0.7, -depth), (hub, -depth * 0.4), (hub, depth * 0.3), (hub * 0.75, depth * 0.9),
(hub * 0.3, depth * 1.3), (0.0, depth * 1.4)], segs=16, m=m_hub, frame=FR, cap0=True, smooth_ang=40))
for k in range(n):
th0 = 2 * math.pi * k / n
def fn(u, v, off, th0=th0):
rho = hub * 0.85 + (r - hub * 0.85) * u
span = 0.55 + 0.25 * u
th = th0 + (v - 0.5) * span
ax = (v - 0.5) * rho * span * math.tan(DEG(pitch * (1.1 - 0.4 * u)))
return FR @ Vector((rho * math.cos(th), rho * math.sin(th), ax + off))
P.append(grid_slab("blade", fn, 3, 3, 0.0025, -0.0025, m_blade, smooth_ang=40))
t = torus("ring", r + 0.004, 0.004, seg=24, rseg=4, m=m_hub)
t.data.transform(FR)
P.append(t)
return part_obj(P, name, origin=loc, uv=6.0)
# ======================================================================= first-person gloves
def finger(name, pts, r, m="M_GloveOrange", per=5, segs=12):
def rf(s, l):
tip = 0.8
if s > tip:
t = (s - tip) / (1 - tip)
return r * (math.sqrt(max(0.0, 1 - t * t)) * 0.97 + 0.03)
return r * (1.0 + 0.07 * math.sin(math.pi * s / tip * 2) ** 2)
return sweep_circle(name, pts, rf, segs=segs, per=per, m=m, cap=True, smooth_ang=80)
def glove(name, side):
"""Right hand built; side=-1 mirrors to the left. Wrist at origin, fingers -Y, palm faces the screen centre (+X for R)."""
P = []
FW = M_fwd()
P.append(loft("palm", [(0, 0, 0.034, 0.04, -0.01, 2.4), (0, 0, 0.04, 0.047, 0.025, 2.6), (0.003, 0.0, 0.043, 0.05, 0.06, 2.8),
(0.002, 0.0, 0.041, 0.05, 0.085, 2.7), (0.0, 0.0, 0.033, 0.043, 0.1, 2.4), (0, 0, 0, 0, 0.106)],
segs=28, m="M_GloveOrange", frame=FW, cap0=False, smooth_ang=80))
for zf, r, ln in ((0.031, 0.0195, 1.0), (0.0, 0.0205, 1.04), (-0.031, 0.0185, 0.93)):
pts = [Vector((x, y, zf)) for x, y in ((-0.002, -0.08), (0.016, -0.118), (0.05, -0.132), (0.085, -0.122), (0.1, -0.096))]
pts[-1] = pts[-2].lerp(pts[-1], ln)
P.append(finger("finger", pts, r))
P.append(finger("thumb", [(0.022, -0.03, 0.03), (0.05, -0.052, 0.046), (0.077, -0.074, 0.05), (0.098, -0.09, 0.044)], 0.021))
# back-of-hand rubber guard (padded plate + knuckle bar) with an GreenHaul drop
fr = frame_on((-0.042, -0.05, 0.0), (-1, 0, 0), up=(0, -1, 0))
P.append(prism("guard", rrect_pts(0.072, 0.05, 0.02, 4), 0.01, fr @ Matrix.Translation((0, 0, -0.005)), "M_Rubber", bevel=0.004, segs=2))
drop_decal(P, (-0.0475, -0.05, 0.0), (-1, 0, 0), r=0.008, m="M_Teal", up=(0, -1, 0))
P.append(sweep_circle("kbar", [(-0.028, -0.097, 0.05), (-0.035, -0.1, 0.0), (-0.028, -0.097, -0.05)],
lambda s, l: 0.0125 * (0.7 + 0.3 * abs(math.sin(3 * math.pi * s)) ** 0.6), segs=10, per=8, m="M_Rubber"))
# gauntlet + velcro strap + rolled cuff + creature arm stub
BK = M_axis("Y")
P.append(loft("gaunt", [(0, 0, 0.035, 0.042, 0.0, 2.4), (0, 0, 0.042, 0.048, 0.03, 2.4), (0, 0, 0.05, 0.055, 0.05, 2.2)],
segs=28, m="M_GloveOrange", frame=BK, cap0=False, cap1=False, smooth_ang=80))
P.append(loft("strap", [(0, 0, 0.0385, 0.0455, 0.006, 2.4), (0, 0, 0.0415, 0.0485, 0.009, 2.4), (0, 0, 0.0435, 0.0505, 0.03, 2.4),
(0, 0, 0.0405, 0.0475, 0.033, 2.4)], segs=28, m="M_Teal", frame=BK, cap0=False, cap1=False, smooth_ang=60))
drop_decal(P, (-0.044, 0.019, 0.0), (-1, 0, 0), r=0.007, m="M_HullWhite")
cuff = torus("cuff", 0.052, 0.015, seg=28, rseg=10, m="M_GloveOrange")
cuff.data.transform(Matrix.Translation((0, 0.054, 0)) @ Matrix.Rotation(DEG(90), 4, "X"))
P.append(cuff)
P.append(lathe("arm", [(0.04, 0.04), (0.042, 0.08), (0.042, 0.105), (0.036, 0.118), (0.0, 0.122)], segs=20, m="M_CrewSkin",
frame=BK, smooth_ang=80))
o = fin(P, "Glove", uv=6.0, ang=70)
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)])
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)])
# ======================================================================= tools
def body_band(P, FR, rx, rz, d0, d1, m, n=3.0, cy=0.0, grow=0.004, segs=32):
P.append(loft("band", [(0, cy, rx + grow * 0.5, rz + grow * 0.5, d0, n), (0, cy, rx + grow, rz + grow, d0 + 0.004, n),
(0, cy, rx + grow, rz + grow, d1 - 0.004, n), (0, cy, rx + grow * 0.5, rz + grow * 0.5, d1, n)],
segs=segs, m=m, frame=FR, cap0=False, cap1=False, smooth_ang=50))
def tool_slurpgun():
P = []
Z, YR = 0.1, 0.13
FR = M_fwd((0, YR, Z))
P.append(loft("body", [(0, 0, 0, 0, -0.004), (0, 0, 0.044, 0.05, 0.0, 2.6), (0, 0, 0.062, 0.068, 0.012, 2.8),
(0, 0, 0.07, 0.078, 0.04, 3.0), (0, 0.004, 0.072, 0.08, 0.2, 3.0), (0, 0.006, 0.074, 0.082, 0.33, 3.0),
(0, 0.006, 0.071, 0.079, 0.37, 3.0)], segs=32, m="M_HullWhite", frame=FR, cap1=False))
body_band(P, FR, 0.071, 0.079, 0.1, 0.14, "M_PaintOrange", cy=0.002)
body_band(P, FR, 0.073, 0.081, 0.29, 0.305, "M_Teal", cy=0.006)
body_band(P, FR, 0.07, 0.078, 0.012, 0.04, "M_Rubber", cy=0.0, grow=0.008)
P.append(lathe("rcap", [(0.0, -0.012), (0.026, -0.012), (0.032, -0.006), (0.034, 0.002)], segs=20, m="M_PaintOrange", frame=FR,
smooth_ang=40))
# intake bell
FI = FR @ Matrix.Translation((0, 0.006, 0.365))
P.append(lathe("bell", [(0.07, 0.0), (0.08, 0.02), (0.096, 0.058), (0.104, 0.086)], segs=32, m="M_HullWhite", frame=FI))
P.append(lathe("lip", [(0.1, 0.082), (0.112, 0.086), (0.12, 0.098), (0.116, 0.11), (0.102, 0.116), (0.092, 0.108)], segs=32,
m="M_PaintOrange", frame=FI, smooth_ang=70))
P.append(lathe("throat", [(0.093, 0.108), (0.084, 0.07), (0.07, 0.04), (0.064, 0.02), (0.02, 0.016), (0.0, 0.016)], segs=32,
m="M_DarkGrey", frame=FI))
for k in range(6):
a = 2 * math.pi * (k + 0.5) / 6
bolt(P, FI @ Vector((0.093 * math.cos(a), 0.093 * math.sin(a), 0.07)),
(FI.to_3x3() @ Vector((math.cos(a), math.sin(a), -0.25))), r=0.0065, h=0.006)
fanloc = FI @ Vector((0, 0, 0.042))
# canister on top
cy_, cz = -0.065, Z + 0.07
CF = Matrix.Translation((0, cy_, cz))
P.append(lathe("cbase", [(0.0, 0.0), (0.066, 0.0), (0.07, 0.01), (0.07, 0.026), (0.064, 0.032), (0.0, 0.032)], segs=28,
m="M_Steel", frame=CF, smooth_ang=40))
P.append(lathe("cglass", [(0.054, 0.03), (0.056, 0.04), (0.056, 0.14), (0.054, 0.15)], segs=28, m="M_Glass", frame=CF,
smooth_ang=60))
P.append(lathe("ctop", [(0.0, 0.145), (0.062, 0.145), (0.066, 0.152), (0.066, 0.166), (0.058, 0.174), (0.03, 0.178), (0.0, 0.179)],
segs=28, m="M_PaintOrange", frame=CF, smooth_ang=40))
P.append(lathe("knob", [(0.0, 0.176), (0.016, 0.176), (0.018, 0.186), (0.014, 0.194), (0.0, 0.196)], segs=12, m="M_DarkGrey",
frame=CF, smooth_ang=40))
for k in range(4):
a = DEG(45 + 90 * k)
P.append(cyl("rod", 0.0045, 0.12, (0.061 * math.cos(a), cy_ + 0.061 * math.sin(a), cz + 0.09), verts=8, m="M_Steel"))
fill = lathe("Fill", [(0.0, 0.032), (0.05, 0.032), (0.05, 0.138), (0.0, 0.138)], segs=24, m="M_WaterFill", frame=CF, smooth_ang=30)
# feed hose intake -> canister
P.append(hose("feed", [(0.0, -0.215, Z + 0.07), (0.0, -0.17, Z + 0.13), (0.0, -0.13, cz + 0.085), (0.0, cy_ - 0.05, cz + 0.09)],
0.017, m="M_Teal", rib=0.014, segs=10, per=6))
P.append(cyl("collar", 0.022, 0.016, (0.0, -0.212, Z + 0.07), axis="Z", verts=16, bevel=0.004, m="M_Steel"))
# pistol grip, trigger, guard
pistol_grip(P, (0, 0.0, 0.0), tilt=12)
P.append(sweep_circle("trig", [(0, -0.028, 0.03), (0, -0.044, 0.008), (0, -0.044, -0.012), (0, -0.036, -0.022)],
lambda s, l: 0.0085 * (1 - 0.3 * s), segs=8, per=3, m="M_PaintOrange"))
P.append(sweep_circle("guard", [(0, -0.075, 0.03), (0, -0.08, -0.012), (0, -0.06, -0.04), (0, -0.028, -0.045), (0, -0.012, -0.04)],
lambda s, l: 0.0065, segs=8, per=3, m="M_DarkGrey"))
# side vents + decals + rear sight fin
for sx in (-1, 1):
for k in range(3):
P.append(rbox("vent", (0.01, 0.052, 0.009), (sx * 0.072, 0.075, Z + 0.022 - k * 0.02), bevel=0.003, segs=1, m="M_DarkGrey"))
drop_decal(P, (sx * 0.0775, -0.08, Z), (sx, 0, 0), r=0.013, m="M_Teal", plate=(0.06, 0.05))
for yy in (0.0, -0.17):
bolt(P, (sx * 0.077, yy, Z - 0.04), (sx, 0, 0), r=0.006, h=0.005)
P.append(rbox("fin", (0.014, 0.06, 0.03), (0, 0.075, Z + 0.088), bevel=0.006, segs=2, m="M_PaintOrange"))
fin(P, "Body", uv=4.0, ang=45)
fan_blades("Fan", fanloc, 0.06, 0.018, n=5)
set_origin(fill, (0, cy_, cz + 0.032))
uv_box(fill, 4.0)
empty("Nozzle", tuple(FI @ Vector((0, 0, 0.116))))
return dict(elev=22, azim=-40, extra=[("fp", dict(elev=20, azim=155), None)])
def tool_handpump():
P = []
Z, YB = 0.072, 0.16
FR = M_fwd((0, YB, Z))
# barrel (brass) with teal caps
P.append(lathe("rcap", [(0.0, -0.016), (0.026, -0.016), (0.036, -0.012), (0.042, -0.004), (0.043, 0.024), (0.038, 0.03)],
segs=28, m="M_Teal", frame=FR, smooth_ang=40))
P.append(lathe("barrel", [(0.034, 0.026), (0.034, 0.33)], segs=28, m="M_Brass", frame=FR))
for d in (0.09, 0.27):
t = torus("band", 0.0355, 0.004, seg=28, rseg=6, m="M_Brass")
t.data.transform(FR @ Matrix.Translation((0, 0, d)))
P.append(t)
P.append(lathe("fcap", [(0.038, 0.326), (0.043, 0.332), (0.043, 0.362), (0.036, 0.372), (0.0, 0.374)], segs=28, m="M_Teal",
frame=FR, smooth_ang=40))
# spigot pointing down at the front
spz = Z - 0.03
P.append(cyl("spig", 0.013, 0.03, (0, -0.2, spz), verts=14, bevel=0.003, m="M_Brass"))
t = torus("hcl", 0.014, 0.004, seg=14, rseg=6, m="M_Steel")
t.data.transform(Matrix.Translation((0, -0.2, spz - 0.02)))
P.append(t)
# pressure gauge on top
P.append(cyl("gstem", 0.006, 0.03, (0, -0.1, Z + 0.042), verts=8, m="M_Brass"))
GF = frame_on((0, -0.1, Z + 0.07), (0, -0.6, 0.8), up=(0, 0, 1))
P.append(lathe("gbody", [(0.0, -0.012), (0.026, -0.012), (0.03, -0.006), (0.03, 0.006), (0.027, 0.01)], segs=20, m="M_Brass",
frame=GF, cap0=True, smooth_ang=40))
P.append(lathe("gface", [(0.0, 0.006), (0.025, 0.006)], segs=20, m="M_HullWhite", frame=GF, cap0=True))
P.append(prism("needle", [(-0.002, 0.0), (0.002, 0.0), (0.0, 0.019)], 0.002,
GF @ Matrix.Translation((0, 0, 0.007)) @ Matrix.Rotation(DEG(-35), 4, "Z"), "M_PaintRed"))
P.append(prism("redz", [(0.024 * math.cos(DEG(a)), 0.024 * math.sin(DEG(a))) for a in range(-20, 41, 10)] +
[(0.017 * math.cos(DEG(a)), 0.017 * math.sin(DEG(a))) for a in range(40, -21, -10)], 0.001,
GF @ Matrix.Translation((0, 0, 0.0065)), "M_PaintRed"))
# clamp + pistol grip under the barrel
P.append(lathe("clamp", [(0.036, -0.02), (0.042, -0.016), (0.042, 0.016), (0.036, 0.02)], segs=28, m="M_Teal",
frame=M_fwd((0, 0.0, Z)), smooth_ang=50))
P.append(rbox("clampnut", (0.022, 0.02, 0.02), (0.0, 0.0, Z - 0.042), bevel=0.005, m="M_Steel"))
pistol_grip(P, (0, 0.0, 0.0), tilt=10, h1=0.04, m="M_Teal", cap_m="M_Rubber")
# floppy corrugated hose + little nozzle
hp = [(0.0, -0.2, spz - 0.02), (0.0, -0.208, spz - 0.06), (0.018, -0.245, spz - 0.1), (0.016, -0.3, spz - 0.105),
(0.0, -0.345, spz - 0.075), (0.0, -0.37, spz - 0.06)]
P.append(hose("hose", hp, 0.016, m="M_DarkGrey", rib=0.013, segs=10, per=6))
NF = M_fwd((0, -0.365, spz - 0.06))
P.append(lathe("nz", [(0.0, -0.01), (0.02, -0.01), (0.022, 0.0), (0.02, 0.02), (0.013, 0.055), (0.015, 0.06), (0.011, 0.064)],
segs=18, m="M_Brass", frame=NF, cap0=True, smooth_ang=40))
P.append(lathe("nzin", [(0.011, 0.064), (0.008, 0.05), (0.0, 0.048)], segs=18, m="M_DarkGrey", frame=NF))
t = torus("nzr", 0.021, 0.0045, seg=18, rseg=6, m="M_Teal")
t.data.transform(NF @ Matrix.Translation((0, 0, 0.004)))
P.append(t)
fin(P, "Body", uv=4.0, ang=45)
# plunger: rod + T handle; origin where the rod enters the rear cap
Q = [cyl("rod", 0.0075, 0.11, (0, YB + 0.065, Z), axis="Y", verts=12, m="M_Steel")]
Q.append(cyl("rodcol", 0.012, 0.012, (0, YB + 0.02, Z), axis="Y", verts=14, bevel=0.003, m="M_Brass"))
TF = M_axis("X", (0, YB + 0.125, Z))
Q.append(lathe("thandle", [(0.0, -0.08), (0.016, -0.08), (0.02, -0.074), (0.02, -0.056), (0.017, -0.052), (0.014, -0.052),
(0.014, 0.052), (0.017, 0.052), (0.02, 0.056), (0.02, 0.074), (0.016, 0.08), (0.0, 0.08)],
segs=16, m="M_Teal", frame=TF, smooth_ang=50))
Q.append(lathe("tgrip", [(0.018, -0.05), (0.02, -0.04), (0.02, 0.04), (0.018, 0.05)], segs=16, m="M_Rubber", frame=TF))
Q.append(sphere("tcen", 0.017, (0, YB + 0.125, Z), m="M_Brass", seg=12, rings=6))
part_obj(Q, "Plunger", origin=(0, YB, Z), uv=5.0)
empty("Nozzle", (0, -0.43, spz - 0.06))
return dict(elev=24, azim=-50, extra=[("fp", dict(elev=20, azim=150), None)])
def side_tank(P, x, z, y0, y1, r, m="M_HullWhite", cap_m="M_PaintOrange"):
FR = M_fwd((x, y0, z))
L = y0 - y1
P.append(lathe("tank", [(0.0, -0.004), (r * 0.6, 0.0), (r * 0.92, 0.014), (r, 0.03), (r, L - 0.03), (r * 0.92, L - 0.014),
(r * 0.6, L), (0.0, L + 0.004)], segs=20, m=m, frame=FR, smooth_ang=55))
for d in (0.03, L - 0.03):
P.append(lathe("tcap", [(r * 1.0, d - 0.016), (r * 1.06, d - 0.012), (r * 1.06, d + 0.012), (r * 1.0, d + 0.016)], segs=20,
m=cap_m, frame=FR, smooth_ang=50))
sx = 1 if x > 0 else -1
# glass gauge strip on the outer side with water inside
WF = frame_on((x + sx * (r - 0.006), (y0 + y1) / 2, z), (sx, 0, 0), up=(0, -1, 0))
wl = L - 0.11
P.append(ring_prism("wfr", rrect_pts(0.04, wl + 0.02, 0.018, 4), rrect_pts(0.022, wl, 0.01, 4), 0.012, WF, "M_DarkGrey"))
P.append(prism("wat", rrect_pts(0.022, wl, 0.01, 4), 0.006, WF, "M_WaterFill"))
P.append(prism("wgl", rrect_pts(0.022, wl, 0.01, 4), 0.002, WF @ Matrix.Translation((0, 0, 0.009)), "M_Glass"))
def tool_hydrocannon():
P = []
Z, YR = 0.135, 0.2
FR = M_fwd((0, YR, Z))
P.append(loft("body", [(0, 0, 0, 0, -0.004), (0, 0, 0.06, 0.066, 0.0, 2.6), (0, 0, 0.085, 0.092, 0.016, 2.8),
(0, 0, 0.094, 0.1, 0.05, 3.0), (0, 0.005, 0.096, 0.104, 0.3, 3.0), (0, 0.008, 0.092, 0.1, 0.5, 3.0),
(0, 0.008, 0.086, 0.094, 0.56, 3.0)], segs=36, m="M_HullWhite", frame=FR, cap1=False))
body_band(P, FR, 0.094, 0.1, 0.016, 0.05, "M_Rubber", grow=0.012, segs=36)
body_band(P, FR, 0.095, 0.103, 0.13, 0.175, "M_PaintOrange", cy=0.003, segs=36)
body_band(P, FR, 0.094, 0.102, 0.42, 0.44, "M_Teal", cy=0.007, segs=36)
P.append(lathe("rpad", [(0.0, -0.012), (0.03, -0.012), (0.036, -0.008), (0.038, 0.0)], segs=24, m="M_PaintOrange", frame=FR, smooth_ang=40))
for k in range(4):
a = DEG(45 + 90 * k)
bolt(P, FR @ Vector((0.05 * math.cos(a), 0.054 * math.sin(a), -0.004)), (0, 1, 0), r=0.006, h=0.005)
# big intake horn
FI = FR @ Matrix.Translation((0, 0.008, 0.55))
P.append(lathe("horn", [(0.086, 0.0), (0.095, 0.04), (0.12, 0.1), (0.16, 0.16), (0.19, 0.2)], segs=32, m="M_HullWhite", frame=FI,
smooth_ang=70))
P.append(lathe("hlip", [(0.184, 0.194), (0.204, 0.197), (0.216, 0.215), (0.202, 0.235), (0.18, 0.232), (0.17, 0.222)],
segs=32, m="M_PaintOrange", frame=FI, smooth_ang=70))
P.append(lathe("hin", [(0.17, 0.222), (0.14, 0.17), (0.105, 0.11), (0.085, 0.07), (0.08, 0.05), (0.0, 0.045)],
segs=32, m="M_DarkGrey", frame=FI))
for k in range(4): # stiffening ribs on the horn
a = DEG(45 + 90 * k)
pts = [FI @ Vector(((r + 0.006) * math.cos(a), (r + 0.006) * math.sin(a), d))
for r, d in ((0.096, 0.04), (0.12, 0.1), (0.16, 0.16), (0.188, 0.195))]
P.append(sweep_circle("hrib", pts, lambda s, l: 0.008, segs=6, per=2, m="M_PaintOrange"))
for k in range(8):
a = 2 * math.pi * (k + 0.5) / 8
bolt(P, FI @ Vector((0.205 * math.cos(a), 0.205 * math.sin(a), 0.236)), FI.to_3x3() @ Vector((0, 0, 1)), r=0.007, h=0.006)
fanloc = FI @ Vector((0, 0, 0.085))
# twin side tanks with brackets + feed pipes
for sx in (-1, 1):
x = sx * 0.152
side_tank(P, x, Z - 0.005, 0.12, -0.26, 0.058)
for yy in (0.07, -0.2):
P.append(rbox("brk", (0.07, 0.03, 0.028), (sx * 0.1, yy, Z - 0.005), bevel=0.008, segs=1, m="M_DarkGrey"))
bolt(P, (sx * 0.12, yy, Z + 0.009), (0, 0, 1), r=0.006, h=0.005)
P.append(sweep_circle("pipe", [(x, -0.27, Z - 0.005), (x, -0.31, Z - 0.0), (sx * 0.11, -0.335, Z + 0.02), (sx * 0.07, -0.34, Z + 0.06)],
lambda s, l: 0.012, segs=8, per=3, m="M_Steel"))
# top carry handle
P.append(sweep_circle("handle", [(0, 0.06, Z + 0.095), (0, 0.05, Z + 0.15), (0, 0.0, Z + 0.165), (0, -0.12, Z + 0.165),
(0, -0.17, Z + 0.15), (0, -0.18, Z + 0.095)], lambda s, l: 0.014, segs=8, per=3, m="M_DarkGrey"))
P.append(lathe("hgrip", [(0.016, 0.0), (0.019, 0.008), (0.019, 0.1), (0.016, 0.108)], segs=12, m="M_Rubber",
frame=M_fwd((0, 0.0, Z + 0.165)), smooth_ang=60))
# top vents
for k in range(4):
P.append(rbox("vent", (0.06, 0.012, 0.01), (0, 0.13 - k * 0.022, Z + 0.1), bevel=0.004, segs=1, m="M_DarkGrey"))
drop_decal(P, (0, -0.24, Z + 0.104), (0, 0, 1), r=0.016, m="M_Teal", plate=(0.075, 0.07), up=(0, -1, 0))
# grips
pistol_grip(P, (0, 0.0, 0.0), tilt=12, h1=0.07)
P.append(sweep_circle("trig", [(0, -0.028, 0.045), (0, -0.046, 0.022), (0, -0.046, 0.0), (0, -0.038, -0.01)],
lambda s, l: 0.009 * (1 - 0.3 * s), segs=8, per=3, m="M_PaintOrange"))
P.append(sweep_circle("guard", [(0, -0.08, 0.045), (0, -0.085, 0.0), (0, -0.062, -0.03), (0, -0.03, -0.035), (0, -0.012, -0.03)],
lambda s, l: 0.007, segs=8, per=3, m="M_DarkGrey"))
pistol_grip(P, (0, -0.33, 0.0), tilt=0, h0=-0.06, h1=0.06, cap_m="M_Teal")
fin(P, "Body", uv=4.0, ang=45)
fan_blades("Fan", fanloc, 0.078, 0.024, n=6, m_blade="M_PaintOrange")
empty("Nozzle", tuple(FI @ Vector((0, 0, 0.236))))
return dict(elev=22, azim=-40, extra=[("fp", dict(elev=20, azim=155), None)])
def siphon_ring(name, loc, r_in, r_out, w, nfin, glow_m="M_LightBlue", m="M_HullWhite", twist=1):
"""Rotating vortex ring around the forward axis; origin on the axis."""
FR = M_fwd(loc)
P = []
P.append(lathe("rb", [(r_in, -w / 2), (r_out - 0.01, -w / 2), (r_out, -w / 2 + 0.01), (r_out, w / 2 - 0.01), (r_out - 0.01, w / 2),
(r_in, w / 2), (r_in, -w / 2)], segs=36, m=m, frame=FR, smooth_ang=40))
P.append(lathe("rg", [(r_in + 0.012, w / 2), (r_out - 0.012, w / 2 + 0.004), (r_out - 0.012, w / 2 + 0.008),
(r_in + 0.012, w / 2 + 0.006)], segs=36, m=glow_m, frame=FR, smooth_ang=40))
for k in range(nfin):
a = 2 * math.pi * k / nfin
fr = FR @ Matrix.Rotation(a, 4, "Z") @ Matrix.Translation((r_out - 0.004, 0, 0)) @ Matrix.Rotation(DEG(25 * twist), 4, "X")
P.append(prism("fin", rrect_pts(0.04, w * 0.85, 0.01, 2), 0.01, fr @ Matrix.Rotation(DEG(90), 4, "Y") @
Matrix.Translation((0, 0, -0.005)), "M_Teal"))
for k in range(0, nfin, 2):
a = 2 * math.pi * (k + 0.5) / nfin
p = FR @ Vector(((r_in + r_out) / 2 * math.cos(a), (r_in + r_out) / 2 * math.sin(a), -w / 2 - 0.001))
bolt(P, p, FR.to_3x3() @ Vector((0, 0, -1)), r=0.006, h=0.005)
return part_obj(P, name, origin=loc, uv=4.0)
def tool_megasiphon():
P = []
Z, YR = 0.15, 0.2
FR = M_fwd((0, YR, Z))
P.append(loft("body", [(0, 0, 0.07, 0.075, 0.0, 2.6), (0, 0, 0.1, 0.105, 0.02, 2.8), (0, 0, 0.11, 0.118, 0.06, 3.0),
(0, 0.006, 0.112, 0.12, 0.3, 3.0), (0, 0.008, 0.104, 0.112, 0.44, 3.0), (0, 0.008, 0.096, 0.104, 0.48, 3.0)],
segs=32, m="M_HullWhite", frame=FR, cap0=False, cap1=False))
# heat-sink stack at the rear
for k in range(3):
d = -0.004 - k * 0.022
a, b = 0.074 - k * 0.006, 0.078 - k * 0.006
P.append(loft("sink", [(0, 0, a, b, d - 0.006, 2.8), (0, 0, a + 0.006, b + 0.006, d - 0.004, 2.8),
(0, 0, a + 0.006, b + 0.006, d + 0.004, 2.8), (0, 0, a, b, d + 0.006, 2.8)],
segs=24, m="M_Steel" if k % 2 == 0 else "M_Teal", frame=FR, cap0=False, cap1=False))
P.append(lathe("score", [(0.0, -0.075), (0.045, -0.075), (0.055, -0.06), (0.06, 0.0)], segs=24, m="M_Navy", frame=FR))
P.append(lathe("glowr", [(0.0, -0.078), (0.025, -0.078), (0.028, -0.074)], segs=16, m="M_LightBlue", frame=FR, cap0=True))
body_band(P, FR, 0.112, 0.12, 0.2, 0.215, "M_PaintOrange", cy=0.005, segs=32)
body_band(P, FR, 0.106, 0.114, 0.39, 0.42, "M_Navy", cy=0.008, segs=32)
# glowing side light lines
for sx in (-1, 1):
P.append(rbox("gline", (0.008, 0.22, 0.012), (sx * 0.114, YR - 0.27, Z + 0.01), bevel=0.004, segs=1, m="M_LightBlue"))
P.append(rbox("gline2", (0.008, 0.16, 0.008), (sx * 0.114, YR - 0.24, Z - 0.03), bevel=0.003, segs=1, m="M_LightBlue"))
drop_decal(P, (sx * 0.1165, YR - 0.12, Z - 0.02), (sx, 0, 0), r=0.014, m="M_Teal", plate=(0.06, 0.06))
# vortex core on top: glass tube with glowing coil
TF = M_fwd((0, 0.12, Z + 0.15))
P.append(lathe("tglass", [(0.0, -0.01), (0.03, -0.006), (0.04, 0.01), (0.042, 0.04), (0.042, 0.24), (0.04, 0.27), (0.03, 0.286), (0.0, 0.29)],
segs=20, m="M_Glass", frame=TF, smooth_ang=70))
P.append(lathe("core", [(0.0, 0.0), (0.016, 0.004), (0.016, 0.276), (0.0, 0.28)], segs=12, m="M_LightBlue", frame=TF, smooth_ang=60))
for d in (0.1, 0.18):
t = torus("cring", 0.03, 0.005, seg=16, rseg=4, m="M_Steel")
t.data.transform(TF @ Matrix.Translation((0, 0, d)))
P.append(t)
for d in (-0.012, 0.29):
P.append(lathe("tcap", [(0.0, d - 0.012), (0.04, d - 0.012), (0.048, d - 0.004), (0.048, d + 0.006), (0.04, d + 0.014), (0.0, d + 0.014)],
segs=20, m="M_PaintOrange", frame=TF, smooth_ang=50))
for yy in (0.1, -0.15):
P.append(rbox("post", (0.03, 0.03, 0.05), (0, yy, Z + 0.11), bevel=0.008, segs=1, m="M_DarkGrey"))
# vortex intake: neck + flaring mouth with glowing throat
FI = FR @ Matrix.Translation((0, 0.008, 0.48))
P.append(lathe("neck", [(0.094, 0.0), (0.09, 0.03), (0.088, 0.1), (0.094, 0.16), (0.108, 0.22), (0.135, 0.28), (0.17, 0.32), (0.2, 0.34)],
segs=32, m="M_Steel", frame=FI, smooth_ang=70))
P.append(lathe("mlip", [(0.196, 0.336), (0.216, 0.34), (0.228, 0.358), (0.212, 0.376), (0.19, 0.372), (0.178, 0.36)],
segs=32, m="M_PaintOrange", frame=FI, smooth_ang=70))
P.append(lathe("min", [(0.178, 0.36), (0.14, 0.31), (0.105, 0.25), (0.085, 0.19), (0.078, 0.14)], segs=32, m="M_DarkGrey", frame=FI))
P.append(lathe("mglow", [(0.078, 0.14), (0.074, 0.12), (0.05, 0.11), (0.0, 0.108)], segs=32, m="M_LightBlue", frame=FI))
for k in range(2): # glowing rings inside the throat
d = 0.21 + k * 0.06
rr = [0.1, 0.13][k]
t = torus("gring", rr, 0.005, seg=28, rseg=4, m="M_LightBlue")
t.data.transform(FI @ Matrix.Translation((0, 0, d)))
P.append(t)
# stator struts for the rings
for k in range(3):
a = DEG(90 + 120 * k)
pts = [FI @ Vector((0.088 * math.cos(a), 0.088 * math.sin(a), 0.02)), FI @ Vector((0.16 * math.cos(a), 0.16 * math.sin(a), 0.06)),
FI @ Vector((0.172 * math.cos(a), 0.172 * math.sin(a), 0.12))]
P.append(sweep_circle("strut", pts, lambda s, l: 0.011, segs=6, per=2, m="M_DarkGrey"))
for k in range(6):
a = 2 * math.pi * (k + 0.5) / 6
bolt(P, FI @ Vector((0.213 * math.cos(a), 0.213 * math.sin(a), 0.376)), FI.to_3x3() @ Vector((0, 0, 1)), r=0.007, h=0.006)
# grips
pistol_grip(P, (0, 0.0, 0.0), tilt=12, h1=0.08)
P.append(sweep_circle("trig", [(0, -0.028, 0.05), (0, -0.046, 0.026), (0, -0.046, 0.004), (0, -0.038, -0.006)],
lambda s, l: 0.009 * (1 - 0.3 * s), segs=8, per=3, m="M_LightBlue"))
P.append(sweep_circle("guard", [(0, -0.08, 0.05), (0, -0.085, 0.0), (0, -0.062, -0.03), (0, -0.03, -0.035), (0, -0.012, -0.03)],
lambda s, l: 0.007, segs=8, per=3, m="M_DarkGrey"))
pistol_grip(P, (0, -0.25, 0.0), tilt=0, h0=-0.06, h1=0.07, cap_m="M_Teal")
fin(P, "Body", uv=4.0, ang=45)
siphon_ring("Ring1", tuple(FI @ Vector((0, 0, 0.085))), 0.1, 0.14, 0.05, 6, twist=1)
siphon_ring("Ring2", tuple(FI @ Vector((0, 0, 0.165))), 0.112, 0.165, 0.05, 8, twist=-1)
empty("Nozzle", tuple(FI @ Vector((0, 0, 0.376))))
return dict(elev=22, azim=-40, extra=[("fp", dict(elev=20, azim=155), None)])
# ======================================================================= runner
BUILDERS = {
"SM_Crew": crew,
"SM_Glove_R": glove_r,
"SM_Glove_L": glove_l,
"SM_Tool_HandPump": tool_handpump,
"SM_Tool_SlurpGun": tool_slurpgun,
"SM_Tool_HydroCannon": tool_hydrocannon,
"SM_Tool_MegaSiphon": tool_megasiphon,
}
def finish_x(name, res):
rig = res.pop("rigged", None)
extra = res.pop("extra", [])
print(f"[{name}] tris={tri_count()}")
if rig is not None:
pose(rig, {})
export_rigged(name)
else:
export(name)
save_blend(name)
preview(name, **res)
for suf, pv, rots in extra:
if rig is not None and rots is not None:
pose(rig, rots)
preview(name + "_" + suf, **pv)
if rig is not None:
pose(rig, {})
save_blend(name)
print(f"[{name}] done")
if __name__ == "__main__":
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
for n in (args or list(BUILDERS)):
reset()
random.seed(hash(n) & 0xffff)
r = BUILDERS[n]() or {}
finish_x(n, r)