Medieval Engineers

Medieval Engineers

Not enough ratings
Character Porting
By SicH
A character modding guide that describes entire process of character porting: from single mesh to textured and animated in-game character.
   
Award
Favorite
Favorited
Unfavorite
1.1. Introduction
Porting a character to ME is very complicated and time-consuming, but at least it's possible. This guide contains an information about all steps of this hard work. Some of the possible issues and ways to overcome it will be also mentioned.

Special thanks to:
Equinox, for aid with animations and weights
Xaerthus, for aid with textures
wolfgar7474, for character editing tutorial videos
1.2. Requirements
1. Blender, any version, any plugins set
2. Image processing software that supports .DDS format editing. GIMP with DDS plugin is recommended
3. Medieval Engineers SDK toolkit
4. Havok Content Tools
5. FBXImporter
6. Blender skills (or tutorials) in character creation: UV mapping, bone editing, weight mapping, animating
2.1. Sauce?
To import a model to the game you will need a model, it's kinda obvious. In this guide the VRoid Studio model is used. This model will require a free .vrm processing plugin for Blender, which can be easily found in net. For those who is worries about copyright things too much: the VRoid Studio models can be distributed freely, if you use vanilla accessories models. By the way, a .vrm file that will be compiled by VRoid Studio contains ready-to-use color and normal map textures, so you don't need to bake them manually. Other models may require a normal map rendering (process description can be easily found in net), if you want to have smoother textured model.

In sum:
  • Model should have two ready textures: color map and normal map
  • You will need only mesh of the model with UV map, clean of other settings or modules
  • To reduce weight mapping related time spendings, hair and other head attachments should be separate object. Head itself shouldn't be separated from body, otherwise you will face serious neck related issues.
  • Less mesh textures is better. Just to avoid dealing with a tons of separate files in Textures folder: each texture will require 3 files. Certain materials can use different areas of one texture file.
  • What really must be reduced is amount of polygons. One unoptimized model can be handled in vanilla game, but it will cause freezes in modded one for sure.

Congratulations, you are ready to go to the nightmare
2.2. Skeleton
After you will port a model into Blender project, get rid of all extra elements that might come with model. Leave only model mesh and UV data. Vertexes groups, armatures, weights etc. are need to be annihilated completely.

Basically, there are two approaches to character modding. First is fits your needs perfectly if character size is similar to vanilla characters (male, female, barbarian or deer). Just pick a needed character, import its .FBX file (can be found in ME SDK folders) in your project and use a ME skeleton as base for your model. Second approach will require a hella hours of hard work and you will need to be a modding chad, but it might worth all expenses. You can create your own skeleton and use it as base for model. The main problem not in the skeleton itself but in importing it to the game. You will need to add all required dummies and create at least 100 different animations. Yes, you need to be a modding chad to add proper Shrek character to the game or something.

In this guide the first approach is described. The model has the size that similar to vanilla female size. So let's use a vanilla female skeleton. Snatch a FBX ME_female model from following folder
common\MedievalEngineersModSDK\OriginalContent\Models\Characters\Basic

Import following .fbx file into your Blender project. Don't delete the vanilla meshes just for now. Hide it if you don't need it right now. The T-pose of your character must be same as armature T-pose, to avoid animation issues. Use your blender skills (or tutorials) and change the inclination of needed parts. After it, you need to manually transfer all bones positions from vanilla body to modded one. Use vanilla body as reference to where must be a certain bone and how it must be rotated etc. Then, finally, parent your objects with skeleton using "deformation - with empty groups" item. And clear all this groups in vertex menu, just in case.

Now it's time to go to the most unclear and the most frustrating part - weight mapping. Weight is literally nightmare that can brake your model easily (MWM Builder will refuse to process it), so be extra careful with it. Here are some useful advises on this topic:
  • MWM Builder is very sensitive to vertex groups with empty weights areas (except ME_RigX_Weapon_pin, ME_main_root and ThirdCameraDummy in case of female skeleton). And it extra sensitive to palm weighting. Any single unweighted spot in hand will brake your model processing.
  • Weight related crash issue is seems to be located only in body object. Hair etc. can safely has empty vertex groups.
  • Blender automatic weight tool most likely will leave some of these "fatal weight spots", good luck in searching it if you will use this tool.
  • You can safely (not 100% chance) adjust new weight by using "transfer" modifier on your modded body, transferring a vertex data from vanilla body. After applying following settings, press a "Generate Data Layers", then press "Apply" item in "arrow to down" icon just left of cross icon.

  • You can check the potential crash areas using following script:
    import bpy bpy.ops.object.mode_set(mode = 'OBJECT') body=bpy.data.objects["Body"] for v in body.data.vertices: v.select = sum([g.weight for g in v.groups]) == 0 bpy.ops.object.mode_set(mode = 'EDIT')
    Note that the "Body" string is ID (name string in scene menu) of target object. If body of your character has different identifier, just replace the "Body" string with your ID string. By running this script in Blender, you will see problem points selected:


  • You can also fix the weight issue automatically for problem object, using following script:
    import bpy from array import * print("Scanning for empty weight verticles") bpy.ops.object.mode_set(mode = 'OBJECT') body=bpy.data.objects["Body"] for v in range(len(body.data.vertices)): try: print(body.vertex_groups.active.weight(v)) except RuntimeError: print("empt") body.vertex_groups.active.add(array('i', [v]), 0.001, 'ADD') print("Done!")
    The "Body" string is also ID string, which neeeds to be replaced if you named object different ID. This script search the weights that responsible for MWM Builder crash and makes it non-zero, allowing to avoid the crash. The problem areas will be visible for previous script anyway, but MWM Builder will not crash during processing this model.

