Esempio n. 1
0
def run(args):
    G.app = ConsoleApp()
    human = G.app.selectedHuman

    import humanargparser
    humanargparser.applyModelingArguments(human, args)


    if args["output"]:
        save(human, args["output"])
Esempio n. 2
0
def run(args):
    G.app = ConsoleApp()
    human = G.app.selectedHuman

    import humanargparser
    humanargparser.applyModelingArguments(human, args)


    if args["output"]:
        save(human, args["output"])


    # A little debug test
    if 'PyOpenGL' in sys.modules.keys():
        log.warning("Debug test detected that OpenGL libraries were imported in the console version! This indicates bad separation from GUI.")
    if 'PyQt4' in sys.modules.keys():
        log.warning("Debug test detected that Qt libraries were imported in the console version! This indicates bad separation from GUI (unless PIL is not installed, in which case PyQt is still used as image back-end).")
Esempio n. 3
0
    def makepng(this, data, symmetric=False, skin=False):
        os.chdir(this.path)

        import core
        import headless
        import humanargparser

        data = BitStream(data)
        if verbose:
            sys.stderr.write("%i bits of data input\n" % len(data))
        
        core.G.app = headless.ConsoleApp()
        human = core.G.app.selectedHuman
    

        ## extract enough bits to select proxies and materials
        
        proxies = {}
        for proxyType in this.proxies:
            proxyFiles = this.proxies[proxyType]
            nfiles = len(proxyFiles)
            bitlen = int(math.ceil(math.log(nfiles+1, 2)))
            fileIdx = int(round(data.get(bitlen) * nfiles / ((1<<bitlen)-1.0)))
            if (fileIdx == nfiles):
                if verbose:
                    sys.stderr.write("Selected no %s with %i bits\n" % (proxyType, bitlen))
            else:
                if verbose:
                    sys.stderr.write("Selected %s #%i with %i bits\n" % (proxyType, fileIdx, bitlen))
                proxies[proxyType] = proxyFiles[fileIdx]
        
        if skin:
            bitlen = int(math.ceil(math.log(len(this.skins), 2)))
            fileIdx = int(round(data.get(bitlen) * (len(this.skins)-1) / ((1<<bitlen)-1.0)))
            if verbose:
                sys.stderr.write("Selected skin #%i with %i bits\n" % (fileIdx, bitlen))
            skin = this.skins[fileIdx]
        
        proxies['eyes'] = 'data/eyes/high-poly/high-poly.mhclo'
        proxies['clothes'] = 'data/clothes/male_worksuit01/male_worksuit01.mhclo'
        
        
        ## spread remaining data among modifiers as floats
        
        if verbose:
            sys.stderr.write("%i bits remaining for facial features\n" % len(data))
        
        modifierDict = {}
        modifiers = this.symmetricalModifiers + this.leftModifiers
        if not symmetric:
            modifiers += this.rightModifiers
        modifierCount = len(modifiers)
        
        bitsPerModifier = len(data) / float(modifierCount)
        # some modifiers get one more bit than other modifiers
        detailedModifierCount = len(data) % modifierCount
        
        detailedAccumulated = 0
        for idx in xrange(modifierCount):
            if detailedAccumulated <  detailedModifierCount * idx / (modifierCount-1.0):
                bitlen = int(math.ceil(bitsPerModifier))
                detailedAccumulated = detailedAccumulated + 1
            else:
                bitlen = int(math.floor(bitsPerModifier))
            value = (data.get(bitlen) + 0.5) / (1<<bitlen)
            modifier = modifiers[idx]
            if verbose:
                sys.stderr.write("%s: %f with %i bits\n" % (modifier.fullName, value, bitlen))
            modifierDict[modifier.fullName] = value
            if symmetric and modifier.getSymmetrySide() is not None:
                modifierDict[modifier.getSymmetricOpposite()] = value

        modifierDict['macrodetails/Caucasian'] = 2.0 - modifierDict['macrodetails/African'] - modifierDict['macrodetails/Asian']
        
        
        ## generate human

        if verbose:
            sys.stderr.write("Generating human\n")
        
        humanargparser.mods_loaded = False
        humanargparser.applyModelingArguments(human, {
          'modifier' : modifierDict.iteritems(),
          'proxy' : proxies.iteritems(),
          'material' : None if skin == False else skin
        });
        
        
        ## render photo
        
        tempdir = tempfile.mkdtemp()
        objfile = tempfile.mkstemp(dir=tempdir)[1] + '.obj'
        outfile = tempfile.mkstemp(dir=tempdir)[1] + '.png'
        
        if verbose:
            sys.stderr.write("Rendering photo to %s\n" % outfile)
        
        headless.save(human, objfile)
        os.chdir(os.path.dirname(outfile))
        stdout, nothing = subprocess.Popen(['blender', realpath + '/photo.blend', '--background', '--render-output', outfile, '--python', realpath + '/blender_photo.py', '--', objfile], stdout=subprocess.PIPE).communicate()
        #os.system("blender '%s' --verbose 0 --background --render-output '%s' --python '%s' -- '%s'" % (realpath + "/photo.blend", outfile, realpath + "/blender_photo.py", objfile))
        with open(outfile, 'r') as outdata:
            photo = outdata.read()
        os.system("rm -rf %s" % tempdir)

        return photo