"""GRASS CUTTER - fourth pass over the robots: the mower robot, its dock, the Reaper and the bundle catcher.
SM_RobotMower rebuilt. A chubby green shell with a clean friendly face, a cutting deck with a blade disc that shows
through the open front, a galvanised clippings hopper with windows, lugged tyres, bumper, light bar,
antenna with a pennant. Body Lamp (as before) and parts for code to move:
SpinBlade blade disc, origin on its shaft, spins about local Z (Unity up).
BlinkEye_L/_R eye white + pupil, origin at the eye's centre, squash local Z to blink.
SwayAntenna mast, ball and pennant, origin at the foot of the mast.
Fill clippings in the hopper, origin on the hopper floor, scale local Z with the load.
Wheel_FL/FR/RL/RR origin on the axle, roll about local X. (L = the robot's left = Blender +X.)
SM_Reaper the stage-3 build with new crawler tracks (belt loop, shoes, sprocket, idler, bogie road wheels),
a cleaner header (knife guards, sickle bar, bevelled fangs), new exhausts, a light bar and a sensor head.
Body Lamp Reel Muzzle (as before) plus SpinSensor (radar head on a mast) and SwayWhip (whip aerial).
SM_RobotDock the stage-3 dock, tidied: a rigid duct on a gantry instead of the sagging hose, guide lamps round the
dish, chevrons into it, a solar panel on the lean-to. Body Lamp.
SM_BundleCatcher the stage-3 catcher with landing lamps on the net poles, a windsock (SwayWindsock) instead of the
flag, a level gauge and a tidier chute. Body.
The old builders run where a model is improved rather than rebuilt (see gc_up3_machines.patched): the parts named in a drop
list go, new parts are added before the Body is joined. Same pivots, forward axes and footprints as before.
Authored in Blender space: metres, Z up, front = -Y (Unity +Z), Unity +X = Blender -X.
Run: blender -b --factory-startup --python D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_up4_robots.py -- [names]
GC_VIEWS=
also renders review angles there with back faces culled, as Unity shows them.
Writes the FBX and the preview only (no .blend).
"""
import sys, os, zlib
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import common
import gc_up_machines as MA
import gc_up_production as PR
import gc_up3_machines as U3
from gc_up3_machines import * # noqa: F401,F403
TAU = 2 * PI
def rsec(y, hw, z0, z1, rt, rb, n=3, grow=0.0):
"""Rounded-rectangle section across X at y: top corners radius rt, bottom rb."""
pts = []
for (cx_, cz_, r, a0) in ((hw - rb, z0 + rb, rb, -90), (hw - rt, z1 - rt, rt, 0), (-hw + rt, z1 - rt, rt, 90), (-hw + rb, z0 + rb, rb, 180)):
for i in range(n + 1):
a = math.radians(a0 + 90 * i / n)
pts.append((cx_ + (r + grow) * math.cos(a), y, cz_ + (r + grow) * math.sin(a)))
return pts
def part(G, name, origin, ang=40):
"""Join G into a loose named part with its origin at `origin`."""
o = pfin(G, name, ang=ang)
set_origin(o, origin)
return o
def lerp_sec(S, y):
for a, b in zip(S, S[1:]):
if a[0] <= y <= b[0]:
t = (y - a[0]) / (b[0] - a[0])
return tuple(a[i] + (b[i] - a[i]) * t for i in range(6))
return S[0] if y < S[0][0] else S[-1]
# ======================================================================= the mower robot
def robot_mower():
P, L = [], []
# shell sections: y, half width, bottom, top, top radius, bottom radius. The face is the flat front at y = -.775
S = [(-.685, .33, .20, .64, .11, .07), (-.66, .375, .17, .69, .14, .08), (-.60, .415, .15, .74, .17, .09),
(-.45, .44, .14, .78, .19, .09), (-.15, .435, .14, .77, .19, .09), (.08, .42, .15, .74, .17, .09), (.17, .39, .17, .69, .14, .08)]
P.append(loft([rsec(*s, n=4) for s in S], "P_GRN", name="shell"))
# panel seams: dark rings round the shell where the face module and the tail meet it
for y in (-.53, .03):
s = lerp_sec(S, y)
P.append(loft([rsec(y - .007, *s[1:], n=4, grow=.004), rsec(y + .007, *s[1:], n=4, grow=.004)], "P_GRND", name="seam"))
# the cream stripe over the top, like the tractor's, and a pinstripe waistline along the flanks
top = [(y, lerp_sec(S, y)[3]) for y in (-.55, -.45, -.3, -.15, .0, .08, .14)]
P.append(px([(y, z + .009) for (y, z) in top] + [(y, z - .02) for (y, z) in reversed(top)], -.075, .075, "P_WHITE", name="stripe"))
W = []
for y in (-.58, -.45, -.15, .08, .16):
hw = lerp_sec(S, y)[1] + .005
W.append([(-hw, y, .295), (hw, y, .295), (hw, y, .325), (-hw, y, .325)])
P.append(loft(W, "P_WHITE", name="waistline"))
# ------------------------------------------------ the face
FY = -.685
for s in (-1, 1):
ex, ez = s * .165, .45
P.append(cy("socket", .138, FY - .016, FY + .01, ex, ez, "P_GRND", v=24))
P.append(cy("sockback", .121, FY - .021, FY - .016, ex, ez, "P_BLACK", v=24))
# brows: a soft arch, the outer end a touch lower, so it looks keen rather than cross
br = []
for k in range(7):
t = -1 + 2 * k / 6
br.append((ex + s * t * .1, FY - .012, .615 + .022 * (1 - t * t) - .012 * t))
P.append(ptube("brow", br, .017, "P_GRND", segs=6))
# the eye: a white with a big dark pupil and two glints. One object per eye, squashed on Z to blink
E = [cy("white", .114, FY - .033, FY - .02, ex, ez, "M_Emissive", v=24),
cy("iris", .064, FY - .037, FY - .033, ex - s * .012, ez - .006, "P_CELLD", v=20),
cy("pupil", .042, FY - .040, FY - .036, ex - s * .012, ez - .006, "P_BLACK", v=16),
cy("glint", .02, FY - .043, FY - .039, ex - s * .012 + .024, ez + .022, "P_WHITE", v=10),
cy("glint", .009, FY - .043, FY - .039, ex - s * .012 - .02, ez - .03, "P_WHITE", v=8)]
part(E, "BlinkEye_L" if s > 0 else "BlinkEye_R", (ex, FY - .03, ez), ang=60)
# the smile: an open D, the corners turned up, a tongue in it, dimples at its ends
def zl(x):
u = (x / .125) ** 2
return .29 - .075 * (1 - u) + .03 * u
def zu(x):
return .292 + .03 * (x / .125) ** 2
xs = [-.125 + .25 * k / 12 for k in range(13)]
mouth = [(x, zu(x)) for x in xs] + [(x, zl(x)) for x in reversed(xs[1:-1])]
P.append(py(mouth, FY - .009, FY + .004, "P_BLACK", name="mouth"))
tx = [-.055 + .11 * k / 8 for k in range(9)]
tongue = [(x, zl(x) + .008) for x in tx] + [(x, zl(0) + .008 + .042 * math.sqrt(max(0.0, 1 - (x / .055) ** 2))) for x in reversed(tx[1:-1])]
P.append(py(tongue, FY - .012, FY - .009, "P_TERRA", name="tongue"))
for s in (-1, 1):
P.append(cy("dimple", .014, FY - .006, FY + .004, s * .148, .33, "P_GRND", v=8))
P.append(cy("cheek", .036, FY - .004, FY + .004, s * .245, .275, "P_TERRA", v=12))
# ------------------------------------------------ light bar on the brow, star badge on the bonnet
P.append(bx(-.24, .24, -.57, -.49, .745, .80, "P_BLACK", bev=.012, name="lightbar"))
for s in (-1, 1):
P.append(bx(s * .2 - .016, s * .2 + .016, -.53, -.49, .71, .75, "P_G1", bev=0, name="lightfoot"))
P.append(bx(s * .14 - .055, s * .14 + .055, -.582, -.565, .752, .793, "P_G2", bev=.006, name="lampbez"))
L.append(bx(s * .14 - .045, s * .14 + .045, -.587, -.578, .759, .786, "M_Emissive", bev=0, name="lamp"))
L.append(bx(-.03, .03, -.578, -.57, .76, .785, "M_LightAmber", bev=0, name="lamp"))
# ------------------------------------------------ chassis, axles, fenders, wheels
P.append(bx(-.34, .34, -.68, .64, .09, .22, "P_DGREY", bev=.02, name="chassis"))
WF, WR = (.5, -.44, .14, .14, .09), (.5, .40, .19, .19, .10)
for (x, y, z, R, Wd) in (WF, WR):
for s in (-1, 1):
P.append(cx("axle", .028, min(s * .3, s * (x - .02)), max(s * .3, s * (x - .02)), y, z, "P_G1", v=8))
MA.fender(P, s, y, z, R + .025, x - .055, x + .06, a0=172, a1=8, n=7, t=.03, m="P_GRN", band="P_WHITE")
P.append(sb(s, x - .06, x - .03, y - .05, y + .05, z + R * .45, z + R + .03, "P_GRND", name="fenderstay"))
for (x, y, z, R, Wd), tag in ((WF, "F"), (WR, "R")):
MA.wheel("Wheel_%sL" % tag, (x, y, z), R, Wd, out=1, lugs=10 if tag == "F" else 12, sides=16, rs=12, bolts=4, rim="P_WHITE")
MA.wheel("Wheel_%sR" % tag, (-x, y, z), R, Wd, out=-1, lugs=10 if tag == "F" else 12, sides=16, rs=12, bolts=4, rim="P_WHITE")
# amber side markers on the front fenders
for s in (-1, 1):
L.append(sb(s, .53, .565, -.62, -.585, .2, .235, "M_LightAmber", name="marker"))
# ------------------------------------------------ the cutting deck: open at the front so the blade shows, a rubber
# bumper round its front edge
DC, DR = (0, -.495), .335
# the deck plate stops at a chord in front of the face: the front is a grille over the blade, it shows from above
YC = -.66
ac = math.degrees(math.asin((YC - DC[1]) / (DR + .005)))
arcp = [((DR + .005) * math.cos(math.radians(ac + (180 - 2 * ac) * i / 16)), DC[1] + (DR + .005) * math.sin(math.radians(ac + (180 - 2 * ac) * i / 16))) for i in range(17)]
P.append(pz(arcp, .128, .155, "P_G2", name="decktop"))
P.append(bx(-.28, .28, YC - .012, YC + .01, .125, .16, "P_G1", bev=0, name="deckchord"))
for y in (-.745,):
hw = math.sqrt(max(0.0, DR * DR - (y - DC[1]) ** 2))
P.append(bx(-hw, hw, y - .009, y + .009, .14, .158, "P_G4", bev=0, name="grille"))
P.append(bx(-.009, .009, -.825, YC, .14, .158, "P_G4", bev=0, name="grille"))
P.append(cz("deckdome", .19, .155, .19, DC[0], DC[1] + .1, "P_G3", v=16, r2=.13))
P.append(revm("deckskirt", [(DR - .02, .035), (DR + .005, .035), (DR + .005, .135), (DR - .02, .135)], "P_G2", segs=18, loc=(DC[0], DC[1], 0), closed=True, a0=-42, a1=222))
P.append(revm("decklip", [(DR + .005, .035), (DR + .013, .035), (DR + .013, .065), (DR + .005, .065)], "P_ORANGE", segs=18, loc=(DC[0], DC[1], 0), closed=True, a0=-42, a1=222))
for a in (-42, 222): # posts close the cut ends of the skirt
c, s_ = math.cos(math.radians(a)), math.sin(math.radians(a))
P.append(cz("deckpost", .022, .03, .14, DC[0] + c * (DR - .007), DC[1] + s_ * (DR - .007), "P_G1", v=8))
BA0, BA1 = -152, -28
P.append(revm("bumper", [(DR + .004, .125), (DR + .03, .125), (DR + .03, .195), (DR + .004, .195)], "P_BLACK", segs=12, loc=(DC[0], DC[1], 0), closed=True, a0=BA0, a1=BA1))
for a in (BA0, BA1):
c, s_ = math.cos(math.radians(a)), math.sin(math.radians(a))
P.append(cz("bumperend", .016, .125, .195, DC[0] + c * (DR + .017), DC[1] + s_ * (DR + .017), "P_BLACK", v=8))
for a in (-120, -60):
c, s_ = math.cos(math.radians(a)), math.sin(math.radians(a))
P.append(xf(bx(-.03, .03, -.004, .004, .145, .175, "P_ORANGE", bev=0, name="reflector"), rz=math.radians(a) + PI / 2, t=(DC[0] + c * (DR + .032), DC[1] + s_ * (DR + .032), 0)))
for a in (-90,):
c, s_ = math.cos(math.radians(a)), math.sin(math.radians(a))
P.append(xf(bx(-.09, .09, -.004, .004, .148, .172, "P_G4", bev=0, name="bumperplate"), rz=math.radians(a) + PI / 2, t=(DC[0] + c * (DR + .032), DC[1] + s_ * (DR + .032), 0)))
# the blade disc: steel plate, red hub, three swing blades with lifted tips and orange paint. Origin on the shaft
BZ = .095
G = [cz("disc", .245, BZ - .008, BZ + .008, DC[0], DC[1], "P_G4", v=24),
cz("hub", .075, BZ + .008, BZ + .03, DC[0], DC[1], "P_RED", v=12),
cz("nut", .03, BZ + .03, BZ + .045, DC[0], DC[1], "P_G4", v=6)]
for k in range(3):
a = TAU * k / 3
bl = [(.1, -.03), (.27, -.032), (.31, -.014), (.31, .028), (.1, .03)]
o = pz(bl, BZ - .02, BZ - .008, "P_G5", name="blade")
G.append(xf(o, rz=a, t=(DC[0], DC[1], 0)))
w = pz([(.245, .0), (.31, .0), (.31, .028), (.245, .028)], BZ - .008, BZ + .014, "P_ORANGE", name="wing")
G.append(xf(w, rz=a, t=(DC[0], DC[1], 0)))
G.append(xf(cz("pin", .015, BZ + .008, BZ + .02, .13, 0, "P_G1", v=6), rz=a, t=(DC[0], DC[1], 0)))
G.append(xf(bx(.08, .235, -.024, .024, BZ + .008, BZ + .014, "P_ORANGE", bev=0, name="paint"), rz=a + PI / 3, t=(DC[0], DC[1], 0)))
part(G, "SpinBlade", (DC[0], DC[1], BZ), ang=30)
for (x, y, az) in ((-.27, -.72, -2.2), (.28, -.71, -1.0)):
tuft(P, x, y, .04, L=.07, n=3, m="M_Clippings", r=.006, az=az)
# ------------------------------------------------ the hopper: galvanised, a window each side, a rolled green rim
X0, Y0, Y1, Z0, Z1 = .36, .17, .66, .22, .66
P.append(bx(-X0, X0, Y0, Y1, Z0, Z0 + .04, "P_G1", bev=0, name="hopfloor"))
P.append(bx(-X0, X0, Y1 - .03, Y1, Z0, Z1, "P_G4", bev=.006, name="hopback"))
P.append(bx(-X0, X0, Y0, Y0 + .03, Z0, Z1, "P_G4", bev=.006, name="hopfront"))
WY0, WY1, WZ0, WZ1 = .27, .56, .33, .56
for s in (-1, 1):
x0, x1 = X0 - .03, X0
P.append(sb(s, x0, x1, Y0, Y1, Z0, WZ0, "P_G4", name="hopside"))
P.append(sb(s, x0, x1, Y0, Y1, WZ1, Z1, "P_G4", name="hopside"))
P.append(sb(s, x0, x1, Y0, WY0, WZ0, WZ1, "P_G4", name="hopside"))
P.append(sb(s, x0, x1, WY1, Y1, WZ0, WZ1, "P_G4", name="hopside"))
P.append(sb(s, X0 - .02, X0 - .012, WY0, WY1, WZ0, WZ1, "M_PackGlass", name="window"))
for (a0, a1, b0, b1) in ((WY0 - .02, WY1 + .02, WZ0 - .02, WZ0), (WY0 - .02, WY1 + .02, WZ1, WZ1 + .02), (WY0 - .02, WY0, WZ0, WZ1), (WY1, WY1 + .02, WZ0, WZ1)):
P.append(sb(s, X0, X0 + .012, a0, a1, b0, b1, "P_BLACK", name="gasket"))
# corner ribs and the rim
for y in (Y0 + .01, Y1 - .01):
P.append(sb(s, X0 - .015, X0 + .015, y - .02, y + .02, Z0, Z1, "P_G2", name="hoprib"))
P.append(sb(s, X0 - .02, X0 + .016, Y0 - .016, Y1 + .016, Z1, Z1 + .035, "P_GRN", bev=.006, name="hoprim"))
for y in (WY0 + .05, WY1 - .05):
for z in (Z0 + .05, Z1 - .04):
bolt(P, (s * (X0 + .002), y, z), (s, 0, 0), r=.009, m="P_G2")
decal(P, (s * (X0 + .016), (WY0 + WY1) / 2, .265), .17, .068, (s, 0, 0), R_52)
P.append(bx(-X0 - .016, X0 + .016, Y1 - .02, Y1 + .016, Z1, Z1 + .035, "P_GRN", bev=.006, name="hoprim"))
P.append(bx(-X0 - .016, X0 + .016, Y0 - .016, Y0 + .02, Z1, Z1 + .035, "P_GRN", bev=.006, name="hoprim"))
# the back: a dump door outlined in a seam, a latch, tail lamps, a rubber buffer
P.append(bx(-.26, .26, Y1, Y1 + .008, .3, .6, "P_G3", bev=0, name="door"))
P.append(bx(-.05, .05, Y1 + .008, Y1 + .026, .53, .565, "P_G1", bev=0, name="latch"))
star_badge(P, (0, Y1 + .01, .42), .13, (0, 1, 0))
P.append(bx(-.2, .2, Y1, Y1 + .02, .24, .29, "P_BLACK", bev=.006, name="buffer"))
for s in (-1, 1):
P.append(sb(s, .27, .34, Y1, Y1 + .016, .52, .6, "P_BLACK", name="tailbez"))
L.append(sb(s, .28, .33, Y1 + .016, Y1 + .024, .53, .59, "M_LightRed", name="tail"))
P.append(sb(s, .18, .22, Y1, Y1 + .014, .3, .6, "P_G1", name="hinge"))
rust(P, (.2, Y1 + .009, .36), .07, .05, (0, 1, 0), heart=False)
rust(P, (-.36, .43, Z0 + .03), .1, .04, (-1, 0, 0), heart=False)
MA.fill(-X0 + .035, X0 - .035, Y0 + .035, Y1 - .035, Z0 + .04, Z1 + .02, lump=.05, nx=6, ny=5, name="Fill")
# ------------------------------------------------ the top: a vent hatch, a grab handle, the status lamp
P.append(loft([[(-.17, y_, z_ - .02), (.17, y_, z_ - .02), (.17, y_, z_ + .01), (-.17, y_, z_ + .01)] for (y_, z_) in ((-.12, .775), (.08, .745))], "P_GRND", name="hatch"))
for k in range(4):
y_ = -.095 + k * .05
P.append(bx(-.12, .12, y_, y_ + .022, .768 - k * .007, .778 - k * .007, "P_BLACK", bev=0, name="louvre"))
for sx in (-1, 1):
for y_ in (-.105, .065):
bolt(P, (sx * .15, y_, .775 - (y_ + .1) * .15), (0, 0, 1), r=.008, m="P_G2")
P.append(ptube("handle", [(-.16, .13, .7), (-.16, .15, .78), (.16, .15, .78), (.16, .13, .7)], .013, "P_G1", segs=6))
P.append(cz("ledbase", .03, .74, .76, -.28, .02, "P_BLACK", v=10))
L.append(cz("led", .02, .76, .775, -.28, .02, "M_LightGreen", v=10, r2=.012))
# ------------------------------------------------ the antenna on a bracket at the back corner, its pennant trailing
AX, AY, AZ = .395, .5, .6
P.append(sb(1, .36, .42, AY - .03, AY + .03, AZ - .1, AZ, "P_G1", name="aerialbracket"))
A = [cz("aerialfoot", .026, AZ, AZ + .05, AX, AY, "P_BLACK", v=8),
cz("aerial", .008, AZ + .05, 1.11, AX, AY, "P_G4", v=6),
sphere("aerialball", .022, (AX, AY, 1.125), seg=8, rings=5, m="P_ORANGE"),
px([(AY + .012, 1.1), (AY + .19, 1.045), (AY + .012, .97)], AX - .006, AX + .006, "P_RED", name="pennant"),
px([(AY + .012, 1.055), (AY + .11, 1.048), (AY + .11, 1.028), (AY + .012, 1.02)], AX - .008, AX + .008, "P_WHITE", name="pennantband")]
part(A, "SwayAntenna", (AX, AY, AZ), ang=40)
pfin(P, "Body", ang=38)
pfin(L, "Lamp", ang=50)
return dict(elev=20, azim=-35)
# ======================================================================= the Reaper
def track_band(outer, inner, x0, x1, m, name="belt"):
"""A closed belt loop: outer and inner (y, z) outlines of the same length, extruded across x0..x1."""
bm = bmesh.new()
n = len(outer)
o0, o1, i0, i1 = [[bm.verts.new((x, y, z)) for (y, z) in ring] for ring in (outer, inner) for x in (x0, x1)]
for k in range(n):
j = (k + 1) % n
bm.faces.new((o0[k], o0[j], o1[j], o1[k]))
bm.faces.new((i0[k], i1[k], i1[j], i0[j]))
bm.faces.new((o0[k], i0[k], i0[j], o0[j]))
bm.faces.new((o1[k], o1[j], i1[j], i1[k]))
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
o = mesh_obj(name, bm)
set_mats(o, m)
return o
def walk(outline, N):
"""N evenly spaced points round a closed outline: (point, tangent, outward normal)."""
L = [0.0]
for a, b in zip(outline, outline[1:] + outline[:1]):
L.append(L[-1] + math.hypot(b[0] - a[0], b[1] - a[1]))
c = Vector((sum(p[0] for p in outline) / len(outline), sum(p[1] for p in outline) / len(outline)))
out = []
for k in range(N):
d = L[-1] * k / N
i = max(j for j in range(len(outline)) if L[j] <= d)
a, b = Vector(outline[i]), Vector(outline[(i + 1) % len(outline)])
t = (d - L[i]) / max(1e-6, L[i + 1] - L[i])
p = a.lerp(b, t)
tg = (b - a).normalized()
nr = Vector((-tg.y, tg.x))
if nr.dot(p - c) < 0:
nr = -nr
out.append((p, tg, nr))
return out
def gear_prof(cy_, cz_, R0, R1, teeth):
pts = []
for k in range(teeth):
a = TAU * k / teeth
for (da, r) in ((-.42, R0), (-.2, R1), (.2, R1), (.42, R0)):
aa = a + da * TAU / teeth
pts.append((cy_ + r * math.cos(aa), cz_ + r * math.sin(aa)))
return pts
def disc_x(P, name, r, xa, xb, y, z, m, v=16):
P.append(cx(name, r, min(xa, xb), max(xa, xb), y, z, m, v=v))
def reaper_tracks(P):
"""Crawler tracks with their works showing: a belt loop of shoes, a toothed drive sprocket at the back, a spoked idler
at the front, four road wheels on trailing arms, and a dark frame plate behind them all."""
SP, IDL = (1.48, .52, .47), (-.90, .47, .42)
T = .07
outer = arc(SP[0], SP[1], SP[2], -90, 90, 12) + arc(IDL[0], IDL[1], IDL[2], 90, 270, 12)
inner = arc(SP[0], SP[1], SP[2] - T, -90, 90, 12) + arc(IDL[0], IDL[1], IDL[2] - T, 90, 270, 12)
for s in (-1, 1):
def X(a):
return s * a
P.append(track_band(outer, inner, min(X(.98), X(1.44)), max(X(.98), X(1.44)), "P_BLACK", name="belt"))
# shoes: a grouser bar on each link, link plates either side of it
for (p, tg, nr) in walk(outer, 44):
q = [tuple(p - tg * .045), tuple(p + tg * .045), tuple(p + tg * .03 + nr * .045), tuple(p - tg * .03 + nr * .045)]
P.append(px(q, min(X(.965), X(1.455)), max(X(.965), X(1.455)), "P_DGREY", name="shoe"))
q = [tuple(p - tg * .05 - nr * .002), tuple(p + tg * .05 - nr * .002), tuple(p + tg * .05 + nr * .012), tuple(p - tg * .05 + nr * .012)]
for (a, b) in ((.97, 1.03), (1.39, 1.45)):
P.append(px(q, min(X(a), X(b)), max(X(a), X(b)), "P_G1", name="link"))
# the frame plate inside the loop, so you see works and not the hull through it
fr = arc(SP[0], SP[1], SP[2] - T - .02, -90, 90, 8) + arc(IDL[0], IDL[1], IDL[2] - T - .02, 90, 270, 8)
P.append(px(fr, min(X(1.02), X(1.06)), max(X(1.02), X(1.06)), "P_DGREY", name="frameplate"))
# drive sprocket: two toothed plates on a drum, a red hub, a ring of nuts
g = gear_prof(SP[0], SP[1], SP[2] - T - .055, SP[2] - T - .005, 13)
for (a, b) in ((1.08, 1.12), (1.33, 1.37)):
P.append(px(g, min(X(a), X(b)), max(X(a), X(b)), "P_G2", name="sprocket"))
disc_x(P, "sprocketdrum", .26, X(1.12), X(1.33), SP[0], SP[1], "P_G1", v=16)
disc_x(P, "sprockethub", .15, X(1.37), X(1.41), SP[0], SP[1], "P_RED", v=12)
disc_x(P, "sprocketcap", .07, X(1.41), X(1.44), SP[0], SP[1], "P_G4", v=8)
for k in range(6):
a = TAU * k / 6
P.append(cx("nut", .016, min(X(1.41), X(1.425)), max(X(1.41), X(1.425)), SP[0] + .11 * math.cos(a), SP[1] + .11 * math.sin(a), "P_G4", v=6))
# idler: a holed steel wheel with a rubber tyre, a tension rod back to the bogie beam
ri = IDL[2] - T - .005
disc_x(P, "idlertyre", ri, X(1.1), X(1.38), IDL[0], IDL[1], "P_BLACK", v=18)
disc_x(P, "idlerface", ri - .045, X(1.38), X(1.395), IDL[0], IDL[1], "P_G4", v=18)
for k in range(5):
a = TAU * k / 5 + .3
disc_x(P, "idlerhole", .055, X(1.395), X(1.4), IDL[0] + .19 * math.cos(a), IDL[1] + .19 * math.sin(a), "P_BLACK", v=8)
disc_x(P, "idlerhub", .1, X(1.395), X(1.43), IDL[0], IDL[1], "P_RED", v=10)
disc_x(P, "idlercap", .045, X(1.43), X(1.45), IDL[0], IDL[1], "P_G4", v=6)
P.append(beam((X(1.24), IDL[0] + .12, IDL[1] + .02), (X(1.24), -.3, .56), .06, .07, m="P_G1", bev=.006, name="tensioner"))
P.append(beam((X(1.24), -.3, .56), (X(1.24), 1.1, .56), .09, .1, m="P_DGREY", bev=.008, name="bogiebeam"))
# four road wheels on trailing arms
for y in (-.36, .03, .42, .81):
z = .12 + .155
P.append(beam((X(1.22), y, z), (X(1.22), y + .2, .54), .05, .06, m="P_G1", bev=.006, name="arm"))
disc_x(P, "roadtyre", .155, X(1.27), X(1.4), y, z, "P_BLACK", v=16)
disc_x(P, "roadrim", .122, X(1.4), X(1.418), y, z, "P_G4", v=14)
disc_x(P, "roadhub", .06, X(1.418), X(1.44), y, z, "P_RED", v=8)
for k in range(4):
a = TAU * k / 4 + PI / 4
P.append(cx("nut", .011, min(X(1.415), X(1.428)), max(X(1.415), X(1.428)), y + .078 * math.cos(a), z + .078 * math.sin(a), "P_G4", v=6))
rust(P, (X(1.457), -.6, .35), .2, .1, (s, 0, 0), heart=False)
def reaper_header(P):
"""Cleaner jaws: a pan, a sickle bar with its knife sections, pointed knife guards, bevelled fangs under the lip."""
HX = 1.44
P.append(pz([(-HX, -1.26), (HX, -1.26), (HX, -1.86), (-HX, -1.86)], .02, .05, "P_G2", name="pan"))
P.append(bx(-HX, HX, -1.9, -1.83, .045, .075, "P_G1", bev=.006, name="sicklebar"))
n = 16
for k in range(n):
x = -HX + .09 + (2 * HX - .18) * k / (n - 1)
base = [(x - .05, -1.86, .03), (x + .05, -1.86, .03), (x + .05, -1.86, .1), (x - .05, -1.86, .1)]
mid = [(x - .032, -1.94, .04), (x + .032, -1.94, .04), (x + .032, -1.94, .085), (x - .032, -1.94, .085)]
tip = [(x - .008, -1.997, .055), (x + .008, -1.997, .055), (x + .008, -1.997, .065), (x - .008, -1.997, .065)]
P.append(loft([base, mid, tip], "P_G4", name="guard"))
P.append(bx(x - .04, x + .04, -1.92, -1.88, .07, .076, "P_BLACK", bev=0, name="slot"))
if k < n - 1:
xm = x + (2 * HX - .18) / (n - 1) / 2
P.append(pz([(xm - .06, -1.84), (xm + .06, -1.84), (xm, -1.92)], .075, .082, "P_G5", name="section"))
for k in range(15):
x = -HX + .1 + (2 * HX - .2) * k / 14
h = .12 if k % 2 == 0 else .09
top = [(x - .07, -1.795, .63), (x + .07, -1.795, .63), (x + .07, -1.74, .63), (x - .07, -1.74, .63)]
mid = [(x - .04, -1.79, .63 - h * .55), (x + .04, -1.79, .63 - h * .55), (x + .03, -1.75, .63 - h * .55), (x - .03, -1.75, .63 - h * .55)]
tip = [(x - .006, -1.785, .63 - h), (x + .006, -1.785, .63 - h), (x + .006, -1.775, .63 - h), (x - .006, -1.775, .63 - h)]
P.append(loft([top, mid, tip], "P_G5", name="fang"))
P.append(bx(-HX, HX, -1.81, -1.73, .62, .65, "P_G1", bev=.006, name="fangbar"))
for k in range(8):
bolt(P, (-HX + .18 + (2 * HX - .36) * k / 7, -1.812, .635), (0, -1, 0), r=.012, m="P_G3")
def reaper_exhausts(P):
"""Mufflers, stacks with a perforated heat shield on the outboard side, soot at the lip, a rain flap propped open."""
for s in (-1, 1):
x, y = s * .74, 1.62
P.append(cz("muffler", .12, 1.22, 1.46, x, y, "P_G2", v=12))
P.append(cz("mufband", .126, 1.3, 1.33, x, y, "P_G1", v=12))
P.append(cz("pipe", .068, 1.46, 1.9, x, y, "P_G1", v=10))
a0, a1 = (-80, 80) if s > 0 else (100, 260)
P.append(revm("heatshield", [(.084, 1.5), (.09, 1.5), (.09, 1.8), (.084, 1.8)], "P_G4", segs=6, loc=(x, y, 0), closed=True, a0=a0, a1=a1))
for z in (1.56, 1.62, 1.68, 1.74):
P.append(sb(s, .74 + .088, .74 + .094, y - .03, y + .03, z - .016, z + .016, "P_BLACK", name="perf"))
P.append(cz("sootring", .072, 1.88, 1.92, x, y, "P_BLACK", v=10))
flap = cz("flap", .08, -.005, .005, 0, -.08, "P_G2", v=10)
P.append(xf(flap, rx=math.radians(55), t=(x, y + .07, 1.925)))
P.append(cx("flaphinge", .014, x - .03, x + .03, y + .07, 1.925, "P_G1", v=6))
def reaper_lights(P):
"""A light bar over the visor: four amber lenses in a black housing on two brackets."""
P.append(bx(-.56, .56, -1.25, -1.15, 1.205, 1.29, "P_BLACK", bev=.014, name="lightbar"))
for x in (-.42, -.14, .14, .42):
P.append(cy("lensbez", .045, -1.262, -1.25, x, 1.247, "P_G2", v=12))
P.append(cy("lens", .036, -1.268, -1.262, x, 1.247, "M_LightAmber", v=12))
for s in (-1, 1):
P.append(sb(s, .3, .36, -1.16, -1.06, 1.19, 1.25, "P_G1", name="barfoot"))
def reaper():
def add(P):
reaper_tracks(P)
reaper_header(P)
reaper_exhausts(P)
reaper_lights(P)
# the sensor mast on the nose; its head is a loose part
P.append(cz("mastfoot", .1, 1.28, 1.35, 0, -.8, "P_G1", v=12))
P.append(cz("mast", .045, 1.35, 1.6, 0, -.8, "P_G2", v=10))
P.append(cz("mastcollar", .07, 1.58, 1.62, 0, -.8, "P_G1", v=10))
for k in range(3):
a = TAU * k / 3 + PI / 2
P.append(cyl_between("maststay", (.16 * math.cos(a), -.8 + .16 * math.sin(a), 1.3), (.04 * math.cos(a), -.8 + .04 * math.sin(a), 1.5), .012, "P_G1", v=5))
patched(MA, "pfin", U3.reaper, drop=("track", "grouser", "roadwheel", "roadhub", "fang", "lowerjaw", "stack", "stackrim", "stackguard", "whip", "rag"), add=add)
# the sensor head: a squat red dome with a red eye and a little dish, spun about Z while it mows
H = (0, -.8, 1.62)
G = [revm("dome", [(.0, 0), (.17, 0), (.18, .05), (.16, .13), (.1, .19), (0, .21)], ["P_G1", "P_RED", "P_RED", "P_RED", "P_RED"], segs=16, loc=H),
cz("domering", .185, H[2] + .045, H[2] + .065, H[0], H[1], "P_G1", v=16),
cy("eyebez", .07, H[1] - .19, H[1] - .12, H[0], H[2] + .1, "P_BLACK", v=12),
cy("eye", .05, H[1] - .198, H[1] - .19, H[0], H[2] + .1, "M_LightRed", v=12),
cz("dishpost", .015, H[2] + .2, H[2] + .28, H[0], H[1] + .05, "P_G2", v=6),
xf(revm("dish", [(0, 0), (.07, .015), (.11, .05), (.1, .055), (.065, .022), (0, .01)], "P_G4", segs=10), rx=math.radians(-60), t=(H[0], H[1] + .05, H[2] + .28))]
part(G, "SpinSensor", H, ang=40)
# the whip aerial with its rag, swaying from its foot
G = [cz("whip", .012, 1.44, 2.18, .86, 1.84, "P_BLACK", v=5),
cz("whipfoot", .03, 1.44, 1.5, .86, 1.84, "P_G1", v=8),
py([(.86, 2.17), (1.06, 2.14), (1.2, 2.16), (1.13, 2.09), (1.2, 2.03), (1.06, 2.02), (.86, 1.97)], 1.834, 1.846, "P_BLACK", name="rag")]
part(G, "SwayWhip", (.86, 1.84, 1.44), ang=40)
return dict(elev=22, azim=-40)
# ======================================================================= the dock
def dock():
TOP, R = .16, 1.16
Yf, Yb, Zf, Zb = .52, 1.42, 1.56, 1.94
def roofz(y):
return Zf + (Zb - Zf) * (y - Yf) / (Yb - Yf)
def add(P):
# a rigid galvanised duct instead of the sagging hose: up out of the funnel, along under a steel gantry, down to a
# nozzle over the dish, where the robot's hopper empties
D = soft([(0, -1.25, 1.28), (0, -1.2, 1.5), (0, -1.0, 1.52), (0, -.62, 1.52), (0, -.46, 1.44), (0, -.42, 1.2)], 2)
P.append(ptube("duct", D, .085, "P_G4", segs=8))
for i in range(2, len(D) - 1, 3):
d = (Vector(D[i + 1]) - Vector(D[i - 1])).normalized()
P.append(cyl_between("ductband", Vector(D[i]) - d * .016, Vector(D[i]) + d * .016, .097, "P_G2", v=8))
P.append(cz("nozzle", .1, 1.04, 1.2, 0, -.42, "P_G2", v=10, r2=.088))
P.append(cz("nozzletip", .108, .98, 1.04, 0, -.42, "P_ORANGE", v=10))
P.append(cz("nozzledark", .09, .975, .985, 0, -.42, "P_BLACK", v=10))
P.append(beam((0, Yf, 1.66), (0, -1.05, 1.66), .1, .1, m="P_G1", bev=.008, name="gantry"))
P.append(beam((0, Yf - .02, 1.3), (0, .05, 1.62), .06, .06, m="P_G1", bev=.006, name="gantrystay"))
for y in (-.95, -.7):
P.append(bx(-.1, .1, y - .02, y + .02, 1.52, 1.62, "P_G2", bev=0, name="hanger"))
decal(P, (.052, -.4, 1.66), .26, .1, (1, 0, 0), R_52)
# guide lamps round the rim of the dish, a ring of studs the robot homes on
for k in range(12):
a = TAU * k / 12 + PI / 12
c, s = math.cos(a), math.sin(a)
P.append(cz("guidebase", .034, TOP + .024, TOP + .036, (R + .015) * c, (R + .015) * s, "P_BLACK", v=8))
P.append(cz("guide", .024, TOP + .036, TOP + .05, (R + .015) * c, (R + .015) * s, "M_LightGreen", v=8, r2=.016))
# gold arrows on the dish floor, pointing in at the contact
for k in range(4):
a = PI / 4 + k * PI / 2
P.append(arrow((.62 * math.cos(a), .62 * math.sin(a), .034), a + PI, s=.12, m="P_GOLD", t=.006))
# a solar panel on the lean-to: the dock tops itself up
Q = []
U3.sun_panel(Q, 0, 1.1, .78, 4, 3)
ang = math.atan2(Zb - Zf, Yb - Yf)
yc = .98
for o in Q:
if o is not None:
P.append(xf(o, rx=ang, t=(-.7, yc, roofz(yc) + .13 + .09)))
for x in (-1.15, -.25):
for y in (.7, 1.26):
P.append(cz("panelfoot", .02, roofz(y) + .14, roofz(y) + .2, x, y, IRON, v=6))
PR.conduit(P, [(-.2, 1.26, roofz(1.26) + .17), (-.1, 1.48, roofz(1.48) + .15), (-.1, 1.5, 1.3), (-.6, 1.5, 1.3)], r=.012)
patched(U3, "pfin", U3.dock, drop=("hose", "hoseband", "hosemouth", "boom", "boomstay", "boomstrap"), add=add)
return dict(elev=30, azim=-35)
# ======================================================================= the catcher
def catcher():
RN, ZN = 1.4, 3.28
def add(P):
# landing lamps on the three net poles, so a Reaper's shot has something to aim at in the dark
for a in (38, 90, 142):
c, s = math.cos(math.radians(a)), math.sin(math.radians(a))
P.append(cz("lampbase", .045, ZN + .035, ZN + .06, c * RN, s * RN, IRON, v=8))
P.append(sphere("landlamp", .056, (c * RN, s * RN, ZN + .1), seg=8, rings=5, m="M_LightAmber"))
P.append(cz("lampcap", .062, ZN + .148, ZN + .165, c * RN, s * RN, IRON, v=8))
# the windsock's pole in place of the flag's
P.append(beam((0, RN, ZN), (0, RN, 3.7), .045, .045, m=STL, bev=0, name="sockpole"))
P.append(cz("sockcap", .03, 3.7, 3.72, 0, RN, IRON, v=6))
# a sight gauge on the bin: a glass slot with the level showing, gold ticks beside it
x = .535
P.append(bx(x - .005, x + .02, -.12, .12, .8, 1.2, IRON, bev=0, name="gaugeframe"))
P.append(bx(x + .02, x + .028, -.07, .07, .84, 1.16, "M_PackGlass", bev=0, name="gaugeglass"))
P.append(bx(x + .012, x + .02, -.07, .07, .84, .98, "M_Clippings", bev=0, name="gaugefill"))
for k in range(5):
z = .86 + k * .07
P.append(bx(x + .02, x + .03, .075, .11, z - .006, z + .006, GOLD, bev=0, name="tick"))
# hazard paint on the chute's lip
haz(-.44, .44, .3, .42, 8, lambda out, col: P.append(loft([[(x_, -1.506, z_) for (x_, z_) in out], [(x_, -1.5, z_) for (x_, z_) in out]], col, name="liphaz")))
patched(U3, "pfin", U3.catcher, drop=("flagpole", "flag"), add=add)
# the windsock: a ring on a swivel and a tapering striped sock, swaying from the pole
H = (0, RN, 3.6)
G = [cz("swivel", .03, 3.56, 3.64, 0, RN, IRON, v=8),
cyl_between("sockarm", (0, RN, 3.6), (.08, RN, 3.6), .012, IRON, v=5)]
n = 5
for k in range(n):
x0, x1 = .08 + .1 * k, .08 + .1 * (k + 1)
r0, r1 = .085 - .011 * k, .085 - .011 * (k + 1)
o = cyl_between("sock", (x0, RN, 3.6 - .012 * k), (x1, RN, 3.6 - .012 * (k + 1)), r0, PRED if k % 2 == 0 else CRM, v=10, r2=r1, cap=False)
G.append(o)
G.append(torus("sockring", .085, .008, (.08, RN, 3.6), "X", seg=10, rseg=4, m=IRON))
o = part(G, "SwayWindsock", H, ang=40)
return dict(elev=25, azim=-35)
# ======================================================================= main
BUILDERS = {
"SM_RobotMower": robot_mower,
"SM_Reaper": reaper,
"SM_RobotDock": dock,
"SM_BundleCatcher": catcher,
}
VIEWS = (("a", 22, -38, .8, 520), ("b", 22, 142, .8, 520), ("c", 6, -10, .75, 520), ("d", 60, -30, .8, 520))
def export_preview(n, res):
common.export(n)
common.preview(n, **res)
def main():
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
vd = os.environ.get("GC_VIEWS")
if os.environ.get("GC_OUT"): # trial runs: FBX and preview go there instead of into the project
common.MODELS = common.PREVIEWS = os.environ["GC_OUT"]
for n in (args or list(BUILDERS)):
common.reset()
random.seed(zlib.crc32(n.encode()))
res = BUILDERS[n]() or {}
parts = {o.name: tri_count([o]) for o in bpy.context.scene.objects if o.type == "MESH"}
print(f"TRIS|{n}|{sum(parts.values())}|{parts}")
export_preview(n, res)
if vd:
for m in bpy.data.materials:
m.use_backface_culling = True
names = [o.name for o in bpy.context.scene.objects if o.type == "MESH"]
zmin = min((o.matrix_world @ Vector(c)).z for o in bpy.context.scene.objects if o.type == "MESH" for c in o.bound_box)
for tag, el, az, dm, res_ in VIEWS:
g = cube("ground", (60, 60, .02), (0, 0, zmin - .012), "M_Grass")
uv_box(g, .5)
g["preview_only"] = True
common.preview(os.path.join(vd, f"{n}_{tag}"), elev=el, azim=az, dist_mul=dm, res=res_, frame=names)
if __name__ == "__main__":
main()