Przeglądaj źródła

Added a flags field to animation curves

BearishSun 9 lat temu
rodzic
commit
950b5b52d7

+ 11 - 0
Source/BansheeCore/Include/BsAnimationCurve.h

@@ -154,11 +154,22 @@ namespace BansheeEngine
 		float mLength;
 	};
 
+	/** Flags that described an TAnimationCurve<T>. */
+	enum class AnimationCurveFlag
+	{
+		/** Signifies that the curve was imported from an external file, and not created manually in-engine. */
+		ImportedCurve
+	};
+
+	typedef Flags<AnimationCurveFlag> AnimationCurveFlags;
+	BS_FLAGS_OPERATORS(AnimationCurveFlag);
+
 	/** An animation curve and its name. */
 	template <class T>
 	struct TNamedAnimationCurve
 	{
 		String name;
+		AnimationCurveFlags flags;
 		TAnimationCurve<T> curve;
 	};
 

+ 3 - 0
Source/BansheeCore/Include/BsAnimationCurveRTTI.h

@@ -110,6 +110,7 @@ namespace BansheeEngine
 			memory += sizeof(UINT32);
 
 			memory = rttiWriteElem(data.name, memory, size);
+			memory = rttiWriteElem(data.flags, memory, size);
 			memory = rttiWriteElem(data.curve, memory, size);
 
 			memcpy(memoryStart, &size, sizeof(UINT32));
@@ -122,6 +123,7 @@ namespace BansheeEngine
 			memory = rttiReadElem(size, memory);
 
 			memory = rttiReadElem(data.name, memory);
+			memory = rttiReadElem(data.flags, memory);
 			memory = rttiReadElem(data.curve, memory);
 
 			return size;
@@ -132,6 +134,7 @@ namespace BansheeEngine
 		{
 			UINT64 dataSize = sizeof(UINT32);
 			dataSize += rttiGetElemSize(data.name);
+			dataSize += rttiGetElemSize(data.flags);
 			dataSize += rttiGetElemSize(data.curve);
 
 			assert(dataSize <= std::numeric_limits<UINT32>::max());

+ 4 - 4
Source/BansheeCore/Source/BsAnimationClip.cpp

@@ -15,7 +15,7 @@ namespace BansheeEngine
 		if (iterFind != position.end())
 			iterFind->curve = curve;
 		else
-			position.push_back({ name, curve });
+			position.push_back({ name, AnimationCurveFlags(), curve });
 	}
 
 	void AnimationCurves::addRotationCurve(const String& name, const TAnimationCurve<Quaternion>& curve)
@@ -25,7 +25,7 @@ namespace BansheeEngine
 		if (iterFind != rotation.end())
 			iterFind->curve = curve;
 		else
-			rotation.push_back({ name, curve });
+			rotation.push_back({ name, AnimationCurveFlags(), curve });
 	}
 
 	void AnimationCurves::addScaleCurve(const String& name, const TAnimationCurve<Vector3>& curve)
@@ -35,7 +35,7 @@ namespace BansheeEngine
 		if (iterFind != scale.end())
 			iterFind->curve = curve;
 		else
-			scale.push_back({ name, curve });
+			scale.push_back({ name, AnimationCurveFlags(), curve });
 	}
 
 	void AnimationCurves::addGenericCurve(const String& name, const TAnimationCurve<float>& curve)
@@ -45,7 +45,7 @@ namespace BansheeEngine
 		if (iterFind != generic.end())
 			iterFind->curve = curve;
 		else
-			generic.push_back({ name, curve });
+			generic.push_back({ name, AnimationCurveFlags(), curve });
 	}
 
 	void AnimationCurves::removePositionCurve(const String& name)

+ 3 - 3
Source/BansheeFBXImporter/Source/BsFBXImporter.cpp

