R
Rabbit, White
Guest
Editing units with NIF (Scene) Viewer - Link to PDF version
Introduction
The NIF Viewer that comes with the 3ds max plugins (SceneViewer.exe) allows you not only to view the files but also to edit them a little – you can remove or add objects, and you can change some of their properties. While limited at first glance, with a little bit of creativity you can create a lot of variations of units, and if you have even the most basic 3ds max skills then there are even more possibilities (just check out the units in my sig).
In this tutorial I will go over how to edit units using the NIF viewer, in particular how to remove and add stuff and how to give one unit a weapon from another unit. All the things I talk about I learned by trial and error working with the viewer, which means that there is probably tons of stuff missing, so if you know something I don’t, or have discovered a better way to do something, don’t hesitate to post about it. Also, while in this tutorial I primarily deal with the civ4 units, all these things can be applied when adding object that you created yourself in 3ds max.
A word about terminology. A unit is the complete civ4 unit. A model is the primary “actor” in that unit – the guy holding a sword, riding a horse, etc. A mesh or an object is any additional part of the unit that is not part of the model (but rather attached to it), e.g. sword, rifle, shield, quiver in some cases, etc.
Finally, this is a fairly detailed tutorial (I want to cover as many potential questions as possible
), but it’s not necessarily basic. For example, I'm assuming that you’re familiar in general with Civ4 modding.
Preparation
Download the 3ds max plugins, if you have 3ds max 6 or 7+ then download the appropriate version and unzip directly into max’s root directory. If you don’t have 3ds max then download any version and unzip wherever.
Once unzipped find the files BoundShape.nif and BoundShape.tga. For any unit you wish to open in the NIF viewer you will need to have these two files in the same folder as that unit (for convenience you can copy these two files into all the unit folders in the civ4 installation directory).
UPDATE: If you get a missing MFC71.DLL dll error, just google it. The first link points to a site where you can download it with isntructions on where to put it.
Ok, now we can start messing with files…
NIF Viewer’s interface
Make a copy of the swordsman unit. It’s easiest to just make a copy of the entire swordsman folder into your project directory but strictly speaking you only need the two [unitname].nif and [unitname]_fx.nif files (swordsman.nif and swordsman_fx.nif in this case) and all the textures. The KF and KFM files are animations, which we can’t do anything with using the NIF Viewer, so they’re not needed. Open the NIF viewer and open the swordsman.nif file.
Ok, the most important part of the interface is the scene graph tree on the right. This is where you do all your unit modifications. It’s a hierarchical representation of the unit with all of its components. It’s composed of two types of nodes – NiNodes, which I will refer to as nodes, and NiTriShapes (and in some cases NiTriStripes), which I will refer to as shapes. The shapes are the actual physical objects in the units – weapon, piece of equipment, the model itself. The nodes are more versatile – they act as containers for shapes, as dummy objects to mark attachment points on bones, and some contain information that allows the unit to use outside resources, such as sounds. Both nodes and shapes have information about their position and orientation, both relative and absolute. Finally, while nodes can contain shapes and other nodes, shapes cannot contain anything.

