Ignore:
Timestamp:
10/23/15 19:35:39 (10 years ago)
Author:
epyon
Message:
  • resource handling rewrite
  • skeletal_mesh/mesh_data updates
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/skeleton_instance.cc

    r475 r477  
    77#include "nv/gfx/skeleton_instance.hh"
    88
    9 void nv::skeleton_instance::prepare( const mesh_nodes_data* bones )
     9void nv::skeleton_binding::prepare( const mesh_nodes_data* node_data, const mesh_nodes_data* bone_data )
    1010{
    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()];
    1517
    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                }
    2138        }
    2239
    23         for ( uint32 n = 0; n < m_data->size(); ++n )
     40        if ( m_key.size() == 0 )
    2441        {
    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        }
    2749
    28                 auto bi = bone_names.find( node->get_name() );
    29                 if ( bi != bone_names.end() )
     50}
     51
     52void 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() )
    3057                {
    31                         bone_id = sint16( bi->second );
     58                        animate_flat( node_data, binding, frame );
    3259                }
    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                }
    3766        }
    3867}
    3968
    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
     69void nv::skeleton_instance::animate_rec( const mesh_nodes_data* node_data, const skeleton_binding& binding, float frame, uint32 id, const mat4& parent )
    7470{
    7571        // TODO: fix transforms, which are now embedded,
    7672        //       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];
    7874        mat4 node_mat( node->get_transform() );
    7975
    8076        if ( node->size() > 0 )
    8177        {
    82                 raw_channel_interpolator interpolator( node, m_key );
     78                raw_channel_interpolator interpolator( node, binding.m_key );
    8379                node_mat = interpolator.get< mat4 >( frame );
    8480        }
     
    8682        mat4 global_mat = parent * node_mat;
    8783
    88         sint16 bone_id = m_indices[id];
     84        sint16 bone_id = binding.m_indices[id];
    8985        if ( bone_id >= 0 )
    9086        {
    91                 data[bone_id] = global_mat * m_offsets[bone_id];
     87                m_transform[bone_id] = global_mat * binding.m_offsets[bone_id];
    9288        }
    9389
    94         for ( auto child : m_data->children( id ) )
     90        for ( auto child : node_data->children( id ) )
    9591        {
    96                 animate_rec( data, frame, child, global_mat );
     92                animate_rec( node_data, binding, frame, child, global_mat );
    9793        }
    9894}
     95
     96void 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.