Ignore:
Timestamp:
07/10/14 20:58:27 (11 years ago)
Author:
epyon
Message:
  • Nova Model Data format loader added
  • keyframed mesh and skeletal mesh don't store time info anymore
  • NMD loader has a temporary utility class for fast usage
File:
1 edited

Legend:

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

    r281 r283  
    1414        : animated_mesh()
    1515        , m_mesh_data( nullptr )
    16         , m_animation( nullptr )
    17         , m_animation_time( 0 )
    1816{
    1917        m_mesh_data = a_mesh_data->spawn();
     
    2119}
    2220
    23 
    24 void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
     21void nv::skeletal_mesh::update_animation( animation_entry* a_anim, uint32 a_anim_time )
    2522{
    26         m_animation      = a_anim;
    27         m_animation_time = 0;
    28         if ( m_animation )
     23        if ( a_anim )
    2924        {
    30                 m_transform.resize( m_animation->get_num_joints() );
    31                 update( 0 );
    32         }
    33 }
    34 
    35 void nv::skeletal_mesh::update( uint32 ms )
    36 {
    37         if ( m_animation )
    38         {
    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.data(), (float)m_animation_time * 0.001f );
     25                skeletal_animation_entry * anim = (skeletal_animation_entry*)a_anim;
     26                float frame_duration = 1000.f / (float)anim->get_frame_rate();
     27                uint32 anim_duration = uint32( frame_duration * (float)anim->get_frame_count() );
     28                uint32 new_time = a_anim_time % anim_duration;
     29                anim->update_skeleton( m_transform.data(), (float)new_time * 0.001f );
    4430                m_mesh_data->apply( m_transform.data() );
    4531                vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
     
    6046        if ( a_anim != nullptr )
    6147        {
    62                 skeletal_animation_entry * anim = down_cast<skeletal_animation_entry>(a_anim);
    63                 setup_animation( anim->m_animation );
    64         }
    65         else
    66         {
    67                 setup_animation( nullptr );
     48                skeletal_animation_entry * anim = (skeletal_animation_entry*)(a_anim);
     49                m_transform.resize( anim->get_num_joints() );
     50                update_animation( a_anim, 0 );
    6851        }
    6952}
     53
     54void nv::skeletal_animation_entry_gpu::update_skeleton( mat4* data, uint32 time )
     55{
     56        m_animation->animate( data, time );
     57}
     58
     59void nv::skeletal_animation_entry_gpu::prepare( const nmd_temp_model* m_model )
     60{
     61        m_animation->prepare( m_model );
     62}
     63
     64nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const nmd_temp_model* a_model, uint32 index, bool primary )
     65        : animated_mesh(), m_primary( primary ), m_model( a_model )
     66{
     67        const mesh_data* data = a_model->get_data( index );
     68        m_va          = a_device->create_vertex_array( data, nv::STATIC_DRAW );
     69        m_index_count = data->get_count();
     70}
     71
     72void nv::skeletal_mesh_gpu::run_animation( animation_entry* a_anim )
     73{
     74        if ( m_primary && a_anim != nullptr )
     75        {
     76                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)(a_anim);
     77                m_transform.resize( m_model->get_bone_count() );
     78                anim->prepare( m_model );
     79                update_animation( a_anim, 0 );
     80        }
     81}
     82
     83void nv::skeletal_mesh_gpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )
     84{
     85        if ( m_primary && a_anim )
     86        {
     87                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)a_anim;
     88                anim->update_skeleton( m_transform.data(), a_anim_time );
     89        }
     90}
     91
     92void nv::skeletal_mesh_gpu::update( program* a_program ) const
     93{
     94        if (m_primary)
     95                a_program->set_uniform_array( "nv_m_bones", m_transform );
     96}
Note: See TracChangeset for help on using the changeset viewer.