Page 1 of 2

Mhx2+ Exporter/Importer

PostPosted: Mon Oct 15, 2018 8:26 pm
by blindsaypatten
Well, I finally got my enhanced exporter working and supporting multiple materials per object!

The exporter plugin for MakeHuman is a modification of the standard mhx2 exporter that adds additional material data to the exported .mhx2 file. The addition to the .mhx2 file is ignored by the standard Blender .mhx2 importer. The additional materials are kept in a .mham file in the same directory as the .mhclo file. The file is in json format, the material is represented the same way materials are represented in the current .mhx2 export files. There is also a list of geometries which specify the material and the faces it applies to.

Of course for an exporter you need a matching importer and I have written a Blender importer addon that handles the additional information. It's a stripped down version of the standard addon that only handles importing a toon "as is" without all the transformations and runtime support in the standard importer-runtime addon. It will also make use of the Principled shader in recent versions of Blender where they are available. And of course it includes the bug fixes I've previously posted for the standard importer.

The final piece of the puzzle, which I haven't written/adapted yet is an addon for Blender that writes out a .mham file for an object. Hopefully I can use the code in MakeHuman as a starting point. I'm also going to look at saving the material nodes more directly since they won't go through MH anyway.

Anyway, I'm now at the point where I can add materials to objects and have them handled automatically every time I export them to Blender, without my having to do anything manually after importing them.

If there's any interest I'll make them available after I clean them up a bit.

