Ejemplo n.º 1
0
 def setEyes(self, human, mhstx):
     # TODO this will change, for now eyes might only be compatible with the original skin
     texture = mh.getTexture(human.getTexture())
     texture.loadSubImage(
         subtextures.combine(mh.Image(human.getTexture()),mhstx), 0, 0)
     self.eyeTexture = mhstx
Ejemplo n.º 2
0
def setupObjects(name, human, config=None, rigfile=None, rawTargets=[], helpers=False, hidden=False, eyebrows=True, lashes=True, subdivide = False, progressCallback=None):
    global theStuff, theTextures, theTexFiles, theMaterials

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

    if not config:
        config = Config()
        config.setHuman(human)
        
    obj = human.meshData
    theTextures = {}
    theTexFiles = {}
    theMaterials = {}
    
    stuffs = []
    stuff = CStuff(name, obj = human)

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

    theStuff = stuff
    deleteGroups = []
    deleteVerts = None  # Don't load deleteVerts from proxies directly, we use the facemask set in the gui module3d
    _,deleteVerts = setupProxies('Clothes', None, obj, stuffs, meshInfo, config, deleteGroups, deleteVerts)
    _,deleteVerts = setupProxies('Hair', None, obj, stuffs, meshInfo, config, deleteGroups, deleteVerts)
    foundProxy,deleteVerts = setupProxies('Proxy', name, obj, stuffs, meshInfo, config, deleteGroups, deleteVerts)
    progress(0.06*(3-2*subdivide))
    if not foundProxy:
        if helpers:     # helpers override everything
            if config.scale == 1.0:
                stuff.meshInfo = meshInfo
            else:
                stuff.meshInfo = meshInfo.fromProxy(config.scale*obj.coord, obj.texco, obj.fvert, obj.fuvs, meshInfo.weights, meshInfo.shapes)
        else:
            stuff.meshInfo = filterMesh(meshInfo, config.scale, deleteGroups, deleteVerts, eyebrows, lashes, not hidden)
        stuffs = [stuff] + stuffs
    progbase = 0.12*(3-2*subdivide)
    progress(progbase)

    # Apply textures, and subdivide, if requested.
    stuffnum = float(len(stuffs))
    i = 0.0
    for stuff in stuffs:
        progress(progbase+(i/stuffnum)*(1-progbase))
        texture = stuff.object.mesh.texture
        stuff.texture = (os.path.dirname(texture), os.path.basename(texture))
        if subdivide:
            subMesh = cks.createSubdivisionObject(
                stuff.meshInfo.object, lambda p: progress(progbase+((i+p)/stuffnum)*(1-progbase)))
            stuff.meshInfo.fromObject(subMesh, stuff.meshInfo.weights, rawTargets)
        i += 1.0

    # Apply subtextures.
    stuffs[0].textureImage = mh.Image(os.path.join(stuffs[0].texture[0], stuffs[0].texture[1]))
    mhstx = mh.G.app.getCategory('Textures').getTaskByName('Texture').eyeTexture
    if mhstx:
        stuffs[0].textureImage = subtextures.combine(stuffs[0].textureImage, mhstx)
    
    progress(1)
    return stuffs