Once you have your blend shapes set up in your 3D modeling application (such as Autodesk® Maya®):
0
means the blend shape has no influence.100
means the blend shape has full influence.To create a blend animation:
Create the animation you want by adjusting the keyframes and blend weights.
To preview your animation, click Play in the Editor window or the Animation window.
You can also set the blend weights through scripting using functions like GetBlendShapeWeight and SetBlendShapeWeight.
To check how many blend shapes a Mesh has, use the blendShapeCount variable.
This code example demonstrates how to blend a default shape into two other blend shapes over time when attached to a GameObject with three or more blend shapes:
using UnityEngine;
using System.Collections;
public class BlendShapeExample : MonoBehaviour
{
int blendShapeCount;
SkinnedMeshRenderer skinnedMeshRenderer;
Mesh skinnedMesh;
float blendOne = 0f;
float blendTwo = 0f;
float blendSpeed = 1f;
bool blendOneFinished = false;
void Awake ()
{
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> ();
skinnedMesh = GetComponent<SkinnedMeshRenderer> ().sharedMesh;
}
void Start ()
{
blendShapeCount = skinnedMesh.blendShapeCount;
}
void Update ()
{
if (blendShapeCount > 2) {
if (blendOne < 100f) {
skinnedMeshRenderer.SetBlendShapeWeight (0, blendOne);
blendOne += blendSpeed;
} else {
blendOneFinished = true;
}
if (blendOneFinished == true && blendTwo < 100f) {
skinnedMeshRenderer.SetBlendShapeWeight (1, blendTwo);
blendTwo += blendSpeed;
}
}
}
}