IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
LinearBlendshape.cs
1 //======= Copyright (c) Valve Corporation, All rights reserved. ===============
2 //
3 // Purpose: Set the blend shape weight based on a linear mapping
4 //
5 //=============================================================================
6 
7 using UnityEngine;
8 using System.Collections;
9 
10 namespace Valve.VR.InteractionSystem
11 {
12  //-------------------------------------------------------------------------
13  public class LinearBlendshape : MonoBehaviour
14  {
15  public LinearMapping linearMapping;
16  public SkinnedMeshRenderer skinnedMesh;
17 
18  private float lastValue;
19 
20 
21  //-------------------------------------------------
22  void Awake()
23  {
24  if ( skinnedMesh == null )
25  {
26  skinnedMesh = GetComponent<SkinnedMeshRenderer>();
27  }
28 
29  if ( linearMapping == null )
30  {
31  linearMapping = GetComponent<LinearMapping>();
32  }
33  }
34 
35 
36  //-------------------------------------------------
37  void Update()
38  {
39  float value = linearMapping.value;
40 
41  //No need to set the blend if our value hasn't changed.
42  if ( value != lastValue )
43  {
44  float blendValue = Util.RemapNumberClamped( value, 0f, 1f, 1f, 100f );
45  skinnedMesh.SetBlendShapeWeight( 0, blendValue );
46  }
47 
48  lastValue = value;
49  }
50  }
51 }