Proper NIF Handling Practices.

Helpful tutorials for doing various things, mostly mod-related.
Tarius
Head of Modelling
 
Posts: 1579
Joined: 03 Jan 2011, 04:46

Proper NIF Handling Practices.

Postby Tarius » 04 Jun 2013, 01:34

Ok, this is basically going to be an info thread on things to do with .nif files in Nifskope. Adding properties, nodes, no collision, etc etc. It is not going to be finished yet, but I just wanted to get it started and if anyone feels like it, they can post more info in here and maybe even pictures.
This address: http://niftools.sourceforge.net/wiki/NifTools will lead you to the wiki(of course). However, its rather in disarray and there is actually spam all over it. Interestingly, a quick search for a comprehensive source of info didnt reveal much; save for the wiki and that isnt even complete. So compiling stuff here might make this a unique source of knowledge. More can be done on this as time passes.

This will assume you at least know some basics on models.(which should be most people interested in reading this I guess)

Practices
As few objects as possible.
When you make a model, try to condense its objects into as few as possible. So say you have a table with four legs and each leg uses the same texture. In this case, it should be a single object, not four separate objects. This goes for most stuff. Obviously, if they remain separate, they will each become a NiTriShape node once exported into a Nif fille. Nif files with a large number of nodes(NiTriShapes or others) take more resources to load and view than the same model with fewer objects. In other words, that four legged table would take more resources with four separate leg objects compared to if the legs had been condensed into a single object.

Importing .nif files into 3ds Max
When importing into 3ds Max, it will not appear at first that any UV mapping was saved. Dont worry, it is still there. When you add an "Unwrap UV" modifier to the mesh, you can find the UV map under map channel 1. Once you have found this, you can simply save the UV coordinates and then change the channel to whatever you want and then load them. This will allow you to have the UV mapping data on the mesh without having to redo it by hand.(needs rewriting but thought I would note this down for now anyway)

Importing .nif files into Blender
Most of the options here are set by default and you typically dont need to worry about much. The only option my may want to look at is the "Combine NiNode + Shapes into Single Mesh" If you want to have them all as a single mesh or maybe not is up to whatever you plan on editing. Please note that the mesh is typically rescaled by 10x when importng. This is reversed when exporting.(needs more info here of course, but thought I would mention it)
Below are pictures of the basic settings for Importing and Exporting animated .nifs.
Import Settings
Spoiler: show
Import.jpg
Import Settings

Export Settings
Spoiler: show
Export.jpg
Export Settings

These pictures are from Arcimaestro Anteres and Spirithawke notified me of them.

Multiple UV Maps
For 3ds Max in partiucular,(Blender gets rid of extra map channels automatically so importing/exporting works here if you really care to do it) sometimes you can end up with multiple UV maps on a single mesh object after exporting. You can find this under Block Details, while NiTriShapeData is highlighted, in a slot called Num UV Sets. This value should be 1. If you happen to end up with a number greater than one, these need to be removed. Basically, you have to clear mapping channel info here. Getting rid of the extra channels will fix this.(you cant do this in Nifskope)
Its important to note that UV sets take up alot of space in a Nif file; its impossible to say exactly as models vary. For example though, if you have like 2-3 sets in a model and you get rid of the extra two, seeing the file size cut in half isnt out of the ordinary.

