Changeset 477 for trunk/src/gfx/skeleton_instance.cc
- Timestamp:
- 10/23/15 19:35:39 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/skeleton_instance.cc
r475 r477 7 7 #include "nv/gfx/skeleton_instance.hh" 8 8 9 void nv::skeleton_ instance::prepare( const mesh_nodes_data* bones)9 void nv::skeleton_binding::prepare( const mesh_nodes_data* node_data, const mesh_nodes_data* bone_data ) 10 10 { 11 if ( m_offsets || m_indices ) return; 12 hash_store< shash64, uint16 > bone_names; 13 m_offsets = new mat4[bones->size()]; 14 m_indices = new sint16[m_data->size()]; 11 if ( !m_offsets || !m_indices ) 12 { 13 // TODO: either fixed size struct or static allocator 14 hash_store< shash64, uint16 > bone_names; 15 m_offsets = new mat4[bone_data->size()]; 16 m_indices = new sint16[node_data->size()]; 15 17 16 for ( nv::uint16 bi = 0; bi < bones->size(); ++bi ) 17 { 18 const data_channel_set* bone = ( *bones )[bi]; 19 bone_names[bone->get_name()] = bi; 20 m_offsets[bi] = bone->get_transform(); 18 for ( nv::uint16 bi = 0; bi < bone_data->size(); ++bi ) 19 { 20 const data_channel_set* bone = ( *bone_data )[bi]; 21 bone_names[bone->get_name()] = bi; 22 m_offsets[bi] = bone->get_transform(); 23 } 24 25 for ( uint32 n = 0; n < node_data->size(); ++n ) 26 { 27 const data_channel_set* node = ( *node_data )[n]; 28 sint16 bone_id = -1; 29 30 auto bi = bone_names.find( node->get_name() ); 31 if ( bi != bone_names.end() ) 32 { 33 bone_id = sint16( bi->second ); 34 } 35 m_indices[n] = bone_id; 36 37 } 21 38 } 22 39 23 for ( uint32 n = 0; n < m_data->size(); ++n)40 if ( m_key.size() == 0 ) 24 41 { 25 const data_channel_set* node = ( *m_data )[n]; 26 sint16 bone_id = -1; 42 for ( uint32 n = 0; n < node_data->size(); ++n ) 43 if ( ( *node_data )[n]->size() > 0 ) 44 { 45 m_key = ( *node_data )[n]->get_interpolation_key(); 46 break; 47 } 48 } 27 49 28 auto bi = bone_names.find( node->get_name() ); 29 if ( bi != bone_names.end() ) 50 } 51 52 void nv::skeleton_instance::animate( const mesh_nodes_data* node_data, const skeleton_binding& binding, float frame ) 53 { 54 if ( m_transform.size() > 0 ) 55 { 56 if ( node_data->is_flat() ) 30 57 { 31 bone_id = sint16( bi->second);58 animate_flat( node_data, binding, frame ); 32 59 } 33 m_indices[n] = bone_id; 34 35 if ( m_key.size() == 0 && node->size() > 0 ) 36 m_key = node->get_interpolation_key(); 60 else 61 { 62 for ( uint32 n = 0; n < node_data->size(); ++n ) 63 if ( ( *node_data )[n]->get_parent_id() == -1 ) 64 animate_rec( node_data, binding, frame, n, mat4() ); 65 } 37 66 } 38 67 } 39 68 40 void nv::skeleton_instance::animate( mat4* data, float frame ) const 41 { 42 if ( m_data->is_flat() ) 43 { 44 animate_flat( data, frame ); 45 } 46 else 47 { 48 for ( uint32 n = 0; n < m_data->size(); ++n ) 49 if ( ( *m_data )[n]->get_parent_id() == -1 ) 50 animate_rec( data, frame, n, mat4() ); 51 } 52 } 53 54 void nv::skeleton_instance::animate_flat( mat4* data, float frame ) const 55 { 56 for ( uint32 n = 0; n < m_data->size(); ++n ) 57 if ( m_indices[n] >= 0 ) 58 { 59 const data_channel_set* node = ( *m_data )[n]; 60 nv::mat4 node_mat( node->get_transform() ); 61 62 if ( node->size() > 0 ) 63 { 64 raw_channel_interpolator interpolator( node, m_key ); 65 node_mat = interpolator.get< mat4 >( frame ); 66 } 67 68 sint16 bone_id = m_indices[n]; 69 data[bone_id] = node_mat * m_offsets[bone_id]; 70 } 71 } 72 73 void nv::skeleton_instance::animate_rec( mat4* data, float frame, uint32 id, const mat4& parent ) const 69 void nv::skeleton_instance::animate_rec( const mesh_nodes_data* node_data, const skeleton_binding& binding, float frame, uint32 id, const mat4& parent ) 74 70 { 75 71 // TODO: fix transforms, which are now embedded, 76 72 // see note in assimp_loader.cc:load_node 77 const data_channel_set* node = ( * m_data )[id];73 const data_channel_set* node = ( *node_data )[id]; 78 74 mat4 node_mat( node->get_transform() ); 79 75 80 76 if ( node->size() > 0 ) 81 77 { 82 raw_channel_interpolator interpolator( node, m_key );78 raw_channel_interpolator interpolator( node, binding.m_key ); 83 79 node_mat = interpolator.get< mat4 >( frame ); 84 80 } … … 86 82 mat4 global_mat = parent * node_mat; 87 83 88 sint16 bone_id = m_indices[id];84 sint16 bone_id = binding.m_indices[id]; 89 85 if ( bone_id >= 0 ) 90 86 { 91 data[bone_id] = global_mat *m_offsets[bone_id];87 m_transform[bone_id] = global_mat * binding.m_offsets[bone_id]; 92 88 } 93 89 94 for ( auto child : m_data->children( id ) )90 for ( auto child : node_data->children( id ) ) 95 91 { 96 animate_rec( data, frame, child, global_mat );92 animate_rec( node_data, binding, frame, child, global_mat ); 97 93 } 98 94 } 95 96 void nv::skeleton_instance::animate_flat( const mesh_nodes_data* node_data, const skeleton_binding& binding, float frame ) 97 { 98 for ( uint32 n = 0; n < node_data->size(); ++n ) 99 if ( binding.m_indices[n] >= 0 ) 100 { 101 const data_channel_set* node = ( *node_data )[n]; 102 nv::mat4 node_mat( node->get_transform() ); 103 104 if ( node->size() > 0 ) 105 { 106 raw_channel_interpolator interpolator( node, binding.m_key ); 107 node_mat = interpolator.get< mat4 >( frame ); 108 } 109 110 sint16 bone_id = binding.m_indices[n]; 111 m_transform[bone_id] = node_mat * binding.m_offsets[bone_id]; 112 } 113 }
Note: See TracChangeset
for help on using the changeset viewer.