User:Thingy Person

The Beyond Skyrim Wiki — Hosted by UESP
Revision as of 23:20, 31 May 2022 by Thingy Person (talk | contribs) (Custom animated object idles)
Jump to: navigation, search

All credit to Jonahex

Tools

1. ck-cmd. Not earlier than May 2022 build is required for custom creature implementation. Can be downloaded from github. Either download latest build from appveyor artifacts or build if from sources.
ck-cmd is command line tool. Following commands are useful for animation implementation:
1) convert. Used for conversion between binary and xml representation of Havok (.hkx) files.
convert <input file path> -o <output file path> -v WIN32 -f SAVE_DEFAULT — to convert xml to Skyrim LE hkx.
convert <input file path> -o <output file path> -v AMD64 -f SAVE_DEFAULT — to convert xml to Skyrim SE hkx.
convert <input file path> -o <output file path> -f SAVE_TEXT_FORMAT — to convert Skyrim LE hkx to xml.
Fun fact #1: SE hkx can’t be converted back to xml. So, save your xmls!
2) importrig. Used to import skeleton from fbx to nif and hkx.
importrig <input fbx path> -a <animation output folder path> -e <nif output folder path>.
Fun fact #2: skeleton hkx will be saved to folder where ck-cmd.exe is located, no matter which output paths you set.
Fun fact #3: most of the time you don’t need animation output, but you need to set animation output folder anyway, command doesn’t work without it.
3) exportfbx. Used to export nifs back to fbx.
exportfbx <input nif path> -e <output folder path>.
4) importskin. Used to import creature or armor skin from fbx to nif.
importskin <input fbx path> -e <output folder path>.
5) retargetcreature. This command copies creature Havok project replacing creature name in all instances where it’s needed and creates esp with idles, sound descriptors and movement types for new creature.
retargetcreature <path to source creature file in meshes\animationdata> <path to source creature Havok project folder> <new creature name> -s <Skyrim LE folder path>.
Fun fact #4: there is no output folder argument. All output is stored in ck-cmd folder. It includes animationdata and animationsetdata folders, animationdatasinglefile.txt, animationsetdatasinglefile.txt and <new creature name> folder with new Havok project.
Fun fact #5: well, actually not all. Esp is stored in your Skyrim LE Data folder.
6) importanimation. Used to export fbx animations to hkx.
importanimation <path to skeleton hkx file> <path to fbx animation file or folder with animations> --b=<path to creature behavior folder> --c=<path to your creature animation cache file, i.e., animationdata\<your creature’s name>project.txt> --e=<output animations folder>.
Fun fact #6: but output animationdata and animationsetdata folders, animationdatasinglefile.txt, animationsetdatasinglefile.txt will be stored in ck-cmd folder!
Fun fact #7: though they won’t be generated if in --b argument <your creature’s name>project.txt contains uppercase letters.
And the final ck-cmd fun fact: if you any of folder paths in commands with slash, commands don’t work.
2. Skyrim Behavior Tool. GUI tool for behavior editing. Download it from github.

Preparation

For any animations work you need Skyrim LE Havok projects and animation cache. So, extract Skyrim – Animations.bsa. It contains all Havok projects in game, animationdata and animationsetdata folders and animationdatasinglefile.txt, animationsetdatasinglefile.txt files. For manual editing of behaviors you can further convert Havok files to xml with ck-cmd.

Custom animated creature implementation

Let’s say you have custom creature modelled and animated, and animations follow one of existing creatures which we will call donor. You need to prepare following files:

1. Skinned mesh in fbx. You will save a lot of headaches if your creature is aligned in +Y direction and skeleton root bone is at origin.
2. Skeleton with collision in fbx.
3. Animations in separate fbxs.

This is what you need to do to implement it:

1. Use ck-cmd importskin command to import skin fbx to nif. Rename root bone in imported nif to NPC Root [Root].
2. Use ck-cmd importrig command to import skeleton fbx to nif and hkx.
3. Use ck-cmd retargetcreature command to copy donor Havok project.

Custom animations 1.png

4. Construct bone pair map. Bone pair map is list of numbers in which item with index n is index of n-th bone mirrored pair. Bone pair map is needed for mirrored animations to work. For example, if your skeleton includes the following bones: root, pelvis, leg_left, leg_right, your bone pair maps is 0, 1, 3, 2. In retargeted Havok project find Characters\<creature name>Character.hkx, find there hkobject hkbMirroredSkeletonInfo, in which find parameter bonePairMap. Replace list there with your bone pair map.
Note that editing something in hkx means first converting it to xml, editing xml and then converting back to hkx.
5. Use ck-cmd importanimation command to import fbx animations to hkx. It’s necessary to set --b argument to donor behavior folder, and --c argument to retargeted animated cache file!
6. Now collect all files and put them to relevant locations:
  • animationdata and animationsetdata folders and animationdatasinglefile.txt, animationsetdatasinglefile.txt files from importanimation command to Meshes folder.
  • Havok project from retargetcreature command to where you store your creatures, probably Meshes\<project name>\Actors\<creature name>.
  • Skin, skeleton.nif and skeleton.hkx to <Havok project folder>\Character Assets\.
