Index: trunk/src/formats/md2_loader.cc
===================================================================
--- trunk/src/formats/md2_loader.cc	(revision 236)
+++ trunk/src/formats/md2_loader.cc	(revision 239)
@@ -203,5 +203,5 @@
 static bool s_md2_normal_ready = false;
 
-md2_loader::md2_loader() : m_md2( nullptr ), m_size( 0 )
+md2_loader::md2_loader() : m_md2( nullptr )
 {
 	if ( !s_md2_normal_ready )
@@ -230,5 +230,4 @@
 bool md2_loader::load( stream& source )
 {
-	m_size = 0;
 	m_md2 = (void*)(new md2_t);
 	if ( !read_md2( (md2_t*)m_md2, source ) )
@@ -237,143 +236,10 @@
 	}
 	reindex();
-	m_size = m_new_indexes.size();
 	return true;
 }
 
-mesh_data_old* nv::md2_loader::release_mesh_data()
-{
-	mesh_data_creator m;
-
-	load_positions( m.get_positions() );
-	load_normals( m.get_normals() );
-	load_texcoords( m.get_texcoords() );
-	load_indicies( m.get_indices() );
-
-	m_size = m.get_indices().size();
-	return m.release();
-}
-
-mesh_data_old* nv::md2_loader::get_frame( sint32 frame )
-{
-	mesh_data_creator m;
-
-	load_positions( m.get_positions(), frame );
-	load_normals( m.get_normals(), frame );
-	load_texcoords( m.get_texcoords() );
-	load_indicies( m.get_indices() );
-
-	m_size = m.get_indices().size();
-	return m.release();
-}
-
-
-/*
-mesh* nv::md2_loader::release_mesh()
-{
-	return get_frame( 0 );
-}
-
-mesh* nv::md2_loader::get_frame( sint32 frame )
-{
-	md2_t* md2 = (md2_t*)m_md2;
-	if ( md2 == nullptr || frame >= md2->header.num_frames ) return nullptr;
-	mesh* m = new mesh();
-
-	vertex_attribute< vec3 >*   position = m->add_attribute<vec3>("nv_position");
-	vertex_attribute< vec3 >*   normal   = m->add_attribute<vec3>("nv_normal");
-	vertex_attribute< vec2 >*   texcoord = m->add_attribute<vec2>("nv_texcoord");
-	vertex_attribute< uint32 >* indices  = m->add_indices<uint32>();
-
-	load_positions( position->get(), frame );
-	load_normals( normal->get(), frame );
-
-	load_texcoords( texcoord->get() );
-	load_indicies( indices->get() );
-
-	m_size = indices->get().size();
-	return m;
-}
-*/
-
 size_t md2_loader::get_max_frames() const
 {
 	return static_cast< size_t >( ((md2_t*)m_md2)->header.num_frames );
-}
-
-void md2_loader::load_positions( std::vector<vec3>& p, sint32 frame /*=-1*/ )
-{
-	md2_t* md2 = (md2_t*)m_md2;
-	size_t num_frames = static_cast< size_t >( md2->header.num_frames );
-	size_t num_verts  =	m_new_vindexes.size();
-	p.clear();
-	size_t current_frame = ( frame == -1 ? 0 : static_cast< size_t >( frame ) );
-	size_t frame_count   = ( frame == -1 ? num_frames : 1 );
-
-	p.reserve( num_verts * frame_count );
-
-	while ( frame_count > 0 )
-	{
-		const md2_frame_t& cframe = md2->frames[current_frame];
-		NV_LOG( LOG_INFO, "FrameID = " << cframe.name );
-
-		vec3 scale     = md2_vec3( cframe.scale );
-		vec3 translate = md2_vec3( cframe.translate );
-
-		for (size_t i = 0; i < num_verts; ++i )
-		{
-			const md2_vertex_t& v = cframe.vertices[ m_new_vindexes[ i ] ];
-			p.push_back( vec3( v.v[0], v.v[2], v.v[1] ) * scale + translate );
-		}
-		++current_frame;
-		--frame_count;
-	}
-}
-
-void md2_loader::load_normals( std::vector<vec3>& n, sint32 frame /*=-1*/ )
-{
-	md2_t* md2 = (md2_t*)m_md2;
-	size_t num_frames = static_cast< size_t >( md2->header.num_frames );
-	size_t num_verts  =	m_new_vindexes.size();
-	n.clear();
-	size_t current_frame = ( frame == -1 ? 0 : static_cast< size_t>( frame ) );
-	size_t frame_count   = ( frame == -1 ? num_frames : 1 );
-
-	n.reserve( num_verts * frame_count );
-
-	while ( frame_count > 0 )
-	{
-		const md2_frame_t& cframe = md2->frames[current_frame];
-
-		for (size_t i = 0; i < num_verts; ++i )
-		{
-			const md2_vertex_t& v = cframe.vertices[ m_new_vindexes[ i ] ];
-			n.push_back( s_md2_normal_cache[ v.n ] );
-		}
-		++current_frame;
-		--frame_count;
-	}
-}
-
-void md2_loader::load_texcoords( std::vector<vec2>& t )
-{
-	md2_t* md2 = (md2_t*)m_md2;
-	size_t num_verts  = m_new_vindexes.size();
-
-	t.clear();
-	t.reserve( num_verts );
-
-	vec2 scale( 1.0f / (float) md2->header.skinwidth, 1.0f / (float) md2->header.skinheight );
-
-	for (size_t i = 0; i < num_verts; ++i )
-	{
-		const md2_texcoord_t& st = md2->texcoords[ m_new_tindexes[ i ] ];
-		t.push_back( scale * vec2( st.s, st.t ) );
-	}
-
-}
-
-void md2_loader::load_indicies( std::vector<uint32>& idx )
-{
-	idx.assign( m_new_indexes.begin(), m_new_indexes.end() );
 }
 
