Ignore:
Timestamp:
07/20/15 13:25:20 (10 years ago)
Author:
epyon
Message:
  • cleanup of mesh_node_data
File:
1 edited

Legend:

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

    r425 r427  
    190190}
    191191
    192 bool nv::assimp_loader::load_bones( size_t index, array_ref< mesh_node_data > bones )
     192bool nv::assimp_loader::load_bones( size_t index, array_ref< data_channel_set* > bones )
    193193{
    194194        if ( m_scene == nullptr ) return false;
     
    200200                aiBone* bone   = mesh->mBones[m];
    201201                mat4    offset = assimp_mat4_cast( bone->mOffsetMatrix );
    202                 bones[m].data = data_channel_set_creator::create_set( 0 );
    203                 data_channel_set_creator access( bones[m].data );
     202                bones[m] = data_channel_set_creator::create_set( 0 );
     203                data_channel_set_creator access( bones[m] );
    204204                const char* name = bone->mName.data;
    205205                access.set_name( make_name( name ) );
     
    287287{
    288288        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    289         vector< mesh_node_data > final_bones;
     289        mesh_nodes_data* result = new mesh_nodes_data( make_name( "bones" ) );
    290290        unordered_map< uint64, uint16 > names;
    291291        for ( unsigned int m = 0; m < m_mesh_count; ++m )
    292292        {
    293293                uint16 translate[MAX_BONES];
    294                 vector< mesh_node_data > bones;
     294                vector< data_channel_set* > bones;
    295295                const aiMesh*  mesh  = scene->mMeshes[ m ];
    296296                if ( mesh->mNumBones != 0 )
     
    301301                        {
    302302
    303                                 mesh_node_data& bone = bones[b];
    304                                 auto iname = names.find( bone.data->get_name() );
     303                                data_channel_set* bone = bones[b];
     304                                auto iname = names.find( bone->get_name() );
    305305                                if ( iname == names.end() )
    306306                                {
    307                                         NV_ASSERT( final_bones.size() < MAX_BONES, "Too many bones to merge!" );
    308                                         uint16 index = uint16( final_bones.size() );
    309                                         final_bones.push_back( bone );
    310                                         names[ bone.data->get_name() ] = index;
     307                                        NV_ASSERT( result->get_count() < MAX_BONES, "Too many bones to merge!" );
     308                                        uint16 index = uint16( result->get_count() );
     309                                        result->push_back( bone );
     310                                        names[ bone->get_name() ] = index;
    311311                                        translate[b] = index;
    312312                                }
     
    334334                }       
    335335        }
    336         mesh_node_data* bones = new mesh_node_data[ final_bones.size() ];
    337         raw_copy( final_bones.begin(), final_bones.end(), bones );
    338         return new mesh_nodes_data( make_name( "bones" ), final_bones.size(), bones );
     336
     337        return result;
    339338}
    340339
     
    349348
    350349        uint32 count = count_nodes( scene->mRootNode );
    351         mesh_node_data* data    = new mesh_node_data[count];
    352350
    353351        uint16 frame_rate     = static_cast<uint16>( anim->mTicksPerSecond );
     
    355353        bool   flat           = false;
    356354
    357         load_node( index, data, root, 0, -1 );
    358 
    359         return new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), count, data, frame_rate, duration, flat );
     355        data_channel_set** temp = new data_channel_set*[ count ];
     356        array_ref< data_channel_set* > temp_ref( temp, count );
     357        load_node( index, temp_ref, root, 0, -1 );
     358
     359        mesh_nodes_data* result = new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), frame_rate, duration, flat );
     360        for ( auto set : temp_ref )
     361        {
     362                result->push_back( set );
     363        }
     364        delete temp;
     365        return result;
    360366}
    361367
     
    371377}
    372378
    373 nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, mesh_node_data* nodes, const void* vnode, sint16 this_id, sint16 parent_id )
     379nv::sint16 nv::assimp_loader::load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, const void* vnode, sint16 this_id, sint16 parent_id )
    374380{
    375381        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
     
    386392        }
    387393
    388         mesh_node_data& a_data = nodes[ this_id ];
    389 
    390         if (anode)
    391                 create_keys( &a_data, anode );
    392         else
    393                 a_data.data = data_channel_set_creator::create_set( 0 );
    394 
    395         data_channel_set_creator access( a_data.data );
     394        nodes[ this_id ] = anode ? create_keys( anode ) : data_channel_set_creator::create_set( 0 );
     395
     396        data_channel_set_creator access( nodes[this_id] );
    396397        access.set_name( make_name( name ) );
    397398        access.set_parent_id( parent_id );
     
    412413}
    413414
    414 void nv::assimp_loader::create_keys( mesh_node_data* data, const void* vnode )
     415data_channel_set* nv::assimp_loader::create_keys( const void* vnode )
    415416{
    416417        const aiNodeAnim* node = reinterpret_cast< const aiNodeAnim* >( vnode );
    417418        if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 )
    418419        {
    419                 return;
    420         }
    421 
    422         data->data = data_channel_set_creator::create_set( 2 );
    423         data_channel_set_creator key_set( data->data );
     420                return data_channel_set_creator::create_set( 0 );
     421        }
     422       
     423        data_channel_set* set = data_channel_set_creator::create_set( 2 );
     424        data_channel_set_creator key_set( set );
    424425
    425426        assimp_key_p* pchannel = key_set.add_channel< assimp_key_p >( node->mNumPositionKeys ).data();
     
    456457//              }
    457458//      }
    458 
     459        return set;
    459460}
    460461
Note: See TracChangeset for help on using the changeset viewer.