Пример #1
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        
Пример #2
0
def exportProxyObj(human, name, options):
    obj = human.meshData
    cfg = export_config.exportConfig(human, True)
    cfg.separatefolder = True

    stuffs = object_collection.setupObjects(os.path.splitext(name)[0],
                                            human,
                                            helpers=options["helpers"],
                                            hidden=options["hidden"],
                                            eyebrows=options["eyebrows"],
                                            lashes=options["lashes"],
                                            subdivide=options["subdivide"])

    (scale, unit) = options["scale"]
    #name = export_config.goodName(name)
    outfile = export_config.getOutFileFolder(name, cfg)
    (path, ext) = os.path.splitext(outfile)

    filename = "%s_clothed.obj" % path
    fp = open(filename, 'w')
    fp.write("# MakeHuman exported OBJ with clothes\n" +
             "# www.makehuman.org\n\n" +
             "mtllib %s_clothed.obj.mtl\n" % os.path.basename(path))
    for stuff in stuffs:
        writeGeometry(obj, fp, stuff, scale)
    fp.close()

    filename = "%s_clothed.obj.mtl" % path
    fp = open(filename, 'w')
    fp.write('# MakeHuman exported MTL with clothes\n' +
             '# www.makehuman.org\n\n')
    for stuff in stuffs:
        writeMaterial(fp, stuff, human, cfg)
    fp.close()
    return
Пример #3
0
def exportProxyObj(human, name, options):
    obj = human.meshData
    the.Config = export_config.exportConfig(human, True)
    the.Options = options
    the.Config.separatefolder = True
    print(options.items())
    (the.Stuff, stuffs) = mh2collada.setupStuff(name, obj, {}, [], the.Config)
    (scale, unit) = options["scale"]   
    #name = export_config.goodName(name)
    outfile = export_config.getOutFileFolder(name+".obj", the.Config)   
    (path, ext) = os.path.splitext(outfile)

    filename = "%s_clothed.obj" % path
    fp = open(filename, 'w')
    fp.write(
"# MakeHuman exported OBJ with clothes\n" +
"# www.makehuman.org\n\n" +
"mtllib %s_clothed.obj.mtl\n" % os.path.basename(path))
    for stuff in stuffs:
        writeGeometry(obj, fp, stuff, scale)
    fp.close()
    
    filename = "%s_clothed.obj.mtl" % path
    fp = open(filename, 'w')
    fp.write(
'# MakeHuman exported MTL with clothes\n' +
'# www.makehuman.org\n\n')
    for stuff in stuffs:
        writeMaterial(fp, stuff, human)
    fp.close()
    return
Пример #4
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
Пример #5
0
def exportMhx(human, filename, options):    
    the.Config = export_config.exportConfig(human, True, options)
    (fpath, ext) = os.path.splitext(filename)

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

    return        
Пример #6
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
Пример #7
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
Пример #8
0
def exportCollada(human, filename, options):
    time1 = time.clock()
    the.Config = export_config.exportConfig(human, True, [])
    the.Config.separatefolder = True
    the.Rotate90X = options["rotate90X"]
    the.Rotate90Z = options["rotate90Z"]
    the.Options = options
    outfile = export_config.getOutFileFolder(filename, the.Config)        
    try:
        fp = open(outfile, 'w')
        log.message("Writing Collada file %s" % outfile)
    except:
        log.error("Unable to open file for writing %s" % outfile)
    (name,ext) = os.path.splitext(os.path.basename(outfile))
    exportDae(human, name, fp)
    fp.close()
    time2 = time.clock()
    log.message("Wrote Collada file in %g s: %s" % (time2-time1, outfile))
    return
Пример #9
0
def exportCollada(human, filename, options):
    time1 = time.clock()
    the.Config = export_config.exportConfig(human, True, [])
    the.Config.separatefolder = True
    the.Rotate90X = options["rotate90X"]
    the.Rotate90Z = options["rotate90Z"]
    the.Options = options
    outfile = export_config.getOutFileFolder(filename, the.Config)
    try:
        fp = open(outfile, 'w')
        log.message("Writing Collada file %s" % outfile)
    except:
        log.error("Unable to open file for writing %s" % outfile)
    (name, ext) = os.path.splitext(os.path.basename(outfile))
    exportDae(human, name, fp)
    fp.close()
    time2 = time.clock()
    log.message("Wrote Collada file in %g s: %s" % (time2 - time1, outfile))
    return
