@@ -36,6 +36,8 @@ public class ModelExporter : System.IDisposable
36
36
37
37
const string ProgressBarTitle = "Fbx Export" ;
38
38
39
+ const char MayaNamespaceSeparator = ':' ;
40
+
39
41
// replace invalid chars with this string
40
42
const string InvalidCharReplacement = "_" ;
41
43
@@ -242,13 +244,13 @@ public void ExportTexture (Material unityMaterial, string unityPropName,
242
244
/// <summary>
243
245
/// Get the color of a material, or grey if we can't find it.
244
246
/// </summary>
245
- public FbxDouble3 GetMaterialColor ( Material unityMaterial , string unityPropName )
247
+ public FbxDouble3 ? GetMaterialColor ( Material unityMaterial , string unityPropName , float defaultValue = 1 )
246
248
{
247
249
if ( ! unityMaterial ) {
248
- return new FbxDouble3 ( 0.5 ) ;
250
+ return new FbxDouble3 ( defaultValue ) ;
249
251
}
250
252
if ( ! unityMaterial . HasProperty ( unityPropName ) ) {
251
- return new FbxDouble3 ( 0.5 ) ;
253
+ return new FbxDouble3 ( defaultValue ) ;
252
254
}
253
255
var unityColor = unityMaterial . GetColor ( unityPropName ) ;
254
256
return new FbxDouble3 ( unityColor . r , unityColor . g , unityColor . b ) ;
@@ -472,6 +474,10 @@ protected int ExportComponents (
472
474
{
473
475
int numObjectsExported = exportProgress ;
474
476
477
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
478
+ unityGo . name = ConvertToMayaCompatibleName ( unityGo . name ) ;
479
+ }
480
+
475
481
// create an FbxNode and add it as a child of parent
476
482
FbxNode fbxNode = FbxNode . Create ( fbxScene , unityGo . name ) ;
477
483
NumNodes ++ ;
@@ -844,6 +850,11 @@ public Material Material {
844
850
if ( ! renderer ) {
845
851
return null ;
846
852
}
853
+
854
+ if ( FbxExporters . EditorTools . ExportSettings . instance . mayaCompatibleNames ) {
855
+ renderer . sharedMaterial . name = ConvertToMayaCompatibleName ( renderer . sharedMaterial . name ) ;
856
+ }
857
+
847
858
// .material instantiates a new material, which is bad
848
859
// most of the time.
849
860
return renderer . sharedMaterial ;
@@ -1024,6 +1035,48 @@ private static void EnsureDirectory (string path)
1024
1035
}
1025
1036
}
1026
1037
1038
+ /// <summary>
1039
+ /// Removes the diacritics (i.e. accents) from letters.
1040
+ /// e.g. é becomes e
1041
+ /// </summary>
1042
+ /// <returns>Text with accents removed.</returns>
1043
+ /// <param name="text">Text.</param>
1044
+ private static string RemoveDiacritics ( string text )
1045
+ {
1046
+ var normalizedString = text . Normalize ( System . Text . NormalizationForm . FormD ) ;
1047
+ var stringBuilder = new System . Text . StringBuilder ( ) ;
1048
+
1049
+ foreach ( var c in normalizedString )
1050
+ {
1051
+ var unicodeCategory = System . Globalization . CharUnicodeInfo . GetUnicodeCategory ( c ) ;
1052
+ if ( unicodeCategory != System . Globalization . UnicodeCategory . NonSpacingMark )
1053
+ {
1054
+ stringBuilder . Append ( c ) ;
1055
+ }
1056
+ }
1057
+
1058
+ return stringBuilder . ToString ( ) . Normalize ( System . Text . NormalizationForm . FormC ) ;
1059
+ }
1060
+
1061
+ private static string ConvertToMayaCompatibleName ( string name )
1062
+ {
1063
+ string newName = RemoveDiacritics ( name ) ;
1064
+
1065
+ if ( char . IsDigit ( newName [ 0 ] ) ) {
1066
+ newName = newName . Insert ( 0 , InvalidCharReplacement . ToString ( ) ) ;
1067
+ }
1068
+
1069
+ for ( int i = 0 ; i < newName . Length ; i ++ ) {
1070
+ if ( ! char . IsLetterOrDigit ( newName , i ) ) {
1071
+ if ( i < newName . Length - 1 && newName [ i ] == MayaNamespaceSeparator ) {
1072
+ continue ;
1073
+ }
1074
+ newName = newName . Replace ( newName [ i ] , InvalidCharReplacement ) ;
1075
+ }
1076
+ }
1077
+ return newName ;
1078
+ }
1079
+
1027
1080
public static string ConvertToValidFilename ( string filename )
1028
1081
{
1029
1082
return System . Text . RegularExpressions . Regex . Replace ( filename , "[" + new string ( Path . GetInvalidFileNameChars ( ) ) + "]" , InvalidCharReplacement ) ;
0 commit comments