Beispiel #1
0
def apply_view(panel, **options):
    """Apply options to panel"""

    camera = cmds.modelPanel(panel, camera=True, query=True)

    # Display options
    display_options = options.get('display_options', {})
    for key, value in display_options.items():
        if key in _DisplayOptionsRGB:
            cmds.displayRGBColor(key, *value)
        else:
            cmds.displayPref(**{key: value})

    # Camera options
    camera_options = options.get('camera_options', {})
    for key, value in camera_options.items():
        cmds.setAttr(f'{camera}.{key}', value)

    # Viewport options
    viewport_options = options.get('viewport_options', {})
    for key, value in viewport_options.items():
        cmds.modelEditor(panel, edit=True, **{key: value})

    viewport2_options = options.get('viewport2_options', {})
    for key, value in viewport2_options.items():
        attr = f'hardwareRenderingGlobals.{key}'
        cmds.setAttr(attr, value)
def _applied_display_options(options):
    """Context manager for setting background color display options."""

    options = dict(DisplayOptions, **(options or {}))

    colors = ['background', 'backgroundTop', 'backgroundBottom']
    preferences = ['displayGradient']

    # Store current settings
    original = {}
    for color in colors:
        original[color] = cmds.displayRGBColor(color, query=True) or []

    for preference in preferences:
        original[preference] = cmds.displayPref(query=True,
                                                **{preference: True})

    # Apply settings
    for color in colors:
        value = options[color]
        cmds.displayRGBColor(color, *value)

    for preference in preferences:
        value = options[preference]
        cmds.displayPref(**{preference: value})

    try:
        yield

    finally:
        # Restore original settings
        for color in colors:
            cmds.displayRGBColor(color, *original[color])
        for preference in preferences:
            cmds.displayPref(**{preference: original[preference]})
Beispiel #3
0
def _applied_display_options(options):
    """Context manager for setting background color display options."""
    from maya import cmds

    options = options or DisplayOptions()

    colors = ['background', 'backgroundTop', 'backgroundBottom']
    prefs = ['displayGradient']

    # store current settings
    original = {}
    for clr in colors:
        original[clr] = cmds.displayRGBColor(clr, query=True)
    for pref in prefs:
        original[pref] = cmds.displayPref(query=True, **{pref: True})

    # apply settings of options
    for clr in colors:
        value = getattr(options, clr)
        cmds.displayRGBColor(clr, *value)
    for pref in prefs:
        value = getattr(options, pref)
        cmds.displayPref(**{pref: value})

    yield

    # restore original settings
    for clr in colors:
        cmds.displayRGBColor(clr, *original[clr])
    for pref in prefs:
        cmds.displayPref(**{pref: original[pref]})
Beispiel #4
0
def apply_view(panel, **options):
    """Apply options to panel"""

    camera = cmds.modelPanel(panel, camera=True, query=True)

    # Display options
    display_options = options.get("display_options", {})
    for key, value in display_options.iteritems():
        if key in _DisplayOptionsRGB:
            cmds.displayRGBColor(key, *value)
        else:
            cmds.displayPref(**{key: value})

    # Camera options
    camera_options = options.get("camera_options", {})
    for key, value in camera_options.iteritems():
        cmds.setAttr("{0}.{1}".format(camera, key), value)

    # Viewport options
    viewport_options = options.get("viewport_options", {})
    for key, value in viewport_options.iteritems():
        cmds.modelEditor(panel, edit=True, **{key: value})

    viewport2_options = options.get("viewport2_options", {})
    for key, value in viewport2_options.iteritems():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        cmds.setAttr(attr, value)
Beispiel #5
0
def _applied_display_options(options):
    """Context manager for setting background color display options."""

    options = options or DisplayOptions()

    colors = ['background', 'backgroundTop', 'backgroundBottom']
    preferences = ['displayGradient']

    # Store current settings
    original = {}
    for color in colors:
        original[color] = cmds.displayRGBColor(color, query=True) or []

    for preference in preferences:
        original[preference] = cmds.displayPref(query=True, **{preference: True})

    # Apply settings
    for color in colors:
        value = getattr(options, color)
        cmds.displayRGBColor(color, *value)

    for preference in preferences:
        value = getattr(options, preference)
        cmds.displayPref(**{preference: value})

    try:
        yield

    finally:
        # Restore original settings
        for color in colors:
            cmds.displayRGBColor(color, *original[color])
        for preference in preferences:
            cmds.displayPref(**{preference: original[preference]})
def apply_view(panel, **options):
    """Apply options to panel"""

    camera = cmds.modelPanel(panel, camera=True, query=True)

    # Display options
    display_options = options.get("display_options", {})
    for key, value in display_options.iteritems():
        if key in _DisplayOptionsRGB:
            cmds.displayRGBColor(key, *value)
        else:
            cmds.displayPref(**{key: value})

    # Camera options
    camera_options = options.get("camera_options", {})
    for key, value in camera_options.iteritems():
        cmds.setAttr("{0}.{1}".format(camera, key), value)

    # Viewport options
    viewport_options = options.get("viewport_options", {})
    for key, value in viewport_options.iteritems():
        cmds.modelEditor(panel, edit=True, **{key: value})

    viewport2_options = options.get("viewport2_options", {})
    for key, value in viewport2_options.iteritems():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        cmds.setAttr(attr, value)
