Skip to content

Commit 6f3edb6

Browse files
committed
code review fixes
moved code in for loops to two functions
1 parent 081bd18 commit 6f3edb6

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

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

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,67 @@ global proc unityImport(){
212212
}
213213
}
214214

215+
// returns the intersection of two string arrays
216+
proc string[] getIntersection(string $set1[], string $set2[]){
217+
string $myIntersector = `stringArrayIntersector`;
218+
219+
stringArrayIntersector -edit -reset $myIntersector;
220+
stringArrayIntersector -edit -intersect $set1 $myIntersector;
221+
stringArrayIntersector -edit -intersect $set2 $myIntersector;
222+
223+
string $intersection[] = `stringArrayIntersector -query $myIntersector`;
224+
225+
// Delete the intersector
226+
deleteUI $myIntersector;
227+
228+
return $intersection;
229+
}
215230

216-
proc unityExport(int $exportAnim){
217-
// get the global variables
218-
global string $UnityExportSets[];
231+
proc exportSet(string $unitySet, int $exportAnim){
219232
global string $UnityFbxFilePathAttr;
220233
global string $UnityFbxFileNameAttr;
221234
global string $UnityFbxAnimFilePathAttr;
222235
global string $UnityFbxAnimFileNameAttr;
236+
237+
string $unitySetContents[] = `listConnections $unitySet`;
238+
239+
string $animatedObjectSet = "";
240+
if($exportAnim){
241+
string $animCurveSelect[] = `ls -typ animCurve`;
242+
string $animatedTransforms[] = `listConnections -t transform $animCurveSelect`;
243+
244+
string $setAnimatedTransforms[] = getIntersection($animatedTransforms, $unitySetContents);
245+
246+
select -r $setAnimatedTransforms;
247+
$animatedObjectSet = `sets`;
248+
select -r -ne $animatedObjectSet;
249+
}
250+
251+
$pathAttr = $UnityFbxFilePathAttr;
252+
$nameAttr = $UnityFbxFileNameAttr;
253+
254+
if($exportAnim){
255+
$pathAttr = $UnityFbxAnimFilePathAttr;
256+
$nameAttr = $UnityFbxAnimFileNameAttr;
257+
}
258+
259+
$unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
260+
$unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
261+
262+
$strCmd = "";
263+
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
264+
$strCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $unity_fbx_file_path + "/" + $unity_fbx_file_name + "\"";
265+
eval $strCmd;
266+
}
267+
268+
if(setExists($animatedObjectSet)){
269+
delete $animatedObjectSet;
270+
}
271+
}
272+
273+
proc unityExport(int $exportAnim){
274+
// get the global variables
275+
global string $UnityExportSets[];
223276

224277
if(!loadUnityDependencies()){
225278
return;
@@ -238,26 +291,19 @@ proc unityExport(int $exportAnim){
238291
return;
239292
}
240293

241-
string $myIntersector = `stringArrayIntersector`;
242-
243294
$i = 0;
244295
string $setsToExport[];
245296
for($exportSet in $UnityExportSets){
246297
if(!setExists($exportSet)){
247298
continue;
248299
}
249300

250-
stringArrayIntersector -edit -reset $myIntersector;
251-
stringArrayIntersector -edit -intersect $origSelection $myIntersector;
252-
301+
// check if the selection intersects with this export set
253302
string $exportSetContents[] = `listConnections $exportSet`;
254-
255-
stringArrayIntersector -edit -intersect $exportSetContents $myIntersector;
256-
257-
string $intersection[] = `stringArrayIntersector -query $myIntersector`;
303+
string $intersection[] = getIntersection($origSelection, $exportSetContents);
258304

259305
if(size($intersection) > 0 ||
260-
stringArrayContains($exportSet, $origSelection)){
306+
stringArrayContains($exportSet, $origSelection)){
261307

262308
$setsToExport[$i] = $exportSet;
263309
$i++;
@@ -272,50 +318,9 @@ proc unityExport(int $exportAnim){
272318

273319
for($unitySet in $setsToExport){
274320
print ("exporting set: " + $unitySet);
275-
276-
string $unitySetContents[] = `listConnections $unitySet`;
277-
278-
string $animatedObjectSet = "";
279-
if($exportAnim){
280-
string $animCurveSelect[] = `ls -typ animCurve`;
281-
string $animatedTransforms[] = `listConnections -t transform $animCurveSelect`;
282-
283-
stringArrayIntersector -edit -reset $myIntersector;
284-
stringArrayIntersector -edit -intersect $animatedTransforms $myIntersector;
285-
stringArrayIntersector -edit -intersect $unitySetContents $myIntersector;
286-
287-
string $setAnimatedTransforms[] = `stringArrayIntersector -query $myIntersector`;
288-
289-
select -r $setAnimatedTransforms;
290-
$animatedObjectSet = `sets`;
291-
select -r -ne $animatedObjectSet;
292-
}
293-
294-
$pathAttr = $UnityFbxFilePathAttr;
295-
$nameAttr = $UnityFbxFileNameAttr;
296-
297-
if($exportAnim){
298-
$pathAttr = $UnityFbxAnimFilePathAttr;
299-
$nameAttr = $UnityFbxAnimFileNameAttr;
300-
}
301-
302-
$unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
303-
$unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
304-
305-
$strCmd = "";
306-
if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
307-
$strCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $unity_fbx_file_path + "/" + $unity_fbx_file_name + "\"";
308-
eval $strCmd;
309-
}
310-
311-
if(setExists($animatedObjectSet)){
312-
delete $animatedObjectSet;
313-
}
321+
exportSet($unitySet, $exportAnim);
314322
}
315323

316-
// Delete the intersector
317-
deleteUI $myIntersector;
318-
319324
select -cl;
320325
if (size($origSelection) > 0){
321326
select -add -ne $origSelection;

0 commit comments

Comments
 (0)