Normals and dealing with them
Mostly, you wont have much of a problem here and even in cases where you do, it usually isnt that bad to just leave things the way they are.
What am I talking about? Well under any NiTriShapeData node, you will find something called Normals and clicking on it will have a bunch of lines appear on the mesh. Basically, this deals with the way light strikes the mesh surface.
In some cases, you will have normals for a mesh get messed up by pointing the wrong way or by having what should be a single normal, split in two or more. Its easy enough to just open up any .nif file and look at how the normals are; in 99.99% of cases, they are pointing at least parallel to the textured side of the surface.
Normals pointing away from the invisible side of a textured surface need to be fixed.(unless you did it on purpose for some reason)
Aside from pointing the wrong way, the other problem will be when a normal is split. This causes a faceted look to the edge they are touching; it makes edges seem very sharp. Typically, this isnt going to be the case with most meshes. You want things like corners rounded, not sharp like its been gem cut.
How to fix any problems? Well, there are a couple ways and they are all tedious. Normals seem to be one thing that just doesnt have any good way to edit many at a time - correctly. The best thing you can do is to make sure the mesh has been smoothed before you export into .nif format. This should solve most of the normal problems. After that(aside from right clicking on the mesh in Nifskope going to Mesh -> Smooth Normals), practically the only way to fix them is by hand, one by one. Mostly, this would be caused by you having two mesh objects, that used to be a single mesh, touching each other(because they each have a different texture now) and the normals on that edge will be perpendicular to their surface. This can make the edges seem sharper than they should or you want them. Unfortunatly most tools lack the ability to smooth normals between two separate objects. If you know of a way to do this, please tell us because it would be kick ass.
The only way to completely remove a sharp seam caused by two normals(when smoothing wont work) is to move them to exacty the same spot. In many cases, you may be able to get away with moving them close to each other as this will reduce the sharpness by quite a bit.
In Nifskope, when you expand the Normals section under Block Details(mentioned above), you will get a list that shows the positioning of every vertex normal. There are three numbers used as the values for this. Basically, each normal should be a total length of 1 and you can use pythagorean theorem to find what three values will equal 1. You can also just type in anything from 0 to 1 in each of the three boxes and right click on it and the hit "Normalize". This will adjust the values so that they can create a normal pointing the same way except with a length of 1.
Anyway, thats are the basics of editing normals in Nifskope. Its up to you if you want to move them around for whatever reason.

Properties(I will put this in alphabetical order later; also, I think I will stick with the more common things that get used instead of listing everything there is)
Alpha
Technical Name NiAlphaProperty
~This allows meshes with an alpha texture to be transparent.(I assume that most people know this already)
Ok, now for details on what settings you should use here. They are all located in the Flags slot under the NiAlphaProperty. Clicking on the little flag icon(in this slot) will bring up a box with different options. Heres what you do:
•Make "Blending" not checked. If Blending is checked, you will notice that the edges of an alpha texture will make things behind them invisible.
•Make "Enable Testing" checked.
•Make "Alpha Test Function" either "Greater" or "Greater or Equal". Any other options are readily apparent in why you dont typically use them.(you can check for yourself)
•Finally, "Alpha Test Threshold" is set to anything above 0 or below 255; preferably something like 64-128(the value can be anything from 0-255). Basically the closer this value is to 0, the more of a black border you will have and at zero all transparent areas will be black. If you set this value to 255, it will basically turn things invisible.
The above is the bare minimum needed to use an alpha texture. Obviously you can play around with this and do whatever suits you. Everyone seems to have their own flag number they like to use and you can input the number directly, or change the options like above.
Tips:
Hair needs to have Test enabled so it doesnt disappear in water.
A Flag of 4845 with an Alpha Test Threshold of 192 seems to work best for clothing. This translates to Enable Blending, Enable Testing - Greater, no "No Sorter".

Collision
Technical Name RootCollisionNode
Ok, technically, MW meshes dont really need to have collision on them, but it does get used to do things like smoothing stairs out or maybe for making the trunk of a tree solid but not the leaves. Please note that its good to make sure it closely follows the shape of the object; in the case of where people will walk, it should be as close as possible to the mesh to prevent floating or sinking when someone walks on it. If you have a stack of boards for example and it is shaped like stairs or is otherwise slanted on one side, you should not just slap a box on top of the thing and call it a day, make sure that the collision mesh follows the shape!(yes, someone actually did this and I hope the person who made that board pile reads this)
Please note: It is more professional to use collision(or no collision) on your meshes. While the effect on performance is debatable, there is still an effect and having a collision mesh(or no collision) is better than not having one for all but the simplest objects. If you can demonstrate for us what exactly the performance effect is, please share!

