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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

55 lines
1.5KB

  1. using UnityEngine;
  2. using System.Collections;
  3. [System.Serializable]
  4. public class MeshActor : Actor
  5. {
  6. public Vector3 skewAngles1;
  7. public Vector3 skewAngles2;
  8. protected Vector3 angles1prev = Vector3.zero;
  9. protected Vector3 angles2prev = Vector3.zero;
  10. protected const float coeff = Mathf.PI/180;
  11. protected Mesh mesh;
  12. protected Vector3[] initialState;
  13. void Awake()
  14. {
  15. mesh = gameObject.GetComponent<MeshFilter>().mesh;
  16. initialState = mesh.vertices;
  17. }
  18. protected void Update()
  19. {
  20. base.Update();
  21. if (skewAngles1 != angles1prev || skewAngles2 != angles2prev)
  22. updateMesh();
  23. }
  24. protected void updateMesh()
  25. {
  26. Matrix4x4 m = Matrix4x4.zero;
  27. m[0, 0] = 1;
  28. m[1, 1] = 1;
  29. m[2, 2] = 1;
  30. m[3, 3] = 1;
  31. m[0, 1] = Mathf.Tan(skewAngles1.x * coeff); // skewing in xy
  32. m[0, 2] = Mathf.Tan(skewAngles2.x * coeff); // skewing in xz
  33. m[1, 0] = Mathf.Tan(skewAngles1.y * coeff); // skewing in yx
  34. m[1, 2] = Mathf.Tan(skewAngles2.y * coeff); // skewing in yz
  35. m[2, 0] = Mathf.Tan(skewAngles1.z * coeff); // skewing in zx
  36. m[2, 1] = Mathf.Tan(skewAngles2.z * coeff); // skewing in zy
  37. Vector3[] verts = new Vector3[initialState.Length];
  38. int i = 0;
  39. while (i < verts.Length)
  40. {
  41. verts[i] = m.MultiplyPoint3x4(initialState[i]);
  42. i++;
  43. }
  44. mesh.vertices = verts;
  45. angles1prev = skewAngles1;
  46. angles2prev = skewAngles2;
  47. }
  48. }