Пример #10
0
def exportCollada(human, filename, options):
    time1 = time.clock()
    the.Config = export_config.exportConfig(human, True, [])
    the.Config.separatefolder = True
    the.Rotate90X = options["rotate90X"]
    the.Rotate90Z = options["rotate90Z"]
    the.Config.pngTexture = options["pngTexture"]
    the.Options = options
    outfile = export_config.getOutFileFolder(filename+".dae", the.Config)        
    try:
        fp = open(outfile, 'w')
        print("Writing Collada file", outfile)
    except:
        print("Unable to open file for writing", outfile)
    (name,ext) = os.path.splitext(os.path.basename(outfile))
    exportDae(human, name, fp)
    fp.close()
    time2 = time.clock()
    print("Wrote Collada file in %g s:" % (time2-time1), outfile)
    return
Пример #11
0
def createRig(human, rigtype):
    config = export_config.exportConfig(human, True)
    config.exporting = False
    config.feetonground = False
    config.rigtype = rigtype

    fp = None
    config.mhx25 = True
    obj = human.meshData
    proxyData = {}
    mhx.mhx_rig.setupRig(obj, config, proxyData)

    amt = CArmature(human, config)
    the.createdArmature = amt
    for (bname, roll, parent, flags, layers, bbone) in config.armatureBones:
        if config.exporting or layers & ACTIVE_LAYERS:
            bone = CBone(amt, bname, roll, parent, flags, layers, bbone)
            amt.boneList.append(bone)        
            amt.bones[bname] = bone
        else:
            pass
            #print "Ignore %s L %x A %x" % (bname, layers, ACTIVE_LAYERS)

    amt.build()        
    
    if rigtype != "mhx":
        return amt

    #setupCircles(fp)

    mhx.mhx_rig.writeControlPoses(fp, config)
    amt.checkDirty()
    return amt

    mhx.mhx_rig.writeAllActions(fp, config)

    drivers = mhx.mhx_rig.writeAllDrivers(fp, config)
    amt.assignDrivers(drivers)
    
    #amt.display()
    return amt
Пример #12
0
def createRig(human, rigtype):
    config = export_config.exportConfig(human, True)
    config.exporting = False
    config.feetonground = False
    config.rigtype = rigtype

    fp = None
    config.mhx25 = True
    obj = human.meshData
    proxyData = {}
    mhx.mhx_rig.setupRig(obj, config, proxyData)

    amt = CArmature(human, config)
    the.createdArmature = amt
    for (bname, roll, parent, flags, layers, bbone) in config.armatureBones:
        if config.exporting or layers & ACTIVE_LAYERS:
            bone = CBone(amt, bname, roll, parent, flags, layers, bbone)
            amt.boneList.append(bone)
            amt.bones[bname] = bone
        else:
            pass
            #print "Ignore %s L %x A %x" % (bname, layers, ACTIVE_LAYERS)

    amt.build()

    if rigtype != "mhx":
        return amt

    #setupCircles(fp)

    mhx.mhx_rig.writeControlPoses(fp, config)
    amt.checkDirty()
    return amt

    mhx.mhx_rig.writeAllActions(fp, config)

    drivers = mhx.mhx_rig.writeAllDrivers(fp, config)
    amt.assignDrivers(drivers)

    #amt.display()
    return amt
