Page 1 of 1

Changing Skin from Function

PostPosted: Tue Jun 13, 2017 5:04 pm
by lychrel
I want to load a .mhmat material and apply it to my current human. Reading through the materials module left me in a bit of disarray, but I ended up with the following plugin (excluding the import statements for clarity:

Code: Select all
def load(app):
    skin = 'middleage_darkskinned_female_diffuse'
    path = '/data/skins/' + skin + '/' + skin + '.mhmat'
    G.app.selectedHuman.material = material.fromFile(os.getcwd() + path)

def unload(app):
    pass

But it always says in the terminal that it failed to load the material at 'usr/share/makehuman/data/skins/middleage_darkskinned_female_diffuse/middleage_darkskinned_female_diffuse.mhmat', even though I'm relatively certain that's the correct path:
Code: Select all
loading skin
/data/skins/middleage_darkskinned_female_diffuse/middleage_darkskinned_female_diffuse.mhmat
Loading material from file /usr/share/makehuman/data/skins/middleage_darkskinned_female_diffuse/middleage_darkskinned_female_diffuse.mhmat
Failed to load material from file /usr/share/makehuman/data/skins/middleage_darkskinned_female_diffuse/middleage_darkskinned_female_diffuse.mhmat.

Is this an incorrect use of the fromFile function? Does anyone have experience with loading and setting object materials via Python?

If I figured this out I would move it to a mhapi namespace, along with some of my other procedural-generation code (which does work). I'm just trying to figure out the syntax first.

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 5:28 pm
by lychrel
update: I found fromFile

Code: Select all
    def fromFile(self, filename):
        """
        Parse .mhmat file and set as the properties of this material.
        """
        if type(filename) is bytes:
            filename = filename.decode('utf-8')
        from io import open
        log.debug("Loading material from file %s", filename)
        try:
            f = open(filename, "rU", encoding="utf-8")
        except:
            f = None
        if f == None:
            log.error("Failed to load material from file %s.", filename)
            return

        self.filename = os.path.normpath(filename)
        self.filepath = os.path.dirname(self.filename)

        shaderConfig_diffuse = None
        shaderConfig_bump = None
        shaderConfig_normal = None
        shaderConfig_displacement = None
        shaderConfig_spec = None
        shaderConfig_vertexColors = None
        shaderConfig_transparency = None
        shaderConfig_ambientOcclusion = None


so the terminal output indicates that the open() call using the absolute pathname returns None.

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 5:36 pm
by lychrel
Update: I realized that the same skins don't exist in OS X MakeHuman (from which I was taking filenames) and Linux MakeHuman (in which I was running the plugin). In my case, I was simply attempting to load a material that didn't exist (oops).

However, when the material does load, it looks pretty darn chromatic:

Image

is this one of the settings in the .mhmat file?

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 6:53 pm
by joepal
Does it look ok if it loads from the MH gui? As in, you're not seeing http://www.makehumancommunity.org/wiki/ ... help_me%3F ?

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 7:50 pm
by lychrel
I just checked: all materials look similarly strange when loaded from the materials pane. I'm running this in VirtualBox on a MacBook with a 2.5 GHz Intel Core i7 processor (and Intel Iris Pro 1536 MB for graphics), so I guess it's probably a shader issue. Does that mean that, if I import an mhx2 with one of these materials into Blender, I likely won't see the same issue? I.e., it's a render issue, not a programmatic one?

Thanks!

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 9:04 pm
by joepal
Yes, it's a render (OpenGL) issue. It should not affect any exports.

Re: Changing Skin from Function

PostPosted: Tue Jun 13, 2017 10:32 pm
by lychrel
Awesome! I'm trying to adapt the export plugin to mhapi, with plans for Blender imports, so that's good to know.