From 028c34be3c52302a8c39e531721a7119b4dab472 Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 12 Aug 2026 13:44:59 +0200 Subject: [PATCH 1/3] fix(visuals): stop Aswid and Sverm eyes measuring their facing off the wrong transform Both files built their eye holder's forward/up axes from headBone.root - the top of whatever hierarchy the head bone (from VisEquipment.m_bodyModel's own bone array) happens to sit in. That does not reliably resolve back to the player, so the measurement came out wrong on every single build rather than on an occasional bad-timing one - which is why resetting the race or logging out never fixed it for Aswid, only starting a fresh build at the same wrong reference every time. DvergarVisuals.BuildEyes already reads player.transform directly and does not have this problem - its own eye glitches are the ordinary bad-pose-timing kind the attach/attack/sleep guard mostly covers, which is why relogging (a fresh, differently-timed build) usually fixes it. AswidVisuals and SvermVisuals now do the same. Also gives SvermVisuals.ApplyEyes the same attach/attack/sleep guard Aswid and Dvergar already had before building fresh, which it was missing entirely. --- JotunnModStub/Aswid/AswidVisuals.cs | 10 +++++++++- JotunnModStub/Sverm/SvermVisuals.cs | 24 +++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/JotunnModStub/Aswid/AswidVisuals.cs b/JotunnModStub/Aswid/AswidVisuals.cs index 8d041f9..e52ef30 100644 --- a/JotunnModStub/Aswid/AswidVisuals.cs +++ b/JotunnModStub/Aswid/AswidVisuals.cs @@ -396,7 +396,15 @@ namespace RacesOfValheim // Ask the rig which way it faces, once, and round the answer to the skull's own axes - // see DvergarVisuals.BuildEyes for why the raw, unrounded measurement puts the eyes at // the jaw instead of the eye line. - Transform root = headBone.root; + // + // player.transform, NOT headBone.root. headBone comes off VisEquipment.m_bodyModel's + // own bone array, and walking .root from there does not reliably land back on the + // player - the eyes came out wrong on every single build, not just an unlucky one, which + // is what a bad-timing read (the guard above already handles that) would look like. + // A CONSISTENTLY wrong answer means a consistently wrong reference, not a bad moment to + // ask it in. DvergarVisuals.BuildEyes already reads player.transform directly for + // exactly this reason; this now matches it. + Transform root = player.transform; EyeFrame frame = holder.AddComponent(); frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward)); frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up)); diff --git a/JotunnModStub/Sverm/SvermVisuals.cs b/JotunnModStub/Sverm/SvermVisuals.cs index 9e5b79c..c912e5e 100644 --- a/JotunnModStub/Sverm/SvermVisuals.cs +++ b/JotunnModStub/Sverm/SvermVisuals.cs @@ -192,7 +192,20 @@ namespace RacesOfValheim return; } - if (eyes == null) eyes = BuildEyes(headBone); + if (eyes == null) + { + // See AswidVisuals.ApplyEyes / DvergarVisuals.ApplyEyes for the full reasoning - + // BuildEyes takes a one-time reading of the head bone's pose to work out which way + // the skull faces, and caches it for as long as the eyes exist. Sitting, attached, + // mid-attack or asleep, the head can be turned away from the body's own forward at + // that instant, which is how the snap-to-axis has picked the wrong side and left + // eyes behind the skull before. + if (player.IsAttached() || player.IsAttachedToShip() || player.InAttack() || player.IsSleeping()) + { + return; + } + eyes = BuildEyes(player, headBone); + } if (eyes == null) return; // already logged once by the resolver PlaceEyes(player, headBone, eyes); @@ -256,7 +269,7 @@ namespace RacesOfValheim } } - private static Transform BuildEyes(Transform headBone) + private static Transform BuildEyes(Player player, Transform headBone) { Shader glow = ResolveGlowShader(); if (glow == null) return null; @@ -270,7 +283,12 @@ namespace RacesOfValheim // Ask the rig which way it faces, once, and ROUND the answer to the skull's own axes. // The raw, unrounded measurement puts the eyes on the jaw - DvergarVisuals found that // out first. - Transform root = headBone.root; + // + // player.transform, NOT headBone.root - walking .root up from a bone in + // VisEquipment.m_bodyModel's own array does not reliably land back on the player, and + // gave a wrong answer on every single build rather than an occasional bad-timing one. + // DvergarVisuals.BuildEyes already reads player.transform directly; this now matches it. + Transform root = player.transform; EyeFrame frame = holder.AddComponent(); frame.LocalForward = SnapToAxis(headBone.InverseTransformDirection(root.forward)); frame.LocalUp = SnapToAxis(headBone.InverseTransformDirection(root.up)); From 982e88fa577f5ec68df009661a20a0e4fbd82fc2 Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 12 Aug 2026 15:35:14 +0200 Subject: [PATCH 2/3] fix(aswid): stop borrowing the Skeleton's eye position, only its mesh player.transform (previous commit) fixed the frame used for the shift/rotation config offsets, but that code path is inert at every offset's default of 0 - so it never touched the actual bug. The real placement came from source.localPosition, copied straight off the Skeleton creature's eye_l/eye_r and reinterpreted under the player's own head bone. That only works if the two rigs agree on scale, and they do not: the Skeleton's rig measured 0.02 lossy scale at the eye bone against this player rig's ~95-100, with nothing tying one prefab's authored scale to another's. Taken as-is it put the eyes roughly 0.2 world units off the head bone - visibly floating above the face, on every single build, matching the "never fixes, not even after logout" report exactly. Eyes are now placed from the player's own measured frame and three fixed constants (BaseEyeForward/Height/Separation) - the pre-rewrite sphere code's own numbers, already tuned and playtested on this exact rig. Still borrows eye_l/eye_r for their mesh and material (the actual point of the rewrite - real lit sockets instead of painted spheres), just not their transform. Confirmed against real numbers from in-game diagnostic logging rather than guessed a third time; that logging has been removed. --- JotunnModStub/Aswid/AswidVisuals.cs | 49 ++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/JotunnModStub/Aswid/AswidVisuals.cs b/JotunnModStub/Aswid/AswidVisuals.cs index e52ef30..45bd46e 100644 --- a/JotunnModStub/Aswid/AswidVisuals.cs +++ b/JotunnModStub/Aswid/AswidVisuals.cs @@ -44,6 +44,20 @@ namespace RacesOfValheim // scale cancels and a given config value lands on the same part of the face at any size - // Fader-tier growth included. Kept in the arithmetic because it is honest about intent. + // The eye_l/eye_r pair is borrowed for its MESH AND MATERIAL only, never for its position. + // Their authored local offset lives in the Skeleton creature's own rig, at whatever scale + // that rig happens to use at the eye bone - measured at 0.02 lossy scale against this + // player rig's 95-100, a roughly 5000x difference with no fixed ratio to correct for, + // because nothing ties one prefab's rig scale to another's. Carrying that number over + // unchanged (even after remapping which axis is which) put the eyes some 0.2 world units + // off the head bone - visibly floating above the face. These three are the pre-rewrite + // sphere code's own numbers, tuned by eye on THIS player rig and confirmed by playtest + // before the borrowed-eye-light rewrite - the one measurement in this file that is + // actually expressed in the right units to begin with. + private const float BaseEyeForward = 0.081f; + private const float BaseEyeHeight = 0.181f; + private const float BaseEyeSeparation = 0.032f; + // ─── Race check ───────────────────────────────────────────────────── /// @@ -412,20 +426,47 @@ namespace RacesOfValheim frame.SourceModel = modelName; frame.FlatShader = AswidConfig.EyeFlatColorShader.Value; + // canonicalToFrame turns "face forward, as authored" into "face forward, on THIS + // rig's own axes" - the rotation that carries the ordinary (X,Y,Z) convention onto + // (frame.LocalRight, frame.LocalUp, frame.LocalForward). Used for the socket's base + // facing below; NOT used for position - see BaseEyeForward/Height/Separation for why. + Quaternion canonicalToFrame = Quaternion.LookRotation(frame.LocalForward, frame.LocalUp); + foreach (Transform source in sources) { GameObject eye = Object.Instantiate(source.gameObject, holder.transform); eye.name = source.name; + // LEFT vs RIGHT read from the source object's own name, not from list order - + // "eye_l"/"eye_r" is the actual contract FindSourceEyes matches against; the order + // GetComponentsInChildren happens to walk the source hierarchy in is not. + float side = source.name.ToLowerInvariant().Contains("_l") ? -1f : 1f; + + // Placed from the player's own measured frame and three fixed constants, NOT from + // source.localPosition. The borrowed position is authored on the Skeleton + // creature's own rig, at whatever scale that rig happens to use at the eye bone - + // measured at 0.02 lossy scale against this player rig's ~95-100, and nothing ties + // one prefab's rig scale to another's, so there is no reliable factor to correct + // it by. Taken as-is (even after fixing which axis is which) it put the eyes + // roughly 0.2 world units off the head bone - visibly floating above the face. + Vector3 basePosition = frame.LocalForward * BaseEyeForward + + frame.LocalUp * BaseEyeHeight + + frame.LocalRight * (side * BaseEyeSeparation); + + // The socket's own authored tilt is skipped for the same reason its position is - + // canonicalToFrame alone (face forward, on this rig's axes) is what the config's + // twist then nudges from in PlaceEyes. + Quaternion baseRotation = canonicalToFrame; + // Remembered before anything moves it, because everything the config does is // expressed as a delta on this. EyeBase authored = eye.AddComponent(); - authored.Position = source.localPosition; - authored.Rotation = source.localRotation; + authored.Position = basePosition; + authored.Rotation = baseRotation; authored.Scale = source.localScale; - eye.transform.localPosition = source.localPosition; - eye.transform.localRotation = source.localRotation; + eye.transform.localPosition = basePosition; + eye.transform.localRotation = baseRotation; eye.transform.localScale = source.localScale; // Allowlist, not a blocklist - the same rule the skeleton's own glow and the head From cb69d3af3e79862e5904b4f60ec3c220643f77d1 Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 12 Aug 2026 16:25:51 +0200 Subject: [PATCH 3/3] fix(aswid): land the borrowed eye sockets on the face, and make the sliders able to say so Scale is inherited, so source.localScale could not come across either: it is authored under a parent that puts the object at 0.02 lossy scale, and re-parenting it under a head bone at ~95 drew the mesh some 4750x too big - an eye the size of the character, centred near the face, therefore mostly inside the skull with the corners reading as flat rectangles. "Wrong place" and "blocky" were one scale error seen from two angles. Carries lossyScale (the size the game actually draws it at on a real skeleton) over the new parent's scale instead. The remaining offset would not compute cleanly from either rig, so it was dialled in on screen and written down as the new defaults rather than guessed at again - size 1.1, forward 0.01, separation 0.007, yaw 24.664, roll -180 (the socket arrives upside down on a player's head bone; that is the half turn that rights it). The sliders that found those numbers could not have: they were bound at +/-0.1 m and 0.1-5x, nowhere near far enough to pull the pair out of the skull, so they read as doing nothing at all. Widened to +/-0.5 m and 0.01-50x. Eye Rotation Y is now mirrored - the left eye takes the negative - so the pair toes in or out together instead of both turning off the same shoulder. X and Z stay shared on purpose: both eyes pitching up is a face looking up, where mirroring pitch or roll would cross them. Confirmed correct in game. --- JotunnModStub/Aswid/AswidConfig.cs | 51 ++++++++++++++++------- JotunnModStub/Aswid/AswidVisuals.cs | 63 +++++++++++++++++++++++------ 2 files changed, 87 insertions(+), 27 deletions(-) diff --git a/JotunnModStub/Aswid/AswidConfig.cs b/JotunnModStub/Aswid/AswidConfig.cs index c4091c3..34f9741 100644 --- a/JotunnModStub/Aswid/AswidConfig.cs +++ b/JotunnModStub/Aswid/AswidConfig.cs @@ -242,28 +242,49 @@ namespace RacesOfValheim new ConfigDescription("How bright the final-stage red burns - the single knob for it, since the hue is already pure. Expect a floor: below the bloom threshold the eyes stop glowing and become flat dots.", new AcceptableValueRange(0f, 3f), new ConfigurationManagerAttributes { Order = 87 })); - EyeSizeMultiplier = config.Bind(eyes, "Eye Size Multiplier", 1f, - new ConfigDescription("Scales both sockets. 1 is the size the source creature wears them at.", - new AcceptableValueRange(0.1f, 5f), new ConfigurationManagerAttributes { Order = 80 })); + // ─── Ranges are deliberately wide ──────────────────────────────── + // These started at +/-0.1 m and 0.1-5x, on the assumption that the borrowed sockets + // land close to right and only need nudging. They do not, and a slider that cannot + // reach the correct value is worse than no slider - it looks like the setting does not + // work. Wide enough to dig the pair out of the skull from any starting point, and to + // find the right size by eye when the source model's own scale does not transfer. + // Every one of these is live: the eye ticker reapplies them each frame, so a drag in + // Configuration Manager moves them while you watch. - EyeForwardOffset = config.Bind(eyes, "Eye Forward Offset", 0f, - new ConfigDescription("Moves both eyes out of (or into) the face. 0 leaves them where the source creature wears them.", - new AcceptableValueRange(-0.1f, 0.1f), new ConfigurationManagerAttributes { Order = 70 })); + // ─── The defaults below were found in game, not derived ────────── + // The borrowed sockets do not arrive on the face by themselves: their authored pose + // and scale belong to the Skeleton's own rig and none of it transfers cleanly to a + // player armature (see AswidVisuals.BuildEyes for what does and does not carry over). + // Four attempts to compute the remainder each missed, so it was dialled in on screen + // instead and the answer written down here. That is what these seven numbers are - a + // measurement, not a taste. Treat them as the working baseline: a fresh install lands + // on a correct face, and the sliders are then free to be about taste again. + // + // The -180 on Z is the honest shape of it: the socket arrives upside down relative to + // the player's head bone, and this is the half turn that rights it. + + EyeSizeMultiplier = config.Bind(eyes, "Eye Size Multiplier", 1.1f, + new ConfigDescription("Scales both sockets. 1 is the size the source creature wears them at.", + new AcceptableValueRange(0.01f, 50f), new ConfigurationManagerAttributes { Order = 80 })); + + EyeForwardOffset = config.Bind(eyes, "Eye Forward Offset", 0.01f, + new ConfigDescription("Moves both eyes out of (or into) the face, in metres. Positive is forward, out of the skull.", + new AcceptableValueRange(-0.5f, 0.5f), new ConfigurationManagerAttributes { Order = 70 })); EyeHeightOffset = config.Bind(eyes, "Eye Height Offset", 0f, - new ConfigDescription("Moves both eyes up or down the face.", - new AcceptableValueRange(-0.1f, 0.1f), new ConfigurationManagerAttributes { Order = 69 })); - EyeSeparationOffset = config.Bind(eyes, "Eye Separation Offset", 0f, - new ConfigDescription("Pushes the two eyes apart (or together). Each moves away from the centre of the face, so this is half the change in the gap.", - new AcceptableValueRange(-0.1f, 0.1f), new ConfigurationManagerAttributes { Order = 68 })); + new ConfigDescription("Moves both eyes up or down the face, in metres. Positive is up.", + new AcceptableValueRange(-0.5f, 0.5f), new ConfigurationManagerAttributes { Order = 69 })); + EyeSeparationOffset = config.Bind(eyes, "Eye Separation Offset", 0.007f, + new ConfigDescription("Pushes the two eyes apart (or together), in metres. Each moves away from the centre of the face, so this is half the change in the gap.", + new AcceptableValueRange(-0.5f, 0.5f), new ConfigurationManagerAttributes { Order = 68 })); EyeRotationX = config.Bind(eyes, "Eye Rotation X", 0f, new ConfigDescription("Turns both eyes on the spot. Only matters if the borrowed socket is flat enough to be seen edge-on.", new AcceptableValueRange(-180f, 180f), new ConfigurationManagerAttributes { Order = 60 })); - EyeRotationY = config.Bind(eyes, "Eye Rotation Y", 0f, - new ConfigDescription("As above, around the second axis.", + EyeRotationY = config.Bind(eyes, "Eye Rotation Y", 24.664f, + new ConfigDescription("As above, around the second axis - but MIRRORED: the left eye turns the opposite way, so the pair toes in or out together instead of both pointing off the same shoulder.", new AcceptableValueRange(-180f, 180f), new ConfigurationManagerAttributes { Order = 59 })); - EyeRotationZ = config.Bind(eyes, "Eye Rotation Z", 0f, - new ConfigDescription("As above, around the third axis.", + EyeRotationZ = config.Bind(eyes, "Eye Rotation Z", -180f, + new ConfigDescription("As above, around the third axis. The default half turn is what rights the borrowed socket, which arrives upside down on a player's head bone.", new AcceptableValueRange(-180f, 180f), new ConfigurationManagerAttributes { Order = 58 })); EyeSmoke = config.Bind(eyes, "Eye Smoke", true, diff --git a/JotunnModStub/Aswid/AswidVisuals.cs b/JotunnModStub/Aswid/AswidVisuals.cs index 45bd46e..47f9453 100644 --- a/JotunnModStub/Aswid/AswidVisuals.cs +++ b/JotunnModStub/Aswid/AswidVisuals.cs @@ -312,11 +312,6 @@ namespace RacesOfValheim Vector3 shift = frame.LocalForward * (AswidConfig.EyeForwardOffset.Value * scale) + frame.LocalUp * (AswidConfig.EyeHeightOffset.Value * scale); - Quaternion twist = Quaternion.Euler( - AswidConfig.EyeRotationX.Value, - AswidConfig.EyeRotationY.Value, - AswidConfig.EyeRotationZ.Value); - for (int i = 0; i < holder.childCount; i++) { Transform eye = holder.GetChild(i); @@ -329,6 +324,19 @@ namespace RacesOfValheim float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight)); if (side == 0f) side = i == 0 ? -1f : 1f; + // YAW IS MIRRORED, the other two are not. Turning both eyes the same way on Y + // makes the pair look sideways - both point off the same shoulder, because a face + // is symmetric about its centre line and yaw is the axis that crosses it. Negating + // it on the left eye turns them out from (or in towards) the nose together, which + // is what "toe them in a bit" actually means on a pair of eyes. + // + // Pitch and roll are shared deliberately: both eyes looking up is a face looking + // up, and mirroring either of those would cross them instead of aiming them. + Quaternion twist = Quaternion.Euler( + AswidConfig.EyeRotationX.Value, + AswidConfig.EyeRotationY.Value * side, + AswidConfig.EyeRotationZ.Value); + eye.localPosition = authored.Position + shift + frame.LocalRight * (side * AswidConfig.EyeSeparationOffset.Value * scale); eye.localRotation = twist * authored.Rotation; @@ -395,6 +403,11 @@ namespace RacesOfValheim List sources = FindSourceEyes(modelName); if (sources.Count == 0) return null; // already logged once by the finder + // The placement below divides by this, and the rig reports 0 for a frame or two while + // it is still coming up. Returning null costs nothing - ApplyEyes calls again next + // tick - where dividing by it would put the pair somewhere unrecoverable. + if (Mathf.Abs(headBone.lossyScale.x) < 0.0001f) return null; + // Anything of ours left anywhere else on this player goes first. ApplyEyes only ever // looks under the head bone, so a holder that ended up on some other transform is // invisible to it - it would build a second pair beside the wrong one rather than @@ -447,27 +460,53 @@ namespace RacesOfValheim // creature's own rig, at whatever scale that rig happens to use at the eye bone - // measured at 0.02 lossy scale against this player rig's ~95-100, and nothing ties // one prefab's rig scale to another's, so there is no reliable factor to correct - // it by. Taken as-is (even after fixing which axis is which) it put the eyes - // roughly 0.2 world units off the head bone - visibly floating above the face. - Vector3 basePosition = frame.LocalForward * BaseEyeForward - + frame.LocalUp * BaseEyeHeight - + frame.LocalRight * (side * BaseEyeSeparation); + // it by. In game it landed 0.22 m straight up from the head bone and barely any + // forward, where 0.181 up / 0.081 forward is the face - eyes above the skull. + // + // THE / lossyScale IS NOT OPTIONAL. The constants are world metres; localPosition + // is in the head bone's own space, which the armature authors at ~95-100x. Setting + // them without this term puts the eyes 0.081 x 95 = 7.7 m out - off the model + // entirely and invisible, which is exactly what dropping this term did once + // already. PlaceEyes applies the config offsets through the same 1/lossy factor + // for the same reason, and the pre-rewrite sphere code always had it. + float toLocal = 1f / headBone.lossyScale.x; + + Vector3 basePosition = frame.LocalForward * (BaseEyeForward * toLocal) + + frame.LocalUp * (BaseEyeHeight * toLocal) + + frame.LocalRight * (side * BaseEyeSeparation * toLocal); // The socket's own authored tilt is skipped for the same reason its position is - // canonicalToFrame alone (face forward, on this rig's axes) is what the config's // twist then nudges from in PlaceEyes. Quaternion baseRotation = canonicalToFrame; + // SCALE IS INHERITED, so the authored localScale cannot come across either. + // + // source.localScale is authored under the Skeleton's own parent chain, which puts + // that object at 0.02 lossy scale in the world. Re-parented under a head bone at + // ~95 and left alone, the same number renders the mesh some 4750x too big: an eye + // the size of the character, centred near the face, therefore mostly INSIDE the + // skull, with the corners that clear it reading as flat rectangles rather than as + // eyes. That is one bug with two faces - "wrong place" and "blocky" were the same + // scale error seen from outside and from in front. + // + // lossyScale (world) rather than localScale (relative to a parent we do not have) + // is the honest quantity to carry over: it is the size the game actually draws + // this object at on a real skeleton. Divided into the new parent's scale, the pair + // lands at exactly the size vanilla wears them, which is the whole point of + // borrowing them instead of drawing spheres. + Vector3 baseScale = source.lossyScale * toLocal; + // Remembered before anything moves it, because everything the config does is // expressed as a delta on this. EyeBase authored = eye.AddComponent(); authored.Position = basePosition; authored.Rotation = baseRotation; - authored.Scale = source.localScale; + authored.Scale = baseScale; eye.transform.localPosition = basePosition; eye.transform.localRotation = baseRotation; - eye.transform.localScale = source.localScale; + eye.transform.localScale = baseScale; // Allowlist, not a blocklist - the same rule the skeleton's own glow and the head // flame are cloned under. Whatever rode along goes, whatever type it turns out to