Browse Source

Model and ModelNode

Panagiotis Christopoulos Charitos 15 years ago
parent
commit
7e76dc6efd
4 changed files with 83 additions and 38 deletions
  1. 18 2
      src/Resources/Model.cpp
  2. 12 7
      src/Resources/Model.h
  3. 20 24
      src/Resources/SkelAnim.h
  4. 33 5
      src/Scene/ModelNode.h

+ 18 - 2
src/Resources/Model.cpp

@@ -4,11 +4,16 @@
 #include "Mesh.h"
 #include "Mesh.h"
 #include "SkelAnim.h"
 #include "SkelAnim.h"
 #include "MeshData.h"
 #include "MeshData.h"
+#include "Vao.h"
+#include "Skeleton.h"
 
 
 
 
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
 
 
 
 
+#define MDL_EXCEPTION(x) EXCEPTION("Model \"" + filename + "\": " + x)
+
+
 //======================================================================================================================
 //======================================================================================================================
 // load                                                                                                                =
 // load                                                                                                                =
 //======================================================================================================================
 //======================================================================================================================
@@ -113,9 +118,18 @@ void Model::load(const char* filename)
 	//
 	//
 	// Sanity checks
 	// Sanity checks
 	//
 	//
-	if(skelAnims.size() > 0 && skeleton.get() == NULL)
+	if(skelAnims.size() > 0 && !hasSkeleton())
+	{
+		throw MDL_EXCEPTION("You have skeleton animations but no skeleton");
+	}
+
+	for(uint i = 0; i < skelAnims.size(); i++)
 	{
 	{
-		throw EXCEPTION("Model \"" + filename + "\": You have skeleton animations but no skeleton");
+		if(skelAnims[i]->bones.size() != skeleton->bones.size())
+		{
+			throw MDL_EXCEPTION("SkelAnim \"" + skelAnims[i]->getRsrcName() + "\" and Skeleton \"" +
+			                    skeleton->getRsrcName() + "\" dont have equal bone count");
+		}
 	}
 	}
 
 
 	//
 	//
@@ -159,6 +173,8 @@ void Model::parseSubModel(Scanner& scanner)
 	subModel.mesh.loadRsrc(mesh.c_str());
 	subModel.mesh.loadRsrc(mesh.c_str());
 	subModel.material.loadRsrc(material.c_str());
 	subModel.material.loadRsrc(material.c_str());
 	subModel.dpMaterial.loadRsrc(dpMaterial.c_str());
 	subModel.dpMaterial.loadRsrc(dpMaterial.c_str());
+
+	/// @todo Sanity checks. See MeshNode.cpp
 }
 }
 
 
 
 

+ 12 - 7
src/Resources/Model.h

@@ -16,7 +16,7 @@ class Scanner;
 
 
 /// Model is an entity that acts as a container for other resources. Models are all the non static objects in a map.
 /// Model is an entity that acts as a container for other resources. Models are all the non static objects in a map.
 ///
 ///
-/// File format:
+/// Text file format:
 /// @code
 /// @code
 /// subModels {
 /// subModels {
 /// 	subModel {
 /// 	subModel {
@@ -41,7 +41,7 @@ class Scanner;
 class Model: public Resource
 class Model: public Resource
 {
 {
 	public:
 	public:
-		/// This is basicaly a container around mesh and materials. It also has the VAOs.
+		/// This is basically a container around mesh and materials. It also has the VAOs.
 		class SubModel: public Object
 		class SubModel: public Object
 		{
 		{
 			friend class Model;
 			friend class Model;
@@ -60,9 +60,9 @@ class Model: public Resource
 
 
 			private:
 			private:
 				RsrcPtr<Mesh> mesh; ///< The geometry
 				RsrcPtr<Mesh> mesh; ///< The geometry
-				RsrcPtr<Material> material; ///< Material for MS ans BS
+				RsrcPtr<Material> material; ///< Material for MS and BS
 				RsrcPtr<Material> dpMaterial; ///< Material for depth passes
 				RsrcPtr<Material> dpMaterial; ///< Material for depth passes
-				Vao* vao; ///< Normal VAO for MS ans BS
+				Vao* vao; ///< Normal VAO for MS and BS
 				Vao* dpVao; ///< Depth pass VAO for SM and EarlyZ
 				Vao* dpVao; ///< Depth pass VAO for SM and EarlyZ
 		};
 		};
 
 
@@ -74,20 +74,25 @@ class Model: public Resource
 		/// @{
 		/// @{
 		const Vec<SubModel>& getSubModels() const {return subModels;}
 		const Vec<SubModel>& getSubModels() const {return subModels;}
 		const Skeleton& getSkeleton() const;
 		const Skeleton& getSkeleton() const;
+		const Vec<RsrcPtr<SkelAnim> >& getSkelAnims() const {return skelAnims;}
 		/// @}
 		/// @}
 
 
 		bool hasSkeleton() const {return skeleton.get() != NULL;}
 		bool hasSkeleton() const {return skeleton.get() != NULL;}
 
 
 	private:
 	private:
-		Vec<SubModel> subModels; ///< The vector of submodels
+		Vec<SubModel> subModels; ///< The vector of SubModel
 		RsrcPtr<Skeleton> skeleton; ///< The skeleton. It can be empty
 		RsrcPtr<Skeleton> skeleton; ///< The skeleton. It can be empty
 		Vec<RsrcPtr<SkelAnim> > skelAnims; ///< The standard skeleton animations
 		Vec<RsrcPtr<SkelAnim> > skelAnims; ///< The standard skeleton animations
 
 
 		/// Parses a submodel from after the "subModel" until the closing bracket
 		/// Parses a submodel from after the "subModel" until the closing bracket
 		void parseSubModel(Scanner& scanner);
 		void parseSubModel(Scanner& scanner);
 
 
-		/// Creates VAOs for an individual submodel
-		void createVao(const Material& mtl, const Mesh& mesh, SubModel& subModel, Vao*& vao);
+		/// Creates a VAO for an individual SubModel
+		/// @param[in] material Needed for the shader program uniform variables
+		/// @param[in] mesh For providing the VBOs
+		/// @param[in,out] subModel For setting a parent to the vao
+		/// @param[out] vao The output
+		static void createVao(const Material& material, const Mesh& mesh, SubModel& subModel, Vao*& vao);
 };
 };
 
 
 
 

