def scanProxies(config, amt):
    amt.proxies = {}
    for pfile in config.getProxyList():
        if pfile.file:
            proxy = mh2proxy.readProxyFile(amt.mesh, pfile, True)
            if proxy:
                amt.proxies[proxy.name] = proxy
Exemple #2
0
    def selectProxy(self, mhclofile):
        """
        Called when a new proxy has been selected.
        """
        if not mhclofile:
            self.deselectProxy(None, suppressSignal=True)

        if self.isProxySelected():
            # Deselect previously selected proxy
            self.deselectProxy(None, suppressSignal=True)

        self.filechooser.selectItem(mhclofile)

        if not mhclofile:
            self.signalChange()
            return

        if mhclofile not in self._proxyCache:
            proxy = mh2proxy.readProxyFile(self.human.meshData,
                                           mhclofile,
                                           type=self.proxyName.capitalize())
            self._proxyCache[mhclofile] = proxy
        else:
            proxy = self._proxyCache[mhclofile]

        self.human.setProxy(proxy)
        self.human.updateProxyMesh()

        # Add to selection
        self.selectedProxies.append(proxy)

        self.filechooser.selectItem(mhclofile)

        self.signalChange()
Exemple #3
0
def scanProxies(config, amt):
    amt.proxies = {}
    for pfile in config.getProxyList():
        if pfile.file:
            proxy = mh2proxy.readProxyFile(amt.mesh, pfile, True)
            if proxy:
                amt.proxies[proxy.name] = proxy        
def setupProxies(typename, name, obj, stuffs, amt, rawTargets, proxyList, deleteGroups, deleteVerts):
    foundProxy = False    
    for pfile in proxyList:
        if pfile.useDae and pfile.type == typename and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, True)
            if proxy and proxy.name and proxy.texVerts:
                foundProxy = True
                deleteGroups += proxy.deleteGroups
                deleteVerts = mh2proxy.multiplyDeleteVerts(proxy, deleteVerts)
                if name:
                    stuff = CStuff(name, proxy)
                else:
                    stuff = CStuff(proxy.name, proxy)
                if amt:
                    stuff.setBones(amt)
                if stuff:
                    if pfile.type == 'Proxy':
                        the.Stuff = stuff
                    if the.Stuff:
                        stuffname = the.Stuff.name
                    else:
                        stuffname = None
                    mesh = mh2proxy.getMeshInfo(obj, proxy, stuff.rawWeights, rawTargets, stuffname)
                    stuff.setMesh(mesh)
                    stuffs.append(stuff)
    return foundProxy
def setupProxies(typename, name, obj, stuffs, meshInfo, proxyList,
                 deleteGroups, deleteVerts):
    global theStuff

    foundProxy = False
    for pfile in proxyList:
        if pfile.type == typename and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, True)
            if proxy and proxy.name and proxy.texVerts:
                foundProxy = True
                deleteGroups += proxy.deleteGroups
                if deleteVerts != None:
                    deleteVerts = deleteVerts | proxy.deleteVerts
                if name:
                    stuff = CStuff(name, proxy)
                else:
                    stuff = CStuff(proxy.name, proxy)
                stuff.boneInfo = theStuff.boneInfo
                if stuff:
                    if pfile.type == 'Proxy':
                        theStuff = stuff
                    if theStuff:
                        stuffname = theStuff.name
                    else:
                        stuffname = None

                    stuff.meshInfo = mh2proxy.getMeshInfo(
                        obj, proxy, meshInfo.weights, meshInfo.targets,
                        stuffname)

                    stuffs.append(stuff)
    return foundProxy, deleteVerts
Exemple #6
0
def scanProxies(obj, config, proxyData):
    for pfile in config.proxyList:
        if pfile.useMhx and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, True)
            if proxy:
                proxyData[proxy.name] = proxy        
    return
