def loadMhpFile(self, filepath): 
    
        log.message("Load Mhp: %s", filepath)

        human = gui3d.app.selectedHuman

        if os.path.basename(filepath) == "clear.mhp":
            posemode.exitPoseMode()
            posemode.resetPoseMode()
            return

        posemode.enterPoseMode()
        folder = os.path.dirname(filepath)
        (fname, ext) = os.path.splitext(os.path.basename(filepath))
        modpath = '%s/${gender}-${age}-${tone}-${weight}-%s.target' % (folder, fname)
        modpath = modpath.replace("\\","/")
        log.debug('PoseLoadTaskView.loadMhpFile: %s %s', filepath, modpath)
        modifier = PoseModifier(modpath)
        modifier.updateValue(human, 1.0)
        
        amt = human.armature
        if amt:
            pass
            #amt.rebuild()
        else:
            amt = human.armature = armature.rigdefs.createRig(human, "soft1")            
        amt.setModifier(modifier)
        amt.readMhpFile(filepath)
Esempio n. 2
0
def exportMhx(human, filename, options):  
    posemode.exitPoseMode()        
    posemode.enterPoseMode()
    config = export_config.exportConfig(human, True, options)
    (fpath, ext) = os.path.splitext(filename)

    if '24' in config.mhxversion:
        mhx_24.exportMhx(human, filename, options, config)
   
    if '25' in config.mhxversion:
        time1 = time.clock()
        fname = os.path.basename(fpath)
        the.Human = fname.capitalize().replace(' ','_')
        outfile = export_config.getOutFileFolder(filename, config)        
        try:
            fp = open(outfile, 'w')
            log.message("Writing MHX 2.5x file %s", outfile )
        except:
            log.message("Unable to open file for writing %s", outfile)
            fp = 0
        if fp:
            #cProfile.runctx( 'exportMhx_25(human, config, fp)', globals(), locals())
            exportMhx_25(human, config, fp)
            fp.close()
            time2 = time.clock()
            log.message("Wrote MHX 2.5x file in %g s: %s", time2-time1, outfile)

    posemode.exitPoseMode()        
    return        
Esempio n. 3
0
def exportMhx(human, filename, options):
    posemode.exitPoseMode()
    posemode.enterPoseMode()
    config = export_config.exportConfig(human, True, options)
    (fpath, ext) = os.path.splitext(filename)

    if '24' in config.mhxversion:
        mhx_24.exportMhx(human, filename, options, config)

    if '25' in config.mhxversion:
        time1 = time.clock()
        fname = os.path.basename(fpath)
        the.Human = fname.capitalize().replace(' ', '_')
        outfile = export_config.getOutFileFolder(filename, config)
        try:
            fp = open(outfile, 'w')
            log.message("Writing MHX 2.5x file %s", outfile)
        except:
            log.message("Unable to open file for writing %s", outfile)
            fp = 0
        if fp:
            #cProfile.runctx( 'exportMhx_25(human, config, fp)', globals(), locals())
            exportMhx_25(human, config, fp)
            fp.close()
            time2 = time.clock()
            log.message("Wrote MHX 2.5x file in %g s: %s", time2 - time1,
                        outfile)

    posemode.exitPoseMode()
    return
Esempio n. 4
0
def exportFbx(human, filepath, options):
    posemode.exitPoseMode()
    posemode.enterPoseMode()

    the.Human = human
    the.Config = export_config.exportConfig(human, True, [])
    the.Config.separatefolder = True
    outfile = export_config.getOutFileFolder(filepath, the.Config)
    (outpath, ext) = os.path.splitext(outfile)

    log.message("Write FBX file %s" % outfile)

    rawTargets = []
    if options["expressions"]:
        shapeList = read_expression.readExpressionUnits(human, 0, 1)
        rawTargets += shapeList

    if options["customshapes"]:
        the.Config.customshapes = True
        mhx_custom.listCustomFiles(the.Config)

        log.message("Custom shapes:")
        for path, name in the.Config.customShapeFiles:
            log.message("    %s", path)
            shape = mhx_custom.readCustomTarget(path)
            target = (name, shape)
            rawTargets.append(target)

    rigfile = "data/rigs/%s.rig" % options["fbxrig"]
    stuffs = object_collection.setupObjects(
        os.path.splitext(outfile)[0],
        human,
        rigfile,
        rawTargets=rawTargets,
        helpers=options["helpers"],
        hidden=options["hidden"],
        eyebrows=options["eyebrows"],
        lashes=options["lashes"],
    )

    (scale, unit) = options["scale"]

    bpy.initialize()
    name = os.path.splitext(os.path.basename(filepath))[0]
    boneInfo = stuffs[0].boneInfo
    rig = bpy.addRig(name, boneInfo)
    for stuff in stuffs:
        ob = bpy.addMesh(stuff.name, stuff, True)
        ob.parent = rig

    # name = os.path.splitext(os.path.basename(filepath))[0]
    # bpy.addMesh(name, human.meshData, False)

    filename = "%s.fbx" % outpath
    io_mh_fbx.fbx_export.exportFbxFile(bpy.context, filename)
    posemode.exitPoseMode()
    return
