Changeset 423 for trunk/src/formats


Ignore:
Timestamp:
07/16/15 19:24:30 (10 years ago)
Author:
epyon
Message:
  • removal of several strings, string hashes used
  • WIP some data lost - see explicit warnings
  • name_hash to name
  • more nmd updates
  • animation names as hashes
Location:
trunk/src/formats
Files:
4 edited

Legend:

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

    r420 r423  
    200200                mat4    offset = assimp_mat4_cast( bone->mOffsetMatrix );
    201201//              bones[m].name = bone->mName.data;
    202                 bones[m].name_hash = hash_string< uint64 >( bone->mName.data );
     202                bones[m].name = hash_string< uint64 >( bone->mName.data );
    203203                bones[m].data = nullptr;
    204204                bones[m].parent_id = -1;
     
    302302
    303303                                mesh_node_data& bone = bones[b];
    304                                 auto iname = names.find( bone.name_hash );
     304                                auto iname = names.find( bone.name );
    305305                                if ( iname == names.end() )
    306306                                {
     
    308308                                        uint16 index = uint16( final_bones.size() );
    309309                                        final_bones.push_back( bone );
    310                                         names[ bone.name_hash] = index;
     310                                        names[ bone.name] = index;
    311311                                        translate[b] = index;
    312312                                }
     
    336336        mesh_node_data* bones = new mesh_node_data[ final_bones.size() ];
    337337        raw_copy( final_bones.begin(), final_bones.end(), bones );
    338         return new mesh_nodes_data( "bones", final_bones.size(), bones );
     338        int name_;
     339        return new mesh_nodes_data( /*"bones"*/0, final_bones.size(), bones );
    339340}
    340341
     
    357358        load_node( index, data, root, 0, -1 );
    358359
    359         return new mesh_nodes_data( anim->mName.data, count, data, frame_rate, duration, flat );
     360        int name;
     361        return new mesh_nodes_data( /*anim->mName.data*/0, count, data, frame_rate, duration, flat );
    360362}
    361363
     
    389391
    390392//      a_data.name      = name;
    391         a_data.name_hash = hash_string< uint64 >( name.c_str() );
     393        a_data.name = hash_string< uint64 >( name.c_str() );
    392394        a_data.parent_id = parent_id;
    393395        // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
  • trunk/src/formats/md3_loader.cc

    r420 r423  
    426426
    427427                nodes[i].transform = mat4();
    428                 nodes[i].name_hash = hash_string< uint64 >( name.data() );
     428                nodes[i].name = hash_string< uint64 >( name.data() );
    429429                nodes[i].parent_id = -1;
    430430                nodes[i].data      = data_channel_set_creator::create( 1 );
    431431                load_tags( data_channel_set_creator( nodes[i].data ).add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name );
    432432        }
    433         return new mesh_nodes_data( "tags", node_count, nodes );
     433        int name_;
     434        return new mesh_nodes_data( 0,/*"tags"*/ node_count, nodes );
    434435}
    435436
  • trunk/src/formats/md5_loader.cc

    r421 r423  
    112112                        assert( m_nodes == nullptr );
    113113                        nodes = new mesh_node_data[ num_joints ];
    114                         m_nodes = new mesh_nodes_data( "md5_bones", num_joints, nodes );
     114                        int name_; //"md5_bones"
     115                        m_nodes = new mesh_nodes_data( 0, num_joints, nodes );
    115116                        discard( sstream, "{" );
    116117                        for ( size_t i = 0; i < m_nodes->get_count(); ++i )
     
    128129                                remove_quotes( name );
    129130//                              nodes[i].name = name;
    130                                 nodes[i].name_hash = hash_string< uint64 >( name.c_str() );
     131                                nodes[i].name = hash_string< uint64 >( name.c_str() );
    131132//                              nodes[i].target_id       = -1;
    132133                                nodes[i].parent_id       = -1;
     
    242243                        assert( nodes == nullptr );
    243244                        nodes = new mesh_node_data[ num_joints ];
    244                         m_nodes = new mesh_nodes_data( "md5_animation", num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true );
     245                        int name_;
     246                        m_nodes = new mesh_nodes_data( 0/*"md5_animation"*/, num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true );
    245247                        joint_infos.resize( num_joints );
    246248
     
    252254                                remove_quotes( name );
    253255//                              nodes[i].name = name;
    254                                 nodes[i].name_hash = hash_string< uint64 >( name.c_str() );
     256                                nodes[i].name = hash_string< uint64 >( name.c_str() );
    255257                                nodes[i].transform = mat4();
    256258                                nodes[i].data = data_channel_set_creator::create( 1 );
  • trunk/src/formats/nmd_loader.cc

    r421 r423  
    2828                case nmd_type::MESH           : load_mesh( source, element_header ); break;
    2929                case nmd_type::ANIMATION      : load_animation( source, element_header ); break;
    30 //              case nmd_type::STRING_TABLE   : load_strings( source ); break;
     30                case nmd_type::STRINGS        : load_strings( source ); break;
    3131                default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break;
    3232                }
     
    6868{
    6969        for ( auto mesh : m_meshes ) if ( mesh ) delete mesh;
    70 //      if ( m_strings )   delete m_strings;
     70        if ( m_strings )   delete m_strings;
    7171        if ( m_node_data ) delete m_node_data;
    7272        m_meshes.clear();
     
    7676        m_node_data  = nullptr;
    7777        m_node_array = nullptr;
    78 //      m_strings    = nullptr;
     78        m_strings    = nullptr;
    7979}
    8080
     
    9090}
    9191
    92 bool nv::nmd_loader::load_strings( stream& /*source*/ )
    93 {
    94 //      NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" );
    95 //      m_strings = new string_table( &source );
     92bool nv::nmd_loader::load_strings( stream& source )
     93{
     94        NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" );
     95        // TODO: load strings optionally
     96        m_strings = new string_table( source );
    9697        return true;
    9798}
     
    112113                load_node( source, &m_node_array[i], element_header );
    113114        }
    114         m_node_data = new mesh_nodes_data( "animation", e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
     115        m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
    115116        return true;
    116117}
     
    118119bool nv::nmd_loader::load_node( stream& source, mesh_node_data* data, const nmd_element_header& e )
    119120{
    120         data->name_hash = e.name_hash;
     121        data->name = e.name;
    121122        data->parent_id = e.parent_id;
    122123        data->transform = e.transform;
     
    190191}
    191192
    192 static void nmd_dump_mesh( const data_channel_set* mesh, stream& stream_out )
    193 {
    194         uint32 size = 0;
    195         for ( auto& chan : *mesh )
    196         {
    197                 size += sizeof( nmd_channel_header );
    198                 size += chan.raw_size();
    199         }
    200 
    201         nmd_element_header eheader;
    202         eheader.type       = nmd_type::MESH;
    203 //      eheader.name       = 0;
    204         eheader.children   = static_cast< uint16 >( mesh->size() );
    205         eheader.size       = size;
    206         eheader.name_hash  = 0;
    207         eheader.transform  = mat4();
    208         eheader.parent_id  = -1;
    209         eheader.attributes = 0;
    210         stream_out.write( &eheader, sizeof( eheader ), 1 );
    211         nmd_dump_channel_set( mesh, stream_out );
    212 }
    213 
    214193static void nmd_dump_node( const mesh_node_data* node, stream& stream_out )
    215194{
     
    227206        eheader.children   = static_cast<uint16>( chan_count );
    228207        eheader.size       = chan_size;
    229         eheader.name_hash  = node->name_hash;
     208        eheader.name       = node->name;
    230209        eheader.parent_id  = node->parent_id;
    231210        eheader.transform  = node->transform;
     
    235214}
    236215
    237 static void nmd_dump_nodes_data( const mesh_nodes_data* nodes, stream& stream_out, string_table_creator* /*strings*/ )
     216void nv::nmd_dump_header( stream& stream_out, uint32 elements, uint64 name )
     217{
     218        nmd_header header;
     219        header.id = four_cc<'n', 'm', 'f', '1'>::value;
     220        header.elements = elements; // +1 string array
     221        header.name = name;
     222        header.version = 1;
     223        header.attributes = 0;
     224        stream_out.write( &header, sizeof( header ), 1 );
     225}
     226
     227void nv::nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh )
     228{
     229        uint32 size = 0;
     230        for ( auto& chan : mesh )
     231        {
     232                size += sizeof( nmd_channel_header );
     233                size += chan.raw_size();
     234        }
     235
     236        nmd_element_header eheader;
     237        eheader.type       = nmd_type::MESH;
     238        eheader.children   = static_cast<uint16>( mesh.size() );
     239        eheader.size       = size;
     240        int uncomment;
     241//      eheader.name       = mesh.get_name();
     242//      eheader.transform  = mesh.get_transform();
     243//      eheader.parent_id  = mesh.get_parent_id();
     244        eheader.name       = 0;
     245        eheader.transform  = mat4();
     246        eheader.parent_id  = -1;
     247        eheader.attributes = 0;
     248        stream_out.write( &eheader, sizeof( eheader ), 1 );
     249        nmd_dump_channel_set( &mesh, stream_out );
     250}
     251
     252void nv::nmd_dump_nodes( stream& stream_out, const mesh_nodes_data& nodes )
    238253{
    239254        uint32 total = sizeof( nmd_animation_header );
    240         for ( uint32 i = 0; i < nodes->get_count(); ++i )
    241         {
    242                 const mesh_node_data* node = nodes->get_node(i);
     255        for ( uint32 i = 0; i < nodes.get_count(); ++i )
     256        {
     257                const mesh_node_data* node = nodes.get_node( i );
    243258                total += sizeof( nmd_element_header );
    244259                if ( node->data )
     
    246261                        {
    247262                                total += sizeof( nmd_channel_header );
    248                                 total += node->data->get_channel(c)->raw_size();
     263                                total += node->data->get_channel( c )->raw_size();
    249264                        }
    250265        }
    251266
    252267        nmd_element_header header;
    253 //      header.name       = 0;
    254         header.type       = nmd_type::ANIMATION;
    255         header.children   = static_cast< uint16 >( nodes->get_count() );
    256         header.size       = total;
    257         header.name_hash  = 0;
    258         header.transform  = mat4();
    259         header.parent_id  = -1;
     268        header.type = nmd_type::ANIMATION;
     269        header.children = static_cast<uint16>( nodes.get_count() );
     270        header.size = total;
     271        header.name = nodes.get_name();
     272        header.transform = mat4();
     273        header.parent_id = -1;
    260274        header.attributes = 0;
    261275
     
    263277
    264278        nmd_animation_header aheader;
    265         aheader.frame_rate  = nodes->get_frame_rate();
    266         aheader.duration    = nodes->get_duration();
    267         aheader.flat        = nodes->is_flat();
     279        aheader.frame_rate = nodes.get_frame_rate();
     280        aheader.duration = nodes.get_duration();
     281        aheader.flat = nodes.is_flat();
    268282        stream_out.write( &aheader, sizeof( aheader ), 1 );
    269283
    270         for ( uint32 i = 0; i < nodes->get_count(); ++i )
    271         {
    272                 nmd_dump_node( nodes->get_node( i ), stream_out );
    273         }
    274 }
    275 
    276 void nv::nmd_dump( const mesh_data_pack* model, stream& stream_out )
    277 {
    278         string_table_creator strings;
    279         {
    280                 nmd_header header;
    281                 header.id       = four_cc<'n','m','f','1'>::value;
    282                 header.elements = 0; // +1 string array
    283                 header.elements += model->get_count();
    284                 if ( model->get_nodes() && model->get_nodes()->get_count() > 0 )
    285                         header.elements += 1;//  +1 bone array
    286                 header.version  = 1;
    287                 header.attributes = 0;
    288                 stream_out.write( &header, sizeof( header ), 1 );
    289         }
     284        for ( uint32 i = 0; i < nodes.get_count(); ++i )
     285        {
     286                nmd_dump_node( nodes.get_node( i ), stream_out );
     287        }
     288}
     289
     290void nv::nmd_dump_strings( stream& stream_out, const string_table& strings )
     291{
     292        nmd_element_header sheader;
     293        sheader.type       = nv::nmd_type::STRINGS;
     294        sheader.children   = 0;
     295        sheader.size       = strings.dump_size();
     296        sheader.name       = 0;
     297        sheader.parent_id  = -1;
     298    sheader.attributes = 0;
     299        stream_out.write( &sheader, sizeof( sheader ), 1 );
     300        strings.dump( stream_out );
     301}
     302
     303void nv::nmd_dump( stream& stream_out, const mesh_data_pack* model, const string_table* strings, uint64 name )
     304{
     305        uint32 elements = ( strings ? 1 : 0 ) // +1 string array
     306                + model->get_count() // meshes
     307                + ( model->get_node_count() > 0 ? 1 : 0 ); // nodes
     308        nmd_dump_header( stream_out, elements, name );
    290309
    291310        for ( uint32 i = 0; i < model->get_count(); ++i )
    292311        {
    293                 const data_channel_set* mesh = model->get_mesh(i);
    294                 nmd_dump_mesh( mesh, stream_out );
    295         }
    296 
    297         if ( model->get_nodes() && model->get_nodes()->get_count() > 0 )
    298         {
    299                 nmd_dump_nodes_data( model->get_nodes(), stream_out, &strings );
    300         }
    301 
    302 //      nmd_element_header sheader;
    303 //      sheader.type     = nv::nmd_type::STRING_TABLE;
    304 //      sheader.name     = 0;
    305 //      sheader.size     = strings.dump_size();
    306 //      sheader.children = 0;
    307 //  sheader.attributes = 0;
    308 //      stream_out.write( &sheader, sizeof( sheader ), 1 );
    309 //      strings.dump( &stream_out );
    310 }
     312                nmd_dump_mesh( stream_out, *model->get_mesh( i ) );
     313        }
     314
     315        if ( model->get_node_count() > 0 )
     316        {
     317                nmd_dump_nodes( stream_out, *model->get_nodes() );
     318        }
     319
     320        if ( strings )
     321        {
     322                nmd_dump_strings( stream_out, *strings );
     323        }
     324}
Note: See TracChangeset for help on using the changeset viewer.