Repeat this procedure for face and hair objects. Btw, you can add additional accessories (bags etc.) to your model. The procedure is similar to adding a body to skeleton: parent with empty groups, then wipe out all vertex groups, then use "data transfer" modifier. Correct the weights manually if you need to.

Also, don't forget to clear any animation data that attached to your armature. It doesn't affect model behavior in game, but it does affect processing speed significantly. Btw, it would be nice if you decreased amounts of mesh faces. For example, the VRoid hair can easily has more than 10k faces. As I wrote before, if you want to play a modded game without freezes, you need to optimize your model. Use a "decimate" modifier to do it. Choose the optimal "ratio" value, to make your model both look good and having less faces than imported model. Hair usually can be "chopped" in half, but "chopping" the either body or face that much will lead to wrapping issue - "untextured holes" in place of surface bend.
2.3. Textures
Remember I mentioned the both color map and normal map textures? Find it in materials menu and export these textures as .png image files. You will need to make a DX11 texture files from it. Here is a general guide on this topic:
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=395248715&searchtext=textures

In our case:
  • Each ".cm"-like file consist of both "color"-like and "metal"-like textures. First is default image data, second is alpha-channel data.
  • To edit default image data in GIMP, use general tools; to edit alpha-channel you need to apply layer mask first. Black color is "full transparency" in meaning of DX11, white is "zero transparency".
  • Alpha channels are usually full-transparent. Exceptions are written in guide below.
  • Use tutorials on this topic to learn how to properly export layer and layer mask as single image.
  • To make a certain part colorable, you will need to amplify red colors in "_cm" textures and apply "zero transparency" fill of this part in "_add" file. The image (not alpha) in "_add" file must be filled by single gray color, otherwise the texture will not be rendered correctly.
2.4. Materials
To apply the textures to the model, you will need to set following properties in materials window for each material:
The VRoid textures are named as "ImageX". You need to refer to "_cm.dds" image in "Base Color" item. This .dds image must be based on "ImageX", otherwise the face of character will be textured as legs or something else.

Also don't forget to simplify a material name (to "face", "hair", etc) - you will need to refer to these later.
2.5. Dummies
The vanilla female .fbx seems to be broken. In order to correct functionality, the model must contain following "dummies" (empty plain axes):
  • detector_character (unparented, but in same collection with armature).
  • HeadDummy, parent - ME_main_root bone.
  • WeaponDummy, parent - ME_main_root bone.
  • LHand, parent - ME_RigRPalm bone (yep, left hand dummy is actually right hand child. It just works).
  • RHand with locked transform, parent - ME_main_root bone.
You can snatch these from male .fbx btw. Just don't forget to parent what needs to be parented. And where it's located too.
2.6. Processing and testing
First of all, export your model as .fbx file with following preferences:


Now you need to create a .xml file named as .fbx file. The .xml file describes which texture must be applied to certain material. Use the texture guide that I mentioned. From this moment you need to use a standard mod path style. For now just create a "Textures" subfolder in your work folder, move all textures to this folder and refer to them using "Textures\..." path. Your .xml will look like:

Note: if you want to make a certain material colorable via wardrobe color menu, use HUE_KEYCOLOR instead of MESH in <Parameter Name="Technique"> XML's line

After it, you need to use a FBXImporter to create a files that required for Model Builder tool in ME SDK. You can either drag'n'drop your .fbx to it or write a batch file that will make it automatically. The .bat file:
path-to-fbximporter.exe "path-to-file.fbx"

While FBXImporter is doing its job, create a mod folder in following path:
C:\Users\username\AppData\Roaming\MedievalEngineers\Mods\Mod_name

The standard character mod folder is organised like:
thumb.jpg - an icon that will be displayed in workshop metadata.mod - will be generated automatically after adding mod to world mods list /Data /Characters CharacterList.sbc Character_name/ Character_nameComponents.sbc Character_nameContainers.sbc /Models /Characters Character_name/ Character_name.mwm /Textures yourtextures.dds

