Skeletal characters (HeroEditor4D rig in Godot) - Claude, started 2026-11-24
Owner approved the full system after the prototype (SKELETAL_PROTOTYPE_20261124.md): characters drawn from part sprites by per-frame slot transforms; every slot swappable.
Data (Unity -> Godot)
- Unity: WieldHavenUnity Assets/Editor/WieldHavenRigExporter.cs, ExportAllBatch (
-rigs-only/-library-only; rig sprites are numbered r*, library sprites p*). Output SpriteSheets/WieldHavenGodot/Rig/: rigs/<Human|Goblin|Skeleton>_<Melee1H|Melee2H|Bow>.json, sprites/*.png, sprites_index(.tsv|_rigs.tsv), library.json. Rig = slots (renderer path, direction, category, HeroEditor sprite mapping names, default tint, material) + prefab sprites (cropped hair, expressions) + anims: 11 rows (idle ready walk run slash jab fire cast block death hit) x 4 dirs x 16 frames of [slot, 2D matrix, sorting order]. Library = 1002 items (all HeroEditor categories we use) -> sprite name -> sprite id. - Godot import: Scripts/Build/import_rig_library.py -> Assets/Rig/{rigs, atlases (one per item), sprites.json, library.json} (55 MB on disk), then Godot --import.
- Old variant numbers -> library items: Scripts/Build/match_player_variants.py (rig render + mask IoU), match_player_parts_shape.py (cropped shape, weapons rotated), map_armor_variants.py (armor by name) -> Assets/Rig/player_variant_map.json.
Runtime
- Scripts/Rig/RigData.gd: static caches (rigs, library, sprites, AtlasTextures).
- Scripts/Rig/RigCharacter.gd: setup(prefab, weapon), set_appearance({Body, Ears, Hair, Beard, Eyes, Eyebrows, Mouth, Helmet, Vest, Bracers, Leggings, Weapon1, Weapon2, Shield, Bow, Back, Mask, Earrings, Wings, Makeup, colors{}}), set_expression(Default|Angry|Dead), play(row, dir), play_split(lower row/dir/frame, upper row/dir/frame). Slot rules copy HeroEditor Character.Initialize (hair cropped under helmets unless FullHair, ear rules, expressions). Same 512 px cell as the old sheets.
- Player: Scripts/Rig/RigPlayerMirror.gd (child of Player, off by default; DEV "Rig Player" or env WIELDHAVEN_RIG_PLAYER=1). Old AnimatedSprite2D layers keep running hidden as the animation clock (combat timing untouched); the rig mirrors legs/upper frames and builds its appearance from modular_layers through player_variant_map.json.
- Tests: Scripts/Build/VerifyRigCharacters.gd (rendered rows/directions sheet), Scripts/Build/GameChecks/game_check_rig_player.gd (in game: enable, walk, attack, armor swap).
- Mobs: Scripts/Rig/MobRigLooks.gd (base look per scene, same items as the Unity sheet exporters) + Scripts/Rig/RigEnemyMirror.gd (in VisualRoot; old body sprites stay as clock with self_modulate alpha 0, MobGearVisual hidden; worn gear mapped through player_variant_map). DEV "Rig Mobs" / env WIELDHAVEN_RIG_MOBS=1; game_check_rig_mobs.gd. 20/20 mobs, play 33/33.
- Armor variant map: name table is right for icon-anchored sets; a colour pass (match_armor_color.py) was WRONG for several (52, 55, 65...) and was reverted except 21/74/129. Visual old-vs-new sheet of the 41 themed sets checked 24.11.
- Perf with BOTH systems running (rig on, old sheets still loaded and drawn transparent): stress_40 74.5 FPS (old alone ~85). The win needs step 6.
Fixes 24.11 evening (Janari: "face broken, eyes blue lamps, mobs simpler")
- Rig is ON by default (RigData.default_on(); env WIELDHAVEN_RIG=0 = old look; DEV buttons switch).
- Eyes: HeroEditor draws eyes with "Gray Paint" (EyesPaint: only the coloured iris takes the eye colour). Port: Scripts/Rig/hero_paint.gdshader (tint read in vertex(): fragment COLOR already includes the texture). RigCharacter uses it for EyesPaint slots and tinted equipment (EquipmentPaint).
- Player face numbers are HeroEditor's own order (category items per collection Basic then Emoji, sorted by name, from 1): Scripts/Build/fix_player_face_map.py rewrote Eyes, Eyebrows, Mouth, Ears, Mustache and Hair 43-63 (Gradient). Before-copy: D:/WieldHavenBackups/archive/rig_face_20261124/.
- Mobs come 1:1 from Unity: WieldHavenUnity Assets/Editor/WieldHavenRigLookExporter.cs builds every mob with the same code as its old sheets (WieldHavenBareMobExporter / OrcDemon CreateCharacter: baked orc/demon bodies, skin and eye colours, hidden human face) and writes every renderer (sprite, colour, paint, on, carried) to Rig/looks/<Mob>.json; importer copies to Assets/Rig/looks; RigEnemyMirror -> RigCharacter.set_resolved_look; worn gear still overrides its categories. MobRigLooks is fallback only.
- Check: Scripts/Build/GameChecks/game_check_rig_compare.gd (close-up old/new of player and every mob).
- Still different: player shield mapping (44 old shields, order rule not found yet), quiver not drawn, skeleton king worn bow (bow match weak).
Character creator, quiver, status (24.11 late)
- New Game / NPC creator (Scripts/Menus/CharacterCreation.gd) previews a RigCharacter built by Scripts/Rig/PlayerRigLook.gd - the same helper RigPlayerMirror uses, so creator == game. Rows: Hair, Ears, Eyes, Brows, Mouth, Facial Hair (item name shown) + Skin / Hair / Eye colour (palette + free ColorPickerButton). Saved: old Stats numbers + Stats["RigColors"] {Skin, Hair, Eyes} as "#rrggbb". Body/Legs/Head rows hidden on the rig (no effect). Check: game_check_char_create.gd.
- Hair/beard tint uses EquipmentPaint (hero_paint.gdshader): only grey pixels take the colour, so coloured details (hair ties) keep theirs - no per-colour sprite sheets needed.
- Bows and quivers: old numbers = HeroEditor order (Basic, Epic, Christmas, Patreon; SkullBandit and Slavic bows newer), confirmed by quiver colours; a quiver is the bow item's "Quiver" sprite.
- GUI.update_rig_status(): DEV buttons read "Rig Player: UUS/VANA", "Rig Mobs: ..." and a label bottom right shows "Mängija: UUS Mobid: UUS".
- Main menu: Menu.gd already shows a "WieldHaven" label; the hidden legacy Title image now points to Assets/GUI/Text/WieldHaven_Title.png (Scripts/Build/make_wieldhaven_title.py); TeJa_Title.png kept.
Races (24.11 late, Janari)
- PlayerRigLook.RACES: human, elf (elf ears), goblin (Goblin rig, 4 bodies + matching ears), skeleton (Skeleton rig, 8 bodies, skeleton eyes, no hair/face), orc and demon (Human rig, Draft bodies 1-4 with painted faces, so Eyes/Eyebrows/Mouth/Ears hidden). Saved Stats["Race"], Stats["RaceBody"]; each race has a default skin colour (picked colour wins). RigPlayerMirror sets the rig prefab from the race. Creator rows "Race" and "Body Type". Check: game_check_races.gd.
- Creator fixes 25.11 (Janari): (1) value between "<" ">" has fixed width 230 (VALUE_WIDTH, long names end with "..."), arrows never move. (2) Orc/demon Draft heads have eyes, brows, mouth and ears painted in; before, removing those keys made RigCharacter fall back to the prefab DEFAULT face, so human eyes/brows/mouth sat on top (misplaced on bodies 2-4). Now PlayerRigLook.apply_race puts hidden parts in look["hidden"] and RigCharacter draws nothing there (same as Unity HideHumanFace). (3)+(4) Rows are shown only when they change something: human all; elf no Ears (forced elf ears); goblin own ears (8 Goblin ears, default = body type) and eyes (4 goblin eyes first, then common); skeleton no part rows (Skin + Eye Color only); orc/demon Hair + Facial Hair, Skin + Hair Color. Race-own picks saved as Stats["RaceParts"] {row: library key}; RigPlayerMirror passes them to apply_race. Check: run_one_game_check.ps1 -Script game_check_creator_parts.gd (contact sheets per race/body/part, ">" x positions); CHECK_RACE=demon game_check_races.gd for the world. Proof: test-results/game_checks/creator_races_20261125/ (enne/parast). Backup of old scripts: D:/WieldHavenBackups/archive/creator_races_20261125/before.
- Same evening, Janari decisions: ORC and DEMON REMOVED from RACE_ORDER (HeroEditor4D has them only as Draft sketch bodies; RACES entries kept, unknown race -> human). Rule: face/body parts ONLY from the race's own Unity editor (human/elf: FantasyHeroes SpriteCollection, goblin: FantasyGoblins [Goblins], skeleton: UndeadHeroes); armour, weapons, shields for every race (tested: game_check_race_gear.gd, 10 sets x 4 races, front+side OK). Every face row is now a race list of library keys (PlayerRigLook HUMAN_*/ELF_EARS/GOBLIN_*/SKELETON_MOUTHS, generated by Scripts/Build/gen_player_parts.py with display names PART_NAMES; edit the .py and paste the block). Only normal open eyes (27, no X/closed/odd/"Stern" lid-over-brow) and closed mouths (13); the rest stay in-game expressions. No bright gradient hair. Elf ears = 7 pointy, human = 7 round. Goblin: 10 hair + bald, 8 ears, 4 eyes, 7 mouths, 4 beards + none, no brows, own moods (face_family "goblin": Angry/Dead eyes, Dead mouth). Skeleton: jaw TypeA/TypeB/none ([NoMouth] bodies none). Body types named (goblin Speckled/Spotted/Mottled/Freckled, skeleton Old Bones...). Skin palettes per race (RACE_SKIN_COLORS: goblin greens, skeleton bone). Saves: Stats["RaceParts"] {row: key} for every shown row; older numbered saves keep their look when that item is still offered.
- Forced full helmets on orcs/demons removed (MobGearRules MOB_PROFILES), VerifyMobGear 1355 pass.
- Planned, waiting for Janari: player stays HeroEditor4D (4 dirs); all mobs/NPCs from HeroEditor 2D (side view, left/right only). 2D has humans, skeletons, zombies, mummies, demons, werewolves - no goblins/orcs. Janari 24.11: mobs wear ONLY armor sets that exist in both packs (so the drop looks like what the mob wore). Shared names (tags ignored, 44): BanditArmor, BanditLightArmor, CataphractArmor, ChainmailLightArmor, ChampionArmor, Cossack, CrusaderChainmail, DarkLordArmor, DraconicArmor, FalconLightArmor, Female01-08, GladiatorArmor, GuardArmor, HighCrusaderArmor, HunterLightArmor, IronArmor, KnightArmor, Knyaz, Kopeynik, Luchnik, LushKnight, MedievalCook, MercenaryArmor, PersianLancerArmor, Ratnik, Robe, SkeletonArmor1-4, SkullBanditOutfit, SkullMarauderOutfit, SkullWarlockOutfit, Strelets, Vityaz, Voivode, WallKeeperArmor. Goblin/orc replacement: Janari chose "A" (2D mobs).
Mobs on HeroEditor 2D (built 24.11 late)
- Unity: Assets/Editor/WieldHavenRig2DExporter.cs (Human2D/Undead2D x Melee1H/Melee2H/Bow, one direction "r", 11 rows; 2D library 1647 items). Godot: Scripts/Build/import_rig2d_library.py -> Assets/Rig/rigs/*2D_*.json + Assets/Rig2D/{atlases,sprites.json,library.json} (keys "2D:...").
- RigData: library_2d(), find_2d(category, name), 2D sprites merged. RigCharacter: rigs with "side_view" use _sprite_2d() (MapSprites rule: Body/Armor/Bow by renderer name, others item.sprite; armor pieces ArmorVest/ArmorBracers/ArmorBoots by renderer name) and mirror "r" for "l"; up/down keep the last side.
- Scripts/Rig/MobLooks2D.gd: per scene look + skin/eye colour + runtime enemy_name: skeletons, bandits (goblin scenes), Zombie / Zombie Brute / Mummy Archer / Werewolf Alpha (orc scenes), demons. RigEnemyMirror uses it first (rig at feet, +104 px, scale 0.78). Scene files untouched.
- MobGearRules: FAMILY_SETS = 21 shared sets that are player items; ROLL_HELMETS false (no same-named 2D helmets; Janari: no full helmets on skeletons); POOLS weapons only axes 1000/1001 (others have no 2D twin, List2DWeapons.gd), no off-hands; bosses Gladiator+1001 / DarkLord(10881-3)+1019.
- Checks 24.11: VerifyMobGear 730/730; run_game_checks quick: play flake enemy_attack_starts (known), stress_40 69.8 FPS (< 80, old sheets still loaded + rig drawn; step 6 fixes).
Late 24.11: performance, NPCs, faces
- Perf: RigEnemyMirror hides old bodies with visibility_layer 0 (no draw; clock keeps running), suppresses MobGearVisual sheet loading (meta rig_suppressed), SkeletonEnemy skips head sheets in rig mode, off-screen mobs skip pose updates; RigCharacter: same-frame split shortcut, static merged-draw cache, only-changed property sets. import_rig2d_library.py packs every mob part into "mobpack" 2048 pages (draws 1469 -> 923); unused per-item atlases archived to D:/WieldHavenBackups/archive/rig2d_atlases_before_mobpack_20261124. Mob rig update ~0.3 ms/frame (env WIELDHAVEN_RIG_PROFILE=1 prints RIGPROF). stress_40: 76.9-79.7 FPS (old 85.6, budget 80).
- NPCs: Scripts/Rig/RigNpc.gd (2D looks after the old 4D presets, idle, turns to the player), attached by Player._ready -> RigNpc.attach_all (also NPCs added later). Check game_check_npc_lineup.gd.
- Faces: RigCharacter.face_family "4d"/"2d", FACES table (pack emoji items), set_mood/follow_row: blink every 2-5 s, Surprised 0.5 s then Angry in fight rows, Hurt 0.4 s on hit, Dead = X eyes (2D uses the 4D X eyes as sprite "x2d_dead", RigData._add_2d_dead_eyes). Player (human/elf/goblin), bandits ("face": true in MobLooks2D), NPCs, creator preview. Check game_check_faces.gd.
25.11: weapons, obstacles, water, sliding, pet
- MobLooks2D: every melee mob has a base (non-dropping) weapon.
- Weapon clip: rig_clip_feet.gdshader on Weapon1/2/Shield/Bow sprites; RigEnemyMirror sets rig.clip_active when a StaticBody2D is right below the feet (point queries every 12 frames).
- Water: Scripts/World/RiverWading.gd (Janari: rivers/streams wadeable, ponds/coves/lakes blocked): river bodies (SouthCreekWater, RiverWater, EastCreekWater, CampConnectedCreek/WaterCollision, DemoWaterCollision Creek* shapes, ShoreBlockers Creek*) lose their blocking and get a twin Area2D on layer 1<<19; RigCharacter.wading cuts below WADE_DEPTH and draws RigRipple; everyone x0.55 speed in rivers (Player.river_slow_factor, SkeletonEnemy._river_slow, PetCompanion). Deep water: Scripts/World/WaterZones.gd + SkeletonEnemy.guard_water moves mobs back to dry land.
- No sliding: RigEnemyMirror plays walk legs when the mob really moves but its clock stands.
- Pet: PetCompanion.mob_avoid_spot picks the spot around the player farthest from mobs.
- Checks: game_check_wading.gd, game_check_water.gd, game_check_sliding.gd, game_check_weapon_clip.gd, game_check_obstacle_chase.gd, game_check_stuck_walkers.gd. scratchpad run_when_free.ps1 waits for other threads' runs (shared headless lock).
Open / next
- Step 6 (waiting for Janari's OK): rig as default; clocks without sheet textures (generate empty SpriteFrames with the same names/frames/fps from the .tres text, or drive the rig from the game state directly), enemy scenes stop preloading the body sheets; remove alpha-0 drawing.
- Clock layers without sheet textures (generate empty SpriteFrames with the same names/fps) so the old sheets are no longer loaded -> the memory win.
- Bow variant match is weak (mask IoU ~0.45); WitchCostume armor (129) has no library match.
- Online visuals (OnlinePlayerVisual/OnlineEnemyVisual) - only when asked (scope rule).
- Exported builds must include Assets/Rig/*.json (export filter) because they are read with FileAccess.