Ignore:
Timestamp:
08/11/14 11:56:19 (11 years ago)
Author:
epyon
Message:
  • mouse wheel support for both SDL 1.2 and 2.0
  • optional unmerged MD3 import
  • selective delete mesh form mesh_creator
  • minor fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/md3_loader.cc

    r291 r304  
    233233static bool s_normal_ready = false;
    234234
    235 md3_loader::md3_loader()
    236         : m_md3( nullptr )
     235md3_loader::md3_loader( bool merge_all )
     236        : m_md3( nullptr ), m_merge_all( merge_all )
    237237{
    238238        if ( !s_normal_ready )
     
    319319};
    320320
    321 mesh_data* nv::md3_loader::release_mesh_data( size_t )
     321mesh_data* nv::md3_loader::release_mesh_data( size_t index )
    322322{
    323323        mesh_data* data = new mesh_data;
    324         release_mesh_frame( data, -1 );
     324        release_mesh_frame( data, -1, index );
    325325        return data;
    326326}
    327327
    328 void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame )
     328void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface )
    329329{
    330330        md3_t* md3 = (md3_t*)m_md3;
    331         sint32 num_surfaces = md3->header.num_surfaces;
    332         sint32 num_verts    = md3->vertices_per_frame;
     331        sint32 num_surfaces  = md3->header.num_surfaces;
     332        sint32 num_verts     = 0;
    333333        sint32 current_frame = ( frame == -1 ? 0 : frame );
    334334        sint32 frame_count   = ( frame == -1 ? md3->header.num_frames : 1 );
     335        sint32 current_surf  = ( surface == -1 ? 0 : surface );
     336        sint32 surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
     337        sint32 index_count   = 0;
     338
     339        if ( surface >= 0 )
     340        {
     341                index_count = md3->surfaces[surface].header.num_triangles * 3;
     342                num_verts   = md3->surfaces[surface].header.num_verts;
     343        }
     344        else
     345                for ( sint32 i = 0; i < num_surfaces; ++i )
     346                {
     347                        index_count += md3->surfaces[i].header.num_triangles * 3;
     348                        num_verts   += md3->surfaces[i].header.num_verts;
     349                }
    335350
    336351        mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( num_verts * frame_count );
     352        mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( num_verts );
     353        mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count );
    337354        vtx_md3_pn* vtx_pn = (vtx_md3_pn*)mc_pn->data;
    338 
    339         uint32 index = 0;
     355        vtx_md3_t*  vtx_t  = (vtx_md3_t*) mc_t->data;
     356        uint16*     icp    = (uint16*)ic->data;
     357
     358        uint32 index  = 0;
     359        uint32 iindex = 0;
     360        sint32 index_base = 0;
     361
     362        while ( surf_count > 0 )
     363        {
     364                const md3_surface_t& surface = md3->surfaces[ current_surf ];
     365                const uint32         vcount  = static_cast< uint32 >( surface.header.num_verts );
     366                const uint32         tcount  = static_cast< uint32 >( surface.header.num_triangles );
     367
     368                for (uint32 j = 0; j < vcount; ++j )
     369                {
     370                        vtx_t[index++].texcoord = md3_texcoord( surface.st[j] );
     371                }
     372
     373                for (size_t j = 0; j < tcount; ++j )
     374                {
     375                        const md3_triangle_t& t = surface.triangles[j];
     376                        icp[iindex++] = static_cast< uint16 >( index_base + t.indexes[0] );
     377                        icp[iindex++] = static_cast< uint16 >( index_base + t.indexes[1] );
     378                        icp[iindex++] = static_cast< uint16 >( index_base + t.indexes[2] );
     379                }
     380                index_base += surface.header.num_verts;
     381                ++current_surf;
     382                --surf_count;
     383        }
     384
     385        index = 0;
    340386        while ( frame_count > 0 )
    341387        {
    342                 for ( sint32 i = 0; i < num_surfaces; ++i )
    343                 {
    344                         md3_surface_t& surface = md3->surfaces[i];
     388                current_surf  = ( surface == -1 ? 0 : surface );
     389                surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
     390
     391                while ( surf_count > 0 )
     392                {
     393                        md3_surface_t& surface = md3->surfaces[current_surf];
    345394                        sint32         vcount  = surface.header.num_verts;
    346395                        sint32         offset  = vcount * current_frame;
     
    353402                                index++;
    354403                        }
    355 
     404                        ++current_surf;
     405                        --surf_count;
    356406                }
    357407                ++current_frame;
    358408                --frame_count;
    359         }
    360 
    361         index = 0;
    362         mesh_raw_channel* mc_t = mesh_raw_channel::create< vtx_md3_t >( num_verts );
    363         vtx_md3_t* vtx_t = (vtx_md3_t*)mc_t->data;
    364         for ( sint32 i = 0; i < num_surfaces; ++i )
    365         {
    366                 const md3_surface_t& surface = md3->surfaces[i];
    367                 const uint32         vcount  = static_cast< uint32 >( surface.header.num_verts );
    368                 for (uint32 j = 0; j < vcount; ++j )
    369                 {
    370                         vtx_t[index++].texcoord = md3_texcoord( surface.st[j] );
    371                 }
    372         }
    373 
    374         sint32 index_count = 0;
    375         for ( sint32 i = 0; i < num_surfaces; ++i )
    376         {
    377                 index_count += md3->surfaces[i].header.num_triangles * 3;
    378         }
    379 
    380         index = 0;
    381         sint32 index_base = 0;
    382         mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count );
    383         uint16* icp = (uint16*)ic->data;
    384         for ( sint32 i = 0; i < num_surfaces; ++i )
    385         {
    386                 const md3_surface_t& surface = md3->surfaces[i];
    387                 const size_t         tcount  = static_cast< size_t >( surface.header.num_triangles );
    388                 for (size_t j = 0; j < tcount; ++j )
    389                 {
    390                         const md3_triangle_t& t = surface.triangles[j];
    391                         icp[index++] = static_cast< uint16 >( index_base + t.indexes[0] );
    392                         icp[index++] = static_cast< uint16 >( index_base + t.indexes[1] );
    393                         icp[index++] = static_cast< uint16 >( index_base + t.indexes[2] );
    394                 }
    395                 index_base += surface.header.num_verts;
    396409        }
    397410
     
    427440mesh_data_pack* nv::md3_loader::release_mesh_data_pack()
    428441{
    429         mesh_data* data = new mesh_data[1];
    430         release_mesh_frame( &data[0], -1 );
    431         return new mesh_data_pack( 1, data, release_mesh_nodes_data() );
     442        md3_t* md3 = (md3_t*)m_md3;
     443        uint32 count = 1;
     444        mesh_data* data = nullptr;
     445        if ( m_merge_all )
     446        {
     447                data = new mesh_data[1];
     448                release_mesh_frame( &data[0], -1, -1 );
     449                data[0].set_name( (char*)md3->header.name );
     450        }
     451        else
     452        {
     453                count = md3->header.num_surfaces;
     454                data = new mesh_data[ count ];
     455                for ( uint32 i = 0; i < count; ++i )
     456                {
     457                        release_mesh_frame( &data[i], -1, i );
     458                        data[i].set_name( (char*)md3->surfaces[i].header.name );
     459                }
     460        }
     461        return new mesh_data_pack( count, data, release_mesh_nodes_data() );
    432462}
    433463
Note: See TracChangeset for help on using the changeset viewer.