115 lines
1.7 KiB
C#
115 lines
1.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Skew")]
|
|
public class MegaSkew : MegaModifier
|
|
{
|
|
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 ModName()
|
|
{
|
|
return "Skew";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=319";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float num = p.y;
|
|
if (doRegion)
|
|
{
|
|
if (p.y < from)
|
|
{
|
|
num = from;
|
|
}
|
|
else if (p.y > to)
|
|
{
|
|
num = to;
|
|
}
|
|
}
|
|
p.x -= num * amountOverLength;
|
|
return invtm.MultiplyPoint3x4(p);
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
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 = bbox.max.x - bbox.min.x;
|
|
break;
|
|
case MegaAxis.Z:
|
|
num = bbox.max.y - bbox.min.y;
|
|
break;
|
|
case MegaAxis.Y:
|
|
num = bbox.max.z - bbox.min.z;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
num = to - from;
|
|
}
|
|
if (num == 0f)
|
|
{
|
|
num = 1E-06f;
|
|
}
|
|
amountOverLength = amount / num;
|
|
return true;
|
|
}
|
|
|
|
public override void ExtraGizmo(MegaModContext mc)
|
|
{
|
|
if (doRegion)
|
|
{
|
|
DrawFromTo(axis, from, to, mc);
|
|
}
|
|
}
|
|
}
|