Unity工具类之BlendShape捏脸的实现

更新时间:2023-07-26 12:26:04 阅读: 评论:0

Unity⼯具类之BlendShape捏脸的实现
Unity ⼯具类之 BlendShape 捏脸的实现
⽬录
⼀、简单介绍
Blender 是⼀款开源的跨平台全能三维动画制作软件,提供从建模、动画、材质、、到⾳频处理、视频剪辑等⼀系列动画短⽚制作解决⽅案。
在Unity程序开发中,使⽤ Blender 制作的模型,进⾏ BlendShap 捏脸的实现;
⼆、实现原理
1、通过控制改变 Skinned Mesh Renderer 的 BlendShapes 下的参数数值,来实现捏脸的效果
三、注意事项
1、Blender 中编辑模式下设置的值是实现好的捏脸效果的关键;
打蛋器怎么用四、效果预览
五、实现步骤
1、打开Unity,新建⼀个⼯程,并且导⼊模型,添加到场景中,如下图
2、在场景中,添加⼏个Slider UI 组件,控制捏脸的数值,如下图
3、编写脚本,控制BlendShapes 对应数值的变化,把对应脚本挂载到对应组件上,如下图
4、运⾏场景,效果如下
六、代码
1、Singleton
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Singleton<T> : MonoBehaviour段家大院
where T:MonoBehaviour
{
private static T m_Instance;
public static T Instance
{
get
{
魔蝎座女return m_Instance;
颜色不一样的烟火}
}
protected virtual void Awake()
{
m_Instance = this as T;
}
}
2、BlendShape
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 存储索引
/// </summary>
public class BlendShape
{
public int postiveIndex { get; t; }
public int negativeIndex { get; t; }
public BlendShape(int postiveIndex,int negativeIndex)
{
this.postiveIndex = postiveIndex;
}
}
3、CharacterCustomization
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class CharacterCustomization : Singleton<CharacterCustomization>{
自己的英文
public string suffixMin = "Min";
public string suffixMax = "Max";
public SkinnedMeshRenderer target;
SkinnedMeshRenderer skm;
Mesh mesh;
Mesh mesh;
Dictionary<string, BlendShape> BlendShapeDataba = new Dictionary<string, BlendShape>();
private void Start()
{
Initialize();
}
public  void Initialize()
{
skm = target;
mesh = skm.sharedMesh;
SaveBlendShapeDataba();
}
#region 存储数据
void SaveBlendShapeDataba()
{
List<string> BlendShapeNames = Enumerable.Range(0, mesh.blendShapeCount).Select(x => mesh.GetBlendShapeName(x)).ToList();        for(int i = 0; BlendShapeNames.Count > 0;)
{
string noSuffix, altSuffix;
noSuffix = BlendShapeNames[i].TrimEnd(suffixMax.ToCharArray()).TrimEnd(suffixMin.ToCharArray()).Trim();
string positiveName = string.Empty;
string negativeName = string.Empty;锐雯台词
int postiveIndex = -1;
int negativeIndex = -1;
bool exist = fal;
//后缀是max
if (BlendShapeNames[i].EndsWith(suffixMax))
{
positiveName = BlendShapeNames[i];
altSuffix = noSuffix + " " + suffixMin;
if (BlendShapeNames.Contains(altSuffix))
exist = true;
postiveIndex = mesh.GetBlendShapeIndex(positiveName);
if (exist)杀生影评
黄鹤楼送孟浩然之广陵诗意{
negativeName = altSuffix;
negativeIndex = mesh.GetBlendShapeIndex(negativeName);
}
//后缀是min结尾
}el if (BlendShapeNames[i].EndsWith(suffixMin))
{
negativeName = BlendShapeNames[i];
altSuffix = noSuffix + " " + suffixMax;
if (BlendShapeNames.Contains(altSuffix))
exist = true;
negativeIndex = mesh.GetBlendShapeIndex(negativeName);
if (exist)
{
positiveName = altSuffix;
postiveIndex = mesh.GetBlendShapeIndex(positiveName);
}

本文发布于:2023-07-26 12:26:04,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1097338.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对应   实现   制作   控制   动画
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图