Panagiotis Christopoulos Charitos 15 yıl önce
ebeveyn
işleme
4a20a26393

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 1
build/debug/Makefile


+ 53 - 33
src/Resources/Skeleton.h

@@ -6,6 +6,52 @@
 #include "Vec.h"
 
 
+/// Skeleton bone
+///
+/// @note The rotation and translation that transform the bone from bone space to armature space. Meaning that if
+/// MA = TRS(rotSkelSpace, tslSkelSpace) then head = MA * Vec3(0.0, length, 0.0) and tail = MA * Vec3(0.0, 0.0, 0.0).
+/// We need the MA because the animation rotations and translations are in bone space. We also keep the inverted
+/// ones for fast calculations. rotSkelSpaceInv = MA.Inverted().getRotationPart() and NOT
+/// rotSkelSpaceInv = rotSkelSpace.getInverted()
+struct Bone
+{
+	friend class Skeleton; /// For loading
+
+	public:
+		/// @name Accessors
+		/// @{
+		GETTER_R(std::string, name, getName)
+		GETTER_R(Vec3, head, getHead)
+		GETTER_R(Vec3, tail, getTail)
+		GETTER_R(uint, id, getPos)
+		GETTER_R_BY_VAL(Bone*, parent, getParent)
+		const Bone& getChild(uint i) const {return *childs[i];}
+		GETTER_R_BY_VAL(ushort, childsNum, getChildsNum)
+
+		GETTER_R(Mat3, rotSkelSpace, getRotSkelSpace)
+		GETTER_R(Vec3, tslSkelSpace, getTslSkelSpace)
+		GETTER_R(Mat3, rotSkelSpaceInv, getRotSkelSpaceInv)
+		GETTER_R(Vec3, tslSkelSpaceInv, getTslSkelSpaceInv)
+		/// @}
+
+	private:
+		std::string name; ///< The name of the bone
+		Vec3 head; ///< Starting point of the bone
+		Vec3 tail; ///< End point of the bone
+		uint id; ///< Pos inside the @ref Skeleton::bones vector
+		static const uint MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
+		Bone* parent;
+		boost::array<Bone*, MAX_CHILDS_PER_BONE> childs;
+		ushort childsNum;
+
+		// see the class notes
+		Mat3 rotSkelSpace;
+		Vec3 tslSkelSpace;
+		Mat3 rotSkelSpaceInv;
+		Vec3 tslSkelSpaceInv;
+};
+
+
 /// It contains the bones with their position and hierarchy
 ///
 /// Binary file format:
@@ -30,42 +76,16 @@
 class Skeleton
 {
 	public:
-		/// Skeleton bone
-		///
-		/// @note The rotation and translation that transform the bone from bone space to armature space. Meaning that if
-		/// MA = TRS(rotSkelSpace, tslSkelSpace) then head = MA * Vec3(0.0, length, 0.0) and tail = MA * Vec3(0.0, 0.0, 0.0).
-		/// We need the MA because the animation rotations and translations are in bone space. We also keep the inverted
-		/// ones for fast calculations. rotSkelSpaceInv = MA.Inverted().getRotationPart() and NOT
-		/// rotSkelSpaceInv = rotSkelSpace.getInverted()
-		class Bone
-		{
-			friend class Skeleton; /// For loading
-
-			PROPERTY_R(std::string, name, getName) ///< The name of the bone
-			PROPERTY_R(Vec3, head, getHead) ///< Starting point of the bone
-			PROPERTY_R(Vec3, tail, getTail) ///< End point of the bone
-			PROPERTY_R(uint, id, getPos) ///< Pos inside the @ref Skeleton::bones vector
-
-			public:
-				static const uint MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
-				Bone*  parent;
-				Bone*  childs[MAX_CHILDS_PER_BONE];
-				ushort childsNum;
+		/// Implements Resource::load
+		void load(const char* filename);
 
-				// see the class notes
-				Mat3 rotSkelSpace;
-				Vec3 tslSkelSpace;
-				Mat3 rotSkelSpaceInv;
-				Vec3 tslSkelSpaceInv;
+		/// @name Accessors
+		/// @{
+		GETTER_R(Vec<Bone>, bones, getBones)
+		/// @}
 
-				 Bone() {}
-				~Bone() {}
-		};	
-	
+	private:
 		Vec<Bone> bones;
-
-		/// Implements Resource::load
-		void load(const char* filename);
 };
 
 

+ 1 - 1
src/Resources/Skin.cpp