@@ -444,9 +444,9 @@ namespace BansheeEngine
 			
 			for (auto& bone : clip.boneAnimations)
 			{
-				curves->position.push_back({ bone.node->name, bone.translation });
-				curves->rotation.push_back({ bone.node->name, bone.rotation });
-				curves->scale.push_back({ bone.node->name, bone.scale });
+				curves->position.push_back({ bone.node->name, AnimationCurveFlag::ImportedCurve, bone.translation });
+				curves->rotation.push_back({ bone.node->name, AnimationCurveFlag::ImportedCurve, bone.rotation });
+				curves->scale.push_back({ bone.node->name, AnimationCurveFlag::ImportedCurve, bone.scale });
 			}
 
 			// See if any splits are required. We only split the first clip as it is assumed if FBX has multiple clips the

+ 54 - 1
Source/MBansheeEngine/Animation/AnimationCurve.cs

@@ -30,6 +30,19 @@ namespace BansheeEngine
         public float time;
     }
 
+    /// <summary>
+    /// Flags that describe an <see cref="AnimationCurve"/>
+    /// </summary>
+    public enum AnimationCurveFlags // Note: Must match C++ enum AnimationCurveFlags
+    {
+        /// <summary>
+        /// 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).
+        /// </summary>
+        ImportedCurve
+    }
+
     /// <summary>
     /// 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.
@@ -90,6 +103,23 @@ namespace BansheeEngine
     /// </summary>
     public class NamedVector3Curve
     {
+        /// <summary>
+        /// Constructor for internal runtime use only.
+        /// </summary>
+        /// <param name="name">Name of the curve.</param>
+        /// <param name="flags">Flags that describe the animation curve, of type <see cref="AnimationCurveFlags"/>.</param>
+        /// <param name="x">Curve representing the x axis of the vector.</param>
+        /// <param name="y">Curve representing the y axis of the vector.</param>
+        /// <param name="z">Curve representing the z axis of the vector.</param>
+        private NamedVector3Curve(string name, int flags, AnimationCurve x, AnimationCurve y, AnimationCurve z)
+        {
+            Name = name;
+            Flags = (AnimationCurveFlags) flags;
+            X = x;
+            Y = y;
+            Z = z;
+        }
+
         /// <summary>
         /// Constructs a new named animation curve.
         /// </summary>
@@ -110,6 +140,11 @@ namespace BansheeEngine
         /// </summary>
         public string Name;
 
+        /// <summary>
+        /// Flags that describe the animation curve.
+        /// </summary>
+        public AnimationCurveFlags Flags;
+
         /// <summary>
         /// Animation curve for the x axis.
         /// </summary>
@@ -127,10 +162,23 @@ namespace BansheeEngine
     }
 
     /// <summary>
-    /// An animatio curve for a single floating point value paired with a name.
+    /// An animation curve for a single floating point value paired with a name.
     /// </summary>
     public class NamedFloatCurve
     {
+        /// <summary>
+        /// Constructor for internal runtime use only.
+        /// </summary>
+        /// <param name="name">Name of the curve.</param>
+        /// <param name="flags">Flags that describe the animation curve, of type <see cref="AnimationCurveFlags"/>.</param>
+        /// <param name="curve">Curve representing the floating point values.</param>
+        private NamedFloatCurve(string name, int flags, AnimationCurve curve)
+        {
+            Name = name;
+            Flags = (AnimationCurveFlags)flags;
+            Curve = curve;
+        }
+
         /// <summary>
         /// Constructs a new named animation curve.
         /// </summary>
@@ -147,6 +195,11 @@ namespace BansheeEngine
         /// </summary>
         public string Name;
 
+        /// <summary>
+        /// Flags that describe the animation curve.
+        /// </summary>
+        public AnimationCurveFlags Flags;
+
         /// <summary>
         /// Animation curve.
         /// </summary>

+ 2 - 0
Source/SBansheeEngine/Include/BsScriptAnimationCurves.h

@@ -53,6 +53,7 @@ namespace BansheeEngine
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
 		static MonoField* sNameField;
+		static MonoField* sFlagsField;
 		static MonoField* sXCurveField;
 		static MonoField* sYCurveField;
 		static MonoField* sZCurveField;
@@ -76,6 +77,7 @@ namespace BansheeEngine
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
 		static MonoField* sNameField;
+		static MonoField* sFlagsField;
 		static MonoField* sCurveField;
 	};
 

