1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[TUT] NIF Viewer Tutorial - Part 2

Discussion in 'Civ4 - Modding Tutorials & Reference' started by Rabbit, White, Apr 2, 2006.

  1. 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.
     
  2. NiProperties

    Open up the properties of a mesh in any unit (I used warrior), scroll down and open the NiProperties tab.



    Double clicking on any of the properties gives you access to its settings. Right-clicking on a property allows you to remove it and right-clicking anywhere else gives you a whole list of properties you can add. Most of them are self-explanatory, some of them might not work as expected, and I only explored few in detail. So, I’ll just cover the stuff I know and leave you to experiment with the rest.

    Alpha Property



    This one allows you to control how the transparency is handled. In particular you can change the source and destination mode (I might in the future explain a bit about this). The two really interesting parts are the Test Function and the No Sorter. They’re interesting because when I tried to add a helmet with a semitransparent visor, manipulating these two fields gave me the effect I wanted.

    What happened was that simply adding a helmet with transparent visor caused the head inside the helmet not to be drawn. When I played around with these alpha settings I managed to fix that. Unfortunately either the settings did not stick, or the game overrides them but when I loaded the unit in game the head was once again missing. If anyone finds a combination that works in game (I haven’t tried all of them) please let me know.

    Texturing Property and how to remove the team colors

    Double clicking NiTexturingProperty opens up this window.



    Notice the base and decal maps, notice the add/remove map buttons and notice the change button. These are all very interesting. ;)

    Basically through this property you can add or remove textures just like you would in 3ds max. For example you can add a gloss map, or change the texture file which the unit uses, and you can even remove team colors.

    To do that all you need to do is remove the decal map, and put the unit texture into base map (you’ll need to reload the unit to see the effect.)



    In that last screenshot the belt is now transparent, that’s because team color and transparency both use the alpha channel. If you remove team color from a unit, you’ll need to change the texture to remove unneeded transparencies.

    Other properties

    The other properties I’ll mention are the Shade Property, Specular Property and Wireframe property.



    The shade property allows you to change the shader to flat, what this means is that the edges will not be smoothed out and the shading will be precise and sharp. While it’s not useful on regular units it might be useful for making perhaps flat cartoon-like units.



    The Wireframe property simply allows you to turn the unit into a wireframe. (Mind you I haven’t actually tested this in game.)

    The Specular property allows you to make the unit shiny (like metal). Theoretically the gloss map controls this shininess but I haven’t tested it and when I tried doing a similar thing through 3ds max it didn’t work as expected.

    Conclusion

    Well this is it for this tutorial I think, but who knows, maybe in few weeks there will be a need for part three :). Feel free to ask me about anything I was unclear about, and if you discover new things about the viewer post them here.

    Cheers :thumbsup:

    I've posted the follow up to this tutorial where I give some general tips about the NIF viewer, as well as describe a technique which allows to attach almost any animations to almost any units.
     
  3. seZereth

    seZereth FfH´s art monk(ey)

    Joined:
    Feb 3, 2006
    Messages:
    3,900
    Location:
    Bayreuth
    Ok, now people know the rest of the things we discovered, i think we should see more creative creations from all sides!

    Thank u for taking the time, writing this down! I hope people will honour it.
     
  4. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Thx again for doing this Rabbit, I already had looked into the nif properties but most of it was totally suaheli for me.
    About Rotationmatrices. I normally don't have a problem rotating 90 or 180 degerees but are there easy ways to rotate smaller angles too? Figuring this out by trial and error is quite frustrating and I'm really no mathgenius.

    I'm not sure if you already noticed that scaling some bones will cause units sink into the ground. You can see this if you look closely at my hairy ogre. Though I'm not sure if this is true in general of is related to my Graphiccard(I'm having lots of probs with that) cause nobody repoted any bugs about. While this is normally undesired and I will probably fix that in the future, this could again lead to some weird constructions who knows:D

    And another question. Do you think it would be possible erasing dependencies of nodes via nifproperties and thus make it possible to get the maceman's weapon and animation on other models or make dummies and modelmeshes attachable easier by reducing the nodes between the desired node/mesh and the sceneroot?
     
  5. Well, to rotate by smaller angles you'll have to actually use the proper matrix formulas, it's very simple but you do have to do the calculations yourself. The simple idea is that the zeroes and ones are actually results of sine and cosine functions, for 90/180 degree angles they always come down to simple zeroes and ones but for any other angles they're gonna be fractions. Here's a site that explains it better.

    I don't think it's your graphics card. If you scale up some of the bones (like spine for example) it will affect the leg bones as well and since you're making them bigger they'll push out the legs, resulting in them appearing below ground level. (The game obviously doesn't "know" you changed the scale of a unit and so doesn't adjust the position to compensate)

    It might be possible although I'm not even sure you can change the children/parent relations using the dialog boxes, since I never tried. This is not something though that I'd want to spend much time figuring out though, if any at all. That is until I find myself in a situation where I need it. :)
     
  6. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    And the possibility of putting a rider dummy on your beasts wouldn't be such a need?;)
     
  7. Chalid

    Chalid Black Dragon

    Joined:
    Nov 24, 2005
    Messages:
    1,742
    Location:
    Munich, Germany
    Great. I tried exactly that for making the body transparent but did not reload. I'll try it again as soon as i am at home. Have you actually put a guy with transparency into the game?

    Adding a gloss map in Nif viewer unfortunately doesn't work. CIV completly hang up when i tried yesterday.
     
  8. seZereth

    seZereth FfH´s art monk(ey)

    Joined:
    Feb 3, 2006
    Messages:
    3,900
    Location:
    Bayreuth

    a transparent guy could look like a predator (arnold you know...) when u get him some lines semi transparent..
     
  9. surdanis

    surdanis Sergeant

    Joined:
    Feb 1, 2006
    Messages:
    223
    totally lost but how do i modify sounds. is that in the mesh? i've got 3ds max 2008 and noob to find this stuff.
     
  10. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    That's a simple string in the animations. You can easily alter animationsounds if you open kf files in nifscope and search for strings that reference the xml entries of the soundfiles.
     
  11. The Capo

    The Capo godless Heathen

    Joined:
    Jan 29, 2001
    Messages:
    9,302
    Location:
    Washington, DC
    Is there anywhere I can download Nif Viewer or do I have to go out and buy it? I can't seem to find it anywhere.
     
  12. NikNaks

    NikNaks Deity

    Joined:
    Jul 25, 2006
    Messages:
    2,972
    Location:
    England
    The NifViewer is the SceneViewer.exe file from there. You'd have known if you'd read part one :p
     
  13. Shiggs713

    Shiggs713 Immortal

    Joined:
    Mar 11, 2007
    Messages:
    2,361
    Location:
    Indianapolis
    these tutorials are amazing. I'm 78% through downloading a 3ds Max trial version, I hope I can do what I need to within 30 days. Thanks for the tut, I'd be lost without them.
     

Share This Page