Changeset 284 for trunk/src/formats
- Timestamp:
- 07/20/14 23:45:56 (11 years ago)
- Location:
- trunk/src/formats
- Files:
-
- 2 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 -
trunk/src/formats/nmd_loader.cc
r283 r284 22 22 switch ( element_header.type ) 23 23 { 24 case nmd_type::MESH : load_mesh( source, element_header .children); break;25 case nmd_type::ANIMATION : load_animation( source, element_header .children); break;26 case nmd_type::BONE_ARRAY : load_bones( source, element_header .children); break;24 case nmd_type::MESH : load_mesh( source, element_header ); break; 25 case nmd_type::ANIMATION : load_animation( source, element_header ); break; 26 case nmd_type::BONE_ARRAY : load_bones( source, element_header ); break; 27 27 case nmd_type::STRING_TABLE : load_strings( source ); break; 28 28 default: NV_ASSERT( false, "UNKNOWN NMD ELEMENT!" ); break; … … 32 32 } 33 33 34 bool nv::nmd_loader::load_mesh( stream& source, uint32 children)34 bool nv::nmd_loader::load_mesh( stream& source, const nmd_element_header& e ) 35 35 { 36 36 mesh_data* mesh = new mesh_data(); 37 for ( uint32 s = 0; s < children; ++s )37 for ( uint32 s = 0; s < e.children; ++s ) 38 38 { 39 39 nmd_element_header element_header; … … 82 82 } 83 83 84 bool nv::nmd_loader::load_bones( stream& source, uint32 children)84 bool nv::nmd_loader::load_bones( stream& source, const nmd_element_header& e ) 85 85 { 86 86 NV_ASSERT( m_bone_data == nullptr, "MULTIPLE BONE ENTRIES!" ); 87 87 m_bone_data = new nmd_bone_data; 88 m_bone_data->bones = new nmd_bone[ children ];89 m_bone_data->count = (uint16) children;90 source.read( m_bone_data->bones, sizeof( nmd_bone ), children );88 m_bone_data->bones = new nmd_bone[ e.children ]; 89 m_bone_data->count = (uint16)e.children; 90 source.read( m_bone_data->bones, sizeof( nmd_bone ), e.children ); 91 91 return true; 92 92 } … … 114 114 115 115 116 bool nv::nmd_loader::load_animation( stream& source, uint32 children)116 bool nv::nmd_loader::load_animation( stream& source, const nmd_element_header& e ) 117 117 { 118 118 NV_ASSERT( m_animation == nullptr, "MULTIPLE ANIMATION ENTRIES!" ); … … 123 123 m_animation->duration = header.duration; 124 124 m_animation->flat = header.flat; 125 m_animation->node_count = (uint16) children;126 m_animation->nodes = new nmd_node[ children ];127 for ( uint32 i = 0; i < children; ++i )125 m_animation->node_count = (uint16)e.children; 126 m_animation->nodes = new nmd_node[ e.children ]; 127 for ( uint32 i = 0; i < e.children; ++i ) 128 128 { 129 129 nmd_element_header element_header; 130 130 source.read( &element_header, sizeof( element_header ), 1 ); 131 131 NV_ASSERT( element_header.type == nmd_type::ANIMATION_NODE, "ANIMATION_NODE expected!" ); 132 m_animation->nodes[i].name = element_header.name; 132 133 133 134 uint16 ch_count = element_header.children; … … 135 136 nmd_animation_node_header node_header; 136 137 source.read( &node_header, sizeof( node_header ), 1 ); 137 m_animation->nodes[i].name = node_header.name;138 138 m_animation->nodes[i].parent_id = node_header.parent_id; 139 139 m_animation->nodes[i].transform = node_header.transform;
Note: See TracChangeset
for help on using the changeset viewer.