74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Cylindrify")]
|
|
public class MegaCylindrify : MegaModifier
|
|
{
|
|
public float Percent;
|
|
|
|
public float Decay;
|
|
|
|
private float size;
|
|
|
|
private float per;
|
|
|
|
public MegaAxis axis;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
public override string ModName()
|
|
{
|
|
return "Cylindrify";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=166";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float num = Mathf.Exp((0f - Decay) * p.magnitude);
|
|
float num2 = (size / Mathf.Sqrt(p.x * p.x + p.z * p.z) / 2f - 1f) * per * num + 1f;
|
|
p.x *= num2;
|
|
p.z *= num2;
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public void SetTM1()
|
|
{
|
|
tm = Matrix4x4.identity;
|
|
MegaMatrix.RotateZ(ref tm, (0f - gizmoRot.z) * ((float)Math.PI / 180f));
|
|
MegaMatrix.RotateY(ref tm, (0f - gizmoRot.y) * ((float)Math.PI / 180f));
|
|
MegaMatrix.RotateX(ref tm, (0f - gizmoRot.x) * ((float)Math.PI / 180f));
|
|
MegaMatrix.SetTrans(ref tm, gizmoPos + Offset);
|
|
invtm = tm.inverse;
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
mat = Matrix4x4.identity;
|
|
switch (axis)
|
|
{
|
|
case MegaAxis.X:
|
|
MegaMatrix.RotateZ(ref mat, (float)Math.PI / 2f);
|
|
break;
|
|
case MegaAxis.Y:
|
|
MegaMatrix.RotateX(ref mat, -(float)Math.PI / 2f);
|
|
break;
|
|
}
|
|
SetAxis(mat);
|
|
float num = bbox.max.x - bbox.min.x;
|
|
float num2 = bbox.max.z - bbox.min.z;
|
|
size = ((!(num > num2)) ? num2 : num);
|
|
per = Percent / 100f;
|
|
return true;
|
|
}
|
|
}
|