using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DingDianDongHua : MonoBehaviour {
float twist;
float inputSensitiv=1.5f;
Mesh twistMesh;
private Vector3[] baseVertex;
private Vector3[] baseNormals;
// Use this for initialization
void Start () {
}
public void GetVertexAndNormals()
{
twistMesh = GetComponent<MeshFilter>().mesh;
baseVertex = twistMesh.vertices;
baseNormals = twistMesh.normals;
}
public void ChangeMesh()
{
GetVertexAndNormals();
Vector3[] vectors = new Vector3[baseVertex.Length];
Vector3[] normals = new Vector3[baseNormals.Length];
for(int i=0;i< baseVertex.Length; i++)
{
vectors[i] = DoTwist(baseVertex[i], ChangT(baseVertex[i]));
normals[i] = DoTwist(baseNormals[i],ChangT(baseVertex[i]));
}
twistMesh.vertices = vectors;
twistMesh.normals = normals;
//每次改变后,送给GPU渲染
twistMesh.RecalculateBounds();
twistMesh.RecalculateNormals();
}
//弹簧扭曲的变化的公式
private Vector3 DoTwist(Vector3 pos,float t)
{
float st = Mathf.Sin(t);
float ct = Mathf.Cos(t);
Vector3 result = Vector3.zero;
result.x = pos.x * ct - pos.z * st;
result.y = pos.y;
result.z = pos.x * st + pos.z * ct;
return result;
}
//改变的数值
public float ChangT(Vector3 pos)
{
twist = Input.GetAxis("Horizontal") * inputSensitiv * Time.deltaTime;
return pos.y * twist;
}
// Update is called once per frame
void Update () {
ChangeMesh();
}
}
morph动画
//动画定点融合,可以做表情动画
Vector3 Function(Vector3 x,Vector3 y,float a){
Vector3 result=a*x+(1-a)y;
return result;
}