feat(eyes): per-eye sliders, Aswid female defaults from playtest

Each Eyes Position section now has a set per body and per eye (the
character's own left and right), because the face is not symmetric enough for
one set to fit both eyes. The Aswid female defaults are the per-eye values
dialled in on screen; Alfar and Dvergar copy their female values to both eyes.
The old shared keys are dropped: they only ever existed in test builds.
This commit is contained in:
kanym 2026-10-27 16:03:24 +01:00
commit 132d7e034f
5 changed files with 124 additions and 100 deletions

View file

@ -186,24 +186,6 @@ namespace RacesOfValheim
float size = AlfarConfig.EyeSizeMultiplier.Value; float size = AlfarConfig.EyeSizeMultiplier.Value;
PlayerFace.AdjustEyes(player, ref height, ref separation, ref size); PlayerFace.AdjustEyes(player, ref height, ref separation, ref size);
float forward = AlfarConfig.EyeForward;
float wrap = AlfarConfig.EyeWrap;
float slant = AlfarConfig.EyeSlant;
float tilt = 0f;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(AlfarConfig.RaceId, player);
if (tuning != null)
{
forward += tuning.Forward.Value;
height += tuning.Height.Value;
separation += tuning.Separation.Value;
size *= tuning.Size.Value;
tilt = tuning.RotX;
wrap += tuning.RotY;
slant += tuning.RotZ;
}
Vector3 baseOffset = frame.LocalForward * forward + frame.LocalUp * height;
Vector3 extent = AlfarConfig.EyeExtent * (size * toLocal);
Quaternion facing = Quaternion.LookRotation(frame.LocalForward, frame.LocalUp); Quaternion facing = Quaternion.LookRotation(frame.LocalForward, frame.LocalUp);
for (int i = 0; i < holder.childCount; i++) for (int i = 0; i < holder.childCount; i++)
@ -213,11 +195,33 @@ namespace RacesOfValheim
// Index 0 is offset against the right axis, so it is the model's left eye. The // Index 0 is offset against the right axis, so it is the model's left eye. The
// slant and the wrap are mirrored so both outer corners go up and back. // slant and the wrap are mirrored so both outer corners go up and back.
float side = i == 0 ? -1f : 1f; float side = i == 0 ? -1f : 1f;
Vector3 offset = baseOffset + frame.LocalRight * (side * separation);
// This eye's sliders from "Eyes Position - Alfar".
float forward = AlfarConfig.EyeForward;
float eyeHeight = height;
float eyeSeparation = separation;
float eyeSize = size;
float wrap = AlfarConfig.EyeWrap;
float slant = AlfarConfig.EyeSlant;
float tilt = 0f;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(AlfarConfig.RaceId, player, side);
if (tuning != null)
{
forward += tuning.Forward.Value;
eyeHeight += tuning.Height.Value;
eyeSeparation += tuning.Separation.Value;
eyeSize *= tuning.Size.Value;
tilt = tuning.RotX;
wrap += tuning.RotY;
slant += tuning.RotZ;
}
Vector3 offset = frame.LocalForward * forward + frame.LocalUp * eyeHeight
+ frame.LocalRight * (side * eyeSeparation);
eye.localPosition = offset * toLocal; eye.localPosition = offset * toLocal;
eye.localRotation = facing * Quaternion.Euler(tilt, wrap * side, slant * side); eye.localRotation = facing * Quaternion.Euler(tilt, wrap * side, slant * side);
eye.localScale = extent; eye.localScale = AlfarConfig.EyeExtent * (eyeSize * toLocal);
} }
} }

View file

