Index: trunk/src/formats/nmd_loader.cc
===================================================================
--- trunk/src/formats/nmd_loader.cc	(revision 425)
+++ trunk/src/formats/nmd_loader.cc	(revision 427)
@@ -71,5 +71,4 @@
 
 	m_node_data  = nullptr;
-	m_node_array = nullptr;
 }
 
@@ -100,5 +99,5 @@
 	nmd_animation_header animation_header;
 	source.read( &animation_header, sizeof( animation_header ), 1 );
-	m_node_array = new mesh_node_data[ e.children ];
+	m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.duration, animation_header.flat );
 	for ( uint32 i = 0; i < e.children; ++i )
 	{
@@ -107,8 +106,8 @@
 		skip_attributes( source, element_header.attributes );
 		NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" );
-		m_node_array[i].data = data_channel_set_creator::create_set( element_header.children );
-		load_channel_set( source, m_node_array[i].data, element_header );
-	}
-	m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
+		data_channel_set* set = data_channel_set_creator::create_set( element_header.children );
+		load_channel_set( source, set, element_header );
+		m_node_data->push_back( set );
+	}
 	return true;
 }
@@ -144,5 +143,4 @@
 		mesh_nodes_data* result = m_node_data;
 		m_node_data = nullptr;
-		m_node_array = nullptr;
 		return result;
 	}
@@ -153,42 +151,4 @@
 // nmd format dump
 // HACK : TEMPORARY - will go to it's own file, probably nmd_io
-static void nmd_dump_channel( const raw_data_channel* channel , stream& stream_out )
-{
-	nmd_channel_header sheader;
-	sheader.format = channel->descriptor();
-	sheader.count = channel->size();
-	stream_out.write( &sheader, sizeof( sheader ), 1 );
-	stream_out.write( channel->raw_data(), channel->element_size(), channel->size() );
-}
-
-static void nmd_dump_channel_set( const data_channel_set* channel_set, stream& stream_out )
-{
-	for ( auto& channel : *channel_set )
-	{
-		nmd_dump_channel( &channel, stream_out );
-	}
-}
-
-static void nmd_dump_node( const mesh_node_data* node, stream& stream_out )
-{
-	uint32 chan_size = 0;
-	uint32 chan_count = ( node->data ? node->data->size() : 0 );
-	for ( uint32 c = 0; c < chan_count; ++c )
-	{
-		chan_size += sizeof( nmd_channel_header );
-		chan_size += node->data->get_channel( c )->raw_size();
-	}
-
-	nmd_element_header eheader;
-	eheader.type = nmd_type::NODE;
-	eheader.children   = static_cast<uint16>( chan_count );
-	eheader.size       = chan_size;
-	eheader.name       = node->data->get_name();
-	eheader.parent_id  = node->data->get_parent_id();
-	eheader.transform  = node->data->get_transform();
-	eheader.attributes = 0;
-	stream_out.write( &eheader, sizeof( eheader ), 1 );
-	if ( chan_count > 0 ) nmd_dump_channel_set( node->data, stream_out );
-}
 
 void nv::nmd_dump_header( stream& stream_out, uint32 elements, uint64 name )
@@ -203,8 +163,8 @@
 }
 
-void nv::nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh )
+void nv::nmd_dump_element( stream& stream_out, const data_channel_set& data, nmd_type type )
 {
 	uint32 size = 0;
-	for ( auto& chan : mesh )
+	for ( auto& chan : data )
 	{
 		size += sizeof( nmd_channel_header );
@@ -213,13 +173,20 @@
 
 	nmd_element_header eheader;
-	eheader.type       = nmd_type::MESH;
-	eheader.children   = static_cast<uint16>( mesh.size() );
+	eheader.type       = type;
+	eheader.children   = static_cast<uint16>( data.size() );
 	eheader.size       = size;
-	eheader.name       = mesh.get_name();
-	eheader.transform  = mesh.get_transform();
-	eheader.parent_id  = mesh.get_parent_id();
+	eheader.name       = data.get_name();
+	eheader.transform  = data.get_transform();
+	eheader.parent_id  = data.get_parent_id();
 	eheader.attributes = 0;
 	stream_out.write( &eheader, sizeof( eheader ), 1 );
-	nmd_dump_channel_set( &mesh, stream_out );
+	for ( auto& channel : data )
+	{
+		nmd_channel_header cheader;
+		cheader.format = channel.descriptor();
+		cheader.count = channel.size();
+		stream_out.write( &cheader, sizeof( cheader ), 1 );
+		stream_out.write( channel.raw_data(), channel.element_size(), channel.size() );
+	}
 }
 
@@ -227,14 +194,12 @@
 {
 	uint32 total = sizeof( nmd_animation_header );
-	for ( uint32 i = 0; i < nodes.get_count(); ++i )
-	{
-		const mesh_node_data* node = nodes.get_node( i );
+	for ( auto node : nodes )
+	{
 		total += sizeof( nmd_element_header );
-		if ( node->data )
-			for ( uint32 c = 0; c < node->data->size(); ++c )
-			{
-				total += sizeof( nmd_channel_header );
-				total += node->data->get_channel( c )->raw_size();
-			}
+		for ( uint32 c = 0; c < node->size(); ++c )
+		{
+			total += sizeof( nmd_channel_header );
+			total += node->get_channel( c )->raw_size();
+		}
 	}
 
@@ -256,7 +221,7 @@
 	stream_out.write( &aheader, sizeof( aheader ), 1 );
 
-	for ( uint32 i = 0; i < nodes.get_count(); ++i )
-	{
-		nmd_dump_node( nodes.get_node( i ), stream_out );
+	for ( auto node : nodes )
+	{
+		nmd_dump_element( stream_out, *node, nv::nmd_type::NODE );
 	}
 }
@@ -284,5 +249,5 @@
 	for ( uint32 i = 0; i < model->get_count(); ++i )
 	{
-		nmd_dump_mesh( stream_out, *model->get_mesh( i ) );
+		nmd_dump_element( stream_out, *model->get_mesh( i ), nv::nmd_type::MESH );
 	}
 
