LinearBlendshape.cs 1.2 KB

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