Beispiel #7
0
    def restoreSettings(self):
        '''
        restore all UI settings
        '''
        cmds.autoKeyframe(state=self.dataStore['autoKey'])

        # timeline management
        cmds.currentTime(self.dataStore['currentTime'])
        cmds.playbackOptions(min=self.dataStore['minTime'])
        cmds.playbackOptions(max=self.dataStore['maxTime'])
        cmds.playbackOptions(ast=self.dataStore['startTime'])
        cmds.playbackOptions(aet=self.dataStore['endTime'])
        cmds.playbackOptions(ps=self.dataStore['playSpeed'])
        cmds.playbackOptions(loop=self.dataStore['playLoop'])

        # unit management
        cmds.currentUnit(time=self.dataStore['timeUnit'])
        cmds.currentUnit(linear=self.dataStore['sceneUnits'])
        if not cmds.upAxis(axis=True, q=True) == self.dataStore['upAxis']:
            cmds.upAxis(axis=self.dataStore['upAxis'])

        log.debug('Restored PlayBack / Timeline setup')

        # viewport colors
        cmds.displayPref(displayGradient=self.dataStore['displayGradient'])
        cmds.displayRGBColor(resetToSaved=True)

        # objects colors
        cmds.displayColor("curve", self.dataStore['curvecolor'], dormant=True)

        # panel management
        for panel, data in self.dataStore['panelStore'].items():
            try:
                cmdString = data['settings'].replace('$editorName', panel)
                mel.eval(cmdString)
                log.debug("Restored Panel Settings Data >> %s" % panel)
                mel.eval('lookThroughModelPanel("%s","%s")' % (data['activeCam'], panel))
                log.debug("Restored Panel Active Camera Data >> %s >> cam : %s" % (panel, data['activeCam']))
            except:
                log.debug("Failed to fully Restore ActiveCamera Data >> %s >> cam : %s" % (panel, data['activeCam']))

        # camera management
        for cam, settings in self.dataStore['cameraTransforms'].items():
            try:
                cmds.setAttr('%s.translate' % cam, settings[0][0][0], settings[0][0][1], settings[0][0][2])
                cmds.setAttr('%s.rotate' % cam, settings[1][0][0], settings[1][0][1], settings[1][0][2])
                cmds.setAttr('%s.scale' % cam, settings[2][0][0], settings[2][0][1], settings[2][0][2])
                log.debug('Restored Default Camera Transform Data : % s' % cam)
            except:
                log.debug("Failed to fully Restore Default Camera Transform Data : % s" % cam)

        # sound management
        if self.dataStore['displaySound']:
            cmds.timeControl(self.gPlayBackSlider, e=True, ds=1, sound=self.dataStore['activeSound'])
            log.debug('Restored Audio setup')
        else:
            cmds.timeControl(self.gPlayBackSlider, e=True, ds=0)
        log.debug('Scene Restored fully')
        return True
    def restoreSettings(self):
        '''
        restore all UI settings
        '''
        cmds.autoKeyframe(state=self.dataStore['autoKey'])

        # timeline management
        cmds.currentTime(self.dataStore['currentTime'])
        cmds.playbackOptions(min=self.dataStore['minTime'])
        cmds.playbackOptions(max=self.dataStore['maxTime'])
        cmds.playbackOptions(ast=self.dataStore['startTime'])
        cmds.playbackOptions(aet=self.dataStore['endTime'])
        cmds.playbackOptions(ps=self.dataStore['playSpeed'])
        cmds.playbackOptions(loop=self.dataStore['playLoop'])

        # unit management
        cmds.currentUnit(time=self.dataStore['timeUnit'])
        cmds.currentUnit(linear=self.dataStore['sceneUnits'])
        if not cmds.upAxis(axis=True, q=True) == self.dataStore['upAxis']:
            cmds.upAxis(axis=self.dataStore['upAxis'])

        log.debug('Restored PlayBack / Timeline setup')

        # viewport colors
        cmds.displayPref(displayGradient=self.dataStore['displayGradient'])
        cmds.displayRGBColor(resetToSaved=True)

        # objects colors
        cmds.displayColor("curve", self.dataStore['curvecolor'], dormant=True)

        # panel management
        for panel, data in self.dataStore['panelStore'].items():
            try:
                cmdString = data['settings'].replace('$editorName', panel)
                mel.eval(cmdString)
                log.debug("Restored Panel Settings Data >> %s" % panel)
                mel.eval('lookThroughModelPanel("%s","%s")' % (data['activeCam'], panel))
                log.debug("Restored Panel Active Camera Data >> %s >> cam : %s" % (panel, data['activeCam']))
            except:
                log.debug("Failed to fully Restore ActiveCamera Data >> %s >> cam : %s" % (panel, data['activeCam']))

        # camera management
        for cam, settings in self.dataStore['cameraTransforms'].items():
            try:
                cmds.setAttr('%s.translate' % cam, settings[0][0][0], settings[0][0][1], settings[0][0][2])
                cmds.setAttr('%s.rotate' % cam, settings[1][0][0], settings[1][0][1], settings[1][0][2])
                cmds.setAttr('%s.scale' % cam, settings[2][0][0], settings[2][0][1], settings[2][0][2])
                log.debug('Restored Default Camera Transform Data : % s' % cam)
            except:
                log.debug("Failed to fully Restore Default Camera Transform Data : % s" % cam)

        # sound management
        if self.dataStore['displaySound']:
            cmds.timeControl(self.gPlayBackSlider, e=True, ds=1, sound=self.dataStore['activeSound'])
            log.debug('Restored Audio setup')
        else:
            cmds.timeControl(self.gPlayBackSlider, e=True, ds=0)
        log.debug('Scene Restored fully')
        return True
