Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
0
    def __init__(self, category):

        gui3d.TaskView.__init__(self, category, 'Save')

        self.fileentry = self.addTopWidget(
            gui.FileEntryView('Save', mode='save'))
        self.fileentry.setDirectory(mh.getPath('models'))
        self.fileentry.setFilter('MakeHuman Models (*.mhm)')

        @self.fileentry.mhEvent
        def onFileSelected(filename):
            self.saveMHM(filename)
Ejemplo n.º 4
0
    def __init__(self, category):

        gui3d.TaskView.__init__(self, category, 'Export')

        self.formats = []
        self.recentlyShown = None

        exportPath = mh.getPath('exports')

        self.fileentry = self.addTopWidget(gui.FileEntryView('Export'))
        self.fileentry.setDirectory(exportPath)
        self.fileentry.setFilter('All Files (*.*)')

        self.exportBodyGroup = []
        self.exportHairGroup = []

        # Mesh Formats
        self.formatBox = self.addLeftWidget(gui.GroupBox('Mesh Format'))

        # Rig formats
        self.rigBox = self.addLeftWidget(gui.GroupBox('Rig format'))

        # Map formats
        self.mapsBox = self.addLeftWidget(gui.GroupBox('Maps'))

        self.empty = True

        self.optionsBox = self.addRightWidget(gui.StackedBox())
        self.optionsBox.setAutoResize(True)

        # Scales
        self.scaleBox = self.addRightWidget(gui.GroupBox('Scale units'))
        self.scaleButtons = self.addScales(self.scaleBox)

        # Encodings
        self.encodingBox = self.addRightWidget(gui.GroupBox('Encoding'))
        self.encodingButtons = self.addEncodings(self.encodingBox)

        self.boxes = {
            'mesh': self.formatBox,
            'rig': self.rigBox,
            'map': self.mapsBox,
            'scale': self.scaleBox
        }

        self.updateGui()

        @self.fileentry.mhEvent
        def onFileSelected(filename):
            path = os.path.normpath(os.path.join(exportPath, filename))
            dir, name = os.path.split(path)
            name, ext = os.path.splitext(name)

            if not os.path.exists(dir):
                os.makedirs(dir)

            def filename(targetExt, different=False):
                if not different and ext != '' and (
                        '.' + targetExt.lower()) != ext.lower():
                    log.warning("expected extension '.%s' but got '%s'",
                                targetExt, ext)
                return os.path.join(dir, name + '.' + targetExt)

            found = False
            for exporter, radio, options in self.formats:
                if radio.selected:
                    exporter.export(gui3d.app.selectedHuman, filename)
                    found = True
                    break

            if not found:
                log.error("Unknown export format selected!")
                return

            gui3d.app.prompt('Info',
                             u'The mesh has been exported to %s.' % dir,
                             'OK',
                             helpId='exportHelp')

            mh.changeCategory('Modelling')
