Currently it only supports importing basic meshes, but it exports functional models that can be seen in the game.
I'd greatly appreciate help in developing this add-on; please post any fixes or added functionality you can make to the scripts here.
Download the add-on here.
Installation instructions:
Download the .zip file (don't open), and in Blender, go in File > User Preferences, and go in the Add-ons tab.
From there, press "Install Add-on from file", and navigate to the .zip file.
Once you've hit install on that, it's been added to the add-ons list, which you can find and enable by searching "Lego".
Lastly, hit Save User Settings in the bottom left.
Usage instructions:
Every .md2 model in the game (with the sole exception of those with their filename starting with ARCTIC in EDITOR GEN\PATCHES\MODELS, and some slight polygon issues with 26 other models) can now be imported. Simply go in File > Import, and select the .md2 option.
There are currently some issues with all the polygons being inverted in blender, but keep them this way for export, as they'll get inverted again.
To flip normals, in edit mode, press space, and use "Flip Normals".
If you want to export a model, you must stick to a strict scene setup, which emulates the way the model file is structured. An imported model is immediately ready for export.
Imported scene example, ready for export:
The rules are:
An empty, referred to as the root, must be the parent of one or more child empties, referred to as detail levels, which in turn are the parents of one or more child meshes objects, referred to as render groups.
These child meshes are split according to material, which is shown by how they're named in imports. Every mesh needs 1 material.
The material name is the entire path, which is directly inserted into the file, and must start with "game data". The ending of the path is .tga, but the target file ends with a .MIP extension (which is actually just a renamed .tga).
Every polygon must be a triangle, which means no quads or ngons. Triangulate your mesh(es) by being in edit mode, selecting everything (A), and hitting Ctrl + T.
There must be a UV map present, but this is usually not a problem.
Make sure your polygons face inwards before export, as they'll get inverted in the resulting file. This is a bug that I can't figure out how to fix.
The exporter cycles through every object, and finds a root, and determines if it's valid. This means it disregards your selection, and completely ignores all objects directly under the scene that isn't an empty.
You can open .MIP files, which are automatically recognized as .tga files, by opening an image and unchecking the filter. The importer has an option checked on by default that does this for every image used by the model, though you'll have to apply them to the meshes yourself.
This is the import:
This is after importing the model, then exporting it with no changes:
Features I want before I can call this add-on finished:
Full shader support, by means of an easily editable text file created on import.
More flexible scene requirements for export.
Weights and animation support (perhaps the SKN0 chunk in the model, and BSA and BSB files).
Collision data ("COLD" chunk in the files). I have not been successful in deciphering them.
Fixed normals.
Here's a GitHub repository for it.