@@ -433,2 +299,75 @@
 	NV_LOG( LOG_INFO, "Reuse count      = " << stats_reuse );
 }
+
+
+struct vtx_md2_pn
+{
+	nv::vec3 position;
+	nv::vec3 normal;
+};
+
+struct vtx_md2_t
+{
+	nv::vec2 texcoord;
+};
+
+
+mesh_data* nv::md2_loader::release_mesh_data()
+{
+	return release_mesh_data( -1 );
+}
+
+mesh_data* nv::md2_loader::release_mesh_data( sint32 frame )
+{
+	md2_t* md2 = (md2_t*)m_md2;
+	size_t num_frames = static_cast< size_t >( md2->header.num_frames );
+	size_t num_verts  =	m_new_vindexes.size();
+	size_t current_frame = ( frame == -1 ? 0 : static_cast< size_t >( frame ) );
+	size_t frame_count   = ( frame == -1 ? num_frames : 1 );
+
+	mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md2_pn >( num_verts * frame_count );
+	vtx_md2_pn* vtx_pn = (vtx_md2_pn*)mc_pn->data;
+
+	uint32 index = 0;
+	while ( frame_count > 0 )
+	{
+		const md2_frame_t& cframe = md2->frames[current_frame];
+		NV_LOG( LOG_INFO, "FrameID = " << cframe.name );
+
+		vec3 scale     = md2_vec3( cframe.scale );
+		vec3 translate = md2_vec3( cframe.translate );
+
+		for (size_t i = 0; i < num_verts; ++i )
+		{
+			const md2_vertex_t& v = cframe.vertices[ m_new_vindexes[ i ] ];
+			vtx_pn[index].position = vec3( v.v[0], v.v[2], v.v[1] ) * scale + translate;
+			vtx_pn[index].normal   = s_md2_normal_cache[ v.n ];
+			index++;
+		}
+		++current_frame;
+		--frame_count;
+	}
+
+	mesh_raw_channel* mc_t = mesh_raw_channel::create< vtx_md2_t >( num_verts );
+	vtx_md2_t* vtx_t = (vtx_md2_t*)mc_t->data;
+
+	vec2 scale( 1.0f / (float) md2->header.skinwidth, 1.0f / (float) md2->header.skinheight );
+	for (size_t i = 0; i < num_verts; ++i )
+	{
+		const md2_texcoord_t& st = md2->texcoords[ m_new_tindexes[ i ] ];
+		vtx_t[i].texcoord = scale * vec2( st.s, st.t );
+	}
+
+	mesh_raw_index_channel* ic = mesh_raw_index_channel::create< uint16 >( m_new_indexes.size() );
+	if ( m_new_indexes.size() > 0 )
+	{
+		uint16* icp = (uint16*)ic->data;
+		std::copy_n( m_new_indexes.data(), m_new_indexes.size(), icp );
+	}
+
+	mesh_data* result = new mesh_data();
+	result->add_channel( mc_pn );
+	result->add_channel( mc_t );
+	result->set_index_channel( ic );
+	return result;
+}
