feat: Skeletons can show their helmet

New "Show Helmet" option under Skeleton - Visuals, off by default. The owner's
choice is written to the ZDO, so other players see the helmet the way its owner
picked.

On a skull the helmet moves up and back and grows to fit, since the skull is
bigger than the viking head the helmet hangs for. Hoods and the other skinned
helmets can't be moved by their transform: their Head bone is swapped for a
fitted child bone, so the head part follows the skull and the shoulder parts
stay put. A viking body gets the vanilla placement and bones back.
This commit is contained in:
kanym 2026-10-29 01:08:07 +01:00
commit e972ca5ea4
5 changed files with 259 additions and 30 deletions

View file

@ -351,7 +351,7 @@ namespace RacesOfValheim
HideItemInstances(__instance, "m_hairItemInstance");
HideItemInstances(__instance, "m_beardItemInstance");
SetHelmetVisible(__instance, false);
SkeletonVisuals.FitHelmet(p, __instance, SkeletonVisuals.ShowsHelmet(p));
// Poses the mandible, once per frame, after the animation. Attached from
// here rather than from SkeletonRace because this postfix is the one path
@ -396,7 +396,7 @@ namespace RacesOfValheim
ShowItemInstances(__instance, "m_hairItemInstance");
ShowItemInstances(__instance, "m_beardItemInstance");
SetHelmetVisible(__instance, true);
SkeletonVisuals.UnfitHelmet(__instance);
// Parented to rig bones, not to the body container that was just switched
// off above - so without this a human keeps the skeleton's lit sockets.
@ -405,26 +405,6 @@ namespace RacesOfValheim
}
}
/// <summary>
/// A helmet on a skull looks like a helmet floating in a skull, so the race hides it.
///
/// SkeletonRace does this every frame in a world, but it only ever runs for the local
/// player - which is why the helmet came back on the main-menu preview once the body
/// swap started working there. Doing it here covers the menu, remote players and the
/// first frame after a race change, all of which reach this postfix and none of which
/// reach SkeletonRace.
///
/// Delegates to SkeletonVisuals.SetEquipmentPieceHidden, which scales the wrapper to
/// zero and disables its renderers - scale alone leaves a skinned piece (bound to the
/// player's own bones rather than its own transform) still drawing, which is what a
/// helmet with a skinned cloth or chain part looked like.
/// </summary>
private static void SetHelmetVisible(VisEquipment visEq, bool visible)
{
GameObject helmet = Traverse.Create(visEq).Field<GameObject>("m_helmetItemInstance").Value;
SkeletonVisuals.SetEquipmentPieceHidden(helmet, !visible);
}
private static void HideItemInstances(VisEquipment visEq, string fieldName)
{
SetItemInstanceActive(visEq, fieldName, false);