Esempio n. 5
0
def exportFbx(human, filepath, options):
    posemode.exitPoseMode()        
    posemode.enterPoseMode()
    
    the.Human = human        
    the.Config = export_config.exportConfig(human, True, [])
    the.Config.separatefolder = True
    outfile = export_config.getOutFileFolder(filepath, the.Config)        
    (outpath, ext) = os.path.splitext(outfile)

    log.message("Write FBX file %s" % outfile)

    rawTargets = []
    if options["expressions"]:
        shapeList = read_expression.readExpressionUnits(human, 0, 1)
        rawTargets += shapeList

    if options["customshapes"]:
        the.Config.customshapes = True
        mhx_custom.listCustomFiles(the.Config)                            

        log.message("Custom shapes:")    
        for path,name in the.Config.customShapeFiles:
            log.message("    %s", path)
            shape = mhx_custom.readCustomTarget(path)
            target = (name,shape)
            rawTargets.append(target)

    rigfile = "data/rigs/%s.rig" % options["fbxrig"]
    stuffs = object_collection.setupObjects(
        os.path.splitext(outfile)[0], 
        human, 
        rigfile, 
        rawTargets=rawTargets,
        helpers=options["helpers"], 
        hidden=options["hidden"], 
        eyebrows=options["eyebrows"], 
        lashes=options["lashes"])

    (scale, unit) = options["scale"]   

    bpy.initialize()
    name = os.path.splitext(os.path.basename(filepath))[0]
    boneInfo = stuffs[0].boneInfo
    rig = bpy.addRig(name, boneInfo)
    for stuff in stuffs:
        ob = bpy.addMesh(stuff.name, stuff, True)
        ob.parent = rig
        
    #name = os.path.splitext(os.path.basename(filepath))[0]
    #bpy.addMesh(name, human.meshData, False)
    
    filename = "%s.fbx" % outpath
    io_mh_fbx.fbx_export.exportFbxFile(bpy.context, filename)
    posemode.exitPoseMode()        
    return
    def loadExpression(self, filename, include):
        human = gui3d.app.selectedHuman
        posemode.enterPoseMode()
        self.resetExpressions(include)

        f = open(filename, 'r')
        for data in f.readlines():
            lineData = data.split()
            if len(lineData) > 0 and not lineData[0] == '#':
                if lineData[0] == 'expression':
                    modifier = self.modifiers.get(lineData[1], None)
                    if modifier:
                        value = float(lineData[2])
                        modifier.setValue(human, value)
                        modifier.updateValue(human, value)  # Force recompilation
        gui3d.app.setFaceCamera()
    def loadExpression(self, filename, include):
        human = gui3d.app.selectedHuman
        posemode.enterPoseMode()
        self.resetExpressions(include)

        f = open(filename, 'r')
        for data in f.readlines():
            lineData = data.split()
            if len(lineData) > 0 and not lineData[0] == '#':
                if lineData[0] == 'expression':
                    modifier = self.modifiers.get(lineData[1], None)
                    if modifier:
                        value = float(lineData[2])
                        modifier.setValue(human, value)
                        modifier.updateValue(human,
                                             value)  # Force recompilation
        gui3d.app.setFaceCamera()
Esempio n. 8
0
    def onShow(self, event):
        gui3d.TaskView.onShow(self, event)
        self.filechooser.setFocus()

        self.posefile = posemode.enterPoseMode()
        if self.posefile:
            self.pose = posemode.loadMhpFile(self.posefile)
        else:
            self.pose = None
