//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace BansheeEngine
{
///
/// Animation keyframe, represented as an endpoint of a cubic hermite spline.
///
[StructLayout(LayoutKind.Sequential), SerializeObject]
public struct KeyFrame // Note: Must match C++ struct TKeyFrame
{
///
/// Value of the key.
///
public float value;
///
/// Input tangent (going from the previous key to this one) of the key.
///
public float inTangent;
///
/// Output tangent (going from this key to next one) of the key.
///
public float outTangent;
///
/// Position of the key along the animation spline.
///
public float time;
}
///
/// Flags that describe an
///
public enum AnimationCurveFlags // Note: Must match C++ enum AnimationCurveFlags
{
///
/// If enabled, the curve was imported from an external file and not created within the engine. This will affect
/// how are animation results applied to scene objects (with imported animations it is assumed the curve is
/// animating bones and with in-engine curves it is assumed the curve is animating scene objects).
///
ImportedCurve = 1 << 0,
///
/// Signifies the curve is used to animate between different frames within a morph channel. In range [0, 1].
///
MorphFrame = 1 << 1,
///
/// Signifies the curve is used to adjust the weight of a morph channel. In range [0, 1].
///
MorphWeight = 1 << 2
}
///
/// Animation spline represented by a set of keyframes, each representing an endpoint of a cubic hermite curve. The
/// spline can be evaluated at any time, and uses caching to speed up multiple sequential evaluations.
///
public class AnimationCurve : ScriptObject
{
///
/// Constructor for internal runtime use only.
///
private AnimationCurve()
{ }
///
/// Creates a new animation curve.
///
/// Keyframes to initialize the curve with.
public AnimationCurve(KeyFrame[] keyFrames)
{
Internal_Create(this, keyFrames);
}
///
/// Keyframes that represent the curve.
///
public KeyFrame[] KeyFrames
{
get { return Internal_GetKeyFrames(mCachedPtr); }
set { Internal_SetKeyFrames(mCachedPtr, value); }
}
///
/// Evaluate the animation curve at the specified time.
///
/// Time to evaluate the curve at.
/// If true the curve will loop when it goes past the end or beggining. Otherwise the curve
/// value will be clamped.
/// Interpolated value from the curve at provided time.
public float Evaluate(float time, bool loop = true)
{
return Internal_Evaluate(mCachedPtr, time, loop);
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Create(AnimationCurve instance, KeyFrame[] keyframes);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern KeyFrame[] Internal_GetKeyFrames(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetKeyFrames(IntPtr thisPtr, KeyFrame[] keyframes);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_Evaluate(IntPtr thisPtr, float time, bool loop);
}
///
/// A set of animation curves for a 3D vector paired with a name.
///
public class NamedVector3Curve
{
///
/// Constructor for internal runtime use only.
///
/// Name of the curve.
/// Flags that describe the animation curve, of type .
/// Curve representing the x axis of the vector.
/// Curve representing the y axis of the vector.
/// Curve representing the z axis of the vector.
private NamedVector3Curve(string name, int flags, AnimationCurve x, AnimationCurve y, AnimationCurve z)
{
Name = name;
Flags = (AnimationCurveFlags) flags;
X = x;
Y = y;
Z = z;
}
///
/// Constructs a new named animation curve.
///
/// Name of the curve.
/// Curve representing the x axis of the vector.
/// Curve representing the y axis of the vector.
/// Curve representing the z axis of the vector.
public NamedVector3Curve(string name, AnimationCurve x, AnimationCurve y, AnimationCurve z)
{
Name = name;
X = x;
Y = y;
Z = z;
}
///
/// Name of the curve.
///
public string Name;
///
/// Flags that describe the animation curve.
///
public AnimationCurveFlags Flags;
///
/// Animation curve for the x axis.
///
public AnimationCurve X;
///
/// Animation curve for the y axis.
///
public AnimationCurve Y;
///
/// Animation curve for the z axis.
///
public AnimationCurve Z;
}
///
/// An animation curve for a single floating point value paired with a name.
///
public class NamedFloatCurve
{
///
/// Constructor for internal runtime use only.
///
/// Name of the curve.
/// Flags that describe the animation curve, of type .
/// Curve representing the floating point values.
private NamedFloatCurve(string name, int flags, AnimationCurve curve)
{
Name = name;
Flags = (AnimationCurveFlags)flags;
Curve = curve;
}
///
/// Constructs a new named animation curve.
///
/// Name of the curve.
/// Curve representing the floating point values.
public NamedFloatCurve(string name, AnimationCurve curve)
{
Name = name;
Curve = curve;
}
///
/// Name of the curve.
///
public string Name;
///
/// Flags that describe the animation curve.
///
public AnimationCurveFlags Flags;
///
/// Animation curve.
///
public AnimationCurve Curve;
}
}