예제 #1
0
    def __init__(self, category, app):
        self.app = app
        gui3d.TaskView.__init__(self, category, 'Custom')
        self.targetsPath = getpath.getPath('data/custom')
        if not os.path.exists(self.targetsPath):
            os.makedirs(self.targetsPath)

        self.optionsBox = self.addRightWidget(gui.GroupBox('Options'))
        rescanButton = self.optionsBox.addWidget(
            gui.Button("Rescan targets' folder"))

        self.folderBox = self.addRightWidget(gui.GroupBox('Folders'))
        self.targetsBox = self.addLeftWidget(gui.StackedBox())

        self.human = app.selectedHuman

        @rescanButton.mhEvent
        def onClicked(event):
            self.searchTargets()

        self.folders = []
        self.sliders = []
        self.modifiers = {}

        self.searchTargets()
예제 #2
0
    def __init__(self,
                 category,
                 name,
                 label=None,
                 saveName=None,
                 cameraView=None):
        if label is None:
            label = name.capitalize()
        if saveName is None:
            saveName = name
        # JH: Hack to get around issue #396 for 1.0.1 release. For 1.1 translation strings should be updated.
        if label == "Arms and legs":
            label = "Arms and Legs"

        super(ModifierTaskView, self).__init__(category, name, label=label)

        self.saveName = saveName
        self.cameraFunc = _getCamFunc(cameraView)

        self.groupBoxes = OrderedDict()
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        self.showMacroStats = False
예제 #3
0
    def __init__(self,
                 category,
                 name,
                 label=None,
                 saveName=None,
                 cameraView=None):
        if label is None:
            label = name.capitalize()
        if saveName is None:
            saveName = name

        super(ModifierTaskView, self).__init__(category, name, label=label)

        self.saveName = saveName
        self.cameraFunc = _getCamFunc(cameraView)

        self.groupBoxes = OrderedDict()
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        self.showMacroStats = False
        self.human = gui3d.app.selectedHuman
    def __init__(self, category):
        gui3d.TaskView.__init__(self, category, 'Expression tuning')

        self.expressions = [
            ('eyebrows-left', ['down', 'extern-up', 'inner-up', 'up']),
            ('eyebrows-right', ['down', 'extern-up', 'inner-up', 'up']),
            ('eye-left', ['closure', 'opened-up', 'slit']),
            ('eye-right', ['closure', 'opened-up', 'slit']),
            ('mouth', [
                'compression', 'corner-puller', 'depression',
                'depression-retraction', 'elevation', 'eversion', 'parling',
                'part-later', 'protusion', 'pursing', 'retraction',
                'upward-retraction', 'open'
            ]),
            ('nose', [
                'depression', 'left-dilatation', 'left-elevation',
                'right-dilatation', 'right-elevation', 'compression'
            ]),
            ('neck', ['platysma']),
        ]

        self.include = "All"

        self.groupBoxes = []
        self.radioButtons = []
        self.sliders = []

        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        for name, subnames in self.expressions:
            # Create box
            box = self.groupBox.addWidget(gui.SliderBox(name.capitalize()))
            self.groupBoxes.append(box)

            # Create sliders
            for subname in subnames:
                modifier = warpmodifier.WarpModifier(
                    'data/targets/expression/units/${ethnic}/${gender}_${age}/%s-%s.target'
                    % (name, subname), "face", "GenderAgeEthnic")

                self.modifiers[name + '-' + subname] = modifier
                slider = box.addWidget(
                    ExpressionSlider(subname.capitalize(), modifier))
                self.sliders.append(slider)
                modifier.slider = slider
            # Create radiobutton
            radio = self.categoryBox.addWidget(
                GroupBoxRadioButton(self,
                                    self.radioButtons,
                                    name.capitalize(),
                                    box,
                                    selected=len(self.radioButtons) == 0))

        self.groupBox.showWidget(self.groupBoxes[0])
예제 #5
0
    def __init__(self, category, app):
        self.app = app
        gui3d.TaskView.__init__(self, category, 'Custom')
        self.targetsPath = getpath.getPath('data/custom')
        if not os.path.exists(self.targetsPath):
            os.makedirs(self.targetsPath)

        self.optionsBox = self.addRightWidget(gui.GroupBox('Options'))
        rescanButton = self.optionsBox.addWidget(
            gui.Button("Rescan targets' folder"))
        self.keepValues = self.optionsBox.addWidget(
            gui.CheckBox('Keep Values', app.getSetting('keepCustomValues')))

        self.folderBox = self.addRightWidget(gui.GroupBox('Folders'))
        self.targetsBox = self.addLeftWidget(gui.StackedBox())

        self.human = app.selectedHuman

        @rescanButton.mhEvent
        def onClicked(event):

            backUpModifiers = {}

            if self.keepValues.isChecked():
                for name, modifier in self.modifiers.items():
                    if modifier.getValue() != 0:
                        backUpModifiers[name] = modifier.getValue()

            self.searchTargets()

            if self.keepValues.isChecked():
                for name, value in backUpModifiers.items():
                    modifier = self.modifiers.get(name)
                    if modifier:
                        modifier.setValue(value)
                self.syncSliders()
                self.human.applyAllTargets()

            backUpModifiers.clear()

        self.folders = []
        self.sliders = []
        self.modifiers = {}

        self.searchTargets()
    def __init__(self, category, app):
        self.app = app
        gui3d.TaskView.__init__(self, category, 'Custom')
        self.targetsPath = os.path.join(mh.getPath(''), 'custom')
        if not os.path.exists(self.targetsPath):
            os.makedirs(self.targetsPath)
        
        self.optionsBox = self.addRightWidget(gui.GroupBox('Options'))
        rescanButton = self.optionsBox.addWidget(gui.Button("Rescan targets' folder"))

        self.folderBox = self.addRightWidget(gui.GroupBox('Folders'))
        self.targetsBox = self.addLeftWidget(gui.StackedBox())
        
        @rescanButton.mhEvent
        def onClicked(event):
            #TODO: undo any applied change here
            self.searchTargets()
           
        self.folders = [] 
            
        self.searchTargets()
