行业知识
Unity:Animation 三 Playable、ImportModel
���录
1. Playables API
1.1 Playable vs Animation
1.2 Advantages of using the Playables API
1.3 PlayableGraph Visualizer
2. Creating models outside of Unity
2.1 Preparing your model files for export
2.1.1 Scaling factors
2.1.2 优化模型文件
3. Importing models into Unity
3.1 Importing a model
3.2 Importing a model with humanoid animations
3.2.1 Set up the Avatar
3.2.1.1 Creating an Avatar Mask
3.3 Importing a model with non-humanoid (generic) animations
3.4 Model Import Settings window
3.4.1 Rig tab
3.4.1.1 Saving and reusing Avatar data (Human Template files)
3.5 Animation tab
Setting error tolerance for key reduction on position and scale curves
Setting error tolerance for key reduction on position and scale curves
Clip selection list
3.5.1 Euler curve resampling
3.5.2 Extracting animation clips
3.5.3 Loop optimization on Animation clips
3.5.4 Curves
3.5.5 Events
3.5.6 Motion
3.6 Materials Tab
1. Playables API
Playables 提供了一组创建、混合、修改多种数据的api 和图表,支持 animation,audio,scripts.
1.1 Playable vs Animation
animation system 仅限于编辑animation, Playables API 被设计得更加灵活并支持其他系统。
1.2 Advantages of using the Playables API
-
1. The Playables API 允许动态的混合动画,在运行时可以修改动画,即在运行时可以创建,混合动画.
-
2. The Playables API 在轻量化播放动画,兼顾了animation clip 和 animator
-
3. The Playables API 可以动态的控制混合的权重
-
4. PlayableGraph 适合大量的,复杂的动画,其它的animator就可以满足需要
1.3 PlayableGraph Visualizer
PlayableGraph Visualizer 插件地址:
-
github: GitHub repository
-
选择: Window > PlayableGraph Visualizer 打开
2. Creating models outside of Unity
2.1 Preparing your model files for export
2.1.1 Scaling factors
Unity’s physics 和 lighting systems 是每个单位1米,也就是1unit/m
不同模型软件里导出的模型单位:
- .fbx, .max, .jas = 0.01
- .3ds = 0.1
- .mb, .ma, .lxo, .dxf, .blend, .dae = 1
导入时打开 Convert Units 选项,进行单位转换。
2.1.2 优化模型文件
- Minimize the polygon count
- Use as few Materials as possible
- Use a single skinned Mesh Renderer
- Use as few bones as possible
- Keep forward and inverse kinematics separate
最小化模型的面片数量,3D模型中显示的面片顶点数量,往往比在unity里面显示的少,如果一个顶点有多个法线、UV坐标或顶点颜色,那么它必须被分割多个顶点。
对于使用蒙皮网格渲染器的动画角色模型,每个角色应该只使用一个这个组件。Unity的动画系统使用可见性剔除和边界体积来优化动画更新。只有当使用一个Animation组件和一个Skin Mesh Render时,才会有效。使用两个蒙皮网格代替单个蒙皮网格可以使模型的渲染时间增加一倍。
骨骼数量越少,性能越高,骨骼消耗性能,是因为每个顶点都需要计算骨骼对顶点位置的影响,如果没有动画,有骨骼也没事
如果反向运动学不需要,就把该节点删掉
3. Importing models into Unity
3.1 Importing a model
模型包含了很多信息,包括动画,网格,材质球,贴图
Unity 支持FBX类型的模型,如果是其它格式的,比如.blend、.max、.mb、.ma等,原理是:Unity会在后台启动三方建模软件,然后把它转成FBX格式,前提是本机安装了三方建模软件
Unity 导入贴图的时候,会自动搜索该模型层级和其父层级下名字叫Texture的文件夹,来匹配贴图,但是如果项目中有多个Texture文件夹,有可能匹配的不正确,所以要把模型用到的贴图,放到模型的同层级下面
3.2 Importing a model with humanoid animations
当Unity导入包含 Humanoid Rigs and Animation的模型文件时,它需要调节模型的骨骼和动画, 通过将文件中的每个骨骼映射到Avatar来实现这一点,这样就可以正确地播放动画.
- Define the Rig type and create the Avatar.
- Correct or verify the Avatar’s mapping.
- 完成骨骼映射后,可以点击 Muscles & Settings 页 to tweak the Avatar’s muscle configuration.
- 可以保存 the mapping of your skeleton’s bones to the Avatar 到 Human Template (.ht)文件
- 可以通过defining an Avatar Mask.细化管理骨骼映射
- 可以定义define specific action ranges as Animation Clips.
- 对于 Animation Clip:
- Change the pose and root transform
- Optimize looping
- Mirror the animation on both sides of the Humanoid skeleton.
- Add curves to the clip in order to animate the timings of other items
- Add events to the clip in order to trigger certain actions in time with the animation
- Discard part of the animation similar to using a runtime Avatar Mask but applied at import time
- Select a different Root Motion Node to drive the action from
- Read any messages from Unity about importing the clip
- Watch a preview of the animation clip
3.2.1 Set up the Avatar
设置Animation Type为Humanoid,默认Avatar Definition设置为Create From This Model.
- Create From This Model:从模型中创建avtar,Unity 会把骨骼映射的信息,保存到Humanoid Avatar中。
- Copy From Other Avatar :使用其它模型定义好的Avatar,比如一个mesh,有多个animation,导出了多个Avatar,则mesh和animation可以通用一个Avatar
如果Avatar映射没成功,就会有报错信息,这时,需要检查Avatar的映射关系,点击configure,手动映射
手动映射骨骼,T-Pose是最好的姿态
3.2.1.1 Creating an Avatar Mask
Avatar Mask 给动画添加遮罩,节省性能,因为这部分动画给屏蔽掉了,动画数据不会加载。
3.3 Importing a model with non-humanoid (generic) animations
非人形动画,也有Avatar,它和人形Avatar不同,非人形需要选择一个RootNode,并且只有节点映射,不能手动映射
3.4 Model Import Settings window
(A) Scene-level 属性,比如是否导入 Lights and Cameras, scale factor 是多少.
(B) Meshes属性
(C) Geometry-related 属性,比如 topology, UVs, normals.
Scale Factor 设置模型的缩放因子,因为模型在3D软件里的,和unity里面的不一样,进行缩放模型 Convert Units 开启后,将模型的单位和unity的单位进行转换,只是转化单位 Preserve Hierarchy 是否保留原有的层级,unity 会默认剔除模型中的空节点 Sort Hierarchy By Name 是否开启模型按透明度排序,不开启,则保留模型的原层级 3.4.1 Rig tab
3.4.1.1 Saving and reusing Avatar data (Human Template files)
可以把Avatar映射关系,保存成 Human Template file (extention *.ht)文件,其它的模型也可以使用同一份文件
3.5 Animation tab
-
Setting error tolerance for key reduction on position and scale curves
Anim. Compression 压缩方式 Off 表示Unity不会减少keyframe的数量,增加运行时性能和内存大小,如果需要高精度的动画,可以开启keyframe reduction,同时降低Animation Compression Error的值. Keyframe Reduction 减少导入时的冗余关键帧. 影响文件大小(运行时内存),也影响曲线的计算方式 Applies to Legacy, Generic, and Humanoid Animation Type rigs.
Keyframe Reduction and Compression 在导入时减少关键帧,同时在文件中存储动画时压缩关键帧。运行时内存和Keyframe Reduction 一样,只是存储是压缩,运行时还得解压缩,和原大小一致 Only for Legacy Animation Type rigs.
Optimal 让unity决定,使用以上两种方法中的哪种 Animation Compression Errors 当 Keyframe Reduction or Optimal 打开时,才有 Rotation Error 设置旋转曲线压缩的误差容差(以角度为单位)。Unity使用这个来决定它是否可以移除旋转曲线上的一个键。
Angle(value, reduced)Position Error see Setting error tolerance for key reduction on position and scale curves. Scale Error see Setting error tolerance for key reduction on position and scale curves. -
Setting error tolerance for key reduction on position and scale curves
对于position 和 scale,使用下面的方法,如果小于OriginalValue*percentageOfError的就会被踢出,position error 是 设置的是percentageOfError,reduce的value就是移除掉这个关键帧之后,该帧的值。比如两个key,一个为11.2,一个为11.1,position error=10,这二个帧被移除后,它的值变成了10,则根据11.2-10>11.2*10%,11.1-10
-
-
-
上一篇:轻松修改织梦网站首页技巧与教程