Changeset 283
- Timestamp:
- 07/10/14 20:58:27 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/keyframed_mesh.hh
r280 r283 44 44 virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop ); 45 45 virtual void set_frame( uint32 frame ); 46 virtual void update ( uint32 ms);46 virtual void update_animation( animation_entry*, uint32 a_anim_time ); 47 47 virtual void update( program* a_program ) const; 48 48 virtual ~keyframed_mesh(); … … 65 65 uint32 m_last_frame; 66 66 uint32 m_next_frame; 67 uint32 m_time;68 67 uint32 m_fps; 69 68 f32 m_interpolation; -
trunk/nv/gfx/skeletal_mesh.hh
r275 r283 12 12 #include <nv/interface/animated_mesh.hh> 13 13 #include <nv/formats/md5_loader.hh> 14 #include <nv/formats/nmd_loader.hh> 14 15 15 16 namespace nv … … 26 27 virtual uint32 get_frame_count() const { return m_animation->get_frame_count(); } 27 28 virtual bool is_looping() const { return m_looping; } 29 uint32 get_num_joints() const { return m_animation->get_num_joints();} 30 void update_skeleton( transform* tr, float time ) const { return m_animation->update_skeleton( tr, time );} 28 31 protected: 29 32 md5_animation* m_animation; … … 31 34 }; 32 35 33 // TODO: INSTANCING! currently md5_mesh data is deleted!34 36 class skeletal_mesh : public animated_mesh 35 37 { … … 38 40 virtual size_t get_index_count() const { return m_mesh_data->get_index_count(); } 39 41 virtual void run_animation( animation_entry* a_anim ); 40 virtual void setup_animation( md5_animation* a_anim ); 41 virtual void update( uint32 ms ); 42 virtual void update_animation( animation_entry* a_anim, uint32 a_anim_time ); 42 43 virtual ~skeletal_mesh(); 43 44 protected: 44 45 md5_mesh_instance* m_mesh_data; 45 md5_animation* m_animation; 46 std::vector< transform > m_transform; 47 }; 46 48 47 std::vector< transform > m_transform; 48 uint32 m_animation_time; 49 class skeletal_animation_entry_gpu : public animation_entry 50 { 51 public: 52 skeletal_animation_entry_gpu( const std::string& name, nmd_temp_animation* anim, bool a_looping ) 53 : animation_entry( name ), m_animation( anim ), m_looping( a_looping ), m_prepared( false ) {} 54 virtual uint32 get_frame_rate() const { return 0; } 55 virtual uint32 get_frame_count() const { return 0; } 56 virtual bool is_looping() const { return m_looping; } 57 void prepare( const nmd_temp_model* m_model ); 58 void update_skeleton( mat4* tr, uint32 time ); 59 protected: 60 nmd_temp_animation* m_animation; 61 bool m_prepared; 62 bool m_looping; 63 }; 64 65 class skeletal_mesh_gpu : public animated_mesh 66 { 67 public: 68 skeletal_mesh_gpu( device* a_device, const nmd_temp_model* a_model, uint32 index, bool primary ); 69 virtual size_t get_index_count() const { return m_index_count; } 70 virtual void run_animation( animation_entry* a_anim ); 71 virtual void update( program* a_program ) const; 72 virtual void update_animation( animation_entry* a_anim, uint32 73 a_anim_time ); 74 protected: 75 const nmd_temp_model* m_model; 76 bool m_primary; 77 uint32 m_index_count; 78 std::vector< mat4 > m_transform; 49 79 }; 50 80 -
trunk/nv/interface/animated_mesh.hh
r231 r283 39 39 public: 40 40 animated_mesh() {} 41 virtual void update_animation( animation_entry*, uint32 ) {} 41 42 virtual void run_animation( animation_entry* ) {} 42 43 virtual transform get_tag( const std::string& ) const { return transform(); } -
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.