diff --git a/README.md b/README.md index c3c85de..83bb2b9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ that roll offers as real-time HUD entries per GAME_DESIGN.md §2.2 (no picking the run is never paused), 3 enemy archetypes, corruption clock, death screen. OoP rituals, scene-wide buffs/debuffs and world objects are in and wired into the HUD. The look is a brutalist 3D diorama with **sculpted low-poly -Blender actors** (no 2D standees or box kits), procedural walk/stagger rigs, +Blender actors** (no 2D standees or box kits). The player is a dedicated +reference-based, Blender-rigged FBC agent (yellow helmet, glowing respirator, +sage coveralls, radio, rifle with a red tip) with real Idle/Run/Dash/Fire/ +Stagger actions; the horde uses procedural walk/stagger rigs, hit/kill sparks and corruption-keyed post FX with half-res bloom. A single tileable 2K concrete PBR set (generated by `tools/blender/build_materials.py`) is shared by floor, curbs and pillars via one triplanar shader and one merged mesh. @@ -78,7 +81,7 @@ raylib 6.2 is fetched automatically by CMake (FetchContent). Needs a C++23 compi `process_concrete_maps.py` — CGTrader concrete source and the reproducible 2K bake/post-process used by floor/walls/pillars - `tools/blender/` — procedural diorama + actor builders (`actor_kit.py` loft/sweep/blob/crystal helpers) and render scripts -- `assets/models/` — game-ready GLB actors (guard, enemies, cyan resonance point crystal), `props/` OoP set dressing and the S16 open-room kit (`tools/blender/build_room_props.py`) +- `assets/models/` — game-ready GLB actors (`agent.glb` is the rigged/animated player from `tools/blender/build_agent.py`, plus enemies and cyan resonance point crystal), `props/` OoP set dressing and the S16 open-room kit (`tools/blender/build_room_props.py`) - `assets/textures/concrete/` — shared seamless albedo/normal/roughness maps - `assets/textures/actor/actor_ramp.png` — Blender-generated stylised lighting ramp - `assets/blender/fbc_corruption_wave.blend` — reusable SDF wave reference scene diff --git a/assets/blender/fbc_agent.blend b/assets/blender/fbc_agent.blend new file mode 100644 index 0000000..314568a Binary files /dev/null and b/assets/blender/fbc_agent.blend differ diff --git a/assets/models/agent.glb b/assets/models/agent.glb new file mode 100644 index 0000000..0e11adb Binary files /dev/null and b/assets/models/agent.glb differ diff --git a/docs/ART_DIRECTION.md b/docs/ART_DIRECTION.md index e5fb7b2..297a249 100644 --- a/docs/ART_DIRECTION.md +++ b/docs/ART_DIRECTION.md @@ -11,11 +11,13 @@ units are little free-standing puppets rather than printed cards: wall signage). Brutalism is literally parametric boxes, so procedural meshes get ~80% of the look for ~20% of the cost. - Units are **sculpted low-poly puppets** — lofted bodies, swept limbs and - deformed organic masses rather than a cube kit (guard ~5.7k triangles, enemies - 1.4–2.9k, point crystal ~60), with readable facets, ID-badge details, Hiss crystal - growths and a little base ring. Thematically the same bureaucrat-moving-case- - files fantasy, but they occupy real depth: they turn to face the player, bob - when floating and are lit by the House's fluorescent key. + deformed organic masses rather than a cube kit (the S17 player agent ~6.0k + triangles with a real 19-bone rig and five baked actions; enemies 1.4–2.9k on + shader rigs, point crystal ~60), with readable facets, ID-badge details, Hiss + crystal growths and a little base ring. The player follows the reference art: + yellow helmet, orange-lit gas mask, sage coveralls, tactical harness, radio and + a boxy Service Weapon carried across the chest with red rounds. They occupy real depth: they turn to face the + player, bob when floating and are lit by the House's fluorescent key. - **Actors are authored in Blender** (`tools/blender/build_enemies.py`), exported as GLB to `assets/models/` and lit in-engine by `assets/shaders/actor.{vs,fs}`. Walk/stagger/blob/crystal motion is done in the vertex shader from local diff --git a/docs/ENV_ENHANCEMENT.md b/docs/ENV_ENHANCEMENT.md index ca26f97..b15833c 100644 --- a/docs/ENV_ENHANCEMENT.md +++ b/docs/ENV_ENHANCEMENT.md @@ -29,6 +29,7 @@ Legend: **[B]** Blender scene (`tools/blender/build_scene.py`) · **[G]** game | S14 | Actor animation & sparks | Shader-side rigs (walk + stagger, blob squash, crystal shimmer) for guard, Hiss units, Mold and shards; idle motion for OoP props; pooled camera-facing sparks | **DONE** [G] | | S15 | Polish pass | Desaturated Mold, outlined Hiss units, clamped camera + dressed outer service band, dimmed glare, crisp HUD, floor decals, carpet seams, gentle contrast grade | **DONE** [G][B] | | S16 | Bigger floor + open-plan room | 260 × 260 m arena with shared pillar anchors, red approach runners, eight-piece Blender furniture kit (desks, meeting table, chairs, computers, plants, sofas, lamps, partitions) dressed into a Control-style research room, live camera dev slider | **DONE** [B][G] | +| S17 | Rigged reference agent | ~6k-tri player model built from the Control reference art (yellow helmet, glowing respirator, sage coveralls, harness, radio, boxy angled rifle with red rounds), 19-bone Blender armature, Idle/Run/Dash/Fire/Stagger actions, skinned GLB playback in game | **DONE** [B][G] | ## S0 — Light, surface & post pass [B][R] @@ -394,6 +395,23 @@ markers / decals rather than Control's corruption creeping out of a body. tactical distance; desk footprint scaled 1.35× after a human/table proportion pass.* +## S17 — Rigged reference agent [B][G] + +- [x] **Reference build** — `build_agent.py` sculpts a 5972-tri agent (vs. + 2898-tri Brute / ~2k others) with a worn yellow helmet, gas mask with a + bright orange visor and filters, pale sage coveralls, harness pouches, + shoulder patch, radio and a boxy Service Weapon carried across the chest + with flat red rounds in the muzzle brake. + Painted `COLOR_0`, one merged mesh, feet at origin, facing -Y in Blender. +- [x] **Real rig** — 19-bone armature (root/hips/spine/chest/neck/head/weapon, + arm and leg chains) with painted hard weights and small joint blends; + baked Idle (48f), Run (36f), Dash (18f), Fire (16f), Stagger (20f) actions. +- [x] **Integration** — `assets/models/agent.glb` is skinned; `ModelBank` + loads/validates the clips, `Presenter` selects Idle/Run/Dash/Stagger from + sim state, and raylib CPU skinning feeds the existing actor shader. +- *Accept: 1080p close-ups and bot captures show the reference silhouette and + two distinct run frames; no shader changes needed for the horde.* + ## How to run ```python @@ -405,6 +423,7 @@ exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_lut.py").read() exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_props.py").read()) exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_wave.py").read()) exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_room_props.py").read()) +exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_agent.py").read()) exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/render_shots.py").read()) ``` @@ -415,6 +434,9 @@ clipping < 0.5%, red-dominant 15–25%. ## Status log +- 2026-11-23 (S17): replaced the procedural-only guard with a reference-based + `agent.glb`: 6.2k tris, 19-bone armature, five baked actions, CPU-skinned by + raylib through the existing actor shader. Verified with close and bot captures. - 2026-11-23 (S16 polish): critical-lens pass — default camera lowered to 16 m / 15 m forward / fovy 55 for readable actors and furniture, 16 mid-field pillars plus survey/cable lines, scuffs, papers and light pools across the diff --git a/docs/TECHNICAL.md b/docs/TECHNICAL.md index 1ccb919..64ae0d3 100644 --- a/docs/TECHNICAL.md +++ b/docs/TECHNICAL.md @@ -7,9 +7,13 @@ - **raylib 6.2**, pinned via CMake `FetchContent` (`GIT_TAG 6.2`, link target `raylib`). 6.2 is the current release (Oct 2026) and fixed CMake-4.x build issues; builds GLFW from source (X11/GL dev headers required). raylib 6.x adds the Image/Draw API - alignment (procedural textures) and skeletal model animation (`UpdateModelAnimation`, - GLTF/IQM/M3D) — an upgrade path for animated bosses; current actors use - shader-side procedural rigs instead, which keep one draw call per actor. + alignment (procedural textures) and skeletal model animation (`UpdateModelAnimation`, + GLTF/IQM/M3D). S17 uses that path for the single player agent: `agent.glb` + carries a 19-bone armature and five baked actions; `ModelBank` advances the + clip with `GetFrameTime() * 60` and raylib CPU-skins it into the existing + `actor.vs` (the shader deliberately has no bone attributes, so raylib's CPU + fallback runs). The horde keeps shader-side procedural rigs, which stay one + draw call per actor. - No other third-party deps until they earn their place. Data lives in C++ tables (JSON only when content volume demands it). @@ -74,9 +78,10 @@ src/ - **One merged triplanar concrete mesh** (`concrete.*`) for floor, curbs, pillars and door frame, sharing one tileable 2K PBR set from `build_materials.py`. - **Sculpted GLB actors** (`models.*`, `assets/models/`) lit by a gradient-ramp - shader with faction rims and a procedural limb rig (`uRigMode` 1 humanoid, - 2 blob, 3 crystal) — no skeletons, no extra draw calls. Hiss actors also get a - cheap expanded-backface ink outline. + shader with faction rims. The horde uses a procedural limb rig (`uRigMode` + 1 humanoid, 2 blob, 3 crystal) — no skeletons, no extra draw calls. The single + player agent instead has a Blender skeleton and baked actions, CPU-skinned by + raylib. Hiss actors and the agent get a cheap expanded-backface ink outline. - **Blob shadows** (flattened cylinders) — no shadow maps in raylib core; they ground the puppets without cost. - **Sparks / glows / world objects** are camera-facing billboards using one diff --git a/docs/concept/agent_detail.png b/docs/concept/agent_detail.png new file mode 100644 index 0000000..a126e1b Binary files /dev/null and b/docs/concept/agent_detail.png differ diff --git a/docs/concept/agent_reference.png b/docs/concept/agent_reference.png new file mode 100644 index 0000000..9ee228f Binary files /dev/null and b/docs/concept/agent_reference.png differ diff --git a/src/render/models.cpp b/src/render/models.cpp index a7f4f7a..457f936 100644 --- a/src/render/models.cpp +++ b/src/render/models.cpp @@ -4,6 +4,7 @@ #include #include +#include #include namespace { @@ -27,7 +28,9 @@ struct Rig { Rig rig_for(ActorModel id) { switch (id) { - case ActorModel::Guard: return {0.90f, 1.45f, 0.18f, 0.43f, 1.0f, 1.0f}; + // The S17 agent is skinned in Blender; the old shader rig would double + // deform it, so its procedural mode is off. + case ActorModel::Guard: return {0.90f, 1.45f, 0.18f, 0.43f, 1.0f, 0.0f}; case ActorModel::HissStaff: return {0.60f, 1.40f, 0.20f, 0.38f, 0.85f, 1.0f}; case ActorModel::HissBrute: return {1.05f, 2.10f, 0.40f, 0.95f, 1.0f, 1.0f}; case ActorModel::HissGhost: return {0.60f, 1.35f, 0.22f, 0.36f, 0.9f, 1.0f}; @@ -111,6 +114,17 @@ void ModelBank::init() { } entries_[i].model = model; entries_[i].loaded = true; + if (id == ActorModel::Guard && model.skeleton.boneCount > 0) { + Entry& e = entries_[i]; + e.animations = LoadModelAnimations(path.c_str(), &e.animation_count); + int valid = 0; + for (int a = 0; a < e.animation_count; ++a) { + if (IsModelAnimationValid(e.model, e.animations[a])) ++valid; + } + TraceLog(LOG_INFO, + "ACTOR: skinned agent — %d bones, %d animations (%d valid)", + model.skeleton.boneCount, e.animation_count, valid); + } TraceLog(LOG_INFO, "ACTOR: %s (%d meshes, %d materials)", file_name(id), model.meshCount, model.materialCount); } @@ -119,6 +133,11 @@ void ModelBank::init() { void ModelBank::shutdown() { for (Entry& e : entries_) { + if (e.animations != nullptr && e.animation_count > 0) + UnloadModelAnimations(e.animations, e.animation_count); + e.animations = nullptr; + e.animation_count = 0; + e.current_animation = -1; if (e.loaded) UnloadModel(e.model); e.loaded = false; } @@ -195,6 +214,27 @@ void ModelBank::draw(ActorModel id, Vector3 pos, float yaw, float scale, Vector3{scale, scale, scale}, tint); } +void ModelBank::update_animation(ActorModel id, const char* name, float dt) { + const int index = static_cast(id); + if (index < 0 || index >= static_cast(ActorModel::Count)) return; + Entry& e = entries_[index]; + if (!e.loaded || e.animations == nullptr || e.animation_count <= 0) return; + + int found = -1; + for (int a = 0; a < e.animation_count; ++a) { + if (std::strcmp(e.animations[a].name, name) == 0) { found = a; break; } + } + if (found < 0) return; + if (found != e.current_animation) { + e.current_animation = found; + e.animation_clock = 0.0f; + } + e.animation_clock += dt; + const float frame = std::fmod(e.animation_clock * 60.0f, + static_cast(e.animations[found].keyframeCount)); + UpdateModelAnimation(e.model, e.animations[found], frame); +} + float ModelBank::height(ActorModel id) { switch (id) { case ActorModel::Guard: return 1.9f; @@ -225,7 +265,7 @@ float ModelBank::height(ActorModel id) { const char* ModelBank::file_name(ActorModel id) { switch (id) { - case ActorModel::Guard: return "assets/models/guard.glb"; + case ActorModel::Guard: return "assets/models/agent.glb"; case ActorModel::HissStaff: return "assets/models/hiss_staff.glb"; case ActorModel::MoldSpore: return "assets/models/mold_spore.glb"; case ActorModel::HissBrute: return "assets/models/hiss_brute.glb"; diff --git a/src/render/models.hpp b/src/render/models.hpp index dc5da4a..dba9bdd 100644 --- a/src/render/models.hpp +++ b/src/render/models.hpp @@ -29,12 +29,19 @@ public: float flash = 0.0f, bool outline = false, float walk = 0.0f, float stagger = 0.0f, float phase = 0.0f, float hiss = 0.0f); + // Plays a named GLB action on a skinned model (dt in seconds, 60 fps clips). + void update_animation(ActorModel id, const char* name, float dt); + // Per-model visual height, used for health bars / floating labels. static float height(ActorModel id); private: struct Entry { Model model{}; + ModelAnimation* animations = nullptr; + int animation_count = 0; + int current_animation = -1; + float animation_clock = 0.0f; bool loaded = false; }; diff --git a/src/render/presenter.cpp b/src/render/presenter.cpp index b1c1c7b..e1a047b 100644 --- a/src/render/presenter.cpp +++ b/src/render/presenter.cpp @@ -638,10 +638,16 @@ void Presenter::draw_scene(Game& game) { const Vec2 moved = p - last_player_pos_; if (length_sq(moved) > 1e-5f) player_yaw_ = std::atan2(moved.x, moved.y); last_player_pos_ = p; - const float guard_bob = std::sin(anim_time_ * 6.0f) * 0.02f; const float player_walk = std::min(1.0f, length(moved) * 14.0f); const float player_flash = actor_flash(game.player.hit_flash, 4.0f); - models_.draw(ActorModel::Guard, {p.x, guard_bob, p.y}, player_yaw_, 1.0f, + // The Blender agent carries its own root bob; the old sine bob would + // double up on top of the skeletal Run/Idle clips. + const char* agent_clip = "Idle"; + if (game.player.dash_timer > 0.0f) agent_clip = "Dash"; + else if (player_flash > 0.05f) agent_clip = "Stagger"; + else if (player_walk > 0.08f) agent_clip = "Run"; + models_.update_animation(ActorModel::Guard, agent_clip, GetFrameTime()); + models_.draw(ActorModel::Guard, {p.x, 0.0f, p.y}, player_yaw_, 1.0f, WHITE, player_flash, true, player_walk, player_flash, anim_time_); diff --git a/tools/blender/build_agent.py b/tools/blender/build_agent.py new file mode 100644 index 0000000..e05d037 --- /dev/null +++ b/tools/blender/build_agent.py @@ -0,0 +1,606 @@ +# tools/blender/build_agent.py +# FBC: NIGHT SHIFT — S17: reference-based, skinned FBC agent (the player). +# +# Run inside Blender 5.x: +# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_agent.py").read()) +# +# Builds a ~10k-tri agent from the Control reference (yellow helmet, glowing +# respirator mask, pale coveralls, tactical harness, radio, rifle with a +# red-tipped barrel), rigs it with an 18-bone armature, authors Idle / Run / +# Dash / Fire / Stagger actions and exports one skinned GLB with animations. +# CPU skinning in raylib needs no bone attributes in actor.vs (see TECHNICAL.md). + +import math +import os +import re +import sys + +import bpy +from mathutils import Euler, 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() +P = K.PALETTE +P.update({ + "coverall": "#6f7f6d", "coverall_dk": "#566452", "coverall_sh": "#414c3e", + "helmet": "#c8a312", "helmet_dk": "#91740c", "helmet_lt": "#d8b729", + "mask": "#242724", "mask_lt": "#3b413b", "glass": "#162020", + "filter": "#2c302e", "black": "#151719", "leather": "#1d201e", + "patch": "#d8d6c8", "visor": "#ff3a06", "visor_hot": "#ffc061", + "board": "#f5c518", "hiss_red": "#c1121f", +}) + + +def panel(root, name, w, h, t, x, y, z, value, rot=(math.pi / 2, 0, 0), ao=0.06): + outline = [(-w / 2, -h / 2), (w / 2, -h / 2), + (w / 2, h / 2), (-w / 2, h / 2)] + obj = K.plate(root, name, outline, 0.0, t, 1.0, value, ao=ao) + mat = Euler(rot).to_matrix() + shift = Vector((x, y, z)) + for v in obj.data.vertices: + v.co = shift + mat @ v.co + obj.data.update() + return obj + + +# ------------------------------------------------------------------- geometry +def build_agent(): + r = K.new_actor("Agent") + + # Head: gas mask under a worn FBC helmet. + K.blob(r, "head", (0, 0, 1.68), (0.195, 0.185, 0.225), P["mask"], + subdiv=3, warp=0.07, seed=11, ao=0.04) + panel(r, "mask_face", 0.31, 0.30, 0.035, 0.0, -0.183, 1.67, + P["mask_lt"]) + panel(r, "visor_band", 0.315, 0.16, 0.022, 0.0, -0.252, 1.735, + P["visor"], ao=0.0) + panel(r, "visor_hot", 0.275, 0.055, 0.01, 0.0, -0.266, 1.745, + P["visor_hot"], ao=0.0) + panel(r, "visor_glow", 0.20, 0.05, 0.008, 0.0, -0.268, 1.65, + P["visor"], ao=0.0) + for side in (-1, 1): + lens = K.ring(r, "lens_%d" % side, (0.0, 0.0, 0.0), 0.058, 0.014, + P["steel_dk"], segments=14) + for v in lens.data.vertices: + v.co = Euler((math.pi / 2, 0, 0)).to_matrix() @ v.co + Vector( + (side * 0.112, -0.267, 1.665)) + lens.data.update() + glass = K.plate(r, "glass_%d" % side, K.octagon(0.05, 0.05), + 0.0, 0.012, 1.0, P["glass"], ao=0.0) + for v in glass.data.vertices: + v.co = Euler((math.pi / 2, 0, 0)).to_matrix() @ v.co + Vector( + (side * 0.112, -0.279, 1.665)) + glass.data.update() + K.blob(r, "filter_%d" % side, (side * 0.095, -0.245, 1.57), + (0.055, 0.05, 0.055), P["filter"], subdiv=2, seed=21 + side) + rim = K.ring(r, "filter_rim_%d" % side, (0.0, 0.0, 0.0), + 0.043, 0.011, P["steel_dk"], segments=12) + for v in rim.data.vertices: + v.co = Euler((math.pi / 2, 0, 0)).to_matrix() @ v.co + Vector( + (side * 0.095, -0.30, 1.57)) + rim.data.update() + K.tube(r, "strap_chin_%d" % side, + [(side * 0.20, 0.02, 1.83), (side * 0.21, -0.05, 1.70), + (side * 0.13, -0.19, 1.58)], [0.024, 0.022, 0.020], + P["black"], sides=7) + K.tube(r, "hose", [(0.0, -0.25, 1.54), (0.05, -0.28, 1.43), + (0.12, -0.25, 1.33)], [0.036, 0.032, 0.028], + P["black"], sides=8) + K.loft(r, "helmet", [ + {"z": 1.80, "r": (0.235, 0.225), "n": 24}, + {"z": 1.88, "r": (0.252, 0.238), "n": 24, "fold": (0.012, 5)}, + {"z": 1.96, "r": (0.235, 0.222), "n": 24, "fold": (0.015, 6)}, + {"z": 2.02, "r": (0.175, 0.168), "n": 24}, + {"z": 2.05, "r": (0.075, 0.075), "n": 24}, + ], P["helmet"], ao=0.07) + K.ring(r, "helmet_band", (0.0, 0.0, 1.815), 0.238, 0.016, + P["helmet_dk"], segments=24) + for side in (-1, 1): + K.tube(r, "helmet_seam_%d" % side, + [(side * 0.06, -0.225, 1.86), + (side * 0.14, -0.19, 1.94), + (side * 0.10, -0.10, 2.02)], [0.008, 0.008, 0.007], + P["helmet_dk"], sides=5) + K.plate(r, "helmet_brim", K.octagon(0.265, 0.195), 1.795, 1.82, 0.94, + P["helmet_dk"], shift=(0, -0.155)) + for i, (x, y) in enumerate(((0.10, 0.19), (-0.10, 0.19), (0.0, 0.22))): + K.blob(r, "helmet_worn_%d" % i, (x, y, 1.94), (0.055, 0.05, 0.035), + P["helmet_lt"], subdiv=1, seed=30 + i, ao=0.0) + K.tube(r, "neck", [(0, 0, 1.50), (0, 0, 1.62)], [0.10, 0.105], + P["coverall_sh"], sides=10) + + # Torso: pale coverall, harness, radio, patch, belt and pouches. + K.loft(r, "torso", [ + {"z": 0.90, "r": (0.27, 0.185), "n": 20}, + {"z": 1.00, "r": (0.30, 0.205), "n": 20, "fold": (0.02, 5)}, + {"z": 1.14, "r": (0.33, 0.225), "n": 20, "fold": (0.03, 6)}, + {"z": 1.26, "r": (0.345, 0.232), "n": 20, "fold": (0.035, 6)}, + {"z": 1.36, "r": (0.355, 0.238), "n": 20, "fold": (0.025, 5)}, + {"z": 1.45, "r": (0.35, 0.23), "n": 20}, + {"z": 1.53, "r": (0.30, 0.20), "n": 20}, + {"z": 1.59, "r": (0.25, 0.17), "n": 20}, + ], P["coverall"], ao=0.10) + K.plate(r, "vest", K.octagon(0.345, 0.23), 1.00, 1.47, 0.94, + P["coverall_dk"], shift=(0, -0.02), ao=0.11) + K.plate(r, "vest_back", K.octagon(0.34, 0.22), 1.04, 1.44, 0.94, + P["coverall_dk"], shift=(0, 0.025), ao=0.11) + for side in (-1, 1): + K.tube(r, "harness_%d" % side, + [(side * 0.32, -0.08, 1.52), (side * 0.22, -0.24, 1.30), + (side * 0.16, -0.22, 1.05)], [0.042, 0.044, 0.040], + P["black"], sides=8) + K.plate(r, "chest_pouch_%d" % side, K.octagon(0.095, 0.06), 1.16, 1.28, + 0.92, P["leather"], shift=(side * 0.21, -0.245)) + K.plate(r, "belt_pouch_%d" % side, K.octagon(0.095, 0.07), 0.84, 0.97, + 0.95, P["leather"], shift=(side * 0.26, -0.18)) + K.plate(r, "patch", K.octagon(0.085, 0.085), 0.0, 0.012, 1.0, + P["patch"], ao=0.0) + patch = r.children[-1] + for v in patch.data.vertices: + v.co = Euler((0, 0, math.pi / 2)).to_matrix() @ v.co + Vector( + (0.42, -0.045, 1.43)) + patch.data.update() + K.plate(r, "patch_mark", K.octagon(0.05, 0.05), 0.0, 0.014, 1.0, + P["hiss_red"], ao=0.0) + mark = r.children[-1] + for v in mark.data.vertices: + v.co = Euler((0, 0, math.pi / 2)).to_matrix() @ v.co + Vector( + (0.43, -0.055, 1.43)) + mark.data.update() + K.loft(r, "belt", [ + {"z": 0.87, "r": (0.31, 0.21), "n": 16}, + {"z": 0.97, "r": (0.32, 0.22), "n": 16}, + ], P["black"], ao=0.05) + K.plate(r, "buckle", K.octagon(0.055, 0.04), 0.90, 0.95, 1.0, + P["steel_dk"], shift=(0, -0.225), ao=0.0) + K.loft(r, "radio", [ + {"z": 1.36, "r": (0.08, 0.06), "n": 10, "c": (0.32, 0.10)}, + {"z": 1.55, "r": (0.075, 0.055), "n": 10, "c": (0.32, 0.10)}, + ], P["black"]) + K.tube(r, "antenna", [(0.32, 0.10, 1.55), (0.35, 0.11, 1.86)], + [0.012, 0.007], P["steel_dk"], sides=6) + for z in (1.06, 1.24, 1.42): + K.tube(r, "seam_%g" % z, + [(-0.30, -0.225, z), (0.0, -0.245, z), + (0.30, -0.225, z)], [0.008, 0.008, 0.008], + P["coverall_sh"], sides=5) + + # Arms: sleeves, padded elbows, gloves and individual fingers. + for side in (-1, 1): + K.blob(r, "shoulder_%d" % side, (side * 0.40, -0.01, 1.46), + (0.13, 0.14, 0.125), P["coverall_dk"], subdiv=2, seed=40 + side) + K.loft(r, "upperarm_%d" % side, [ + {"z": 1.46, "r": (0.112, 0.112), "n": 16, "c": (side * 0.41, -0.02)}, + {"z": 1.36, "r": (0.107, 0.107), "n": 16, "c": (side * 0.42, -0.07)}, + {"z": 1.26, "r": (0.10, 0.10), "n": 16, "c": (side * 0.425, -0.12)}, + {"z": 1.19, "r": (0.094, 0.094), "n": 16, "c": (side * 0.43, -0.17)}, + {"z": 1.14, "r": (0.088, 0.088), "n": 16, "c": (side * 0.43, -0.20)}, + ], P["coverall"], ao=0.06) + K.blob(r, "elbow_%d" % side, (side * 0.43, -0.22, 1.14), + (0.09, 0.095, 0.085), P["leather"], subdiv=2, seed=50 + side) + K.tube(r, "forearm_%d" % side, [ + (side * 0.43, -0.23, 1.14), (side * 0.40, -0.36, 1.15), + (side * 0.35, -0.49, 1.16), (side * 0.31, -0.60, 1.17), + ], [0.09, 0.084, 0.077, 0.07], P["coverall"], sides=10) + K.ring(r, "cuff_%d" % side, (side * 0.31, -0.60, 1.17), 0.075, + 0.012, P["coverall_dk"], segments=12) + K.blob(r, "glove_%d" % side, (side * 0.30, -0.69, 1.17), + (0.085, 0.095, 0.09), P["black"], subdiv=2, seed=60 + side) + for f in range(4): + x = side * (0.27 + f * 0.03) + K.tube(r, "finger_%d_%d" % (side, f), + [(x, -0.74, 1.17), (x, -0.81, 1.16), (x, -0.84, 1.14)], + [0.024, 0.02, 0.016], P["black"], sides=7) + K.tube(r, "thumb_%d" % side, + [(side * 0.265, -0.68, 1.22), (side * 0.23, -0.76, 1.20)], + [0.029, 0.022], P["black"], sides=7) + + # Legs: coverall thighs, knee pads, shin, laced boots. + for side in (-1, 1): + K.loft(r, "thigh_%d" % side, [ + {"z": 0.88, "r": (0.15, 0.16), "n": 16, "c": (side * 0.16, 0)}, + {"z": 0.78, "r": (0.148, 0.158), "n": 16, "c": (side * 0.165, 0)}, + {"z": 0.68, "r": (0.14, 0.15), "n": 16, "c": (side * 0.17, 0)}, + {"z": 0.58, "r": (0.13, 0.14), "n": 16, "c": (side * 0.175, 0)}, + {"z": 0.50, "r": (0.115, 0.125), "n": 16, "c": (side * 0.18, 0)}, + ], P["coverall"], ao=0.09) + K.blob(r, "knee_%d" % side, (side * 0.18, -0.08, 0.51), + (0.125, 0.09, 0.11), P["leather"], subdiv=2, seed=70 + side) + K.loft(r, "shin_%d" % side, [ + {"z": 0.50, "r": (0.115, 0.125), "n": 16, "c": (side * 0.18, 0)}, + {"z": 0.40, "r": (0.11, 0.118), "n": 16, "c": (side * 0.185, 0)}, + {"z": 0.30, "r": (0.105, 0.11), "n": 16, "c": (side * 0.19, 0)}, + {"z": 0.20, "r": (0.098, 0.10), "n": 16, "c": (side * 0.19, 0)}, + {"z": 0.13, "r": (0.09, 0.095), "n": 16, "c": (side * 0.19, 0)}, + ], P["coverall_dk"], ao=0.09) + K.loft(r, "boot_%d" % side, [ + {"z": 0.015, "r": (0.15, 0.225), "n": 12, + "c": (side * 0.19, -0.08)}, + {"z": 0.09, "r": (0.14, 0.20), "n": 12, + "c": (side * 0.19, -0.06)}, + {"z": 0.20, "r": (0.12, 0.14), "n": 12, "c": (side * 0.19, 0)}, + ], P["black"], ao=0.06) + K.plate(r, "sole_%d" % side, K.octagon(0.155, 0.23), 0.0, 0.025, 0.98, + P["leather"], shift=(side * 0.19, -0.08)) + K.tube(r, "thigh_strap_%d" % side, + [(side * 0.06, -0.12, 0.72), (side * 0.18, -0.17, 0.70), + (side * 0.30, -0.10, 0.68)], [0.028, 0.03, 0.026], + P["leather"], sides=6) + for lace in range(4): + K.tube(r, "lace_%d_%d" % (side, lace), + [(side * 0.13, -0.22, 0.05 + lace * 0.035), + (side * 0.25, -0.22, 0.05 + lace * 0.035)], + [0.008, 0.008], P["coverall_sh"], sides=5) + + HOLSTER_SIDE = -1 + K.plate(r, "holster", K.octagon(0.095, 0.065), 0.65, 0.85, 0.9, + P["black"], shift=(HOLSTER_SIDE * 0.33, 0.10)) + K.tube(r, "holster_strap", + [(HOLSTER_SIDE * 0.33, 0.10, 0.85), (HOLSTER_SIDE * 0.20, -0.02, 0.92)], + [0.025, 0.022], P["leather"], sides=6) + + # Service Weapon: a clearly boxy rifle carried across the chest. No round + # muzzle bulb — the red rounds are flat bands on a rectangular brake. + def rect(x0, x1, y0, y1): + return [(x0, y0), (x1, y0), (x1, y1), (x0, y1)] + + K.plate(r, "rifle_receiver", rect(0.05, 0.27, -0.62, -0.12), + 1.09, 1.25, 1.0, P["black"], ao=0.06) + K.plate(r, "rifle_rail", rect(0.08, 0.24, -0.58, -0.16), + 1.25, 1.27, 1.0, P["steel_dk"], ao=0.0) + K.plate(r, "rifle_stock", rect(0.04, 0.27, -0.14, 0.06), + 1.12, 1.23, 0.94, P["leather"], ao=0.06) + K.plate(r, "rifle_grip", rect(0.10, 0.21, -0.29, -0.17), + 0.92, 1.12, 0.86, P["black"], ao=0.06) + K.plate(r, "rifle_magazine", rect(0.09, 0.22, -0.52, -0.32), + 0.84, 1.10, 0.92, P["steel_dk"], ao=0.06) + K.plate(r, "rifle_foregrip", rect(0.09, 0.21, -0.76, -0.62), + 0.97, 1.12, 0.9, P["black"], ao=0.06) + K.plate(r, "rifle_barrel", rect(0.12, 0.20, -0.98, -0.62), + 1.15, 1.20, 1.0, P["steel_dk"], ao=0.0) + K.plate(r, "rifle_brake", rect(0.11, 0.21, -1.06, -0.98), + 1.14, 1.21, 1.0, P["steel_dk"], ao=0.0) + for i, y in enumerate((-1.02, -1.05)): + K.plate(r, "rifle_red_round_%d" % i, rect(0.115, 0.205, y - 0.01, y + 0.01), + 1.135, 1.215, 1.0, P["hiss_red"], ao=0.0) + K.plate(r, "rifle_sight", rect(0.11, 0.19, -0.35, -0.25), + 1.27, 1.34, 1.0, P["black"], ao=0.0) + K.plate(r, "rifle_sight_lens", rect(0.125, 0.175, -0.33, -0.27), + 1.34, 1.345, 1.0, P["teal"], ao=0.0) + for i in range(4): + K.plate(r, "rifle_vent_%d" % i, rect(0.27, 0.272, -0.22 - i * 0.075, + -0.20 - i * 0.075), + 1.14, 1.20, 1.0, P["steel_dk"], ao=0.0) + + # Angle the whole weapon across the body so it reads as a carried rifle + # instead of a centred cylinder, and move the weapon bone with it. + pivot = Vector((0.16, -0.15, 1.17)) + turn = Euler((0.0, 0.0, -math.radians(32))).to_matrix() + for obj in list(r.children): + if obj.type == "MESH" and obj.name.lower().startswith("rifle"): + for v in obj.data.vertices: + v.co = pivot + turn @ (v.co - pivot) + obj.data.update() + for i, (x, y, z, tilt) in enumerate([ + (0.12, 0.22, 1.40, (0.3, 0.2, 0.4)), + (-0.10, 0.23, 1.24, (-0.4, 0.1, -0.3)), + (0.05, 0.24, 1.10, (0.2, -0.3, 0.1)), + ]): + K.crystal(r, "taint_%d" % i, (x, y, z), 0.13, P["hiss_red"], sides=5, + seed=70 + i, tilt=tilt) + + # The yellow selection ring stays planted at the feet (weighted to root). + K.ring(r, "base", (0, 0, 0.055), 0.50, 0.035, P["board"]) + K.plate(r, "base_disc", K.octagon(0.46), 0.0, 0.025, 1.0, P["black"]) + return r + + +# ------------------------------------------------------------------- rigging +BONES = [ + ("root", (0, 0, 0.0), (0, 0, 0.20), None), + ("hips", (0, 0, 0.90), (0, 0, 1.04), "root"), + ("spine", (0, 0, 1.04), (0, 0, 1.26), "hips"), + ("chest", (0, 0, 1.26), (0, 0, 1.48), "spine"), + ("neck", (0, 0, 1.50), (0, 0, 1.62), "chest"), + ("head", (0, 0, 1.62), (0, 0, 1.98), "neck"), + ("weapon", (0.15, -0.25, 1.17), (-0.20, -0.75, 1.17), "chest"), +] +for SIDE, SIGN in (("L", -1), ("R", 1)): + BONES += [ + ("upperarm." + SIDE, (SIGN * 0.43, 0, 1.46), + (SIGN * 0.50, -0.04, 1.09), "chest"), + ("forearm." + SIDE, (SIGN * 0.50, -0.04, 1.09), + (SIGN * 0.54, -0.08, 0.78), "upperarm." + SIDE), + ("hand." + SIDE, (SIGN * 0.54, -0.08, 0.78), + (SIGN * 0.54, -0.20, 0.62), "forearm." + SIDE), + ("thigh." + SIDE, (SIGN * 0.17, 0, 0.88), + (SIGN * 0.18, 0, 0.51), "hips"), + ("shin." + SIDE, (SIGN * 0.18, 0, 0.51), + (SIGN * 0.19, 0, 0.13), "thigh." + SIDE), + ("foot." + SIDE, (SIGN * 0.19, 0, 0.13), + (SIGN * 0.19, -0.20, 0.04), "shin." + SIDE), + ] + + +def build_rig(): + data = bpy.data.armatures.new("AgentRig") + arm = bpy.data.objects.new("AgentRig", 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, b.tail = head, tail + 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"(?:^|_)(-1|1)(?=_|$)", name) + if m: + return "R" if m.group(1) == "1" else "L" + 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 "base" in n: + return "root" + if any(k in n for k in ("helmet", "visor", "mask", "head", "hose", "filter", + "lens", "glass", "chin", "neck")): + return "head" + if "rifle" in n or "weapon" in n or "muzzle" in n or "magazine" in n: + return "weapon" + if any(k in n for k in ("upperarm", "shoulder", "patch")): + return "upperarm." + s + if any(k in n for k in ("forearm", "elbow", "cuff")): + return "forearm." + s + if any(k in n for k in ("glove", "finger", "thumb", "hand")): + return "hand." + s + if any(k in n for k in ("thigh", "knee")): + 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] + return "chest" if (sum(zs) / max(len(zs), 1)) > 1.14 else "hips" + + +def assign_groups(root): + for obj in list(root.children): + if obj.type != "MESH": + continue + primary = group_for(obj.name, obj) + groups = {primary: []} + for v in obj.data.vertices: + z = v.co.z + if primary == "upperarm." + side_of(obj.name, obj) and 1.06 < z < 1.18: + groups[primary].append((v.index, (1.18 - z) / 0.12)) + groups.setdefault("forearm." + side_of(obj.name, obj), []).append( + (v.index, (z - 1.06) / 0.12)) + elif primary == "forearm." + side_of(obj.name, obj) and 1.06 < z < 1.18: + groups[primary].append((v.index, (z - 1.06) / 0.12)) + groups.setdefault("upperarm." + side_of(obj.name, obj), []).append( + (v.index, (1.18 - z) / 0.12)) + elif primary == "thigh." + side_of(obj.name, obj) and 0.45 < z < 0.57: + groups[primary].append((v.index, (z - 0.45) / 0.12)) + groups.setdefault("shin." + side_of(obj.name, obj), []).append( + (v.index, (0.57 - z) / 0.12)) + elif primary == "shin." + side_of(obj.name, obj) and 0.45 < z < 0.57: + groups[primary].append((v.index, (0.57 - z) / 0.12)) + groups.setdefault("thigh." + side_of(obj.name, obj), []).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 pose_idle(pb, t): + breath = math.sin(t * 2.0 * math.pi) + pb["chest"].rotation_euler.x = 0.015 + 0.018 * breath + pb["head"].rotation_euler.z = 0.025 * math.sin(t * math.pi) + pb["upperarm.L"].rotation_euler.x = -0.03 + pb["upperarm.R"].rotation_euler.x = 0.03 + + +def pose_run(pb, t): + phase = t * 2.0 * math.pi + s = math.sin(phase) + pb["root"].location.z = 0.035 * abs(math.sin(2.0 * phase)) + pb["chest"].rotation_euler.x = 0.20 + pb["head"].rotation_euler.x = -0.10 + pb["thigh.L"].rotation_euler.x = 0.62 * s + pb["thigh.R"].rotation_euler.x = -0.62 * s + pb["shin.L"].rotation_euler.x = 0.55 * max(0.0, -s) + pb["shin.R"].rotation_euler.x = 0.55 * max(0.0, s) + pb["upperarm.L"].rotation_euler.x = -0.28 * s + pb["upperarm.R"].rotation_euler.x = 0.18 * s + pb["forearm.L"].rotation_euler.x = 0.35 + pb["forearm.R"].rotation_euler.x = 0.42 + + +def pose_dash(pb, t): + pb["root"].location.z = 0.02 + pb["chest"].rotation_euler.x = 0.42 + pb["head"].rotation_euler.x = -0.18 + pb["thigh.L"].rotation_euler.x = 0.80 + pb["thigh.R"].rotation_euler.x = -0.55 + pb["shin.L"].rotation_euler.x = 0.30 + pb["upperarm.L"].rotation_euler.x = -0.55 + pb["upperarm.R"].rotation_euler.x = -0.35 + pb["forearm.L"].rotation_euler.x = 0.30 + pb["forearm.R"].rotation_euler.x = 0.30 + + +def pose_fire(pb, t): + kick = math.exp(-9.0 * t) + pb["weapon"].rotation_euler.x = -0.22 * kick + pb["chest"].rotation_euler.x = 0.06 * kick + pb["upperarm.R"].rotation_euler.x = 0.16 * kick + pb["forearm.R"].rotation_euler.x = 0.20 * kick + pb["head"].rotation_euler.x = -0.05 * kick + + +def pose_stagger(pb, t): + fade = 1.0 - t + pb["chest"].rotation_euler.x = -0.30 * fade + pb["head"].rotation_euler.x = -0.35 * fade + pb["upperarm.L"].rotation_euler.x = -0.35 * fade + pb["upperarm.R"].rotation_euler.x = 0.30 * fade + + +def make_actions(arm): + specs = [ + ("Idle", 1, 48, pose_idle), + ("Run", 1, 36, pose_run), + ("Dash", 1, 18, pose_dash), + ("Fire", 1, 16, pose_fire), + ("Stagger", 1, 20, pose_stagger), + ] + arm.animation_data_create() + made = [] + for name, start, end, fn in specs: + act = bpy.data.actions.new(name) + act.use_fake_user = True # keep unassigned clips in the saved .blend + 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 == "root": + 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_agent() +arm = build_rig() +assign_groups(root) +mesh = K.merge_actor(root, "agent") +tris = K.triangle_count(root) +print("[budget] agent %d tris (cap 12000) %s" + % (tris, "OK" if tris <= 12000 else "OVER")) +assert tris <= 12000, "agent over triangle budget" + +mod = mesh.modifiers.new("AgentSkin", "ARMATURE") +mod.object = arm +mesh.parent = arm +actions = make_actions(arm) + +out = os.path.join(MODEL_DIR, "agent.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, plus a tight detail camera. +scene = bpy.context.scene +arm.animation_data.action = actions["Idle"] +scene.frame_set(12) + +world = bpy.data.worlds.new("AgentWorld") +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("#101a16"), 1.0) +bg.inputs["Strength"].default_value = 0.8 + +for name, loc, power, col in ( + ("Key", (-3, -7, 6), 2400, "#e8f0e2"), + ("Rim", (3, 4, 5), 1400, "#4ec9b0"), + ("VisorFill", (0, -4, 2.2), 700, "#ff4a12"), +): + data = bpy.data.lights.new(name, "AREA") + data.energy = power + data.shape = "DISK" + data.size = 6 + data.color = K.rgb(col) + obj = bpy.data.objects.new(name, data) + scene.collection.objects.link(obj) + obj.location = loc + obj.rotation_euler = (Vector((0, 0, 1.1)) - Vector(loc)).to_track_quat( + "-Z", "Y").to_euler() + +for name, loc, lens, target in ( + ("AgentCam", (0.2, -6.5, 3.6), 44, (0, 0, 1.1)), + ("AgentDetail", (-1.3, -3.0, 2.3), 50, (0, -0.05, 1.55)), +): + data = bpy.data.cameras.new(name) + cam = bpy.data.objects.new(name, data) + scene.collection.objects.link(cam) + cam.location = loc + cam.rotation_euler = (Vector(target) - Vector(loc)).to_track_quat( + "-Z", "Y").to_euler() + data.lens = lens + if name == "AgentCam": + 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 engines[0] +scene.render.resolution_x = 1000 +scene.render.resolution_y = 1100 +scene.render.image_settings.file_format = "PNG" +scene.render.filepath = os.path.join(CONCEPT_DIR, "agent_reference.png") +bpy.ops.render.render(write_still=True) + +scene.camera = bpy.data.objects["AgentDetail"] +scene.render.filepath = os.path.join(CONCEPT_DIR, "agent_detail.png") +bpy.ops.render.render(write_still=True) + +bpy.ops.wm.save_as_mainfile(filepath=os.path.join(BLEND_DIR, "fbc_agent.blend")) +print("[done] agent rig + animations exported")