Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

AssetPostprocessor is failing to set ModelImporter.humanDescription mappings in Unity 2019

Discussion in 'Scripting' started by Airmouse, Mar 23, 2019.

  1. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    37
    in OnPreprocessModel where I get an instance of (ModelImporter) assetImporter; I used to be able to set the bone names for the avatar tpose setup. This worked great in 2018

    In 2019 however all .fbx avatars are automatically set in tpose and all bones are pre mapped without honoring the humanDescription overrides. Because of this, Unity is mapping to the wrong bones and all of my avatar's hands are strange.

    In Unity 2018 I simply set the importer.humanDescription from OnPreprocessModel, and they would remain.
    Code (csharp):
    1.  
    2.     private void OnPreprocessModel() {
    3.         //Load in the preconfigured avatar from the resources folder
    4.             Func<string, string, HumanLimit, HumanBone> Bone = (humanName, boneName, limit) => new HumanBone() {humanName = humanName, boneName = boneName, limit = limit};
    5.             var humanDesc = new HumanDescription {
    6.                 human = new[] {
    7.  
    8.                     Bone("Jaw",                       "jaw",          new HumanLimit() {max = new Vector3(0.0f, 10.0f, 10.0f), min = new Vector3(0.0f, -10.0f, -10.0f)}  ),
    9.                     Bone("LeftEye",                   "eye.L",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    10.                     Bone("RightEye",                  "eye.R",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    11.                                                                              
    12.                     Bone("Head",                      "neck02",       new HumanLimit() {max = new Vector3(40.0f, 40.0f ,40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    13.                     Bone("Neck",                      "neck01",       new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    14.                     Bone("UpperChest",                "spine01",      new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    15.                     Bone("Chest",                     "spine02",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    16.                     Bone("Spine",                     "spine04",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    17.                     Bone("Hips",                      "root",         new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    18.                                                                  
    19.                     Bone("Right Index Distal",        "finger2-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    20.                     Bone("Right Index Intermediate",  "finger2-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    21.                     Bone("Right Index Proximal",      "finger2-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    22.                     Bone("Right Middle Distal",       "finger3-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    23.                     Bone("Right Middle Intermediate", "finger3-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    24.                     Bone("Right Middle Proximal",     "finger3-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    25.                     Bone("Right Ring Distal",         "finger4-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    26.                     Bone("Right Ring Intermediate",   "finger4-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    27.                     Bone("Right Ring Proximal",       "finger4-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    28.                     Bone("Right Little Distal",       "finger5-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    29.                     Bone("Right Little Intermediate", "finger5-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    30.                     Bone("Right Little Proximal",     "finger5-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    31.                     Bone("Right Thumb Distal",        "finger1-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    32.                     Bone("Right Thumb Intermediate",  "finger1-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    33.                     Bone("Right Thumb Proximal",      "finger1-1.R",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    34.                                                                                        
    35.                     Bone("RightToes",                 "toe1-1.R",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    36.                     Bone("RightFoot",                 "foot.R",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    37.                     Bone("RightHand",                 "wrist.R",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    38.                                                                      
    39.                     Bone("RightLowerArm",             "lowerarm01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    40.                     Bone("RightLowerLeg",             "lowerleg01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    41.                     Bone("RightShoulder",             "shoulder01.R", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    42.                     Bone("RightUpperArm",             "upperarm01.R", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)} ),
    43.                     Bone("RightUpperLeg",             "upperleg01.R", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    44.                                                                      
    45.                     Bone("Left Index Distal",         "finger2-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    46.                     Bone("Left Index Intermediate",   "finger2-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    47.                     Bone("Left Index Proximal",       "finger2-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    48.                     Bone("Left Middle Distal",        "finger3-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    49.                     Bone("Left Middle Intermediate",  "finger3-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    50.                     Bone("Left Middle Proximal",      "finger3-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    51.                     Bone("Left Ring Distal",          "finger4-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    52.                     Bone("Left Ring Intermediate",    "finger4-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    53.                     Bone("Left Ring Proximal",        "finger4-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),    
    54.                     Bone("Left Little Distal",        "finger5-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    55.                     Bone("Left Little Intermediate",  "finger5-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    56.                     Bone("Left Little Proximal",      "finger5-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    57.                     Bone("Left Thumb Distal",         "finger1-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    58.                     Bone("Left Thumb Intermediate",   "finger1-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    59.                     Bone("Left Thumb Proximal",       "finger1-1.L",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    60.                                                                              
    61.                     Bone("LeftToes",                  "toe1-1.L",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    62.                     Bone("LeftFoot",                  "foot.L",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    63.                     Bone("LeftHand",                  "wrist.L",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    64.                                                      
    65.                     Bone("LeftLowerArm",              "lowerarm01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    66.                     Bone("LeftLowerLeg",              "lowerleg01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    67.                     Bone("LeftShoulder",              "shoulder01.L", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    68.                     Bone("LeftUpperArm",              "upperarm01.L", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)}  ),
    69.                     Bone("LeftUpperLeg",              "upperleg01.L", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    70.                 },
    71.             };
    72.             importer.humanDescription = humanDesc;
    73.         }
    74.     }
    75.  
    But now, running the same code in 2019 and the bone mappings remain as the defaults (which are incorrect).



    Please help me fix this!
     
    Last edited: Mar 23, 2019
  2. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    37
    I thought I solved my issue, not sure why but using OnPreprocessModel no longer works.

    However I now apply my templates from OnPostprocessAllAssets, I then reset the pose back to tpose using reflection:
    Code (csharp):
    1.  
    2.     static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    3.     {
    4.         foreach (string assetPath in importedAssets)
    5.         {    
    6.              //TODO ensure it is an .fbx first
    7.              MakeHumanAvatar (assetPath); //load template and set "enforce-tpose"
    8.          }
    9.      }
    10.  
    11.  
    12.  
    13.  
    14.     public static void MakeHumanAvatar(string avatarPath)
    15.     {
    16.  
    17.         Func<string, string, HumanLimit, HumanBone> Bone = (humanName, boneName, limit) => new HumanBone() {humanName = humanName, boneName = boneName, limit = limit};
    18.         var humanDesc = new HumanDescription {
    19.             human = new[] {
    20.  
    21.                 Bone("Jaw",                       "jaw",          new HumanLimit() {max = new Vector3(0.0f, 10.0f, 10.0f), min = new Vector3(0.0f, -10.0f, -10.0f)}  ),
    22.                 Bone("LeftEye",                   "eye.L",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    23.                 Bone("RightEye",                  "eye.R",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    24.  
    25.                 Bone("Head",                      "neck02",       new HumanLimit() {max = new Vector3(40.0f, 40.0f ,40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    26.                 Bone("Neck",                      "neck01",       new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    27.                 Bone("UpperChest",                "spine01",      new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    28.                 Bone("Chest",                     "spine02",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    29.                 Bone("Spine",                     "spine04",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    30.                 Bone("Hips",                      "root",         new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    31.  
    32.                 Bone("Right Index Distal",        "finger2-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    33.                 Bone("Right Index Intermediate",  "finger2-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    34.                 Bone("Right Index Proximal",      "finger2-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    35.                 Bone("Right Middle Distal",       "finger3-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    36.                 Bone("Right Middle Intermediate", "finger3-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    37.                 Bone("Right Middle Proximal",     "finger3-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    38.                 Bone("Right Ring Distal",         "finger4-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    39.                 Bone("Right Ring Intermediate",   "finger4-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    40.                 Bone("Right Ring Proximal",       "finger4-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    41.                 Bone("Right Little Distal",       "finger5-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    42.                 Bone("Right Little Intermediate", "finger5-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    43.                 Bone("Right Little Proximal",     "finger5-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    44.                 Bone("Right Thumb Distal",        "finger1-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    45.                 Bone("Right Thumb Intermediate",  "finger1-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    46.                 Bone("Right Thumb Proximal",      "finger1-1.R",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    47.  
    48.                 Bone("RightToes",                 "toe1-1.R",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    49.                 Bone("RightFoot",                 "foot.R",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    50.                 Bone("RightHand",                 "wrist.R",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    51.  
    52.                 Bone("RightLowerArm",             "lowerarm01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    53.                 Bone("RightLowerLeg",             "lowerleg01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    54.                 Bone("RightShoulder",             "shoulder01.R", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    55.                 Bone("RightUpperArm",             "upperarm01.R", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)} ),
    56.                 Bone("RightUpperLeg",             "upperleg01.R", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    57.  
    58.                 Bone("Left Index Distal",         "finger2-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    59.                 Bone("Left Index Intermediate",   "finger2-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    60.                 Bone("Left Index Proximal",       "finger2-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    61.                 Bone("Left Middle Distal",        "finger3-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    62.                 Bone("Left Middle Intermediate",  "finger3-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    63.                 Bone("Left Middle Proximal",      "finger3-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    64.                 Bone("Left Ring Distal",          "finger4-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    65.                 Bone("Left Ring Intermediate",    "finger4-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    66.                 Bone("Left Ring Proximal",        "finger4-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    67.                 Bone("Left Little Distal",        "finger5-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    68.                 Bone("Left Little Intermediate",  "finger5-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    69.                 Bone("Left Little Proximal",      "finger5-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    70.                 Bone("Left Thumb Distal",         "finger1-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    71.                 Bone("Left Thumb Intermediate",   "finger1-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    72.                 Bone("Left Thumb Proximal",       "finger1-1.L",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    73.  
    74.                 Bone("LeftToes",                  "toe1-1.L",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    75.                 Bone("LeftFoot",                  "foot.L",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    76.                 Bone("LeftHand",                  "wrist.L",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    77.  
    78.                 Bone("LeftLowerArm",              "lowerarm01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    79.                 Bone("LeftLowerLeg",              "lowerleg01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    80.                 Bone("LeftShoulder",              "shoulder01.L", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    81.                 Bone("LeftUpperArm",              "upperarm01.L", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)}  ),
    82.                 Bone("LeftUpperLeg",              "upperleg01.L", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    83.             },
    84.         };
    85.  
    86.         var modelImporter = AssetImporter.GetAtPath(avatarPath) as ModelImporter;
    87.         modelImporter.humanDescription = humanDesc;
    88.         modelImporter.userData = modelImporter.userData +  reimportTag;
    89.  
    90.  
    91.         var aEditorType = typeof(Editor).Assembly.GetType("UnityEditor.AvatarEditor");
    92.  
    93.         var asset = AssetDatabase.LoadAssetAtPath<Avatar> (avatarPath);
    94.  
    95.         var editor = Editor.CreateEditor(asset, aEditorType);
    96.  
    97.         var nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
    98.  
    99.  
    100.         aEditorType.GetMethod("SwitchToEditMode", nonPublicInstance).Invoke(editor, null);
    101.  
    102.         var mapperField = aEditorType.GetField("m_MappingEditor", nonPublicInstance);
    103.         var mapperType = mapperField.FieldType;
    104.         var mapper = mapperField.GetValue(editor);
    105.  
    106.         mapperType.GetMethod("MakePoseValid", nonPublicInstance).Invoke(mapper, null);
    107.         mapperType.GetMethod("Apply", nonPublicInstance).Invoke(mapper, null);
    108.  
    109.         aEditorType.GetMethod("SwitchToAssetMode", nonPublicInstance).Invoke(editor, new object[] {false});
    110.     }
    111.  


    This is still broken as it reverts back after running SaveAndReimport()

    I could still really use some help understanding why I cant use OnPreprocessModel as I have been in 2018? Unity is now very persistent about changing mappings, it's impossible to automate.

    [EDIT]

    I think this is all related to some kind of bug because I see that when I print the values of the animator's bones they are not the same as the bones in the tpose mappings. So something is definitely not being applied somewhere,

    I can easily resolve by editing tpose mappings manually, just to hit apply is all, then everything is consistent. However this is not an options as it is a manual process.

    Please help!
     
    Last edited: Mar 23, 2019
  3. Airmouse

    Airmouse

    Joined:
    Jan 12, 2019
    Posts:
    37
    Its strange, after running my postprocessor I can see that animations apply perfectly, as if my HumanDescription template was applied correctly.

    But when calling `animator.GetBoneTransform(HumanBodyBones)` to retreive the bone transform, it returns the bones from my first example instead of the bones currently set in tpose editor.

    It's as if Unity is using both sets of bones simultaneous o_O.

    Currently I must hack around this, I have created my own list of HumanBodyBones which is aligned with the HumanDescription template, so after my postprocessor is finished, I have a reliable list of the actual bones being used:

    Code (csharp):
    1.     public struct MakeHumanMapping {
    2.         public HumanBone[] human;
    3.         public HumanBodyBones[] boneType;
    4.     };
    5.  
    6. public static MakeHumanMapping mappings = new MakeHumanMapping {
    7.         human = new[] {
    8.             Bone("Jaw",                       "jaw",          new HumanLimit() {max = new Vector3(0.0f, 10.0f, 10.0f), min = new Vector3(0.0f, -10.0f, -10.0f)}  ),
    9.             Bone("LeftEye",                   "eye.L",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    10.             Bone("RightEye",                  "eye.R",        new HumanLimit() {max = new Vector3(0.0f, 20.0f, 15.0f), min = new Vector3(0.0f, -20.0f, -10.0f)}  ),
    11.  
    12.             Bone("Head",                      "neck02",       new HumanLimit() {max = new Vector3(40.0f, 40.0f ,40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    13.             Bone("Neck",                      "neck01",       new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    14.             Bone("UpperChest",                "spine01",      new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    15.             Bone("Chest",                     "spine02",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    16.             Bone("Spine",                     "spine04",      new HumanLimit() {max = new Vector3(40.0f, 40.0f, 40.0f), min = new Vector3(-40.0f, -40.0f, -40.0f)}  ),
    17.             Bone("Hips",                      "root",         new HumanLimit() {max = new Vector3(0.0f, 0.0f, 0.0f), min = new Vector3(0.0f, 0.0f, 0.0f)}  ),
    18.  
    19.             Bone("Right Index Distal",        "finger2-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    20.             Bone("Right Index Intermediate",  "finger2-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    21.             Bone("Right Index Proximal",      "finger2-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    22.             Bone("Right Middle Distal",       "finger3-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    23.             Bone("Right Middle Intermediate", "finger3-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    24.             Bone("Right Middle Proximal",     "finger3-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    25.             Bone("Right Ring Distal",         "finger4-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    26.             Bone("Right Ring Intermediate",   "finger4-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    27.             Bone("Right Ring Proximal",       "finger4-1.R",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    28.             Bone("Right Little Distal",       "finger5-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    29.             Bone("Right Little Intermediate", "finger5-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    30.             Bone("Right Little Proximal",     "finger5-1.R",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    31.             Bone("Right Thumb Distal",        "finger1-3.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    32.             Bone("Right Thumb Intermediate",  "finger1-2.R",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    33.             Bone("Right Thumb Proximal",      "finger1-1.R",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    34.  
    35.             Bone("RightToes",                 "toe1-1.R",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    36.             Bone("RightFoot",                 "foot.R",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    37.             Bone("RightHand",                 "wrist.R",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    38.  
    39.             Bone("RightLowerArm",             "lowerarm01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    40.             Bone("RightLowerLeg",             "lowerleg01.R", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    41.             Bone("RightShoulder",             "shoulder01.R", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    42.             Bone("RightUpperArm",             "upperarm01.R", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)} ),
    43.             Bone("RightUpperLeg",             "upperleg01.R", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    44.  
    45.             Bone("Left Index Distal",         "finger2-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    46.             Bone("Left Index Intermediate",   "finger2-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    47.             Bone("Left Index Proximal",       "finger2-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f,-50.0f)}  ),
    48.             Bone("Left Middle Distal",        "finger3-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    49.             Bone("Left Middle Intermediate",  "finger3-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    50.             Bone("Left Middle Proximal",      "finger3-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),
    51.             Bone("Left Ring Distal",          "finger4-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    52.             Bone("Left Ring Intermediate",    "finger4-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    53.             Bone("Left Ring Proximal",        "finger4-1.L",  new HumanLimit() {max = new Vector3(0.0f, 7.5f, 50.0f), min = new Vector3(0.0f, -7.5f, -50.0f)}  ),  
    54.             Bone("Left Little Distal",        "finger5-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    55.             Bone("Left Little Intermediate",  "finger5-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 45.0f), min = new Vector3(0.0f, 0.0f, -45.0f)}  ),
    56.             Bone("Left Little Proximal",      "finger5-1.L",  new HumanLimit() {max = new Vector3(0.0f, 20.0f, 50.0f), min = new Vector3(0.0f, -20.0f, -50.0f)}  ),
    57.             Bone("Left Thumb Distal",         "finger1-3.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    58.             Bone("Left Thumb Intermediate",   "finger1-2.L",  new HumanLimit() {max = new Vector3(0.0f, 0.0f, 35.0f), min = new Vector3(0.0f, 0.0f, -40.0f)}  ),
    59.             Bone("Left Thumb Proximal",       "finger1-1.L",  new HumanLimit() {max = new Vector3(0.0f, 25.0f, 20.0f), min = new Vector3(0.0f, -25.0f, -20.0f)}  ),
    60.  
    61.             Bone("LeftToes",                  "toe1-1.L",     new HumanLimit() {max = new Vector3(0.0f, 0.0f, 50.0f), min = new Vector3(0.0f, 0.0f, -50.0f)}  ),
    62.             Bone("LeftFoot",                  "foot.L",       new HumanLimit() {max = new Vector3(0.0f, 30.0f, 50.0f), min = new Vector3(0.0f, -30.0f, -50.0f)}  ),
    63.             Bone("LeftHand",                  "wrist.L",      new HumanLimit() {max = new Vector3(0.0f, 40.0f, 80.0f), min = new Vector3(0.0f, -40.0f, -80.0f)}  ),
    64.  
    65.             Bone("LeftLowerArm",              "lowerarm01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    66.             Bone("LeftLowerLeg",              "lowerleg01.L", new HumanLimit() {max = new Vector3(90.0f, 0.0f, 80.0f), min = new Vector3(-90.0f, 0.0f, -80.0f)}  ),
    67.             Bone("LeftShoulder",              "shoulder01.L", new HumanLimit() {max = new Vector3(0.0f, 15.0f, 30.0f), min = new Vector3(0.0f, -15.0f, -15.0f)}  ),
    68.             Bone("LeftUpperArm",              "upperarm01.L", new HumanLimit() {max = new Vector3(90.0f, 100.0f, 100.0f), min = new Vector3(-90.0f, -100.0f, -60.0f)}  ),
    69.             Bone("LeftUpperLeg",              "upperleg01.L", new HumanLimit() {max = new Vector3(60.0f, 60.0f, 50.0f), min = new Vector3(-60.0f, -60.0f, -90.0f)}  ),
    70.         },
    71.         boneType = new HumanBodyBones[] {
    72.             HumanBodyBones.Jaw,
    73.             HumanBodyBones.LeftEye,
    74.             HumanBodyBones.RightEye,
    75.  
    76.             HumanBodyBones.Head,
    77.             HumanBodyBones.Neck,
    78.             HumanBodyBones.UpperChest,
    79.             HumanBodyBones.Chest,
    80.             HumanBodyBones.Spine,
    81.             HumanBodyBones.Hips,
    82.  
    83.             HumanBodyBones.RightIndexDistal,
    84.             HumanBodyBones.RightIndexIntermediate,
    85.             HumanBodyBones.RightIndexProximal,
    86.             HumanBodyBones.RightMiddleDistal,
    87.             HumanBodyBones.RightMiddleIntermediate,
    88.             HumanBodyBones.RightMiddleProximal,
    89.             HumanBodyBones.RightRingDistal,
    90.             HumanBodyBones.RightRingIntermediate,
    91.             HumanBodyBones.RightRingProximal,
    92.             HumanBodyBones.RightLittleDistal,
    93.             HumanBodyBones.RightLittleIntermediate,
    94.             HumanBodyBones.RightLittleProximal,
    95.             HumanBodyBones.RightThumbDistal,
    96.             HumanBodyBones.RightThumbIntermediate,
    97.             HumanBodyBones.RightThumbProximal,
    98.  
    99.             HumanBodyBones.RightToes,
    100.             HumanBodyBones.RightFoot,
    101.             HumanBodyBones.RightHand,
    102.  
    103.             HumanBodyBones.RightLowerArm,
    104.             HumanBodyBones.RightLowerLeg,
    105.             HumanBodyBones.RightShoulder,
    106.             HumanBodyBones.RightUpperArm,
    107.             HumanBodyBones.RightUpperLeg,
    108.  
    109.             HumanBodyBones.LeftIndexDistal,
    110.             HumanBodyBones.LeftIndexIntermediate,
    111.             HumanBodyBones.LeftIndexProximal,
    112.             HumanBodyBones.LeftMiddleDistal,
    113.             HumanBodyBones.LeftMiddleIntermediate,
    114.             HumanBodyBones.LeftMiddleProximal,
    115.             HumanBodyBones.LeftRingDistal,
    116.             HumanBodyBones.LeftRingIntermediate,
    117.             HumanBodyBones.LeftRingProximal,
    118.             HumanBodyBones.LeftLittleDistal,
    119.             HumanBodyBones.LeftLittleIntermediate,
    120.             HumanBodyBones.LeftLittleProximal,
    121.             HumanBodyBones.LeftThumbDistal,
    122.             HumanBodyBones.LeftThumbIntermediate,
    123.             HumanBodyBones.LeftThumbProximal,
    124.  
    125.             HumanBodyBones.LeftToes,
    126.             HumanBodyBones.LeftFoot,
    127.             HumanBodyBones.LeftHand,
    128.  
    129.             HumanBodyBones.LeftLowerArm,
    130.             HumanBodyBones.LeftLowerLeg,
    131.             HumanBodyBones.LeftShoulder,
    132.             HumanBodyBones.LeftUpperArm,
    133.             HumanBodyBones.LeftUpperLeg,
    134.         }
    135.  
    136.     };
    137.  
    138. }
    I still feel like this reveals a rather large bug, as most postprocessor model importing relies heavily on being able to adjust the bone mappings,

    Please, if anyone knows why this is happening, I desperately would like to fix this instead of carefully hacking around it!
     
    Last edited: Mar 24, 2019