Unity导入FBX自动进行动画切分
手动处理动画分割
在导入FBX模型过程中,若带有动画呢,需要对它进行切分。
当然这个工作可以在Unity中完成。
比如:
这样手动来分割进行。
自动动画切分
- // FbxAnimListPostprocessor.cs : Use an external text file to import a list of
- // splitted animations for FBX 3D models.
- //
- // Put this script in your "Assets/Editor" directory. When Importing or
- // Reimporting a FBX file, the script will search a text file with the
- // same name and the ".txt" extension.
- // File format: one line per animation clip "firstFrame-lastFrame loopFlag animationName"
- // The keyworks "loop" or "noloop" are optional.
- // Example:
- // 0-50 loop Move forward
- // 100-190 die
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- using System.IO;
- using System.Text.RegularExpressions;
- using System;
- using System.IO;
- public class FbxAnimListPostprocessor : AssetPostprocessor
- {
- public void OnPreprocessModel()
- {
- if (Path.GetExtension(assetPath).ToLower() == ".fbx"
- && !assetPath.Contains("@"))
- {
- try
- {
- string fileAnim;
- if (DragAndDrop.paths.Length <= 0)
- {
- return;
- }
- fileAnim = DragAndDrop.paths[0];
- string ClipText = Path.ChangeExtension(fileAnim, ".txt");
- StreamReader file = new StreamReader(ClipText);
- string sAnimList = file.ReadToEnd();
- file.Close();
- //
- if (EditorUtility.DisplayDialog("FBX Animation Import from file",
- fileAnim, "Import", "Cancel"))
- {
- System.Collections.ArrayList List = new ArrayList();
- ParseAnimFile(sAnimList, ref List);
- ModelImporter modelImporter = assetImporter as ModelImporter;
- //modelImporter.clipAnimations. = true;
- modelImporter.clipAnimations = (ModelImporterClipAnimation[])
- List.ToArray(typeof(ModelImporterClipAnimation));
- EditorUtility.DisplayDialog("Imported animations",
- "Number of imported clips: "
- + modelImporter.clipAnimations.GetLength(0).ToString(), "OK");
- }
- }
- catch { }
- // (Exception e) { EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); }
- }
- }
- void ParseAnimFile(string sAnimList, ref System.Collections.ArrayList List)
- {
- Regex regexString = new Regex(" *(?<firstFrame>[0-9]+) *- *(?<lastFrame>[0-9]+) *(?<loop>(loop|noloop| )) *(?<name>[^\r^\n]*[^\r^\n^ ])",
- RegexOptions.Compiled | RegexOptions.ExplicitCapture);
- Match match = regexString.Match(sAnimList, 0);
- while (match.Success)
- {
- ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
- if (match.Groups["firstFrame"].Success)
- {
- clip.firstFrame = System.Convert.ToInt32(match.Groups["firstFrame"].Value, 10);
- }
- if (match.Groups["lastFrame"].Success)
- {
- clip.lastFrame = System.Convert.ToInt32(match.Groups["lastFrame"].Value, 10);
- }
- if (match.Groups["loop"].Success)
- {
- clip.loop = match.Groups["loop"].Value == "loop";
- }
- if (match.Groups["name"].Success)
- {
- clip.name = match.Groups["name"].Value;
- }
- List.Add(clip);
- match = regexString.Match(sAnimList, match.Index + match.Length);
- }
- }
- }
- 0-50 loop Move forward
- 100-190 die

