Changeset 230


Ignore:
Timestamp:
05/06/14 12:39:51 (11 years ago)
Author:
epyon
Message:
  • animated_mesh, scene_node, camera and transform classes added
  • order in mesh hierarchies
  • simplified and generified animation class hierarchy
Location:
trunk
Files:
7 added
7 edited

Legend:

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

    r228 r230  
    1717#include <unordered_map>
    1818#include <vector>
     19#include <nv/transform.hh>
    1920#include <nv/gfx/mesh_data.hh>
    2021#include <nv/interface/mesh_loader.hh>
     
    2627        {
    2728                std::string name;
    28                 mat4 transform;
     29                transform   trans;
    2930        };
    3031
     
    4041
    4142                virtual const md3_tag* get_tag( const std::string& name ) const;
    42                 virtual mat4 get_tag( sint32 frame, const std::string& name ) const;
     43                virtual transform get_tag( sint32 frame, const std::string& name ) const;
    4344                size_t get_max_frames() const;
    4445                void load_tag_names( std::vector< std::string >& tags );
    45                 void load_tags( std::vector<mat4>& t, const std::string& tag );
     46                void load_tags( std::vector<transform>& t, const std::string& tag );
    4647                void load_positions( std::vector<vec3>& p, sint32 frame =-1 );
    4748                void load_normals( std::vector<vec3>& n, sint32 frame =-1 );
  • trunk/nv/gfx/keyframed_mesh.hh

    r224 r230  
    1010#include <nv/common.hh>
    1111#include <nv/interface/context.hh>
     12#include <nv/interface/animated_mesh.hh>
    1213#include <nv/formats/md3_loader.hh>
    1314
     
    1516{
    1617
    17         class keyframed_mesh
     18        class keyframed_animation_entry : public animation_entry
    1819        {
    1920        public:
    20                 keyframed_mesh( context* a_context, mesh_data* a_data, program* a_program );
     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 uint32 get_frame_count() const { return 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        class keyframed_mesh : public animated_mesh
     37        {
     38        public:
     39                keyframed_mesh( context* a_context, mesh_data* a_data );
     40                virtual size_t get_index_count() const { return m_data->get_index_count(); }
     41                virtual void run_animation( animation_entry* a_anim );
    2142                size_t get_max_frames() const;
    22                 mat4 get_tag( const std::string& tag ) const;
     43                transform get_tag( const std::string& tag ) const;
    2344                virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop );
    2445                virtual void set_frame( uint32 frame );
    2546                virtual void update( uint32 ms );
    26                 virtual void draw( render_state& rstate );
    27                 program* get_program() { return m_program; }
     47                virtual void update( program* a_program );
    2848                virtual ~keyframed_mesh();
    2949        protected:
    30                 context*      m_context;
    3150                mesh_data*    m_data;
    32                 program*      m_program;
    33                 vertex_array* m_va;
    3451
    3552                uint32 m_start_frame;
     
    4966        public:
    5067                keyframed_mesh_gpu( context* a_context, mesh_data* a_data, program* a_program );
    51                 void draw( render_state& rstate );
     68                void update( uint32 ms );
    5269        private:
    5370                int m_loc_next_position;
     
    6178        {
    6279        public:
    63                 keyframed_mesh_cpu( context* a_context, mesh_data* a_data, program* a_program );
     80                keyframed_mesh_cpu( context* a_context, mesh_data* a_data );
    6481                void update( uint32 ms );
    6582        private:
  • trunk/nv/gfx/mesh_data.hh

    r224 r230  
    1111#include <unordered_map>
    1212#include <vector>
     13#include <nv/math.hh>
     14#include <nv/transform.hh>
    1315#include <nv/interface/device.hh>
    14 #include <nv/math.hh>
    1516
    1617namespace nv
     
    2021        public:
    2122                friend class mesh_data_creator;
    22                 typedef std::vector< mat4 > transforms;
     23                typedef std::vector< transform > transforms;
    2324                typedef std::unordered_map< std::string, transforms > tag_map;
    2425
  • trunk/nv/gfx/skeletal_mesh.hh

    r227 r230  
    1010#include <nv/common.hh>
    1111#include <nv/interface/context.hh>
     12#include <nv/interface/animated_mesh.hh>
    1213#include <nv/formats/md5_loader.hh>
    1314
     
    1516{
    1617
    17         class skeletal_mesh
     18        class skeletal_animation_entry : public animation_entry
    1819        {
    1920        public:
    20                 skeletal_mesh( context* a_context, program* a_program, md5_loader* a_loader );
     21                friend class skeletal_mesh;
     22
     23                skeletal_animation_entry( const std::string& name, md5_animation* a_animation, bool a_looping )
     24                        : animation_entry( name ), m_animation( a_animation ), m_looping( a_looping ) {}
     25                virtual uint32 get_frame_rate() const { return m_animation->get_frame_rate(); }
     26                virtual uint32 get_frame_count() const { return m_animation->get_frame_count(); }
     27                virtual bool is_looping() const { return m_looping; }
     28        protected:
     29                md5_animation* m_animation;
     30                bool           m_looping;
     31        };
     32
     33        class skeletal_mesh : public animated_mesh
     34        {
     35        public:
     36                skeletal_mesh( context* a_context, md5_loader* a_loader );
     37                virtual size_t get_index_count() const { return m_data->get_index_count(0); }
     38                virtual void run_animation( animation_entry* a_anim );
    2139                virtual void setup_animation( md5_animation* a_anim );
    2240                virtual void update( uint32 ms );
    23                 virtual void draw( render_state& rstate );
    24                 program* get_program() { return m_program; }
    2541                virtual ~skeletal_mesh();
    2642        protected:
    27                 context*      m_context;
    28                 program*      m_program;
    29                 vertex_array* m_va;
    30 
    3143                vertex_buffer* m_vb_position;
    3244                vertex_buffer* m_vb_normal;
     
    3547                md5_loader*    m_data;
    3648                md5_animation* m_animation;
    37 
    38                 uint32 m_start_frame;
    39                 uint32 m_stop_frame;
    40                 uint32 m_last_frame;
    41                 uint32 m_next_frame;
    42                 uint32 m_time;
    43                 uint32 m_fps;
    44                 f32    m_interpolation;
    45                 bool   m_looping;
    46                 bool   m_active;
    4749        };
    4850
  • trunk/src/formats/md3_loader.cc

    r224 r230  
    328328*/
    329329
    330 void nv::md3_loader::load_tags( std::vector<mat4>& t, const std::string& tag )
     330void nv::md3_loader::load_tags( std::vector<transform>& t, const std::string& tag )
    331331{
    332332        md3_t* md3 = (md3_t*)m_md3;
     
    340340                        if (rname == tag)
    341341                        {
    342                                 vec4 axisx     = vec4( md3_vec3( rtag.axis[0] ), 0.0 );
    343                                 vec4 axisz     = vec4( md3_vec3( rtag.axis[1] ), 0.0 );
    344                                 vec4 axisy     = vec4( md3_vec3( rtag.axis[2] ), 0.0 );
    345                                 vec4 origin    = vec4( md3_vec3( rtag.origin ),  1.0 );
    346                                 t.emplace_back( axisx, axisy, axisz, origin );
     342                                vec3 axisx  ( md3_vec3( rtag.axis[0] ) );
     343                                vec3 axisz  ( md3_vec3( rtag.axis[1] ) );
     344                                vec3 axisy  ( md3_vec3( rtag.axis[2] ) );
     345                                vec3 origin ( md3_vec3( rtag.origin ) );
     346                                t.emplace_back( origin, quat( mat3( axisx, axisy, axisz ) ) );
    347347                        }
    348348                }
     
    406406}
    407407
    408 mat4 md3_loader::get_tag( sint32 frame, const std::string& name ) const
     408transform md3_loader::get_tag( sint32 frame, const std::string& name ) const
    409409{
    410410        md3_t* md3 = (md3_t*)m_md3;
     
    415415                if (rname == name)
    416416                {
    417                         vec4 axisx     = vec4( md3_vec3( rtag.axis[0] ), 0.0 );
    418                         vec4 axisz     = vec4( md3_vec3( rtag.axis[1] ), 0.0 );
    419                         vec4 axisy     = vec4( md3_vec3( rtag.axis[2] ), 0.0 );
    420                         vec4 origin    = vec4( md3_vec3( rtag.origin ),  1.0 );
    421                         return glm::mat4( axisx, axisy, axisz, origin );
    422                 }
    423         }
    424         return glm::mat4();
     417                        vec3 axisx ( md3_vec3( rtag.axis[0] ) );
     418                        vec3 axisz ( md3_vec3( rtag.axis[1] ) );
     419                        vec3 axisy ( md3_vec3( rtag.axis[2] ) );
     420                        vec3 origin( md3_vec3( rtag.origin ) );
     421                        return transform( origin, quat( mat3( axisx, axisy, axisz ) ) );
     422                }
     423        }
     424        return transform();
    425425}
    426426
  • trunk/src/gfx/keyframed_mesh.cc

    r224 r230  
    1515using namespace nv;
    1616
    17 keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data, program* a_program )
    18         : m_context( a_context )
     17keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data )
     18        : animated_mesh( a_context )
    1919        , m_data( a_data )
    20         , m_program( a_program )
    21         , m_va( nullptr )
    2220        , m_start_frame( false )
    2321        , m_stop_frame( false )
     
    3836}
    3937
    40 mat4 keyframed_mesh::get_tag( const std::string& tag ) const
    41 {
    42         const std::vector< nv::mat4 >& transforms = m_data->get_tag_map().at( tag );
    43         return glm::interpolate( transforms[ m_last_frame ], transforms[ m_next_frame ], m_interpolation );
     38transform keyframed_mesh::get_tag( const std::string& tag ) const
     39{
     40        const std::vector< transform >& transforms = m_data->get_tag_map().at( tag );
     41        return interpolate( transforms[ m_last_frame ], transforms[ m_next_frame ], m_interpolation );
    4442}
    4543
     
    10199}
    102100
    103 void nv::keyframed_mesh::draw( render_state& rstate )
    104 {
    105         m_program->set_opt_uniform( "nv_interpolate", m_interpolation );
    106         m_context->draw( nv::TRIANGLES, rstate, m_program, m_va, m_data->get_index_count() );
     101void nv::keyframed_mesh::update( program* a_program )
     102{
     103        a_program->set_opt_uniform( "nv_interpolate", m_interpolation );
    107104}
    108105
     
    112109}
    113110
     111void nv::keyframed_mesh::run_animation( animation_entry* a_anim )
     112{
     113        keyframed_animation_entry * anim = down_cast<keyframed_animation_entry>(a_anim);
     114        setup_animation( anim->m_start, anim->m_frames, anim->m_fps, anim->m_looping );
     115}
     116
    114117keyframed_mesh_gpu::keyframed_mesh_gpu( context* a_context, mesh_data* a_data, program* a_program )
    115         : keyframed_mesh( a_context, a_data, a_program )
     118        : keyframed_mesh( a_context, a_data )
    116119        , m_loc_next_position( 0 )
    117120        , m_loc_next_normal( 0 )
     
    120123{
    121124        nv::vertex_buffer* vb;
    122         m_loc_next_position = m_program->get_attribute( "nv_next_position" )->get_location();
    123         m_loc_next_normal   = m_program->get_attribute( "nv_next_normal" )->get_location();
     125        m_loc_next_position = a_program->get_attribute( "nv_next_position" )->get_location();
     126        m_loc_next_normal   = a_program->get_attribute( "nv_next_normal" )->get_location();
    124127
    125128        vb = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ) * m_data->get_frame_count(), (void*)m_data->get_positions().data() );
     
    137140}
    138141
    139 void nv::keyframed_mesh_gpu::draw( render_state& rstate )
    140 {
     142void nv::keyframed_mesh_gpu::update( uint32 ms )
     143{
     144        keyframed_mesh::update( ms );
     145
    141146        size_t vtx_count = m_data->get_vertex_count();
    142147        if ( m_gpu_last_frame != m_last_frame )
     
    152157                m_gpu_next_frame = m_next_frame;
    153158        }
    154         keyframed_mesh::draw( rstate );
    155 }
    156 
    157 
    158 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data* a_data, program* a_program )
    159         : keyframed_mesh( a_context, a_data, a_program )
     159}
     160
     161
     162nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data* a_data )
     163        : keyframed_mesh( a_context, a_data )
    160164{
    161165        m_vb_position = m_context->get_device()->create_vertex_buffer( nv::STATIC_DRAW, m_data->get_vertex_count() * sizeof( nv::vec3 ), (void*)m_data->get_position_frame(0) );
  • trunk/src/gfx/skeletal_mesh.cc

    r227 r230  
    1111
    1212
    13 nv::skeletal_mesh::skeletal_mesh( context* a_context, program* a_program, md5_loader* a_loader )
    14         : m_context( a_context )
    15         , m_program( a_program )
    16         , m_va( nullptr )
     13nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_loader* a_loader )
     14        : animated_mesh( a_context )
    1715        , m_data( a_loader )
    1816        , m_animation( nullptr )
     
    3836        if ( m_animation ) m_animation->reset_animation();
    3937        m_animation = a_anim;
     38        // TODO : INSTANCE!
    4039        m_animation->reset_animation();
    4140}
     
    6463}
    6564
    66 void nv::skeletal_mesh::draw( render_state& rstate )
    67 {
    68         m_context->draw( nv::TRIANGLES, rstate, m_program, m_va, m_data->get_index_count(0) );
    69 }
    70 
    7165nv::skeletal_mesh::~skeletal_mesh()
    7266{
    7367        delete m_va;
    7468}
     69
     70void nv::skeletal_mesh::run_animation( animation_entry* a_anim )
     71{
     72        skeletal_animation_entry * anim = down_cast<skeletal_animation_entry>(a_anim);
     73        // TODO : INSTANCE!
     74        setup_animation( anim->m_animation );
     75}
Note: See TracChangeset for help on using the changeset viewer.