Hegemony III: Clash of the Ancients

Hegemony III: Clash of the Ancients

Not enough ratings
Modding: A Blender import/export script and how to use it
By Fristi61
An import/export script with corresponding tutorial to make custom models for mods.

This is perhaps somewhat academic as the game takes an overly long time to load custom models from mod folders.
   
Award
Favorite
Favorited
Unfavorite
Introduction
Hello. Today I am sharing a Blender script that I wrote 4 years ago, that lets you import/export models to and from Hegemony's model .xnt format, essentially allowing you to add models to the game without needing expensive 3dsmax software.

I developed a small working knowledge of Blender at the time, just enough to make minor additions to a model and have them be textured and animated correctly. And, of course, understanding how these things work on the code side of things so as to program this import/export script.

But I am NOT an expert in Blender or modelling in general, and this is NOT a guide for how to completely make models. This guide merely explains how to get the script and how it works, some peculiarities to keep in mind etc...

The script is, admittedly, rough around the edges in places.
I never developed it further than I needed at the time because loading custom models into a Hegemony mod drastically extends the game's boot time!
Being on a 7-year old pc which was only low-mid tier when I bought it, I didn't find this very desirable as the one custom model I inserted into the Latium mod already extends its loading time by several minutes for me.

Anyway, some people are interested in the script, so here it is, along with this rather hastily written guide :-)
If anyone is interested in developing the script further, feel free!
Getting the Blender script
Download the script file here: https://drive.google.com/file/d/1zlcAbp5KImg4phCB6IEMWMmlVZ5Jzzzu/view?usp=share_link

The installation method will depend on your operating system.

I am assuming you can figure this out for yourself, if you're a experienced modder and/or modeler (which you'll probably need to be to make sense of this guide).
For me personally, on Windows, I had to put the file in an 'addons' folder. In Windows 10 this folder will be somewhere inside the main installation directory, but on older versions of Windows it might also be somewhere within AppData\Roaming.
Blender may also have easier ways to install scripts without needing to manually move files, I am not familiar with them.
Importing model from Hegemony .xnt
To import a model I've just added a new option to the File->Import menu. "Import Hegemony XNT".

Most of the game's models are loaded from an archive file and not directly available for modding. However, the devs have made 3 example models available in the entities_mesh_examples.zip here: https://drive.google.com/drive/folders/1yqBtoJ0THiRmmA1BslrZNuGrrtPTRBUq

In the below example, I've imported the Latin Spearman model that is one of the 3 available example models.



(The orientation of the import is a bit weird. The Latin Spearmen appears to be lying face-down, and also actually mirrored, probably because Blender's coordinate system is ordered differently.
When I last used this script I just rolled with it and edited the model in face-down position. But if anyone is really bothered by it, let me know and I will add extra code to convert the coordinates on import/export.)
Editing the model
This isn't a tutorial for Blender, I am assuming you already understand the basics for how things work.
Also, I'm going to be honest, it's been 4 years since I last did anything modelling-related and I can barely remember where some things even are in Blender. So I'm not the best person to explain that anyway.

But, there are a few general rules that must be obeyed for the model to work in Hegemony, and with my export script.

VERTEX PAINTING

Some models in Hegemony, particularly unit models, use MULTIPLE textures.
Unit models will often have their own texture, as well as a shared "weapons" texture which is re-used for things like helmets and weapons, and will additionally have parts of their model on which the faction's "shield" texture is dynamically displayed as well.
To top it off, there is a 4th texture which is also shared by many units, used for the soldier's face.

WHICH textures the game uses is defined in the unit entities, all of which are available in entities_units.zip here (and this is beyond the scope of this tutorial, for now): https://drive.google.com/drive/folders/14PUUlJK4UTKvq_P4BHNnaGUnzsq85i0f

