Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
0
Question by EmmetOT · Mar 03, 2020 at 11:29 AM · editoreditor-scriptingfbxfbximportercontextmenu

Creating Context Menu Item for FBX files

I would like to add a context menu option for imported .FBX files. I previously had the same functionality in the AssetImporter, but I don't want this functionality to happen for all .FBXs imported. I don't want it to be automatic.

The specific functionality is just that I want to set the .FBX's animation clips' masks to 'create from this model' and set the avatar mask to every child bone.

Here's the method I used in the Asset Importer:

 /// <summary>
 /// Automatically set this model importer's mask type to 'CreateFromThisModel' and set the mask
 /// to the entire hierarchy.
 /// </summary>
 public static bool CreateMaskFromThisModel(this ModelImporter modelImporter, GameObject model)
 {
     bool changed = false;
 
     ModelImporterClipAnimation[] clips = modelImporter.clipAnimations;
 
     if (clips == null || clips.Length == 0)
         clips = modelImporter.defaultClipAnimations;
 
     ModelImporterClipAnimation[] newAnims = new ModelImporterClipAnimation[clips.Length];
 
     for (int i = 0; i < clips.Length; i++)
     {
         if (clips[i].maskType != ClipAnimationMaskType.CreateFromThisModel)
         {
             newAnims[i] = clips[i];
             newAnims[i].maskType = ClipAnimationMaskType.CreateFromThisModel;
 
             changed = true;
         }
     }
 
     AvatarMask mask = new AvatarMask();
     mask.AddTransformPath(model.transform, true);
 
     for (int i = 0; i < clips.Length; i++)
     {
         if (clips[i].maskSource == null || clips[i].maskSource.transformCount != mask.transformCount)
         {
             clips[i].ConfigureClipFromMask(mask);
             changed = true;
         }
     }
 
     modelImporter.clipAnimations = clips;
 
     return changed;
 }



This works. However, I seem to have no way to access the model importer after the import, at will. This is as far as I've gotten for my context menu.

 [MenuItem("Assets/Create Mask From This Model", isValidateFunction: true)]
 private static bool CheckIfFBX()
 {
     if (Selection.gameObjects.Length == 0)
         return false;
 
     for (int i = 0; i < Selection.gameObjects.Length; i++)
         if (!AssetDatabase.GetAssetPath(Selection.gameObjects[i]).ToLowerInvariant().EndsWith(".fbx"))
             return false;
 
     return true;
 }
 
 [MenuItem("Assets/Create Mask From This Model")]
 private static void CreateMaskFromThisModel()
 {
     for (int i = 0; i < Selection.gameObjects.Length; i++)
     {
         // get importer, clips, avatar mask, anything?
     }
 }


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

171 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

Related Questions

How to avoid 2019.3 FBX Import missing Inspector UI? 1 Answer

How to add items to the Component references context menu? 0 Answers

Adding to GameObject context menu WITHOUT [MenuItem(...)] 1 Answer

Unity soft locks on FBX Import,Unity Soft Locks on Import 0 Answers

applying toon shading to all 3d meshes at once 1 Answer


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