Ignore:
Timestamp:
07/10/15 20:34:11 (10 years ago)
Author:
epyon
Message:
  • duh, data_channel and data_channel_access was not added!
  • data_channel now holds raw_data_channels directly
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/mesh_creator.cc

    r417 r418  
    8282                                for ( uint16 c = 0; c < chan_count; ++c )
    8383                                {
    84                                         size_t idx = nv::min( old_keys->get_channel(c)->size() - 1, n );
    85                                         pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey );
     84                                        size_t idx = nv::min( old_keys->get_channel_size(c) - 1, n );
     85                                        pkey += old_keys->get_raw( *old_keys->get_channel(c), idx, pkey );
    8686                                }
    8787                                kt_channel.data()[n].tform = extract_transform_raw( final_key, key );
     
    252252        }
    253253
    254         raw_data_channel* g_channel = data_channel_creator::create< vertex_g >( p_channel->size() );
    255         vec4* tangents              = &( data_channel_access< vertex_g >( g_channel ).data()[0].tangent );
     254        raw_data_channel g_channel = data_channel_creator::create< vertex_g >( p_channel->size() );
     255        vec4* tangents              = &( data_channel_access< vertex_g >( &g_channel ).data()[0].tangent );
    256256        vec3* tangents2             = new vec3[ p_channel->size() ];
    257257        uint32 tri_count = i_channel ? i_channel->size() / 3 : t_channel->size() / 3;
     
    334334        delete tangents2;
    335335
    336         data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( n_channel, g_channel ) );
    337         delete g_channel;
    338 }
    339 
    340 nv::raw_data_channel* nv::mesh_data_creator::merge_channels( const raw_data_channel* a, const raw_data_channel* b )
    341 {
    342         NV_ASSERT( a->size() == b->size(), "merge_channel - bad channels!" );
    343         data_descriptor desc  = a->descriptor();
    344         desc.append( b->descriptor() );
    345 
    346         raw_data_channel* result = data_channel_creator::create( desc, a->size() );
    347         for ( uint32 i = 0; i < a->size(); ++i )
    348         {
    349                 raw_copy_n( a->raw_data() + i * a->element_size(), a->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() );
    350                 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() );
     336        data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( *n_channel, g_channel ) );
     337}
     338
     339nv::raw_data_channel nv::mesh_data_creator::merge_channels( const raw_data_channel& a, const raw_data_channel& b )
     340{
     341        NV_ASSERT( a.size() == b.size(), "merge_channel - bad channels!" );
     342        data_descriptor desc  = a.descriptor();
     343        desc.append( b.descriptor() );
     344
     345        raw_data_channel result = data_channel_creator::create( desc, a.size() );
     346        for ( uint32 i = 0; i < a.size(); ++i )
     347        {
     348                raw_copy_n( a.raw_data() + i * a.element_size(), a.element_size(), raw_data_channel_access( &result ).raw_data() + i*desc.element_size() );
     349                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() );
    351350        }
    352351
     
    354353}
    355354
    356 nv::raw_data_channel* nv::mesh_data_creator::append_channels( const raw_data_channel* a, const raw_data_channel* b, uint32 frame_count )
    357 {
    358         if ( a->descriptor() != b->descriptor() ) return nullptr;
    359         if ( a->size() % frame_count != 0 ) return nullptr;
    360         if ( b->size() % frame_count != 0 ) return nullptr;
    361         size_t vtx_size = a->element_size();
    362 
    363         raw_data_channel* result = data_channel_creator::create( a->descriptor(), a->size() + b->size() );
    364         uint8* rdata = raw_data_channel_access( result ).raw_data();
     355nv::raw_data_channel nv::mesh_data_creator::append_channels( const raw_data_channel& a, const raw_data_channel& b, uint32 frame_count )
     356{
     357        NV_ASSERT( a.descriptor() == b.descriptor(), "Merge - append not compatible format!" );
     358        NV_ASSERT( a.size() % frame_count == 0, "Merge - append first mesh empty!" );
     359        NV_ASSERT( b.size() % frame_count == 0, "Merge - append second mesh empty!" );
     360        size_t vtx_size = a.element_size();
     361
     362        raw_data_channel result = data_channel_creator::create( a.descriptor(), a.size() + b.size() );
     363        uint8* rdata = raw_data_channel_access( &result ).raw_data();
    365364
    366365        if ( frame_count == 1 )
    367366        {
    368                 size_t a_size = vtx_size * a->size();
    369                 raw_copy_n( a->raw_data(), a_size, rdata );
    370                 raw_copy_n( b->raw_data(), vtx_size * b->size(), rdata + a_size );
     367                size_t a_size = vtx_size * a.size();
     368                raw_copy_n( a.raw_data(), a_size, rdata );
     369                raw_copy_n( b.raw_data(), vtx_size * b.size(), rdata + a_size );
    371370        }
    372371        else
    373372        {
    374                 size_t frame_size_a = ( a->size() / frame_count ) * vtx_size;
    375                 size_t frame_size_b = ( b->size() / frame_count ) * vtx_size;
     373                size_t frame_size_a = ( a.size() / frame_count ) * vtx_size;
     374                size_t frame_size_b = ( b.size() / frame_count ) * vtx_size;
    376375                size_t pos_a = 0;
    377376                size_t pos_b = 0;
     
    379378                for ( size_t i = 0; i < frame_count; ++i )
    380379                {
    381                         raw_copy_n( a->raw_data() + pos_a, frame_size_a, rdata + pos );
    382                         raw_copy_n( b->raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a );                          pos_a += frame_size_a;
     380                        raw_copy_n( a.raw_data() + pos_a, frame_size_a, rdata + pos );
     381                        raw_copy_n( b.raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a );                           pos_a += frame_size_a;
    383382                        pos_b += frame_size_b;
    384383                        pos   += frame_size_a + frame_size_b;
     
    422421        {
    423422                const raw_data_channel* old = m_data->get_channel( c );
    424                 bool old_is_index = old->size() > 0 && old->descriptor()[0].vslot == slot::INDEX;
    425                 size_t frame_count = ( old_is_index ? 1 : old->size() / size );
    426                 data.set_channel( c, append_channels( old, other->get_channel(c), frame_count ) );
    427                 NV_ASSERT( data[c], "Merge problem!" );
     423                uint32 old_size = old->size();
     424                data_descriptor old_desc = old->descriptor();
     425                bool old_is_index = old_size > 0 && old_desc[0].vslot == slot::INDEX;
     426                size_t frame_count = ( old_is_index ? 1 : old_size / size );
     427                data.set_channel( c, append_channels( *old, *other->get_channel(c), frame_count ) );
    428428                if ( old_is_index )
    429429                {
    430                         switch ( old->descriptor()[0].etype )
     430                        switch ( old_desc[0].etype )
    431431                        {
    432432                        case USHORT :
     
    435435                                        raw_data_channel_access ic( data[c] );
    436436                                        uint16* indexes = reinterpret_cast<uint16*>( ic.raw_data() );
    437                                         for ( uint16 i = uint16( old->size() ); i < ic.size(); ++i )
     437                                        for ( uint16 i = uint16( old_size ); i < ic.size(); ++i )
    438438                                                indexes[i] += uint16( size );
    439439
     
    444444                                        raw_data_channel_access ic( data[c] );
    445445                                        uint32* indexes = reinterpret_cast<uint32*>( ic.raw_data() );
    446                                         for ( uint32 i = old->size(); i < ic.size(); ++i )
     446                                        for ( uint32 i = old_size; i < ic.size(); ++i )
    447447                                                indexes[i] += size;
    448448                                }
     
    451451                        }
    452452                }
    453                 delete old;
    454453        }
    455454}
     
    459458        if ( index < m_pack->get_count() )
    460459        {
    461                 data_channel_set_creator( &m_pack->m_meshes[index] ).destroy();
    462460                data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] );
    463461                m_pack->m_count--;
Note: See TracChangeset for help on using the changeset viewer.