Changeset 283 for trunk/src/gfx/skeletal_mesh.cc
- Timestamp:
- 07/10/14 20:58:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.