Beispiel #9
0
 def doubleCleanUp(self):
     cmds.displayPref(displayGradient=1)
     for i in [
             'PanormaPlayBlastConvertingWindow',
             'PanormaPlayBlastRecordingWindow', 'showPanoramaWindow'
     ]:
         if cmds.window(i, q=1, exists=1):
             cmds.deleteUI(i)
     newNodes = list(set(cmds.ls()) - set(self.allOrigNodes))
     for i in newNodes[::-1]:
         try:
             cmds.delete(i)
         except:
             pass
Beispiel #10
0
 def _resize_font(self):
     '''重缩放maya字体大小
     '''
     scalemode = cmds.mayaDpiSetting(q = 1,mode = 1)
     if scalemode == 0:
         print (u"error:当前ui缩放模式不正确")
         return
     else:
         hudScale = cmds.mayaDpiSetting(q = 1,scaleValue = 1)
         font_size = int(15/hudScale)
         current_font_size= cmds.displayPref(q = 1,dfs = 1)
         if font_size != current_font_size:
             if font_size == 15:
                 cmds.displayPref(dfs = 16)
             else:
                 cmds.displayPref(dfs = font_size)
Beispiel #11
0
def parse_active_view():
    """Parse active view for settings"""
    panel = cmds.getPanel(withFocus=True)
    assert "model" in panel, "No active viewport"
    camera = cmds.modelPanel(panel, query=True, camera=True)
    camera_shape = cmds.listRelatives(camera, shapes=True)[0]

    return {
        "camera": camera,
        "width": cmds.getAttr("defaultResolution.width"),
        "height": cmds.getAttr("defaultResolution.height"),
        "camera_options": type("CameraOptions", (object, CameraOptions,), {
            "displayFilmGate": cmds.getAttr(camera_shape + ".displayFilmGate"),
            "displayResolution": cmds.getAttr(camera_shape + ".displayResolution"),
            "displaySafeAction": cmds.getAttr(camera_shape + ".displaySafeAction"),
        }),
        "viewport_options": type("ViewportOptions", (object, ViewportOptions,), {
            "useDefaultMaterial": cmds.modelEditor(panel, query=True, useDefaultMaterial=True),
            "wireframeOnShaded": cmds.modelEditor(panel, query=True, wireframeOnShaded=True),
            "displayAppearance": cmds.modelEditor(panel, query=True, displayAppearance=True),
            "displayTextures": cmds.modelEditor(panel, query=True, displayTextures=True),
            "displayLights": cmds.modelEditor(panel, query=True, displayLights=True),
            "shadows": cmds.modelEditor(panel, query=True, shadows=True),
            "xray": cmds.modelEditor(panel, query=True, xray=True),
        }),
        "display_options": type("DisplayOptions", (object, DisplayOptions,), {
            "background": cmds.displayRGBColor('background', q=True),
            "backgroundTop": cmds.displayRGBColor('backgroundTop', q=True),
            "backgroundBottom": cmds.displayRGBColor('backgroundBottom', q=True),
            'displayGradient': cmds.displayPref(dgr=True, q=True),
        }),
    }
Beispiel #12
0
    def endShow(self):
        cmds.displayPref(displayGradient=1)
        if cmds.window('PanormaPlayBlastConvertingWindow', q=1, exists=1):
            cmds.deleteUI('PanormaPlayBlastConvertingWindow')
        tmpWindow = cmds.window('PanormaPlayBlastConvertingWindow',
                                w=300,
                                h=5,
                                title='Converting Video')
        cmds.showWindow(tmpWindow)
        inSeq = self.imagePath + '/tmp/latlong_' + self.imageName + '_%04d.png'

        vFrames = self.maxTime - self.minTime + 1
        outVideo = self.imagePath + '/' + self.imageName + '.mov'
        aa = (
            '%s/Maya/Python/Mili/Module/utilties/ffmpeg/ffmpeg.exe -i "%s" %s -vframes %s -vcodec mjpeg -x264opts keyint=1 -y "%s"'
            % (os.environ['PIPELINE_PATH'], inSeq, self.soundCmdStr, vFrames,
               outVideo))
        print aa
        os.popen(aa)

        if self.playMovie:
            command = 'start "" "D:/Projects/_mili_common_push/pyUpload/panoViewer.exe" "%s"' % (
                outVideo)
            print command
            os.popen(command)

        if 0:
            outVideo = self.imagePath + '/' + self.imageName + '.mp4'
            aa = (
                '%s/Maya/Python/Mili/Module/utilties/ffmpeg/ffmpeg.exe -i "%s" %s -vframes %i -vcodec mpeg4 -x264opts keyint=1 -y "%s"'
                % (os.environ['PIPELINE_PATH'], inSeq, self.soundCmdStr,
                   vFrames, outVideo))
            print aa
            os.popen(aa)

        for i in self.garbages:
            if os.path.isfile(i):
                print 'remove:', i
                try:
                    os.remove(i)
                except:
                    pass
        print 'Done!'
        #shutil.rmtree(self.imagePath+'/tmp/')
        #~ cmds.confirmDialog(title='JobDone', message=u'全景视频已生成\n请去相应路径查看', button='OK')
        cmds.deleteUI(tmpWindow)
