Ignore:
Timestamp:
09/17/15 17:19:14 (10 years ago)
Author:
epyon
Message:
  • animation time definition fixes
File:
1 edited

Legend:

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

    r467 r470  
    1313void nv::skeletal_animation_entry::initialize()
    1414{
     15        m_root      = uint32(-1);
    1516        m_prepared  = false;
    1617        m_children  = nullptr;
     
    3031                                m_children[ node->get_parent_id()].push_back( n );
    3132                        }
    32                 }
    33         }
    34 }
    35 
    36 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 time ) const
    37 {
    38         float tick_time = ( time * 0.001f ) * m_frame_rate;
    39         float anim_time = m_start;
    40         if ( m_duration > 0.0f ) anim_time += fmodf( tick_time, m_duration );
     33                        else
     34                        {
     35                                if ( m_root >= 0 )
     36                                {
     37                                        m_root = uint32( -2 );
     38                                }
     39                                else
     40                                        m_root = n;
     41                        }
     42                }
     43                NV_ASSERT( m_root != uint32( -1 ), "Animation without root!" );
     44        }
     45}
     46
     47void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 a_ms_time ) const
     48{
     49        float  fframe   = ( a_ms_time * 0.001f ) * m_fps;
     50        uint32 frame    = math::floor( fframe );
     51        float  reminder = fframe - static_cast<float>( frame );
     52        uint32 duration = get_frame_count();
     53        if ( duration == 0 )
     54        {
     55                frame  = get_start_frame();
     56                fframe = static_cast<float>( frame );
     57        }
     58        else if ( frame >= duration )
     59        {
     60                if ( is_looping() )
     61                {
     62                        frame  = frame % duration;
     63                        fframe = static_cast<float>( frame ) + reminder;
     64                }
     65                else
     66                {
     67                        frame  = get_end_frame();
     68                        fframe = static_cast<float>( frame );
     69                }
     70        }
    4171
    4272        if ( !m_node_data->is_flat() )
    4373        {
    44                 animate_rec( data, anim_time, 0, mat4() );
     74                if ( m_root == uint32( -2 ) ) // multi-root
     75                {
     76                        for ( uint32 n = 0; n < m_node_data->size(); ++n )
     77                                if ( ( *m_node_data )[n]->get_parent_id() == -1 )
     78                                        animate_rec( data, fframe, n, mat4() );
     79                }
     80                else
     81                        animate_rec( data, fframe, m_root, mat4() );
    4582                return;
    4683        }
     
    5592                        {
    5693                                raw_channel_interpolator interpolator( node, m_interpolation_key );
    57                                 node_mat = interpolator.get< mat4 >( anim_time );
     94                                node_mat = interpolator.get< mat4 >( fframe );
    5895                        }
    5996
     
    66103{
    67104        if ( m_prepared ) return;
    68         unordered_map< uint64, uint16 > bone_names;
     105        nv::hash_store< shash64, uint16 > bone_names;
    69106        m_offsets = new mat4[ bones->size() ];
    70107        for ( nv::uint16 bi = 0; bi < bones->size(); ++bi )
    71108        {
    72109                const data_channel_set* bone = (*bones)[ bi ];
    73                 bone_names[ bone->get_name().value() ] = bi;
     110                bone_names[ bone->get_name() ] = bi;
    74111                m_offsets[bi] = bone->get_transform();
    75112        }
     
    80117                sint16 bone_id = -1;
    81118
    82                 auto bi = bone_names.find( node->get_name().value() );
     119                auto bi = bone_names.find( node->get_name() );
    83120                if ( bi != bone_names.end() )
    84121                {
     
    129166
    130167nv::skeletal_mesh::skeletal_mesh( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data )
    131         : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr )
     168        : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr ), m_parent_id(-1)
    132169{
    133170        if ( a_mesh )
     
    135172                m_va = a_context->create_vertex_array( a_mesh, nv::STATIC_DRAW );
    136173                m_index_count = a_mesh->get_channel_size( slot::INDEX );
     174                m_parent_id = a_mesh->get_parent_id();
    137175        }
    138176        if ( m_bone_data )
Note: See TracChangeset for help on using the changeset viewer.