예제 #7
0
    def __init__(self, category):
        gui3d.TaskView.__init__(self, category, 'Expression tuning')

        self.expressions = [
            ('eyebrows-left', ['down', 'extern-up', 'inner-up', 'up']),
            ('eyebrows-right', ['down', 'extern-up', 'inner-up', 'up']),
            ('eye-left', ['closure', 'opened-up', 'slit']),
            ('eye-right', ['closure', 'opened-up', 'slit']),
            ('mouth', [
                'compression', 'corner-puller', 'depression',
                'depression-retraction', 'elevation', 'eversion', 'parling',
                'part-later', 'protusion', 'pursing', 'retraction',
                'upward-retraction', 'open'
            ]),
            ('nose', [
                'depression', 'left-dilatation', 'left-elevation',
                'right-dilatation', 'right-elevation', 'compression'
            ]),
            ('neck', ['platysma']),
        ]

        self.include = "All"

        self.groupBoxes = []
        self.radioButtons = []
        self.sliders = []

        self.modifiers = {}
        self.targets = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        for name, subnames in self.expressions:
            # Create box
            box = self.groupBox.addWidget(gui.SliderBox(name.capitalize()))
            self.groupBoxes.append(box)

            # Create sliders
            for subname in subnames:
                if _UseWarping:
                    targetName = name + "-" + subname
                    modifier = ExpressionWarpModifier(targetName)
                else:
                    template = 'data/targets/expression/units/caucasian/%s-%s.target' % (
                        name, subname)
                    modifier = ExpressionSimpleModifier(template)

                modifier.setHuman(gui3d.app.selectedHuman)
                slider = box.addWidget(
                    ExpressionModifierSlider(taskview=self,
                                             label=subname.capitalize(),
                                             modifier=modifier))
                slider.modifier = modifier
                self.modifiers[name + '-' + subname] = modifier
                self.sliders.append(slider)
                modifier.slider = slider
            # Create radiobutton
            self.categoryBox.addWidget(
                GroupBoxRadioButton(self,
                                    self.radioButtons,
                                    name.capitalize(),
                                    box,
                                    selected=len(self.radioButtons) == 0))

        self.groupBox.showWidget(self.groupBoxes[0])
예제 #8
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')
예제 #9
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
예제 #10
0
    def __init__(self, category):
        super(ModifierTaskView, self).__init__(category, self._name, label=self._label)

        def resolveOptionsDict(opts, type = 'simple'):
            # Function to analyze options passed
            # with a dictionary in the features.
            if not 'cam' in opts.keys():
                opts['cam'] = 'noSetCamera'
            if not 'min' in opts.keys():
                if type == 'paired':
                    opts['min'] = -1.0
                else:
                    opts['min'] = 0.0
            if not 'max' in opts.keys():
                opts['max'] = 1.0
            if 'reverse' in opts.keys() and opts['reverse'] == True:
                temp = opts['max']
                opts['max'] = opts['min']
                opts['min'] = temp
            if not 'label' in opts.keys():
                opts['label'] = None

        self.groupBoxes = []
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        for name, base, templates in self._features:
            title = name.capitalize()

            # Create box
            box = self.groupBox.addWidget(gui.GroupBox(title))
            self.groupBoxes.append(box)

            # Create radiobutton
            self.categoryBox.addWidget(GroupBoxRadioButton(self, self.radioButtons, title, box, selected = len(self.radioButtons) == 0))

            # Create sliders
            for index, template in enumerate(templates):
                macro = len(template) == 3
                if macro:
                    tname, tvar, opts = template
                    resolveOptionsDict(opts, 'macro')
                    if tname:
                        groupName = base + "-" + tname
                    else:
                        groupName = base
                    modifier = humanmodifier.MacroModifier(groupName, tvar)
                    modifier.setHuman(G.app.selectedHuman)
                    self.modifiers[tvar] = modifier
                    tpath = '-'.join(template[1:-1])
                    slider = modifierslider.MacroSlider(modifier, opts['label'], ('%s.png' % tpath).lower(),
                                                       opts['cam'], opts['min'], opts['max'])
                else:
                    paired = len(template) == 4
                    if paired:
                        tname, tleft, tright, opts = template
                        resolveOptionsDict(opts, 'paired')
                        left  = '-'.join([base, tname, tleft])
                        right = '-'.join([base, tname, tright])
                    else:
                        tname, opts = template
                        resolveOptionsDict(opts)
                        tleft = None
                        tright = None

                    if opts['label'] is None:
                        tlabel = tname.split('-')
                        if len(tlabel) > 1 and tlabel[0] == base:
                            tlabel = tlabel[1:]
                        opts['label'] = ' '.join([word.capitalize() for word in tlabel])

                    groupName = base
                    name = tname
                    modifier = humanmodifier.UniversalModifier(groupName, name, tleft, tright, centerExt=None)
                    modifier.setHuman(G.app.selectedHuman)

                    tpath = '-'.join(template[0:-1])
                    modifierName = tpath
                    clashIndex = 0
                    while modifierName in self.modifiers:
                        log.debug('modifier clash: %s', modifierName)
                        modifierName = '%s%d' % (tpath, clashIndex)
                        clashIndex += 1

                    self.modifiers[modifierName] = modifier
                    slider = modifierslider.UniversalSlider(modifier, opts['label'], '%s.png' % tpath,
                                                           opts['cam'], opts['min'], opts['max'])

                box.addWidget(slider)
                self.sliders.append(slider)

        self.updateMacro()

        self.groupBox.showWidget(self.groupBoxes[0])
