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/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}
Note: See TracChangeset for help on using the changeset viewer.