zoukankan      html  css  js  c++  java
  • unity从模型中抽取动画文件(animation)

    http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html

    由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文件(read-ony),比如为动画绑定事件,所以要把模型中的动画文件抽取出来,这样文件是可写的了。抽取动画文件的脚本非本人所写,贴在此处大家分享。---unity3d

    using UnityEditor;
    using UnityEngine;
    using System.IO;
    
    public class CurvesTransferer
    {
        [MenuItem("Character Generator/Transfer Clip Curves to Copy")]
        static void CopyClip()
        {
            foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
            {
                if (!(o is GameObject)) continue;
                if (!o.name.Contains("@")) continue;
                GameObject animationFBX = (GameObject)o;
    
                AnimationClip srcClip = animationFBX.animation.clip;
                AnimationClip newClip = new AnimationClip();
                newClip.name = srcClip.name;
    
                // Create directory to store generated materials.
                if (!Directory.Exists(AnimationsPath(animationFBX)))
                    Directory.CreateDirectory(AnimationsPath(animationFBX));
    
                string animationPath = AnimationsPath(animationFBX) + newClip.name + ".anim";
    
                AssetDatabase.CreateAsset(newClip, animationPath);
                AssetDatabase.Refresh();
    
                AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(srcClip, true);
                for (int i = 0; i < curveDatas.Length; i++)
                {
                    AnimationUtility.SetEditorCurve(newClip, curveDatas[i].path, curveDatas[i].type, curveDatas[i].propertyName, curveDatas[i].curve);
                }
            }
        }
    
        // Returns the path to the directory that holds the specified FBX.
        static string CharacterRoot(GameObject character)
        {
            string root = AssetDatabase.GetAssetPath(character);
            return root.Substring(0, root.LastIndexOf('/') + 1);
        }
    
        // Returns the path to the directory that holds materials generated
        // for the specified FBX.
        public static string AnimationsPath(GameObject character)
        {
            return CharacterRoot(character) + "Copy Animations/";
        }
    }


  • 相关阅读:
    腾讯精品课程
    什么都没有,先空出来!
    Python3-super().__init()__
    Python3-模块
    Python3-单例模式
    Python3-私有化修改
    Python3-私有属性
    Python3-面向对象-魔术方法
    Python3-面向对象-四种方法
    Python3-迭代器
  • 原文地址:https://www.cnblogs.com/nafio/p/9137365.html
Copyright © 2011-2022 走看看