예제 #11
0
    def __init__(self, category):
        gui3d.TaskView.__init__(self, category, 'Measure')

        self.ruler = Ruler()

        self.measureMesh = module3d.Object3D('measure', 2)
        self.measureMesh.createFaceGroup('measure')

        names = []
        for n, v in self.ruler.Measures.items():
            if len(v) % 2 != 0:
                names.append(n)
        if len(names) > 0:
            raise RuntimeError(
                "One or more measurement rulers contain an uneven number of vertex indices. It's required that they are pairs indicating the begin and end point of every line to draw. Rulers with uneven index count: %s"
                % ", ".join(names))
        del names
        count = max([len(vertIdx) for vertIdx in self.ruler.Measures.values()])

        self.measureMesh.setCoords(np.zeros((count, 3), dtype=np.float32))
        self.measureMesh.setUVs(np.zeros((1, 2), dtype=np.float32))
        self.measureMesh.setFaces(np.arange(count).reshape((-1, 2)))

        self.measureMesh.setCameraProjection(0)
        self.measureMesh.setShadeless(True)
        self.measureMesh.setDepthless(True)
        self.measureMesh.setColor([255, 255, 255, 255])
        self.measureMesh.setPickable(0)
        self.measureMesh.updateIndexBuffer()
        self.measureMesh.priority = 50

        self.measureObject = self.addObject(gui3d.Object(self.measureMesh))

        measurements = [
            ('neck', ['neckcirc', 'neckheight']),
            ('upperarm', ['upperarm', 'upperarmlenght']),
            ('lowerarm', ['lowerarmlenght', 'wrist']),
            ('torso', [
                'frontchest', 'bust', 'underbust', 'waist', 'napetowaist',
                'waisttohip', 'shoulder'
            ]),
            ('hips', ['hips']),
            ('upperleg', ['upperlegheight', 'thighcirc']),
            ('lowerleg', ['lowerlegheight', 'calf']),
            ('ankle', ['ankle']),
        ]

        sliderLabel = {
            'neckcirc': 'Neck circum',
            'neckheight': 'Neck height',
            'upperarm': 'Upper arm circum',
            'upperarmlenght': 'Upperarm length',
            'lowerarmlenght': 'Lowerarm length',
            'wrist': 'Wrist circum',
            'frontchest': 'Front chest dist',
            'bust': 'Bust circum',
            'underbust': 'Underbust circum',
            'waist': 'Waist circum',
            'napetowaist': 'Nape to waist',
            'waisttohip': 'Waist to hip',
            'shoulder': 'Shoulder dist',
            'hips': 'Hips circum',
            'upperlegheight': 'Upperleg height',
            'thighcirc': 'Thigh circ.',
            'lowerlegheight': 'Lowerleg height',
            'calf': 'Calf circum',
            'ankle': 'Ankle circum'
        }

        self.groupBoxes = {}
        self.radioButtons = []
        self.sliders = []
        self.active_slider = None

        self.modifiers = {}

        measureDataPath = mh.getSysDataPath("targets/measure/")

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        for name, subnames in measurements:
            # Create box
            box = self.groupBox.addWidget(gui.SliderBox(name.capitalize()))
            self.groupBoxes[name] = box

            # Create radiobutton
            box.radio = self.categoryBox.addWidget(
                GroupBoxRadioButton(self,
                                    self.radioButtons,
                                    name.capitalize(),
                                    box,
                                    selected=len(self.radioButtons) == 0))

            # Create sliders
            for subname in subnames:
                # TODO use another modifier
                modifier = humanmodifier.Modifier(
                    os.path.join(measureDataPath,
                                 "measure-%s-decrease.target" % subname),
                    os.path.join(measureDataPath,
                                 "measure-%s-increase.target" % subname))
                modifier.setHuman(gui3d.app.selectedHuman)
                self.modifiers[subname] = modifier
                slider = box.addWidget(
                    MeasureSlider(sliderLabel[subname], self, subname,
                                  modifier))
                self.sliders.append(slider)
        self.lastActive = None

        self.statsBox = self.addRightWidget(gui.GroupBox('Statistics'))
        self.height = self.statsBox.addWidget(gui.TextView('Height: '))
        self.chest = self.statsBox.addWidget(gui.TextView('Chest: '))
        self.waist = self.statsBox.addWidget(gui.TextView('Waist: '))
        self.hips = self.statsBox.addWidget(gui.TextView('Hips: '))
        '''
        self.braBox = self.addRightWidget(gui.GroupBox('Brassiere size'))
        self.eu = self.braBox.addWidget(gui.TextView('EU: '))
        self.jp = self.braBox.addWidget(gui.TextView('JP: '))
        self.us = self.braBox.addWidget(gui.TextView('US: '))
        self.uk = self.braBox.addWidget(gui.TextView('UK: '))
        '''

        self.groupBox.showWidget(self.groupBoxes['neck'])
    def __init__(self, category):
        super(ModifierTaskView, self).__init__(category,
                                               self._name,
                                               label=self._label)

        self.groupBoxes = []
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        for name, base, templates in self._features:
            title = name.capitalize()

            # Create box
            box = self.groupBox.addWidget(gui.GroupBox(title))
            self.groupBoxes.append(box)

            # Create radiobutton
            radio = self.categoryBox.addWidget(
                GroupBoxRadioButton(self,
                                    self.radioButtons,
                                    title,
                                    box,
                                    selected=len(self.radioButtons) == 0))

            # Create sliders
            for index, template in enumerate(templates):
                macro = len(template) >= 6
                if macro:
                    tlabel, tname, tvar, tmin, tmax, tview = template
                    modifier = humanmodifier.MacroModifier(
                        base, tname, tvar, tmin, tmax)
                    self.modifiers[tlabel] = modifier
                    slider = humanmodifier.GenericSlider(
                        tmin, tmax, modifier, tlabel, None, tview)
                else:
                    paired = len(template) == 5
                    if paired:
                        tlabel, tname, tleft, tright, tview = template
                        left = '-'.join([base, tname, tleft])
                        right = '-'.join([base, tname, tright])
                    else:
                        tlabel, tname, tview = template
                        left = None
                        right = '-'.join([base, tname])

                    if tlabel is None:
                        tlabel = tname.split('-')
                        if len(tlabel) > 1 and tlabel[0] == base:
                            tlabel = tlabel[1:]
                        tlabel = ' '.join(
                            [word.capitalize() for word in tlabel])

                    modifier = humanmodifier.UniversalModifier(left, right)

                    tpath = '-'.join(template[1:-1])
                    modifierName = tpath
                    clashIndex = 0
                    while modifierName in self.modifiers:
                        log.debug('modifier clash: %s', modifierName)
                        modifierName = '%s%d' % (tpath, clashIndex)
                        clashIndex += 1

                    self.modifiers[modifierName] = modifier
                    slider = humanmodifier.UniversalSlider(
                        modifier, tlabel, '%s.png' % tpath, tview)

                box.addWidget(slider)
                self.sliders.append(slider)

        self.updateMacro()

        self.groupBox.showWidget(self.groupBoxes[0])
