@@ -36,6 +36,10 @@ public class ModelExporter : System.IDisposable
36
36
37
37
const string ProgressBarTitle = "Fbx Export" ;
38
38
39
+ const char InvalidCharReplacement = '_' ;
40
+
41
+ const char MayaNamespaceSeparator = ':' ;
42
+
39
43
/// <summary>
40
44
/// Create instance of example
41
45
/// </summary>
@@ -469,6 +473,10 @@ protected int ExportComponents (
469
473
{
470
474
int numObjectsExported = exportProgress ;
471
475
476
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
477
+ unityGo . name = ConvertToMayaCompatibleName ( unityGo . name ) ;
478
+ }
479
+
472
480
// create an FbxNode and add it as a child of parent
473
481
FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
474
482
NumNodes ++ ;
@@ -838,6 +846,11 @@ public Material Material {
838
846
if ( ! renderer ) {
839
847
return null ;
840
848
}
849
+
850
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
851
+ renderer . sharedMaterial . name = ConvertToMayaCompatibleName ( renderer . sharedMaterial . name ) ;
852
+ }
853
+
841
854
// .material instantiates a new material, which is bad
842
855
// most of the time.
843
856
return renderer . sharedMaterial ;
@@ -1011,6 +1024,48 @@ private static void EnsureDirectory (string path)
1011
1024
Directory . CreateDirectory ( fileInfo . Directory . FullName ) ;
1012
1025
}
1013
1026
}
1027
+
1028
+ /// <summary>
1029
+ /// Removes the diacritics (i.e. accents) from letters.
1030
+ /// e.g. é becomes e
1031
+ /// </summary>
1032
+ /// <returns>Text with accents removed.</returns>
1033
+ /// <param name="text">Text.</param>
1034
+ private static string RemoveDiacritics ( string text )
1035
+ {
1036
+ var normalizedString = text . Normalize ( System . Text . NormalizationForm . FormD ) ;
1037
+ var stringBuilder = new System . Text . StringBuilder ( ) ;
1038
+
1039
+ foreach ( var c in normalizedString )
1040
+ {
1041
+ var unicodeCategory = System . Globalization . CharUnicodeInfo . GetUnicodeCategory ( c ) ;
1042
+ if ( unicodeCategory != System . Globalization . UnicodeCategory . NonSpacingMark )
1043
+ {
1044
+ stringBuilder . Append ( c ) ;
1045
+ }
1046
+ }
1047
+
1048
+ return stringBuilder . ToString ( ) . Normalize ( System . Text . NormalizationForm . FormC ) ;
1049
+ }
1050
+
1051
+ private static string ConvertToMayaCompatibleName ( string name )
1052
+ {
1053
+ string newName = RemoveDiacritics ( name ) ;
1054
+
1055
+ if ( char . IsDigit ( newName [ 0 ] ) ) {
1056
+ newName = newName . Insert ( 0 , InvalidCharReplacement . ToString ( ) ) ;
1057
+ }
1058
+
1059
+ for ( int i = 0 ; i < newName . Length ; i ++ ) {
1060
+ if ( ! char . IsLetterOrDigit ( newName , i ) ) {
1061
+ if ( i < newName . Length - 1 && newName [ i ] == MayaNamespaceSeparator ) {
1062
+ continue ;
1063
+ }
1064
+ newName = newName . Replace ( newName [ i ] , InvalidCharReplacement ) ;
1065
+ }
1066
+ }
1067
+ return newName ;
1068
+ }
1014
1069
}
1015
1070
}
1016
1071
}
0 commit comments