151 lines
2.6 KiB
C#
151 lines
2.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Stretch")]
|
|
public class MegaStretch : MegaModifier
|
|
{
|
|
public float amount;
|
|
|
|
public bool doRegion;
|
|
|
|
public float to;
|
|
|
|
public float from;
|
|
|
|
public float amplify;
|
|
|
|
public MegaAxis axis;
|
|
|
|
private float heightMax;
|
|
|
|
private float heightMin;
|
|
|
|
private float amplifier;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
public bool useheightaxis;
|
|
|
|
public MegaAxis axis1;
|
|
|
|
private float ovh;
|
|
|
|
public override string ModName()
|
|
{
|
|
return "Stretch";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=334";
|
|
}
|
|
|
|
private void CalcBulge(MegaAxis axis, float stretch, float amplify)
|
|
{
|
|
amount = stretch;
|
|
amplifier = ((!(amplify >= 0f)) ? (1f / (0f - amplify + 1f)) : (amplify + 1f));
|
|
if (!doRegion)
|
|
{
|
|
switch (axis)
|
|
{
|
|
case MegaAxis.X:
|
|
heightMin = bbox.min.x;
|
|
heightMax = bbox.max.x;
|
|
break;
|
|
case MegaAxis.Z:
|
|
heightMin = bbox.min.y;
|
|
heightMax = bbox.max.y;
|
|
break;
|
|
case MegaAxis.Y:
|
|
heightMin = bbox.min.z;
|
|
heightMax = bbox.max.z;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
heightMin = from;
|
|
heightMax = to;
|
|
}
|
|
ovh = 1f / (heightMax - heightMin);
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
if (amount == 0f || heightMax - heightMin == 0f)
|
|
{
|
|
return p;
|
|
}
|
|
if (doRegion && to - from == 0f)
|
|
{
|
|
return p;
|
|
}
|
|
p = tm.MultiplyPoint3x4(p);
|
|
float num = ((doRegion && p.y > to) ? ((to - heightMin) * ovh) : ((!doRegion || !(p.y < from)) ? ((p.y - heightMin) * ovh) : ((from - heightMin) * ovh)));
|
|
float num2;
|
|
float num3;
|
|
if (amount < 0f)
|
|
{
|
|
num2 = amplifier * (0f - amount) + 1f;
|
|
num3 = -1f / (amount - 1f);
|
|
}
|
|
else
|
|
{
|
|
num2 = 1f / (amplifier * amount + 1f);
|
|
num3 = amount + 1f;
|
|
}
|
|
float num4 = 4f * (1f - num2);
|
|
float num5 = (num4 * num - num4) * num + 1f;
|
|
p.x *= num5;
|
|
p.z *= num5;
|
|
if (doRegion && p.y < from)
|
|
{
|
|
p.y += (num3 - 1f) * from;
|
|
}
|
|
else if (doRegion && p.y <= to)
|
|
{
|
|
p.y *= num3;
|
|
}
|
|
else if (doRegion && p.y > to)
|
|
{
|
|
p.y += (num3 - 1f) * to;
|
|
}
|
|
else
|
|
{
|
|
p.y *= num3;
|
|
}
|
|
p = invtm.MultiplyPoint3x4(p);
|
|
return p;
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
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);
|
|
CalcBulge(axis, amount, amplify);
|
|
return true;
|
|
}
|
|
|
|
public override void ExtraGizmo(MegaModContext mc)
|
|
{
|
|
if (doRegion)
|
|
{
|
|
DrawFromTo(axis, from, to, mc);
|
|
}
|
|
}
|
|
}
|