Esempio n. 9
0
def exportFbx(human, filepath, config):
    posemode.exitPoseMode()
    posemode.enterPoseMode()

    config.setHuman(human)
    config.setupTexFolder(filepath)

    log.message("Write FBX file %s" % filepath)
    print(config)

    rigfile = "data/rigs/%s.rig" % config.rigtype
    rawTargets = exportutils.collect.readTargets(human, config)
    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    stuffs = exportutils.collect.setupObjects(name,
                                              human,
                                              config=config,
                                              rigfile=rigfile,
                                              rawTargets=rawTargets,
                                              helpers=config.helpers,
                                              eyebrows=config.eyebrows,
                                              lashes=config.lashes)

    bpy.initialize(human, config)
    boneInfo = stuffs[0].boneInfo
    rig = bpy.addRig(name, boneInfo, scale=config.scale)
    for stuff in stuffs:
        ob = bpy.addMesh(stuff.name,
                         stuff,
                         rig,
                         isStuff=True,
                         scale=config.scale)

    #name = os.path.splitext(os.path.basename(filepath))[0]
    #bpy.addMesh(name, human.meshData, isStuff=False)

    gui3d.app.progress(0, text="Exporting %s" % filepath)
    io_fbx.fbx_export.exportFbxFile(bpy.context,
                                    filepath,
                                    scale=1.0,
                                    encoding=config.encoding)
    gui3d.app.progress(1)
    posemode.exitPoseMode()
    return
    def loadMhpFile(self, filepath):

        log.message("Load Mhp: %s", filepath)

        human = gui3d.app.selectedHuman

        self.lastPose = filepath

        if os.path.basename(filepath) == "clear.mhp":
            posemode.exitPoseMode()
            posemode.resetPoseMode()
            return

        posemode.enterPoseMode()
        folder = os.path.dirname(filepath)

        hasTargets = False
        for file in os.listdir(folder):
            if os.path.splitext(file)[1] == ".target":
                hasTargets = True
                break

        if hasTargets:
            (fname, ext) = os.path.splitext(os.path.basename(filepath))
            filenamePattern = "${gender}-${age}-${tone}-${weight}-%s.target" % fname
            modpath = os.path.join(folder, filenamePattern)
            log.debug("PoseLoadTaskView.loadMhpFile: %s %s", filepath, modpath)
            modifier = PoseModifier(modpath)
            modifier.updateValue(human, 1.0)
        else:
            modifier = None

        amt = human.armature
        print("AMT", amt)
        if amt:
            pass
            # amt.rebuild()
        else:
            amt = human.armature = amtpkg.rigdefs.createPoseRig(human, "soft1")
        print("New", amt)
        print(amt.bones.keys())
        amt.setModifier(modifier)
        amt.readMhpFile(filepath)
    def loadMhpFile(self, filepath): 
    
        log.message("Load Mhp: %s", filepath)

        human = gui3d.app.selectedHuman

        self.lastPose = filepath

        if os.path.basename(filepath) == "clear.mhp":
            posemode.exitPoseMode()
            posemode.resetPoseMode()
            return

        posemode.enterPoseMode()
        folder = os.path.dirname(filepath)

        hasTargets = False
        for file in os.listdir(folder):
            if os.path.splitext(file)[1] == ".target":
                hasTargets = True
                break

        if hasTargets:                
            (fname, ext) = os.path.splitext(os.path.basename(filepath))
            filenamePattern = "${gender}-${age}-${tone}-${weight}-%s.target" % fname
            modpath = os.path.join(folder, filenamePattern)
            log.debug('PoseLoadTaskView.loadMhpFile: %s %s', filepath, modpath)
            modifier = PoseModifier(modpath)
            modifier.updateValue(human, 1.0)
        else:
            modifier = None
        
        amt = human.armature
        print("AMT", amt)
        if amt:
            pass
            #amt.rebuild()
        else:
            amt = human.armature = amtpkg.rigdefs.createPoseRig(human, "soft1")            
        print("New", amt)
        print(amt.bones.keys())
        amt.setModifier(modifier)
        amt.readMhpFile(filepath)
Esempio n. 12
0
    def onShow(self, event):
        gui3d.TaskView.onShow(self, event)
        self.filechooser.setFocus()
        if gui3d.app.settings.get('cameraAutoZoom', True):
            gui3d.app.setGlobalCamera()

        self.posefile = posemode.enterPoseMode()
        if self.posefile:
            self.pose = posemode.loadMhpFile(self.posefile)
        else:
            self.pose = None
