Changeset 470 for trunk/src


Ignore:
Timestamp:
09/17/15 17:19:14 (10 years ago)
Author:
epyon
Message:
  • animation time definition fixes
Location:
trunk/src
Files:
6 edited

Legend:

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

    r454 r470  
    350350
    351351        uint16 frame_rate     = static_cast<uint16>( anim->mTicksPerSecond );
    352         float  duration       = static_cast<float>( anim->mDuration );
     352        int check_this;
     353        uint16 duration       = static_cast<uint16>( anim->mDuration );
    353354        bool   flat           = false;
    354355
  • trunk/src/formats/nmd_loader.cc

    r442 r470  
    9898        nmd_animation_header animation_header;
    9999        source.read( &animation_header, sizeof( animation_header ), 1 );
    100         m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.duration, animation_header.flat );
     100        m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.frame_count, animation_header.flat );
    101101        for ( uint32 i = 0; i < e.children; ++i )
    102102        {
     
    215215
    216216        nmd_animation_header aheader;
    217         aheader.frame_rate = nodes.get_frame_rate();
    218         aheader.duration = nodes.get_duration();
     217        aheader.frame_rate  = nodes.get_fps();
     218        aheader.frame_count = nodes.get_frame_count();
    219219        aheader.flat = nodes.is_flat();
    220220        stream_out.write( &aheader, sizeof( aheader ), 1 );
  • trunk/src/gfx/keyframed_mesh.cc

    r454 r470  
    7272}
    7373
    74 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_anim_time )
     74void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_ms_anim_time )
    7575{
    7676        if ( m_active )
    7777        {
    78                 float tick_time = ( static_cast<float>( a_anim_time ) * 0.001f ) * anim->get_frame_rate();
    79                 float duration  = anim->is_looping() ? anim->get_duration() + 1.0f : anim->get_duration();
    80                 if ( tick_time >= duration )
     78                float  fframe   = ( static_cast<float>( a_ms_anim_time ) * 0.001f ) * anim->get_fps();
     79                uint32 frame    = uint32( fframe );
     80                float  reminder = fframe - static_cast<float>( frame );
     81                uint32 duration = anim->is_looping() ? anim->get_frame_count() + 1 : anim->get_frame_count();
     82
     83                if ( frame >= duration )
    8184                {
    8285                        if ( anim->is_looping() )
    8386                        {
    84                                 tick_time = fmodf( tick_time, duration );
     87                                frame  = frame % duration;
     88                                fframe = static_cast<float>( frame ) + reminder;
    8589                        }
    8690                        else
    8791                        {
    88                                 m_active     = false;
    89                                 m_last_frame = static_cast<uint32>( anim->get_end() );
    90                                 m_next_frame = m_last_frame;
     92                                m_active        = false;
     93                                m_last_frame    = anim->get_end_frame();
     94                                m_next_frame    = m_last_frame;
    9195                                m_interpolation = 0.0f;
    9296                                return;
    9397                        }
    9498                }
    95                 m_last_frame    = static_cast<uint32>( math::floor( tick_time ) + anim->get_start() );
     99                m_last_frame    = frame + anim->get_start_frame();
    96100                m_next_frame    = m_last_frame + 1;
    97                 if ( m_next_frame > static_cast<uint32>( anim->get_end() ) ) m_next_frame = static_cast<uint32>( anim->get_start() );
    98                 m_interpolation = tick_time - math::floor( tick_time );
     101                if ( m_next_frame > anim->get_end_frame() ) m_next_frame = anim->get_start_frame();
     102                m_interpolation = reminder;
    99103        }
    100104}
  • trunk/src/gfx/mesh_creator.cc

    r458 r470  
    99#include "nv/interface/data_channel_access.hh"
    1010
     11#include "nv/core/logging.hh"
     12
    1113struct nv_key_transform { nv::transform tform; };
    1214
     
    1618        merge_keys();
    1719        uint32 max_frames = 0;
    18         for ( auto keys : m_data->m_data )
    19         {
     20
     21        nv::vector< sint16 > ids;
     22        {
     23                // TODO: simplify this shit!
     24                // The complexity here is that we cannot pre-transform in any order
     25                // as the bones depend on previous bones, but ARE NOT IN ORDER
     26                //
     27                // Either rewrite this a lot nicer, or sort the bones on creation
     28                // by tree-order.
     29
     30                ids.reserve( m_data->m_data.size() );
     31                {
     32                        nv::vector< sint16 > ids_next;
     33                        ids_next.reserve( m_data->m_data.size() );
     34                        ids_next.push_back( -1 );
     35                        while ( !ids_next.empty() )
     36                        {
     37                                sint16 pid = ids_next.back();
     38                                ids_next.pop_back();
     39                                for ( sint16 i = 0; i < sint16(m_data->m_data.size()); ++i )
     40                                        if ( m_data->m_data[i]->get_parent_id() == pid )
     41                                        {
     42                                                sint16* it = nv::find( ids.begin(), ids.end(), i );
     43                                                if ( it == ids.end() )
     44                                                {
     45                                                        ids.push_back( i );
     46                                                        ids_next.push_back( i );
     47                                                }
     48                                        }
     49                        }
     50                }
     51
     52                if ( ids.size() != m_data->m_data.size() )
     53                {
     54                        NV_LOG_WARNING( "Bad skeleton!" );
     55                }
     56        }
     57
     58        NV_LOG_DEBUG( "ID/PID" );
     59        for ( auto id : ids )
     60        {
     61                data_channel_set* keys = m_data->m_data[id];
    2062                sint16 parent_id = keys->get_parent_id();
    21                 data_channel_set* pkeys  = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr );
     63                NV_LOG_DEBUG( "Id : ", id, " PID", parent_id );
     64                data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr );
    2265                size_t count     = ( keys ? keys->get_channel_size(0) : 0 );
    2366                size_t pcount    = ( pkeys ? pkeys->get_channel_size(0) : 0 );
     
    2669                {
    2770                        data_channel_access< nv_key_transform > channel_creator( keys, 0 );
     71
    2872                        nv_key_transform* channel = channel_creator.data();
    2973                        const nv_key_transform* pchannel = pkeys->get_channel(0)->data_cast< nv_key_transform >();
     
    3882        if ( m_data->m_frame_rate == 1 )
    3983        {
    40                 m_data->m_frame_rate = 32;
    41                 m_data->m_duration   = static_cast<float>( max_frames );
     84                m_data->m_frame_rate  = 32;
     85                m_data->m_frame_count = max_frames;
    4286        }
    4387
  • 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 )
  • trunk/src/wx/wx_canvas.cc

    r467 r470  
    66
    77#include <nv/wx/wx_canvas.hh>
     8
     9#include <nv/core/time.hh>
    810
    911wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow )
     
    5153void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
    5254{
     55        nv::sleep( 10 );
    5356        if ( m_render )
    5457        {
Note: See TracChangeset for help on using the changeset viewer.