126 lines
1.9 KiB
C#
126 lines
1.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Warps/Skew")]
|
|
public class MegaSkewWarp : MegaWarp
|
|
{
|
|
public float amount;
|
|
|
|
public bool doRegion;
|
|
|
|
public float to;
|
|
|
|
public float from;
|
|
|
|
public float dir;
|
|
|
|
public MegaAxis axis;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
private float amountOverLength;
|
|
|
|
public override string WarpName()
|
|
{
|
|
return "Skew";
|
|
}
|
|
|
|
public override string GetIcon()
|
|
{
|
|
return "MegaSkew icon.png";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=2571";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
Vector3 a = p;
|
|
float magnitude = p.magnitude;
|
|
float t = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude));
|
|
float num = p.y;
|
|
if (doRegion)
|
|
{
|
|
if (p.y < from)
|
|
{
|
|
num = from;
|
|
}
|
|
else if (p.y > to)
|
|
{
|
|
num = to;
|
|
}
|
|
}
|
|
p.x -= num * amountOverLength;
|
|
p = Vector3.Lerp(a, p, t);
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool Prepare(float decay)
|
|
{
|
|
tm = base.transform.worldToLocalMatrix;
|
|
invtm = tm.inverse;
|
|
if (from > 0f)
|
|
{
|
|
from = 0f;
|
|
}
|
|
if (to < 0f)
|
|
{
|
|
to = 0f;
|
|
}
|
|
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;
|
|
}
|
|
MegaMatrix.RotateY(ref mat, (float)Math.PI / 180f * dir);
|
|
SetAxis(mat);
|
|
float num = 0f;
|
|
if (!doRegion)
|
|
{
|
|
switch (axis)
|
|
{
|
|
case MegaAxis.X:
|
|
num = Width;
|
|
break;
|
|
case MegaAxis.Z:
|
|
num = Height;
|
|
break;
|
|
case MegaAxis.Y:
|
|
num = Length;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num = to - from;
|
|
}
|
|
if (num == 0f)
|
|
{
|
|
num = 1E-06f;
|
|
}
|
|
amountOverLength = amount / num;
|
|
totaldecay = Decay + decay;
|
|
if (totaldecay < 0f)
|
|
{
|
|
totaldecay = 0f;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void ExtraGizmo()
|
|
{
|
|
if (doRegion)
|
|
{
|
|
DrawFromTo(axis, from, to);
|
|
}
|
|
}
|
|
}
|