Changeset 415 for trunk/src/formats


Ignore:
Timestamp:
07/09/15 20:02:58 (10 years ago)
Author:
epyon
Message:
  • naming scheme for data_descriptor changed
  • channels can only be created by data_channel_creators
Location:
trunk/src/formats
Files:
3 edited

Legend:

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

    r413 r415  
    117117
    118118        bool skinned = mesh->mNumBones > 0;
    119         raw_data_channel* channel = nullptr;
     119
     120        data_descriptor desc;
    120121        if ( skinned )
    121                 channel = raw_data_channel::create< assimp_skinned_vtx >( mesh->mNumVertices );
     122                desc.initialize< assimp_skinned_vtx >();
    122123        else
    123                 channel = raw_data_channel::create< assimp_plain_vtx >( mesh->mNumVertices );
    124         uint8* cdata = const_cast< uint8*>( channel->raw_data() );
    125 
    126         data->add_channel( channel );
     124                desc.initialize< assimp_plain_vtx >();
     125        raw_data_channel_creator channel( desc, mesh->mNumVertices );
     126        uint8* cdata = channel.raw_data();
     127
    127128        if ( mesh->mTangents && mesh->mBitangents )
    128         for (unsigned int i=0; i<mesh->mNumVertices; i++)
    129         {
    130                 vec3 v = assimp_vec3_cast( mesh->mVertices[ i ] );
    131                 vec3 n = glm::normalize( assimp_vec3_cast( mesh->mNormals[ i ] ) );
    132                 vec3 t = glm::normalize( assimp_vec3_cast( mesh->mTangents[ i ] ) );
    133                 vec3 b = glm::normalize( assimp_vec3_cast( mesh->mBitangents[ i ] ) );
    134                 vec2 s = assimp_st_cast( mesh->mTextureCoords[ 0 ][ i ] );
    135 
    136                 glm::vec3 t_i = glm::normalize (t - n * glm::dot (n, t));
    137                 float det = (glm::dot (glm::cross (n, t), b));
    138                 det = (det < 0.0f ? -1.0f : 1.0f );
    139                 nv::vec4 vt ( t_i[0], t_i[1], t_i[2], det );
    140                 if ( skinned )
    141                         reinterpret_cast< assimp_skinned_vtx* >( cdata )[i] = assimp_skinned_vtx( v, s, n, vt );
    142                 else
    143                         reinterpret_cast< assimp_plain_vtx* >( cdata )[i] = assimp_plain_vtx( v, s, n, vt );
    144         }
     129                for ( unsigned int i = 0; i < mesh->mNumVertices; i++ )
     130                {
     131                        vec3 v = assimp_vec3_cast( mesh->mVertices[i] );
     132                        vec3 n = glm::normalize( assimp_vec3_cast( mesh->mNormals[i] ) );
     133                        vec3 t = glm::normalize( assimp_vec3_cast( mesh->mTangents[i] ) );
     134                        vec3 b = glm::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) );
     135                        vec2 s = assimp_st_cast( mesh->mTextureCoords[0][i] );
     136
     137                        glm::vec3 t_i = glm::normalize( t - n * glm::dot( n, t ) );
     138                        float det = ( glm::dot( glm::cross( n, t ), b ) );
     139                        det = ( det < 0.0f ? -1.0f : 1.0f );
     140                        nv::vec4 vt( t_i[0], t_i[1], t_i[2], det );
     141                        if ( skinned )
     142                                reinterpret_cast<assimp_skinned_vtx*>( cdata )[i] = assimp_skinned_vtx( v, s, n, vt );
     143                        else
     144                                reinterpret_cast<assimp_plain_vtx*>( cdata )[i] = assimp_plain_vtx( v, s, n, vt );
     145                }
    145146
    146147        if ( skinned )
     
    179180                }
    180181        }
     182        data->add_channel( channel.release() );
    181183        data->add_channel( ichannel.release() );
    182184}
  • trunk/src/formats/md5_loader.cc

    r413 r415  
    137137                        assert( m_type == MESH );
    138138                        mesh_data* mesh = new mesh_data("md5_mesh");
    139                         raw_data_channel* ch_pntiw = nullptr;
    140139
    141140                        uint32 num_verts   = 0;
     
    160159                                        md5_vtx_t* tdata = nullptr;
    161160                                        {
    162                                                 data_channel_creator<md5_vtx_pnt> ch_pnt( num_verts );
    163                                                 data_channel_creator<md5_vtx_t>   ch_t( num_verts );
    164                                                 ch_pntiw = raw_data_channel::create<md5_vtx_pntiw>( num_verts );
     161                                                data_channel_creator<md5_vtx_pnt>   ch_pnt( num_verts );
     162                                                data_channel_creator<md5_vtx_t>     ch_t( num_verts );
     163                                                data_channel_creator<md5_vtx_pntiw> ch_pntiw( num_verts );
    165164                                                tdata = ch_t.data();
    166165                                                mesh->add_channel( ch_pnt.release() );
     
    168167                                                // TODO: hack to prevent rendering
    169168                                                //ch_pntiw->m_count = 0;
    170                                                 mesh->add_channel( ch_pntiw );
     169                                                mesh->add_channel( ch_pntiw.release() );
    171170                                        }
    172171                                        weight_info.resize( num_verts );
     
    236235                        }
    237236
    238                         prepare_mesh( reinterpret_cast< md5_vtx_pntiw* >( const_cast< uint8* >( ch_pntiw->raw_data() ) ), nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );
     237                        prepare_mesh( nodes, weight_info.size(), mesh, weights.data(), weight_info.data() );
    239238
    240239                        m_meshes[ num_meshes ] = mesh;
     
    258257                                nodes[i].target_id = -1;
    259258                                nodes[i].data      = new key_data;
    260                                 nodes[i].data->add_channel( raw_data_channel::create< md5_key_t >( num_frames ) );
     259                                data_channel_creator< md5_key_t > fc( num_frames );
     260                                nodes[i].data->add_channel( fc.release() );
    261261                                next_line( sstream );
    262262                        }
     
    335335}
    336336
    337 bool md5_loader::prepare_mesh( md5_vtx_pntiw* vtx_data, mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
     337bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )
    338338{
    339339        assert( m_type == MESH );
    340         data_channel_creator< md5_vtx_pnt > pnt( const_cast< raw_data_channel* >( mdata->get_channel< md5_vtx_pnt >() ) );
    341         md5_vtx_pnt* vtcs       = pnt.data();
     340        data_channel_creator< md5_vtx_pnt >   pnt  ( const_cast< raw_data_channel* >( mdata->get_channel< md5_vtx_pnt >() ) );
     341        data_channel_creator< md5_vtx_pntiw > pntiw( const_cast< raw_data_channel* >( mdata->get_channel< md5_vtx_pntiw >() ) );
     342        md5_vtx_pntiw* vtx_data = pntiw.data();
     343        md5_vtx_pnt* vtcs = pnt.data();
    342344
    343345        for ( uint32 i = 0; i < vtx_count; ++i )
     
    488490                        const transform* ptv = reinterpret_cast< const transform* >( pjoint.data->get_channel(0)->raw_data() );
    489491                        transform ptr;
    490                         if ( pjoint.data->get_channel(0)->element_count() > index ) ptr = ptv[ index ];
     492                        if ( pjoint.data->get_channel(0)->size() > index ) ptr = ptv[ index ];
    491493                        vec3 rot_pos = ptr.get_orientation() * pos;
    492494
  • trunk/src/formats/nmd_loader.cc

    r413 r415  
    189189                nmd_stream_header sheader;
    190190                sheader.format = chan->descriptor();
    191                 sheader.count  = chan->element_count();
     191                sheader.count  = chan->size();
    192192                stream_out.write( &sheader, sizeof( sheader ), 1 );
    193                 stream_out.write( chan->raw_data(), chan->element_size(), chan->element_count() );
     193                stream_out.write( chan->raw_data(), chan->element_size(), chan->size() );
    194194        }
    195195}
     
    257257                        nmd_stream_header cheader;
    258258                        cheader.format    = channel->descriptor();
    259                         cheader.count     = channel->element_count();
     259                        cheader.count     = channel->size();
    260260                        stream_out.write( &cheader, sizeof( cheader ), 1 );
    261                         stream_out.write( channel->raw_data(), channel->element_size(), channel->element_count() );
     261                        stream_out.write( channel->raw_data(), channel->element_size(), channel->size() );
    262262                }
    263263        }
Note: See TracChangeset for help on using the changeset viewer.