Esempio n. 13
0
def exportFbx(human, filepath, config):
    posemode.exitPoseMode()        
    posemode.enterPoseMode()
    
    config.setHuman(human)
    config.setupTexFolder(filepath)        

    log.message("Write FBX file %s" % filepath)
    print(config)

    rigfile = "data/rigs/%s.rig" % config.rigtype
    rawTargets = exportutils.collect.readTargets(human, config)
    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    stuffs = exportutils.collect.setupObjects(
        name, 
        human, 
        config=config,
        rigfile=rigfile, 
        rawTargets=rawTargets,
        helpers=config.helpers, 
        eyebrows=config.eyebrows, 
        lashes=config.lashes)

    bpy.initialize(human, config)
    boneInfo = stuffs[0].boneInfo
    rig = bpy.addRig(name, boneInfo, scale=config.scale)
    for stuff in stuffs:
        ob = bpy.addMesh(stuff.name, stuff, rig, isStuff=True, scale=config.scale)
        
    #name = os.path.splitext(os.path.basename(filepath))[0]
    #bpy.addMesh(name, human.meshData, isStuff=False)
    
    gui3d.app.progress(0, text="Exporting %s" % filepath)
    io_fbx.fbx_export.exportFbxFile(bpy.context, filepath, scale=1.0, encoding=config.encoding)
    gui3d.app.progress(1)
    posemode.exitPoseMode()        
    return
Esempio n. 14
0
def exportCollada(human, filepath, config):    
    posemode.exitPoseMode()        
    posemode.enterPoseMode()
    gui3d.app.progress(0, text="Exporting %s" % filepath)

    time1 = time.clock()
    config.setHuman(human)
    config.setupTexFolder(filepath)        
    try:
        fp = open(filepath, 'w')
        log.message("Writing Collada file %s" % filepath)
    except:
        log.error("Unable to open file for writing %s" % filepath)

    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    exportDae(human, name, fp, config)

    fp.close()
    time2 = time.clock()
    log.message("Wrote Collada file in %g s: %s" % (time2-time1, filepath))
    gui3d.app.progress(1)
    posemode.exitPoseMode()        
    return
Esempio n. 15
0
def exportCollada(human, filepath, config):
    posemode.exitPoseMode()
    posemode.enterPoseMode()
    gui3d.app.progress(0, text="Exporting %s" % filepath)

    time1 = time.clock()
    config.setHuman(human)
    config.setupTexFolder(filepath)
    try:
        fp = open(filepath, 'w')
        log.message("Writing Collada file %s" % filepath)
    except:
        log.error("Unable to open file for writing %s" % filepath)

    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    exportDae(human, name, fp, config)

    fp.close()
    time2 = time.clock()
    log.message("Wrote Collada file in %g s: %s" % (time2 - time1, filepath))
    gui3d.app.progress(1)
    posemode.exitPoseMode()
    return
Esempio n. 16
0
 def enterPoseMode(self):
     self.posefile = posemode.enterPoseMode()
     if self.posefile:
         posemode.loadMhpFile(self.posefile)
Esempio n. 17
0
 def enterPoseMode(self):
     self.posefile = posemode.enterPoseMode()
     if self.posefile:
         posemode.loadMhpFile(self.posefile)
