Ted's RPG Rant

A place to rant about RPG games, particularly the Temple of Elemental Evil. Co8 members get a free cookie for stopping by. Thats ONE cookie each, no seconds.

Thursday, June 12, 2008

Adding New Meshes

This is a blog I have been meaning to write for a long time, not because I have anything to add to this subject - I generally leave these things up to the artists, and the groundbreaking stuff has been written about and explained previously by the folks who discovered it such as Cujo, Cuchulainn and Allyx - but because I often get tied up in knots myself and forget some important element, so I thought I would do a step-by-step idiot-proof guide for myself and other folks who are interested in this area of modding could then get into it easily.

Today I am going to add some new meshes to KotB: new boots, armour etc made by Half Knight. He has done the hard yards changing the graphics and I am going to put them into the game and record how that is done. I won't attempt to explain model-making, bones, skeletons, alpha-channels or any of the other weird stuff that the folks who make new things talk about: apart from technical nous, that sort of thing also requires artistic talent, something I don't have. What I will explain is simple techniques for making new meshes and the various files that have to be altered to see them in the game.

What is a mesh? By that, I mean the texture files that you see on screen on the various models - NPCs, weapons, clothes etc: the .jpgs or .tgas that wrap over the top of the models. Today we will specifically be looking at clothes. Different sorts of clothes can be made from one model by using different meshes: thus there is one model for female 'mystic garb' - the saucy little number worn by Elisteria in DH - but it can come in different colours, by putting different meshes on the models. The game currently has 'blue' (which is greenish) and 'red' (which is pink). Fabulous. Half Knight has already made some new ones: blue and red that are just that, and black and white as well. Lets start by adding the new prototypes for them as a base, and as we fill in each column, we can have a look at where each file goes and how they interact with each other.

In KotB, we'll put the new stuff at 6340 onwards, since there are some new robes there. So we add the following lines:

{6340}{Red Mystic Garb}
{6341}{Blue Mystic Garb}
{6342}{White Mystic Garb}
{6343}{Black Mystic Garb}

We also alter 6211 and 6213 to 'Cyan' and 'Pink' to better reflect the reality of their colours.

Then we back up protos.tab and add 4 new lines at 6340-6343. I'll assume you can do the basics like adding the obj type in column 1, the Id# in col 23, size_medium in 24 etc. If you aren't sure, just go back up to 6211 and copy those sorts of things (weight, cost etc too).

Material is an interesting one: its mat_cloth. No surprises there, but the more knowledgable or observant will have noticed that in data/rules, next to the protos.tab file that you just backed up before adding stuff to it, there is a file called 'materials.mes'. The materials column does NOT refer to this file, but we WILL be playing with this file in making our new meshes. Later.

Category is '1', same as 6211. The first column of real interest is col 34, 'model'. This is very important, it tells the prototype exactly where to find the model to display the item on screen. The 5 digit number (usually in the 12000s) that you see in the other armour and clothing prototypes (this section, the 6000s, includes pretty much everything wearable, such as boots, belts, goggles, shields, amulets and headbands, as well as armour and clothes), well this 'model' number refers to meshes.mes. Thats way down in the innards of the art folder, so lets go there:


Open it up and you will see thousands of entries - thats every damn model and mesh in the game, right there! Ducking back to prototype 6211 we see that the original blue (now Cyan) mystic garb refers to line 12131, which in turn says


This, obviously, refers to a file or folder location. Going back to the meshes folder, we find an armor folder, and opening that we find... well, lots of stuff, including folders named marauder, gladiator, leather_scale and other stuff made by Co8ers (Cujo and Maggit in those cases). We don't find a sorcerer folder, though, since no-one has ever made new mystic garb for the game prior to this (or at least they have never posted it). To see the original, we have to go to the dats, so going to ToEE1.dat we find


and popping that open, we find a huge number of files. Before we start dissecting those, lets put our new entries in meshes.mes: since both Half Knight and Cuchulainn are currently making all sorts of stuff, I will pick some obscure numbers that shouldn't get in anyone’s way and stick this particular bunch of new stuff at 12299, working backwards. Since they will all be going in the sorcerer folder we can copy that bit from 6211, but we have to rename the destination file since the game already recognises sorcerer_blue_ground, sorcerer_red_ground and sorcerer_green_ground. We'll call ours sorcerer_nblue_ground (for 'new blue'), sorcerer_nred_ground ('new red'), sorcerer_black_ground and sorcerer_white_ground. There is actually a logic to this, which I will reveal in a minute. In any case, the following lines will now appear in meshes.mes:


