def __init__(self, category): self.systemSkins = os.path.join('data', 'skins') self.userSkins = os.path.join(mh.getPath(''), 'data', 'skins') gui3d.TaskView.__init__(self, category, 'Human texture', label='Skin') if not os.path.exists(os.path.join(mh.getPath(''), 'data', 'skins')): os.makedirs(os.path.join(mh.getPath(''), 'data', 'skins')) self.filechooser = self.addView(gui3d.FileChooser([self.systemSkins, self.userSkins], 'png', 'thumb')) self.update = self.filechooser.sortBox.addView(gui3d.Button('Check for updates')) self.mediaSync = None @self.filechooser.event def onFileSelected(filename): gui3d.app.do(Action(gui3d.app.selectedHuman, gui3d.app.selectedHuman.getTexture(), os.path.join(mh.getPath(''), 'data', 'skins', filename))) gui3d.app.switchCategory('Modelling') @self.update.event def onClicked(event): self.syncMedia() gui3d.app.addLoadHandler('skinTexture', self.loadHandler) gui3d.app.addSaveHandler(self.saveHandler)
def __init__(self, category): modelPath = mh.getPath('models') gui3d.TaskView.__init__( self, category, 'Load', ) self.fileentry = self.addTopWidget( gui.FileEntryView('Browse', mode='dir')) self.fileentry.setDirectory(mh.getPath('models')) self.fileentry.text = mh.getPath('models') self.fileentry.setFilter('MakeHuman Models (*.mhm)') @self.fileentry.mhEvent def onFileSelected(dirpath): self.filechooser.setPaths([dirpath]) self.filechooser.refresh() self.filechooser = fc.IconListFileChooser( modelPath, 'mhm', 'thumb', mh.getSysDataPath('notfound.thumb'), sort=HumanFileSort()) self.addRightWidget(self.filechooser) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): self.loadMHM(filename)
def saveSettings(self, promptOnFail=False): try: if not os.path.exists(mh.getPath('')): os.makedirs(mh.getPath('')) with outFile("settings.ini") as f: f.write(mh.formatINI(self.settings)) with outFile("shortcuts.ini") as f: for action, shortcut in self.shortcuts.iteritems(): f.write('%d %d %s\n' % (shortcut[0], shortcut[1], action)) with outFile("mouse.ini") as f: for mouseAction, method in self.mouseActions.iteritems(): f.write('%d %d %s\n' % (mouseAction[0], mouseAction[1], method.__name__)) if self.dialog is not None: self.helpIds.update(self.dialog.helpIds) with outFile("help.ini") as f: for helpId in self.helpIds: f.write('%s\n' % helpId) except: log.error('Failed to save settings file', exc_info=True) if promptOnFail: self.prompt('Error', 'Could not save settings file.', 'OK')
def projectLighting(self): mesh = gui3d.app.selectedHuman.mesh mesh.setShadeless(1) dstImg = mh.Image(width=1024, height=1024, bitsPerPixel=24) dstW = dstImg.width dstH = dstImg.height for v in mesh.verts: ld = vnorm(vsub((-10.99, 20.0, 20.0,), v.co)) s = vdot(v.no, ld) s = max(0, min(255, int(s*255))) v.setColor([s, s, s, 255]) for g in mesh.faceGroups: if g.name.startswith("joint") or g.name.startswith("helper"): continue for f in g.faces: co = [(mesh.uvValues[i][0]*dstW, dstH-(mesh.uvValues[i][1]*dstH)) for i in f.uv] c = [v.color for v in f.verts] RasterizeTriangle(dstImg, co[0], co[1], co[2], ColorShader(c[:3])) RasterizeTriangle(dstImg, co[2], co[3], co[0], ColorShader((c[2], c[3], c[0]))) #dstImg.resize(128, 128); dstImg.save(os.path.join(mh.getPath(''), 'data', 'skins', 'lighting.png')) gui3d.app.selectedHuman.setTexture(os.path.join(mh.getPath(''), 'data', 'skins', 'lighting.png')) mesh.setColor([255, 255, 255, 255])
def getMaterialPaths(self, objType, proxy = None): if objType == 'skin': objType = 'skins' elif objType not in [t.lower() for t in SimpleProxyTypes]: objType = 'clothes' objType = objType.lower() if proxy and objType != 'skins': subPath = None else: subPath = objType # General paths if subPath: paths = [mh.getPath(os.path.join('data', subPath)), mh.getSysDataPath(subPath)] for p in paths: if getpath.isSubPath(p, mh.getPath()) and not os.path.exists(p): os.makedirs(p) else: paths = [] # Global material paths for p in [mh.getPath(os.path.join('data', objType, 'materials')), mh.getSysDataPath(os.path.join(objType, 'materials'))]: if os.path.isdir(p): paths.append(p) # Path where proxy file is located if proxy: paths = [os.path.dirname(proxy.file)] + paths return paths
def projectUV(self): dstImg = projection.mapUV() # dstImg.resize(128, 128) dstImg.save(os.path.join(mh.getPath(""), "data", "skins", "uvtopo.png")) gui3d.app.selectedHuman.setTexture(os.path.join(mh.getPath(""), "data", "skins", "uvtopo.png")) log.debug("Enabling shadeless rendering on body") gui3d.app.selectedHuman.mesh.setShadeless(1) # Remember to reset this when lighting projection is done.
def onClicked(event): if not self.path: if not os.path.exists(mh.getPath('render')): os.makedirs(mh.getPath('render')) self.path = mh.getPath('render') filename = mh.getSaveFileName(os.path.splitext(self.path)[0], 'PNG Image (*.png);;JPEG Image (*.jpg);;All files (*.*)') if filename: self.path = os.path.dirname(filename) self.image.save(filename)
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Save') modelPath = mh.getPath('models') self.fileentry = self.addTopWidget(gui.FileEntryView('Save', mode='save')) self.fileentry.setDirectory(mh.getPath('models')) self.fileentry.setFilter('MakeHuman Models (*.mhm)') self.selection_width = 1.2 self.selection_height = 1.3 mesh = geometry3d.FrameMesh(self.selection_width, self.selection_height) mesh.move(-self.selection_width/2, -self.selection_height/2) self.selection = gui3d.app.addObject(gui3d.Object([0, 0, 9], mesh)) mesh.setColor([0, 0, 0, 255]) mesh.setPickable(False) mesh.setShadeless(True) mesh.setDepthless(True) mesh.priority = 90 self.selection.hide() @self.fileentry.mhEvent def onFileSelected(filename): if not filename.lower().endswith('.mhm'): filename += '.mhm' path = os.path.normpath(os.path.join(modelPath, filename)) dir, name = os.path.split(path) name, ext = os.path.splitext(name) if not os.path.exists(dir): os.makedirs(dir) # Save the thumbnail ((x0,y0,z0),(x1,y1,z1)) = self.selection.mesh.calcBBox() x0,y0,z0 = gui3d.app.guiCamera.convertToScreen(x0, y0, 0) x1,y1,z1 = gui3d.app.guiCamera.convertToScreen(x1, y1, 0) log.debug('grab rectangle: %d %d %d %d', x0, y0, x1, y1) mh.grabScreen(int(x0+1), int(y1+1), int(x1-x0-1), int(y0-y1-1), os.path.join(dir, name + '.thumb')) # Save the model human = gui3d.app.selectedHuman human.save(path, name) gui3d.app.modified = False #gui3d.app.clearUndoRedo() gui3d.app.setFilenameCaption(filename) gui3d.app.setFileModified(False) mh.changeCategory('Modelling')
def onClicked(event): if not self.path: if not os.path.exists(mh.getPath('render')): os.makedirs(mh.getPath('render')) self.path = mh.getPath('render') filename = mh.getSaveFileName( os.path.splitext(self.path)[0], 'PNG Image (*.png);;JPEG Image (*.jpg);;Thumbnail (*.thumb);;All files (*.*)' ) if filename: if os.path.splitext(filename)[1].lower() == '.thumb': self.image.save(filename, iformat='PNG') else: self.image.save(filename) self.path = os.path.dirname(filename)
def __init__(self, category): modelPath = mh.getPath('models') gui3d.TaskView.__init__(self, category, 'Load', ) self.filechooser = self.addTopWidget(fc.FileChooser(modelPath, 'mhm', 'thumb', 'data/notfound.thumb', sort=HumanFileSort())) self.addLeftWidget(self.filechooser.sortBox) @self.filechooser.mhEvent def onFileSelected(filename): human = gui3d.app.selectedHuman human.load(filename, True, gui3d.app.progress) del gui3d.app.undoStack[:] del gui3d.app.redoStack[:] gui3d.app.modified = False name = os.path.basename(filename).replace('.mhm', '') self.parent.tasksByName['Save'].fileentry.text = name self.parent.tasksByName['Save'].fileentry.edit.setText(name) gui3d.app.setFilenameCaption(filename) gui3d.app.setFileModified(False) mh.changeCategory('Modelling')
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Eyes') eyesDir = os.path.join(mh.getPath(''), 'data', 'eyes') if not os.path.exists(eyesDir): os.makedirs(eyesDir) self.paths = [eyesDir , mh.getSysDataPath('eyes')] #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'mhclo', 'thumb', mh.getSysDataPath('eyes/notfound.thumb'))) self.filechooser = self.addRightWidget(fc.IconListFileChooser(self.paths, 'mhclo', 'thumb', mh.getSysDataPath('clothes/notfound.thumb'), 'Eyes')) self.filechooser.setIconSize(50,50) self.filechooser.enableAutoRefresh(False) self.addLeftWidget(self.filechooser.createSortBox()) self.oHeadCentroid = [0.0, 7.436, 0.03 + 0.577] self.oHeadBBox = [[-0.84,6.409,-0.9862],[0.84,8.463,1.046]] self.human = gui3d.app.selectedHuman @self.filechooser.mhEvent def onFileSelected(filename): if self.human.eyesProxy: oldFile = self.human.eyesProxy.file else: oldFile = 'clear.mhclo' gui3d.app.do(EyesAction("Change eyes", self.human, self, oldFile, filename))
def __init__(self, category): modelPath = mh.getPath('models') gui3d.TaskView.__init__(self, category, 'Load', ) self.filechooser = self.addTopWidget(fc.FileChooser(modelPath, 'mhm', 'thumb', 'data/notfound.thumb', sort=HumanFileSort())) self.addLeftWidget(self.filechooser.sortBox) @self.filechooser.mhEvent def onFileSelected(filename): human = gui3d.app.selectedHuman human.load(filename, True, gui3d.app.progress) del gui3d.app.undoStack[:] del gui3d.app.redoStack[:] gui3d.app.modified = False gui3d.app.clearUndoRedo() name = os.path.basename(filename).replace('.mhm', '') self.parent.tasksByName['Save'].fileentry.text = name self.parent.tasksByName['Save'].fileentry.edit.setText(name) gui3d.app.setFilenameCaption(filename) gui3d.app.setFileModified(False) mh.changeCategory('Modelling')
def onShow(self, event): # When the task gets shown, set the focus to the file chooser gui3d.TaskView.onShow(self, event) human = gui3d.app.selectedHuman self.skinRadio.setChecked(True) self.reloadMaterialChooser() if human.hairObj: self.hairRadio.setEnabled(True) else: self.hairRadio.setEnabled(False) if human.eyesObj: self.eyesRadio.setEnabled(True) else: self.eyesRadio.setEnabled(False) self.populateClothesSelector() # Offer to download skins if none are found self.numSkin = len([filename for filename in os.listdir(os.path.join(mh.getPath(''), 'data', 'skins')) if filename.lower().endswith('png')]) if self.numSkin < 1: gui3d.app.prompt('No skins found', 'You don\'t seem to have any skins, download them from the makehuman media repository?\nNote: this can take some time depending on your connection speed.', 'Yes', 'No', self.syncMedia)
def fileentry(ext): of = outputFilename if useExportsDir: of = os.path.basename(of) ed = mh.getPath("exports") of = os.path.join(ed, of) return of
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Load') self.modelPath = None self.fileentry = self.addTopWidget(gui.FileEntryView('Browse', mode='dir')) self.fileentry.filter = 'MakeHuman Models (*.mhm)' @self.fileentry.mhEvent def onFileSelected(event): self.filechooser.setPaths([event.path]) self.filechooser.refresh() self.filechooser = fc.IconListFileChooser(mh.getPath("models"), 'mhm', 'thumb', mh.getSysDataPath('notfound.thumb'), sort=HumanFileSort()) self.addRightWidget(self.filechooser) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): if gui3d.app.currentFile.modified: gui3d.app.prompt("Load", "You have unsaved changes. Are you sure you want to close the current file?", "Yes", "No", lambda: gui3d.app.loadHumanMHM(filename)) else: gui3d.app.loadHumanMHM(filename)
def __init__(self, category): self.systemClothes = os.path.join('data', 'clothes') self.userClothes = os.path.join(mh.getPath(''), 'data', 'clothes') self.taggedClothes = {} self.clothesList = [] gui3d.TaskView.__init__(self, category, 'Clothes') if not os.path.exists(self.userClothes): os.makedirs(self.userClothes) self.filechooser = self.addTopWidget(fc.FileChooser([self.systemClothes, self.userClothes], 'mhclo', 'thumb', 'data/clothes/notfound.thumb')) self.addLeftWidget(self.filechooser.sortBox) self.update = self.filechooser.sortBox.addWidget(gui.Button('Check for updates')) self.mediaSync = None @self.filechooser.mhEvent def onFileSelected(filename): gui3d.app.do(Action("Change clothing piece", gui3d.app.selectedHuman, self, filename)) if gui3d.app.settings.get('jumpToModelling', True): mh.changeCategory('Modelling') @self.update.mhEvent def onClicked(event): self.syncMedia()
def reloadMaterial(self): obj = self.getSelectedObject() pxy = self.humanObjSelector.getSelectedProxy() author = "unknown" license = "unknown" filename = "internal" if pxy is not None: author = pxy.license.author license = pxy.license.license filename = pxy.file # update description self.descrLbl.setText(obj.name + ":\n" + str(len(obj.mesh.coord)) + " vertices\n" + str(len(obj.mesh.fvert)) + " faces\n" + str(obj.mesh.vertsPerFaceForExport) + " vertices per face.\n" + "Author: " + author + "\nLicense: " + license + "\n\nFile: " + filename) if shader.Shader.supported(): self.listShaders(obj.material) self.listUniforms(obj.material) self.updateShaderConfig(obj.material) self.listMaterialSettings(obj) if obj.material.filepath: self.saveMaterialBtn.directory = obj.material.filepath self.loadMaterialBtn.directory = obj.material.filepath else: self.saveMaterialBtn.directory = mh.getPath('data') self.loadMaterialBtn.directory = mh.getSysDataPath()
def __init__(self, template, bodypart, modtype): global theModifierTypes, theBaseCharacterParts string = template.replace('$','').replace('{','').replace('}','') warppath = os.path.join(mh.getPath(""), "warp", string) if not os.path.exists(os.path.dirname(warppath)): os.makedirs(os.path.dirname(warppath)) if not os.path.exists(warppath): fp = open(warppath, "w") fp.close() humanmodifier.SimpleModifier.__init__(self, warppath) self.eventType = 'warp' self.warppath = warppath self.template = template self.isWarp = True self.bodypart = bodypart self.slider = None self.refTargets = {} self.refTargetVerts = {} self.modtype = modtype self.fallback = None for (tlabel, tname, tvar) in theModifierTypes[modtype]: self.fallback = humanmodifier.MacroModifier(tlabel, tname, tvar) break self.bases = {} self.targetSpecs = {} if modtype == "GenderAge": self.setupBaseCharacters("Gender", "Age", "NoEthnic", "NoUniv", "NoUniv") elif modtype == "GenderAgeEthnic": self.setupBaseCharacters("Gender", "Age", "Ethnic", "NoUniv", "NoUniv") elif modtype == "GenderAgeToneWeight": self.setupBaseCharacters("Gender", "Age", "NoEthnic", "Tone", "Weight")
def doLoad(): filename = mh.getOpenFileName( mh.getPath("scenes"), 'MakeHuman scene (*.mhscene);;All files (*.*)') if filename: self.scene.load(filename) self.readScene()
def onShow(self, event): # When the task gets shown, set the focus to the file chooser gui3d.TaskView.onShow(self, event) human = gui3d.app.selectedHuman human.hide() self.skinRadio.setChecked(True) self.reloadTextureChooser() if human.hairObj: self.hairRadio.setEnabled(True) else: self.hairRadio.setEnabled(False) self.populateClothesSelector() # Offer to download skins if none are found self.numSkin = len([ filename for filename in os.listdir( os.path.join(mh.getPath(''), 'data', 'skins')) if filename.lower().endswith('png') ]) if self.numSkin < 1: gui3d.app.prompt( 'No skins found', 'You don\'t seem to have any skins, download them from the makehuman media repository?\nNote: this can take some time depending on your connection speed.', 'Yes', 'No', self.syncMedia)
def projectLighting(self): dstImg = projection.mapLighting() #dstImg.resize(128, 128); dstImg.save( os.path.join(mh.getPath(''), 'data', 'skins', 'lighting.png'))
def __init__(self, category): self.systemPoses = mh.getSysDataPath('poses') self.userPoses = mh.getPath('data/poses') self.paths = [self.systemPoses, self.userPoses] self.posefile = None self.pose = None gui3d.TaskView.__init__(self, category, 'Poses') if not os.path.exists(self.userPoses): os.makedirs(self.userPoses) #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'mhp', 'thumb', mh.getSysDataPath('notfound.thumb'))) self.filechooser = self.addRightWidget( fc.IconListFileChooser( self.paths, 'mhp', 'thumb', notFoundImage=mh.getSysDataPath('notfound.thumb'), name='Pose', noneItem=True, clearImage=os.path.join(self.systemPoses, 'clear.thumb'))) self.filechooser.setIconSize(50, 50) #self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filepath): oldFile = self.posefile gui3d.app.do(PoseAction("Change pose", self, oldFile, filepath))
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Scene') self.scene = scene.Scene() leftTopBox = self.addLeftWidget(gui.GroupBox("Current scene")) filebox = leftTopBox.addWidget(gui.TextView("Default.mhscene")) sceneDir = mh.getPath('scenes') if not os.path.exists(sceneDir): os.makedirs(sceneDir) defscene = os.path.join(sceneDir, "Default.mhscene") if os.path.exists(defscene): self.scene.load(defscene) else: self.scene.save(defscene) if not os.path.exists(os.path.join(sceneDir, "notfound.thumb")): shutil.copy(os.path.normpath(mh.getSysDataPath("uvs/notfound.thumb")), sceneDir) self.filechooser = self.addRightWidget( \ fc.IconListFileChooser(sceneDir , 'mhscene', ['thumb', 'png'], 'notfound.thumb', 'Scene')) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): self.scene.load(filename) filebox.setText(os.path.basename(filename))
def onClicked(event): filename = mh.getSaveFileName( mh.getPath("scenes"), 'MakeHuman scene (*.mhscene);;All files (*.*)') if filename: self.scene.save(filename) self.updateFileTitle()
def __init__(self, category): self.systemClothes = os.path.join('data', 'clothes') self.userClothes = os.path.join(mh.getPath(''), 'data', 'clothes') self.taggedClothes = {} self.clothesList = [] gui3d.TaskView.__init__(self, category, 'Clothes') if not os.path.exists(self.userClothes): os.makedirs(self.userClothes) self.filechooser = self.addView(gui3d.FileChooser([self.systemClothes, self.userClothes], 'mhclo', 'png', 'data/clothes/notfound.png')) self.update = self.filechooser.sortBox.addView(gui3d.Button('Check for updates')) self.mediaSync = None @self.filechooser.event def onFileSelected(filename): self.setClothes(gui3d.app.selectedHuman, filename) gui3d.app.switchCategory('Modelling') @self.update.event def onClicked(event): self.syncMedia()
def __init__(self, category, mhmTaskView, mhmLabel, folder): gui3d.TaskView.__init__(self, category, mhmLabel, label=mhmLabel) self.mhmTaskView = mhmTaskView self.include = "All" self.globalMhmPath = os.path.join('data', folder) self.mhmPath = os.path.join(mh.getPath(''), 'data', folder) if not os.path.exists(self.mhmPath): os.makedirs(self.mhmPath) self.filechooser = self.addTopWidget( fc.FileChooser([self.globalMhmPath, self.mhmPath], 'mhm', 'thumb')) self.addLeftWidget(self.filechooser.sortBox) @self.filechooser.mhEvent def onFileSelected(filename): gui3d.app.do( Action(gui3d.app.selectedHuman, filename, self.mhmTaskView, self.include)) mh.changeCategory('Modelling')
def __init__(self, category): guirender.RenderTaskView.__init__(self, category, 'Scene') self.scene = scene.Scene() sceneDir = mh.getPath('scenes') if not os.path.exists(sceneDir): os.makedirs(sceneDir) self.currentScene = os.path.join(sceneDir, "Default.mhscene") if os.path.exists(self.currentScene): loaded = self.scene.load(self.currentScene) if loaded is False: self.scene.save(self.currentScene) else: self.scene.save(self.currentScene) if not os.path.exists(os.path.join(sceneDir, "notfound.thumb")): shutil.copy( os.path.normpath(mh.getSysDataPath("uvs/notfound.thumb")), sceneDir) self.filechooser = self.addRightWidget( \ fc.IconListFileChooser(sceneDir , 'mhscene', ['thumb', 'png'], 'notfound.thumb', 'Scene')) #self.addLeftWidget(self.filechooser.createSortBox()) self.filechooser.enableAutoRefresh(False) glmodule.setSceneLighting(self.scene) @self.filechooser.mhEvent def onFileSelected(filename): self.loadScene(filename)
def renderFacsPicture(self, dir_images=None, pic_file=None, pic_file_reverse=None): #self.facs_human.applyAllTargets() #self.refreshAuSmoothSetting() self.renderingWidth = '500' self.renderingHeight = '500' self.grabPath = mh.getPath('grab') #log.message('self.grabPath = %s', self.grabPath) grabName = datetime.datetime.now().strftime( 'grab_%Y-%m-%d_%H.%M.%S.png') pic_file = os.path.join(self.grabPath, 'test', grabName) img_width, img_height = int(self.renderingWidth), int( self.renderingHeight) glmodule.draw(False) img = glmodule.renderToBuffer(img_width, img_height) #log.message('img type = %s'. type(img)) alphaImg = glmodule.renderAlphaMask(int(img_width), int(img_height)) img = imgop.addAlpha(img, imgop.getChannel(alphaImg, 0)) img = img.toQImage() img.save(pic_file) log.message("Image saved to %s", pic_file) del alphaImg del img
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Hair') hairDir = os.path.join(mh.getPath(''), 'data', 'hairstyles') if not os.path.exists(hairDir): os.makedirs(hairDir) self.paths = [hairDir , 'data/hairstyles'] #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'mhclo', 'thumb', 'data/hairstyles/notfound.thumb')) self.filechooser = self.addRightWidget(fc.IconListFileChooser(self.paths, 'mhclo', 'thumb', 'data/hairstyles/notfound.thumb', 'Hair')) self.filechooser.setIconSize(50,50) self.addLeftWidget(self.filechooser.createSortBox()) self.oHeadCentroid = [0.0, 7.436, 0.03 + 0.577] self.oHeadBBox = [[-0.84,6.409,-0.9862],[0.84,8.463,1.046]] @self.filechooser.mhEvent def onFileSelected(filename): human = gui3d.app.selectedHuman if human.hairProxy: oldFile = human.hairProxy.file else: oldFile = 'clear.mhclo' gui3d.app.do(HairAction("Change hair", human, self, oldFile, filename))
def onFileSelected(filename): gui3d.app.do(Action(gui3d.app.selectedHuman, gui3d.app.selectedHuman.getTexture(), os.path.join(mh.getPath(''), 'data', 'skins', filename))) gui3d.app.switchCategory('Modelling')
def __init__(self, template, bodypart, fallback): string = template.replace("$", "").replace("{", "").replace("}", "") warppath = os.path.join(mh.getPath(""), "warp", string) if not os.path.exists(os.path.dirname(warppath)): os.makedirs(os.path.dirname(warppath)) if not os.path.exists(warppath): fp = open(warppath, "w") fp.close() humanmodifier.SimpleModifier.__init__(self, warppath) self.fallback = eval("humanmodifier.%s('%s')" % (fallback, template)) self.warppath = warppath self.template = template paths = self.fallback.expandTemplate([(self.template, [])]) self.bases = {} if len(paths) == 1: path = paths[0] char, key = getBaseCharacter(path[0]) self.bases[key] = (path[0], char, -1) else: for path in paths: char, key = getBaseCharacter(path[1]) self.bases[key] = (path[0], char, -1) self.isWarp = True self.bodypart = bodypart self.slider = None self.refTargets = {} self.refTargetVerts = {}
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Proxies') self.installDir = mh.getSysDataPath('proxymeshes') self.userDir = os.path.join(mh.getPath(''), 'data', 'proxymeshes') if not os.path.exists(self.userDir): os.makedirs(self.userDir) self.paths = [self.userDir , self.installDir] #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'proxy', 'thumb', mh.getSysDataPath('proxymeshes/notfound.thumb'), sort=ProxyFileSort())) #self.filechooser = self.addRightWidget(fc.ListFileChooser(self.paths, 'proxy', 'Proxy', sort=ProxyFileSort())) self.filechooser = self.addRightWidget(fc.IconListFileChooser(self.paths, 'proxy', 'thumb', mh.getSysDataPath('proxymeshes/notfound.thumb'), 'Proxy')) self.filechooser.setIconSize(50,50) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): human = gui3d.app.selectedHuman if human.proxy: oldFile = human.proxy.file else: oldFile = "clear.proxy" gui3d.app.do(ProxyAction("Change proxy", human, self, oldFile, filename))
def exportCurrentFrame(self): exportPath = mh.getPath('exports') if not os.path.exists(exportPath): os.makedirs(exportPath) mh2obj.exportObj(gui3d.app.selectedHuman.meshData, os.path.join(exportPath, 'bvh_frame_%d.obj' % self.frameSlider.getValue()))
def __init__(self, category): """SaveTaskView constructor. The Save Task view contains a filename entry box at the top, and lets the model be displayed in the center, accompanied by a square border which the user can utilize to create a thumbnail for the saved model. """ gui3d.TaskView.__init__(self, category, 'Save') # Declare new settings gui3d.app.addSetting('savedir', mh.getPath("models")) self.fileentry = self.addTopWidget(gui.FileEntryView('Save', mode='save')) self.fileentry.setFilter('MakeHuman Models (*.mhm)') @self.fileentry.mhEvent def onFileSelected(event): path = event.path if not path.lower().endswith(".mhm"): path += ".mhm" if event.source in ('return', 'button') and \ os.path.exists(path) and \ path != G.app.currentFile.path: G.app.prompt("File exists", "The file already exists. Overwrite?", "Yes", "No", lambda: saveMHM(path)) else: saveMHM(path)
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Proxies') self.installDir = 'data/proxymeshes' self.userDir = os.path.join(mh.getPath(''), 'data', 'proxymeshes') if not os.path.exists(self.userDir): os.makedirs(self.userDir) self.paths = [self.userDir, self.installDir] #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'proxy', 'thumb', 'data/proxymeshes/notfound.thumb', sort=ProxyFileSort())) #self.filechooser = self.addRightWidget(fc.ListFileChooser(self.paths, 'proxy', 'Proxy', sort=ProxyFileSort())) self.filechooser = self.addRightWidget( fc.IconListFileChooser(self.paths, 'proxy', 'thumb', 'data/proxymeshes/notfound.thumb', 'Proxy')) self.filechooser.setIconSize(50, 50) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): human = gui3d.app.selectedHuman if human.proxy: oldFile = human.proxy.file else: oldFile = "clear.proxy" gui3d.app.do( ProxyAction("Change proxy", human, self, oldFile, filename))
def projectBackground(self): if not self.backgroundChooserView.isBackgroundShowing(): gui3d.app.prompt("Warning", "You need to load a background for the current view before you can project it.", "OK") return mesh = self.human.getSeedMesh() # for all quads, project vertex to screen # if one vertex falls in bg rect, project screen quad into uv quad # warp image region into texture ((x0,y0,z0), (x1,y1,z1)) = self.backgroundImage.mesh.calcBBox() camera = mh.cameras[self.backgroundImage.mesh.cameraMode] x0, y0, _ = camera.convertToScreen(x0, y0, z0, self.backgroundImage.mesh) x1, y1, _ = camera.convertToScreen(x1, y1, z1, self.backgroundImage.mesh) leftTop = (x0, y1) rightBottom = (x1, y0) dstImg = projection.mapImage(self.backgroundImage, mesh, leftTop, rightBottom) texPath = mh.getPath('data/skins/projection.png') if os.path.isfile(texPath): oldImg = mh.Image(texPath) else: oldImg = None gui3d.app.do(ProjectionAction("Change projected background texture", self.human.getTexture(), texPath, oldImg, dstImg)) log.debug("Enabling shadeless rendering on body") self.shadelessButton.setChecked(True) self.human.setShadeless(1) mh.redraw()
def __init__(self): self.human = gui3d.app.selectedHuman self.fileIncrement = 0; self.modelPath = mh.getPath('models') self.cam = G.app.modelCamera if(not os.path.exists(self.modelPath)): os.makedirs(self.modelPath)
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Material', label='Skin/Material') self.human = gui3d.app.selectedHuman # Paths, in order, in which relative material filepaths will be searched self.searchPaths = [mh.getPath(), mh.getSysDataPath()] self.searchPaths = [os.path.abspath(p) for p in self.searchPaths] self.materials = None self.filechooser = self.addRightWidget(fc.IconListFileChooser(self.materials, 'mhmat', ['thumb', 'png'], mh.getSysDataPath('skins/notfound.thumb'), name='Material')) self.filechooser.setIconSize(50,50) self.filechooser.enableAutoRefresh(False) #self.filechooser.setFileLoadHandler(fc.MhmatFileLoader()) #self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): mat = material.fromFile(filename) human = self.human obj = self.humanObjSelector.getSelectedObject() if obj: gui3d.app.do(MaterialAction(obj, mat)) self.humanObjSelector = self.addLeftWidget(HumanObjectSelector(self.human)) @self.humanObjSelector.mhEvent def onActivate(value): self.reloadMaterialChooser()
def loadHandler(self, human, values): if values[0] == 'skinTexture': (fname, ext) = os.path.splitext(values[1]) if fname != "texture": path = os.path.join(os.path.join(mh.getPath(''), 'data', 'skins', values[1])) if os.path.isfile(path): human.setTexture(path) elif ext == ".tif": path = path.replace(".tif", ".png") human.setTexture(path) elif values[0] == 'textures': uuid = values[1] filepath = values[2] if human.hairProxy and human.hairProxy.getUuid() == uuid: if not os.path.dirname(filepath): proxy = human.hairProxy hairPath = os.path.dirname(proxy.file) filepath = os.path.join(hairPath, filepath) human.hairObj.mesh.setTexture(filepath) return elif not uuid in human.clothesProxies.keys(): log.error("Could not load texture for object with uuid %s!" % uuid) return proxy = human.clothesProxies[uuid] if not os.path.dirname(filepath): proxy = human.clothesProxies[uuid] clothesPath = os.path.dirname(proxy.file) filepath = os.path.join(clothesPath, filepath) self.applyClothesTexture(uuid, filepath) return elif values[0] == 'eyeTexture': self.setEyes(human, values[1])
def __init__(self, category): """SaveTaskView constructor. The Save Task view contains a filename entry box at the top, and lets the model be displayed in the center, accompanied by a square border which the user can utilize to create a thumbnail for the saved model. """ gui3d.TaskView.__init__(self, category, 'Save') # Declare new settings gui3d.app.addSetting('savedir', mh.getPath("models")) self.fileentry = self.addTopWidget( gui.FileEntryView('Save', mode='save')) self.fileentry.setFilter('MakeHuman Models (*.mhm)') @self.fileentry.mhEvent def onFileSelected(event): path = event.path if not path.lower().endswith(".mhm"): path += ".mhm" if event.source in ('return', 'button') and \ os.path.exists(path) and \ path != G.app.currentFile.path: G.app.prompt("File exists", "The file already exists. Overwrite?", "Yes", "No", lambda: saveMHM(path)) else: saveMHM(path)
def __init__(self): self.human = gui3d.app.selectedHuman self.fileIncrement = 0 self.modelPath = mh.getPath('models') self.cam = G.app.modelCamera if (not os.path.exists(self.modelPath)): os.makedirs(self.modelPath)
def __init__(self, category, mhmTaskView, mhmLabel, folder): gui3d.TaskView.__init__(self, category, mhmLabel, label=mhmLabel) self.mhmTaskView = mhmTaskView self.include = "All" self.globalMhmPath = mh.getSysDataPath(folder) self.mhmPath = mh.getPath(os.path.join('data', folder)) self.paths = [self.globalMhmPath, self.mhmPath] if not os.path.exists(self.mhmPath): os.makedirs(self.mhmPath) #self.filechooser = self.addTopWidget(fc.FileChooser(self.paths, 'mhm', 'thumb')) self.filechooser = self.addRightWidget( fc.IconListFileChooser( self.paths, 'mhm', 'thumb', notFoundImage=mh.getSysDataPath('notfound.thumb'), name=mhmLabel, noneItem=True, clearImage=os.path.join(self.globalMhmPath, 'clear.thumb'))) self.filechooser.setIconSize(50, 50) self.addLeftWidget(self.filechooser.createSortBox()) @self.filechooser.mhEvent def onFileSelected(filename): gui3d.app.do( ExpressionAction(gui3d.app.selectedHuman, filename, self.mhmTaskView, self.include))
def onClicked(event): filename = mh.getSaveFileName( G.app.settings.get('Scene_Editor_FileDlgPath', mh.getPath('data/scenes')), 'MakeHuman scene (*.mhscene);;All files (*.*)') if filename: G.app.settings['Scene_Editor_FileDlgPath'] = filename doSave(filename)
def grabScreen(self): import datetime grabPath = mh.getPath('grab') if not os.path.exists(grabPath): os.makedirs(grabPath) # TODO: use bbox to choose grab region grabName = datetime.datetime.now().strftime('grab_%Y-%m-%d_%H.%M.%S.png') mh.grabScreen(0, 0, G.windowWidth, G.windowHeight, os.path.join(grabPath, grabName))
def loadHandler(self, human, values): if values[0] == 'status': return if values[0] == 'skinMaterial': path = values[1] if os.path.isfile(path): mat = material.fromFile(path) human.material = mat return else: absP = getpath.findFile( path, [mh.getPath('data'), mh.getSysDataPath()]) if not os.path.isfile(absP): log.warning( 'Could not find material %s for skinMaterial parameter.', values[1]) return mat = material.fromFile(absP) human.material = mat return elif values[0] == 'material': if len(values) == 3: uuid = values[1] filepath = values[2] name = "" else: name = values[1] uuid = values[2] filepath = values[3] if human.hairProxy and human.hairProxy.getUuid() == uuid: proxy = human.hairProxy filepath = self.getMaterialPath(filepath, proxy.file) proxy.object.material = material.fromFile(filepath) return elif human.eyesProxy and human.eyesProxy.getUuid() == uuid: proxy = human.eyesProxy filepath = self.getMaterialPath(filepath, proxy.file) proxy.object.material = material.fromFile(filepath) return elif human.genitalsProxy and human.genitalsProxy.getUuid() == uuid: proxy = human.genitalsProxy filepath = self.getMaterialPath(filepath, proxy.file) proxy.object.material = material.fromFile(filepath) return elif not uuid in human.clothesProxies.keys(): log.error( "Could not load material for proxy with uuid %s (%s)! No such proxy." % (uuid, name)) return proxy = human.clothesProxies[uuid] proxy = human.clothesProxies[uuid] filepath = self.getMaterialPath(filepath, proxy.file) self.applyClothesMaterial(uuid, filepath) return
def getMaterialPaths(self, objType, proxy=None): if objType == 'skin': objType = 'skins' elif objType not in [t.lower() for t in SimpleProxyTypes]: objType = 'clothes' objType = objType.lower() if proxy and objType != 'skins': subPath = None else: subPath = objType # General paths if subPath: paths = [ mh.getPath(os.path.join('data', subPath)), mh.getSysDataPath(subPath) ] for p in paths: if getpath.isSubPath(p, mh.getPath()) and not os.path.exists(p): os.makedirs(p) else: paths = [] # Global material paths for p in [ mh.getPath(os.path.join('data', objType, 'materials')), mh.getSysDataPath(os.path.join(objType, 'materials')) ]: if os.path.isdir(p): paths.append(p) # Path where proxy file is located if proxy: dirname = os.path.abspath(os.path.dirname(proxy.file)) parent = os.path.abspath(os.path.join(dirname, '..')) asset_basename = os.path.basename(dirname) asset_parentbase = os.path.basename(parent) user_parent_base = getpath.getDataPath(asset_parentbase) user_asset_final = os.path.abspath( os.path.join(user_parent_base, asset_basename)) paths = [dirname, user_asset_final] + paths return paths
def __init__(self, category): gui3d.TaskView.__init__(self, category, 'Save') modelPath = mh.getPath('models') self.fileentry = self.addTopWidget(gui.FileEntryView('Save')) self.fileentry.setDirectory(modelPath) self.fileentry.setFilter('MakeHuman Models (*.mhm)') self.selection_width = 1.2 self.selection_height = 1.3 mesh = geometry3d.FrameMesh(self.selection_width, self.selection_height) mesh.move(-self.selection_width / 2, -self.selection_height / 2) self.selection = gui3d.app.addObject(gui3d.Object([0, 0, 9], mesh)) mesh.setColor([0, 0, 0, 255]) mesh.setPickable(False) mesh.setShadeless(True) mesh.setDepthless(True) mesh.priority = 90 self.selection.hide() @self.fileentry.mhEvent def onFileSelected(filename): if not filename.lower().endswith('.mhm'): filename += '.mhm' path = os.path.normpath(os.path.join(modelPath, filename)) dir, name = os.path.split(path) name, ext = os.path.splitext(name) if not os.path.exists(dir): os.makedirs(dir) # Save the thumbnail ((x0, y0, z0), (x1, y1, z1)) = self.selection.mesh.calcBBox() x0, y0, z0 = gui3d.app.guiCamera.convertToScreen(x0, y0, 0) x1, y1, z1 = gui3d.app.guiCamera.convertToScreen(x1, y1, 0) log.debug('grab rectangle: %d %d %d %d', x0, y0, x1, y1) mh.grabScreen(int(x0 + 1), int(y1 + 1), int(x1 - x0 - 1), int(y0 - y1 - 1), os.path.join(dir, name + '.thumb')) # Save the model human = gui3d.app.selectedHuman human.save(path, name) gui3d.app.modified = False #gui3d.app.clearUndoRedo() gui3d.app.setFilenameCaption(filename) gui3d.app.setFileModified(False) mh.changeCategory('Modelling')
def grabScreen(self): import datetime grabPath = mh.getPath('grab') if not os.path.exists(grabPath): os.makedirs(grabPath) grabName = datetime.datetime.now().strftime('grab_%Y-%m-%d_%H.%M.%S.png') filename = os.path.join(grabPath, grabName) mh.grabScreen(0, 0, G.windowWidth, G.windowHeight, filename) self.status("Screengrab saved to %s", filename)
def syncMedia(self): if self.mediaSync: return skinsFolder = os.path.join(mh.getPath(''), 'data', 'skins') if not os.path.isdir(skinsFolder): os.makedirs(skinsFolder) self.mediaSync = download.MediaSync(gui3d.app, skinsFolder, 'http://download.tuxfamily.org/makehuman/skins/', self.syncMediaFinished) self.mediaSync.start()
def quickExport(self): exportPath = mh.getPath('exports') if not os.path.exists(exportPath): os.makedirs(exportPath) import mh2obj mh2obj.exportObj(self.selectedHuman.meshData, exportPath + '/quick_export.obj') import mh2bvh mh2bvh.exportSkeleton(self.selectedHuman.meshData, exportPath + '/quick_export.bvh') import mh2mhx mh2mhx.exportMhx(self.selectedHuman.meshData, exportPath + '/quick_export.mhx')
def inFile(path): try: path = os.path.join(mh.getPath(''), path) if not os.path.isfile(path): yield [] return with open(path, 'r') as f: yield f except: log.error('Failed to load file %s', path, exc_info=True)