Changeset 296


Ignore:
Timestamp:
07/31/14 08:08:31 (11 years ago)
Author:
epyon
Message:
  • lua::table_guard is_* utility functions
  • minor tweaks
Location:
trunk
Files:
8 edited

Legend:

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

    r294 r296  
    2626                virtual mat4 get_node_matrix( uint32 node_id ) const;
    2727                virtual void update_animation( animation_entry*, uint32 a_anim_time );
    28                 virtual void update( program* a_program ) const;
     28                virtual void update( program* a_program );
    2929                virtual ~keyframed_mesh();
    3030        protected:
     
    6767        {
    6868        public:
    69                 keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map, program* a_program );
     69                keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map );
    7070                void update( uint32 ms );
     71                virtual void update( program* a_program );
    7172        private:
    7273                int m_loc_next_position;
  • trunk/nv/gfx/skeletal_mesh.hh

    r289 r296  
    1616namespace nv
    1717{
    18 
    19         class skeletal_animation_entry : public animation_entry
     18        class skeletal_mesh : public animated_mesh
    2019        {
    2120        public:
    22                 skeletal_animation_entry( const std::string& name, const mesh_nodes_data* a_animation, bool a_looping )
     21                skeletal_mesh() : animated_mesh() {}
     22                virtual void run_animation( animation_entry* a_anim )
     23                {
     24                        update_animation( a_anim, 0 );
     25                }
     26        };
     27
     28        class skeletal_animation_entry_cpu : public animation_entry
     29        {
     30        public:
     31                skeletal_animation_entry_cpu( const std::string& name, const mesh_nodes_data* a_animation, bool a_looping )
    2332                        : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_node_data( a_animation ) {}
    24                 skeletal_animation_entry( const std::string& name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )
     33                skeletal_animation_entry_cpu( const std::string& name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping )
    2534                        : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_node_data( a_animation ) {}
    2635                void update_skeleton( transform* skeleton, float time ) const;
     
    2938        };
    3039
    31         class skeletal_mesh : public animated_mesh
     40        class skeletal_mesh_cpu : public skeletal_mesh
    3241        {
    3342        public:
    34                 skeletal_mesh( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones );
     43                skeletal_mesh_cpu( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones );
    3544                virtual size_t get_index_count() const { return m_indices; }
    36                 virtual void run_animation( animation_entry* a_anim );
    3745                virtual void update_animation( animation_entry* a_anim, uint32 a_anim_time );
    38                 virtual ~skeletal_mesh();
     46                virtual ~skeletal_mesh_cpu();
    3947        protected:
    4048                uint32                       m_indices;
     
    8088        };
    8189
    82         class skeletal_mesh_gpu : public animated_mesh
     90        class skeletal_mesh_gpu : public skeletal_mesh
    8391        {
    8492        public:
    8593                skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data );
    8694                virtual size_t get_index_count() const { return m_index_count; }
    87                 virtual void run_animation( animation_entry* a_anim );
    88                 virtual void update( program* a_program ) const;
     95                virtual void update( program* a_program );
    8996                virtual void update_animation( animation_entry* a_anim, uint32
    9097                        a_anim_time );
  • trunk/nv/interface/animated_mesh.hh

    r295 r296  
    2626        public:
    2727                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 ) {}
     28                m_start( a_start ), m_end( a_end ), m_duration( m_end - m_start ), m_material_idx(0) {}
    2929                const std::string& get_name() const { return m_name; }
    3030                uint32 get_frame_rate() const { return m_frame_rate; }
     
    4343                        m_frame_rate = rate;
    4444                }
     45                void set_material_idx( uint32 idx ) { m_material_idx = idx; }
     46                uint32 get_material_idx() const { return m_material_idx; }
    4547                virtual ~animation_entry() {}
    4648        protected:
     
    5153                float  m_end;
    5254                float  m_duration;
     55                uint32 m_material_idx;
    5356        };
    5457
  • trunk/nv/interface/context.hh

    r251 r296  
    3939                explicit mesh_interface( vertex_array* array ) : m_va( array ) {}
    4040                virtual void update( uint32 ) {}
    41                 virtual void update( program* ) const {}
     41                virtual void update( program* ) {}
    4242                virtual nv::vertex_array* get_vertex_array() const { return m_va; }
    4343                virtual size_t get_index_count() const { return 0; }
  • trunk/nv/lua/lua_state.hh

    r288 r296  
    230230                        float get_float( const std::string& element, float defval = 0.0 );
    231231                        bool get_boolean( const std::string& element, bool defval = false );
    232 
     232                        bool is_table( const std::string& element );
     233                        bool is_number( const std::string& element );
     234                        bool is_boolean( const std::string& element );
     235                        bool is_string( const std::string& element );
    233236                private:
    234237                        int m_level;
  • trunk/src/gfx/keyframed_mesh.cc

    r294 r296  
    9898
    9999
    100 void nv::keyframed_mesh::update( program* a_program ) const
     100void nv::keyframed_mesh::update( program* a_program )
    101101{
    102102        a_program->set_opt_uniform( "nv_interpolate", m_interpolation );
     
    123123}
    124124
    125 nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map, program* a_program )
     125nv::keyframed_mesh_gpu::keyframed_mesh_gpu( device* a_device, const mesh_data* a_data, const mesh_nodes_data* a_tag_map )
    126126        : keyframed_mesh( a_device, a_data, a_tag_map )
    127127        , m_loc_next_position( -1 )
     
    131131        , m_gpu_next_frame( 0xFFFFFFFF )
    132132{
    133         m_loc_next_position = a_program->get_attribute( "nv_next_position" )->get_location();
    134         m_loc_next_normal   = a_program->get_attribute( "nv_next_normal" )->get_location();
    135         m_loc_next_tangent  = a_program->try_get_attribute_location( "nv_next_tangent" );
    136133        m_va = a_device->create_vertex_array( a_data, STATIC_DRAW );
    137         vertex_buffer* vb = m_va->find_buffer( slot::POSITION );
    138         m_va->add_vertex_buffer( m_loc_next_position, vb, FLOAT, 3, 0, m_vsize, false );
    139         m_va->add_vertex_buffer( m_loc_next_normal,   vb, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
    140         if ( m_has_tangent )
    141                 m_va->add_vertex_buffer( m_loc_next_tangent, vb, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
    142134}
    143135
     
    145137void nv::keyframed_mesh_gpu::update( uint32 ms )
    146138{
     139        if ( m_loc_next_position == -1 ) return;
    147140        animated_mesh::update( ms );
    148141
     
    157150                m_gpu_last_frame = m_last_frame;
    158151        }
    159         if ( m_gpu_next_frame != m_next_frame )
     152        if ( m_loc_next_position != -1 && m_gpu_next_frame != m_next_frame )
    160153        {
    161154                m_va->update_vertex_buffer( m_loc_next_position, m_next_frame * m_vertex_count * m_vsize );
     
    164157                m_gpu_next_frame = m_next_frame;
    165158        }
     159}
     160
     161void nv::keyframed_mesh_gpu::update( program* a_program )
     162{
     163        if ( m_loc_next_position == -1 )
     164        {
     165                m_loc_next_position = a_program->get_attribute( "nv_next_position" )->get_location();
     166                m_loc_next_normal   = a_program->get_attribute( "nv_next_normal" )->get_location();
     167                if ( m_has_tangent )
     168                        m_loc_next_tangent  = a_program->get_attribute( "nv_next_tangent" )->get_location();
     169
     170                vertex_buffer* vb = m_va->find_buffer( slot::POSITION );
     171                m_va->add_vertex_buffer( m_loc_next_position, vb, FLOAT, 3, 0, m_vsize, false );
     172                m_va->add_vertex_buffer( m_loc_next_normal,   vb, FLOAT, 3, sizeof( vec3 ), m_vsize, false );
     173                if ( m_has_tangent )
     174                        m_va->add_vertex_buffer( m_loc_next_tangent, vb, FLOAT, 4, 2*sizeof( vec3 ), m_vsize, false );
     175        }
     176        keyframed_mesh::update( a_program );
    166177}
    167178
  • trunk/src/gfx/skeletal_mesh.cc

    r295 r296  
    1111
    1212
    13 nv::skeletal_mesh::skeletal_mesh( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
    14         : animated_mesh()
     13nv::skeletal_mesh_cpu::skeletal_mesh_cpu( device* a_device, const mesh_data* a_mesh_data, const mesh_nodes_data* bones )
     14        : skeletal_mesh()
    1515        , m_data( a_mesh_data )
    1616{
     
    2929}
    3030
    31 void nv::skeletal_mesh::update_animation( animation_entry* a_anim, uint32 a_anim_time )
     31void nv::skeletal_mesh_cpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )
    3232{
    3333        if ( a_anim )
    3434        {
    35                 skeletal_animation_entry * anim = (skeletal_animation_entry*)a_anim;
     35                skeletal_animation_entry_cpu * anim = (skeletal_animation_entry_cpu*)a_anim;
    3636                anim->update_skeleton( m_transform.data(), (float)a_anim_time );
    3737                {
     
    7070
    7171
    72 void nv::skeletal_animation_entry::update_skeleton( transform* skeleton, float time ) const
     72void nv::skeletal_animation_entry_cpu::update_skeleton( transform* skeleton, float time ) const
    7373{
    7474        float frame_duration = 1000.f / (float)m_node_data->get_frame_rate();
     
    8585
    8686
    87 nv::skeletal_mesh::~skeletal_mesh()
     87nv::skeletal_mesh_cpu::~skeletal_mesh_cpu()
    8888{
    8989        delete m_va;
    90 }
    91 
    92 void nv::skeletal_mesh::run_animation( animation_entry* a_anim )
    93 {
    94         if ( a_anim != nullptr )
    95         {
    96                 update_animation( a_anim, 0 );
    97         }
    9890}
    9991
     
    209201
    210202nv::skeletal_mesh_gpu::skeletal_mesh_gpu( device* a_device, const mesh_data* a_mesh, const mesh_nodes_data* a_bone_data )
    211         : animated_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr )
     203        : skeletal_mesh(), m_bone_data( a_bone_data ), m_transform( nullptr )
    212204{
    213205        m_va          = a_device->create_vertex_array( a_mesh, nv::STATIC_DRAW );
     
    219211}
    220212
    221 void nv::skeletal_mesh_gpu::run_animation( animation_entry* a_anim )
    222 {
    223         if ( m_bone_data && a_anim != nullptr )
    224         {
    225                 skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)(a_anim);
     213void nv::skeletal_mesh_gpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )
     214{
     215        if ( m_bone_data && a_anim )
     216        {
     217                skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)a_anim;
    226218                anim->prepare( m_bone_data );
    227                 update_animation( a_anim, 0 );
    228         }
    229 }
    230 
    231 void nv::skeletal_mesh_gpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )
    232 {
    233         if ( m_bone_data && a_anim )
    234         {
    235                 skeletal_animation_entry_gpu * anim = (skeletal_animation_entry_gpu*)a_anim;
    236219                anim->update_skeleton( m_transform, a_anim_time );
    237220        }
    238221}
    239222
    240 void nv::skeletal_mesh_gpu::update( program* a_program ) const
     223void nv::skeletal_mesh_gpu::update( program* a_program )
    241224{
    242225        if ( m_bone_data )
  • trunk/src/lua/lua_state.cc

    r288 r296  
    209209        return result;
    210210}
     211
     212bool nv::lua::table_guard::is_table( const std::string& element )
     213{
     214        lua_getfield( m_state, -1, element.c_str() );
     215        bool result = lua_type( m_state, -1 ) == LUA_TTABLE;
     216        lua_pop( m_state, 1 );
     217        return result;
     218}
     219
     220bool nv::lua::table_guard::is_number( const std::string& element )
     221{
     222        lua_getfield( m_state, -1, element.c_str() );
     223        bool result = lua_type( m_state, -1 ) == LUA_TNUMBER;
     224        lua_pop( m_state, 1 );
     225        return result;
     226}
     227
     228bool nv::lua::table_guard::is_boolean( const std::string& element )
     229{
     230        lua_getfield( m_state, -1, element.c_str() );
     231        bool result = lua_type( m_state, -1 ) == LUA_TBOOLEAN;
     232        lua_pop( m_state, 1 );
     233        return result;
     234}
     235
     236bool nv::lua::table_guard::is_string( const std::string& element )
     237{
     238        lua_getfield( m_state, -1, element.c_str() );
     239        bool result = lua_type( m_state, -1 ) == LUA_TSTRING;
     240        lua_pop( m_state, 1 );
     241        return result;
     242}
     243
    211244
    212245// state
Note: See TracChangeset for help on using the changeset viewer.