@@ -469,6 +469,10 @@ protected int ExportComponents (
469
469
{
470
470
int numObjectsExported = exportProgress ;
471
471
472
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
473
+ unityGo . name = ConvertToMayaCompatibleName ( unityGo . name ) ;
474
+ }
475
+
472
476
// create an FbxNode and add it as a child of parent
473
477
FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
474
478
NumNodes ++ ;
@@ -838,6 +842,11 @@ public Material Material {
838
842
if ( ! renderer ) {
839
843
return null ;
840
844
}
845
+
846
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
847
+ renderer . sharedMaterial . name = ConvertToMayaCompatibleName ( renderer . sharedMaterial . name ) ;
848
+ }
849
+
841
850
// .material instantiates a new material, which is bad
842
851
// most of the time.
843
852
return renderer . sharedMaterial ;
@@ -1011,6 +1020,42 @@ private static void EnsureDirectory (string path)
1011
1020
Directory . CreateDirectory ( fileInfo . Directory . FullName ) ;
1012
1021
}
1013
1022
}
1023
+
1024
+ private static string RemoveDiacritics ( string text )
1025
+ {
1026
+ var normalizedString = text . Normalize ( System . Text . NormalizationForm . FormD ) ;
1027
+ var stringBuilder = new System . Text . StringBuilder ( ) ;
1028
+
1029
+ foreach ( var c in normalizedString )
1030
+ {
1031
+ var unicodeCategory = System . Globalization . CharUnicodeInfo . GetUnicodeCategory ( c ) ;
1032
+ if ( unicodeCategory != System . Globalization . UnicodeCategory . NonSpacingMark )
1033
+ {
1034
+ stringBuilder . Append ( c ) ;
1035
+ }
1036
+ }
1037
+
1038
+ return stringBuilder . ToString ( ) . Normalize ( System . Text . NormalizationForm . FormC ) ;
1039
+ }
1040
+
1041
+ private static string ConvertToMayaCompatibleName ( string name )
1042
+ {
1043
+ string newName = RemoveDiacritics ( name ) ;
1044
+
1045
+ if ( char . IsDigit ( newName [ 0 ] ) ) {
1046
+ newName = newName . Insert ( 0 , "_" ) ;
1047
+ }
1048
+
1049
+ for ( int i = 0 ; i < newName . Length ; i ++ ) {
1050
+ if ( ! char . IsLetterOrDigit ( newName , i ) ) {
1051
+ if ( i < newName . Length - 1 && newName [ i ] == ':' ) {
1052
+ continue ;
1053
+ }
1054
+ newName = newName . Replace ( newName [ i ] , '_' ) ;
1055
+ }
1056
+ }
1057
+ return newName ;
1058
+ }
1014
1059
}
1015
1060
}
1016
1061
}
0 commit comments