Register | Login

Morrowind Modding History is an affiliate of Great House Fliggerty. Click the link below to register an account at Great House Fliggerty, which you can then use to login here.


Register Now!

Share |
Download >> Mods >> Utilities

NORMALS SMOOTHING GUIDE

by Erstam

Version: 1Added: 2011-10-08Last Edited: 2011-10-08File Size: 34.63 KDownloads: 52

Description:

=============================================
=====----- NORMALS SMOOTHING GUIDE -----=====
=============================================
.... by Erstam


-----===== Introduction =====-----

OK, this is the legendary little proggy I've written to create the (no less legendary) seamless Better Bodies meshes. ;) But you'll see that it certainly does NOT deserve that attribute - it's a very simple console app, user friendliness = near zero. But I hope this little guide will help you to cope with its whims and imperfections.

For some basic knowledge on what the program does, read the first post in this thread (if you haven't already):
http://www.psychodogstudios.net/forums/viewtopic.php?t=3094

You'll need as well: 3ds max 4 or 5 (preferably 4.2), both the official TESExporter and Dave Humphrey's NIF importer, and a hex editor.

I've included the source of the smoother program (MS VC++ 6 project), so if anyone wants to improve on my crappy piece of software, feel free to do so. ;)



-----===== Working with Smoother.exe =====-----

The normals smoothing program (Smoother.exe) averages the normal vectors of corresponding vertices in different submeshes, and patches the result to all the original normals it was calculated from. It uses an ini file named Smoother.ini that contains information about what vertices correspond to another, and the offsets of the normals data tables for each submesh (NiTriShape).

All this ini data has to be set up by hand. How to do this, see the next section. In theory, it would have been possible to let the program automatically decide which vertices occupy the same point in space, but that would have required some really complex programming (including applying transformation matrices for the whole node hierarchy). Since I only had to work on a few meshes, I didn't bother about that. Yeah, I know, I'm lazy...

Smoother.exe, Smoother.ini and the .nif file to patch have to be in the same folder. You'll also need the 1st person hand file. Then simply run Smoother.exe, which patches the body and hand .nifs.

(INFO: the wrist/hand transition is calculated from the wrist and the 3rd person hand mesh, and then copied over to the 1st person hand mesh. This is to ensure that no seams appear in either perspective. One of the 1st person hands is globally rotated around 90°Z in the max scene - the program takes this into account.)

It's a good idea to keep a backup of the original (unsmoothed) meshes and the corresponding Smoother.ini file(s), in case something goes wrong. And be warned, a lot can go wrong. The program has no failsafe mechanisms at all - wrong ini syntax or mismatching data will produce garbage, or even crash the program.

I prefer to create a different folder for each mesh I work on, and put the original mesh there, along with its Smoother.ini. When I'm going to process a mesh, I copy the files into a separate work folder that contains the Smoother program.



-----===== The secrets of Smoother.ini =====-----

(a) General

The best way to understand the Smoother.ini syntax is by studying a sample file. I've included the ini's for the four original BB meshes: male and female, each nude and underwear.

Please use them as a template when you adapt them to your custom meshes. Since the program that parses them is really minimalistic, the syntax has to be followed very strictly. Every comma, space, and blank line is important!


(b) Normals tables offsets

Let's open the ini for the female nude mesh. At the top you see the filenames: bb_skinf_br.nif and bb_handf_br.nif, both followed
by a couple of entries. The numbers at the
beginning of the lines are the byte offsets (decimal values) of the normals tables for each submesh. Everything after the commas is just a comment, for easier reference when you work on the vertex pair data below.

Both lists have to end with a "-1" entry.

So how to get these offsets? That's where the hex editor comes in. Open the nif and search for "NiTriShape" strings. You see the name of the submesh (minus the "Tri ") next to it. Some meshes (Left Foot, Ankle, Knee, and Upper Leg) are empty, they're covered by the opposite body part mesh. You can skip them.

Scroll down a bit until you see a "NiTriShapeData" string. The following two bytes are a short integer that contains the number of vertices in the submesh. Multiply this value by 12, add 10, and add the address/offset of the numVerts integer. The result is the offset of the submesh's normals data. (I could have easily made that procedure simpler by adding a few more code lines to the program, I know...)


(c) Vertex pair data

Now for the larger section of Smoother.ini. Each line represents a group of vertices that occupy the same point in space, and of which the normals vectors have to be averaged/unified.

The first number is the number of vertices in the group. Let's look at the first of these lines. It reads "3, 1-133, 1-220, 2-73". That means, 3 vertices: vertex #133 from submesh 1 (Chest), vertex #220 from submesh 1 (Chest), and vertex #73 from submesh 2 (Groin). You see, that's where the "comments" above come in handy. :)

You can add blank lines at your leisure here, I've done it to group the data after the various mesh transitions.

This section closes with another "-1". The last section tells the program from what vertices in the body .nif the averaged normals have to be copied to the corresponding vertices in the 1st person hand nif. For instance, the line
"6-20, 2, 2-8, 2-12"
means: The normal vector of vertex #20 from submesh 6 (Left Wrist) in bb_skinf_br.nif is to be copied to 2 vertices in bb_handf_br.nif: vertex #8 from submesh 2 (Left Hand), and vertex #12 from submesh 2 (Left Hand).

Finally, to close this section, a "0-0" (no, we aren't playing chess ;)).


(d) Determining vertex numbers

So how do we get the vertex numbers? The simple answer: You can see them in 3ds max. Select a submesh, open the Modify tab in the command panel, go to Vertex sub-object level under "Editable Mesh", and select a vertex. Its number will appear at the bottom of the Selection rollout.

The complex (but important) answer: The vertex numbers in the original .max file are NOT the correct ones. The vertices have to be in the order as they appear in the exported .nif file. On exporting, vertex order gets scrambled, and single vertices that lie along a UV mapping edge, or belong to faces with different smoothing groups, are broken up into two or more vertices at the same place. This is the reason why sometimes groups of three or more vertices have to be smoothed.

The solution: The scene has to be exported first, then reimported into Max. The vertex numbers in the reimported meshes correspond to the order in the .nif file. When selecting a vertex in Max, be sure to click repeatedly on it to see if there aren't actually two or more vertices at the same spot.



-----===== Some hints and observations =====-----

Just changing material properties, such as adding a glow map or an alpha property, doesn't seem to change the order of vertices in the exported mesh. In this case, you only have to change the table offsets, which saves you quite some work. But be sure not to accidentally select any vertex. Moving one vertex only a little bit can definitely change vertex order. Once I noticed this happening out of no apparent reason.

Determining in 3ds max if there are several vertices at a single spot can be a bit tricky. Set the viewport to wireframe, uncheck the "Ignore backfacing" option, and click repeatedly on the vertex without moving the mouse.
Submitted by: jaxawier

Submitter Comments:

File: Smoother.exe
CRC-32: 68907cc6
  MD4: 152667cfc9ddccdfde345efca47eb4ae
  MD5: 9e8459b66f1f01ffe464192fbf0d4e1b
SHA-1: 3d8cfdd72d759dab2152f30dd65c61e317005a71

Admin Comments:

CSS Template by Rambling Soul
cookiecookiecookiecookiecookiecookiecookiecookiecookie