Changeset 470 for trunk/src/gfx/skeletal_mesh.cc
- Timestamp:
- 09/17/15 17:19:14 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 )
Note: See TracChangeset
for help on using the changeset viewer.