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 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 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 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 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 populateEditorSettings(editor): """ This routine populates some initial values onto the specified editor. It does this by searching the Maya scene for any selected stereo camera rigs. If there are no stereo rigs selected, then it searches the scene for the first available stereo rig. If there are no stereo rigs in the scene, then it defaults to using the perspective camera for center, left, and right views. """ # Do we have any selected stereo cameras. # selList = cmds.ls(sl=True) viewCam = None stereoFound = True if selList: for s in selList: if stereoCameraRig.isStereoRig(s): viewCam = s # Do we have any stereo rigs in this scene. # if not viewCam: rigs = stereoCameraRig.listRigs() if rigs: viewCam = rigs[0] # Fallback to using the persp camera, which is always in the scene. # if not viewCam: cams = cmds.listCameras(perspective=True) viewCam = cams[0] stereoFound = False # Set the default value on the plugin. # cmds.stereoCameraView(editor, edit=True, camera=viewCam) if stereoFound: cmds.stereoCameraView(editor, edit=True, rightCamera=stereoCameraRig.rightCam(viewCam)) cmds.stereoCameraView(editor, edit=True, leftCamera=stereoCameraRig.leftCam(viewCam)) cmds.stereoCameraView(editor, edit=True, centerCamera=viewCam) cmds.stereoCameraView(editor, edit=True, displayMode='centerEye')
def activeModeAvailable(*args): """ Query the custom view to determine if the specified mode is available. """ modeSupported = cmds.stereoCameraView(args[0], query=True, activeSupported=True) return (modeSupported == 1)
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)
def currentViewCameraFromEditor(editor): """ Given an editor retrieve the current camera from that editor. """ theCam = cmds.stereoCameraView(editor, query=True, camera=True) if theCam: relatives = cmds.listRelatives(theCam, parent=True) if relatives: return relatives[0] return theCam
def checkState(*args): """ This is a callback that is invoked by the menu creation code. It is used to determine if the menu item should be checked. The first argument is assumed to be the displayMode name to check against and the second argument is assumed to be the name of the editor. Both are string types. """ displayMode = cmds.stereoCameraView(args[1], query=True, displayMode=True) if displayMode == args[0]: return True return False
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 createViewUI( panelName, editor ): """ Creates the UI around a StereoCamera 3d View tool. This includes tool bar and corresponding buttons. You can pass in a panel name and an editor name to this procedure. If panelName == '' then a window is created for the UI. If editor == '' then a new editor is created. Otherwise, a named editor tells this method that one has been created and it should simple parent the editor to the created UI. """ isNewEditor = False if not editor: isNewEditor = True # Create a new window if we have no panel. # window = '' if not panelName: window = cmds.window() form = cmds.formLayout() if isNewEditor: # No previous editor was created. We need to create a new # editor for this window. # if not panelName: editor = cmds.stereoCameraView() else: editor = cmds.stereoCameraView( panelName + 'Editor' ) else: # We already have an editor. Parent this edtor to the # newly created form. # cmds.stereoCameraView( editor, edit=True, unParent=True ) cmds.stereoCameraView( editor, edit=True, parent=form ) toolBarPack( editor, form ) if isNewEditor: populateEditorSettings( editor ) if window: cmds.showWindow( window ) return editor
def currentViewRigFromEditor(editor): theRig = cmds.stereoCameraView(editor, query=True, rigRoot=True) return theRig