Difference between revisions of "Nif Optimization"

2,871 bytes added ,  20:10, 23 June 2012
Byline and one broken link removed
imported>Sproaty
(fixed copy/paste mistake)
imported>QQuix
(Byline and one broken link removed)
 
(12 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{Byline}}


[[Category:Modeling Tutorials]]
[[Category:Modeling Tutorials]]
[[Category:Tutorials]]
[[Category:Tutorials]]
Created by [[User:Razorwing|Razorwing]] from [http://www.silgrad.com/ Silgrad Tower]


==Background==
==Background==


My name is Razorwing from the [http://www.silgrad.com/ Silgrad Tower] team. If you're a 3D Studio Max modeller like me and haven't tried [http://niftools.sourceforge.net/forum/profile.php?mode=viewprofile&u=4 amorilia]'s script before you'll most likely want to read this information.
If you're a 3D Studio Max modeller and haven't tried amorilia's script before you'll most likely want to read this information.
 


First I'll make a run-of-the-mill disclaimer that you're using this method at your own risk. It's not tested 100% and could cause you problems. All I can say is that I've used it quite a lot myself and haven't experienced any problems at all.
First I'll make a run-of-the-mill disclaimer that you're using this method at your own risk. It's not tested 100% and could cause you problems. All I can say is that I've used it quite a lot myself and haven't experienced any problems at all.
Line 36: Line 32:
To get the script to work you need Python and PyFFI. Python is an open source programming language, while PyFFI is an interface between Python and nif files.
To get the script to work you need Python and PyFFI. Python is an open source programming language, while PyFFI is an interface between Python and nif files.


*Install [http://www.python.org/download/ Python 2.5] (in this article it will be assume that you use the default installation path, C:\Python25).
*Install [http://www.python.org/download/ Python 2.6] (in this article it will be assume that you use the default installation path, C:\Python26).
*Install [http://sourceforge.net/project/platformdownload.php?group_id=199269&sel_platform=3089 PyFFI].
*Install [http://sourceforge.net/projects/pyffi/files/ PyFFI].


==Using the Script from the Windows Explorer==
==Using the Script from the Windows Explorer==
Line 59: Line 55:


In the text box under "Application used to perform action", you see this text string:
In the text box under "Application used to perform action", you see this text string:
  "C:\Python25\python.exe" "C:\Python25\Scripts\nifoptimize.py" --pause "%1"
  "C:\Python26\python.exe" "C:\Python26\Scripts\niftoaster.py" --pause optimize "%1"
You can add new options between <tt>--pause</tt> and <tt>"%1"</tt>, for instance:
You can add new options between <tt>--pause</tt> and <tt>"%1"</tt>, for instance:
  "C:\Python25\python.exe" "C:\Python25\Scripts\nifoptimize.py" --pause -x NiMaterialProperty "%1"
  "C:\Python26\python.exe" "C:\Python26\Scripts\niftoaster.py" --pause -x NiMaterialProperty optimize "%1"
if you do not want the script to optimize NiMaterialProperty blocks when you run it from the context menu.
if you do not want the script to optimize NiMaterialProperty blocks when you run it from the context menu.


Line 75: Line 71:
*Open the start menu in Windows and select Run ([http://s11.photobucket.com/albums/a177/SilgradTower/AmoriliasScript/RunOnStartMenu.jpg img]). In the popup, write cmd and hit enter ([http://s11.photobucket.com/albums/a177/SilgradTower/AmoriliasScript/cmd.jpg img]). Now a Windows shell with command prompt will appear. [[Image:PythonScriptInDos.jpg|thumb| This is what the DOS window should look like if using the default commands.]]
*Open the start menu in Windows and select Run ([http://s11.photobucket.com/albums/a177/SilgradTower/AmoriliasScript/RunOnStartMenu.jpg img]). In the popup, write cmd and hit enter ([http://s11.photobucket.com/albums/a177/SilgradTower/AmoriliasScript/cmd.jpg img]). Now a Windows shell with command prompt will appear. [[Image:PythonScriptInDos.jpg|thumb| This is what the DOS window should look like if using the default commands.]]
*Type
*Type
  cd C:\Python25
  cd C:\Python26
followed by enter, to tell the Windows shell to go to your Python install folder. If you did not install Python in the default location then just replace the folder with your Python install folder. If you are unsure about where Python is installed, open the start menu then go to "Programs > Python 2.5", right-click any of the shortcuts and choose properties. Open the Shortcut tab, where the Python path is displayed in the "Target:" textbox. Write that url in your DOS window in the same format as the example.
followed by enter, to tell the Windows shell to go to your Python install folder. If you did not install Python in the default location then just replace the folder with your Python install folder. If you are unsure about where Python is installed, open the start menu then go to "Programs > Python 2.6", right-click any of the shortcuts and choose properties. Open the Shortcut tab, where the Python path is displayed in the "Target:" textbox. Write that url in your DOS window in the same format as the example.
*Next, type
*Next, type
  python.exe Scripts\niftoaster.py optimize C:\nifoptimize
  python.exe Scripts\niftoaster.py optimize C:\nifoptimize
followed by enter, to run the niftoaster.py script, which will process all nif files in the folder <tt>C:\nifoptimize</tt> '''including the nifs in all subfolders, subsubfolders, ...''' If you optimize a lot of nif files at the same time, it may be useful to store the output in a file instead of having to browse through the console. You can do this using the following command:
followed by enter, to run the niftoaster.py script, which will process all nif files in the folder <tt>C:\nifoptimize</tt> '''including the nifs in all subfolders, subsubfolders, ...''' If you optimize a lot of nif files at the same time, it may be useful to store the output in a file instead of having to browse through the console. You can do this using the following command:
  python.exe Scripts\niftoasty.py optimize C:\nifoptimize > C:\log.txt
  python.exe Scripts\niftoaster.py optimize C:\nifoptimize > C:\log.txt
which will store all output in the file <tt>C:\log.txt</tt>.
which will store all output in the file <tt>C:\log.txt</tt>.
*If everything works like it should, you should get a warning and a confirmation prompt. Write the letter Y and hit return. Now the program will work it's way through all the nifs in the folder.
*If everything works like it should, you should get a warning and a confirmation prompt. Write the letter Y and hit return. Now the program will work it's way through all the nifs in the folder.
Line 90: Line 86:
The most important command line options are listed here. For a complete list use the '-h' option.
The most important command line options are listed here. For a complete list use the '-h' option.


;-h
====Simple Options====
:Show all command line options with brief help.
 
;-r
For most use cases, these options will suffice.
:Raise exception on errors during optimization. The desired behaviour is simply to print a warning on errors, but continue with the next file nevertheless. If you want the script to halt when it encounters an error, use this option.
 
;-x ''blocktype''
;-x ''blocktype''
:Exclude block type ''blocktype'' from optimization. For example, if you type
:Exclude block type ''blocktype'' from optimization. For example, if you type
  python.exe Scripts\nifoptimize.py -x NiTriStrips C:\nifoptimize
  python.exe Scripts\niftoaster.py -x NiTriStrips optimize C:\nifoptimize
:then the script will not attempt to optimize NiTriStrips blocks (that is, removing duplicate vertices, restripifying, reskinning, and so on). You can accumulate this option to exclude multiple block types.
:then the script will not attempt to optimize NiTriStrips blocks (that is, removing duplicate vertices, restripifying, reskinning, and so on). You can accumulate this option to exclude multiple block types.
  python.exe Scripts\nifoptimize.py -x NiTriStrips -x NiMaterialProperty C:\nifoptimize
  python.exe Scripts\niftoaster.py -x NiTriStrips -x NiMaterialProperty optimize C:\nifoptimize
:will prevent NiTriStrips to be optimized, and will also prevent duplicate NiMaterialProperty blocks to be merged.
:will prevent NiTriStrips to be optimized, and will also prevent duplicate NiMaterialProperty blocks to be merged.
;-i ''blocktype''
:Only optimize block type ''blocktype''. For example, if you type
python.exe Scripts\niftoaster.py -i NiTriStrips optimize C:\nifoptimize
:then the script will only attempt to optimize NiTriStrips blocks (that is, removing duplicate vertices, restripifying, reskinning, and so on). You can accumulate this option to include multiple block types. If not specified, then all block types are included except those listed with the '''-x''' option.
;-h
:Show all command line options with brief help.
====Advanced Options====
These options are mainly useful for debugging.
;-r
:Raise exception on errors during optimization. The desired behaviour is simply to print a warning on errors, but continue with the next file nevertheless. If you want the script to halt when it encounters an error, use this option. Mainly useful for debugging.
;--noninteractive
:Do not ask for confirmation before optimizing all files. Usually, you do not want to use this option, but when you have to run the optimizer many times on the same file for debugging purposes, then this might save you some time.
;--dry-run
:Run the optimizer but save the result to a temporary file instead of overwriting the original files. Again, only useful for debugging.


Good luck, and happy optimizing!
Good luck, and happy optimizing!
==FAQ==
*''Where do I report bugs?'' http://sourceforge.net/tracker/?group_id=199269
*''Is there a visual difference/loss?'' No. If you notice a visual difference between  a nif and its optimized version, please report this as a bug and include the original nif in your report.
*''If the optimizer bails out with an error message like '''*** TEST FAILED ON ... ***''' what does that mean? Is my nif corrupted?'' What you should do is report this as a bug and post the nif with your bug report. Most likely your nif is not corrupted. Whenever the optimizer gives this error, then it will try to restore the original file. As far as is known, this restoration always succeeds. If you need to be absolutely sure, check your nif afterwards and compare it with the original.
*''Does the optimizer act on kf files?'' The current version (as of 19 September 2008) should simply leave them alone as kf files usually do not contain geometry. Future versions might include optimizations also for nif blocks related to animation, and hence, kf files.
*''This is great! Can I run the optimizer on my complete meshes folder?'' The optimizer was not written for this purpose, however some users have reported significant frame rate improvements by doing so. The risk is that it is impossible to manually check each optimized nif, leaving you with possibly corrupted files. So you're on your own. From the official meshes which are stored in the bsa, in these folders no corrupted nifs have yet been found in them after optimizing (starred means making a big difference, so you might want to try these first). ''ALWAYS MAKE A BACKUP.''
**architecture *
**dungeons *
**clutter
**furniture
**landscape
**plants
**rocks
*''So, are there any meshes that I should not run with the optimizer?'' In principle, the optimizer is intended to work with any nif, but of course not every nif has been tested and there might be corner cases where the optimizer will not work, or even corrupt your nif. These are known not to work:
**hair
**helmets
**some creatures
**some clothes
**any nif that has an .egm associated with it
Anonymous user