手动处理动画分割

在导入FBX模型过程中,若带有动画呢,需要对它进行切分。

当然这个工作可以在Unity中完成。

比如:

这样手动来分割进行。

自动动画切分

 
这就需要代码了。
把代码保存成cs文件,然后放在Editor文件夹中。若没有此文件夹,就自己创建一个!
 
 
代码如下:
  1. // FbxAnimListPostprocessor.cs : Use an external text file to import a list of
  2. // splitted animations for FBX 3D models.
  3. //
  4. // Put this script in your "Assets/Editor" directory. When Importing or
  5. // Reimporting a FBX file, the script will search a text file with the
  6. // same name and the ".txt" extension.
  7. // File format: one line per animation clip "firstFrame-lastFrame loopFlag animationName"
  8. // The keyworks "loop" or "noloop" are optional.
  9. // Example:
  10. // 0-50 loop Move forward
  11. // 100-190 die
  12. using UnityEngine;
  13. using UnityEditor;
  14. using System.Collections;
  15. using System.IO;
  16. using System.Text.RegularExpressions;
  17. using System;
  18. using System.IO;
  19. public class FbxAnimListPostprocessor : AssetPostprocessor
  20. {
  21. public void OnPreprocessModel()
  22. {
  23. if (Path.GetExtension(assetPath).ToLower() == ".fbx"
  24. && !assetPath.Contains("@"))
  25. {
  26. try
  27. {
  28. string fileAnim;
  29. if (DragAndDrop.paths.Length <= 0)
  30. {
  31. return;
  32. }
  33. fileAnim = DragAndDrop.paths[0];
  34. string ClipText = Path.ChangeExtension(fileAnim, ".txt");
  35. StreamReader file = new StreamReader(ClipText);
  36. string sAnimList = file.ReadToEnd();
  37. file.Close();
  38. //
  39. if (EditorUtility.DisplayDialog("FBX Animation Import from file",
  40. fileAnim, "Import", "Cancel"))
  41. {
  42. System.Collections.ArrayList List = new ArrayList();
  43. ParseAnimFile(sAnimList, ref List);
  44. ModelImporter modelImporter = assetImporter as ModelImporter;
  45. //modelImporter.clipAnimations. = true;
  46. modelImporter.clipAnimations = (ModelImporterClipAnimation[])
  47. List.ToArray(typeof(ModelImporterClipAnimation));
  48. EditorUtility.DisplayDialog("Imported animations",
  49. "Number of imported clips: "
  50. + modelImporter.clipAnimations.GetLength(0).ToString(), "OK");
  51. }
  52. }
  53. catch { }
  54. // (Exception e) { EditorUtility.DisplayDialog("Imported animations", e.Message, "OK"); }
  55. }
  56. }
  57. void ParseAnimFile(string sAnimList, ref System.Collections.ArrayList List)
  58. {
  59. Regex regexString = new Regex(" *(?<firstFrame>[0-9]+) *- *(?<lastFrame>[0-9]+) *(?<loop>(loop|noloop| )) *(?<name>[^\r^\n]*[^\r^\n^ ])",
  60. RegexOptions.Compiled | RegexOptions.ExplicitCapture);
  61. Match match = regexString.Match(sAnimList, 0);
  62. while (match.Success)
  63. {
  64. ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
  65. if (match.Groups["firstFrame"].Success)
  66. {
  67. clip.firstFrame = System.Convert.ToInt32(match.Groups["firstFrame"].Value, 10);
  68. }
  69. if (match.Groups["lastFrame"].Success)
  70. {
  71. clip.lastFrame = System.Convert.ToInt32(match.Groups["lastFrame"].Value, 10);
  72. }
  73. if (match.Groups["loop"].Success)
  74. {
  75. clip.loop = match.Groups["loop"].Value == "loop";
  76. }
  77. if (match.Groups["name"].Success)
  78. {
  79. clip.name = match.Groups["name"].Value;
  80. }
  81. List.Add(clip);
  82. match = regexString.Match(sAnimList, match.Index + match.Length);
  83. }
  84. }
  85. }
怎么使用呢?
在你的FBX同目录文件夹下,创建一个txt文件,名字与FBX文件同名即可。
 
txt内容,为 每个动画的起始帧和结束帧,是否循环播放,和帧名。
CowGirl_Ani.txt
  1. 0-50 loop Move forward
  2. 100-190 die
 
 
把FBX文件拖入到Unity的资源中,可以看到弹出对话框。选择Import导入,就会自动弹出分割动画的数量。
若点击cancle ,就会直接导入动画,而不会分割动画。

