MegaCrumple.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Crumple")]
  3. public class MegaCrumple : MegaModifier
  4. {
  5. public float scale = 1.0f;
  6. public float speed = 1.0f;
  7. public float phase = 0.0f;
  8. public bool animate = false;
  9. Matrix4x4 mat = new Matrix4x4();
  10. MegaPerlin iperlin = MegaPerlin.Instance;
  11. public override string ModName() { return "Crumple"; }
  12. public override string GetHelpURL() { return "?page_id=653"; }
  13. public override Vector3 Map(int i, Vector3 p)
  14. {
  15. p = tm.MultiplyPoint3x4(p);
  16. p.x += iperlin.Noise(timex + p.x, timex + p.y, timex + p.z) * scale;
  17. p.y += iperlin.Noise(timey + p.x, timey + p.y, timey + p.z) * scale;
  18. p.z += iperlin.Noise(timez + p.x, timez + p.y, timez + p.z) * scale;
  19. return invtm.MultiplyPoint3x4(p);
  20. }
  21. float timex = 0.0f;
  22. float timey = 0.0f;
  23. float timez = 0.0f;
  24. public override bool ModLateUpdate(MegaModContext mc)
  25. {
  26. if ( animate )
  27. {
  28. if ( Application.isPlaying )
  29. phase += Time.deltaTime * speed;
  30. }
  31. timex = 0.1365143f + phase;
  32. timey = 1.21688f + phase;
  33. timez = 2.5564f + phase;
  34. return Prepare(mc);
  35. }
  36. public override bool Prepare(MegaModContext mc)
  37. {
  38. mat = Matrix4x4.identity;
  39. SetAxis(mat);
  40. return true;
  41. }
  42. }