@ -320,16 +320,6 @@ namespace RacesOfValheim
float scale = GetPlayerScale(player) * toLocal; float scale = GetPlayerScale(player) * toLocal;
// The per-body sliders of "Eyes Position - Aswid", on top of the race's own offsets.
EyePositionConfig.Tuning tuning = EyePositionConfig.For("Aswid", player);
float forward = AswidConfig.EyeForwardOffset.Value + (tuning != null ? tuning.Forward.Value : 0f);
float height = AswidConfig.EyeHeightOffset.Value + (tuning != null ? tuning.Height.Value : 0f);
float separation = AswidConfig.EyeSeparationOffset.Value + (tuning != null ? tuning.Separation.Value : 0f);
float size = AswidConfig.EyeSizeMultiplier.Value * (tuning != null ? tuning.Size.Value : 1f);
Vector3 shift = frame.LocalForward * (forward * scale)
+ frame.LocalUp * (height * scale);
for (int i = 0; i < holder.childCount; i++) for (int i = 0; i < holder.childCount; i++)
{ {
Transform eye = holder.GetChild(i); Transform eye = holder.GetChild(i);
@ -342,6 +332,16 @@ namespace RacesOfValheim
float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight)); float side = Mathf.Sign(Vector3.Dot(authored.Position, frame.LocalRight));
if (side == 0f) side = i == 0 ? -1f : 1f; if (side == 0f) side = i == 0 ? -1f : 1f;
// This eye's sliders from "Eyes Position - Aswid", on top of the race's own offsets.
EyePositionConfig.Tuning tuning = EyePositionConfig.For("Aswid", player, side);
float forward = AswidConfig.EyeForwardOffset.Value + (tuning != null ? tuning.Forward.Value : 0f);
float height = AswidConfig.EyeHeightOffset.Value + (tuning != null ? tuning.Height.Value : 0f);
float separation = AswidConfig.EyeSeparationOffset.Value + (tuning != null ? tuning.Separation.Value : 0f);
float size = AswidConfig.EyeSizeMultiplier.Value * (tuning != null ? tuning.Size.Value : 1f);
Vector3 shift = frame.LocalForward * (forward * scale)
+ frame.LocalUp * (height * scale);
// YAW IS MIRRORED, the other two are not. Turning both eyes the same way on Y // 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 // 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 // is symmetric about its centre line and yaw is the axis that crosses it. Negating

View file

@ -283,21 +283,6 @@ namespace RacesOfValheim
float eyeSize = DvergarConfig.EyeSize; float eyeSize = DvergarConfig.EyeSize;
PlayerFace.AdjustEyes(player, ref height, ref separation, ref eyeSize); PlayerFace.AdjustEyes(player, ref height, ref separation, ref eyeSize);
float forward = DvergarConfig.EyeForward;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(DvergarConfig.RaceId, player);
if (tuning != null)
{
forward += tuning.Forward.Value;
height += tuning.Height.Value;
separation += tuning.Separation.Value;
eyeSize *= tuning.Size.Value;
}
Vector3 baseLocal = localForward * (forward * raceScale * toLocal)
+ localUp * (height * raceScale * toLocal);
float eyeLocalSize = eyeSize * raceScale * toLocal;
for (int i = 0; i < holder.childCount; i++) for (int i = 0; i < holder.childCount; i++)
{ {
Transform eye = holder.GetChild(i); Transform eye = holder.GetChild(i);
@ -307,9 +292,25 @@ namespace RacesOfValheim
// curved and the two sides do not present the same surface to a ball of this // curved and the two sides do not present the same surface to a ball of this
// radius. // radius.
float side = i == 0 ? -1f : 1f; float side = i == 0 ? -1f : 1f;
float size = i == 0 ? eyeLocalSize * DvergarConfig.LeftEyeSizeMultiplier : eyeLocalSize;
eye.localPosition = baseLocal + localRight * (side * separation * raceScale * toLocal); // This eye's sliders from "Eyes Position - Dvergar".
float forward = DvergarConfig.EyeForward;
float eyeHeight = height;
float eyeSeparation = separation;
float size = eyeSize * raceScale * toLocal;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(DvergarConfig.RaceId, player, side);
if (tuning != null)
{
forward += tuning.Forward.Value;
eyeHeight += tuning.Height.Value;
eyeSeparation += tuning.Separation.Value;
size *= tuning.Size.Value;
}
if (i == 0) size *= DvergarConfig.LeftEyeSizeMultiplier;
eye.localPosition = localForward * (forward * raceScale * toLocal)
+ localUp * (eyeHeight * raceScale * toLocal)
+ localRight * (side * eyeSeparation * raceScale * toLocal);
eye.localScale = Vector3.one * size; eye.localScale = Vector3.one * size;
} }
} }

