Changeset 283 for trunk/src/gfx
- Timestamp:
- 07/10/14 20:58:27 (11 years ago)
- Location:
- trunk/src/gfx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/keyframed_mesh.cc
r282 r283 23 23 , m_last_frame( 0 ) 24 24 , m_next_frame( 0 ) 25 , m_time( 0 )26 25 , m_fps( 0 ) 27 26 , m_interpolation( 0.0f ) … … 56 55 m_fps = fps; 57 56 m_active = count > 1; 58 m_time = 0;59 57 m_last_frame = start; 60 58 m_next_frame = (count > 1 ? start + 1 : start ); … … 70 68 } 71 69 72 void keyframed_mesh::update( uint32 ms)70 void nv::keyframed_mesh::update_animation( animation_entry*, uint32 a_anim_time ) 73 71 { 74 72 if ( m_active ) 75 73 { 76 m_time += ms;77 74 uint32 f_diff = (m_stop_frame - m_start_frame); 78 float f_time= 1000 / (float)m_fps;75 float f_time = 1000 / (float)m_fps; 79 76 float f_max = ( m_looping ? ( f_diff + 1 ) : f_diff ) * f_time; 80 float f_pos = m_time / f_time; 81 82 m_last_frame = (uint32)glm::floor( f_pos ) + m_start_frame; 83 m_next_frame = m_last_frame + 1; 84 if ( m_next_frame > m_stop_frame ) 85 { 86 m_next_frame = m_start_frame; 87 } 88 89 if ( m_time >= f_max ) 77 uint32 time = a_anim_time; 78 if ( time >= f_max ) 90 79 { 91 80 if ( m_looping ) 92 81 { 93 uint32 left = m_time - static_cast< uint32 >( f_max ); 94 m_time = 0; 95 update( left ); 82 time = time % static_cast< uint32 >( f_max ); 96 83 } 97 84 else … … 102 89 } 103 90 } 91 float f_pos = time / f_time; 92 93 m_last_frame = (uint32)glm::floor( f_pos ) + m_start_frame; 94 m_next_frame = m_last_frame + 1; 95 if ( m_next_frame > m_stop_frame ) m_next_frame = m_start_frame; 104 96 m_interpolation = f_pos - glm::floor( f_pos ); 105 97 } 106 98 } 99 107 100 108 101 void nv::keyframed_mesh::update( program* a_program ) const … … 148 141 void nv::keyframed_mesh_gpu::update( uint32 ms ) 149 142 { 150 keyframed_mesh::update( ms );143 animated_mesh::update( ms ); 151 144 152 145 if ( m_gpu_last_frame != m_last_frame ) … … 181 174 void nv::keyframed_mesh_cpu::update( uint32 ms ) 182 175 { 183 keyframed_mesh::update( ms );176 animated_mesh::update( ms ); 184 177 185 178 const vertex_pn* data = m_mesh_data->get_channel_data<vertex_pn>(); -
trunk/src/gfx/skeletal_mesh.cc
r281 r283 14 14 : animated_mesh() 15 15 , m_mesh_data( nullptr ) 16 , m_animation( nullptr )17 , m_animation_time( 0 )18 16 { 19 17 m_mesh_data = a_mesh_data->spawn(); … … 21 19 } 22 20 23 24 void nv::skeletal_mesh::setup_animation( md5_animation* a_anim ) 21 void nv::skeletal_mesh::update_animation( animation_entry* a_anim, uint32 a_anim_time ) 25 22 { 26 m_animation = a_anim; 27 m_animation_time = 0; 28 if ( m_animation ) 23 if ( a_anim ) 29 24 { 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 ); 44 30 m_mesh_data->apply( m_transform.data() ); 45 31 vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION ); … … 60 46 if ( a_anim != nullptr ) 61 47 { 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 ); 68 51 } 69 52 } 53 54 void nv::skeletal_animation_entry_gpu::update_skeleton( mat4* data, uint32 time ) 55 { 56 m_animation->animate( data, time ); 57 } 58 59 void nv::skeletal_animation_entry_gpu::prepare( const nmd_temp_model* m_model ) 60 { 61 m_animation->prepare( m_model ); 62 } 63 64 nv::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 72 void 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 83 void 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 92 void 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.