cntrl/tools/blender/build_hiss_boss.py

734 lines
32 KiB
Python

# tools/blender/build_hiss_boss.py
# FBC: NIGHT SHIFT — final boss: the Hiss Warden (Control "Hissed guard").
#
# Run inside Blender 5.x:
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_hiss_boss.py").read())
#
# Builds a ~3x-scale (5.7 m) corrupted security officer: pale red-veined face,
# grey FBC uniform, lanyard/badge, pump shotgun held across the chest and black
# Hiss smoke boiling off the head and shoulders. Rigs it with a 19-bone
# armature, authors Idle / Walk / Attack / Stagger / Death actions and exports
# one skinned, colour-painted GLB with animations for the in-game ModelBank.
# Geometry and bones are authored at human scale then scaled by S together.
import math
import os
import re
import sys
import bpy
from mathutils import Euler, Matrix, Vector
REPO = "/home/dandovlatov/Documents/cntrl"
MODEL_DIR = os.path.join(REPO, "assets", "models")
BLEND_DIR = os.path.join(REPO, "assets", "blender")
CONCEPT_DIR = os.path.join(REPO, "docs", "concept")
for d in (MODEL_DIR, BLEND_DIR, CONCEPT_DIR):
os.makedirs(d, exist_ok=True)
sys.path.insert(0, os.path.join(REPO, "tools", "blender"))
import importlib
import actor_kit as K
importlib.reload(K)
K.clear_scene()
# Re-running in a live session must not leave stale fake-user actions in the
# saved .blend or in the exported GLB's animation list.
for old_action in list(bpy.data.actions):
bpy.data.actions.remove(old_action)
P = K.PALETTE
P.update({
"uniform": "#57574f", "uniform_dk": "#34342f", "uniform_lt": "#6d6d63",
"cloth": "#41413c", "skin_burn": "#c0ac96", "skin_hot": "#d1232b",
"rot": "#4a1018", "rot_dk": "#200a10", "rot_vein": "#a81a22",
"badge_photo": "#7d1819", "brass": "#c8a312",
})
S = 3.0 # final boss is exactly three times the agent's height
# The shotgun is authored in its own frame: local +X runs from the butt to the
# muzzle. Everything is rotated into place around WEAPON_CENTER so the stock,
# receiver, pump and barrel stay properly aligned across the chest.
WEAPON_CENTER = (0.25, -0.20)
WEAPON_YAW = math.atan2(-0.56, -1.61)
def wpt(lx, ly, lz):
c, s = math.cos(WEAPON_YAW), math.sin(WEAPON_YAW)
return (WEAPON_CENTER[0] + lx * c - ly * s,
WEAPON_CENTER[1] + lx * s + ly * c, lz)
def wplate(root, name, outline, z0, z1, value, taper=1.0, ao=0.05):
obj = K.plate(root, name, outline, z0, z1, taper, value, ao=ao)
c, s = math.cos(WEAPON_YAW), math.sin(WEAPON_YAW)
for v in obj.data.vertices:
x, y = v.co.x, v.co.y
v.co.x = WEAPON_CENTER[0] + x * c - y * s
v.co.y = WEAPON_CENTER[1] + x * s + y * c
obj.data.update()
return obj
# ------------------------------------------------------------------- geometry
def build_warden():
r = K.new_actor("HissWarden")
# --- bald head, warped beyond recognition by the Hiss ---
K.blob(r, "head_skull", (0.01, 0, 1.72), (0.205, 0.19, 0.235),
P["skin_burn"], subdiv=3, warp=0.11, seed=11, ao=0.04)
# One cheek balloons outward; the other has collapsed inward.
K.blob(r, "head_swelling_R", (0.135, -0.075, 1.64), (0.10, 0.10, 0.12),
P["skin_burn"], subdiv=2, warp=0.24, seed=14, ao=0.05)
K.blob(r, "head_hollow_L", (-0.135, -0.11, 1.65), (0.09, 0.055, 0.10),
P["rot_dk"], subdiv=2, warp=0.20, seed=15, ao=0.0)
# Melted, uneven red tissue rather than a clean mask.
for i, (center, scale, hot) in enumerate([
((0.0, -0.17, 1.70), (0.16, 0.055, 0.17), False),
((0.10, -0.19, 1.62), (0.09, 0.06, 0.10), True),
((-0.10, -0.18, 1.76), (0.07, 0.05, 0.08), False),
((0.03, -0.195, 1.55), (0.08, 0.05, 0.07), True),
]):
K.blob(r, "head_curse_%d" % i, center, scale,
P["hiss_hot"] if hot else P["hiss"], subdiv=2, warp=0.22,
seed=12 + i, ao=0.0)
# Crooked brow, crushed nose, a torn open mouth with a hanging jaw.
K.plate(r, "head_brow", K.octagon(0.18, 0.042), 1.79, 1.82, 1.0,
P["rot_dk"], shift=(0.015, -0.17))
K.blob(r, "head_nose_shattered", (0, -0.215, 1.67), (0.045, 0.03, 0.05),
P["rot_dk"], subdiv=1, seed=3)
K.crystal(r, "head_nose_spur", (-0.02, -0.23, 1.67), 0.055, P["hiss_hot"],
sides=4, seed=4, tilt=(0.35, 0.2, 0.4))
K.blob(r, "head_maw", (0.02, -0.205, 1.525), (0.115, 0.04, 0.075),
P["rot_dk"], subdiv=2, warp=0.14, seed=5)
for t in range(5):
K.crystal(r, "head_tooth_%d" % t,
(-0.07 + t * 0.036, -0.244, 1.525 + (t % 2) * 0.014),
0.022, P["skin_burn"] if t % 2 else P["hiss_hot"],
sides=4, seed=60 + t, tilt=(math.pi, 0, 0))
K.plate(r, "head_jaw", K.octagon(0.125, 0.09), 1.44, 1.51, 0.88,
P["hiss"], shift=(0.05, -0.08), ao=0.05)
K.tube(r, "head_jaw_tendon", [(0.09, -0.10, 1.58), (0.11, -0.15, 1.49)],
[0.018, 0.012], P["rot"], sides=5)
# Mismatched eyes: one bulging red orb, one sunken pit, a third on the brow.
K.blob(r, "head_socket_R", (0.085, -0.215, 1.745), (0.055, 0.035, 0.05),
P["rot_dk"], subdiv=1, seed=20)
K.blob(r, "head_eye_R", (0.09, -0.248, 1.745), (0.035, 0.022, 0.032),
P["hiss_hot"], subdiv=2, seed=21, ao=0.0)
K.crystal(r, "head_pupil_R", (0.095, -0.27, 1.745), 0.016, P["rot_dk"],
sides=4, seed=22, tilt=(math.pi / 2, 0, 0))
K.blob(r, "head_socket_L", (-0.08, -0.19, 1.75), (0.06, 0.02, 0.045),
P["rot_dk"], subdiv=1, seed=23)
K.crystal(r, "head_eye_L", (-0.08, -0.212, 1.75), 0.018, P["hiss_hot"],
sides=4, seed=24, tilt=(math.pi / 2, 0, 0))
K.blob(r, "head_third_socket", (0.04, -0.185, 1.84), (0.03, 0.016, 0.028),
P["rot_dk"], subdiv=1, seed=25)
K.crystal(r, "head_third_eye", (0.04, -0.204, 1.84), 0.018,
P["hiss_hot"], sides=4, seed=26, tilt=(math.pi / 2, 0, 0))
K.blob(r, "head_ear_R", (0.205, 0.01, 1.69), (0.04, 0.05, 0.075),
P["skin_burn"], subdiv=1, seed=27)
K.blob(r, "head_ear_L", (-0.205, 0.01, 1.69), (0.03, 0.045, 0.06),
P["skin_burn"], subdiv=1, seed=28)
K.crystal(r, "head_ear_spur", (-0.215, -0.01, 1.73), 0.05, P["hiss_hot"],
sides=4, seed=29, tilt=(-0.3, 0.2, -0.6))
# Branching fissures: dark splits with hot light leaking out of them.
fissures = [
[(-0.01, -0.225, 1.82), (-0.07, -0.222, 1.75), (-0.12, -0.19, 1.64),
(-0.09, -0.16, 1.55)],
[(0.03, -0.225, 1.81), (0.10, -0.218, 1.73), (0.14, -0.17, 1.61)],
[(-0.12, -0.19, 1.64), (-0.05, -0.215, 1.57), (-0.02, -0.21, 1.51)],
[(0.14, -0.17, 1.61), (0.08, -0.22, 1.55), (0.03, -0.23, 1.50)],
[(0.04, -0.205, 1.84), (0.02, -0.22, 1.72), (0.01, -0.22, 1.60)],
]
for i, pts in enumerate(fissures):
K.tube(r, "head_fissure_%d" % i, pts,
[0.016, 0.012, 0.007, 0.004][:len(pts)], P["rot_dk"], sides=5)
K.tube(r, "head_vein_%d" % i, pts,
[0.008, 0.006, 0.004, 0.003][:len(pts)], P["hiss_hot"], sides=5)
for i, (pos, tilt) in enumerate([
((0.15, -0.16, 1.63), (0.2, 0.3, 0.8)),
((-0.12, -0.14, 1.57), (-0.3, -0.2, -0.7)),
((0.06, -0.19, 1.48), (math.pi / 2, 0.2, 0.3)),
]):
K.crystal(r, "head_spur_%d" % i, pos, 0.045, P["hiss_hot"],
sides=4, seed=70 + i, tilt=tilt)
# Soft black-red smoke behind the head and shoulders — no crystal quills.
for i, (center, scale) in enumerate([
((-0.20, 0.13, 1.94), (0.08, 0.07, 0.10)),
((0.21, 0.13, 1.96), (0.08, 0.07, 0.10)),
((0.0, 0.19, 2.06), (0.09, 0.08, 0.11)),
]):
K.blob(r, "smoke_mass_%d" % i, center, scale, P["rot_dk"],
subdiv=1, warp=0.38, seed=40 + i, ao=0.05)
for i, (pts, radii) in enumerate([
([(-0.14, 0.15, 1.94), (-0.26, 0.26, 2.08), (-0.20, 0.34, 2.24),
(-0.34, 0.40, 2.38)], [0.026, 0.020, 0.011, 0.004]),
([(0.15, 0.15, 1.96), (0.28, 0.27, 2.10), (0.22, 0.35, 2.26),
(0.36, 0.41, 2.40)], [0.025, 0.019, 0.010, 0.004]),
([(0.0, 0.20, 2.08), (0.07, 0.30, 2.22), (-0.02, 0.38, 2.36),
(0.05, 0.44, 2.50)], [0.025, 0.018, 0.009, 0.004]),
]):
K.tube(r, "smoke_tendril_%d" % i, pts, radii, P["rot"], sides=5)
for i, pos in enumerate([(-0.22, 0.30, 2.25), (0.23, 0.31, 2.28)]):
K.crystal(r, "smoke_ember_%d" % i, pos, 0.03, P["hiss_hot"],
sides=4, seed=50 + i)
K.tube(r, "neck", [(0, 0, 1.48), (0, 0, 1.60)], [0.10, 0.105],
P["skin_burn"], sides=9)
for i, pts in enumerate([
[(0.05, -0.09, 1.50), (0.07, -0.10, 1.61), (0.05, -0.13, 1.70)],
[(-0.05, -0.09, 1.50), (-0.07, -0.10, 1.60), (-0.06, -0.13, 1.69)],
]):
K.tube(r, "neck_vein_%d" % i, pts, [0.012, 0.010, 0.006],
P["hiss_hot"], sides=5)
# --- torso: old FBC uniform, vest, lanyard, radio, Hiss lesions ---
K.loft(r, "torso", [
{"z": 0.90, "r": (0.29, 0.19), "n": 14},
{"z": 1.00, "r": (0.32, 0.21), "n": 14, "fold": (0.025, 5)},
{"z": 1.16, "r": (0.37, 0.24), "n": 14, "fold": (0.03, 5)},
{"z": 1.28, "r": (0.40, 0.26), "n": 14, "fold": (0.035, 6)},
{"z": 1.40, "r": (0.415, 0.27), "n": 14, "fold": (0.03, 6)},
{"z": 1.50, "r": (0.41, 0.265), "n": 14},
{"z": 1.57, "r": (0.35, 0.23), "n": 14},
], P["uniform"], ao=0.09)
K.plate(r, "chest_vest", K.octagon(0.39, 0.26), 0.99, 1.48, 0.93,
P["uniform_dk"], shift=(0, -0.015), ao=0.10)
K.plate(r, "chest_tie", K.octagon(0.055, 0.016), 1.18, 1.54, 0.9,
P["cloth"], shift=(0, -0.268))
for side in (-1, 1):
K.tube(r, "chest_strap_%d" % side,
[(side * 0.30, -0.08, 1.54), (side * 0.21, -0.25, 1.31),
(side * 0.14, -0.24, 1.04)], [0.042, 0.044, 0.038],
P["tan"], sides=6)
K.plate(r, "chest_pouch_%d" % side, K.octagon(0.09, 0.055),
1.13, 1.25, 0.92, P["uniform_lt"], shift=(side * 0.21, -0.24))
K.plate(r, "chest_epaulette_%d" % side, K.octagon(0.16, 0.085),
1.52, 1.565, 0.95, P["uniform_lt"], shift=(side * 0.42, 0.0))
K.plate(r, "chest_epaulette_bar_%d" % side, K.octagon(0.11, 0.012),
1.545, 1.565, 1.0, P["brass"], shift=(side * 0.42, -0.05))
K.plate(r, "chest_badge", K.octagon(0.10, 0.018), 1.32, 1.40, 1.0,
P["paper"], shift=(0.17, -0.268))
K.plate(r, "chest_badge_photo", K.octagon(0.035, 0.008), 1.335, 1.375,
1.0, P["badge_photo"], shift=(0.15, -0.279))
K.tube(r, "chest_lanyard", [(0.22, -0.16, 1.53), (0.14, -0.27, 1.34),
(0.09, -0.30, 1.21)], [0.010, 0.010, 0.008],
P["paper"], sides=5)
K.loft(r, "belt", [
{"z": 0.87, "r": (0.31, 0.21), "n": 12},
{"z": 0.96, "r": (0.32, 0.215), "n": 12},
], P["rot_dk"], ao=0.06)
K.loft(r, "chest_radio", [
{"z": 1.39, "r": (0.075, 0.06), "n": 8, "c": (0.34, 0.12)},
{"z": 1.55, "r": (0.07, 0.055), "n": 8, "c": (0.34, 0.12)},
], P["cloth"])
K.tube(r, "chest_antenna", [(0.34, 0.12, 1.55), (0.36, 0.13, 1.81)],
[0.012, 0.007], P["steel"], sides=5)
for i, pts in enumerate([
[(-0.10, -0.30, 1.42), (-0.08, -0.30, 1.24), (-0.05, -0.28, 1.05)],
[(0.20, -0.28, 1.44), (0.16, -0.29, 1.23), (0.12, -0.27, 1.03)],
]):
K.tube(r, "chest_vein_%d" % i, pts, [0.014, 0.012, 0.008],
P["rot_vein"], sides=5)
# Restrained rot stains under the uniform — the reference is a possessed
# officer, not a crystal monster.
for i, (center, scale) in enumerate([
((-0.34, 0.22, 1.42), (0.11, 0.09, 0.14)),
((0.34, 0.22, 1.40), (0.10, 0.09, 0.13)),
((0.0, 0.27, 1.24), (0.12, 0.09, 0.16)),
]):
K.blob(r, "chest_growth_%d" % i, center, scale,
P["rot"] if i != 1 else P["skin_hot"], subdiv=1, warp=0.30,
seed=70 + i, ao=0.05)
# --- arms, bent inward around the pump shotgun ---
for side in (-1, 1):
tag = "R" if side > 0 else "L"
K.blob(r, "upperarm_shoulder_%s" % tag, (side * 0.47, 0, 1.50),
(0.145, 0.16, 0.15), P["uniform_dk"], subdiv=2, seed=80 + side)
K.loft(r, "upperarm_sleeve_%s" % tag, [
{"z": 1.49, "r": (0.115, 0.115), "n": 10,
"c": (side * 0.47, -0.01)},
{"z": 1.34, "r": (0.112, 0.112), "n": 10,
"c": (side * 0.51, -0.11)},
{"z": 1.18, "r": (0.105, 0.105), "n": 10,
"c": (side * 0.55, -0.20)},
], P["uniform"], ao=0.05)
grip = wpt(-0.07, 0.0, 1.06) if side > 0 else wpt(0.34, 0.0, 1.10)
K.tube(r, "forearm_sleeve_%s" % tag,
[(side * 0.55, -0.21, 1.17),
(grip[0] * 0.55 + side * 0.25, grip[1] * 0.55 - 0.09, 1.12),
grip], [0.10, 0.085, 0.08], P["uniform_lt"], sides=9)
K.blob(r, "forearm_elbow_%s" % tag, (side * 0.55, -0.20, 1.17),
(0.095, 0.10, 0.095), P["cloth"], subdiv=1, seed=90 + side)
K.blob(r, "hand_glove_%s" % tag, grip, (0.10, 0.10, 0.10),
P["skin_hot"], subdiv=2, seed=100 + side)
for f in range(3):
K.tube(r, "hand_finger_%s_%d" % (tag, f),
[(grip[0] + (f - 1) * 0.03, grip[1] - 0.06, grip[2] - 0.01),
(grip[0] + (f - 1) * 0.035, grip[1] - 0.11, grip[2] - 0.03)],
[0.022, 0.014], P["skin_burn"], sides=5)
# --- proper pump-action shotgun, authored in its own aligned frame ---
# Butt / stock: a short, tapered wooden stock with a comb, heel and grip.
wplate(r, "weapon_stock",
[(-0.52, -0.055), (-0.30, -0.075), (-0.20, -0.06),
(-0.20, 0.06), (-0.30, 0.075), (-0.52, 0.055)],
1.01, 1.125, P["tan"], taper=0.92, ao=0.06)
wplate(r, "weapon_heel", [(-0.545, -0.058), (-0.505, -0.058),
(-0.505, 0.058), (-0.545, 0.058)],
0.995, 1.14, P["steel_dk"], ao=0.05)
K.tube(r, "weapon_comb",
[wpt(-0.50, 0, 1.135), wpt(-0.22, 0, 1.14)],
[0.018, 0.016], P["uniform_dk"], sides=6)
K.tube(r, "weapon_grip",
[wpt(-0.24, 0, 1.05), wpt(-0.29, 0, 0.94), wpt(-0.33, 0, 0.91)],
[0.045, 0.041, 0.034], P["tan"], sides=7)
# Receiver: a compact steel body with a top rail and ejection port.
wplate(r, "weapon_receiver",
[(-0.20, -0.07), (0.18, -0.07), (0.18, 0.07), (-0.20, 0.07)],
1.035, 1.165, P["steel_dk"], ao=0.05)
K.tube(r, "weapon_rail",
[wpt(-0.18, 0, 1.175), wpt(0.16, 0, 1.175)],
[0.012, 0.012], P["steel_dk"], sides=6)
wplate(r, "weapon_ejection_port",
[(-0.04, -0.045), (0.10, -0.045), (0.10, 0.045), (-0.04, 0.045)],
1.165, 1.176, P["steel"], ao=0.0)
# Trigger guard and trigger hang below the receiver.
K.tube(r, "weapon_trigger_guard",
[wpt(-0.18, 0, 1.035), wpt(-0.10, 0, 0.965),
wpt(0.0, 0, 0.965), wpt(0.06, 0, 1.035)],
[0.010, 0.010, 0.010, 0.010], P["steel_dk"], sides=6)
K.tube(r, "weapon_trigger",
[wpt(-0.07, 0, 1.03), wpt(-0.07, 0, 0.98)],
[0.008, 0.006], P["steel"], sides=5)
# Magazine tube under the barrel, then the ribbed pump forend over it.
K.tube(r, "weapon_magazine",
[wpt(0.14, 0, 1.085), wpt(0.72, 0, 1.085)],
[0.034, 0.031], P["steel"], sides=8)
wplate(r, "weapon_pump",
[(0.20, -0.065), (0.48, -0.065), (0.48, 0.065), (0.20, 0.065)],
1.055, 1.14, P["uniform_dk"], ao=0.05)
for i, lx in enumerate((0.25, 0.32, 0.39, 0.46)):
K.tube(r, "weapon_pump_ridge_%d" % i,
[wpt(lx, -0.065, 1.145), wpt(lx, 0.065, 1.145)],
[0.008, 0.008], P["steel_dk"], sides=5)
# Barrel, front bead and a short muzzle collar.
K.tube(r, "weapon_barrel",
[wpt(0.16, 0, 1.165), wpt(0.48, 0, 1.165), wpt(0.76, 0, 1.165)],
[0.044, 0.041, 0.038], P["steel_dk"], sides=8)
K.tube(r, "weapon_muzzle",
[wpt(0.73, 0, 1.165), wpt(0.79, 0, 1.165)],
[0.038, 0.038], P["steel"], sides=8)
K.crystal(r, "weapon_bead", wpt(0.70, 0, 1.20), 0.020,
P["brass"], sides=4, seed=6)
# --- legs: heavy boots planted apart ---
for side in (-1, 1):
tag = "R" if side > 0 else "L"
x = side * 0.21
K.loft(r, "thigh_trouser_%s" % tag, [
{"z": 0.88, "r": (0.155, 0.16), "n": 10, "c": (x, 0)},
{"z": 0.72, "r": (0.15, 0.155), "n": 10, "c": (x + side * 0.01, 0)},
{"z": 0.54, "r": (0.135, 0.14), "n": 10, "c": (x + side * 0.02, 0)},
], P["uniform"], ao=0.08)
K.plate(r, "thigh_knee_%s" % tag, K.octagon(0.135, 0.11), 0.49, 0.58,
0.90, P["cloth"], shift=(x + side * 0.02, -0.10))
K.loft(r, "shin_trouser_%s" % tag, [
{"z": 0.54, "r": (0.125, 0.13), "n": 10, "c": (x + side * 0.02, 0)},
{"z": 0.36, "r": (0.115, 0.12), "n": 10, "c": (x + side * 0.025, 0)},
{"z": 0.16, "r": (0.10, 0.105), "n": 10, "c": (x + side * 0.03, 0)},
], P["uniform"], ao=0.08)
K.loft(r, "shin_boot_%s" % tag, [
{"z": 0.015, "r": (0.155, 0.225), "n": 10,
"c": (x + side * 0.03, -0.075)},
{"z": 0.10, "r": (0.145, 0.20), "n": 10,
"c": (x + side * 0.03, -0.055)},
{"z": 0.20, "r": (0.125, 0.145), "n": 10,
"c": (x + side * 0.03, 0)},
], P["rot_dk"], ao=0.06)
K.plate(r, "shin_sole_%s" % tag, K.octagon(0.16, 0.23), 0.0, 0.025,
0.98, P["cloth"], shift=(x + side * 0.03, -0.075))
K.tube(r, "thigh_strap_%s" % tag,
[(x - side * 0.10, -0.12, 0.74), (x, -0.17, 0.72),
(x + side * 0.10, -0.10, 0.70)], [0.026, 0.028, 0.024],
P["tan"], sides=6)
# Blood-slicked right hand: a small, readable detail at boss scale.
K.blob(r, "hand_blood", wpt(-0.07, -0.06, 1.05), (0.075, 0.06, 0.07),
P["badge_photo"], subdiv=1, seed=130)
# Scale the authored actor to triple size, geometry and rig pivots together.
for obj in r.children:
if obj.type == "MESH":
for v in obj.data.vertices:
v.co *= S
obj.data.update()
return r
# ------------------------------------------------------------------- rigging
BONES = [
("root", (0, 0, 0.0), (0, 0, 0.20), None),
("hips", (0, 0, 0.90), (0, 0, 1.03), "root"),
("spine", (0, 0, 1.03), (0, 0, 1.27), "hips"),
("chest", (0, 0, 1.27), (0, 0, 1.55), "spine"),
("neck", (0, 0, 1.55), (0, 0, 1.66), "chest"),
("head", (0, 0, 1.66), (0, 0, 2.04), "neck"),
# Stock -> muzzle; the IK pass pins both wrists to this bone.
("weapon", wpt(-0.52, 0, 1.07), wpt(0.79, 0, 1.165), "chest"),
]
BONES += [
("upperarm.R", (0.46, -0.02, 1.52), (0.55, -0.21, 1.17), "chest"),
("forearm.R", (0.55, -0.21, 1.17), wpt(-0.07, 0, 1.06), "upperarm.R"),
("hand.R", wpt(-0.07, 0, 1.06), wpt(0.01, -0.02, 1.06), "forearm.R"),
("upperarm.L", (-0.46, -0.02, 1.52), (-0.55, -0.15, 1.15), "chest"),
("forearm.L", (-0.55, -0.15, 1.15), wpt(0.34, 0, 1.10), "upperarm.L"),
("hand.L", wpt(0.34, 0, 1.10), wpt(0.42, -0.02, 1.10), "forearm.L"),
("thigh.R", (0.21, 0, 0.88), (0.22, 0, 0.51), "hips"),
("shin.R", (0.22, 0, 0.51), (0.24, 0, 0.13), "thigh.R"),
("foot.R", (0.24, 0, 0.13), (0.24, -0.22, 0.04), "shin.R"),
("thigh.L", (-0.21, 0, 0.88), (-0.22, 0, 0.51), "hips"),
("shin.L", (-0.22, 0, 0.51), (-0.24, 0, 0.13), "thigh.L"),
("foot.L", (-0.24, 0, 0.13), (-0.24, -0.22, 0.04), "shin.L"),
]
GRIP_REST = {
"R": Vector(wpt(-0.07, 0.0, 1.06)), # trigger hand
"L": Vector(wpt(0.34, 0.0, 1.10)), # pump hand
}
def build_rig():
data = bpy.data.armatures.new("WardenRig")
arm = bpy.data.objects.new("WardenRig", data)
bpy.context.scene.collection.objects.link(arm)
bpy.ops.object.select_all(action="DESELECT")
arm.select_set(True)
bpy.context.view_layer.objects.active = arm
bpy.ops.object.mode_set(mode="EDIT")
for name, head, tail, parent in BONES:
b = data.edit_bones.new(name)
b.head = Vector(head) * S
b.tail = Vector(tail) * S
if parent:
b.parent = data.edit_bones[parent]
bpy.ops.object.mode_set(mode="OBJECT")
return arm
def side_of(name, obj):
m = re.search(r"[._-](R|L)(?=_|$)", name)
if m:
return m.group(1)
xs = [v.co.x for v in obj.data.vertices]
return "R" if (sum(xs) / max(len(xs), 1)) > 0 else "L"
def group_for(name, obj):
n = name.lower()
s = side_of(n, obj)
if any(k in n for k in ("head", "face", "skull", "jaw", "brow", "nose",
"mouth", "eye", "cheek", "ear", "smoke")):
return "head" if "smoke_tendril" not in n else "chest"
if "neck" in n:
return "neck"
if any(k in n for k in ("weapon", "receiver", "barrel", "stock", "pump",
"trigger", "muzzle")):
return "weapon"
if any(k in n for k in ("upperarm", "shoulder", "epaulette")):
return "upperarm." + s
if any(k in n for k in ("forearm", "elbow")):
return "forearm." + s
if any(k in n for k in ("hand", "finger", "thumb", "glove", "blood")):
return "hand." + s
if any(k in n for k in ("thigh", "knee", "holster")):
return "thigh." + s
if any(k in n for k in ("shin", "boot", "sole", "lace")):
return "shin." + s
zs = [v.co.z for v in obj.data.vertices]
z = sum(zs) / max(len(zs), 1)
if z > 1.62 * S:
return "head"
if z > 1.10 * S:
return "chest"
if z > 0.60 * S:
return "hips"
return "root"
def assign_groups(root):
for obj in list(root.children):
if obj.type != "MESH":
continue
primary = group_for(obj.name, obj)
groups = {primary: []}
side = s[0] if (s := re.search(r"[._-](R|L)(?=_|$)", obj.name.lower())) else None
for v in obj.data.vertices:
z = v.co.z / S # thresholds stay in authored (human) units
if side and primary == "upperarm." + side and 1.10 < z < 1.22:
groups[primary].append((v.index, (1.22 - z) / 0.12))
groups.setdefault("forearm." + side, []).append(
(v.index, (z - 1.10) / 0.12))
elif side and primary == "forearm." + side and 1.10 < z < 1.22:
groups[primary].append((v.index, (z - 1.10) / 0.12))
groups.setdefault("upperarm." + side, []).append(
(v.index, (1.22 - z) / 0.12))
elif side and primary == "thigh." + side and 0.45 < z < 0.57:
groups[primary].append((v.index, (z - 0.45) / 0.12))
groups.setdefault("shin." + side, []).append(
(v.index, (0.57 - z) / 0.12))
elif side and primary == "shin." + side and 0.45 < z < 0.57:
groups[primary].append((v.index, (0.57 - z) / 0.12))
groups.setdefault("thigh." + side, []).append(
(v.index, (z - 0.45) / 0.12))
else:
groups[primary].append((v.index, 1.0))
for bone, entries in groups.items():
vg = obj.vertex_groups.get(bone) or obj.vertex_groups.new(name=bone)
for index, weight in entries:
if weight > 1e-4:
vg.add([index], min(1.0, weight), "REPLACE")
# ----------------------------------------------------------------- animation
def reset_pose(bones):
for pb in bones:
pb.rotation_mode = "XYZ"
pb.rotation_euler = (0.0, 0.0, 0.0)
pb.location = (0.0, 0.0, 0.0)
def aim_bone(pb, parent_pose, head, tail):
direction = (tail - head).normalized()
up = Vector((0.0, 0.0, 1.0))
if abs(direction.dot(up)) > 0.95:
up = Vector((0.0, 1.0, 0.0))
right = direction.cross(up).normalized()
up2 = right.cross(direction).normalized()
desired = Matrix((right, direction, up2)).transposed().to_4x4()
desired.translation = head
rest_parent = pb.parent.bone.matrix_local if pb.parent else Matrix.Identity(4)
basis = parent_pose @ rest_parent.inverted() @ pb.bone.matrix_local
pb.matrix_basis = basis.inverted() @ desired
return desired
def solve_arm(pb, side, target, pole, parent_pose, hand_dir):
upper = pb["upperarm." + side]
lower = pb["forearm." + side]
hand = pb["hand." + side]
shoulder = upper.head.copy()
l1 = (upper.bone.tail_local - upper.bone.head_local).length
l2 = (lower.bone.tail_local - lower.bone.head_local).length
delta = target - shoulder
reach = max(abs(l1 - l2) + 1e-3, min(delta.length, l1 + l2 - 1e-3))
direction = delta.normalized()
along = (l1 * l1 - l2 * l2 + reach * reach) / (2.0 * reach)
height = math.sqrt(max(0.0, l1 * l1 - along * along))
bend = pole - direction * pole.dot(direction)
if bend.length < 1e-5:
bend = Vector((1.0 if side == "R" else -1.0, 0.0, 0.0))
bend -= direction * bend.dot(direction)
bend.normalize()
elbow = shoulder + direction * along + bend * height
upper_pose = aim_bone(upper, parent_pose, shoulder, elbow)
lower_pose = aim_bone(lower, upper_pose, elbow, target)
aim_bone(hand, lower_pose, target, target + hand_dir)
def grip_weapon(pb, recoil=0.0):
"""Keep both hands on the shotgun while the chest leans or the gun kicks."""
bpy.context.view_layer.update()
weapon = pb["weapon"]
if recoil:
pivot = pb["chest"].head.copy()
around_chest = (Matrix.Translation(pivot)
@ Matrix.Rotation(-0.26 * recoil, 4, "X")
@ Matrix.Translation(-pivot))
weapon.matrix = around_chest @ weapon.matrix.copy()
bpy.context.view_layer.update()
skin = weapon.matrix @ weapon.bone.matrix_local.inverted()
forward = (weapon.tail - weapon.head).normalized()
hand_dir = (forward - Vector((0.0, 0.0, 0.55))).normalized()
chest_pose = pb["chest"].matrix.copy()
for side, behind in (("R", 0.05), ("L", 0.07)):
target = skin @ (GRIP_REST[side] * S) - forward * behind
pole = Vector((1.2 if side == "R" else -1.2, 0.3, -2.0))
solve_arm(pb, side, target, pole, chest_pose, hand_dir)
def pose_idle(pb, t):
breath = math.sin(t * 2.0 * math.pi)
pb["chest"].rotation_euler.x = 0.02 + 0.022 * breath
pb["head"].rotation_euler.z = 0.035 * math.sin(t * math.pi)
pb["head"].rotation_euler.x = -0.02 * breath
grip_weapon(pb)
def pose_walk(pb, t):
phase = t * 2.0 * math.pi
s = math.sin(phase)
pb["root"].location.z = 0.05 * S * abs(math.sin(2.0 * phase))
pb["chest"].rotation_euler.x = 0.16
pb["head"].rotation_euler.x = -0.08
pb["thigh.R"].rotation_euler.x = 0.50 * s
pb["thigh.L"].rotation_euler.x = -0.50 * s
pb["shin.R"].rotation_euler.x = 0.42 * max(0.0, -s)
pb["shin.L"].rotation_euler.x = 0.42 * max(0.0, s)
grip_weapon(pb)
def pose_attack(pb, t):
# Raise the shotgun, drive the stock into the shoulder, then recover.
lift = math.sin(min(1.0, t) * math.pi)
kick = math.exp(-9.0 * t)
pb["chest"].rotation_euler.x = -0.10 * lift + 0.09 * kick
pb["head"].rotation_euler.x = -0.10 * lift
grip_weapon(pb, recoil=kick)
def pose_stagger(pb, t):
fade = 1.0 - t
pb["chest"].rotation_euler.x = -0.34 * fade
pb["head"].rotation_euler.x = -0.28 * fade
pb["root"].location.z = -0.04 * S * fade
grip_weapon(pb)
def pose_death(pb, t):
fall = min(1.0, t * 1.25)
pb["root"].location.z = -0.55 * S * fall
pb["chest"].rotation_euler.x = 0.75 * fall
pb["head"].rotation_euler.x = 0.40 * fall
grip_weapon(pb)
def make_actions(arm):
specs = [
("Idle", 1, 48, pose_idle),
("Walk", 1, 36, pose_walk),
("Attack", 1, 24, pose_attack),
("Stagger", 1, 20, pose_stagger),
("Death", 1, 32, pose_death),
]
arm.animation_data_create()
made = []
for name, start, end, fn in specs:
act = bpy.data.actions.new(name)
act.use_fake_user = True
act.use_frame_range = True
act.frame_start, act.frame_end = start, end
arm.animation_data.action = act
for frame in range(start, end + 1):
reset_pose(arm.pose.bones)
fn(arm.pose.bones, (frame - start) / max(1, end - start))
for pb in arm.pose.bones:
pb.keyframe_insert(data_path="rotation_euler", frame=frame,
group=name)
if pb.name in ("root", "weapon", "upperarm.R", "upperarm.L",
"forearm.R", "forearm.L", "hand.R", "hand.L"):
pb.keyframe_insert(data_path="location", frame=frame,
group=name)
made.append((name, act))
print("[anim] %-8s frames %d-%d" % (name, start, end))
arm.animation_data.action = made[0][1]
return dict(made)
# ------------------------------------------------------------------- build it
root = build_warden()
arm = build_rig()
assign_groups(root)
mesh = K.merge_actor(root, "hiss_boss")
tris = K.triangle_count(root)
print("[budget] hiss_boss %d tris (cap 14000) %s"
% (tris, "OK" if tris <= 14000 else "OVER"))
assert tris <= 14000, "hiss boss over triangle budget"
mod = mesh.modifiers.new("WardenSkin", "ARMATURE")
mod.object = arm
mesh.parent = arm
actions = make_actions(arm)
out = os.path.join(MODEL_DIR, "hiss_boss.glb")
bpy.ops.object.select_all(action="DESELECT")
arm.select_set(True)
mesh.select_set(True)
bpy.context.view_layer.objects.active = arm
bpy.ops.export_scene.gltf(
filepath=out,
export_format="GLB",
use_selection=True,
export_apply=False,
export_yup=True,
export_materials="EXPORT",
export_skins=True,
export_animations=True,
export_animation_mode="ACTIONS",
export_bake_animation=True,
export_frame_range=True,
export_cameras=False,
export_lights=False,
export_extras=False,
)
print("[export] %s %d bytes, %d bones, %d actions"
% (out, os.path.getsize(out), len(BONES), len(actions)))
# Showcase: the rig in its idle pose, full-body and close-up renders.
scene = bpy.context.scene
arm.animation_data.action = actions["Idle"]
scene.frame_set(12)
world = bpy.data.worlds.new("WardenWorld")
scene.world = world
world.use_nodes = True
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
bg.inputs["Color"].default_value = (*K.rgb("#0a0b0e"), 1.0)
bg.inputs["Strength"].default_value = 0.75
def area(name, loc, color, power, size):
data = bpy.data.lights.new(name, "AREA")
data.energy = power
data.shape = "DISK"
data.size = size
data.color = K.rgb(color)
obj = bpy.data.objects.new(name, data)
bpy.context.scene.collection.objects.link(obj)
obj.location = loc
direction = Vector((0.0, 0.0, 2.8)) - Vector(loc)
obj.rotation_euler = direction.to_track_quat("-Z", "Y").to_euler()
return obj
area("Key", (-8, -12, 14), "#eef2ff", 5200, 12)
area("HissFill", (10, -2, 7), "#ff3b46", 3600, 10)
area("Rim", (0, 10, 10), "#4ec9b0", 2800, 10)
cam_data = bpy.data.cameras.new("WardenCam")
cam = bpy.data.objects.new("WardenCam", cam_data)
bpy.context.scene.collection.objects.link(cam)
cam.location = (0.0, -22.0, 8.0)
cam.rotation_euler = (Vector((0.0, 0.0, 2.9)) - cam.location).to_track_quat("-Z", "Y").to_euler()
cam_data.lens = 40
scene.camera = cam
engines = [i.identifier for i in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
scene.render.engine = ("BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines
else ("BLENDER_EEVEE" if "BLENDER_EEVEE" in engines else engines[0]))
scene.render.resolution_x = 900
scene.render.resolution_y = 1000
scene.render.resolution_percentage = 100
scene.render.image_settings.file_format = "PNG"
scene.render.filepath = os.path.join(CONCEPT_DIR, "hiss_boss.png")
try:
scene.eevee.taa_render_samples = 48
except Exception:
pass
bpy.ops.render.render(write_still=True)
print("[render] %s" % scene.render.filepath)
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(BLEND_DIR, "fbc_hiss_boss.blend"))
print("[done] hiss_boss: 3x agent, %d tris, %d bones, %d clips"
% (tris, len(BONES), len(actions)))