예제 #13
0
    def __init__(self, category):
        gui3d.TaskView.__init__(self, category, 'Scene Editor')
        sceneBox = self.addLeftWidget(gui.GroupBox('Scene'))
        self.fnlbl = sceneBox.addWidget(gui.TextView('<New scene>'))
        self.saveButton = sceneBox.addWidget(gui.Button('Save'), 1, 0)
        self.loadButton = sceneBox.addWidget(gui.Button('Load ...'), 1, 1)
        self.saveAsButton = sceneBox.addWidget(gui.Button('Save As...'), 2, 0)
        self.closeButton = sceneBox.addWidget(gui.Button('Close'), 2, 1)

        itemBox = self.addLeftWidget(gui.GroupBox('Items'))
        self.itemList = itemBox.addWidget(gui.ListView())
        self.itemList.setSizePolicy(gui.SizePolicy.Ignored,
                                    gui.SizePolicy.Preferred)

        self.propsBox = gui.StackedBox()
        self.addRightWidget(self.propsBox)

        self.addButton = itemBox.addWidget(gui.Button('Add...'))
        self.adder = SceneItemAdder(self)
        self.propsBox.addWidget(self.adder.widget)

        self.items = {}
        self.activeItem = None
        self.scene = scene.Scene()
        self.readScene()

        def doLoad():
            filename = mh.getOpenFileName(
                mh.getPath("scenes"),
                'MakeHuman scene (*.mhscene);;All files (*.*)')
            if filename:
                self.scene.load(filename)
                self.readScene()

        @self.scene.mhEvent
        def onChanged(scene):
            self.updateFileTitle()

        @self.loadButton.mhEvent
        def onClicked(event):
            if self.scene.unsaved:
                gui3d.app.prompt(
                    'Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', doLoad())
            else:
                doLoad()

        @self.saveButton.mhEvent
        def onClicked(event):
            if self.scene.path is None:
                self.saveAsButton.callEvent('onClicked', None)
            else:
                self.scene.save()
            self.updateFileTitle()

        @self.closeButton.mhEvent
        def onClicked(event):
            if self.scene.unsaved:
                gui3d.app.prompt(
                    'Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', self.scene.close())
            else:
                self.scene.close()
            self.readScene()

        @self.saveAsButton.mhEvent
        def onClicked(event):
            filename = mh.getSaveFileName(
                mh.getPath("scenes"),
                'MakeHuman scene (*.mhscene);;All files (*.*)')
            if filename:
                self.scene.save(filename)
            self.updateFileTitle()

        @self.itemList.mhEvent
        def onClicked(event):
            self.items[self.itemList.getSelectedItem()].showProps()

        @self.addButton.mhEvent
        def onClicked(event):
            self.adder.showProps()
