EdyJ / blender-to-unity3d-importer

Advanced Blender to Unity 3D model importer
MIT License
141 stars 34 forks source link

I succeeded to get Generic Animation Clips. #8

Open tompsono opened 4 years ago

tompsono commented 4 years ago

Are you updating this importer,yet? This importer is very useul.

This importer supports only Legacy Animation Clips, but by this code, you can get Generic Animation Clips. It works good for me.

// from https://forum.unity.com/threads/getting-animationclip-from-fbx-in-the-editor-mecanim.295229/

    public IEnumerable<AnimationClip> GetAnimationClip(GameObject go)
    {
      AnimationClip[] clips = AnimationUtility.GetAnimationClips(go);

      if (clips.Length == 0)
      {
        clips = Object.FindObjectsOfType<AnimationClip>();
      }

      HashSet<string> importClipName = new HashSet<string>();
      ModelImporter modelImporter = assetImporter as ModelImporter;

      for (int i = 0; i < modelImporter.defaultClipAnimations.Length; ++i)
      {
        importClipName.Add(modelImporter.defaultClipAnimations[i].name);
      }

      for (int i = 0; i < clips.Length; ++i)
      {
        AnimationClip clip = clips[i];
        if (clip != null &&
            importClipName.Contains(clip.name) &&
            !EditorUtility.IsPersistent(clip))
        {
            yield return clip;
        }
      }
    }
EdyJ commented 4 years ago

Hello! Thank you for your contribution, and sorry for the late reply.

I'm not using this importer anymore because I can't include the Blender models in my packages. These must be FBX files so people can import them without having Blender installed.

So I made an FBX Exporter add-on that fixed the rotations in the Blender side and exports a FBX file that is imported into Unity perfectly, without undesired rotations. Please check it out:

https://github.com/EdyJ/blender-to-unity-fbx-exporter

I haven't tested it with animations or armatures. Feel free to give it a try and let me know if/how it works.