Changeset 406 for trunk/src/formats/md3_loader.cc
- Timestamp:
- 06/20/15 00:05:17 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/md3_loader.cc
r399 r406 267 267 nv::md3_loader::~md3_loader() 268 268 { 269 if (m_md3 != nullptr) 270 { 271 free_md3( (md3_t*)(m_md3) ); 272 delete (md3_t*)m_md3; 269 md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 ); 270 if ( md3 != nullptr ) 271 { 272 free_md3( md3 ); 273 delete md3; 273 274 } 274 275 } … … 276 277 bool nv::md3_loader::load( stream& source ) 277 278 { 278 m_md3 = (void*)(new md3_t); 279 if ( !read_md3( (md3_t*)m_md3, source ) ) 279 md3_t* md3 = new md3_t; 280 m_md3 = md3; 281 if ( !read_md3( md3, source ) ) 280 282 { 281 283 return false; … … 286 288 nv::key_raw_channel* nv::md3_loader::load_tags( const string_view& tag ) 287 289 { 288 md3_t* md3 = (md3_t*)m_md3;289 key_raw_channel* result = key_raw_channel::create<md3_key>( (uint32)md3->header.num_frames);290 md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 ); 291 key_raw_channel* result = key_raw_channel::create<md3_key>( uint32( md3->header.num_frames ) ); 290 292 // TODO: is this brain damaged in efficiency (loop nest order) or what? 291 293 for ( sint32 f = 0; f < md3->header.num_frames; ++f ) … … 294 296 { 295 297 const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags * f]; 296 string_view rname( (char*)(rtag.name));298 string_view rname( reinterpret_cast< const char* >(rtag.name) ); 297 299 if (rname == tag) 298 300 { … … 301 303 vec3 axisy ( md3_vec3( rtag.axis[2] ) ); 302 304 vec3 origin ( md3_vec3( rtag.origin ) ); 303 ((md3_key*)(result->data))[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) );305 reinterpret_cast< md3_key*>(result->data)[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) ); 304 306 } 305 307 } … … 323 325 { 324 326 mesh_data* data = new mesh_data; 325 release_mesh_frame( data, -1, (sint32)index);327 release_mesh_frame( data, -1, static_cast< sint32 >( index ) ); 326 328 return data; 327 329 } … … 329 331 void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface ) 330 332 { 331 md3_t* md3 = (md3_t*)m_md3;332 uint32 num_surfaces = (uint32)md3->header.num_surfaces;333 uint32 num_verts = 0;334 uint32 current_frame = ( frame == -1 ? 0 : (uint32)frame );335 uint32 frame_count = ( frame == -1 ? (uint32)md3->header.num_frames : 1 );336 uint32 current_surf = ( surface == -1 ? 0 : (uint32)surface );337 uint32 surf_count = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );338 uint32 index_count = 0;333 md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 ); 334 sint32 num_surfaces = md3->header.num_surfaces; 335 sint32 num_verts = 0; 336 sint32 current_frame = ( frame == -1 ? 0 : frame ); 337 sint32 frame_count = ( frame == -1 ? md3->header.num_frames : 1 ); 338 sint32 current_surf = ( surface == -1 ? 0 : surface ); 339 sint32 surf_count = ( surface == -1 ? md3->header.num_surfaces : 1 ); 340 sint32 index_count = 0; 339 341 340 342 if ( surface >= 0 ) 341 343 { 342 index_count = (uint32)md3->surfaces[(uint32)surface].header.num_triangles * 3;343 num_verts = (uint32)md3->surfaces[(uint32)surface].header.num_verts;344 index_count = md3->surfaces[surface].header.num_triangles * 3; 345 num_verts = md3->surfaces[surface].header.num_verts; 344 346 } 345 347 else 346 for ( uint32 i = 0; i < num_surfaces; ++i )347 { 348 index_count += (uint32)md3->surfaces[i].header.num_triangles * 3;349 num_verts += (uint32)md3->surfaces[i].header.num_verts;350 } 351 352 mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( num_verts * frame_count);353 mesh_raw_channel* mc_t = mesh_raw_channel::create< vtx_md3_t >( num_verts);354 mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count);355 vtx_md3_pn* vtx_pn = (vtx_md3_pn*)mc_pn->data;356 vtx_md3_t* vtx_t = (vtx_md3_t*) mc_t->data;357 uint16* icp = (uint16*)ic->data;348 for ( sint32 i = 0; i < num_surfaces; ++i ) 349 { 350 index_count += md3->surfaces[i].header.num_triangles * 3; 351 num_verts += md3->surfaces[i].header.num_verts; 352 } 353 354 mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) ); 355 mesh_raw_channel* mc_t = mesh_raw_channel::create< vtx_md3_t >( uint32( num_verts ) ); 356 mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( uint32( index_count ) ); 357 vtx_md3_pn* vtx_pn = reinterpret_cast< vtx_md3_pn* >( mc_pn->data ); 358 vtx_md3_t* vtx_t = reinterpret_cast< vtx_md3_t* >( mc_t->data ); 359 uint16* icp = reinterpret_cast< uint16* >( ic->data ); 358 360 359 361 uint32 index = 0; … … 387 389 while ( frame_count > 0 ) 388 390 { 389 current_surf = ( surface == -1 ? 0 : (uint32)surface );390 surf_count = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );391 current_surf = ( surface == -1 ? 0 : surface ); 392 surf_count = ( surface == -1 ? md3->header.num_surfaces : 1 ); 391 393 392 394 while ( surf_count > 0 ) 393 395 { 394 396 md3_surface_t& sface = md3->surfaces[current_surf]; 395 uint32 vcount = (uint32)sface.header.num_verts;396 uint32offset = vcount * current_frame;397 uint32limit = vcount + offset;398 for ( uint32 j = offset; j < limit; ++j )397 sint32 vcount = sface.header.num_verts; 398 sint32 offset = vcount * current_frame; 399 sint32 limit = vcount + offset; 400 for ( sint32 j = offset; j < limit; ++j ) 399 401 { 400 402 md3_vertex_t& v = sface.vertices[j]; … … 410 412 } 411 413 412 data->set_name( (char*)md3->header.name);414 data->set_name( reinterpret_cast< char* >( md3->header.name ) ); 413 415 data->add_channel( mc_pn ); 414 416 data->add_channel( mc_t ); … … 418 420 mesh_nodes_data* nv::md3_loader::release_mesh_nodes_data( nv::size_t ) 419 421 { 420 md3_t* md3 = (md3_t*)m_md3;421 uint32 node_count = (uint32)md3->header.num_tags;422 md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 ); 423 uint32 node_count = uint32( md3->header.num_tags ); 422 424 if ( node_count == 0 ) return nullptr; 423 425 mesh_node_data* nodes = new mesh_node_data[ node_count ]; … … 425 427 { 426 428 const md3_tag_t& rtag = md3->tags[i]; 427 string_view name( (char*)(rtag.name) );429 string_view name( reinterpret_cast< const char* >(rtag.name) ); 428 430 429 431 nodes[i].transform = mat4(); … … 441 443 mesh_data_pack* nv::md3_loader::release_mesh_data_pack() 442 444 { 443 md3_t* md3 = (md3_t*)m_md3;444 uint32count = 1;445 md3_t* md3 = reinterpret_cast<md3_t*>( m_md3 ); 446 int count = 1; 445 447 mesh_data* data = nullptr; 446 448 if ( m_merge_all ) … … 448 450 data = new mesh_data[1]; 449 451 release_mesh_frame( &data[0], -1, -1 ); 450 data[0].set_name( (char*)md3->header.name);452 data[0].set_name( reinterpret_cast< char* >( md3->header.name ) ); 451 453 } 452 454 else 453 455 { 454 count = (uint32)md3->header.num_surfaces;456 count = md3->header.num_surfaces; 455 457 data = new mesh_data[ count ]; 456 for ( uint32i = 0; i < count; ++i )457 { 458 release_mesh_frame( &data[i], -1, (sint32)i );459 data[i].set_name( (char*)md3->surfaces[i].header.name);460 } 461 } 462 return new mesh_data_pack( count, data, release_mesh_nodes_data() );458 for ( int i = 0; i < count; ++i ) 459 { 460 release_mesh_frame( &data[i], -1, i ); 461 data[i].set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) ); 462 } 463 } 464 return new mesh_data_pack( uint32( count ), data, release_mesh_nodes_data() ); 463 465 } 464 466 465 467 nv::size_t md3_loader::get_max_frames() const 466 468 { 467 return static_cast< size_t >( ((md3_t*)m_md3)->header.num_frames );468 } 469 return static_cast<size_t>( reinterpret_cast<md3_t*>( m_md3 )->header.num_frames ); 470 }
Note: See TracChangeset
for help on using the changeset viewer.