+ 19 - 4
Source/SBansheeEngine/Source/BsScriptAnimationCurves.cpp

@@ -149,6 +149,7 @@ namespace BansheeEngine
 	}
 
 	MonoField* ScriptNamedVector3Curve::sNameField = nullptr;
+	MonoField* ScriptNamedVector3Curve::sFlagsField = nullptr;
 	MonoField* ScriptNamedVector3Curve::sXCurveField = nullptr;
 	MonoField* ScriptNamedVector3Curve::sYCurveField = nullptr;
 	MonoField* ScriptNamedVector3Curve::sZCurveField = nullptr;
@@ -160,6 +161,7 @@ namespace BansheeEngine
 	void ScriptNamedVector3Curve::initRuntimeData()
 	{
 		sNameField = metaData.scriptClass->getField("Name");
+		sFlagsField = metaData.scriptClass->getField("Flags");
 		sXCurveField = metaData.scriptClass->getField("X");
 		sYCurveField = metaData.scriptClass->getField("Y");
 		sZCurveField = metaData.scriptClass->getField("Z");
@@ -174,6 +176,10 @@ namespace BansheeEngine
 
 		output.name = MonoUtil::monoToString(monoName);
 
+		UINT32 flags;
+		sFlagsField->getValue(instance, &flags);
+		output.flags = (AnimationCurveFlags)flags;
+
 		// Convert from three separate floating point curves, to a Vector3 curve
 		MonoObject* monoCurves[3];
 		sXCurveField->getValue(instance, &monoCurves[0]);
@@ -278,11 +284,14 @@ namespace BansheeEngine
 		MonoObject* monoYCurve = ScriptAnimationCurve::create(yCurve);
 		MonoObject* monoZCurve = ScriptAnimationCurve::create(zCurve);
 
-		void* params[4] = { monoString, monoXCurve, monoYCurve, monoZCurve };
-		return metaData.scriptClass->createInstance("string, AnimationCurve, AnimationCurve, AnimationCurve", params);
+		UINT32 flags = curve.flags;
+
+		void* params[5] = { monoString, &flags, monoXCurve, monoYCurve, monoZCurve };
+		return metaData.scriptClass->createInstance("string, int, AnimationCurve, AnimationCurve, AnimationCurve", params);
 	}
 
 	MonoField* ScriptNamedFloatCurve::sNameField = nullptr;
+	MonoField* ScriptNamedFloatCurve::sFlagsField = nullptr;
 	MonoField* ScriptNamedFloatCurve::sCurveField = nullptr;
 
 	ScriptNamedFloatCurve::ScriptNamedFloatCurve(MonoObject* instance)
@@ -292,6 +301,7 @@ namespace BansheeEngine
 	void ScriptNamedFloatCurve::initRuntimeData()
 	{
 		sNameField = metaData.scriptClass->getField("Name");
+		sFlagsField = metaData.scriptClass->getField("Flags");
 		sCurveField = metaData.scriptClass->getField("Curve");
 	}
 
@@ -304,6 +314,10 @@ namespace BansheeEngine
 
 		output.name = MonoUtil::monoToString(monoName);
 
+		UINT32 flags;
+		sFlagsField->getValue(instance, &flags);
+		output.flags = (AnimationCurveFlags)flags;
+
 		MonoObject* monoCurve = nullptr;
 		sCurveField->getValue(instance, &monoCurve);
 
@@ -321,7 +335,8 @@ namespace BansheeEngine
 		MonoString* monoString = MonoUtil::stringToMono(curve.name);
 		MonoObject* monoCurve = ScriptAnimationCurve::create(curve.curve);
 
-		void* params[2] = { monoString, monoCurve };
-		return metaData.scriptClass->createInstance("string, AnimationCurve", params);
+		UINT32 flags = curve.flags;
+		void* params[3] = { monoString, &flags, monoCurve };
+		return metaData.scriptClass->createInstance("string, int, AnimationCurve", params);
 	}
 }