Changeset 415 for trunk/src/formats
- Timestamp:
- 07/09/15 20:02:58 (10 years ago)
- Location:
- trunk/src/formats
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r413 r415 117 117 118 118 bool skinned = mesh->mNumBones > 0; 119 raw_data_channel* channel = nullptr; 119 120 data_descriptor desc; 120 121 if ( skinned ) 121 channel = raw_data_channel::create< assimp_skinned_vtx >( mesh->mNumVertices);122 desc.initialize< assimp_skinned_vtx >(); 122 123 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 127 128 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 else143 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 } 145 146 146 147 if ( skinned ) … … 179 180 } 180 181 } 182 data->add_channel( channel.release() ); 181 183 data->add_channel( ichannel.release() ); 182 184 } -
trunk/src/formats/md5_loader.cc
r413 r415 137 137 assert( m_type == MESH ); 138 138 mesh_data* mesh = new mesh_data("md5_mesh"); 139 raw_data_channel* ch_pntiw = nullptr;140 139 141 140 uint32 num_verts = 0; … … 160 159 md5_vtx_t* tdata = nullptr; 161 160 { 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 ); 165 164 tdata = ch_t.data(); 166 165 mesh->add_channel( ch_pnt.release() ); … … 168 167 // TODO: hack to prevent rendering 169 168 //ch_pntiw->m_count = 0; 170 mesh->add_channel( ch_pntiw );169 mesh->add_channel( ch_pntiw.release() ); 171 170 } 172 171 weight_info.resize( num_verts ); … … 236 235 } 237 236 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() ); 239 238 240 239 m_meshes[ num_meshes ] = mesh; … … 258 257 nodes[i].target_id = -1; 259 258 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() ); 261 261 next_line( sstream ); 262 262 } … … 335 335 } 336 336 337 bool md5_loader::prepare_mesh( m d5_vtx_pntiw* vtx_data, mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info )337 bool md5_loader::prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info ) 338 338 { 339 339 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(); 342 344 343 345 for ( uint32 i = 0; i < vtx_count; ++i ) … … 488 490 const transform* ptv = reinterpret_cast< const transform* >( pjoint.data->get_channel(0)->raw_data() ); 489 491 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 ]; 491 493 vec3 rot_pos = ptr.get_orientation() * pos; 492 494 -
trunk/src/formats/nmd_loader.cc
r413 r415 189 189 nmd_stream_header sheader; 190 190 sheader.format = chan->descriptor(); 191 sheader.count = chan-> element_count();191 sheader.count = chan->size(); 192 192 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() ); 194 194 } 195 195 } … … 257 257 nmd_stream_header cheader; 258 258 cheader.format = channel->descriptor(); 259 cheader.count = channel-> element_count();259 cheader.count = channel->size(); 260 260 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() ); 262 262 } 263 263 }
Note: See TracChangeset
for help on using the changeset viewer.