Changeset 288
- Timestamp:
- 07/23/14 17:37:44 (11 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/md5_loader.hh
r287 r288 72 72 size_t get_num_joints() const { return m_num_joints; } 73 73 size_t get_frame_rate() const { return m_frame_rate; } 74 size_t get_frame_count() const { returnm_num_frames; }74 float get_duration() const { return (float)m_num_frames; } 75 75 76 76 protected: -
trunk/nv/gfx/keyframed_mesh.hh
r287 r288 16 16 { 17 17 18 class keyframed_animation_entry : public animation_entry19 {20 public:21 friend class keyframed_mesh;22 23 keyframed_animation_entry( const std::string& name, uint32 a_start, uint32 a_frames, uint32 a_fps, bool a_loop )24 : animation_entry( name ), m_start( a_start ), m_frames( a_frames ), m_fps( a_fps ), m_looping( a_loop ) {}25 virtual uint32 get_frame_rate() const { return m_fps; }26 virtual float get_duration() const { return (float)m_frames; }27 virtual bool is_looping() const { return m_looping; }28 protected:29 uint32 m_start;30 uint32 m_frames;31 uint32 m_fps;32 bool m_looping;33 };34 35 36 18 class keyframed_mesh : public animated_mesh 37 19 { … … 43 25 virtual transform get_node_transform( uint32 node_id ) const; 44 26 virtual mat4 get_node_matrix( uint32 node_id ) const; 45 virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );46 virtual void set_frame( uint32 frame );47 27 virtual void update_animation( animation_entry*, uint32 a_anim_time ); 48 28 virtual void update( program* a_program ) const; 49 29 virtual ~keyframed_mesh(); 50 30 protected: 31 virtual void set_frame( uint32 frame ); 32 51 33 struct vertex_pn 52 34 { … … 62 44 const mesh_nodes_data* m_tag_map; 63 45 64 uint32 m_start_frame;65 uint32 m_stop_frame;66 46 uint32 m_last_frame; 67 47 uint32 m_next_frame; 68 uint32 m_fps;69 48 f32 m_interpolation; 70 bool m_looping;71 49 bool m_active; 72 50 -
trunk/nv/gfx/skeletal_mesh.hh
r287 r288 23 23 24 24 skeletal_animation_entry( const std::string& name, md5_animation* a_animation, bool a_looping ) 25 : animation_entry( name ), m_animation( a_animation ), m_looping( a_looping ) {} 26 virtual uint32 get_frame_rate() const { return m_animation->get_frame_rate(); } 27 virtual uint32 get_frame_count() const { return m_animation->get_frame_count(); } 28 virtual bool is_looping() const { return m_looping; } 25 : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_animation( a_animation ) {} 26 skeletal_animation_entry( const std::string& name, md5_animation* a_animation, float time_start, float time_end, bool a_looping ) 27 : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_animation( a_animation ) {} 29 28 uint32 get_num_joints() const { return m_animation->get_num_joints();} 30 29 void update_skeleton( transform* tr, float time ) const { return m_animation->update_skeleton( tr, time );} 31 30 protected: 32 31 md5_animation* m_animation; 33 bool m_looping;34 32 }; 35 33 … … 56 54 { 57 55 public: 58 skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping ); 59 virtual uint32 get_frame_rate() const { return m_node_data->get_frame_rate(); } 60 virtual float get_duration() const { return m_node_data->get_duration(); } 61 virtual bool is_looping() const { return m_looping; } 56 skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping ) 57 : animation_entry( name, a_looping, anim->get_frame_rate(), 0.0f, anim->get_duration() ) 58 , m_node_data( anim ) 59 { 60 initialize(); 61 } 62 63 skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping ) 64 : animation_entry( name, a_looping, anim->get_frame_rate(), time_start, time_end ) 65 , m_node_data( anim ) 66 { 67 initialize(); 68 } 69 62 70 void prepare( const mesh_nodes_data* bones ); 63 71 void update_skeleton( mat4* tr, uint32 time ) const; 64 72 ~skeletal_animation_entry_gpu(); 65 73 protected: 74 void initialize(); 66 75 void animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const; 76 77 protected: 67 78 const mesh_nodes_data* m_node_data; 68 79 std::vector< uint32 >* m_children; … … 70 81 mat4* m_offsets; 71 82 bool m_prepared; 72 bool m_looping;73 83 }; 74 84 -
trunk/nv/interface/animated_mesh.hh
r287 r288 25 25 { 26 26 public: 27 animation_entry( const std::string& name ) : m_name( name ) {} 28 virtual const std::string& get_name() const { return m_name; } 29 virtual uint32 get_frame_rate() const = 0; 30 virtual float get_duration() const = 0; 31 virtual bool is_looping() const = 0; 27 animation_entry( const std::string& name, bool looping, uint32 frame_rate, float a_start, float a_end ) : m_name( name ), m_looping( looping ), m_frame_rate( frame_rate ), 28 m_start( a_start ), m_end( a_end ), m_duration( m_end - m_start ) {} 29 const std::string& get_name() const { return m_name; } 30 uint32 get_frame_rate() const { return m_frame_rate; } 31 float get_duration() const { return m_duration; } 32 float get_start() const { return m_start; } 33 float get_end() const { return m_end; } 34 bool is_looping() const { return m_looping; } 32 35 virtual ~animation_entry() {} 33 36 protected: 34 37 std::string m_name; 38 bool m_looping; 39 uint32 m_frame_rate; 40 float m_start; 41 float m_end; 42 float m_duration; 35 43 }; 36 44 -
trunk/nv/lua/lua_state.hh
r265 r288 228 228 unsigned get_unsigned( const std::string& element, unsigned defval = 0 ); 229 229 double get_double( const std::string& element, double defval = 0.0 ); 230 float get_float( const std::string& element, float defval = 0.0 ); 230 231 bool get_boolean( const std::string& element, bool defval = false ); 231 232 -
trunk/src/gfx/keyframed_mesh.cc
r287 r288 19 19 , m_mesh_data( a_data ) 20 20 , m_tag_map( a_tag_map ) 21 , m_start_frame( false )22 , m_stop_frame( false )23 21 , m_last_frame( 0 ) 24 22 , m_next_frame( 0 ) 25 , m_fps( 0 )26 23 , m_interpolation( 0.0f ) 27 , m_looping( false )28 24 , m_active( false ) 29 25 { … … 56 52 } 57 53 58 void keyframed_mesh::setup_animation( uint32 start, uint32 count, uint32 fps, bool loop )59 {60 m_start_frame = start;61 m_stop_frame = start+count-1;62 m_looping = loop;63 m_fps = fps;64 m_active = count > 1;65 m_last_frame = start;66 m_next_frame = (count > 1 ? start + 1 : start );67 m_interpolation = 0.0f;68 }69 70 54 void nv::keyframed_mesh::set_frame( uint32 frame ) 71 55 { … … 76 60 } 77 61 78 void nv::keyframed_mesh::update_animation( animation_entry* , uint32 a_anim_time )62 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_anim_time ) 79 63 { 80 64 if ( m_active ) 81 65 { 82 uint32 f_diff = (m_stop_frame - m_start_frame); 83 float f_time = 1000 / (float)m_fps; 84 float f_max = ( m_looping ? ( f_diff + 1 ) : f_diff ) * f_time; 85 uint32 time = a_anim_time; 86 if ( time >= f_max ) 66 float tick_time = ( (float)a_anim_time * 0.001f ) * anim->get_frame_rate(); 67 float duration = anim->is_looping() ? anim->get_duration() + 1.0f : anim->get_duration(); 68 if ( tick_time >= duration ) 87 69 { 88 if ( m_looping)70 if ( anim->is_looping() ) 89 71 { 90 ti me = time % static_cast< uint32 >( f_max);72 tick_time = fmodf( tick_time, duration ); 91 73 } 92 74 else 93 75 { 94 76 m_active = false; 95 m_last_frame = m_stop_frame; 96 m_next_frame = m_stop_frame; 77 m_last_frame = (uint32)anim->get_end(); 78 m_next_frame = m_last_frame; 79 m_interpolation = 0.0f; 80 return; 97 81 } 98 82 } 99 float f_pos = time / f_time; 100 101 m_last_frame = (uint32)glm::floor( f_pos ) + m_start_frame; 83 m_last_frame = (uint32)( glm::floor( tick_time ) + anim->get_start() ); 102 84 m_next_frame = m_last_frame + 1; 103 if ( m_next_frame > m_stop_frame ) m_next_frame = m_start_frame;104 m_interpolation = f_pos - glm::floor( f_pos);85 if ( m_next_frame > (uint32)anim->get_end() ) m_next_frame = (uint32)anim->get_start(); 86 m_interpolation = tick_time - glm::floor( tick_time ); 105 87 } 106 88 } … … 121 103 if ( a_anim ) 122 104 { 123 keyframed_animation_entry * anim = down_cast<keyframed_animation_entry>(a_anim); 124 m_active = true; 125 setup_animation( anim->m_start, anim->m_frames, anim->m_fps, anim->m_looping ); 105 m_active = true; 106 m_last_frame = 0; 107 m_next_frame = 0; 108 m_interpolation = 0.0f; 126 109 } 127 110 else -
trunk/src/gfx/skeletal_mesh.cc
r287 r288 33 33 skeletal_animation_entry * anim = (skeletal_animation_entry*)a_anim; 34 34 float frame_duration = 1000.f / (float)anim->get_frame_rate(); 35 uint32 anim_duration = uint32( frame_duration * (float)anim->get_frame_count());36 uint32 new_time = a_anim_time % anim_duration;37 anim->update_skeleton( m_transform.data(), (float)new_time * 0.001f );35 float anim_duration = frame_duration * anim->get_duration(); 36 float new_time = fmodf( (float)a_anim_time, anim_duration ); 37 anim->update_skeleton( m_transform.data(), new_time * 0.001f ); 38 38 39 39 //m_mesh_data->apply( m_transform.data() ); … … 87 87 } 88 88 89 90 nv::skeletal_animation_entry_gpu::skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping ) 91 : animation_entry( name ) 92 , m_node_data( anim ) 93 { 94 uint32 node_count = m_node_data->get_count(); 95 89 void nv::skeletal_animation_entry_gpu::initialize() 90 { 96 91 m_prepared = false; 97 m_looping = a_looping;98 92 m_children = nullptr; 99 93 m_offsets = nullptr; 94 uint32 node_count = m_node_data->get_count(); 100 95 m_bone_ids = new sint16[ node_count ]; 101 96 -
trunk/src/lua/lua_state.cc
r265 r288 148 148 { 149 149 lua_getfield( m_state, -1, element.c_str() ); 150 bool result = lua_isnil( m_state, -1);150 bool result = !( lua_isnil( m_state, -1 ) ); 151 151 lua_pop( m_state, 1 ); 152 152 return result; … … 189 189 lua_getfield( m_state, -1, element.c_str() ); 190 190 double result = lua_type( m_state, -1 ) == LUA_TNUMBER ? lua_tonumber( m_state, -1 ) : defval; 191 lua_pop( m_state, 1 ); 192 return result; 193 } 194 195 196 float nv::lua::table_guard::get_float( const std::string& element, float defval /*= 0.0 */ ) 197 { 198 lua_getfield( m_state, -1, element.c_str() ); 199 float result = lua_type( m_state, -1 ) == LUA_TNUMBER ? (float)lua_tonumber( m_state, -1 ) : defval; 191 200 lua_pop( m_state, 1 ); 192 201 return result;
Note: See TracChangeset
for help on using the changeset viewer.