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
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 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 setupStuff(name, obj, amt, rawTargets, cfg): global StuffTextures, StuffTexFiles, StuffMaterials StuffTextures = {} StuffTexFiles = {} StuffMaterials = {} stuffs = [] stuff = CStuff(name, None) if amt: stuff.setBones(amt) the.Stuff = stuff deleteGroups = [] deleteVerts = [] foundProxy = setupProxies('Proxy', name, obj, stuffs, amt, rawTargets, cfg.proxyList, deleteGroups, deleteVerts) setupProxies('Clothes', None, obj, stuffs, amt, rawTargets, cfg.proxyList, deleteGroups, deleteVerts) if not foundProxy: mesh1 = mh2proxy.getMeshInfo(obj, None, stuff.rawWeights, rawTargets, None) if (the.Options["helpers"] and the.Options["eyebrows"] and the.Options["lashes"] and deleteGroups == [] and deleteVerts == []): mesh2 = mesh1 else: mesh2 = filterMesh(mesh1, obj, deleteGroups, deleteVerts) stuff.setMesh(mesh2) stuffs = [stuff] + stuffs return (stuff, stuffs)
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
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
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
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