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/";
        }
    }


  • 相关阅读:
    CSS压缩工具(自动合并重复的定义)
    windows创建服务
    ashx是什么文件,如何创建(转载)
    在mojoportal中建立自定义模块
    Mojoportal2339之汇总页面
    在vs2008中设置jquery智能提示 (转载)
    关于mojoportal在局域网或单机使用时注意事项
    html编辑器kindeditor我的使用方法 (转载)
    visual studio 2008 没有设计视图的解决方法(转载)
    模块开发捷径配置参数
  • 原文地址:https://www.cnblogs.com/nafio/p/9137365.html
Copyright © 2011-2022 走看看