gc_up5_tools (blades: scythes, shears, sickle, hammer, nail scissors), gc_up5_machines (lawn mower and the four farm machines), gc_up5_props (hand can, cigar, phone, phone hand, beer cans) and gc_up5_check (verify against the game FBX, previews, review scene). Output in ArtSource/Blender/remaster_v3_tools with Hand_Tools_v3_Review.blend; the hand items review scene from round 1. Preview half-panels are ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1823 lines
94 KiB
Python
1823 lines
94 KiB
Python
"""GRASS CUTTER - round 5 detail pass on the first-person hand-held props: SM_HandCan, SM_HandCigar, SM_Phone, SM_PhoneHand.
|
|
|
|
Same level of detail as the round 5 pilot (gc_up5_tools.py), same frames as the models they replace:
|
|
|
|
SM_HandCan gc_vend.hand_can. Hand (right hand round the can) and Can (with child Tab, origin on its rivet at z = TOPZ).
|
|
Can: a smooth 48-sided body with the GRASS BEER label, a tapered heel and a domed bottom on a standing bead,
|
|
a die-necked shoulder, a rolled double-seam rim, a recessed lid (chuck wall, countersink, panel bead, rivet button,
|
|
the scored opening with its stiffening bead). Tab: a stay-on ring pull with curled edges, a finger hole and a domed rivet.
|
|
SM_HandCigar gc_vend.hand_cigar. Hand, Cigar (turned 90 degrees about Z, SM_Cigar's frame), Ember (child of Cigar, at the +X tip).
|
|
Cigar: a helical wrapper seam with leaf veins, a rounded cap with its cap line and a cut, a raised band with gold beads
|
|
and a red seal, an ash end with a jagged burn line; Ember: a crusty glowing coal.
|
|
Hands the same finger centre lines, radii and contact points as gc_vend; the skin is one blended surface (voxel remesh of
|
|
the palm, fingers, thumb and wrist, then decimated) with knuckle creases, knuckle wrinkles, cuticles and fingernails.
|
|
The shirt cuff has a rolled edge, a top-stitch groove, a seam where it meets the sleeve, a placket and a button with
|
|
its thread; the sleeve has pleats at the cuff, drape folds and a seam welt.
|
|
SM_Phone gc_phone. One body mesh (the game's Phone.cs takes the one non-Screen renderer as the body and finds the glow slot by
|
|
name) and the child Screen, built by gc_phone.screen() itself so its position, size, winding and UVs are untouched.
|
|
Body: a rugged bumper band with a rounded section, raised lips over the glass and the back, corner guards that stand
|
|
proud of the lips with a screw in each, a chamfered bezel with the light line round the display, the light line round
|
|
the band, side buttons with chamfers, grip ridges and guard fences, a USB-C port with its tongue, speaker and mic holes
|
|
(boolean cuts), a speaker grille on the back, a two-step camera bump with three lens stacks (metal ring, retaining
|
|
ring, black ring, domed glass), screws on the bump, cooling ribs, the company mark and a ribbed antenna.
|
|
SM_PhoneHand gc_phone_hand. The left hand round the phone, in the phone's frame (origin and axes of SM_Phone), one object.
|
|
As the brief asks it is the work glove: a blended leather glove (fingers lifted just clear of the new bumper), side
|
|
seam welts on every finger, padded knuckle guards over the knuckles and the middle joints with stitching round them,
|
|
reinforced fingertips, a thumb patch, a leather gauntlet with a rolled edge, a strap and a brass buckle, then the bare
|
|
forearm and the shirt cuff and sleeve. To clear the new bumper (verify: no intersecting triangles) the glove's thenar sits
|
|
5 mm further behind the phone, the thumb runs 1-2 mm further out along the left edge, and the wrist/gauntlet root is
|
|
dropped 7 mm behind the bottom-left corner (gc_phone_hand's own hand already dipped into the old phone there). gc_phone_hand.py itself is bare (M_CrewSkin): GC5_PHONEHAND_BARE=1 builds a
|
|
bare version with nails and creases instead. SM_PhoneHand is not in Assets/Art/Models and no game code loads it, so its
|
|
reference is gc_phone_hand.py's own build.
|
|
|
|
Material slots stay the ones the game FBX uses (M_ materials, all existing .mat files). No pack parts.
|
|
Blender space: metres, Z up, front -Y (Unity +Z), Unity +X = Blender -X. The hands and the phone are seen from +Y.
|
|
|
|
Output (never Assets): ArtSource/Blender/remaster_v3_tools/<name>.blend, fbx/<name>.fbx, previews/<name>_<view>.png.
|
|
Run (absolute paths, one Blender per command):
|
|
blender -b --factory-startup --python C:/Github/Grass-Cutters/ArtSource/Blender/scripts/gc_up5_props.py -- build [names]
|
|
blender -b --factory-startup --python .../gc_up5_props.py -- verify [names] frame against Assets/Art/Models (+ Screen UVs, clipping)
|
|
blender -b --factory-startup --python .../gc_up5_props.py -- views [names] old | new panels -> previews/_panels
|
|
blender -b --factory-startup --python .../gc_up5_props.py -- fpv [names] the in-game first-person poses (TreatHand, Phone)
|
|
python C:/Github/Grass-Cutters/ArtSource/Blender/scripts/gc_up5_props.py compose [names] panels -> previews/<name>_<view>.png
|
|
"""
|
|
import sys, os, math, random, zlib, bisect
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
ROOT = os.path.normpath(os.path.join(HERE, "..", "..", ".."))
|
|
OUT = os.path.join(ROOT, "ArtSource", "Blender", "remaster_v3_tools")
|
|
GAME = os.path.join(ROOT, "Assets", "Art", "Models")
|
|
PANELS = os.path.join(OUT, "previews", "_panels")
|
|
REF = os.path.join(OUT, "fbx", "_ref")
|
|
NAMES = ["SM_HandCan", "SM_HandCigar", "SM_Phone", "SM_PhoneHand", "SM_BeerCan", "SM_BeerCanCrushed"]
|
|
TAU = 2 * math.pi
|
|
DEG = math.radians
|
|
|
|
|
|
# ======================================================================= compose (outside Blender)
|
|
|
|
def compose(names):
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
try:
|
|
font, small = ImageFont.truetype("arial.ttf", 26), ImageFont.truetype("arial.ttf", 20)
|
|
except Exception:
|
|
font = small = ImageFont.load_default()
|
|
made = []
|
|
for fn in sorted(os.listdir(PANELS)):
|
|
if not fn.endswith("_old.png") or not any(fn.startswith(n + "_") for n in names):
|
|
continue
|
|
key = fn[:-len("_old.png")]
|
|
a, b = os.path.join(PANELS, fn), os.path.join(PANELS, key + "_new.png")
|
|
if not os.path.exists(b):
|
|
continue
|
|
A, B = Image.open(a).convert("RGB"), Image.open(b).convert("RGB")
|
|
w, h = A.size
|
|
bar = 44
|
|
im = Image.new("RGB", (w * 2 + 8, h + bar), (30, 32, 36))
|
|
im.paste(A, (0, bar))
|
|
im.paste(B, (w + 8, bar))
|
|
d = ImageDraw.Draw(im)
|
|
d.text((14, 9), "before (game / gc_phone_hand)", fill=(230, 230, 230), font=font)
|
|
d.text((w + 22, 9), "round 5", fill=(255, 214, 120), font=font)
|
|
d.text((w * 2 + 8 - 14 - d.textlength(key, font=small), 13), key, fill=(170, 170, 170), font=small)
|
|
out = os.path.join(OUT, "previews", key + ".png")
|
|
im.save(out)
|
|
made.append(out)
|
|
print("\n".join(made))
|
|
|
|
|
|
if __name__ == "__main__" and "compose" in sys.argv[1:2]:
|
|
compose([a for a in sys.argv[2:] if a in NAMES] or NAMES)
|
|
sys.exit(0)
|
|
|
|
# ======================================================================= Blender side
|
|
|
|
sys.path.insert(0, HERE)
|
|
import bpy, bmesh
|
|
from mathutils import Vector, Matrix
|
|
from mathutils.bvhtree import BVHTree
|
|
from mathutils.kdtree import KDTree
|
|
import common
|
|
from common import mat, mesh_obj, set_mats, smooth, join, set_origin, apply_xform, bake, mod, tri_count
|
|
import gc_up5_tools as T5 # round 5 helpers: sweep, fz, frames
|
|
from os_crew import catmull, sweep_circle
|
|
import gc_farm_tools as FT
|
|
import gc_vend as GV
|
|
import gc_phone as GP
|
|
import gc_phone_hand as GPH
|
|
|
|
SKIN, SLEEVE = "M_CrewSkin", "M_PaintRed"
|
|
STEEL, GREEN, GOLD, CREAM, LEAFG, SOOT = "M_Steel", "M_PaintDarkGreen", "M_Gold", "M_PaintCream", "M_PaintGreen", "M_Soot"
|
|
ASH, WRAP, WRAP2, REDP, EMBER = "M_Concrete", "M_Leather", "M_Bark", "M_PaintRed", "M_Ember"
|
|
GLOVE, GLEATH, STITCH, BRASS = "M_GloveOrange", "M_Leather", "M_PaintCream", "M_Brass"
|
|
CR, TOPZ, CIG_R, FOOT = GV.CR, GV.TOPZ, GV.CIG_R, GV.FOOT
|
|
SLOTS = {"Hand": [SKIN, SLEEVE], "Can": [STEEL, GREEN, GOLD, CREAM, LEAFG, SOOT], "Tab": [STEEL],
|
|
"Cigar": [ASH, WRAP, GOLD, CREAM, WRAP2, REDP], "Ember": [EMBER], "SM_Phone": list(GP.MATS), "Screen": ["M_PhoneIdle"],
|
|
"SM_PhoneHand": [SKIN, SLEEVE, GLOVE, GLEATH, STITCH, BRASS], "Body": [STEEL, GREEN, GOLD, CREAM, LEAFG, SOOT]}
|
|
BUDGET = {"SM_HandCan": 20000, "SM_HandCigar": 20000, "SM_Phone": 20000, "SM_PhoneHand": 20000, "SM_BeerCan": 12000, "SM_BeerCanCrushed": 16000}
|
|
|
|
|
|
# ======================================================================= small helpers
|
|
|
|
def smoothstep(a, b, x):
|
|
t = max(0.0, min(1.0, (x - a) / (b - a)))
|
|
return t * t * (3 - 2 * t)
|
|
|
|
|
|
def perp(v, t):
|
|
w = Vector(v) - t * Vector(v).dot(t)
|
|
return w.normalized() if w.length > 1e-9 else t.orthogonal().normalized()
|
|
|
|
|
|
def reorder(o, names):
|
|
"""Material slots in the order of `names` (any others after them)."""
|
|
me = o.data
|
|
cur = [m.name.split(".")[0] if m else "" for m in me.materials]
|
|
order = [n for n in names if n in cur] + [n for n in cur if n not in names]
|
|
idx = [order.index(cur[p.material_index]) for p in me.polygons]
|
|
me.materials.clear()
|
|
for n in order:
|
|
me.materials.append(mat(n))
|
|
me.polygons.foreach_set("material_index", idx)
|
|
me.update()
|
|
return o
|
|
|
|
|
|
def obj_from_bm(name, bm, mats, ang=40):
|
|
idx = [f.material_index for f in bm.faces]
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, *mats)
|
|
o.data.polygons.foreach_set("material_index", idx)
|
|
o.data.update()
|
|
smooth(o, ang)
|
|
return o
|
|
|
|
|
|
def finish(P, name, uv=6.0, ang=45, slots=None):
|
|
"""Box UVs on parts without their own, one UVMap layer, joined, ngons triangulated, slots ordered."""
|
|
o = FT.done([q for q in P if q is not None], name, uv=uv, ang=ang)
|
|
GV.tri_all(o)
|
|
smooth(o, ang)
|
|
if slots:
|
|
reorder(o, slots)
|
|
return o
|
|
|
|
|
|
def lathe5(name, prof, mats, colfn=None, segs=32, rfn=None, frame=None, ang=40, ph=0.0):
|
|
"""Surface of revolution about local Z. prof [(r, z)] (r == 0: a pole). colfn(k, j) -> slot of the face from profile point k to k + 1,
|
|
segment j round. rfn(r, z, theta, k) -> the radius actually used (noise, a spiral seam...). Faces point to the right of the profile."""
|
|
bm = bmesh.new()
|
|
R = []
|
|
for k, (r, z) in enumerate(prof):
|
|
if r <= 1e-7:
|
|
R.append([bm.verts.new((0.0, 0.0, z))])
|
|
continue
|
|
ring = []
|
|
for j in range(segs):
|
|
th = TAU * j / segs + ph
|
|
rr = rfn(r, z, th, k) if rfn else r
|
|
ring.append(bm.verts.new((rr * math.cos(th), rr * math.sin(th), z)))
|
|
R.append(ring)
|
|
for k in range(len(R) - 1):
|
|
a, b = R[k], R[k + 1]
|
|
for j in range(segs):
|
|
jj = (j + 1) % segs
|
|
if len(a) == 1 and len(b) == 1:
|
|
continue
|
|
if len(a) == 1:
|
|
f = bm.faces.new((a[0], b[jj], b[j]))
|
|
elif len(b) == 1:
|
|
f = bm.faces.new((a[j], a[jj], b[0]))
|
|
else:
|
|
f = bm.faces.new((a[j], a[jj], b[jj], b[j]))
|
|
f.material_index = colfn(k, j) if colfn else 0
|
|
if frame is not None:
|
|
bmesh.ops.transform(bm, matrix=frame, verts=bm.verts)
|
|
return obj_from_bm(name, bm, mats, ang)
|
|
|
|
|
|
def closed_catmull(pts, per=4):
|
|
P = [Vector(p) for p in pts]
|
|
n = len(P)
|
|
out = []
|
|
for i in range(n):
|
|
p0, p1, p2, p3 = P[i - 1], P[i], P[(i + 1) % n], P[(i + 2) % n]
|
|
for k in range(per):
|
|
t = k / per
|
|
t2, t3 = t * t, t * t * t
|
|
out.append(0.5 * ((2 * p1) + (-p0 + p2) * t + (2 * p0 - 5 * p1 + 4 * p2 - p3) * t2 + (-p0 + 3 * p1 - 3 * p2 + p3) * t3))
|
|
return out
|
|
|
|
|
|
def loop_sweep(name, C, up, sec, m, ang=50):
|
|
"""A closed tube along the closed polyline C; sec -> [(a, b)]: a across (in the plane, outward of the loop's left side), b along `up`."""
|
|
C = [Vector(p) for p in C]
|
|
n = len(C)
|
|
up = Vector(up).normalized()
|
|
bm = bmesh.new()
|
|
R = []
|
|
for i in range(n):
|
|
t = (C[(i + 1) % n] - C[i - 1]).normalized()
|
|
a = t.cross(up).normalized()
|
|
R.append([bm.verts.new(C[i] + a * x + up * y) for x, y in sec])
|
|
k = len(sec)
|
|
for i in range(n):
|
|
A, B = R[i], R[(i + 1) % n]
|
|
for j in range(k):
|
|
jj = (j + 1) % k
|
|
bm.faces.new((A[j], A[jj], B[jj], B[j]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
return obj_from_bm(name, bm, [m], ang)
|
|
|
|
|
|
def ellipse_sec(a, b, n=8):
|
|
return [(a * math.cos(TAU * q / n), b * math.sin(TAU * q / n)) for q in range(n)]
|
|
|
|
|
|
def surface_patch(name, P, H, nu, nv, base, m, bvh=None, ang=45, use_nrm=False):
|
|
"""A thin slab lying on a surface: P(u, v) -> (point near the surface, outward direction); snapped to the nearest point of bvh when given.
|
|
Top at H(u, v) above the surface, bottom `base` below it, closed round the sides."""
|
|
bm = bmesh.new()
|
|
top, bot = [], []
|
|
for i in range(nu + 1):
|
|
rt, rb = [], []
|
|
for j in range(nv + 1):
|
|
u, v = i / nu, j / nv
|
|
q, d = P(u, v)
|
|
q, d = Vector(q), Vector(d).normalized()
|
|
if bvh is not None:
|
|
loc, nrm, _, _ = bvh.find_nearest(q)
|
|
if loc is not None:
|
|
q = loc
|
|
if use_nrm:
|
|
d = nrm if nrm.dot(d) > 0 else -nrm
|
|
rt.append(bm.verts.new(q + d * H(u, v)))
|
|
rb.append(bm.verts.new(q - d * base))
|
|
top.append(rt)
|
|
bot.append(rb)
|
|
for i in range(nu):
|
|
for j in range(nv):
|
|
bm.faces.new((top[i][j], top[i + 1][j], top[i + 1][j + 1], top[i][j + 1]))
|
|
bm.faces.new((bot[i][j + 1], bot[i + 1][j + 1], bot[i + 1][j], bot[i][j]))
|
|
ring_t = [top[i][0] for i in range(nu + 1)] + [top[nu][j] for j in range(1, nv + 1)] + [top[i][nv] for i in range(nu - 1, -1, -1)] + \
|
|
[top[0][j] for j in range(nv - 1, 0, -1)]
|
|
ring_b = [bot[i][0] for i in range(nu + 1)] + [bot[nu][j] for j in range(1, nv + 1)] + [bot[i][nv] for i in range(nu - 1, -1, -1)] + \
|
|
[bot[0][j] for j in range(nv - 1, 0, -1)]
|
|
L = len(ring_t)
|
|
for k in range(L):
|
|
kk = (k + 1) % L
|
|
bm.faces.new((ring_t[k], ring_b[k], ring_b[kk], ring_t[kk]))
|
|
# orient: the top faces go along the outward direction
|
|
bm.normal_update()
|
|
bm.faces.ensure_lookup_table()
|
|
f0 = bm.faces[(nu // 2) * nv * 2]
|
|
q, d = P((nu // 2 + 0.5) / nu, 0.5 / nv)
|
|
if f0.normal.dot(Vector(d)) < 0:
|
|
bmesh.ops.reverse_faces(bm, faces=bm.faces)
|
|
return obj_from_bm(name, bm, [m], ang)
|
|
|
|
|
|
# ======================================================================= digits and the organic skin
|
|
|
|
def digit_rf(r, joints):
|
|
"""gc_farm_tools.digit's radius: soft swellings at the joints, a squared-off padded tip."""
|
|
tip0 = 0.84
|
|
|
|
def rf(s):
|
|
k = (0.93 + 0.1 * sum(math.exp(-((s - j) / 0.06) ** 2) for j in joints)) * (1.04 - 0.14 * s)
|
|
if s > tip0:
|
|
t = (s - tip0) / (1 - tip0)
|
|
k *= math.sqrt(max(0.0, 1 - t ** 4)) * 0.94 + 0.06
|
|
return r * k
|
|
return rf
|
|
|
|
|
|
class Digit:
|
|
"""A finger or thumb: the centre line through pts (Catmull-Rom, as FT.digit), the radius of FT.digit, and a palm-side direction D
|
|
(perpendicular to the line, towards what the finger closes on). Angles round it: 0 on the back (nail side), +90 towards B = T x D."""
|
|
|
|
def __init__(self, pts, r, joints, inside, per=10, grow=0.0, kind="finger"):
|
|
self.pts = [Vector(p) for p in pts]
|
|
self.per, self.r, self.joints, self.grow, self.kind = per, r, joints, grow, kind
|
|
base = digit_rf(r, joints)
|
|
self.rf = lambda s: base(s) + grow * (1.0 if s < 0.84 else max(0.3, 1 - (s - 0.84) / 0.16))
|
|
C = catmull(self.pts, per)
|
|
L = [0.0]
|
|
for a, b in zip(C, C[1:]):
|
|
L.append(L[-1] + (b - a).length)
|
|
self.C, self.L, self.tot = C, L, L[-1]
|
|
n = len(C)
|
|
self.T = [(C[min(i + 1, n - 1)] - C[max(i - 1, 0)]).normalized() for i in range(n)]
|
|
D = [perp(Vector(inside(C[i], self.T[i])), self.T[i]) for i in range(n)]
|
|
for _ in range(4):
|
|
D = [perp(D[max(i - 1, 0)] + D[i] * 2 + D[min(i + 1, n - 1)], self.T[i]) for i in range(n)]
|
|
self.D = D
|
|
|
|
def frame(self, s):
|
|
x = max(0.0, min(1.0, s)) * self.tot
|
|
i = max(0, min(len(self.L) - 2, bisect.bisect_right(self.L, x) - 1))
|
|
f = (x - self.L[i]) / max(1e-9, self.L[i + 1] - self.L[i])
|
|
c = self.C[i].lerp(self.C[i + 1], f)
|
|
T = self.T[i].lerp(self.T[i + 1], f).normalized()
|
|
D = perp(self.D[i].lerp(self.D[i + 1], f), T)
|
|
return c, T, D, T.cross(D)
|
|
|
|
def surf(self, s, th, h=0.0):
|
|
c, T, D, B = self.frame(s)
|
|
d = -D * math.cos(th) + B * math.sin(th)
|
|
return c + d * (self.rf(s) + h), d
|
|
|
|
def tube(self, name, m, segs=16):
|
|
return sweep_circle(name, self.pts, lambda s, l: self.rf(s), segs=segs, per=self.per, m=m, cap=True, smooth_ang=70)
|
|
|
|
|
|
SKIN_CREASES = dict(palm=[[(-0.0012, 0.0006, 0.0006), (0.0013, 0.00055, 0.0006)], [(-0.0009, 0.00065, 0.00055), (0.001, 0.0005, 0.0005)],
|
|
[(0.0, 0.00055, 0.0005)]],
|
|
dorsal=(0.00026, 0.00034, (-0.0021, -0.0007, 0.0007, 0.0021)), bulge=(0.0006, 0.0035), cuticle=0.745)
|
|
GLOVE_CREASES = dict(palm=[[(0.0, 0.0006, 0.0009)], [(-0.0012, 0.00055, 0.0008), (0.0014, 0.0005, 0.0008)], [(0.0, 0.0005, 0.0008)]],
|
|
dorsal=(0.00028, 0.0006, (-0.0032, 0.0, 0.0032)), bulge=(0.0, 0.003), cuticle=None)
|
|
|
|
|
|
def crease_pass(o, digits, spec):
|
|
"""Knuckle creases on the palm side, wrinkles and the knuckle swell on the back, a cuticle groove: the dense skin moved along its normal."""
|
|
kd = KDTree(sum(len(d.C) for d in digits))
|
|
idx = []
|
|
for di, d in enumerate(digits):
|
|
for i, c in enumerate(d.C):
|
|
kd.insert(c, len(idx))
|
|
idx.append((di, i))
|
|
kd.balance()
|
|
me = o.data
|
|
co = [v.co.copy() for v in me.vertices]
|
|
for vi, p in enumerate(co):
|
|
best = None
|
|
for (q, k, dist) in kd.find_n(p, 6):
|
|
di, i = idx[k]
|
|
d = digits[di]
|
|
s = d.L[i] / d.tot + (p - q).dot(d.T[i]) / d.tot
|
|
if s < -0.02 or s > 1.0:
|
|
continue
|
|
c, T, D, B = d.frame(s)
|
|
rv = p - c - T * (p - c).dot(T)
|
|
err = abs(rv.length - d.rf(s))
|
|
if best is None or err < best[0]:
|
|
best = (err, d, s, rv, D)
|
|
if best is None:
|
|
continue
|
|
err, d, s, rv, D = best
|
|
if err > 0.0022 or rv.length < 1e-6:
|
|
continue
|
|
n = rv.normalized()
|
|
cp = n.dot(D)
|
|
pw, bw = smoothstep(0.1, 0.6, cp), smoothstep(0.15, 0.6, -cp)
|
|
disp = 0.0
|
|
for jn, j in enumerate(d.joints):
|
|
x = (s - j) * d.tot
|
|
if abs(x) > 0.009:
|
|
continue
|
|
for off, dep, w in spec["palm"][min(jn, len(spec["palm"]) - 1)]:
|
|
disp -= dep * math.exp(-((x - off) / w) ** 2) * pw
|
|
if jn > 0 or d.kind == "thumb":
|
|
dep, w, offs = spec["dorsal"]
|
|
for off in offs:
|
|
disp -= dep * math.exp(-((x - off) / w) ** 2) * bw * math.exp(-(off / 0.004) ** 2)
|
|
hb, wb = spec["bulge"]
|
|
disp += hb * math.exp(-(x / wb) ** 2) * bw
|
|
if spec.get("cuticle"):
|
|
# the nail folds: a groove under the cuticle and down both sides of the nail
|
|
c_, T_, D_, B_ = d.frame(s)
|
|
th = math.atan2(n.dot(B_), -n.dot(D_))
|
|
x = (s - spec["cuticle"]) * d.tot
|
|
fold = abs(abs(th) - DEG(43) * (0.78 + 0.22 * smoothstep(0.0, 0.4, (s - spec["cuticle"]) / 0.2)))
|
|
along = smoothstep(-0.0005, 0.0005, x) * (1 - smoothstep(0.9, 0.97, s))
|
|
disp -= 0.00042 * math.exp(-(x / 0.0006) ** 2) * smoothstep(0.4, 0.8, -cp)
|
|
disp -= 0.0004 * math.exp(-(fold / DEG(4)) ** 2) * along
|
|
if disp:
|
|
me.vertices[vi].co = p + n * disp
|
|
me.update()
|
|
|
|
|
|
def soften(o, spots, iters=300):
|
|
"""Extra smoothing where separate parts were blended (the wrist into the heel of the hand): weights fall off from each spot."""
|
|
vg = o.vertex_groups.new(name="soft")
|
|
for v in o.data.vertices:
|
|
w = max(math.exp(-((v.co - Vector(c)).length / r) ** 2) for c, r in spots)
|
|
if w > 0.02:
|
|
vg.add([v.index], min(1.0, w * 1.3), "REPLACE")
|
|
md = o.modifiers.new("soft", "SMOOTH")
|
|
md.factor, md.iterations, md.vertex_group = 1.0, iters, "soft"
|
|
bake(o)
|
|
o.vertex_groups.clear()
|
|
|
|
|
|
def organic(parts, name, m, digits, voxel=0.0006, tris=10000, spec=SKIN_CREASES, smooth_it=6, soft=None):
|
|
"""Join closed parts and remesh them into one blended surface; creases on the dense mesh; then decimated to `tris`."""
|
|
o = join(parts, name)
|
|
mod(o, "REMESH", mode="VOXEL", voxel_size=voxel, adaptivity=0.0)
|
|
bake(o)
|
|
mod(o, "SMOOTH", factor=0.6, iterations=smooth_it)
|
|
bake(o)
|
|
if soft:
|
|
soften(o, soft)
|
|
if spec:
|
|
crease_pass(o, digits, spec)
|
|
dense = common.link(bpy.data.objects.new(name + "_dense", o.data.copy()))
|
|
for p in dense.data.polygons:
|
|
p.use_smooth = True
|
|
n = sum(len(p.vertices) - 2 for p in o.data.polygons)
|
|
if n > tris:
|
|
mod(o, "DECIMATE", decimate_type="COLLAPSE", ratio=tris / n, use_collapse_triangulate=True)
|
|
bake(o)
|
|
o.data.materials.clear()
|
|
o.data.materials.append(mat(m))
|
|
for p in o.data.polygons:
|
|
p.material_index = 0
|
|
smooth(o, 80)
|
|
o["dense"] = dense.name
|
|
return o
|
|
|
|
|
|
def transfer_normals(o, dense_name, nv):
|
|
"""The shading of the dense remesh (creases and all) on the decimated skin: custom normals on the first nv vertices of o."""
|
|
dense = bpy.data.objects[dense_name]
|
|
vg = o.vertex_groups.new(name="skin")
|
|
vg.add(list(range(nv)), 1.0, "REPLACE")
|
|
md = o.modifiers.new("nrm", "DATA_TRANSFER")
|
|
md.object = dense
|
|
md.use_loop_data = True
|
|
md.data_types_loops = {"CUSTOM_NORMAL"}
|
|
md.loop_mapping = "POLYINTERP_NEAREST"
|
|
md.vertex_group = "skin"
|
|
bake(o)
|
|
o.vertex_groups.clear()
|
|
me = dense.data
|
|
bpy.data.objects.remove(dense)
|
|
bpy.data.meshes.remove(me)
|
|
return o
|
|
|
|
|
|
def nail(bvh, d, m=SKIN, s0=0.75, s1=0.955, half=DEG(44)):
|
|
"""A fingernail on the back of the tip: sunk into its folds at the sides and under the cuticle, a free edge at the end."""
|
|
def P(u, v):
|
|
return d.surf(s0 + (s1 - s0) * u, (-half + 2 * half * v) * (0.78 + 0.22 * smoothstep(0.0, 0.4, u)))
|
|
|
|
def H(u, v):
|
|
e = 1 - abs(2 * v - 1) ** 3
|
|
return 0.0008 * e * (0.35 + 0.65 * smoothstep(0.0, 0.3, u)) + 0.0002 * smoothstep(0.8, 1.0, u) + 0.0001
|
|
return surface_patch("nail", P, H, 6, 6, 0.0007, m, bvh=bvh, ang=28)
|
|
|
|
|
|
# ======================================================================= shirt cuff and sleeve
|
|
|
|
def shirt_arm(P, root, way, r0, look, skin=True, fore=(-0.03, 0.26), seam_side=None):
|
|
"""gc_vend.arm with the detail: the bare forearm (returned, to blend with the hand), a shirt cuff (rolled edge, top-stitch groove,
|
|
seam into the sleeve, a placket with a button and its thread) and the sleeve (pleats into the cuff, drape folds, a seam welt).
|
|
look: the side the button faces (towards the viewer)."""
|
|
root, way = Vector(root), Vector(way).normalized()
|
|
p = lambda s: root + way * s
|
|
# bare: the wrist end tapers inside the heel of the hand, so the blend has no ring where the tube's end came out
|
|
taper = (lambda t: 0.8 + 0.2 * smoothstep(0.0, 0.2, t)) if skin else (lambda t: 1.0)
|
|
fa = sweep_circle("forearm", [p(fore[0]), p((fore[0] + fore[1]) / 2), p(fore[1])],
|
|
lambda t, l: (r0 * 0.9 + (0.042 - r0 * 0.9) * t) * taper(t) if skin else r0 + (0.042 - r0) * t, segs=16, per=4, m=SKIN, cap=True,
|
|
smooth_ang=60)
|
|
X = perp(Vector(look), way)
|
|
Y = way.cross(X)
|
|
F = Matrix((X, Y, way)).transposed().to_4x4()
|
|
F.translation = root
|
|
# the cuff: a band with a thick rolled front edge, the stitch groove, the back edge sewn to the sleeve
|
|
prof = [(0.0452, 0.2565), (0.0460, 0.2512), (0.0474, 0.2494), (0.0492, 0.2491), (0.0502, 0.2499), (0.0505, 0.2513), (0.0505, 0.2527),
|
|
(0.0500, 0.2532), (0.0505, 0.2537), (0.0505, 0.2668), (0.0501, 0.2673), (0.0505, 0.2678), (0.0505, 0.2702), (0.0500, 0.2716),
|
|
(0.0490, 0.2722), (0.0478, 0.2723)]
|
|
P.append(lathe5("cuff", prof, [SLEEVE], segs=34, frame=F, ang=50))
|
|
# the placket: the end of the cuff lapping over itself, with a button
|
|
R = 0.0505
|
|
|
|
def cyl(s, a):
|
|
d = X * math.cos(a) + Y * math.sin(a)
|
|
return p(s) + d * R, d
|
|
w = 0.026 / R
|
|
P.append(surface_patch("placket", lambda u, v: cyl(0.2500 + 0.0212 * u, -w * 0.5 + w * v),
|
|
lambda u, v: 0.0011 * smoothstep(0.0, 0.12, v) * smoothstep(0.0, 0.06, u) * smoothstep(0.0, 0.06, 1 - u), 6, 8, 0.0006, SLEEVE))
|
|
c, dn = cyl(0.2606, w * 0.32)
|
|
c = c + dn * 0.0011
|
|
Fb = T5.fz(c, dn, ref=way)
|
|
P.append(lathe5("button", [(0.0, 0.0011), (0.0024, 0.0010), (0.0034, 0.0015), (0.0047, 0.0017), (0.0054, 0.0013), (0.0055, 0.0003), (0.0052, 0.0)][::-1],
|
|
[SLEEVE], segs=20, frame=Fb, ang=40))
|
|
for a in (45, 135): # the thread crossing the four holes
|
|
q0 = Fb @ Vector((0.0016 * math.cos(DEG(a)), 0.0016 * math.sin(DEG(a)), 0.00105))
|
|
q1 = Fb @ Vector((-0.0016 * math.cos(DEG(a)), -0.0016 * math.sin(DEG(a)), 0.00105))
|
|
P.append(GV.cyl_between("thread", q0, q1, 0.00042, SLEEVE, v=6))
|
|
# the sleeve: pleats gathered into the cuff, drape folds further up
|
|
s0, s1 = 0.2655, 0.5
|
|
C = [p(s0 + (s1 - s0) * i / 24) for i in range(25)]
|
|
rng = random.Random(11)
|
|
ph = [rng.uniform(0, TAU) for _ in range(3)]
|
|
|
|
def sec(sf, i):
|
|
s = s0 + (s1 - s0) * sf
|
|
base = 0.047 + (0.058 - 0.047) * smoothstep(0.268, 0.5, s) + 0.0012 * smoothstep(0.266, 0.275, s)
|
|
pleat = 0.0022 * smoothstep(0.268, 0.276, s) * (1 - smoothstep(0.29, 0.35, s))
|
|
drape = 0.0019 * smoothstep(0.29, 0.36, s)
|
|
out = []
|
|
for q in range(32):
|
|
a = TAU * q / 32
|
|
r = base + pleat * math.cos(7 * a + ph[0]) + drape * (0.6 * math.sin(3 * a + 18 * s + ph[1]) + 0.4 * math.sin(5 * a - 11 * s + ph[2]))
|
|
out.append((r * math.cos(a), r * math.sin(a)))
|
|
return out
|
|
frm = ([way] * len(C), [X] * len(C), [Y] * len(C))
|
|
sl = T5.sweep("sleeve", C, sec, [SLEEVE], ang=55, frm=frm)
|
|
P.append(sl)
|
|
# the seam welt down the underside of the sleeve, lying on the folds
|
|
bvh = BVHTree.FromObject(sl, bpy.context.evaluated_depsgraph_get())
|
|
aw = DEG(180 + 25) if seam_side is None else seam_side
|
|
P.append(surface_patch("seam", lambda u, v: ((p(0.276 + 0.218 * u) + (X * math.cos(aw + (v - 0.5) * 0.05) + Y * math.sin(aw + (v - 0.5) * 0.05)) * 0.05),
|
|
X * math.cos(aw + (v - 0.5) * 0.05) + Y * math.sin(aw + (v - 0.5) * 0.05)),
|
|
lambda u, v: 0.0009 * math.sin(math.pi * v) + 0.0001, 16, 2, 0.0008, SLEEVE, bvh=bvh))
|
|
return fa
|
|
|
|
|
|
# ======================================================================= SM_HandCan
|
|
|
|
def can_profile():
|
|
"""(r, z, slot) bottom pole to top pole; slot of the band from this point to the next."""
|
|
S, G, Au, Cm = 0, 1, 2, 3
|
|
pts = [(0.0, -0.0507, S), (0.006, -0.0512, S), (0.0115, -0.0528, S), (0.0160, -0.0553, S), (0.0192, -0.0578, S), (0.0208, -0.0592, S),
|
|
(0.0218, -0.0599, S), (0.0228, -0.0600, S), (0.0238, -0.0598, S), (0.0250, -0.0592, S), (0.0268, -0.0580, S), (0.0290, -0.0560, S),
|
|
(0.0308, -0.0538, S), (0.0320, -0.0518, S), (0.0327, -0.0503, S), (CR, -0.0490, G), (CR, -0.046, G), (CR, -0.034, G),
|
|
(CR, -0.022, Au), (CR, -0.020, Cm), (CR, -0.010, Cm), (CR, 0.0, Cm), (CR, 0.010, Cm), (CR, 0.022, Au), (CR, 0.024, G),
|
|
(CR, 0.033, G), (CR, 0.040, G), (0.0329, 0.0425, G), (0.0325, 0.0450, G), (0.0318, 0.0474, G), (0.0309, 0.0494, G),
|
|
(0.0299, 0.0511, G), (0.0291, 0.0524, G), (0.0286, 0.0531, G), (0.0287, 0.0535, G), (0.0282, 0.0540, G), (0.0283, 0.0544, G),
|
|
(0.0279, 0.0549, S), (0.0278, 0.0555, S), (0.0280, 0.0560, S), (0.0286, 0.0567, S), (0.0288, 0.0577, S), (0.0287, 0.0590, S),
|
|
(0.0283, 0.0598, S), (0.0276, 0.0602, S), (0.0268, 0.0602, S), (0.0263, 0.0597, S), (0.0260, 0.0585, S), (0.0256, 0.0570, S),
|
|
(0.0251, 0.0556, S), (0.0247, 0.0549, S), (0.0242, 0.0547, S), (0.0238, 0.0550, S), (0.0235, 0.0557, S), (0.0231, 0.0563, S),
|
|
(0.0225, 0.0565, S), (0.0212, 0.0565, S), (0.0206, 0.05672, S), (0.0198, 0.05672, S), (0.0192, 0.0565, S), (0.0120, 0.0565, S),
|
|
(0.0060, 0.0565, S), (0.0044, 0.0565, S), (0.0039, 0.05668, S), (0.0032, 0.0568, S), (0.0, 0.0568, S)]
|
|
return pts
|
|
|
|
|
|
def opening_outline(n=40, grow=0.0):
|
|
"""The scored opening, a rounded tear towards -Y (towards the rim), under the nose of the tab."""
|
|
cy, rx, ry = -0.0139, 0.0066, 0.0056
|
|
out = []
|
|
for i in range(n):
|
|
a = TAU * i / n
|
|
k = 1.25 if math.sin(a) < 0 else 1.0
|
|
out.append(Vector(((rx + grow) * math.cos(a) * (1 - 0.12 * max(0.0, -math.sin(a))), cy + (ry * k + grow) * math.sin(a), 0.0)))
|
|
return out
|
|
|
|
|
|
def densify(prof, step):
|
|
"""More rings up the soft wall (the heel to the neck), for the crumple."""
|
|
out = []
|
|
for (r0, z0, s0), (r1, z1, s1) in zip(prof, prof[1:]):
|
|
out.append((r0, z0, s0))
|
|
if -0.051 < z0 < 0.055 and -0.051 < z1 < 0.055 and z1 - z0 > step * 1.4:
|
|
k = int((z1 - z0) / step)
|
|
for i in range(1, k):
|
|
f = i / k
|
|
out.append((r0 + (r1 - r0) * f, z0 + (z1 - z0) * f, s0))
|
|
out.append(prof[-1])
|
|
return out
|
|
|
|
|
|
def can5(dense=False):
|
|
"""The Can (as SM_BeerCan, much finer) and its Tab. Origin of the can at its centre, the Tab's on its rivet.
|
|
dense: more rings and segments, for SM_BeerCanCrushed's crumple."""
|
|
prof = densify(can_profile(), 0.0022) if dense else can_profile()
|
|
mats = SLOTS["Can"]
|
|
B = [lathe5("can", [(r, z) for r, z, s in prof], mats, colfn=lambda k, j: prof[k][2], segs=56 if dense else 40, ang=32)]
|
|
# the leaf logo on the cream band, front (-Y) and back (+Y), and the gold dots, as gc_vend
|
|
for a0 in (-math.pi / 2, math.pi / 2):
|
|
for (base, L, W, ang, m, bend) in (((-0.004, -0.012), 0.032, 0.0075, DEG(70), GREEN, 0.12), ((-0.002, -0.011), 0.022, 0.006, DEG(118), LEAFG, -0.14)):
|
|
pr = GV.leaf_pairs(base, L, W, ang, 18 if dense else 10, bend)
|
|
o = GV.strip_obj("logo", [((a[0], -CR, a[1]), (b[0], -CR, b[1])) for a, b in pr], m, (0, -1, 0))
|
|
if dense: # across the leaf too, so it can follow the crumple
|
|
bm_ = bmesh.new()
|
|
bm_.from_mesh(o.data)
|
|
bmesh.ops.subdivide_edges(bm_, edges=bm_.edges[:], cuts=3, use_grid_fill=True)
|
|
bmesh.ops.triangulate(bm_, faces=bm_.faces[:])
|
|
bm_.to_mesh(o.data)
|
|
bm_.free()
|
|
rr = CR + (0.0005 if m == GREEN else 0.0008)
|
|
for v in o.data.vertices:
|
|
x, z = v.co.x, v.co.z
|
|
phi = a0 + x / CR
|
|
v.co = (rr * math.cos(phi), rr * math.sin(phi), z)
|
|
o.data.update()
|
|
for pg in o.data.polygons:
|
|
c = Vector(pg.center)
|
|
if Vector(pg.normal).dot(Vector((c.x, c.y, 0))) < 0:
|
|
pg.flip()
|
|
B.append(o)
|
|
# the midrib
|
|
pr2 = GV.leaf_pairs(base, L * 0.85, W * 0.1, ang, 8, bend * 0.8)
|
|
o2 = GV.strip_obj("rib", [((a[0], -CR, a[1]), (b[0], -CR, b[1])) for a, b in pr2], CREAM if m == GREEN else GREEN, (0, -1, 0))
|
|
for v in o2.data.vertices:
|
|
x, z = v.co.x, v.co.z
|
|
phi = a0 + x / CR
|
|
v.co = ((rr + 0.0001) * math.cos(phi), (rr + 0.0001) * math.sin(phi), z)
|
|
o2.data.update()
|
|
for pg in o2.data.polygons:
|
|
c = Vector(pg.center)
|
|
if Vector(pg.normal).dot(Vector((c.x, c.y, 0))) < 0:
|
|
pg.flip()
|
|
B.append(o2)
|
|
for dx in (-0.016, 0.016):
|
|
ph = a0 + dx / CR
|
|
q = Vector((CR * math.cos(ph), CR * math.sin(ph), 0.002))
|
|
B.append(GV.cyl_between("dot", q * 0.9995, q + Vector((math.cos(ph), math.sin(ph), 0)) * 0.0008, 0.0022, GOLD, v=16))
|
|
# the lid: the score of the opening (a dark line) and its stiffening bead just inside
|
|
sc_out, sc_in = opening_outline(48, 0.00045), opening_outline(48, -0.00015)
|
|
bm = bmesh.new()
|
|
vo = [bm.verts.new(p + Vector((0, 0, TOPZ + 0.0001))) for p in sc_out]
|
|
vi = [bm.verts.new(p + Vector((0, 0, TOPZ + 0.0001))) for p in sc_in]
|
|
for i in range(48):
|
|
f = bm.faces.new((vi[i], vi[(i + 1) % 48], vo[(i + 1) % 48], vo[i]))
|
|
bm.normal_update()
|
|
for f in bm.faces:
|
|
if f.normal.z < 0:
|
|
f.normal_flip()
|
|
B.append(obj_from_bm("score", bm, [SOOT]))
|
|
B.append(loop_sweep("bead", [p + Vector((0, 0, TOPZ)) for p in opening_outline(40, -0.0012)], (0, 0, 1),
|
|
[(0.00045 * math.cos(PI_ * q / 6), 0.00028 * math.sin(PI_ * q / 6)) for q in range(7)] + [(0.0, -0.0002)],
|
|
STEEL, ang=60))
|
|
can = finish(B, "Can", uv=6.0, ang=32, slots=mats)
|
|
# the lid on a darker band of T_Metal, the tab (below) on a bright one: same M_Steel, but the tab reads as its own piece
|
|
me = can.data
|
|
uvl = me.uv_layers.active
|
|
for pg in me.polygons:
|
|
c = pg.center
|
|
if pg.material_index == 0 and c.z > 0.0540 and math.hypot(c.x, c.y) < 0.0266:
|
|
for li in pg.loop_indices:
|
|
co = me.vertices[me.loops[li].vertex_index].co
|
|
uvl.data[li].uv = (0.405 + co.x * 0.55, 0.5 + co.y * 0.9)
|
|
# ---- Tab
|
|
half = [(0.0, -0.0090), (0.0022, -0.0087), (0.0036, -0.0079), (0.0043, -0.0066), (0.0046, -0.0048), (0.0050, -0.0028), (0.0058, -0.0010),
|
|
(0.0068, 0.0012), (0.0075, 0.0040), (0.0078, 0.0075), (0.0077, 0.0110), (0.0072, 0.0145), (0.0060, 0.0175), (0.0040, 0.0193),
|
|
(0.0020, 0.0199), (0.0, 0.0200)]
|
|
ol = half + [(-x, y) for x, y in reversed(half[1:-1])]
|
|
ol = closed_catmull([Vector((x, y, 0)) for x, y in ol], 2)
|
|
hole = [Vector((0.0050 * math.cos(TAU * i / 28), 0.0112 + 0.0058 * math.sin(TAU * i / 28), 0)) for i in range(28)]
|
|
# flat on the lid at the nose, bent up past the rivet so the ring end stands a little off the lid (a finger gets under it)
|
|
zt = lambda y: TOPZ + 0.00105 + 0.0003 * smoothstep(-0.003, 0.004, y) + 0.0013 * smoothstep(0.003, 0.02, y) ** 1.4
|
|
|
|
def inset_loop(C, d):
|
|
n = len(C)
|
|
out = []
|
|
for i in range(n):
|
|
t = (C[(i + 1) % n] - C[i - 1]).normalized()
|
|
a = t.cross(Vector((0, 0, 1))).normalized() # outward for a counter-clockwise loop
|
|
out.append(C[i] - a * d)
|
|
return out
|
|
T = []
|
|
bm = bmesh.new()
|
|
for dz, flip in ((0.0, False), (-0.00048, True)):
|
|
oo = inset_loop(ol, 0.00035)
|
|
hh = inset_loop(hole, -0.00035)
|
|
vo = [bm.verts.new((p.x, p.y, zt(p.y) + dz)) for p in oo]
|
|
vh = [bm.verts.new((p.x, p.y, zt(p.y) + dz)) for p in hh]
|
|
es = [bm.edges.new((vo[i], vo[(i + 1) % len(vo)])) for i in range(len(vo))] + [bm.edges.new((vh[i], vh[(i + 1) % len(vh)])) for i in range(len(vh))]
|
|
r = bmesh.ops.triangle_fill(bm, use_beauty=True, use_dissolve=False, edges=es, normal=Vector((0, 0, 1)))
|
|
fs = [g for g in r["geom"] if isinstance(g, bmesh.types.BMFace)]
|
|
for f in fs:
|
|
f.normal_update()
|
|
if (f.normal.z < 0) != flip:
|
|
f.normal_flip()
|
|
T.append(obj_from_bm("plate", bm, [STEEL], 30))
|
|
curl = [(0.0005 * math.cos(TAU * q / 8), 0.0004 * math.sin(TAU * q / 8)) for q in range(8)]
|
|
for C, d in ((ol, 0.00032), (hole, -0.00032)):
|
|
L = inset_loop(C, d)
|
|
T.append(loop_sweep("curl", [Vector((p.x, p.y, zt(p.y) - 0.00024)) for p in L], (0, 0, 1), curl, STEEL, ang=70))
|
|
T.append(lathe5("rivet", [(0.0026, TOPZ - 0.0002), (0.0024, TOPZ + 0.0009), (0.0020, TOPZ + 0.00135), (0.0013, TOPZ + 0.0016), (0.0, TOPZ + 0.00166)],
|
|
[STEEL], segs=20, ang=50))
|
|
# a stiffening rib pressed into the nose
|
|
T.append(surface_patch("rib", lambda u, v: (Vector((-0.0011 + 0.0022 * v, -0.0078 + 0.0046 * u, zt(-0.0078 + 0.0046 * u))), Vector((0, 0, 1))),
|
|
lambda u, v: 0.00018 * math.sin(math.pi * v) * smoothstep(0, 0.2, u) * smoothstep(0, 0.2, 1 - u), 4, 4, 0.0001, STEEL))
|
|
tab = finish(T, "Tab", uv=15.0, ang=40, slots=["M_Steel"])
|
|
me = tab.data
|
|
uvl = me.uv_layers.active
|
|
for li, lp in enumerate(me.loops):
|
|
co = me.vertices[lp.vertex_index].co
|
|
uvl.data[li].uv = (0.155 + co.x * 1.4, 0.3 + co.y * 2.5)
|
|
set_origin(tab, (0, 0, TOPZ))
|
|
tab.parent = can
|
|
tab.matrix_parent_inverse = Matrix.Identity(4)
|
|
return can, tab
|
|
|
|
|
|
PI_ = math.pi
|
|
|
|
|
|
def hand_can5():
|
|
at = lambda u, v, w: Vector((-u, w, v))
|
|
|
|
def pol(a_deg, rho, v):
|
|
a = DEG(a_deg)
|
|
return at(rho * math.cos(a), v, rho * math.sin(a))
|
|
rad = lambda a: Vector((-math.cos(DEG(a)), math.sin(DEG(a)), 0))
|
|
tan = lambda a: Vector((-math.sin(DEG(a)), -math.cos(DEG(a)), 0)) * -1
|
|
Z = Vector((0, 0, 1))
|
|
S = []
|
|
S.append(GV.ell("palm", pol(-12, CR + 0.026, -0.006), (0.021, 0.042, 0.054), (rad(-12), tan(-12), Z), seg=28, rings=18))
|
|
S.append(GV.ell("heel", pol(8, CR + 0.025, -0.058), (0.02, 0.034, 0.03), (rad(8), tan(8), Z), seg=24, rings=14))
|
|
S.append(GV.ell("thenar", pol(30, CR + 0.017, -0.04), (0.017, 0.022, 0.034), (rad(30), tan(30), Z), seg=24, rings=14))
|
|
inside = lambda c, T: Vector((-c.x, -c.y, 0.0))
|
|
digits = []
|
|
for v, r, a_tip, ln in ((0.034, 0.0118, -186, 1.0), (0.0105, 0.0124, -192, 1.0), (-0.0135, 0.0118, -182, 0.95), (-0.0365, 0.0104, -166, 0.85)):
|
|
rho = CR + r * 1.02
|
|
pts = [pol(-22, CR + 0.03, v - 0.003), pol(-42, CR + 0.022, v - 0.002), pol(-62, rho + 0.002, v - 0.001), pol(-92, rho, v),
|
|
pol(-122, rho, v + 0.001), pol(-150, rho, v + 0.002), pol(a_tip + 12, rho, v + 0.002), pol(a_tip, rho - 0.002, v + 0.002)]
|
|
digits.append(Digit(pts, r, (0.04, 0.4, 0.7), inside))
|
|
rt = 0.0128
|
|
digits.append(Digit([pol(24, CR + 0.03, -0.062), pol(30, CR + 0.022, -0.042), pol(40, CR + rt, -0.018), pol(48, CR + rt * 0.95, 0.004),
|
|
pol(53, CR + rt * 0.9, 0.018)], rt, (0.34, 0.68), inside, kind="thumb"))
|
|
for d in digits:
|
|
S.append(d.tube("digit", SKIN))
|
|
P = []
|
|
S.append(shirt_arm(P, pol(6, CR + 0.03, -0.082), at(0.34, -0.8, 0.5), 0.031, look=(-0.55, 1.0, 0.1)))
|
|
wrist = pol(6, CR + 0.03, -0.082)
|
|
heel = pol(8, CR + 0.025, -0.058)
|
|
skin = organic(S, "skin", SKIN, digits, tris=7500, soft=[(wrist + at(0.34, -0.8, 0.5).normalized() * 0.022, 0.034), (wrist.lerp(heel, 0.5), 0.024)])
|
|
clear_of_can(skin)
|
|
clear_of_can(bpy.data.objects[skin["dense"]])
|
|
dn, nv = skin["dense"], len(skin.data.vertices)
|
|
bvh = BVHTree.FromObject(skin, bpy.context.evaluated_depsgraph_get())
|
|
for d in digits:
|
|
P.append(nail(bvh, d))
|
|
transfer_normals(finish([skin] + P, "Hand", ang=60, slots=SLOTS["Hand"]), dn, nv)
|
|
return digits
|
|
|
|
|
|
def clear_of_can(o, gap=0.00015):
|
|
"""The remesh and the decimation can sink a fingertip a fraction of a millimetre into the can: lift the skin back onto it."""
|
|
side = [(r, z) for r, z, _ in can_profile() if r > 0.022 and -0.0601 < z < 0.0578]
|
|
side = side[:next(i for i, (r, z) in enumerate(side) if z > 0.0577) + 1] if any(z > 0.0577 for r, z in side) else side
|
|
side.sort(key=lambda p: p[1])
|
|
|
|
def env(z):
|
|
if z <= side[0][1] or z >= side[-1][1]:
|
|
return None
|
|
i = next(k for k in range(len(side) - 1) if side[k + 1][1] >= z)
|
|
(r0, z0), (r1, z1) = side[i], side[i + 1]
|
|
return r0 + (r1 - r0) * (z - z0) / max(1e-9, z1 - z0)
|
|
n = 0
|
|
for v in o.data.vertices:
|
|
r = math.hypot(v.co.x, v.co.y)
|
|
e = env(v.co.z)
|
|
g = gap
|
|
if -0.017 < v.co.z < 0.024 and abs(abs(math.atan2(v.co.y, v.co.x)) - math.pi / 2) < 0.75:
|
|
g = gap + 0.0009 # the leaf logos stand 0.8 mm off the label
|
|
if e is None or r < 1e-6 or r < e - 0.008 or r >= e + g:
|
|
continue
|
|
k = (e + g) / r
|
|
v.co.x *= k
|
|
v.co.y *= k
|
|
n += 1
|
|
o.data.update()
|
|
return n
|
|
|
|
|
|
CRUMPLE = dict(keep=0.40, tilt=6.0, shift=0.002, dent=0.4) # tuned so the tab lands where gc_vend's crushed can had it
|
|
CRUSHED_TAB = (0.004299134, 0.000498753, 0.028109681) # SM_BeerCanCrushed's Tab origin in the game FBX (gc_vend.crush_fn)
|
|
|
|
|
|
def crumple(keep=None, tilt=None, shift=None, dent=None):
|
|
"""Stood on: the wall between the heel and the shoulder folds up like a concertina, the folds buckling into diamonds
|
|
(five lobes, half a lobe round from one fold to the next), with a dent from the heel of the boot and the top pushed over.
|
|
Heel, bottom, shoulder, rim and lid stay as made."""
|
|
rng = random.Random(77)
|
|
ph = [rng.uniform(0, TAU) for _ in range(4)]
|
|
zb0, zb1 = -0.0478, 0.0418
|
|
L = zb1 - zb0
|
|
keep = CRUMPLE["keep"] if keep is None else keep
|
|
tilt = DEG(CRUMPLE["tilt"] if tilt is None else tilt)
|
|
shift = CRUMPLE["shift"] if shift is None else shift
|
|
dent = CRUMPLE["dent"] if dent is None else dent
|
|
m, n = 4, 5
|
|
zp = zb0 + L * keep
|
|
|
|
def rot(x, z, a, px):
|
|
c, s_ = math.cos(a), math.sin(a)
|
|
dx, dz = x - px, z - zp
|
|
return px + dx * c + dz * s_, zp - dx * s_ + dz * c
|
|
|
|
def f(p):
|
|
x, y, z = p
|
|
if z <= zb0:
|
|
return Vector((x, y, z))
|
|
if z >= zb1:
|
|
x2, z2 = rot(x + shift, z - L * (1 - keep), tilt, shift)
|
|
return Vector((x2, y, z2))
|
|
r = math.hypot(x, y)
|
|
th = math.atan2(y, x)
|
|
t = (z - zb0) / L
|
|
band = t * m + 0.3 # phased so the two gold lines ride on crests, not in the folds
|
|
k = int(band)
|
|
fr = band - k
|
|
env = smoothstep(0.0, 0.07, t) * smoothstep(0.0, 0.07, 1 - t)
|
|
lobe = 0.5 + 0.5 * math.cos(n * th + k * math.pi + ph[0]) # the lobes swap over from one fold to the next
|
|
mid = 0.5 - 0.5 * math.cos(TAU * fr) # 0 on the fold lines, 1 between them
|
|
dr = (0.0050 * mid * (0.3 + 0.7 * lobe) - 0.0032 * (1 - mid)) * env
|
|
dr += 0.0035 * math.sin(math.pi * t)
|
|
dth = math.atan2(math.sin(th - dent), math.cos(th - dent))
|
|
dr -= 0.0075 * math.exp(-(dth / 0.65) ** 2 - ((t - 0.55) / 0.22) ** 2)
|
|
rr = r + dr if r > 0.01 else r
|
|
zn = zb0 + L * keep * t + 0.0016 * math.sin(TAU * fr) * (lobe - 0.5) * 2 * env
|
|
x2, z2 = rot(rr * math.cos(th) + shift * t, zn, tilt * t, shift * t)
|
|
return Vector((x2, rr * math.sin(th), z2))
|
|
return f
|
|
|
|
|
|
def beer_can5(crushed=False):
|
|
"""SM_BeerCan / SM_BeerCanCrushed: the hand's can, Body and Tab (both roots, as gc_vend). Crushed: crumpled, centred on its bounds."""
|
|
can, tab = can5(dense=crushed)
|
|
tab.parent = None
|
|
tab.matrix_parent_inverse = Matrix.Identity(4)
|
|
can.name = can.data.name = "Body"
|
|
if crushed:
|
|
f = crumple()
|
|
for o in (can, tab):
|
|
apply_xform(o)
|
|
for v in o.data.vertices:
|
|
v.co = f(v.co)
|
|
o.data.update()
|
|
pts = [v.co for v in can.data.vertices]
|
|
c = Vector([(max(p[i] for p in pts) + min(p[i] for p in pts)) / 2 for i in range(3)])
|
|
for o in (can, tab):
|
|
o.data.transform(Matrix.Translation(-c))
|
|
set_origin(can, (0, 0, 0))
|
|
smooth(can, 50)
|
|
smooth(tab, 40)
|
|
# the rivet lands within 0.7 mm of the old pivot; the pivot itself is kept exactly (nothing turns the crushed tab)
|
|
set_origin(tab, CRUSHED_TAB)
|
|
return can, tab
|
|
|
|
|
|
def hand_can_build():
|
|
hand_can5()
|
|
can5()
|
|
|
|
|
|
# ======================================================================= SM_HandCigar
|
|
|
|
def cigar_noise(seed):
|
|
rng = random.Random(seed)
|
|
terms = [(rng.randint(2, 7), rng.uniform(150, 900), rng.uniform(0, TAU), rng.uniform(0.4, 1.0)) for _ in range(5)]
|
|
|
|
def f(th, z):
|
|
return sum(a * math.sin(k * th + w * z + p) for k, w, p, a in terms) / sum(a for *_, a in terms)
|
|
return f
|
|
|
|
|
|
def cigar5():
|
|
"""Body and Ember in SM_Cigar's frame (axis Y, the lit foot at -Y), built about Z and turned at the end like gc_vend."""
|
|
r = CIG_R
|
|
burn = cigar_noise(5)
|
|
ashn = cigar_noise(9)
|
|
PITCH = 0.034
|
|
zs = [FOOT, FOOT + 0.0004, FOOT + 0.0012, FOOT + 0.0022, FOOT + 0.0033, FOOT + 0.0044, FOOT + 0.0055, FOOT + 0.0063, FOOT + 0.0071,
|
|
FOOT + 0.0080, FOOT + 0.0092]
|
|
prof = [(0.0, FOOT), (0.0062, FOOT), (0.0078, FOOT + 0.00005)]
|
|
prof += [(0.0083 if z < FOOT + 0.0068 else r, z) for z in zs[1:]]
|
|
z = FOOT + 0.0092
|
|
while z < 0.0280:
|
|
z += 0.0019
|
|
prof.append((r, min(z, 0.0280)))
|
|
band = [(r, 0.0291), (0.0088, 0.02935), (0.0091, 0.0298), (0.0091, 0.0306), (0.00895, 0.0310), (0.00895, 0.0314), (0.0091, 0.0318),
|
|
(0.0090, 0.0322), (0.0090, 0.0400), (0.0090, 0.0458), (0.0091, 0.0462), (0.00895, 0.0466), (0.00895, 0.0470), (0.0091, 0.0474),
|
|
(0.0091, 0.0482), (0.0088, 0.04865), (r, 0.0489)]
|
|
prof += band
|
|
z = 0.0489
|
|
while z < 0.0548:
|
|
z += 0.002
|
|
prof.append((r, min(z, 0.0548)))
|
|
prof += [(r, 0.0551), (0.00838, 0.05535), (0.0083, 0.0575), (0.0080, 0.0600), (0.0075, 0.0625), (0.0067, 0.0648), (0.0056, 0.0668),
|
|
(0.0043, 0.0685), (0.0034, 0.0696), (0.0031, 0.0701), (0.0, 0.0703)]
|
|
zb = [p[1] for p in band]
|
|
|
|
def rfn(rr, z, th, k):
|
|
if z < FOOT + 0.0072: # ash: flaky, layered, a little narrower
|
|
return rr * (1 + 0.035 * ashn(th, z)) - 0.00012 * abs(math.sin(z * 2600))
|
|
if zb[0] - 1e-6 <= z <= zb[-1] + 1e-6 or z > 0.0551:
|
|
if z > 0.0551: # the cap: its own leaf, a faint line where it overlaps
|
|
return rr + (0.00005 if abs(z - 0.0575) < 0.0003 else 0.0)
|
|
return rr
|
|
ph = th / TAU + z / PITCH
|
|
frac = ph - math.floor(ph)
|
|
vein = math.exp(-(((th / TAU * 3 - z / 0.011) % 1.0 - 0.5) / 0.035) ** 2)
|
|
return rr + 0.00011 * frac + 0.00005 * vein
|
|
|
|
M = {m: i for i, m in enumerate(SLOTS["Cigar"])}
|
|
|
|
def col(k, j):
|
|
za, zb_ = prof[k][1], prof[k + 1][1]
|
|
zc = (za + zb_) / 2
|
|
th = TAU * (j + 0.5) / 32
|
|
if prof[k][0] < 1e-7 or zc < FOOT + 0.0001:
|
|
return M[ASH]
|
|
line = FOOT + 0.0066 + 0.0011 * burn(th, 0.0)
|
|
if zc < line:
|
|
return M[ASH]
|
|
if zc < line + 0.0011:
|
|
return M[WRAP2] # scorched just behind the burn line
|
|
if zb[0] <= zc <= zb[-1]:
|
|
if 0.0294 < zc < 0.0320 or 0.0460 < zc < 0.0486:
|
|
return M[GOLD]
|
|
return M[CREAM]
|
|
if zc > 0.0699:
|
|
return M[WRAP2] # the cut
|
|
ph = th / TAU + zc / PITCH
|
|
return M[WRAP2] if (ph - math.floor(ph)) > 0.86 else M[WRAP]
|
|
body = lathe5("cigar", prof, SLOTS["Cigar"], colfn=col, segs=32, rfn=rfn, ang=50)
|
|
P = [body]
|
|
# the seal on the band: a red medallion with a gold rim and a gold crest dot, facing -Y here (up once turned)
|
|
Fs = T5.fz(Vector((0, -(0.0090 - 0.0002), 0.039)), (0, -1, 0), ref=(1, 0, 0))
|
|
P.append(lathe5("seal", [(0.0, 0.00105), (0.0016, 0.00102), (0.0026, 0.00092), (0.0036, 0.00082), (0.0043, 0.00068), (0.0045, 0.0003), (0.0045, 0.0)][::-1],
|
|
[REDP], segs=20, frame=Fs, ang=40))
|
|
P.append(lathe5("sealrim", [(0.0037, 0.00083), (0.0041, 0.00098), (0.0044, 0.00086), (0.0045, 0.0006)][::-1], [GOLD], segs=20, frame=Fs, ang=60))
|
|
P.append(lathe5("sealdot", [(0.0, 0.00122), (0.0010, 0.00118), (0.0016, 0.00108), (0.0018, 0.00095)][::-1], [GOLD], segs=12, frame=Fs, ang=60))
|
|
for q in range(7): # small gold beads round the middle of the band, the seal between the first and the last
|
|
a = -PI_ / 2 + DEG(45) * (q + 1)
|
|
c = Vector((0.0090 * math.cos(a), 0.0090 * math.sin(a), 0.039))
|
|
P.append(lathe5("bandbead", [(0.0007, 0.0), (0.0005, 0.00022), (0.0, 0.00028)], [GOLD], segs=8, frame=T5.fz(c, Vector((math.cos(a), math.sin(a), 0))), ang=70))
|
|
for o in P:
|
|
GV.xf(o, rx=-PI_ / 2)
|
|
# the ember: a crusty glowing coal on the lit end
|
|
en = cigar_noise(21)
|
|
# the glowing core (from the tip up, so the faces look out), inside a crust of ash
|
|
eprof = [(0.0, FOOT + 0.0006), (0.0064, FOOT + 0.0006), (0.0065, FOOT - 0.0012), (0.0064, FOOT - 0.0026), (0.0060, FOOT - 0.0038),
|
|
(0.0052, FOOT - 0.0049), (0.0041, FOOT - 0.0058), (0.0027, FOOT - 0.0064), (0.0012, FOOT - 0.0067), (0.0, FOOT - 0.0067)][::-1]
|
|
em = lathe5("ember", eprof, [EMBER], segs=28, rfn=lambda rr, z, th, k: rr * (1 + 0.06 * en(th, z) * (0.3 if k > 7 else 1.0)), ang=70)
|
|
GV.xf(em, rx=-PI_ / 2)
|
|
# the crust: a ragged rim of grey ash round the coal, part of the Body (M_Concrete, the ash slot it already has)
|
|
an = cigar_noise(33)
|
|
cprof = [(0.0063, FOOT + 0.0008), (0.0066, FOOT - 0.0010), (0.0068, FOOT - 0.0026), (0.0072, FOOT - 0.0035), (0.0078, FOOT - 0.0034),
|
|
(0.0083, FOOT - 0.0024), (0.00855, FOOT - 0.0010), (0.0085, FOOT + 0.0010)]
|
|
crust = lathe5("crust", cprof, [ASH], segs=36, rfn=lambda rr, z, th, k: rr * (1 + 0.06 * an(th, z * 3) * (1.0 if 2 <= k <= 5 else 0.4)), ang=55)
|
|
for v in crust.data.vertices:
|
|
if v.co.z < FOOT - 0.0005: # the burnt edge is ragged: it reaches further out in places
|
|
th = math.atan2(v.co.y, v.co.x)
|
|
v.co.z -= 0.0016 * (0.5 + 0.5 * an(th * 2.0, 0.0)) * smoothstep(FOOT - 0.0005, FOOT - 0.0033, v.co.z)
|
|
crust.data.update()
|
|
GV.xf(crust, rx=-PI_ / 2)
|
|
P.append(crust)
|
|
return P, em
|
|
|
|
|
|
def hand_cigar5():
|
|
F = Vector((0, -0.42, 0.9)).normalized()
|
|
N = Vector((1, 0, 0))
|
|
A = N.cross(F)
|
|
Kc = Vector((-0.024, 0, 0)) - F * 0.03
|
|
H = lambda f, a, n: Kc + F * f + A * a + N * n
|
|
S = []
|
|
S.append(GV.ell("palm", H(-0.046, 0.021, -0.002), (0.046, 0.052, 0.0185), (A, F, N), seg=28, rings=18))
|
|
S.append(GV.ell("heel", H(-0.088, 0.024, 0.0), (0.034, 0.026, 0.019), (A, F, N), seg=24, rings=14))
|
|
S.append(GV.ell("thenar", H(-0.062, -0.024, 0.01), (0.019, 0.034, 0.016), (A, F, N), seg=24, rings=14))
|
|
for a in (-0.012, 0.012, 0.035, 0.056):
|
|
S.append(GV.ell("knuckle", H(0.0, a, -0.006), (0.011, 0.012, 0.011), (A, F, N), seg=16, rings=10))
|
|
rc = CIG_R
|
|
ri, rm = 0.0112, 0.0118
|
|
idx = [H(-0.012, -0.011, -0.001), H(0.004, -0.013, 0.0), H(0.03, -(rc + ri) - 0.001, 0.0), H(0.048, -0.023, 0.004), H(0.062, -0.023, 0.013),
|
|
H(0.071, -0.022, 0.022), H(0.077, -0.021, 0.033)]
|
|
mid = [H(-0.012, 0.011, -0.001), H(0.004, 0.013, 0.0), H(0.03, rc + rm + 0.001, 0.0), H(0.05, 0.022, 0.005), H(0.065, 0.022, 0.016),
|
|
H(0.074, 0.021, 0.027), H(0.079, 0.02, 0.039)]
|
|
rng_ = [H(-0.014, 0.035, -0.001), H(0.002, 0.037, 0.0), H(0.03, 0.041, 0.007), H(0.045, 0.042, 0.02), H(0.05, 0.041, 0.034), H(0.047, 0.039, 0.046),
|
|
H(0.04, 0.037, 0.052)]
|
|
pnk = [H(-0.02, 0.056, -0.001), H(-0.006, 0.058, 0.002), H(0.017, 0.061, 0.01), H(0.029, 0.061, 0.022), H(0.032, 0.059, 0.034), H(0.028, 0.057, 0.043),
|
|
H(0.021, 0.055, 0.047)]
|
|
digits = []
|
|
for pts, r in ((idx, ri), (mid, rm), (rng_, 0.0112), (pnk, 0.0098)):
|
|
digits.append(Digit(pts, r, (0.05, 0.42, 0.72), lambda c, T: N))
|
|
rt = 0.0125
|
|
digits.append(Digit([H(-0.078, -0.028, 0.006), H(-0.058, -0.04, 0.018), H(-0.036, -0.046, 0.026), H(-0.014, -0.044, 0.032),
|
|
H(0.004, -0.04, 0.034), H(0.016, -0.035, 0.034)], rt, (0.3, 0.64), lambda c, T: A + N * 0.35, kind="thumb"))
|
|
for d in digits:
|
|
S.append(d.tube("digit", SKIN))
|
|
P = []
|
|
S.append(shirt_arm(P, H(-0.1, 0.018, 0.0), Vector((-0.35, 0.5, -0.8)), 0.03, look=(-0.6, 1.0, 0.2)))
|
|
wrist, heel = H(-0.1, 0.018, 0.0), H(-0.088, 0.024, 0.0)
|
|
skin = organic(S, "skin", SKIN, digits, tris=7500, soft=[(wrist + Vector((-0.35, 0.5, -0.8)).normalized() * 0.022, 0.034), (wrist.lerp(heel, 0.5), 0.024)])
|
|
dn, nv = skin["dense"], len(skin.data.vertices)
|
|
bvh = BVHTree.FromObject(skin, bpy.context.evaluated_depsgraph_get())
|
|
for d in digits:
|
|
P.append(nail(bvh, d))
|
|
transfer_normals(finish([skin] + P, "Hand", ang=60, slots=SLOTS["Hand"]), dn, nv)
|
|
Q, em = cigar5()
|
|
cig = finish(Q, "Cigar", uv=6.0, ang=50, slots=SLOTS["Cigar"])
|
|
emb = finish([em], "Ember", uv=6.0, ang=70, slots=[EMBER])
|
|
set_origin(emb, (0, FOOT - 0.0067, 0))
|
|
emb.parent = cig
|
|
emb.matrix_parent_inverse = Matrix.Identity(4)
|
|
cig.rotation_euler = (0, 0, math.pi / 2)
|
|
|
|
|
|
# ======================================================================= SM_Phone
|
|
|
|
W, Hh, D = GP.W, GP.H, GP.D
|
|
BACK, FRONT, EDGE = -D / 2, D / 2, W / 2
|
|
GUARD_E, GUARD_D = 0.0062, 0.0006 # how far the corner guards run along the edges from the corner, and their soft end
|
|
SHELL, BAND, BLACK, GLOW, LENS = range(5)
|
|
# the band, back to front: (inset from the outline, height on the edges, extra height on the corner guards, slot to the next ring)
|
|
BAND_PROF = [(0.0030, -0.0044, 0.0, BAND), (0.0027, -0.0048, -0.0006, BAND), (0.0018, -0.0050, -0.0008, BAND), (0.0009, -0.0048, -0.0007, BAND),
|
|
(0.0003, -0.0041, -0.0004, BAND), (0.0, -0.0029, 0.0, BAND), (0.0, -0.0004, 0.0, GLOW), (0.0, 0.0004, 0.0, BAND),
|
|
(0.0, 0.0029, 0.0, BAND), (0.0003, 0.0041, 0.0006, BAND), (0.0008, 0.0048, 0.0009, BAND), (0.0012, 0.0050, 0.0010, BAND),
|
|
(0.0015, 0.0049, 0.0009, BAND), (0.0018, 0.00452, 0.0004, BAND), (0.0019, 0.0044, 0.0, GLOW), (0.0024, 0.0044, 0.0, None)]
|
|
|
|
|
|
def phone_sharp():
|
|
"""gc_phone's outline corners, with points added on the long edges where the corner guards end. -> (points, kind, guard weight)"""
|
|
S = GP.sharp(W, Hh, GP.CUT, GP.NICK)
|
|
pts, kind, wt = [], [], []
|
|
for i in range(8):
|
|
a, b = S[i], S[(i + 1) % 8]
|
|
pts.append(a)
|
|
kind.append("v")
|
|
wt.append(1.0)
|
|
L = (b - a).length
|
|
if L > 0.03:
|
|
for t, w in ((GUARD_E - GUARD_D, 1.0), (GUARD_E + GUARD_D, 0.0), (L - GUARD_E - GUARD_D, 0.0), (L - GUARD_E + GUARD_D, 1.0)):
|
|
pts.append(a + (b - a) * (t / L))
|
|
kind.append("c")
|
|
wt.append(w)
|
|
return pts, kind, wt
|
|
|
|
|
|
def phone_ring(d, seg=6):
|
|
"""The outline inset by d, every true corner rounded as gc_phone.outline does (radius ROUND - d / 2), with more points."""
|
|
pts, kind, wt = phone_sharp()
|
|
Pp = GP.inset(pts, d)
|
|
rr = max(GP.ROUND - d * 0.5, 0.0007)
|
|
out, ws = [], []
|
|
n = len(Pp)
|
|
for i, p in enumerate(Pp):
|
|
if kind[i] == "c":
|
|
out.append(p)
|
|
ws.append(wt[i])
|
|
continue
|
|
a, b = Pp[i - 1], Pp[(i + 1) % n]
|
|
q0, q1 = p + (a - p).normalized() * rr, p + (b - p).normalized() * rr
|
|
for s in range(seg + 1):
|
|
t = s / seg
|
|
out.append(q0 * (1 - t) ** 2 + p * 2 * t * (1 - t) + q1 * t ** 2)
|
|
ws.append(1.0)
|
|
return out, ws
|
|
|
|
|
|
def at2(p, y):
|
|
return Vector((-p.x, y, p.y))
|
|
|
|
|
|
def slab(bm, pts, F, levels, mats, cap):
|
|
"""A raised feature: rings of pts inset by levels[k] = (inset, height) mapped by F(u, v, h); the face from ring k to k + 1 takes mats[k],
|
|
the top `cap` (None: open). pts counter-clockwise in (u, v), F's h along the outward normal; faces are turned to face outward."""
|
|
rings = []
|
|
dd = []
|
|
for p in pts: # gc_phone.pill repeats a point where two arcs meet
|
|
p = Vector(p)
|
|
if not dd or (p - dd[-1]).length > 1e-7:
|
|
dd.append(p)
|
|
if (dd[0] - dd[-1]).length < 1e-7:
|
|
dd.pop()
|
|
pts = dd
|
|
for d, h in levels:
|
|
q = GP.inset([Vector(p) for p in pts], d) if d else [Vector(p) for p in pts]
|
|
rings.append([bm.verts.new(F(p.x, p.y, h)) for p in q])
|
|
made = []
|
|
n = len(pts)
|
|
for k in range(len(rings) - 1):
|
|
a, b = rings[k], rings[k + 1]
|
|
for i in range(n):
|
|
f = bm.faces.new((a[i], a[(i + 1) % n], b[(i + 1) % n], b[i]))
|
|
f.material_index = mats[k]
|
|
made.append(f)
|
|
if cap is not None:
|
|
f = bm.faces.new(rings[-1])
|
|
f.material_index = cap
|
|
made.append(f)
|
|
f.normal_update()
|
|
c = sum((Vector(p) for p in pts), Vector((0.0, 0.0))) / n
|
|
out = F(c.x, c.y, 1.0) - F(c.x, c.y, 0.0)
|
|
if f.normal.dot(out) < 0:
|
|
bmesh.ops.reverse_faces(bm, faces=made)
|
|
r = bmesh.ops.triangulate(bm, faces=[f], quad_method="BEAUTY", ngon_method="EAR_CLIP")
|
|
else:
|
|
f = made[0]
|
|
f.normal_update()
|
|
return made
|
|
|
|
|
|
def back_F(shift, base=0.0):
|
|
sx, sy = shift
|
|
return lambda u, v, h: at2(Vector((u + sx, v + sy)), BACK - base - h)
|
|
|
|
|
|
def phone_core():
|
|
"""The band (bumper), the back shell and the front glass as one closed mesh, ready for the boolean cuts."""
|
|
bm = bmesh.new()
|
|
rings = []
|
|
for d, y, ex, m in BAND_PROF:
|
|
pts, ws = phone_ring(d)
|
|
rings.append([bm.verts.new(at2(p, y + ex * w)) for p, w in zip(pts, ws)])
|
|
n = len(rings[0])
|
|
for k in range(len(rings) - 1):
|
|
a, b = rings[k], rings[k + 1]
|
|
for i in range(n):
|
|
f = bm.faces.new((a[i], a[(i + 1) % n], b[(i + 1) % n], b[i]))
|
|
f.material_index = BAND_PROF[k][3]
|
|
f = bm.faces.new(rings[0])
|
|
f.material_index = SHELL
|
|
g = bm.faces.new(rings[-1])
|
|
g.material_index = BLACK
|
|
bmesh.ops.triangulate(bm, faces=[f, g], quad_method="BEAUTY", ngon_method="EAR_CLIP")
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
return obj_from_bm("core", bm, GP.MATS, ang=34)
|
|
|
|
|
|
def phone_cuts(core):
|
|
"""USB-C port in the bottom edge, speaker holes either side of it, a mic hole in the top edge."""
|
|
bm = bmesh.new()
|
|
zb = -Hh / 2
|
|
|
|
def pill_cut(cx, w, h, z0, z1, n=6):
|
|
pts = GP.pill(w, h, n)
|
|
lo = [bm.verts.new((-(cx + p.x), p.y, z0)) for p in pts]
|
|
hi = [bm.verts.new((-(cx + p.x), p.y, z1)) for p in pts]
|
|
m = len(pts)
|
|
bm.faces.new(list(reversed(lo)))
|
|
bm.faces.new(hi)
|
|
for i in range(m):
|
|
bm.faces.new((lo[i], lo[(i + 1) % m], hi[(i + 1) % m], hi[i]))
|
|
pill_cut(0.0, 0.0086, 0.0028, zb - 0.002, zb + 0.0062)
|
|
for sx in (-1, 1):
|
|
for k in range(4):
|
|
pill_cut(sx * (0.0085 + 0.0022 * k), 0.0011, 0.0011, zb - 0.002, zb + 0.0035, n=2)
|
|
pill_cut(0.012, 0.0009, 0.0009, Hh / 2 - 0.003, Hh / 2 + 0.002, n=2)
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
cutter = obj_from_bm("cutter", bm, [GP.MATS[BLACK]])
|
|
md = core.modifiers.new("cut", "BOOLEAN")
|
|
md.operation = "DIFFERENCE"
|
|
md.object = cutter
|
|
md.solver = "EXACT"
|
|
try:
|
|
md.material_mode = "TRANSFER"
|
|
except Exception:
|
|
pass
|
|
bake(core)
|
|
bpy.data.objects.remove(cutter)
|
|
# the walls and floors of the holes are dark
|
|
names = [m.name for m in core.data.materials]
|
|
kb = names.index(GP.MATS[BLACK])
|
|
for p in core.data.polygons:
|
|
c = p.center
|
|
inside_bot = c.z > zb + 0.00015 and c.z < zb + 0.0063 and abs(c.y) < 0.0016 and abs(c.x) < 0.0165
|
|
inside_top = c.z < Hh / 2 - 0.00015 and c.z > Hh / 2 - 0.0031 and abs(c.y) < 0.0006 and abs(c.x + 0.012) < 0.0006
|
|
if inside_bot or inside_top:
|
|
p.material_index = kb
|
|
core.data.update()
|
|
return core
|
|
|
|
|
|
def guard_plate(bm, mid, d_out=0.0024, d_in=0.0074, h=0.0013, ch=0.0004):
|
|
"""The back half of a corner guard: a raised plate following the corner, from the band's lip inwards, chamfered on top."""
|
|
rings = {d: phone_ring(d) for d in (d_out, d_out + ch * 0.6, d_in - ch, d_in)}
|
|
pts, ws = rings[d_out]
|
|
n = len(pts)
|
|
run = [i for i in range(n) if ws[i] > 0.5 and (pts[i] - mid).length < 0.03]
|
|
# the run in ring order, even when it wraps past index 0
|
|
run.sort()
|
|
for k in range(len(run) - 1):
|
|
if run[k + 1] - run[k] > 1:
|
|
run = run[k + 1:] + run[:k + 1]
|
|
break
|
|
loop = lambda da, di: [rings[da][0][i] for i in run] + [rings[di][0][i] for i in reversed(run)]
|
|
levels = [(loop(d_out, d_in), -0.0002), (loop(d_out, d_in), h - ch), (loop(d_out + ch * 0.6, d_in - ch), h)]
|
|
R = [[bm.verts.new(at2(p, BACK - hh)) for p in L] for L, hh in levels]
|
|
m = len(R[0])
|
|
made = []
|
|
for a, b in zip(R, R[1:]):
|
|
for k in range(m):
|
|
f = bm.faces.new((a[k], a[(k + 1) % m], b[(k + 1) % m], b[k]))
|
|
f.material_index = BAND
|
|
made.append(f)
|
|
cap = bm.faces.new(R[-1])
|
|
cap.material_index = BAND
|
|
made.append(cap)
|
|
cap.normal_update()
|
|
if cap.normal.y > 0:
|
|
bmesh.ops.reverse_faces(bm, faces=made)
|
|
bmesh.ops.triangulate(bm, faces=[cap], quad_method="BEAUTY", ngon_method="EAR_CLIP")
|
|
|
|
|
|
def phone_details():
|
|
bm = bmesh.new()
|
|
pod = (0.0, Hh / 2 - 0.03)
|
|
# the camera bump: a wall, a chamfer, a flat rim and a field a step down
|
|
slab(bm, GP.pill(0.079, 0.025, 8), back_F(pod), [(0, -0.0003), (0, 0.0011), (0.0005, 0.0016), (0.0013, 0.0016), (0.0016, 0.00135)],
|
|
[BAND, BAND, BAND, BAND], SHELL)
|
|
base_f = 0.00135
|
|
for x, R in ((-0.024, 0.0072), (0.0, 0.0072), (0.024, 0.0054)):
|
|
c = (pod[0] + x, pod[1])
|
|
g = R - 0.0028
|
|
slab(bm, GP.circle(R, 36), back_F(c, base_f),
|
|
[(0, -0.0001), (0, 0.0008), (0.0004, 0.00125), (0.0011, 0.00125), (0.0013, 0.0006), (0.0019, 0.0006), (0.00205, 0.00068), (0.0023, 0.00068),
|
|
(0.00245, 0.0006), (0.0028, 0.0006), (0.0028 + g * 0.3, 0.00082), (0.0028 + g * 0.65, 0.00094)],
|
|
[BAND, BAND, BAND, BLACK, BLACK, BAND, BAND, BLACK, BLACK, LENS, LENS], LENS)
|
|
# the flash window and the light strip under the bump
|
|
slab(bm, GP.pill(0.0072, 0.0042, 4), back_F((pod[0] + 0.0345 - 0.0005, pod[1] + 0.0065), base_f), [(0, -0.0001), (0, 0.0003), (0.0004, 0.00045)],
|
|
[BAND, BAND], GLOW)
|
|
slab(bm, GP.pill(0.05, 0.0014, 3), back_F((0.0, pod[1] - 0.0165)), [(0, -0.0001), (0, 0.00012)], [GLOW], GLOW)
|
|
# screws on the ends of the bump and on the corner guards
|
|
def screw(c, base):
|
|
slab(bm, GP.circle(0.0011, 14), back_F(c, base), [(0, -0.0002), (0, 0.00012), (0.00035, 0.00028), (0.0006, 0.00031)], [BAND, BAND, BAND], BAND)
|
|
hexs = [Vector((0.00042 * math.cos(TAU * q / 6 + 0.3), 0.00042 * math.sin(TAU * q / 6 + 0.3))) for q in range(6)]
|
|
slab(bm, hexs, back_F(c, base + 0.00031), [(0, 0.00002)], [], BLACK)
|
|
for sx in (-1, 1):
|
|
screw((sx * 0.0352, pod[1]), base_f)
|
|
S = GP.sharp(W, Hh, GP.CUT, GP.NICK)
|
|
for i, j in ((7, 0), (1, 2), (3, 4), (5, 6)):
|
|
mid = (S[i] + S[j]) / 2
|
|
nrm = Vector(((S[j] - S[i]).y, -(S[j] - S[i]).x)).normalized()
|
|
guard_plate(bm, mid)
|
|
c = mid - nrm * 0.0047
|
|
screw((c.x, c.y), 0.0013)
|
|
# cooling ribs and the company mark, as gc_phone
|
|
for i in range(8):
|
|
slab(bm, GP.pill(0.056 - abs(i - 3.5) * 0.004, 0.0018, 4), back_F((0.0, -Hh / 2 + 0.024 + i * 0.0048)),
|
|
[(0, -0.0001), (0, 0.0004), (0.0002, 0.0006)], [BAND, BAND], BAND)
|
|
y = BACK - 0.00012
|
|
GP.blade(bm, (0.0, -0.022), (0.002, 0.03), 0.004, 0.0034, y, GLOW)
|
|
GP.blade(bm, (-0.004, -0.022), (-0.024, 0.012), 0.012, 0.0028, y, GLOW)
|
|
GP.blade(bm, (0.004, -0.022), (0.024, 0.01), -0.012, 0.0028, y, GLOW)
|
|
# the speaker grille low on the back: a raised frame, a perforated plate
|
|
gc = (0.0, -Hh / 2 + 0.0132)
|
|
slab(bm, GP.pill(0.036, 0.0078, 6), back_F(gc), [(0, -0.0001), (0, 0.00032), (0.0005, 0.00036), (0.0008, 0.00018)], [BAND, BAND, BAND], SHELL)
|
|
for row in range(3):
|
|
for k in range(13 - (row % 2)):
|
|
x = (k - (12 - (row % 2)) / 2) * 0.0022
|
|
slab(bm, GP.circle(0.00045, 8), back_F((gc[0] + x, gc[1] + (row - 1) * 0.0019), 0.00018), [(0, 0.00002)], [], BLACK)
|
|
|
|
# the side buttons: chamfered, the long one ridged, with guard fences either side
|
|
def side_F(side, v):
|
|
x = side * EDGE
|
|
return lambda u, w, h: Vector((-(x + side * h), u, v + w))
|
|
|
|
def button(side, v, length, ridges):
|
|
F = side_F(side, v)
|
|
slab(bm, GP.pill(0.0032, length, 5), F, [(0, -0.0003), (0, 0.0004), (0.0003, 0.0006)], [BAND, BAND], BAND)
|
|
for k in range(ridges):
|
|
w = (k - (ridges - 1) / 2) * 0.0026
|
|
slab(bm, [Vector((p.x, p.y + w)) for p in GP.pill(0.0021, 0.0006, 2)], F, [(0, 0.00045), (0, 0.0006)], [BAND], BAND)
|
|
for u in (-0.00275, 0.00275):
|
|
slab(bm, [Vector((p.x + u, p.y)) for p in GP.pill(0.0007, length + 0.004, 3)], F, [(0, -0.0002), (0, 0.00035)], [BAND], BAND)
|
|
button(1, 0.03, 0.024, 7)
|
|
button(-1, 0.05, 0.017, 0)
|
|
button(-1, 0.03, 0.017, 0)
|
|
# the USB-C tongue in the port
|
|
F = lambda u, v, h: Vector((-u, v, -Hh / 2 + 0.0058 - h))
|
|
slab(bm, GP.pill(0.0066, 0.0007, 2), F, [(0, -0.0006), (0, 0.0028)], [BAND], BAND)
|
|
o = obj_from_bm("details", bm, GP.MATS, ang=34)
|
|
# the antenna for the relay, ribbed rubber over a collar, the light ring, a domed tip
|
|
ax = -(-W / 2 + 0.016)
|
|
prof = [(0.0033, -0.0006), (0.0033, 0.0005), (0.0029, 0.0011), (0.0026, 0.0026), (0.0019, 0.0031), (0.0016, 0.0035)]
|
|
mats = [BAND] * 5
|
|
for k in range(5):
|
|
z0 = 0.0042 + k * 0.0024
|
|
prof += [(0.0015, z0), (0.00172, z0 + 0.0004), (0.00172, z0 + 0.0008), (0.0015, z0 + 0.0012)]
|
|
mats += [BAND] * 4
|
|
prof += [(0.0015, 0.0162), (0.0024, 0.0168), (0.0024, 0.0172), (0.0024, 0.0203), (0.0024, 0.0206), (0.0019, 0.0213), (0.0011, 0.0218), (0.0, 0.0220)]
|
|
mats += [BAND, BAND, GLOW, BAND, BAND, BAND, BAND, BAND]
|
|
ant = lathe5("antenna", prof, GP.MATS, colfn=lambda k, j: mats[min(k, len(mats) - 1)], segs=16,
|
|
frame=Matrix.Translation((ax, 0.0, Hh / 2 - 0.0002)), ang=40)
|
|
return [o, ant]
|
|
|
|
|
|
def phone5():
|
|
core = phone_cuts(phone_core())
|
|
parts = [core] + phone_details()
|
|
for q in parts:
|
|
q["uv_done"] = True
|
|
body = finish(parts, "SM_Phone", ang=34, slots=GP.MATS)
|
|
if body.data.uv_layers:
|
|
body.data.uv_layers.remove(body.data.uv_layers[0]) # the game's SM_Phone body has no UVs; keep it that way
|
|
GP.screen(body)
|
|
return body
|
|
|
|
|
|
# ======================================================================= SM_PhoneHand
|
|
|
|
def phone_hand5(bare=False):
|
|
"""gc_phone_hand's left hand round the phone, in its frame, as the work glove (or bare). The fingers' lines are gc_phone_hand's,
|
|
lifted off the back, the edge and the front just enough to clear the new bumper and the glove's leather."""
|
|
at = GPH.at
|
|
g = 0.0 if bare else 0.0011 # leather over the hand
|
|
clear = 0.0010 # the bumper's lips and the ribs stand this far off the back and the front
|
|
m_main = SKIN if bare else GLOVE
|
|
S = []
|
|
S.append(common.sphere("palm", 1.0, tuple(at(-0.025, -0.05, BACK - 0.024)), seg=28, rings=18, m=m_main, scale=(0.045 + g, 0.021 + g, 0.058 + g)))
|
|
S.append(common.sphere("heel", 1.0, tuple(at(-0.044, -0.098, BACK - 0.026)), seg=24, rings=14, m=m_main, scale=(0.033 + g, 0.022 + g, 0.036 + g)))
|
|
# gc_phone_hand's thenar already dips into the phone's edge; the glove's sits just behind it
|
|
th_c = at(-0.06, -0.082, BACK - 0.0195 + (0.0011 - g))
|
|
S.append(common.sphere("thenar", 1.0, tuple(th_c), seg=24, rings=14, m=m_main, scale=(0.02 + g, 0.016 + g, 0.036 + g)))
|
|
|
|
def ctr_dir(c, T):
|
|
"""Towards the nearest point of the phone's box: what the hand closes on."""
|
|
q = Vector((max(-EDGE, min(EDGE, c.x)), max(BACK, min(FRONT, c.y)), max(-Hh / 2, min(Hh / 2, c.z))))
|
|
return q - c
|
|
digits = []
|
|
for v, r, ln in ((-0.012, 0.0122, 0.9), (-0.0365, 0.0126, 1.0), (-0.0615, 0.0122, 0.95), (-0.0845, 0.0108, 0.8)):
|
|
rg = r + g
|
|
behind = BACK - clear - rg * 1.05
|
|
ahead = FRONT + clear + rg * 0.95
|
|
out = EDGE + rg * 1.02
|
|
pts = [(-0.014, v - 0.005, behind - 0.009), (0.016, v - 0.003, behind - 0.003), (0.04, v - 0.001, behind), (out - 0.004, v, behind + 0.004),
|
|
(out + 0.001, v + 0.001, -0.002), (out - 0.003, v + 0.002, ahead - 0.005), (out - 0.004 - 0.008 * ln, v + 0.003, ahead)]
|
|
digits.append(Digit([at(*p) for p in pts], r, (0.04, 0.44, 0.74), ctr_dir, grow=g))
|
|
r = 0.0128
|
|
rg = r + g
|
|
if True: # up the left edge, the thumb just clear of the band, the corner guard and the front lip
|
|
tp = [(-0.05, -0.098, BACK - 0.021), (-0.066, -0.078, BACK - 0.009), (-EDGE - rg * 1.05, -0.056, -0.002), (-EDGE - rg * 0.78, -0.036, FRONT + clear + rg * 0.55),
|
|
(-EDGE - 0.002, -0.02, FRONT + clear + rg * 0.92)]
|
|
digits.append(Digit([at(*p) for p in tp], r, (0.34, 0.68), ctr_dir, grow=g, kind="thumb"))
|
|
for d in digits:
|
|
S.append(d.tube("digit", m_main))
|
|
# the glove's wrist and gauntlet are thicker than the bare wrist: dropped a little further behind the phone's bottom corner
|
|
root = Vector((-0.051, -0.128, BACK - 0.028)) if bare else Vector((-0.052, -0.13, BACK - 0.031))
|
|
way_uvw = Vector((-0.34, -0.8, 0.5)).normalized()
|
|
root_b, way_b = at(*root), at(*way_uvw)
|
|
P = []
|
|
look = (0.25, 1.0, 0.2)
|
|
if bare:
|
|
S.append(shirt_arm(P, root_b, way_b, 0.031, look=look, fore=(-0.012, 0.26)))
|
|
heel = at(-0.044, -0.098, BACK - 0.026)
|
|
skin = organic(S, "skin", SKIN, digits, tris=9000, soft=[(root_b + way_b * 0.022, 0.034), (root_b.lerp(heel, 0.5), 0.024)])
|
|
dn, nv = skin["dense"], len(skin.data.vertices)
|
|
bvh = BVHTree.FromObject(skin, bpy.context.evaluated_depsgraph_get())
|
|
for d in digits:
|
|
P.append(nail(bvh, d))
|
|
return transfer_normals(finish([skin] + P, "SM_PhoneHand", ang=60, slots=SLOTS["SM_PhoneHand"]), dn, nv)
|
|
# the glove's wrist, blended with the palm
|
|
pw = lambda s: root_b + way_b * s
|
|
S.append(sweep_circle("gwrist", [pw(-0.03), pw(0.0), pw(0.03)], lambda t, l: 0.0335 + 0.002 * t, segs=20, per=4, m=GLOVE, cap=True))
|
|
glove = organic(S, "glove", GLOVE, digits, voxel=0.0007, tris=7000, spec=GLOVE_CREASES, smooth_it=4,
|
|
soft=[(root_b + way_b * 0.012, 0.03)])
|
|
bvh = BVHTree.FromObject(bpy.data.objects[glove["dense"]], bpy.context.evaluated_depsgraph_get())
|
|
# seam welts down both sides of every finger, padded knuckle guards, reinforced tips, stitching
|
|
for di, d in enumerate(digits):
|
|
thumb = d.kind == "thumb"
|
|
for side in (-1, 1):
|
|
th = side * DEG(86)
|
|
s0, s1 = (0.12, 0.765) if not thumb else (0.36, 0.765)
|
|
P.append(surface_patch("welt", lambda u, v, th=th, s0=s0, s1=s1, d=d: d.surf(s0 + (s1 - s0) * u, th + (v - 0.5) * 0.11),
|
|
lambda u, v: 0.00055 * math.sin(math.pi * v) + 0.00025, 12, 2, 0.0005, GLOVE, bvh=bvh, use_nrm=True))
|
|
if not thumb:
|
|
for (s0, s1, half, h, nu) in ((0.0, 0.17, DEG(70), 0.0019, 6), (0.36, 0.5, DEG(58), 0.0013, 5)):
|
|
P.append(surface_patch("kpad", lambda u, v, s0=s0, s1=s1, half=half, d=d: d.surf(s0 + (s1 - s0) * u, -half + 2 * half * v),
|
|
lambda u, v, h=h: h * smoothstep(0.0, 0.28, u) * smoothstep(0.0, 0.28, 1 - u) * smoothstep(0.0, 0.25, v) *
|
|
smoothstep(0.0, 0.25, 1 - v) + 0.0004, nu, 6, 0.0008, GLEATH, bvh=bvh, use_nrm=True))
|
|
# stitches round the pad
|
|
L = (s1 - s0) * d.tot
|
|
for k in range(int(L / 0.0028)):
|
|
for vv in (0.12, 0.88):
|
|
ss = s0 + (s1 - s0) * (0.1 + 0.8 * (k + 0.5) / int(L / 0.0028))
|
|
P.append(stitch(bvh, d, ss, -half + 2 * half * vv, along=True, lift=0.0004 + h * 0.55))
|
|
# the reinforced tip
|
|
s0, s1, half = 0.78, 0.985, DEG(78) if not thumb else DEG(70)
|
|
P.append(surface_patch("tipcap", lambda u, v, d=d, s0=s0, s1=s1, half=half: d.surf(s0 + (s1 - s0) * u, -half + 2 * half * v),
|
|
lambda u, v: 0.0006 * smoothstep(0.0, 0.15, u) * smoothstep(0.0, 0.12, v) * smoothstep(0.0, 0.12, 1 - v) + 0.0004,
|
|
6, 8, 0.0008, GLEATH, bvh=bvh, use_nrm=True))
|
|
for k in range(7):
|
|
P.append(stitch(bvh, d, s0 + 0.025, -half * 0.85 + 2 * half * 0.85 * k / 6, along=False, lift=0.0009))
|
|
# a patch over the ball of the thumb, stitched
|
|
dt = digits[-1]
|
|
P.append(surface_patch("tpatch", lambda u, v: dt.surf(0.22 + 0.26 * u, DEG(-50) + DEG(100) * v),
|
|
lambda u, v: 0.0008 * smoothstep(0.0, 0.2, u) * smoothstep(0.0, 0.2, 1 - u) * smoothstep(0.0, 0.2, v) * smoothstep(0.0, 0.2, 1 - v) + 0.0004,
|
|
7, 6, 0.0008, GLEATH, bvh=bvh, use_nrm=True))
|
|
# the gauntlet: a leather cuff flaring from the wrist, a rolled edge, a strap and a brass buckle
|
|
X = perp(Vector(look), way_b)
|
|
Y = way_b.cross(X)
|
|
Fw = Matrix((X, Y, way_b)).transposed().to_4x4()
|
|
Fw.translation = root_b
|
|
gr = lambda s: 0.0352 + 0.0115 * smoothstep(0.0, 0.08, s)
|
|
prof = [(gr(s), s) for s in (-0.022, -0.012, 0.0, 0.012, 0.024, 0.036, 0.048, 0.058, 0.066, 0.072)]
|
|
prof += [(gr(0.072) + 0.0009, 0.0745), (gr(0.072) + 0.0012, 0.0775), (gr(0.072) + 0.0006, 0.0793), (gr(0.072) - 0.0006, 0.0796),
|
|
(gr(0.072) - 0.0014, 0.0785), (gr(0.072) - 0.0016, 0.0740)]
|
|
prof = [(0.0336, -0.026)] + prof
|
|
P.append(lathe5("gauntlet", prof, [GLEATH], segs=40, frame=Fw, ang=45))
|
|
for k in range(26): # stitches round the gauntlet under the roll
|
|
a = TAU * k / 26
|
|
dvec = X * math.cos(a) + Y * math.sin(a)
|
|
c = root_b + way_b * 0.0705 + dvec * (gr(0.0705) + 0.0001)
|
|
tng = (X * -math.sin(a) + Y * math.cos(a))
|
|
P.append(dash(c, dvec, tng))
|
|
sa, sb = 0.006, 0.019
|
|
P.append(lathe5("strap", [(gr(sa) - 0.0003, sa), (gr(sa) + 0.0013, sa + 0.0006), (gr(sa) + 0.0017, sa + 0.0018), (gr(sb) + 0.0017, sb - 0.0018),
|
|
(gr(sb) + 0.0013, sb - 0.0006), (gr(sb) - 0.0003, sb)], [GLEATH], segs=40, frame=Fw, ang=45))
|
|
# the buckle on the strap, facing the viewer
|
|
sc = (sa + sb) / 2
|
|
Rb = gr(sc) + 0.0019
|
|
a0 = 0.0
|
|
|
|
def cylp(s, a, rr):
|
|
dvec = X * math.cos(a) + Y * math.sin(a)
|
|
return root_b + way_b * s + dvec * rr
|
|
frame_pts = []
|
|
hw, hl = 0.0105, 0.0085 # half extents round the wrist and along it
|
|
for q in range(28):
|
|
t = TAU * q / 28
|
|
cx, cy = math.cos(t), math.sin(t)
|
|
e = 4.0
|
|
rx = hw * math.copysign(abs(cx) ** (2 / e), cx)
|
|
ry = hl * math.copysign(abs(cy) ** (2 / e), cy)
|
|
frame_pts.append(cylp(sc + ry, a0 + rx / Rb, Rb + 0.0006))
|
|
bm = bmesh.new()
|
|
n = len(frame_pts)
|
|
R = []
|
|
for i, c in enumerate(frame_pts):
|
|
t = (frame_pts[(i + 1) % n] - frame_pts[i - 1]).normalized()
|
|
nrm = (c - (root_b + way_b * (c - root_b).dot(way_b))).normalized()
|
|
b_ = t.cross(nrm).normalized()
|
|
R.append([bm.verts.new(c + (nrm * math.cos(TAU * k / 8) * 0.00075 + b_ * math.sin(TAU * k / 8) * 0.0009)) for k in range(8)])
|
|
for i in range(n):
|
|
A_, B_ = R[i], R[(i + 1) % n]
|
|
for k in range(8):
|
|
bm.faces.new((A_[k], A_[(k + 1) % 8], B_[(k + 1) % 8], B_[k]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
P.append(obj_from_bm("buckle", bm, [BRASS], 60))
|
|
P.append(GV.cyl_between("bar", cylp(sc, a0 - hw / Rb, Rb + 0.0006), cylp(sc, a0 + hw / Rb, Rb + 0.0006), 0.0008, BRASS, v=8))
|
|
P.append(GV.cyl_between("prong", cylp(sc, a0, Rb + 0.0011), cylp(sc + hl * 1.05, a0, Rb + 0.0009), 0.00055, BRASS, v=6))
|
|
# the strap's free end through the buckle
|
|
P.append(surface_patch("tongue", lambda u, v: (cylp(sc + (v - 0.5) * (sb - sa - 0.004), a0 - hw * 0.8 / Rb + u * 0.034 / Rb, Rb - 0.0001),
|
|
(cylp(sc, a0 - hw * 0.8 / Rb + u * 0.034 / Rb, 1.0) - (root_b + way_b * sc))),
|
|
lambda u, v: 0.0012 * smoothstep(0, 0.2, v) * smoothstep(0, 0.2, 1 - v) * (1 - smoothstep(0.85, 1.0, u)) + 0.0002, 10, 4, 0.0006, GLEATH))
|
|
# the bare forearm out of the gauntlet, the shirt cuff and the sleeve
|
|
fa = shirt_arm(P, root_b, way_b, 0.034, look=look, fore=(0.05, 0.26), skin=False)
|
|
P.append(fa)
|
|
dn, nv = glove["dense"], len(glove.data.vertices)
|
|
return transfer_normals(finish([glove] + P, "SM_PhoneHand", ang=60, slots=SLOTS["SM_PhoneHand"]), dn, nv)
|
|
|
|
|
|
def stitch(bvh, d, s, th, along=True, lift=0.0):
|
|
"""One stitch on a digit: a short raised dash, along the finger or across it."""
|
|
c, dirn = d.surf(s, th)
|
|
loc, nrm, _, _ = bvh.find_nearest(c) if bvh else (None, None, None, None)
|
|
if loc is not None:
|
|
c = loc
|
|
dirn = nrm if nrm.dot(dirn) > 0 else -nrm
|
|
_, T, D_, B = d.frame(s)
|
|
tng = T if along else (D_ * math.sin(th) + B * math.cos(th))
|
|
return dash(c + Vector(dirn).normalized() * lift, dirn, tng)
|
|
|
|
|
|
def dash(c, nrm, tng, L=0.0016, w=0.00045, h=0.0003):
|
|
nrm = Vector(nrm).normalized()
|
|
tng = perp(Vector(tng), nrm)
|
|
side = nrm.cross(tng)
|
|
M = Matrix((tng, side, nrm)).transposed().to_4x4()
|
|
M.translation = Vector(c)
|
|
pts = [(L / 2, 0.0), (0.0, w / 2), (-L / 2, 0.0), (0.0, -w / 2)]
|
|
bm = bmesh.new()
|
|
lo = [bm.verts.new(M @ Vector((x, y, -0.0003))) for x, y in pts]
|
|
hi = [bm.verts.new(M @ Vector((x * 0.9, y * 0.7, h))) for x, y in pts]
|
|
bm.faces.new(list(reversed(lo)))
|
|
bm.faces.new(hi)
|
|
for i in range(4):
|
|
bm.faces.new((lo[i], lo[(i + 1) % 4], hi[(i + 1) % 4], hi[i]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
return obj_from_bm("stitch", bm, [STITCH], 80)
|
|
|
|
|
|
def phone_hand_build():
|
|
phone_hand5(bare=os.environ.get("GC5_PHONEHAND_GLOVE") != "1")
|
|
|
|
|
|
# ======================================================================= build
|
|
|
|
BUILDERS = {"SM_HandCan": hand_can_build, "SM_HandCigar": hand_cigar5, "SM_Phone": phone5, "SM_PhoneHand": phone_hand_build,
|
|
"SM_BeerCan": lambda: beer_can5(False), "SM_BeerCanCrushed": lambda: beer_can5(True)}
|
|
|
|
|
|
def build(names):
|
|
common.MODELS = os.path.join(OUT, "fbx")
|
|
common.BLENDS = OUT
|
|
os.makedirs(common.MODELS, exist_ok=True)
|
|
for n in names:
|
|
common.reset()
|
|
random.seed(zlib.crc32(n.encode()) & 0xffff)
|
|
BUILDERS[n]()
|
|
bpy.context.view_layer.update()
|
|
objs = [o for o in bpy.context.scene.objects if o.type == "MESH"]
|
|
for o in sorted(objs, key=lambda o: o.name):
|
|
print(f"B5|{n}| {o.name:14s} parent {o.parent.name if o.parent else '-':8s} tris {tri_count([o]):6d} loc {tuple(round(v, 4) for v in o.location)}"
|
|
f" mats {[m.name for m in o.data.materials]}")
|
|
t = tri_count(objs)
|
|
print(f"B5|{n}| tris {t} budget {BUDGET[n]} {'OVER' if t > BUDGET[n] else 'ok'}")
|
|
common.export(n)
|
|
for m in bpy.data.materials:
|
|
m.use_backface_culling = True
|
|
common.save_blend(n)
|
|
|
|
|
|
def ref_phone_hand():
|
|
"""gc_phone_hand.py's own hand (it is not in Assets), exported once as the reference for verify and the before panels."""
|
|
os.makedirs(REF, exist_ok=True)
|
|
p = os.path.join(REF, "SM_PhoneHand.fbx")
|
|
if not os.path.exists(p):
|
|
common.reset()
|
|
GPH.hand()
|
|
old = common.MODELS
|
|
common.MODELS = REF
|
|
common.export("SM_PhoneHand")
|
|
common.MODELS = old
|
|
return p
|
|
|
|
|
|
def old_path(n):
|
|
return ref_phone_hand() if n == "SM_PhoneHand" else os.path.join(GAME, n + ".fbx")
|
|
|
|
|
|
# ======================================================================= verify
|
|
|
|
def snapshot(path):
|
|
import gc_up5_check as C5
|
|
return C5.snapshot(path)
|
|
|
|
|
|
def load_only(path):
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
bpy.ops.import_scene.fbx(filepath=path)
|
|
bpy.context.view_layer.update()
|
|
return {o.name: o for o in bpy.context.scene.objects}
|
|
|
|
|
|
def screen_data(path):
|
|
objs = load_only(path)
|
|
s = objs["Screen"]
|
|
me = s.data
|
|
uvl = me.uv_layers.active
|
|
loops = []
|
|
for p in me.polygons:
|
|
for li in p.loop_indices:
|
|
v = me.vertices[me.loops[li].vertex_index].co
|
|
w = s.matrix_world @ v
|
|
uv = uvl.data[li].uv
|
|
loops.append((round(w.x, 6), round(w.y, 6), round(w.z, 6), round(uv.x, 5), round(uv.y, 5)))
|
|
# winding: the screen's triangles face +Y (the viewer) and their UVs turn the same way
|
|
faces = []
|
|
for p in me.polygons:
|
|
ls = list(p.loop_indices)
|
|
a, b, c = [uvl.data[i].uv for i in ls[:3]]
|
|
uv_area = (b - a).cross(c - a) if hasattr(b - a, "cross") else (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
|
nrm = (s.matrix_world.to_3x3() @ p.normal)
|
|
faces.append((round(nrm.y, 3), 1 if uv_area > 0 else -1))
|
|
# where the display's corners land in UV
|
|
return dict(loops=sorted(loops), faces=sorted(faces), mw=[tuple(round(x, 6) for x in r) for r in s.matrix_world], parent=s.parent.name if s.parent else None,
|
|
name_uv=uvl.name, mats=[m.name.split(".")[0] for m in me.materials])
|
|
|
|
|
|
def overlap_count(path_body, path_hand, body_name="SM_Phone", hand_name="SM_PhoneHand"):
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
bpy.ops.import_scene.fbx(filepath=path_body)
|
|
bpy.ops.import_scene.fbx(filepath=path_hand)
|
|
bpy.context.view_layer.update()
|
|
dg = bpy.context.evaluated_depsgraph_get()
|
|
objs = {o.name.split(".")[0]: o for o in bpy.context.scene.objects if o.type == "MESH"}
|
|
b = objs[body_name]
|
|
h = [o for n, o in objs.items() if n.startswith(hand_name)][0]
|
|
|
|
def tree(o):
|
|
me = o.data
|
|
vs = [o.matrix_world @ v.co for v in me.vertices]
|
|
return BVHTree.FromPolygons(vs, [tuple(p.vertices) for p in me.polygons]), vs
|
|
tb, vb = tree(b)
|
|
th, vh = tree(h)
|
|
pairs = tb.overlap(th)
|
|
# how deep: hand vertices inside the phone body (ray parity along +X)
|
|
inside = 0
|
|
for v in vh:
|
|
if not (-EDGE - 0.002 < v.x < EDGE + 0.002 and BACK - 0.004 < v.y < FRONT + 0.003 and -Hh / 2 - 0.002 < v.z < Hh / 2 + 0.03):
|
|
continue
|
|
cnt, o_ = 0, v.copy()
|
|
dvec = Vector((1, 0.0137, 0.0071)).normalized()
|
|
while cnt < 50:
|
|
hit = tb.ray_cast(o_, dvec)
|
|
if hit[0] is None:
|
|
break
|
|
cnt += 1
|
|
o_ = hit[0] + dvec * 1e-6
|
|
if cnt % 2 == 1:
|
|
inside += 1
|
|
return len(pairs), inside
|
|
|
|
|
|
def verify(names):
|
|
import gc_up5_check as C5
|
|
bad = 0
|
|
for n in names:
|
|
old = snapshot(old_path(n))
|
|
new = snapshot(os.path.join(OUT, "fbx", n + ".fbx"))
|
|
print(f"V5P|{n} (reference: {'gc_phone_hand.py build' if n == 'SM_PhoneHand' else 'Assets/Art/Models'})")
|
|
if set(old) != set(new):
|
|
print(f"V5P| FAIL objects differ: old {sorted(old)} new {sorted(new)}")
|
|
bad += 1
|
|
for k in sorted(set(old) & set(new)):
|
|
o, w = old[k], new[k]
|
|
dloc = max(abs(a - b) for a, b in zip(o[2], w[2]))
|
|
drot = max(abs(a - b) for a, b in zip(o[3], w[3]))
|
|
dsc = max(abs(a - b) for a, b in zip(o[4], w[4]))
|
|
ok = o[0] == w[0] and o[1] == w[1] and dloc < 1e-4 and drot < 1e-4 and dsc < 1e-4
|
|
bad += 0 if ok else 1
|
|
ext = lambda s: tuple(round(b - a, 4) for a, b in zip(s[5], s[6]))
|
|
dmin = max(abs(a - b) for a, b in zip(o[5], w[5]))
|
|
dmax = max(abs(a - b) for a, b in zip(o[6], w[6]))
|
|
print(f"V5P| {'ok ' if ok else 'FAIL'} {k:<12} type {w[0]} parent {w[1]} origin {tuple(round(x, 4) for x in w[2])} (d {dloc:.1e}) rot "
|
|
f"{tuple(round(math.degrees(x), 2) for x in w[3])} (d {drot:.1e}) scale d {dsc:.1e}")
|
|
print(f"V5P| bbox old {tuple(round(x, 4) for x in o[5])}..{tuple(round(x, 4) for x in o[6])} size {ext(o)}")
|
|
print(f"V5P| bbox new {tuple(round(x, 4) for x in w[5])}..{tuple(round(x, 4) for x in w[6])} size {ext(w)} (max corner shift {max(dmin, dmax) * 1000:.2f} mm)")
|
|
print(f"V5P| tris {o[7]} -> {w[7]}")
|
|
extra = sorted(set(w[8]) - set(o[8]))
|
|
gone = sorted(set(o[8]) - set(w[8]))
|
|
nomat = sorted(m for m in set(w[8]) if not os.path.exists(os.path.join(ROOT, "Assets", "Art", "Materials", m + ".mat")))
|
|
print(f"V5P| slots old {o[8]}")
|
|
print(f"V5P| slots new {w[8]} added: {extra or 'none'} dropped: {gone or 'none'} without a .mat: {nomat or 'none'}")
|
|
if nomat or (gone and n != "SM_PhoneHand"):
|
|
bad += 1
|
|
if n == "SM_Phone":
|
|
a = screen_data(old_path(n))
|
|
b = screen_data(os.path.join(OUT, "fbx", n + ".fbx"))
|
|
same_loops = len(a["loops"]) == len(b["loops"]) and all(max(abs(p - q) for p, q in zip(x, y)) < 2e-6 for x, y in zip(a["loops"], b["loops"]))
|
|
same_faces = a["faces"] == b["faces"]
|
|
same_mw = a["mw"] == b["mw"] and a["parent"] == b["parent"]
|
|
uvs = [l[3:] for l in b["loops"]]
|
|
u0, u1 = min(u for u, v in uvs), max(u for u, v in uvs)
|
|
v0, v1 = min(v for u, v in uvs), max(v for u, v in uvs)
|
|
ok = same_loops and same_faces and same_mw and a["mats"] == b["mats"]
|
|
bad += 0 if ok else 1
|
|
print(f"V5P| {'ok ' if ok else 'FAIL'} Screen: {len(b['loops'])} loops, positions + UVs identical to the game FBX: {same_loops}; "
|
|
f"winding (normal y, UV turn) identical: {same_faces} {sorted(set(b['faces']))}; transform + parent identical: {same_mw}; "
|
|
f"UV layer {b['name_uv']} mats {b['mats']}")
|
|
print(f"V5P| Screen UV range u {u0:.4f}..{u1:.4f} v {v0:.4f}..{v1:.4f} (bounding box of the cut-corner display = 0..1)")
|
|
# nothing of the body in front of the display
|
|
objs = load_only(os.path.join(OUT, "fbx", n + ".fbx"))
|
|
body = objs["SM_Phone"]
|
|
poly = [Vector((-p.x, p.y)) for p in GP.outline(GP.BEZEL)]
|
|
yscr = 0.0046
|
|
worst = -1.0
|
|
vs = [body.matrix_world @ v.co for v in body.data.vertices]
|
|
tb = BVHTree.FromPolygons(vs, [tuple(q.vertices) for q in body.data.polygons])
|
|
pl = [(p.x, p.y) for p in poly]
|
|
nray = 0
|
|
for i in range(41): # rays straight down onto the display, edge to edge
|
|
for j in range(81):
|
|
x, z = -0.0475 + 0.095 * i / 40, -0.1035 + 0.207 * j / 80
|
|
if not GV.inside2((x, z), pl):
|
|
continue
|
|
hit = tb.ray_cast(Vector((x, 0.05, z)), Vector((0, -1, 0)))
|
|
nray += 1
|
|
if hit[0] is not None:
|
|
worst = max(worst, hit[0].y)
|
|
ok = worst < yscr
|
|
bad += 0 if ok else 1
|
|
print(f"V5P| {'ok ' if ok else 'FAIL'} nothing of the body over the display: highest body surface under {nray} rays inside the Screen outline y = {worst:.5f} "
|
|
f"(Screen at {yscr})")
|
|
slots = [m.name.split(".")[0] for m in body.data.materials]
|
|
gs = [i for i, m in enumerate(slots) if m.startswith("M_PhoneGlow")]
|
|
print(f"V5P| {'ok ' if gs else 'FAIL'} Phone.cs: one body renderer + Screen, glow slot found by name at index {gs}")
|
|
bad += 0 if gs else 1
|
|
if n == "SM_PhoneHand":
|
|
for tag, ph, hd in (("old hand on old phone", os.path.join(GAME, "SM_Phone.fbx"), ref_phone_hand()),
|
|
("old hand on new phone", os.path.join(OUT, "fbx", "SM_Phone.fbx"), ref_phone_hand()),
|
|
("new glove on new phone", os.path.join(OUT, "fbx", "SM_Phone.fbx"), os.path.join(OUT, "fbx", "SM_PhoneHand.fbx"))):
|
|
if not os.path.exists(ph) or not os.path.exists(hd):
|
|
continue
|
|
pairs, inside = overlap_count(ph, hd)
|
|
okc = pairs == 0 and inside == 0
|
|
if tag.startswith("new"):
|
|
bad += 0 if okc else 1
|
|
print(f"V5P| {'ok ' if okc else 'note' if not tag.startswith('new') else 'FAIL'} clipping, {tag}: intersecting triangle pairs {pairs}, "
|
|
f"hand vertices inside the phone {inside}")
|
|
if n in ("SM_HandCan", "SM_HandCigar"):
|
|
# TreatHand needs: the item, its tab / ember by name, the Hand to switch off
|
|
need = {"SM_HandCan": ["Hand", "Can", "Tab"], "SM_HandCigar": ["Hand", "Cigar", "Ember"]}[n]
|
|
miss = [x for x in need if x not in new]
|
|
print(f"V5P| {'ok ' if not miss else 'FAIL'} TreatHand names {need} present")
|
|
bad += 1 if miss else 0
|
|
# contact: how close the fingers come to the item, before and after
|
|
for tag, p in (("old", old_path(n)), ("new", os.path.join(OUT, "fbx", n + ".fbx"))):
|
|
objs = load_only(p)
|
|
h = objs["Hand"]
|
|
item = objs["Can" if n == "SM_HandCan" else "Cigar"]
|
|
dg = bpy.context.evaluated_depsgraph_get()
|
|
vs = [item.matrix_world @ v.co for v in item.data.vertices]
|
|
ti = BVHTree.FromPolygons(vs, [tuple(q.vertices) for q in item.data.polygons])
|
|
hv = [h.matrix_world @ v.co for v in h.data.vertices]
|
|
th_ = BVHTree.FromPolygons(hv, [tuple(q.vertices) for q in h.data.polygons])
|
|
ds = [ti.find_nearest(v)[3] for v in hv if (v - Vector((0, 0, 0))).length < 0.12]
|
|
near = sorted(ds)[:200]
|
|
npairs = len(ti.overlap(th_))
|
|
if tag == "new" and npairs:
|
|
bad += 1
|
|
print(f"V5P| {'FAIL' if tag == 'new' and npairs else ' '} {tag}: hand to {item.name}: closest {min(ds) * 1000:.2f} mm, "
|
|
f"200th closest {near[-1] * 1000:.2f} mm, intersecting triangle pairs {npairs}")
|
|
print("V5P|RESULT|" + ("OK" if bad == 0 else f"{bad} problem(s)"))
|
|
|
|
|
|
# ======================================================================= review renders
|
|
|
|
# (tag, target or None for the whole model, radius, elev, azim)
|
|
VIEWS = {
|
|
"SM_HandCan": [("full", (-0.03, 0.03, -0.03), 0.16, 8, 160), ("back", (-0.02, 0.0, -0.02), 0.13, 12, -25), ("lid", (0.0, 0.0, 0.056), 0.034, 58, 165),
|
|
("tab", (0.0, 0.004, 0.058), 0.017, 40, 200), ("fingers", (0.03, 0.012, 0.0), 0.05, 10, 140), ("nails", (0.04, 0.006, 0.034), 0.016, 20, 75), ("cuff", (-0.15, 0.137, -0.29), 0.075, 25, 150),
|
|
("bottom", (0.0, 0.0, -0.055), 0.05, -45, 170)],
|
|
"SM_HandCigar": [("full", (-0.02, 0.02, -0.02), 0.16, 10, 150), ("back", (-0.03, 0.0, -0.02), 0.13, 15, -60), ("ember", (0.064, 0.0, 0.0), 0.022, 15, 120),
|
|
("band", (-0.035, 0.0, 0.0), 0.03, 30, 170), ("fingers", (0.0, 0.0, 0.0), 0.06, 20, 110), ("cuff", (-0.18, 0.15, -0.3), 0.075, 25, 160)],
|
|
"SM_Phone": [("front", (0.0, 0.0, 0.01), 0.125, 8, 162), ("back", (0.0, 0.0, 0.01), 0.125, 12, -24), ("corner", (-0.044, 0.002, 0.098), 0.022, 28, 150),
|
|
("bump", (0.0, -0.006, 0.076), 0.045, 22, -15), ("port", (0.0, 0.0, -0.106), 0.026, -40, 165), ("buttons", (-0.05, 0.0, 0.035), 0.036, 22, -60), ("guard", (0.04, -0.004, -0.1), 0.022, 35, 20),
|
|
("antenna", (-0.034, 0.0, 0.112), 0.022, 15, -150)],
|
|
"SM_BeerCan": [("full", (0.0, 0.0, 0.0), 0.075, 22, -30), ("back", (0.0, 0.0, 0.0), 0.075, 22, 150), ("lid", (0.0, 0.0, 0.056), 0.034, 58, -15),
|
|
("bottom", (0.0, 0.0, -0.055), 0.045, -50, 20)],
|
|
"SM_BeerCanCrushed": [("full", (0.0, 0.0, 0.0), 0.07, 22, -30), ("back", (0.0, 0.0, 0.0), 0.07, 30, 140), ("side", (0.0, 0.0, 0.0), 0.07, 4, -90),
|
|
("top", (0.0, 0.0, 0.02), 0.06, 65, 10)],
|
|
"SM_PhoneHand": [("front", (0.0, 0.01, -0.05), 0.17, 6, 168), ("back", (0.0, -0.01, -0.05), 0.17, 10, -20), ("fingertips", (-0.05, 0.01, -0.048), 0.05, 20, 160),
|
|
("knuckles", (-0.02, -0.03, -0.05), 0.075, 12, -40), ("thumb", (0.055, 0.005, -0.06), 0.05, 15, 140), ("wrist", (0.065, 0.06, -0.15), 0.07, 20, 150)],
|
|
}
|
|
|
|
|
|
def _with_phone(n, which):
|
|
if n != "SM_PhoneHand":
|
|
return None
|
|
return os.path.join(GAME, "SM_Phone.fbx") if which == "old" else os.path.join(OUT, "fbx", "SM_Phone.fbx")
|
|
|
|
|
|
def views(names):
|
|
import gc_up5_check as C5
|
|
os.makedirs(PANELS, exist_ok=True)
|
|
tags = os.environ.get("GC5_VIEWS")
|
|
only = os.environ.get("GC5_ONLY")
|
|
for n in names:
|
|
for which, path in (("old", old_path(n)), ("new", os.path.join(OUT, "fbx", n + ".fbx"))):
|
|
if only and which != only:
|
|
continue
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
C5.load_fbx(path)
|
|
ph = _with_phone(n, which)
|
|
if ph:
|
|
C5.load_fbx(ph)
|
|
C5.lights()
|
|
for tag, tgt, rad, el, az in VIEWS[n]:
|
|
if tags and tag not in tags.split(","):
|
|
continue
|
|
C5.shoot(os.path.join(PANELS, f"{n}_{tag}_{which}.png"), Vector(tgt), rad, el, az)
|
|
|
|
|
|
# TreatHand / Phone poses: (tag, pivot position, pivot euler (Unity), flip the model 180 about Y, show the Hand)
|
|
FPV = {
|
|
"SM_HandCan": [("fpv", (0.17, -0.15, 0.33), (-6, -12, 6), True, False), ("fpv_hand", (0.17, -0.15, 0.33), (-6, -12, 6), True, True),
|
|
("fpv_drink", (0.075, -0.085, 0.25), (-45, -18, 22), True, False)],
|
|
"SM_HandCigar": [("fpv", (0.16, -0.14, 0.33), (-4, -8, -4), True, False), ("fpv_hand", (0.16, -0.14, 0.33), (-4, -8, -4), True, True)],
|
|
"SM_Phone": [("fpv", (-0.215, -0.012, 0.31), (4, -27, 4), False, True), ("fpv_up", (0.0, 0.0, 0.207), (0, 0, 0), False, True)],
|
|
"SM_PhoneHand": [("fpv", (-0.215, -0.012, 0.31), (4, -27, 4), False, True)],
|
|
}
|
|
|
|
|
|
def fpv(names):
|
|
import gc_up5_check as C5
|
|
M = Matrix(((-1, 0, 0, 0), (0, 0, -1, 0), (0, 1, 0, 0), (0, 0, 0, 1)))
|
|
os.makedirs(PANELS, exist_ok=True)
|
|
for n in names:
|
|
for tag, pos, eu, flip, show_hand in FPV.get(n, []):
|
|
for which, path in (("old", old_path(n)), ("new", os.path.join(OUT, "fbx", n + ".fbx"))):
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
rig = Matrix.Translation(Vector(pos)) @ C5.euler(*eu)
|
|
if flip:
|
|
rig = rig @ Matrix.Rotation(math.pi, 4, "Y")
|
|
W_ = M @ rig @ M.inverted()
|
|
objs = C5.load_fbx(path)
|
|
ph = _with_phone(n, which)
|
|
if ph:
|
|
objs += C5.load_fbx(ph)
|
|
for o in objs:
|
|
if o.name.startswith("Hand") and not show_hand:
|
|
o.hide_render = True
|
|
if o.parent is None:
|
|
o.matrix_world = W_ @ o.matrix_world
|
|
sc = bpy.context.scene
|
|
cam_d = bpy.data.cameras.new("c")
|
|
cam_d.sensor_fit = "VERTICAL"
|
|
cam_d.angle = math.radians(62)
|
|
cam_d.clip_start = 0.01
|
|
cam = common.link(bpy.data.objects.new("c", cam_d))
|
|
cam.rotation_euler = (math.radians(90), 0, math.pi)
|
|
sc.camera = cam
|
|
C5.lights((0.55, 0.72, 0.42), 0.7)
|
|
sc.render.resolution_x, sc.render.resolution_y = 1280, 720
|
|
sc.render.filepath = os.path.join(PANELS, f"{n}_{tag}_{which}.png")
|
|
bpy.ops.render.render(write_still=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
mode = args[0] if args and args[0] in ("build", "verify", "views", "fpv") else "build"
|
|
names = [a for a in args if a in NAMES] or NAMES
|
|
{"build": build, "verify": verify, "views": views, "fpv": fpv}[mode](names)
|