- Timestamp:
- 08/13/15 20:51:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/mesh_creator.cc
r456 r457 345 345 tan.y, 346 346 tan.x * r21 + tan.z * r22, 347 1.0f// make sure this is proper347 tan.w // make sure this is proper 348 348 ); 349 349 } 350 350 351 351 352 } 353 354 void nv::mesh_data_creator::mirror( bool x, bool z ) 355 { 356 if ( !x && !z ) return; 357 NV_ASSERT( m_pos_type == FLOAT_VECTOR_3, "Unsupported position vector type!" ); 358 NV_ASSERT( m_nrm_type == FLOAT_VECTOR_3, "Unsupported normal vector type!" ); 359 NV_ASSERT( m_tan_type == FLOAT_VECTOR_4, "Unsupported tangent vector type!" ); 360 361 float kx = x ? -1.0f : 1.0f; 362 float kz = z ? -1.0f : 1.0f; 363 364 unsigned vtx_count = m_pos_channel->size(); 365 uint8* pos_data = raw_data_channel_access( m_pos_channel ).raw_data(); 366 uint8* nrm_data = raw_data_channel_access( m_nrm_channel ).raw_data(); 367 uint8* tan_data = raw_data_channel_access( m_tan_channel ).raw_data(); 368 for ( unsigned int i = 0; i < vtx_count; ++i ) 369 { 370 vec3& pos = *reinterpret_cast<vec3*>( pos_data + m_pos_channel->element_size() * i + m_pos_offset ); 371 vec3& nrm = *reinterpret_cast<vec3*>( nrm_data + m_nrm_channel->element_size() * i + m_nrm_offset ); 372 vec4& tan = *reinterpret_cast<vec4*>( tan_data + m_tan_channel->element_size() * i + m_tan_offset ); 373 374 pos = vec3( 375 pos.x * kx, 376 pos.y, 377 pos.z * kz 378 ); 379 nrm = vec3( 380 nrm.x * kx, 381 nrm.y, 382 nrm.z * kz 383 ); 384 tan = vec4( 385 tan.x * kx, 386 tan.y, 387 tan.z * kz, 388 tan.w * kx * kz// make sure this is proper 389 ); 390 } 391 392 if ( !( x && z ) ) 393 swap_culling(); 394 } 395 396 template < typename T > 397 static inline void swap_culling_impl( nv::raw_data_channel* index_channel ) 398 { 399 nv::raw_data_channel_access ichannel( index_channel ); 400 T* indices = reinterpret_cast<T*>( ichannel.raw_data() ); 401 nv::uint32 count = index_channel->size() / 3; 402 for ( nv::uint32 i = 0; i < count; ++i ) 403 { 404 nv::swap( indices[i * 3], indices[i * 3 + 1] ); 405 } 406 } 407 408 void nv::mesh_data_creator::swap_culling() 409 { 410 NV_ASSERT( m_idx_channel, "Swap culling unsupported on non-indexed meshes!" ); 411 NV_ASSERT( m_idx_channel->descriptor().size() == 1, "Malformed index channel!" ); 412 NV_ASSERT( m_idx_channel->size() % 3 == 0, "Malformed index channel - not per GL_TRIANGLE LAYOUT?" ); 413 414 if ( m_idx_channel->size() == 0 ) return; 415 switch ( m_idx_type ) 416 { 417 case USHORT: swap_culling_impl< uint16 >( m_idx_channel ); break; 418 case UINT: swap_culling_impl< uint16 >( m_idx_channel ); break; 419 default: NV_ASSERT( false, "Swap culling supports only unsigned and unsigned short indices!" ); break; 420 } 352 421 } 353 422 … … 477 546 478 547 479 bool nv::mesh_data_creator::is_same_format( data_channel_set* other )548 bool nv::mesh_data_creator::is_same_format( const data_channel_set* other ) 480 549 { 481 550 if ( m_data->size() != other->size() ) return false; … … 488 557 } 489 558 490 void nv::mesh_data_creator::merge( data_channel_set* other )559 void nv::mesh_data_creator::merge( const data_channel_set* other ) 491 560 { 492 561 if ( !is_same_format( other ) ) return;
Note: See TracChangeset
for help on using the changeset viewer.