// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Description: // Initialization script for our scripted panel stereo editor. // This script defines the scriptedPanelType, if one does not exists, // the callback methods for save, creation, init, and removal. // global string $gStereoPerspPanelConfig = ""; global string $gStereoOutlinerPerspPanelConfig = ""; // Define callbacks for this type and make it a unique type // as we don't want two panels sharing the same global data. // global proc stereoCameraCustomPanelType() { int $exists = `scriptedPanelType -q -ex Stereo`; if ( !$exists ) { scriptedPanelType -createCallback stereoCameraCreateCallback -initCallback stereoCameraInitCallback -addCallback stereoCameraAddCallback -removeCallback stereoCameraRemoveCallback -deleteCallback stereoCameraDeleteCallback -saveStateCallback stereoCameraSaveStateCallback -cv true -unique true -retainOnFileOpen true Stereo; } else { scriptedPanelType -edit -createCallback stereoCameraCreateCallback -initCallback stereoCameraInitCallback -addCallback stereoCameraAddCallback -removeCallback stereoCameraRemoveCallback -deleteCallback stereoCameraDeleteCallback -saveStateCallback stereoCameraSaveStateCallback Stereo; } } global proc stereoCameraCustomPanelTypeClear() { int $exists = `scriptedPanelType -q -ex Stereo`; if ( $exists ) { scriptedPanelType -edit -createCallback "" -initCallback "" -addCallback "" -removeCallback "" -deleteCallback "" -saveStateCallback "" Stereo; } } proc buildMarkingMenuForStereoCamera( string $parent, string $panelControl ) // // Description: // Handles the creation of the marking menus for the viewport. // { global int $gIsMarkingMenuOn; // Find out current location of the panel and ensure that it has // a control layout associated with it. // // regular popup mappings. int $objectButton = 3; int $ctlObjectQualifier = 0; int $shObjectQualifier = 0; string $objectMenuName = ( $parent + "ObjectPop" ); string $convertMenuName = ( $parent + "ConvertPop" ); string $commandMenuName = ( $parent + "CommandPop" ); string $toolOptionsMenuName = ( $parent + "ToolOptionsPop" ); // Build the object specific menu if( !`popupMenu -exists $objectMenuName` ) { string $fullObjectMenuName = `popupMenu -parent $panelControl $objectMenuName`; string $buildObjectMenuItemsNow = "buildObjectMenuItemsNow"; popupMenu -e -mm $gIsMarkingMenuOn -button $objectButton -sh $shObjectQualifier -ctl $ctlObjectQualifier -aob true -pmc ( $buildObjectMenuItemsNow + " \"" + $fullObjectMenuName + "\"") $objectMenuName; } if (!`popupMenu -exists $convertMenuName`) { string $fullConvertMenuName = `popupMenu -parent $panelControl -allowOptionBoxes true $convertMenuName`; string $buildConvertMM = "buildConvertMM"; popupMenu -edit -markingMenu $gIsMarkingMenuOn -ctrlModifier true -button 3 -postMenuCommand ($buildConvertMM + " \"" + $fullConvertMenuName + "\"") $convertMenuName; } if (!`popupMenu -exists $commandMenuName`) { string $fullCommandMenuName = `popupMenu -parent $panelControl -allowOptionBoxes true $commandMenuName`; string $buildCommandMM = "contextToolsMM"; popupMenu -edit -markingMenu $gIsMarkingMenuOn -ctrlModifier false -shiftModifier true -button 3 -postMenuCommand ($buildCommandMM + " \"" + $fullCommandMenuName + "\"") $commandMenuName; } if (!`popupMenu -exists $toolOptionsMenuName`) { string $fullToolOptionsMenuName = `popupMenu -parent $panelControl -allowOptionBoxes true $toolOptionsMenuName`; string $buildCommandMM = "buildToolOptionsMM"; popupMenu -edit -markingMenu $gIsMarkingMenuOn -ctrlModifier true -shiftModifier true -button 3 -postMenuCommand ($buildCommandMM + " \"" + $fullToolOptionsMenuName + "\"") $toolOptionsMenuName; } } global proc scriptedPanelRunTimeCmd( string $rootCmd, string $currentPanel ) { string $scriptedType = `scriptedPanel -q -type $currentPanel`; if ( $scriptedType == "Stereo" ) { string $editor = $currentPanel + "Editor"; string $theCmd = $rootCmd + " " + $editor; evalEcho( $theCmd ); } } global proc stereoCameraCustomPanelCleanup() { string $panelName = "StereoPanel"; if (`scriptedPanel -exists $panelName`) { deleteUI -panel $panelName; } // do not save plugin info anymore // since the scripted panel has been removed if ( !`scriptedPanel -exists $panelName` ) { pluginInfo -edit -writeRequires false stereoCamera; } // Clear the type. Must be done after the deleteUI otherwise // an error occurs. stereoCameraCustomPanelTypeClear(); // Delete any UI configurations added. global string $gStereoPerspPanelConfig; string $stereoPerspName = localizedPanelLabel( "Stereo Persp" ); string $configName = `getPanel -cwl $stereoPerspName`; if (size($configName)) { deleteUI -panelConfig $gStereoPerspPanelConfig; $gStereoPerspPanelConfig = ""; } global string $gStereoOutlinerPerspPanelConfig; string $stereoOutPerspName = localizedPanelLabel( "Stereo Persp/Outliner" ); $configName = `getPanel -cwl $stereoOutPerspName`; if (size($configName)) { deleteUI -panelConfig $gStereoOutlinerPerspPanelConfig; $gStereoOutlinerPerspPanelConfig = ""; } } global proc stereoCameraCustomPanelSetup( string $panelName ) // // Description: // Initial scripted panel start up script. Defines the scripted panel type // and also creates the some UI panel configurations. // { stereoCameraCustomPanelType(); if ( $panelName == "" ) { $panelName = "StereoPanel"; } string $stereoName = localizedPanelLabel("Stereo"); if ( !`scriptedPanel -exists $panelName` ) { global string $gMainPane; setParent $gMainPane; scriptedPanel -unParent -type Stereo -label $stereoName $panelName; } //ensure plugin stereoCamera be loaded python("from maya.app.stereo import stereoCameraUtil"); python("stereoCameraUtil.loadPlugin()"); // save plugin info into scene file // to make sure we can reload scripted panel // next time we open the scene if ( `scriptedPanel -exists $panelName` ) { pluginInfo -edit -writeRequires true stereoCamera; } // Add some panel configurations ... // global string $gStereoPerspPanelConfig; global string $gStereoOutlinerPerspPanelConfig; string $stereoPerspName = localizedPanelLabel( "Stereo Persp" ); string $configName = `getPanel -cwl $stereoPerspName`; if ( $configName == "" ) { $gStereoPerspPanelConfig = `panelConfiguration -label $stereoPerspName -sc false -cfs "paneLayout -e -cn \"single\" $gMainPane" -addPanel true $stereoName "scriptedPanel" ("{ scriptedPanel -type Stereo\ -unParent -label \""+$stereoName+"\";}" ) ("scriptedPanel -edit -label \""+$stereoName+"\" $panelName")`; } else { $gStereoPerspPanelConfig = $configName; } string $stereoOutPerspName = localizedPanelLabel( "Stereo Persp/Outliner" ); $configName = `getPanel -cwl $stereoOutPerspName`; if ( $configName == "" ) { string $outlinerCmd = "(localizedPanelLabel(\"Outliner\"))"; $gStereoOutlinerPerspPanelConfig = `panelConfiguration -label $stereoOutPerspName -sceneConfig false -configString ("paneLayout " + "-edit " + "-configuration \"vertical2\" " + "-ps 1 20 100 " + "-ps 2 80 100 " + "$gMainPane;") -addPanel false (localizedPanelLabel("Outliner")) "outlinerPanel" ("{global int $gUseMenusInPanels;\ $panelName = `outlinerPanel -mbv $gUseMenusInPanels -unParent -label " + $outlinerCmd + "`;\ outlinerEditor -e -highlightActive true $panelName;}") ("outlinerPanel -edit -label " + $outlinerCmd + " $panelName") -addPanel true $stereoName "scriptedPanel" ("{ scriptedPanel -type Stereo\ -unParent -label \""+$stereoName+"\";}" ) ("scriptedPanel -edit -label \""+$stereoName+"\" $panelName")`; } else { $gStereoOutlinerPerspPanelConfig = $configName; } } global proc stereoCameraCreateCallback(string $panelName) // // Description: // Create any editors unparented here and do // any other initialization required. // { python("from maya.app.stereo import stereoCameraRig"); string $editor = ($panelName + "Editor"); stereoCameraView -unParent $editor; string $rigs[] = python("stereoCameraRig.listRigs()"); if (size($rigs)>0) { stereoCameraView -edit -rigRoot $rigs[0] $editor ; } else { // This code may be executed before any rig is created. It is // even executed sometime before *any camera* is created. string $cams[] = `listCameras -perspective`; if (size($cams) > 0) { stereoCameraView -edit -camera $cams[0] $editor ; } } } global proc stereoCameraInitCallback(string $panelName) // // Description: // Re-initialize the panel on file -new or file -open. // // In this example we will only re-init the global array. // { stereoCameraCustomPanelSetup( $panelName ); } global proc stereoMenuCallback( string $parent, string $editor ) // // Description: // Invoke our menu creation code. // { string $pyCmd = "from maya.app.stereo import stereoCameraMenus\n"; $pyCmd = $pyCmd + "stereoCameraMenus.addCustomViewMenus( '" + $parent + "', '" + $editor + "' ) "; python($pyCmd); } global proc stereoCameraAddCallback(string $panelName) // // Description: Create UI and parent any editors. // { string $editorName = ( $panelName + "Editor" ); if ( !`stereoCameraView -query -exists $editorName` ) { $editorName = ""; } string $pyCmd = ("stereoCameraUI.createViewUI(\'" + $panelName + "', '" + $editorName + "')\n"); python( "from maya.app.stereo import stereoCameraUI" ); python( $pyCmd ); global string $gScriptedModelEditorTypes[]; global string $gScriptedModelEditorList[]; int $nextAvail = size( $gScriptedModelEditorTypes ); $gScriptedModelEditorTypes[$nextAvail] = "Stereo"; $gScriptedModelEditorList[$nextAvail] = $editorName; string $vstring = (uiRes("m_stereoCameraCustomPanelSetup.kView")); string $lstring = (uiRes("m_stereoCameraCustomPanelSetup.kLighting")); string $shstring = (uiRes("m_stereoCameraCustomPanelSetup.kShading")); string $shwstring = (uiRes("m_stereoCameraCustomPanelSetup.kShow")); string $rndstring = (uiRes("m_stereoCameraCustomPanelSetup.kRnd")); string $subset[] = { $vstring, $lstring, $shstring, $shwstring, $rndstring }; string $extraMenus[] = { localizedPanelLabel( "Stereo" ) }; string $extraCmds[] = { "stereoMenuCallback" }; string $panelControl = `panel -q -control $panelName`; setParent $panelControl; createModelEditorMenu( $panelName, $editorName, $subset, $extraMenus, $extraCmds ); buildMarkingMenuForStereoCamera( $panelName, $editorName ); } global proc stereoCameraRemoveCallback(string $panelName) // // Description: // Unparent any editors and save state if required. // { // Scope the control names to this panel. // string $editor = ($panelName + "Editor"); stereoCameraView -edit -unParent $editor; global string $gScriptedModelEditorTypes[]; global string $gScriptedModelEditorList[]; int $index = -1; for ( $i = 0; $i < size($gScriptedModelEditorTypes); $i ++ ) { if ( $gScriptedModelEditorTypes[$i] == "Stereo" && $gScriptedModelEditorList[$i] == $editor ) { $index = $i; break; } } if ( $index != -1 ) { stringArrayRemoveAtIndex( $index, $gScriptedModelEditorTypes ); stringArrayRemoveAtIndex( $index, $gScriptedModelEditorList ); } } global proc stereoCameraDeleteCallback(string $panelName) // // Description: // Delete any editors and do any other cleanup required. // { } global proc lookThroughModelPanelClipped( string $object, string $panel, float $nearClip, float $farClip ) { string $type = `getPanel -typeOf $panel`; string $editor = $panel; if ( $type == "scriptedPanel" ) { string $sptype = `scriptedPanel -q -type $panel`; if ( $sptype == "Stereo" ) { $editor = ($panel + "Editor"); } } python("from maya.app.stereo import stereoCameraRig"); int $isStereo = `python("stereoCameraRig.rigRoot('"+$object+"') <> ''")`; if ( $isStereo ) { string $pyCmd = "from maya.app.stereo import stereoCameraCustomPanel\n"; $pyCmd = $pyCmd + "stereoCameraCustomPanel.switchToSelected( '" + $editor + "' ) "; python($pyCmd); } else { lookThroughModelPanelSetup $panel; lookThru -nc $nearClip -fc $farClip $object $panel; } } global proc string stereoCameraSaveStateCallback(string $panelName) // // Description: // Return a string that will restore the current state // when it is executed. // { string $editor = ($panelName + "Editor"); return ("{ string $editorName = ($panelName+\"Editor\");\n" + `stereoCameraView -q -stateString $editor` + "; }"); }