Esempio n. 18
0
def exportMhx(human, filepath, config):
    gui3d.app.progress(0, text="Exporting MHX")
    log.message("Exporting %s" % filepath.encode('utf-8'))
    time1 = time.clock()
    posemode.exitPoseMode()
    posemode.enterPoseMode()

    config.setHuman(human)
    config.setupTexFolder(filepath)

    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    fp = open(filepath, 'w')

    if config.rigtype == 'mhx':
        amt = mhx_armature.MhxArmature(name, human, config)
    elif config.rigtype == 'rigify':
        amt = mhx_armature.RigifyArmature(name, human, config)
    else:
        amt = mhx_armature.ExportArmature(name, human, config)

    fp.write("# MakeHuman exported MHX\n" + "# www.makeinfo.human.org\n" +
             "MHX %d %d ;\n" % (MAJOR_VERSION, MINOR_VERSION) +
             "#if Blender24\n" +
             "  error 'This file can only be read with Blender 2.5' ;\n" +
             "#endif\n")

    scanProxies(config, amt)
    amt.setup()

    if not config.cage:
        fp.write(
            "#if toggle&T_Cage\n" +
            "  error 'This MHX file does not contain a cage. Unselect the Cage import option.' ;\n"
            + "#endif\n")

    fp.write("NoScale True ;\n" + "Object CustomShapes EMPTY None\n" +
             "  layers Array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1  ;\n" +
             "end Object\n\n")

    amt.setupCustomShapes(fp)

    gui3d.app.progress(0.1, text="Exporting armature")
    amt.writeArmature(fp, MINOR_VERSION)

    gui3d.app.progress(0.15, text="Exporting materials")
    fp.write("\nNoScale False ;\n\n")
    mhx_materials.writeMaterials(fp, amt, config)

    if config.cage:
        mhx_proxy.writeProxyType('Cage', 'T_Cage', amt, config, fp, 0.2, 0.25)

    gui3d.app.progress(0.25, text="Exporting main mesh")
    fp.write("#if toggle&T_Mesh\n")
    mhx_mesh.writeMesh(fp, amt, config)
    fp.write("#endif\n")

    mhx_proxy.writeProxyType('Proxy', 'T_Proxy', amt, config, fp, 0.35, 0.4)
    mhx_proxy.writeProxyType('Clothes', 'T_Clothes', amt, config, fp, 0.4,
                             0.55)
    mhx_proxy.writeProxyType('Hair', 'T_Clothes', amt, config, fp, 0.55, 0.6)

    mhx_pose.writePose(fp, amt, config)

    writeGroups(fp, amt)

    if config.rigtype == 'rigify':
        fp.write("Rigify %s ;\n" % amt.name)

    fp.close()
    log.message("%s exported" % filepath.encode('utf-8'))
    gui3d.app.progress(1.0)
    return
Esempio n. 19
0
def exportMhx(human, filepath, config):  
    gui3d.app.progress(0, text="Exporting MHX")
    log.message("Exporting %s" % filepath.encode('utf-8'))
    time1 = time.clock()
    posemode.exitPoseMode()        
    posemode.enterPoseMode()
    
    config.setHuman(human)
    config.setupTexFolder(filepath)    

    filename = os.path.basename(filepath)
    name = config.goodName(os.path.splitext(filename)[0])
    fp = open(filepath, 'w')
        
    if config.rigtype == 'mhx':
        amt = mhx_armature.MhxArmature(name, human, config)
    elif config.rigtype == 'rigify':
        amt = mhx_armature.RigifyArmature(name, human, config)
    else:
        amt = mhx_armature.ExportArmature(name, human, config)
    
    fp.write(
        "# MakeHuman exported MHX\n" +
        "# www.makeinfo.human.org\n" +
        "MHX %d %d ;\n" % (MAJOR_VERSION, MINOR_VERSION) +
        "#if Blender24\n" +
        "  error 'This file can only be read with Blender 2.5' ;\n" +
        "#endif\n")

    scanProxies(config, amt)
    amt.setup()
    
    if not config.cage:
        fp.write(
            "#if toggle&T_Cage\n" +
            "  error 'This MHX file does not contain a cage. Unselect the Cage import option.' ;\n" +
            "#endif\n")

    fp.write(
        "NoScale True ;\n" +
        "Object CustomShapes EMPTY None\n" +
        "  layers Array 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1  ;\n" +
        "end Object\n\n")

    amt.setupCustomShapes(fp)
        
    gui3d.app.progress(0.1, text="Exporting armature")
    amt.writeArmature(fp, MINOR_VERSION)
    
    gui3d.app.progress(0.15, text="Exporting materials")    
    fp.write("\nNoScale False ;\n\n")
    mhx_materials.writeMaterials(fp, amt, config)

    if config.cage:
        mhx_proxy.writeProxyType('Cage', 'T_Cage', amt, config, fp, 0.2, 0.25)
    
    gui3d.app.progress(0.25, text="Exporting main mesh")    
    fp.write("#if toggle&T_Mesh\n")
    mhx_mesh.writeMesh(fp, amt, config)
    fp.write("#endif\n")

    mhx_proxy.writeProxyType('Proxy', 'T_Proxy', amt, config, fp, 0.35, 0.4)
    mhx_proxy.writeProxyType('Clothes', 'T_Clothes', amt, config, fp, 0.4, 0.55)
    mhx_proxy.writeProxyType('Hair', 'T_Clothes', amt, config, fp, 0.55, 0.6)

    mhx_pose.writePose(fp, amt, config)

    writeGroups(fp, amt)

    if config.rigtype == 'rigify':
        fp.write("Rigify %s ;\n" % amt.name)

    fp.close()
    log.message("%s exported" % filepath.encode('utf-8'))
    gui3d.app.progress(1.0)
    return