Exemple #7
0
    def getProxies(self):
        """
        Get the proxy list from the current state of the set human object.
        Proxy list will contain all proxy items such as proxy mesh and clothes,
        hair, eyes, genitals and cages.
        """
        if not self.human:
            return {}

        proxies = {}
        for proxy in self.human.getProxies():
            if proxy:
                name = self.goodName(proxy.name)
                proxies[name] = proxy

        if self.human.proxy:
            proxy = self.human.proxy
            name = self.goodName(proxy.name)
            proxies[name] = proxy

        if self.cage:
            import mh2proxy
            obj = G.app.selectedHuman
            filepath = getSysDataPath("cages/cage/cage.mhclo")
            proxy = mh2proxy.readProxyFile(obj, filepath, type="Cage")
            proxy.update(obj)
            proxies[name] = proxy

        return proxies
Exemple #8
0
def scanProxies(obj, config, proxyData):
    for pfile in config.proxyList:
        if pfile.useMhx and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, True)
            if proxy:
                proxyData[proxy.name] = proxy
    return
def setupProxies(typename, name, obj, stuffs, meshInfo, proxyList, deleteGroups, deleteVerts):
    global theStuff
    
    foundProxy = False    
    for pfile in proxyList:
        if pfile.type == typename and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, True)
            if proxy and proxy.name and proxy.texVerts:
                foundProxy = True
                deleteGroups += proxy.deleteGroups
                if deleteVerts != None:
                    deleteVerts = deleteVerts | proxy.deleteVerts
                if name:
                    stuff = CStuff(name, proxy)
                else:
                    stuff = CStuff(proxy.name, proxy)
                stuff.boneInfo = theStuff.boneInfo
                if stuff:
                    if pfile.type == 'Proxy':
                        theStuff = stuff
                    if theStuff:
                        stuffname = theStuff.name
                    else:
                        stuffname = None

                    stuff.meshInfo = mh2proxy.getMeshInfo(obj, proxy, meshInfo.weights, meshInfo.targets, stuffname)

                    stuffs.append(stuff)
    return foundProxy, deleteVerts
Exemple #10
0
def setupProxies(typename, name, obj, stuffs, meshInfo, config, deleteGroups, deleteVerts):
    # TODO document that this method does not only return values, it also modifies some of the passed parameters (deleteGroups and stuffs, deleteVerts is modified only if it is not None)
    global theStuff
    
    foundProxy = False    
    for pfile in config.getProxyList():
        if pfile.type == typename and pfile.file:
            proxy = mh2proxy.readProxyFile(obj, pfile, evalOnLoad=True, scale=config.scale)
            if proxy and proxy.name and proxy.texVerts:
                foundProxy = True
                deleteGroups += proxy.deleteGroups
                if deleteVerts != None:
                    deleteVerts = deleteVerts | proxy.deleteVerts
                if name:
                    stuff = CStuff(name, proxy, pfile.obj)
                else:
                    stuff = CStuff(proxy.name, proxy, pfile.obj)
                stuff.boneInfo = theStuff.boneInfo
                if stuff:
                    if pfile.type == 'Proxy':
                        theStuff = stuff
                    if theStuff:
                        stuffname = theStuff.name
                    else:
                        stuffname = None

                    stuff.meshInfo = mh2proxy.getMeshInfo(obj, proxy, config, meshInfo.weights, meshInfo.shapes, stuffname)

                    stuffs.append(stuff)
    return foundProxy, deleteVerts
    def setProxy(self, human, filename):

        if os.path.basename(filename) == "clear.proxy":
            human.setProxy(None)
            return

        proxy = mh2proxy.readProxyFile(human.getSeedMesh(), filename, False)        
        human.setProxy(proxy)
    def setProxy(self, human, filename):

        if os.path.basename(filename) == "clear.proxy":
            human.setProxy(None)
            return

        proxy = mh2proxy.readProxyFile(human.getSeedMesh(), filename, False)
        human.setProxy(proxy)
        human.updateProxyMesh()
    def setProxy(self, human, filename):
        self.filechooser.selectItem(filename)

        if os.path.basename(filename) == "clear.proxy":
            human.setProxy(None)
            return

        proxy = mh2proxy.readProxyFile(human.getSeedMesh(), filename, type="Proxy", layer=4)
        human.setProxy(proxy)
        human.updateProxyMesh()
    def setProxy(self, human, filename):
        self.filechooser.selectItem(filename)

        if os.path.basename(filename) == "clear.proxy":
            human.setProxy(None)
            return

        proxy = mh2proxy.readProxyFile(human.getSeedMesh(), filename)
        proxy.type = 'Proxy'
        human.setProxy(proxy)
        human.updateProxyMesh()