View file

@ -5,10 +5,13 @@ namespace RacesOfValheim
{ {
/// <summary> /// <summary>
/// Hand placement for every race that hangs eyes on the face: one "Eyes Position - race" /// Hand placement for every race that hangs eyes on the face: one "Eyes Position - race"
/// section each, with a female and a male set, because the two bodies put their painted eyes /// section each, with a set of sliders per body and per eye. Per body because the two bodies
/// in different places (PlayerFace). Every value is a delta on the placement the race's own /// put their painted eyes in different places (PlayerFace); per eye because the face is not
/// code computes: all zeros (and size 1) is the code's own placement, and the female /// symmetric enough for one set to fit both. Left and right are the character's own.
/// defaults below are the corrections found in game on top of it. ///
/// Every value is a delta on the placement the race's own code computes: all zeros (and size
/// 1) is the code's own placement, and the female defaults below are the corrections found in
/// game on top of it.
/// ///
/// Local, never synced (ConfigSync): it only changes how this client draws faces. /// Local, never synced (ConfigSync): it only changes how this client draws faces.
/// </summary> /// </summary>
@ -16,7 +19,7 @@ namespace RacesOfValheim
{ {
public const string SectionPrefix = "Eyes Position - "; public const string SectionPrefix = "Eyes Position - ";
/// <summary>One body's sliders for one race.</summary> /// <summary>One eye's sliders, for one body of one race.</summary>
public sealed class Tuning public sealed class Tuning
{ {
public ConfigEntry<float> Forward; public ConfigEntry<float> Forward;
@ -34,74 +37,89 @@ namespace RacesOfValheim
public float RotZ => RotationZ != null ? RotationZ.Value : 0f; public float RotZ => RotationZ != null ? RotationZ.Value : 0f;
} }
// [race] -> { male, female } // [race] -> { male left, male right, female left, female right }
private static readonly Dictionary<string, Tuning[]> tunings = new Dictionary<string, Tuning[]>(); private static readonly Dictionary<string, Tuning[]> tunings = new Dictionary<string, Tuning[]>();
public static void Bind(ConfigFile config) public static void Bind(ConfigFile config)
{ {
// Female defaults dialled in on screen (playtest, 2026-10-27). The male ones are // Female defaults dialled in on screen (playtest, 2026-10-27). The male ones are
// still the code's own placement; the Sverm's helmet hides its eyes, so it keeps it. // still the code's own placement; the Sverm's helmet hides its eyes, so it keeps it.
BindRace(config, AlfarConfig.RaceId, true, Defaults alfar = new Defaults { Separation = 0.006f, RotX = -17.524f };
new Defaults { Separation = 0.006f, RotX = -17.524f }); BindRace(config, AlfarConfig.RaceId, true, alfar, alfar);
BindRace(config, "Aswid", true, BindRace(config, "Aswid", true,
new Defaults { Forward = -0.001f, Height = 0.001f, Separation = 0.006f, Size = 1.061f }); new Defaults { Forward = -0.002f, Height = -0.001f, Separation = 0.003f, Size = 1.142f,
BindRace(config, DvergarConfig.RaceId, false, RotX = 1.298f, RotY = 0.649f },
new Defaults { Forward = -0.011f, Separation = 0.005f, Size = 1.616f }); new Defaults { Forward = -0.001f, Height = -0.001f, Separation = 0.009f, Size = 1.142f,
BindRace(config, SvermConfig.RaceId, false, new Defaults()); RotX = 1.298f, RotY = 0.649f, RotZ = -7.788f });
Defaults dvergar = new Defaults { Forward = -0.011f, Separation = 0.005f, Size = 1.616f };
BindRace(config, DvergarConfig.RaceId, false, dvergar, dvergar);
BindRace(config, SvermConfig.RaceId, false, new Defaults(), new Defaults());
} }
/// <summary>Starting values for one body's sliders.</summary> /// <summary>Starting values for one eye's sliders.</summary>
private sealed class Defaults private sealed class Defaults
{ {
public float Forward, Height, Separation, RotX, RotY, RotZ; public float Forward, Height, Separation, RotX, RotY, RotZ;
public float Size = 1f; public float Size = 1f;
} }
/// <summary>The sliders for the body this player is wearing right now.</summary> /// <summary>
public static Tuning For(string race, Player player) /// The sliders for one eye of the body this player is wearing right now. Side is the
/// races' own convention: negative is offset against the head frame's right axis, which is
/// the character's left eye.
/// </summary>
public static Tuning For(string race, Player player, float side)
{ {
if (!tunings.TryGetValue(race, out Tuning[] pair)) return null; if (!tunings.TryGetValue(race, out Tuning[] set)) return null;
return pair[PlayerFace.IsFemale(player) ? 1 : 0]; return set[(PlayerFace.IsFemale(player) ? 2 : 0) + (side < 0f ? 0 : 1)];
} }
private static void BindRace(ConfigFile config, string race, bool rotation, Defaults female) private static void BindRace(ConfigFile config, string race, bool rotation, Defaults femaleLeft, Defaults femaleRight)
{ {
string section = SectionPrefix + race; string section = SectionPrefix + race;
// Female first in the list, left before right: Order sorts high to low.
tunings[race] = new[] tunings[race] = new[]
{ {
BindBody(config, section, "Male", rotation, 100, new Defaults()), BindEye(config, section, "Male", "Left", rotation, 200, new Defaults()),
BindBody(config, section, "Female", rotation, 200, female), BindEye(config, section, "Male", "Right", rotation, 100, new Defaults()),
BindEye(config, section, "Female", "Left", rotation, 400, femaleLeft),
BindEye(config, section, "Female", "Right", rotation, 300, femaleRight),
}; };
} }
private static Tuning BindBody(ConfigFile config, string section, string body, bool rotation, int order, Defaults d) private static Tuning BindEye(ConfigFile config, string section, string body, string eye, bool rotation, int order, Defaults d)
{ {
// Female first in the list: Order sorts high to low. string prefix = $"{body} {eye} Eye ";
string who = $"{body} characters, {eye.ToLowerInvariant()} eye (the character's own {eye.ToLowerInvariant()})";
Tuning t = new Tuning(); Tuning t = new Tuning();
t.Forward = config.Bind(section, body + " Forward", d.Forward, t.Forward = config.Bind(section, prefix + "Forward", d.Forward,
new ConfigDescription($"{body} characters: moves both eyes out of (+) or into (-) the face, in metres.", new ConfigDescription($"{who}: moves the eye out of (+) or into (-) the face, in metres.",
new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 9 })); new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 9 }));
t.Height = config.Bind(section, body + " Height", d.Height, t.Height = config.Bind(section, prefix + "Height", d.Height,
new ConfigDescription($"{body} characters: moves both eyes up (+) or down (-), in metres.", new ConfigDescription($"{who}: moves the eye up (+) or down (-), in metres.",
new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 8 })); new AcceptableValueRange<float>(-0.05f, 0.05f), new ConfigurationManagerAttributes { Order = order + 8 }));
t.Separation = config.Bind(section, body + " Separation", d.Separation, t.Separation = config.Bind(section, prefix + "Separation", d.Separation,
new ConfigDescription($"{body} characters: pushes the eyes apart (+) or together (-), in metres. Each eye moves by this much.", new ConfigDescription($"{who}: moves the eye away from (+) or toward (-) the nose, in metres.",
new AcceptableValueRange<float>(-0.03f, 0.03f), new ConfigurationManagerAttributes { Order = order + 7 })); new AcceptableValueRange<float>(-0.03f, 0.03f), new ConfigurationManagerAttributes { Order = order + 7 }));
t.Size = config.Bind(section, body + " Size", d.Size, t.Size = config.Bind(section, prefix + "Size", d.Size,
new ConfigDescription($"{body} characters: scales both eyes. 1 is the default size.", new ConfigDescription($"{who}: scales the eye. 1 is the default size.",
new AcceptableValueRange<float>(0.2f, 3f), new ConfigurationManagerAttributes { Order = order + 6 })); new AcceptableValueRange<float>(0.2f, 3f), new ConfigurationManagerAttributes { Order = order + 6 }));
if (rotation) if (rotation)
{ {
t.RotationX = config.Bind(section, body + " Rotation X", d.RotX, t.RotationX = config.Bind(section, prefix + "Rotation X", d.RotX,
new ConfigDescription($"{body} characters: tips both eyes down (+) or up (-), in degrees.", new ConfigDescription($"{who}: tips the eye down (+) or up (-), in degrees.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 5 })); new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 5 }));
t.RotationY = config.Bind(section, body + " Rotation Y", d.RotY, t.RotationY = config.Bind(section, prefix + "Rotation Y", d.RotY,
new ConfigDescription($"{body} characters: turns the eyes toward the temples (+) or the nose (-), in degrees. Mirrored between the two eyes.", new ConfigDescription($"{who}: turns the eye toward the temple (+) or the nose (-), in degrees.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 4 })); new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 4 }));
t.RotationZ = config.Bind(section, body + " Rotation Z", d.RotZ, t.RotationZ = config.Bind(section, prefix + "Rotation Z", d.RotZ,
new ConfigDescription($"{body} characters: raises (+) or lowers (-) the outer corners, in degrees. Mirrored between the two eyes.", new ConfigDescription($"{who}: raises (+) or lowers (-) the outer corner, in degrees.",
new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 3 })); new AcceptableValueRange<float>(-90f, 90f), new ConfigurationManagerAttributes { Order = order + 3 }));
} }

View file

@ -256,30 +256,31 @@ namespace RacesOfValheim
float eyeSize = EyeSize; float eyeSize = EyeSize;
PlayerFace.AdjustEyes(player, ref height, ref separation, ref eyeSize); PlayerFace.AdjustEyes(player, ref height, ref separation, ref eyeSize);
float forward = EyeForward;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(SvermConfig.RaceId, player);
if (tuning != null)
{
forward += tuning.Forward.Value;
height += tuning.Height.Value;
separation += tuning.Separation.Value;
eyeSize *= tuning.Size.Value;
}
Vector3 baseLocal = frame.LocalForward * (forward * scale * toLocal)
+ frame.LocalUp * (height * scale * toLocal);
float eyeLocalSize = eyeSize * scale * toLocal;
for (int i = 0; i < holder.childCount; i++) for (int i = 0; i < holder.childCount; i++)
{ {
Transform eye = holder.GetChild(i); Transform eye = holder.GetChild(i);
// Index 0 is offset against the right axis, so it is the model's left eye. // Index 0 is offset against the right axis, so it is the model's left eye.
float side = i == 0 ? -1f : 1f; float side = i == 0 ? -1f : 1f;
float size = i == 0 ? eyeLocalSize * LeftEyeSizeMultiplier : eyeLocalSize;
eye.localPosition = baseLocal + frame.LocalRight * (side * separation * scale * toLocal); // This eye's sliders from "Eyes Position - Sverm".
float forward = EyeForward;
float eyeHeight = height;
float eyeSeparation = separation;
float size = eyeSize * scale * toLocal;
EyePositionConfig.Tuning tuning = EyePositionConfig.For(SvermConfig.RaceId, player, side);
if (tuning != null)
{
forward += tuning.Forward.Value;
eyeHeight += tuning.Height.Value;
eyeSeparation += tuning.Separation.Value;
size *= tuning.Size.Value;
}
if (i == 0) size *= LeftEyeSizeMultiplier;
eye.localPosition = frame.LocalForward * (forward * scale * toLocal)
+ frame.LocalUp * (eyeHeight * scale * toLocal)
+ frame.LocalRight * (side * eyeSeparation * scale * toLocal);
eye.localScale = Vector3.one * size; eye.localScale = Vector3.one * size;
} }
} }