@@ -446,6 +446,146 @@ proc string[] getUnityExportSets(){
446
446
return $unityExportSets;
447
447
}
448
448
449
+ proc setupNewExportSet(string $exportPath, int $exportAnimOnly, string $selectedObjects[]){
450
+ global string $UnityFbxFilePathAttr;
451
+ global string $UnityFbxFileNameAttr;
452
+ global string $UnityFbxAnimFilePathAttr;
453
+ global string $UnityFbxAnimFileNameAttr;
454
+ global string $UnityFbxNamespaceAttr;
455
+ global string $UnityExportSetNameFormat;
456
+ // extract name from path
457
+ // create export set
458
+ // create namespace
459
+ // move objects into namespace
460
+ // add objects to export set
461
+ // add attributes to set
462
+
463
+ $exportDir = dirname($exportPath);
464
+ $exportFileName = basename($exportPath, "");
465
+ $exportAnimDir = $exportDir;
466
+ $exportAnimFileName = "";
467
+ $fileNameWithoutExt = basename($exportPath, ".fbx");
468
+ $exportAnimFileName = ($fileNameWithoutExt + "@Take1.fbx");
469
+ $isAnimFile = $exportAnimOnly;
470
+
471
+ if($exportAnimOnly){
472
+ // import as animation
473
+ $exportAnimDir = $exportDir;
474
+ $exportAnimFileName = $exportFileName;
475
+
476
+ if(match("@", basename($exportDir, ".fbx")) != ""){
477
+ $fileNameWithoutExt = match("[^@]+", $fileNameWithoutExt);
478
+ }
479
+ }
480
+ $fileNameWithoutExt = formValidObjectName($fileNameWithoutExt);
481
+
482
+ $unityExportSet = `format -stringArg $fileNameWithoutExt $UnityExportSetNameFormat`;
483
+
484
+ string $origNamespace = `namespaceInfo -cur -an`;
485
+ string $targetNamespace = ":" + $fileNameWithoutExt;
486
+ // make sure there are no duplicate colons in namespace name
487
+ if($origNamespace != ":"){
488
+ $targetNamespace = `format -s $origNamespace -s $fileNameWithoutExt "^1s:^2s"`;
489
+ }
490
+
491
+ $setNamespaceExists = false;
492
+ if (setExists($unityExportSet)){
493
+ string $unitySetContents[] = `listConnections $unityExportSet`;
494
+
495
+ // get namespace from set
496
+ $setNamespace = getAttribute($unityExportSet, $UnityFbxNamespaceAttr);
497
+ if(size($unitySetContents) > 0){
498
+ $setNamespace = checkNamespaceNeedsUpdate($unityExportSet, $setNamespace, getObjectNamespace($unitySetContents[0]));
499
+ }
500
+
501
+ if($setNamespace != "" && `namespace -exists $setNamespace`){
502
+ $targetNamespace = $setNamespace;
503
+ $setNamespaceExists = true;
504
+ }
505
+ }
506
+
507
+ // warn if namespace already exists
508
+ if(!$setNamespaceExists){
509
+ if(`namespace -exists $targetNamespace`){
510
+ if(!showConfirmDialog("Warning: " + $exportFileName,
511
+ $targetNamespace + " namespace already exists, the selected objects will be added to the existing namespace and export set.",
512
+ "Continue", "Cancel"
513
+ )){
514
+ // cancelled, don't import this fbx
515
+ return;
516
+ }
517
+ }
518
+ else{
519
+ namespace -add $targetNamespace;
520
+ }
521
+ }
522
+
523
+ // Get or create the Unity Fbx Export Set
524
+ $setCreated = false;
525
+ if (!setExists($unityExportSet)){
526
+ if(!`namespaceInfo -isRootNamespace $origNamespace`){
527
+ namespace -set ":";
528
+ }
529
+
530
+ // if a set is selected when creating a new set, then
531
+ // the selected set will be added into the new set.
532
+ // avoid this by temporarily deselecting everything.
533
+ $origSelection = `ls -sl`;
534
+ select -clear;
535
+
536
+ // couldn't find export set so create it
537
+ sets -name $unityExportSet;
538
+ $setCreated = true;
539
+
540
+ if(size($origSelection) > 0){
541
+ select -r $origSelection;
542
+ }
543
+ }
544
+
545
+ // unlock set so we can add attributes to it
546
+ lockNode -lock false $unityExportSet;
547
+
548
+ if(!$isAnimFile){
549
+ // reset attribute values, in case import fails
550
+ storeAttribute($unityExportSet, $UnityFbxFilePathAttr, "");
551
+ storeAttribute($unityExportSet, $UnityFbxFileNameAttr, "");
552
+ storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, "");
553
+ }
554
+
555
+ // add to the targetNamespace
556
+ // iterate over all selected objects and rename
557
+ // rename FOO:sphere2 :BAR:sphere2;
558
+
559
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $exportDir != ""){
560
+ storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $exportDir);
561
+ }
562
+
563
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $exportFileName != ""){
564
+ storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$exportFileName);
565
+ }
566
+
567
+ if($exportAnimDir != ""){
568
+ storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$exportAnimDir);
569
+ }
570
+
571
+ if($exportAnimFileName != ""){
572
+ storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$exportAnimFileName);
573
+ }
574
+
575
+ if($fileNameWithoutExt != ""){
576
+ storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace);
577
+ }
578
+
579
+ if (setExists($unityExportSet) == true){
580
+ // add newly imported items to set
581
+ if (size($selectedObjects) > 0){
582
+ sets -include $unityExportSet $selectedObjects;
583
+ }
584
+ // lock set so it doesn't get deleted when empty
585
+ lockNode -lock true $unityExportSet;
586
+ }
587
+ }
588
+
449
589
proc unityExport(int $exportType){
450
590
451
591
if(!loadUnityDependencies()){
@@ -501,7 +641,16 @@ proc unityExport(int $exportType){
501
641
502
642
// if selection doesn't belong to a set, export to a new file
503
643
if(size($setsToExport) <= 0){
504
- eval "SendToUnitySelection";
644
+ //eval "GamePipelineSendToUnity 1";
645
+ $unityProject = `optionVar -q "UnityProject"`;
646
+ $exportPath = `fileDialog2 -ds 2 -cap "FBX Export Selection" -dir $unityProject -ff "*.fbx" -fm 0`;
647
+ if(size($exportPath)<=0){
648
+ return;
649
+ }
650
+ $exportCmd = "file -force -options \"\" -typ \"FBX export\" -pr -es \"" + $exportPath[0] + "\"";
651
+ eval $exportCmd;
652
+
653
+ setupNewExportSet($exportPath[0], $exportAnimOnly, $origSelection);
505
654
return;
506
655
}
507
656
0 commit comments