Changeset 425 for trunk


Ignore:
Timestamp:
07/17/15 13:34:28 (10 years ago)
Author:
epyon
Message:
  • mesh formats now support string loading via string_table
  • nmd string_table dump
  • fixes all around
Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/formats/assimp_loader.hh

    r422 r425  
    2020        {
    2121        public:
    22                 explicit assimp_loader( const std::string& a_ext, uint32 a_assimp_flags = 0 );
     22                explicit assimp_loader( string_table* strings, const string_view& a_ext, uint32 a_assimp_flags = 0 );
    2323                virtual bool load( stream& source );
    2424                virtual data_channel_set* release_mesh_data( size_t index = 0 );
     
    3737                void create_keys( mesh_node_data* data, const void* vnode );
    3838
    39                 string_table* m_strings;
    40                 std::string m_ext;
     39                const_string m_ext;
    4140                uint32 m_assimp_flags;
    4241                const void* m_scene;
  • trunk/nv/formats/md2_loader.hh

    r416 r425  
    2424        {
    2525        public:
    26                 md2_loader();
     26                explicit md2_loader( string_table* strings );
    2727                virtual ~md2_loader();
    2828                virtual bool load( stream& source );
     
    3636        private:
    3737                void* m_md2;
     38                string_table* m_strings;
    3839                vector< uint16 > m_new_indexes;
    3940                vector< uint16 > m_new_vindexes;
  • trunk/nv/formats/md3_loader.hh

    r417 r425  
    3030        {
    3131        public:
    32                 md3_loader( bool merge_all = true );
     32                explicit md3_loader( string_table* strings, bool merge_all = true );
    3333                virtual ~md3_loader();
    3434                virtual bool load( stream& source );
  • trunk/nv/formats/md5_loader.hh

    r416 r425  
    5252                enum file_type { UNKNOWN, MESH, ANIMATION };
    5353
    54                 md5_loader() : m_type( UNKNOWN ), m_nodes( nullptr ) {}
     54                explicit md5_loader( string_table* strings ) : mesh_loader( strings ), m_type( UNKNOWN ), m_nodes( nullptr ) {}
    5555                virtual ~md5_loader();
    5656                virtual bool load( stream& source );
  • trunk/nv/formats/nmd_loader.hh

    r423 r425  
    7878        {
    7979        public:
    80                 nmd_loader() : m_node_data( nullptr ), m_node_array( nullptr ), m_strings( nullptr ) {}
     80                explicit nmd_loader( string_table* strings ) : mesh_loader( strings ), m_node_data( nullptr ), m_node_array( nullptr ) {}
    8181                virtual bool load( stream& source );
    8282                virtual data_channel_set* release_mesh_data( size_t index = 0 );
     
    9898                mesh_nodes_data*            m_node_data;
    9999                mesh_node_data*             m_node_array;
    100                 string_table*               m_strings;
    101100//              vector< uint16 >            m_mesh_names;
    102101//              vector< uint16 >            m_node_names;
  • trunk/nv/formats/obj_loader.hh

    r416 r425  
    2525        {
    2626        public:
    27                 obj_loader( bool normals = true, bool tangents = false );
     27                obj_loader( string_table* strings, bool normals = true, bool tangents = false );
    2828                virtual bool load( stream& source );
    2929                virtual data_channel_set* release_mesh_data( size_t index = 0 );
     
    3232                ~obj_loader();
    3333        private:
    34                 data_descriptor             m_descriptor;
    3534                bool                        m_normals;
    3635                bool                        m_tangents;
     36                data_descriptor             m_descriptor;
    3737                vector< data_channel_set* > m_meshes;
    3838        };
  • trunk/nv/interface/data_channel_access.hh

    r424 r425  
    141141                const_iterator end()   const { return m_set->end(); }
    142142
    143                 void set_name( const char* /*name*/ ) {}// { m_name = name; }
    144                                                                                                            //const std::string& get_name() const { return m_name; }
    145 
    146143                void move_to( data_channel_set& other )
    147144                {
  • trunk/nv/interface/mesh_loader.hh

    r423 r425  
    2020#include <nv/interface/mesh_data.hh>
    2121#include <nv/stl/stream.hh>
     22#include <nv/io/string_table.hh>
    2223
    2324namespace nv
     
    2728        {
    2829        public:
    29                 mesh_loader() {}
     30                explicit mesh_loader( string_table* strings ) : m_strings( strings ) {}
    3031                virtual ~mesh_loader() {}
    3132                virtual bool load( stream& source ) = 0;
     
    3536                virtual size_t get_nodes_data_count() const { return 0; }
    3637                virtual mesh_nodes_data* release_mesh_nodes_data( size_t = 0 ) { return nullptr; }
     38        protected:
     39                inline uint64 make_name( const string_view& name )
     40                {
     41                        return m_strings ? m_strings->insert( name ) : name.get_hash< uint64 >();
     42                }
     43                string_table* m_strings;
    3744        };
    3845
  • trunk/nv/io/string_table.hh

    r422 r425  
    6262                }
    6363
     64                uint32 size() const { return m_map.size(); }
     65                bool empty() const { return m_map.empty(); }
    6466                uint32 dump_size() const;
    6567                void dump( stream& out ) const;
  • trunk/src/formats/assimp_loader.cc

    r424 r425  
    5757
    5858
    59 nv::assimp_loader::assimp_loader( const std::string& a_ext, uint32 a_assimp_flags /*= 0 */ )
    60         : m_scene( nullptr ), m_mesh_count(0)
     59nv::assimp_loader::assimp_loader( string_table* strings, const string_view& a_ext, uint32 a_assimp_flags /*= 0 */ )
     60        : mesh_loader( strings ), m_scene( nullptr ), m_mesh_count(0)
    6161{
    6262        m_ext   = a_ext;
     
    9292        char* data  = new char[ size ];
    9393        source.read( data, size, 1 );
    94         const aiScene* scene = aiImportFileFromMemory( data, size, m_assimp_flags, m_ext.c_str() );
     94        const aiScene* scene = aiImportFileFromMemory( data, size, m_assimp_flags, m_ext.data() );
    9595
    9696        if( !scene)
     
    125125                desc.initialize< assimp_plain_vtx >();
    126126        data_channel_set_creator maccess( data );
    127         maccess.set_name( mesh->mName.data );
     127        const char* name = mesh->mName.data;
     128        maccess.set_name( make_name( name ) );
    128129        uint8*  cdata   = maccess.add_channel( desc, mesh->mNumVertices ).raw_data();
    129130        uint16* indices = reinterpret_cast<uint16*>( maccess.add_channel< index_u16 >( mesh->mNumFaces * 3 ).raw_data() );
     
    201202                bones[m].data = data_channel_set_creator::create_set( 0 );
    202203                data_channel_set_creator access( bones[m].data );
    203                 access.set_name( hash_string< uint64 >( bone->mName.data ) );
     204                const char* name = bone->mName.data;
     205                access.set_name( make_name( name ) );
    204206                access.set_transform( offset );
    205207        }
     
    334336        mesh_node_data* bones = new mesh_node_data[ final_bones.size() ];
    335337        raw_copy( final_bones.begin(), final_bones.end(), bones );
    336         int name_;
    337         return new mesh_nodes_data( /*"bones"*/0, final_bones.size(), bones );
     338        return new mesh_nodes_data( make_name( "bones" ), final_bones.size(), bones );
    338339}
    339340
     
    356357        load_node( index, data, root, 0, -1 );
    357358
    358         int name;
    359         return new mesh_nodes_data( /*anim->mName.data*/0, count, data, frame_rate, duration, flat );
     359        return new mesh_nodes_data( make_name( static_cast<const char*>( anim->mName.data ) ), count, data, frame_rate, duration, flat );
    360360}
    361361
     
    375375        const aiScene* scene = reinterpret_cast<const aiScene*>( m_scene );
    376376        const aiNode*  node  = reinterpret_cast<const aiNode*>( vnode );
    377         std::string name( node->mName.data );
     377        string_view name( static_cast< const char* >( node->mName.data ) );
    378378        const aiAnimation* anim  = scene->mAnimations[anim_id];
    379379        const aiNodeAnim*  anode = nullptr;
     
    382382        {
    383383                anode = anim->mChannels[i];
    384                 if ( std::string( anode->mNodeName.data ) == name ) break;
     384                if ( string_view( static_cast< const char* >( anode->mNodeName.data ) ) == name ) break;
    385385                anode = nullptr;
    386386        }
     
    394394
    395395        data_channel_set_creator access( a_data.data );
    396         access.set_name( hash_string< uint64 >( name.c_str() ) );
     396        access.set_name( make_name( name ) );
    397397        access.set_parent_id( parent_id );
    398398        // This value is ignored by the create_transformed_keys, but needed by create_direct_keys!
     
    468468        {
    469469                const aiMesh* mesh = scene->mMeshes[ m ];
    470                 data_channel_set_creator( &meshes[m] ).set_name( mesh->mName.data );
     470                data_channel_set_creator( &meshes[m] ).set_name( make_name( static_cast<const char*>( mesh->mName.data ) ) );
    471471                if ( mesh->mNumBones > 0 ) has_bones = true;
    472472                load_mesh_data(&meshes[m],m);
  • trunk/src/formats/md2_loader.cc

    r424 r425  
    199199static bool s_md2_normal_ready = false;
    200200
    201 md2_loader::md2_loader() : m_md2( nullptr )
     201md2_loader::md2_loader( string_table* strings )
     202        : mesh_loader( strings ), m_md2( nullptr )
    202203{
    203204        if ( !s_md2_normal_ready )
     
    331332        uint16* icp        = &maccess.add_channel< index_u16 >( m_new_indexes.size() ).data()->index;
    332333
     334        maccess.set_name( make_name( "md2_mesh" ) );
     335
    333336        uint32 index = 0;
    334337        while ( frame_count > 0 )
  • trunk/src/formats/md3_loader.cc

    r424 r425  
    235235static bool s_normal_ready = false;
    236236
    237 md3_loader::md3_loader( bool merge_all )
    238         : m_merge_all( merge_all ), m_md3( nullptr )
     237md3_loader::md3_loader( string_table* strings, bool merge_all )
     238        : mesh_loader( strings ), m_merge_all( merge_all ), m_md3( nullptr )
    239239{
    240240        if ( !s_normal_ready )
     
    353353
    354354        data_channel_set_creator maccess( data );
    355         maccess.set_name( reinterpret_cast<char*>( md3->header.name ) );
     355        maccess.set_name( make_name( reinterpret_cast<char*>( md3->header.name ) ) );
     356
    356357
    357358        vtx_md3_pn* vtx_pn = maccess.add_channel< vtx_md3_pn >( static_cast< uint32 >( num_verts * frame_count ) ).data();
     
    426427                nodes[i].data      = data_channel_set_creator::create_set( 1 );
    427428                data_channel_set_creator access( nodes[i].data );
    428                 access.set_name( hash_string< uint64 >( name.data() ) );
     429                access.set_name( make_name( name ) );
    429430                load_tags( access.add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name );
    430431        }
    431         int name_;
    432         return new mesh_nodes_data( 0,/*"tags"*/ node_count, nodes );
     432        return new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0, node_count, nodes );
    433433}
    434434
     
    442442                data = data_channel_set_creator::create_set_array(1,3);
    443443                release_mesh_frame( &data[0], -1, -1 );
    444                 data_channel_set_creator( &data[0] ).set_name( reinterpret_cast< char* >( md3->header.name ) );
    445444        }
    446445        else
     
    451450                {
    452451                        release_mesh_frame( &data[i], -1, i );
    453                         data_channel_set_creator( &data[i] ).set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) );
     452                        data_channel_set_creator( &data[i] ).set_name( make_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) ) );
    454453                }
    455454        }
  • trunk/src/formats/md5_loader.cc

    r424 r425  
    112112                        assert( m_nodes == nullptr );
    113113                        nodes = new mesh_node_data[ num_joints ];
    114                         int name_; //"md5_bones"
    115                         m_nodes = new mesh_nodes_data( 0, num_joints, nodes );
     114                        m_nodes = new mesh_nodes_data( make_name( "md5_bones"), num_joints, nodes );
    116115                        discard( sstream, "{" );
    117116                        for ( size_t i = 0; i < m_nodes->get_count(); ++i )
     
    133132                                access.set_parent_id( parent_id );
    134133                                access.set_transform( transform( pos, orient ).inverse().extract() );
    135                                 access.set_name( hash_string< uint64 >( name.c_str() ) );
     134                                access.set_name( make_name( name.c_str() ) );
    136135                                next_line( sstream );
    137136                        }
     
    157156                                        sstream >> shader;
    158157                                        remove_quotes( shader );
     158                                        maccess.set_name( make_name( shader ) );
    159159                                        next_line( sstream );
    160160                                }
     
    243243                        assert( nodes == nullptr );
    244244                        nodes = new mesh_node_data[ num_joints ];
    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 );
     245                        m_nodes = new mesh_nodes_data( make_name( "md5_animation" ), num_joints, nodes, static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true );
    247246                        joint_infos.resize( num_joints );
    248247
     
    257256                                data_channel_set_creator access( nodes[i].data );
    258257                                access.add_channel< md5_key_t >( num_frames );
    259                                 access.set_name( hash_string< uint64 >( name.c_str() ) );
     258                                access.set_name( make_name( name.c_str() ) );
    260259                                access.set_parent_id( parent_id );
    261260                                next_line( sstream );
  • trunk/src/formats/nmd_loader.cc

    r424 r425  
    4747{
    4848        data_channel_set* result = m_meshes[ index ];
    49 //      if ( m_strings ) data_channel_set_creator( result ).set_name( m_strings->get( m_mesh_names[ index ] ) );
    5049        m_meshes[ index ] = nullptr;
    5150        return result;
     
    6867{
    6968        for ( auto mesh : m_meshes ) if ( mesh ) delete mesh;
    70         if ( m_strings )   delete m_strings;
    7169        if ( m_node_data ) delete m_node_data;
    7270        m_meshes.clear();
    73 //      m_mesh_names.clear();
    74 //      m_node_names.clear();
    7571
    7672        m_node_data  = nullptr;
    7773        m_node_array = nullptr;
    78         m_strings    = nullptr;
    7974}
    8075
     
    9287bool nv::nmd_loader::load_strings( stream& source )
    9388{
    94         NV_ASSERT( m_strings == nullptr, "MULTIPLE STRING ENTRIES!" );
     89        if ( !m_strings ) return true;
    9590        // TODO: load strings optionally
    96         m_strings = new string_table( source );
     91        string_table* strings = new string_table( source );
     92        m_strings->insert( strings );
     93        delete strings;
    9794        return true;
    9895}
     
    110107                skip_attributes( source, element_header.attributes );
    111108                NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" );
    112 //              m_node_names.push_back( element_header.name );
    113                 load_node( source, &m_node_array[i], element_header );
     109                m_node_array[i].data = data_channel_set_creator::create_set( element_header.children );
     110                load_channel_set( source, m_node_array[i].data, element_header );
    114111        }
    115112        m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
    116         return true;
    117 }
    118 
    119 bool nv::nmd_loader::load_node( stream& source, mesh_node_data* data, const nmd_element_header& e )
    120 {
    121         data->data = data_channel_set_creator::create_set( e.children );
    122         if ( e.children > 0 )
    123         {
    124                 load_channel_set( source, data->data, e );
    125         }
    126         data_channel_set_creator access( data->data );
    127         access.set_name( e.name );
    128         access.set_parent_id( e.parent_id );
    129         access.set_transform( e.transform );
    130113        return true;
    131114}
     
    148131                load_channel( source, channel_set );
    149132        }
     133        data_channel_set_creator access( channel_set );
     134        access.set_name( e.name );
     135        access.set_parent_id( e.parent_id );
     136        access.set_transform( e.transform );
    150137        return true;
    151138}
     
    155142        if ( m_node_data )
    156143        {
    157 //              if ( m_strings )
    158 //              {
    159 //                      for ( uint32 i = 0; i < m_node_data->get_count(); ++i )
    160 //                      {
    161 //                              m_node_array[i].name = m_strings->get( m_node_names[i] );
    162 //                              m_node_array[i].name_hash = hash_string< uint64 >( m_strings->get( m_node_names[i] ) );
    163 //                      }
    164 //              }
    165144                mesh_nodes_data* result = m_node_data;
    166145                m_node_data = nullptr;
     
    203182        nmd_element_header eheader;
    204183        eheader.type = nmd_type::NODE;
    205         //              eheader.name     = strings->insert( node->name );
    206184        eheader.children   = static_cast<uint16>( chan_count );
    207185        eheader.size       = chan_size;
  • trunk/src/formats/obj_loader.cc

    r424 r425  
    291291};
    292292
    293 nv::obj_loader::obj_loader( bool normals /*= true*/, bool tangents /*= false */ )
    294         : m_normals( normals ), m_tangents( tangents )
     293nv::obj_loader::obj_loader( string_table* strings, bool normals /*= true*/, bool tangents /*= false */ )
     294        : mesh_loader( strings ), m_normals( normals ), m_tangents( tangents )
    295295{
    296296        if ( normals )
     
    327327       
    328328                data_channel_set* result = data_channel_set_creator::create_set( 1 );
    329                 data_channel_set_creator raccess( result );// ( reader->name );
     329                data_channel_set_creator raccess( result );
     330                raccess.set_name( make_name( reader->name ) );
    330331                uint8* rdata = raccess.add_channel( m_descriptor, reader->size * 3 ).raw_data();
    331332
  • trunk/src/io/string_table.cc

    r422 r425  
    1313        m_map.reserve( entry_count );
    1414        indexer_type::value_type entry;
    15         for ( uint32 i = 0; i < entry_count; )
     15        for ( uint32 i = 0; i < entry_count; i++ )
    1616        {
    1717                in.read( &entry, sizeof( entry ), 1 );
Note: See TracChangeset for help on using the changeset viewer.