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.
This commit is contained in:
parent
982e88fa57
commit
cb69d3af3e
2 changed files with 86 additions and 26 deletions
|
|
@ -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<Transform> 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<EyeBase>();
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue