Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by NPSimulation · Nov 04, 2021 at 09:53 AM · animationeditoravatarassetdatabase

Automatically disabling model's facial bones for body-only animations,Disabling bones for non-facial animations automatically

Hi!

I have hundred of high-quality models (from renderpeople.com) that come originally with animations that move both the body and the face of the models. I also want to play animations (from mixamo.com) on these models. The thing is that these animations are limited to the body and not the facial bones. Therefore when playing the animations, the model's face always has a stupid default pose like for this example model.


stupid default pose


Now I found out that disabling some transforms (neck, left eye, right eye, jaw) from the Avatar Definition makes the model's default expression much nicer but iterating manually through hundred of models really isn't that smart.


avatar definition


I'm working on an editor script to import all these models and configure them in one click and I'm stuck on this point. Does anyone have an idea of how to do it?

So far my approach was to create a copy of each model, this time with avatar with these bones disabled but for some reason my modifications aren't taken into account and the avatar stays the same. If you know why this change isn't taken into account or have a better approach I would be very grateful.

By the way, I had to comment the neck from the list of skeletonNamesToRemove because AvatarBuilder.BuildHumanAvatar would log an error message saying that the neck is required. That's strange since it can be manually disabled without problem from the avatar window.

Thanks in advance!


 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using UnityEditor;
 using UnityEngine;
 using UnityEngine.Perception.GroundTruth;
 
 [ExecuteInEditMode]
 public class CharactersImportation : MonoBehaviour
 {
     public Transform InstantiatedCharactersParent = null;
     public float InstantiationDist = 1.5f;
     static int instantiatedObjectIndex = 0;
     private string[] skeletonNamesToRemove = new string[] {/*"neck",*/ "eye_l", "eye_r", "jaw"};
     private string[] humanNamesToRemove = new string[] {"Neck", "LeftEye", "RightEye", "Jaw"};
 
 
     public void CreateNonFaciallyAnimatedAvatarsForAllCharacters()
     {
         string mainFolder = "Assets/RP_Character";
 
         Debug.Log("Starting procedure");
         CreateNonFaciallyAnimatedAvatarsRec(mainFolder);
     }
 
     void CreateNonFaciallyAnimatedAvatarsRec(string path)
     {
         string[] dirs = Directory.GetDirectories(path);
         string[] files = Directory.GetFiles(path);
 
         foreach (string f in files)
         if (f.Contains("FixedExpression"))//skip the ones already done manually
         {
             return;
         }
         foreach (string f in files)
         {
             if (instantiatedObjectIndex >= 1)//while testing, limits this script to the first character of the list
                 return;
             if (Path.GetExtension(f) == ".fbx")
             {
                 string FixedExpressionName = f.Substring(0, f.Length - 4) + "_FixedExpression.fbx";
 
                 if (!AssetDatabase.CopyAsset(f, FixedExpressionName))//Substring -4 is to remove ".fbx"
                     Debug.LogError($"Failed to copy {f}");
                 else
                     Debug.Log($"Created {f + "_FixedExpression"}");
                 instantiatedObjectIndex++;
                 GameObject g = AssetDatabase.LoadAssetAtPath(FixedExpressionName, typeof(GameObject)) as GameObject;
                 Avatar FEA = g.GetComponent<Animator>().avatar;
                 Debug.Log("Found avatar named: " + FEA.name);
                 HumanBone[] headlessHuman = new HumanBone[FEA.humanDescription.human.Length - humanNamesToRemove.Length];
 
                 int copiedBonesIndex = 0;
                 foreach (HumanBone b in FEA.humanDescription.human)
                 {
                     bool badBoneFound = false;
                     foreach (string bone in humanNamesToRemove)
                     {
                         if (bone == b.humanName)
                         {
                             //Debug.LogWarning("Found bone to discard: " + b.humanName);
                             badBoneFound = true;
                         }
                     }
                     if (badBoneFound == false)
                     {
                         //Debug.Log("Acceptable will be copied at index" + copiedBonesIndex);
                         headlessHuman[copiedBonesIndex] = new HumanBone
                         {
                             humanName = b.humanName,
                             boneName = b.boneName,
                             limit = b.limit
                         };
                         copiedBonesIndex++;
                     }
                 }
                 //////////////////////////////////////////////////////// skeleton
                 SkeletonBone[] headlessSkeleton = new SkeletonBone[FEA.humanDescription.skeleton.Length - skeletonNamesToRemove.Length];
                 copiedBonesIndex = 0;
                 foreach (SkeletonBone b in FEA.humanDescription.skeleton)
                 {
                     bool badBoneFound = false;
                     foreach (string bone in skeletonNamesToRemove)
                     {
                         if (bone == b.name)
                         {
                             //Debug.LogWarning("Found bone to discard: " + b.humanName);
                             badBoneFound = true;
                         }
                     }
                     if (badBoneFound == false)
                     {
                         //Debug.Log("Acceptable will be copied at index" + copiedBonesIndex);
                         headlessSkeleton[copiedBonesIndex] = new SkeletonBone
                         {
                             name = b.name,
                             position = b.position,
                             rotation = b.rotation,
                             scale = b.scale
                         };
                         //Debug.Log("Acceptable bone copied " + headlessBones[copiedBonesIndex].humanName);
                         copiedBonesIndex++;
                     }
                 }
 
                 HumanDescription description = new HumanDescription()
                 {
                     armStretch = FEA.humanDescription.armStretch,
                     feetSpacing = FEA.humanDescription.feetSpacing,
                     hasTranslationDoF = FEA.humanDescription.hasTranslationDoF,
                     legStretch = FEA.humanDescription.legStretch,
                     lowerArmTwist = FEA.humanDescription.lowerArmTwist,
                     lowerLegTwist = FEA.humanDescription.lowerLegTwist,
                     upperArmTwist = FEA.humanDescription.upperArmTwist,
                     upperLegTwist = FEA.humanDescription.upperLegTwist,
                     skeleton = headlessSkeleton,
                     human = headlessHuman,
                 };
                 FEA = AvatarBuilder.BuildHumanAvatar(g, description);
                 g.GetComponent<Animator>().avatar = FEA;
                 AssetDatabase.SaveAssets();
             }
         }
         foreach (string d in dirs)
         {
             if (d.Contains("_rigged_"))//check this is a character sub folder and not something related to animations or something else
                 CreateNonFaciallyAnimatedAvatarsRec(d);
         }
     }
 }










step2removeavatarheadsubtransforms.png (32.9 kB)
defaultlook.png (219.9 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

345 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a Avatar Mask for 2D skeletal Animation? 0 Answers

Animate cannon with artillerymen 0 Answers

How to copy and paste animation events from one clip to another if those clips are included in FBXs? 1 Answer

Model does not play animation 0 Answers

A game like KendallKylie? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges