- Timestamp:
- 09/08/15 18:40:48 (10 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gfx/skeletal_mesh.hh
r441 r467 17 17 { 18 18 19 // TODO: remove or make generic 20 struct md5_vtx_pnt 21 { 22 vec3 position; 23 vec3 normal; 24 vec3 tangent; 25 }; 26 27 // TODO: remove or make generic 28 struct md5_key_t 29 { 30 transform tform; 31 }; 32 33 // TODO: remove or make generic 34 struct md5_vtx_t 35 { 36 vec2 texcoord; 37 }; 38 39 // TODO: remove or make generic 40 struct md5_vtx_pntiw 41 { 42 vec3 position; 43 vec3 normal; 44 vec3 tangent; 45 ivec4 boneindex; 46 vec4 boneweight; 47 }; 48 49 50 class skeletal_mesh : public animated_mesh 51 { 52 public: 53 skeletal_mesh( context* a_context ) : animated_mesh(), m_context( a_context ) {} 54 virtual vertex_array get_vertex_array() const { return m_va; } 55 virtual void run_animation( animation_entry* a_anim ) 56 { 57 update_animation( a_anim, 0 ); 58 } 59 ~skeletal_mesh() 60 { 61 m_context->release( m_va ); 62 } 63 protected: 64 vertex_array m_va; 65 context* m_context; 66 data_descriptor m_interpolation_key; 67 }; 68 69 class skeletal_animation_entry_cpu : public animation_entry 70 { 71 public: 72 skeletal_animation_entry_cpu( shash64 name, const mesh_nodes_data* a_animation, bool a_looping ) 73 : animation_entry( name, a_looping, a_animation->get_frame_rate(), 0.0f, a_animation->get_duration() ), m_node_data( a_animation ) 74 { 75 initialize(); 76 } 77 skeletal_animation_entry_cpu( shash64 name, mesh_nodes_data* a_animation, float time_start, float time_end, bool a_looping ) 78 : animation_entry( name, a_looping, a_animation->get_frame_rate(), time_start, time_end ), m_node_data( a_animation ) 79 { 80 initialize(); 81 } 82 void initialize(); 83 void update_skeleton( transform* skeleton, float time ) const; 84 protected: 85 const mesh_nodes_data* m_node_data; 86 data_descriptor m_interpolation_key; 87 }; 88 89 class skeletal_mesh_cpu : public skeletal_mesh 90 { 91 public: 92 skeletal_mesh_cpu( context* a_context, const data_channel_set* a_mesh_data, const mesh_nodes_data* bones ); 93 virtual size_t get_index_count() const { return m_indices; } 94 virtual void update_animation( animation_entry* a_anim, uint32 a_anim_time ); 95 protected: 96 buffer m_pbuffer; 97 uint32 m_indices; 98 dynamic_array< md5_vtx_pnt > m_pntdata; 99 dynamic_array< transform > m_pos_offset; 100 dynamic_array< transform > m_bone_offset; 101 102 const md5_vtx_pntiw* m_vtx_data; 103 dynamic_array< transform > m_transform; 104 }; 105 106 class skeletal_animation_entry_gpu : public animation_entry 19 class skeletal_animation_entry : public animation_entry 107 20 { 108 21 public: 109 skeletal_animation_entry _gpu( shash64 name, const mesh_nodes_data* anim, bool a_looping )22 skeletal_animation_entry( shash64 name, const mesh_nodes_data* anim, bool a_looping ) 110 23 : animation_entry( name, a_looping, anim->get_frame_rate(), 0.0f, anim->get_duration() ) 111 24 , m_node_data( anim ) … … 114 27 } 115 28 116 skeletal_animation_entry _gpu( shash64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping )29 skeletal_animation_entry( shash64 name, const mesh_nodes_data* anim, float time_start, float time_end, bool a_looping ) 117 30 : animation_entry( name, a_looping, anim->get_frame_rate(), time_start, time_end ) 118 31 , m_node_data( anim ) … … 123 36 void prepare( const mesh_nodes_data* bones ); 124 37 void update_skeleton( mat4* tr, uint32 time ) const; 125 ~skeletal_animation_entry _gpu();38 ~skeletal_animation_entry(); 126 39 protected: 127 40 void initialize(); … … 137 50 }; 138 51 139 class skeletal_mesh _gpu : public skeletal_mesh52 class skeletal_mesh : public animated_mesh 140 53 { 141 54 public: 142 skeletal_mesh_gpu( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data ); 55 skeletal_mesh( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data ); 56 virtual vertex_array get_vertex_array() const { return m_va; } 143 57 virtual size_t get_index_count() const { return m_index_count; } 58 virtual void run_animation( animation_entry* a_anim ) 59 { 60 update_animation( a_anim, 0 ); 61 } 144 62 virtual void update( program a_program ); 145 63 virtual void update_animation( animation_entry* a_anim, uint32 … … 147 65 virtual transform get_node_transform( uint32 node_id ) const; 148 66 virtual mat4 get_node_matrix( uint32 node_id ) const; 149 ~skeletal_mesh_gpu() { delete[] m_transform; } 67 ~skeletal_mesh() 68 { 69 m_context->release( m_va ); 70 delete[] m_transform; 71 } 150 72 protected: 73 vertex_array m_va; 74 context* m_context; 75 data_descriptor m_interpolation_key; 151 76 const mesh_nodes_data* m_bone_data; 152 77 uint32 m_index_count; -
trunk/nv/stl/string.hh
r440 r467 130 130 typedef string_hash< uint32 > shash32; 131 131 typedef string_hash< uint64 > shash64; 132 133 constexpr shash32 operator "" _sh32( const char* str, size_t len ) 134 { 135 return shash32( detail::fnv_hash< uint32 >::hash( str, len ) ); 136 } 137 138 constexpr shash64 operator "" _sh64( const char* str, size_t len ) 139 { 140 return shash64( detail::fnv_hash< uint64 >::hash( str, len ) ); 141 } 132 142 } 133 143 144 using nv::operator "" _sh32; 145 using nv::operator "" _sh64; 146 134 147 #endif // NV_STL_STRING_HH -
trunk/src/gfx/skeletal_mesh.cc
r458 r467 11 11 #include "nv/stl/unordered_map.hh" 12 12 13 nv::skeletal_mesh_cpu::skeletal_mesh_cpu( context* a_context, const data_channel_set* a_mesh_data, const mesh_nodes_data* bones ) 14 : skeletal_mesh( a_context ) 15 { 16 const raw_data_channel* pnt_chan = a_mesh_data->get_channel<md5_vtx_pnt>(); 17 const raw_data_channel* pntiw_chan = a_mesh_data->get_channel<md5_vtx_pntiw>(); 18 19 m_pntdata.assign( pnt_chan->data_cast< md5_vtx_pnt >(), pnt_chan->size() ); 20 m_bone_offset.resize( bones->size() ); 21 m_transform.resize( bones->size() ); 22 23 for ( uint32 i = 0; i < bones->size(); ++i ) 24 { 25 m_bone_offset[i] = transform( (*bones)[i]->get_transform() ); 26 } 27 28 m_vtx_data = a_mesh_data->get_channel_data<md5_vtx_pntiw>(); 29 m_indices = a_mesh_data->get_channel_size( slot::INDEX ); 30 m_va = a_context->create_vertex_array(); 31 32 //array_view< raw_data_channel* > channels = a_mesh_data->get_raw_channels(); 33 for ( auto& channel : *a_mesh_data ) 34 { 35 //const raw_data_channel* channel = channels[ch]; 36 if ( channel.size() > 0 && &channel != pntiw_chan ) 37 { 38 const data_descriptor& desc = channel.descriptor(); 39 if ( desc[0].vslot == slot::INDEX ) 40 { 41 buffer b = a_context->get_device()->create_buffer( INDEX_BUFFER, STREAM_DRAW, channel.raw_size(), channel.raw_data() ); 42 a_context->set_index_buffer( m_va, b, desc[0].etype, true ); 43 } 44 else 45 { 46 buffer b = a_context->get_device()->create_buffer( VERTEX_BUFFER, STREAM_DRAW, channel.raw_size(), channel.raw_data() ); 47 a_context->add_vertex_buffers( m_va, b, desc ); 48 } 49 } 50 } 51 52 m_pbuffer = a_context->find_buffer( m_va, slot::POSITION ); 53 } 54 55 void nv::skeletal_mesh_cpu::update_animation( animation_entry* a_anim, uint32 a_anim_time ) 56 { 57 if ( a_anim ) 58 { 59 skeletal_animation_entry_cpu * anim = static_cast<skeletal_animation_entry_cpu*>( a_anim ); 60 anim->update_skeleton( m_transform.data(), static_cast<float>( a_anim_time ) ); 61 { 62 size_t skeleton_size = m_bone_offset.size(); 63 size_t vertex_count = m_pntdata.size(); 64 m_pos_offset.resize( skeleton_size ); 65 for ( unsigned int i = 0; i < skeleton_size; ++i ) 66 { 67 m_pos_offset[i] = m_transform[i] * m_bone_offset[i]; 68 } 69 70 fill( m_pntdata.raw_data(), m_pntdata.raw_data() + m_pntdata.raw_size(), 0 ); 71 for ( unsigned int i = 0; i < vertex_count; ++i ) 72 { 73 const md5_vtx_pntiw& vert = m_vtx_data[i]; 74 75 for ( int j = 0; j < 4; ++j ) 76 { 77 unsigned index = unsigned( vert.boneindex[j] ); 78 float weight = vert.boneweight[j]; 79 const quat& orient = m_transform[index].get_orientation(); 80 const transform& offset = m_pos_offset[index]; 81 m_pntdata[i].position += offset.transformed( vert.position ) * weight; 82 m_pntdata[i].normal += ( orient * vert.normal ) * weight; 83 m_pntdata[i].tangent += ( orient * vert.tangent ) * weight; 84 } 85 } 86 } 87 88 m_context->update( m_pbuffer, m_pntdata.data(), 0, m_pntdata.raw_size() ); 89 } 90 } 91 92 93 void nv::skeletal_animation_entry_cpu::initialize() 94 { 95 for ( auto bone : *m_node_data ) 96 { 97 if ( bone->size() > 0 ) 98 { 99 m_interpolation_key = bone->get_interpolation_key(); 100 break; 101 } 102 } 103 } 104 105 void nv::skeletal_animation_entry_cpu::update_skeleton( transform* skeleton, float time ) const 106 { 107 float frame_duration = 1000.f / static_cast<float>( m_node_data->get_frame_rate() ); 108 float anim_duration = frame_duration * m_node_data->get_duration(); 109 float new_time = fmodf( time, anim_duration ) * 0.001f; 110 111 float frame_num = new_time * m_node_data->get_frame_rate(); 112 for ( size_t i = 0; i < m_node_data->size(); ++i ) 113 { 114 raw_channel_interpolator interpolator( (*m_node_data)[i], m_interpolation_key ); 115 skeleton[i] = interpolator.get< transform >( frame_num ); 116 } 117 } 118 119 void nv::skeletal_animation_entry_gpu::initialize() 13 void nv::skeletal_animation_entry::initialize() 120 14 { 121 15 m_prepared = false; … … 140 34 } 141 35 142 void nv::skeletal_animation_entry _gpu::update_skeleton( mat4* data, uint32 time ) const36 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 time ) const 143 37 { 144 38 float tick_time = ( time * 0.001f ) * m_frame_rate; … … 169 63 } 170 64 171 void nv::skeletal_animation_entry _gpu::prepare( const mesh_nodes_data* bones )65 void nv::skeletal_animation_entry::prepare( const mesh_nodes_data* bones ) 172 66 { 173 67 if ( m_prepared ) return; … … 200 94 } 201 95 202 void nv::skeletal_animation_entry _gpu::animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const96 void nv::skeletal_animation_entry::animate_rec( mat4* data, float time, uint32 node_id, const mat4& parent_mat ) const 203 97 { 204 98 // TODO: fix transforms, which are now embedded, … … 227 121 } 228 122 229 nv::skeletal_animation_entry _gpu::~skeletal_animation_entry_gpu()123 nv::skeletal_animation_entry::~skeletal_animation_entry() 230 124 { 231 125 delete[] m_offsets; … … 234 128 } 235 129 236 nv::skeletal_mesh _gpu::skeletal_mesh_gpu( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data )237 : skeletal_mesh( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr )130 nv::skeletal_mesh::skeletal_mesh( context* a_context, const data_channel_set* a_mesh, const mesh_nodes_data* a_bone_data ) 131 : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr ) 238 132 { 239 133 if ( a_mesh ) … … 248 142 } 249 143 250 void nv::skeletal_mesh _gpu::update_animation( animation_entry* a_anim, uint32 a_anim_time )144 void nv::skeletal_mesh::update_animation( animation_entry* a_anim, uint32 a_anim_time ) 251 145 { 252 146 if ( m_bone_data && a_anim ) 253 147 { 254 skeletal_animation_entry _gpu * anim = static_cast<skeletal_animation_entry_gpu*>( a_anim );148 skeletal_animation_entry * anim = static_cast<skeletal_animation_entry*>( a_anim ); 255 149 anim->prepare( m_bone_data ); 256 150 anim->update_skeleton( m_transform, a_anim_time ); … … 258 152 } 259 153 260 void nv::skeletal_mesh _gpu::update( program a_program )154 void nv::skeletal_mesh::update( program a_program ) 261 155 { 262 156 if ( m_bone_data ) … … 264 158 } 265 159 266 nv::transform nv::skeletal_mesh _gpu::get_node_transform( uint32 node_id ) const160 nv::transform nv::skeletal_mesh::get_node_transform( uint32 node_id ) const 267 161 { 268 162 if ( node_id == 0 ) return transform(); … … 271 165 } 272 166 273 nv::mat4 nv::skeletal_mesh _gpu::get_node_matrix( uint32 node_id ) const167 nv::mat4 nv::skeletal_mesh::get_node_matrix( uint32 node_id ) const 274 168 { 275 169 return m_transform[ node_id ]; -
trunk/src/wx/wx_canvas.cc
r410 r467 63 63 } 64 64 65 static wxColor wx_log_color[] = 66 { 67 wxColor( *wxWHITE ), 68 wxColor( *wxRED ), 69 wxColor( *wxRED ), 70 wxColor( *wxRED ), 71 wxColor( *wxYELLOW ), 72 wxColor( *wxGREEN ), 73 wxColor( *wxLIGHT_GREY ), 74 wxColor( *wxLIGHT_GREY ), 75 wxColor( *wxLIGHT_GREY ), 76 wxColor( *wxLIGHT_GREY ), 77 wxColor( *wxLIGHT_GREY ), 78 }; 79 65 80 void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message ) 66 81 { … … 68 83 char stamp[16]; 69 84 size_t ssize = timestamp( stamp ); 70 str << stamp << " [" << padded_level_name( level ).data() << "] " << message.data() << "\n"; 85 m_text_ctrl->SetDefaultStyle( wxTextAttr( wx_log_color[ level / 10 ] ) ); 86 str << "[" << padded_level_name( level ).data() << "] " << message.data() << "\n"; 71 87 m_text_ctrl->AppendText( str ); 72 88 }
Note: See TracChangeset
for help on using the changeset viewer.