7/03/2012

Model Import Presets

Working with Unity3d is typically a pleasure but even after years of development some design quirks remain (beside some technical bugs, but this another story). One of them is the way Unity imports 3d models (typically in ".fbx" format). After adding the file to the project Unity imports the model using default import settings. After the object has been imported it is now possible to alter the import settings by e.g. changing the import scale, mesh optimization etc.

The problem here is that you first have to import the whole model before applying the preferred import settings. One typical issue for example is Unity´s strategy to define the import scale value based on the modelling tool used. If this doesn´t match the developers/designers expectations the import settings have to be adjusted and applied.
Importing huge models (e.g. urban environments) can take a few minutes in Unity. Adjusting and applying custom import settings can take another couple of minutes then.

My solution for this problem is to make use of Unity´s ability to intercept model imports with a custom AssetPostProcessor scripts. Such a script has direct access to import parameters and can alter them before import. Unfortunately this script itself cannot be configured therefore I implemented an editor script where the developer/designer can adjust the model import settings. These settings are stored using Unity´s EditorPrefs handle which stores the settings in the system registry. The AssetPostProcessor script reads the settings from there and applies them on import.

To make this process more flexible I finally added preset support which allows to define different configurations for different types of assets. I´m pretty happy with the result so far although I´m not exceptionally happy with the visual appearance of the UI. Anyway, since the presets are stored into the local registry this data is not shared in a team working on the same project. Therefore one improvement could be to put the preset data into a file instead which can be synchronized with repositories and can be shipped with a project.

I´ve uploaded the final code to Unify Community for all. I hope it helps to streamline the import process for others as well.

No comments:

Post a Comment