[1.2-1.7] Blender (2.80) .mu import/export addon

Recommended Posts

Hello, I have been working on an addon for Blender to import and export .mu files. It is still very incomplete, but I have released it under the GNU General Public License (version 2), and it is available from github.

NOTE: The addon is now targeted for Blender 2.80. Those requiring 2.79 support should checkout the blender2.79 branch.

NOTE 2: Blender won't load the plugin if the directory name has periods in it, so if the resulting directory has periods in it, you will need to rename it.

NOTE 3: I haven't done an actual release for a long time, nor do I have plans to do so any time soon, so ignore the release section on github and just clone the repository. I do update the code whenever something comes up.

For help with Blender in general, #blender on irc.freenode.net is generally full of experts.

However, thanks to @Snark, here are some installation instructions:

1. Clone the github repo
2. Copy the entire folder (io_object_mu) into Blender's scripts/addons folder
3. Start Blender
4. Go to File ->  User Preferences... -> Add-ons tab -> Import-Export category
5. Find "Import-Export: Mu model format (KSP)" in the list
6. Check the checkbox next to it
7. Click "Save User Settings"
8. If you go to the File -> Import menu, it now has "KSP Mu" and "KSP Craft" in the list.

Working features

• Import .mu into blender. Meshes, materials, textures (including .mbm) and colliders supported. Many animation properties are supported (transform, light, material (not texture))
• Export from blender to .mu. Same as features and limitations as import, however .mbm is not written.
• Unity colliders can be added via the Add menu. Updating the collider via the tool panel or the object panel works as expected (ie, visual updates). Note that other than mesh colliders, editing the mesh of the collider will have no effect.
• Create mesh colliders from multiple selected mesh objects. Optionally (default) "convert" the mesh to a convex hull as Unity (and thus KSP) requires part mesh colliders to be convex.
• Convex hull creation can be used separately as a modeling tool.
• KSP shaders can be created by selecting the shader type in the materials panel. The material will be built automatically any time something is changed (a little inefficient, but it works (actually, it doesn't right now)). The material setup is really just a best-effort WYSIWYG thing.
• Standalone (still requires python to run) command line script that lets you view and edit wheel collider parameters.
• Skins (bones) working for both import and export.
• v4 materials for import, possibly for export (not fully tested).

Plans (no particular order):

• More animations.
• Bones and skins (WIP).
• Better IVA support (WIP?)

Export is simple: select the root object, then File->Export->KSP Mu. The active object and all of its children (of supported types) will be exported to the one .mu file.

Edited by taniwha

Share on other sites

Even if I don't modeling, this is a great thing!

A Im-/Exporter for blender should make things very easy for model creators!

Share on other sites

How do you use this?

Share on other sites

For the blender addon, you just copy the entire directory into your addons directory, enable it like any other addon (there are tuts for this on places like blendercookie.com), and then File->Import->KSP Mu. Export is not working yet.

For using mu.py for creating utilities, it would probably be best to study the code and import.py.

I'm sorry I can't be of more help just now. This is very much a work in progress (I announced it now only because I used it to help fix the Extraplanetary Launchpads auger), and I'm a bit busy trying to help fix bugs in the mod.

Share on other sites

Awesome! Works perfectly so far with the import.

Have you got any plans for adapting the script for 3Ds Max/Maya?

Share on other sites

No, as I use/know neither. However, as I've released the code under the GPL, you're free to do so (or find someone who can).

Just as a note: I'm aware that my scripts do not read version 3 .mu files (eg, current LV-909). I'll look into that soon.

Share on other sites
Just as a note: I'm aware that my scripts do not read version 3 .mu files (eg, current LV-909). I'll look into that soon.

It seems that nearly all of the models have been "upgraded" to version 3. The only one I've been able to import is the Mk2 fuselage (I tried quite a few, but not all of them). This is such a great tool, but it doesn't seem to work for most of the KSP models... help?

Here's an error that pops up when I try to import the latest "Parts\Engine\microEngine\model.mu" or "Parts\Aero\rocketNoseCone\model.mu"

Traceback (most recent call last):  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\__init__.py", line 63, in execute    return import_mu.import_mu(self, context, **keywords)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\import_mu.py", line 167, in import_mu    if not mu.read(filepath):  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 970, in read    self.obj = MuObject().read(self)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 791, in read    self.children.append(MuObject().read(mu))  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 809, in read    self.renderer = MuRenderer().read(mu)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 552, in read    self.materials = mu.read_int(num_mat, True)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 869, in read_int    raise EOFErrorEOFError

and here's another slightly different one when I try "Parts\FuelTank\mk3Fuselage\model.mu"

Traceback (most recent call last):  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\__init__.py", line 63, in execute    return import_mu.import_mu(self, context, **keywords)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\import_mu.py", line 167, in import_mu    if not mu.read(filepath):  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 970, in read    self.obj = MuObject().read(self)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 791, in read    self.children.append(MuObject().read(mu))  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 791, in read    self.children.append(MuObject().read(mu))  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 805, in read    self.collider = MuCollider(entry_type).read(mu)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 601, in read    self.mesh = MuMesh().read(mu)  File "C:\Program Files\Blender Foundation\Blender\2.67\scripts\addons\io_object_mu-master\mu.py", line 446, in read    raiseRuntimeError: No active exception to reraise

When I try to open "Parts\Electrical\batteryBankLarge\model.mu" it just says

Unrecognized format: 76543 3

So, looks like more than one problem involved here. Looking forward to any progress, as I'd love to have use of this tool back.

Thanks!

Share on other sites

batteryBankLarge import worked for me. Make sure you update your version of blender. It wouldn't work for me when I had 2.66a but when I upgraded to 2.68a I was able to import the batteryBankLarge.

This also worked for the microEngine and the rocketNoseCone.

Only one that didn't work out of your set was the mk3Fuselage.

Share on other sites

Those errors are actually from bones and bone related information in the .mu, not v3 stuff. I've recently pushed fixes for that (which might be why sirkut had no trouble).

As for v3 .mu: as far as I can tell, that's all particles related. I haven't started working on that yet as I've been concentrating on getting import and export working for v2.

Share on other sites
Those errors are actually from bones and bone related information in the .mu, not v3 stuff. I've recently pushed fixes for that (which might be why sirkut had no trouble).

As for v3 .mu: as far as I can tell, that's all particles related. I haven't started working on that yet as I've been concentrating on getting import and export working for v2.

So far you are doing a splendid job. You actually saved my butt one time when I had a hard drive crash and lost a part I was working on and all I had was a beta part mu.

Odd thing is I've had a few times where I couldn't open one of my Infernal Robotics parts but later on it will work just fine. Weird!

Share on other sites

That is rather weird.

I'm glad my code has been of use

Share on other sites
That is rather weird.

I'm glad my code has been of use

Immensely. It helps to get some dimensions correct with outside parts. If you ever need anyone to test anything I'll be more than happy to help.

Share on other sites

Eh? It's right there in the first paragraph (for those who know what it means, I guess).

Share on other sites

Funny. I didn't bother reading that part of your post, I immediately jumped to github to try this out when I first saw mu import. There I saw the copying file

Share on other sites

heh. Too excited to read the (not so) fine print, eh?

Share on other sites

Ok, a little bit of an update.

I have colliders mostly working. You get nice little wire meshes showing the shapes, and a panel to configure them (wheels not fully implemented due to laziness). I've also added a sub-menu to add the various collider types, and the size/shape params can be adjusted, but currently only immediately after adding (via the usual blender method). The fields can be updated in the panel, but they don't have any visible effect.

KSP shader support is mostly done: you can create and configure KSP shaders in the material panel, and it will automatically create the material nodes in an attempt to give WYSIWYG in GLSL mode (bump maps are a bit broken, I need to look into that).

Exporting is getting close. Just need to transfer the shader info from blender to my internal mu object, and then I can write that to disk.

After that, lots of testing and bug fixing. Massaging blender mesh data into something suitable for .mu is a slightly complicated process, so I expect some initial breakage.

Share on other sites
Ok, a little bit of an update.

I have colliders mostly working. You get nice little wire meshes showing the shapes, and a panel to configure them (wheels not fully implemented due to laziness). I've also added a sub-menu to add the various collider types, and the size/shape params can be adjusted, but currently only immediately after adding (via the usual blender method). The fields can be updated in the panel, but they don't have any visible effect.

KSP shader support is mostly done: you can create and configure KSP shaders in the material panel, and it will automatically create the material nodes in an attempt to give WYSIWYG in GLSL mode (bump maps are a bit broken, I need to look into that).

Exporting is getting close. Just need to transfer the shader info from blender to my internal mu object, and then I can write that to disk.

After that, lots of testing and bug fixing. Massaging blender mesh data into something suitable for .mu is a slightly complicated process, so I expect some initial breakage.

Oh hell yes. Thanks for updating!

Excellent work!

Share on other sites

Way, way too cool taniwha.

I've managed to import the Mk1-2 Pod into Blender 2.68a, textures and all - it has been exceptionally handy in making sure my upcoming accessories would mesh perfectly with it.

As soon as the the forums' AJAX features get fixed, expect a +1 rep from me

Share on other sites

I've pushed exporting (animations not supported). uv2 is not written at this stage (not sure what it's for, even: mk1pod has identical uv and uv2 maps), but re-importing the exported .mu worked .

Share on other sites

I've updated the first post with the current status. I'm 30 bytes away from a re-export of the mk1 command pod being near-perfect (I expect that exact vertex order will always be a mess, but I have an idea for that, and normals and tangets... who knows?)

Share on other sites

Amazing Takes a lot to import anything, but works!

Share on other sites

Now give us a tool that opens .mu files in unity to give exactly what was previously exported back!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.