fix(visuals): measure the skull's facing from the bind pose, for all three clawed races
The eye frame was read from the head bone's pose ON THE FRAME THE EYES WERE BUILT, snapped to the nearest axis, then cached for the life of the eyes. Catch the head a few degrees into a turn and the snap picks the neighbouring axis, and the pair stays wrong until something rebuilds it. Each race met this separately and each added the same guard - do not build while attached, mid-attack or asleep - which caught the loud cases and left the quiet one: a race change rebuilds while the rig is still settling, which is none of those three. That is why resetting into a race could break the placement while logging out and back in silently fixed it. The logout was never a fix, only a rebuild at a calmer moment, and no fourth guard condition would have closed it - the read itself had to stop depending on when it happens. sharedMesh.bindposes[headBone] is the rig as authored: no animation in it, no timing, the same answer on frame one and frame ten thousand. A rebuild is now deterministic and a bad moment cannot exist. Falls back to the live read, warning once, on a rig that carries no bind pose. Lives in one shared RigBindPose rather than in three copies. The three eye implementations are separate files by design - they differ in what they hang and how it is coloured - but this is the one piece of maths where a divergence would be a bug in whichever copy got fixed second, and it had already been fixed twice. The three now-dead private SnapToAxis copies go with it. Also updates the Aswid eye defaults to the values dialled in on screen: forward 0.013, height 0.004, yaw 22.068.
This commit is contained in:
parent
7668a0a996
commit
3f09c7cf3f
5 changed files with 141 additions and 72 deletions
|
|
@ -298,20 +298,6 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a direction to the nearest of the six axis directions. Whichever component is
|
||||
/// largest wins, sign included.
|
||||
/// </summary>
|
||||
private static Vector3 SnapToAxis(Vector3 direction)
|
||||
{
|
||||
float x = Mathf.Abs(direction.x);
|
||||
float y = Mathf.Abs(direction.y);
|
||||
float z = Mathf.Abs(direction.z);
|
||||
|
||||
if (x >= y && x >= z) return new Vector3(Mathf.Sign(direction.x), 0f, 0f);
|
||||
if (y >= z) return new Vector3(0f, Mathf.Sign(direction.y), 0f);
|
||||
return new Vector3(0f, 0f, Mathf.Sign(direction.z));
|
||||
}
|
||||
|
||||
private static Transform BuildEyes(Player player, Transform headBone)
|
||||
{
|
||||
|
|
@ -327,22 +313,15 @@ namespace RacesOfValheim
|
|||
holder.transform.localRotation = Quaternion.identity;
|
||||
holder.transform.localScale = Vector3.one;
|
||||
|
||||
// Ask the rig which way it faces, once - and then round the answer to the skull's own
|
||||
// axes. The raw measurement is taken at whatever pose the head happens to be in on
|
||||
// this frame, so it arrives tilted: a "forward" leaning 20 degrees down put the eyes
|
||||
// at the jaw instead of the eye line. A bone's real axes are square, and the tilt is
|
||||
// nothing but the pose at the moment of asking, so it is rounded away.
|
||||
Transform root = player.transform;
|
||||
// Which way the rig faces, rounded to the skull's own square axes - and taken from the
|
||||
// BIND POSE rather than from whatever pose the head holds on this frame. See
|
||||
// RigBindPose: read live, the rounding lands on the neighbouring axis whenever the head
|
||||
// is caught mid-turn, and a race change rebuilds at exactly such a moment. That is why
|
||||
// a Dvergar could come out of a reset with its eyes misplaced and be right again after
|
||||
// a logout - the logout was simply a rebuild at a calmer moment, not a fix.
|
||||
EyeFrame frame = holder.AddComponent<EyeFrame>();
|
||||
frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward));
|
||||
frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up));
|
||||
|
||||
// Right is derived, never snapped. Rounding all three independently guarantees
|
||||
// nothing about the angles between them, and a "right" that shares an axis with
|
||||
// forward stops being sideways: the separation then pushes one eye out of the face
|
||||
// and pulls the other into it, which is one eye sitting proud of a forehead while its
|
||||
// twin sits correctly. A cross product cannot be anything but perpendicular.
|
||||
frame.LocalRight = Vector3.Cross(frame.LocalUp, frame.LocalForward).normalized;
|
||||
RigBindPose.MeasureHeadFrame(player, headBone, "Dvergar",
|
||||
out frame.LocalForward, out frame.LocalUp, out frame.LocalRight);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue