Ignore:
Timestamp:
11/12/15 19:02:08 (10 years ago)
Author:
epyon
Message:
  • skeletal animation updated
File:
1 edited

Legend:

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

    r480 r482  
    105105}
    106106
    107 data_channel_set* nv::assimp_loader::release_mesh_data( size_t index /*= 0 */ )
     107data_channel_set* nv::assimp_loader::release_mesh_data( size_t index, data_node_info& info )
    108108{
    109109        if ( index >= m_mesh_count ) return nullptr;
    110110        data_channel_set* result = data_channel_set_creator::create_set( 2 );
    111         load_mesh_data( result, index );
     111        load_mesh_data( result, index, info );
    112112        return result;
    113113}
    114 void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index )
     114void nv::assimp_loader::load_mesh_data( data_channel_set* data, size_t index, data_node_info& info )
    115115{
    116116        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
     
    126126        data_channel_set_creator maccess( data );
    127127        const char* name = mesh->mName.data;
    128         maccess.set_name( make_name( name ) );
     128        info.name = make_name( name );
     129        info.parent_id = -1;
    129130        uint8*  cdata   = maccess.add_channel( desc, mesh->mNumVertices ).raw_data();
    130131        uint16* indices = reinterpret_cast<uint16*>( maccess.add_channel< index_u16 >( mesh->mNumFaces * 3 ).raw_data() );
     
    190191}
    191192
    192 bool nv::assimp_loader::load_bones( size_t index, array_ref< data_channel_set* > bones )
     193bool nv::assimp_loader::load_bones( size_t index, array_ref< data_node_info > bones )
    193194{
    194195        if ( m_scene == nullptr ) return false;
     
    200201                aiBone* bone   = mesh->mBones[m];
    201202                mat4    offset = assimp_mat4_cast( bone->mOffsetMatrix );
    202                 bones[m] = data_channel_set_creator::create_set( 0 );
    203                 data_channel_set_creator access( bones[m] );
    204203                const char* name = bone->mName.data;
    205                 access.set_name( make_name( name ) );
    206                 access.set_transform( offset );
     204                bones[m].name = make_name( name );
     205                bones[m].transform = offset;
    207206        }
    208207        return true;
     
    284283}
    285284
    286 mesh_nodes_data* nv::assimp_loader::release_merged_bones( data_channel_set* meshes )
    287 {
    288         const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    289         mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) );
     285data_node_list* nv::assimp_loader::release_merged_bones( data_channel_set* meshes )
     286{
     287        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
     288        data_node_list* result = new data_node_list( make_name( "bones" ) );
    290289        hash_store< shash64, uint16 > names;
    291290        for ( unsigned int m = 0; m < m_mesh_count; ++m )
    292291        {
    293292                uint16 translate[MAX_BONES];
    294                 vector< data_channel_set* > bones;
     293                vector< data_node_info > bones;
    295294                const aiMesh*  mesh  = scene->mMeshes[ m ];
    296295                if ( mesh->mNumBones != 0 )
    297296                {
    298297                        bones.resize( mesh->mNumBones );
     298                        NV_ASSERT( false, "parent ids for bones are not loaded!" );
    299299                        load_bones( m, bones );
    300300                        for ( unsigned int b = 0; b < mesh->mNumBones; ++b )
    301301                        {
    302302
    303                                 data_channel_set* bone = bones[b];
    304                                 auto iname = names.find( bone->get_name() );
     303                                data_node_info bone = bones[b];
     304                                auto iname = names.find( bone.name );
    305305                                if ( iname == names.end() )
    306306                                {
     
    308308                                        uint16 index = uint16( result->size() );
    309309                                        result->append( bone );
    310                                         names[ bone->get_name() ] = index;
     310                                        names[ bone.name ] = index;
    311311                                        translate[b] = index;
    312312                                }
     
    334334                }       
    335335        }
    336         result->initialize();
     336        //result->initialize();
    337337
    338338        return result;
     
    352352        uint16 frame_rate     = static_cast<uint16>( anim->mTicksPerSecond );
    353353        uint16 duration       = static_cast<uint16>( anim->mDuration );
    354         bool   flat           = false;
    355 
    356         data_channel_set** temp = new data_channel_set*[ count ];
     354
     355        data_channel_set** temp  = new data_channel_set*[ count ];
     356        data_node_info*    temp2 = new data_node_info[count];
    357357        array_ref< data_channel_set* > temp_ref( temp, count );
    358         load_node( index, temp_ref, root, 0, -1 );
    359 
    360         mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration, flat );
    361         for ( auto set : temp_ref )
    362         {
    363                 result->append( set );
     358        array_ref< data_node_info >    temp2_ref( temp2, count );
     359        load_node( index, temp_ref, temp2_ref, root, 0, -1 );
     360
     361        mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration );
     362        for ( nv::uint32 i = 0; i < count; ++i )
     363        {
     364                result->append( temp_ref[i], temp2_ref[i] );
    364365        }
    365366        result->initialize();
    366367        delete temp;
     368        delete temp2;
    367369        return result;
     370}
     371
     372data_node_list* nv::assimp_loader::release_data_node_list( size_t index /*= 0 */ )
     373{
     374        int this_is_incorrect;
     375        NV_ASSERT( false, "unimplemented!" );
     376//      mesh_nodes_data* half_result = release_mesh_nodes_data( index );
     377//      data_node_list* result = new data_node_list( half_result->get_name() );
     378//      for ( auto node : *half_result )
     379//              result->append( node->get_info() );
     380//      delete half_result;
     381//      return result;
     382        return nullptr;
     383}
     384
     385bool nv::assimp_loader::is_animated( size_t /*= 0 */ )
     386{
     387        int this_is_incorrect;
     388        return false;
    368389}
    369390
     
    379400}
    380401
    381 nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, const void* vnode, sint16 this_id, sint16 parent_id )
     402nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, array_ref< data_node_info > infos, const void* vnode, sint16 this_id, sint16 parent_id )
    382403{
    383404        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
     
    396417        nodes[ this_id ] = anode ? create_keys( anode ) : data_channel_set_creator::create_set( 0 );
    397418
    398         data_channel_set_creator access( nodes[this_id] );
    399         access.set_name( make_name( name ) );
    400         access.set_parent_id( parent_id );
     419        infos[this_id].name      = make_name( name );
     420        infos[this_id].parent_id = parent_id;
    401421        // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
    402422        // TODO: find a common solution!
    403423        //       This is bad because create_transformed_keys never uses node-transformations for
    404424        //       node's without keys
    405         access.set_transform( nv::assimp_mat4_cast( node->mTransformation ) );
    406         if ( this_id == 0 ) access.set_transform( mat4() );
     425        // TODO: this can probably be deleted
     426        infos[this_id].transform = nv::assimp_mat4_cast( node->mTransformation );
     427        if ( this_id == 0 ) infos[this_id].transform = mat4();
    407428
    408429        nv::sint16 next = this_id + 1;
    409430        for ( unsigned i = 0; i < node->mNumChildren; ++i )
    410431        {
    411                 next = load_node( anim_id, nodes, node->mChildren[i], next, this_id );
     432                next = load_node( anim_id, nodes, infos, node->mChildren[i], next, this_id );
    412433        }
    413434
Note: See TracChangeset for help on using the changeset viewer.