7. Now take esp file generated by retargetcreature command and load it in CK. Create race, armor addon, armor and actor records for your creature. In armor addon set paths to skin. In race set paths to skeleton and Havok project, and generated movement types. Check generated IDLE records – paths there may need to be adjusted to where you actually stored your Havok project.

If everything was done right your creature animations must work in game! But there are a lot of things to tweak in behaviors…

Root motion

Your animations may include root transform which describes creature’s center of mass movement. Skyrim engine handles it in a very special way. Hkx animations actually can contain only Z translations and X and Y rotations of root. X and Y components of translations and Z and W components of rotation are stripped from animations by ck-cmd importanimation command and is stored in text cache in animationdata\boundanims folder (and in animationsdatasinglefile.txt). Translation and rotation of creature are instead determined by engine. Speed of movement is defined by creature’s movement type. Most of creatures have several animations for movement, which are blended depending on movement speed. In order to make creature movement animation synchronized with its motion one needs to do two things:

1. Set walking and running speed in movement types to actual speed values for which respective animations are made.

Custom animations 2.png

2. Open your creature’s behavior and find hkbBlenderGenerator of movement animations. Weights of its children are values of speed to which respective animations correspond. When speed of creature is between weights of two of those animations, resulting animation is blended from those two animations proportionally. So, you need to set those weights to values for which respective animations are made.

Creating creature collision

For creature physics to work you need provide two things in skeleton: bounding box and collision. You can either make them in NifSkope (very long and painfully) or export from your 3d editor to fbx together with skeleton. Let’s follow second route using Blender. In this case you need to have in your .blend file you exports from three things:

Custom animations 3.png
Custom animations 4.png
1. Armature representing your creature’s skeleton.
2. Empty called BoundingBox with child box mesh called BoudingBox_Box.
3. Hierarchy of empties replicating your skeleton. You don’t need to construct it manually: you can obtain exporting skeleton nif with ck-cmd exportfbx command.

Each empty corresponding to bone can have mesh children representing bone colliders and empty children representing ragdoll constraints. Colliders must be called <bone name>_rb_capsule for capsule shape or <bone name>_rb_sphere for sphere shape or <bone name>_rb_box for box shape or <bone name>_rb_convex for convex shape. Note that collider pivot transform is ignored by ck-cmd, so transform must be baked into geometry. Mass and components of inertia tensor for collider are calculated by ck-cmd, but can be to far off. In that case you can set them in float custom properties "mass", "inertiaX", "inertiaY", "inertiaZ" on collider mesh. Constraints determine which motions of ragdoll are allowed. Empty defining constraint must be child of constraint’s parent bone and must be called <parent bone name>_rb_con_<child bone name>_rb_attach_point. Orientation of constraint is defined by orientation of respective empty. There are two kinds of constraints: full-blown ragdoll constraint and simpler hinge constraint. Constraint type is defined by string custom property "constraint_type". Set Ragdoll for ragdoll constraint and Hinge otherwise. For ragdoll constraint you need provide the following parameters in string custom properties: "coneMaxAngle", "maxFriction", "planeMaxAngle", "planeMinAngle", "twistMaxAngle", "twistMinAngle". For ragdoll constraint you need provide the following parameters in string custom properties: "maxFriction", "maxAngle", "minAngle". Check vanilla skeletons for good values of those parameters.

Fun fact again: since there are in essence two instances of skeleton (one in armature and another in hierarchy of empties), ck-cmd make two skeletons in nif on export. So you will need to delete one.

Custom animated object idles

Custom animations 5.png

Skyrim includes a lot of idle animations related to usage of some object, for example musical instruments playing, using pickaxe, carrying buckets or firewood, etc. Such objects are described by AnimObject records. But it appears that replacing those objects is impossible without behavior edits: when animation event is fired and behavior enters respective state, it sends AnimObjLoad event which contains EditorID of AnimObject to use as payload string. So, in order to create new idle using existing animation but with different object you need to do the following:

1. Open defaultmale Havok project and mt_behavior in it. Find state corresponding to usage of object of interest and copy it. Skyrim Behavior Tool doesn’t support copying, so you need to recreate whole state hierarchy and add it to the same parent.

Custom animations 6.png

2. Replace payload string of AnimObjLoad event of your newly created state with your object’s EditorID.
3. Create new animation events for your object.
4. Find transitions to original object’s state and copy them for your new state and animation events.
5. Create IDLE records for your new animation events and relevant idle markers.