Index: trunk/src/gfx/mesh_creator.cc
===================================================================
--- trunk/src/gfx/mesh_creator.cc	(revision 416)
+++ trunk/src/gfx/mesh_creator.cc	(revision 417)
@@ -19,12 +19,12 @@
 	{
 		sint16 parent_id = m_data->m_nodes[i].parent_id;
-		key_data* keys   = m_data->m_nodes[i].data;
-		key_data* pkeys  = ( parent_id != -1 ? m_data->m_nodes[parent_id].data : nullptr );
-		size_t count     = ( keys ? keys->get_channel(0)->size() : 0 );
-		size_t pcount    = ( pkeys ? pkeys->get_channel(0)->size() : 0 );
+		key_channel_set* keys   = m_data->m_nodes[i].data;
+		key_channel_set* pkeys  = ( parent_id != -1 ? m_data->m_nodes[parent_id].data : nullptr );
+		size_t count     = ( keys ? keys->get_channel_size(0) : 0 );
+		size_t pcount    = ( pkeys ? pkeys->get_channel_size(0) : 0 );
 		max_frames = nv::max<uint32>( count, max_frames );
 		if ( pkeys && pkeys->size() > 0 && keys && keys->size() > 0 )
 		{
-			data_channel_creator< nv_key_transform > channel_creator( const_cast< raw_data_channel* >( keys->get_channel( 0 ) ) );
+			data_channel_access< nv_key_transform > channel_creator( keys, 0 );
 			nv_key_transform* channel = channel_creator.data();
 			const nv_key_transform* pchannel = pkeys->get_channel(0)->data_cast< nv_key_transform >();
@@ -55,5 +55,5 @@
 	for ( size_t i = 0; i < m_data->get_count(); ++i )
 	{
-		key_data* old_keys = m_data->m_nodes[i].data;
+		key_channel_set* old_keys = m_data->m_nodes[i].data;
 		if ( old_keys && old_keys->size() > 0 )
 		{
@@ -69,6 +69,8 @@
 			}
 
-			data_channel_creator< nv_key_transform > kt_channel( max_keys );
-			key_data* new_keys = new key_data;
+			key_channel_set* new_keys = key_channel_set_creator::create( 1 );
+			key_channel_set_creator nk_access( new_keys );
+			data_channel_access< nv_key_transform > kt_channel( nk_access.add_channel<nv_key_transform>( max_keys ) );
+
 			data_descriptor final_key = old_keys->get_final_key();
 
@@ -87,5 +89,4 @@
 
 			delete old_keys;
-			new_keys->add_key_channel( kt_channel.release() );
 			m_data->m_nodes[i].data = new_keys;
 		}
@@ -105,8 +106,8 @@
 		if ( node.data )
 		{
-			key_data* kdata  = node.data;
+			key_channel_set* kdata  = node.data;
 			for ( size_t c = 0; c < kdata->size(); ++c )
 			{
-				raw_data_channel_creator channel( const_cast< raw_data_channel* >( kdata->get_channel( c ) ) );
+				raw_data_channel_access channel( kdata, c );
 				size_t key_size = channel.element_size();
 				for ( size_t n = 0; n < channel.size(); ++n )
@@ -127,5 +128,5 @@
 	for ( uint32 c = 0; c < m_data->size(); ++c )
 	{
-		raw_data_channel_creator channel( m_data, c );
+		raw_data_channel_access channel( m_data, c );
 		const data_descriptor&  desc    = channel.descriptor();
 		uint8* raw_data = channel.raw_data();
@@ -175,5 +176,5 @@
 	size_t n_offset = 0;
 	if ( ch_n == -1 ) return;
-	raw_data_channel_creator channel( m_data, unsigned( ch_n ) );
+	raw_data_channel_access channel( m_data, unsigned( ch_n ) );
 	for ( const auto& cslot : channel.descriptor() )
 		if ( cslot.vslot == slot::NORMAL )
@@ -251,6 +252,6 @@
 	}
 
-	data_channel_creator< vertex_g > g_channel( p_channel->size() );
-	vec4* tangents              = &( g_channel.data()[0].tangent );
+	raw_data_channel* g_channel = data_channel_creator::create< vertex_g >( p_channel->size() );
+	vec4* tangents              = &( data_channel_access< vertex_g >( g_channel ).data()[0].tangent );
 	vec3* tangents2             = new vec3[ p_channel->size() ];
 	uint32 tri_count = i_channel ? i_channel->size() / 3 : t_channel->size() / 3;
@@ -333,6 +334,6 @@
 	delete tangents2;
 
-	( data_channel_set_creator( m_data ))[ n_channel_index ] = merge_channels( n_channel, g_channel.channel() );
-	delete n_channel;
+	data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( n_channel, g_channel ) );
+	delete g_channel;
 }
 
@@ -343,12 +344,12 @@
 	desc.append( b->descriptor() );
 
-	raw_data_channel_creator result( desc, a->size() );
+	raw_data_channel* result = data_channel_creator::create( desc, a->size() );
 	for ( uint32 i = 0; i < a->size(); ++i )
 	{
-		raw_copy_n( a->raw_data() + i * a->element_size(), a->element_size(), result.raw_data() + i*desc.element_size() );
-		raw_copy_n( b->raw_data() + i * b->element_size(), b->element_size(), result.raw_data() + i*desc.element_size() + a->element_size() );
-	}
-
-	return result.release();
+		raw_copy_n( a->raw_data() + i * a->element_size(), a->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() );
+		raw_copy_n( b->raw_data() + i * b->element_size(), b->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() + a->element_size() );
+	}
+
+	return result;
 }
 