Quickly going back to protos,tab, then, in column 34, 'model' we now put 12296, 12297, 12298 and 12299.

Ok, so now when we hit 'give 6340' in the console, the game knows to display this prototype it has to create an item from model #12296, and by going to meshes.mes and looking at line 12296 it knows the relevant files for that model are found at data\art\meshes\Armor\Sorcerer in something called sorcerer_nred_ground. Sweet! But what are those files?

Before we create file sorcerer_nred_ground and friends, lets look at an existing one in the dat: specifically sorcerer_blue_ground. Lets open it up. Eek, there's two of him! sorcerer_blue_ground.ska and sorcerer_blue_ground.skm. One is 1kb and the other is 15kb. We'll have a quick look inside the bigger one. Opening it with HexEdit, it looks like this:

Ugh, what a mess! Obviously this is not meant to be viewed as a text file. What .skm means, afaik, is 'skeletal model' - this is the actual bones of the animated 3d models we see in the game. We are not going to make anything sensible out of it without looking at it with a model viewer, but we're modders - that won't stop us hacking it and hacking it good!

One thing in all that mess was intelligible - the bit that says


Hmmm... note it says 'sorceress'. Keep in mind, the male and female versions of this model are radically different: we have to create male and female files. Ok, what does the .mdf file look like? Opening it we see it says:

Ok, thats legible! It is pointing to the actual tga graphic that is the texture that gets wrapped around the model - thats the one we are going to change to produce our new clothes. So now we can see how the files interact:

protos.tab gets the model from meshes.mes

meshes.mes gives the location of the files

.skm gives the model, and looks to .mdf for the mesh

.mdf gives the name of the mesh graphic file

Easy! If you are wondering what .ska does, as .skm means 'skeletal model' I think .ska means 'skeletal animation' - it handles the model animations (how the mystic skirt flaps as the player runs, etc). They don't change from one type of mystic garb to the next so we just have to copy that.

Thats our next job, we are going to copy all these files for our new stuff. We already decided what to call them: prototype 6340 will look for model sorcerer_nred_ground. So we have to have some .ska, .skm and .mdf files named accordingly (not to mention the tga files we see onscreen, which is the point of it all!)

So: we are going to take the sorcerer_blue_ground files we have been looking at and copy them and rename them sorcerer_nred_ground. Note we are using the BLUE ones - we are NOT using sorcerer_red_ground or sorcerer_green_ground. ONLY USE BLUE. The reason why will become very clear in a minute.

When I say 'copy', we have no 'sorcerer' folder in our KotB art/meshes folder, so the first thing we do is make a new folder in there called 'sorcerer' being VERY careful to name it correctly. As you can now tell, all the files are looking for very specifically named things, and a single typo will bring an instant CTD in the game when you try to display the model, so be thorough. I am simply going to copy the whole sorcerer folder over from ToEE1.dat then rename and cull everything as necessary to prevent typo issues.

Egad, there is a lot of them...

Note a few things: each new .tga has its own mdf file that points to it, and each race has its own .tga (well, not joke races like half-elves and halflings, proper races). Furthermore, while the elf model is the same as the human one (just with paler skin and thus its own .tgas) the half-orcs and dwarves (that should be dwarfs, thankyou Mr Tolkien) have their own models, thus their own .skms. We have a LOT of files to hack...

Lets start by renaming them. I go through now and rename every blue one 'nred' at the relevant bit (keeping in mind the game still gets the relevant blue ones, for the original cyan-coloured garment, from the .dats). This takes a few minutes. I don't rename the .tgas - they will be replaced by the ones Half Knight has done for us, and I rename those appropriately.

Here's the new human red male next to the old pinkish one:

Not a lot of difference; its mainly in the female ones.

