Changeset 277 for trunk/src/formats/assimp_loader.cc
- Timestamp:
- 07/07/14 22:38:55 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r250 r277 13 13 using namespace nv; 14 14 15 const int MAX_BONES = 64; 15 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 ) … … 35 36 } 36 37 37 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 } 38 58 bool nv::assimp_loader::load( stream& source ) 39 59 { … … 68 88 mat3 scaled_rotatation = glm::mat3( glm::scale( m_scale, m_scale, m_scale ) * m_rotate_transform ); 69 89 vec3 vertex_offset = glm::vec3(); 70 mat3 vertex_transform = glm::mat3( glm::transpose( scaled_rotatation ) ); 71 mat3 normal_transform = glm::mat3( glm::transpose( glm::inverse( scaled_rotatation ) ) ); 72 mat4 bone_transform = glm::scale( 1.0f/m_scale, 1.0f/m_scale, 1.0f/m_scale ) * m_rotate_transform; 90 mat3 vertex_transform = scaled_rotatation; 91 mat3 normal_transform = glm::mat3( m_rotate_transform ); 73 92 74 93 bool skinned = mesh->mNumBones > 0; … … 104 123 { 105 124 aiBone* bone = mesh->mBones[m]; 106 nv::mat4 offset = nv::assimp_mat4_cast( bone->mOffsetMatrix ) * bone_transform;107 125 for (unsigned int w=0; w<bone->mNumWeights; w++) 108 126 { … … 151 169 if ( mesh->mNumBones == 0 ) return false; 152 170 153 mat4 bone_transform = glm:: scale( 1.0f/m_scale, 1.0f/m_scale, 1.0f/m_scale ) * m_rotate_transform;171 mat4 bone_transform = glm::inverse( glm::scale( m_scale, m_scale, m_scale ) * glm::mat4(m_rotate_transform) ); //glm::scale( 1.f/m_scale, 1.f/m_scale, 1.f/m_scale ) * m_rotate_transform; 154 172 155 173 for (unsigned int m=0; m<mesh->mNumBones; m++) … … 250 268 for ( unsigned int m = 0; m < model->meshes.size(); ++m ) 251 269 { 252 nv::sint16 translate[64];270 sint16 translate[MAX_BONES]; 253 271 std::vector< assimp_bone > bones; 254 272 load_bones( m, bones ); … … 256 274 { 257 275 258 nv::assimp_bone& bone = bones[b];276 assimp_bone& bone = bones[b]; 259 277 auto iname = names.find( bone.name ); 260 278 if ( iname == names.end() ) 261 279 { 262 NV_ASSERT( model->bones.size() < 64, "Too many bones to merge!" );263 nv::sint16 index = (nv::sint16)model->bones.size();280 NV_ASSERT( model->bones.size() < MAX_BONES, "Too many bones to merge!" ); 281 sint16 index = (sint16)model->bones.size(); 264 282 model->bones.push_back( bone ); 265 283 names[ bone.name ] = index; … … 268 286 else 269 287 { 270 translate[b] = ( nv::sint16)iname->second;288 translate[b] = (sint16)iname->second; 271 289 } 272 290 } … … 274 292 { 275 293 mesh_data* mesh = model->meshes[m]; 276 nv::mesh_raw_channel* channel = mesh->get_channel_data()[0];277 nv::assimp_skinned_vtx* va = (nv::assimp_skinned_vtx*)channel->data;294 mesh_raw_channel* channel = mesh->get_channel_data()[0]; 295 assimp_skinned_vtx* va = (assimp_skinned_vtx*)channel->data; 278 296 for ( unsigned v = 0; v < channel->count; ++v ) 279 297 { 280 nv::assimp_skinned_vtx& vertex = va[v];281 282 for ( nv::uint32 i = 0 ; i < 4; ++i)298 assimp_skinned_vtx& vertex = va[v]; 299 300 for (uint32 i = 0 ; i < 4; ++i) 283 301 { 284 302 if ( vertex.boneweight[i] > 0.0f )
Note: See TracChangeset
for help on using the changeset viewer.