188 lines
3.9 KiB
C#
188 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class MegaMorphBase : MegaModifier
|
|
{
|
|
[Serializable]
|
|
public class MegaMorphBlend
|
|
{
|
|
public float t;
|
|
|
|
public float weight;
|
|
}
|
|
|
|
public List<MegaMorphChan> chanBank = new List<MegaMorphChan>();
|
|
|
|
public MegaMorphAnimType animtype;
|
|
|
|
public int numblends;
|
|
|
|
public List<MegaMorphBlend> blends;
|
|
|
|
public override void PostCopy(MegaModifier src)
|
|
{
|
|
MegaMorphBase megaMorphBase = (MegaMorphBase)src;
|
|
chanBank = new List<MegaMorphChan>();
|
|
for (int i = 0; i < megaMorphBase.chanBank.Count; i++)
|
|
{
|
|
MegaMorphChan megaMorphChan = new MegaMorphChan();
|
|
MegaMorphChan.Copy(megaMorphBase.chanBank[i], megaMorphChan);
|
|
chanBank.Add(megaMorphChan);
|
|
}
|
|
}
|
|
|
|
public string[] GetChannelNames()
|
|
{
|
|
string[] array = new string[chanBank.Count];
|
|
for (int i = 0; i < chanBank.Count; i++)
|
|
{
|
|
array[i] = chanBank[i].mName;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
public MegaMorphChan GetChannel(string name)
|
|
{
|
|
for (int i = 0; i < chanBank.Count; i++)
|
|
{
|
|
if (chanBank[i].mName == name)
|
|
{
|
|
return chanBank[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int NumChannels()
|
|
{
|
|
return chanBank.Count;
|
|
}
|
|
|
|
public void SetPercent(int i, float percent)
|
|
{
|
|
if (i >= 0 && i < chanBank.Count)
|
|
{
|
|
chanBank[i].Percent = percent;
|
|
}
|
|
}
|
|
|
|
public void SetPercentLim(int i, float alpha)
|
|
{
|
|
if (i >= 0 && i < chanBank.Count)
|
|
{
|
|
if (chanBank[i].mUseLimit)
|
|
{
|
|
chanBank[i].Percent = chanBank[i].mSpinmin + (chanBank[i].mSpinmax - chanBank[i].mSpinmin) * alpha;
|
|
}
|
|
else
|
|
{
|
|
chanBank[i].Percent = alpha * 100f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetPercent(int i, float percent, float speed)
|
|
{
|
|
chanBank[i].SetTarget(percent, speed);
|
|
}
|
|
|
|
public void ResetPercent(int[] channels, float speed)
|
|
{
|
|
foreach (int index in channels)
|
|
{
|
|
chanBank[index].SetTarget(0f, speed);
|
|
}
|
|
}
|
|
|
|
public float GetPercent(int i)
|
|
{
|
|
if (i >= 0 && i < chanBank.Count)
|
|
{
|
|
return chanBank[i].Percent;
|
|
}
|
|
return 0f;
|
|
}
|
|
|
|
public void SetAnim(float t)
|
|
{
|
|
if (animtype == MegaMorphAnimType.Bezier)
|
|
{
|
|
for (int i = 0; i < chanBank.Count; i++)
|
|
{
|
|
if (chanBank[i].control != null && chanBank[i].control.Times != null && chanBank[i].control.Times.Length > 0)
|
|
{
|
|
chanBank[i].Percent = chanBank[i].control.GetFloat(t);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
for (int j = 0; j < chanBank.Count; j++)
|
|
{
|
|
if (chanBank[j].control != null && chanBank[j].control.Times != null && chanBank[j].control.Times.Length > 0)
|
|
{
|
|
chanBank[j].Percent = chanBank[j].control.GetHermiteFloat(t);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetAnimBlend(float t, float weight)
|
|
{
|
|
if (blends == null)
|
|
{
|
|
blends = new List<MegaMorphBlend>();
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
blends.Add(new MegaMorphBlend());
|
|
}
|
|
}
|
|
blends[numblends].t = t;
|
|
blends[numblends].weight = weight;
|
|
numblends++;
|
|
}
|
|
|
|
public void ClearBlends()
|
|
{
|
|
numblends = 0;
|
|
}
|
|
|
|
public void SetChannels()
|
|
{
|
|
float num = 0f;
|
|
for (int i = 0; i < numblends; i++)
|
|
{
|
|
num += blends[i].weight;
|
|
}
|
|
for (int j = 0; j < numblends; j++)
|
|
{
|
|
for (int k = 0; k < chanBank.Count; k++)
|
|
{
|
|
if (animtype == MegaMorphAnimType.Bezier)
|
|
{
|
|
if (chanBank[k].control != null && chanBank[k].control.Times != null && chanBank[k].control.Times.Length > 0)
|
|
{
|
|
if (j == 0)
|
|
{
|
|
chanBank[k].Percent = chanBank[k].control.GetFloat(blends[j].t) * (blends[j].weight / num);
|
|
}
|
|
else
|
|
{
|
|
chanBank[k].Percent += chanBank[k].control.GetFloat(blends[j].t) * (blends[j].weight / num);
|
|
}
|
|
}
|
|
}
|
|
else if (chanBank[k].control != null && chanBank[k].control.Times != null && chanBank[k].control.Times.Length > 0)
|
|
{
|
|
if (j == 0)
|
|
{
|
|
chanBank[k].Percent = chanBank[k].control.GetHermiteFloat(blends[j].t) * (blends[j].weight / num);
|
|
}
|
|
else
|
|
{
|
|
chanBank[k].Percent += chanBank[k].control.GetHermiteFloat(blends[j].t) * (blends[j].weight / num);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|