Now, how do you add collision? Well, not many people seem to know how to set it up in either 3ds Max or Blender so if someone does, they can tell us.
Setting up collision in Nifskope isnt hard though:
•Make sure you have a .nif file with a mesh you want to use as collision. This can be in the same .nif file as the main object(it should be a different object from the main mesh(es) which means it will be under a different NiTriShape node. You can also have it in a different file and simply copy it into the main one.
•Select the NiTriShape you want to use for collision and make sure you delete everything in it except for the NiTriShapeData; this is all thats needed.
•Copy the NiTriShape by right clicking on it and then clicking Block -> Copy Branch. Using Ctrl-c works here too as that is the basic command to copy things.
•Select the NiNode that needs the collision and right click-> Node -> Attach Node -> RootCollisionNode. This will add a RootCollisionNode under this NiNode.
•Select the RootCollisionNode and either right click Block -> Paste Branch or do Ctrl-v(which also is the standard method of pasting stuff). This copies the NiTriShape with its NiTriShapeData to the collision node.
•Now make sure you delete the original NiTriShape (Ctrl+Del or right clicking and Block -> Delete Branch)
•Make sure the NiTriShapeData has "Has Vertex Colors" set to 'No'. All you need is the mesh and nothing else.
Important: This RootCollisionNode can be put under any NiNode. Any meshes under a NiNode with this will become no collision as the collision mesh will be used for all collision.
To insert another NiNode, simply right click on the main NiNode and go to Node -> Attach Node -> NiNode.
As an example, if you have a mesh with some stairs and you decide you want walking up and down them to be smooth, you can give them a RootCollisionNode. However, if they are linked with the rest of your mesh and you simply put the RootCollisionNode under the main NiNode and unless you attach a collision mesh that covers the entire mesh, you will end up being able to walk up the stairs but touching anywhere else will have you fall through it.
Collision flags do nothing! If you have no RootCollisionNode in a file, and you set the NiTriShape flags to None, Bounding, or TrIangles it wont make a difference. If you set it to none, it will have per poly collision, if you set it to bounding, it will have per poly collision. Basically, if you dont have a RootCollisionNode that is a simplified mesh, then you will be using per poly collision. This is as tested by SGMonkey.
Correction: Sometimes they do nothing. The behavior seems a bit inconsistant though so it is best to just leave the flag as none.

Material
Technical Name NiMaterialProperty
Most of you should know what this does. However, I wanted to say something about colors here and Glossiness.
Colors should be used to simply shade the whole mesh something and should be used sparingly, mostly light colors are good.
Ambient is almost always the lightest, close to white in the majority of cases.
Diffuse is going to be somewhat darker but not by too much.
Specular is usually very dark, close to black in most cases, though I have seen it as a light color. Mostly, this would be used for thngs like showing when something is wet. I am not entirely sure if MW uses this.
Emissive is always going to be black. This is unless your mesh needs to emit light for some reason, but this isnt the case in most instances as particles are used for that.
Now for glossiness. I have seen up to 100 here but mostly the values seem to be confined below like 30 and in most cases, 10 or lower with <1 being reserved for those surfaces that shouldnt really have glossiness at all.
Important: The combination of letters and numbers next to each type(ambient, diffuse, etc) is supposed to be in hexidecimal. White will always be #ffffff and black will always be #000000. The hex code here should be a combo of 6 letters and/or numbers, no more, no less. Having a hex code outside the correct range will cause the mesh to have lighting problems as seen in the example door below taken by Scamp:
Spoiler: show
Scampshot001.jpg

As you can see, the door shows up terribly bright because now lighting settings dont have any effect on it. It is always displayed at full brightness.
As far as we know, this apparently will happen with the Niftools Shader in 3ds Max sometimes if the settings are off.
Technical description by Hrnchamd:
The material doesn't show up as white with standard lighting, because the driver will clamp the light contribution to 1.0 from all sources. That isn't a particularly good lighting model as it makes 100 overlapping lights look the same as one. The per-pixel lighting shader calculation uses the broken material ambient, which happens to be 255 times brighter than normal (export plugin forgot to divide by 255), making the output pure white.

No Collision
~There is nothing actually called "No Collision" in Nifskope.
What you do to get an object as No Collision is to:
++Right click the NiNode, click Block->Insert->NiS...->NiStringExtraData.
++Make sure you pick NiStringExtraData not NiStringsExtraData
++Change the value to NCO (where normally the name of the separate objects go..) You should also be able to see a slot under the Block Details thats called String Data. The value column can be changed to NCO here as well, if you didnt change it already.
Under Block Details, there is a slot labeled Bytes Remaining. I have seen both a value of 0 and 7 in here. What difference this makes I cant tell.
Important: This No Collision can be put under any NiNode. Any meshes under a NiNode with this will become no collision.
Please note, that in order to get NiStringExtraData under a NiNode other than the scene root(the main node), you have insert it as normal(described above) and then go to the NiNode you want it under. Look for the Extra Data slot and in the Value column, put the number of the NiStringExtraData there and it will move under that NiNode.(as everything there is assigned a number from 0 to whatever, you see them to the left of every property, node, etc)

Specular
Technical Name NiSpecularProperty
What this does is different things according to where ever its used. In many cases, its used for making light reflect off a surface as if it were wet. For Morrowind, it does not do anything. Morrowind does not use specular maps so this property is useless. There is an easy option to add it in using 3ds Max but its not needed.

Stencil
Technical Name NiStencilProperty
~This allows you to see both sides of polys in the mesh its attached to under the NiTriShape node. Stencil is only going to be needed if you need to see both sides of a poly(or polys) without having to add more to the mesh. An example of this would be using a single two poly plane for a plant leaf. Typically, you would only be able to see a single side, the other side would be completely invisible. Adding in Stencil makes it so that instead of only being able to see a single sided leaf, you can now see the leaf as if it had two sides.
Please note, if you have a mesh where you cant "see" the invisible back side of its polys(ie, something like a wall thats only meant to be seen from one direction in game), than you dont need Stencil.(if anyone knows anything about performance with(stencil) versus without here, it would be nice to know)(I put this first because wolli asked about it)

People who have helped add to this(in alphabetical order and if not listed somewhere above):
Mwgek
Tarius
Tarius: I have now conquered the galaxy twice and am working on a third. Once thats out of me, I will be back to work.
TDF: Which game is that(I assume its a game and not real life)
The Khan: If it was real life, we would know about it. And I dont think he means this Galaxy.
Tarius: Yes, I really lead a secret double life where I am a galactic overlord.

User avatar
SGMonkey
P:C Admin
 
Posts: 254
Joined: 15 Dec 2010, 02:51

Re: Proper NIF Handling Practices.

Postby SGMonkey » 04 Jun 2013, 02:11

Nice to see Tarius, was planning on putting something like this up on the PT forum.

Stencil should be used sparingly. It does increase load. I will try and find evidence but i know it to be true. Its what you get if you use a 2-sided material in 3ds max, (or whatever the blender alternative is).

I'm still certain there is a naming convention used for collision creation. You can use it to either create a simple root collision simple geometry, or an empty object to remove collision completely.

User avatar
SGMonkey
P:C Admin
 
Posts: 254
Joined: 15 Dec 2010, 02:51

Re: Proper NIF Handling Practices.

Postby SGMonkey » 09 Jun 2013, 15:21

An unfinished house I've been making.
https://dl.dropboxusercontent.com/u/229 ... use_01.nif
https://dl.dropboxusercontent.com/u/229 ... 01_opt.nif

First one has no RootCollision and all similar objects haven't been merged. The second has. Notice the difference in file size and clearness of the node tree.

User avatar
SGMonkey
P:C Admin
 
Posts: 254
Joined: 15 Dec 2010, 02:51

Re: Proper NIF Handling Practices.

Postby SGMonkey » 30 Jun 2013, 19:16

Been playing around with collision settings in nifskope and I've found out how to make them work exactly as they are in vanilla.

Instead of applying the RootCollisionNode and then setting the NiTriShape Flag to Hidden, no collision.

You should apply a RooCollisionNode, set its flag to 3, and either set the NiTriShape flag to 3, or set the collision detection to Triangles (Same thing, different method).

Setting the NiTriShape to hidden and collision to none works fine but not in all situations. The second way i mentioned is the correct way to do it.

User avatar
HaZard
Pleb
 
Posts: 5
Joined: 12 Feb 2014, 18:18
Location: Nova Scotia

Re: Proper NIF Handling Practices.

Postby HaZard » 12 Feb 2014, 21:20

Incredibly Helpful Guide, Thanks.
"The infinite once fractured, cascading into creation; as one rests their dreary eyes on the chime of nights fold, may the silence of it's glistening tears drip into the depths of consciousness, and settle within the grander purpose."-REGS


Return to Tutorials



Who is online

Users browsing this forum: No registered users and 1 guest