예제 #14
0
    def __init__(self, category):
        guirender.RenderTaskView.__init__(self, category, 'Scene Editor')
        sceneBox = self.addLeftWidget(gui.GroupBox('Scene'))
        self.fnlbl = sceneBox.addWidget(gui.TextView('<New scene>'))
        self.saveButton = sceneBox.addWidget(gui.Button('Save'), 1, 0)
        self.loadButton = sceneBox.addWidget(gui.Button('Load ...'), 1, 1)
        self.saveAsButton = sceneBox.addWidget(gui.Button('Save As...'), 2, 0)
        self.closeButton = sceneBox.addWidget(gui.Button('Close'), 2, 1)

        itemBox = self.addLeftWidget(gui.GroupBox('Items'))
        self.itemList = itemBox.addWidget(gui.ListView())
        self.itemList.setSizePolicy(gui.SizePolicy.Ignored,
                                    gui.SizePolicy.Preferred)

        self.propsBox = gui.StackedBox()
        self.addRightWidget(self.propsBox)

        self.addButton = itemBox.addWidget(gui.Button('Add...'))
        self.adder = SceneItemAdder(self)
        self.propsBox.addWidget(self.adder.widget)

        self.items = {}
        self.activeItem = None
        self.scene = scene.Scene()
        self.readScene()

        def doLoad():
            filename = mh.getOpenFileName(
                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
                self.scene.load(filename)
                self.readScene()

        def doSave(filename=None):
            ok = self.scene.save(filename)
            if ok and not G.app.currentScene.path is None \
                and os.path.normpath(G.app.currentScene.path) \
                == os.path.normpath(self.scene.path):
                # Refresh MH's current scene if it was modified.
                G.app.currentScene.reload()

        @self.scene.mhEvent
        def onChanged(scn):
            self.updateScene()

        @self.loadButton.mhEvent
        def onClicked(event):
            if self.scene.unsaved:
                G.app.prompt(
                    'Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', doLoad)
            else:
                doLoad()

        @self.saveButton.mhEvent
        def onClicked(event):
            if self.scene.path is None:
                self.saveAsButton.callEvent('onClicked', None)
            else:
                doSave()
            self.updateFileTitle()

        @self.closeButton.mhEvent
        def onClicked(event):
            if self.scene.unsaved:
                G.app.prompt(
                    'Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', self.scene.close)
            else:
                self.scene.close()
            self.readScene()

        @self.saveAsButton.mhEvent
        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)
            self.updateFileTitle()

        @self.itemList.mhEvent
        def onClicked(event):
            self.items[self.itemList.getSelectedItem()].showProps()

        @self.addButton.mhEvent
        def onClicked(event):
            self.adder.showProps()
