@@ -111,20 +111,19 @@ proc string getNewNamespace(string $n1, string $n2){
111
111
return $newNamespace;
112
112
}
113
113
114
- proc checkNamespaceNeedsUpdate(string $unitySet, string $objectNamespace){
115
- global string $UnityFbxNamespaceAttr;
116
-
117
- string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
118
- string $newNamespace = getNewNamespace($unity_fbx_namespace, $objectNamespace);
119
- if($unity_fbx_namespace != $newNamespace){
114
+ proc string checkNamespaceNeedsUpdate(string $unitySet, string $unityFbxNamespace, string $objectNamespace){
115
+ string $newNamespace = getNewNamespace($unityFbxNamespace, $objectNamespace);
116
+ if($unityFbxNamespace != $newNamespace){
120
117
// popup asking to change namespace value to new namespace
121
118
if(showConfirmDialog($unitySet,
122
- "Set namespace has been modified from "+$unity_fbx_namespace +" to "+$newNamespace+", update export set namespace attribute?",
119
+ "Set namespace has been modified from "+$unityFbxNamespace +" to "+$newNamespace+", update export set namespace attribute?",
123
120
"Yes", "No"
124
121
)){
125
122
storeAttribute($unitySet, $UnityFbxNamespaceAttr, $newNamespace);
123
+ return $newNamespace;
126
124
}
127
125
}
126
+ return $unityFbxNamespace;
128
127
}
129
128
130
129
proc importFile(string $filePathStr){
@@ -136,36 +135,37 @@ proc importFile(string $filePathStr){
136
135
global string $UnityFbxAnimFileNameAttr;
137
136
global string $UnityFbxNamespaceAttr;
138
137
global string $UnityExportSetNameFormat;
139
-
140
- $tempPath = dirname($filePathStr);
141
- $tempName = basename($filePathStr, "");
142
- $tempAnimPath = "";
143
- $tempAnimName = "";
144
- $nameWithoutExt = basename($filePathStr, ".fbx");
138
+
139
+ $currentDir = dirname($filePathStr);
140
+ $fileName = basename($filePathStr, "");
141
+ $currentAnimDir = "";
142
+ $animFileName = "";
143
+ $fileNameWithoutExt = basename($filePathStr, ".fbx");
145
144
146
145
$isAnimFile = false;
147
146
if(match("@", basename($filePathStr, ".fbx")) != ""){
148
147
// import as animation
149
148
$isAnimFile = true;
150
- $tempAnimPath = $tempPath ;
151
- $tempAnimName = $tempName ;
149
+ $currentAnimDir = $currentDir ;
150
+ $animFileName = $fileName ;
152
151
153
- $nameWithoutExt = match("[^@]+", $nameWithoutExt );
152
+ $fileNameWithoutExt = match("[^@]+", $fileNameWithoutExt );
154
153
}
155
- $unityExportSet = `format -stringArg $nameWithoutExt $UnityExportSetNameFormat`;
154
+ $unityExportSet = `format -stringArg $fileNameWithoutExt $UnityExportSetNameFormat`;
156
155
157
156
string $origNamespace = `namespaceInfo -cur -an`;
158
- string $targetNamespace = `format -s $origNamespace -s $nameWithoutExt "^1s:^2s"`;
157
+ string $targetNamespace = `format -s $origNamespace -s $fileNameWithoutExt "^1s:^2s"`;
159
158
160
159
$setNamespaceExists = false;
161
160
if (setExists($unityExportSet)){
162
161
string $unitySetContents[] = `listConnections $unityExportSet`;
163
- if(size($unitySetContents) > 0){
164
- checkNamespaceNeedsUpdate($unityExportSet, getObjectNamespace($unitySetContents[0]));
165
- }
166
162
167
163
// get namespace from set
168
164
$setNamespace = getAttribute($unityExportSet, $UnityFbxNamespaceAttr);
165
+ if(size($unitySetContents) > 0){
166
+ $setNamespace = checkNamespaceNeedsUpdate($unityExportSet, $setNamespace, getObjectNamespace($unitySetContents[0]));
167
+ }
168
+
169
169
if($setNamespace != "" && `namespace -exists $setNamespace`){
170
170
$targetNamespace = $setNamespace;
171
171
$setNamespaceExists = true;
@@ -175,8 +175,8 @@ proc importFile(string $filePathStr){
175
175
// warn if namespace already exists
176
176
if(!$setNamespaceExists){
177
177
if(`namespace -exists $targetNamespace`){
178
- if(!showConfirmDialog("Warning" ,
179
- "Namespace already exists, the imported objects will be added to the existing namespace and export set.",
178
+ if(!showConfirmDialog("Warning: " + $fileName ,
179
+ $targetNamespace + " namespace already exists, the imported objects will be added to the existing namespace and export set.",
180
180
"Continue", "Cancel"
181
181
)){
182
182
// cancelled, don't import this fbx
@@ -222,23 +222,23 @@ proc importFile(string $filePathStr){
222
222
namespace -set $origNamespace;
223
223
}
224
224
225
- if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempPath != ""){
226
- storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $tempPath );
225
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $currentDir != ""){
226
+ storeAttribute($unityExportSet, $UnityFbxFilePathAttr, $currentDir );
227
227
}
228
228
229
- if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $tempName != ""){
230
- storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$tempName );
229
+ if ((!$isAnimFile || ($isAnimFile && $setCreated)) && $fileName != ""){
230
+ storeAttribute($unityExportSet,$UnityFbxFileNameAttr,$fileName );
231
231
}
232
232
233
- if($tempAnimPath != ""){
234
- storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$tempAnimPath );
233
+ if($currentAnimDir != ""){
234
+ storeAttribute($unityExportSet,$UnityFbxAnimFilePathAttr,$currentAnimDir );
235
235
}
236
236
237
- if($tempAnimName != ""){
238
- storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$tempAnimName );
237
+ if($animFileName != ""){
238
+ storeAttribute($unityExportSet,$UnityFbxAnimFileNameAttr,$animFileName );
239
239
}
240
240
241
- if($nameWithoutExt != ""){
241
+ if($fileNameWithoutExt != ""){
242
242
storeAttribute($unityExportSet, $UnityFbxNamespaceAttr, $targetNamespace);
243
243
}
244
244
@@ -306,11 +306,11 @@ global proc unityImport(){
306
306
importFile($filePathStr);
307
307
}
308
308
309
- $tempPath = dirname($filePaths[0]);
309
+ $currentDir = dirname($filePaths[0]);
310
310
// Change Unity project if fbx is from a different Unity project.
311
311
// Get the project based on the folder structure (i.e. folder above Assets)
312
- $head = dirname($tempPath );
313
- $tail = basename($tempPath , "");
312
+ $head = dirname($currentDir );
313
+ $tail = basename($currentDir , "");
314
314
// Check that we are not at the root directory.
315
315
// dirname($head) returns the last directory name in the path,
316
316
// or head if head is the root directory.
@@ -349,10 +349,10 @@ proc exportSet(string $unitySet, int $exportAnim){
349
349
global string $UnityFbxNamespaceAttr;
350
350
351
351
string $unitySetContents[] = `listConnections $unitySet`;
352
- string $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
352
+ string $unityFbxNamespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
353
353
354
354
if(size($unitySetContents) > 0){
355
- checkNamespaceNeedsUpdate($unitySet, getObjectNamespace($unitySetContents[0]));
355
+ $unityFbxNamespace = checkNamespaceNeedsUpdate($unitySet, $unityFbxNamespace , getObjectNamespace($unitySetContents[0]));
356
356
}
357
357
358
358
string $animatedObjectSet = "";
@@ -378,13 +378,14 @@ proc exportSet(string $unitySet, int $exportAnim){
378
378
$nameAttr = $UnityFbxAnimFileNameAttr;
379
379
}
380
380
381
- string $unity_fbx_file_path = getAttribute($unitySet, $pathAttr);
382
- string $unity_fbx_file_name = getAttribute($unitySet, $nameAttr);
383
- $unity_fbx_namespace = getAttribute($unitySet, $UnityFbxNamespaceAttr);
381
+ string $unityFbxFilePath = getAttribute($unitySet, $pathAttr);
382
+ string $unityFbxFileName = getAttribute($unitySet, $nameAttr);
384
383
385
384
$strCmd = "";
386
- if ($unity_fbx_file_path != "" && $unity_fbx_file_name != ""){
387
- $strCmd = `format -s $unity_fbx_namespace -s $unity_fbx_file_path -s $unity_fbx_file_name "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" -es \"^2s/^3s\""`;
385
+ if ($unityFbxFilePath != "" && $unityFbxFileName != ""){
386
+ // export selected, relative to given namespace
387
+ string $exportFormat = "file -force -options \"\" -typ \"FBX export\" -relativeNamespace \"^1s\" -es \"^2s/^3s\"";
388
+ $strCmd = `format -s $unityFbxNamespace -s $unityFbxFilePath -s $unityFbxFileName $exportFormat`;
388
389
eval $strCmd;
389
390
}
390
391
0 commit comments