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 8d041f9..47f9453 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 ───────────────────────────────────────────────────── /// @@ -298,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); @@ -315,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; @@ -381,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 @@ -396,7 +423,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)); @@ -404,21 +439,74 @@ 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. 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 = source.localPosition; - authored.Rotation = source.localRotation; - authored.Scale = source.localScale; + authored.Position = basePosition; + authored.Rotation = baseRotation; + authored.Scale = baseScale; - eye.transform.localPosition = source.localPosition; - eye.transform.localRotation = source.localRotation; - eye.transform.localScale = source.localScale; + eye.transform.localPosition = basePosition; + eye.transform.localRotation = baseRotation; + 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 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));