R
Rabbit, White
Guest
Originally this was going to be a simple update to the first NIF Viewer tutorial but it turned out to be much longer than I thought and so it's a whole separate part.
NIF Viewer Tutorial – Part 2 - Link to PDF version
Introduction
In this part I’ll cover more features of the viewer, as well as talk a bit more about the orientation matrix. If you haven’t read the first part you should as I’m assuming knowledge of everything covered there.
Quick tip before we begin...
A very useful thing you can do when manipulating the models is open up the “Default Node” node and open the properties for the first default light, find the entries for ambient light and change them all to 1.0 - this will light up the scene evenly so you can see clearly what you’re doing.
On to the tutorial...
Scaling of bone nodes
By bone nodes I’m referring to those nodes that represent the bones of a unit. For human or animal units these are usually called something like BIP Spine, or BIP Head, or HorseBip Tail. In any case it’s easy to tell by the name which nodes are the bone nodes, and it’s the same deal for mechanical units.
What’s special about those bone nodes (to which I’ll refer to as bones from now on) is that even though you won’t see any geometry attached to them in the scene graph tree, nonetheless some parts of the model are skinned to them. By “skinned” I mean that the vertices of the geometry are controlled by the bones. This means that if you scale these bones, any geometry that’s skinned to them will also get scaled. Take a look at these two units.