Where are they? Looking around, I don't see any new red ones: H_K did say he hadn't done both sexes yet, so lets do that one ourselves (this way you will see how to make basic meshes, not just how to add them, for all those of you out there reading this who don't have a graphic designer like Half Knight sending you stuff ;-) )

Popping the 4 female ones (sorcerer_nred_F_human.tga, sorcerer_nred_F_halforc.tga, sorcerer_nred_F_elf.tga and sorcerer_nred_F_dwarf.tga) we see they look like this:

while the old pinkish ones look like this:

Ewwww... and they call that red. Lets fix it. As well as the 4 tgas, there is a 5th one simply called sorcerer_nred_ground and a matching .mdf file: we'll modify that too. Mine pop in Photoshop.

The next bit can only really be described, rather than shown. Look at the pic above, we see that there are predominantly cyan bits, with some blue highlights. I am going to change them to bright red with gold highlights. First, I select the nred_ground.tga and select all the greeny-cyan bits with magic wand. Some fiddling with the tolerance and I finally set it at 15: still a lot of clicking, but it doesn't try to grab the stencil-blue parts as well. (Anyone remember stencils? Anyone?) Holding shift, for those who don't use magic wand, allows me to select new sections while keeping the old ones selected too. Eventually I have done a basic job selecting the greenish stuff. It looks like this:

I then go Enhance / Adjust Colour / Colour Variations and I press the 'increase red' button SEVEN times. Thats important, because I have to do this with 5 different .tgas and want to remember what I did with each one.

That gives me something like this:

Well thats something, isn't it? I mean, its red, not pink 8^P

Next I select the blue highlight parts, and do much the same, only in the enhancing bit I change them to 'decrease blue', which makes them glow yellow. Nice :-)

Next, I labouriously do the other 4 .tgas for the 4 racial models. And thats the basic artwork done. We now have male and female versions.

Time to see them in game? Not quite. We may have renamed the new files with variations on 'nred', but internally they are still pointing at the old ones, so we have to crack open the .skm and .mdf files and hack them. I will use Notepad++ this time for the .mdf file, since it makes it that little bit easier (I will still use the hex one for the .skm since either way you get a screen full of gibberish and a few intellible words here and there). Here's what we see in sorcerer_nred_F_human.mdf:

So we change the bit saying




Now, listen carefully, this is the most important thing I can tell you. The rest of it is just renaming files and using common sense - here is where hours of frustrated hacking by previous modders comes into its own.

One of the reasons I opened these files in a Hex Editor is so you can remember the game is handling files in hex format, not text like a .mes file. So you can't just remove a byte or add one - that shifts everything one byte to the right or left and bang, the whole thing is ruined. You have to copy byte by byte.

Therefore, if we are going to point a file to a new file called sorcerer_nred_F_human.tga, we have to use an existing file that can be altered to say that IN EXACTLY THE SAME NUMBER OF BYTES. In this case, that means the same number of letters. Hence we have NOT copied all the files called sorcerer_red_F_human and simply introduced an 'n' - that would be adding a byte. Rather, we have changed the ones called sorcerer_blue_F_human (and variations) to sorcerer_nred_F_human.

If that doesn't make any sense, think about it very carefully then open an Hex editor and try it. As you type over the letters, watch how the numbers in the other windows change. We want all the other numbers to stay the same! I mean they will, but to get our new file reference to work we have to change all the numbers in the relevant part of the old one, and there is no room to add new ones, so we can't 'introduce' an 'n' to 'nred' but we can type 'n-r-e-d' over the top of 'b-l-u-e'.

I hope thats clear. If not, I'm afraid you'll be going for a walk in CTD land.

Ok, so I go through and use the Notepad++ to rename all the male and female .mdf files, and then I use my Hex Editor to do sorcerer_blue_ground.skm: these model files sometimes take some searching through to find the relevant bits but you have to do it. If you later run the game and the object you have made looks wrong, or looks like a mish-mash of something you made and something else, or just plain looks like the original file you were modding instead of the new file you made, then chances are this is the problem: you forgot something in the .skm. This is more of a problem with monster meshes, though, and in this particular case, the mystic garb, there is only one entry in the skm to change.

So now our new files look at each other in their innards as well as their outtards: can we run it now and have a look? Absolutely not! We have only done half the prototype!