There is also the scene graph list, which allows you to quickly find the necessary objects (instead of opening every branch in the tree), as well as texture and performance statistics, which are useful but are not needed for this tutorial.
Figuring out what you can do
Since the most basic thing that you’ll use the viewer for (besides viewing
) is to remove objects, you need to know what exactly you can remove. Go into selection mode (the mouse cursor button at the top) and click one of the swordsman’s swords (try saying that five times fast), you will notice that the tree opened up and has the sword’s shape selected. Now click the shield, same thing. Now, click the shoulder pads – notice that the shape selected is the swordsman himself. In fact, if you search through the entire tree you will not find a shape for the shoulder pads. That means that the shoulder pads are part of the model and cannot be removed. If you really want them gone you’ll have to recreate the unit from scratch.
So, you can only remove or add things that are separate shapes. Anything that’s part of the model itself cannot be removed or replaced. Other than recreating the model, the best you can do is cover that up with something else, but that’s not always appropriate.
Removing the Swordsman’s shield
I don’t know why but people don’t seem to like the shield, I guess they want the swordsman to suffer more
, so we’ll remove it. It’s literally a three click process. Click on the shield to select it. Go to the scene graph tree (tree from now on) and right click on either the Swordsman_Shield node, or the shape that is contained in it. Click on remove. Done. Now all you have to do is save.
In this particular case you could’ve remove either the node or the shape, however make note that it’s not always appropriate to remove the parent node of a shape (i.e. you should only remove the shape). Sometimes, the parent node will contain other shapes or nodes, but even when it doesn’t, it might contain some information necessary for correct functioning of the unit. If you get into the habit of removing the nodes instead of the shapes and notice that something weird is happening with your latest unit then the first thing to do is try to only remove the shape and not its parent node.
Adding objects from other units
Ok, let’s give the swordsman a different sword, say from a knight. While the swordsman is open, click the add file button and load up knight.nif. Side note: When merging objects from two different files I usually prefer to match the files, i.e. to swordsman.nif add sword from knight.nif, and to swordsman_fx.nif add sword from knight_fx.nif. I don’t know how necessary it is but it doesn’t cost you anything.
After you added the knight to swordsman you will see both models together. Go into selection mode, and click the knight’s sword and then the swordsman’s sword. This will open up the tree to display both swords. Select the knight’s sword (in the tree), click and drag it to the Swordsman_Sword node, and drop it. Now you have both swords in the swordsman hand and you no longer need the knight. Remove the NiNode “knight.nif” node.
You will notice that the knight’s sword isn’t properly oriented in the swordsman’s hand. This will be a common result when moving objects from one unit to another. To fix it we’ll need to adjust the sword’s orientation and perhaps position. Right-click on the sword in the tree and click properties. This opens up the properties dialog, the tab we’re interested in is the second one, entitled Local Transforms. This is where we can adjust object’s orientation, position and scale. The orientation is the most complicated one as it is represented by a rotation matrix. Here’s a good place to learn more about rotation matrices.
In our case, in order to properly orient and position the sword, we will need to rotate it 180 degrees around the X-axis (refer to the image to see what are the values in the matrix for that) and position it at coordinates (0, 14, 0). Once you’re satisfied with the new sword’s position and orientation you can remove the old one (I usually use the old weapon to help me figure out the proper position for the new one), and save the file.