Ejemplo n.º 5
0
    def __init__(self, category):
        super(ExportTaskView, self).__init__(category, 'Export')

        # Declare new settings
        gui3d.app.addSetting('exportdir', mh.getPath("exports"))

        self.formats = []
        self.recentlyShown = None
        self._requiresUpdate = True
        self.showOverwriteWarning = False

        self.fileentry = self.addTopWidget(
            gui.FileEntryView(label='File Name:',
                              buttonLabel='Export',
                              mode='save'))
        self.fileentry.directory = gui3d.app.getSetting('exportdir')
        self.fileentry.filter = 'All Files (*.*)'

        self.exportBodyGroup = []
        self.exportHairGroup = []

        # Mesh Formats
        self.formatBox = self.addLeftWidget(gui.GroupBox('Mesh Format'))

        # Rig formats
        self.rigBox = self.addLeftWidget(gui.GroupBox('Rig format'))

        # Map formats
        self.mapsBox = self.addLeftWidget(gui.GroupBox('Maps'))

        self.optionsBox = self.addRightWidget(gui.StackedBox())
        self.optionsBox.setAutoResize(True)

        # Scales
        self.scaleBox = self.addRightWidget(gui.GroupBox('Scale units'))
        self.scaleButtons = self.addScales(self.scaleBox)

        self.boxes = {
            'mesh': self.formatBox,
            'rig': self.rigBox,
            'map': self.mapsBox
        }

        self.updateGui()

        @self.fileentry.mhEvent
        def onFileSelected(event):
            dir, name = os.path.split(event.path)
            name, ext = os.path.splitext(name)

            if not os.path.exists(dir):
                os.makedirs(dir)

            # Remember last used export folder
            gui3d.app.setSetting('exportdir', formatPath(dir))

            def filename(targetExt, different=False):
                if not different and ext != '' and (
                        '.' + targetExt.lower()) != ext.lower():
                    log.warning("expected extension '.%s' but got '%s'",
                                targetExt, ext)
                return os.path.join(dir, name + '.' + targetExt)

            for exporter in [f[0] for f in self.formats if f[1].selected]:
                if self.showOverwriteWarning and \
                    event.source in ('button', 'return') and \
                    os.path.exists(os.path.join(dir, name + '.' + exporter.fileExtension)):
                    if not gui3d.app.prompt(
                            "File exists",
                            "The file already exists. Overwrite?", "Yes",
                            "No"):
                        break
                exporter.export(gui3d.app.selectedHuman, filename)
                gui3d.app.status(['The mesh has been exported to', ' %s.'],
                                 dir)
                self.showOverwriteWarning = False
                break
            else:
                log.error("Unknown export format selected!")

        @self.fileentry.mhEvent
        def onChange(text):
            self.showOverwriteWarning = True
    def __init__(self, category, appFacs):
        gui3d.TaskView.__init__(self, category, 'Pain Face Generator')
        self.facs_human = appFacs.selectedHuman
        camera = G.app.modelCamera
        self.app = appFacs

        # self.targets_path_emotions_blender = getpath.getPath('data/FACSHuman/00 Emotions')
        self.targets_path_upper_face = getpath.getPath(
            'data/FACSHuman/01 Upper Face AUs')
        self.targets_path_lower_face = getpath.getPath(
            'data/FACSHuman/02 Lower Face AUs')
        self.targets_path_lip_jaw = getpath.getPath(
            'data/FACSHuman/03 Lip Parting and Jaw Opening')
        # self.targets_path_eye = getpath.getPath('data/FACSHuman/04 Eye Positions')
        # self.targets_path_head = getpath.getPath('data/FACSHuman/05 Head Positions')
        # self.targets_path_misc = getpath.getPath('data/FACSHuman/06 Miscellaneous AUs')

        self.last_directory_rendering = ''
        self.images_to_convert = ''
        self.video_destination = ''
        #self.video_background = 'black.jpg'
        self.renderingWidth = '500'
        self.renderingHeight = '500'
        self.images_set_dir_destination = ''

        # box_emotions_blender = self.addLeftWidget(gui.GroupBox('Emotions blender'))
        box_upper = self.addLeftWidget(gui.GroupBox('Upper Face AUs'))
        box_lower = self.addLeftWidget(gui.GroupBox('Lower Face AUs'))
        # box_head = self.addLeftWidget(gui.GroupBox('Head Positions'))
        # box_eye = self.addLeftWidget(gui.GroupBox('Eye Positions'))
        box_lip = self.addLeftWidget(
            gui.GroupBox('Lip Parting and Jaw Opening'))
        # box_misc = self.addLeftWidget(gui.GroupBox('Miscellaneous AUs'))
        box_weight = self.addRightWidget(gui.GroupBox('AU Matrix Weights'))
        box_gen = self.addRightWidget(gui.GroupBox('View and Generate Images'))
        box_tools = self.addRightWidget(gui.GroupBox('Tools'))
        # box_aus_code = self.addRightWidget(gui.GroupBox('Action Units coding'))

        # self.general_intensity = box_aus_code.addWidget(gui.Slider(value=100, min=0, max=100, label=['General Intensity : ','%d%%']), columnSpan = 2)
        # #self.general_intensity_progress_bar = box_tools.addWidget(gui.ProgressBar())
        # #self.general_intensity_progress_bar.setProgress(1)
        # self.txt_file_loaded = box_aus_code.addWidget(gui.TextView('- New facial code -'), columnSpan = 2)
        # self.load_facs_button = box_aus_code.addWidget(gui.BrowseButton('open', "Load FACS Code"), 3, 0)
        # self.save_facs_button = box_aus_code.addWidget(gui.BrowseButton('save', "Save FACS Code"), 3, 1)
        # # self.save_target_button = box_aus_code.addWidget(gui.BrowseButton('save', "Save target"))
        # self.generate_au_coding_button = box_aus_code.addWidget(gui.Button('Get AU\'s Code'), columnSpan = 2)
        # self.txt_coding = box_aus_code.addWidget(gui.TextView('AU\'s code generated :'), columnSpan = 2)
        # self.au_coding = box_aus_code.addWidget(gui.DocumentEdit(text='Neutral'), columnSpan = 2)
        # self.one_shot_button = box_tools.addWidget(gui.Button('Take one shot'), 1, 0)

        self.survey_img_button = box_weight.addWidget(
            gui.Button('Generate Survey Images'), columnSpan=2)
        self.au4_lab = box_weight.addWidget(gui.TextView('AU4 Weight'))
        self.au4_val = box_weight.addWidget(gui.TextEdit(text='0.8865'))
        self.au7_lab = box_weight.addWidget(gui.TextView('AU7 Weight'))
        self.au7_val = box_weight.addWidget(gui.TextEdit(text='0.7758'))
        self.au9_lab = box_weight.addWidget(gui.TextView('AU9 Weight'))
        self.au9_val = box_weight.addWidget(gui.TextEdit(text='2.6129'))
        self.au10_lab = box_weight.addWidget(gui.TextView('AU10 Weight'))
        self.au10_val = box_weight.addWidget(gui.TextEdit(text='3.6517'))

        self.reset_camera_button = box_gen.addWidget(
            gui.Button('Full face camera view'), columnSpan=2)
        self.master_slider = box_gen.addWidget(gui.Slider(
            value=0, min=0, max=100, label=['General Intensity : ', '%d%%']),
                                               columnSpan=2)
        self.one_shot_button = box_gen.addWidget(gui.Button('Take one shot'),
                                                 columnSpan=2)
        self.generate_set_button = box_gen.addWidget(
            gui.Button('generate pain image set'), columnSpan=2)

        self.one_shot_stereo_button = box_tools.addWidget(
            gui.Button('Stereoscopic shot'), columnSpan=2)
        self.au_set_gen_button = box_tools.addWidget(
            gui.BrowseButton('open', "Dir to img"), 2, 0)
        self.material_gen_button = box_tools.addWidget(
            gui.BrowseButton('open', "Images set"), 2, 1)
        self.material_gen_dir_button = box_tools.addWidget(gui.FileEntryView(
            'Browse', mode='dir'),
                                                           columnSpan=2)
        self.camera_slider_x = box_tools.addWidget(gui.Slider(
            value=0, min=-1, max=1, label=['camera x: ', '%2f']),
                                                   columnSpan=2)
        self.camera_slider_y = box_tools.addWidget(gui.Slider(
            value=0, min=-1, max=1, label=['camera y: ', '%2f']),
                                                   columnSpan=2)
        self.camera_slider_zoom = box_tools.addWidget(gui.Slider(
            value=0, min=4, max=9, label=['Zoom: ', '%2f']),
                                                      columnSpan=2)
        self.rotation_slider_z = box_tools.addWidget(gui.Slider(
            value=0, min=-90, max=90, label=['rotation z: ', '%2f']),
                                                     columnSpan=2)
        self.reset_button = box_tools.addWidget(
            gui.Button('Reset Facial Code'), columnSpan=2)
        self.full_set_button = box_tools.addWidget(
            gui.Button('Full set generation'), columnSpan=2)
        self.facsvatar_set_button = box_tools.addWidget(gui.BrowseButton(
            'open', 'FACAvatar rendering'),
                                                        columnSpan=2)

        self.facs_code_names_path = getpath.getDataPath('FACSHuman')
        self.facs_code_names_file = self.facs_code_names_path + '/au.json'
        self.facs_code_names = json.loads(
            open(self.facs_code_names_file).read())

        self.slidersValues = {
        }  #Keep a trace of values in the General intensity sliders function
        self.sliders = {}
        self.sliders_order = []
        self.labelSlider = {}
        #self.modifiers = {}
        self.au_timeline_values = {}  # For the animation functionality
        self.au_facs_loaded_file_values = {}  # For the animation functionality

        self.facs_code_names_path = getpath.getDataPath('FACSHuman')
        self.facs_code_names_file = self.facs_code_names_path + '/au.json'
        self.facs_code_names = json.loads(
            open(self.facs_code_names_file).read())

        # self.searchTargets(self.targets_path_emotions_blender, box_emotions_blender, 'Emotions Blender')
        self.searchTargets(self.targets_path_upper_face, box_upper,
                           'Upper Face AUs')
        self.searchTargets(self.targets_path_lower_face, box_lower,
                           'Lower Face AUs')
        self.searchTargets(self.targets_path_lip_jaw, box_lip,
                           'Lip Parting and Jaw Opening')
        # self.searchTargets(self.targets_path_eye, box_eye, 'Eye Positions')
        # self.searchTargets(self.targets_path_head, box_head, 'Head Positions')
        # self.searchTargets(self.targets_path_misc, box_misc, 'Miscellaneous AUs')

        @self.camera_slider_x.mhEvent
        def onChanging(value):
            pos = self.facs_human.getPosition()
            pos[0] = value
            self.facs_human.setPosition(pos)
            mh.redraw()

        @self.camera_slider_y.mhEvent
        def onChanging(value):
            pos = self.facs_human.getPosition()
            pos[1] = value
            self.facs_human.setPosition(pos)
            mh.redraw()

        @self.camera_slider_zoom.mhEvent
        def onChanging(value):
            camera.setZoomFactor(value)

        @self.rotation_slider_z.mhEvent
        def onChanging(value):
            pos = self.facs_human.getRotation()
            pos[1] = value
            self.facs_human.setRotation(pos)
            mh.redraw()

