Changeset 287 for trunk/src/formats/assimp_loader.cc
- Timestamp:
- 07/23/14 15:24:03 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r285 r287 79 79 { 80 80 if ( index >= m_mesh_count ) return nullptr; 81 mesh_data* result = new mesh_data(); 81 mesh_data* result = new mesh_data; 82 load_mesh_data( result, index ); 83 return result; 84 } 85 void nv::assimp_loader::load_mesh_data( mesh_data* data, size_t index ) 86 { 82 87 const aiScene* scene = (const aiScene*)m_scene; 83 88 const aiMesh* mesh = scene->mMeshes[ index ]; 89 data->set_name( mesh->mName.data ); 84 90 85 91 vec3 vertex_offset = glm::vec3(); … … 94 100 channel = mesh_raw_channel::create< assimp_plain_vtx >( mesh->mNumVertices ); 95 101 96 result->add_channel( channel );102 data->add_channel( channel ); 97 103 for (unsigned int i=0; i<mesh->mNumVertices; i++) 98 104 { … … 139 145 140 146 mesh_raw_channel* ichannel = mesh_raw_channel::create_index( USHORT, mesh->mNumFaces * 3 ); 141 result->add_channel( ichannel );147 data->add_channel( ichannel ); 142 148 uint16* indices = (uint16*)ichannel->data; 143 149 for (unsigned int i=0; i<mesh->mNumFaces; i++) … … 149 155 } 150 156 } 151 152 return result;153 157 } 154 158 … … 322 326 const aiAnimation* anim = scene->mAnimations[0]; // if implemented, change in load_node also 323 327 324 result->f ps = (float)anim->mTicksPerSecond;328 result->frame_rate = (uint16)anim->mTicksPerSecond; 325 329 result->duration = (float)anim->mDuration; 326 result->pretransformed = pre_transform; 330 result->flat = pre_transform; 331 result->max_frames = 0; 327 332 328 333 load_node( result, root, 0, -1 ); 334 335 // DAE pre_transform hack 336 if ( result->flat && result->frame_rate == 1 ) 337 { 338 result->frame_rate = 32; 339 result->duration = (float)result->max_frames; 340 } 341 329 342 return result; 330 343 } … … 371 384 if (anode) 372 385 { 373 if ( data-> pretransformed)386 if ( data->flat ) 374 387 { 375 388 create_transformed_keys( &a_data, anode, parent_id >= 0 ? &(data->nodes[ parent_id ]) : nullptr ); … … 379 392 create_direct_keys( &a_data, anode ); 380 393 } 394 data->max_frames = glm::max<uint32>( a_data.data->get_channel(0)->count, data->max_frames ); 381 395 } 382 396 … … 386 400 next = load_node( data, node->mChildren[i], next, this_id ); 387 401 } 402 388 403 return next; 389 404 } … … 432 447 key_raw_channel* raw_pchannel = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys ); 433 448 key_raw_channel* raw_rchannel = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys ); 434 key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys );449 //key_raw_channel* raw_schannel = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys ); 435 450 data->data->add_channel( raw_pchannel ); 436 451 data->data->add_channel( raw_rchannel ); 437 data->data->add_channel( raw_schannel );452 //data->data->add_channel( raw_schannel ); 438 453 assimp_key_p* pchannel = ((assimp_key_p*)(raw_pchannel->data)); 439 454 assimp_key_r* rchannel = ((assimp_key_r*)(raw_rchannel->data)); 440 assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data));455 //assimp_key_s* schannel = ((assimp_key_s*)(raw_schannel->data)); 441 456 442 457 for ( unsigned np = 0; np < node->mNumPositionKeys; ++np ) … … 450 465 rchannel[np].rotation = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[np].mValue ) ) * m_ri33 ); 451 466 } 452 if ( node->mNumScalingKeys > 0 ) 453 { 454 nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue ); 455 float scale_value = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) ); 456 if ( node->mNumScalingKeys > 1 || scale_value > 0.001 ) 457 { 458 NV_LOG( nv::LOG_WARNING, "scale key significant!" ); 459 for ( unsigned np = 0; np < node->mNumRotationKeys; ++np ) 460 { 461 schannel[np].time = (float)node->mScalingKeys[np].mTime; 462 schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue); 463 } 464 } 465 else 466 { 467 schannel[0].time = (float)node->mScalingKeys[0].mTime; 468 schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue); 469 } 470 } 471 472 } 473 467 // if ( node->mNumScalingKeys > 0 ) 468 // { 469 // nv::vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue ); 470 // float scale_value = glm::length( glm::abs( scale_vec0 - nv::vec3(1,1,1) ) ); 471 // if ( node->mNumScalingKeys > 1 || scale_value > 0.001 ) 472 // { 473 // NV_LOG( nv::LOG_WARNING, "scale key significant!" ); 474 // for ( unsigned np = 0; np < node->mNumRotationKeys; ++np ) 475 // { 476 // schannel[np].time = (float)node->mScalingKeys[np].mTime; 477 // schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue); 478 // } 479 // } 480 // else 481 // { 482 // schannel[0].time = (float)node->mScalingKeys[0].mTime; 483 // schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue); 484 // } 485 // } 486 487 } 488 489 mesh_data_pack* nv::assimp_loader::release_mesh_data_pack() 490 { 491 mesh_data* meshes = new mesh_data[ m_mesh_count ]; 492 for ( uint32 i = 0; i < m_mesh_count; ++i ) 493 { 494 load_mesh_data(&meshes[i],i); 495 } 496 return new mesh_data_pack( m_mesh_count, meshes, release_mesh_nodes_data() ); 497 } 498 499 mesh_nodes_data* nv::assimp_loader::release_mesh_nodes_data() 500 { 501 // TODO: implement 502 return nullptr; 503 } 504
Note: See TracChangeset
for help on using the changeset viewer.