Work with blend shapes
Import blend shapes to create blend animation.
読み終わるまでの所要時間 2 分最終更新 1ヶ月前
Prepare the artwork
Once you have set up blend shapes in your 3D modeling application, do the following:
-
In your 3D modeling application, enable these export settings:
- Enable exporting animation.
- Enable exporting blend shapes for deformed models.
-
Export your selection to an .fbx file.
-
Import your FBX file into Unity.
-
Select the newly imported Model in the Hierarchy window. The Inspector window displays the BlendShapes section containing all the blend shapes under the SkinnedMeshRenderer component.
-
For each listed blend shape, you can change its influence (weighting) to the default shape, where:
- means the blend shape has no influence.
0 - means the blend shape has full influence.
100
Create animations In Unity
To create a blend animation:
- Open the Animation window (from the main Unity menu: Window > Animation > Animation).
- Select the Animation Clip where you want to add the blend shape animation. You can select Create New Clip to create a new Animation Clip.
- Click Add Property and select [Your Character] > [Your Character Body] > Skinned Mesh Renderer and select the blend shape you want to animate.
- Select the added blend shape property, adjusting the keyframes and blend weights, and set keyframes.
To preview your animation, click Play in the Editor window or the Animation window.
Scripting access
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; } } }}