Changing Skin from Function

MakeHuman python API, python plugins, etc

Moderator: joepal

Changing Skin from Function

Postby lychrel » Tue Jun 13, 2017 5:04 pm

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.
Last edited by lychrel on Tue Jun 13, 2017 5:29 pm, edited 1 time in total.
lychrel
 
Posts: 16
Joined: Mon Jun 05, 2017 7:29 pm

Re: Changing Skin from Function

Postby lychrel » Tue Jun 13, 2017 5:28 pm

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.
lychrel
 
Posts: 16
Joined: Mon Jun 05, 2017 7:29 pm

Re: Changing Skin from Function

Postby lychrel » Tue Jun 13, 2017 5:36 pm

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?
lychrel
 
Posts: 16
Joined: Mon Jun 05, 2017 7:29 pm

Re: Changing Skin from Function

Postby joepal » Tue Jun 13, 2017 6:53 pm

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 ?
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 3613
Joined: Wed Jun 04, 2008 11:20 am

Re: Changing Skin from Function

Postby lychrel » Tue Jun 13, 2017 7:50 pm

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!
lychrel
 
Posts: 16
Joined: Mon Jun 05, 2017 7:29 pm

Re: Changing Skin from Function

Postby joepal » Tue Jun 13, 2017 9:04 pm

Yes, it's a render (OpenGL) issue. It should not affect any exports.
Joel Palmius (LinkedIn)
MakeHuman Infrastructure Manager
http://www.palmius.com/joel
joepal
 
Posts: 3613
Joined: Wed Jun 04, 2008 11:20 am

Re: Changing Skin from Function

Postby lychrel » Tue Jun 13, 2017 10:32 pm

Awesome! I'm trying to adapt the export plugin to mhapi, with plans for Blender imports, so that's good to know.
lychrel
 
Posts: 16
Joined: Mon Jun 05, 2017 7:29 pm


Return to Python scripts

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron