Changeset 427


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

Legend:

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

    r425 r427  
    3131        private:
    3232                mesh_nodes_data* release_merged_bones( data_channel_set* meshes );
    33                 bool load_bones( size_t index, array_ref< mesh_node_data > bones );
     33                bool load_bones( size_t index, array_ref< data_channel_set* > bones );
    3434                void load_mesh_data( data_channel_set* data, size_t index );
    35                 sint16 load_node( uint32 anim_id, mesh_node_data* nodes, const void* vnode, sint16 this_id, sint16 parent_id );
     35                sint16 load_node( uint32 anim_id, array_ref< data_channel_set* > nodes, const void* vnode, sint16 this_id, sint16 parent_id );
    3636                uint32 count_nodes( const void* node ) const;
    37                 void create_keys( mesh_node_data* data, const void* vnode );
     37                data_channel_set* create_keys( const void* vnode );
    3838
    3939                const_string m_ext;
  • trunk/nv/formats/md5_loader.hh

    r425 r427  
    8383        protected:
    8484                void reset();
    85                 void build_frame_skeleton( mesh_node_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data );
    86                 bool prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info );
     85                void build_frame_skeleton( mesh_nodes_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_info, const array_view<transform>& base_frames, const array_view<float>& frame_data );
     86                bool prepare_mesh( mesh_nodes_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info );
    8787        protected:
    8888                file_type m_type;
  • trunk/nv/formats/nmd_loader.hh

    r425 r427  
    7878        {
    7979        public:
    80                 explicit nmd_loader( string_table* strings ) : mesh_loader( strings ), m_node_data( nullptr ), m_node_array( nullptr ) {}
     80                explicit nmd_loader( string_table* strings ) : mesh_loader( strings ), m_node_data( nullptr ) {}
    8181                virtual bool load( stream& source );
    8282                virtual data_channel_set* release_mesh_data( size_t index = 0 );
     
    9292                bool load_strings( stream& source );
    9393                bool load_animation( stream& source, const nmd_element_header& e );
    94                 bool load_node( stream& source, mesh_node_data* data, const nmd_element_header& e );
    9594                bool load_channel( stream& source, data_channel_set* channel_set );
    9695                bool load_channel_set( stream& source, data_channel_set* channel_set, const nmd_element_header& e );
    9796
    9897                mesh_nodes_data*            m_node_data;
    99                 mesh_node_data*             m_node_array;
    100 //              vector< uint16 >            m_mesh_names;
    101 //              vector< uint16 >            m_node_names;
    10298                vector< data_channel_set* > m_meshes;
    10399        };
     
    106102        void nmd_dump_header( stream& stream_out, uint32 elements, uint64 name );
    107103        void nmd_dump_strings( stream& stream_out, const string_table& strings );
    108         void nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh );
     104        void nmd_dump_element( stream& stream_out, const data_channel_set& data, nmd_type type );
    109105        void nmd_dump_nodes( stream& stream_out, const mesh_nodes_data& nodes );
    110106        void nmd_dump( stream& stream_out, const mesh_data_pack* model, const string_table* strings = nullptr, uint64 name = 0 );
  • trunk/nv/interface/data_channel_access.hh

    r425 r427  
    141141                const_iterator end()   const { return m_set->end(); }
    142142
    143                 void move_to( data_channel_set& other )
    144                 {
    145                         int change_to_move;
    146                         //                      other.m_name          = m_name;
    147                         for ( uint32 c = 0; c < m_set->m_size; ++c )
    148                         {
    149 //                              if ( other.m_channels[c] ) delete other.m_channels[c];
    150                                 other.m_channels[c] = move( m_set->m_channels[c] );
    151                         }
    152                         other.m_name = m_set->m_name;
    153                         other.m_parent_id = m_set->m_parent_id;
    154                         other.m_transform = m_set->m_transform;
    155                         other.m_size = m_set->m_size;
    156                         m_set->m_size = 0;
    157                 }
    158 
    159143                void set_transform( const mat4& tr ) { m_set->m_transform = tr; }
    160144                const mat4& get_transform() const { return m_set->m_transform; }
  • trunk/nv/interface/mesh_data.hh

    r424 r427  
    2222        using mesh_data = data_channel_set;
    2323
    24 #pragma warning TODO_LIST!
    25         // TODO :
    26         //  * get rid of mesh_node_data, optimize further
    27         //  * properly write and read strings from nmd's
    28         //  * mesh_loader string_table support
    29         //  * properly write strings in other loaders
    30         //  * attribute/property implementation and read/write on every nmd::command
    31         struct mesh_node_data
    32         {
    33                 data_channel_set* data;
    34         };
     24        // TODO : attribute/property implementation and read/write on every nmd::command
    3525
    3626        class mesh_nodes_data
     
    3929                friend class mesh_nodes_creator;
    4030        public:
    41                 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes )
    42                         : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false )
     31                typedef vector< data_channel_set* > storage;
     32                typedef storage::const_iterator const_iterator;
     33
     34                explicit mesh_nodes_data( uint64 name )
     35                        : m_name( name ), m_frame_rate(0), m_duration(0.0f), m_flat( false )
    4336                {
    4437                }
    4538
    46                 explicit mesh_nodes_data( uint64 name, uint32 count, mesh_node_data* nodes,
    47                         uint16 a_fps, float a_frames, bool a_flat )
    48                         : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat )
     39                explicit mesh_nodes_data( uint64 name, uint16 a_fps, float a_frames, bool a_flat )
     40                        : m_name( name ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat )
    4941                {
    5042                }
    5143
    52                 size_t get_count() const { return m_count; }
     44                void push_back( data_channel_set* set )
     45                {
     46                        m_data.push_back( set );
     47                }
     48
     49                size_t get_count() const { return m_data.size(); }
    5350
    5451                bool is_animated( size_t i ) const
    5552                {
    56                         if ( i >= m_count ) return false;
    57                         return ( m_nodes[i].data && m_nodes[i].data->size() > 0 );
     53                        if ( i >= m_data.size() ) return false;
     54                        return ( m_data[i]->size() > 0 );
    5855                }
    5956
    60                 const mesh_node_data* get_node( size_t i ) const
     57                const data_channel_set* get_node( size_t i ) const
    6158                {
    62                         if ( i >= m_count ) return nullptr;
    63                         return &m_nodes[i];
     59                        if ( i >= m_data.size() ) return nullptr;
     60                        return m_data[i];
    6461                }
    6562
    66                 const mesh_node_data* get_node_by_hash( uint64 h ) const
     63                const data_channel_set* get_node_by_hash( uint64 h ) const
    6764                {
    68                         for ( uint32 i = 0; i < m_count; ++i )
     65                        for ( auto data : m_data )
    6966                        {
    70                                 NV_ASSERT( m_nodes[i].data, "data!" );
    71                                 if ( m_nodes[ i ].data->get_name() == h )
    72                                         return &m_nodes[ i ];
     67                                if ( data->get_name() == h ) return data;
    7368                        }
    7469                        return nullptr;
     
    7772                int get_node_index_by_hash( uint64 h ) const
    7873                {
    79                         for ( uint32 i = 0; i < m_count; ++i )
     74                        for ( uint32 i = 0; i < m_data.size(); ++i )
    8075                        {
    81                                 NV_ASSERT( m_nodes[i].data, "data!" );
    82                                 if ( m_nodes[ i ].data->get_name() == h )
     76                                if ( m_data[ i ]->get_name() == h )
    8377                                        return int( i );
    8478                        }
     
    8680                }
    8781
    88 //              data_channel_set* rlease_node_data( size_t i )
    89 //              {
    90 //                      data_channel_set* result = m_nodes[i].data;
    91 //                      m_nodes[i].data = nullptr;
    92 //                      return result;
    93 //              }
     82                const data_channel_set* operator[]( size_t i ) const
     83                {
     84                        return m_data[i];
     85                }
     86
     87                const_iterator begin() const { return m_data.begin(); }
     88                const_iterator end() const { return m_data.end(); }
    9489
    9590                bool is_flat() const { return m_flat; }
     
    10196                ~mesh_nodes_data()
    10297                {
    103                         if ( m_count > 0 )
    104                                 for ( uint32 i = 0; i < m_count; ++i ) delete m_nodes[i].data;
    105                         delete[] m_nodes;
     98                        for ( auto data : m_data ) delete data;
    10699                }
    107100
    108101        private:
     102                vector< data_channel_set* > m_data;
    109103                uint64 m_name;
    110                 uint32 m_count;
    111                 mesh_node_data* m_nodes;
    112104                uint16  m_frame_rate;
    113105                float   m_duration;
  • trunk/nv/stl/memory.hh

    r407 r427  
    137137
    138138                constexpr size_type size() const { return m_size; }
    139                 constexpr bool empty() const { return m_size != 0; }
     139                constexpr bool empty() const { return m_size == 0; }
    140140                constexpr const value_type* data() const { return m_data; }
    141141                constexpr size_type   raw_size() const { return sizeof( value_type ) * m_size; }
  • 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
  • trunk/src/formats/md3_loader.cc

    r425 r427  
    420420        uint32 node_count = uint32( md3->header.num_tags );
    421421        if ( node_count == 0 ) return nullptr;
    422         mesh_node_data* nodes = new mesh_node_data[ node_count ];
     422        mesh_nodes_data* result = new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0 );
    423423        for ( uint32 i = 0; i < node_count; ++i )
    424424        {
    425425                const md3_tag_t& rtag = md3->tags[i];
    426426                string_view name( reinterpret_cast< const char* >(rtag.name) );
    427                 nodes[i].data      = data_channel_set_creator::create_set( 1 );
    428                 data_channel_set_creator access( nodes[i].data );
     427                data_channel_set* set = data_channel_set_creator::create_set( 1 );
     428                data_channel_set_creator access( set );
    429429                access.set_name( make_name( name ) );
    430430                load_tags( access.add_channel<md3_key>( uint32( md3->header.num_frames ) ).channel(), name );
    431         }
    432         return new mesh_nodes_data( m_strings ? m_strings->insert( "tags" ) : 0, node_count, nodes );
     431                result->push_back( set );
     432        }
     433        return result;
    433434}
    434435
  • trunk/src/formats/md5_loader.cc

    r425 r427  
    4646        std_stream sstream( &source );
    4747        std::string command;
    48         mesh_node_data* nodes = nullptr;
    4948        size_t num_joints = 0;
    5049
     
    111110                        assert( m_type == MESH );
    112111                        assert( m_nodes == nullptr );
    113                         nodes = new mesh_node_data[ num_joints ];
    114                         m_nodes = new mesh_nodes_data( make_name( "md5_bones"), num_joints, nodes );
     112                        m_nodes = new mesh_nodes_data( make_name( "md5_bones") );
    115113                        discard( sstream, "{" );
    116114                        for ( size_t i = 0; i < m_nodes->get_count(); ++i )
     
    128126                                unit_quat_w( orient );
    129127                                remove_quotes( name );
    130                                 nodes[i].data      = data_channel_set_creator::create_set( 0 );
    131                                 data_channel_set_creator access( nodes[i].data );
     128                                data_channel_set* set = data_channel_set_creator::create_set( 0 );
     129                                data_channel_set_creator access( set );
    132130                                access.set_parent_id( parent_id );
    133131                                access.set_transform( transform( pos, orient ).inverse().extract() );
    134132                                access.set_name( make_name( name.c_str() ) );
    135133                                next_line( sstream );
     134                                m_nodes->push_back( set );
    136135                        }
    137136                        discard( sstream, "}" );
     
    233232                        }
    234233
    235                         prepare_mesh( nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );
     234                        prepare_mesh( m_nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );
    236235
    237236                        m_meshes[ num_meshes ] = mesh;
     
    241240                {
    242241                        assert( m_type == ANIMATION );
    243                         assert( nodes == nullptr );
    244                         nodes = new mesh_node_data[ num_joints ];
    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 );
     242                        assert( m_nodes == nullptr );
     243                        m_nodes = new mesh_nodes_data( make_name( "md5_animation" ), static_cast< nv::uint16 >( frame_rate ), static_cast< float >( num_frames ), true );
    246244                        joint_infos.resize( num_joints );
    247245
     
    253251                                sstream >> name >> parent_id >> joint_infos[i].flags >> joint_infos[i].start_index;
    254252                                remove_quotes( name );
    255                                 nodes[i].data = data_channel_set_creator::create_set( 1 );
    256                                 data_channel_set_creator access( nodes[i].data );
     253                                data_channel_set* set = data_channel_set_creator::create_set( 1 );
     254                                data_channel_set_creator access( set );
    257255                                access.add_channel< md5_key_t >( num_frames );
    258256                                access.set_name( make_name( name.c_str() ) );
    259257                                access.set_parent_id( parent_id );
     258                                m_nodes->push_back( set );
    260259                                next_line( sstream );
    261260                        }
     
    322321                        }
    323322
    324                         build_frame_skeleton( nodes, frame_id, joint_infos, base_frames, frame );
     323                        build_frame_skeleton( m_nodes, frame_id, joint_infos, base_frames, frame );
    325324
    326325                        discard( sstream, "}" );
     
    334333}
    335334
    336 bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info )
     335bool md5_loader::prepare_mesh( mesh_nodes_data* nodes, uint32 vtx_count, data_channel_set* mdata, md5_weight* weights, md5_weight_info* weight_info )
    337336{
    338337        assert( m_type == MESH );
     
    389388                        if ( j < weight_count )
    390389                        {
    391                                 md5_weight& weight           = weights[start_weight + j];
    392                                 const mesh_node_data&  joint = nodes[weight.joint_id];
    393                                 const transform tr = transform( joint.data->get_transform() ).inverse();
     390                                md5_weight& weight             = weights[start_weight + j];
     391                                const data_channel_set*  joint = (*nodes)[weight.joint_id];
     392                                const transform tr = transform( joint->get_transform() ).inverse();
    394393                                vec3 rot_pos = tr.get_orientation() * weight.pos;
    395394
     
    453452                for ( int j = 0; j < 4; ++j )
    454453                {
    455                         const mesh_node_data&  joint = nodes[vdata.boneindex[j]];
    456                         const transform tr = transform( joint.data->get_transform() ).inverse();
     454                        const data_channel_set*  joint = ( *nodes )[vdata.boneindex[j]];
     455                        const transform tr = transform( joint->get_transform() ).inverse();
    457456                        vdata.normal  += ( normal  * tr.get_orientation() ) * vdata.boneweight[j];
    458457                        vdata.tangent += ( tangent * tr.get_orientation() ) * vdata.boneweight[j];
     
    463462}
    464463
    465 void md5_loader::build_frame_skeleton( mesh_node_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_infos, const array_view<transform>& base_frames, const array_view<float>& frame_data )
     464void md5_loader::build_frame_skeleton( mesh_nodes_data* nodes, uint32 index, const array_view<md5_joint_info>& joint_infos, const array_view<transform>& base_frames, const array_view<float>& frame_data )
    466465{
    467466        assert( m_type == ANIMATION );
     
    471470
    472471                const md5_joint_info& jinfo = joint_infos[i];
    473                 mesh_node_data& joint = nodes[i];
    474                 int parent_id         = joint.data->get_parent_id();
     472                const data_channel_set* joint = (*nodes)[i];
     473                int parent_id         = joint->get_parent_id();
    475474
    476475                vec3 pos    = base_frames[i].get_position();
     
    486485                if ( parent_id >= 0 ) // Has a parent joint
    487486                {
    488                         const mesh_node_data& pjoint = nodes[parent_id];
    489                         const transform* ptv = reinterpret_cast< const transform* >( pjoint.data->get_channel(0)->raw_data() );
     487                        const data_channel_set* pjoint = ( *nodes )[i];
     488                        const transform* ptv = reinterpret_cast< const transform* >( pjoint->get_channel(0)->raw_data() );
    490489                        transform ptr;
    491                         if ( pjoint.data->get_channel(0)->size() > index ) ptr = ptv[ index ];
     490                        if ( pjoint->get_channel(0)->size() > index ) ptr = ptv[ index ];
    492491                        vec3 rot_pos = ptr.get_orientation() * pos;
    493492
     
    498497                }
    499498
    500                 reinterpret_cast< transform* >( const_cast< uint8* >( joint.data->get_channel(0)->raw_data() ) )[index] = transform( pos, orient );
     499                reinterpret_cast< transform* >( const_cast< uint8* >( joint->get_channel(0)->raw_data() ) )[index] = transform( pos, orient );
    501500        }
    502501}
  • trunk/src/formats/nmd_loader.cc

    r425 r427  
    7171
    7272        m_node_data  = nullptr;
    73         m_node_array = nullptr;
    7473}
    7574
     
    10099        nmd_animation_header animation_header;
    101100        source.read( &animation_header, sizeof( animation_header ), 1 );
    102         m_node_array = new mesh_node_data[ e.children ];
     101        m_node_data = new mesh_nodes_data( e.name, animation_header.frame_rate, animation_header.duration, animation_header.flat );
    103102        for ( uint32 i = 0; i < e.children; ++i )
    104103        {
     
    107106                skip_attributes( source, element_header.attributes );
    108107                NV_ASSERT( element_header.type == nmd_type::NODE, "NODE expected!" );
    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 );
    111         }
    112         m_node_data = new mesh_nodes_data( e.name, e.children, m_node_array, animation_header.frame_rate, animation_header.duration, animation_header.flat );
     108                data_channel_set* set = data_channel_set_creator::create_set( element_header.children );
     109                load_channel_set( source, set, element_header );
     110                m_node_data->push_back( set );
     111        }
    113112        return true;
    114113}
     
    144143                mesh_nodes_data* result = m_node_data;
    145144                m_node_data = nullptr;
    146                 m_node_array = nullptr;
    147145                return result;
    148146        }
     
    153151// nmd format dump
    154152// HACK : TEMPORARY - will go to it's own file, probably nmd_io
    155 static void nmd_dump_channel( const raw_data_channel* channel , stream& stream_out )
    156 {
    157         nmd_channel_header sheader;
    158         sheader.format = channel->descriptor();
    159         sheader.count = channel->size();
    160         stream_out.write( &sheader, sizeof( sheader ), 1 );
    161         stream_out.write( channel->raw_data(), channel->element_size(), channel->size() );
    162 }
    163 
    164 static void nmd_dump_channel_set( const data_channel_set* channel_set, stream& stream_out )
    165 {
    166         for ( auto& channel : *channel_set )
    167         {
    168                 nmd_dump_channel( &channel, stream_out );
    169         }
    170 }
    171 
    172 static void nmd_dump_node( const mesh_node_data* node, stream& stream_out )
    173 {
    174         uint32 chan_size = 0;
    175         uint32 chan_count = ( node->data ? node->data->size() : 0 );
    176         for ( uint32 c = 0; c < chan_count; ++c )
    177         {
    178                 chan_size += sizeof( nmd_channel_header );
    179                 chan_size += node->data->get_channel( c )->raw_size();
    180         }
    181 
    182         nmd_element_header eheader;
    183         eheader.type = nmd_type::NODE;
    184         eheader.children   = static_cast<uint16>( chan_count );
    185         eheader.size       = chan_size;
    186         eheader.name       = node->data->get_name();
    187         eheader.parent_id  = node->data->get_parent_id();
    188         eheader.transform  = node->data->get_transform();
    189         eheader.attributes = 0;
    190         stream_out.write( &eheader, sizeof( eheader ), 1 );
    191         if ( chan_count > 0 ) nmd_dump_channel_set( node->data, stream_out );
    192 }
    193153
    194154void nv::nmd_dump_header( stream& stream_out, uint32 elements, uint64 name )
     
    203163}
    204164
    205 void nv::nmd_dump_mesh( stream& stream_out, const data_channel_set& mesh )
     165void nv::nmd_dump_element( stream& stream_out, const data_channel_set& data, nmd_type type )
    206166{
    207167        uint32 size = 0;
    208         for ( auto& chan : mesh )
     168        for ( auto& chan : data )
    209169        {
    210170                size += sizeof( nmd_channel_header );
     
    213173
    214174        nmd_element_header eheader;
    215         eheader.type       = nmd_type::MESH;
    216         eheader.children   = static_cast<uint16>( mesh.size() );
     175        eheader.type       = type;
     176        eheader.children   = static_cast<uint16>( data.size() );
    217177        eheader.size       = size;
    218         eheader.name       = mesh.get_name();
    219         eheader.transform  = mesh.get_transform();
    220         eheader.parent_id  = mesh.get_parent_id();
     178        eheader.name       = data.get_name();
     179        eheader.transform  = data.get_transform();
     180        eheader.parent_id  = data.get_parent_id();
    221181        eheader.attributes = 0;
    222182        stream_out.write( &eheader, sizeof( eheader ), 1 );
    223         nmd_dump_channel_set( &mesh, stream_out );
     183        for ( auto& channel : data )
     184        {
     185                nmd_channel_header cheader;
     186                cheader.format = channel.descriptor();
     187                cheader.count = channel.size();
     188                stream_out.write( &cheader, sizeof( cheader ), 1 );
     189                stream_out.write( channel.raw_data(), channel.element_size(), channel.size() );
     190        }
    224191}
    225192
     
    227194{
    228195        uint32 total = sizeof( nmd_animation_header );
    229         for ( uint32 i = 0; i < nodes.get_count(); ++i )
    230         {
    231                 const mesh_node_data* node = nodes.get_node( i );
     196        for ( auto node : nodes )
     197        {
    232198                total += sizeof( nmd_element_header );
    233                 if ( node->data )
    234                         for ( uint32 c = 0; c < node->data->size(); ++c )
    235                         {
    236                                 total += sizeof( nmd_channel_header );
    237                                 total += node->data->get_channel( c )->raw_size();
    238                         }
     199                for ( uint32 c = 0; c < node->size(); ++c )
     200                {
     201                        total += sizeof( nmd_channel_header );
     202                        total += node->get_channel( c )->raw_size();
     203                }
    239204        }
    240205
     
    256221        stream_out.write( &aheader, sizeof( aheader ), 1 );
    257222
    258         for ( uint32 i = 0; i < nodes.get_count(); ++i )
    259         {
    260                 nmd_dump_node( nodes.get_node( i ), stream_out );
     223        for ( auto node : nodes )
     224        {
     225                nmd_dump_element( stream_out, *node, nv::nmd_type::NODE );
    261226        }
    262227}
     
    284249        for ( uint32 i = 0; i < model->get_count(); ++i )
    285250        {
    286                 nmd_dump_mesh( stream_out, *model->get_mesh( i ) );
     251                nmd_dump_element( stream_out, *model->get_mesh( i ), nv::nmd_type::MESH );
    287252        }
    288253
  • trunk/src/formats/obj_loader.cc

    r425 r427  
    363363        for ( uint32 i = 0; i < size; ++i )
    364364        {
    365                 data_channel_set_creator( m_meshes[i] ).move_to( meshes[i] );
     365                meshes[i] = move( *m_meshes[i] );
    366366                delete m_meshes[i];
    367367        }
  • trunk/src/gfx/keyframed_mesh.cc

    r424 r427  
    4242        if ( m_tag_map && m_tag_map->get_count() > 0 )
    4343        {
    44                 m_interpolation_key = m_tag_map->get_node( 0 )->data->get_interpolation_key();
     44                m_interpolation_key = (*m_tag_map)[ 0 ]->get_interpolation_key();
    4545        }
    4646}
     
    5555        if ( !m_tag_map ) return transform();
    5656        NV_ASSERT( node_id < m_tag_map->get_count(), "TAGMAP FAIL" );
    57         const data_channel_set* data = m_tag_map->get_node( node_id )->data;
    58         NV_ASSERT( data && data->size() > 0, "TAG FAIL" );
    59         raw_channel_interpolator interpolator( data, m_interpolation_key );
     57        NV_ASSERT( (*m_tag_map)[node_id]->size() > 0, "TAG FAIL" );
     58        raw_channel_interpolator interpolator( ( *m_tag_map )[node_id], m_interpolation_key );
    6059        return interpolator.get< transform >( m_last_frame, m_next_frame, m_interpolation );
    6160}
  • trunk/src/gfx/mesh_creator.cc

    r424 r427  
    1818        for ( size_t i = 0; i < m_data->get_count(); ++i )
    1919        {
    20                 sint16 parent_id = m_data->m_nodes[i].data->get_parent_id();
    21                 data_channel_set* keys   = m_data->m_nodes[i].data;
    22                 data_channel_set* pkeys  = ( parent_id != -1 ? m_data->m_nodes[parent_id].data : nullptr );
     20                data_channel_set* keys = m_data->m_data[i];
     21                sint16 parent_id = keys->get_parent_id();
     22                data_channel_set* pkeys  = ( parent_id != -1 ? m_data->m_data[parent_id] : nullptr );
    2323                size_t count     = ( keys ? keys->get_channel_size(0) : 0 );
    2424                size_t pcount    = ( pkeys ? pkeys->get_channel_size(0) : 0 );
     
    5151        for ( size_t i = 0; i < m_data->get_count(); ++i )
    5252        {
    53                 data_channel_set* old_keys = m_data->m_nodes[i].data;
     53                data_channel_set* old_keys = m_data->m_data[i];
    5454                if ( old_keys && old_keys->size() > 0 )
    5555                {
     
    8989
    9090                        delete old_keys;
    91                         m_data->m_nodes[i].data = new_keys;
     91                        m_data->m_data[i] = new_keys;
    9292                }
    9393        }
     
    102102        for ( size_t i = 0; i < m_data->get_count(); ++i )
    103103        {
    104                 mesh_node_data& node = m_data->m_nodes[i];
    105                 node.data->m_transform = pre_transform * node.data->m_transform * post_transform;
    106                 if ( node.data )
    107                 {
    108                         data_channel_set* kdata  = node.data;
    109                         for ( size_t c = 0; c < kdata->size(); ++c )
    110                         {
    111                                 raw_data_channel_access channel( kdata, c );
    112                                 size_t key_size = channel.element_size();
    113                                 for ( size_t n = 0; n < channel.size(); ++n )
    114                                 {
    115                                         transform_key_raw( kdata->get_channel( c )->descriptor(), channel.raw_data() + n * key_size, scale, r33, ri33 );
    116                                 }
     104                data_channel_set* node = m_data->m_data[i];
     105                node->m_transform = pre_transform * node->m_transform * post_transform;
     106
     107                for ( size_t c = 0; c < node->size(); ++c )
     108                {
     109                        raw_data_channel_access channel( node, c );
     110                        size_t key_size = channel.element_size();
     111                        for ( size_t n = 0; n < channel.size(); ++n )
     112                        {
     113                                transform_key_raw( node->get_channel( c )->descriptor(), channel.raw_data() + n * key_size, scale, r33, ri33 );
    117114                        }
    118115                }
     
    458455        if ( index < m_pack->get_count() )
    459456        {
    460                 data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] );
     457
     458                m_pack->m_meshes[index] = move( m_pack->m_meshes[m_pack->m_count - 1] );
    461459                m_pack->m_count--;
    462460        }
  • trunk/src/gfx/skeletal_mesh.cc

    r424 r427  
    2323        for ( uint32 i = 0; i < bones->get_count(); ++i )
    2424        {
    25                 m_bone_offset[i] = transform( bones->get_node(i)->data->get_transform() );
     25                m_bone_offset[i] = transform( (*bones)[i]->get_transform() );
    2626        }
    2727
     
    9393void nv::skeletal_animation_entry_cpu::initialize()
    9494{
    95         for ( size_t i = 0; i < m_node_data->get_count(); ++i )
    96         {
    97                 if ( m_node_data->is_animated( i ) )
    98                 {
    99                         m_interpolation_key = m_node_data->get_node( i )->data->get_interpolation_key();
     95        for ( auto bone : *m_node_data )
     96        {
     97                if ( bone->size() > 0 )
     98                {
     99                        m_interpolation_key = bone->get_interpolation_key();
    100100                        break;
    101101                }
     
    112112        for ( size_t i = 0; i < m_node_data->get_count(); ++i )
    113113        {
    114                 raw_channel_interpolator interpolator( m_node_data->get_node( i )->data, m_interpolation_key );
     114                raw_channel_interpolator interpolator( (*m_node_data)[i], m_interpolation_key );
    115115                skeleton[i] = interpolator.get< transform >( frame_num );
    116116        }
     
    132132                for ( uint32 n = 0; n < node_count; ++n )
    133133                {
    134                         const mesh_node_data* node = m_node_data->get_node(n);
    135                         if ( node->data->get_parent_id() != -1 )
    136                         {
    137                                 m_children[ node->data->get_parent_id()].push_back( n );
     134                        const data_channel_set* node = (*m_node_data)[n];
     135                        if ( node->get_parent_id() != -1 )
     136                        {
     137                                m_children[ node->get_parent_id()].push_back( n );
    138138                        }
    139139                }
     
    156156                if ( m_bone_ids[n] >= 0 )
    157157                {
    158                         const mesh_node_data* node = m_node_data->get_node(n);
    159                         nv::mat4 node_mat( node->data->get_transform() );
    160 
    161                         if ( node->data && node->data->size() > 0 )
    162                         {
    163                                 raw_channel_interpolator interpolator( node->data, m_interpolation_key );
     158                        const data_channel_set* node = m_node_data->get_node(n);
     159                        nv::mat4 node_mat( node->get_transform() );
     160
     161                        if ( node->size() > 0 )
     162                        {
     163                                raw_channel_interpolator interpolator( node, m_interpolation_key );
    164164                                node_mat = interpolator.get< mat4 >( anim_time );
    165165                        }
     
    177177        for ( nv::uint16 bi = 0; bi < bones->get_count(); ++bi )
    178178        {
    179                 const mesh_node_data* bone = bones->get_node(bi);
    180                 bone_names[ bone->data->get_name() ] = bi;
    181                 m_offsets[bi] = bone->data->get_transform();
     179                const data_channel_set* bone = bones->get_node( bi );
     180                bone_names[ bone->get_name() ] = bi;
     181                m_offsets[bi] = bone->get_transform();
    182182        }
    183183
    184184        for ( uint32 n = 0; n < m_node_data->get_count(); ++n )
    185185        {
    186                 const mesh_node_data* node = m_node_data->get_node(n);
     186                const data_channel_set* node = m_node_data->get_node( n );
    187187                sint16 bone_id = -1;
    188188
    189                 auto bi = bone_names.find( node->data->get_name() );
     189                auto bi = bone_names.find( node->get_name() );
    190190                if ( bi != bone_names.end() )
    191191                {
     
    194194                m_bone_ids[n] = bone_id;
    195195
    196                 if ( m_interpolation_key.size() == 0 && node->data->size() > 0 )
    197                         m_interpolation_key = node->data->get_interpolation_key();
     196                if ( m_interpolation_key.size() == 0 && node->size() > 0 )
     197                        m_interpolation_key = node->get_interpolation_key();
    198198
    199199        }
     
    205205        // TODO: fix transforms, which are now embedded,
    206206        //       see note in assimp_loader.cc:load_node
    207         const mesh_node_data* node = m_node_data->get_node( node_id );
    208         mat4 node_mat( node->data->get_transform() );
    209 
    210         if ( node->data && node->data->size() > 0 )
    211         {
    212                 raw_channel_interpolator interpolator( node->data, m_interpolation_key );
     207        const data_channel_set* node = m_node_data->get_node( node_id );
     208        mat4 node_mat( node->get_transform() );
     209
     210        if ( node->size() > 0 )
     211        {
     212                raw_channel_interpolator interpolator( node, m_interpolation_key );
    213213                node_mat = interpolator.get< mat4 >( time );
    214214        }
  • trunk/src/io/string_table.cc

    r425 r427  
    6666        m_data.resize( dsize + 2 + length + 1 );
    6767        *reinterpret_cast<uint16*>( m_data.data() + dsize ) = length;
    68         raw_copy( str, str + length + 1, m_data.data() + dsize + 2 );
     68        if ( length > 0 )
     69                raw_copy( str, str + length, m_data.data() + dsize + 2 );
     70        m_data[dsize + 2 + length] = 0;
    6971        m_map[h] = dsize;
    7072        return dsize;
Note: See TracChangeset for help on using the changeset viewer.