The obvious use for this is of course to change the scale of some parts to create new units, for example the Ugly Ogre. Another use for this technique is to remove a certain part of a unit without using transparency (which is not always desired), although to do that it’s necessary for that part to be skinned to a separate bone. For example, many pony tails or ribbons on units are attached to separate bones so by scaling them (the bones) to something like 0.0001 you can “remove” them. On the other hand the Knight’s sword sheath cannot be removed this way because it’s skinned to the same bone as the rest of the body.
Yet another use for this is to replace body parts with new ones. The idea is simple, scale down a body part to be very small and attach a new one. An example of this is this skeleton unit or the drill sergeant unit, for both of which the head was replaced with a new one. The tricky part about doing this is that when you scale down the bone to make the original part smaller you need to scale the new part up so that it remains normal size, and if you change the scale too much it becomes difficult to properly position and orient the new part. Also, keep in mind that the scale propagates to all the children, so scaling the neck will also scale the entire upper torso.
Another thing to keep in mind, in case you’re thinking of replacing the entire unit with new parts, is that even if the engine is smart enough not to render the scaled down parts because they’re too small (which it probably is), it still needs to process them to actually know that it doesn’t need to render them.
Rotation matrix and non-uniform scaling
The rotation matrix actually has very simple “rules” for rotating objects, especially if we limit ourselves to rotations of 90 or 180 degrees.
First, every row represents an axis – first row is X-axis, second row is Y-axis, and third is Z-axis.
Second, when rotating around some axis the values for that axis do not change.
Third, as long as you’re sticking with regular rotations, two non-zero digits cannot appear on the same row or column.
And before I go into examples the last thing to mention is that changing the sign of “1” in one of the rows, mirrors the object on the corresponding axis.
Here are some examples of how this works.
This is how the object looks with the default matrix. The X-axis here is vertical, Y is horizontal, and Z-axis goes into the screen.
And this is what happens if we negate the 1 in the 2nd row (y-axis).
First notice that it was mirrored along the y-axis, second I slightly rotated the object to demonstrate something – notice how the object appears inside out. This is because when we mirrored the object in y-axis we mirrored its normals as well, which inverted them and so the object looks inverted. To fix this we need to invert the object along another axis, let’s try the x-axis.
Well, it’s no longer inside out and as you see we mirrored it along the x-axis as expected. Now, let’s try instead the z-axis.
Because the object is symmetrical on the z-axis we just fixed the normals of the object without really changing its orientation, and in fact we just turned it 180 degrees on the y-axis. Notice the matrix – first row remains unchanged and the second and third have their signs switched. This is basically how you turn an object 180 degrees – whichever axis you want to turn it around, just switch the signs on the other two. Notice how I said “switch the signs” and not “make them negative”, this is important.
90 degree rotations
90 degree rotations are only slightly more complicated. All you need to do is switch the column locations of the other two digits and switch the sign of one digit. Let’s try 90 degree rotation around the z-axis.
Notice the matrix – 3rd row is unchanged, while the other two have switched their columns, and on the first row the sign is negative. The rotation is btw counter clockwise. If I hadn’t switched the sign in the first row the object would simply be inverted along the x-axis as expected (and will have its normal inverted as well). If instead the negative sign was on the second row it would simply result in 90 degree rotation in the other direction, i.e. clockwise. Of course, 90 degree rotation the other way is simply 180 degree rotation from the current orientation, and indeed you can see that the 180 degree rotation rules are followed – the center axis remains unchanged (z-axis) and the signs of the other two axes are switched. And if you wanted to rotate it 180 degrees around the x-axis you’d just switch the signs on the 2nd and 3rd rows, like so.
Now, you might think that it rotated around the y-axis (horizontal), but remember that when we rotated 90 degrees around the z-axis the other axes also rotated, and now x-axis is horizontal while y-axis is vertical. This is something to keep in mind when working with the rotation matrix, otherwise things can get confusing very fast.
As you can see, the pattern for rotations is very simple, and once you know which axis goes which way rotating an object is trivial.
The interesting thing about the rotation matrix is that it’s really more than just that, it’s also a scaling matrix – try to change all the ones to 2 or 0.5. Interesting isn’t it. Of course the row/axis relations are still followed. That is, scaling a digit on a row results in the object being scaled the same way on the appropriate axis. For example, doubling size on y-axis and halving it on x-axis results in this.
With some creative thinking this can be used to make dwarves.
One last thing I’ll mention is that changing zeroes to some negative or positive values will skew the geometry. I haven’t explored this aspect of matrix manipulation too much but it should follow the same rules – i.e. changing zeroes on first row skews the geometry along the x-axis, and so on.
NIF Viewer Tutorial – Part 2 - Link to PDF version
Introduction
In this part I’ll cover more features of the viewer, as well as talk a bit more about the orientation matrix. If you haven’t read the first part you should as I’m assuming knowledge of everything covered there.
Quick tip before we begin...
A very useful thing you can do when manipulating the models is open up the “Default Node” node and open the properties for the first default light, find the entries for ambient light and change them all to 1.0 - this will light up the scene evenly so you can see clearly what you’re doing.
On to the tutorial...
Scaling of bone nodes
By bone nodes I’m referring to those nodes that represent the bones of a unit. For human or animal units these are usually called something like BIP Spine, or BIP Head, or HorseBip Tail. In any case it’s easy to tell by the name which nodes are the bone nodes, and it’s the same deal for mechanical units.
What’s special about those bone nodes (to which I’ll refer to as bones from now on) is that even though you won’t see any geometry attached to them in the scene graph tree, nonetheless some parts of the model are skinned to them. By “skinned” I mean that the vertices of the geometry are controlled by the bones. This means that if you scale these bones, any geometry that’s skinned to them will also get scaled. Take a look at these two units.