Exemple #15
0
def exportProxy24(obj, plist, fp):
    proxy = mh2proxy.readProxyFile(obj, plist, True)
    if not proxy:
        return
    faces = mh2proxy.oldStyleFaces(obj)
    tmpl = open("shared/mhx/templates/proxy24.mhx", "rU")
    for line in tmpl:
        words = line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'mesh':
            fp.write("mesh %s %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'object':
            fp.write("object %s Mesh %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'v':
            for bary in proxy.realVerts:
                (x, y, z) = mh2proxy.proxyCoord(bary)
                fp.write("v %.4g %.4g %.4g ;\n" % (x, -z, y))
        elif words[0] == 'f':
            for (f, g) in proxy.faces:
                fp.write("    f")
                for v in f:
                    fp.write(" %d" % v)
                fp.write(" ;\n")
            fn = 0
            for mat in proxy.materials:
                fp.write("    fx %d %d 1 ;\n" % (fn, mat))
                fn += 1
        elif words[0] == 'vt':
            for f in proxy.texFaces:
                fp.write("    vt")
                for v in f:
                    uv = proxy.texVerts[v]
                    fp.write(" %.4g %.4g" % (uv[0], uv[1]))
                fp.write(" ;\n")
        elif words[0] == 'vertgroup':
            copyVertGroups("shared/mhx/templates/vertexgroups-24.mhx", fp,
                           proxy)
        elif words[0] == 'shapekey':
            fp.write("  ShapeKey Basis Sym\n  end ShapeKey\n")
            copyShapeKeys("shared/mhx/templates/shapekeys-bodylanguage25.mhx",
                          fp, proxy, False)
            copyShapeKeys("shared/mhx/templates/shapekeys-extra24.mhx", fp,
                          proxy, False)
            copyShapeKeys("shared/mhx/templates/shapekeys-body25.mhx", fp,
                          proxy, False)
            writeIpo(fp)
        else:
            fp.write(line)
    tmpl.close()
    return
def exportProxy24(obj, plist, fp):
    proxy = mh2proxy.readProxyFile(obj, plist, True)
    if not proxy:
        return
    faces = mhx_main.loadFacesIndices(obj)
    tmpl = open("shared/mhx/templates/proxy24.mhx", "rU")
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            fp.write(line)
        elif words[0] == 'mesh':
            fp.write("mesh %s %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'object':
            fp.write("object %s Mesh %s\n" % (proxy.name, proxy.name))
        elif words[0] == 'v':
            for bary in proxy.realVerts:
                (x,y,z) = mh2proxy.proxyCoord(bary)
                fp.write("v %.6g %.6g %.6g ;\n" % (x, -z, y))
        elif words[0] == 'f':
            for (f,g) in proxy.faces:
                fp.write("    f")
                for v in f:
                    fp.write(" %d" % v)
                fp.write(" ;\n")
            fn = 0
            for mat in proxy.materials:
                fp.write("    fx %d %d 1 ;\n" % (fn,mat))
                fn += 1
        elif words[0] == 'vt':
            for f in proxy.texFaces:
                fp.write("    vt")
                for v in f:
                    uv = proxy.texVerts[v]
                    fp.write(" %.6g %.6g" %(uv[0], uv[1]))
                fp.write(" ;\n")
        elif words[0] == 'vertgroup':
            mhx_main.copyVertGroups("shared/mhx/templates/vertexgroups-24.mhx", fp, proxy)    
        elif words[0] == 'shapekey':
            fp.write("  ShapeKey Basis Sym\n  end ShapeKey\n")
            if mhx_main.BODY_LANGUAGE:
                copyShapeKeys("shared/mhx/templates/shapekeys-bodylanguage25.mhx", fp, proxy, False)    
            else:
                copyShapeKeys("shared/mhx/templates/shapekeys-facial25.mhx", fp, proxy, False)    
            copyShapeKeys("shared/mhx/templates/shapekeys-extra24.mhx", fp, proxy, False)    
            copyShapeKeys("shared/mhx/templates/shapekeys-body25.mhx", fp, proxy, False)    
            writeIpo(fp)
        else:
            fp.write(line)
    tmpl.close()
    return
Exemple #17
0
    def setHair(self, human, mhclo):
        self.filechooser.selectItem(mhclo)

        if human.hairObj:
            gui3d.app.removeObject(human.hairObj)
            human.hairObj = None
            human.hairProxy = None

        if os.path.basename(mhclo) == "clear.mhclo":
            return
            
        human.hairProxy = mh2proxy.readProxyFile(human.meshData, mhclo)
        human.hairProxy.type = 'Hair'
        if not human.hairProxy:
            log.error("Failed to load %s", mhclo)
            return

        obj = human.hairProxy.obj_file
        obj = os.path.join(obj[0], obj[1])
        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Failed to load %s", obj)
            return
        if human.hairProxy.texture:
            (folder, name) = human.hairProxy.texture
            tex = os.path.join(folder, name)
            mesh.setTexture(tex)
        else:
            tex = obj.replace('.obj', '_texture.png')
            mesh.setTexture(tex)

        human.hairObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        human.hairObj.setRotation(human.getRotation())
        human.hairObj.mesh.setCameraProjection(0)
        human.hairObj.mesh.setSolid(human.mesh.solid)
        if human.hairProxy.cull:
            human.hairObj.mesh.setCull(1)
        else:
            human.hairObj.mesh.setCull(None)
        human.hairObj.mesh.setTransparentPrimitives(len(human.hairObj.mesh.fvert))
        human.hairObj.mesh.priority = 20

        hairName = human.hairObj.mesh.name.split('.')[0]

        self.adaptHairToHuman(human)
        human.hairObj.setSubdivided(human.isSubdivided())
    def setEyes(self, human, mhclo):
        self.filechooser.selectItem(mhclo)

        if human.eyesObj:
            gui3d.app.removeObject(human.eyesObj)
            human.eyesObj = None
            human.eyesProxy = None

        if os.path.basename(mhclo) == "clear.mhclo":
            return

        human.eyesProxy = mh2proxy.readProxyFile(human.meshData, mhclo, type="Eyes", layer=3)
        if not human.eyesProxy:
            log.error("Failed to load %s", mhclo)
            return

        obj = human.eyesProxy.obj_file
        #obj = os.path.join(obj[0], obj[1])
        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Failed to load %s", obj)
            return

        mesh.material = human.eyesProxy.material

        human.eyesObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        human.eyesObj.setRotation(human.getRotation())
        human.eyesObj.mesh.setCameraProjection(0)
        human.eyesObj.mesh.setSolid(human.mesh.solid)
        if human.eyesProxy.cull:
            human.eyesObj.mesh.setCull(1)
        else:
            human.eyesObj.mesh.setCull(None)
        # Enabling this causes render-que order issues so that eyes render over hair
        # Disabling it renders hi-poly eyes wrong
        if human.eyesProxy.transparent:
            human.eyesObj.mesh.setTransparentPrimitives(len(human.eyesObj.mesh.fvert))
        else:
            human.eyesObj.mesh.setTransparentPrimitives(0)
        human.eyesObj.mesh.priority = 5

        eyesName = human.eyesObj.mesh.name.split('.')[0]

        self.adaptEyesToHuman(human)
        human.eyesObj.setSubdivided(human.isSubdivided())
    def setHair(self, human, obj, mhclo):

        if human.hairObj:
            gui3d.app.removeObject(human.hairObj)
            human.hairObj = None
            human.hairProxy = None

        if os.path.basename(obj) == "clear.obj":
            return
            
        mesh = files3d.loadMesh(obj)
        if mesh:
            human.hairProxy = mh2proxy.readProxyFile(human.meshData, mhclo, False)
            if human.hairProxy.texture:
                (folder, name) = human.hairProxy.texture
                tex = os.path.join(folder, name)
                mesh.setTexture(tex)
            else:
                tex = obj.replace('.obj', '_texture.png')
                mesh.setTexture(tex)

            human.hairObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
            human.hairObj.setRotation(human.getRotation())
            human.hairObj.mesh.setCameraProjection(0)
            human.hairObj.mesh.setSolid(human.mesh.solid)
            if human.hairProxy.cull:
                human.hairObj.mesh.setCull(1)
            else:
                human.hairObj.mesh.setCull(None)
            human.hairObj.mesh.setTransparentPrimitives(len(human.hairObj.mesh.faces))
            human.hairObj.mesh.priority = 20
                
            hairName = human.hairObj.mesh.name.split('.')[0]

            self.adaptHairToHuman(human)
            human.hairObj.setSubdivided(human.isSubdivided())
Exemple #20
0
    def selectProxy(self, mhclofile):
        """
        Called when a new proxy has been selected.
        If this library selects only a single proxy, specifying None as
        mhclofile parameter will deselect the current proxy and set the selection
        to "none".
        If this library allows selecting multiple proxies, specifying None as
        mhclofile will have no effect.
        """
        if not mhclofile:
            if self.multiProxy:
                return
            else:
                self.deselectProxy(None)
                return

        log.message('Selecting proxy file "%s" from %s library.', mhclofile,
                    self.proxyName)
        human = self.human

        proxy = None
        mhcloId = getpath.canonicalPath(mhclofile)
        if mhcloId in self._proxyCache:
            proxy = self._proxyCache[mhcloId]
            if proxy.mtime < os.path.getmtime(mhclofile):
                proxy = None

        if not proxy:
            proxy = mh2proxy.readProxyFile(human.meshData,
                                           mhclofile,
                                           type=self.proxyName.capitalize())
            self._proxyCache[mhcloId] = proxy

        if proxy.uuid in [p.uuid for p in self.getSelection()]:
            log.debug(
                "Proxy with UUID %s (%s) already loaded in %s library. Skipping.",
                proxy.uuid, proxy.file, self.proxyName)
            return

        if not self.multiProxy and self.isProxySelected():
            # Deselect previously selected proxy
            self.deselectProxy(None, suppressSignal=True)

        mesh = files3d.loadMesh(proxy.obj_file, maxFaces=proxy.max_pole)
        if not mesh:
            log.error("Failed to load %s", proxy.obj_file)
            return

        self.filechooser.selectItem(mhclofile)

        mesh.material = proxy.material
        mesh.priority = proxy.z_depth  # Set render order
        mesh.setCameraProjection(0)  # Set to model camera
        mesh.setSolid(
            human.mesh.solid)  # Set to wireframe if human is in wireframe

        obj = gui3d.Object(mesh, self.human.getPosition())
        obj.setRotation(human.getRotation())
        gui3d.app.addObject(obj)

        self.adaptProxyToHuman(proxy, obj)
        obj.setSubdivided(
            human.isSubdivided())  # Copy subdivided state of human

        # Add to selection
        self.selectedProxies.append(proxy)
        self.proxyObjects.append(obj)

        self.filechooser.selectItem(mhclofile)

        self.proxySelected(proxy, obj)

        self.signalChange()
Exemple #21
0
    def setClothes(self, human, filepath):
        if os.path.basename(filepath) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            human.clothesProxies = {}
            self.clothesList = []
            human.activeClothing = None
            self.updateFaceMasks(self.faceHidingTggl.selected)
            return

        if filepath not in self.cache:
            proxy = mh2proxy.readProxyFile(human.meshData, filepath)
            proxy.type = 'Clothes'
            self.cache[filepath] = proxy
            proxy.toggleEnabled = False
        else:
            proxy = self.cache[filepath]

        if not proxy:
            return

        uuid = proxy.getUuid()

        # TODO costumes should go in a separate library
        '''
        # For loading costumes (sets of individual clothes)
        if proxy.clothings:
            t = 0
            dt = 1.0/len(proxy.clothings)
            folder = os.path.dirname(filepath)
            for (pieceName, uuid) in proxy.clothings:
                gui3d.app.progress(t, text="Loading %s" % pieceName)
                t += dt
                piecePath = os.path.join(folder, pieceName+".mhclo")
                mhclo = exportutils.config.getExistingProxyFile(piecePath, uuid, "clothes")
                if mhclo:
                    self.setClothes(human, mhclo)
                else:
                    log.warning("Could not load clothing %s", pieceName)
            gui3d.app.progress(1, text="%s loaded" % proxy.name)
            # Load custom textures
            for (uuid, texPath) in proxy.textures:
                if not uuid in human.clothesObjs.keys():
                    log.warning("Cannot override texture for clothing piece with uuid %s!" % uuid)
                    continue
                pieceProxy = human.clothesProxies[uuid]
                if not os.path.dirname(texPath):
                    pieceProxy = human.clothesProxies[uuid]
                    clothesPath = os.path.dirname(pieceProxy.file)
                    texPath = os.path.join(clothesPath, texPath)
                log.debug("Overriding texture for clothpiece %s to %s", uuid, texPath)
                clo = human.clothesObjs[uuid]
                clo.mesh.setTexture(texPath)
            # Apply overridden transparency setting to pieces of a costume
            for (uuid, isTransparent) in proxy.transparencies.items():
                if not uuid in human.clothesProxies.keys():
                    log.warning("Could not override transparency for object with uuid %s!" % uuid)
                    continue
                clo = human.clothesObjs[uuid]
                log.debug("Overriding transparency setting for clothpiece %s to %s", uuid, bool(proxy.transparencies[uuid]))
                if proxy.transparencies[uuid]:
                    clo.mesh.setTransparentPrimitives(len(clo.mesh.fvert))
                else:
                    clo.mesh.setTransparentPrimitives(0)
            return
        '''

        #folder = os.path.dirname(filepath)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            if human.activeClothing == uuid:
                human.activeClothing = None
            proxy = human.clothesProxies[uuid]
            del human.clothesProxies[uuid]
            self.updateFaceMasks(self.faceHidingTggl.selected)
            self.filechooser.deselectItem(proxy.file)
            log.message("Removed clothing %s %s", proxy.name, uuid)
            return

        if obj not in self.meshCache:
            mesh = files3d.loadMesh(obj)
            self.meshCache[obj] = mesh
        else:
            mesh = self.meshCache[obj]
        if not mesh:
            log.error("Could not load mesh for clothing object %s", proxy.name)
            return
        if proxy.texture:
            (dir, name) = proxy.texture
            tex = os.path.join(folder, name)
            if not os.path.exists(tex):
                tex = os.path.join(self.systemClothes, "textures", name)
            mesh.setTexture(tex)
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        if proxy.cull:
            clo.mesh.setCull(1)
        else:
            clo.mesh.setCull(None)
        if proxy.transparent:
            clo.mesh.setTransparentPrimitives(len(clo.mesh.fvert))
        else:
            clo.mesh.setTransparentPrimitives(0)
        clo.mesh.priority = 10
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        human.activeClothing = uuid
        self.clothesList.append(uuid)

        # TODO Disabled until conflict with new filechooser is sorted out
        '''
        for tag in proxy.tags:
            tag = tag.lower()
            # Allow only one piece of clothing per known tag
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:  # TODO use parameter here
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        gui3d.app.removeObject(oldClo)
                        del human.clothesObjs[oldUuid]
                        self.clothesList.remove(oldUuid)
                        if human.activeClothing == oldUuid:
                            human.activeClothing = None
                        log.message("Removed clothing %s with known tag %s", oldUuid, tag)
                    else:
                        log.message("Kept clothing %s with known tag %s", oldUuid, tag)
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids
        '''

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())
        
        #self.clothesButton.setTexture(obj.replace('.obj', '.png'))
        self.orderRenderQueue()
        self.updateFaceMasks(self.faceHidingTggl.selected)
    def setClothes(self, human, filepath):
        if os.path.basename(filepath) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            self.clothesList = []
            human.activeClothing = None
            return

        proxy = mh2proxy.readProxyFile(human.meshData, filepath, False)
        
        if not proxy:
            return

        uuid = proxy.getUuid()
        
        # For loading costumes (sets of individual clothes)
        if proxy.clothings:
            t = 0
            dt = 1.0/len(proxy.clothings)
            for (pieceName, uuid) in proxy.clothings:
                gui3d.app.progress(t, text="Loading %s" % pieceName)
                t += dt
                mhclo = export_config.getExistingProxyFile(pieceName+".mhclo", uuid, "clothes")
                if mhclo:
                    self.setClothes(human, mhclo)
                else:
                    log.warning("Could not load clothing %s", pieceName)
            gui3d.app.progress(1, text="%s loaded" % proxy.name)
            # Load custom textures
            for (uuid, texPath) in proxy.textures:
                if not uuid in human.clothesObjs.keys():
                    log.warning("Cannot override texture for clothing piece with uuid %s!" % uuid)
                    continue
                pieceProxy = human.clothesProxies[uuid]
                if not os.path.dirname(texPath):
                    pieceProxy = human.clothesProxies[uuid]
                    clothesPath = os.path.dirname(pieceProxy.file)
                    texPath = os.path.join(clothesPath, texPath)
                log.debug("Overriding texture for clothpiece %s to %s", uuid, texPath)
                clo = human.clothesObjs[uuid]
                clo.mesh.setTexture(texPath)
            # Apply overridden transparency setting to pieces of a costume
            for (uuid, isTransparent) in proxy.transparencies.items():
                if not uuid in human.clothesProxies.keys():
                    log.warning("Could not override transparency for object with uuid %s!" % uuid)
                    continue
                clo = human.clothesObjs[uuid]
                log.debug("Overriding transparency setting for clothpiece %s to %s", uuid, bool(proxy.transparencies[uuid]))
                if proxy.transparencies[uuid]:
                    clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
                else:
                    clo.mesh.setTransparentPrimitives(0)
            return
            
        #folder = os.path.dirname(filepath)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            if human.activeClothing == uuid:
                human.activeClothing = None
            log.message("Removed clothing %s %s", proxy.name, uuid)
            return

        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Could not load mesh for clothing object %s", proxy.name)
            return
        if proxy.texture:
            (dir, name) = proxy.texture
            tex = os.path.join(folder, name)
            if not os.path.exists(tex):
                tex = os.path.join(self.systemClothes, "textures", name)
            mesh.setTexture(tex)
        else:
            pass
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        if proxy.cull:
            clo.mesh.setCull(1)
        else:
            clo.mesh.setCull(None)
        if proxy.transparent:
            clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
        else:
            clo.mesh.setTransparentPrimitives(0)
        clo.mesh.priority = 10
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        human.activeClothing = uuid
        self.clothesList.append(uuid)
        
        for tag in proxy.tags:
            tag = tag.lower()
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        log.message("Removed clothing %s", oldUuid)
                        gui3d.app.removeObject(oldClo)
                        del human.clothesObjs[oldUuid]
                        self.clothesList.remove(oldUuid)
                        if human.activeClothing == oldUuid:
                            human.activeClothing = None
                    else:
                        log.message("Kept clothing %s", oldUuid)
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())
    def setClothes(self, human, mhclo):
    
        if os.path.basename(mhclo) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            self.clothesList = []
            return

        proxy = mh2proxy.readProxyFile(human.meshData, mhclo, False)
        
        if not proxy:
            return

        uuid = proxy.getUuid()
        
        if proxy.clothings:
            folder = os.path.dirname(mhclo)
            for piece in proxy.clothings:
                piecefile = os.path.join(folder, piece, piece+".mhclo")
                self.setClothes(human, piecefile)
            return
            
        #folder = os.path.dirname(mhclo)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            print "Removed clothing 1", proxy.name, uuid
            return

        mesh = files3d.loadMesh(obj)
        if proxy.texture:
            (dir, name) = proxy.texture
            tif = os.path.join(folder, name)
            mesh.setTexture(tif)
        else:
            pass
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
        clo.mesh.originalClothesVerts = [v.co[:] for v in clo.mesh.verts]
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        self.clothesList.append(uuid)
        
        for tag in proxy.tags:
            tag = tag.lower()
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        print "OVERRIDE: do not remove clothing 2", oldUuid
                        #gui3d.app.removeObject(oldClo)
                        #del human.clothesObjs[oldUuid]
                        #self.clothesList.remove(oldUuid)
                    else:
                        print "Kept clothing", oldUuid
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())