105 lines
1.7 KiB
C#
105 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Rolled")]
|
|
public class MegaRolled : MegaModifier
|
|
{
|
|
public float radius = 1f;
|
|
|
|
public Transform roller;
|
|
|
|
public float splurge = 1f;
|
|
|
|
public MegaAxis fwdaxis = MegaAxis.Z;
|
|
|
|
private Matrix4x4 mat = default(Matrix4x4);
|
|
|
|
private Vector3[] offsets;
|
|
|
|
private Plane plane;
|
|
|
|
private float height;
|
|
|
|
private Vector3 rpos;
|
|
|
|
public bool clearoffsets;
|
|
|
|
private float delta;
|
|
|
|
public override string ModName()
|
|
{
|
|
return "Rolled";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=1292";
|
|
}
|
|
|
|
public override Vector3 Map(int i, Vector3 p)
|
|
{
|
|
if (i >= 0)
|
|
{
|
|
p = tm.MultiplyPoint3x4(p);
|
|
if (p.z > rpos.z)
|
|
{
|
|
p.y *= delta;
|
|
p.x += (1f - delta) * splurge * p.x;
|
|
p.z += (1f - delta) * splurge * (p.z - rpos.z);
|
|
}
|
|
p = invtm.MultiplyPoint3x4(p);
|
|
}
|
|
return p;
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
if (!roller)
|
|
{
|
|
return false;
|
|
}
|
|
rpos = base.transform.worldToLocalMatrix.MultiplyPoint3x4(roller.position);
|
|
height = rpos.y - radius;
|
|
if (offsets == null || offsets.Length != mc.mod.verts.Length)
|
|
{
|
|
offsets = new Vector3[mc.mod.verts.Length];
|
|
}
|
|
mat = Matrix4x4.identity;
|
|
SetAxis(mat);
|
|
tm = Matrix4x4.identity;
|
|
if (clearoffsets)
|
|
{
|
|
clearoffsets = false;
|
|
for (int i = 0; i < offsets.Length; i++)
|
|
{
|
|
offsets[i] = Vector3.zero;
|
|
}
|
|
}
|
|
if (height < mc.bbox.Size().y)
|
|
{
|
|
delta = height / mc.bbox.Size().y;
|
|
}
|
|
else
|
|
{
|
|
delta = 1f;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override void PrepareMT(MegaModifiers mc, int cores)
|
|
{
|
|
}
|
|
|
|
public override void DoWork(MegaModifiers mc, int index, int start, int end, int cores)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
Modify(mc);
|
|
}
|
|
}
|
|
}
|