The obvious use for this is of course to change the scale of some parts to create new units, for example the Ugly Ogre. Another use for this technique is to remove a certain part of a unit without using transparency (which is not always desired), although to do that it’s necessary for that part to be skinned to a separate bone. For example, many pony tails or ribbons on units are attached to separate bones so by scaling them (the bones) to something like 0.0001 you can “remove” them. On the other hand the Knight’s sword sheath cannot be removed this way because it’s skinned to the same bone as the rest of the body.
Yet another use for this is to replace body parts with new ones. The idea is simple, scale down a body part to be very small and attach a new one. An example of this is this skeleton unit or the drill sergeant unit, for both of which the head was replaced with a new one. The tricky part about doing this is that when you scale down the bone to make the original part smaller you need to scale the new part up so that it remains normal size, and if you change the scale too much it becomes difficult to properly position and orient the new part. Also, keep in mind that the scale propagates to all the children, so scaling the neck will also scale the entire upper torso.
Another thing to keep in mind, in case you’re thinking of replacing the entire unit with new parts, is that even if the engine is smart enough not to render the scaled down parts because they’re too small (which it probably is), it still needs to process them to actually know that it doesn’t need to render them.
Rotation matrix and non-uniform scaling
The rotation matrix actually has very simple “rules” for rotating objects, especially if we limit ourselves to rotations of 90 or 180 degrees.
First, every row represents an axis – first row is X-axis, second row is Y-axis, and third is Z-axis.
Second, when rotating around some axis the values for that axis do not change.
Third, as long as you’re sticking with regular rotations, two non-zero digits cannot appear on the same row or column.
And before I go into examples the last thing to mention is that changing the sign of “1” in one of the rows, mirrors the object on the corresponding axis.
Here are some examples of how this works.
This is how the object looks with the default matrix. The X-axis here is vertical, Y is horizontal, and Z-axis goes into the screen.

And this is what happens if we negate the 1 in the 2nd row (y-axis).

First notice that it was mirrored along the y-axis, second I slightly rotated the object to demonstrate something – notice how the object appears inside out. This is because when we mirrored the object in y-axis we mirrored its normals as well, which inverted them and so the object looks inverted. To fix this we need to invert the object along another axis, let’s try the x-axis.

Well, it’s no longer inside out and as you see we mirrored it along the x-axis as expected. Now, let’s try instead the z-axis.

Because the object is symmetrical on the z-axis we just fixed the normals of the object without really changing its orientation, and in fact we just turned it 180 degrees on the y-axis. Notice the matrix – first row remains unchanged and the second and third have their signs switched. This is basically how you turn an object 180 degrees – whichever axis you want to turn it around, just switch the signs on the other two. Notice how I said “switch the signs” and not “make them negative”, this is important.
90 degree rotations
90 degree rotations are only slightly more complicated. All you need to do is switch the column locations of the other two digits and switch the sign of one digit. Let’s try 90 degree rotation around the z-axis.

Notice the matrix – 3rd row is unchanged, while the other two have switched their columns, and on the first row the sign is negative. The rotation is btw counter clockwise. If I hadn’t switched the sign in the first row the object would simply be inverted along the x-axis as expected (and will have its normal inverted as well). If instead the negative sign was on the second row it would simply result in 90 degree rotation in the other direction, i.e. clockwise. Of course, 90 degree rotation the other way is simply 180 degree rotation from the current orientation, and indeed you can see that the 180 degree rotation rules are followed – the center axis remains unchanged (z-axis) and the signs of the other two axes are switched. And if you wanted to rotate it 180 degrees around the x-axis you’d just switch the signs on the 2nd and 3rd rows, like so.

Now, you might think that it rotated around the y-axis (horizontal), but remember that when we rotated 90 degrees around the z-axis the other axes also rotated, and now x-axis is horizontal while y-axis is vertical. This is something to keep in mind when working with the rotation matrix, otherwise things can get confusing very fast.
As you can see, the pattern for rotations is very simple, and once you know which axis goes which way rotating an object is trivial.
The interesting thing about the rotation matrix is that it’s really more than just that, it’s also a scaling matrix – try to change all the ones to 2 or 0.5. Interesting isn’t it. Of course the row/axis relations are still followed. That is, scaling a digit on a row results in the object being scaled the same way on the appropriate axis. For example, doubling size on y-axis and halving it on x-axis results in this.

With some creative thinking this can be used to make dwarves.

One last thing I’ll mention is that changing zeroes to some negative or positive values will skew the geometry. I haven’t explored this aspect of matrix manipulation too much but it should follow the same rules – i.e. changing zeroes on first row skews the geometry along the x-axis, and so on.