Jump to content

[1.2-1.7] Blender (2.83+) .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 , with documentation here.

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

NOTE 2: (for Windows) Blender must not be installed in Program Files. Due to file access permissions, installing blender in Program Files messes with addons resulting in weird errors.

NOTE 3: 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 4: 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 Edit ->  Preferences... -> Add-ons.
  5. Find "Import-Export: Mu model format (KSP)" in the list
  6. Check the checkbox next to it. Clicking on the little triangle to the left will open the configuration panel for the addon. You can...
    1. Set the KSP GameData directory (point it at GameData itself, not just the KSP root directory). Required for craft import
    2. Install shader presets. Optional. These make it easier to set up materials for exported models.
    3. Install config templates (only one right now). Optional and rather advances (ask for details).
    4. Install some color palette presets. Optional for texture painting etc.
  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
Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...
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 EOFError
EOFError

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
raise
RuntimeError: 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!

Link to comment
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.

Link to comment
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.

Link to comment
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!

Link to comment
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.

Link to comment
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!

Link to comment
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 :)

Link to comment
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?)

Link to comment
Share on other sites

  • 2 weeks later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...