Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

52 rindas
1.6KB

  1. using UnityEngine;
  2. using System.Collections;
  3. [System.Serializable]
  4. public class SkewModifier : MonoBehaviour
  5. {
  6. public Vector3 angles1;
  7. public Vector3 angles2;
  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. void Awake()
  13. {
  14. mesh = gameObject.GetComponent<MeshFilter>().mesh;
  15. }
  16. void Update()
  17. {
  18. if (angles1 != angles1prev || angles2 != angles2prev)
  19. updateMesh();
  20. }
  21. protected void updateMesh()
  22. {
  23. Matrix4x4 m = Matrix4x4.zero;
  24. m[0, 0] = 1;
  25. m[1, 1] = 1;
  26. m[2, 2] = 1;
  27. m[3, 3] = 1;
  28. m[0, 1] = Mathf.Tan(angles1.x * coeff) - Mathf.Tan(angles1prev.x * coeff); // skewing in xy
  29. m[0, 2] = Mathf.Tan(angles2.x * coeff) - Mathf.Tan(angles2prev.x * coeff); // skewing in xz
  30. m[1, 0] = Mathf.Tan(angles1.y * coeff) - Mathf.Tan(angles1prev.y * coeff); // skewing in yx
  31. m[1, 2] = Mathf.Tan(angles2.y * coeff) - Mathf.Tan(angles2prev.y * coeff); // skewing in yz
  32. m[2, 0] = Mathf.Tan(angles1.z * coeff) - Mathf.Tan(angles1prev.z * coeff); // skewing in zx
  33. m[2, 1] = Mathf.Tan(angles2.z * coeff) - Mathf.Tan(angles2prev.z * coeff); // skewing in zy
  34. Vector3[] verts = mesh.vertices;
  35. int i = 0;
  36. while (i < verts.Length)
  37. {
  38. verts[i] = m.MultiplyPoint3x4(verts[i]);
  39. i++;
  40. }
  41. mesh.vertices = verts;
  42. angles1prev = angles1;
  43. angles2prev = angles2;
  44. }
  45. }