##########################################################################
# Generate all AUs images
##########################################################################

        @self.facsvatar_set_button.mhEvent
        def onClicked(path):
            self.generateFacsvatarDirSet(path)

##########################################################################
# Generate all AUs images
##########################################################################

        @self.au_set_gen_button.mhEvent
        def onClicked(path):
            self.generateDirSet(path)

##########################################################################
# Generate material images
##########################################################################

        @self.material_gen_button.mhEvent
        def onClicked(path):
            self.generateCompleteImagesSetFromDir(path)
##########################################################################
# Generate material images
##########################################################################

        @self.material_gen_dir_button.mhEvent
        def onFileSelected(event):
            # self.images_set_dir_destination = os.path.dirname(path)
            self.images_set_dir_destination = event.path
            # self.images_set_dir_destination = os.path.dirname(path)
            gui3d.app.statusPersist('Images destination : ' +
                                    str(self.images_set_dir_destination))

##########################################################################
# Reset button for camera's orientation to have full face view
# in order to have constant point of view for experiments
##########################################################################

        @self.reset_camera_button.mhEvent
        def onClicked(event):
            gui3d.app.setTargetCamera(131, 9, False)
            gui3d.app.axisView([0.0, 0.0, 0.0])
            pos = [0, 0.2, 0]
            self.facs_human.setPosition(pos)
            self.camera_slider_x.setValue(0)
            self.camera_slider_y.setValue(0.2)
            self.camera_slider_zoom.setValue(9)
            self.rotation_slider_z.setValue(0)
            self.rotation_slider_z.onChanging(0)
            self.rotation_slider_z.update()
            mh.redraw()
            gui3d.app.statusPersist('Camera updated')

        @self.one_shot_button.mhEvent
        def onClicked(event):
            self.renderFacsPicture()

##########################################################################
# Reset facial code and AUs button
##########################################################################

        @self.reset_button.mhEvent
        def onClicked(event):
            G.app.prompt('Confirmation',
                         'Do you really want to reset your Facial code ?',
                         'Yes', 'Cancel', self.resetFacialCodes)

##########################################################################
# Generate 81 images for the survey website
##########################################################################

        @self.survey_img_button.mhEvent
        def onClicked(event):
            weight = [0, 0.5, 1]
            for i4 in range(3):
                for i7 in range(3):
                    for i9 in range(3):
                        for i10 in range(3):
                            self.survey_img_gen(weight[i4], weight[i7],
                                                weight[i9], weight[i10])
                            time.sleep(0.5)
                            self.renderSurveyImg(i4, i7, i9, i10)

##########################################################################
# Generate and save 101 images for overall intensity = 0% to 100%
##########################################################################

        @self.generate_set_button.mhEvent
        def onClicked(event):
            for val in range(0, 101):
                self.generate_face_set(val)
                time.sleep(0.5)
                self.renderFacsPicture()


##########################################################################
# View pain expression change at various general intensities
##########################################################################

        @self.master_slider.mhEvent
        def onChange(value):
            self.masterslider_render(value, True)