Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

  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. }