Changeset 285 for trunk/src/formats


Ignore:
Timestamp:
07/21/14 02:19:34 (11 years ago)
Author:
epyon
Message:
  • full pure data model for animation
  • all loaders now use pure data model instead of the template/virtual one
Location:
trunk/src/formats
Files:
3 edited

Legend:

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

    r284 r285  
    367367        if (this_id == 0)
    368368                a_data.transform = mat4();
    369         a_data.channel_count = 0;
     369        a_data.data = nullptr;
    370370
    371371        if (anode)
     
    394394        size_t max_keys = glm::max( node->mNumPositionKeys, node->mNumRotationKeys );
    395395
    396         data->channel_count = 1;
    397         data->channels[0] = key_raw_channel::create<assimp_key_tr>( max_keys );
    398         assimp_key_tr* channel = ((assimp_key_tr*)(data->channels[0]->data));
     396        key_raw_channel* raw_channel = key_raw_channel::create<assimp_key_tr>( max_keys );
     397        data->data = new key_data;
     398        data->data->add_channel( raw_channel );
     399        assimp_key_tr* channel = ((assimp_key_tr*)(raw_channel->data));
    399400
    400401        for ( unsigned n = 0; n < max_keys; ++n )
     
    406407                // TODO: only do the calculation when a rotate transform is present!
    407408                nv::transform ptr;
    408                 if ( parent )
    409                 {
    410                         key_raw_channel* pchannel = parent->channels[0];
    411                         if ( parent->channels[0] && parent->channels[0]->count > 0 )
    412                         {
    413                                 ptr = ((assimp_key_tr*)pchannel->data)[ glm::min( n, parent->channels[0]->count-1 ) ].tform;
     409                if ( parent && parent->data )
     410                {
     411                        const key_raw_channel* pchannel = parent->data->get_channel(0);
     412                        if ( pchannel && pchannel->count > 0 )
     413                        {
     414                                ptr = ((assimp_key_tr*)pchannel->data)[ glm::min( n, pchannel->count-1 ) ].tform;
    414415                        }
    415416                }
     
    422423void nv::assimp_loader::create_direct_keys( assimp_animated_node_data* data, const void* vnode )
    423424{
    424         data->channel_count = 0;
    425425        const aiNodeAnim* node = (const aiNodeAnim*)vnode;
    426426        if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
     
    429429        }
    430430
    431         data->channel_count = 3;
    432         data->channels[0] = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
    433         data->channels[1] = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
    434         data->channels[2] = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
    435         assimp_key_p* pchannel = ((assimp_key_p*)(data->channels[0]->data));
    436         assimp_key_r* rchannel = ((assimp_key_r*)(data->channels[1]->data));
    437         assimp_key_s* schannel = ((assimp_key_s*)(data->channels[2]->data));
     431        data->data = new key_data;
     432        key_raw_channel* raw_pchannel = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys );
     433        key_raw_channel* raw_rchannel = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys );
     434        key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );
     435        data->data->add_channel( raw_pchannel );
     436        data->data->add_channel( raw_rchannel );
     437        data->data->add_channel( raw_schannel );
     438        assimp_key_p* pchannel = ((assimp_key_p*)(raw_pchannel->data));
     439        assimp_key_r* rchannel = ((assimp_key_r*)(raw_rchannel->data));
     440        assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));
    438441
    439442        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
  • trunk/src/formats/md3_loader.cc

    r282 r285  
    407407        for ( sint32 i = 0; i < md3->header.num_tags; ++i )
    408408        {
    409                 const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags];
     409                const md3_tag_t& rtag = md3->tags[i];
    410410                std::string name( (char*)(rtag.name) );
    411                 nv::key_raw_channel* keys = load_tags( name );
    412                 result->insert( name, keys );
     411
     412                key_data* data = new key_data;
     413                data->add_channel( load_tags( name ) );
     414                result->insert( name, data );
    413415        }
    414416        return result;
    415417}
    416418
     419mesh_node_data* nv::md3_loader::release_mesh_node_data( size_t index )
     420{
     421        md3_t* md3 = (md3_t*)m_md3;
     422        const md3_tag_t& rtag = md3->tags[index];
     423        std::string name( (char*)(rtag.name) );
     424
     425        mesh_node_data* result = new mesh_node_data;
     426        result->transform = mat4();
     427        result->name      = name;
     428        result->parent_id = -1;
     429        result->target_id = -1;
     430        result->data = new key_data;
     431       
     432        key_raw_channel* keys = load_tags( name );
     433        result->data->add_channel( keys );
     434        return result;
     435}
     436
     437size_t nv::md3_loader::get_node_count() const
     438{
     439        return ((md3_t*)m_md3)->header.num_tags;
     440}
     441
    417442size_t md3_loader::get_max_frames() const
    418443{
  • trunk/src/formats/nmd_loader.cc

    r284 r285  
    138138                m_animation->nodes[i].parent_id     = node_header.parent_id;
    139139                m_animation->nodes[i].transform     = node_header.transform;
    140                 m_animation->nodes[i].channel_count = ch_count;
    141                 m_animation->nodes[i].channels      = nullptr;
     140                m_animation->nodes[i].data          = nullptr;
    142141                if ( ch_count > 0 )
    143142                {
    144                         m_animation->nodes[i].channels      = new key_raw_channel* [ch_count];
     143                        key_data* kdata = new key_data;
     144                        m_animation->nodes[i].data = kdata;
    145145                        for ( uint32 c = 0; c < ch_count; ++c )
    146146                        {
     
    151151                                key_raw_channel* channel = key_raw_channel::create( cheader.format, cheader.count );
    152152                                source.read( channel->data, channel->desc.size, channel->count );
    153                                 m_animation->nodes[i].channels[c] = channel;
     153                                kdata->add_channel( channel );
    154154                        }
    155155                }
     
    168168        {
    169169                nmd_node& node = m_animation->nodes[n];
    170                 key_animation_data* keys = nullptr;
    171                 if ( node.channel_count > 1 )
    172                 {
    173                         keys = new nv::key_vectors_prs( node.channels[0], node.channels[1], node.channels[2] );
    174                 }
    175                 else if ( node.channel_count == 1 )
    176                 {
    177                         keys      =  new nv::transform_vector( node.channels[0] );
    178                         node.channels[0] = nullptr;
    179                         node.channel_count = 0;
    180                 }
    181                 m_data.push_back( keys );
     170                m_data.push_back( node.data );
     171                node.data = nullptr;
    182172        }
    183173
     
    239229                        nv::mat4 node_mat( node->transform );
    240230
    241                         if ( m_data[n] && !m_data[n]->empty() )
     231                        if ( m_data[n] )
    242232                        {
    243233                                node_mat = m_data[n]->get_matrix( anim_time );
     
    257247        mat4 node_mat( node->transform );
    258248
    259         if ( m_data[ node_id ] && !m_data[ node_id ]->empty() )
     249        if ( m_data[ node_id ] )
    260250        {
    261251                node_mat = m_data[ node_id ]->get_matrix( time );
Note: See TracChangeset for help on using the changeset viewer.