Going back to protos.tab, just keep moving along. Do the weight, cost and inventory icon the same as 6211, and the flags too (cols 50 and 61). Also go over to col 79, “Max Dexterity”, and set that to 100 (the basic setting for any item of clothing or wearable item that shouldn’t affect the Dexterity bonus). We now have one more column to do: 62, ‘colour’ in ProtoEd. I am not sure what ToEEWB calls it, but I can tell you now, it refers to our aforementioned materials.mes. 6211 has an entry of 9000, so go to data/rules and open materials.mes (in Notepad).

Entry 9000 onwards looks something like this:

// Sorcerer Outblue Fit blue

// 9000-9099 sorcerer outblue_Fit blue

This does two things: it tells the game where to apply these new meshes – to the chest of the PC / NPC model where it replaces the existing one (we’ll prove that in a moment) – and it also formally tells the game which of the many .tgas (which are individually named in the .mdf files, remember) to apply for the male and female of each race. You might think, “well that’s obvious, ‘blue_F_Dwarf” is for the female dwarf model!” but remember, we could name them anything at all (as long as it was the right number of bytes, and we cross-referenced it the same way internally). Its like naming a new weapon “Longsword +3” – you have to still put the +3 bonus and the weapon type in protos.tab to make it what it sounds like, you can’t just call it that in description.mes and leave it at that.

Take a look at the size of that materials.mes file, btw – if someone (probably Cujo) ever did add a new race like Drow or Snervfleblin, then someone else (probably me or Gaear ;-) would have to go through and add an extra male and female line to EVERY damn entry here. Even if it just said blue_M_human / blue_F_human all over again, as it does here for many of them (since the Halfling, Half-Elf and Gnome races are just human models somewhat shrunken). If you want a whole new model, then that’s all new meshes and mdfs for EVERY garment. Who wants to do that? Any takers?

Enough of that. We have to now make a new bunch of entries for all the variations. I am putting them at 12900, since there are big gaps among the temple Robe entries for some reasons (they should be differentiated in the hundreds but among the robes they do it in the thousands, leaving 9 hundreds to play with if you take my meaning). Once I have renamed the blue entries to ‘nred’ it looks like this:

// remeshed and new mystic garb

// 12900-12999 sorcerer proper red

Easy, and didn’t take long thanks to copy-paste. We then place the entry 12900 back in col 61 of protos.tab.

