Changeset 230
- Timestamp:
- 05/06/14 12:39:51 (11 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/md3_loader.hh
r228 r230 17 17 #include <unordered_map> 18 18 #include <vector> 19 #include <nv/transform.hh> 19 20 #include <nv/gfx/mesh_data.hh> 20 21 #include <nv/interface/mesh_loader.hh> … … 26 27 { 27 28 std::string name; 28 mat4 transform;29 transform trans; 29 30 }; 30 31 … … 40 41 41 42 virtual const md3_tag* get_tag( const std::string& name ) const; 42 virtual mat4get_tag( sint32 frame, const std::string& name ) const;43 virtual transform get_tag( sint32 frame, const std::string& name ) const; 43 44 size_t get_max_frames() const; 44 45 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 ); 46 47 void load_positions( std::vector<vec3>& p, sint32 frame =-1 ); 47 48 void load_normals( std::vector<vec3>& n, sint32 frame =-1 ); -
trunk/nv/gfx/keyframed_mesh.hh
r224 r230 10 10 #include <nv/common.hh> 11 11 #include <nv/interface/context.hh> 12 #include <nv/interface/animated_mesh.hh> 12 13 #include <nv/formats/md3_loader.hh> 13 14 … … 15 16 { 16 17 17 class keyframed_ mesh18 class keyframed_animation_entry : public animation_entry 18 19 { 19 20 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 ); 21 42 size_t get_max_frames() const; 22 mat4get_tag( const std::string& tag ) const;43 transform get_tag( const std::string& tag ) const; 23 44 virtual void setup_animation( uint32 start, uint32 count, uint32 fps, bool loop ); 24 45 virtual void set_frame( uint32 frame ); 25 46 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 ); 28 48 virtual ~keyframed_mesh(); 29 49 protected: 30 context* m_context;31 50 mesh_data* m_data; 32 program* m_program;33 vertex_array* m_va;34 51 35 52 uint32 m_start_frame; … … 49 66 public: 50 67 keyframed_mesh_gpu( context* a_context, mesh_data* a_data, program* a_program ); 51 void draw( render_state& rstate);68 void update( uint32 ms ); 52 69 private: 53 70 int m_loc_next_position; … … 61 78 { 62 79 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 ); 64 81 void update( uint32 ms ); 65 82 private: -
trunk/nv/gfx/mesh_data.hh
r224 r230 11 11 #include <unordered_map> 12 12 #include <vector> 13 #include <nv/math.hh> 14 #include <nv/transform.hh> 13 15 #include <nv/interface/device.hh> 14 #include <nv/math.hh>15 16 16 17 namespace nv … … 20 21 public: 21 22 friend class mesh_data_creator; 22 typedef std::vector< mat4> transforms;23 typedef std::vector< transform > transforms; 23 24 typedef std::unordered_map< std::string, transforms > tag_map; 24 25 -
trunk/nv/gfx/skeletal_mesh.hh
r227 r230 10 10 #include <nv/common.hh> 11 11 #include <nv/interface/context.hh> 12 #include <nv/interface/animated_mesh.hh> 12 13 #include <nv/formats/md5_loader.hh> 13 14 … … 15 16 { 16 17 17 class skeletal_ mesh18 class skeletal_animation_entry : public animation_entry 18 19 { 19 20 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 ); 21 39 virtual void setup_animation( md5_animation* a_anim ); 22 40 virtual void update( uint32 ms ); 23 virtual void draw( render_state& rstate );24 program* get_program() { return m_program; }25 41 virtual ~skeletal_mesh(); 26 42 protected: 27 context* m_context;28 program* m_program;29 vertex_array* m_va;30 31 43 vertex_buffer* m_vb_position; 32 44 vertex_buffer* m_vb_normal; … … 35 47 md5_loader* m_data; 36 48 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;47 49 }; 48 50 -
trunk/src/formats/md3_loader.cc
r224 r230 328 328 */ 329 329 330 void nv::md3_loader::load_tags( std::vector< mat4>& t, const std::string& tag )330 void nv::md3_loader::load_tags( std::vector<transform>& t, const std::string& tag ) 331 331 { 332 332 md3_t* md3 = (md3_t*)m_md3; … … 340 340 if (rname == tag) 341 341 { 342 vec 4 axisx = vec4( md3_vec3( rtag.axis[0] ), 0.0);343 vec 4 axisz = vec4( md3_vec3( rtag.axis[1] ), 0.0);344 vec 4 axisy = vec4( md3_vec3( rtag.axis[2] ), 0.0);345 vec 4 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 ) ) ); 347 347 } 348 348 } … … 406 406 } 407 407 408 mat4md3_loader::get_tag( sint32 frame, const std::string& name ) const408 transform md3_loader::get_tag( sint32 frame, const std::string& name ) const 409 409 { 410 410 md3_t* md3 = (md3_t*)m_md3; … … 415 415 if (rname == name) 416 416 { 417 vec 4 axisx = vec4( md3_vec3( rtag.axis[0] ), 0.0);418 vec 4 axisz = vec4( md3_vec3( rtag.axis[1] ), 0.0);419 vec 4 axisy = vec4( md3_vec3( rtag.axis[2] ), 0.0);420 vec 4 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(); 425 425 } 426 426 -
trunk/src/gfx/keyframed_mesh.cc
r224 r230 15 15 using namespace nv; 16 16 17 keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data , program* a_program)18 : m_context( a_context )17 keyframed_mesh::keyframed_mesh( context* a_context, mesh_data* a_data ) 18 : animated_mesh( a_context ) 19 19 , m_data( a_data ) 20 , m_program( a_program )21 , m_va( nullptr )22 20 , m_start_frame( false ) 23 21 , m_stop_frame( false ) … … 38 36 } 39 37 40 mat4keyframed_mesh::get_tag( const std::string& tag ) const41 { 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 );38 transform 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 ); 44 42 } 45 43 … … 101 99 } 102 100 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() ); 101 void nv::keyframed_mesh::update( program* a_program ) 102 { 103 a_program->set_opt_uniform( "nv_interpolate", m_interpolation ); 107 104 } 108 105 … … 112 109 } 113 110 111 void 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 114 117 keyframed_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 ) 116 119 , m_loc_next_position( 0 ) 117 120 , m_loc_next_normal( 0 ) … … 120 123 { 121 124 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(); 124 127 125 128 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() ); … … 137 140 } 138 141 139 void nv::keyframed_mesh_gpu::draw( render_state& rstate ) 140 { 142 void nv::keyframed_mesh_gpu::update( uint32 ms ) 143 { 144 keyframed_mesh::update( ms ); 145 141 146 size_t vtx_count = m_data->get_vertex_count(); 142 147 if ( m_gpu_last_frame != m_last_frame ) … … 152 157 m_gpu_next_frame = m_next_frame; 153 158 } 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 162 nv::keyframed_mesh_cpu::keyframed_mesh_cpu( context* a_context, mesh_data* a_data ) 163 : keyframed_mesh( a_context, a_data ) 160 164 { 161 165 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 11 11 12 12 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 ) 13 nv::skeletal_mesh::skeletal_mesh( context* a_context, md5_loader* a_loader ) 14 : animated_mesh( a_context ) 17 15 , m_data( a_loader ) 18 16 , m_animation( nullptr ) … … 38 36 if ( m_animation ) m_animation->reset_animation(); 39 37 m_animation = a_anim; 38 // TODO : INSTANCE! 40 39 m_animation->reset_animation(); 41 40 } … … 64 63 } 65 64 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 71 65 nv::skeletal_mesh::~skeletal_mesh() 72 66 { 73 67 delete m_va; 74 68 } 69 70 void 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.