Unity实现一个morpher/blendShape
2015-12-03 10:34
543 查看
using UnityEngine; using System.Collections; [RequireComponent (typeof (MeshFilter))] public class BlendShape : MonoBehaviour { public Mesh[] meshs; #if UNITY_EDITOR public float[] weights; #else float[] weights; #endif bool isChange = false; void Start () { weights = new float[meshs.Length]; System.Array.Clear (weights,0,weights.Length); GetComponent<MeshFilter> ().mesh = meshs [0]; } public void SetWeight(int argIndex,float argWeight) { weights [argIndex] = (argWeight > 1 ? 1: argWeight ); isChange = true; } void Update() { UpdateMesh (); } void UpdateMesh() { #if UNITY_EDITOR #else if (!isChange) return; #endif Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = new Vector3[meshs[0].vertices.Length]; System.Array.Copy (meshs [0].vertices, vertices, vertices.Length); for (int w=1;w<weights.Length;w++) { if (weights[w] <= 0) continue; Vector3[] verticesT = meshs[w].vertices; int i = 0; while (i < vertices.Length) { vertices[i] = vertices[i] + (verticesT[i] - meshs[0].vertices[i]) * weights[w]; i++; } } mesh.vertices = vertices; isChange = false; } }
View Code
相关文章推荐
- [shader]Unity3D地形
- 通过Scroll View实现简易背包的滑动效果
- win8.1 unity静默调用打印机
- unity 球体表面平均分割点
- unity 球体表面平均分割点
- unity基础概念
- unity3d脚本控制骨骼旋转
- Unity手游之路<十三>手游代码更新策略探讨
- Unity手游之路<十二>手游资源热更新策略探讨
- Unity手游之路<十一>资源打包Assetbundle
- Unity 行为树 Behavior Designer
- Unity下SpriteSheet 使用
- unity3d5.2.3中 调整视角
- Unity3d 手游之旅
- 【Unity3D ugui】UI特效的位置自适应及调整层次关系的一种解决方案
- UNITY 5.2 Camera类
- unity3d 笔记
- Unity脚本打包android工程
- 不用Unity库,利用.NET动态代理自己实现AOP
- Unity3D_Quad_实现播放序列帧