But WHERE each texture is used on the model, is actually defined in a rather unique way: namely through vertex painting.
These colours will NOT show up in game in any way, rather they are a way of letting the game know which textures to use on which parts of the model.
  • BLACK vertices show the model's own basic texture
  • BLUE vertices show the "weapons" texture which is shared by many units.
  • GREEN vertices show the "face" texture
  • RED vertices show the "shield" texture of the faction in question.

See the below example of my modded scutum-bearing spearman. You can see RED on the outside of the shield, BLUE on the inside of the shield and the helmet, GREEN on the head and BLACK elsewhere.


BUT THERE'S A CATCH

Blender's default "Vertex Paint" utility is NOT adequate for our needs.
Why?
Because the game only allows ONE color per vertex.
Whereas with Blender's Vertex Paint utility you will happily paint different vertex colours for the different loops of a vertex (so in Blender a vertex can have separate colours for each of the connected faces, whereas for Hegemony this is not allowed).
If a vertex has different colours for different faces, my export script will randomly choose one of those colours for the vertex. So there won't be an immediate error but the chance is high that it will not come out exactly the way you intended.
Also, the colors probably need to be exactly right for the game to understand them and correctly determine which texture to use there.

For those reasons, I have instead created a SEPARATE VERTEX COLOURING UTILITY!
It works in a very basic way, but it gets the job done and makes sure to obey Hegemony's rules.

In Edit mode, go to the Misc panel. There should be a little "Hegemony Color" segment. Now simply select the vertices you wish to color, and choose from among the 4 colors in the dropdown.
This will ensure all selected vertices have only that one color, and that it is the exact right color value.
Perhaps Blender has (or, has gained it in the 4 years since I've made this script) a built-in way to ensure all sides of a vertex have the same colour, but I wasn't able to find it when last I looked.


PS: For the export script to work, all vertex painting should be done in a vertex color layer by the name of "Hegemony_Color". My import script will create this layer by default.

UV MAPPING

Like with vertex colors, only one UV map coordinate is allowed per vertex. Avoid having separate UV coordinates for the different sides of the same vertex, or the export script will be forced to simplify it and the result may not look as predicted.

Like with vertex colours, all UV mapping needs to be done in a UV layer named "Hegemony_UV" (created automatically by my import script).

This may get a bit confusing to work with, because this UV mapping will actually be for up to 4 different image files at the same time, as defined by the vertex color codes.

RIGGING

For the game, each bone of a skeleton has a simple numeric id (0-indexed). Each vertex can be assigned to at most 4 bones and has separate weights for each, which must together sum to 100%.

In Blender, my script simply uses vertex groups for bones. Each bone is in a vertex group named "heg_bone_[bone number]".

Do not use vertex groups for things other than bones, and ensure they are all correctly named. Else the export script will not work correctly.

You can simply use the "Vertex Weights" tool in the Properties Panel in edit mode, after having selected a vertex, to fine-tune the bone weights.

NORMALS

You don't really need to do anything here, Blender will automatically calculate the normals, tangents and binormals.

HOWEVER make sure that the normals are all facing the outside, or (parts of) the model will be invisible!
To do so, before exporting go to Edit Mode, press A to select all vertices, then go to Mesh->Normals->Recalculate outside (or hit CTRL N)
Exporting model back to Hegemony .xnt
Predictably, we go to File->Export->Export Hegemony XNT where I've added a new file save menu.

HOWEVER there are some options in the lower left corner of the file save menu that NEED to be set.
Specifically, we need to enter the name of the object that we will be exporting to a .xnt file.

Also, we can select whether we want to export a UNIT model or a PROP.


The only difference is that props are simpler models without animation and with only one texture. So then the script will not attempt to export vertex groups and vertex colours. The texture for the props is defined within the model .xnt itself, and you will need to put it there by hand when done.

For unit models, the exported .xnt should be good (if everything went right) and you can use it directly in a mod without needing further changes.


There are many built-in error handlers and warnings in the script. This is especially relevant for the export feature, which will let you know if it detected something which may result in an undesired result for you. Read them!