Пример #13
0
def exportProxyObj(human, name, options):
    obj = human.meshData
    cfg = export_config.exportConfig(human, True)
    cfg.separatefolder = True

    stuffs = object_collection.setupObjects(os.path.splitext(name)[0], human,
        helpers=options["helpers"], 
        hidden=options["hidden"], 
        eyebrows=options["eyebrows"], 
        lashes=options["lashes"],
        subdivide=options["subdivide"])
    
    (scale, unit) = options["scale"]   
    #name = export_config.goodName(name)
    outfile = export_config.getOutFileFolder(name, cfg)   
    (path, ext) = os.path.splitext(outfile)

    filename = "%s_clothed.obj" % path
    fp = open(filename, 'w')
    fp.write(
"# MakeHuman exported OBJ with clothes\n" +
"# www.makehuman.org\n\n" +
"mtllib %s_clothed.obj.mtl\n" % os.path.basename(path))
    for stuff in stuffs:
        writeGeometry(obj, fp, stuff, scale)
    fp.close()
    
    filename = "%s_clothed.obj.mtl" % path
    fp = open(filename, 'w')
    fp.write(
'# MakeHuman exported MTL with clothes\n' +
'# www.makehuman.org\n\n')
    for stuff in stuffs:
        writeMaterial(fp, stuff, human, cfg)
    fp.close()
    return
Пример #14
0
def exportDae(human, name, fp):
    cfg = export_config.exportConfig(human, True)
    obj = human.meshData
    rigfile = "data/rigs/%s.rig" % the.Options["daerig"]
    print("Using rig file %s" % rigfile)
    amt = getArmatureFromRigFile(rigfile, obj)
    #rawTargets = loadShapeKeys("shared/mhx/templates/shapekeys-facial25.mhx")
    rawTargets = []
    (the.Stuff, stuffs) = setupStuff(name, obj, amt, rawTargets, cfg)

    date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
    if the.Rotate90X:
        upaxis = 'Z_UP'
    else:
        upaxis = 'Y_UP'
    (scale, unit) = the.Options["scale"]        
        
    fp.write('<?xml version="1.0" encoding="utf-8"?>\n' +
'<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">\n' +
'  <asset>\n' +
'    <contributor>\n' +
'      <author>www.makehuman.org</author>\n' +
'    </contributor>\n' +
'    <created>%s</created>\n' % date +
'    <modified>%s</modified>\n' % date +
'    <unit meter="%.4f" name="%s"/>\n' % (0.1/scale, unit) +
'    <up_axis>%s</up_axis>\n' % upaxis+
'  </asset>\n' +
'  <library_images>\n')

    for stuff in stuffs:
        writeImages(obj, fp, stuff, human)

    fp.write(
'  </library_images>\n' +
'  <library_effects>\n')

    for stuff in stuffs:
        writeEffects(obj, fp, stuff)

    fp.write(
'  </library_effects>\n' +
'  <library_materials>\n')

    for stuff in stuffs:
        writeMaterials(obj, fp, stuff)

    fp.write(
'  </library_materials>\n'+
'  <library_controllers>\n')

    for stuff in stuffs:
        writeController(obj, fp, stuff)

    fp.write(
'  </library_controllers>\n'+
'  <library_geometries>\n')

    for stuff in stuffs:
        writeGeometry(obj, fp, stuff)

    fp.write(
'  </library_geometries>\n\n' +
'  <library_visual_scenes>\n' +
'    <visual_scene id="Scene" name="Scene">\n' +
'      <node id="Scene_root">\n')
    for root in the.Stuff.rigHier:
        writeBone(fp, root, [0,0,0], 'layer="L1"', '  ', the.Stuff)
    for stuff in stuffs:
        writeNode(obj, fp, "        ", stuff)

    fp.write(
'      </node>\n' +    
'    </visual_scene>\n' +
'  </library_visual_scenes>\n' +
'  <scene>\n' +
'    <instance_visual_scene url="#Scene"/>\n' +
'  </scene>\n' +
'</COLLADA>\n')
    return