@@ -360,11 +361,12 @@
 	size_t vtx_size = a->element_size();
 
-	raw_data_channel_creator result( a->descriptor(), a->size() + b->size() );
+	raw_data_channel* result = data_channel_creator::create( a->descriptor(), a->size() + b->size() );
+	uint8* rdata = raw_data_channel_access( result ).raw_data();
 
 	if ( frame_count == 1 )
 	{
 		size_t a_size = vtx_size * a->size();
-		raw_copy_n( a->raw_data(), a_size, result.raw_data() );
-		raw_copy_n( b->raw_data(), vtx_size * b->size(), result.raw_data() + a_size );
+		raw_copy_n( a->raw_data(), a_size, rdata );
+		raw_copy_n( b->raw_data(), vtx_size * b->size(), rdata + a_size );
 	}
 	else
@@ -377,6 +379,6 @@
 		for ( size_t i = 0; i < frame_count; ++i )
 		{
-			raw_copy_n( a->raw_data() + pos_a, frame_size_a, result.raw_data() + pos );
-			raw_copy_n( b->raw_data() + pos_b, frame_size_b, result.raw_data() + pos + frame_size_a );				pos_a += frame_size_a;
+			raw_copy_n( a->raw_data() + pos_a, frame_size_a, rdata + pos );
+			raw_copy_n( b->raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a );				pos_a += frame_size_a;
 			pos_b += frame_size_b; 
 			pos   += frame_size_a + frame_size_b;
@@ -384,5 +386,5 @@
 	}
 
-	return result.release();
+	return result;
 }
 
@@ -422,5 +424,5 @@
 		bool old_is_index = old->size() > 0 && old->descriptor()[0].vslot == slot::INDEX;
 		size_t frame_count = ( old_is_index ? 1 : old->size() / size );
-		data[c] = append_channels( old, other->get_channel(c), frame_count );
+		data.set_channel( c, append_channels( old, other->get_channel(c), frame_count ) );
 		NV_ASSERT( data[c], "Merge problem!" );
 		if ( old_is_index )
@@ -431,5 +433,5 @@
 				{
 					NV_ASSERT( size + osize < uint16(-1), "Index out of range!" );
-					raw_data_channel_creator ic( data[c] );
+					raw_data_channel_access ic( data[c] );
 					uint16* indexes = reinterpret_cast<uint16*>( ic.raw_data() );
 					for ( uint16 i = uint16( old->size() ); i < ic.size(); ++i )
@@ -440,5 +442,5 @@
 			case UINT   : 
 				{
-					raw_data_channel_creator ic( data[c] );
+					raw_data_channel_access ic( data[c] );
 					uint32* indexes = reinterpret_cast<uint32*>( ic.raw_data() );
 					for ( uint32 i = old->size(); i < ic.size(); ++i )