예제 #15
0
    def __init__(self, category):
        guirender.RenderTaskView.__init__(self, category, 'Scene Editor')

        # Declare settings
        G.app.addSetting('Scene_Editor_FileDlgPath', mh.getDataPath('scenes'))

        sceneBox = self.addLeftWidget(gui.GroupBox('Scene'))
        self.fnlbl = sceneBox.addWidget(gui.TextView('<New scene>'))
        self.saveButton = sceneBox.addWidget(gui.Button('Save'), 1, 0)
        self.loadButton = sceneBox.addWidget(gui.Button('Load ...'), 1, 1)
        self.saveAsButton = sceneBox.addWidget(gui.Button('Save As...'), 2, 0)
        self.closeButton = sceneBox.addWidget(gui.Button('Close'), 2, 1)

        itemBox = self.addLeftWidget(gui.GroupBox('Items'))
        self.itemList = itemBox.addWidget(gui.ListView())
        self.itemList.setSizePolicy(
            gui.SizePolicy.Ignored, gui.SizePolicy.Preferred)

        self.propsBox = gui.StackedBox()
        self.addRightWidget(self.propsBox)

        self.addButton = itemBox.addWidget(gui.Button('Add...'))
        self.adder = SceneItemAdder(self)
        self.propsBox.addWidget(self.adder.widget)
        self.activeItem = None

        self._scene = None

        def doLoad():
            filename = mh.getOpenFileName(
                G.app.getSetting('Scene_Editor_FileDlgPath'),
                'MakeHuman scene (*.mhscene);;All files (*.*)')
            if filename:
                G.app.setSetting('Scene_Editor_FileDlgPath', filename)
                self.scene.load(filename)

        def doSave(filename):
            ok = self.scene.save(filename)
            if ok and self._scene.file.path is not None \
                and self._scene.file.path == self.scene.file.path:
                # Refresh MH's current scene if it was modified.
                self._scene.load(self._scene.file.path)

        @self.loadButton.mhEvent
        def onClicked(event):
            if self.scene.file.modified:
                G.app.prompt('Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', doLoad)
            else:
                doLoad()

        @self.saveButton.mhEvent
        def onClicked(event):
            if self.scene.file.path is None:
                self.saveAsButton.callEvent('onClicked', event)
            else:
                doSave(self.scene.file.path)

        @self.closeButton.mhEvent
        def onClicked(event):
            if self.scene.file.modified:
                G.app.prompt('Confirmation',
                    'Your scene is unsaved. Are you sure you want to close it?',
                    'Close', 'Cancel', self.scene.reset)
            else:
                self.scene.reset()

        @self.saveAsButton.mhEvent
        def onClicked(event):
            filename = mh.getSaveFileName(
                G.app.getSetting('Scene_Editor_FileDlgPath'),
                'MakeHuman scene (*.mhscene);;All files (*.*)')
            if filename:
                G.app.setSetting('Scene_Editor_FileDlgPath', filename)
                doSave(filename)

        @self.itemList.mhEvent
        def onClicked(item):
            item.getUserData().showProps()

        @self.addButton.mhEvent
        def onClicked(event):
            self.adder.showProps()
