Skip to content

Commit 67fa621

Browse files
authored
Merge pull request #299 from Unity-Technologies/UNI-20156-export-multi-select-and-animation
Uni 20156 export multi select and animation
2 parents c6408dc + c10634f commit 67fa621

File tree

2 files changed

+117
-22
lines changed

2 files changed

+117
-22
lines changed

Assets/Integrations/Autodesk/maya/scripts/unityCommands.mel

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,70 @@ global proc unityImport(){
217217
}
218218
}
219219

220+
// returns the intersection of two string arrays
221+
proc string[] getIntersection(string $set1[], string $set2[]){
222+
string $myIntersector = `stringArrayIntersector`;
223+
224+
stringArrayIntersector -edit -reset $myIntersector;
225+
stringArrayIntersector -edit -intersect $set1 $myIntersector;
226+
stringArrayIntersector -edit -intersect $set2 $myIntersector;
227+
228+
string $intersection[] = `stringArrayIntersector -query $myIntersector`;
229+
230+
// Delete the intersector
231+
deleteUI $myIntersector;
232+
233+
return $intersection;
234+
}
220235

221-
global proc unityExport(){
222-
// get the global variables
223-
global string $UnityExportSet;
236+
proc exportSet(string $unitySet, int $exportAnim){
224237
global string $UnityFbxFilePathAttr;
225238
global string $UnityFbxFileNameAttr;
239+
global string $UnityFbxAnimFilePathAttr;
240+
global string $UnityFbxAnimFileNameAttr;
241+
242+
string $unitySetContents[] = `listConnections $unitySet`;
243+
244+
string $animatedObjectSet = "";
245+
if($exportAnim){
246+
string $animCurveSelect[] = `ls -typ animCurve`;
247+
string $animatedTransforms[] = `listConnections -t transform $animCurveSelect`;
248+
249+
string $setAnimatedTransforms[] = getIntersection($animatedTransforms, $unitySetContents);
250+
251+
select -r $setAnimatedTransforms;
252+
$animatedObjectSet = `sets`;
253+
select -r -ne $animatedObjectSet;
254+
}
255+
else{
256+
select -r -ne $unitySet;
257+
}
258+
259+
$pathAttr = $UnityFbxFilePathAttr;
260+
$nameAttr = $UnityFbxFileNameAttr;
261+
262+
if($exportAnim){
263+
$pathAttr = $UnityFbxAnimFilePathAttr;
264+
$nameAttr = $UnityFbxAnimFileNameAttr;
265+
}
266+
267+
$unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
268+
$unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
269+
270+
$strCmd = "";
271+
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
272+
$strCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $unity_fbx_file_path + "/" + $unity_fbx_file_name + "\"";
273+
eval $strCmd;
274+
}
275+
276+
if(setExists($animatedObjectSet)){
277+
delete $animatedObjectSet;
278+
}
279+
}
280+
281+
proc unityExport(int $exportAnim){
282+
// get the global variables
283+
global string $UnityExportSets[];
226284

227285
if(!loadUnityDependencies()){
228286
return;
@@ -232,27 +290,56 @@ global proc unityExport(){
232290
return;
233291
}
234292

235-
// select the export set for export, if it exists,
236-
// otherwise take what is currently selected
293+
FBXProperty "Export|IncludeGrp|Animation" -v $exportAnim;
294+
FBXExportAnimationOnly -v $exportAnim;
295+
237296
$origSelection = `ls -sl`;
238-
if (setExists($UnityExportSet)){
239-
select -r -ne $UnityExportSet;
297+
if(size($origSelection) <= 0){
298+
// nothing selected
299+
return;
240300
}
241301

242-
$unity_fbx_file_path = getAttribute($UnityExportSet, $UnityFbxFilePathAttr);
243-
$unity_fbx_file_name = getAttribute($UnityExportSet, $UnityFbxFileNameAttr);
302+
$i = 0;
303+
string $setsToExport[];
304+
for($exportSet in $UnityExportSets){
305+
if(!setExists($exportSet)){
306+
continue;
307+
}
308+
309+
// TODO (UNI-39197) move functionality to separate mel file
310+
// check if the selection intersects with this export set
311+
string $exportSetContents[] = `listConnections $exportSet`;
312+
string $intersection[] = getIntersection($origSelection, $exportSetContents);
313+
314+
if(size($intersection) > 0 ||
315+
stringArrayContains($exportSet, $origSelection)){
316+
317+
$setsToExport[$i] = $exportSet;
318+
$i++;
319+
}
320+
}
244321

245-
$strCmd = "";
246-
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
247-
$strCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $unity_fbx_file_path + "/" + $unity_fbx_file_name + "\"";
322+
// if selection doesn't belong to a set, export to a new file
323+
if(size($setsToExport) <= 0){
324+
eval "SendToUnitySelection";
325+
return;
248326
}
249-
else {
250-
$strCmd = "SendToUnitySelection";
327+
328+
for($unitySet in $setsToExport){
329+
print ("exporting set: " + $unitySet);
330+
exportSet($unitySet, $exportAnim);
251331
}
252-
eval $strCmd;
253332

254333
select -cl;
255334
if (size($origSelection) > 0){
256335
select -add -ne $origSelection;
257336
}
337+
}
338+
339+
global proc unityExportAnim(){
340+
unityExport(true);
341+
}
342+
343+
global proc unityExportModel(){
344+
unityExport(false);
258345
}

Assets/Integrations/Autodesk/maya/scripts/unitySetupUI.mel

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ global string $unityIconPath = "unity.png";
99

1010
global string $unityFamilyLabel = "The UnityFbxForMaya plugin (v.{Version}) allows you to reliably exchange and review your work between Maya and Unity.";
1111
global string $unityImportLabel = "Import an FBX file from a Unity project and auto-configure for exporting";
12-
global string $unityExportLabel = "Export Model to Unity";
12+
global string $unityExportModelLabel = "Export Model to Unity";
13+
global string $unityExportAnimLabel = "Export Animation to Unity";
1314

1415
global string $unityCommandsFile = "unityCommands.mel";
1516
global string $unityImportMenuName = "Import";
16-
global string $unityExportMenuName = "Export";
17+
global string $unityExportModelMenuName = "Export Model Only";
18+
global string $unityExportAnimMenuName = "Export Animation Only";
1719
global string $unityImportCommand = "unityImport";
18-
global string $unityExportCommand = "unityExport";
20+
global string $unityExportModelCommand = "unityExportModel";
21+
global string $unityExportAnimCommand = "unityExportAnim";
1922

2023
global proc string unityWhatsNewVersion(){
2124
return `about -q -version`;
@@ -49,12 +52,15 @@ global proc unityInstallUI(){
4952
global string $unityPluginVersion;
5053
global string $unityFamilyLabel;
5154
global string $unityImportLabel;
52-
global string $unityExportLabel;
55+
global string $unityExportModelLabel;
56+
global string $unityExportAnimLabel;
5357
global string $unityCommandsFile;
5458
global string $unityImportMenuName;
55-
global string $unityExportMenuName;
59+
global string $unityExportModelMenuName;
60+
global string $unityExportAnimMenuName;
5661
global string $unityImportCommand;
57-
global string $unityExportCommand;
62+
global string $unityExportModelCommand;
63+
global string $unityExportAnimCommand;
5864

5965
global string $gMainFileMenu;
6066

@@ -65,8 +71,10 @@ global proc unityInstallUI(){
6571
menuItem -parent $parentMenu -insertAfter $unityMenuInsertAfter -divider true -longDivider false -version $pluginVersion $unityMenuDivider;
6672
menuItem -parent $parentMenu -insertAfter $unityMenuDivider -subMenu true -label $unityMenuLabel -tearOff true -version $pluginVersion -image $unityIconPath -annotation $unityFamilyLabel $unityMenuName;
6773
menuItem -parent $unityMenuName -label $unityImportMenuName -version $pluginVersion -image $unityImportIconPath -annotation $unityImportLabel -command $unityImportCommand;
68-
menuItem -parent $unityMenuName -label $unityExportMenuName -version $pluginVersion -image $unityExportIconPath -annotation $unityExportLabel -command $unityExportCommand;
6974

75+
menuItem -parent $unityMenuName -label $unityExportModelMenuName -version $pluginVersion -image $unityExportIconPath -annotation $unityExportModelLabel -command $unityExportModelCommand;
76+
menuItem -parent $unityMenuName -label $unityExportAnimMenuName -version $pluginVersion -image $unityExportIconPath -annotation $unityExportAnimLabel -command $unityExportAnimCommand;
77+
7078
unityRemoveNativeMenuOnLoad();
7179

7280
}

0 commit comments

Comments
 (0)