Deforming a Skyrim SE mustache: TRIs & NIFs
In Skyrim Special Edition, TRI files are used to indicate to the game how to deform a mesh, housed in a NIF file. Notable uses are deforming a beard (e.g. beard.nif) designed for human jaws to fit elven jaws (i.e. beardRaces.tri), deforming said beard during the generation of the player character (i.e. beardChargen.tri), and when characters speak or emote (i.e. beard.tri).
Without the TRI files, the game can load the meshes fine, but they will be static. Below is a procedure I found worked (for SSE in 2020) for creating the basic TRI file for a mod-derived NIF file, using nothing more than OutfitStudio and the Creation Kit (not the CharGen, nor the Races, just the base TRI file). The TRI and the NIF must have the same vertex number and numbering. So it is recommended to derive the TRI from the NIF. There are tools to correct externally a mismatch (e.g. Blender can renumber vertices in an OBJ), but it is quite the hassle.
For additional coverage, see https://wiki.nexusmods.com/index.php/Working_with_Skyrim_head_TRIs
- OutfitStudio, comes with BodySlide and is available at https://www.nexusmods.com/skyrimspecialedition/mods/201
- The CreationKit is available through the Bethesda launcher, from https://bethesda.net (Bethesda account may be required)
- Sample mod, BeasthHHBB available at https://www.nexusmods.com/skyrimspecialedition/mods/38480
Let's take as example one of the files in the mod Beast Hair Horn Beard and Brow (BeastHHBB), specifically the file
mustachebrow2.nif is light and easy to check if it is moving. As of this writing, it doesn't come with a TRI file, so the mustache remains static even when the character wearing it is gesticulating.
In OutfitStudio, File -> Import -> From NIF mustachebrow2.nif and the shape
ArgonianMaleHorns09 appears. It is mostly feathers, arranged as a mustache. This is the static mesh we are going to "animate". OutfitStudio supports importing TRI files, and the transforms end up represented as sliders in OutfitStudio. What we want therefore is a Reference file that contains all the relevant TRI data to generate our sliders.
One such file, for female Argonians, can be found at:
File -> Import -> From TRI (head) that file, and the shape
femaleheadargonian appears in the meshes pane.
The sliders should appear for the various emotes, phonemes, and expressions in the slider pane (e.g.
The (untextured?) head appears near the 0,0,0 origin, below the feather mesh. Using the OutfitStudio gizmo (aka transform tool), we can move the feather shape down and forward so it rests on the reference head as one would expect. Good positioning is important for the Conformation step.
Make sure the shape
femaleheadargonian is selected in the Meshes pane, then in the Shape menu, click Make Reference. The shape's name should now be in green font, instead of white.
Click the feather shape
AronianMaleHorns09, make sure all the Sliders are checked (i.e.
BigAah, etc), then Slider menu -> Conform Selected. The "Conforming..." dialogue opens and asks for settings. I found the default worked OK, but I'm sure those can be refined.The Conform step uses euclidean distance to map vertices from the reference to the selected shape, so if they're too far, they'll map incorrectly. We don't want all the vertices of the mustache thinking their closest vertex on the reference is at the top of the head.
Conforming takes a bit of time depending on geometry complexity, and once it's finished, moving any of the sliders will deform both reference head AND the feather mesh. Try
BigAah set to 100% and the bottom of the mustache should deform and track the jaw, but the top of the mustache should stay where the nose is.
Now that we have a working morph, we can export it as a TRI. Right-click the shape we just conformed, Export -> To TRI(HEAD), and put that in the same directory where the relevant NIF is located. If the NIF was in
Meshes\hair\mustachebrow2.nif then the TRI should end up in
If the files are not in the same directory, even if their paths are properly declared to the Plugin's records, Skyrim may or may not fail to use the TRI properly. I do not know why this fails, but only sometimes. Regardless, it seems good practice to keep the NIFs and TRIs together.
At this point, you should have a NIF (with proper Z & X coordinates), as well as the TRI derived from that mesh. Now the easy part is creating the HeadPart and putting that into an Argonian somewhere.
Fire up the CreationKit
- Create a HeadPart, set stuff (type: facial hair, races: headpartsargonian, unisex), use as Model the NIF from above, as TRI the associated TRI (which auto-populates if the name's right)
- Create an Actor, set stuff (race: Argonian), over to CharGenParts and FacialHair whatever you created above, check the Head Preview, and there you have it, a moustachioed lizard. Head over to FaceAnimPreview, and the Expression:DialogueDisgusted -> DialogueAnger shows compaction of the mustache along the Z axis (and importantly, no meshplosion, which happens when the vertex numbering is inconsistent between TRI and NIF)
Sometimes when exporting a shape to NIF via Right Click -> Export -> to NIF (without reference) the resulting NIF may be cryptically invalid. It will contain the XML data structure, and some vertex information, but when viewed in NifSkope or the CreationKit, the camera defaults to 0,0,0 and there isn't a visible mesh. I've had better luck using File -> Export -> to NIF (without reference) in such cases.
If when morphing the mesh in the CreationKit, the mesh explodes with crazy geometry going everywhere (i.e. a meshsplotion), I've found a frequent culprit is a mismatch between the vertex numbering of the NIF and the TRI; re-exporiting the NIF (or the TRI...) can solve that issue.
The mustache is at the character's feet. You must have exported the NIF after moving it to match the reference head. Revert the file, or if all's lost, just load some other argonian head (e.g. any of the ones in the FaceGeom subfolder inside Meshes) and manually align it again.
NifSkope opens the mesh fine, but the CreationKit doesn't. I found some meshes may have been too large for the CK's preview pane work well. Some of those worked in game, but not in the CK's preview. Regardless, it may be a good idea to break up the mesh into smaller meshes, and use those as Extra Parts. Once can define one HeadPart, and then tack onto it Extra Parts in the Actor definition. Since each part is simpler, the part preview is less burdened, and in my experience works more reliably.