Index: trunk/src/formats/md5_loader.cc
===================================================================
--- trunk/src/formats/md5_loader.cc	(revision 200)
+++ trunk/src/formats/md5_loader.cc	(revision 224)
@@ -90,5 +90,5 @@
 		{
 			// TODO : efficiency dammit
-			md5_mesh mesh;
+			md5_mesh* mesh = new md5_mesh;
 			int num_verts, num_tris, num_weights;
 
@@ -99,6 +99,6 @@
 				if ( command == "shader" )
 				{
-					sstream >> mesh.shader;
-					remove_quotes( mesh.shader );
+					sstream >> mesh->shader;
+					remove_quotes( mesh->shader );
 					// texturePath.replace_extension( ".tga" );
 					next_line( sstream );
@@ -120,6 +120,6 @@
 						next_line( sstream );
 
-						mesh.verts.push_back(vert);
-						mesh.texcoord_buffer.push_back( vert.texcoord );
+						mesh->verts.push_back(vert);
+						mesh->texcoord_buffer.push_back( vert.texcoord );
 					}  
 				}
@@ -136,8 +136,8 @@
 						next_line( sstream );
 
-						mesh.tris.push_back( tri );
-						mesh.index_buffer.push_back( (uint32)tri.indices[0] );
-						mesh.index_buffer.push_back( (uint32)tri.indices[1] );
-						mesh.index_buffer.push_back( (uint32)tri.indices[2] );
+						mesh->tris.push_back( tri );
+						mesh->index_buffer.push_back( (uint32)tri.indices[0] );
+						mesh->index_buffer.push_back( (uint32)tri.indices[1] );
+						mesh->index_buffer.push_back( (uint32)tri.indices[2] );
 					}              
 				}
@@ -156,5 +156,5 @@
 						discard( sstream, ")" );
 						next_line( sstream );
-						mesh.weights.push_back(weight);
+						mesh->weights.push_back(weight);
 					}
 				}
@@ -180,12 +180,12 @@
 }
 