Beispiel #13
0
def parse_view(panel):
    """Parse the scene, panel and camera for their current settings

    Example:
        >>> parse_view("modelPanel1")

    Arguments:
        panel (str): Name of modelPanel

    """

    camera = cmds.modelPanel(panel, query=True, camera=True)

    # Display options
    display_options = {}
    for key in DisplayOptions:
        if key in _DisplayOptionsRGB:
            display_options[key] = cmds.displayRGBColor(key, query=True)
        else:
            display_options[key] = cmds.displayPref(query=True, **{key: True})

    # Camera options
    camera_options = {}
    for key in CameraOptions:
        camera_options[key] = cmds.getAttr("{0}.{1}".format(camera, key))

    # Viewport options
    viewport_options = {}

    # capture plugin display filters first to ensure we never override
    # built-in arguments if ever possible a plugin has similarly named
    # plugin display filters (which it shouldn't!)
    plugins = cmds.pluginDisplayFilter(query=True, listFilters=True)
    for plugin in plugins:
        plugin = str(plugin)  # unicode->str for simplicity of the dict
        state = cmds.modelEditor(panel, query=True, queryPluginObjects=plugin)
        viewport_options[plugin] = state

    for key in ViewportOptions:
        viewport_options[key] = cmds.modelEditor(panel,
                                                 query=True,
                                                 **{key: True})

    viewport2_options = {}
    for key in Viewport2Options.keys():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        try:
            viewport2_options[key] = cmds.getAttr(attr)
        except ValueError:
            continue

    return {
        "camera": camera,
        "display_options": display_options,
        "camera_options": camera_options,
        "viewport_options": viewport_options,
        "viewport2_options": viewport2_options
    }
Beispiel #14
0
def parse_view(panel):
    """Parse the scene, panel and camera for their current settings

    Example:
        >>> parse_view("modelPanel1")

    Arguments:
        panel (str): Name of modelPanel

    """

    camera = cmds.modelPanel(panel, query=True, camera=True)

    # Display options
    display_options = {}
    for key in DisplayOptions:
        if key in _DisplayOptionsRGB:
            display_options[key] = cmds.displayRGBColor(key, query=True)
        else:
            display_options[key] = cmds.displayPref(query=True, **{key: True})

    # Camera options
    camera_options = {}
    for key in CameraOptions:
        camera_options[key] = cmds.getAttr("{0}.{1}".format(camera, key))

    # Viewport options
    viewport_options = {}

    # capture plugin display filters first to ensure we never override
    # built-in arguments if ever possible a plugin has similarly named
    # plugin display filters (which it shouldn't!)
    plugins = cmds.pluginDisplayFilter(query=True, listFilters=True)
    for plugin in plugins:
        plugin = str(plugin)  # unicode->str for simplicity of the dict
        state = cmds.modelEditor(panel, query=True, queryPluginObjects=plugin)
        viewport_options[plugin] = state

    for key in ViewportOptions:
        viewport_options[key] = cmds.modelEditor(
            panel, query=True, **{key: True})

    viewport2_options = {}
    for key in Viewport2Options.keys():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        try:
            viewport2_options[key] = cmds.getAttr(attr)
        except ValueError:
            continue

    return {
        "camera": camera,
        "display_options": display_options,
        "camera_options": camera_options,
        "viewport_options": viewport_options,
        "viewport2_options": viewport2_options
    }
Beispiel #15
0
def cycleWOS():
    '''
    cycles wireframe on: all > selected > none
    '''
    mPanel = getActiveModelPanel()
    dPref = mc.displayPref(q=1, wsa=1)
    # if 'wsa' or wireframeOnShaded is off goto 1: all
    if dPref == 'none' or dPref == 'reduced':
        mc.displayPref(wsa='full')
        for p in mPanel:
            mc.modelEditor(p, e=1, wos=1)
    elif dPref == 'full':
        #NTH: i don't query "all" modelPanels but in my case there is never more that 1
        if mc.modelEditor(mPanel[0], q=1, wos=1):
            for p in mPanel:
                mc.modelEditor(p, e=1, wos=0)
        else:
            mc.displayPref(wsa='none')
Beispiel #16
0
def active_view_snapshot(*args):
    capture.snap(clipboard=True,
                 display_options={
                     "displayGradient":
                     cmds.displayPref(query=True, displayGradient=True),
                     "background":
                     cmds.displayRGBColor("background", query=True),
                     "backgroundTop":
                     cmds.displayRGBColor("backgroundTop", query=True),
                     "backgroundBottom":
                     cmds.displayRGBColor("backgroundBottom", query=True),
                 })
