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