Saving entire models

MakeHuman python API, python plugins, etc

Moderator: joepal

Saving entire models

Postby Shedeki » Fri Dec 09, 2016 12:45 pm

'7_scripting' offers the function 'saveObj()' which -- as its name implies -- saves the current human to an obj file. Unfortunately, it only saves the base (body) mesh together with its material, whereas the GUI's export functionality also saves eyes, teeth, hair, and whatnot. How would you go about achieving something similar in an automatized matter?

Specifically, I want a complete human exported and then import and render it with Blender.
Shedeki
 
Posts: 6
Joined: Mon Dec 05, 2016 11:10 am

Re: Saving entire models

Postby loki1950 » Fri Dec 09, 2016 6:35 pm

Are you trying to use just the cmd line for your export for use in a script or are you just wanting to get the model into blender in that case nhx2 is the best exporter as it has been customised for blender allowing proper materials for both blender render and cycles render.

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: 925
Joined: Thu Dec 18, 2014 6:27 pm
Location: Ottawa,Ontario

Re: Saving entire models

Postby Shedeki » Mon Dec 12, 2016 4:45 pm

loki1950 wrote:Are you trying to use just the cmd line for your export for use in a script [...]

Not sure how the command line factors in, but I need to export the model as the last step of a script that I run via the scripting interface (i.e. I hit the button labeled "execute").
loki1950 wrote:[...] get the model into blender in that case nhx2 is the best exporter as it has been customised for blender allowing proper materials for both blender render and cycles render.

That sounds terrific -- I thought I would have to use a script in Blender to correct the materials. How would nhx2 be accessible from a script?
Shedeki
 
Posts: 6
Joined: Mon Dec 05, 2016 11:10 am

Re: Saving entire models

Postby loki1950 » Mon Dec 12, 2016 5:21 pm

Mhx2 is a plug-in exporter it writes a .json file that the gets imported by the blender importer it is not officially part of MH have a look at our mhx2 sub-forum for the details on where to get it and how to install,it should be callable from your script.

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: 925
Joined: Thu Dec 18, 2014 6:27 pm
Location: Ottawa,Ontario

Re: Saving entire models

Postby Shedeki » Mon Dec 12, 2016 6:27 pm

For reference, this is where mhx2 can currently be found:

https://bitbucket.org/Diffeomorphic/mhx ... n-exchange

I could not figure out how to call the exporter from a script, though. :cry:
Shedeki
 
Posts: 6
Joined: Mon Dec 05, 2016 11:10 am

Re: Saving entire models

Postby drewbeasty » Sat Aug 19, 2017 9:22 pm

I have over 800 morph targets to export. MHScript is ideal for me because it allows me to export all of my custom meshes at once while i sit on couch. Theirs a problem! MHScript.saveObj('Morph Name') only saves base mesh and not the extras that I have applied to my save file mesh MHScript.loadModel('BaseHuman'). I know there is a simple fix for this. I'm new to python and so far it is awesome. But I was wondering have you found a workaround yet for this issue. i really need my eyebrows and hair etc because my mesh look otherwise...naked. In the 7_scripting.py on line 579-583

Code: Select all
def saveObj(self, name, path = mh.getPath('exports')):
        log.message("SCRIPT: saveObj(" + name + "," + path + ")")
        filename = os.path.join(path,name + ".obj")
        import wavefront
        wavefront.writeObjFile(filename, self.human.mesh


I feel like if "self.human.mesh" was something else like "self.human.allmesh" or something. Is any one familiar with this at all. Like I said im new to python and im having trouble figuring out how python is accessing these functions. For example like the import mh or import humanmodifier I think i have looked every were but can find these files to use as reference. I figure the must be pre-compiled inside the .pyd files maybe. Any help in the right direction would be greatly appreciated. Thank you.
drewbeasty
 
Posts: 3
Joined: Wed Oct 07, 2015 1:44 am

Re: Saving entire models

Postby Aranuvir » Sun Aug 20, 2017 11:31 am

Just some observations, though I haven't really played around with this part of code.

If you intend to do scripting at all, it could be helpful to get to know greater parts of the code, so either download MakeHuman source code from bitbucket (P2) or github (P3) and get an IDE of your choice (I'd recommend PyCharm Community Edition) with code inspection functionality. (Though, recently it has become difficult to get all dependencies needed to run from source (= PyQT4), best choice is a Linux platform.)

In your example self.human is defined as:
Code: Select all
from core import G
self.human = G.app.selectedHuman

You can use MakeHuman's built-in data inspection (tab utilities/data) to see what selectedHuman consists of. If you take a look a 9_export_collada/mh2obj.py you can see that selectedHuman provides a method called getObjects, from there you can pull the meshes and so on ...
Code: Select all
objects = self.human.getObjects(excludeZeroFaceObjs=Ture/False)
And then:
Code: Select all
meshes = [o.meshes for o in objects]

It might be helpful to take a look at apps/guiexport.py and shared/wavefront.py, too.

The method writeObjFile from wavefront.py has a glitch in P3, the line
Code: Select all
if isinstance(path, file):

should be replaced by something like
Code: Select all
if isinstance(path, io.IOBase):

or

if hasattr(path, 'write'):

if not the check is superfluous at all. Fixing this in my branch ...
Aranuvir
 
Posts: 1043
Joined: Sun Oct 12, 2014 2:12 pm

Re: Saving entire models

Postby drewbeasty » Fri Aug 25, 2017 11:54 pm

Will pycharm download dependency automatically on linux?
drewbeasty
 
Posts: 3
Joined: Wed Oct 07, 2015 1:44 am

Re: Saving entire models

Postby loki1950 » Sat Aug 26, 2017 1:57 am

drewbeasty wrote:Will pycharm download dependency automatically on linux?


That's a yes if you install it through your distro's package management system that's Apt-get on Debian based ones Yum with fedora,Yast on OpenSUCE or pac-man on BSD based systems if not check pycharm's web site for the deps and you may have to them install the manually. For A Python IDE like Ninja.

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: 925
Joined: Thu Dec 18, 2014 6:27 pm
Location: Ottawa,Ontario

Re: Saving entire models

Postby drewbeasty » Sun Aug 27, 2017 4:03 pm

Success! My first time using Linux(Ubuntu) now I understand why so many ppl use it, very powerful and light weight. Thanks to @Aranuvir @loki1950 for support, Cant wait to use the py3 port of makhuman.
drewbeasty
 
Posts: 3
Joined: Wed Oct 07, 2015 1:44 am


Return to Python scripts

Who is online

Users browsing this forum: No registered users and 0 guests