+ 20 - 24
src/Resources/SkelAnim.h

@@ -10,37 +10,33 @@
 /// The format will be changed to:
 /// The format will be changed to:
 ///
 ///
 /// @code
 /// @code
-/// skeletonAnimation
+/// keyframes {<integer> <integer> ... <integer>}
+/// bones
 /// {
 /// {
-/// 	name same-as-file
-/// 	keyframes {<integer> <integer> ... <integer>}
-/// 	bones
+/// 	num <integer>
+/// 	boneAnims
 /// 	{
 /// 	{
-/// 		num <integer>
-/// 		boneAnims
+/// 		boneAnim
 /// 		{
 /// 		{
-/// 			boneAnim
+/// 			hasAnim <true | false>
+/// 			[bonePoses
 /// 			{
 /// 			{
-/// 				hasAnim <true | false>
-/// 				[bonePoses
+/// 				bonePose
+/// 				{
+/// 					quat {<float> <float> <float> <float>}
+/// 					trf {<float> <float> <float>}
+/// 				}
+/// 				...
+/// 				bonePose
 /// 				{
 /// 				{
-/// 					bonePose
-/// 					{
-/// 						quat {<float> <float> <float> <float>}
-/// 						trf {<float> <float> <float>}
-/// 					}
 /// 					...
 /// 					...
-/// 					bonePose
-/// 					{
-/// 						...
-/// 					}
-/// 				}]
-/// 			}
+/// 				}
+/// 			}]
+/// 		}
+/// 		...
+/// 		boneAnim
+/// 		{
 /// 			...
 /// 			...
-/// 			boneAnim
-/// 			{
-/// 				...
-/// 			}
 /// 		}
 /// 		}
 /// 	}
 /// 	}
 /// }
 /// }

+ 33 - 5
src/Scene/ModelNode.h

@@ -14,17 +14,17 @@ class SkelAnimModelNodeCtrl;
 class ModelNode: public SceneNode
 class ModelNode: public SceneNode
 {
 {
 	public:
 	public:
-		SkelAnimModelNodeCtrl* skelAnimModelNodeCtrl;
+		SkelAnimModelNodeCtrl* skelAnimModelNodeCtrl; ///< @todo Clean this
 
 
 		ModelNode(): SceneNode(SNT_MODEL) {}
 		ModelNode(): SceneNode(SNT_MODEL) {}
 
 
 		/// @name Accessors
 		/// @name Accessors
 		/// @{
 		/// @{
 		const Model& getModel() const {return *model;}
 		const Model& getModel() const {return *model;}
-		Vec<Vec3>& getHeads() {return heads;}
-		Vec<Vec3>& getTails() {return tails;}
-		Vec<Mat3>& getBoneRotations() {return boneRotations;}
-		Vec<Vec3>& getBoneTranslations() {return boneTranslations;}
+		Vec<Vec3>& getHeads();
+		Vec<Vec3>& getTails();
+		Vec<Mat3>& getBoneRotations();
+		Vec<Vec3>& getBoneTranslations();
 		/// @}
 		/// @}
 
 
 		/// @return True if the model support skeleton animation
 		/// @return True if the model support skeleton animation
@@ -42,4 +42,32 @@ class ModelNode: public SceneNode
 };
 };
 
 
 
 
+inline Vec<Vec3>& ModelNode::getHeads()
+{
+	RASSERT_THROW_EXCEPTION(!hasSkeleton());
+	return heads;
+}
+
+
+inline Vec<Vec3>& ModelNode::getTails()
+{
+	RASSERT_THROW_EXCEPTION(!hasSkeleton());
+	return tails;
+}
+
+
+inline Vec<Mat3>& ModelNode::getBoneRotations()
+{
+	RASSERT_THROW_EXCEPTION(!hasSkeleton());
+	return boneRotations;
+}
+
+
+inline Vec<Vec3>& ModelNode::getBoneTranslations()
+{
+	RASSERT_THROW_EXCEPTION(!hasSkeleton());
+	return boneTranslations;
+}
+
+
 #endif
 #endif