Beispiel #17
0
    def storeSettings(self):
        '''
        main work function, store all UI settings
        '''
        self.dataStore['autoKey'] = cmds.autoKeyframe(query=True, state=True)

        # timeline management
        self.dataStore['currentTime'] = cmds.currentTime(q=True)
        self.dataStore['minTime'] = cmds.playbackOptions(q=True, min=True)
        self.dataStore['maxTime'] = cmds.playbackOptions(q=True, max=True)
        self.dataStore['startTime'] = cmds.playbackOptions(q=True, ast=True)
        self.dataStore['endTime'] = cmds.playbackOptions(q=True, aet=True)
        self.dataStore['playSpeed'] = cmds.playbackOptions(query=True, playbackSpeed=True)
        self.dataStore['playLoop'] = cmds.playbackOptions(query=True, loop=True)

        # unit management
        self.dataStore['timeUnit'] = cmds.currentUnit(q=True, fullName=True, time=True)
        self.dataStore['sceneUnits'] = cmds.currentUnit(q=True, fullName=True, linear=True)
        self.dataStore['upAxis'] = cmds.upAxis(q=True, axis=True)

        # viewport colors
        self.dataStore['displayGradient'] = cmds.displayPref(q=True, displayGradient=True)

        # objects colors
        self.dataStore['curvecolor'] = cmds.displayColor("curve", q=True, dormant=True)

        # panel management
        self.dataStore['panelStore'] = {}
        for panel in ['modelPanel1', 'modelPanel2', 'modelPanel3', 'modelPanel4']:
            if not cmds.modelPanel(panel, q=True, exists=True):
                continue
            self.dataStore['panelStore'][panel] = {}
            self.dataStore['panelStore'][panel]['settings'] = cmds.modelEditor(panel, q=True, sts=True)
            activeCam = cmds.modelPanel(panel, q=True, camera=True)
            if not cmds.nodeType(activeCam) == 'camera':
                activeCam = cmds.listRelatives(activeCam, f=True)[0]
            self.dataStore['panelStore'][panel]['activeCam'] = activeCam

        # camera management
        # TODO : store the camera field of view etc also
        self.dataStore['cameraTransforms'] = {}
        for cam in ['persp', 'top', 'side', 'front']:
            try:
                self.dataStore['cameraTransforms'][cam] = [cmds.getAttr('%s.translate' % cam),
                                                     cmds.getAttr('%s.rotate' % cam),
                                                     cmds.getAttr('%s.scale' % cam)]
            except:
                log.debug("Camera doesn't exists : %s" % cam)

        # sound management
        self.dataStore['activeSound'] = cmds.timeControl(self.gPlayBackSlider, q=True, s=1)
        self.dataStore['displaySound'] = cmds.timeControl(self.gPlayBackSlider, q=True, ds=1)
Beispiel #18
0
    def storeSettings(self):
        '''
        main work function, store all UI settings
        '''
        self.dataStore['autoKey'] = cmds.autoKeyframe(query=True, state=True)

        # timeline management
        self.dataStore['currentTime'] = cmds.currentTime(q=True)
        self.dataStore['minTime'] = cmds.playbackOptions(q=True, min=True)
        self.dataStore['maxTime'] = cmds.playbackOptions(q=True, max=True)
        self.dataStore['startTime'] = cmds.playbackOptions(q=True, ast=True)
        self.dataStore['endTime'] = cmds.playbackOptions(q=True, aet=True)
        self.dataStore['playSpeed'] = cmds.playbackOptions(query=True, playbackSpeed=True)
        self.dataStore['playLoop'] = cmds.playbackOptions(query=True, loop=True)

        # unit management
        self.dataStore['timeUnit'] = cmds.currentUnit(q=True, fullName=True, time=True)
        self.dataStore['sceneUnits'] = cmds.currentUnit(q=True, fullName=True, linear=True)
        self.dataStore['upAxis'] = cmds.upAxis(q=True, axis=True)

        # viewport colors
        self.dataStore['displayGradient'] = cmds.displayPref(q=True, displayGradient=True)

        # objects colors
        self.dataStore['curvecolor'] = cmds.displayColor("curve", q=True, dormant=True)

        # panel management
        self.dataStore['panelStore'] = {}
        for panel in ['modelPanel1', 'modelPanel2', 'modelPanel3', 'modelPanel4']:
            if not cmds.modelPanel(panel, q=True, exists=True):
                continue
            self.dataStore['panelStore'][panel] = {}
            self.dataStore['panelStore'][panel]['settings'] = cmds.modelEditor(panel, q=True, sts=True)
            activeCam = cmds.modelPanel(panel, q=True, camera=True)
            if not cmds.nodeType(activeCam) == 'camera':
                activeCam = cmds.listRelatives(activeCam, f=True)[0]
            self.dataStore['panelStore'][panel]['activeCam'] = activeCam

        # camera management
        # TODO : store the camera field of view etc also
        self.dataStore['cameraTransforms'] = {}
        for cam in ['persp', 'top', 'side', 'front']:
            try:
                self.dataStore['cameraTransforms'][cam] = [cmds.getAttr('%s.translate' % cam),
                                                     cmds.getAttr('%s.rotate' % cam),
                                                     cmds.getAttr('%s.scale' % cam)]
            except:
                log.debug("Camera doesn't exists : %s" % cam)

        # sound management
        self.dataStore['activeSound'] = cmds.timeControl(self.gPlayBackSlider, q=True, s=1)
        self.dataStore['displaySound'] = cmds.timeControl(self.gPlayBackSlider, q=True, ds=1)
    def get_outputs(self):
        outputs = {}
        if self.override.isChecked():
            outputs["displayGradient"] = self.display_gradient()
            for label, widget in self._colors.items():
                outputs[label] = widget.color
        else:
            # Parse active color settings
            outputs["displayGradient"] = cmds.displayPref(query=True,
                                                          displayGradient=True)
            for key in COLORS.keys():
                color = cmds.displayRGBColor(key, query=True)
                outputs[key] = color

        return {"display_options": outputs}
