Ignore:
Timestamp:
07/10/14 00:29:34 (11 years ago)
Author:
epyon
Message:
  • key_slots - another template hell similar to vertex definitions
  • animation data is now stored using key_raw_channel's similarly to mesh_raw_channels
  • automatic compile-time templated interpolation generation for any type of animation key
  • QUAT and TRANSFORM as registered types for channels
  • a ton of minor cleanups
  • do not open vertex.hh if you want to stay sane
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/assimp_loader.cc

    r280 r282  
    314314}
    315315
    316 assimp_animation* nv::assimp_loader::release_animation( size_t, bool pre_transform, const std::vector< assimp_bone >* bone_data )
     316assimp_animation* nv::assimp_loader::release_animation( size_t, bool pre_transform )
    317317{
    318318        if ( m_scene == nullptr ) return nullptr;
     
    332332
    333333        load_node( result, root, 0, -1 );
    334         // TODO: this is not used when pretransformed, is it used otherwise?
    335 
    336         if ( bone_data )
    337         {
    338                 std::unordered_map< std::string, uint16 > names;
    339                 for ( uint16 bi = 0; bi < bone_data->size(); ++bi )
    340                 {
    341                         names[ (*bone_data)[bi].name ] = bi;
    342                 }
    343 
    344                 for ( unsigned i = 0; i < result->nodes.size(); ++i )
    345                 {
    346                         assimp_animated_node_data& node = result->nodes[i];
    347                         node.bone_id = -1;
    348                         auto bi = names.find( node.name );
    349                         if ( bi != names.end() )
    350                         {
    351                                 node.bone_id = bi->second;
    352                         }
    353                         if ( node.parent_id != -1 )
    354                         {
    355                                 result->nodes[ node.parent_id ].children.push_back( &node );
    356                         }
    357                 }
    358         }
    359 
    360334        return result;
    361335}
     
    391365        a_data.name      = name;
    392366        a_data.parent_id = parent_id;
    393         a_data.bone_id = -1;
    394367        // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
    395368        // TODO: find a common solution!
     
    397370        //       node's without keys
    398371        a_data.transform = nv::assimp_mat4_cast( node->mTransformation );
     372        a_data.channel_count = 0;
    399373
    400374        if (anode)
     
    402376                if ( data->pretransformed )
    403377                {
    404                         a_data.keys = create_transformed_keys( anode, parent_id >= 0 ? data->nodes[ parent_id ].keys : nullptr );
     378                        create_transformed_keys( &a_data, anode, parent_id >= 0 ? &(data->nodes[ parent_id ]) : nullptr );
    405379                }
    406380                else
    407381                {
    408                         a_data.keys = create_direct_keys( anode );
     382                        create_direct_keys( &a_data, anode );
    409383                }
    410384        }
     
    418392}
    419393
    420 key_animation_data* nv::assimp_loader::create_transformed_keys( const void* vnode, const key_animation_data* parent_keys )
     394void nv::assimp_loader::create_transformed_keys( assimp_animated_node_data* data, const void* vnode, const assimp_animated_node_data* parent )
    421395{
    422396        const aiNodeAnim* node = (const aiNodeAnim*)vnode;
    423397        size_t max_keys = glm::max( node->mNumPositionKeys, node->mNumRotationKeys );
    424         nv::transform_vector* keys = new nv::transform_vector;
     398
     399        data->channel_count = 1;
     400        data->channels[0] = key_raw_channel::create<assimp_key_tr>( max_keys );
     401        assimp_key_tr* channel = ((assimp_key_tr*)(data->channels[0]->data));
     402
    425403        for ( unsigned n = 0; n < max_keys; ++n )
    426404        {
     
    431409                // TODO: only do the calculation when a rotate transform is present!
    432410                nv::transform ptr( vec3(), glm::quat_cast( m_rotate_transform ) );
    433                 if ( parent_keys )
    434                 {
    435                         const nv::transform_vector* pv = (const nv::transform_vector*)parent_keys;
    436                         if ( pv && pv->size() > 0 ) ptr = pv->get( glm::min( n, pv->size()-1 ) );
     411                if ( parent )
     412                {
     413                        key_raw_channel* pchannel = parent->channels[0];
     414                        if ( parent->channels[0] && parent->channels[0]->count > 0 )
     415                        {
     416                                ptr = ((assimp_key_tr*)pchannel->data)[ glm::min( n, parent->channels[0]->count-1 ) ].tform;
     417                        }
    437418                }
    438419                nv::transform key( ptr * nv::transform( pos * m_scale, rot ) );
    439                 keys->insert( key );
    440         }
    441         return keys;
    442 }
    443 
    444 key_animation_data* nv::assimp_loader::create_direct_keys( const void* vnode )
    445 {
     420                channel[n].tform = key;
     421        }
     422}
     423
     424void nv::assimp_loader::create_direct_keys( assimp_animated_node_data* data, const void* vnode )
     425{
     426        data->channel_count = 0;
    446427        // TODO : support for m_rotate_transform and m_scale! ( should be easy )
    447428        const aiNodeAnim* node = (const aiNodeAnim*)vnode;
    448         if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) return nullptr;
    449         key_vectors_prs* keys = new key_vectors_prs;
     429        if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
     430        {
     431                return;
     432        }
     433
     434        data->channel_count = 3;
     435        data->channels[0] = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
     436        data->channels[1] = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
     437        data->channels[2] = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
     438        assimp_key_p* pchannel = ((assimp_key_p*)(data->channels[0]->data));
     439        assimp_key_r* rchannel = ((assimp_key_r*)(data->channels[1]->data));
     440        assimp_key_s* schannel = ((assimp_key_s*)(data->channels[2]->data));
    450441
    451442        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
    452443        {
    453                 keys->insert_position( (float)node->mPositionKeys[np].mTime, m_scale * assimp_vec3_cast(node->mPositionKeys[np].mValue) );
     444                pchannel[np].time     = (float)node->mPositionKeys[np].mTime;
     445                pchannel[np].position = assimp_vec3_cast(node->mPositionKeys[np].mValue);
    454446        }
    455447        for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
    456448        {
    457                 keys->insert_rotation( (float)node->mRotationKeys[np].mTime, assimp_quat_cast(node->mRotationKeys[np].mValue) );
     449                rchannel[np].time     = (float)node->mRotationKeys[np].mTime;
     450                rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue);
    458451        }
    459452        if ( node->mNumScalingKeys > 0 )
     
    466459                        for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
    467460                        {
    468                                 keys->insert_scale( (float)node->mScalingKeys[np].mTime, assimp_vec3_cast(node->mScalingKeys[np].mValue) );
    469                         }
    470                 }
    471         }
    472         return keys;
    473 }
    474 
     461                                schannel[np].time  = (float)node->mScalingKeys[np].mTime;
     462                                schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue);
     463                        }
     464                }
     465        }
     466}
     467
Note: See TracChangeset for help on using the changeset viewer.