Sample .mham file:
Code: Select all
    "mhx2_version" : "0.30",
    "materials" : [
            "name" : "High_poly4glass",
            "diffuse_color" : [0.64,0.64,0.64],
            "diffuse_map_intensity" : 1,
            "specular_color" : [0.5,0.5,0.5],
            "specular_map_intensity" : 1,
            "shininess" : 1,
            "opacity" : 0,
            "translucency" : 0,
            "emissive_color" : [0,0,0],
            "ambient_color" : [1,1,1],
            "transparency_map_intensity" : 1,
            "shadeless" : false,
            "wireframe" : false,
            "transparent" : true,
            "alphaToCoverage" : true,
            "backfaceCull" : true,
            "depthless" : false,
            "castShadows" : true,
            "receiveShadows" : true,
            "sssEnabled" : false,
            "sssRScale" : 0,
            "sssGScale" : 0,
            "sssBScale" : 0,
            "diffuse_texture" : "textures/brown_eye.png",
            "specular_map_texture" : "textures/EyeballSpecular.png"
    "geometries" : [
            "auxmaterials" : [
                    "material" : "High_poly4glass",
                    "faces" : [

Re: Mhx2+ Exporter/Importer

PostPosted: Fri Oct 19, 2018 3:30 am
by blindsaypatten
I wrote the code to save a material node setup to a json file, as well as the code to read the json file back and recreate the node setup. It recreates the nodes, with the same position and size, and puts in all the links between nodes. I need to think about how best to set all the other values on nodes. There are dozens of attributes on the nodes, of a wide variety of types, some of which are read-only, so I need to consider how far I want to go with that. Since the json files are human-readable text files they can always be tweaked to set values that I don't choose to deal with.

The more I think about it, the more I like the idea of being able to save the exact Blender material, and then restore it automatically when the toon goes back to Blender.

A possible side-benefit is that all the Blender material information gets stored in a simple text file, which means that someone can use it to translate to other formats without having to take a deep dive into Blender's internals. One could possibly achieve better fidelity than they would passing through the .mhmat format, for example making use of roughness textures.

What endless fun this is!

I think sometime soon I'll expunge the remaining layer-related code from my mhx2 importer so that it will work on Blender 2.8.

Re: Mhx2+ Exporter/Importer

PostPosted: Fri Oct 19, 2018 6:03 am
by joepal
I've been researching serializing/deserializing cycles materials earlier. It seems the common approach for the various material libraries out there is saving them as .blend, but there is also at least one attempt at serializing them as XML: ... al_Library

This never seemed to get much traction though, and the latest version it is specified to be working with is blender 2.66. Also, there's not much documentation around.

Re: Mhx2+ Exporter/Importer

PostPosted: Wed Nov 07, 2018 6:04 pm
by blindsaypatten
While still experimental, I'm attaching my MHX2+ MakeHuman exporter, Blender importer, an example weights file with somewhat improved weight paintings for the shoulders, knees, and elbows, and a eyes object as an example of an object that has multiple materials.

It is now at the point where I can export from MakeHuman and import into Blender without having to do manual tweaks. Depending on the options selected it will automatically add corrective smooth and subsurf modifiers and load a customized weight painting if you have one. should be unzipped into the <makehuman-install-dir>/plugins directory. It adds an additional export option rather than modifying the existing one, so it should not interfere with the existing mhx2 exporter.

mhx2plus should be loaded into blender using the File, User Preferences, Addons tab, Load from file button. Again, it provides an additional option in the File, Export menu and should not interfere with the existing mhx2 importer-runtime. mhx2plus is strictly an importer, it doesn't support the various override and runtime options offered by the existing mhx2 addon.

weights.mhw should be placed in the same directory as the .mhx2 file is exported to. The blender importer will load it if it finds it there, although this can be turned off in the import panel in the choose file screen. I decided to structure it this way to avoid having to modify the default weights in the makehuman installation. For some reason the weights that work in Blender have some odd glitches when used in MakeHuman. The downside is that you have to match your weights file to the body topology you use yourself, the attached weights file for example only works for the default topology; and it only repaints the body, so clothes may have issues where the new painting significantly changes the way the body mesh is modified. In theory a weight painting can be transferred/copied from the body mesh to the clothes mesh in Blender, although I haven't tried that yet.

high_poly4 should be unzipped in your <home/documents>/makehuman/v1/data/eyes directory. It is an eye that uses as single mesh with a cornea instead of having a transparent glossy mesh over top of the eyeball mesh. I have not yet taken the time to alter the uvmap to show the iris in makehuman, so the iris is displayed as white in MakeHuman. The second material is a transparent material for the cornea. The second material is in the .mham file in the directory.

I have not yet included the code to allow you to save a Blender material node graph and then get that exact material restored when you import a model back into Blender.

If anyone tries it out I would welcome feedback, try not to be too vicious. ;)

Re: Mhx2+ Exporter/Importer

PostPosted: Thu Nov 08, 2018 11:29 pm
by Mindfront
Very intresting! A must to test. Downloading, and will take a look as soon as possible :D

Re: Mhx2+ Exporter/Importer

PostPosted: Mon Sep 16, 2019 8:28 am
by Dragonshair
I don't suppose there is any chance of this being set up as an .exe file for the less technically inclined of up, please?

Re: Mhx2+ Exporter/Importer

PostPosted: Mon Sep 16, 2019 4:56 pm
by loki1950
Setting it up as an exe limits the solution to Windows what are Mac and Linux users supposed to do just a reminder we have to provide solutions that work on all three platforms.

Enjoy the Choice :)

Re: Mhx2+ Exporter/Importer

PostPosted: Mon Sep 16, 2019 9:41 pm
by Dragonshair
Thank you for the reply.

Re: Mhx2+ Exporter/Importer

PostPosted: Mon Sep 16, 2019 11:30 pm
by MTKnife
There's no reason you can't have executables for multiple operating systems, with appropriate extensions (or lack thereof) for each--indeed, the "Downloads" link above links to different compiled versions of Makehuman itself for different operation systems. It does however take a programmer extra work to do that.

Re: Mhx2+ Exporter/Importer

PostPosted: Tue Sep 17, 2019 2:04 am
by loki1950
Almost all of of your work is in Python and meant to work within makehuman or blender not as stand alone programs so binaries are just not needed and even more confusing for non power users.

Enjoy the Choice :)