Пример #15
0
def setupObjects(name, human, rigfile=None, rawTargets=[], helpers=False, hidden=True, eyebrows=True, lashes=True, subdivide = False, progressCallback=None):
    global theStuff, theTextures, theTexFiles, theMaterials

    def progress(base,prog):
        if progressCallback == None:
            pass
        else:
            progressCallback (base+prog)
    
    cfg = export_config.exportConfig(human, True)
    obj = human.meshData
    theTextures = {}
    theTexFiles = {}
    theMaterials = {}
    
    stuffs = []
    stuff = CStuff(name, None)

    if rigfile:
        stuff.boneInfo = getArmatureFromRigFile(rigfile, obj)
        log.message("Using rig file %s" % rigfile)
            
    meshInfo = mh2proxy.getMeshInfo(obj, None, None, rawTargets, None)
    if stuff.boneInfo:
        meshInfo.weights = stuff.boneInfo.weights

    theStuff = stuff
    deleteGroups = []
    if hidden:
        deleteVerts = None
    else:
        deleteVerts = numpy.zeros(len(obj.verts), bool)
    _,deleteVerts = setupProxies('Clothes', None, obj, stuffs, meshInfo, cfg.proxyList, deleteGroups, deleteVerts)
    foundProxy,deleteVerts = setupProxies('Proxy', name, obj, stuffs, meshInfo, cfg.proxyList, deleteGroups, deleteVerts)
    if not foundProxy:
        # If we subdivide here, helpers will not be removed.
        if False and subdivide:
            stuff.setObject3dMesh(human.getSubdivisionMesh(False,progressCallback = lambda p: progress(0,p*0.5)),
                                  stuff.meshInfo.weights, rawTargets)
        else:
            if helpers:     # helpers override everything
                stuff.meshInfo = meshInfo
            else:
                stuff.meshInfo =  filterMesh(meshInfo, obj, deleteGroups, deleteVerts, eyebrows, lashes)
        stuffs = [stuff] + stuffs

    clothKeys = human.clothesObjs.keys()

    # Apply custom textures if applicable
    for stuff in stuffs:
        proxy = stuff.proxy
        if proxy:
            if proxy.type == 'Clothes':
                uuid = proxy.getUuid()
                if uuid:
                    if uuid in clothKeys:
                        # Clothes
                        clothesObj = human.clothesObjs[uuid]
                        if clothesObj:
                            texture = clothesObj.mesh.texture
                            stuff.texture = (os.path.dirname(texture), os.path.basename(texture))
                    elif uuid == human.hairProxy.getUuid():
                        # Hair
                        texture = human.hairObj.mesh.texture
                        stuff.texture = (os.path.dirname(texture), os.path.basename(texture))
            elif proxy.type == 'Proxy':
                # Proxy
                texture = human.mesh.texture
                stuff.texture = (os.path.dirname(texture), os.path.basename(texture))

    # Subdivide proxy meshes if requested
    if subdivide:
        for stuff in stuffs:
            proxy = stuff.proxy
            if proxy:
                if proxy.type == 'Clothes':
                    uuid = proxy.getUuid()
                    if uuid and uuid in clothKeys:
                        # Subdivide clothes
                        clo = human.clothesObjs[uuid]
                        subMesh = clo.getSubdivisionMesh(False)
                        stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights, rawTargets)
                    elif uuid and uuid == human.hairProxy.getUuid():
                        # Subdivide hair
                        hair = human.hairObj
                        subMesh = hair.getSubdivisionMesh(False)
                        stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights, rawTargets)
                elif proxy.type == 'Proxy':
                    # Subdivide proxy
                    subMesh = human.getSubdivisionMesh(False)
                    stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights, rawTargets)

    progress(1,0)
    return stuffs