Unity导入FBX自动进行动画切分的更多相关文章
- Unity游戏开发——自动为动画剪辑添加事件 之 最后几帧的事件不能被调用的问题
最近在做一个根据配置表自动生成动画剪辑clip以及controller的功能.做法是根据配置表配置的动作以及每个动作的关键帧,自动为每个clip添加事件.这样做可以把动画的事件处理在游戏运行之前就计算 ...
- Unity导入fbx格式的模型
1. 在Model文件夹右击,选择 import new Asset,然后选择要导入的模型 2. 将纹理图片导入Pictures中 3. 在Materials中创建一个Material,然后点击属性中 ...
- Unity自动切割动画
最近在开发项目时,需要处理大量的动画,于是就网上查找资料,然后写了这么编辑器工具: 就是在模型导入时,根据配置文件自动切割动画. 首先我们需要封装两个类:一个模型类和一个动画类 public clas ...
- Unity3d修改FBX文件的动画名方法
问题描述:FBX文件导入Unity3d后的动画名字一般都是 “Take 001”并且无法修改!如何修改它呢? 解决方法:解决方法其实很简单,只要你按照Unity3d的FBX文件命名规则,压根就不会存在 ...
- [转载]一个高效简洁的Aseprite to Unity导入工具
原文链接 https://zhuanlan.zhihu.com/p/28644268 期待原作者上传至AssetStore. 今天,我的第一个 Unity 插件 MetaSprite 正式发布了它的 ...
- FBX BlendShape/Morph动画解析
目前fbx 2015.1中支持三种变形器:skinDeformer,blendShapeDeformer,vertexCacheDeformer.定义在fbxdeformer.h中: enum EDe ...
- unity导入3dsMax源文件.max
https://blog.csdn.net/qq_28002559/article/details/53693621 首先unity导入3dsMax文件为什么要使用.max而不用.fbx,因为我不是做 ...
- Unity2D研究院之自动生成动画、AnimationController、Prefab(一)
http://www.xuanyusong.com/archives/3243 国庆了,回家了.时刻还是要吃一颗学习的心,在家了也要抽出时间好好学习一下.之前MOMO一直没研究过Unity2D,今天研 ...
- GJM:Unity导入百度地图SDK [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
随机推荐
- Accumulator
Accumulator简介 Accumulator是spark提供的累加器,顾名思义,该变量只能够增加. 只有driver能获取到Accumulator的值(使用value方法),Task只能对其做增 ...
- 【转】【Unity】四元数(Quaternion)和旋转
http://blog.csdn.net/candycat1992/article/details/41254799
- 【C#】Queue的简单试用
新建一个WPF项目,测试C#的Queue类的简单使用. 前台准备两个按钮 MainWindow.xaml <StackPanel VerticalAlignment="Center&q ...
- linux 使用NSF 映射远程磁盘目录
假设源目录在192.168.1.1机器上,目录为/data 客户端集群在192.168.1.2, 需要将192.168.1.1机器上的/data目录到本地的/data目录 1.在两台机器上安装nsf ...
- jquery动态分页
最近一直研究jquery的分页效果,刚刚弄好了一个,拿出来与大家分享.分页效果与时光网的差不多. 网址:http://www.mtime.com/movie/news/all/ 先在aspx页面放置一 ...
- 25+开源的在线购物软件(PHP, JavaScript 和 ASP.Net)
25 +免费开源的电子商务解决方案,提供了建立一个在线购物所有主要功能,并能够连接到一个支付处理系统1. Magento Magento是一套专业开源的PHP电子商务系统.Magento设计得非常灵活 ...
- BCM_GPIO驱动测试
在写内核驱动的时候,最好先在uboot上,进行裸板测试,验证寄存器,再移植到内核中,这样可以熟悉寄存器,也排除内核中的一些干扰. /********************************** ...
- Intellij IDEA 使用学习
Intellij中名词解释: Project,就是一个完整的项目,类似Eclipse中的WorkSet(虽然WorkSet是人为归类的). Module,是Project中的模块,类似Eclipse中 ...
- Android 利用cursor来进行排序(转至http://blog.csdn.net/yangzongquan/article/details/6547860)
主要思路是:override move系列的方法,让cursor以自己想要的顺序来移动,从而达到对cursor排序的目的.比如数组A0里有 4(0),3(1),1(2),2(3),括号内为位置,排序后 ...
- 【Java面试题】17 如何把一个逗号分隔的字符串转换为数组? 关于String类中split方法的使用,超级详细!!!
split 方法:将一个字符串分割为子字符串,然后将结果作为字符串数组返回. stringObj.split([separator],[limit])参数:stringObj 必选项.要被分解的 ...