You might’ve noticed that the new sword leans back a bit when compared to the old one. In general, little differences like that will not be detectable in game but if you want you can adjust angles like that as well, it just involves sine and cosine functions
. I find that whenever I move something between vanilla units, 90 or 180 degree rotation around one of the axis is enough, and if you’re adding your own object you can adjust those (little) angles in 3ds max.
Before using this unit in game you should make the exact same changes in the swordsman_fx.nif files. I always modify both files when I’m making my units. The good thing is that the changes are exactly the same for both files, so when you’re working on the first file, record the values you used for orientation, position and anything else, and then repeat them for the other file.
Finally, don’t forget to add whatever textures are used by the new object to the folder where the new unit is in. In this case it’s knight_128.dds, sometimes you might also need to copy the gloss texture as well.
Now you can just copy both nif files and the textures into art/units/swordsman folder and see it in action.
Conclusion
Well, that’s all there is to it - fairly simple. All we did was give the swordsman a different sword but there’s much more that can be done. Obviously if you have some experience with 3ds max you can create alternative weapons or just objects to add to units – helmets, armor, equipment etc. You’re also not limited to only replacing non-animated objects, because in some cases the animations used are just simple combinations of rotations and translations (same as a sword swinging during attack animation).
For example planes use such simple animations for their missions – if you replace the plane model from one of the vanilla units with your plane, it will get the proper animations, effects and sounds associated with planes. You can even replace propellers with your own or just use the propellers from vanilla planes with your plane models (i.e. replace vanilla plane with your own model and re-position the propeller from their plane to match yours) and have a fully animated plane without doing a single animation.
If you want to know more about that refer to the second part of my Exporting models from 3DS MAX into Civ IV tutorial, and really, replacing a the entire plane is not much different than replacing a sword, the only trick is to find the proper node to which attach the new mesh.
Note: The above mentioned method of replacing the entire plane only works with planes, and to an extent with ships and tanks. It will not work with other units. For example, you can't put the maceman's model instead of the rifleman's model so that maceman uses rifleman's animations.
Well anyway, I hope this tutorial was helpful. Feel free to post any questions about the tutorial or the topic in general.
Cheers
I've posted the second part of this tutorial with more about rotation matrices and object properties.
Introduction
The NIF Viewer that comes with the 3ds max plugins (SceneViewer.exe) allows you not only to view the files but also to edit them a little – you can remove or add objects, and you can change some of their properties. While limited at first glance, with a little bit of creativity you can create a lot of variations of units, and if you have even the most basic 3ds max skills then there are even more possibilities (just check out the units in my sig).
In this tutorial I will go over how to edit units using the NIF viewer, in particular how to remove and add stuff and how to give one unit a weapon from another unit. All the things I talk about I learned by trial and error working with the viewer, which means that there is probably tons of stuff missing, so if you know something I don’t, or have discovered a better way to do something, don’t hesitate to post about it. Also, while in this tutorial I primarily deal with the civ4 units, all these things can be applied when adding object that you created yourself in 3ds max.
A word about terminology. A unit is the complete civ4 unit. A model is the primary “actor” in that unit – the guy holding a sword, riding a horse, etc. A mesh or an object is any additional part of the unit that is not part of the model (but rather attached to it), e.g. sword, rifle, shield, quiver in some cases, etc.
Finally, this is a fairly detailed tutorial (I want to cover as many potential questions as possible

Preparation
Download the 3ds max plugins, if you have 3ds max 6 or 7+ then download the appropriate version and unzip directly into max’s root directory. If you don’t have 3ds max then download any version and unzip wherever.
Once unzipped find the files BoundShape.nif and BoundShape.tga. For any unit you wish to open in the NIF viewer you will need to have these two files in the same folder as that unit (for convenience you can copy these two files into all the unit folders in the civ4 installation directory).
UPDATE: If you get a missing MFC71.DLL dll error, just google it. The first link points to a site where you can download it with isntructions on where to put it.
Ok, now we can start messing with files…
NIF Viewer’s interface
Make a copy of the swordsman unit. It’s easiest to just make a copy of the entire swordsman folder into your project directory but strictly speaking you only need the two [unitname].nif and [unitname]_fx.nif files (swordsman.nif and swordsman_fx.nif in this case) and all the textures. The KF and KFM files are animations, which we can’t do anything with using the NIF Viewer, so they’re not needed. Open the NIF viewer and open the swordsman.nif file.
Ok, the most important part of the interface is the scene graph tree on the right. This is where you do all your unit modifications. It’s a hierarchical representation of the unit with all of its components. It’s composed of two types of nodes – NiNodes, which I will refer to as nodes, and NiTriShapes (and in some cases NiTriStripes), which I will refer to as shapes. The shapes are the actual physical objects in the units – weapon, piece of equipment, the model itself. The nodes are more versatile – they act as containers for shapes, as dummy objects to mark attachment points on bones, and some contain information that allows the unit to use outside resources, such as sounds. Both nodes and shapes have information about their position and orientation, both relative and absolute. Finally, while nodes can contain shapes and other nodes, shapes cannot contain anything.

There is also the scene graph list, which allows you to quickly find the necessary objects (instead of opening every branch in the tree), as well as texture and performance statistics, which are useful but are not needed for this tutorial.
Figuring out what you can do
Since the most basic thing that you’ll use the viewer for (besides viewing

So, you can only remove or add things that are separate shapes. Anything that’s part of the model itself cannot be removed or replaced. Other than recreating the model, the best you can do is cover that up with something else, but that’s not always appropriate.
Removing the Swordsman’s shield
I don’t know why but people don’t seem to like the shield, I guess they want the swordsman to suffer more

In this particular case you could’ve remove either the node or the shape, however make note that it’s not always appropriate to remove the parent node of a shape (i.e. you should only remove the shape). Sometimes, the parent node will contain other shapes or nodes, but even when it doesn’t, it might contain some information necessary for correct functioning of the unit. If you get into the habit of removing the nodes instead of the shapes and notice that something weird is happening with your latest unit then the first thing to do is try to only remove the shape and not its parent node.
Adding objects from other units
Ok, let’s give the swordsman a different sword, say from a knight. While the swordsman is open, click the add file button and load up knight.nif. Side note: When merging objects from two different files I usually prefer to match the files, i.e. to swordsman.nif add sword from knight.nif, and to swordsman_fx.nif add sword from knight_fx.nif. I don’t know how necessary it is but it doesn’t cost you anything.

After you added the knight to swordsman you will see both models together. Go into selection mode, and click the knight’s sword and then the swordsman’s sword. This will open up the tree to display both swords. Select the knight’s sword (in the tree), click and drag it to the Swordsman_Sword node, and drop it. Now you have both swords in the swordsman hand and you no longer need the knight. Remove the NiNode “knight.nif” node.


You will notice that the knight’s sword isn’t properly oriented in the swordsman’s hand. This will be a common result when moving objects from one unit to another. To fix it we’ll need to adjust the sword’s orientation and perhaps position. Right-click on the sword in the tree and click properties. This opens up the properties dialog, the tab we’re interested in is the second one, entitled Local Transforms. This is where we can adjust object’s orientation, position and scale. The orientation is the most complicated one as it is represented by a rotation matrix. Here’s a good place to learn more about rotation matrices.
In our case, in order to properly orient and position the sword, we will need to rotate it 180 degrees around the X-axis (refer to the image to see what are the values in the matrix for that) and position it at coordinates (0, 14, 0). Once you’re satisfied with the new sword’s position and orientation you can remove the old one (I usually use the old weapon to help me figure out the proper position for the new one), and save the file.

You might’ve noticed that the new sword leans back a bit when compared to the old one. In general, little differences like that will not be detectable in game but if you want you can adjust angles like that as well, it just involves sine and cosine functions

Before using this unit in game you should make the exact same changes in the swordsman_fx.nif files. I always modify both files when I’m making my units. The good thing is that the changes are exactly the same for both files, so when you’re working on the first file, record the values you used for orientation, position and anything else, and then repeat them for the other file.
Finally, don’t forget to add whatever textures are used by the new object to the folder where the new unit is in. In this case it’s knight_128.dds, sometimes you might also need to copy the gloss texture as well.
Now you can just copy both nif files and the textures into art/units/swordsman folder and see it in action.
Conclusion
Well, that’s all there is to it - fairly simple. All we did was give the swordsman a different sword but there’s much more that can be done. Obviously if you have some experience with 3ds max you can create alternative weapons or just objects to add to units – helmets, armor, equipment etc. You’re also not limited to only replacing non-animated objects, because in some cases the animations used are just simple combinations of rotations and translations (same as a sword swinging during attack animation).
For example planes use such simple animations for their missions – if you replace the plane model from one of the vanilla units with your plane, it will get the proper animations, effects and sounds associated with planes. You can even replace propellers with your own or just use the propellers from vanilla planes with your plane models (i.e. replace vanilla plane with your own model and re-position the propeller from their plane to match yours) and have a fully animated plane without doing a single animation.

Note: The above mentioned method of replacing the entire plane only works with planes, and to an extent with ships and tanks. It will not work with other units. For example, you can't put the maceman's model instead of the rifleman's model so that maceman uses rifleman's animations.
Well anyway, I hope this tutorial was helpful. Feel free to post any questions about the tutorial or the topic in general.
Cheers

I've posted the second part of this tutorial with more about rotation matrices and object properties.