Пример #16
0
def exportDae(human, name, fp):
    cfg = export_config.exportConfig(human, True)
    obj = human.meshData
    rigfile = "data/rigs/%s.rig" % the.Options["daerig"]

    stuffs = object_collection.setupObjects(
        name, 
        human, 
        rigfile=rigfile, 
        helpers=the.Options["helpers"], 
        hidden=the.Options["hidden"], 
        eyebrows=the.Options["eyebrows"], 
        lashes=the.Options["lashes"])
    mainStuff = stuffs[0]        

    date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
    if the.Rotate90X:
        upaxis = 'Z_UP'
    else:
        upaxis = 'Y_UP'
    (scale, unit) = the.Options["scale"]        
        
    fp.write('<?xml version="1.0" encoding="utf-8"?>\n' +
'<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">\n' +
'  <asset>\n' +
'    <contributor>\n' +
'      <author>www.makehuman.org</author>\n' +
'    </contributor>\n' +
'    <created>%s</created>\n' % date +
'    <modified>%s</modified>\n' % date +
'    <unit meter="%.4f" name="%s"/>\n' % (0.1/scale, unit) +
'    <up_axis>%s</up_axis>\n' % upaxis+
'  </asset>\n' +
'  <library_images>\n')

    for stuff in stuffs:
        writeImages(obj, fp, stuff, human)

    fp.write(
'  </library_images>\n' +
'  <library_effects>\n')

    for stuff in stuffs:
        writeEffects(obj, fp, stuff)

    fp.write(
'  </library_effects>\n' +
'  <library_materials>\n')

    for stuff in stuffs:
        writeMaterials(obj, fp, stuff)

    fp.write(
'  </library_materials>\n'+
'  <library_controllers>\n')

    for stuff in stuffs:
        writeController(obj, fp, stuff)

    fp.write(
'  </library_controllers>\n'+
'  <library_geometries>\n')

    for stuff in stuffs:
        writeGeometry(obj, fp, stuff)

    fp.write(
'  </library_geometries>\n\n' +
'  <library_visual_scenes>\n' +
'    <visual_scene id="Scene" name="Scene">\n' +
'      <node id="Scene_root">\n')
    for root in mainStuff.boneInfo.hier:
        writeBone(fp, root, [0,0,0], 'layer="L1"', '  ', mainStuff)
    for stuff in stuffs:
        writeNode(obj, fp, "        ", stuff)

    fp.write(
'      </node>\n' +    
'    </visual_scene>\n' +
'  </library_visual_scenes>\n' +
'  <scene>\n' +
'    <instance_visual_scene url="#Scene"/>\n' +
'  </scene>\n' +
'</COLLADA>\n')
    return
Пример #17
0
def setupObjects(name,
                 human,
                 rigfile=None,
                 rawTargets=[],
                 helpers=False,
                 hidden=True,
                 eyebrows=True,
                 lashes=True,
                 subdivide=False,
                 progressCallback=None):
    global theStuff, theTextures, theTexFiles, theMaterials

    def progress(base, prog):
        if progressCallback == None:
            pass
        else:
            progressCallback(base + prog)

    cfg = export_config.exportConfig(human, True)
    obj = human.meshData
    theTextures = {}
    theTexFiles = {}
    theMaterials = {}

    stuffs = []
    stuff = CStuff(name, None)

    if rigfile:
        stuff.boneInfo = getArmatureFromRigFile(rigfile, obj)
        log.message("Using rig file %s" % rigfile)

    meshInfo = mh2proxy.getMeshInfo(obj, None, None, rawTargets, None)
    if stuff.boneInfo:
        meshInfo.weights = stuff.boneInfo.weights

    theStuff = stuff
    deleteGroups = []
    if hidden:
        deleteVerts = None
    else:
        deleteVerts = numpy.zeros(len(obj.verts), bool)
    _, deleteVerts = setupProxies('Clothes', None, obj, stuffs, meshInfo,
                                  cfg.proxyList, deleteGroups, deleteVerts)
    foundProxy, deleteVerts = setupProxies('Proxy', name, obj, stuffs,
                                           meshInfo, cfg.proxyList,
                                           deleteGroups, deleteVerts)
    if not foundProxy:
        # If we subdivide here, helpers will not be removed.
        if False and subdivide:
            stuff.setObject3dMesh(
                human.getSubdivisionMesh(
                    False, progressCallback=lambda p: progress(0, p * 0.5)),
                stuff.meshInfo.weights, rawTargets)
        else:
            if helpers:  # helpers override everything
                stuff.meshInfo = meshInfo
            else:
                stuff.meshInfo = filterMesh(meshInfo, obj, deleteGroups,
                                            deleteVerts, eyebrows, lashes)
        stuffs = [stuff] + stuffs

    clothKeys = human.clothesObjs.keys()

    # Apply custom textures if applicable
    for stuff in stuffs:
        proxy = stuff.proxy
        if proxy:
            if proxy.type == 'Clothes':
                uuid = proxy.getUuid()
                if uuid:
                    if uuid in clothKeys:
                        # Clothes
                        clothesObj = human.clothesObjs[uuid]
                        if clothesObj:
                            texture = clothesObj.mesh.texture
                            stuff.texture = (os.path.dirname(texture),
                                             os.path.basename(texture))
                    elif uuid == human.hairProxy.getUuid():
                        # Hair
                        texture = human.hairObj.mesh.texture
                        stuff.texture = (os.path.dirname(texture),
                                         os.path.basename(texture))
            elif proxy.type == 'Proxy':
                # Proxy
                texture = human.mesh.texture
                stuff.texture = (os.path.dirname(texture),
                                 os.path.basename(texture))

    # Subdivide proxy meshes if requested
    if subdivide:
        for stuff in stuffs:
            proxy = stuff.proxy
            if proxy:
                if proxy.type == 'Clothes':
                    uuid = proxy.getUuid()
                    if uuid and uuid in clothKeys:
                        # Subdivide clothes
                        clo = human.clothesObjs[uuid]
                        subMesh = clo.getSubdivisionMesh(False)
                        stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights,
                                              rawTargets)
                    elif uuid and uuid == human.hairProxy.getUuid():
                        # Subdivide hair
                        hair = human.hairObj
                        subMesh = hair.getSubdivisionMesh(False)
                        stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights,
                                              rawTargets)
                elif proxy.type == 'Proxy':
                    # Subdivide proxy
                    subMesh = human.getSubdivisionMesh(False)
                    stuff.setObject3dMesh(subMesh, stuff.meshInfo.weights,
                                          rawTargets)

    progress(1, 0)
    return stuffs
