Models make up:

  • Creature appearances
  • Placeable appearances
  • Item appearances
  • Tileset appearances
  • Visual effects

They are MDL files that can be either compiled (by the game or a compiler) or be in ASCII (inefficient but useful if you've decompiled and need to make tweaks/have the original uncompiled models).

Model Bones Limit

Bone notes. Dem bones. Dem bones. The bone limit has changed throughout NWNs lifetime:

  • 1.69 and earlier: the bones were tied to a skinmesh, and you could have 17 of them.
  • NWN:EE up to patch 8193.19: bones are tied to the model, and you can have 128. Which is both better and worse than 1.69, since if you breach the limit you can't cut up the model into multiple skinmeshed nodes.
  • NWN:EE patch 8193.21, we're back to bones being tied to a skinmesh, but you can only have 64 of them in a single node. Models do support multiple skinmeshes however.
    • There is also a maximum of 4 bones per vertex

Model Triangle Limit

There is around a 11K triangle limit for individual meshes. This is 2^15 / 3 (the max number of vertex indices assigned to a mesh is a signed 16 bit integer, 1 face requires 3 indices), resulting in the total of 10922 faces. It primarily is important for large tiles and placeables.

Note that there is apparently some bugs in relation to splitting up a complex model into multiple meshes if they use the same "bitmap" reference in ASCII, see: https://github.com/Beamdog/nwn-issues/issues/396

Model Editors

There are a few model editors of note.

Blender

Blender is available for free and has Neverblender as a supported and more up to date plugin for NWN:EE being developed in tandem with Blender releases and NWN:EE features. There are several useful plugin lists and tutorials also available.

GMax / 3D Studio Max

GMax was used (and still is) for NWN development with the help of NWMax plugins. See this tutorial for a download and guide or this plugin page. It is however considered legacy and doesn't support all the NWN:EE features such as PBR fancymaps.

Model Compilers and Decompilers

There are several model compilers all with their benefits and drawbacks.

Game Compiler

The in game compiler has all the game supported features and is highly recommended to use. The best option is to load the model in game and compile using compileloadedasciimodels in the console.

If not defined, it has the small drawback of generating vert normals from smoothing groups which can generate seams (only applicable on complex models with multiple skinmeshes).

Remember the console commands needs to have the model(s) to compile loaded in the game in many cases, so get a module with the models placed in it. Once done run these commands from the Console or use the command line parameter.

These all output to a new folder in your user data folder, eg on Windows: Documents\Neverwinter Nights\modelcompiler

The client log will state if a model doesn't compile; usually with an error.

Console CommandParametersDescription and Notes
compileloadedmodels

Compiles all loaded models, including binary.

compileloadedasciimodels

Compiles all loaded models, only ones loaded from ASCII.

This is the recommended way to compile your models, since they should be in ASCII before compiling, and removes some bugs to do with skinmesh or lighting/shadows/generated tangents the command line parameter has.

compilemodel <name>
<name> is a resref name, eg; "mymodel" for "mymodel.mdl"Specific model, will load and unload it for you even if it is not currently loaded. Note: like the command line this will not work with skinmesh models unless the model is loaded and visible to the client (and in those cases just use compileloadedmodels instead).
Command Line ParameterParametersDescription and Notes
nwmain.exe compilemodel <name>
<name> is a resref name, eg; "mymodel" for "mymodel.mdl"

Same as the above console command; will compile the model and exit the game immediately.

Have the model file somewhere the game can find it - eg the override or development folder (development trumps all others if you are using the same model name as base model)

Note 1: Since this isn't properly loading the model in game as such, this may produce the wrong vertex lighting/shadowing, as noted below.

Note 2: Skinmesh models will not compile using this since it has the error in the log:

Model compile error: xxxxxxxxxxx contains skinmeshes not yet initialized. Correct by calling the function with the skinmeshed model in view.

To fix; load the game, load the model into view and use compileloadedasciimodels instead.


Compiling by command line vs. compiling in-game

Note that Merricksdad reports that there may be issues when compiling using nwnmain.exe via command line (see: the below 'PowerShell Script' and 'CMD Script' sections) instead of actually loading the game fully, loading the modules into the game environment (which compiles them) and outputting the compiled versions from there.

Although convenient, compiling via command line may sometimes bake the wrong vertex lighting to each vert, producing polygons of wrong shadowing that you can't remove.


Scripts for batch compiling tile models in-game

Use the following guides to pull all the tile models into a live game session, after which you can use the console to export the compiled versions of your models. Either method should work fine:

https://neverwintervault.org/project/nwn1/script/shadguy-prolerics-moneo-script-tileset-review-area-generation

https://neverwintervault.org/project/nwn1/script/merricksdads-quick-export-all-new-tiles-script


PowerShell Script

On Windows save this as a .ps1 file inside your Documents\Neverwinter Nights\ folder, then put the files to compile in Documents\Neverwinter Nights\development

This is cleverer then the CMD file below and will check for any files that have already been processed.

# By Andrew Armstrong (Jasperre) compile all models in the given folder (development or override)
# Script should be put in the My Document\Neverwinter Nights folder

# Path to folder inside of NWN documents folder; override or development
$folder = "development"

# Path to main EXE location
$runpath = "D:\Steam\steamapps\common\Neverwinter Nights\bin\win32\"

######## Code

Write-Output "Compile Models in $folder folder"

$exepath = $runpath + "nwmain.exe"

if(!(Test-Path $exepath))
{
    Write-Error "Error: Cannot find nwmain.exe. Provided path: $exepath. Exiting..." -Category ObjectNotFound
    return
}

if(!(Test-Path $folder))
{
    Write-Error "Error: folder $folder not found! Exiting..." -Category ObjectNotFound
    return
}

$source = (Get-ChildItem "$folder\*.mdl").BaseName | foreach {$_.Split(".")[0]}
$sourcecount = $source.count*100

if($sourcecount -eq 0)
{
    # What are you doing, no models to compile...
    Write-Error "Error: No models found to compile! Exiting..." -Category ObjectNotFound
    return
}

# Make sure modelcompiler exists
if(!(Test-Path "modelcompiler"))
{
    New-Item -Name "modelcompiler" -ItemType "directory"
}

# If the destination is blank just compile everything
if((Get-ChildItem "modelcompiler\*.mdl").Count -eq 0)
{
    Write-Output "Compiling All models in $folder"
    foreach ($sourcefile in $source)
    {
        $i = $i+1
        Write-Progress -Activity "Compiling Models" -Status "Progress:" -PercentComplete ($i/$sourcecount)

        Write-Output "Compiling $sourcefile"
        Start-Process -FilePath $exepath -WorkingDirectory $runpath -ArgumentList "compilemodel $sourcefile" -WindowStyle Minimized -Wait #-PassThru
    }
}
else
{
    # Compile some things
    Write-Output "Compiling some models in $folder based on what is in modelcompiler folder"

    $destination = (Get-ChildItem "modelcompiler\*.mdl").BaseName | foreach {$_.Split(".")[0]}

    $found = 0
    $foundfile = ""
    $i = 0

    foreach ($sourcefile in $source)
    {
        $i = $i+1
        Write-Progress -Activity "Compiling Models" -Status "Progress:" -PercentComplete ($i/$sourcecount)

        $found = 0
        $foundfile = ""
        foreach ($destinationfile in $destination)
        {
            if($sourcefile -match $destinationfile)
            {
                $found = 1
                $foundfile = $destinationfile
            }
        }
        if($found -eq 1)
        {
            Write-Output "Ignoring $sourcefile since it matches something in the modelcompiler folder"
        }
        else
        {
            Write-Output "Compiling $sourcefile (does not match anything in modelcompiler folder)"
            Start-Process -FilePath $exepath -WorkingDirectory $runpath -ArgumentList "compilemodel $sourcefile" -WindowStyle Minimized -Wait #-PassThru
        }
    }
}

Write-Output "Done Compile Models in $folder folder"


CMD Script

On Windows save this as a .cmd file inside your Documents\Neverwinter Nights\ folder, then put the files to compile in Documents\Neverwinter Nights\development

It's set for the Steam version but alter the path as needed. REM uncomments a line.

::---###############-############-#########-######-###
@echo off
setlocal enabledelayedexpansion
::---###############-############-#########-######-###

call :void_main >"%~n0.log" 2>&1

                goto :end
::---###############-############-#########-######-###

:void_main

rem set "CWD=C:\Users\[user]\Beamdog Library\00785\bin\win32\"
set "CWD=C:\Program Files (x86)\Steam\steamapps\common\Neverwinter Nights\bin\win32\"

for %%F in ("development\*.mdl") do (
    START "" /D "%CWD%" /WAIT /MIN /HIGH nwmain.exe compilemodel "%%~nF"
)

               goto :eof
::---###############-############-#########-######-###

:end

Blender

Has a newer set of plugins in the form of Neverblender which support newer NWN:EE model things, and can export models using normals if you have two different skinmeshes in one model.

Clean Models EE

This tool can do two major things; it will clean up errors in models and do some work on them and compile them, and now for EE properly decompile the new EE model elements back into usable ASCII: https://neverwintervault.org/project/nwnee/other/tool/clean-modelsee

It should be able to safely decompile (use the "Decompile Only" option) but the "cleaning" it does may be bad so avoid it unless you know what you're doing.

NOTE: After investigation even using cleanmodelsee there are some known bugs when decompiling - and therefore it might produce inaccurate source ASCII. One case was found when the node names are past the 32 character limit and then matched. Other issues are creating an inaccurate list of verts or tverts on some models. Use nwnmdlcomp in these cases if it is not EE compiled. Or manually clean up the model after decompiling.

The older version is still available but is now out of date and for 1.69 only: https://neverwintervault.org/project/nwn1/other/cleanmodels3

NWMax for GMax/3D Studio Max

Now quite out of date plugins called NWMax "max-exported models use smoothing group, not explicit normals". It contains no updates for NWN:EE.

nwnmdlcomp

This fails to decompile some NWN:EE compiled models (normals/tangents etc.) but can work on older 1.69 and earlier models (most of the base game models). However do not use this to compile models nowadays, as the game can compile models properly.

nwnmdlcomp is considered out of date for NWN:EE now, see other options above. It has both compiling and decompiling options, but both do not support the latest NWN:EE features, and crashes decompiling things compiled in the engine. This is used pretty much entirely in NWN Explorer still which is why that will crash on newer EE compiled models.

NWN Explorer

This uses nwnmdlcomp as a base so same issues with EE models applies to this as noted below.

NWN Explorer can be used to view older 1.69 models (it misses many newer parameters and settings and crashes on some EE models). You can find the latest EE compatible version here: https://github.com/virusman/nwnexplorer/releases

Even the latest EE compatible version basically uses nwnmdlcomp and thus crashes loading anything that is EE only. Even on older files not using new features, it will cause potentially major export-to-ASCII issues in a number of cases, such as when the node names are more than 32 characters and other edge cases.

  • No labels