- Timestamp:
- 09/17/15 17:19:14 (10 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r454 r470 350 350 351 351 uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond ); 352 float duration = static_cast<float>( anim->mDuration ); 352 int check_this; 353 uint16 duration = static_cast<uint16>( anim->mDuration ); 353 354 bool flat = false; 354 355 -
trunk/src/formats/nmd_loader.cc
r442 r470 98 98 nmd_animation_header animation_header; 99 99 source.read( &animation_header, sizeof( animation_header ), 1 ); 100 m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header. duration, animation_header.flat );100 m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.frame_count, animation_header.flat ); 101 101 for ( uint32 i = 0; i < e.children; ++i ) 102 102 { … … 215 215 216 216 nmd_animation_header aheader; 217 aheader.frame_rate = nodes.get_frame_rate();218 aheader. duration = nodes.get_duration();217 aheader.frame_rate = nodes.get_fps(); 218 aheader.frame_count = nodes.get_frame_count(); 219 219 aheader.flat = nodes.is_flat(); 220 220 stream_out.write( &aheader, sizeof( aheader ), 1 ); -
trunk/src/gfx/keyframed_mesh.cc
r454 r470 72 72 } 73 73 74 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_ anim_time )74 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_ms_anim_time ) 75 75 { 76 76 if ( m_active ) 77 77 { 78 float tick_time = ( static_cast<float>( a_anim_time ) * 0.001f ) * anim->get_frame_rate(); 79 float duration = anim->is_looping() ? anim->get_duration() + 1.0f : anim->get_duration(); 80 if ( tick_time >= duration ) 78 float fframe = ( static_cast<float>( a_ms_anim_time ) * 0.001f ) * anim->get_fps(); 79 uint32 frame = uint32( fframe ); 80 float reminder = fframe - static_cast<float>( frame ); 81 uint32 duration = anim->is_looping() ? anim->get_frame_count() + 1 : anim->get_frame_count(); 82 83 if ( frame >= duration ) 81 84 { 82 85 if ( anim->is_looping() ) 83 86 { 84 tick_time = fmodf( tick_time, duration ); 87 frame = frame % duration; 88 fframe = static_cast<float>( frame ) + reminder; 85 89 } 86 90 else 87 91 { 88 m_active = false;89 m_last_frame = static_cast<uint32>( anim->get_end());90 m_next_frame = m_last_frame;92 m_active = false; 93 m_last_frame = anim->get_end_frame(); 94 m_next_frame = m_last_frame; 91 95 m_interpolation = 0.0f; 92 96 return; 93 97 } 94 98 } 95 m_last_frame = static_cast<uint32>( math::floor( tick_time ) + anim->get_start());99 m_last_frame = frame + anim->get_start_frame(); 96 100 m_next_frame = m_last_frame + 1; 97 if ( m_next_frame > static_cast<uint32>( anim->get_end() ) ) m_next_frame = static_cast<uint32>( anim->get_start());98 m_interpolation = tick_time - math::floor( tick_time );101 if ( m_next_frame > anim->get_end_frame() ) m_next_frame = anim->get_start_frame(); 102 m_interpolation = reminder; 99 103 } 100 104 } -
trunk/src/gfx/mesh_creator.cc
r458 r470 9 9 #include "nv/interface/data_channel_access.hh" 10 10 11 #include "nv/core/logging.hh" 12 11 13 struct nv_key_transform { nv::transform tform; }; 12 14 … … 16 18 merge_keys(); 17 19 uint32 max_frames = 0; 18 for ( auto keys : m_data->m_data ) 19 { 20 21 nv::vector< sint16 > ids; 22 { 23 // TODO: simplify this shit! 24 // The complexity here is that we cannot pre-transform in any order 25 // as the bones depend on previous bones, but ARE NOT IN ORDER 26 // 27 // Either rewrite this a lot nicer, or sort the bones on creation 28 // by tree-order. 29 30 ids.reserve( m_data->m_data.size() ); 31 { 32 nv::vector< sint16 > ids_next; 33 ids_next.reserve( m_data->m_data.size() ); 34 ids_next.push_back( -1 ); 35 while ( !ids_next.empty() ) 36 { 37 sint16 pid = ids_next.back(); 38 ids_next.pop_back(); 39 for ( sint16 i = 0; i < sint16(m_data->m_data.size()); ++i ) 40 if ( m_data->m_data[i]->get_parent_id() == pid ) 41 { 42 sint16* it = nv::find( ids.begin(), ids.end(), i ); 43 if ( it == ids.end() ) 44 { 45 ids.push_back( i ); 46 ids_next.push_back( i ); 47 } 48 } 49 } 50 } 51 52 if ( ids.size() != m_data->m_data.size() ) 53 { 54 NV_LOG_WARNING( "Bad skeleton!" ); 55 } 56 } 57 58 NV_LOG_DEBUG( "ID/PID" ); 59 for ( auto id : ids ) 60 { 61 data_channel_set* keys = m_data->m_data[id]; 20 62 sint16 parent_id = keys->get_parent_id(); 21 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr ); 63 NV_LOG_DEBUG( "Id : ", id, " PID", parent_id ); 64 data_channel_set* pkeys = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr ); 22 65 size_t count = ( keys ? keys->get_channel_size(0) : 0 ); 23 66 size_t pcount = ( pkeys ? pkeys->get_channel_size(0) : 0 ); … … 26 69 { 27 70 data_channel_access< nv_key_transform > channel_creator( keys, 0 ); 71 28 72 nv_key_transform* channel = channel_creator.data(); 29 73 const nv_key_transform* pchannel = pkeys->get_channel(0)->data_cast< nv_key_transform >(); … … 38 82 if ( m_data->m_frame_rate == 1 ) 39 83 { 40 m_data->m_frame_rate = 32;41 m_data->m_ duration = static_cast<float>( max_frames );84 m_data->m_frame_rate = 32; 85 m_data->m_frame_count = max_frames; 42 86 } 43 87 -
trunk/src/gfx/skeletal_mesh.cc
r467 r470 13 13 void nv::skeletal_animation_entry::initialize() 14 14 { 15 m_root = uint32(-1); 15 16 m_prepared = false; 16 17 m_children = nullptr; … … 30 31 m_children[ node->get_parent_id()].push_back( n ); 31 32 } 32 } 33 } 34 } 35 36 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 time ) const 37 { 38 float tick_time = ( time * 0.001f ) * m_frame_rate; 39 float anim_time = m_start; 40 if ( m_duration > 0.0f ) anim_time += fmodf( tick_time, m_duration ); 33 else 34 { 35 if ( m_root >= 0 ) 36 { 37 m_root = uint32( -2 ); 38 } 39 else 40 m_root = n; 41 } 42 } 43 NV_ASSERT( m_root != uint32( -1 ), "Animation without root!" ); 44 } 45 } 46 47 void nv::skeletal_animation_entry::update_skeleton( mat4* data, uint32 a_ms_time ) const 48 { 49 float fframe = ( a_ms_time * 0.001f ) * m_fps; 50 uint32 frame = math::floor( fframe ); 51 float reminder = fframe - static_cast<float>( frame ); 52 uint32 duration = get_frame_count(); 53 if ( duration == 0 ) 54 { 55 frame = get_start_frame(); 56 fframe = static_cast<float>( frame ); 57 } 58 else if ( frame >= duration ) 59 { 60 if ( is_looping() ) 61 { 62 frame = frame % duration; 63 fframe = static_cast<float>( frame ) + reminder; 64 } 65 else 66 { 67 frame = get_end_frame(); 68 fframe = static_cast<float>( frame ); 69 } 70 } 41 71 42 72 if ( !m_node_data->is_flat() ) 43 73 { 44 animate_rec( data, anim_time, 0, mat4() ); 74 if ( m_root == uint32( -2 ) ) // multi-root 75 { 76 for ( uint32 n = 0; n < m_node_data->size(); ++n ) 77 if ( ( *m_node_data )[n]->get_parent_id() == -1 ) 78 animate_rec( data, fframe, n, mat4() ); 79 } 80 else 81 animate_rec( data, fframe, m_root, mat4() ); 45 82 return; 46 83 } … … 55 92 { 56 93 raw_channel_interpolator interpolator( node, m_interpolation_key ); 57 node_mat = interpolator.get< mat4 >( anim_time );94 node_mat = interpolator.get< mat4 >( fframe ); 58 95 } 59 96 … … 66 103 { 67 104 if ( m_prepared ) return; 68 unordered_map< uint64, uint16 > bone_names;105 nv::hash_store< shash64, uint16 > bone_names; 69 106 m_offsets = new mat4[ bones->size() ]; 70 107 for ( nv::uint16 bi = 0; bi < bones->size(); ++bi ) 71 108 { 72 109 const data_channel_set* bone = (*bones)[ bi ]; 73 bone_names[ bone->get_name() .value()] = bi;110 bone_names[ bone->get_name() ] = bi; 74 111 m_offsets[bi] = bone->get_transform(); 75 112 } … … 80 117 sint16 bone_id = -1; 81 118 82 auto bi = bone_names.find( node->get_name() .value());119 auto bi = bone_names.find( node->get_name() ); 83 120 if ( bi != bone_names.end() ) 84 121 { … … 129 166 130 167 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 ) 168 : m_context( a_context ), m_bone_data( a_bone_data ), m_index_count( 0 ), m_transform( nullptr ), m_parent_id(-1) 132 169 { 133 170 if ( a_mesh ) … … 135 172 m_va = a_context->create_vertex_array( a_mesh, nv::STATIC_DRAW ); 136 173 m_index_count = a_mesh->get_channel_size( slot::INDEX ); 174 m_parent_id = a_mesh->get_parent_id(); 137 175 } 138 176 if ( m_bone_data ) -
trunk/src/wx/wx_canvas.cc
r467 r470 6 6 7 7 #include <nv/wx/wx_canvas.hh> 8 9 #include <nv/core/time.hh> 8 10 9 11 wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow ) … … 51 53 void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt ) 52 54 { 55 nv::sleep( 10 ); 53 56 if ( m_render ) 54 57 {
Note: See TracChangeset
for help on using the changeset viewer.