fix(skeleton): hide beard and skinned helmet pieces correctly
The hair/beard hide called into m_hairItemInstances/m_beardItemInstances (plural), fields that don't exist on VisEquipment - every other race uses the real singular m_hairItemInstance/m_beardItemInstance, so the beard was never actually hidden. Fixed the field names and made the helper handle both a GameObject and a List<GameObject> defensively. Helmet hiding only scaled the wrapper to zero, which does nothing for a skinned-mesh piece bound to the player's own bones - it ignores its wrapper's transform. Added SkeletonVisuals.SetEquipmentPieceHidden, which scales to zero and disables every child renderer, and used it everywhere the helmet is hidden (local player, remote players, main-menu preview). Also added an F8 debug dump of the hair/beard/helmet instance state (active, renderer enabled, scale) for diagnosing any future visibility regressions in-game. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ce87e987c9
commit
2f890f95f7
4 changed files with 154 additions and 54 deletions
|
|
@ -170,6 +170,87 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// F8 debug: fires a ray from the camera and logs whatever it hits. Cosmetic pieces
|
||||
/// (hair, beard, helmet) carry no collider, so this mostly confirms terrain/creature hits
|
||||
/// - LogHeadCosmeticsState below is what actually answers "what is that floating chunk."
|
||||
/// Kept anyway because it is the general-purpose "what am I looking at" tool for any other
|
||||
/// bone or prefab placement question that comes up later.
|
||||
/// </summary>
|
||||
private void LogRaycastHit()
|
||||
{
|
||||
Camera cam = Camera.main;
|
||||
if (cam == null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo("[F8] No camera found for raycast.");
|
||||
return;
|
||||
}
|
||||
|
||||
Ray ray = new Ray(cam.transform.position, cam.transform.forward);
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 50f))
|
||||
{
|
||||
Jotunn.Logger.LogInfo("--- F8 RAYCAST HIT ---");
|
||||
Jotunn.Logger.LogInfo($"Collider: '{hit.collider.gameObject.name}' at {hit.point:F2}, distance={hit.distance:F2}");
|
||||
Jotunn.Logger.LogInfo($"Full path: {GetFullPath(hit.collider.transform)}");
|
||||
Renderer renderer = hit.collider.GetComponentInParent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"Nearest renderer: '{renderer.gameObject.name}' ({renderer.GetType().Name}), enabled={renderer.enabled}, scale={renderer.transform.lossyScale:F3}");
|
||||
}
|
||||
Jotunn.Logger.LogInfo("----------------------");
|
||||
}
|
||||
else
|
||||
{
|
||||
Jotunn.Logger.LogInfo("[F8] Raycast hit nothing within 50m (cosmetic pieces usually have no collider anyway).");
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetFullPath(Transform t)
|
||||
{
|
||||
string path = t.name;
|
||||
for (Transform parent = t.parent; parent != null; parent = parent.parent)
|
||||
{
|
||||
path = parent.name + "/" + path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// F8 debug: dumps the exact state of the three item slots this race hides (hair, beard,
|
||||
/// helmet) - active flag, renderer enabled flag and scale for every renderer underneath.
|
||||
/// This is the direct answer to "what is still visible and why": a chunk that survives
|
||||
/// hiding will show up here as active=true, or as a renderer with enabled=true even while
|
||||
/// its wrapper is scaled to zero (the skinned-mesh case scale alone cannot hide).
|
||||
/// </summary>
|
||||
private void LogHeadCosmeticsState()
|
||||
{
|
||||
if (Player.m_localPlayer == null) return;
|
||||
VisEquipment vis = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (vis == null) return;
|
||||
|
||||
Jotunn.Logger.LogInfo("--- F8 SKELETON HEAD COSMETICS ---");
|
||||
DumpItemInstanceField(vis, "m_hairItemInstance");
|
||||
DumpItemInstanceField(vis, "m_beardItemInstance");
|
||||
DumpItemInstanceField(vis, "m_helmetItemInstance");
|
||||
Jotunn.Logger.LogInfo("----------------------------------");
|
||||
}
|
||||
|
||||
private static void DumpItemInstanceField(VisEquipment vis, string fieldName)
|
||||
{
|
||||
GameObject go = HarmonyLib.Traverse.Create(vis).Field<GameObject>(fieldName).Value;
|
||||
if (go == null)
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[F8] {fieldName}: null (nothing equipped/instantiated).");
|
||||
return;
|
||||
}
|
||||
|
||||
Jotunn.Logger.LogInfo($"[F8] {fieldName}: '{go.name}' active={go.activeSelf} scale={go.transform.localScale:F3}");
|
||||
foreach (Renderer r in go.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
Jotunn.Logger.LogInfo($"[F8] renderer '{r.gameObject.name}' ({r.GetType().Name}) enabled={r.enabled}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F8))
|
||||
|
|
@ -180,6 +261,9 @@ namespace RacesOfValheim
|
|||
DumpTransformHierarchy(Hud.instance.transform, "");
|
||||
Jotunn.Logger.LogInfo("--------------------------");
|
||||
}
|
||||
|
||||
LogRaycastHit();
|
||||
LogHeadCosmeticsState();
|
||||
}
|
||||
|
||||
if (Player.m_localPlayer == null) return;
|
||||
|
|
@ -245,10 +329,7 @@ namespace RacesOfValheim
|
|||
{
|
||||
// Hide Helmets (Valheim uses singular GameObject for helmet)
|
||||
var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field<GameObject>("m_helmetItemInstance").Value;
|
||||
if (helmetObj != null && helmetObj.transform.localScale != Vector3.zero)
|
||||
{
|
||||
helmetObj.transform.localScale = Vector3.zero;
|
||||
}
|
||||
SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true);
|
||||
|
||||
// Scale Body Armor (Chest, Legs, Shoulder) by 5%
|
||||
string[] armorFields = { "m_chestItemInstances", "m_legItemInstances", "m_shoulderItemInstances" };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue