R
Rabbit, White
Guest
NIF Viewer Tutorial – Part 3 - Link to PDF version
How to make almost any unit use almost any other animation from other units in the game.
Introduction
This is probably going to be the last NIF viewer tutorial as I have a feeling we about reached the limit of what can be done with it.
I will start with some general tidbits of information about the various things I discovered, or were shown, about the viewer, and then move on to the main topic (in the second post).
It is strongly recommended that you read the first two parts (links in my sig) because if you're not familiar with the viewer, much of this tutorial will not make sense.
Oh and needless to say that you should of course work with copies of civ4 units, not the original files.
Some tips for using the rotation matrix
For the purpose of this discussion I will label the matrix “cells” as follows:
[ a1 ] [ a2 ] [ a3 ]
[ b1 ] [ b2 ] [ b3 ]
[ c1 ] [ c2 ] [ c3 ]
Faster 90 degree rotations
If you're well versed in matrix math then you can twist and turn these models at your will, but for the rest of us there's a quick way to figure out how to turn the model in the direction we want. It's very simple - instead of switching the locations of 1's and 0's outright, just put a 1 in any cell containing 0, without touching the rest of the matrix. You will see the model distort in the same direction it will turn if you "continue" the transformation.
Here’s a quick example. We start with a default orientation [img1] (whichever it might be), then we add ‘1’ in c1, and you can see how the model skews away from us [img2]. So then if we continue the process - remove ‘1’ from c3 and a1, and put ‘-1’ at a3, the model indeed turns 90 degrees away from us[img3].
img1
img2
img3
Rotating at arbitrary angles
Once again of course, you could calculate the correct values for each cell for whatever angle and direction you want, but I find that rough estimation is usually enough, and certainly faster. So, let's say I want to turn this model 30-40 degrees to the right. Start by typing a value of something like 0.4 into one of the '0' cells. What you're looking for is a distortion (skewing) in the direction of the turn (just like above). After a few tries this is what I get.

Looks like it is skewing in the opposite direction from what I need, so I just negate the 0.2 value, and now we're half way there. The next step is to "un-distort" the model while still maintaining the "rotation". The trick is simple, put the same value you added (-0.2 in this case) or its opposite into one of the other '0' cells (there's a lot of guess work here obviously but after working with this for a while, you get a feel for it and it goes much faster). What happens is that this cancels out the distortion while maintaining (or probably more accurately, creating) the rotation. In this case adding 0.2 in a2 cell did the trick.

You might’ve noticed a pattern here - these values are located in the same cells in which putting ‘1’ and –‘1’ would have resulted in a 90 degree rotation. So basically, they follow the same rules - to rotate around any given axis, you add the values into the rows for the other two axes.
Removing team color and adding transparency
Sometimes you want to add transparency to an already existing model (for example to "remove" the backpack from the Scout). It's easy to do but the price of that is that you remove team color.
The way to do that is as follows – select the mesh of the unit, right-click and open properties. Scroll down a bit and open the NiProperties tab. You should see a “NiTexturingProperty” item on the list[img6]. Double-click it and you should see the texture properties dialog. In the list of the maps you’ll see a Decal Map and a Base map[img7]. Remove the Decal map. Then select the Base Map and click Change, browse for the unit’s texture and select it[img8]. After that you will see the entire model turn pink. That’s ok, once you save it and reload you should see the same unit but textured and without team color. So, basically by doing this you tell the game to use the texture's alpha channel for transparency instead of team color.
img6
img7
img8
Cleaning up the Scene Graph Tree
If you work a lot with the NIF viewer and often save and re-load your unit, then you might have noticed that every time you do that, there is an extra node added at the top of the tree.
This accumulation of nodes doesn't seem to have a significant impact on the size of the file, and I don't know if it affects performance, but it sure is annoying, and makes working with files more frustrating, especially when doing "bone transplants". Getting rid of that however is simple.
With the unit open, add to it the same unit. Then drag the scene node(s) from one of them into the top most node of the other. Then remove the unit (node) from which you dragged that scene node, as well as the nodes from the other unit that are no longer necessary. Save, and next time you load this unit it will only have two extra nodes on top.