Create these folders and transfer all required files. .sbc files can be found in example that I attached. If you are using a not female skeleton, just replace all "medieval_female" lines to "medieval_male"

When FBXImporter will finish its job, launch a Model Builder tool. Select your work folder (where .fbx is located) as "content path". Set a full path to /Character_name folder as output path. Set "pause after build" box checked. Press "Build" button and pray to don't catch a "key is not present in dictionary" exception. If you catch one, it means that weight map is broken, good luck in finding of empty weight spots. If weight map is ok, the .mwm file will be created.

Launch the game, create a vanilla world (to reduce loading time) and add only your mod to world mod list. After applying this list, the "metadata.mod" file will be created. Check subfolders, game can create additional "metadata.mod" sometimes, you need to delete all files except one that located at your mod root folder.

Load the world and check your model using wardrobe. Here is the possible issues list:
  • Model doesn't appear in wardrobe list - one of .sbc file is missing
  • Model doesn't appear in game - fbx import issue. You probably messed up with bones that must be unweighted, have a certain vertex group missing or suddenly deleted bone.
  • Model is painted in purple - textures issue. Make sure that you exported "merged layers" .dds files correctly
  • Some of the character parts are frozen partially or completely - weight map issue. Correct a weight of these parts manually for each bone that related to frozen part.
  • Face is splits in two when character turns its head - apply some extra 1.0 weight to lower face part from following bones: ME_RigHead, ME_RigL_ear and ME_RigR_ear
  • Colorable part doesn't color properly - you forgot to amplify red colors in needed area of _cm texture. If your textures renders too either dark or light, change a monochrome color in _add texture. An example of color which allows to render your model with proper "lighting" can be found in example files (any _add texture with colorable fields)

If it didn't help, feel free to ask in following discord channel:
https://discord.gg/NZut94De
#modding
3.1. Animation layer
You character has a long clothes that needs to wave while character is moving? Or you want to add a working tail? Unfortunately, both ME and SE doesn't support brand new Havok Cloth tech, which allows to make a waving elements of your character easily (cmon even Todd added a waving clothes to overmodified Oblivion game engine that Fallout 4 is using lol. And these procedural waving clothes doesn't affect on performance fatally, even mobile games has it now). So you will have to mess with animation states and other fun stuff in order to animate a part of your character.

First of all, you need to create a bone or group of bones that paranted to vanilla skeleton. Process your new model to .mwm file using described procedure. Then create a new Blender file that contains only this armature, other objects needs to be wiped out. After it, proceed to following folder:
MedievalEngineersModSDK\OriginalContent\Models\Characters\Animations
You will see a plenty of animations. These which located in root \Animations folder are related to male skeleton. Go to \Female folder. As you can see, any action, any movement etc. is animated by different file (I wrote that this is mess). But you don't need to re-animate all bones. All you need to do is find out a length of animation in frames, just to keep your waving synchronized with running animation or something. To do it, just import a needed .fbx animation file to new Blender file and see on which frame the animation ends. Use these limits in your Blender file and create custom animation of your custom bones, there are plenty of tutorials how to do it. When you done, export a .fbx file with following settings:


















Process .fbx file like regular model file. The .xml is needs to contain only following lines:
<?xml version="1.0"?> <Model Name="Default"> <Parameter Name="Centered">false</Parameter> <Parameter Name="RescaleFactor">0.01</Parameter> <Parameter Name="RotationY">180</Parameter> <Parameter Name="RescaleToLengthInMeters">false</Parameter> <Parameter Name="SpecularPower">10</Parameter> <Parameter Name="SpecularShininess">0.8</Parameter> </Model>

For animation files, you need to add next folders to your mod folder:
/Data /AnimationControllers custom_controller.sbc /Models /Animations youranimations.mwm

Also you need to create same folders in your work folder (with .fbx files). The root folder is gonna be /Content:
/Content /Data /AnimationControllers custom_controller.sbc /Models /Animations youranimations.mwm

Launch an Animation Controller tool from ME SDK. Create a new animation controller in /Content folder. Create a new subtype that named "Medieval_female" if you are using female skeleton. Also create a new Layer with following properties:

In "Bone Mask" choose your new bones that needs to be animated. In this case it's 3 bones of tail.

Then you need to create state map:
Every state is defining which animation should be played, the arrows are transition conditions. You can find working state map example in attached files.

Every state needs to be linked to certain .mwm animation file:


When you done, save the file again. You need to modify "Merge" line in .sbc controller file manually. Change a value from "Replace" to "Append":


If you done it right, your new bones will begin to move as character begins to move. Otherwise you will get a T-pose. Note that game updates an AnimationController info only after complete restart of the game. Modifying AnimationController file while game is running will lead to T-pose.
1 Comments
shad 5 Feb, 2022 @ 6:04am 
I will still have to read this guide carefully, but the fact that something like that finally exists is already a great value. Thanks for writing this!