Notifications
Clear all
[Closed] [C#] AddBezierKey
Jul 30, 2019 10:31 pm
I just created this function to add new bezierkeys on bezier_float controller:
public static class TestClass
{
static IGlobal globalInterface = GlobalInterface.Instance;
static IInterface coreInterface = globalInterface.COREInterface;
public static class TangentType
{
public static uint Smooth = 0, Linear = 1, Step = 2, Fast = 3, Slow = 4, User = 5, Flat = 6;
}
const uint NUM_TANGENTTYPES = 7;
const uint BEZKEY_NUMTYPEBITS = 3;
const int BEZKEY_INTYPESHIFT = 7;
const int BEZKEY_OUTTYPESHIFT = (int)(BEZKEY_INTYPESHIFT + BEZKEY_NUMTYPEBITS);
const uint BEZKEY_TYPEMASK = 7;
public static void SetInTanType(ref IIBezFloatKey key, uint t)
{
key.Flags = (key.Flags & (~(BEZKEY_TYPEMASK << BEZKEY_INTYPESHIFT))) | (t << BEZKEY_INTYPESHIFT);
}
public static void SetOutTanType(ref IIBezFloatKey key, uint t)
{
key.Flags = (key.Flags & (~(BEZKEY_TYPEMASK << BEZKEY_OUTTYPESHIFT))) | (t << BEZKEY_OUTTYPESHIFT);
}
public static uint GetTangentType(string type)
{
switch (type)
{
case "Smooth":
return 0;
case "Linear":
return 1;
case "Step":
return 2;
case "Fast":
return 3;
case "Slow":
return 4;
case "User":
return 5;
case "Flat":
return 6;
default:
return 0;
}
}
public static void AddBezierKeys(UIntPtr controllerHandle,int[] time,float[] value,float[] inTangent,float[] outTangent, float[] inTangentLength,float[] outTangentLength, string[] inTangentType,string[] outTangentType)
{
globalInterface.SuspendAnimate();
IControl control = (IControl)globalInterface.Animatable.GetAnimByHandle(controllerHandle);
IIKeyControl keyControl = (IIKeyControl)(control.GetInterface(InterfaceID.Keycontrol));
if (keyControl == null) return;
IIBezFloatKey key = globalInterface.IBezFloatKey.Create();
for (var i = 0; i < time.Length; i++)
{
control.AddNewKey(time[i]*globalInterface.TicksPerFrame, 1);
keyControl.GetKey(i, key);
key.Val = value[i];
key.Intan = inTangent[i];
key.Outtan = outTangent[i];
key.InLength = inTangentLength[i];
key.OutLength = outTangentLength[i];
SetInTanType(ref key, GetTangentType(inTangentType[i]));
SetOutTanType(ref key, GetTangentType(outTangentType[i]));
keyControl.SetKey(i, key);
}
keyControl.SortKeys();
control.Dispose();
keyControl.Dispose();
key.Dispose();
globalInterface.ResumeAnimate();
}
}
Everything works find but there is slightly difference between saved and loaded animation.I know I missed 4 key properties x_locked, y_locked, z_locked, constantVelocity, freeHandle. But I couldn’t find them in the IIBezFloatKey.