MegaCylindrify.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using UnityEngine;
  2. [AddComponentMenu("Modifiers/Cylindrify")]
  3. public class MegaCylindrify : MegaModifier
  4. {
  5. public float Percent = 0.0f;
  6. public float Decay = 0.0f;
  7. public override string ModName() { return "Cylindrify"; }
  8. public override string GetHelpURL() { return "?page_id=166"; }
  9. float size;
  10. float per;
  11. public override Vector3 Map(int i, Vector3 p)
  12. {
  13. p = tm.MultiplyPoint3x4(p);
  14. float dcy = Mathf.Exp(-Decay * p.magnitude);
  15. float k = ((size / Mathf.Sqrt(p.x * p.x + p.z * p.z) / 2.0f - 1.0f) * per * dcy) + 1.0f;
  16. p.x *= k;
  17. p.z *= k;
  18. return invtm.MultiplyPoint3x4(p);
  19. }
  20. public override bool ModLateUpdate(MegaModContext mc)
  21. {
  22. return Prepare(mc);
  23. }
  24. public void SetTM1()
  25. {
  26. tm = Matrix4x4.identity;
  27. MegaMatrix.RotateZ(ref tm, -gizmoRot.z * Mathf.Deg2Rad);
  28. MegaMatrix.RotateY(ref tm, -gizmoRot.y * Mathf.Deg2Rad);
  29. MegaMatrix.RotateX(ref tm, -gizmoRot.x * Mathf.Deg2Rad);
  30. MegaMatrix.SetTrans(ref tm, gizmoPos + Offset);
  31. //tm.SetTRS(gizmoPos + Offset, rot, gizmoScale);
  32. invtm = tm.inverse;
  33. }
  34. public MegaAxis axis;
  35. Matrix4x4 mat = new Matrix4x4();
  36. public override bool Prepare(MegaModContext mc)
  37. {
  38. mat = Matrix4x4.identity;
  39. switch ( axis )
  40. {
  41. case MegaAxis.X: MegaMatrix.RotateZ(ref mat, Mathf.PI * 0.5f); break;
  42. case MegaAxis.Y: MegaMatrix.RotateX(ref mat, -Mathf.PI * 0.5f); break;
  43. case MegaAxis.Z: break;
  44. }
  45. SetAxis(mat);
  46. float xsize = bbox.max.x - bbox.min.x;
  47. float zsize = bbox.max.z - bbox.min.z;
  48. size = (xsize > zsize) ? xsize : zsize;
  49. // Get the percentage to spherify at this time
  50. per = Percent / 100.0f;
  51. return true;
  52. }
  53. }