@@ -70,6 +70,106 @@ proc int loadUnityPlugin(string $plugin){
70
70
return true;
71
71
};
72
72
73
+ proc importFile(string $filePathStr){
74
+ // get the global variables
75
+ global string $UnityExportSets[];
76
+ global string $UnityFbxFilePathAttr;
77
+ global string $UnityFbxFileNameAttr;
78
+ global string $UnityFbxAnimFilePathAttr;
79
+ global string $UnityFbxAnimFileNameAttr;
80
+ global string $UnityExportSetNameFormat;
81
+
82
+ $tempPath = dirname($filePathStr);
83
+ $tempName = basename($filePathStr, "");
84
+ $tempAnimPath = "";
85
+ $tempAnimName = "";
86
+ $nameWithoutExt = basename($filePathStr, ".fbx");
87
+
88
+ $isAnimFile = false;
89
+ if(match("@", basename($filePathStr, ".fbx")) != ""){
90
+ // import as animation
91
+ $isAnimFile = true;
92
+ $tempAnimPath = $tempPath;
93
+ $tempAnimName = $tempName;
94
+
95
+ $nameWithoutExt = match("[^@]+", $nameWithoutExt);
96
+ }
97
+ $unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
98
+
99
+ // Gather everything that is in the scene
100
+ $origItemsInScene = `ls -tr -o -r true`;
101
+
102
+ // Get or create the Unity Fbx Export Set
103
+ $setCreated = false;
104
+ if (!setExists($unityExportSet)){
105
+ // couldn't find export set so create it
106
+ sets -name $unityExportSet;
107
+ $setCreated = true;
108
+ }
109
+
110
+ // unlock set so we can add attributes to it
111
+ lockNode -lock false $unityExportSet;
112
+
113
+ if(!$isAnimFile){
114
+ // reset attribute values, in case import fails
115
+ storeAttribute($unityExportSet, $UnityFbxFilePathAttr, "");
116
+ storeAttribute($unityExportSet, $UnityFbxFileNameAttr, "");
117
+ }
118
+
119
+ FBXImport -f $filePathStr;
120
+
121
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempPath != ""){
122
+ storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $tempPath);
123
+
124
+ // Change Unity project if fbx is from a different Unity project.
125
+ // Get the project based on the folder structure (i.e. folder above Assets)
126
+ $head = dirname($tempPath);
127
+ $tail = basename($tempPath, "");
128
+ // Check that we are not at the root directory.
129
+ // dirname($head) returns the last directory name in the path,
130
+ // or head if head is the root directory.
131
+ while ($head != "" && dirname($head) != $head){
132
+ if (`strcmp $tail "Assets"` == 0){
133
+ // this is a valid Unity project, so set it
134
+ optionVar -sv "UnityProject" $head;
135
+ break;
136
+ }
137
+ $head = dirname($head);
138
+ $tail = basename($head, "");
139
+ }
140
+ }
141
+
142
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempName != ""){
143
+ storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$tempName);
144
+ }
145
+
146
+ if($tempAnimPath != ""){
147
+ storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$tempAnimPath);
148
+ }
149
+
150
+ if($tempAnimName != ""){
151
+ storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$tempAnimName);
152
+ }
153
+
154
+ if (setExists($unityExportSet) == true){
155
+ // figure out what has been added after import
156
+ $itemsInScene = `ls -tr -o -r true`;
157
+
158
+ $newItems = stringArrayRemove($origItemsInScene, $itemsInScene);
159
+
160
+ // add newly imported items to set
161
+ if (size($newItems) > 0){
162
+ sets -include $unityExportSet $newItems;
163
+ }
164
+ // lock set so it doesn't get deleted when empty
165
+ lockNode -lock true $unityExportSet;
166
+
167
+ if(!stringArrayContains($unityExportSet, $UnityExportSets)){
168
+ $UnityExportSets[size($UnityExportSets)] = $unityExportSet;
169
+ }
170
+ }
171
+ }
172
+
73
173
74
174
global proc int loadUnityDependencies(){
75
175
// GamePipeline plugin 'SendToUnitySelection' command used in export
@@ -93,14 +193,6 @@ global proc int loadUnityDependencies(){
93
193
}
94
194
95
195
global proc unityImport(){
96
- // get the global variables
97
- global string $UnityExportSets[];
98
- global string $UnityFbxFilePathAttr;
99
- global string $UnityFbxFileNameAttr;
100
- global string $UnityFbxAnimFilePathAttr;
101
- global string $UnityFbxAnimFileNameAttr;
102
- global string $UnityExportSetNameFormat;
103
-
104
196
if(!loadUnityDependencies()){
105
197
error("Failed to load Unity dependencies");
106
198
return;
@@ -120,95 +212,7 @@ global proc unityImport(){
120
212
}
121
213
for($i=0; $i<size($filePaths); ++$i){
122
214
$filePathStr = $filePaths[$i];
123
- $tempPath = dirname($filePathStr);
124
- $tempName = basename($filePathStr, "");
125
- $tempAnimPath = "";
126
- $tempAnimName = "";
127
- $nameWithoutExt = basename($filePathStr, ".fbx");
128
-
129
- $isAnimFile = false;
130
- if(match("@", basename($filePathStr, ".fbx")) != ""){
131
- // import as animation
132
- $isAnimFile = true;
133
- $tempAnimPath = $tempPath;
134
- $tempAnimName = $tempName;
135
-
136
- $nameWithoutExt = match("[^@]+", $nameWithoutExt);
137
- }
138
- $unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
139
-
140
- // Gather everything that is in the scene
141
- $origItemsInScene = `ls -tr -o -r true`;
142
-
143
- // Get or create the Unity Fbx Export Set
144
- $setCreated = false;
145
- if (!setExists($unityExportSet)){
146
- // couldn't find export set so create it
147
- sets -name $unityExportSet;
148
- $setCreated = true;
149
- }
150
-
151
- // unlock set so we can add attributes to it
152
- lockNode -lock false $unityExportSet;
153
-
154
- if(!$isAnimFile){
155
- // reset attribute values, in case import fails
156
- storeAttribute($unityExportSet, $UnityFbxFilePathAttr, "");
157
- storeAttribute($unityExportSet, $UnityFbxFileNameAttr, "");
158
- }
159
-
160
- FBXImport -f $filePathStr;
161
-
162
- if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempPath != ""){
163
- storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $tempPath);
164
-
165
- // Change Unity project if fbx is from a different Unity project.
166
- // Get the project based on the folder structure (i.e. folder above Assets)
167
- $head = dirname($tempPath);
168
- $tail = basename($tempPath, "");
169
- // Check that we are not at the root directory.
170
- // dirname($head) returns the last directory name in the path,
171
- // or head if head is the root directory.
172
- while ($head != "" && dirname($head) != $head){
173
- if (`strcmp $tail "Assets"` == 0){
174
- // this is a valid Unity project, so set it
175
- optionVar -sv "UnityProject" $head;
176
- break;
177
- }
178
- $head = dirname($head);
179
- $tail = basename($head, "");
180
- }
181
- }
182
-
183
- if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempName != ""){
184
- storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$tempName);
185
- }
186
-
187
- if($tempAnimPath != ""){
188
- storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$tempAnimPath);
189
- }
190
-
191
- if($tempAnimName != ""){
192
- storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$tempAnimName);
193
- }
194
-
195
- if (setExists($unityExportSet) == true){
196
- // figure out what has been added after import
197
- $itemsInScene = `ls -tr -o -r true`;
198
-
199
- $newItems = stringArrayRemove($origItemsInScene, $itemsInScene);
200
-
201
- // add newly imported items to set
202
- if (size($newItems) > 0){
203
- sets -include $unityExportSet $newItems;
204
- }
205
- // lock set so it doesn't get deleted when empty
206
- lockNode -lock true $unityExportSet;
207
-
208
- if(!stringArrayContains($unityExportSet, $UnityExportSets)){
209
- $UnityExportSets[size($UnityExportSets)] = $unityExportSet;
210
- }
211
- }
215
+ importFile($filePathStr);
212
216
}
213
217
}
214
218
0 commit comments