Difference between revisions of "Nif Optimization"

822 bytes added ,  20:10, 23 June 2012
Byline and one broken link removed
imported>Amorilia
(updated nifoptimize.py -> niftoaster.py optimize)
imported>QQuix
(Byline and one broken link removed)
 
(8 intermediate revisions by 5 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\niftoaster.py" --pause optimize "%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\niftoaster.py" --pause -x NiMaterialProperty optimize "%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
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
Line 100: Line 96:
  python.exe Scripts\niftoaster.py -x NiTriStrips -x NiMaterialProperty optimize 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!
Line 118: Line 131:
**rocks
**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:
*''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:
**head nifs
**hair
**helmets
**some creatures
**some clothes
**any nif that has an .egm associated with it
Anonymous user