186 lines
4.0 KiB
C#
186 lines
4.0 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Modifiers/Vertex Anim")]
|
|
public class MegaVertexAnim : MegaModifier
|
|
{
|
|
public float time;
|
|
|
|
public bool animated;
|
|
|
|
public float speed = 1f;
|
|
|
|
public float maxtime = 4f;
|
|
|
|
public int[] NoAnim;
|
|
|
|
public float weight = 1f;
|
|
|
|
public MegaAnimatedVert[] Verts;
|
|
|
|
private float t;
|
|
|
|
public MegaBlendAnimMode blendMode = MegaBlendAnimMode.Additive;
|
|
|
|
public MegaRepeatMode LoopMode = MegaRepeatMode.PingPong;
|
|
|
|
public override string ModName()
|
|
{
|
|
return "AnimatedMesh";
|
|
}
|
|
|
|
public override string GetHelpURL()
|
|
{
|
|
return "?page_id=1350";
|
|
}
|
|
|
|
private void Replace(MegaModifiers mc, int startvert, int endvert)
|
|
{
|
|
for (int i = startvert; i < endvert; i++)
|
|
{
|
|
MegaBezVector3KeyControl con = Verts[i].con;
|
|
Vector3 vector = con.GetVector3(t);
|
|
for (int j = 0; j < Verts[i].indices.Length; j++)
|
|
{
|
|
sverts[Verts[i].indices[j]] = vector;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ReplaceWeighted(MegaModifiers mc, int startvert, int endvert)
|
|
{
|
|
for (int i = startvert; i < endvert; i++)
|
|
{
|
|
MegaBezVector3KeyControl con = Verts[i].con;
|
|
Vector3 vector = con.GetVector3(t);
|
|
float num = mc.selection[Verts[i].indices[0]] * weight;
|
|
Vector3 vector2 = verts[Verts[i].indices[0]];
|
|
vector = vector2 + (vector - vector2) * num;
|
|
for (int j = 0; j < Verts[i].indices.Length; j++)
|
|
{
|
|
sverts[Verts[i].indices[j]] = vector;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Additive(MegaModifiers mc, int startvert, int endvert)
|
|
{
|
|
for (int i = startvert; i < endvert; i++)
|
|
{
|
|
MegaBezVector3KeyControl con = Verts[i].con;
|
|
Vector3 vector = mc.verts[Verts[i].indices[0]];
|
|
Vector3 vector2 = con.GetVector3(t) - vector;
|
|
vector2 = verts[Verts[i].indices[0]] + vector2 * weight;
|
|
for (int j = 0; j < Verts[i].indices.Length; j++)
|
|
{
|
|
int num = Verts[i].indices[j];
|
|
sverts[num] = vector2;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AdditiveWeighted(MegaModifiers mc, int startvert, int endvert)
|
|
{
|
|
for (int i = startvert; i < endvert; i++)
|
|
{
|
|
MegaBezVector3KeyControl con = Verts[i].con;
|
|
Vector3 vector = mc.verts[Verts[i].indices[0]];
|
|
Vector3 vector2 = con.GetVector3(t) - vector;
|
|
float num = mc.selection[Verts[i].indices[0]] * weight;
|
|
Vector3 vector3 = verts[Verts[i].indices[0]];
|
|
vector2 = vector3 + (vector2 - vector3) * num;
|
|
for (int j = 0; j < Verts[i].indices.Length; j++)
|
|
{
|
|
int num2 = Verts[i].indices[j];
|
|
sverts[num2] = vector2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void Modify(MegaModifiers mc)
|
|
{
|
|
switch (blendMode)
|
|
{
|
|
case MegaBlendAnimMode.Additive:
|
|
Additive(mc, 0, Verts.Length);
|
|
break;
|
|
case MegaBlendAnimMode.Replace:
|
|
Replace(mc, 0, Verts.Length);
|
|
break;
|
|
}
|
|
if (NoAnim != null)
|
|
{
|
|
for (int i = 0; i < NoAnim.Length; i++)
|
|
{
|
|
int num = NoAnim[i];
|
|
sverts[num] = verts[num];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool ModLateUpdate(MegaModContext mc)
|
|
{
|
|
if (animated)
|
|
{
|
|
time += Time.deltaTime * speed;
|
|
}
|
|
switch (LoopMode)
|
|
{
|
|
case MegaRepeatMode.Loop:
|
|
t = Mathf.Repeat(time, maxtime);
|
|
break;
|
|
case MegaRepeatMode.PingPong:
|
|
t = Mathf.PingPong(time, maxtime);
|
|
break;
|
|
case MegaRepeatMode.Clamp:
|
|
t = Mathf.Clamp(time, 0f, maxtime);
|
|
break;
|
|
}
|
|
return Prepare(mc);
|
|
}
|
|
|
|
public override bool Prepare(MegaModContext mc)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public override void DoWork(MegaModifiers mc, int index, int start, int end, int cores)
|
|
{
|
|
ModifyCompressedMT(mc, index, cores);
|
|
}
|
|
|
|
public void ModifyCompressedMT(MegaModifiers mc, int tindex, int cores)
|
|
{
|
|
int num = NoAnim.Length / cores;
|
|
int num2 = tindex * num;
|
|
int num3 = num2 + num;
|
|
if (tindex == cores - 1)
|
|
{
|
|
num3 = NoAnim.Length;
|
|
}
|
|
if (NoAnim != null)
|
|
{
|
|
for (int i = num2; i < num3; i++)
|
|
{
|
|
int num4 = NoAnim[i];
|
|
sverts[num4] = verts[num4];
|
|
}
|
|
}
|
|
num = Verts.Length / cores;
|
|
num2 = tindex * num;
|
|
num3 = num2 + num;
|
|
if (tindex == cores - 1)
|
|
{
|
|
num3 = Verts.Length;
|
|
}
|
|
switch (blendMode)
|
|
{
|
|
case MegaBlendAnimMode.Additive:
|
|
Additive(mc, num2, num3);
|
|
break;
|
|
case MegaBlendAnimMode.Replace:
|
|
Replace(mc, num2, num3);
|
|
break;
|
|
}
|
|
}
|
|
}
|