def parse_view(panel):
    """Parse the scene, panel and camera for their current settings

    Example:
        >>> parse_view("modelPanel1")

    Arguments:
        panel (str): Name of modelPanel

    """

    camera = cmds.modelPanel(panel, query=True, camera=True)

    # Display options
    display_options = {}
    for key in DisplayOptions:
        if key in _DisplayOptionsRGB:
            display_options[key] = cmds.displayRGBColor(key, query=True)
        else:
            display_options[key] = cmds.displayPref(query=True, **{key: True})

    # Camera options
    camera_options = {}
    for key in CameraOptions:
        camera_options[key] = cmds.getAttr("{0}.{1}".format(camera, key))

    # Viewport options
    viewport_options = {}
    for key in ViewportOptions:
        viewport_options[key] = cmds.modelEditor(panel,
                                                 query=True,
                                                 **{key: True})

    viewport2_options = {}
    for key in Viewport2Options.keys():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        try:
            viewport2_options[key] = cmds.getAttr(attr)
        except ValueError:
            continue

    return {
        "camera": camera,
        "display_options": display_options,
        "camera_options": camera_options,
        "viewport_options": viewport_options,
        "viewport2_options": viewport2_options
    }
Beispiel #21
0
def parse_view(panel):
    """Parse the scene, panel and camera for their current settings

    Example:
        >>> parse_view("modelPanel1")

    Arguments:
        panel (str): Name of modelPanel

    """

    camera = cmds.modelPanel(panel, query=True, camera=True)

    # Display options
    display_options = {}
    for key in DisplayOptions:
        if key in _DisplayOptionsRGB:
            display_options[key] = cmds.displayRGBColor(key, query=True)
        else:
            display_options[key] = cmds.displayPref(query=True, **{key: True})

    # Camera options
    camera_options = {}
    for key in CameraOptions:
        camera_options[key] = cmds.getAttr("{0}.{1}".format(camera, key))

    # Viewport options
    viewport_options = {}
    for key in ViewportOptions:
        viewport_options[key] = cmds.modelEditor(
            panel, query=True, **{key: True})

    viewport2_options = {}
    for key in Viewport2Options.keys():
        attr = "hardwareRenderingGlobals.{0}".format(key)
        try:
            viewport2_options[key] = cmds.getAttr(attr)
        except ValueError:
            continue

    return {
        "camera": camera,
        "display_options": display_options,
        "camera_options": camera_options,
        "viewport_options": viewport_options,
        "viewport2_options": viewport2_options
    }
Beispiel #22
0
    def get_outputs(self):
        """Get the plugin outputs that matches `capture.capture` arguments

        Returns:
            dict: Plugin outputs

        """

        outputs = {}
        if self.override.isChecked():
            outputs["displayGradient"] = self.display_gradient()
            for label, widget in self._colors.items():
                outputs[label] = widget.color
        else:
            # Parse active color settings
            outputs["displayGradient"] = cmds.displayPref(query=True,
                                                          displayGradient=True)
            for key in COLORS.keys():
                color = cmds.displayRGBColor(key, query=True)
                outputs[key] = color

        return {"display_options": outputs}
    def process(self, instance):
        self.log.info("Extracting capture..")
        components = instance.data['ftrackComponents'].copy()
        self.log.debug('Components: {}'.format(components))

        camera = instance[0]

        if 'persp' in camera:
            self.log.info("If you want movie review, create a camera with \
                          '_CAM' suffix")
            return

        format = instance.data('format') or 'qt'
        compression = instance.data('compression') or 'h264'
        off_screen = instance.data('offScreen', False)
        maintain_aspect_ratio = instance.data('maintainAspectRatio', True)

        try:
            preset = capture.parse_active_view()

            if 'show' in instance.data():
                self.log.info("Overriding show: %s" % instance.data['show'])
                for nodetype in instance.data['show']:
                    # self.log.info("Overriding show: %s" % nodetype)
                    if hasattr(preset['viewport_options'], nodetype):
                        setattr(preset['viewport_options'], nodetype, True)
                    else:
                        self.log.warning("Specified node-type in 'show' not "
                                         "recognised: %s" % nodetype)
        except:
            camera_shape = cmds.listRelatives(camera, shapes=True)[0]

            preset = {
                "camera": camera,
                "width": cmds.getAttr("defaultResolution.width"),
                "height": cmds.getAttr("defaultResolution.height"),
                "camera_options": type("CameraOptions", (object, capture.CameraOptions,), {
                    "displayFilmGate": cmds.getAttr(camera_shape + ".displayFilmGate"),
                    "displayResolution": cmds.getAttr(camera_shape + ".displayResolution"),
                    "displaySafeAction": cmds.getAttr(camera_shape + ".displaySafeAction"),
                }),
                "viewport_options": type("ViewportOptions", (object, capture.ViewportOptions,), {
                    "useDefaultMaterial": False,
                    "wireframeOnShaded": False,
                    # "displayAppearance": cmds.modelEditor(panel, query=True, displayAppearance=True),
                    "displayTextures": True,
                    "displayLights": True,
                    "shadows": True,
                }),
                "display_options": type("DisplayOptions", (object, capture.DisplayOptions,), {
                    "background": cmds.displayRGBColor('background', q=True),
                    "backgroundTop": cmds.displayRGBColor('backgroundTop', q=True),
                    "backgroundBottom": cmds.displayRGBColor('backgroundBottom', q=True),
                    'displayGradient': cmds.displayPref(dgr=True, q=True),
                }),
            }


        # Ensure name of camera is valid
        sourcePath = os.path.normpath(instance.context.data('currentFile'))
        path, extension = os.path.splitext(sourcePath)
        path = (path + ".png")

        # Ensure name of camera is valid
        sourcePath = os.path.normpath(instance.context.data('currentFile'))
        path, extension = os.path.splitext(sourcePath)


        if format == 'image':
            # Append sub-directory for image-sequence
            path = os.path.join(path, camera)
        else:
            path = (path + ".mov")

        self.log.info("Outputting to %s" % path)

        with maintained_time():
            output = capture.capture(
                # camera=camera,
                # width=width,
                # height=height,
                filename=path,
                # start_frame=start_frame,
                # end_frame=end_frame,
                format=format,
                viewer=False,
                compression=compression,
                off_screen=off_screen,
                maintain_aspect_ratio=maintain_aspect_ratio,
                overwrite=True,
                quality=80,
                **preset
                )


        instance.data["outputPath_qt"] = output
