def switchToCamera(*args):
    """
	Switch the viewport editor the specified camera name.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = args[1]
    cameraName = args[0]
    root = cameraName

    # Display an error to the user if the camera set contains no data.
    #
    if cmds.objectType(cameraName, isa="cameraSet"):
        nl = cmds.cameraSet(cameraName, query=True, numLayers=True)
        if nl == 0:
            stereoCameraErrors.displayError('kNoDataInCameraSet', cameraName)

    editor = getValidPanel(editor)

    # Users can switch to a stereo camera using camera sets or via
    # rigs.  If it is a camera set then we don't need to find the
    # root.  We can simply view that camera set.
    #
    if not cmds.objectType(cameraName, isa="cameraSet"):
        root = stereoCameraRig.rigRoot(cameraName)

    cmds.stereoCameraView(editor, edit=True, rigRoot=root)

    if len(args) > 2 and args[2]:
        # The 3rd argument indicates if we should select the camera
        # after assignment. It is tiggered by an option box on the
        # camera switcher.
        #
        cmds.select(cameraName, replace=True)
def adjustBackground(*args):
    """
	Get the camera that is assigned to the current view.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = ''
    if len(args):
        editor = args[0]
    else:
        panel = cmds.getPanel(withFocus=True)
        editor = panel + 'Editor'

    result = cmds.stereoCameraView(editor, query=True, viewColor=True)
    result = cmds.colorEditor(
        alpha=float(result[3]),
        rgbValue=[float(result[0]),
                  float(result[1]),
                  float(result[2])])
    buffer = result.split()
    if '1' == buffer[3]:
        values = cmds.colorEditor(query=True, rgb=True)
        alpha = cmds.colorEditor(query=True, alpha=True)
        cmds.stereoCameraView(
            editor,
            edit=True,
            viewColor=[values[0], values[1], values[2], alpha],
            useCustomBackground=True)
def switchToCameraCenter(cameraName, editor):
    """
	Additional wrapper layer around switchToCamera. This function switches
	to the current camera and also toggles the view mode to be 'center'
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    switchToCamera(cameraName, editor)
    cmds.stereoCameraView(editor, edit=True, displayMode="centerEye")
def switchToSinglePerspLayout():
    """
	Switch the current view into to single perspective stereo mode.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    mel.eval("setNamedPanelLayout `localizedPanelLabel( " +
             "\"Stereo Persp\"" + " )`")
    cmds.refresh()
def switchToOutlinerPerspLayout():
    """
	Switch the current view into a outliner / persp viewer mode.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return

    mel.eval("setNamedPanelLayout `localizedPanelLabel( " +
             "\"Stereo Persp/Outliner\"" + " )`")
    cmds.refresh()
def switchToSelected(*args):
    """
	Switch the viewing camera to the current selection.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    nodes = stereoCameraRig.selectedCameras()
    if nodes:
        switchToCamera(nodes[0], args[0])
    else:
        stereoCameraErrors.displayError('kNotAValidStereoCamera')
def addNewCameraToCurrentSet(rigRoot, panel):
    """
	This is the main function for adding camera rigs to a camera
	set. Given a valid stereo rig, add that rig to the current camera
	set. If a camera set does not exist then, create one and make the
	view aware of the camera set.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = getValidEditor(panel)
    currentRig = currentViewRigFromEditor(editor)
    cameraSet = stereoCameraSets.addNewRigToSet(rigRoot, currentRig)
    cmds.stereoCameraView(editor, edit=True, rigRoot=cameraSet)
def useCustomBackgroundState(*args):
    """
	Return the state (True/False) of whether we use the display preferences or
	a solid background.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = ''
    if len(args):
        editor = args[0]
    else:
        panel = cmds.getPanel(withFocus=True)
        editor = panel + 'Editor'
    return cmds.stereoCameraView(editor, query=True, useCustomBackground=True)
def currentViewCamera(*args):
    """
	Get the camera that is assigned to the current view.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return

    editor = ''
    if len(args):
        editor = args[0]
    else:
        panel = cmds.getPanel(withFocus=True)
        editor = panel + 'Editor'

    return currentViewCameraFromEditor(editor)
def stereoCameraViewCallback(*args):
    """
	Main callback point for sending information to the editor command.
	The format of the callback is as follows:
	
	arg1 = the name of the editor
	arg2 = keyword dictionary represented as a string.
	
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    keywords = eval(args[1])
    keywords['edit'] = True
    # Run the command
    #
    cmds.stereoCameraView(args[0], **keywords)
def switchToCameraSet(*args):
    """
	Switch the viewport editor the specified cameraSet name.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = args[1]
    cameraSetName = args[0]
    editor = getValidPanel(editor)
    if cmds.objectType(cameraSetName, isa="cameraSet"):
        nl = cmds.cameraSet(cameraSetName, query=True, numLayers=True)
        if nl == 0:
            stereoCameraErrors.displayError('kNoDataInCameraSet',
                                            cameraSetName)
        else:
            cmds.stereoCameraView(editor, edit=True, rigRoot=cameraSetName)
def toggleUseCustomBackground(*args):
    """
    Toggle whether the current viewport background should match the background
    that is defined in the user preferences.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    editor = ''
    if len(args):
        editor = args[0]
    else:
        panel = cmds.getPanel(withFocus=True)
        editor = panel + 'Editor'

    usePref = cmds.stereoCameraView(editor,
                                    query=True,
                                    useCustomBackground=True)
    cmds.stereoCameraView(editor, edit=True, useCustomBackground=not usePref)
def swapCameras(*args):
    """
	Toggle the swap bit on the view.
	"""
    if not stereoCameraUtil.runCallbackChecks():
        return
    if len(args):
        editor = args[0]
        cmds.stereoCameraView(editor, edit=True, swapEyes=True)
    else:
        panels = cmds.lsUI(panels=True)
        for panel in panels:
            ttype = cmds.getPanel(typeOf=panel)
            if ttype == 'scriptedPanel':
                stype = cmds.scriptedPanel(panel, query=True, type=True)
                if stype == 'Stereo':
                    editor = panel + 'Editor'
                    cmds.stereoCameraView(editor, edit=True, swapEyes=True)
Beispiel #14
0
def getDefaultRig():
    stereoCameraUtil.runCallbackChecks()
    return cmds.stereoRigManager(query=True, defaultRig=True)