Changeset 284 for trunk/src/formats/assimp_loader.cc
- Timestamp:
- 07/20/14 23:45:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r282 r284 15 15 const int MAX_BONES = 64; 16 16 17 nv::assimp_loader::assimp_loader( const string& a_ext, const mat4& a_rotate_transform, float a_scale, uint32 a_assimp_flags /*= 0 */ ) : m_ext( a_ext ), m_rotate_transform( a_rotate_transform ), m_scale( a_scale ), m_assimp_flags( a_assimp_flags ), m_mesh_count(0), m_scene( nullptr ) 18 { 17 nv::assimp_loader::assimp_loader( const string& a_ext, const mat3& a_rotate_transform, float a_scale, uint32 a_assimp_flags /*= 0 */ ) : m_mesh_count(0), m_scene( nullptr ) 18 { 19 initialize( a_ext, a_rotate_transform, a_scale, a_assimp_flags ); 20 } 21 22 nv::assimp_loader::assimp_loader( const string& a_ext, uint32 a_assimp_flags /*= 0 */ ) : m_mesh_count(0), m_scene( nullptr ) 23 { 24 initialize( a_ext, mat3(), 1.0f, a_assimp_flags ); 25 } 26 27 28 void nv::assimp_loader::initialize( const string& a_ext, const mat3& a_rotate_transform, float a_scale, uint32 a_assimp_flags ) 29 { 30 m_ext = a_ext; 31 m_r33 = a_rotate_transform; 32 m_ri33 = glm::transpose( m_r33 ); 33 m_scale = a_scale; 34 m_assimp_flags = a_assimp_flags; 19 35 if ( m_assimp_flags == 0 ) 20 36 { … … 36 52 } 37 53 38 nv::assimp_loader::assimp_loader( const string& a_ext, uint32 a_assimp_flags /*= 0 */ ) : m_ext( a_ext ), m_rotate_transform(), m_scale( 1.0f ), m_assimp_flags( a_assimp_flags ), m_mesh_count(0), m_scene( nullptr ) 39 { 40 if ( m_assimp_flags == 0 ) 41 { 42 m_assimp_flags = ( 43 aiProcess_CalcTangentSpace | 44 aiProcess_GenSmoothNormals | 45 aiProcess_JoinIdenticalVertices | 46 aiProcess_ImproveCacheLocality | 47 aiProcess_LimitBoneWeights | 48 aiProcess_RemoveRedundantMaterials | 49 aiProcess_SplitLargeMeshes | 50 aiProcess_Triangulate | 51 aiProcess_GenUVCoords | 52 aiProcess_SortByPType | 53 aiProcess_FindDegenerates | 54 aiProcess_FindInvalidData | 55 0 ); 56 } 57 } 54 58 55 bool nv::assimp_loader::load( stream& source ) 59 56 { … … 86 83 const aiMesh* mesh = scene->mMeshes[ index ]; 87 84 88 mat3 scaled_rotatation = glm::mat3( glm::scale( m_scale, m_scale, m_scale ) * m_rotate_transform );89 //mat3 scaled_rotatation = glm::mat3( m_rotate_transform );90 85 vec3 vertex_offset = glm::vec3(); 91 mat3 vertex_transform = scaled_rotatation;92 mat3 normal_transform = glm::mat3( m_rotate_transform );86 mat3 vertex_transform = m_scale * m_r33; 87 mat3 normal_transform = m_r33; 93 88 94 89 bool skinned = mesh->mNumBones > 0; … … 170 165 if ( mesh->mNumBones == 0 ) return false; 171 166 172 mat4 bone_transform = glm::scale( 1.f/m_scale, 1.f/m_scale, 1.f/m_scale ) * glm::inverse( glm::mat4(m_rotate_transform) );173 mat4 bone_pre_transform = glm::scale( m_scale, m_scale, m_scale);167 mat4 bone_transform = mat4( ( 1.f/m_scale * m_ri33 ) ); 168 mat4 bone_pre_transform = mat4( m_scale * m_r33 ); 174 169 175 170 for (unsigned int m=0; m<mesh->mNumBones; m++) … … 291 286 } 292 287 } 293 if ( m > 0 )288 if ( m > 0 && bones.size() > 0 ) 294 289 { 295 290 mesh_data* mesh = model->meshes[m]; … … 318 313 if ( m_scene == nullptr ) return nullptr; 319 314 const aiScene* scene = (const aiScene*)m_scene; 320 if ( scene->mRootNode == nullptr || scene->mAnimations [0] == nullptr) return nullptr;315 if ( scene->mRootNode == nullptr || scene->mAnimations == nullptr || scene->mAnimations[0] == nullptr) return nullptr; 321 316 assimp_animation* result = new assimp_animation; 322 317 … … 370 365 // node's without keys 371 366 a_data.transform = nv::assimp_mat4_cast( node->mTransformation ); 367 if (this_id == 0) 368 a_data.transform = mat4(); 372 369 a_data.channel_count = 0; 373 370 … … 405 402 size_t pn = glm::min( node->mNumPositionKeys - 1, n ); 406 403 size_t rn = glm::min( node->mNumRotationKeys - 1, n ); 407 nv::vec3 pos = nv::assimp_vec3_cast(node->mPositionKeys[pn].mValue);408 nv::quat rot = nv::assimp_quat_cast(node->mRotationKeys[rn].mValue);404 nv::vec3 pos = m_r33 * nv::assimp_vec3_cast(node->mPositionKeys[pn].mValue) * m_scale; 405 nv::quat rot = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[rn].mValue ) ) * m_ri33 ); 409 406 // TODO: only do the calculation when a rotate transform is present! 410 nv::transform ptr ( vec3(), glm::quat_cast( m_rotate_transform ) );407 nv::transform ptr; 411 408 if ( parent ) 412 409 { … … 417 414 } 418 415 } 419 nv::transform key( ptr * nv::transform( pos * m_scale, rot ) ); 416 417 nv::transform key( ptr * nv::transform( pos, rot ) ); 420 418 channel[n].tform = key; 421 419 } … … 425 423 { 426 424 data->channel_count = 0; 427 // TODO : support for m_rotate_transform and m_scale! ( should be easy )428 425 const aiNodeAnim* node = (const aiNodeAnim*)vnode; 429 426 if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) … … 443 440 { 444 441 pchannel[np].time = (float)node->mPositionKeys[np].mTime; 445 pchannel[np].position = assimp_vec3_cast(node->mPositionKeys[np].mValue);442 pchannel[np].position = m_r33 * assimp_vec3_cast(node->mPositionKeys[np].mValue) * m_scale; 446 443 } 447 444 for ( unsigned np = 0; np < node->mNumRotationKeys; ++np ) 448 445 { 449 446 rchannel[np].time = (float)node->mRotationKeys[np].mTime; 450 rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue);447 rchannel[np].rotation = glm::quat_cast( m_r33 * glm::mat3_cast( assimp_quat_cast(node->mRotationKeys[np].mValue ) ) * m_ri33 ); 451 448 } 452 449 if ( node->mNumScalingKeys > 0 ) … … 463 460 } 464 461 } 465 } 466 } 467 462 else 463 { 464 schannel[0].time = (float)node->mScalingKeys[0].mTime; 465 schannel[0].scale = assimp_vec3_cast(node->mScalingKeys[0].mValue); 466 } 467 } 468 469 } 470
Note: See TracChangeset
for help on using the changeset viewer.