Пример #18
0
def exportDae(human, name, fp):
    cfg = export_config.exportConfig(human, True)
    obj = human.meshData
    rigfile = "data/rigs/%s.rig" % the.Options["daerig"]

    stuffs = object_collection.setupObjects(name,
                                            human,
                                            rigfile=rigfile,
                                            helpers=the.Options["helpers"],
                                            hidden=the.Options["hidden"],
                                            eyebrows=the.Options["eyebrows"],
                                            lashes=the.Options["lashes"])
    mainStuff = stuffs[0]

    date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())
    if the.Rotate90X:
        upaxis = 'Z_UP'
    else:
        upaxis = 'Y_UP'
    (scale, unit) = the.Options["scale"]

    fp.write(
        '<?xml version="1.0" encoding="utf-8"?>\n' +
        '<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema">\n'
        + '  <asset>\n' + '    <contributor>\n' +
        '      <author>www.makehuman.org</author>\n' + '    </contributor>\n' +
        '    <created>%s</created>\n' % date +
        '    <modified>%s</modified>\n' % date +
        '    <unit meter="%.4f" name="%s"/>\n' % (0.1 / scale, unit) +
        '    <up_axis>%s</up_axis>\n' % upaxis + '  </asset>\n' +
        '  <library_images>\n')

    for stuff in stuffs:
        writeImages(obj, fp, stuff, human)

    fp.write('  </library_images>\n' + '  <library_effects>\n')

    for stuff in stuffs:
        writeEffects(obj, fp, stuff)

    fp.write('  </library_effects>\n' + '  <library_materials>\n')

    for stuff in stuffs:
        writeMaterials(obj, fp, stuff)

    fp.write('  </library_materials>\n' + '  <library_controllers>\n')

    for stuff in stuffs:
        writeController(obj, fp, stuff)

    fp.write('  </library_controllers>\n' + '  <library_geometries>\n')

    for stuff in stuffs:
        writeGeometry(obj, fp, stuff)

    fp.write('  </library_geometries>\n\n' + '  <library_visual_scenes>\n' +
             '    <visual_scene id="Scene" name="Scene">\n' +
             '      <node id="Scene_root">\n')
    for root in mainStuff.boneInfo.hier:
        writeBone(fp, root, [0, 0, 0], 'layer="L1"', '  ', mainStuff)
    for stuff in stuffs:
        writeNode(obj, fp, "        ", stuff)

    fp.write('      </node>\n' + '    </visual_scene>\n' +
             '  </library_visual_scenes>\n' + '  <scene>\n' +
             '    <instance_visual_scene url="#Scene"/>\n' + '  </scene>\n' +
             '</COLLADA>\n')
    return