예제 #16
0
    def __init__(self, category, name, label=None, saveName=None, cameraView=None):
        if label is None:
            label = name.capitalize()
        if saveName is None:
            saveName = name

        super(Modifier1TaskView, self).__init__(category, name, label=label)

        self.saveName = saveName
        self.cameraFunc = _getCamFunc(cameraView)

        self.groupBoxes = OrderedDict()
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        self.showMacroStats = False
        self.human = gui3d.app.selectedHuman
        a = [0]
        deltvalue = [100]
        deltva = [0]
        box = self.addLeftWidget(gui.GroupBox(u'体态自动化'))
        self.aButton = box.addWidget(gui.Button(u'体态变化'))

        @self.aButton.mhEvent
        def onClicked(event):
            log.message('start...')
            for slider in self.sliders:
                for valuenum in range(0, 105, 5):
                    valuenums = valuenum / 100.000000
                    slider.update()
                    # log.message(slider.modifier.getValue())
                    # if slider.enabledCondition:
                    # log.message(slider)
                    slider.modifier.setValue(valuenums)
                    # log.message(slider.modifier.getValue())
                    sli = modifierslider.ModifierSlider(slider.modifier)
                    value = slider.modifier.getValue()
                    valuesli = sli.getValue()
                    # sli.onChanging(slider.modifier.getValue())
                    action = humanmodifier.ModifierAction(slider.modifier, value, valuesli, sli.update)
                    log.message(str(valuesli))
                    log.message(str(value))
                    if valuesli != value:
                        G.app.do(action)
                    else:
                        action.do()

                    filenameImage = fileAotupicture + '/' + str(time.strftime("%Y-%m-%d_%H.%M.%S")) + '.png'
                    filenameIma = fileAotupicture + '/' + str(time.strftime("%Y-%m-%d_%H.%M.%S")) + '.png'
                    filenameIma1 = fileAotupicture + '/result' + str(time.strftime("%Y-%m-%d_%H.%M.%S")), '.png'
                    width = G.windowWidth;
                    height = G.windowHeight;
                    width1 = width - 3;
                    height1 = height - 3;
                    # log.message(filenameImage)
                    mh.grabScreen(0, 0, width, height, filenameImage)
                    img = cv2.imread(filenameImage)
                    height1, width1 = img.shape[:2]
                    # print height,width
                    for i in range(height1):
                        for j in range(width1):
                            r, b, g = img[i][j]
                            rb = abs(r - b)
                            rg = abs(r - g)
                            bg = abs(b - g)
                            if rb < 10 and rg < 10 and bg < 10:
                                img[i][j] = [0, 0, 0]
                            else:
                                img[i][j] = [255, 255, 255]

                    imsave = normalize.Normalize(img)
                    cv2.imwrite(filenameIma, imsave)
                    # cv2.imshow("img",imsave)
                    # cv2.waitKey(10)
                    delt = onpicture()
                    log.message(str(delt))
                    if delt <= deltvalue[0]:
                        deltvalue[0] = delt
                        deltva[0] = valuenums

                num = deltva[0] * 20 + 1
                result = cv2.imread(fileResult + str(num) + '.png')
                cv2.imshow("Result", result)
                cv2.waitKey(0)
                log.message(deltvalue)
                log.message(num)

            slider.modifier.setValue(valuenums)
            # log.message(slider.modifier.getValue())
            sli = modifierslider.ModifierSlider(slider.modifier)
            value = slider.modifier.getValue()
            valuesli = sli.getValue()
            # sli.onChanging(slider.modifier.getValue())
            action = humanmodifier.ModifierAction(slider.modifier, value, valuesli, sli.update)
            G.app.do(action)
            mh.grabScreen(0, 0, width, height, filenameImage)
            imgw = cv2.imread(filenameImage)
            height1, width1 = imgw.shape[:2]
            # print height,width
            for i in range(height1):
                for j in range(width1):
                    r, b, g = imgw[i][j]
                    rb = abs(r - b)
                    rg = abs(r - g)
                    bg = abs(b - g)
                    if rb < 10 and rg < 10 and bg < 10:
                        imgw[i][j] = [0, 0, 0]
                    else:
                        imgw[i][j] = [255, 255, 255]

            imsavew = normalize.Normalize(imgw)
            cv2.imwrite(filenameIma1, imsavew)
            # sli.resetValue()
            # syncSliders()
            # slider.modifier.human
            # enabled = getattr(slider.modifier.human, slider.enabledCondition)()
            # slider.setEnabled(str(2))
            # log.message(str(enabled))

        def grabMyScreen(x, y, width, height, filename=None, productionRender=False):
            if width <= 0 or height <= 0:
                raise RuntimeError("width or height is 0")

            log.debug('grabScreen: %d %d %d %d', x, y, width, height)
            # Draw before grabbing, to make sure we grab a rendering and not a picking buffer
            glmodule.draw(productionRender)
            sx0 = x
            sy0 = G.windowHeight - y - height
            sx1 = sx0 + width
            sy1 = sy0 + height
            sx0 = max(sx0, 0)
            sx1 = min(sx1, G.windowWidth)
            sy0 = max(sy0, 0)
            sy1 = min(sy1, G.windowHeight)
            rwidth = sx1 - sx0
            rwidth -= rwidth % 4
            sx1 = sx0 + rwidth
            rheight = sy1 - sy0
            surface = np.empty((rheight, rwidth, 3), dtype=np.uint8)
            log.debug('glReadPixels: %d %d %d %d', sx0, sy0, rwidth, rheight)
            glmodule.glReadPixels(sx0, sy0, rwidth, rheight, GL_RGB, GL_UNSIGNED_BYTE, surface)
            if width != rwidth or height != rheight:
                surf = np.zeros((height, width, 3), dtype=np.uint8) + 127
                surf[...] = surface[:1, :1, :]
                dx0 = (width - rwidth) / 2
                dy0 = (height - rheight) / 2
                dx1 = dx0 + rwidth
                dy1 = dy0 + rheight
                surf[dy0:dy1, dx0:dx1] = surface
                surface = surf

            surface = np.ascontiguousarray(surface[::-1, :, :])
            # surface = Image(data = surface)
            return surface

        def onpicture():
            # filenameImage='F:/Auto3DImage/'+str(time.strftime("%Y-%m-%d_%H.%M.%S"))+'.png'
            # filenameIma='F:/Auto3DImage/'+str(time.strftime("%Y-%m-%d_%H.%M.%S"))+'.png'
            width = G.windowWidth;
            height = G.windowHeight;
            width = width - 3;
            height = height - 3;
            # log.message(filenameImage)
            # mh.grabScreen(0,0,width,height,filenameImage)
            img = grabMyScreen(0, 0, width, height)
            # log.message(str(imgs))
            # img=cv2.imread(filenameImage)
            height, width = img.shape[:2]
            # print height,width
            for i in range(height):
                for j in range(width):
                    r, b, g = img[i][j]
                    rb = abs(r - b)
                    rg = abs(r - g)
                    bg = abs(b - g)
                    if rb < 10 and rg < 10 and bg < 10:
                        img[i][j] = [0, 0, 0]
                    else:
                        img[i][j] = [255, 255, 255]



                        # cv2.imwrite(filenameIma,img)
            imsave = normalize.Normalize(img)
            imnew= cv2.imread(filepicture)
            delt = findcontours.GetDeltValue(imsave, imnew)
            return delt
