"""GRASS CUTTER - the grass train. SM_TrainLoco a stubby green shunting locomotive with a red cab and a wide yellow cutter reel on its nose, 4.6 m long (nose at -Y), 2.1 m wide, 2.7 m to the cab roof. Body, plus Wheel0..Wheel5 (origin at the axle, axis Blender X), Reel (origin on its axle, axis X) and Lamp (the headlamp, M_LightAmber) SM_TrainWagon an open timber hopper wagon heaped with cut grass, 4.4 m long, 2.0 m wide, 2.1 m tall. Body, plus Wheel0..Wheel7 and Grass (the heap) SM_TrainStation the platform the train lives at, 4 x 8 m: two raised platforms either side of a gravel track bed down the middle (the train's own rails are laid over it by the game), a canopy on posts over the left one, a red buffer stop at the back (+Y), lamps and a sign board. Body Origin bottom centre at z = 0 (the wheels stand on z = 0, the top of the rails), front = -Y (Unity +Z), Unity +X = Blender -X. Run (absolute paths): blender -b --factory-startup --python D:/PROJECTS/GIT/grass-cutters/ArtSource/Blender/scripts/gc_train.py -- [names] """ import sys, os, math HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import common as C from mathutils import Vector GREEN, DGREEN, RED, CREAM, YELLOW = "M_PaintGreen", "M_PaintDarkGreen", "M_PaintRed", "M_PaintCream", "M_PaintYellow" STEEL, SOOT, RUBBER, GLASS, TIMB = "M_Steel", "M_Soot", "M_Rubber", "M_WindowGlass", "M_Timber" LAMP, GRASS, CONC, CONCL, HAZ = "M_LightAmber", "M_Clippings", "M_Sand", "M_Brick", "M_Hazard" ROOF, BRASS, DECK = "M_Roof", "M_Brass", "M_Deck" def wheel(name, x, y, r=0.38, w=0.16, hub=RED): """A flanged rail wheel on its own, origin on the axle so the game can turn it.""" rim = C.cyl(name + "_r", r, w, (x, y, r), axis="X", verts=28, bevel=0.02, m=STEEL) flange = C.cyl(name + "_f", r + 0.05, 0.04, (x - math.copysign(w * 0.5 - 0.02, x), y, r), axis="X", verts=28, m=STEEL) disc = C.cyl(name + "_h", r * 0.62, w + 0.03, (x, y, r), axis="X", verts=20, bevel=0.015, m=hub) cap = C.cyl(name + "_c", r * 0.2, w + 0.08, (x, y, r), axis="X", verts=12, m=BRASS) o = C.join([rim, flange, disc, cap], name) C.uv_box(o, 1.5) C.set_origin(o, (x, y, r)) C.smooth(o, 35) return o def loco(): parts = [] # running gear: frame, buffers, coupling parts.append(C.rbox("frame", (1.9, 4.3, 0.28), (0, 0, 0.62), bevel=0.04, m=SOOT)) parts.append(C.rbox("skirt", (2.05, 3.9, 0.2), (0, 0.1, 0.86), bevel=0.05, m=DGREEN)) for y in (-2.12, 2.12): for x in (-0.62, 0.62): parts.append(C.cyl("buf", 0.11, 0.24, (x, y + math.copysign(0.08, y), 0.66), axis="Y", verts=16, bevel=0.02, m=STEEL)) parts.append(C.cyl("bufp", 0.17, 0.05, (x, y + math.copysign(0.21, y), 0.66), axis="Y", verts=20, m=SOOT)) parts.append(C.rbox("beam", (1.95, 0.12, 0.3), (0, y, 0.66), bevel=0.03, m=RED)) # the long hood (engine) ahead of the cab, rounded and fat parts.append(C.rbox("hood", (1.5, 2.35, 1.05), (0, -0.85, 1.48), bevel=0.32, segs=5, m=GREEN)) parts.append(C.rbox("hoodband", (1.54, 2.38, 0.12), (0, -0.85, 1.12), bevel=0.05, m=CREAM)) for i in range(5): parts.append(C.rbox("louvre", (1.56, 0.06, 0.42), (0, -1.6 + i * 0.3, 1.5), bevel=0.02, m=DGREEN)) parts.append(C.cyl("stack", 0.15, 0.55, (0, -1.45, 2.2), verts=16, bevel=0.02, m=SOOT, r2=0.19)) parts.append(C.cyl("stacklip", 0.22, 0.07, (0, -1.45, 2.48), verts=16, m=SOOT)) parts.append(C.cyl("dome", 0.24, 0.22, (0, -0.55, 2.04), verts=20, bevel=0.06, m=BRASS)) # the cab parts.append(C.rbox("cab", (2.0, 1.55, 1.55), (0, 1.15, 1.72), bevel=0.12, segs=4, m=RED)) parts.append(C.rbox("roof", (2.25, 1.85, 0.16), (0, 1.15, 2.58), bevel=0.07, m=CREAM)) parts.append(C.rbox("roofcap", (1.7, 1.4, 0.12), (0, 1.15, 2.68), bevel=0.05, m=CREAM)) for x in (-1.0, 1.0): parts.append(C.rbox("win", (0.04, 0.85, 0.6), (x, 1.1, 2.05), bevel=0.04, m=GLASS)) parts.append(C.rbox("front_win_l", (0.62, 0.04, 0.55), (-0.5, 0.36, 2.08), bevel=0.04, m=GLASS)) parts.append(C.rbox("front_win_r", (0.62, 0.04, 0.55), (0.5, 0.36, 2.08), bevel=0.04, m=GLASS)) parts.append(C.rbox("back_win", (1.2, 0.04, 0.5), (0, 1.94, 2.08), bevel=0.04, m=GLASS)) parts.append(C.rbox("handrail", (0.05, 2.2, 0.05), (0.82, -0.85, 1.95), bevel=0.02, m=BRASS)) parts.append(C.rbox("handrail2", (0.05, 2.2, 0.05), (-0.82, -0.85, 1.95), bevel=0.02, m=BRASS)) # the cutter on the nose: a hood over a wide reel parts.append(C.rbox("cutarm_l", (0.12, 0.55, 0.12), (-1.0, -2.35, 0.7), bevel=0.03, m=SOOT)) parts.append(C.rbox("cutarm_r", (0.12, 0.55, 0.12), (1.0, -2.35, 0.7), bevel=0.03, m=SOOT)) parts.append(C.rbox("cuthood", (3.3, 0.6, 0.22), (0, -2.62, 0.72), bevel=0.08, m=YELLOW)) parts.append(C.rbox("cutlip", (3.3, 0.08, 0.3), (0, -2.9, 0.55), bevel=0.03, m=HAZ)) for x in (-1.62, 1.62): parts.append(C.rbox("cutend", (0.08, 0.6, 0.5), (x, -2.62, 0.5), bevel=0.03, m=YELLOW)) body = C.join(parts, "Body") C.uv_box(body, 1.0) C.smooth(body, 40) # the reel turns: its own object, origin on the axle blades = [C.cyl("reelcore", 0.09, 3.1, (0, -2.62, 0.38), axis="X", verts=12, m=STEEL)] for k in range(6): a = k * math.pi / 3 y, z = -2.62 + math.cos(a) * 0.2, 0.38 + math.sin(a) * 0.2 blades.append(C.rbox("blade", (3.05, 0.05, 0.05), (0, y, z), bevel=0.015, m=STEEL)) reel = C.join(blades, "Reel") C.uv_box(reel, 1.0) C.set_origin(reel, (0, -2.62, 0.38)) lamp = C.sphere("Lamp", 0.16, (0, -2.05, 1.82), seg=16, rings=8, m=LAMP) lamp_ring = C.cyl("lampring", 0.2, 0.08, (0, -1.98, 1.82), axis="Y", verts=16, m=BRASS) C.join([lamp_ring], "LampRing") wheels = [] for i, y in enumerate((-1.35, 0.0, 1.35)): for j, x in enumerate((-0.82, 0.82)): wheels.append(wheel(f"Wheel{i * 2 + j}", x, y, r=0.42)) for o in wheels + [reel, lamp]: o.parent = body return dict(elev=18, azim=-40) def wagon(): parts = [] parts.append(C.rbox("frame", (1.85, 4.2, 0.24), (0, 0, 0.6), bevel=0.04, m=SOOT)) for y in (-2.05, 2.05): for x in (-0.6, 0.6): parts.append(C.cyl("buf", 0.1, 0.22, (x, y + math.copysign(0.08, y), 0.62), axis="Y", verts=14, bevel=0.02, m=STEEL)) parts.append(C.cyl("bufp", 0.15, 0.05, (x, y + math.copysign(0.2, y), 0.62), axis="Y", verts=18, m=SOOT)) parts.append(C.rbox("beam", (1.9, 0.12, 0.26), (0, y, 0.62), bevel=0.03, m=RED)) for y in (-1.3, 1.3): parts.append(C.rbox("bogie", (1.75, 1.25, 0.3), (0, y, 0.42), bevel=0.06, m=SOOT)) # the tub: timber planks on a green frame, a little wider at the top parts.append(C.rbox("floor", (1.95, 3.9, 0.12), (0, 0, 0.8), bevel=0.03, m=TIMB)) for side in (-1, 1): for k in range(4): parts.append(C.rbox("plank", (0.08, 3.9, 0.24), (side * 0.98, 0, 0.98 + k * 0.26), bevel=0.03, m=TIMB)) for end in (-1, 1): for k in range(4): parts.append(C.rbox("plankE", (1.95, 0.08, 0.24), (0, end * 1.93, 0.98 + k * 0.26), bevel=0.03, m=TIMB)) for y in (-1.93, -0.65, 0.65, 1.93): for side in (-1, 1): parts.append(C.rbox("post", (0.12, 0.12, 1.12), (side * 1.0, y, 1.36), bevel=0.03, m=GREEN)) parts.append(C.rbox("rim_l", (0.14, 4.02, 0.1), (-1.0, 0, 1.95), bevel=0.03, m=GREEN)) parts.append(C.rbox("rim_r", (0.14, 4.02, 0.1), (1.0, 0, 1.95), bevel=0.03, m=GREEN)) parts.append(C.rbox("rim_f", (2.1, 0.14, 0.1), (0, -1.98, 1.95), bevel=0.03, m=GREEN)) parts.append(C.rbox("rim_b", (2.1, 0.14, 0.1), (0, 1.98, 1.95), bevel=0.03, m=GREEN)) body = C.join(parts, "Body") C.uv_box(body, 1.0) C.smooth(body, 40) # the heap: a soft mound of clippings over the top of the tub heap = C.sphere("Grass", 1.0, (0, 0, 1.78), seg=24, rings=12, m=GRASS, scale=(0.92, 1.85, 0.36)) C.uv_box(heap, 0.8) C.smooth(heap, 60) wheels = [] for i, y in enumerate((-1.75, -0.85, 0.85, 1.75)): for j, x in enumerate((-0.8, 0.8)): wheels.append(wheel(f"Wheel{i * 2 + j}", x, y, r=0.32, hub=DGREEN)) for o in wheels + [heap]: o.parent = body return dict(elev=20, azim=-40) def station(): parts = [] # gravel bed down the middle, raised platforms either side parts.append(C.rbox("bed", (2.0, 8.0, 0.08), (0, 0, 0.04), bevel=0.02, m=CONC)) for side in (-1, 1): x = side * 1.5 parts.append(C.rbox("plat", (1.0, 8.0, 0.55), (x, 0, 0.275), bevel=0.05, m=CONCL)) parts.append(C.rbox("edge", (0.12, 8.0, 0.04), (side * 1.06, 0, 0.57), bevel=0.01, m=YELLOW)) parts.append(C.rbox("deck", (0.86, 7.9, 0.04), (x + side * 0.06, 0, 0.57), bevel=0.01, m=DECK)) # canopy over the left platform (Blender +X is the viewer's left from the front) for y in (-3.2, 0.0, 3.2): parts.append(C.cyl("post", 0.07, 2.6, (1.8, y, 1.85), verts=12, m=DGREEN)) parts.append(C.rbox("brace", (0.6, 0.08, 0.08), (1.55, y, 3.05), bevel=0.02, m=DGREEN)) parts.append(C.rbox("canopy", (1.5, 7.6, 0.12), (1.55, 0, 3.2), bevel=0.04, m=ROOF)) parts.append(C.rbox("canopyfront", (0.06, 7.6, 0.28), (0.82, 0, 3.12), bevel=0.02, m=CREAM)) parts.append(C.rbox("bench", (0.4, 1.4, 0.08), (1.75, 1.6, 1.0), bevel=0.02, m=TIMB)) for y in (1.05, 2.15): parts.append(C.rbox("benchleg", (0.36, 0.06, 0.42), (1.75, y, 0.76), bevel=0.01, m=SOOT)) # sign board on two legs at the right platform's front parts.append(C.rbox("signboard", (0.08, 1.4, 0.55), (-1.75, -2.6, 2.05), bevel=0.03, m=GREEN)) parts.append(C.rbox("signface", (0.1, 1.24, 0.4), (-1.75, -2.6, 2.05), bevel=0.02, m=CREAM)) for y in (-3.15, -2.05): parts.append(C.cyl("signleg", 0.05, 1.5, (-1.75, y, 1.3), verts=10, m=SOOT)) # lamps for y in (-3.6, 3.6): parts.append(C.cyl("lamppost", 0.06, 2.4, (-1.85, y, 1.75), verts=10, m=SOOT)) parts.append(C.sphere("lampglobe", 0.16, (-1.85, y, 3.0), seg=12, rings=6, m=LAMP)) # buffer stop at the back of the bed parts.append(C.rbox("stopbeam", (1.8, 0.25, 0.32), (0, 3.75, 0.72), bevel=0.05, m=RED)) parts.append(C.rbox("stopstripe", (1.82, 0.27, 0.08), (0, 3.75, 0.72), bevel=0.02, m=CREAM)) for x in (-0.6, 0.6): parts.append(C.rbox("stopleg", (0.14, 0.55, 0.62), (x, 3.85, 0.33), bevel=0.03, m=SOOT)) parts.append(C.cyl("stopbuf", 0.15, 0.2, (x, 3.55, 0.72), axis="Y", verts=14, m=STEEL)) body = C.join(parts, "Body") C.uv_box(body, 1.0) C.smooth(body, 40) return dict(elev=35, azim=-35) if __name__ == "__main__": C.run({"SM_TrainLoco": loco, "SM_TrainWagon": wagon, "SM_TrainStation": station})