Unity导入FBX自动进行动画切分的更多相关文章

  1. Unity游戏开发——自动为动画剪辑添加事件 之 最后几帧的事件不能被调用的问题

    最近在做一个根据配置表自动生成动画剪辑clip以及controller的功能.做法是根据配置表配置的动作以及每个动作的关键帧,自动为每个clip添加事件.这样做可以把动画的事件处理在游戏运行之前就计算 ...

  2. Unity导入fbx格式的模型

    1. 在Model文件夹右击,选择 import new Asset,然后选择要导入的模型 2. 将纹理图片导入Pictures中 3. 在Materials中创建一个Material,然后点击属性中 ...

  3. Unity自动切割动画

    最近在开发项目时,需要处理大量的动画,于是就网上查找资料,然后写了这么编辑器工具: 就是在模型导入时,根据配置文件自动切割动画. 首先我们需要封装两个类:一个模型类和一个动画类 public clas ...

  4. Unity3d修改FBX文件的动画名方法

    问题描述:FBX文件导入Unity3d后的动画名字一般都是 “Take 001”并且无法修改!如何修改它呢? 解决方法:解决方法其实很简单,只要你按照Unity3d的FBX文件命名规则,压根就不会存在 ...

  5. [转载]一个高效简洁的Aseprite to Unity导入工具

    原文链接 https://zhuanlan.zhihu.com/p/28644268  期待原作者上传至AssetStore. 今天,我的第一个 Unity 插件 MetaSprite 正式发布了它的 ...

  6. FBX BlendShape/Morph动画解析

    目前fbx 2015.1中支持三种变形器:skinDeformer,blendShapeDeformer,vertexCacheDeformer.定义在fbxdeformer.h中: enum EDe ...

  7. unity导入3dsMax源文件.max

    https://blog.csdn.net/qq_28002559/article/details/53693621 首先unity导入3dsMax文件为什么要使用.max而不用.fbx,因为我不是做 ...

  8. Unity2D研究院之自动生成动画、AnimationController、Prefab(一)

    http://www.xuanyusong.com/archives/3243 国庆了,回家了.时刻还是要吃一颗学习的心,在家了也要抽出时间好好学习一下.之前MOMO一直没研究过Unity2D,今天研 ...

  9. GJM:Unity导入百度地图SDK [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...

随机推荐

  1. MAC上类apt-get工具brew的安装与使用

    对于习惯了linux系统的人来说,使用yum或者apt-get来在线安装软件是一件非常愉快的事情.这些工具能够解决依赖问题.使得安装过程变得简单快捷. 在使用MAC的时候,也会想:MAC OS上有没有 ...

  2. 【WPF/MVVM】把鼠标事件写到Controller层

    要使用Mouse Event,最快捷的方法便是前台控件直接绑定事件,然后再后台代码中实现. 在MVVM中,View层的后台代码无法调用Contrller层的函数.(反过来可以Controller –& ...

  3. r画饼图

    原始图样: library(ggplot2) dt = data.frame(A = c(2, 7, 4, 10, 1), B = c('B','A','C','D','E')) p = ggplot ...

  4. 《FPGA全程进阶---实战演练》第二章之PCB layout注意事项以及投板几点说明

           上一篇博客讲述了各个部分的原理图,那么根据原理图画出PCB,其实PCB是一门很大的学问,想要掌握谈何容易.就笔者在画PCB时的一些注意事项做一些说明.        1.电源部分的电源线 ...

  5. Oracle数据库中,在SQL语句中连接字符串的方法是哪个?(选择1项)

    Oracle数据库中,在SQL语句中连接字符串的方法是哪个?(选择1项) A.cat B.concat C.join D.+ 解答:B

  6. 【转载】C# 快速高效率复制对象另一种方式 表达式树

    1.需求 在代码中经常会遇到需要把对象复制一遍,或者把属性名相同的值复制一遍. 比如: public class Student { public int Id { get; set; } publi ...

  7. websocke前世今生

    注:以下内容来自网上.本人经过加工整理. 1.问什么要用websocke? Browser已经支持http协议,为什么还要开发一种新的WebSocket协议呢?我们知道http协议是一种单向的网络协议 ...

  8. perl 字符串比较操作符

    perl 中数字和字符串的比较操作符是不一样的 : 其中 == 用于比较数字是否相等:eq 用于比较字符串是否相等: 今天找程序里的bug,结果就是这个操作符用错,哎,赶紧记一下!

  9. C#接口之IEnumerable,IEnumerator

    IEnumerable 截图来源于https://msdn.microsoft.com/zh-cn/library/system.collections.ienumerable.getenumerat ...

  10. org.xml.sax.SAXParseException: prolog 中不允许有内容

    org.xml.sax.SAXParseException: prolog 中不允许有内容 digester.fatalError 不下心踢了电源导致的错误应该是解析xml出问题,找了半天不知道哪个x ...