Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to cleanup Mixamo bone names?

Discussion in 'Animation' started by agnis16, Jun 6, 2022.

  1. agnis16

    agnis16

    Joined:
    Aug 1, 2018
    Posts:
    3
    Hi, I'm trying out to clean up paths in animations so I can be worry-less about animation importing. I'd like to manipulate the original FBX file. In the worst case, I can import in scene rename objects and create a prefab.

    I attached the script I tried. It goes over FBX bones but it doesn't really manipulate the file. Can someone suggest a better solution?
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6. using UnityEditor.Animations;
    7. using System.IO;
    8.  
    9. public class MixamoCleanFBX : MonoBehaviour
    10. {
    11.     [MenuItem("Assets/Mixamo clean bone names", true)]
    12.     static public bool MixamoCleanValidate() => Selection.activeObject == null ? false : Path.GetExtension(AssetDatabase.GetAssetPath(Selection.activeObject)) == ".fbx";
    13.  
    14.     [MenuItem("Assets/Mixamo clean bone names")]
    15.     static public void MixamoClean()
    16.     {
    17.         GameObject go = (GameObject)Selection.activeObject;
    18.         if (go == null) { return; }
    19.  
    20.         UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(Selection.activeObject));
    21.         string newName;
    22.         bool pastCol;
    23.         foreach (UnityEngine.Object obj in objects)
    24.         {
    25.             if (obj.name.Contains("mixamorig"))
    26.             {
    27.                 newName = "";
    28.                 pastCol = false;
    29.                 for (int i = 0; i < obj.name.Length; i++)
    30.                 {
    31.                     if (pastCol)
    32.                     {
    33.                         newName += obj.name[i];
    34.                     }
    35.                     else if (obj.name[i] == ':') { pastCol = true; }
    36.                 }
    37.                 obj.name = newName;
    38.                 Debug.Log(newName);
    39.             }
    40.         }
    41.         EditorUtility.SetDirty(go);
    42.         AssetDatabase.SaveAssets();
    43.         AssetDatabase.Refresh();
    44.  
    45.     }
    46. }
    47.  
     

    Attached Files: