// =========================================================================== // 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. // =========================================================================== // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Functions defined in this file (gameFbxExporterQuickSelectSet.mel): // // global proc gameExp_QuickSelectSet(int $mods) // global proc gameExp_CreateSelectionSetList() // global proc gameExp_QuickSelectSetPopupMenu(string $parent) // proc gameExp_ActivateWith() // proc gameExp_ActionOnSet(int $mods) // proc gameExp_PromptToCreateSet() // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Switch the export mode to SelectionSet and automatically selects the $newSet // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- proc gameExp_ActivateWith(string $newSet) { // Switch export set mode to "Object set" (3) string $gameExporterExportSet = gameExp_GetPrefixedName("gameExporterExportSet"); optionMenu -e -select 3 $gameExporterExportSet; // Make sure we create the SelectionSet list (this automatically selects an empty string) gameExp_CreateSelectionSetList(); // now we select the newly created entry global string $gGameFbxExporterCurrentNode; string $gameExporterExportSelectionSet = gameExp_GetPrefixedName("gameExporterExportSelectionSet"); string $menuItemList[] = `optionMenu -q -itemListLong $gameExporterExportSelectionSet`; int $pos = 1; int $found = false; // loop to find the index ($pos) of $newSet in the menu items so we can select it for ($mItm in $menuItemList) { string $val = `menuItem -q -label $mItm`; if ($val == $newSet) { $found = true; break; } $pos += 1; } if ($found) { // make sure the SelectionSet list is enabled otherwise we cannot set values optionMenu -edit -enable true $gameExporterExportSelectionSet; optionMenu -edit -select $pos $gameExporterExportSelectionSet; setAttr($gGameFbxExporterCurrentNode + ".selectionSetName") -type "string" $newSet; } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Performs the actual action to update the set or the scene // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- proc gameExp_ActionOnSet(int $mods) { // $mods : // 0 = no mod ignored // 1 = "Shift" from LMB click or dropdown menu "Select Objects in Set" // 8 = "Alt" ignored // 4 = "Ctrl" from LMB click or dropdown menu "Update Selection Set" // 16 = "Cmd" ignored // global string $gGameFbxExporterCurrentNode; int $isShift = ($mods % 2); int $isCtrl = ($mods / 4 % 2); string $objectSetName = (getAttr($gGameFbxExporterCurrentNode + ".selectionSetName")); if (size($objectSetName) == 0) // undefined, bail out! return; // validate that the $objectSetName exists string $allSets[] = `listSets -as`; if (stringArrayFind($objectSetName, 0, $allSets) == -1) return; if ($isShift) { // SHIFT click : the objects in the current set should become selected. select -clear; // clear current selection select $objectSetName; // select all the objects in the set } else if ($isCtrl) { // CTRL click : the current set should be updated to the current selection. // wipe out content of set sets -e -clear $objectSetName; // collect the current selection string $sel[] = `ls -selection`; // just in case, remove $objectSetName from $sel to avoid a cycle error int $index = stringArrayFind($objectSetName, 0, $sel); if ($index != -1) stringArrayRemoveAtIndex($index, $sel); // fill it with the current selection sets -e -add $objectSetName $sel ; } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // This is pretty much the same code as the "defineCharacter" function defined // inside the ModCreateMenu.mel script. We simply could not re-use it because // it does not return a value and we need to know what the user did so we can // proceed with the synchronization tasks. // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- proc gameExp_PromptToCreateSet() { string $OK = getPluginResource( "gameFbxExporter", "kGameExporterOkLabel" ); string $cancel = getPluginResource( "gameFbxExporter", "kGameExporterCancelLabel" ); string $characterName; string $default = "Set"; string $setDefaultName = "gCharacterSet"; // Prompt the user for a new name // string $title = getPluginResource( "gameFbxExporter", "kGameExporterCreateQuickSelectSet"); string $message = getPluginResource( "gameFbxExporter", "kGameExporterEnterQuickSelectSetname"); string $result = `promptDialog -title $title -message $message -text $default -button $OK -button $cancel -defaultButton $OK -cancelButton $cancel -dismissString $cancel`; // If the result was "OK", then proceed // if ( $result == $OK ) { // Also, notice that the `type` is being set // to "gCharacterSet" - just trying to pick // a name that users probably won't type // $characterName = `promptDialog -q`; string $newName; $newName = `sets -text $setDefaultName -name $characterName`; string $resultStr = getPluginResource( "gameFbxExporter", "kGameExporterCreatedQuickSet"); string $infoStr = `format -stringArg $newName $resultStr`; print $infoStr; $characterName = $newName; gameExp_ActivateWith($characterName); } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Manages selection sets commands // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- global proc gameExp_QuickSelectSet(int $mods) { // $mods : // 0 = check current modifiers now // 1 = "Shift" from dropdown menu "Select Objects in Set" // 8 = "Alt" ignored // 4 = "Ctrl" from dropdown menu "Update Selection Set" // 16 = "Cmd" ignored // if ($mods == 0) $mods = `getModifiers`; int $isShift = ($mods % 2); int $isCtrl = ($mods / 4 % 2); if ($isShift==0 && $isCtrl==0) { gameExp_PromptToCreateSet(); } else { gameExp_ActionOnSet($mods); } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Populate the object sets list for the export selection set option // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- global proc gameExp_CreateSelectionSetList() { global string $gGameFbxExporterCurrentNode; string $gameExporterExportSelectionSet = gameExp_GetPrefixedName("gameExporterExportSelectionSet"); setParent -menu $gameExporterExportSelectionSet; string $menuItemList[] = `optionMenu -q -itemListLong $gameExporterExportSelectionSet`; string $menuItem; for($menuItem in $menuItemList) { deleteUI -menuItem $menuItem; } if(size($gGameFbxExporterCurrentNode)) { string $setsList[] = `ls -exactType objectSet`; string $defaultSets[] = `ls -defaultNodes -exactType objectSet`; // Remove default node sets $setsList = stringArrayRemove($defaultSets, $setsList); for( $i=0; $i < size($setsList); $i++) { // Add only specific object sets string $setName = $setsList[$i]; if(!`sets -q -vertices $setName` && !`sets -q -edges $setName` && !`sets -q -facets $setName` && !`sets -q -editPoints $setName`) { menuItem -label $setName; } } if(size(`optionMenu -query -itemListShort $gameExporterExportSelectionSet`)) { string $objectSetName = (getAttr($gGameFbxExporterCurrentNode + ".selectionSetName")); if(size($objectSetName)) { // catchQuiet if we still have a set name that doesn't exist anymore in the scene if( !catchQuiet( `optionMenu -edit -value $objectSetName $gameExporterExportSelectionSet`)) { // The object set is valid. return; } } // Create an empty item and select it. // Either we have never selected an object set or we had an object set that doesn't exist anymore. menuItem -insertAfter "" -label ""; optionMenu -edit -select 1 $gameExporterExportSelectionSet; setAttr($gGameFbxExporterCurrentNode + ".selectionSetName") -type "string" ""; } } } // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // Create a new popupMenu (for right click) attached to $parent // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- global proc gameExp_QuickSelectSetPopupMenu(string $parent) { popupMenu -parent $parent -button 3; menuItem -label (getPluginResource( "gameFbxExporter","kGameExporterUpdateSelectionSet")) -command ("gameExp_QuickSelectSet 4"); //4=Ctrl modifier menuItem -label (getPluginResource( "gameFbxExporter","kGameExporterSelectAllSet")) -command ("gameExp_QuickSelectSet 1"); //1=Shift modifier }