예제 #17
0
    def __init__(self,
                 category,
                 name,
                 label=None,
                 saveName=None,
                 cameraView=None):
        if label is None:
            label = name.capitalize()
        if saveName is None:
            saveName = name

        super(Modifier1TaskView, self).__init__(category, name, label=label)

        self.saveName = saveName
        self.cameraFunc = _getCamFunc(cameraView)

        self.groupBoxes = OrderedDict()
        self.radioButtons = []
        self.sliders = []
        self.modifiers = {}

        self.categoryBox = self.addRightWidget(gui.GroupBox('Category'))
        self.groupBox = self.addLeftWidget(gui.StackedBox())

        self.showMacroStats = False
        self.human = gui3d.app.selectedHuman
        a = [0]
        deltvalue = [100]
        deltva = [0]
        box = self.addLeftWidget(gui.GroupBox(u'体型自动化'))
        self.aButton = box.addWidget(gui.Button(u'体型搜索'))
        self.bButton = box.addWidget(gui.Button(u'Test'))

        @self.bButton.mhEvent
        def onClicked(event):
            #img=cv2.imread('/home/smith/PycharmProjects/AutoMakeHuman/src/7_auto_human_body/data/MyAutoData/picture.png')
            #cv2.imshow("img", img)
            #cv2.waitKey(0)
            slider = self.sliders[0]
            slider.modifier.setValue(1)
            sli = modifierslider.ModifierSlider(slider.modifier)
            value = slider.modifier.getValue()
            valuesli = sli.getValue()
            # sli.onChanging(slider.modifier.getValue())
            action = humanmodifier.ModifierAction(slider.modifier, value,
                                                  valuesli, sli.update)
            G.app.do(action)

        def worker(sliders, stopSearch):
            log.message('start...')
            for slider in sliders:
                if (stopSearch):
                    stopSearch = False
                    break
                value = 0
                for valuenum in range(0, 101, 1):
                    if (stopSearch):
                        stopSearch = False
                        break
                    valuenums = valuenum / 100.000000
                    slider.update()
                    slider.modifier.setValue(valuenums)
                    log.message('slider modifiy value:' + str(valuenums))
                    sli = modifierslider.ModifierSlider(slider.modifier)
                    # value = slider.modifier.getValue()
                    valuesli = sli.getValue()
                    # #sli.onChanging(slider.modifier.getValue())
                    action = humanmodifier.ModifierAction(
                        slider.modifier, value, valuesli, sli.update)
                    log.message('before value:' + str(value))
                    # 以下更新场景代码均无效
                    if valuesli != value:
                        G.app.do(action)
                    else:
                        action.do()
                    #gui3d.app.do(action)
                    #G.app.do(action)
                    #G.app.redraw()
                    log.message('update views')
                    value = valuesli
                    filenameImage = fileAotupicture + '/' + str(
                        time.strftime("%Y-%m-%d_%H.%M.%S")) + '.png'
                    filenameIma = fileAotupicture + '/' + str(
                        time.strftime("%Y-%m-%d_%H.%M.%S")) + '.png'
                    filenameIma1 = fileAotupicture + '/result' + str(
                        time.strftime("%Y-%m-%d_%H.%M.%S")), '.png'
                    width = G.windowWidth
                    height = G.windowHeight
                    width1 = width - 3
                    height1 = height - 3
                    log.message('grab screen')
                    mh.grabScreen(0, 0, width, height, filenameImage)
                    img = cv2.imread(filenameImage)
                    height1, width1 = img.shape[:2]
                    # print height,width
                    for i in range(height1):
                        for j in range(width1):
                            r, b, g = img[i][j]
                            rb = abs(r - b)
                            rg = abs(r - g)
                            bg = abs(b - g)
                            if rb < 10 and rg < 10 and bg < 10:
                                img[i][j] = [0, 0, 0]
                            else:
                                img[i][j] = [255, 255, 255]
                    imsave = normalize.Normalize(img)
                    log.message('show normalize image')
                    try:
                        log.message('cv2 start')
                        cv2.imwrite(filenameIma, imsave)
                        # log.message('cv2 imwrite:'+filenameIma)
                        # newimg=cv2.imread(filenameIma)
                        # log.message('cv2 imread')
                        # cv2.imshow("img", imsave)
                        # log.message('cv2 imshow')
                        ## 60与电脑的刷新频率有关,如果<60刷新频率跟不上,则不会显示图像
                        # cv2.waitKey(60)
                        # cv2.destroyAllWindows()
                        # delt = onpicture()
                        imnew = cv2.imread(filepicture)
                        delt = findcontours.GetDeltValue(imsave, imnew)
                        log.message('delt value:' + str(delt))
                        if delt <= deltvalue[0]:
                            deltvalue[0] = delt
                            deltva[0] = valuenums
                    except Exception, e:
                        log.message(e)
                num = deltva[0] * 20 + 1
                # result = cv2.imread(fileResult + str(num) + '.png')
                # cv2.imshow("Result", result)
                # cv2.waitKey(0)
                log.message(deltvalue)
                log.message(num)

            slider.modifier.setValue(valuenums)
            # log.message(slider.modifier.getValue())
            sli = modifierslider.ModifierSlider(slider.modifier)
            value = slider.modifier.getValue()
            valuesli = sli.getValue()
            # sli.onChanging(slider.modifier.getValue())
            action = humanmodifier.ModifierAction(slider.modifier, value,
                                                  valuesli, sli.update)
            G.app.do(action)
            mh.grabScreen(0, 0, width, height, filenameImage)
            imgw = cv2.imread(filenameImage)
            height1, width1 = imgw.shape[:2]
            # print height,width
            for i in range(height1):
                for j in range(width1):
                    r, b, g = imgw[i][j]
                    rb = abs(r - b)
                    rg = abs(r - g)
                    bg = abs(b - g)
                    if rb < 10 and rg < 10 and bg < 10:
                        imgw[i][j] = [0, 0, 0]
                    else:
                        imgw[i][j] = [255, 255, 255]
            imsavew = normalize.Normalize(imgw)
            cv2.imwrite(filenameIma1, imsavew)
            # sli.resetValue()
            # syncSliders()
            # slider.modifier.human
            # enabled = getattr(slider.modifier.human, slider.enabledCondition)()
            # slider.setEnabled(str(2))
            # log.message(str(enabled))
            return