Utility for applying an "animal ear" morph set to a character. It prepares the shared human ear rig when needed and applies up to seven morph targets to a skinned model renderer based on appearance weights.
using System;
namespace CharacterEditor;
/// <summary>Authored whole-pinna targets on the shared human rig.</summary>
public static class AnimalEarShape
{
public const string MorphPrefix = "ce_animal_human";
// Older unblended bodies do not contain the authored ear targets. Only this
// new endpoint opts into the shared rig; legacy Human/Goblin/Elf stay exact.
public static void Prepare(CharacterAppearanceData appearance)
{
if (appearance?.BaseShape is null && appearance?.EarBlend is { Valid: true }
&& EarShapes.Weights(appearance).z > 0)
UnifiedHuman.Enable(appearance);
}
public static void Apply(SkinnedModelRenderer body, CharacterAppearanceData appearance)
{
if (appearance.BaseShape is null) return;
float amount = EarShapes.Weights(PhotoFace.ApplyOffsets(appearance)).z;
var weights = FaceRegions.Weights(appearance.BaseShape, "ears");
for (int i = 0; i < 7; i++)
body.Morphs.Set($"{MorphPrefix}{i + 1:00}", weights[i] * amount, 0);
}
}