72 lines
1.4 KiB
C#
72 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Cylindrify")]
|
|
public class MegaCylindrifyWarp : MegaWarp
|
|
{
|
|
public float Percent;
|
|
|
|
private float size1;
|
|
|
|
private float per;
|
|
|
|
public MegaAxis axis;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Cylindrify";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=166";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
Vector3 a = p;
|
|
float magnitude = p.magnitude;
|
|
float num = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
|
|
float num2 = (size1 / Mathf.Sqrt(p.x * p.x + p.z * p.z) / 2f - 1f) * per * num + 1f;
|
|
p.x *= num2;
|
|
p.z *= num2;
|
|
p = Vector3.Lerp(a, p, num);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
Prepare(Decay);
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
totaldecay = Decay + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
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 width = Width;
|
|
float length = Length;
|
|
size1 = ((!(width > length)) ? length : width);
|
|
per = Percent / 100f;
|
|
return true;
|
|
}
|
|
}
|