"""GRASS CUTTER - the crew and the first-person hands, re-cut in the faceted style of the POLYGON Farm pack. SM_Glove_R / _L tan leather work gloves on a red flannel sleeve. Same wrist origin, same fist as gc_farm_tools.py, so ViewModel's GloveR / GloveL / HandScale placement still lands on the grips. One mesh, `Glove`. SM_Hand_R / _L the same fist bare, a bare forearm and a plain sleeve from the elbow: what ViewModel shows now, painted per crew member. One mesh, `Hand`. SM_Crew the provided creature, kept: the same capsule and stubby arms on longer legs, small eyes, now low poly and dressed as an old hand: lids, brows, a sunburnt nose and a mustache, overalls, boots, straw hat, grass sack. The rig is NOT rebuilt by hand. crew() still loads Creature_src.fbx and runs os_crew.crew_rig() on it, so every bone comes from the same measurements as before. Only then is the skinned mesh swapped for the low-poly one, with the same five vertex groups and the same leg blend. Names CrewAvatar and verify look up are unchanged: Rig, Root, Body, Leg_L, Leg_R, Arm_L, Arm_R, CrewBody, Vest (the renderer tinted per player), Helmet, Lamp, Backpack, TankFill, Boot_L, Boot_R. Run (from project root): blender -b --factory-startup --python ArtSource/Blender/scripts/gc_up_crew.py -- [SM_Glove_R SM_Glove_L SM_Crew] Check with gc_up_check.py. """ import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import gc_up_tools as UT from gc_up_tools import * # noqa: F401,F403 (tube, plate, stud, Path + everything gc_farm_tools brings) SKIN, SHIRT, DENIM, GLV = "M_CrewSkin", "M_PaintRed", "M_Denim", "M_GloveOrange" HAIR, NOSE = "M_Navy", "M_PaintTerracotta" WAIST, COLLAR = 0.38, 0.6 FACET = 24.0 # shading break on the body: every ring and column of the capsule stays a visible facet LEGS = 0.22 # metres of extra leg over the source creature def paint(o, names, fn): """Give a mesh several material slots, chosen per face from the face centre.""" set_mats(o, *names) me = o.data idx = [fn(p.center) for p in me.polygons] me.polygons.foreach_set("material_index", idx) me.update() return o # ======================================================================= gloves def digit(name, pts, r, joints, m=GLV): pts = [Vector(p) for p in pts] pts.insert(-1, pts[-2].lerp(pts[-1], 0.62)) def rf(s): k = (0.95 + 0.11 * sum(math.exp(-((s - j) / 0.07) ** 2) for j in joints)) * (1.04 - 0.14 * s) return r * k * (0.72 if s > 0.985 else 1.0) return tube(name, pts, rf, m, segs=7, per=1, ang=30, u0=0.5, uw=0.4) def glove(side): P = [] FW = M_fwd() P.append(loft("palm", [(0, 0, 0.036, 0.042, -0.012, 2.8), (0, 0, 0.04, 0.05, 0.025, 3.0), (0.003, 0.0, 0.041, 0.054, 0.06, 3.3), (0.002, 0.0, 0.038, 0.055, 0.085, 3.3), (0.0, 0.0, 0.03, 0.05, 0.1, 2.8), (0, 0, 0, 0, 0.108)], segs=10, m=GLV, frame=FW, cap0=False, smooth_ang=30)) rows = ((0.0385, 0.0172, 0.97), (0.0132, 0.0178, 1.03), (-0.0122, 0.0172, 0.99), (-0.0362, 0.0156, 0.88)) for z, r, ln in rows: f = FT.fist_finger(z, ln) P.append(digit("finger", f, r, (0.02, 0.36, 0.68))) # a darker leather tip, then a stiff pad over the knuckle P.append(tube("tip", [f[-2], f[-2].lerp(f[-1], 0.6), f[-1] + (f[-1] - f[-2]).normalized() * 0.002], lambda s: r * (0.97 if s < 0.9 else 0.74), LEA, segs=7, per=1, ang=30)) c = f[0].lerp(f[2], 0.3) + Vector((-0.0125, -0.0015, 0)) P.append(rbox("kpad", (0.012, 0.031, r * 1.72), tuple(c), bevel=0.0032, segs=1, m=LEA)) thumb = [(0.016, -0.02, 0.03), (0.042, -0.044, 0.046), (0.07, -0.07, 0.056), (0.082, -0.084, 0.056), (0.106, -0.098, 0.05)] P.append(digit("thumb", thumb, 0.0195, (0.1, 0.55))) tv = [Vector(p) for p in thumb] P.append(tube("ttip", [tv[-2], tv[-2].lerp(tv[-1], 0.6), tv[-1] + (tv[-1] - tv[-2]).normalized() * 0.003], lambda s: 0.0175 * (1.0 if s < 0.9 else 0.74), LEA, segs=7, per=1, ang=30)) P.append(sphere("thenar", 0.034, (0.028, -0.036, 0.036), seg=7, rings=4, m=GLV, scale=(0.8, 1.5, 0.9))) # the back of the hand: a raised stitched plate fr = frame_on((-0.0405, -0.047, 0.0), (-1, 0, 0), up=(0, -1, 0)) P.append(prism("patch", rrect_pts(0.064, 0.08, 0.016, 2), 0.0075, fr @ Matrix.Translation((0, 0, -0.003)), LEA, bevel=0.002, segs=1)) for sz in (-0.0315, 0.0315): FT.stitches(P, [(-0.0486, -0.016, sz), (-0.0486, -0.078, sz)], 3, m=CRM) # the gauntlet: stiff, flared, a rolled edge, a strap and a brass buckle at the wrist BK = M_axis("Y") P.append(loft("wrist", [(0, 0, 0.0352, 0.0432, -0.016, 2.6), (0, 0, 0.038, 0.046, 0.016, 2.6)], segs=10, m=GLV, frame=BK, cap0=False, cap1=False, smooth_ang=30)) P.append(loft("gaunt", [(0, 0, 0.036, 0.044, 0.012, 2.5), (0, 0, 0.046, 0.054, 0.034, 2.4), (0, 0, 0.0545, 0.0625, 0.078, 2.3)], segs=10, m=LEA, frame=BK, cap0=False, cap1=False, smooth_ang=30)) P.append(loft("cedge", [(0, 0, 0.0535, 0.0615, 0.074, 2.3), (0, 0, 0.0595, 0.068, 0.078, 2.3), (0, 0, 0.0595, 0.068, 0.088, 2.3), (0, 0, 0.05, 0.059, 0.092, 2.3)], segs=10, m=GLV, frame=BK, cap0=False, cap1=False, smooth_ang=30)) P.append(loft("strap", [(0, 0, 0.0375, 0.0455, 0.006, 2.6), (0, 0, 0.0412, 0.0492, 0.008, 2.6), (0, 0, 0.0412, 0.0492, 0.025, 2.6), (0, 0, 0.0395, 0.0475, 0.027, 2.6)], segs=10, m=HAIR, frame=BK, cap0=False, cap1=False, smooth_ang=30)) P.append(rbox("buckle", (0.008, 0.026, 0.03), (-0.043, 0.0162, 0.0), bevel=0.002, segs=1, m=BRASS)) for a in (-60, 0, 60): c = Vector((0.0545 * math.cos(DEG(a + 180)), 0.0615, 0.0625 * math.sin(DEG(a + 180)))) P.append(rbox("cstud", (0.009, 0.009, 0.009), tuple(c * 1.03 + Vector((0, 0.002, 0))), bevel=0.002, segs=1, m=BRASS)) # red flannel. It bends towards the back of the hand, as the old sleeve did: that swings the elbow to the screen's edge sp = [(0, 0.1, 0), (0, 0.112, 0), (-0.004, 0.18, 0), (-0.042, 0.272, 0), (-0.13, 0.36, 0), (-0.28, 0.5, 0), (-0.47, 0.7, 0)] pth = Path(sp, per=3) rs = lambda s: 0.05 + 0.012 * min(1.0, s * 2) P.append(tube("sleeve", sp, rs, SHIRT, segs=9, per=2, ang=30)) P.append(loft("rolled", [(0, 0, 0.0505, 0.0505, 0.09), (0, 0, 0.0565, 0.0565, 0.096), (0, 0, 0.0565, 0.0565, 0.126), (0, 0, 0.0515, 0.0515, 0.132)], segs=9, m=SHIRT, frame=BK, cap0=False, cap1=False, smooth_ang=30)) # the check of the flannel: bands of cream and dark round the sleeve for t0, w, m in ((0.18, 0.012, CRM), (0.2, 0.016, HAIR), (0.33, 0.012, CRM), (0.35, 0.016, HAIR)): P.append(tube("check", [pth.at(t0), pth.at(t0 + w)], lambda s: rs(t0) + 0.0016, m, segs=9, ang=30, cap=False)) P.append(disc("button", 0.0105, 0.006, (0.0, 0.112, 0.057), BRASS, n=6)) # a denim elbow patch, sewn on by someone in a hurry c = pth.at(0.3) + Vector((0, 0, 0.0545)) fr2 = frame_on(c, (0, 0, 1), up=(-0.2, 1, 0)) P.append(prism("elbow", rrect_pts(0.084, 0.072, 0.012, 1), 0.0045, fr2 @ Matrix.Translation((0, 0, -0.001)), DENIM)) for x in (-0.03, 0.0, 0.03): p = fr2 @ Vector((x, 0.036, 0.0035)) P.append(rbox("sew", (0.0036, 0.019, 0.003), tuple(p), bevel=0.0, m=GOLD)) o = done(P, "Glove", uv=6.0, ang=30) if side < 0: mirror_x(o) return o def glove_r(): glove(1) return dict(elev=28, azim=150, dist_mul=0.74, extra=[("front", dict(elev=15, azim=-40, dist_mul=0.74), None), ("palm", dict(elev=10, azim=70, dist_mul=0.74), None), ("back", dict(elev=15, azim=-100, dist_mul=0.74), None)]) def glove_l(): glove(-1) return dict(elev=28, azim=-150, dist_mul=0.74, extra=[("front", dict(elev=15, azim=40, dist_mul=0.74), None), ("palm", dict(elev=10, azim=-70, dist_mul=0.74), None)]) def hand(side): """The glove's fist with nothing on it: a bare hand, a bare forearm, a plain sleeve from the elbow. Two materials only, SKIN and SHIRT, which ViewModel paints in the colours of whoever the player is.""" P = [] FW = M_fwd() P.append(loft("palm", [(0, 0, 0.036, 0.042, -0.012, 2.8), (0, 0, 0.04, 0.05, 0.025, 3.0), (0.003, 0.0, 0.041, 0.054, 0.06, 3.3), (0.002, 0.0, 0.038, 0.055, 0.085, 3.3), (0.0, 0.0, 0.03, 0.05, 0.1, 2.8), (0, 0, 0, 0, 0.108)], segs=10, m=SKIN, frame=FW, cap0=False, smooth_ang=30)) for z, r, ln in ((0.0385, 0.0172, 0.97), (0.0132, 0.0178, 1.03), (-0.0122, 0.0172, 0.99), (-0.0362, 0.0156, 0.88)): P.append(digit("finger", FT.fist_finger(z, ln), r, (0.02, 0.36, 0.68), m=SKIN)) P.append(digit("thumb", [(0.016, -0.02, 0.03), (0.042, -0.044, 0.046), (0.07, -0.07, 0.056), (0.082, -0.084, 0.056), (0.106, -0.098, 0.05)], 0.0195, (0.1, 0.55), m=SKIN)) P.append(sphere("thenar", 0.034, (0.028, -0.036, 0.036), seg=7, rings=4, m=SKIN, scale=(0.8, 1.5, 0.9))) BK = M_axis("Y") P.append(loft("wrist", [(0, 0, 0.0352, 0.0432, -0.016, 2.6), (0, 0, 0.037, 0.045, 0.016, 2.6)], segs=10, m=SKIN, frame=BK, cap0=False, cap1=False, smooth_ang=30)) # the forearm, on the line the glove's sleeve took, so the elbow still swings to the screen's edge fore = [(0, 0.0, 0), (0, 0.05, 0), (0, 0.1, 0), (-0.004, 0.18, 0), (-0.042, 0.272, 0)] P.append(tube("forearm", fore, lambda s: 0.039 + 0.012 * s, SKIN, segs=9, per=2, ang=30)) sleeve = [(-0.042, 0.272, 0), (-0.13, 0.36, 0), (-0.28, 0.5, 0), (-0.47, 0.7, 0)] P.append(tube("sleeve", sleeve, lambda s: 0.058 + 0.008 * min(1.0, s * 2), SHIRT, segs=9, per=2, ang=30)) # the hem, turned up once P.append(tube("hem", [(-0.036, 0.262, 0), (-0.042, 0.272, 0), (-0.05, 0.282, 0)], lambda s: 0.064, SHIRT, segs=9, ang=30)) o = done(P, "Hand", uv=6.0, ang=30) if side < 0: mirror_x(o) return o def hand_r(): hand(1) return dict(elev=28, azim=150, dist_mul=0.74, extra=[("front", dict(elev=15, azim=-40, dist_mul=0.74), None)]) def hand_l(): hand(-1) return dict(elev=28, azim=-150, dist_mul=0.74, extra=[("front", dict(elev=15, azim=40, dist_mul=0.74), None)]) # ======================================================================= the creature, re-cut def arm_rings(body, sx): """Elliptic sections of the source arm: (cx, cy, rx, ry) at a height.""" me = body.data for ix in OC.islands(me): if len(ix) <= 600: continue pts = [me.vertices[i].co for i in ix] xs = [p.x for p in pts] if not (min(xs) > 0.1 if sx > 0 else max(xs) < -0.1): continue def sect(z): near = [p for p in pts if abs(p.z - z) < 0.016] or sorted(pts, key=lambda p: abs(p.z - z))[:30] x0, x1 = min(p.x for p in near), max(p.x for p in near) y0, y1 = min(p.y for p in near), max(p.y for p in near) return (x0 + x1) / 2, (y0 + y1) / 2, (x1 - x0) / 2, (y1 - y0) / 2 return sect raise RuntimeError("no arm island") def low_arm(body, sx): sect = arm_rings(body, sx) SL, GL = 0.445, 0.32 # sleeve hem and glove cuff prof = [(0.552, 0.0), (0.5, 0.008), (SL + 0.012, 0.01), (SL + 0.01, 0.019), (SL - 0.012, 0.019), (SL - 0.014, 0.0), (0.38, 0.0), (GL + 0.012, 0.0), (GL + 0.01, 0.018), (GL - 0.012, 0.018), (GL - 0.014, 0.007), (0.26, 0.007), (0.215, 0.007), (0.183, 0.004)] rings = [] for z, d in prof: cx, cy, rx, ry = sect(z) rings.append((cx, cy, rx + d, ry + d, z, 2.3)) top = sect(0.552) bot = sect(0.183) rings = [(top[0], top[1], 0, 0, 0.571)] + rings + [(bot[0], bot[1], 0, 0, 0.165)] rings = list(reversed(rings)) # loft runs bottom to top a = loft("arm", rings, segs=8, frame=None, smooth_ang=FACET) return paint(a, (SHIRT, SKIN, GLV), lambda c: 0 if c.z > SL - 0.002 else (1 if c.z > GL + 0.0 else 2)) def thumb(body, sx): sect = arm_rings(body, sx) cx, cy, rx, ry = sect(0.235) a = Vector((cx - sx * rx * 0.72, cy - ry * 0.3, 0.262)) b = a + Vector((-sx * 0.036, -0.012, -0.044)) return tube("mthumb", [a, a.lerp(b, 0.6), b], lambda s: 0.03 - 0.008 * s, GLV, segs=6, per=1, ang=FACET) def low_torso(S): """The capsule from its own surface. Rings land on the hems, so the clothes are clean bands.""" rings = [(0.205, 0.012), (0.24, 0.012), (0.29, 0.012), (0.335, 0.012), (0.362, 0.012), (0.364, 0.019), (0.38, 0.019), (0.382, 0.006), (0.45, 0.006), (0.52, 0.006), (0.598, 0.006), (0.6, 0.0), (0.66, 0.0), (0.74, 0.0), (0.82, 0.0), (0.885, 0.0), (0.935, 0.0), (0.975, 0.0)] N = 14 bm = bmesh.new() R = [] for z, off in rings: ring = [] for i in range(N): a = -90 + 360 * i / N if z < 0.235: # the source splits into legs down here, the ray would land between them d = Vector((math.cos(DEG(a)), math.sin(DEG(a)), 0)) ring.append(bm.verts.new(Vector((0, S.cy, z)) + d * (0.19 + off))) else: ring.append(bm.verts.new(S.p(a, z, off))) R.append(ring) pole = bm.verts.new((0, S.cy, 0.998)) for a, b in zip(R, R[1:]): for i in range(N): j = (i + 1) % N bm.faces.new((a[i], a[j], b[j], b[i])) for i in range(N): bm.faces.new((R[-1][i], R[-1][(i + 1) % N], pole)) bm.faces.new(list(reversed(R[0]))) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) o = mesh_obj("torso", bm) smooth(o, FACET) return paint(o, (SKIN, SHIRT, DENIM), lambda c: 2 if c.z < WAIST else (1 if c.z < COLLAR else 0)) EYE = 0.064 EYEZ = Vector((0.13, -0.178, 0.76)) def eye_p(c, lon, lat, r): a, b = DEG(lon), DEG(lat) return c + Vector((math.cos(b) * math.sin(a), -math.cos(b) * math.cos(a), math.sin(b))) * r def face(sx, F): """One side of the face. sx=+1 is the character's left. The two sides differ on purpose: one lid droops, one brow lifts.""" c = Vector((sx * EYEZ.x, EYEZ.y, EYEZ.z)) F.append(sphere("eye", EYE, tuple(c), seg=12, rings=7, m="M_EyeWhite")) # the pupil looks a little inward and up, so he seems to be sizing you up pc = c + Vector((-sx * 0.0095, -0.0615, -0.003)) F.append(sphere("pupil", 0.034, tuple(pc), seg=10, rings=5, m="M_Pupil", scale=(1.0, 0.38, 1.0))) F.append(sphere("glint", 0.009, tuple(pc + Vector((-0.0105, -0.011, 0.015))), seg=6, rings=3, m="M_PaintCream", scale=(1, 0.5, 1))) lat0 = 36 if sx > 0 else 27 lift = 11 if sx > 0 else 0 rl = EYE + 0.008 def lid(u, v, off): lon = -94 + 188 * u lat = lat0 + 7 * sx * math.sin(DEG(lon)) * -1 + (112 - lat0) * v return eye_p(c, lon, lat, rl + off) F.append(grid_slab("lid", lid, 8, 3, 0.012, -0.002, SKIN, smooth_ang=FACET)) rim = [lid(i / 8, 0.0, 0.013) for i in range(2, 7)] F.append(tube("lidrim", rim, lambda s: 0.0052, NOSE, segs=4, per=1, ang=FACET)) def lower(u, v, off): lon = -82 + 164 * u return eye_p(c, lon, -46 + (-30) * v, rl + off) F.append(grid_slab("bag", lower, 6, 1, 0.009, -0.002, SKIN, smooth_ang=FACET)) # the brow: a chunky wedge, heavier at the nose pts = [eye_p(c, sx * (-62 + 124 * k / 4) * -1, lat0 + 22 + lift + 7 * math.cos(DEG(-62 + 124 * k / 4)), rl + 0.03) for k in range(5)] F.append(tube("brow", pts, lambda s: (0.03 - 0.016 * s, 0.021 - 0.009 * s), HAIR, segs=6, per=1, ang=FACET)) # a sunburnt cheek k = Vector((sx * 0.135, -0.205, 0.63)) ck = sphere("cheek", 0.044, tuple(k), seg=7, rings=4, m=NOSE, scale=(1.0, 0.34, 0.72)) F.append(ck) # half of the mustache, drooping past the mouth and turned up at the end must = [(0.0, -0.272, 0.626), (sx * 0.06, -0.27, 0.622), (sx * 0.125, -0.238, 0.593), (sx * 0.17, -0.186, 0.586), (sx * 0.2, -0.13, 0.62)] F.append(tube("mustache", must, lambda s: (0.03 * (1 - s) ** 0.8 + 0.006, 0.024 * (1 - s) ** 0.8 + 0.006), HAIR, segs=6, per=1, ang=FACET)) def low_face(): F = [] face(1, F) face(-1, F) # a big bulbous nose between the eyes F.append(sphere("nose", 0.056, (0, -0.274, 0.668), seg=8, rings=5, m=NOSE, scale=(1.02, 0.9, 0.92))) F.append(sphere("bridge", 0.034, (0, -0.238, 0.712), seg=6, rings=4, m=SKIN, scale=(0.9, 1.2, 1.3))) return F def low_legs(): """Short denim stubs between the capsule and the boots.""" L = [] for sx in (1, -1): o = tube("leg", [(sx * 0.145, 0.016, 0.27), (sx * 0.145, 0.018, 0.215), (sx * 0.145, 0.022, 0.16)], lambda s: 0.1, DENIM, segs=8, per=1, ang=FACET) L.append(o) return L def crew_kerchief(S, tilt): """`Vest`: CrewAvatar tints this renderer per player, so it is the neckerchief and the hat band.""" P = [] band = lambda u, v, off: S.p(-268 + 356 * u, 0.586 + 0.034 * v, 0.03 + off + 0.008 * math.sin(math.pi * v)) P.append(grid_slab("band", band, 12, 1, 0.006, -0.008, "M_Teal", smooth_ang=FACET)) def tri(u, v, off): w = (1 - v) ** 0.9 * 40.0 + 0.8 a = -90 + (u - 0.5) * 2 * w z = 0.61 - 0.13 * v - 0.02 * abs(2 * u - 1) * (1 - v) return S.p(a, z, 0.044 + 0.012 * math.sin(math.pi * v) * (1 - abs(2 * u - 1)) + off) P.append(grid_slab("tri", tri, 4, 3, 0.004, -0.008, "M_Teal", smooth_ang=FACET)) kn = S.p(90, 0.606, 0.046) P.append(sphere("knot", 0.027, tuple(kn), seg=6, rings=4, m="M_Teal", scale=(1.2, 0.8, 1))) for sx in (-1, 1): pts = [kn, kn + Vector((sx * 0.03, 0.012, -0.045)), kn + Vector((sx * 0.062, 0.02, -0.105))] P.append(tube("ktail", pts, lambda s: (0.022 - 0.008 * s, 0.009), "M_Teal", segs=4, per=1, ang=FACET)) P.append(lathe("hatband", [(0.2345, 0.018), (0.2395, 0.024), (0.2395, 0.07), (0.2315, 0.076)], segs=12, m="M_Teal", frame=tilt, smooth_ang=FACET)) return done(P, "Vest", uv=3.0, ang=FACET) def crew_hat(tilt): """A wide straw hat, the same tilt and seat on the head. Bands of two straw tones, a bite out of the brim.""" P = [] crown = [(0.232, -0.012), (0.236, 0.02), (0.236, 0.06), (0.229, 0.1), (0.212, 0.135), (0.178, 0.162), (0.128, 0.182), (0.07, 0.196), (0.0, 0.2)] for i, (a, b) in enumerate(zip(crown, crown[1:])): P.append(lathe("crown", [a, b], segs=12, m="M_Hay" if i % 3 == 2 else "M_Straw", frame=tilt, smooth_ang=FACET)) bite = 4.1 def edge(a): d = min(abs(a - bite), TAU - abs(a - bite)) return 1 + 0.018 * math.sin(3 * a) - 0.13 * math.exp(-(d / 0.2) ** 2) def rim_z(a): return 0.014 * math.cos(2 * a) + 0.007 * math.sin(5 * a) rings = [(0.228, 0.0), (0.3, -0.0165), (0.335, -0.027), (0.36, -0.039)] def brim(i): r0, z0 = rings[i] r1, z1 = rings[i + 1] f = lambda a, r: 1 + (edge(a) - 1) * (r / 0.36) ** 3 return lambda a: [(r0 * f(a, r0), z0 + rim_z(a) * r0 / 0.36 + 0.004), (r1 * f(a, r1), z1 + rim_z(a) * r1 / 0.36 + 0.004)] for i in range(len(rings) - 1): P.append(revolve_fn("brim", 16, brim(i), m="M_Hay" if i == 1 else "M_Straw", frame=tilt, smooth_ang=FACET)) P.append(revolve_fn("under", 16, lambda a: [(0.361 * edge(a), -0.039 + rim_z(a) + 0.004), (0.228, -0.014)], m="M_Straw", frame=tilt, smooth_ang=FACET)) rnd = random.Random(8) for k in range(7): a = rnd.uniform(0, TAU) rr = 0.36 * edge(a) p0 = tilt @ Vector((math.cos(a) * rr * 0.98, math.sin(a) * rr * 0.98, -0.036 + rim_z(a))) p1 = tilt @ Vector((math.cos(a + rnd.uniform(-0.1, 0.1)) * (rr + rnd.uniform(0.03, 0.06)), math.sin(a + rnd.uniform(-0.1, 0.1)) * (rr + 0.04), -0.042 + rim_z(a))) P.append(tube("fray", [p0, p1], lambda s: 0.0046 - 0.002 * s, "M_Straw", segs=3, ang=FACET)) # a sprig of grass tucked in the band: he is proud of the job for dx, h, m in ((0.0, 0.2, "M_LeafDark"), (0.02, 0.16, "M_Leaf"), (-0.022, 0.13, "M_Leaf")): a = tilt @ Vector((0.238, 0.03 + dx, 0.03)) b = tilt @ Vector((0.262 + dx, 0.09 + dx * 2, 0.03 + h)) P.append(tube("sprig", [a, a.lerp(b, 0.6) + Vector((0.012, 0, 0)), b], lambda s: (0.013 * (1 - s) + 0.002, 0.0048), m, segs=4, per=1, ang=FACET)) return done(P, "Helmet", uv=4.0, ang=FACET) def crew_gear(S): """`Backpack`: the overalls' bib and straps, the burlap grass sack with its fill window, rope straps, the lantern.""" P = [] GAP = 0.02 def bibf(u, v, off): span = 66 - 18 * v a = -90 + (u - 0.5) * span z = 0.356 + (0.538 - 0.356) * v - 0.01 * v * (2 * u - 1) ** 2 return S.p(a, z, GAP + off) P.append(grid_slab("bib", bibf, 6, 4, 0.007, -0.012, DENIM, smooth_ang=FACET)) def backf(u, v, off): span = 74 - 34 * v return S.p(90 + (u - 0.5) * span, 0.356 + 0.12 * v, GAP + off) P.append(grid_slab("backp", backf, 5, 2, 0.007, -0.012, DENIM, smooth_ang=FACET)) def pocket(u, v, off): return S.p(-90 + (u - 0.5) * 30, 0.4 + 0.08 * v, GAP + 0.009 + off) P.append(grid_slab("pocket", pocket, 3, 2, 0.005, -0.004, DENIM, smooth_ang=FACET)) loop = [pocket(0, 1, 0.0065), pocket(0, 0, 0.0065), pocket(1, 0, 0.0065), pocket(1, 1, 0.0065)] P.append(tube("pstitch", loop, lambda s: 0.0036, GOLD, segs=4, per=1, ang=FACET)) edge = [bibf(0, 0.2, 0.0095), bibf(0, 1, 0.0095), bibf(0.5, 1, 0.0095), bibf(1, 1, 0.0095), bibf(1, 0.2, 0.0095)] P.append(tube("bstitch", edge, lambda s: 0.0034, GOLD, segs=4, per=1, ang=FACET)) # a pencil stub and a folded rag in the bib pocket q = pocket(0.3, 1, 0.012) P.append(tube("pencil", [q, q + Vector((-0.012, 0.0, 0.05))], lambda s: 0.0075, GOLD, segs=5, ang=FACET)) def strap_fn(path, w): C = catmull([(a, z, 0) for a, z in path], 3) def f(u, v, off): i = u * (len(C) - 1) i0 = min(int(i), len(C) - 2) t = i - i0 p = C[i0].lerp(C[i0 + 1], t) tan = C[i0 + 1] - C[i0] tan = Vector((tan.x * DEG(1) * 0.27, tan.y, 0)).normalized() nrm = Vector((-tan.y, tan.x, 0)) a = p.x + nrm.x * (v - 0.5) * w / (DEG(1) * 0.27) z = p.y + nrm.y * (v - 0.5) * w return S.p(a, z, GAP + 0.004 + off) return f, len(C) for sx in (1, -1): path = [(-90 + sx * 22, 0.532), (-90 + sx * 36, 0.568), (-90 + sx * 72, 0.59), (-90 + sx * 115, 0.585), (-90 + sx * 150, 0.53), (-90 + sx * 172, 0.47), (-90 + sx * 192, 0.42)] f, nc = strap_fn(path, 0.05) P.append(grid_slab("strap", f, nc, 1, 0.007, -0.006, DENIM, smooth_ang=FACET)) pb = S.p(-90 + sx * 21, 0.522, GAP + 0.012) stud(P, pb, (pb - Vector((0, S.cy, pb.z))).normalized(), r=0.021, h=0.012, m=BRASS) ps = S.p(-90 + sx * 62, 0.352, 0.03) stud(P, ps, (ps - Vector((0, S.cy, ps.z))).normalized(), r=0.016, h=0.01, m=BRASS) # the sack: the back surface sits where the fill window expects it cy_, zb, zt = 0.43, 0.285, 0.75 FB = Matrix.Translation((0, cy_, 0)) rx, ry = 0.205, 0.135 rings = [(0, 0, 0, 0, zb), (0, 0, rx * 0.72, ry * 0.7, zb + 0.004, 2.5), (0, 0, rx * 0.93, ry * 0.92, zb + 0.04, 2.5), (0, 0, rx * 1.04, ry * 1.02, zb + 0.13, 2.6), (0, 0, rx * 1.05, ry * 1.03, zb + 0.28, 2.6), (0, 0, rx * 0.93, ry * 0.92, zt - 0.08, 2.4), (0, 0, rx * 0.66, ry * 0.68, zt - 0.02, 2.2), (0, 0, rx * 0.38, ry * 0.46, zt + 0.02, 2.0), (0, 0, rx * 0.21, ry * 0.28, zt + 0.045, 2.0), (0, 0, rx * 0.2, ry * 0.27, zt + 0.06, 2.0), (0, 0, rx * 0.34, ry * 0.44, zt + 0.09, 2.0), (0, 0, rx * 0.4, ry * 0.5, zt + 0.115, 2.0), (0, 0, rx * 0.2, ry * 0.26, zt + 0.1, 2.0)] sack = loft("sack", rings, segs=12, m="M_Burlap", frame=FB, smooth_ang=FACET + 8) FT.pleats(sack, (0, cy_, 0), (0, 0, 1), n=6, amp=0.22, t0=zt - 0.08, t1=zt + 0.03) wobble(sack, 0.012, 6.5, seed=3.0) around(sack, (0, cy_, 0), (0, 0, 1), nu=4.5, s=4.6) P.append(sack) # a patch sewn on the sack cp = Vector((-0.17, cy_ + 0.075, 0.46)) fr = frame_on(cp, (-0.8, 0.6, 0), up=(0, 0, 1)) P.append(prism("spatch", [(-0.05, -0.04), (0.046, -0.046), (0.05, 0.042), (-0.042, 0.048)], 0.006, fr, "M_Canvas")) P.append(tube("twist", [(0.0, cy_, zt + 0.042), (0.0, cy_, zt + 0.07)], lambda s: 0.058, TWINE, segs=8, ang=FACET, cap=False)) tail = [(0.05, cy_ - 0.02, zt + 0.056), (0.095, cy_ - 0.05, zt + 0.05), (0.118, cy_ - 0.06, zt + 0.01), (0.12, cy_ - 0.05, zt - 0.03)] P.append(tube("tail", tail, lambda s: 0.0052, TWINE, segs=4, per=1, ang=FACET)) rnd = random.Random(4) for k in range(7): a = TAU * k / 7 + rnd.uniform(-0.2, 0.2) r_ = rnd.uniform(0.02, 0.062) p0 = Vector((math.cos(a) * r_, cy_ + math.sin(a) * r_ * 0.8, zt + 0.08)) p1 = p0 + Vector((math.cos(a) * rnd.uniform(0.03, 0.07), math.sin(a) * rnd.uniform(0.02, 0.05), rnd.uniform(0.09, 0.14))) P.append(tube("blade", [p0, p0.lerp(p1, 0.55) + Vector((0, 0, 0.012)), p1], lambda s: (0.024 * (1 - s) + 0.002, 0.008), rnd.choice(("M_Leaf", "M_LeafDark")), segs=4, per=1, ang=FACET)) # the fill window: a laced leather-edged slit wz0, wz1, ww = 0.433, 0.767, 0.082 wc = (wz0 + wz1) / 2 F = frame_on((0, 0.566, wc), (0, 1, 0), up=(0, 0, 1)) P.append(ring_prism("wframe", rrect_pts(ww + 0.056, wz1 - wz0 + 0.056, 0.04, 2), rrect_pts(ww, wz1 - wz0, 0.03, 2), 0.022, F, LEA, bevel=0.0)) P.append(prism("wback", rrect_pts(ww + 0.006, wz1 - wz0 + 0.006, 0.03, 2), 0.003, F, HAIR)) for k in range(5): z = wz0 + 0.035 + k * (wz1 - wz0 - 0.07) / 4 s_ = 1 if k % 2 else -1 P.append(tube("lace", [(-(ww / 2 + 0.018), 0.589, z + s_ * 0.014), (0, 0.593, z), ((ww / 2 + 0.018), 0.589, z - s_ * 0.014)], lambda s: 0.0048, TWINE, segs=4, per=1, ang=FACET)) fill = prism("TankFill", rrect_pts(ww - 0.004, wz1 - wz0 - 0.004, 0.028, 2), 0.012, F @ Matrix.Translation((0, 0, 0.004)), "M_Clippings") for sx in (1, -1): pts = [(sx * 0.13, cy_ - 0.1, 0.7), (sx * 0.19, 0.26, 0.655), S.p(90 - sx * 72, 0.632, 0.034), S.p(90 - sx * 108, 0.612, 0.034), S.p(90 - sx * 130, 0.555, 0.034), S.p(90 - sx * 143, 0.47, 0.03)] P.append(tube("rope", pts, lambda s: 0.0135, ROPE, segs=5, per=2, ang=FACET + 8)) P.append(sphere("rknot", 0.022, tuple(S.p(90 - sx * 143, 0.465, 0.034)), seg=6, rings=4, m=ROPE)) # the lantern clipped to the strap lc = S.p(-90 + 49, 0.47, 0.062) + Vector((0.012, -0.018, 0)) L = Matrix.Translation(lc) P.append(lathe("lbase", [(0.0, -0.05), (0.034, -0.05), (0.039, -0.04), (0.03, -0.028)], segs=8, m=BRASS, frame=L, smooth_ang=FACET)) P.append(lathe("ltop", [(0.03, 0.028), (0.037, 0.036), (0.02, 0.054), (0.0, 0.07)], segs=8, m=BRASS, frame=L, smooth_ang=FACET)) for k in range(4): a = DEG(45 + 90 * k) P.append(cyl("lrod", 0.0048, 0.06, lc + Vector((0.032 * math.cos(a), 0.032 * math.sin(a), 0)), verts=4, m=BRASS)) FT.ring_on(P, lc + Vector((0, 0, 0.082)), (0, 1, 0), 0.016, 0.0048, m=IRON, seg=8) P.append(tube("hook", [lc + Vector((0, 0, 0.096)), lc + Vector((-0.012, 0.018, 0.116))], lambda s: 0.0062, LEA, segs=4, ang=FACET)) lamp = lathe("Lamp", [(0.0, -0.03), (0.024, -0.03), (0.029, -0.012), (0.029, 0.012), (0.024, 0.03), (0.0, 0.03)], segs=8, m="M_Emissive", frame=L, smooth_ang=FACET) bp = done(P, "Backpack", uv=4.0, ang=FACET) set_origin(fill, (0, 0.57, wz0)) uv_box(fill, 3.0) return bp, fill, lamp, lc def work_boot(name, sx): """Chunky boot on a stepped sole. Same footprint and height as the old one.""" P = [] cx, cy = sx * 0.145, 0.012 FR = Matrix.Identity(4) P.append(loft("sole", [(cx, cy, 0, 0, 0.0), (cx, cy, 0.112, 0.142, 0.0, 3.0), (cx, cy, 0.126, 0.158, 0.012, 3.0), (cx, cy, 0.126, 0.158, 0.032, 3.0), (cx, cy, 0.121, 0.152, 0.042, 3.0)], segs=12, m="M_Rubber", cap1=True, smooth_ang=FACET)) P.append(loft("welt", [(cx, cy, 0.128, 0.16, 0.03, 3.0), (cx, cy, 0.131, 0.163, 0.037, 3.0), (cx, cy, 0.128, 0.16, 0.046, 3.0), (cx, cy, 0.118, 0.148, 0.052, 3.0)], segs=12, m=TIM, cap0=False, cap1=False, smooth_ang=FACET)) up = [(cx, cy - 0.002, 0.118, 0.148, 0.04, 2.8), (cx, cy - 0.004, 0.12, 0.15, 0.072, 2.6), (cx, cy + 0.006, 0.114, 0.138, 0.112, 2.4), (cx, cy + 0.02, 0.102, 0.114, 0.146, 2.2), (cx, cy + 0.03, 0.096, 0.1, 0.21, 2.1)] P.append(loft("upper", up, segs=12, m=LEA, cap0=False, cap1=True, smooth_ang=FACET)) # a scuffed steel toe and a heel counter tf = [(cx, cy - 0.098, 0.098, 0.066, 0.046, 2.6), (cx, cy - 0.1, 0.1, 0.066, 0.078, 2.4), (cx, cy - 0.094, 0.082, 0.05, 0.103, 2.2), (cx, cy - 0.09, 0.06, 0.034, 0.112, 2.0), (cx, cy - 0.09, 0, 0, 0.114)] P.append(loft("toe", tf, segs=10, m=STL, cap0=False, smooth_ang=FACET)) P.append(loft("heelc", [(cx, cy + 0.098, 0.085, 0.055, 0.046, 2.6), (cx, cy + 0.098, 0.086, 0.055, 0.1, 2.4), (cx, cy + 0.1, 0.07, 0.04, 0.122, 2.2)], segs=8, m=HAIR, cap0=False, smooth_ang=FACET)) for k in range(3): z = 0.118 + k * 0.03 y = cy - 0.098 + k * 0.014 P.append(tube("lace", [(cx - 0.034, y + 0.004, z), (cx, y - 0.002, z + 0.002), (cx + 0.034, y + 0.004, z)], lambda s: 0.0082, ROPE, segs=4, per=1, ang=FACET)) P.append(lathe("turnup", [(0.095, 0.2), (0.11, 0.205), (0.112, 0.238), (0.09, 0.242)], segs=12, m=DENIM, frame=Matrix.Translation((cx, cy + 0.03, 0)), smooth_ang=FACET)) P.append(lathe("turnst", [(0.1135, 0.212), (0.1145, 0.214), (0.1145, 0.218), (0.1135, 0.22)], segs=12, m=GOLD, frame=Matrix.Translation((cx, cy + 0.03, 0)), smooth_ang=FACET)) return done(P, name, uv=4.0, ang=FACET) def skin_new(new, rig, armL, armR, legs): """The same weighting as os_crew.crew_rig: arms rigid on their bones, a blend from the body into the legs.""" sc = OC.CREW_H vg = {n: new.vertex_groups.new(name=n) for n in ("Body", "Leg_L", "Leg_R", "Arm_L", "Arm_R")} for v in new.data.vertices: i, p = v.index, v.co if armL[0] <= i < armL[1]: vg["Arm_L"].add([i], 1.0, "REPLACE") elif armR[0] <= i < armR[1]: vg["Arm_R"].add([i], 1.0, "REPLACE") elif legs[0] <= i < legs[1]: w = 1 - OC.smoothstep(0.2 * sc + LEGS, 0.27 * sc + LEGS, p.z) vg["Leg_L" if p.x > 0 else "Leg_R"].add([i], w, "REPLACE") if w < 0.999: vg["Body"].add([i], 1 - w, "REPLACE") else: wl = (1 - OC.smoothstep(0.16 * sc + LEGS, 0.27 * sc + LEGS, p.z)) * OC.smoothstep(0.004 * sc, 0.055 * sc, abs(p.x)) if wl > 0.001: vg["Leg_L" if p.x > 0 else "Leg_R"].add([i], wl, "REPLACE") if wl < 0.999: vg["Body"].add([i], 1 - wl, "REPLACE") new.parent = rig new.parent_type = "OBJECT" md = new.modifiers.new("Armature", "ARMATURE") md.object = rig def crew(): body = OC.load_creature() S = OC.BodySurf(body) ctr = Vector((0, 0.03, 0.885)) tilt = Matrix.Translation(ctr) @ Matrix.Rotation(DEG(-11), 4, "X") vest = crew_kerchief(S, tilt) hat = crew_hat(tilt) bp, fill, lamp, lc = crew_gear(S) bl = work_boot("Boot_L", 1) br = work_boot("Boot_R", -1) # the new body: joined in a known order, so the vertex ranges of arms and legs are known core = [low_torso(S)] + low_face() legs = low_legs() arm_l, arm_r = [low_arm(body, 1), thumb(body, 1)], [low_arm(body, -1), thumb(body, -1)] groups = (core, legs, arm_l, arm_r) cnt = [sum(len(o.data.vertices) for o in g) for g in groups] new = done([o for g in groups for o in g], "CrewBodyNew", uv=3.0, ang=FACET) # bring everything to the final size, the old body too: crew_rig measures the arms on it sc = Matrix.Scale(OC.CREW_H, 4) for o in (body, new, vest, hat, lamp, bp, fill, bl, br): o.data.transform(sc @ o.matrix_world) o.matrix_world = Matrix.Identity(4) # the legs grow: everything above them rises as it is, only the leg tubes stretch, and the boots stay on the ground OC.HIP = LEGS a = cnt[0] b = a + cnt[1] for v in new.data.vertices: v.co.z += LEGS * (OC.smoothstep(0.2, 0.262, v.co.z) if a <= v.index < b else 1.0) for o in (body, vest, hat, lamp, bp, fill): for v in o.data.vertices: v.co.z += LEGS lift = Matrix.Translation((0, 0, LEGS)) set_origin(fill, lift @ sc @ Vector((0, 0.57, 0.433))) set_origin(lamp, lift @ sc @ lc) G = dict(body=body, vest=vest, helmet=hat, lamp=lamp, backpack=bp, fill=fill, boot_l=bl, boot_r=br) rig = OC.crew_rig(G) # the rig stands, measured from the source creature: swap the skinned mesh d = body.data bpy.data.objects.remove(body) bpy.data.meshes.remove(d) new.name = "CrewBody" new.data.name = "CrewBody" a = cnt[0] + cnt[1] skin_new(new, rig, (a, a + cnt[2]), (a + cnt[2], a + cnt[2] + cnt[3]), (cnt[0], cnt[0] + cnt[1])) bpy.context.view_layer.update() OC.pose(rig, {}) return dict(elev=12, azim=-30, dist_mul=0.8, rigged=rig, extra=[("pose", dict(elev=10, azim=-55), {"Leg_L": (DEG(30), 0, 0), "Leg_R": (DEG(-30), 0, 0), "Arm_L": (DEG(-30), 0, 0), "Arm_R": (DEG(35), 0, 0), "Body": (0, DEG(6), 0)}), ("back", dict(elev=15, azim=150), {}), ("side", dict(elev=8, azim=-90), {}), ("aim", dict(elev=8, azim=-50), {"Arm_R": (DEG(-80), 0, 0)}), ("head", dict(elev=6, azim=-22, target=(0, -0.1, 1.0), radius=0.42), {}), ("drive", dict(elev=8, azim=-60), {"Leg_L": (DEG(-60), 0, 0), "Leg_R": (DEG(-60), 0, 0), "Arm_L": (DEG(-55), 0, 0), "Arm_R": (DEG(-55), 0, 0)})]) BUILDERS = {"SM_Glove_R": glove_r, "SM_Glove_L": glove_l, "SM_Hand_R": hand_r, "SM_Hand_L": hand_l} if __name__ == "__main__": args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] for nm in (args or list(BUILDERS)): reset() random.seed(7) r = BUILDERS[nm]() or {} OC.finish_x(nm, r)