One last thing: we now open another file in the Rules folder: addmesh.mes. It has identical numbering to materials.mes, so looking again at 9000 (where the original blue mystic garb, proto #6211, kept its racial mesh information in materials.mes) we see the following:

// 9000-9099 sorcerer blue oufit blue


Its easier to see what addmesh does than explain it, so for now we’ll just rename these to match our newly named files, and also put it at 12900:

// 12900-12999 sorcerer proper red


Ok, lets power it up! I run the game, clear the map cache (to be sure), it loads – good – then I load a save and ‘give 6340’ to my female human rogue. It doesn’t CTD – woohooo!! I then click on it to get her to wear it, and see this:

Ooops! There’s the red-and-gold outfit, but the dangly bit and the shoulder-pads are blue-green!

Those are the addmesh right there: I may have altered their names and pointed the addmesh.mes at them, but I didn’t do the addmesh.skm file and they are still pointing at the old files.

I left this error in not only because I actually made it, but because it nicely demonstrates what an addmesh is. We saw in materials.mes that the mesh that our new mesh replaces is the chest mesh on the PC / NPC model: and it does replace it, not just cover it, because it includes the skin element and if you leave it out, or alpha channel it into transparency, you won’t see something underneath (this is an ongoing problem with trying to make things that allow other things to show, such as tabards).

An addmesh, on the other hand, does not simply provide a new mesh for a part of the existing model, but adds a new little modelled bit on top. Hence while the existing chest mesh can essentially be replaced with a new body-hugging garb, there are no shoulder-pads on the human model to re-mesh, these have to be provided afresh by an added mesh (hence Addmesh. But you figured that out 6 paragraphs back, I dare say).

Anyways, addmeshes go in addmesh.mes at the same place as the remeshing in materials.mes. Some things have both, some have only one or the other: for instance, male mystic garb has no addmesh, its just repainted trousers and tattoos (all for the chest) while helmets are all addmesh and nothing else, so in materials.mes we see this for the helmets bit:

// 4000-4007 AsianHat

// 4100-4199 Barbarian Helmet

// 4200-4299 Chain Coif

// 4300-4399 CircletNice

// 4400-4499 CircletSimple

// 4500-4599 Generic Helm

// 4600-4699 Great Helm

// 4700-4799 Plumed Helm

// 4800-4899 Sorceror Helm

// 4900-4999 Wizard hat

// 5000-5099 Leather Cap

While we see something similar for addmesh.mes at the areas for gloves and boots

// 5700-5799 Hedrack Full boots

// 5800-5899 Hedrack Full gloves

// 7900-7999 Fullplate2 Gloves

// 8000-8099 Fullplate2 Boots

They’re just placeholder remarks, so you don’t make your brand new pride and joy – a multicoloured helmet with glowing horns - hack it into materials.mes at what looks like a free spot, then go mad wondering why it comes out with a skirt because there was an addmesh already at that spot that you knew nothing about and hadn’t checked for. Make use of those remarks. Here are some more:

//21100-21199 Cuchulainn

//21200-21299 Cuchulainn

//21300-21399 Cuchulainn

//21400-21499 Cuchulainn

//21500-21599 Cuchulainn

//21600-21699 Cuchulainn

//21700-21799 Cuchulainn

//21800-21899 Cuchulainn

//21900-21999 Cuchulainn

That’ll save name-calling and blood-letting later!

Lets fix our addmesh. Its sorceress_addm_red.mdf: open that, hack it as before to point at the nred file. Thats it. And now, lets run the game again and se if it works.

And there’s our finished product! Simple, eh? No? Contrary to what it looks like, it really is just copying files, making a few changes here and there to match them all up, and having a nice tga to introduce something worth doing it all for. Not hard, just tedious, and once you have done a few, not even that.

To be thorough I will introduce one more thing that Half Knight has done for these new garments: new icons. Probably most people who read this will already know how to add new icons but since I don’t think I have ever mentioned it in a tutorial, I will say something now.

Icons, as we saw in protos.tab earlier, is at col 53, which is called Inventory Icon in ProtoEd: spot on. We put in the number 242 based on 6211: lets give them all individual icons. 242 is not just an unfulfilled UN resolution, its also a number in inventory.mes (don’t you love how easy these files are to remember? At least they don’t call it something weird or in latin or something – graphica_minor.mes) which is found in data\art\interface\inventory, not tooo far from the meshes folder. Also in the folder, as well as the .mes file, are all the inventory .tgas: too easy. Lets look inside the .mes file:

{00239} {mandolin_icon.tga}
{00240} {bone_helm_icon.tga}
{00241} {bone_armor_icon.tga}
{00242} {sorcerer_outfit_blue.tga}
{00243} {sorcerer_outfit_green.tga}
{00244} {sorcerer_outfit_red.tga}
{00245} {Familiar_Bat.tga}
{00246} {Familiar_Cat.tga}
{00247} {Familiar_Frog.tga}

There it is! Heading further down, we see there is a gap at 573-579 where some clothes will fit nicely, but I have to add a bunch of hats and a helmet and there are already hats and helmets in that bit (568-70 and 580-85) so I will put those in there and move this stuff back to before 455 (which has the worn and grubby boots – I am adding some new boots Half Knight made too, so I will put the mystic garb and boots there). So lets just put it at 444 onwards:

{00444} {sorcerer_outfit_nred.tga}
{00445} {sorcerer_outfit_nblue.tga}
{00446} {sorcerer_outfit_white.tga}
{00447} {sorcerer_outfit_black.tga}

Looking again, Half Knight has only done the later two (black and white) since he intended blue and red to be replacements for the current pink and cyan ones, not new ones: I had other ideas ;-) So I go back into ToEE1.dat, find the blue icon, 5 shots of enhance / colour variations, and I have a nice red icon. Lets see it all together:

Well I have no idea where that damn left-click led us - something bizarre in longdescription.mes: some left over from ToEE, perhaps. But here you can see the icon, the new garb and its stats in protos.tab (such as it is - very little stat-wise for simple clothing) all in one pic. Finished!

If you'll excuse me, I have a blue, black and white garb to add. Plus new boots, helmets, a breastplate and a bunch of hats ;-)


Post a Comment

<< Home