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 3

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

  1. 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...
     
  2. How to do a "Bone Transplant" ;)

    This technique was pioneered by AlazkanAssassin when he made his Napoleonic Era Units, so I don't take credit for it. Using this technique you can make almost any unit in the game (the non-mechanical ones that is), use animations from almost any other unit. Of course, whenever possible you should just switch the animations between units but it doesn't always work. And when it does, sometimes it produces very strange results.
    With this technique however, there are far fewer surprises and it works 90% of the time. Examples of this technique include the various mounted units I created, as well as the wolf rider.

    The basic idea behind the technique is that you attach all the bones of the unit which you want to give new animations, to the bones of the unit who's animations you want to use. It's basically like a puppet on strings, except that the strings are actually the bones of another unit, and that unit itself is not visible.

    I will demonstrate by going over the steps of creating one such unit, and for this tutorial this unit shall be, drum roll please... Incan Quechua using Archer's animations (and weapons).

    So, start by opening the Archer unit in NIF viewer, and adding to it the Quechua unit. Then move the entire scene node of the Quechua unit to the same place where the archer's scene node is, i.e. under the "archer.nif" node. I also usually like to rename the unit's (the one who's body I'm gonna use) scene node into something else, so as not to get confused (when you rename the node the name change will not show up until the tree is refreshed, which happens when you move it).


    Next, find the BIP (or for other units it might be Bip01) node of the archer unit, then find the same node for the Quechua unit. Grab the Quechua's BIP node and attach it to the archer's BIP node, by dragging it and then dropping it over the archer's node. You will see that the Quechua has shifted position and orientation.


    At this point you could also remove the weapons Quechua will no longer be using. Sometimes you could also remove some unused nodes, but never "bone" nodes. For example if we were doing this with the settler, as the "body", we could remove the nodes that have the extra bag and the extra staff, in addition to obviously to removing the "regular" staff and bag. I also like hiding the body of the other unit (archer in this case), and at the end it's removed completely, but until I'm done I like to keep it, just in case I need to double check the proportions.

    Now, to fix the position and orientation you need to open the properties of the Quechua's BIP node, and reset the values of rotation and position, i.e. the rotation matrix should be set to (1,0,0)(0,1,0)(0,0,1), and the position to (0,0,0).



    And this is it. No, really. Everything else is just repeating that last step for every single bone Quechua has. Basically, you attach (for example) BIP L Clavicle from Quechua to BIP L Clavicle from archer, BIP Neck to BIP Neck and so on. And if the other unit (archer) doesn't have a corresponding bone then you leave it where it is. Only thing to look out for is that the program is somewhat unstable and will sometimes crash when you drag bones like that. So I recommend saving often, at least every 2-3 bones, 4-5 if you're feeling lucky.

    Here is a screenshot with all the bones up to, and linking directly to, the head done.


    The nodes surrounded by blue outline are those from Quechua, thigh nodes and everything underneath the Neck wasn't moved yet, but as you can see, even though archer doesn't have a neck, after attaching the head node and resetting its position and orientation, the Quechua's head looks fine. Same deal with the right clavicle, which the archer doesn't have - simply leave the Quechua's R clavicle where it is, and attach the upper arm. Once position and orientation are reset, it'll look fine.

    Here's how the Quechua's tree looks in the end.


    And here's a screenshot of a complete tree for another unit.


    Oh, and don't forget to remove the archer's body at this point, if you haven't done that yet. It will save up a bit of resources.

    Finalizing the unit - creating FX version

    If possible I always like to create an FX version of the unit so that team color is supported. One way to do that is to perform the "bone transplant" on the FX versions of the original files. However, there is also a shortcut.

    With the Quechua open, select its body and open its properties. First thing you want to do is change the shader to TCiv4Skinning.


    You will notice that the model becomes pink and even "breaks apart" in places, that's perfectly fine.


    Next, do the same thing you did when removing team color - go to NiProperties, open NiTexture, remove the decal map, and change the base map to point to the unit's texture.


    It still doesn't look like anything has changed but it did - save the unit under a different name, usually it's [unit's name]_FX.nif (i.e archerquechua_fx.nif in this case), and then re-open it. If all the pink parts are now green then you did everything right and you got yourself a brand new unit with full support of team colors.


    The only downside to this shortcut is that it seem that glossiness is not properly preserved, even when using TCiv4SkinningGloss shader instead of just TCiv4Skinning. So if working on units that have gloss, if you want to preserve it, and you want to have team color, then you'll need to do it the hard way.

    Conclusion

    Well, this is it. It may seem complex (and certainly the tutorial's length doesn't help in that department), but it's actually pretty straightforward and once you get the hang of it, it's easy and fairly fast to do (at least if you don't get a lot of crashes :)).

    And just to prove these are not the ramblings of a crazy person, here is a mini-mod in which I added the quechua archer as UU for Inca's that replaces regular archer.

    Enjoy and thank you for reading :thumbsup:
     

    Attached Files:

  3. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Great! Hope this will animate some poeple to give the unitsection another boost of new stuff:)
     
  4. Civmansam

    Civmansam King

    Joined:
    Jan 15, 2006
    Messages:
    909
    Nice Tutorial Rabbit!
     
  5. Thanks

    Um, I think you're required by law to follow up that sentence with either "pun not indended" or "damn right, that pun was intended!" :D
     
  6. Prestidigitator

    Prestidigitator Prince

    Joined:
    Mar 14, 2006
    Messages:
    587
    Location:
    Is this a trick question?
    Excellent as usual! :thumbsup:
     
  7. TheBladeRoden

    TheBladeRoden Deity

    Joined:
    Oct 16, 2005
    Messages:
    2,257
    Location:
    The Middle West
  8. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Ähem, what exactly did I say?:mischief:
    Please tell me- could be I meant it even if without intention:D
     
  9. "Hope this will animate some [people]..."

    You used the word "animate", and this tutorial is about animation, so I figured you were going for a pun. :)

    P.S. My condolences on the loss. :cheers:
     
  10. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Oh I'm sorry. I think I'm not good with puns. In fact I had to look into a dictionary what the word pun actually means:blush:
    Maybe next time:mischief:
     
  11. woodelf

    woodelf Bard Retired Moderator

    Joined:
    Jun 12, 2003
    Messages:
    15,036
    Location:
    Gallery
    Wow, great write-up Rabbit.

    And accidental puns are even funnier Ploep. :p
     
  12. Shqype

    Shqype Shqyptar

    Joined:
    Nov 15, 2005
    Messages:
    2,468
    Location:
    New York + Shqypni
    Very detailed Rabbit. But, I read these tutorials and I can't help but wish it was easier for me... I'm just no good at animation and model creating.
     
  13. Thank you but I'm confused, which part of this tutorial is about modeling and animation? :confused: :)

    Really, if you know how to drag'n'drop files or folders, you know how to do this - all it is, is moving one node from one place to another, and just editing a bunch of numbers. The most difficult part about this is the repetitiveness of it. :)
     
  14. seZereth

    seZereth FfH´s art monk(ey)

    Joined:
    Feb 3, 2006
    Messages:
    3,900
    Location:
    Bayreuth
    This Tutorial "animated" me to give it a try, cause i read that you can completely remove the body of the other figure... which takes away the drawback of doubling Polygons...
    I tried and at first i got wierd results, cause i forgot to set the Bones of the new unit to 100 010 001 etc... it looked like a chicken then ;) But that actually brought me to another idea... :



    with this we can produce some more really nice Fantasy Creatures...
    And with the "trick" of creating Templates of Units (i created a maceman_Fx with every node on 100 010 001) it is just a fast drag and drop job with some adjustments...

    So this should motivate People to try it out!!!!
     
  15. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Those Skeletons are fantastic, seZ! Explain in more detail how you made them, please!
     
  16. Wow, these are great. Did you rescale their limbs to make 'em thinner or did you replace them with bone models, either way they look awesome.

    But tell me more about that templates trick - on that maceman_fx, did you reset the maceman's nodes (bones)?
     
  17. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    I think he just did reset the bones to 100 010 001 and saved the model. This way you can spare your time. Instead of resetting the bones every time you want to replace a model mesh you now just drag and drop and do some finetuning.

    @seZ
    btw what about uploading your templates? Or did you just make that maceman yet? Well as soon you get more a template set would be a good idea;) Could save some time.
     
  18. seZereth

    seZereth FfH´s art monk(ey)

    Joined:
    Feb 3, 2006
    Messages:
    3,900
    Location:
    Bayreuth
    hell i started yesterday evening triing this technique, so i only have the maceman template (which is what Ploeperpengel said, just the original maceman_fx with every bone node to 100 010 001 and then saved as such, so you drag this units nodes to the ones you want to replace) right now, but will for certain do a scout one and a chokuno one.

    The Trick with the skeleton is, that the Bones (Nodes) of the original unit (the one you use the animation from) can be rotated or scaled (and will show up in nif viewer as such) BUT willl fall back to normal in game, cause the animation has full controll over it.
    But the Nodes of the new unit (you replace the original with) can be transformed in any way you like and by such you can deform the complete Mesh via the bipnodes.... and if you set 100 /010 /001 to 100 /0 0,3 0 /00 0,3 you will get thinner limps which are as long as before... by this technque you should be able to create giants with long legs and stuff or a real orc or troll body....


    EDIT: Rabbit dont you wanna try this and do a female warrior this way ?!
     
  19. Ploeperpengel

    Ploeperpengel academic precarity

    Joined:
    Feb 2, 2006
    Messages:
    4,748
    Location:
    Berlin
    Great this way we finally can get Ogres and Trolls with Weapons that don't float in the air. Beware Humies! Ogre Kingdoms are coming:D
    Well this'll take a while still...
     
  20. Oh I see. 'Cause I thought the template you made is for the unit to which you attach the other units (which of course wouldn't work), but of course it's the template for the attachable unit, so you can then quickly put it on any unit to get maceman to do those animation. Great idea, especially since I already used units like settler and scout 20 times (slight exaggeration :D) and every time I had to reset their bones all over again. I really should've thought of that first :hammer2:

    Yep yep, exactly. Although there are limits to how much you can distort the geometry before it starts breaking up. In paticular, while scaling works more or less well all the time, moving the geometry can quickly totally mess up the unit. This is a problem I encountered while making the wolf rider. The front legs of the wolf, when attached to the horse's front legs didn't align properly, scaling couldn't help much with that, so I needed to move them. Unfortunately, doing that made things even worse as they got even more distorted. I had to actually twist them, essentially distorting them the other way, to negate that other distortion, and they still turned out looking a bit weird. Luckily it's only visible upon close examination. :)

    What makes you think I already didn't do that? :) I have a spy-using-maceman's animations sitting in a folder - got slightly weird shoulders (they look like she has big shoulder pads, like the ones women used to put under their shirts/dresses), but other than that it works fairly nice. Reason I'm holding out on the release is because I want to give another try to fixing the shoulders, and get some nice texture done, so she actually looks like a medieval warrior woman or amazon or some such thing, not just a spy with a mace. Plus, I'm really busy. :)
     

Share This Page