Changeset 283


Ignore:
Timestamp:
07/10/14 20:58:27 (11 years ago)
Author:
epyon
Message:
  • Nova Model Data format loader added
  • keyframed mesh and skeletal mesh don't store time info anymore
  • NMD loader has a temporary utility class for fast usage
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gfx/keyframed_mesh.hh

    r280 r283  
    4444                virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );
    4545                virtual void set_frame( uint32 frame );
    46                 virtual void update( uint32 ms );
     46                virtual void update_animation( animation_entry*, uint32 a_anim_time );
    4747                virtual void update( program* a_program ) const;
    4848                virtual ~keyframed_mesh();
     
    6565                uint32 m_last_frame;
    6666                uint32 m_next_frame;
    67                 uint32 m_time;
    6867                uint32 m_fps;
    6968                f32    m_interpolation;
  • trunk/nv/gfx/skeletal_mesh.hh

    r275 r283  
    1212#include <nv/interface/animated_mesh.hh>
    1313#include <nv/formats/md5_loader.hh>
     14#include <nv/formats/nmd_loader.hh>
    1415
    1516namespace nv
     
    2627                virtual uint32 get_frame_count() const { return m_animation->get_frame_count(); }
    2728                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 );}
    2831        protected:
    2932                md5_animation* m_animation;
     
    3134        };
    3235
    33         // TODO: INSTANCING! currently md5_mesh data is deleted!
    3436        class skeletal_mesh : public animated_mesh
    3537        {
     
    3840                virtual size_t get_index_count() const { return m_mesh_data->get_index_count(); }
    3941                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 );
    4243                virtual ~skeletal_mesh();
    4344        protected:
    4445                md5_mesh_instance* m_mesh_data;
    45                 md5_animation*     m_animation;
     46                std::vector< transform > m_transform;
     47        };
    4648
    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;
    4979        };
    5080
  • trunk/nv/interface/animated_mesh.hh

    r231 r283  
    3939        public:
    4040                animated_mesh() {}
     41                virtual void update_animation( animation_entry*, uint32 ) {}
    4142                virtual void run_animation( animation_entry* ) {}
    4243                virtual transform get_tag( const std::string& ) const { return transform(); }
  • trunk/src/gfx/keyframed_mesh.cc

    r282 r283  
    2323        , m_last_frame( 0 )
    2424        , m_next_frame( 0 )
    25         , m_time( 0 )
    2625        , m_fps( 0 )
    2726        , m_interpolation( 0.0f )
     
    5655        m_fps           = fps;
    5756        m_active        = count > 1;
    58         m_time          = 0;
    5957        m_last_frame    = start;
    6058        m_next_frame    = (count > 1 ? start + 1 : start );
     
    7068}
    7169
    72 void keyframed_mesh::update( uint32 ms )
     70void nv::keyframed_mesh::update_animation( animation_entry*, uint32 a_anim_time )
    7371{
    7472        if ( m_active )
    7573        {
    76                 m_time += ms;
    7774                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;
    7976                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 )
    9079                {
    9180                        if ( m_looping )
    9281                        {
    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 );
    9683                        }
    9784                        else
     
    10289                        }
    10390                }
     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;
    10496                m_interpolation = f_pos - glm::floor( f_pos );
    10597        }
    10698}
     99
    107100
    108101void nv::keyframed_mesh::update( program* a_program ) const
     
    148141void nv::keyframed_mesh_gpu::update( uint32 ms )
    149142{
    150         keyframed_mesh::update( ms );
     143        animated_mesh::update( ms );
    151144
    152145        if ( m_gpu_last_frame != m_last_frame )
     
    181174void nv::keyframed_mesh_cpu::update( uint32 ms )
    182175{
    183         keyframed_mesh::update( ms );
     176        animated_mesh::update( ms );
    184177
    185178        const vertex_pn* data = m_mesh_data->get_channel_data<vertex_pn>();
  • trunk/src/gfx/skeletal_mesh.cc

    r281 r283  
    1414        : animated_mesh()
    1515        , m_mesh_data( nullptr )
    16         , m_animation( nullptr )
    17         , m_animation_time( 0 )
    1816{
    1917        m_mesh_data = a_mesh_data->spawn();
     
    2119}
    2220
    23 
    24 void nv::skeletal_mesh::setup_animation( md5_animation* a_anim )
     21void nv::skeletal_mesh::update_animation( animation_entry* a_anim, uint32 a_anim_time )
    2522{
    26         m_animation      = a_anim;
    27         m_animation_time = 0;
    28         if ( m_animation )
     23        if ( a_anim )
    2924        {
    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 );
    4430                m_mesh_data->apply( m_transform.data() );
    4531                vertex_buffer* vb = m_va->find_buffer( nv::slot::POSITION );
     
    6046        if ( a_anim != nullptr )
    6147        {
    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 );
    6851        }
    6952}
     53
     54void nv::skeletal_animation_entry_gpu::update_skeleton( mat4* data, uint32 time )
     55{
     56        m_animation->animate( data, time );
     57}
     58
     59void nv::skeletal_animation_entry_gpu::prepare( const nmd_temp_model* m_model )
     60{
     61        m_animation->prepare( m_model );
     62}
     63
     64nv::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
     72void 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
     83void 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
     92void 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.