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>
This commit is contained in:
NiemandKG
2026-11-06 18:44:40 +06:00
parent 0f0467cd0c
commit d1c3761e58
4190 changed files with 270757 additions and 1 deletions

View File

@ -0,0 +1,799 @@
"""GRASS CUTTER - model upgrade: SM_Windmill, a Dutch smock mill that takes over from SM_Vaporizer as the Dryer's look.
SM_Windmill 2 x 2 m footprint, hub 5 m up, sails sweep 2.6 m. Body Spin (hub, Sail_1..4 parented to it) Lamp
Stone plinth with a little gallery round it, a tapered eight-sided tower in board and batten, a shingled boat-shaped cap with
a tail pole down the back, four lattice sails with canvas. Paint and stone come straight from the pack's atlas, same as
gc_up_machines.py, so the whole mill is nearly one draw call.
The game's Machine ports sit on the centre line, 1.05 m out, at 0.4 m: the chute (front, -Y) and the hopper (back, +Y) end at
y = -+1.0 on x = 0, and everything below the gallery stays inside the 2 x 2 m footprint.
Spin's origin is on the hub, its rotation is identity, so its local Y is the wind shaft. Machine picks the local axis that lies
along the piece's forward. The sails are at the classic X when Spin is at rest.
Run (absolute paths, the shell starts in another project):
blender -b --factory-startup --python D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_up_windmill.py
Set GC_VIEWS=<dir> to also render review angles there with back faces culled, as Unity shows them.
"""
import sys, os, zlib
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import common
from gc_up_machines import * # noqa: F401,F403 (helpers + paint)
HUB = (0.0, -1.30, 5.0)
SAIL_R = 2.53 # along the stock; the far corner of the lattice sweeps 2.6
Z_G = 1.86 # gallery deck, top of the plinth
Z_T = 4.46 # top of the tower
Z_E = 4.62 # eaves of the cap
C225 = math.cos(math.radians(22.5))
# more flat swatches of the pack's ramps
for k_, v_ in {"TIM1": (.43, .495, "#A47A56"), "TIM2": (.43, .47, "#79573B"), "TIM3": (.43, .45, "#543919"),
"TAN": (.005, .385, "#CAAE86"), "TAN2": (.005, .34, "#B49770"), "CRM2": (.071, .385, "#DBC7A9"), "CRM3": (.071, .34, "#CCB79A"), "PANE": (.34, .45, "#49667E")}.items():
SW[k_] = v_
common.MATDEFS["P_" + k_] = {"name": "P_" + k_, "color": v_[2]}
# atlas regions used as tiles: u0, v0, u1, v1
RG = {"PEEL": (.725, .515, .985, .98), "WORN": (.288, .03, .47, .385), "BOARD": (.755, .255, .998, .495),
"STONE": (.54, .505, .715, .982), "SHING": (.505, .012, .748, .245)}
# ======================================================================= paint
def reg_fit(o, key, su=.25, sv=.25, rot=False, g=(0, 0, 1)):
"""A region of the atlas on every face of a part, V along g (rot: U along g). Each face lands somewhere else in the region."""
u0, v0, u1, v1 = RG[key]
g = Vector(g)
me = o.data
bm = bmesh.new()
bm.from_mesh(me)
bm.normal_update()
uvl = bm.loops.layers.uv.verify()
for f in bm.faces:
n = f.normal
t = g - n * g.dot(n)
if t.length < .3:
t = n.orthogonal()
t.normalize()
s = t.cross(n)
aa = [l.vert.co.dot(s) * su for l in f.loops]
bb = [l.vert.co.dot(t) * sv for l in f.loops]
if rot:
aa, bb = bb, aa
spa, spb = max(aa) - min(aa), max(bb) - min(bb)
ka, kb = min(1.0, (u1 - u0) / max(spa, 1e-6)), min(1.0, (v1 - v0) / max(spb, 1e-6))
du = u0 + random.random() * max(0.0, (u1 - u0) - spa * ka) - min(aa) * ka
dv = v0 + random.random() * max(0.0, (v1 - v0) - spb * kb) - min(bb) * kb
for l, a, b in zip(f.loops, aa, bb):
l[uvl].uv = (a * ka + du, b * kb + dv)
bm.to_mesh(me)
bm.free()
set_mats(o, "M_Pack")
return uv_keep(o)
# ======================================================================= the octagon
def fp(k, t, hw, z, off=0.0):
"""Point on facet k of an octagon with flats on the axes: t runs from corner k to corner k + 1, hw is the half width across flats.
Facet normals: k = 0 +X+Y, 1 +Y, 2 -X+Y, 3 -X, 4 -X-Y (door), 5 -Y (front), 6 +X-Y, 7 +X."""
R = (hw + off) / C225
a0, a1 = math.radians(22.5 + 45 * k), math.radians(67.5 + 45 * k)
return Vector((R * ((1 - t) * math.cos(a0) + t * math.cos(a1)), R * ((1 - t) * math.sin(a0) + t * math.sin(a1)), z))
def ring8(hw, z):
return [tuple(fp(k, 0.0, hw, z)) for k in range(8)]
def octa(stack, m, name="octa"):
"""Solid through (hw, z) levels."""
return loft([ring8(h, z) for (h, z) in stack], m, name=name)
def hw_p(z):
return .85 + (.79 - .85) * z / Z_G
def hw_t(z):
return .775 + (.50 - .775) * (z - Z_G) / (Z_T - Z_G)
TILT_P = math.atan2(.06, Z_G)
TILT_T = math.atan2(.275, Z_T - Z_G)
def fac(P, G, k, z, hw, tilt=0.0):
"""Lay parts built facing -Y around the origin on facet k, at height z on a wall of half width hw."""
a = math.radians(45 * (k + 1))
for o in G:
P.append(xf(o, rx=-tilt, rz=a - math.radians(270), t=(hw * math.cos(a), hw * math.sin(a), z)))
def quad(a, b, c, d, m, name="q"):
o = mesh_obj(name, verts=[tuple(a), tuple(b), tuple(c), tuple(d)], faces=[(0, 1, 2, 3)])
set_mats(o, m)
return o
def strip(k, t, z0, z1, hw0, hw1, w, d, m, name="batten"):
"""A batten on a wall: three faces, no caps. w wide, d proud."""
fw0, fw1 = 2 * hw0 * math.tan(math.radians(22.5)), 2 * hw1 * math.tan(math.radians(22.5))
t00, t01 = t - w / 2 / fw0, t + w / 2 / fw0
t10, t11 = t - w / 2 / fw1, t + w / 2 / fw1
v = [fp(k, t00, hw0, z0, -.01), fp(k, t00, hw0, z0, d), fp(k, t01, hw0, z0, d), fp(k, t01, hw0, z0, -.01),
fp(k, t10, hw1, z1, -.01), fp(k, t10, hw1, z1, d), fp(k, t11, hw1, z1, d), fp(k, t11, hw1, z1, -.01)]
o = mesh_obj(name, verts=[tuple(p) for p in v], faces=[(0, 1, 5, 4), (1, 2, 6, 5), (2, 3, 7, 6)])
set_mats(o, m)
return o
def corner_post(c, z0, z1, hw0, hw1, w, d, m):
"""Trim round corner c, between facets c - 1 and c."""
def rng(z, hw):
fw = 2 * hw * math.tan(math.radians(22.5))
q = w / fw
return [fp(c - 1, 1 - q, hw, z, -.01), fp(c - 1, 1 - q, hw, z, d), fp(c, 0, hw, z, d), fp(c, q, hw, z, d), fp(c, q, hw, z, -.01)]
v = rng(z0, hw0) + rng(z1, hw1)
o = mesh_obj("cornerpost", verts=[tuple(p) for p in v], faces=[(i, i + 1, i + 6, i + 5) for i in range(4)])
set_mats(o, m)
return o
def quoin(c, z0, z1, L, m, off=.016):
"""A dressed stone wrapped round corner c of the plinth."""
def rng(z):
hw = hw_p(z)
q = L / (2 * hw * math.tan(math.radians(22.5)))
return [fp(c - 1, 1 - q, hw, z, -.01), fp(c - 1, 1 - q, hw, z, off), fp(c, 0, hw, z, off), fp(c, q, hw, z, off), fp(c, q, hw, z, -.01)]
v = rng(z0) + rng(z1)
o = mesh_obj("quoin", verts=[tuple(p) for p in v], faces=[(i, i + 1, i + 6, i + 5) for i in range(4)])
set_mats(o, m)
return o
# ======================================================================= plinth
def stone_wall(P):
zs = (.08, .66, 1.24, Z_G)
o = loft([ring8(hw_p(z), z) for z in zs], "M_Pack", name="plinth")
reg_fit(o, "STONE", .27, .27, rot=True)
P.append(o)
def plinth(P):
# footing: a low apron of big dressed stones, it fills the footprint
P.append(octa([(.985, 0.0), (.985, .075), (.955, .105), (.87, .105)], "P_G2", "apron"))
for k in range(8):
for t0, t1 in ((.012, .988),):
hwo, hwi = .993, .875
z0, z1 = 0.0, .112
m = random.choice(("P_G3", "P_G2", "P_G3", "P_G4"))
q = lambda t, h, z: tuple(fp(k, t, h, z))
P.append(loft([[q(t0, hwi, z0), q(t1, hwi, z0), q(t1, hwo, z0), q(t0, hwo, z0)], [q(t0, hwi, z1), q(t1, hwi, z1), q(t1, hwo - .03, z1), q(t0, hwo - .03, z1)]], m, name="footstone"))
stone_wall(P)
# quoins up every corner, long and short
for c in range(8):
z = .10
i = c % 2
for h in (.36, .32, .35, .33, .36):
L = (.12 if i % 2 == 0 else .075) * (.5 if c in (4, 5) else 1.0) # the door's jambs fill the facet between 4 and 5
P.append(quoin(c, z, min(z + h - .012, Z_G - .1), L, random.choice(("P_G3", "P_G4", "P_G3", "P_CRM3", "P_G2"))))
z += h
i += 1
# a string course of pale stone right under the gallery
P.append(octa([(hw_p(Z_G - .13) + .022, Z_G - .13), (hw_p(Z_G) + .022, Z_G)], "P_G4", "stringcourse"))
def stone_door(P):
"""Plank door under a stone arch on the door facet. Built on a wall at y = 0, z up from the ground."""
G = []
W, ZS, ZC = .215, .105, 1.20
# planks
n = 5
for i in range(n):
x0, x1 = -W + 2 * W * i / n + .004, -W + 2 * W * (i + 1) / n - .004
top = lambda x: ZC + math.sqrt(max(0.0, W * W - x * x))
prof = [(x0, ZS), (x1, ZS), (x1, top(x1)), ((x0 + x1) / 2, top((x0 + x1) / 2)), (x0, top(x0))]
G.append(py(prof, -.012, .006, "P_CAB" if i % 2 else "P_GRND", name="doorplank"))
# dark behind the planks
G.append(py([(-W, ZS)] + [(W, ZS)] + [(W * math.cos(a), ZC + W * math.sin(a)) for a in (0, .5, 1.05, 1.57, 2.1, 2.64, PI)], .006, .012, "P_BLACK", name="doorback"))
# ledges and strap hinges
for z in (.36, 1.02):
G.append(bx(-W, W, -.024, -.012, z - .04, z + .04, "P_CAB", bev=0, name="ledge"))
G.append(py([(-W - .02, z - .022), (W - .13, z - .022), (W - .07, z), (W - .13, z + .022), (-W - .02, z + .022)], -.03, -.02, "P_BLACK", name="strap"))
for x in (-W + .05, W - .2):
bolt(G, (x, -.03, z), (0, -1, 0), r=.009, m="P_G3")
# ring latch
G.append(xf(torus("latch", .026, .006, (0, 0, 0), "Y", seg=8, rseg=3, m="P_G4"), t=(.135, -.034, .78)))
G.append(cy("latchboss", .02, -.034, -.024, .135, .805, "P_BLACK", v=6))
# jamb stones, long and short
z = ZS
i = 0
for h in (.30, .26, .28, .27):
for s in (-1, 1):
d = .115 if (i + (s > 0)) % 2 else .08
a, b = sorted((s * W, s * (W + d)))
G.append(bx(a, b, -.05, .01, z, z + h - .012, random.choice(("P_G4", "P_CRM3", "P_G3")), bev=0, name="jamb"))
z += h
i += 1
# voussoirs: a real stone arch with a key
NV = 7
for j in range(NV):
a0, a1 = PI * j / NV + .012, PI * (j + 1) / NV - .012
Ro = .115 if j != 3 else .15
fw = -.075 if j == 3 else -.05
cs = [(W * math.cos(a0), ZC + W * math.sin(a0)), (W * math.cos(a1), ZC + W * math.sin(a1)),
((W + Ro) * math.cos(a1), ZC + (W + Ro) * math.sin(a1)), ((W + Ro) * math.cos(a0), ZC + (W + Ro) * math.sin(a0))]
G.append(py(cs, fw, .01, "P_CRM2" if j == 3 else random.choice(("P_G4", "P_CRM3", "P_CRM3")), name="voussoir"))
# worn step
G.append(bx(-.33, .33, -.2, .02, 0.0, .118, "P_G3", bev=.012, name="step"))
G.append(bx(-.26, .24, -.205, -.14, .118, .122, "P_G4", bev=0, name="stepworn"))
fac(P, G, 4, 0.0, hw_p(0.0), TILT_P)
def stone_slit(P, k, z):
G = [bx(-.1, .1, -.008, .01, -.17, .17, "P_BLACK", bev=0, name="slit"),
bx(-.17, .17, -.045, .01, .17, .25, "P_CRM3", bev=0, name="lintel"),
bx(-.17, .17, -.055, .01, -.25, -.17, "P_G4", bev=0, name="sill")]
for s in (-1, 1):
G.append(sb(s, .1, .165, -.04, .01, -.17, .17, "P_G3", bev=0, name="slitjamb"))
for x in (-.04, .04):
G.append(cz("slitbar", .008, -.17, .17, x, -.012, "P_G1", v=4))
fac(P, G, k, z, hw_p(z), TILT_P)
# ======================================================================= tower
def tower(P):
Z_M = 3.16
CL = ("PEEL", "PEEL", "PEEL", "PEEL", "RED", "REDD", "PEEL")
for k in range(8):
for (z0, z1) in ((Z_G, Z_M), (Z_M, Z_T)):
nb = 5
for i in range(nb):
t0, t1 = i / nb, (i + 1) / nb
o = quad(fp(k, t0, hw_t(z0), z0), fp(k, t1, hw_t(z0), z0), fp(k, t1, hw_t(z1), z1), fp(k, t0, hw_t(z1), z1), "M_Pack", "clad")
key = random.choice(CL)
if key == "PEEL":
reg_fit(o, "PEEL", .28, .2)
else:
set_mats(o, "P_" + key)
P.append(o)
# battens on the joints, tone on tone with the boards, a few gone to bare timber; the corners carry the cream
for t in (.2, .4, .6, .8):
P.append(strip(k, t, Z_G, Z_T, hw_t(Z_G), hw_t(Z_T), .026, .018, random.choice(("P_DRED", "P_DRED", "P_REDD", "P_TIM2"))))
P.append(corner_post(k, Z_G, Z_T, hw_t(Z_G), hw_t(Z_T), .034, .026, "P_CRM2"))
# bands: at the foot, the floor line, under the curb
P.append(octa([(hw_t(Z_G) + .036, Z_G), (hw_t(Z_G + .14) + .036, Z_G + .14)], "P_CRM2", "footband"))
P.append(octa([(hw_t(Z_M - .05) + .034, Z_M - .05), (hw_t(Z_M + .05) + .034, Z_M + .05)], "P_CRM2", "floorband"))
P.append(octa([(hw_t(Z_M - .065) + .024, Z_M - .065), (hw_t(Z_M - .05) + .024, Z_M - .05)], "P_TIM3", "floorshadow"))
# patched boards, nailed over the old ones
for (k, t, z0, z1, m) in ((3, .32, 2.3, 2.86, "P_TIM1"), (5, .72, 3.66, 4.1, "P_TAN2"), (6, .28, 2.05, 2.5, "P_TIM2"), (7, .6, 3.4, 3.9, "P_TIM1")):
a, b, c, d = (fp(k, t - .07, hw_t(z0), z0, .024), fp(k, t + .07, hw_t(z0), z0, .024), fp(k, t + .07, hw_t(z1), z1, .024), fp(k, t - .07, hw_t(z1), z1, .024))
P.append(board(a, b, c, d, .03, m, bev=0, name="patch"))
def window(w=.22, h=.32, shut="P_GRND", ajar=0.0):
"""Facing -Y around the origin."""
t = .034
G = [quad((-w / 2, -.006, -h / 2), (w / 2, -.006, -h / 2), (w / 2, -.006, h / 2), (-w / 2, -.006, h / 2), "P_PANE", "glass")]
G.append(bx(-w / 2 - t, w / 2 + t, -.04, .012, h / 2, h / 2 + t, "P_WHITE", bev=0, name="wframe"))
G.append(bx(-w / 2 - t, w / 2 + t, -.04, .012, -h / 2 - t, -h / 2, "P_WHITE", bev=0, name="wframe"))
for s in (-1, 1):
G.append(sb(s, w / 2, w / 2 + t, -.04, .012, -h / 2, h / 2, "P_WHITE", bev=0, name="wframe"))
G.append(quad((-.009, -.02, -h / 2), (.009, -.02, -h / 2), (.009, -.02, h / 2), (-.009, -.02, h / 2), "P_WHITE", "muntin"))
G.append(quad((-w / 2, -.021, -.009), (w / 2, -.021, -.009), (w / 2, -.021, .009), (-w / 2, -.021, .009), "P_WHITE", "muntin"))
G.append(bx(-w / 2 - t - .022, w / 2 + t + .022, -.07, .012, -h / 2 - t - .022, -h / 2 - t, "P_CRM3", bev=0, name="wsill"))
# little drip head
G.append(px([(.012, h / 2 + t), (-.075, h / 2 + t), (.012, h / 2 + t + .05)], -w / 2 - t - .02, w / 2 + t + .02, "P_CRM3", name="wdrip"))
# shutters folded back, one left swinging
if shut:
for s in (-1, 1):
a = -ajar if s > 0 else 0.0
G.append(xf(sb(s, 0, w * .44, -.022, 0, -h / 2, h / 2, shut, bev=0, name="shutter"), rz=a, t=(s * (w / 2 + t + .002), -.02, 0)))
return G
def windows(P):
for k, z, kw in ((5, 3.6, {}), (4, 2.56, {}), (6, 2.72, {"ajar": .7}), (3, 3.62, {}), (7, 3.5, {}), (1, 3.5, {})):
fac(P, window(**kw), k, z, hw_t(z), TILT_T)
# ======================================================================= gallery
def gallery(P):
Zd = Z_G
HO = 1.115
P.append(octa([(HO + .012, Zd - .10), (HO + .012, Zd - .004)], "P_CRM2", "fascia"))
P.append(octa([(HO, Zd - .004), (HO, Zd + .006)], "P_BLACK", "deckshadow"))
for k in range(8):
n = 6
for i in range(n):
t0, t1 = (i + .06) / n, (i + .94) / n
z = Zd + .016
P.append(quad(fp(k, t0, .74, z), fp(k, t0, HO - .008, z), fp(k, t1, HO - .008, z), fp(k, t1, .74, z), random.choice(("P_TIM1", "P_TAN2", "P_TIM1", "P_TIM2")), "deckplank"))
# joists and knee braces under the deck
for c in range(8):
a = math.radians(22.5 + 45 * c)
ca, sa = math.cos(a), math.sin(a)
R0, R1 = .80 / C225, 1.17 / C225
P.append(beam((R0 * ca, R0 * sa, Zd - .14), (R1 * ca, R1 * sa, Zd - .14), .07, .08, "P_TIM2", bev=0, name="joist"))
P.append(beam((.86 * ca, .86 * sa, Zd - .62), (1.10 * ca, 1.10 * sa, Zd - .16), .06, .06, "P_TIM2", bev=0, name="knee"))
# posts at corners and mid facets
Zr = Zd + .70
tops = []
for k in range(8):
for t in (0.0, .5):
p = fp(k, t, HO - .03, Zd)
a = math.atan2(p.y, p.x)
P.append(xf(bx(-.028, .028, -.028, .028, 0, .72, "P_WHITE", bev=0, name="post"), rz=a, t=(p.x, p.y, Zd)))
c0, c1 = fp(k, 0.0, HO - .03, Zr), fp((k + 1) % 8, 0.0, HO - .03, Zr)
P.append(beam(c0, c1, .075, .036, "P_WHITE", bev=0, over=.025, name="toprail"))
P.append(beam(c0 - Vector((0, 0, .34)), c1 - Vector((0, 0, .34)), .03, .05, "P_CRM2", bev=0, name="midrail"))
tops.append((c0, c1))
# X bracing in a few bays, like the barn's doors; the others stay open
for k in (1, 3, 5, 7):
c0, c1 = tops[k]
lo = Vector((0, 0, .34))
lo2 = Vector((0, 0, .68))
P.append(beam(c0 - lo2, c1 - lo, .03, .03, "P_CRM2", bev=0, name="xbrace"))
P.append(beam(c1 - lo2, c0 - lo, .03, .03, "P_CRM2", bev=0, name="xbrace"))
# a rope coil hung on the rail, a sack on the deck
P.append(xf(torus("railrope", .09, .014, (0, 0, 0), "Y", seg=9, rseg=3, m="M_Rope"), rz=math.radians(0), t=(-1.115, .22, Zd + .56)))
low_sack(P, (.98, .34, Zd + .02), .13, .3, rz=.6)
def low_sack(P, c, r=.16, h=.32, rz=0.0, lean=0.0):
prof = [(0, 0.0), (r * .86, 0.0), (r * 1.02, h * .3), (r * .9, h * .62), (r * .36, h * .84), (r * .42, h), (0, h * 1.03)]
o = revm("lowsack", prof, "M_Burlap", segs=6)
for v in o.data.vertices:
v.co.x *= 1.0 + .1 * math.sin(v.co.z * 19 + c[0] * 7)
v.co.y *= 1.0 + .1 * math.cos(v.co.z * 13 + c[1] * 7)
xf(o, ry=lean, rz=rz, t=c)
uv_box(o, 3.5)
P.append(uv_keep(o))
P.append(xf(cz("sacktie", r * .4, h * .8, h * .86, m="M_Twine", v=5), ry=lean, rz=rz, t=c))
# ======================================================================= cap
CAP = ((-.93, .54, .92), (-.66, .63, 1.10), (-.32, .665, 1.20), (.04, .64, 1.13), (.36, .53, .92), (.60, .34, .64), (.74, .12, .34))
ARC = ((1.06, -.02), (1.0, .08), (.93, .27), (.80, .48), (.60, .68), (.33, .85), (.0, 1.0))
def cap_point(st, j, sc=1.0, drop=0.0):
"""Point j of the roof section at a station: j = -6 left eave, 0 ridge, 6 right eave."""
y, w, h = st
fx, fz = ARC[6 - abs(j)]
return (math.copysign(1, j) * fx * w * sc if j else 0.0, y, Z_E + fz * h * sc - drop)
def cap_roof():
"""Shingled shell: the pack's shingle tile, rows run along the ridge, row spacing kept over the facets."""
u0, v0, u1, v1 = RG["SHING"]
A, B = u1 - u0, v1 - v0
SU, SV = .145, .155
bm = bmesh.new()
uvl = bm.loops.layers.uv.verify()
rings = []
T = .92
for st in CAP:
out = [bm.verts.new(cap_point(st, j)) for j in range(-6, 7)]
inn = [bm.verts.new(cap_point(st, j, T, .02)) for j in range(6, -7, -1)]
rings.append(out + inn)
N = len(rings[0])
# slope length up to each row
arcl = [0.0]
for j in range(5, -1, -1):
a, b = ARC[6 - (j + 1)], ARC[6 - j]
arcl.append(arcl[-1] + math.hypot((a[0] - b[0]) * .68, (a[1] - b[1]) * 1.2))
def tile(c, span, tiles):
o = math.floor(c / tiles) * tiles
return o if c + span - o <= tiles else c - 1e-4
for i in range(len(rings) - 1):
a, b = rings[i], rings[i + 1]
for q in range(N):
r = (q + 1) % N
f = bm.faces.new((a[q], a[r], b[r], b[q]))
if q < 12:
j0 = q - 6
j1 = r - 6
s0, s1 = arcl[6 - abs(j0)], arcl[6 - abs(j1)]
y0, y1 = CAP[i][0], CAP[i + 1][0]
cc = [(y0, s0), (y0, s1), (y1, s1), (y1, s0)]
pu = [p[0] * SU for p in cc]
pv = [p[1] * SV for p in cc]
ou = tile(min(pu), max(pu) - min(pu), A)
ov = tile(min(pv), max(pv) - min(pv), B)
for l, pa, pb in zip(f.loops, pu, pv):
l[uvl].uv = (u0 + min(A, pa - ou), v0 + min(B, pb - ov))
else:
for l in f.loops:
l[uvl].uv = SW["BLACK"][:2]
for r_, sgn in ((rings[0], 1), (rings[-1], -1)):
f = bm.faces.new(r_ if sgn < 0 else list(reversed(r_)))
for l in f.loops:
l[uvl].uv = SW["CRM2" if sgn > 0 else "G1"][:2]
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
bmesh.ops.triangulate(bm, faces=[f for f in bm.faces if len(f.verts) > 4], ngon_method="EAR_CLIP")
o = mesh_obj("caproof", bm)
set_mats(o, "M_Pack")
return uv_keep(o)
def dormer(P, s):
"""Little gabled window in the side of the cap."""
y0, y1, z0, z1 = -.42, -.14, Z_E + .20, Z_E + .44
a, b = sorted((s * .36, s * .70))
P.append(bx(a, b, y0, y1, z0, z1, "P_CRM2", bev=0, name="dormer"))
x = s * .704
w = [(x, y0 + .05, z0 + .04), (x, y1 - .05, z0 + .04), (x, y1 - .05, z1 - .04), (x, y0 + .05, z1 - .04)]
P.append(quad(*(w if s > 0 else (w[1], w[0], w[3], w[2])), "P_PANE", "dormerglass"))
a, b = sorted((s * .36, s * .735))
r = px([(y0 - .05, z1 - .015), (y1 + .05, z1 - .015), ((y0 + y1) / 2, z1 + .15)], a, b, "M_Pack", name="dormerroof")
P.append(reg_fit(r, "SHING", .145, .155))
def cap(P):
# curb the cap turns on, sitting on little corbels
P.append(octa([(.565, Z_T - .02), (.60, Z_T + .03), (.60, Z_T + .10), (.56, Z_T + .13)], "P_CRM2", "curb"))
P.append(octa([(.50, Z_T - .10), (.56, Z_T - .02)], "P_TIM3", "curbunder"))
for k in range(8):
a, b = fp(k, .5, .49, Z_T - .12), fp(k, .5, .585, Z_T + .0)
P.append(beam(a, b, .05, .05, "P_TIM2", bev=0, name="corbel"))
P.append(cap_roof())
# body under the roof
body = []
for st in CAP[:-1]:
y, w, h = st
pts = [(-w * .9, y + .045 if st is CAP[0] else y, Z_E - .05)] + [cap_point((y + .045 if st is CAP[0] else y, w, h), j, .9, .03) for j in range(-5, 6)] + [(w * .9, y + .045 if st is CAP[0] else y, Z_E - .05)]
body.append(pts)
P.append(loft(body, "P_TIM3", name="capbody"))
# breast boards on the front gable, cream and tan
y0 = CAP[0][0] + .035
w, h = CAP[0][1] * .9, CAP[0][2] * .9
def gable_z(x):
"""Height of the section at |x| (fractions of the arc), straight between points."""
fx = abs(x) / w
pts = ARC
for a, b in zip(pts, pts[1:]):
if b[0] <= fx <= a[0]:
q = (a[0] - fx) / max(a[0] - b[0], 1e-6)
return Z_E - .03 + (a[1] + (b[1] - a[1]) * q) * h
return Z_E
n = 7
for i in range(n):
x0, x1 = -w + 2 * w * i / n + .006, -w + 2 * w * (i + 1) / n - .006
prof = [(x0, Z_E - .06), (x1, Z_E - .06), (x1, gable_z(x1) - .02), (x0, gable_z(x0) - .02)]
P.append(py(prof, y0 - .02, y0 + .004, "P_CRM2" if i % 3 else "P_TAN", name="breastboard"))
P.append(bx(-w - .02, w + .02, y0 - .05, y0 + .01, Z_E - .1, Z_E + .0, "P_RED", bev=0, name="breastbeam"))
# the neck bearing the shaft comes out of
P.append(bx(-.20, .20, y0 - .10, y0, HUB[2] - .19, HUB[2] + .19, "P_TIM2", bev=.012, name="neck"))
P.append(cy("neckcollar", .135, y0 - .13, y0 - .1, 0, HUB[2], "P_G1", v=8))
for sx in (-1, 1):
for sz in (-1, 1):
bolt(P, (sx * .155, y0 - .10, HUB[2] + sz * .145), (0, -1, 0), r=.014, m="P_G3")
# ridge caps, following the ridge from nose to tail
rid = []
for st in CAP:
y, w_, h_ = st
rid.append([(-.05, y, Z_E + h_ - .05), (0, y, Z_E + h_ + .035), (.05, y, Z_E + h_ - .05)])
P.append(loft(rid, "P_G3", name="ridge"))
dormer(P, 1)
dormer(P, -1)
# finial and weather vane on the crown
fy = -.2
ft = Z_E + 1.16
P.append(revm("finial", [(.055, ft + .0), (.07, ft + .05), (.028, ft + .11), (.055, ft + .15), (.055, ft + .19), (.02, ft + .24), (.012, ft + .62)], "P_G1", segs=6, loc=(0, fy, 0)))
P.append(pz([(-.02, -.30), (.012, -.30), (.012, .16), (.06, .16), (0, .30), (-.06, .16), (-.02, .16)], ft + .47, ft + .485, "P_RED", name="vanearrow"))
P[-1].location = (0, fy, 0)
P.append(pz([(-.09, -.40), (0, -.33), (.09, -.40), (.09, -.30), (0, -.24), (-.09, -.30)], ft + .47, ft + .485, "P_G4", name="vanetail"))
P[-1].location = (0, fy, 0)
# tail pole down the back to a capstan wheel over the gallery, with its two struts
T0, T1 = Vector((0, .56, Z_E + .02)), Vector((0, 1.34, 2.0))
P.append(beam(T0, T1, .10, .10, "P_TIM2", bev=0, name="tailpole"))
Tm = T0.lerp(T1, .36)
for s in (-1, 1):
P.append(beam((s * .47, .22, Z_E - .02), Tm, .06, .06, "P_TIM1", bev=0, name="tailstrut"))
P.append(beam((-.47, .22, Z_E - .03), (.47, .22, Z_E - .03), .07, .08, "P_RED", bev=0, name="tailbeam"))
for t in (.14, .7, .96):
p = T0.lerp(T1, t)
P.append(bx(p.x - .058, p.x + .058, p.y - .06, p.y + .06, p.z - .03, p.z + .03, "P_G1", bev=0, name="tailband"))
# capstan: a little spoked wheel on the pole
Cw = T0.lerp(T1, .84)
P.append(cyl_between("capstan", Cw + Vector((-.12, 0, 0)), Cw + Vector((.12, 0, 0)), .055, "P_TIM3", v=6))
for k in range(6):
a = k * PI / 3
d = Vector((0, math.cos(a), math.sin(a))) * .27
for s in (-.13, .13):
if k % 2 == (s > 0):
P.append(beam(Cw + Vector((s, 0, 0)), Cw + Vector((s, 0, 0)) + d, .02, .02, "P_TAN", bev=0, name="capstanbar"))
# the chain from the pole to the gallery rail
P.append(ptube("tailchain", [T1 - Vector((0, .0, .02)), (0, 1.22, 1.96), (0, 1.13, 1.97)], .012, "P_G1", segs=4))
# ======================================================================= chute, hopper, lantern, yard
def chute(P):
"""Output, front centre: top of the lip at 0.4 m, y = -1."""
hw = hw_p(.5)
# opening in the wall with a timber frame and a tin flap propped over it
G = [bx(-.20, .20, -.01, .012, .44, .82, "P_BLACK", bev=0, name="hatch"),
bx(-.25, .25, -.05, .012, .82, .90, "P_TIM2", bev=0, name="hatchhead"),
bx(-.26, .26, -.03, .012, .90, .935, "P_G4", bev=0, name="hatchstone")]
for s in (-1, 1):
G.append(sb(s, .20, .25, -.05, .012, .40, .82, "P_TIM2", bev=0, name="hatchpost"))
fac(P, G, 5, 0.0, hw_p(0.0), TILT_P)
Y0, Y1 = -hw + .04, -1.0
Z0, Z1 = .545, .40
W = .19
for i, (x0, x1) in enumerate(((-W, -W / 3 - .005), (-W / 3 + .005, W / 3 - .005), (W / 3 + .005, W))):
P.append(board((x0, Y1, Z1), (x1, Y1, Z1), (x1, Y0, Z0), (x0, Y0, Z0), .022, ("P_TIM1", "P_TAN2", "P_TIM1")[i], bev=0, along="ad", name="chutefloor"))
# low cheeks parallel to the floor, flaring at the lip
for s in (-1, 1):
xi, xo = s * W, s * (W + .026)
cheek = [[(xi, Y1, Z1 - .03), (xo, Y1, Z1 - .03), (xo + s * .035, Y1, Z1 + .075), (xi + s * .035, Y1, Z1 + .075)],
[(xi, Y0 + .02, Z0 - .03), (xo, Y0 + .02, Z0 - .03), (xo, Y0 + .02, Z0 + .10), (xi, Y0 + .02, Z0 + .10)]]
P.append(loft(cheek, "P_TIM2", name="chutecheek"))
P.append(bx(-W - .03, W + .03, Y1 + .002, Y1 + .04, Z1 - .07, Z1 - .018, "P_G1", bev=0, name="chutelip"))
# one stub prop on a stone
P.append(bx(-.035, .035, Y1 + .03, Y1 + .09, .105, Z1 - .05, "P_TIM2", bev=0, name="chuteprop"))
# a tin hood over the opening and the last of the hay on its way out
P.append(board((-.27, -hw - .15, .845), (.27, -hw - .15, .845), (.27, -hw + .02, .93), (-.27, -hw + .02, .93), .016, "P_G4", bev=0, along="ab", name="chutehood"))
for x, y, r_ in ((-.07, -.90, .05), (.06, -.875, .055), (.0, -.94, .04)):
o = sphere("chutehay", 1.0, (0, 0, 0), seg=5, rings=3, m="M_Hay", scale=(r_ * 1.5, r_ * 1.2, r_ * .6))
P.append(uv_wall(xf(o, rx=-.65, t=(x, y, Z1 + (y - Y1) * .68 + .022))))
tuft(P, .03, -.9, .48, L=.08, n=2, az=-PI / 2, m="M_Hay")
def hopper_in(P):
"""Input, back centre: the rim at 0.4 m on y = 1, belts tip into it, its board runs up the wall behind."""
hw = hw_p(.5)
G = [bx(-.21, .21, -.01, .012, .26, .74, "P_BLACK", bev=0, name="inhatch"),
bx(-.26, .26, -.05, .012, .74, .82, "P_TIM2", bev=0, name="inhead")]
for s in (-1, 1):
G.append(sb(s, .21, .26, -.05, .012, .24, .74, "P_TIM2", bev=0, name="inpost"))
fac(P, G, 1, 0.0, hw_p(0.0), TILT_P)
Y0, Y1 = hw - .02, 1.0
ZR, ZT = .395, .19
XR, XT = .30, .13
YT0, YT1 = Y0 + .01, Y0 + .10
# four sloping boards round a throat
P.append(board((-XR, Y1, ZR), (XR, Y1, ZR), (XT, YT1, ZT), (-XT, YT1, ZT), .02, "P_TIM1", bev=0, name="hopperboard"))
P.append(board((-XT, YT0, ZT), (XT, YT0, ZT), (XR, Y0, ZR + .2), (-XR, Y0, ZR + .2), .02, "P_TIM2", bev=0, name="hopperboard"))
for s in (-1, 1):
q = [(s * XR, Y1 - .012, ZR), (s * XR, Y0, ZR + .2), (s * XT, YT0, ZT), (s * XT, YT1, ZT)]
q = q if s > 0 else [q[1], q[0], q[3], q[2]]
P.append(board(*q, .02, "P_TAN2", bev=0, name="hopperside"))
# inside: dark throat
P.append(quad((-XT, YT0, ZT + .012), (XT, YT0, ZT + .012), (XT, YT1, ZT + .012), (-XT, YT1, ZT + .012), "P_BLACK", "throat"))
# iron rim, stays and a stub leg
P.append(bx(-XR - .012, XR + .012, Y1 - .022, Y1 + .0, ZR - .03, ZR, "P_G1", bev=0, name="hopperrim"))
for s in (-1, 1):
P.append(beam((s * XR, Y1 - .03, ZR - .02), (s * XR, Y0 + .01, ZR + .19), .022, .03, "P_G1", bev=0, name="hopperrim"))
P.append(bx(-.05, .05, YT0 + .0, YT1, .105, ZT, "P_TIM2", bev=0, name="hopperleg"))
def lamp_bracket(P):
"""Iron arm on the front face next to the door, the lantern hangs off it. Returns the Lamp."""
r = .07
x, y, z = -.235, -hw_p(1.2) - .098, 1.06
lo = lantern(P, x, y, z, r=r, cage="P_BLACK")
wy = -hw_p(1.42) + .01
top = z + .238 + r * .5 + r * .5
P.append(ptube("lamparm", [(x, wy, top + .03), (x, y - .02, top + .03), (x, y - .02, top - .0)], .011, "P_BLACK", segs=4))
P.append(ptube("lampstay", [(x, wy, top - .22), (x, y + .08, top + .03)], .008, "P_BLACK", segs=4))
P.append(bx(x - .035, x + .035, wy - .01, wy + .01, top - .26, top + .06, "P_BLACK", bev=0, name="lampplate"))
return lo
def yard(P):
"""Stuff of a working mill, in the corners of the footprint where the octagon leaves room."""
# sacks waiting on a pallet, front right
P.append(bx(.56, .96, -.96, -.62, 0.0, .06, "P_TIM2", bev=0, name="pallet"))
low_sack(P, (.68, -.77, .06), .15, .36, rz=.3)
low_sack(P, (.85, -.83, .06), .13, .3, rz=1.4)
low_sack(P, (.81, -.68, .05), .12, .28, rz=.9, lean=-.16)
# hay bale and a pitchfork, back left
P.append(xf(bx(-.28, .28, -.17, .17, 0, .3, "M_Hay", bev=.02, name="milbale"), rz=.785, t=(-.68, .68, .0)))
for s in (-.14, .14):
o = bx(s - .012, s + .012, -.175, .175, 0.0, .305, "M_Twine", bev=0, name="baletwine")
P.append(xf(o, rz=.785, t=(-.68, .68, 0)))
tuft(P, -.68, .68, .3, L=.12, n=3, m="M_Hay")
# stones and a barrel, back right
P.append(cz("barrel", .15, .0, .36, .78, .78, "P_TIM1", v=8, r2=.15))
for z in (.07, .29):
P.append(cz("barrelhoop", .158, z - .012, z + .012, .78, .78, "P_G1", v=8))
P.append(cz("barrellid", .13, .36, .375, .78, .78, "P_TIM2", v=8))
# ======================================================================= the turning part
def Qs(r, s, h, th):
"""Point of a sail: r out along the stock (local +Z), s across it to the trailing side (+X), h behind the plane. th: the twist there."""
return Vector((s * math.cos(th) - h * math.sin(th), s * math.sin(th) + h * math.cos(th), r))
def twist(r):
return math.radians(13.0 - 9.0 * max(0.0, r - .5) / 2.1)
def rail(G, s, h, w, t, r0, r1, m, n=3, name="lath"):
rings = []
for i in range(n + 1):
r = r0 + (r1 - r0) * i / n
th = twist(r)
rings.append([tuple(Qs(r, s - w / 2, h - t / 2, th)), tuple(Qs(r, s + w / 2, h - t / 2, th)), tuple(Qs(r, s + w / 2, h + t / 2, th)), tuple(Qs(r, s - w / 2, h + t / 2, th))])
G.append(loft(rings, m, name=name))
def canvas(G, r0, r1, s0, s1, m="M_Canvas", nr=3, ns=2, bulge=.05, h=.012):
"""Sailcloth, seen from both sides, bellied a little between the bars."""
vs, fs = [], []
W = (ns + 1)
for side in (0, 1):
for i in range(nr + 1):
r = r0 + (r1 - r0) * i / nr
th = twist(r)
edge = 1.0 if 0 < i < nr else .25
for j in range(ns + 1):
q = j / ns
s = s0 + (s1 - s0) * q
b = math.sin(PI * q) * edge * bulge
vs.append(tuple(Qs(r, s, h + b + side * .005, th)))
N = (nr + 1) * W
for i in range(nr):
for j in range(ns):
a = i * W + j
fs.append((a, a + 1, a + W + 1, a + W))
a += N
fs.append((a + W, a + W + 1, a + 1, a))
o = mesh_obj("canvas", verts=vs, faces=fs)
set_mats(o, m)
if m == "M_Burlap":
uv_box(o, 3.5)
return G.append(uv_keep(o))
return G.append(uv_wall(o))
def sail(n, ang, fill):
"""One sail, built along +Z with its origin on the hub, then turned round Y to its place."""
G = []
R0, R1 = .50, SAIL_R
S0, S1, SM = -.14, .60, .24
H_W = -.05 # lattice in front of the stock
# stock, tapering: half of the great beam through the poll end
G.append(loft([[(-.062, -.062, .10), (.062, -.062, .10), (.062, .062, .10), (-.062, .062, .10)],
[(-.03, -.03, 2.3), (.03, -.03, 2.3), (.03, .03, 2.3), (-.03, .03, 2.3)]], "P_TIM2", name="stock"))
# whip, bolted on the stock and running out to the tip
G.append(loft([[(-.038, -.062, .34), (.038, -.062, .34), (.038, -.022, .34), (-.038, -.022, .34)],
[(-.022, -.062, R1), (.022, -.062, R1), (.022, -.034, R1), (-.022, -.034, R1)]], "P_RED", name="whip"))
# the lattice: sail bars through the whip, hemlaths along the edges
NB = 11
for i in range(NB):
r = R0 + (R1 - .04 - R0) * i / (NB - 1)
th = twist(r)
G.append(beam(Qs(r, S0, H_W, th), Qs(r, S1, H_W, th), .026, .018, "P_TAN", bev=0, over=.012, name="sailbar"))
rail(G, S1, H_W, .04, .03, R0 - .05, R1, "P_WHITE", name="hemlath")
rail(G, SM, H_W, .022, .024, R0, R1 - .02, "P_TAN", name="midlath")
rail(G, S0, H_W, .03, .026, R0 - .05, R1, "P_TAN2", name="leadlath")
# leading board on the short side of the whip
rail(G, -.085, H_W, .085, .012, R0 + .15, R1 - .06, "P_CRM2", n=2, name="leadboard")
# iron straps stock to whip
for r in (.56, 1.15, 1.72):
G.append(bx(-.05, .05, -.072, .05, r - .022, r + .022, "P_G1", bev=0, name="strap"))
# cloth
bar = lambda i: R0 + (R1 - .04 - R0) * i / (NB - 1)
for (a, b, s0, s1, m) in fill:
canvas(G, bar(a) + .012, bar(b) - .012, s0, s1, m)
if not any(s0 < .1 for (_, _, s0, _, _) in fill):
# furled on this one: the cloth rolled along the whip and tied off
p, q = Qs(.62, .09, H_W + .005, twist(.62)), Qs(2.42, .09, H_W + .005, twist(2.42))
G.append(cyl_between("furled", p, q, .04, "M_Canvas", v=5, r2=.03))
for r in (.9, 1.4, 1.9, 2.3):
p0 = Qs(r, .09, H_W + .005, twist(r))
G.append(bx(p0.x - .046, p0.x + .046, p0.y - .046, p0.y + .046, r - .012, r + .012, "M_Rope", bev=0, name="tie"))
for o in G:
xf(o, ry=ang)
return pfin(G, "Sail_%d" % n, ang=25)
def spin():
G = []
# the poll end: an iron canister the stocks pass through, with the firm's badge on its nose
G.append(cy("poll", .185, -.15, .13, 0, 0, "P_G1", v=8))
for y in (-.155, .085):
G.append(cy("pollband", .20, y, y + .05, 0, 0, "P_DGREY", v=8))
G.append(cyl_between("pollnose", (0, -.155, 0), (0, -.25, 0), .135, "P_RED", v=8, r2=.095))
star_badge(G, (0, -.253, 0), .17, (0, -1, 0))
for k in range(8):
a = (k + .5) * PI / 4
G.append(cy("pollbolt", .014, -.17, -.15, .165 * math.cos(a), .165 * math.sin(a), "P_G4", v=4))
# wedges round the stocks
for s in (-1, 1):
G.append(bx(-.09, .09, -.09, .09, s * .19 - .022, s * .19 + .022, "P_TIM3", bev=0, name="wedge"))
G.append(bx(s * .19 - .022, s * .19 + .022, -.09, .09, -.09, .09, "P_TIM3", bev=0, name="wedge"))
# the wind shaft back to the neck bearing, turns with the hub
G.append(cy("shaft", .092, .12, .36, 0, 0, "P_G2", v=8))
G.append(cy("shaftband", .105, .22, .26, 0, 0, "P_G1", v=8))
for o in G:
xf(o, ry=PI / 4)
o = pfin(G, "Spin", ang=30)
o.location = HUB
CL = "M_Canvas"
plans = {
1: [(2, 6, .015, .585, CL), (6, 8, .255, .585, "M_Burlap"), (6, 8, .015, .255, CL), (8, 10, .015, .585, CL)],
2: [(1, 10, .255, .585, CL)],
3: [(2, 6, .015, .585, CL), (6, 10, .255, .585, CL)],
4: [(1, 10, .255, .585, CL)],
}
for n in range(1, 5):
s = sail(n, math.radians(45 + 90 * (n - 1)), plans[n])
s.parent = o
s.location = (0, 0, 0)
return o
# ======================================================================= the mill
def windmill():
P = []
plinth(P)
stone_door(P)
stone_slit(P, 7, 1.0)
tower(P)
windows(P)
gallery(P)
cap(P)
chute(P)
hopper_in(P)
one_uv(lamp_bracket(P))
yard(P)
pfin(P, "Body", ang=20)
spin()
return dict(elev=10, azim=-34, res=900, dist_mul=.82, target=(0, -.2, 3.5))
BUILDERS = {"SM_Windmill": windmill}
MID = (0, -.2, 3.5)
VIEWS = (("a", 10, -34, .82, MID), ("b", 6, -90, .82, MID), ("c", 10, 150, .82, MID), ("d", 4, 0, .82, MID),
("door", 10, -44, .26, (0, -.3, 1.2)), ("cap", 8, -32, .26, (0, -.5, 5.0)), ("back", 14, 168, .26, (0, .8, 1.2)), ("far", 8, -34, 2.7, MID))
def scene_props(zmin):
g = cube("ground", (90, 90, .02), (0, 0, zmin - .012), "M_Grass")
uv_box(g, .5)
g["preview_only"] = True
# a crew member for scale, 1.3 m, standing by the door
c = cz("crewman", .17, 0, 1.3, -1.3, -.3, "M_PaintYellow", v=10)
c["preview_only"] = True
def main():
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
vd = os.environ.get("GC_VIEWS")
for n in (args or list(BUILDERS)):
common.reset()
random.seed(zlib.crc32(n.encode()))
res = BUILDERS[n]() or {}
print(f"[{n}] parts:", {o.name: tri_count([o]) for o in bpy.context.scene.objects if o.type == "MESH"})
common.finish(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"]
for tag, el, az, dm, tgt in VIEWS:
scene_props(0.0)
common.preview(os.path.join(vd, f"{n}_{tag}"), elev=el, azim=az, dist_mul=dm, res=640, frame=names, target=tgt)
if __name__ == "__main__":
main()