Beispiel #24
0
    def showPanoramaWindow(self, argCamera):
        #tool`s second UI,this window uesed to be snaped
        #~ if cmds.window('MayaPanoramaPlayBlast', q=1, exists=1):
        #~ cmds.deleteUI('MayaPanoramaPlayBlast')

        if cmds.window('showPanoramaWindow', q=1, exists=1):
            cmds.deleteUI('showPanoramaWindow')
        self.window = cmds.window('showPanoramaWindow',
                                  widthHeight=(1536, 1024),
                                  sizeable=False,
                                  topLeftCorner=(0, 0),
                                  titleBar=False)

        form = cmds.formLayout(width=1536, height=1024)
        editor1 = cmds.modelEditor()
        editor2 = cmds.modelEditor()
        editor3 = cmds.modelEditor()
        editor4 = cmds.modelEditor()
        editor5 = cmds.modelEditor()
        editor6 = cmds.modelEditor()
        self.modelEditor(editor1)
        self.modelEditor(editor2)
        self.modelEditor(editor3)
        self.modelEditor(editor4)
        self.modelEditor(editor5)
        self.modelEditor(editor6)

        #change backgoundcolor
        cmds.displayPref(displayGradient=0)

        cmds.formLayout(form,
                        edit=True,
                        attachForm=[(editor1, 'top', 0),
                                    (editor1, 'bottom', 512),
                                    (editor1, 'left', 0),
                                    (editor1, 'right', 1024),
                                    (editor2, 'top', 0),
                                    (editor2, 'bottom', 512),
                                    (editor2, 'right', 512),
                                    (editor2, 'left', 512),
                                    (editor3, 'top', 0),
                                    (editor3, 'bottom', 512),
                                    (editor3, 'right', 0),
                                    (editor3, 'left', 1024),
                                    (editor4, 'top', 512),
                                    (editor4, 'bottom', 0),
                                    (editor4, 'left', 0),
                                    (editor4, 'right', 1024),
                                    (editor5, 'top', 512),
                                    (editor5, 'bottom', 0),
                                    (editor5, 'right', 512),
                                    (editor5, 'left', 512),
                                    (editor6, 'top', 512),
                                    (editor6, 'bottom', 0),
                                    (editor6, 'right', 0),
                                    (editor6, 'left', 1024)],
                        attachControl=[(editor1, 'right', 0, editor2),
                                       (editor2, 'right', 0, editor3),
                                       (editor4, 'right', 0, editor5),
                                       (editor5, 'right', 0, editor6),
                                       (editor1, 'bottom', 0, editor4),
                                       (editor2, 'bottom', 0, editor5),
                                       (editor3, 'bottom', 0, editor6)])

        cameraShape = self.camera
        if cmds.objectType(self.camera, isType='transform'):
            cameraShape = cmds.listRelatives(self.camera, children=True)[0]
        nearClipPlane = cmds.getAttr(cameraShape + '.nearClipPlane')
        farClipPlane = cmds.getAttr(cameraShape + '.farClipPlane')
        cameraFront = cmds.camera(centerOfInterest=2.450351)
        cmds.setAttr(cameraFront[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraFront[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraFront)
        cameraLeft = cmds.camera(centerOfInterest=2.450351,
                                 rotation=(0, 90, 0))
        cmds.setAttr(cameraLeft[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraLeft[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraLeft)
        cameraBack = cmds.camera(centerOfInterest=2.450351,
                                 rotation=(0, 180, 0))
        cmds.setAttr(cameraBack[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraBack[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraBack)
        cameraRight = cmds.camera(centerOfInterest=2.450351,
                                  rotation=(0, 270, 0))
        cmds.setAttr(cameraRight[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraRight[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraRight)
        cameraUp = cmds.camera(centerOfInterest=2.450351, rotation=(90, 0, 0))
        cmds.setAttr(cameraUp[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraUp[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraUp)
        cameraDown = cmds.camera(centerOfInterest=2.450351,
                                 rotation=(270, 0, 0))
        cmds.setAttr(cameraDown[0] + '.nearClipPlane', nearClipPlane)
        cmds.setAttr(cameraDown[0] + '.farClipPlane', farClipPlane)
        cmds.hide(cameraDown)

        #group = cmds.group(camera2,camera3,camera4,camera5,camera6,name='cameraFull')
        #cmds.parentConstraint(camera1,group,maintainOffset=False)
        cmds.parent(cameraFront[0], argCamera, relative=True)
        cmds.parent(cameraLeft[0], argCamera, relative=True)
        cmds.parent(cameraBack[0], argCamera, relative=True)
        cmds.parent(cameraRight[0], argCamera, relative=True)
        cmds.parent(cameraUp[0], argCamera, relative=True)
        cmds.parent(cameraDown[0], argCamera, relative=True)

        cameraList = [
            cameraFront[1], cameraRight[1], cameraBack[1], cameraLeft[1],
            cameraUp[1], cameraDown[1]
        ]
        self.tmpCameraList = cameraList
        self.argCamera = argCamera
        for item in cameraList:
            cmds.setAttr('%s.horizontalFilmAperture' % item, 1)
            cmds.setAttr('%s.verticalFilmAperture' % item, 1)
            cmds.setAttr('%s.filmFit' % item, 3)
            cmds.setAttr('%s.focalLength' % item, 12.700)

        #~ cmds.modelEditor( editor1, edit=True, camera=cameraFront[0] )
        #~ cmds.modelEditor( editor2, edit=True, camera=cameraLeft[0] )
        #~ cmds.modelEditor( editor3, edit=True, camera=cameraBack[0] )
        #~ cmds.modelEditor( editor4, edit=True, camera=cameraRight[0] )
        #~ cmds.modelEditor( editor5, edit=True, camera=cameraUp[0] )
        #~ cmds.modelEditor( editor6, edit=True, camera=cameraDown[0] )
        cmds.modelEditor(editor1, edit=True, camera=cameraBack[0])
        cmds.modelEditor(editor2, edit=True, camera=cameraUp[0])
        cmds.modelEditor(editor3, edit=True, camera=cameraDown[0])
        cmds.modelEditor(editor4, edit=True, camera=cameraLeft[0])
        cmds.modelEditor(editor5, edit=True, camera=cameraFront[0])
        cmds.modelEditor(editor6, edit=True, camera=cameraRight[0])

        cmds.showWindow(self.window)
        cmds.window('showPanoramaWindow', topLeftCorner=(0, 0), edit=True)
Beispiel #25
0
 def screen_shot(self, ):
     cmds.displayPref(displayGradient=1)
     Dir = os.path.dirname(self.__file)
     if not os.path.exists(Dir):
         os.makedirs(Dir)
     self.__file = self.__file.split('.')[0]
     WindowName = 'Snapshot'
     if cmds.window(WindowName, exists=True):
         cmds.deleteUI(WindowName, window=True)
     if cmds.windowPref(WindowName, exists=True):
         cmds.windowPref(WindowName, remove=True)
     cmds.window(WindowName, title='Snapshot')
     modelPanels = cmds.getPanel(typ="modelPanel")
     for currentPanel in modelPanels:
         cmds.modelEditor(currentPanel,
                          e=True,
                          displayAppearance='smoothShaded')
     PaneLayout = cmds.paneLayout(width=480, height=480)
     if self.__sceneSnap:
         ModelPanel = cmds.modelPanel(
             copy=cmds.getPanel(withLabel='Persp View'),
             menuBarVisible=False)
         cmds.camera('persp',
                     e=1,
                     displayFilmGate=False,
                     displayResolution=False)
         cmds.setAttr('persp.rx', -45)
         cmds.setAttr('persp.ry', 45)
     else:
         ModelPanel = cmds.modelPanel(
             copy=cmds.getPanel(withLabel='Front View'),
             menuBarVisible=False)
         cmds.camera('front',
                     e=1,
                     displayFilmGate=False,
                     displayResolution=False)
     cmds.showWindow(WindowName)
     cmds.modelEditor(ModelPanel, edit=True, useDefaultMaterial=False)
     mel.eval('setWireframeOnShadedOption false ' + ModelPanel)
     cmds.modelEditor(ModelPanel,
                      edit=True,
                      allObjects=False,
                      displayTextures=True)
     cmds.modelEditor(ModelPanel, edit=True, polymeshes=True)
     cmds.modelEditor(ModelPanel,
                      edit=True,
                      pluginObjects=['gpuCacheDisplayFilter', True])
     cmds.modelEditor(ModelPanel, edit=True, grid=False)
     mel.eval('SelectAllPolygonGeometry')
     mel.eval('LowQualityDisplay')
     cmds.viewFit(cmds.lookThru(ModelPanel, query=True),
                  fitFactor=0.8,
                  animate=True)
     cmds.select(clear=True)
     cmds.modelEditor(ModelPanel, edit=True, activeView=True)
     cmds.playblast(startTime=0,
                    endTime=0,
                    format='image',
                    filename=self.__file,
                    sequenceTime=False,
                    clearCache=True,
                    viewer=False,
                    showOrnaments=False,
                    offScreen=True,
                    framePadding=4,
                    percent=100,
                    compression='png',
                    quality=100,
                    widthHeight=[480, 480])
     if cmds.window(WindowName, exists=True):
         cmds.deleteUI(WindowName, window=True)
     if cmds.windowPref(WindowName, exists=True):
         cmds.windowPref(WindowName, remove=True)
     if os.path.exists(self.__file + '.png'):
         os.remove(self.__file + '.png')
     os.rename(self.__file + '.0000.png', self.__file + '.png')
def ToggleAffected(*args, **kwargs):
    # display affected or not ?? - f**k it all!
    checker = cmds.displayPref(q=True, da=True)
    cmds.displayPref(displayAffected=not (checker))
def viewportColor(BG):
    if BG == 'gradGrey':
        cmds.displayPref(dgr=True)
    elif BG == 'Grey':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', .631, .631, .631)
    elif BG == 'Green':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', 0, 1, 0)
    elif BG == 'Blue':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', 0, 0, 1)
    elif BG == 'Red':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', 1, 0, 0)
    elif BG == 'White':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', 1, 1, 1)
    elif BG == 'Black':
        cmds.displayPref(dgr=False)
        cmds.displayRGBColor('background', 0, 0, 0)
    else:
        print 'Error: There was a problem with setting the camera viewport background color'