Changeset 288


Ignore:
Timestamp:
07/23/14 17:37:44 (11 years ago)
Author:
epyon
Message:
  • unified animation_entry class
  • virtuals removed from animation_entry
  • lua_table - added missing get_float
  • lua_table - fixed has_field
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/formats/md5_loader.hh

    r287 r288  
    7272                size_t get_num_joints() const { return m_num_joints; }
    7373                size_t get_frame_rate() const { return m_frame_rate; }
    74                 size_t get_frame_count() const { return m_num_frames; }
     74                float get_duration() const { return (float)m_num_frames; }
    7575
    7676        protected:
  • trunk/nv/gfx/keyframed_mesh.hh

    r287 r288  
    1616{
    1717
    18         class keyframed_animation_entry : public animation_entry
    19         {
    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 
    3618        class keyframed_mesh : public animated_mesh
    3719        {
     
    4325                virtual transform get_node_transform( uint32 node_id ) const;
    4426                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 );
    4727                virtual void update_animation( animation_entry*, uint32 a_anim_time );
    4828                virtual void update( program* a_program ) const;
    4929                virtual ~keyframed_mesh();
    5030        protected:
     31                virtual void set_frame( uint32 frame );
     32
    5133                struct vertex_pn
    5234                {
     
    6244                const mesh_nodes_data* m_tag_map;
    6345
    64                 uint32 m_start_frame;
    65                 uint32 m_stop_frame;
    6646                uint32 m_last_frame;
    6747                uint32 m_next_frame;
    68                 uint32 m_fps;
    6948                f32    m_interpolation;
    70                 bool   m_looping;
    7149                bool   m_active;
    7250
  • trunk/nv/gfx/skeletal_mesh.hh

    r287 r288  
    2323
    2424                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 ) {}
    2928                uint32 get_num_joints() const { return m_animation->get_num_joints();}
    3029                void update_skeleton( transform* tr, float time ) const { return m_animation->update_skeleton( tr, time );}
    3130        protected:
    3231                md5_animation* m_animation;
    33                 bool           m_looping;
    3432        };
    3533
     
    5654        {
    5755        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
    6270                void prepare( const mesh_nodes_data* bones );
    6371                void update_skeleton( mat4* tr, uint32 time ) const;
    6472                ~skeletal_animation_entry_gpu();
    6573        protected:
     74                void initialize();
    6675                void animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const;
     76
     77        protected:
    6778                const mesh_nodes_data* m_node_data;
    6879                std::vector< uint32 >* m_children;
     
    7081                mat4* m_offsets;
    7182                bool m_prepared;
    72                 bool m_looping;
    7383        };
    7484
  • trunk/nv/interface/animated_mesh.hh

    r287 r288  
    2525        {
    2626        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; }
    3235                virtual ~animation_entry() {}
    3336        protected:
    3437                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;
    3543        };
    3644
  • trunk/nv/lua/lua_state.hh

    r265 r288  
    228228                        unsigned get_unsigned( const std::string& element, unsigned defval = 0 );
    229229                        double get_double( const std::string& element, double defval = 0.0 );
     230                        float get_float( const std::string& element, float defval = 0.0 );
    230231                        bool get_boolean( const std::string& element, bool defval = false );
    231232
  • trunk/src/gfx/keyframed_mesh.cc

    r287 r288  
    1919        , m_mesh_data( a_data )
    2020        , m_tag_map( a_tag_map )
    21         , m_start_frame( false )
    22         , m_stop_frame( false )
    2321        , m_last_frame( 0 )
    2422        , m_next_frame( 0 )
    25         , m_fps( 0 )
    2623        , m_interpolation( 0.0f )
    27         , m_looping( false )
    2824        , m_active( false )
    2925{
     
    5652}
    5753
    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 
    7054void nv::keyframed_mesh::set_frame( uint32 frame )
    7155{
     
    7660}
    7761
    78 void nv::keyframed_mesh::update_animation( animation_entry*, uint32 a_anim_time )
     62void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_anim_time )
    7963{
    8064        if ( m_active )
    8165        {
    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 )
    8769                {
    88                         if ( m_looping )
     70                        if ( anim->is_looping() )
    8971                        {
    90                                 time = time % static_cast< uint32 >( f_max );
     72                                tick_time = fmodf( tick_time, duration );
    9173                        }
    9274                        else
    9375                        {
    9476                                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;
    9781                        }
    9882                }
    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() );
    10284                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 );
    10587        }
    10688}
     
    121103        if ( a_anim )
    122104        {
    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;
    126109        }
    127110        else
  • trunk/src/gfx/skeletal_mesh.cc

    r287 r288  
    3333                skeletal_animation_entry * anim = (skeletal_animation_entry*)a_anim;
    3434                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 );
    3838
    3939                //m_mesh_data->apply( m_transform.data() );
     
    8787}
    8888
    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 
     89void nv::skeletal_animation_entry_gpu::initialize()
     90{
    9691        m_prepared  = false;
    97         m_looping   = a_looping;
    9892        m_children  = nullptr;
    9993        m_offsets   = nullptr;
     94        uint32 node_count = m_node_data->get_count();
    10095        m_bone_ids  = new sint16[ node_count ];
    10196
  • trunk/src/lua/lua_state.cc

    r265 r288  
    148148{
    149149        lua_getfield( m_state, -1, element.c_str() );
    150         bool result = lua_isnil( m_state, -1 );
     150        bool result = !( lua_isnil( m_state, -1 ) );
    151151        lua_pop( m_state, 1 );
    152152        return result;
     
    189189        lua_getfield( m_state, -1, element.c_str() );
    190190        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
     196float 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;
    191200        lua_pop( m_state, 1 );
    192201        return result;
Note: See TracChangeset for help on using the changeset viewer.