@@ -56,7 +56,7 @@ void Skin::load(const char* filename)
 		BOOST_FOREACH(const RsrcPtr<SkelAnim>& skelAnim, skelAnims)
 		{
 			// Bone number problem
-			if(skelAnim->bones.size() != skeleton->bones.size())
+			if(skelAnim->bones.size() != skeleton->getBones().size())
 			{
 				throw EXCEPTION("Skeleton animation \"" + skelAnim.getRsrcName() + "\" and skeleton \"" +
 								skeleton.getRsrcName() + "\" dont have equal bone count");

+ 18 - 15
src/Scene/Controllers/SkelAnimModelNodeCtrl.cpp

@@ -1,3 +1,4 @@
+#include <boost/foreach.hpp>
 #include "SkelAnimModelNodeCtrl.h"
 #include "SkelAnim.h"
 #include "Skeleton.h"
@@ -92,11 +93,11 @@ void SkelAnimModelNodeCtrl::updateBoneTransforms(const Skeleton& skeleton,
 	uint head = 0, tail = 0;
 
 	// put the roots
-	for(uint i=0; i<skeleton.bones.size(); i++)
+	BOOST_FOREACH(const Bone& bone, skeleton.getBones())
 	{
-		if(skeleton.bones[i].parent == NULL)
+		if(bone.getParent() == NULL)
 		{
-			queue[tail++] = i; // queue push
+			queue[tail++] = bone.getPos(); // queue push
 		}
 	}
 
@@ -104,31 +105,32 @@ void SkelAnimModelNodeCtrl::updateBoneTransforms(const Skeleton& skeleton,
 	while(head != tail) // while queue not empty
 	{
 		uint boneId = queue[head++]; // queue pop
-		const Skeleton::Bone& boned = skeleton.bones[boneId];
+		const Bone& boned = skeleton.getBones()[boneId];
 
 		// bone.final_transform = MA * ANIM * MAi
 		// where MA is bone matrix at armature space and ANIM the interpolated transformation.
 		combineTransformations(boneTranslations[boneId], boneRotations[boneId],
-		                       boned.tslSkelSpaceInv, boned.rotSkelSpaceInv,
+		                       boned.getTslSkelSpaceInv(), boned.getRotSkelSpaceInv(),
 		                       boneTranslations[boneId], boneRotations[boneId]);
 
-		combineTransformations(boned.tslSkelSpace, boned.rotSkelSpace,
+		combineTransformations(boned.getTslSkelSpace(), boned.getRotSkelSpace(),
 		                       boneTranslations[boneId], boneRotations[boneId],
 		                       boneTranslations[boneId], boneRotations[boneId]);
 
 		// and finaly add the parent's transform
-		if(boned.parent)
+		if(boned.getParent())
 		{
 			// bone.final_final_transform = parent.transf * bone.final_transform
-			combineTransformations(boneTranslations[boned.parent->getPos()], boneRotations[boned.parent->getPos()],
-		                         boneTranslations[boneId], boneRotations[boneId],
-		                         boneTranslations[boneId], boneRotations[boneId]);
+			combineTransformations(boneTranslations[boned.getParent()->getPos()],
+			                       boneRotations[boned.getParent()->getPos()],
+			                       boneTranslations[boneId], boneRotations[boneId],
+			                       boneTranslations[boneId], boneRotations[boneId]);
 		}
 
 		// now add the bone's childes
-		for(uint i=0; i<boned.childsNum; i++)
+		for(uint i = 0; i < boned.getChildsNum(); i++)
 		{
-			queue[tail++] = boned.childs[i]->getPos();
+			queue[tail++] = boned.getChild(i).getPos();
 		}
 	}
 }
@@ -140,13 +142,13 @@ void SkelAnimModelNodeCtrl::updateBoneTransforms(const Skeleton& skeleton,
 void SkelAnimModelNodeCtrl::deform(const Skeleton& skeleton, const Vec<Vec3>& boneTranslations,
                                    const Vec<Mat3>& boneRotations, Vec<Vec3>& heads, Vec<Vec3>& tails)
 {
-	for(uint i=0; i<skeleton.bones.size(); i++)
+	for(uint i = 0; i < skeleton.getBones().size(); i++)
 	{
 		const Mat3& rot = boneRotations[i];
 		const Vec3& transl = boneTranslations[i];
 
-		heads[i] = skeleton.bones[i].getHead().getTransformed(transl, rot);
-		tails[i] = skeleton.bones[i].getTail().getTransformed(transl, rot);
+		heads[i] = skeleton.getBones()[i].getHead().getTransformed(transl, rot);
+		tails[i] = skeleton.getBones()[i].getTail().getTransformed(transl, rot);
 	}
 }
 
@@ -169,6 +171,7 @@ void SkelAnimModelNodeCtrl::update(float)
 
 	interpolate(*skelAnim, frame, skinNode.getBoneTranslations(), skinNode.getBoneRotations());
 	updateBoneTransforms(skinNode.getSkin().getSkeleton(), skinNode.getBoneTranslations(), skinNode.getBoneRotations());
+
 	if(MainRendererSingleton::getInstance().getDbg().isEnabled() &&
 	   MainRendererSingleton::getInstance().getDbg().isShowSkeletonsEnabled())
 	{

+ 1 - 1
src/Scene/SkinNode.cpp

@@ -17,7 +17,7 @@ void SkinNode::init(const char* filename)
 		patches.push_back(new SkinPatchNode(patch, this));
 	}
 
-	uint bonesNum = skin->getSkeleton().bones.size();
+	uint bonesNum = skin->getSkeleton().getBones().size();
 	tails.resize(bonesNum);
 	heads.resize(bonesNum);
 	boneRotations.resize(bonesNum);

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor