فهرست منبع

Added data structures required for storing morph shape animation

BearishSun 9 سال پیش
والد
کامیت
73a81b29b3

+ 3 - 0
Source/BansheeCore/CMakeSources.cmake

@@ -348,6 +348,7 @@ set(BS_BANSHEECORE_INC_RTTI
 	"Include/BsCCameraRTTI.h"
 	"Include/BsCameraRTTI.h"
 	"Include/BsPostProcessSettingsRTTI.h"
+	"Include/BsMorphShapesRTTI.h"
 )
 
 set(BS_BANSHEECORE_SRC_RENDERER
@@ -517,6 +518,7 @@ set(BS_BANSHEECORE_INC_ANIMATION
 	"Include/BsCurveCache.h"
 	"Include/BsAnimationUtility.h"
 	"Include/BsSkeletonMask.h"
+	"Include/BsMorphShapes.h"
 )
 
 set(BS_BANSHEECORE_SRC_ANIMATION
@@ -527,6 +529,7 @@ set(BS_BANSHEECORE_SRC_ANIMATION
 	"Source/BsAnimationManager.cpp"
 	"Source/BsAnimationUtility.cpp"
 	"Source/BsSkeletonMask.cpp"
+	"Source/BsMorphShapes.cpp"
 )
 
 source_group("Header Files\\Components" FILES ${BS_BANSHEECORE_INC_COMPONENTS})

+ 2 - 0
Source/BansheeCore/Include/BsCorePrerequisites.h

@@ -539,6 +539,8 @@ namespace BansheeEngine
 		TID_CBone = 1125,
 		TID_MaterialParamData = 1126,
 		TID_PostProcessSettings = 1127,
+		TID_MorphShape = 1128,
+		TID_MorphShapes = 1129,
 
 		// Moved from Engine layer
 		TID_CCamera = 30000,

+ 95 - 0
Source/BansheeCore/Include/BsMorphShapes.h

@@ -0,0 +1,95 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+#include "BsVector3.h"
+
+namespace BansheeEngine
+{
+	/** @addtogroup Animation-Internal
+	 *  @{
+	 */
+
+	/** A single vertex used for morph target animation. Contains a difference between base and target shape. */
+	struct BS_CORE_EXPORT MorphVertex
+	{
+		Vector3 deltaPosition;
+		Vector3 deltaNormal;
+		UINT32 sourceIdx;
+	};
+
+	/** 
+	 * A set of vertices representing a single shape in a morph target animation. Vertices are represented as a difference
+	 * between base and target shape.
+	 */
+	class BS_CORE_EXPORT MorphShape : public IReflectable
+	{
+	public:
+		MorphShape(const String& name, const Vector<MorphVertex>& vertices);
+
+		/** Returns the name of the shape. */
+		const String& getName() const { return mName; }
+
+		/** Returns a reference to all of the shape's vertices. Contains only vertices that differ from the base. */
+		const Vector<MorphVertex>& getVertices() const { return mVertices; }
+
+		/** Creates a new morph shape from the provided set of vertices. */
+		SPtr<MorphShape> create(const String& name, const Vector<MorphVertex>& vertices);
+
+	private:
+		String mName;
+		Vector<MorphVertex> mVertices;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class MorphShapeRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		RTTITypeBase* getRTTI() const override;
+
+		MorphShape(); // Serialization only
+	};
+
+	/** 
+	 * Contains a set of morph shapes, used for morph target animation. Each morph shape contains a single possible shape
+	 * that can be added on top of the base shape in order to create the animation.
+	 */
+	class BS_CORE_EXPORT MorphShapes : public IReflectable // Note: Must be immutable in order to be usable on multiple threads
+	{
+	public:
+		/** Returns the number of available morph shapes. */
+		UINT32 getNumShapes() const { return (UINT32)mShapes.size(); }
+
+		/** Returns the morph shape at the specified index. */
+		SPtr<MorphShape> getShape(UINT32 idx) const { return mShapes[idx]; }
+
+		/** Creates a new set of morph shapes. */
+		static SPtr<MorphShapes> create(const Vector<SPtr<MorphShape>>& shapes);
+
+	private:
+		MorphShapes();
+		MorphShapes(const Vector<SPtr<MorphShape>>& shapes);
+
+		Vector<SPtr<MorphShape>> mShapes;
+
+		/************************************************************************/
+		/* 								SERIALIZATION                      		*/
+		/************************************************************************/
+	public:
+		friend class MorphShapesRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		RTTITypeBase* getRTTI() const override;
+
+		/** 
+		 * Creates MorphShapes with no data. You must populate its data manually.
+		 *
+		 * @note	For serialization use only.
+		 */
+		static SPtr<MorphShapes> createEmpty();
+	};
+
+	/** @} */
+}

+ 79 - 0
Source/BansheeCore/Include/BsMorphShapesRTTI.h

@@ -0,0 +1,79 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsMorphShapes.h"
+
+namespace BansheeEngine
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Core
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT MorphShapeRTTI : public RTTIType <MorphShape, IReflectable, MorphShapeRTTI>
+	{
+	private:
+		BS_BEGIN_RTTI_MEMBERS
+			BS_RTTI_MEMBER_PLAIN(mName, 0)
+			BS_RTTI_MEMBER_PLAIN_ARRAY(mVertices, 1)
+		BS_END_RTTI_MEMBERS
+		
+	public:
+		MorphShapeRTTI()
+			:mInitMembers(this)
+		{ }
+
+		const String& getRTTIName() override
+		{
+			static String name = "MorphShape";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_MorphShape;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return bs_shared_ptr_new<MorphShape>();
+		}
+	};
+
+	class BS_CORE_EXPORT MorphShapesRTTI : public RTTIType <MorphShapes, IReflectable, MorphShapesRTTI>
+	{
+	private:
+		BS_BEGIN_RTTI_MEMBERS
+			BS_RTTI_MEMBER_REFLPTR_ARRAY(mShapes, 0)
+			BS_END_RTTI_MEMBERS
+
+	public:
+		MorphShapesRTTI()
+			:mInitMembers(this)
+		{ }
+
+		const String& getRTTIName() override
+		{
+			static String name = "MorphShapes";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_MorphShapes;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return MorphShapes::createEmpty();
+		}
+	};
+
+	BS_ALLOW_MEMCPY_SERIALIZATION(MorphVertex);
+
+	/** @} */
+	/** @endcond */
+}

+ 59 - 0
Source/BansheeCore/Source/BsMorphShapes.cpp

@@ -0,0 +1,59 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsMorphShapes.h"
+#include "BsMorphShapesRTTI.h"
+
+namespace BansheeEngine
+{
+	MorphShape::MorphShape()
+	{ }
+
+	MorphShape::MorphShape(const String& name, const Vector<MorphVertex>& vertices)
+		:mName(name), mVertices(vertices)
+	{ }
+
+	/** Creates a new morph shape from the provided set of vertices. */
+	SPtr<MorphShape> MorphShape::create(const String& name, const Vector<MorphVertex>& vertices)
+	{
+		return bs_shared_ptr_new<MorphShape>(name, vertices);
+	}
+
+	RTTITypeBase* MorphShape::getRTTIStatic()
+	{
+		return MorphShapeRTTI::instance();
+	}
+
+	RTTITypeBase* MorphShape::getRTTI() const
+	{
+		return getRTTIStatic();
+	}
+
+	MorphShapes::MorphShapes()
+	{ }
+
+	MorphShapes::MorphShapes(const Vector<SPtr<MorphShape>>& shapes)
+		:mShapes(shapes)
+	{ }
+
+	SPtr<MorphShapes> MorphShapes::create(const Vector<SPtr<MorphShape>>& shapes)
+	{
+		MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes(shapes);
+		return bs_shared_ptr(raw);
+	}
+
+	SPtr<MorphShapes> MorphShapes::createEmpty()
+	{
+		MorphShapes* raw = new (bs_alloc<MorphShapes>()) MorphShapes();
+		return bs_shared_ptr(raw);
+	}
+
+	RTTITypeBase* MorphShapes::getRTTIStatic()
+	{
+		return MorphShapesRTTI::instance();
+	}
+
+	RTTITypeBase* MorphShapes::getRTTI() const
+	{
+		return getRTTIStatic();
+	}
+}