139 lines
2.2 KiB
C#
139 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Taper")]
|
|
public class MegaTaperWarp : MegaWarp
|
|
{
|
|
public float amount;
|
|
|
|
public bool doRegion;
|
|
|
|
public float to;
|
|
|
|
public float from;
|
|
|
|
public float dir;
|
|
|
|
public MegaAxis axis;
|
|
|
|
public MegaEffectAxis EAxis;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
public float crv;
|
|
|
|
public bool sym;
|
|
|
|
private bool doX;
|
|
|
|
private bool doY;
|
|
|
|
private float k1;
|
|
|
|
private float k2;
|
|
|
|
private float l;
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Taper";
|
|
}
|
|
|
|
public override string GetIcon()
|
|
{
|
|
return "MegaTaper icon.png";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=2566";
|
|
}
|
|
|
|
private void SetK(float K1, float K2)
|
|
{
|
|
k1 = K1;
|
|
k2 = K2;
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
if (l == 0f)
|
|
{
|
|
return p;
|
|
}
|
|
p = tm.MultiplyPoint3x4(p);
|
|
Vector3 a = p;
|
|
float magnitude = p.magnitude;
|
|
float t = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
|
|
float num = ((!doRegion) ? (p.y / l) : ((p.y < from) ? (from / l) : ((!(p.y > to)) ? (p.y / l) : (to / l))));
|
|
if (sym && num < 0f)
|
|
{
|
|
num = 0f - num;
|
|
}
|
|
float num2 = 1f + num * k1 + k2 * num * (1f - num);
|
|
if (doX)
|
|
{
|
|
p.x *= num2;
|
|
}
|
|
if (doY)
|
|
{
|
|
p.z *= num2;
|
|
}
|
|
p = Vector3.Lerp(a, p, t);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
switch (EAxis)
|
|
{
|
|
case MegaEffectAxis.X:
|
|
doX = true;
|
|
doY = false;
|
|
break;
|
|
case MegaEffectAxis.Y:
|
|
doX = false;
|
|
doY = true;
|
|
break;
|
|
case MegaEffectAxis.XY:
|
|
doX = true;
|
|
doY = true;
|
|
break;
|
|
}
|
|
mat = Matrix4x4.identity;
|
|
switch (axis)
|
|
{
|
|
case MegaAxis.X:
|
|
MegaMatrix.RotateZ(ref mat, (float)Math.PI / 2f);
|
|
l = Width;
|
|
break;
|
|
case MegaAxis.Y:
|
|
MegaMatrix.RotateX(ref mat, -(float)Math.PI / 2f);
|
|
l = Length;
|
|
break;
|
|
case MegaAxis.Z:
|
|
l = Height;
|
|
break;
|
|
}
|
|
MegaMatrix.RotateY(ref mat, (float)Math.PI / 180f * dir);
|
|
SetAxis(mat);
|
|
SetK(amount, crv);
|
|
totaldecay = Decay + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void ExtraGizmo()
|
|
{
|
|
if (doRegion)
|
|
{
|
|
DrawFromTo(axis, from, to);
|
|
}
|
|
}
|
|
}
|