Panagiotis Christopoulos Charitos vor 14 Jahren
Ursprung
Commit
c2ae524574
3 geänderte Dateien mit 129 neuen und 74 gelöschten Zeilen
  1. 1 1
      anki/resource/Model.h
  2. 41 0
      anki/scene/SkinNode.cpp
  3. 87 73
      anki/scene/SkinNode.h

+ 1 - 1
anki/resource/Model.h

@@ -12,7 +12,7 @@
 namespace anki {
 
 
-/// XXX
+/// Model patch interface class
 class ModelPatchBase
 {
 public:

+ 41 - 0
anki/scene/SkinNode.cpp

@@ -13,6 +13,23 @@ namespace anki {
 // SkinMesh                                                                    =
 //==============================================================================
 
+//==============================================================================
+const Vbo* SkinMesh::getVbo(VboId id) const
+{
+	switch(id)
+	{
+		case VBO_POSITIONS:
+			return &tfVbos[VBO_TF_POSITIONS];
+		case VBO_NORMALS:
+			return &tfVbos[VBO_TF_NORMALS];
+		case VBO_TANGENTS:
+			return &tfVbos[VBO_TF_TANGENTS];
+		default:
+			return mesh->getVbo(id);
+	}
+}
+
+
 //==============================================================================
 SkinMesh::SkinMesh(const Mesh* mesh_)
 	: mesh(mesh_)
@@ -56,6 +73,30 @@ SkinMesh::SkinMesh(const Mesh* mesh_)
 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
 
 //==============================================================================
+//==============================================================================
+SkinPatchNode::SkinPatchNode(const ModelPatch* modelPatch_,
+	const char* name, Scene* scene,
+	uint movableFlags, Movable* movParent)
+	: SceneNode(name, scene), Movable(movableFlags, movParent, *this),
+	  Spatial(spatialCs)
+{
+	skinModelPatch.reset(new SkinModelPatch(modelPatch_));
+
+	tfVao.create();
+	if(skinModelPatch->getMeshBase().getVbo(MeshBase::VBO_NORMALS))
+	{
+		tfVao.attachArrayBufferVbo(mesh.getVbo(Mesh::VBO_VERT_POSITIONS),
+			POSITION_LOC,
+			3,
+			GL_FLOAT,
+			false,
+			0,
+			NULL);
+	}
+
+	Renderable::init(*this);
+}
+
 SkinPatchNode::SkinPatchNode(const ModelPatch* modelPatch_, SceneNode* parent)
 	: SceneNode(SNT_RENDERABLE_NODE, parent->getScene(),
 		SNF_INHERIT_PARENT_TRANSFORM, parent),

+ 87 - 73
anki/scene/SkinNode.h

@@ -32,22 +32,17 @@ public:
 	/// Create the @a tfVbos with empty data
 	SkinMesh(const Mesh* mesh_);
 
-	/// @name Implementations of MeshBase virtuals
+	/// @name Accessors
 	/// @{
-	const Vbo* getVbo(VboId id) const
+	const Vbo* getTfVbo(TfVboId id) const
 	{
-		switch(id)
-		{
-			case VBO_POSITIONS:
-				return &tfVbos[VBO_TF_POSITIONS];
-			case VBO_NORMALS:
-				return &tfVbos[VBO_TF_NORMALS];
-			case VBO_TANGENTS:
-				return &tfVbos[VBO_TF_TANGENTS];
-			default:
-				return mesh->getVbo(id);
-		}
+		return &tfVbos[id];
 	}
+	/// @}
+
+	/// @name Implementations of MeshBase virtuals
+	/// @{
+	const Vbo* getVbo(VboId id) const;
 
 	uint getTextureChannelsNumber() const
 	{
@@ -81,79 +76,98 @@ private:
 };
 
 
+/// XXX
+class SkinModelPatch: public ModelPatchBase
+{
+public:
+	SkinModelPatch(const ModelPatch* mpatch_)
+		: mpatch(mpatch_)
+	{
+		skinMesh.reset(new SkinMesh(&mpatch->getMeshBase()));
+		create();
+	}
+
+	const MeshBase& getMeshBase() const
+	{
+		return *skinMesh;
+	}
+
+	const Material& getMaterial() const
+	{
+		return mpatch->getMaterial();
+	}
+
+private:
+	boost::scoped_ptr<SkinMesh> skinMesh;
+	const ModelPatch* mpatch;
+};
+
+
 /// A fragment of the SkinNode
 class SkinPatchNode: public SceneNode, public Movable, public Renderable,
 	public Spatial
 {
-	public:
-		/// See TfHwSkinningGeneric.glsl for the locations
-		enum TfShaderProgAttribLoc
-		{
-			POSITION_LOC,
-			NORMAL_LOC,
-			TANGENT_LOC,
-			VERT_WEIGHT_BONES_NUM_LOC,
-			VERT_WEIGHT_BONE_IDS_LOC,
-			VERT_WEIGHT_WEIGHTS_LOC
-		};
-
-		SkinPatchNode(const ModelPatch* modelPatch_, SceneNode* parent);
-
-		/// @name Accessors
-		/// @{
-		const Vao& getTfVao() const
-		{
-			return tfVao;
-		}
+public:
+	/// See TfHwSkinningGeneric.glsl for the locations
+	enum TfShaderProgAttribLoc
+	{
+		POSITION_LOC,
+		NORMAL_LOC,
+		TANGENT_LOC,
+		VERT_WEIGHT_BONES_NUM_LOC,
+		VERT_WEIGHT_BONE_IDS_LOC,
+		VERT_WEIGHT_WEIGHTS_LOC
+	};
 
-		const Vbo& getTfVbo(uint i) const
-		{
-			return tfVbos[i];
-		}
-		/// @}
+	/// @name Constructors/Destructor
+	/// @{
+	SkinPatchNode(const ModelPatch* modelPatch_,
+		const char* name, Scene* scene, // Scene
+		uint movableFlags, Movable* movParent, // Movable
+		CollisionShape* spatialCs); // Spatial
+	/// @}
 
-		void init(const char*)
-		{}
+	/// @name SceneNode virtuals
+	/// @{
 
-		/// Implements Renderable::getVao
-		const Vao& getVao(const PassLevelKey& k)
-		{
-			return *vaosHashMap.at(k);
-		}
+	/// Override SceneNode::getMovable()
+	Movable* getMovable()
+	{
+		return this;
+	}
 
-		/// Implements Renderable::getVertexIdsNum
-		uint getVertexIdsNum(const PassLevelKey& k)
-		{
-			return modelPatch->getMesh().getVertsNum();
-		}
+	/// Override SceneNode::getSpatial()
+	Spatial* getSpatial()
+	{
+		return this;
+	}
 
-		/// Implements Renderable::getMaterialRuntime
-		MaterialRuntime& getMaterialRuntime()
-		{
-			return *mtlr;
-		}
+	/// Override SceneNode::getRenderable
+	Renderable* getRenderable()
+	{
+		return this;
+	}
+	/// @}
 
-		/// Implements Renderable::getWorldTransform
-		const Transform& getWorldTransform(const PassLevelKey&)
-		{
-			return SceneNode::getWorldTransform();
-		}
+	/// @name Renderable virtuals
+	/// @{
 
-		/// Implements Renderable::getPreviousWorldTransform
-		const Transform& getPreviousWorldTransform(
-			const PassLevelKey& k)
-		{
-			return SceneNode::getPrevWorldTransform();
-		}
+	/// Implements Renderable::getModelPatchBase
+	const ModelPatchBase& getModelPatchBase() const
+	{
+		return *skinModelPatch;
+	}
 
-	private:
-		ModelPatch::VaosContainer vaos;
-		ModelPatch::PassLevelToVaoHashMap vaosHashMap;
-		const ModelPatch* modelPatch;
-		boost::scoped_ptr<MaterialRuntime> mtlr; ///< Material runtime
+	/// Implements Renderable::getMaterial
+	const Material& getMaterial() const
+	{
+		return skinModelPatch->getMaterial();
+	}
+	/// @}
 
-		boost::array<Vbo, TFV_NUM> tfVbos;
-		Vao tfVao; ///< For TF passes
+private:
+	boost::scoped_ptr<SkinModelPatch> skinModelPatch;
+	Vao tfVao;
 };