Continued in post 2...
How to make almost any unit use almost any other animation from other units in the game.
Introduction
This is probably going to be the last NIF viewer tutorial as I have a feeling we about reached the limit of what can be done with it.
I will start with some general tidbits of information about the various things I discovered, or were shown, about the viewer, and then move on to the main topic (in the second post).
It is strongly recommended that you read the first two parts (links in my sig) because if you're not familiar with the viewer, much of this tutorial will not make sense.
Oh and needless to say that you should of course work with copies of civ4 units, not the original files.
Some tips for using the rotation matrix
For the purpose of this discussion I will label the matrix “cells” as follows:
[ a1 ] [ a2 ] [ a3 ]
[ b1 ] [ b2 ] [ b3 ]
[ c1 ] [ c2 ] [ c3 ]
Faster 90 degree rotations
If you're well versed in matrix math then you can twist and turn these models at your will, but for the rest of us there's a quick way to figure out how to turn the model in the direction we want. It's very simple - instead of switching the locations of 1's and 0's outright, just put a 1 in any cell containing 0, without touching the rest of the matrix. You will see the model distort in the same direction it will turn if you "continue" the transformation.
Here’s a quick example. We start with a default orientation [img1] (whichever it might be), then we add ‘1’ in c1, and you can see how the model skews away from us [img2]. So then if we continue the process - remove ‘1’ from c3 and a1, and put ‘-1’ at a3, the model indeed turns 90 degrees away from us[img3].
img1



Rotating at arbitrary angles
Once again of course, you could calculate the correct values for each cell for whatever angle and direction you want, but I find that rough estimation is usually enough, and certainly faster. So, let's say I want to turn this model 30-40 degrees to the right. Start by typing a value of something like 0.4 into one of the '0' cells. What you're looking for is a distortion (skewing) in the direction of the turn (just like above). After a few tries this is what I get.

Looks like it is skewing in the opposite direction from what I need, so I just negate the 0.2 value, and now we're half way there. The next step is to "un-distort" the model while still maintaining the "rotation". The trick is simple, put the same value you added (-0.2 in this case) or its opposite into one of the other '0' cells (there's a lot of guess work here obviously but after working with this for a while, you get a feel for it and it goes much faster). What happens is that this cancels out the distortion while maintaining (or probably more accurately, creating) the rotation. In this case adding 0.2 in a2 cell did the trick.

You might’ve noticed a pattern here - these values are located in the same cells in which putting ‘1’ and –‘1’ would have resulted in a 90 degree rotation. So basically, they follow the same rules - to rotate around any given axis, you add the values into the rows for the other two axes.
Removing team color and adding transparency
Sometimes you want to add transparency to an already existing model (for example to "remove" the backpack from the Scout). It's easy to do but the price of that is that you remove team color.
The way to do that is as follows – select the mesh of the unit, right-click and open properties. Scroll down a bit and open the NiProperties tab. You should see a “NiTexturingProperty” item on the list[img6]. Double-click it and you should see the texture properties dialog. In the list of the maps you’ll see a Decal Map and a Base map[img7]. Remove the Decal map. Then select the Base Map and click Change, browse for the unit’s texture and select it[img8]. After that you will see the entire model turn pink. That’s ok, once you save it and reload you should see the same unit but textured and without team color. So, basically by doing this you tell the game to use the texture's alpha channel for transparency instead of team color.
img6



Cleaning up the Scene Graph Tree
If you work a lot with the NIF viewer and often save and re-load your unit, then you might have noticed that every time you do that, there is an extra node added at the top of the tree.

This accumulation of nodes doesn't seem to have a significant impact on the size of the file, and I don't know if it affects performance, but it sure is annoying, and makes working with files more frustrating, especially when doing "bone transplants". Getting rid of that however is simple.
With the unit open, add to it the same unit. Then drag the scene node(s) from one of them into the top most node of the other. Then remove the unit (node) from which you dragged that scene node, as well as the nodes from the other unit that are no longer necessary. Save, and next time you load this unit it will only have two extra nodes on top.

Continued in post 2...