Native Mesh Format

From OpenMW Wiki
Jump to navigation Jump to search

This article explains how to export a model from Blender to OpenMW using the OSG model format. Starting with OpenMW version 0.38 we can utilize the OSG native model format. The OSG model format doesn't yet support all the features that NIF's support, but works for basic models. For more details on the format, refer to this forum post.

Previously, NIF files were the only way to get models into the game. Unfortunately, the NIF format is proprietary, bloated, and the available exporters are not in a great shape. For example, the Blender NIF exporter currently only works with the very old Blender 2.49.

Prerequisites

  • OpenMW 0.38 (commit e62470d67411c665231162959c764c27f4f19e2e) or later
  • Blender 2.6x or later
  • A Blender model you would like to export

Install the exporter

  • Download the OSG export script
  • Open Blender and go to File -> User Preferences
  • Select Add-ons -> Install from File, then select the downloaded .zip
  • Enter "osg" into the search bar, then tick the checkbox next to the add-on to enable it
  • Now click Save user setting so the exporter stays enabled when you re-start Blender

You can now export your models using the OSG model (osgt) entry in the File -> Export menu.

Model's location

When exporting, the model needs to be at 0,0,0 coordinates in Blender, as that's where its origin will always be. If the model is away from 0,0,0 it will be offset in the exported file as well.

Model's rotation

  • Blender's Z axis is up axis in OpenMW.
  • Blender's X axis is...
  • Blender's Y axis is...

(ToDo : check about left-right and front-back axis)

Model's scale

Blender:OpenMW model scale is 70:1 which means 70 Blender units (BU) translate into 1m in OpenMW. Using this scale, any models you make will fit with the existing ones. However, 70 is an odd number to work with so here's a preferred workflow for new models:

  • In Blender, use a scale of 1BU = 1m which is a nice scale and ratio to work with. Have all models use this scale.
  • Before exporting a model, scale it up by a factor of 70.
  • After exporting, undo the model's scale change and continue working as normal (in the future a preferable way would be to apply the scale through the exporter)

Putting the model in-game

Place the exported model in the Meshes sub-folder of a data folder recognized by the game, e.g. the Morrowind Data Files folder, or the local data folder ($HOME/.local/share/openmw/data on Linux). Place all required textures in the Textures sub-folder. Now start OpenMW-CS, create a new addon file and you should see your mesh in the Assets -> Meshes table. Go ahead and make some object use your mesh. You can now preview by right clicking on the object -> Preview to see what the mesh will look like.

Converting the model to binary

When the model behaves to our liking, we can think about converting it from the "osgt" text format to the "osgb" binary format so that it's smaller in size - and thus faster to load.

To do this, simply invoke the osgconv tool. This tool should be included with your distribution of OpensceneGraph.

osgconv -O WriteImageHint=UseExternal model.osgt model.osgb

Of course, you can convert the binary model back to text format as well:

osgconv -O WriteImageHint=UseExternal model.osgb model.osgt


Note the use of -O WriteHint=UseExternal option. Enabling this option is desirable because it keeps the textures as external file references, rather than embedding the textures within the model file. Embedded textures have disadvantages such as being hard to inspect, and impossible to share between model files.

Using shaders / normal maps

See TextureModding#OSG_native_files.

Conclusion

These are the basics of getting a textured, static model from Blender into the game. In the future, we will want a way to add texture animations, skeletal animations, separate collision shapes, and some other features that are currently only available via NIF files. We will likely add these features to the native OSG format after OpenMW 1.0.