Skip to content

Commit b083fa5

Browse files
committed
added function to convert names to be maya compatible
1 parent 87a78aa commit b083fa5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ protected int ExportComponents (
469469
{
470470
int numObjectsExported = exportProgress;
471471

472+
if (FbxExporters.EditorTools.ExportSettings.instance.mayaCompatibleNames) {
473+
unityGo.name = ConvertToMayaCompatibleName (unityGo.name);
474+
}
475+
472476
// create an FbxNode and add it as a child of parent
473477
FbxNode fbxNode = FbxNode.Create (fbxScene, unityGo.name);
474478
NumNodes++;
@@ -838,6 +842,11 @@ public Material Material {
838842
if (!renderer) {
839843
return null;
840844
}
845+
846+
if (FbxExporters.EditorTools.ExportSettings.instance.mayaCompatibleNames) {
847+
renderer.sharedMaterial.name = ConvertToMayaCompatibleName (renderer.sharedMaterial.name);
848+
}
849+
841850
// .material instantiates a new material, which is bad
842851
// most of the time.
843852
return renderer.sharedMaterial;
@@ -1011,6 +1020,42 @@ private static void EnsureDirectory (string path)
10111020
Directory.CreateDirectory (fileInfo.Directory.FullName);
10121021
}
10131022
}
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+
}
10141059
}
10151060
}
10161061
}

0 commit comments

Comments
 (0)