Mhx2+ Exporter/Importer

Works in progress and technical screen shots.

Moderator: joepal

Mhx2+ Exporter/Importer

Postby blindsaypatten » Mon Oct 15, 2018 8:26 pm

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" : [
0,1,2,3,4,5,6,7,8,9,
10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,
60,61,62,63,64,65,66,67,68,69,
70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,
350,351,352,353,354,355,356,357,358,359,
360,361,362,363,364,365,366,367,368,369,
370,371,372,373,374,375,376,377,378,379,
380,381,382,383,384,385,386,387,388,389,
390,391,392,393,394,395,396,397,398,399,
400,401,402,403,404,405,406,407,408,409,
410,411,412,413,414,415,416,417,418,419,
420,421,422,423,424,425,426,427,428,429,
430,431,432,433,434   
                    ]
                }
            ]
        }
    ]
}
blindsaypatten
 
Posts: 586
Joined: Tue Mar 14, 2017 11:16 pm

Re: Mhx2+ Exporter/Importer

Postby blindsaypatten » Fri Oct 19, 2018 3:30 am

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.
blindsaypatten
 
Posts: 586
Joined: Tue Mar 14, 2017 11:16 pm

Re: Mhx2+ Exporter/Importer

Postby joepal » Fri Oct 19, 2018 6:03 am

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:

https://en.blender.org/index.php/Extens ... 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.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 4465
Joined: Wed Jun 04, 2008 11:20 am

Re: Mhx2+ Exporter/Importer

Postby blindsaypatten » Wed Nov 07, 2018 6:04 pm

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.

9_export_mhx2plus.zip 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. ;)
Attachments
high_poly4.zip
Example object that has multiple materials
(724.26 KiB) Downloaded 1067 times
weights.mhw
Modified weight painting for shoulders, knees, elbows, for the default topology
(1.03 MiB) Downloaded 1126 times
mhx2plus.zip
Blender importer addon
(387.86 KiB) Downloaded 1042 times
9_export_mhx2plus.zip
MakeHuman exporter plugin
(22.34 KiB) Downloaded 1100 times
blindsaypatten
 
Posts: 586
Joined: Tue Mar 14, 2017 11:16 pm

Re: Mhx2+ Exporter/Importer

Postby Mindfront » Thu Nov 08, 2018 11:29 pm

Very intresting! A must to test. Downloading, and will take a look as soon as possible :D
Mindfront
 
Posts: 228
Joined: Thu Jun 23, 2016 9:20 pm
Location: Sweden

Re: Mhx2+ Exporter/Importer

Postby Dragonshair » Mon Sep 16, 2019 8:28 am

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?
Dragonshair
 
Posts: 10
Joined: Mon Aug 26, 2019 3:24 am
Location: Geurie, NSW

Re: Mhx2+ Exporter/Importer

Postby loki1950 » Mon Sep 16, 2019 4:56 pm

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 :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo Ideapad 320-15ABR Win 10/Mint 19
User avatar
loki1950
 
Posts: 1219
Joined: Thu Dec 18, 2014 6:27 pm
Location: Ottawa,Ontario

Re: Mhx2+ Exporter/Importer

Postby Dragonshair » Mon Sep 16, 2019 9:41 pm

Thank you for the reply.
Dragonshair
 
Posts: 10
Joined: Mon Aug 26, 2019 3:24 am
Location: Geurie, NSW

Re: Mhx2+ Exporter/Importer

Postby MTKnife » Mon Sep 16, 2019 11:30 pm

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.
MTKnife
 
Posts: 311
Joined: Tue Sep 01, 2015 5:22 am

Re: Mhx2+ Exporter/Importer

Postby loki1950 » Tue Sep 17, 2019 2:04 am

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 :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo Ideapad 320-15ABR Win 10/Mint 19
User avatar
loki1950
 
Posts: 1219
Joined: Thu Dec 18, 2014 6:27 pm
Location: Ottawa,Ontario

Next

Return to WIP (Work In Progress)

Who is online

Users browsing this forum: No registered users and 1 guest