Changeset 241 for trunk/src/gfx


Ignore:
Timestamp:
05/22/14 01:19:08 (11 years ago)
Author:
epyon
Message:
  • significant simplification of the md5 code
  • proper instancing for both md5 animations and meshes
  • transform_vectors
Location:
trunk/src/gfx
Files:
2 edited

Legend:

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

    r239 r241  
    4444{
    4545        NV_ASSERT( m_tag_map, "TAGMAP FAIL" );
    46         const std::vector< transform >* transforms = m_tag_map->get_tag( tag );
     46        const transform_vector* transforms = m_tag_map->get_tag( tag );
    4747        NV_ASSERT( transforms, "TAG FAIL" );
    48         return interpolate( (*transforms)[ m_last_frame ], (*transforms)[ m_next_frame ], m_interpolation );
     48        return interpolate( transforms->get( m_last_frame ), transforms->get( m_next_frame ), m_interpolation );
    4949}
    5050
  • trunk/src/gfx/skeletal_mesh.cc

    r240 r241  
    1313nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_mesh_data* a_mesh_data )
    1414        : animated_mesh()
    15         , m_mesh_data( a_mesh_data )
     15        , m_mesh_data( nullptr )
    1616        , m_animation( nullptr )
     17        , m_animation_time( 0 )
    1718{
    18         m_va = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
     19        m_mesh_data = a_mesh_data->spawn();
     20        m_va        = a_context->get_device()->create_vertex_array( a_mesh_data, nv::STREAM_DRAW );
    1921}
    2022
     
    2224void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
    2325{
    24         if ( m_animation ) m_animation->reset_animation();
    25         m_animation = a_anim;
    26         // TODO : INSTANCE!
    27         m_animation->reset_animation();
     26        m_animation      = a_anim;
     27        m_animation_time = 0;
     28        if ( m_animation )
     29        {
     30                m_transform.resize( m_animation->get_num_joints() );
     31                update( 0 );
     32        }
    2833}
    2934
    3035void nv::skeletal_mesh::update( uint32 ms )
    3136{
    32         if (m_animation != nullptr)
     37        if ( m_animation )
    3338        {
    34                 m_animation->update( ms * 0.001f );
    35                 m_mesh_data->apply( *m_animation );
     39                m_animation_time += ms;
     40                float frame_duration = 1000.f / (float)m_animation->get_frame_rate();
     41                uint32 anim_duration = uint32( frame_duration * (float)m_animation->get_frame_count() );
     42                while ( m_animation_time >= anim_duration ) m_animation_time -= anim_duration;
     43                m_animation->update_skeleton( m_transform, (float)m_animation_time * 0.001f );
     44                m_mesh_data->apply( m_transform );
    3645                vertex_buffer* vb = m_va->find_buffer( nv::POSITION );
    37                 const mesh_raw_channel* pch = m_mesh_data->get_channel_data()[0];
    3846                vb->bind();
    39                 vb->update( (const void*)pch->data, 0, pch->size );
     47                vb->update( m_mesh_data->data(), 0, m_mesh_data->size() );
    4048                vb->unbind();
    4149        }
     
    4553{
    4654        delete m_va;
    47         // TODO : INSTANCE!
    48         //      delete m_mesh_data;
     55        delete m_mesh_data;
    4956}
    5057
     
    5259{
    5360        skeletal_animation_entry * anim = down_cast<skeletal_animation_entry>(a_anim);
    54         // TODO : INSTANCE!
    5561        setup_animation( anim->m_animation );
    5662}
Note: See TracChangeset for help on using the changeset viewer.