-bool md5_loader::prepare_mesh( md5_mesh& mesh )
-{
-	mesh.position_buffer.clear();
-	mesh.texcoord_buffer.clear();
-
-	for ( uint32 i = 0; i < mesh.verts.size(); ++i )
-	{
-		md5_vertex& vert = mesh.verts[i];
+bool md5_loader::prepare_mesh( md5_mesh* mesh )
+{
+	mesh->position_buffer.clear();
+	mesh->texcoord_buffer.clear();
+
+	for ( uint32 i = 0; i < mesh->verts.size(); ++i )
+	{
+		md5_vertex& vert = mesh->verts[i];
 
 		vert.position = glm::vec3(0);
@@ -195,5 +195,5 @@
 		for ( size_t j = 0; j < vert.weight_count; ++j )
 		{
-			md5_weight& weight = mesh.weights[vert.start_weight + j];
+			md5_weight& weight = mesh->weights[vert.start_weight + j];
 			md5_joint&  joint  = m_joints[weight.joint_id];
 
@@ -203,6 +203,6 @@
 		}
 
-		mesh.position_buffer.push_back(vert.position);
-		mesh.texcoord_buffer.push_back(vert.texcoord);
+		mesh->position_buffer.push_back(vert.position);
+		mesh->texcoord_buffer.push_back(vert.texcoord);
 	}
 
@@ -210,14 +210,14 @@
 }
 
-bool md5_loader::prepare_normals( md5_mesh& mesh )
-{
-	mesh.normal_buffer.clear();
-
-	for ( unsigned int i = 0; i < mesh.tris.size(); ++i )
-	{
-		const md5_triangle& tri = mesh.tris[i];
-		glm::vec3 v1 = mesh.verts[ tri.indices[0] ].position;
-		glm::vec3 v2 = mesh.verts[ tri.indices[1] ].position;
-		glm::vec3 v3 = mesh.verts[ tri.indices[2] ].position;
+bool md5_loader::prepare_normals( md5_mesh* mesh )
+{
+	mesh->normal_buffer.clear();
+
+	for ( unsigned int i = 0; i < mesh->tris.size(); ++i )
+	{
+		const md5_triangle& tri = mesh->tris[i];
+		glm::vec3 v1 = mesh->verts[ tri.indices[0] ].position;
+		glm::vec3 v2 = mesh->verts[ tri.indices[1] ].position;
+		glm::vec3 v3 = mesh->verts[ tri.indices[2] ].position;
 		glm::vec3 xyz1 = v3 - v1;
 		glm::vec3 xyz2 = v2 - v1;
@@ -225,11 +225,11 @@
 		glm::vec3 normal = glm::cross( xyz1, xyz2 );
 
-		mesh.verts[ tri.indices[0] ].normal += normal;
-		mesh.verts[ tri.indices[1] ].normal += normal;
-		mesh.verts[ tri.indices[2] ].normal += normal;
-
-		const vec2& w1 = mesh.verts[ tri.indices[0] ].texcoord;
-		const vec2& w2 = mesh.verts[ tri.indices[1] ].texcoord;
-		const vec2& w3 = mesh.verts[ tri.indices[2] ].texcoord;
+		mesh->verts[ tri.indices[0] ].normal += normal;
+		mesh->verts[ tri.indices[1] ].normal += normal;
+		mesh->verts[ tri.indices[2] ].normal += normal;
+
+		const vec2& w1 = mesh->verts[ tri.indices[0] ].texcoord;
+		const vec2& w2 = mesh->verts[ tri.indices[1] ].texcoord;
+		const vec2& w3 = mesh->verts[ tri.indices[2] ].texcoord;
 
 		vec2 st1 = w3 - w1;
@@ -240,17 +240,17 @@
 		vec3 tangent = (( xyz1 * st2.y ) - ( xyz2 * st1.y )) * coef;
 
-		mesh.verts[ tri.indices[0] ].tangent += tangent;
-		mesh.verts[ tri.indices[1] ].tangent += tangent;
-		mesh.verts[ tri.indices[2] ].tangent += tangent;
-	}
-
-	for ( size_t i = 0; i < mesh.verts.size(); ++i )
-	{
-		md5_vertex& vert = mesh.verts[i];
+		mesh->verts[ tri.indices[0] ].tangent += tangent;
+		mesh->verts[ tri.indices[1] ].tangent += tangent;
+		mesh->verts[ tri.indices[2] ].tangent += tangent;
+	}
+
+	for ( size_t i = 0; i < mesh->verts.size(); ++i )
+	{
+		md5_vertex& vert = mesh->verts[i];
 
 		glm::vec3 normal  = glm::normalize( vert.normal );
 		glm::vec3 tangent = glm::normalize( vert.tangent );
-		mesh.normal_buffer.push_back( normal );
-		mesh.tangent_buffer.push_back( tangent );
+		mesh->normal_buffer.push_back( normal );
+		mesh->tangent_buffer.push_back( tangent );
 
 		vert.normal  = glm::vec3(0);
@@ -259,5 +259,5 @@
 		for ( size_t j = 0; j < vert.weight_count; ++j )
 		{
-			const md5_weight& weight = mesh.weights[vert.start_weight + j];
+			const md5_weight& weight = mesh->weights[vert.start_weight + j];
 			const md5_joint&  joint  = m_joints[weight.joint_id];
 			vert.normal  += ( normal  * joint.orient ) * weight.bias;
@@ -269,4 +269,17 @@
 }
 
+mesh_data* nv::md5_loader::release_submesh_data( uint32 mesh_id )
+{
+	mesh_data_creator m;
+	m.get_positions().assign( m_meshes[mesh_id]->position_buffer.begin(), m_meshes[mesh_id]->position_buffer.begin() );
+	m.get_normals()  .assign( m_meshes[mesh_id]->normal_buffer.begin(),   m_meshes[mesh_id]->normal_buffer.begin() );
+	m.get_tangents() .assign( m_meshes[mesh_id]->tangent_buffer.begin(),  m_meshes[mesh_id]->tangent_buffer.begin() );
+	m.get_texcoords().assign( m_meshes[mesh_id]->texcoord_buffer.begin(), m_meshes[mesh_id]->texcoord_buffer.begin() );
+	m.get_indices()  .assign( m_meshes[mesh_id]->index_buffer.begin(),    m_meshes[mesh_id]->index_buffer.begin() );
+
+	return m.release();
+}
+
+/*
 mesh* md5_loader::release_mesh()
 {
@@ -287,4 +300,5 @@
 	return m;
 }
+*/
 
 md5_animation::md5_animation()
@@ -539,12 +553,12 @@
 }
 
-bool md5_loader::prepare_animated_mesh( md5_mesh& mesh, const md5_animation::md5_frame_skeleton& skel )
-{
-	for ( unsigned int i = 0; i < mesh.verts.size(); ++i )
-	{
-		const md5_vertex& vert = mesh.verts[i];
-		glm::vec3& pos     = mesh.position_buffer[i];
-		glm::vec3& normal  = mesh.normal_buffer[i];
-		glm::vec3& tangent = mesh.tangent_buffer[i];
+bool md5_loader::prepare_animated_mesh( md5_mesh* mesh, const md5_animation::md5_frame_skeleton& skel )
+{
+	for ( unsigned int i = 0; i < mesh->verts.size(); ++i )
+	{
+		const md5_vertex& vert = mesh->verts[i];
+		glm::vec3& pos     = mesh->position_buffer[i];
+		glm::vec3& normal  = mesh->normal_buffer[i];
+		glm::vec3& tangent = mesh->tangent_buffer[i];
 
 		pos     = glm::vec3(0);
@@ -554,5 +568,5 @@
 		for ( size_t j = 0; j < vert.weight_count; ++j )
 		{
-			const md5_weight& weight = mesh.weights[vert.start_weight + j];
+			const md5_weight& weight = mesh->weights[vert.start_weight + j];
 			const md5_animation::md5_skeleton_joint& joint = skel.joints[weight.joint_id];
 
