"""GRASS CUTTER - upgrade round 3, the world of Herbaria-7: SM_Foundation_Square / SM_Foundation_Hex timber building slabs with a stone and timber footing, one mesh each, they tile edge to edge SM_SurveyStake Body, Post (origin at the foot, leans about it), children of Post: ClothKnot, ClothFlag (the code shows one of the two) SM_SurveyPoint Body, Lamp (own object, one slot, the code swaps its material) SM_Spire_A/B/C wind-carved alien rock, one mesh each, MeshCollider at runtime Foundations: top at z = 0.30, footing to z = -1.5, pivot at z = 0. Square 3.0 x 3.0 m, hex 3.0 m across the flats with flats on +-Y, corners on +-X. Nothing passes those outlines or z = 0.30: the iron is let into the timber, even the bolt heads end flush. Stake and point: Unity keeps a lone top-level FBX node as the prefab root, so the stake needs Body beside Post, or Post stops being a child. Spires: an implicit field (pillars, bedding, wind, joints, arches) is meshed by surface nets at about 0.4 m, then collapsed to the budget. Facets and overhangs come out irregular that way. Vertices near a bed boundary are snapped onto it, so colours change along edges and not in saw teeth. The violet seams are raised ribs cast onto the finished rock, four tris a step. Run (from anywhere): blender -b --factory-startup --python D:/PROJECTS/LOCAL/GrassCutter/ArtSource/Blender/scripts/gc_up3_world.py -- [SM_Name ...] [--quick] ... -- --verify re-import the FBX files and check names, parents, outlines and budgets ... -- --states review shots: the stake in both states, slabs tiled, spires with a crew member. Output goes to $GC_SHOTS """ import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import numpy as np from gc_up_kit import * # noqa: F401,F403 from gc_up_base import uvbox # noqa: F401 from mathutils.bvhtree import BVHTree import common CLOTH, BRASS = "M_ClothRed", "M_Brass" PLUM, CRY, CRYD = "M_RockPlum", "M_CrystalViolet", "M_CrystalDeep" TURF, MOSS = CLIP, "M_Barnacle" # ======================================================================= foundations ZTOP, ZFOOT = 0.30, -1.5 FW = 0.22 # width of the perimeter beam GAP = {4: 0.31, 6: 0.27} # length of the iron corner along each edge SQ = [(1.5, -1.5), (1.5, 1.5), (-1.5, 1.5), (-1.5, -1.5)] RH = math.sqrt(3.0) # corner radius of a hex 3 m across the flats HX = [(RH, 0.0), (RH / 2, 1.5), (-RH / 2, 1.5), (-RH, 0.0), (-RH / 2, -1.5), (RH / 2, -1.5)] class Edge: """An edge of the counter-clockwise outline. s runs along it, u inward from it.""" def __init__(self, a, b): self.a, self.b = Vector(a), Vector(b) self.L = (self.b - self.a).length self.t = (self.b - self.a) / self.L self.n = Vector((-self.t.y, self.t.x)) # inward def at(self, s, u, z): p = self.a + self.t * s + self.n * u return Vector((p.x, p.y, z)) def rail(e, s0, s1, m0, m1, sec, m=TIM, name="rail"): """A timber along the edge. sec: (u, z) section. The ends follow s = s0 + u m0 and s = s1 - u m1, so m = cot(half corner) gives a mitre.""" bm = bmesh.new() a = [bm.verts.new(e.at(s0 + u * m0, u, z)) for u, z in sec] b = [bm.verts.new(e.at(s1 - u * m1, u, z)) for u, z in sec] n = len(sec) for i in range(n): j = (i + 1) % n bm.faces.new((a[i], a[j], b[j], b[i])) bm.faces.new(a) bm.faces.new(list(reversed(b))) bmesh.ops.triangulate(bm, faces=[f for f in bm.faces if len(f.verts) > 4]) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return grain(o, (e.t.x, e.t.y, 0)) def plate_edge(e, pts, u0, u1, m=IRON, name="plate", mitre=0.0, far=False): """A plate let into the face of the edge. pts: (s, z), measured from the far end of the edge if far is set. Points with s == 0 follow the mitre.""" def at(s, u, z): s_ = s + (u * mitre if s < 1e-6 else 0.0) return e.at(e.L - s_ if far else s_, u, z) bm = bmesh.new() a = [bm.verts.new(at(s, u0, z)) for s, z in pts] b = [bm.verts.new(at(s, u1, z)) for s, z in pts] n = len(pts) for i in range(n): j = (i + 1) % n bm.faces.new((a[i], a[j], b[j], b[i])) bm.faces.new(a) bm.faces.new(list(reversed(b))) bmesh.ops.triangulate(bm, faces=[f for f in bm.faces if len(f.verts) > 4]) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return o def stud(P, p, nrm, r=0.02, h=0.006, m=STL): """A square-headed bolt. The head ends exactly h out of p.""" p, nrm = Vector(p), Vector(nrm).normalized() _, u, v = basis(nrm) bm = bmesh.new() a = [bm.verts.new(p - nrm * 0.004 + (u * math.cos(PI / 4 + k * PI / 2) + v * math.sin(PI / 4 + k * PI / 2)) * r) for k in range(4)] b = [bm.verts.new(p + nrm * h + (u * math.cos(PI / 4 + k * PI / 2) + v * math.sin(PI / 4 + k * PI / 2)) * r * 0.75) for k in range(4)] for k in range(4): j = (k + 1) % 4 bm.faces.new((a[k], a[j], b[j], b[k])) bm.faces.new(b) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj("stud", bm) set_mats(o, m) P.append(uv_wall(o)) def clip_convex(pts, poly): """Sutherland-Hodgman: pts clipped by the convex counter-clockwise polygon poly.""" out = list(pts) n = len(poly) for i in range(n): a, b = poly[i], poly[(i + 1) % n] ex, ey = b[0] - a[0], b[1] - a[1] inside = lambda p: ex * (p[1] - a[1]) - ey * (p[0] - a[0]) >= 0 cur, out = out, [] for k in range(len(cur)): p, q = cur[k], cur[(k + 1) % len(cur)] ip, iq = inside(p), inside(q) if ip: out.append(p) if ip != iq: dp = ex * (p[1] - a[1]) - ey * (p[0] - a[0]) dq = ex * (q[1] - a[1]) - ey * (q[0] - a[0]) t = dp / (dp - dq) out.append((p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t)) if not out: return [] keep = [] for p in out: if not keep or (Vector(p) - Vector(keep[-1])).length > 0.012: keep.append(p) if len(keep) > 2 and (Vector(keep[0]) - Vector(keep[-1])).length < 0.012: keep.pop() return keep def nail_head(x, y, z, r=0.012, m=IRON): """Just a dark square a hair over the board.""" bm = bmesh.new() bm.faces.new([bm.verts.new((x + a * r, y + b * r, z)) for a, b in ((-1, -1), (1, -1), (1, 1), (-1, 1))]) o = mesh_obj("nail", bm) set_mats(o, m) return uv_wall(o) def deck_board(pts, yc, w, z0, z1, m, rng, ch=0.012, along=0.535): """A sawn board with the plan pts (counter-clockwise), chamfered top edges, UV on one board of the 6-board T_Deck, no underside.""" ip = inset(pts, ch) bm = bmesh.new() k_, uo = rng.randrange(6), rng.random() r0 = [bm.verts.new((x, y, z0)) for x, y in pts] r1 = [bm.verts.new((x, y, z1 - ch)) for x, y in pts] r2 = [bm.verts.new((x, y, z1)) for x, y in ip] n = len(pts) for a, b in ((r0, r1), (r1, r2)): for i in range(n): j = (i + 1) % n bm.faces.new((a[i], a[j], b[j], b[i])) bm.faces.new(r2) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) uvl = bm.loops.layers.uv.verify() for f in bm.faces: for l in f.loops: p = l.vert.co l[uvl].uv = (p.x * along + uo, (k_ + 0.5 + max(-0.5, min(0.5, (p.y - yc) / w)) * 0.86) / 6) o = mesh_obj("plank", bm) set_mats(o, m) return uv_keep(o) def stone_face(e, s0, s1, z0, z1, u, rng, bot=False): """One rough stone in the wall: a face broken over a proud middle, four sloped sides, nothing behind it. u: how far in from the outline it stands.""" ch = min(0.04, (s1 - s0) * 0.24, (z1 - z0) * 0.24) j = lambda: rng.uniform(0.02, 0.06) wz = lambda: rng.uniform(-0.03, 0.03) sm = (s0 + s1) / 2 + rng.uniform(-0.2, 0.2) * (s1 - s0) zm = (z0 + z1) / 2 + rng.uniform(-0.2, 0.2) * (z1 - z0) bm = bmesh.new() fr = [bm.verts.new(e.at(s, u + 0.012 + j(), z + wz())) for s, z in ((s0 + ch, z0 + ch), (s1 - ch, z0 + ch), (s1 - ch, z1 - ch), (s0 + ch, z1 - ch))] ctr = bm.verts.new(e.at(sm, u, zm)) bk = [bm.verts.new(e.at(s, u + 0.11, z)) for s, z in ((s0, z0), (s1, z0), (s1, z1), (s0, z1))] for i in range(4): k = (i + 1) % 4 bm.faces.new((fr[i], fr[k], ctr)) bm.faces.new((fr[i], bk[i], bk[k], fr[k])) # outward is minus the edge's inward normal bmesh.ops.recalc_face_normals(bm, faces=bm.faces) bm.normal_update() if sum(f.normal.to_2d().dot(e.n) for f in bm.faces) > 0: bmesh.ops.reverse_faces(bm, faces=bm.faces) o = mesh_obj("stone", bm) set_mats(o, rng.choice((ROCK, ROCK, "M_RockBand", "M_RockBand", "M_RockWet", "M_RockLilac"))) uv_box(o, 0.62, (rng.random(), rng.random())) return uv_keep(o) def foundation(poly): n = len(poly) rng = random.Random(70 + n) E = [Edge(poly[i], poly[(i + 1) % n]) for i in range(n)] half = PI * (n - 2) / n / 2 M = 1.0 / math.tan(half) # mitre slope G = GAP[n] P = [] # ---- the deck: seven boards along X, as wide as on the base deck, clipped by the inside of the frame inn = inset(poly, FW + 0.004) P.append(prism("sub", inn, "XY", 0.2, 0.235, IRON)) ys = [p[1] for p in inn] y0, y1 = min(ys), max(ys) nb = 7 pitch = (y1 - y0) / nb joists = (-0.72, 0.72) hx = 2.2 for i in range(nb): yc = y0 + pitch * (i + 0.5) w = pitch - 0.015 cut = [rng.choice(joists)] if rng.random() < 0.75 else [] xs = [-hx] + cut + [hx] for a, b in zip(xs, xs[1:]): rect = [(a + (0.003 if a > -hx else 0), yc - w / 2), (b - (0.003 if b < hx else 0), yc - w / 2), (b - (0.003 if b < hx else 0), yc + w / 2), (a + (0.003 if a > -hx else 0), yc + w / 2)] pts = clip_convex(rect, inn) if len(pts) < 3: continue m = rng.choice((PK, PK, PK, PK, PKW, PKD)) top = rng.choice((0.297, 0.297, 0.296, 0.294, 0.292)) P.append(deck_board(pts, yc, w, 0.2, top, m, rng)) # nails over the joists for jx in joists: x0_, x1_ = min(p[0] for p in pts), max(p[0] for p in pts) if x0_ + 0.05 < jx < x1_ - 0.05: for dy in (-0.09, 0.09): ox = jx + (0.05 if (a == jx) else -0.05 if (b == jx) else 0.0) P.append(nail_head(ox, yc + dy, top + 0.0012)) # ---- the frame: thick beams, flush with the outline and with z = 0.30, stopping short of the iron corners ch = 0.014 U = 0.016 # the corner timber is let in this far, the iron fills that up to 6 mm under the outline top_sec = lambda u0: [(u0, 0.06), (FW, 0.06), (FW, ZTOP - ch), (FW - ch, ZTOP), (u0 + ch, ZTOP), (u0, ZTOP - ch)] for e in E: if n == 4: mid = e.L / 2 P.append(rail(e, G, mid - 0.13, 0, 0, top_sec(0.0), TIM, "beam")) P.append(rail(e, mid + 0.13, e.L - G, 0, 0, top_sec(0.0), TIM, "beam")) # the scarf at mid-span: let in a fish plate with two bolts each way P.append(rail(e, mid - 0.13, mid + 0.13, 0, 0, [(U, 0.06), (FW, 0.06), (FW, ZTOP - ch), (FW - ch, ZTOP), (U + ch, ZTOP), (U, ZTOP - ch)], TIM, "scarf")) P.append(plate_edge(e, [(mid - 0.13, 0.09), (mid + 0.13, 0.09), (mid + 0.13, 0.27), (mid - 0.13, 0.27)], 0.006, U, IRON, "fish")) for s in (mid - 0.08, mid + 0.08): for z in (0.135, 0.225): stud(P, e.at(s, 0.006, z), (-e.n.x, -e.n.y, 0)) else: P.append(rail(e, G, e.L - G, 0, 0, top_sec(0.0), TIM, "beam")) # the corner timbers, mitred, a little lower so the iron plate sits in them lo = [(U, 0.06), (FW, 0.06), (FW, 0.288), (U, 0.288)] P.append(rail(e, 0, G, M, 0, lo, TIM, "cornert")) P.append(rail(e, e.L - G, e.L, 0, M, lo, TIM, "cornert")) # second course under the frame, set back, and the sleepers of the footing P.append(rail(e, 0, e.L, M, M, [(0.05, -0.12), (0.2, -0.12), (0.2, 0.06), (0.05, 0.06)], TIM, "sill")) # ---- iron corners: a chevron on top, a spade-ended strap down each face, all let in for i in range(n): e, ep = E[i], E[i - 1] c0, c1 = poly[i], inset(poly, 0.12)[i] a0, a1 = e.at(G, 0.0, 0), e.at(G, 0.12, 0) b1, b0 = ep.at(ep.L - G, 0.12, 0), ep.at(ep.L - G, 0.0, 0) P.append(prism("ctop", [c0, (a0.x, a0.y), (a1.x, a1.y), c1, (b1.x, b1.y), (b0.x, b0.y)], "XY", 0.28, 0.295, IRON)) zb, zt = 0.075, 0.285 strap = [(0.0, zb), (G - 0.06, zb), (G - 0.005, (zb + zt) / 2), (G - 0.06, zt), (0.0, zt)] P.append(plate_edge(e, strap, 0.006, U, IRON, "cside", mitre=M)) P.append(plate_edge(ep, strap, 0.006, U, IRON, "cside", mitre=M, far=True)) for s in (0.09, G - 0.1): stud(P, e.at(s, 0.006, 0.18), (-e.n.x, -e.n.y, 0)) stud(P, ep.at(ep.L - s, 0.006, 0.18), (-ep.n.x, -ep.n.y, 0)) for p in (e.at(G - 0.07, 0.06, 0.295), ep.at(ep.L - G + 0.07, 0.06, 0.295)): stud(P, p, (0, 0, 1), r=0.02, h=0.005) stud(P, (*tuple(inset(poly, 0.075)[i]), 0.295), (0, 0, 1), r=0.022, h=0.005) # ---- the footing: a post in each corner, a waling timber, rough stone between, packed with dirt, all of it battered out to the outline at the bottom PW = 0.25 in0, in1 = inset(poly, 0.03), inset(poly, 0.03 + PW) for i in range(n): e, ep = E[i], E[i - 1] q = [in0[i], tuple(e.at(0.03 * M + PW, 0.03, 0)[:2]), in1[i], tuple(ep.at(ep.L - 0.03 * M - PW, 0.03, 0)[:2])] p = prism("cpost", q, "XY", ZFOOT, -0.12, TIM) P.append(grain(p, (0, 0, 1))) ubat = lambda z: 0.082 + (0.01 - 0.082) * (-0.12 - z) / (-0.12 - ZFOOT) # how far the wall stands in at height z for e in E: sa, sb = 0.03 * M + PW + 0.012, e.L - 0.03 * M - PW - 0.012 bays = [(sa, sb)] if n == 4: mid = e.L / 2 bays = [(sa, mid - 0.11), (mid + 0.11, sb)] P.append(rail(e, mid - 0.11, mid + 0.11, 0, 0, [(0.03, ZFOOT), (0.2, ZFOOT), (0.2, -0.12), (0.03, -0.12)], TIM, "mpost")) P[-1]["grain"] = [0.0, 0.0, 1.0] # the wall behind the stones o = rail(e, 0.1, e.L - 0.1, 0, 0, [(0.145, ZFOOT), (0.17, ZFOOT), (0.17, -0.12), (0.145, -0.12)], "M_DeckDark", "packing") P.append(uv_wall(o)) for s0, s1 in bays: P.append(rail(e, s0, s1, 0, 0, [(0.042, -0.72), (0.15, -0.72), (0.15, -0.53), (0.042, -0.53)], TIM, "waling")) for (z0, z1, sl) in ((-0.33, -0.12, 0.4), (-0.53, -0.33, 0.48), (-1.08, -0.72, 0.62), (-1.5, -1.08, 0.86)): s = s0 + (rng.uniform(-0.1, 0.0) if z0 < -0.5 else 0.0) s = max(s0, s) while s < s1 - 0.08: L = sl * rng.uniform(0.75, 1.25) e_ = min(s + L, s1) if s1 - e_ < 0.14: e_ = s1 dz = rng.uniform(0.008, 0.04) P.append(stone_face(e, s + 0.012, e_ - 0.012, z0 + dz if z0 > ZFOOT else ZFOOT, z1 - rng.uniform(0.008, 0.04), ubat((z0 + z1) / 2), rng)) s = e_ return P def foundation_builder(poly, name): def build(): ffin(foundation(poly), name, ang=30, ms={ROCK: 0.4, TIM: 1.0}) return dict(elev=30, azim=-35, man=(2.1, -2.1, 0.0), views=[("_close", dict(elev=24, azim=-40, dist_mul=0.42, target=(1.1, -1.1, 0.25))), ("_low", dict(elev=4, azim=-30, dist_mul=0.75, target=(0, 0, -0.5))), ("_top", dict(elev=89, azim=0, dist_mul=0.85))]) return build # ======================================================================= survey stake def ribbon(path, w, t, m, name="ribbon", up=(0, 0, 1)): """A flat strip of cloth along a path, width w across, thickness t.""" pts = [Vector(p) for p in path] n = len(pts) bm = bmesh.new() rows = [] for i, p in enumerate(pts): d = (pts[min(i + 1, n - 1)] - pts[max(i - 1, 0)]).normalized() a = d.cross(Vector(up)).normalized() b = d.cross(a).normalized() w_ = w(i / (n - 1)) if callable(w) else w rows.append([bm.verts.new(p + a * sx * w_ / 2 + b * sy * t / 2) for sx, sy in ((1, 1), (-1, 1), (-1, -1), (1, -1))]) for a, b in zip(rows, rows[1:]): for k in range(4): bm.faces.new((a[k], a[(k + 1) % 4], b[(k + 1) % 4], b[k])) bm.faces.new(rows[0]) bm.faces.new(list(reversed(rows[-1]))) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj(name, bm) set_mats(o, m) return uv_wall(o) def cloth_wrap(z, R, b, tilt, az, m=CLOTH, n=8): """A band of cloth wrapped round the post at height z, tilted, a little fatter than the post.""" o = revm("wrap", [(R, -b / 2), (R + 0.016, 0.0), (R, b / 2)], m, segs=n, closed=True) for v in o.data.vertices: v.co.x *= 1.0 + 0.1 * math.cos(v.co.z * 40) xf(o, ry=tilt) xf(o, rz=az, t=(0, 0, z)) return uv_wall(o) def stake(): """A hewn surveyor's post with a brass cap, tin bands and a numbered tin tag in a ring of fieldstones. The Post leans about its origin in the ground.""" rng = random.Random(9) # ---- Body: what stays on the ground when the post leans B = [] for k, (a, r, s) in enumerate(((0.3, 0.19, 0.1), (1.4, 0.23, 0.085), (2.5, 0.2, 0.11), (3.5, 0.24, 0.075), (4.6, 0.2, 0.1), (5.6, 0.25, 0.08))): B.append(rock(s, (math.cos(a) * r, math.sin(a) * r, s * 0.35), seed=30 + k, sc=(1.25, 1.0, 0.8), m=("M_RockBand", ROCK, "M_RockLilac")[k % 3], sub=1 if k < 2 else 0, amp=0.16, name="stone")) # a driven wedge and a split peg beside the post B.append(prism("wedge", [(-0.05, 0.0), (0.05, 0.0), (0.012, 0.17)], "XZ", -0.025, 0.025, TIM)) xf(B[-1], rz=0.9, t=(0.1, -0.1, -0.01)) B.append(prism("wedge", [(-0.05, 0.0), (0.05, 0.0), (0.012, 0.13)], "XZ", -0.025, 0.025, PKD)) xf(B[-1], rz=2.3, t=(-0.11, 0.08, -0.01)) # a marker plate on a short peg: the company's mark, so the ring of stones reads as somebody's work B.append(grain(bx(0.2, 0.26, -0.3, -0.24, -0.02, 0.2, TIM, bev=0.006, name="peg"), (0, 0, 1))) B.append(plain(0.205, 0.255, -0.305, -0.3, 0.1, 0.18, BRASS, "pegtag")) ffin(B, "Body", ang=35) # ---- Post: hewn, eight-sided, tapered, the point in the ground, origin at the foot H = 2.2 P = [revm("post", [(0.0, -0.3), (0.05, -0.12), (0.066, 0.0), (0.064, 1.0), (0.052, H)], [TIM] * 4, segs=8, cap_top=True)] grain(P[0], (0, 0, 1)) # a flat hewn on the front, for the tag P.append(grain(plain(-0.04, 0.04, -0.069, -0.055, 1.02, 1.36, PKD, "flat"), (0, 0, 1))) for z, r in ((0.16, 0.068), (0.98, 0.066), (1.86, 0.058)): P.append(cz("tinband", r, z, z + 0.05, 0, 0, STL, v=8)) for z, r in ((1.385, 0.06), (1.72, 0.057)): P.append(cz("redband", r, z, z + 0.07, 0, 0, PRED, v=8)) P.append(cz("creamband", 0.0585, 1.455, 1.72, 0, 0, CRM, v=8)) # the tag: tin, two brass pins, a scratched number P.append(plain(-0.034, 0.034, -0.074, -0.069, 1.1, 1.3, TIN, "tag")) for z in (1.12, 1.28): P.append(cy("pin", 0.009, -0.08, -0.07, 0, z, BRASS, v=5)) for z in (1.16, 1.2, 1.24): P.append(plain(-0.02, 0.02 - (z - 1.16) * 0.3, -0.0755, -0.073, z, z + 0.012, IRON, "scratch")) # brass cap with a finial P.append(revm("cap", [(0.058, H - 0.05), (0.06, H - 0.04), (0.06, H + 0.02), (0.034, H + 0.045), (0.016, H + 0.05), (0.024, H + 0.07), (0.02, H + 0.09), (0.0, H + 0.105)], BRASS, segs=8)) ffin(P, "Post", ang=35) # ---- ClothKnot: red cloth and rope knotted round the post at two thirds of its height zk = 1.53 Rk = 0.06 K = [cloth_wrap(zk + 0.03, Rk + 0.004, 0.15, 0.32, 0.4), cloth_wrap(zk - 0.05, Rk + 0.006, 0.13, -0.42, 1.9), cloth_wrap(zk + 0.11, Rk + 0.002, 0.08, -0.2, 3.5)] knot = rock(0.055, (0.05, -0.075, zk - 0.02), seed=4, sc=(1.25, 0.8, 0.95), m=CLOTH, sub=1, amp=0.12, name="knot") K.append(knot) # two tails blown out and down, frayed K.append(ribbon([(0.06, -0.09, zk - 0.02), (0.15, -0.14, zk - 0.1), (0.23, -0.13, zk - 0.27), (0.29, -0.17, zk - 0.45), (0.3, -0.15, zk - 0.6)], lambda t: 0.1 - 0.04 * t, 0.008, CLOTH, "tail")) K.append(ribbon([(0.03, -0.09, zk - 0.03), (-0.07, -0.15, zk - 0.14), (-0.1, -0.15, zk - 0.3), (-0.17, -0.18, zk - 0.4)], lambda t: 0.085 - 0.04 * t, 0.008, CLOTH, "tail")) # rope: tight turns over the cloth and a loose end rope_turns(K, (0, 0, zk + 0.16), Rk + 0.012, n=2, r=0.011, seg=8, step=0.021) rope_turns(K, (0, 0, zk - 0.13), Rk + 0.016, n=2, r=0.011, seg=8, step=0.021) K.append(ptube("ropeend", [(-0.07, 0.03, zk + 0.15), (-0.15, 0.05, zk + 0.1), (-0.18, 0.13, zk - 0.05), (-0.13, 0.17, zk - 0.2)], 0.011, ROPE, segs=4)) k = ffin(K, "ClothKnot", ang=45, wn=False) set_origin(k, (0, 0, zk)) # ---- ClothFlag: a neat pennant near the top, flying toward Blender -X (Unity +X, where the old stand-in flew) zh0, zh1 = 1.87, 2.17 L, nu, nv = 0.56, 6, 2 wave = lambda u: 0.055 * math.sin(u * 8.4) * (0.2 + u) bm = bmesh.new() def fv(i, j, side): u = i / nu hw_ = (zh1 - zh0) / 2 * (1 - u ** 1.25 * 0.98) zc = (zh0 + zh1) / 2 - 0.035 * u * u return bm.verts.new((-0.075 - L * u, wave(u) + side * 0.003, zc + hw_ * (2 * j / nv - 1))) for side, flip in ((-1, False), (1, True)): g = [[fv(i, j, side) for j in range(nv + 1)] for i in range(nu + 1)] for i in range(nu): for j in range(nv): q = (g[i][j], g[i + 1][j], g[i + 1][j + 1], g[i][j + 1]) bm.faces.new(q[::-1] if flip else q) fl = mesh_obj("pennant", bm) set_mats(fl, CLOTH) F = [uv_wall(fl)] # the hoist: a cream tape, two brass rings on the post F.append(plain(-0.08, -0.052, -0.008, 0.008, zh0 - 0.01, zh1 + 0.01, CRM, "hoist")) for z in (zh0 + 0.035, zh1 - 0.035): F.append(torus("ring", 0.056, 0.008, (0, 0, z), "Z", seg=8, rseg=3, m=BRASS)) # a cream diamond on each face, the company's mark, on the cloth where the cloth is um, zm = 0.17, (zh0 + zh1) / 2 - 0.002 xm = -0.075 - L * um for side in (-1, 1): a_ = [(xm, zm + 0.05), (xm + 0.04, zm), (xm, zm - 0.05), (xm - 0.04, zm)] y = wave(um) + side * 0.006 F.append(prism("mark", a_, "XZ", y - 0.002, y + 0.002, CRM)) f_ = ffin(F, "ClothFlag", ang=50, wn=False) set_origin(f_, (0, 0, zh0)) post = bpy.data.objects["Post"] for c in (k, f_): c.parent = post c.matrix_parent_inverse = Matrix.Identity(4) return dict(elev=14, azim=-35, man=(0.75, -0.35, 0), views=[("_close", dict(elev=6, azim=-40, dist_mul=0.42, target=(-0.1, 0, 1.75))), ("_far", dict(elev=8, azim=-40, dist_mul=2.0))]) # ======================================================================= survey point def survey_point(): """A brass and timber surveying tripod: three double-rail legs on brass shoes, a theodolite with a sighting tube, a plumb bob, a tin case, and one lamp on top.""" P = [] ZH = 1.2 # top of the tripod head R0, R1 = 0.62, 0.13 legs = [] for k in range(3): a = PI / 2 + k * 2 * PI / 3 + 0.12 d = Vector((math.cos(a), math.sin(a), 0)) s = Vector((-d.y, d.x, 0)) top = d * R1 + Vector((0, 0, ZH - 0.07)) foot = d * R0 up = (top - foot).normalized() shoe = foot + (top - foot) * 0.17 legs.append((d, s, top, foot, shoe)) for sg in (-1, 1): P.append(beam(top + s * sg * 0.07, shoe + s * sg * 0.026, 0.066, 0.042, TIM, bev=0, name="rail")) P.append(beam(top + up * 0.08, top - up * 0.11, 0.2, 0.06, TIM, bev=0, name="hinge")) # brass shoe and iron spike, a brass clamp round the rails P.append(cyl_between("shoe", shoe + up * 0.09, shoe - up * 0.04, 0.056, BRASS, v=6, r2=0.046)) P.append(cyl_between("spike", shoe - up * 0.04, foot, 0.042, IRON, v=5, r2=0.006)) mid = foot + (top - foot) * 0.6 P.append(beam(mid + s * 0.1, mid - s * 0.1, 0.075, 0.06, BRASS, bev=0, name="clamp")) P.append(cyl_between("screw", mid + d * 0.03, mid + d * 0.1, 0.014, BRASS, v=5)) # the spreader: a stout brass stay down to a collar on the plumb line P.append(cyl_between("stay", foot + (top - foot) * 0.42, Vector((0, 0, 0.72)), 0.013, BRASS, v=4)) P.append(cz("collar", 0.06, 0.69, 0.75, 0, 0, TIM, v=8)) # the head: timber disc with a brass plate P.append(cz("head", 0.235, ZH - 0.09, ZH - 0.02, 0, 0, TIM, v=10)) P.append(cz("headplate", 0.19, ZH - 0.02, ZH, 0, 0, BRASS, v=10)) # plumb bob on a line, under the head P.append(cyl_between("line", (0, 0, 0.69), (0, 0, 0.3), 0.005, ROPE, v=3)) P.append(revm("bob", [(0.0, 0.17), (0.018, 0.2), (0.058, 0.28), (0.052, 0.31), (0.016, 0.325), (0.0, 0.34)], BRASS, segs=6)) # red cloth tied round a leg: the crew's own mark, a green field case on a strap from another leg d, s, top, foot, shoe = legs[0] c = foot + (top - foot) * 0.74 P.append(beam(c + s * 0.105, c - s * 0.105, 0.09, 0.07, CLOTH, bev=0, name="tie")) P.append(ribbon([c + s * 0.08 + d * 0.03, c + s * 0.17 + d * 0.07 - Vector((0, 0, 0.1)), c + s * 0.2 + d * 0.06 - Vector((0, 0, 0.27)), c + s * 0.27 + d * 0.09 - Vector((0, 0, 0.38))], lambda t: 0.09 - 0.05 * t, 0.008, CLOTH, "tail")) d, s, top, foot, shoe = legs[1] c = foot + (top - foot) * 0.84 hang = c + d * 0.05 - Vector((0, 0, 0.32)) P.append(cyl_between("strap", c + s * 0.05, hang + Vector((0.07, 0, 0.09)), 0.009, "M_Leather", v=3)) P.append(cyl_between("strap", c - s * 0.05, hang + Vector((-0.07, 0, 0.09)), 0.009, "M_Leather", v=3)) P.append(uvbox(bx(hang.x - 0.13, hang.x + 0.13, hang.y - 0.075, hang.y + 0.075, hang.z - 0.15, hang.z + 0.08, GRN, bev=0.01, name="case"), 1.0)) P.append(plain(hang.x - 0.135, hang.x + 0.135, hang.y - 0.08, hang.y + 0.08, hang.z + 0.01, hang.z + 0.03, BRASS, "caseband")) # ---- the instrument: levelling screws, a graduated circle, two standards, the sighting tube on its trunnion z = ZH for k in range(3): a = k * 2 * PI / 3 + 0.5 P.append(cz("lscrew", 0.022, z, z + 0.07, 0.125 * math.cos(a), 0.125 * math.sin(a), BRASS, v=5)) P.append(cz("lknob", 0.04, z + 0.014, z + 0.04, 0.125 * math.cos(a), 0.125 * math.sin(a), IRON, v=6)) P.append(revm("base", [(0.0, z + 0.065), (0.16, z + 0.065), (0.168, z + 0.09), (0.13, z + 0.115), (0.105, z + 0.165)], [BRASS] * 4, segs=10)) P.append(cz("circle", 0.145, z + 0.165, z + 0.195, 0, 0, BRASS, v=10)) P.append(cz("dial", 0.122, z + 0.195, z + 0.2, 0, 0, CRM, v=10)) P.append(cz("vernier", 0.128, z + 0.2, z + 0.22, 0, 0, STL, v=10, r2=0.115)) zs, zt = z + 0.22, z + 0.43 # foot of the standards, the trunnion for sx in (-1, 1): x = sx * 0.1 P.append(prism("standard", [(-0.082, zs), (0.082, zs), (0.03, zt + 0.03), (-0.03, zt + 0.03)], "YZ", x - 0.013, x + 0.013, BRASS)) P.append(cx("journal", 0.04, min(x * 1.34, x), max(x * 1.34, x), 0, zt, BRASS, v=6)) P.append(cx("trunnion", 0.016, -0.134, 0.134, 0, zt, IRON, v=5)) P.append(cx("focus", 0.056, 0.134, 0.15, 0, zt, IRON, v=8)) # sighting tube, tipped up a touch, objective end to the front, an eyepiece behind T = [revm("tube", [(0.0, -0.31), (0.024, -0.31), (0.024, -0.24), (0.04, -0.21), (0.04, 0.24), (0.056, 0.27), (0.056, 0.35), (0.046, 0.355)], [IRON, IRON, BRASS, BRASS, BRASS, BRASS, BRASS], segs=8), cz("lens", 0.046, 0.348, 0.352, 0, 0, "M_Glass", v=8)] for zz in (-0.08, 0.12): T.append(cz("tband", 0.044, zz, zz + 0.022, 0, 0, IRON, v=8)) for o in T: xf(o, rx=PI / 2 + 0.09, t=(0, 0, zt)) P += T P.append(cyl_between("level", (0, 0.1, zt + 0.057), (0, -0.05, zt + 0.07), 0.014, STL, v=5)) # ---- the lamp stalk: a brass rod up from the back of the instrument, a tin cup, three guard wires LZ = 1.915 LY = 0.15 P.append(ptube("stalk", [(0, 0.09, z + 0.19), (0, LY, z + 0.26), (0, LY, LZ - 0.1)], 0.017, BRASS, segs=5)) P.append(cz("collar2", 0.03, z + 0.36, z + 0.395, 0, LY, IRON, v=6)) P.append(revm("cup", [(0.016, LZ - 0.115), (0.07, LZ - 0.07), (0.073, LZ - 0.05), (0.062, LZ - 0.055), (0.012, LZ - 0.095)], [TIN, BRASS, TIN, TIN], segs=8, loc=(0, LY, 0))) for k in range(3): a = k * 2 * PI / 3 + 0.3 c, s_ = math.cos(a), math.sin(a) P.append(ptube("guard", [(0.068 * c, LY + 0.068 * s_, LZ - 0.055), (0.115 * c, LY + 0.115 * s_, LZ + 0.01), (0.082 * c, LY + 0.082 * s_, LZ + 0.082), (0.0, LY, LZ + 0.115)], 0.0075, BRASS, segs=3)) P.append(cz("guardtop", 0.018, LZ + 0.105, LZ + 0.13, 0, LY, BRASS, v=6)) ffin(P, "Body", ang=35) lamp = sphere("Lamp", 0.09, (0, LY, LZ), seg=10, rings=6, m="M_LightAmber") uv_box(lamp, 1) smooth(lamp, 80) set_origin(lamp, (0, LY, LZ)) return dict(elev=12, azim=-35, man=(0.95, -0.55, 0), views=[("_close", dict(elev=8, azim=-35, dist_mul=0.36, target=(0, 0.04, 1.55))), ("_back", dict(elev=14, azim=150)), ("_far", dict(elev=8, azim=-40, dist_mul=2.0))]) # ======================================================================= spires _LAT = {} def lat(seed): if seed not in _LAT: _LAT[seed] = np.random.RandomState(seed & 0xffff).rand(64, 64, 64) * 2 - 1 return _LAT[seed] def vnoise(x, y, z, seed): """Value noise, about -1..1, on arrays.""" T = lat(seed) xi, yi, zi = np.floor(x).astype(np.int64), np.floor(y).astype(np.int64), np.floor(z).astype(np.int64) fx, fy, fz = x - xi, y - yi, z - zi ux, uy, uz = fx * fx * (3 - 2 * fx), fy * fy * (3 - 2 * fy), fz * fz * (3 - 2 * fz) def g(dx, dy, dz): return T[(xi + dx) & 63, (yi + dy) & 63, (zi + dz) & 63] a = g(0, 0, 0) * (1 - ux) + g(1, 0, 0) * ux b = g(0, 1, 0) * (1 - ux) + g(1, 1, 0) * ux c = g(0, 0, 1) * (1 - ux) + g(1, 0, 1) * ux d = g(0, 1, 1) * (1 - ux) + g(1, 1, 1) * ux return (a * (1 - uy) + b * uy) * (1 - uz) + (c * (1 - uy) + d * uy) * uz def fbm(x, y, z, seed, oct=3): s, a, t = 0.0, 1.0, 0.0 for k in range(oct): f = 2.0 ** k s = s + a * vnoise(x * f + 11.3 * k, y * f + 5.7 * k, z * f + 3.1 * k, seed + k) t += a a *= 0.5 return s / t * 1.5 def beds(spec): """The bedding: edges, hardness (-1 soft .. 1 hard) and a colour for each bed, thin and thick mixed.""" rng = random.Random(spec["seed"] * 7 + 1) e = [-14.0] H = spec["top"] while e[-1] < H + 16: e.append(e[-1] + (rng.uniform(*spec["thin"]) if rng.random() < 0.3 else rng.uniform(*spec["thick"]))) n = len(e) - 1 hard, cols = [], [] pal = (ROCK, "M_RockBand", "M_RockPale", "M_RockBand", PLUM, ROCK, "M_RockPale", "M_RockBand", "M_RockRust", ROCK) for i in range(n): th = e[i + 1] - e[i] h = rng.uniform(0.2, 1.0) if th > spec["thin"][1] else rng.uniform(-1.0, -0.2) hard.append(h) cols.append(pal[(i + spec["seed"]) % len(pal)] if h > 0 else rng.choice((PLUM, ROCK, "M_RockRust"))) return np.array(e), np.array(hard), cols def bed_coord(spec, X, Y, Z): d = spec["dip"] return Z + d[0] * X + d[1] * Y + spec["warp"] * fbm(X / 16.0, Y / 16.0, Z * 0.0 + 1.3, spec["seed"] + 40, 2) def rock_field(spec, X, Y, Z): """Positive inside, roughly metres.""" H, seed, rough = spec["top"], spec["seed"], spec["rough"] f = None for pl in spec["pillars"]: zp = np.array([q[0] for q in pl["prof"]], float) a_ = np.interp(Z, zp, [q[1] for q in pl["prof"]]) b_ = np.interp(Z, zp, [q[2] for q in pl["prof"]]) t = np.clip(Z / H, 0, 1) ** 1.4 dx = X - pl["c"][0] - pl["lean"][0] * t dy = Y - pl["c"][1] - pl["lean"][1] * t c_, s_ = math.cos(pl["rot"]), math.sin(pl["rot"]) u, v = dx * c_ + dy * s_, -dx * s_ + dy * c_ q = np.sqrt((u / a_) ** 2 + (v / b_) ** 2) fi = (1 - q) * np.minimum(a_, b_) if "top" in pl: fi = np.minimum(fi, pl["top"] + pl.get("slope", 0.0) * dx + 1.2 * fbm(X / 3.0, Y / 3.0, Z * 0 + 2.1, seed + 60 + int(pl["top"]), 2) - Z) f = fi if f is None else np.maximum(f, fi) # big lumps, then the streaky surface the wind leaves: long along the ground, tight up and down f = f + rough * (1.25 * fbm(X / 8.0, Y / 8.0, Z / 9.0, seed + 1, 2) + 0.5 * fbm(X / 4.5, Y / 4.5, Z / 1.1, seed + 2, 3)) # flutes: long up and down, so something runs across the beds f = f + rough * spec.get("flute", 0.8) * fbm(X / 2.6, Y / 2.6, Z / 16.0, seed + 6, 2) # joints: near-vertical planes that slice the mass into walls with sharp corners for (ang, off, tilt) in spec["joints"]: c_, s_ = math.cos(ang), math.sin(ang) f = np.minimum(f, off + tilt * Z - (c_ * X + s_ * Y) + 0.35 * fbm(X / 5.0, Y / 5.0, Z / 3.0, seed + 3, 2)) # the beds: soft ones are eaten back, deepest on the windward side, the hard ones stand out as lips E, hard, _ = spec["_beds"] zc = bed_coord(spec, X, Y, Z) i = np.clip(np.searchsorted(E, zc) - 1, 0, len(hard) - 1) h = hard[i] t = (zc - E[i]) / (E[i + 1] - E[i]) w0 = spec["wind"] rho = np.sqrt((X - spec["axis"][0]) ** 2 + (Y - spec["axis"][1]) ** 2) + 1e-3 wind = 0.5 + 0.5 * ((X - spec["axis"][0]) * math.cos(w0) + (Y - spec["axis"][1]) * math.sin(w0)) / rho soft = np.minimum(h, 0.0) hrd = np.maximum(h, 0.0) fade = np.clip(Z / 3.0, 0.1, 1.0) lee = np.clip(wind * 1.5 - 0.15, 0.0, 1.0) f = f + fade * (soft * spec["cut"] * (0.32 + 1.68 * lee * lee) + hrd * spec["lip"] * (0.25 + 0.75 * t) * (0.4 + 0.6 * lee)) # alcoves scoured out of the windward face for (c, r, sq) in spec["alcoves"]: d = np.sqrt(((X - c[0]) / r) ** 2 + ((Y - c[1]) / r) ** 2 + ((Z - c[2]) / (r * sq)) ** 2) f = np.minimum(f, (d - 1.0) * r * sq + 0.5 * fbm(X / 2.5, Y / 2.5, Z / 2.5, seed + 4, 2)) # windows: a tube right through for (p, dr, r0, sq) in spec["arches"]: p, dr = np.array(p, float), np.array(dr, float) / np.linalg.norm(dr) px, py, pz = X - p[0], Y - p[1], Z - p[2] along = px * dr[0] + py * dr[1] + pz * dr[2] qx, qy, qz = px - along * dr[0], py - along * dr[1], pz - along * dr[2] d = np.sqrt(qx * qx + qy * qy + (qz / sq) ** 2) f = np.minimum(f, d - r0 + 0.7 * fbm(X / 3.0, Y / 3.0, Z / 3.0, seed + 5, 2)) return f def keep_grounded(s, k0): """Only what is joined to the layer k0 stays, no chunks floating in the air.""" reach = np.zeros_like(s) reach[:, :, k0] = s[:, :, k0] for _ in range(4000): g = reach.copy() g[1:, :, :] |= reach[:-1, :, :] g[:-1, :, :] |= reach[1:, :, :] g[:, 1:, :] |= reach[:, :-1, :] g[:, :-1, :] |= reach[:, 1:, :] g[:, :, 1:] |= reach[:, :, :-1] g[:, :, :-1] |= reach[:, :, 1:] g &= s if (g == reach).all(): break reach = g return reach def surface_nets(F, org, step): """numpy surface nets. F on a regular grid. Returns verts (n, 3), quads (m, 4), wound outward.""" s = F > 0 ncell = tuple(d - 1 for d in F.shape) acc = np.zeros(ncell + (3,)) cnt = np.zeros(ncell) edges = [] for ax in range(3): o1, o2 = (ax + 1) % 3, (ax + 2) % 3 a, b = [slice(None)] * 3, [slice(None)] * 3 a[ax], b[ax] = slice(None, -1), slice(1, None) fa, fb = F[tuple(a)], F[tuple(b)] cross = s[tuple(a)] != s[tuple(b)] t = np.where(cross, fa / np.where(cross, fa - fb, 1.0), 0.0) idx = np.indices(fa.shape).astype(float) idx[ax] += t pos = np.moveaxis(idx, 0, -1) for d1 in (0, 1): for d2 in (0, 1): sel = [slice(None)] * 3 sel[o1] = slice(None, -1) if d1 == 0 else slice(1, None) sel[o2] = slice(None, -1) if d2 == 0 else slice(1, None) sel = tuple(sel) acc += pos[sel] * cross[sel][..., None] cnt += cross[sel] edges.append((ax, o1, o2, cross, s[tuple(a)])) mask = cnt > 0 vid = -np.ones(ncell, dtype=np.int64) vid[mask] = np.arange(mask.sum()) V = acc[mask] / cnt[mask][:, None] V = np.array(org) + V * np.array(step) quads = [] for ax, o1, o2, cross, low in edges: I = np.nonzero(cross) keep = (I[o1] > 0) & (I[o1] < F.shape[o1] - 1) & (I[o2] > 0) & (I[o2] < F.shape[o2] - 1) I = [i[keep] for i in I] def cell(d1, d2): c = [I[0].copy(), I[1].copy(), I[2].copy()] c[o1] -= d1 c[o2] -= d2 return vid[tuple(c)] a, b, c, d = cell(1, 1), cell(0, 1), cell(0, 0), cell(1, 0) q = np.stack((a, b, c, d), 1) inside_low = low[tuple(I)] q[~inside_low] = q[~inside_low][:, ::-1] quads.append(q) return V, np.concatenate(quads) def rock_body(spec, target): """Field -> surface nets -> collapse. Returns the object and the grid (for placing things round the foot).""" (x0, x1, y0, y1), H, c = spec["box"], spec["top"], spec["cell"] spec["_beds"] = beds(spec) zb = -1.25 xs = np.arange(x0 - 1, x1 + 1 + c, c) ys = np.arange(y0 - 1, y1 + 1 + c, c) zs = np.arange(zb - 0.8, H + 2.5 + c, c * spec.get("zk", 0.8)) X, Y, Z = np.meshgrid(xs, ys, zs, indexing="ij") F = rock_field(spec, X, Y, Z) F = np.minimum(F, Z - zb) F = np.minimum(F, H + 0.0 - Z) F[0, :, :] = F[-1, :, :] = F[:, 0, :] = F[:, -1, :] = F[:, :, 0] = F[:, :, -1] = -1.0 s = keep_grounded(F > 0, int(np.searchsorted(zs, 0.0))) F = np.where(s | (F <= 0), F, -0.05) V, Q = surface_nets(F, (xs[0], ys[0], zs[0]), (c, c, zs[1] - zs[0])) me = bpy.data.meshes.new("rockbody") me.from_pydata(V.tolist(), [], Q.tolist()) me.update() o = link(bpy.data.objects.new("rockbody", me)) n0 = sum(len(p.vertices) - 2 for p in me.polygons) bm = bmesh.new() bm.from_mesh(me) bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-4) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) bm.to_mesh(me) bm.free() d = o.modifiers.new("dec", "DECIMATE") d.decimate_type = "COLLAPSE" d.ratio = target / n0 d.use_collapse_triangulate = True bake(o) print(f"[rock] {V.shape[0]} verts, {n0} tris -> {len(o.data.polygons)}") return o, (X, Y, Z, F, xs, ys, zs) def paint_rock(o, spec): """Colour by bed, moss and turf on what faces up. Slots first, so the indices stay.""" E, hard, cols = spec["_beds"] names = list(dict.fromkeys(cols)) + [TURF, MOSS] me = o.data me.materials.clear() for m_ in names: me.materials.append(mat(m_)) bm = bmesh.new() bm.from_mesh(me) bmesh.ops.triangulate(bm, faces=bm.faces) V = np.array([tuple(v.co) for v in bm.verts]) zc = bed_coord(spec, V[:, 0], V[:, 1], V[:, 2]) I = np.clip(np.searchsorted(E, zc), 1, len(E) - 1) dn, up = E[I - 1] - zc, E[I] - zc near = np.where(np.abs(dn) < np.abs(up), dn, up) snap = spec.get("snap", 0.75) for v, d in zip(bm.verts, near): if abs(d) < snap and v.co.z > -0.5: v.co.z += float(d) bm.normal_update() so = spec["seed"] C = np.array([tuple(f.calc_center_median()) for f in bm.faces]) zc = bed_coord(spec, C[:, 0], C[:, 1], C[:, 2]) I = np.clip(np.searchsorted(E, zc) - 1, 0, len(cols) - 1) pn = fbm(C[:, 0] / 3.0, C[:, 1] / 3.0, C[:, 2] / 3.0, so + 8, 2) for k, f in enumerate(bm.faces): m_ = cols[I[k]] big = f.calc_area() > 0.7 # the bed snap leaves slivers on the ledges, painted green they read as scratches if big and f.normal.z > 0.86 and pn[k] > 0.15: m_ = TURF elif big and f.normal.z > 0.72 and pn[k] > -0.25: m_ = MOSS f.material_index = names.index(m_) bm.to_mesh(me) bm.free() uv_box(o, 0.11) return uv_keep(o) def vein(P, tree, spec, path, rng, hits): """A mineral seam: a jagged raised rib cast onto the rock from outside, thin at both ends, each flank a different violet. Three verts a ring, four tris a step.""" az0, az1, z0, z1, wmax = path ax = spec["axis"] step = spec.get("vstep", 1.3) n = max(6, int(abs(z1 - z0) / step)) rows = [] for k in range(n + 1): t = k / n az = math.radians(az0 + (az1 - az0) * t) + (0.09 if k % 2 else -0.09) * rng.uniform(0.3, 1.0) * (1 if 0 < k < n else 0) z = z0 + (z1 - z0) * t + rng.uniform(-0.2, 0.2) d = Vector((math.cos(az), math.sin(az), 0)) org = Vector((ax[0], ax[1], z)) + d * 40.0 loc, nrm, _, _ = tree.ray_cast(org, -d, 60.0) rows.append((loc, nrm, t)) # chop the path where the ray fell into a hollow runs, cur = [], [] for r in rows: if r[0] is None or (cur and (r[0] - cur[-1][0]).length > step * 2.5): if len(cur) > 2: runs.append(cur) cur = [] if r[0] is not None: cur.append(r) if len(cur) > 2: runs.append(cur) for run in runs: bm = bmesh.new() R = [] m = len(run) for i, (p, nrm, t) in enumerate(run): hits.append((p.copy(), nrm.copy())) tang = (run[min(i + 1, m - 1)][0] - run[max(i - 1, 0)][0]).normalized() side = tang.cross(nrm).normalized() w = wmax * (0.12 + 0.88 * math.sin(PI * (i + 0.5) / m) ** 0.7) * rng.uniform(0.7, 1.1) R.append((bm.verts.new(p + side * w / 2 - nrm * 0.12), bm.verts.new(p + nrm * (0.14 + w * 0.22)), bm.verts.new(p - side * w / 2 - nrm * 0.12))) for a, b in zip(R, R[1:]): f1 = bm.faces.new((a[0], b[0], b[1], a[1])) f2 = bm.faces.new((a[1], b[1], b[2], a[2])) f1.material_index, f2.material_index = 0, 1 bmesh.ops.recalc_face_normals(bm, faces=bm.faces) bm.normal_update() # the flanks must face away from the rock c = sum((f.normal.dot(run[len(run) // 2][1]) for f in bm.faces)) if c < 0: bmesh.ops.reverse_faces(bm, faces=bm.faces) o = mesh_obj("vein", bm) o.data.materials.clear() o.data.materials.append(mat(CRY)) o.data.materials.append(mat(CRYD)) P.append(uv_keep(o)) def chunk(c, size, rng, m, rx=0.0, ry=0.0, rz=0.0): """A broken block: a jittered box with one corner knocked off, as a convex hull.""" bm = bmesh.new() for sx in (-1, 1): for sy in (-1, 1): for sz in (-1, 1): if (sx, sy, sz) == (1, 1, 1): continue bm.verts.new(((sx * size[0] / 2) * rng.uniform(0.75, 1.1), (sy * size[1] / 2) * rng.uniform(0.75, 1.1), (sz * size[2] / 2) * rng.uniform(0.8, 1.1))) bm.verts.new((size[0] * 0.5, size[1] * 0.3, size[2] * 0.2)) bm.verts.new((size[0] * 0.2, size[1] * 0.5, size[2] * 0.3)) r = bmesh.ops.convex_hull(bm, input=bm.verts) bmesh.ops.delete(bm, geom=r["geom_unused"] + r["geom_interior"], context="VERTS") bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj("block", bm) set_mats(o, m) xf(o, rx=rx, ry=ry, rz=rz, t=c) uv_box(o, 0.11, (rng.random(), rng.random())) return uv_keep(o) def shard(base, d, r, L, m, rng, sides=5): """A crystal: a five-sided prism with a chisel tip, no underside.""" base, d = Vector(base), Vector(d).normalized() _, u, v = basis(d) bm = bmesh.new() a0 = rng.uniform(0, 6.28) ring = lambda p, rr: [bm.verts.new(p + (u * math.cos(a0 + 2 * PI * k / sides) + v * math.sin(a0 + 2 * PI * k / sides)) * rr * (0.82 + 0.3 * ((k * 7) % 3) / 2)) for k in range(sides)] r0, r1 = ring(base, r * 0.85), ring(base + d * L * 0.72, r) tip = bm.verts.new(base + d * L + u * r * 0.3) for k in range(sides): j = (k + 1) % sides bm.faces.new((r0[k], r0[j], r1[j], r1[k])) bm.faces.new((r1[k], r1[j], tip)) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj("shard", bm) set_mats(o, m) return uv_keep(o) def grass_tuft(P, p, rng, h=1.2, n=4): """Blades on a ledge: three-sided spikes, bigger than life so they read from the ground.""" p = Vector(p) for k in range(n): a = rng.uniform(0, 6.28) q = p + Vector((math.cos(a), math.sin(a), 0)) * rng.uniform(0, 0.25) top = q + Vector((math.cos(a) * h * 0.45, math.sin(a) * h * 0.45, h * rng.uniform(0.7, 1.1))) o = cyl_between("blade", q - Vector((0, 0, 0.1)), top, 0.1 * h, rng.choice((TURF, TURF, MOSS)), v=3, r2=0.001, cap=False) P.append(uv_keep(o)) def foot_radius(G, spec, th): """How far out the rock stands at knee height in direction th.""" X, Y, Z, F, xs, ys, zs = G k = int(np.searchsorted(zs, 0.7)) a = spec["axis"] for r in np.arange(16.0, 0.0, -0.25): x, y = a[0] + math.cos(th) * r, a[1] + math.sin(th) * r i, j = int(np.searchsorted(xs, x)), int(np.searchsorted(ys, y)) if 0 <= i < len(xs) and 0 <= j < len(ys) and F[i, j, k] > 0: return r return 2.0 def spire(spec, target, veins, name, bounds): rng = random.Random(spec["seed"] + 100) o, G = rock_body(spec, target) paint_rock(o, spec) me = o.data tree = BVHTree.FromPolygons([tuple(v.co) for v in me.vertices], [tuple(p.vertices) for p in me.polygons]) P = [o] x0, x1, y0, y1 = spec["box"] # ---- the seams hits = [] for path in veins: vein(P, tree, spec, path, rng, hits) # ---- fallen blocks at the foot, a scree on the windward side, beds and all E, hard, cols = spec["_beds"] th = spec["wind"] - 1.6 for k in range(spec.get("blocks", 11)): th += rng.uniform(0.25, 0.65) if k % 4 else rng.uniform(0.6, 1.4) r = foot_radius(G, spec, th) + rng.uniform(0.2, 2.6) x = min(x1 - 0.8, max(x0 + 0.8, spec["axis"][0] + math.cos(th) * r)) y = min(y1 - 0.8, max(y0 + 0.8, spec["axis"][1] + math.sin(th) * r)) s = rng.uniform(0.55, 1.0) ** 1.5 * spec["blk"] P.append(chunk((x, y, s * 0.15), (s * rng.uniform(1.2, 1.9), s, s * rng.uniform(0.55, 0.85)), rng, rng.choice(cols), rng.uniform(-0.35, 0.35), rng.uniform(-0.3, 0.3), rng.uniform(0, 6.28))) # ---- crystals where the seams come out, a big clump at the foot rng.shuffle(hits) chosen = [] for c, n_ in hits: if n_.z > -0.25 and all((c - q).length > spec["cry_gap"] for q, _ in chosen): chosen.append((c, n_)) for c, n_ in chosen[:spec.get("clumps", 5)]: for k in range(rng.choice((2, 3, 3))): d = (n_ + Vector((rng.uniform(-0.6, 0.6), rng.uniform(-0.6, 0.6), rng.uniform(0.2, 0.9)))).normalized() P.append(shard(c - d * 0.3 + Vector((rng.uniform(-0.3, 0.3), rng.uniform(-0.3, 0.3), 0)), d, rng.uniform(0.28, 0.5) * spec["cry"], rng.uniform(1.2, 2.6) * spec["cry"], rng.choice((CRY, CRY, CRYD)), rng)) for (b, n_s) in spec["geodes"]: for k in range(n_s): d = Vector((rng.uniform(-0.55, 0.55) + b[3], rng.uniform(-0.55, 0.55) + b[4], 1.0)).normalized() L = rng.uniform(1.6, 3.6) * spec["cry"] P.append(shard((b[0] + rng.uniform(-0.8, 0.8), b[1] + rng.uniform(-0.8, 0.8), b[2]), d, rng.uniform(0.3, 0.6) * spec["cry"], L, CRY if k % 3 else CRYD, rng)) # ---- grass on the ledges up = [(Vector(f.center), f.area) for f in me.polygons if f.normal.z > 0.8 and f.area > 0.5 and f.center.z > 1.0] rng.shuffle(up) for c, a_ in up[:spec.get("tufts", 9)]: grass_tuft(P, c, rng, h=spec.get("tuft_h", 1.2) * rng.uniform(0.8, 1.2), n=3) r = ffin(P, name, ang=30, wn=False) flat(r) # fit the old bounds: the same height, the same keep-out radius in Ground.Place vs = r.data.vertices ztop = max(v.co.z for v in vs) kz = bounds["top"] / ztop ex = max(max(v.co.x for v in vs) / bounds["x"][1], min(v.co.x for v in vs) / bounds["x"][0], max(v.co.y for v in vs) / bounds["y"][1], min(v.co.y for v in vs) / bounds["y"][0]) k = 1.0 / ex r.data.transform(Matrix.Diagonal((k, k, kz, 1.0))) r.data.update() return r def rock_view(): return dict(elev=7, azim=-35, bg=(0.62, 0.72, 0.84), views=[("_top", dict(elev=34, azim=-60)), ("_close", dict(elev=5, azim=-30, dist_mul=0.42, target=(3, -5, 5))), ("_back", dict(elev=8, azim=140)), ("_side", dict(elev=6, azim=60))]) def spec_a(): """The Anvil: a squat block with a window through it, its cap thrown out to the lee and broken into horns, a stump beside it.""" return dict(seed=3, cell=0.42, box=(-8.2, 8.2, -9.0, 8.2), top=20.4, thin=(0.7, 1.05), thick=(1.25, 2.6), dip=(0.27, 0.12), warp=1.5, rough=1.0, cut=1.05, lip=0.65, wind=2.6, axis=(0, 0), pillars=[dict(c=(0.3, 0), lean=(1.1, 0.5), rot=0.5, prof=[(-3, 8.0, 7.0), (2, 7.2, 6.0), (6, 6.0, 5.1), (9, 5.2, 4.6), (12, 5.0, 4.3), (15, 5.4, 4.3), (18, 5.0, 3.8), (22, 4.0, 3.0)], top=17.2, slope=0.42), dict(c=(2.6, 1.1), lean=(0.4, 0.2), rot=0.9, prof=[(-3, 3.2, 2.6), (10, 3.0, 2.3), (15, 2.6, 2.0), (18, 1.9, 1.5), (21, 0.9, 0.7)], top=20.3), dict(c=(-5.1, 3.9), lean=(0.0, 0.0), rot=1.2, prof=[(-3, 3.4, 2.7), (2, 2.8, 2.3), (6, 2.1, 1.7), (9, 1.5, 1.2), (13, 0.9, 0.7)], top=10.8), dict(c=(4.8, -5.2), lean=(0.3, -0.2), rot=0.2, prof=[(-3, 3.2, 2.4), (3, 2.1, 1.7), (5.5, 1.5, 1.2)], top=5.6)], joints=[(0.4, 7.6, -0.06), (2.3, 7.4, -0.05), (3.9, 7.0, -0.07), (5.3, 7.6, -0.05)], alcoves=[((-5.4, 2.3, 4.2), 2.9, 0.7), ((-4.6, -3.2, 11.0), 2.4, 0.8), ((4.2, 3.4, 7.2), 2.2, 0.8)], arches=[((0.8, 0, 7.4), (0.55, 1.0, 0.08), 2.0, 1.2)], blk=2.6, cry=1.0, cry_gap=3.6, clumps=4, geodes=[((3.4, -6.6, -0.2, 0.3, -0.2), 5)], tufts=9, tuft_h=1.1) def spec_b(): """The Fin: a leaning blade the wind has holed, with a broken shoulder.""" return dict(seed=7, cell=0.46, box=(-8.6, 8.6, -9.2, 7.6), top=31.5, thin=(0.8, 1.3), thick=(1.5, 3.2), dip=(-0.19, 0.12), warp=2.4, rough=1.05, cut=1.1, lip=0.7, wind=-0.5, axis=(0, 0), pillars=[dict(c=(-0.4, 0), lean=(3.4, -1.3), rot=0.75, prof=[(-3, 8.2, 5.8), (3, 7.0, 4.6), (9, 5.6, 3.5), (16, 4.9, 2.9), (22, 4.2, 2.4), (27, 3.4, 2.2), (33, 2.4, 1.7)], top=28.5, slope=0.5), dict(c=(0.6, -0.2), lean=(3.8, -1.5), rot=0.75, prof=[(-3, 3.0, 2.2), (20, 2.6, 1.8), (27, 1.9, 1.3), (31, 1.0, 0.8), (33, 0.5, 0.5)], top=31.4), dict(c=(-3.6, -3.4), lean=(0.3, -0.2), rot=0.3, prof=[(-3, 4.2, 3.6), (4, 3.4, 2.8), (9, 2.9, 2.3), (13, 3.2, 2.4), (15, 2.6, 2.0), (19, 1.4, 1.1)], top=16.5), dict(c=(4.2, 4.0), lean=(0.0, 0.0), rot=1.1, prof=[(-3, 3.0, 2.4), (2, 2.3, 1.9), (6, 1.5, 1.1), (8.5, 0.9, 0.7)], top=8.0)], joints=[(0.75, 7.3, -0.1), (3.9, 7.2, -0.08), (2.3, 7.8, -0.09), (5.4, 7.8, -0.1)], alcoves=[((4.4, -3.4, 5.0), 3.4, 0.8), ((4.9, -2.6, 12.6), 3.0, 0.9), ((4.9, -1.9, 24.5), 1.9, 0.9), ((-5.2, 2.6, 8.0), 2.2, 0.8)], arches=[((3.0, -1.2, 19.5), (-0.75, -0.62, 0.05), 1.85, 1.35)], blk=2.8, cry=1.15, cry_gap=5.0, clumps=5, geodes=[((-5.2, 3.1, -0.2, -0.3, 0.3), 5)], tufts=9, tuft_h=1.3, vstep=1.7) def spec_c(): """The Hoodoo: a tall waisted column under a great balanced cap, and a thin needle beside it. The one you steer by.""" return dict(seed=13, cell=0.52, box=(-12.0, 11.0, -11.0, 11.0), top=46.0, thin=(0.9, 1.5), thick=(1.8, 3.8), dip=(0.15, -0.16), warp=2.8, rough=1.1, cut=0.85, lip=0.6, wind=0.9, axis=(0, 0), pillars=[dict(c=(0, 0), lean=(-3.0, 2.0), rot=0.3, prof=[(-3, 11.0, 10.0), (3, 9.4, 8.6), (8, 7.4, 6.6), (15, 6.2, 5.6), (24, 5.4, 4.8), (30, 4.3, 3.8), (33, 3.5, 3.0), (34.5, 3.9, 3.4), (36, 7.8, 6.6), (41, 8.6, 6.6), (46, 6.0, 4.4)], top=45.0, slope=-0.3), dict(c=(6.4, -4.2), lean=(0.8, -0.5), rot=0.9, prof=[(-3, 4.6, 3.8), (5, 3.1, 2.7), (12, 2.0, 1.7), (19, 1.2, 1.0), (26, 0.6, 0.6)], top=25.5), dict(c=(-6.6, 5.2), lean=(0.0, 0.0), rot=2.0, prof=[(-3, 4.0, 3.4), (4, 2.9, 2.4), (9, 2.0, 1.7), (12, 1.3, 1.1)], top=12.5)], joints=[(0.3, 9.8, -0.03), (1.9, 9.4, -0.02), (3.2, 10.2, -0.03), (4.6, 9.6, -0.03)], alcoves=[((6.9, 5.0, 6.0), 3.2, 0.85), ((4.8, 4.0, 21.0), 2.2, 1.1), ((-1.0, 6.4, 14.0), 2.2, 1.0)], arches=[], blk=3.2, cry=1.4, cry_gap=6.0, clumps=6, geodes=[((2.2, 8.4, -0.2, 0.0, 0.4), 6)], tufts=11, tuft_h=1.5, vstep=2.2) OLD = {"SM_Spire_A": dict(top=19.3, x=(-7.24, 6.75), y=(-8.03, 7.08)), "SM_Spire_B": dict(top=30.7, x=(-7.87, 7.81), y=(-8.21, 6.63)), "SM_Spire_C": dict(top=44.9, x=(-11.34, 9.61), y=(-9.88, 9.96))} # seams: azimuth at the bottom and at the top (degrees from +X), z bottom and top, widest width in metres VEINS = { "SM_Spire_A": [(-80, -35, 0.6, 16.0, 0.8), (-50, -5, 6.0, 13.0, 0.5), (120, 165, 1.0, 12.0, 0.65)], "SM_Spire_B": [(-70, -25, 0.6, 26.0, 0.95), (-45, 15, 9.0, 18.0, 0.55), (100, 150, 1.0, 16.0, 0.75)], "SM_Spire_C": [(95, 40, 0.6, 30.0, 1.15), (60, 100, 12.0, 24.0, 0.6), (-100, -40, 1.0, 21.0, 0.9), (-20, 30, 35.0, 42.0, 0.8)], } TARGET = {"SM_Spire_A": 1810, "SM_Spire_B": 1760, "SM_Spire_C": 1660} def spire_builder(fn, name): def build(): spire(fn(), TARGET[name], VEINS[name], name, OLD[name]) return rock_view() return build BUILDERS = {"SM_Foundation_Square": foundation_builder(SQ, "SM_Foundation_Square"), "SM_Foundation_Hex": foundation_builder(HX, "SM_Foundation_Hex"), "SM_SurveyStake": stake, "SM_SurveyPoint": survey_point, "SM_Spire_A": spire_builder(spec_a, "SM_Spire_A"), "SM_Spire_B": spire_builder(spec_b, "SM_Spire_B"), "SM_Spire_C": spire_builder(spec_c, "SM_Spire_C")} BUDGET = {"SM_Foundation_Square": 2500, "SM_Foundation_Hex": 2500, "SM_SurveyStake": 1500, "SM_SurveyPoint": 1500, "SM_Spire_A": 2500, "SM_Spire_B": 2500, "SM_Spire_C": 2500} # ======================================================================= checks and review shots REQ = {"SM_SurveyStake": {"Body": None, "Post": None, "ClothKnot": "Post", "ClothFlag": "Post"}, "SM_SurveyPoint": {"Body": None, "Lamp": None}} def verify(): bad = 0 for n in BUILDERS: bpy.ops.wm.read_factory_settings(use_empty=True) bpy.ops.import_scene.fbx(filepath=os.path.join(common.MODELS, n + ".fbx")) bpy.context.view_layer.update() objs = list(bpy.context.scene.objects) meshes = [o for o in objs if o.type == "MESH"] tris = sum(len(p.vertices) - 2 for o in meshes for p in o.data.polygons) pts = [o.matrix_world @ v.co for o in meshes for v in o.data.vertices] bb = [(round(min(p[i] for p in pts), 4), round(max(p[i] for p in pts), 4)) for i in range(3)] print(f"V3|{n} tris {tris} / {BUDGET[n]} size {[round(b - a, 3) for a, b in bb]} bb {bb}") if tris > BUDGET[n]: print("V3| OVER BUDGET") bad += 1 for o in sorted(objs, key=lambda o: o.name): print(f"V3| {o.type:<5} {o.name:<22} par {o.parent.name if o.parent else '-':<8} origin {tuple(round(x, 3) for x in o.matrix_world.translation)} rot {tuple(round(math.degrees(a), 2) for a in o.matrix_world.to_euler())} " f"slots {[m.name for m in o.data.materials] if o.type == 'MESH' else ''}") for ch, par in REQ.get(n, {}).items(): o = bpy.data.objects.get(ch) if not o or (o.parent.name if o.parent else None) != par: print(f"V3| BAD child {ch}, wanted parent {par}") bad += 1 if n == "SM_SurveyPoint" and len(bpy.data.objects["Lamp"].data.materials) != 1: print("V3| BAD lamp slots") bad += 1 if n.startswith("SM_Foundation"): poly = SQ if n.endswith("Square") else HX E = [Edge(poly[i], poly[(i + 1) % len(poly)]) for i in range(len(poly))] out = max(-(Vector((p.x, p.y)) - e.a).dot(e.n) for p in pts for e in E) ztop, zlow = max(p.z for p in pts), min(p.z for p in pts) touch = [max((-(Vector((p.x, p.y)) - e.a).dot(e.n) for p in pts)) for e in E] print(f"V3| past the outline by {out:.5f}, top {ztop:.5f}, foot {zlow:.5f}, gap to each edge {[round(t, 5) for t in touch]}") if out > 2e-4 or abs(ztop - ZTOP) > 2e-4 or abs(zlow - ZFOOT) > 2e-4 or min(touch) < -2e-4: print("V3| BAD outline") bad += 1 print("V3|RESULT|" + ("OK" if bad == 0 else f"BAD {bad}")) def load_blend(name, M=None): with bpy.data.libraries.load(os.path.join(common.BLENDS, name + ".blend")) as (src, dst): dst.objects = [n for n in src.objects] out = [] for o in dst.objects: if o is None or o.type != "MESH": continue link(o) if M is not None and o.parent is None: o.matrix_world = M out.append(o) return out def duplicate(objs, M): out = [] for o in objs: c = o.copy() link(c) c.matrix_world = M out.append(c) return out def ground(z=0.0, s=40.0, col="M_GrassFill"): g = cube("ground", (s, s, 0.02), (0, 0, z - 0.01), col) g["preview_only"] = True return g def states(): common.PREVIEWS = SHOTS os.makedirs(SHOTS, exist_ok=True) # slabs tiled, square and hex, on grass for nm, offs in (("SM_Foundation_Square", [(i * 3.0, j * 3.0) for i in range(-1, 2) for j in range(-1, 2)]), ("SM_Foundation_Hex", [(0, 0)] + [(3 * math.sin(math.radians(a)), 3 * math.cos(math.radians(a))) for a in range(0, 360, 60)])): reset() base = load_blend(nm) for (x, y) in offs[1:]: duplicate(base, Matrix.Translation((x, y, 0))) base[0].matrix_world = Matrix.Translation((offs[0][0], offs[0][1], 0)) ground(0.02) scale_man(1.5, -1.2, 0.3) preview(nm + "_tiled", elev=32, azim=-32, dist_mul=0.62, target=(0, 0, 0.3), radius=6.0, res=900) preview(nm + "_seam", elev=30, azim=-20, dist_mul=0.2, target=(1.5, 0.3, 0.3), radius=6.0, res=900) # the stake, both states side by side, leaning the way Landmark.Show leans it (Unity Euler(16, 0, 9) about the origin) reset() objs = load_blend("SM_SurveyStake") ob = {o.name: o for o in objs} for o in objs: if o.name in ("ClothKnot", "ClothFlag"): o.parent = ob["Post"] o.matrix_parent_inverse = Matrix.Identity(4) ob["ClothKnot"].hide_render = True # the second stake, tangled T = Matrix.Translation((1.3, 0, 0)) c = {o.name: duplicate([o], T)[0] for o in objs} c["Body"].matrix_world = T c["Post"].parent = None u2b = Matrix(((-1, 0, 0, 0), (0, 0, -1, 0), (0, 1, 0, 0), (0, 0, 0, 1))) lean = u2b @ Matrix.Rotation(math.radians(0), 4, "Y") @ Matrix.Rotation(math.radians(16), 4, "X") @ Matrix.Rotation(math.radians(9), 4, "Z") @ u2b.inverted() c["Post"].matrix_world = T @ lean for nm in ("ClothKnot", "ClothFlag"): c[nm].parent = c["Post"] c[nm].matrix_parent_inverse = Matrix.Identity(4) c[nm].matrix_basis = Matrix.Translation(ob[nm].location) c["ClothFlag"].hide_render = True c["ClothKnot"].hide_render = False bpy.context.view_layer.update() ground(0.0) scale_man(0.62, 0.7, 0) preview("SM_SurveyStake_states", elev=10, azim=-22, dist_mul=0.62, target=(0.55, 0, 1.1), radius=2.0, res=900) preview("SM_SurveyStake_states2", elev=14, azim=150, dist_mul=0.62, target=(0.55, 0, 1.1), radius=2.0, res=900) # the rocks together, at their scale in Ground, with a crew member reset() for k, (nm, x, y, s) in enumerate((("SM_Spire_A", -24, 4, 1.0), ("SM_Spire_B", 0, 0, 1.0), ("SM_Spire_C", 26, 6, 1.0), ("SM_Spire_A", 10, -24, 0.4), ("SM_Spire_C", -8, -26, 0.4))): o = load_blend(nm) for q in o: q.matrix_world = Matrix.Translation((x, y, -0.4 * s)) @ Matrix.Rotation(k * 1.3, 4, "Z") @ Matrix.Diagonal((s, s, s, 1)) ground(0.0, 400) scale_man(4, -30, 0) preview("Spires_group", elev=8, azim=-12, dist_mul=0.55, target=(2, 0, 14), radius=40.0, res=1000) if __name__ == "__main__": args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] if "--verify" in args: verify() elif "--states" in args: states() else: build_main(BUILDERS, BUDGET)