Changeset 277 for trunk/src/formats


Ignore:
Timestamp:
07/07/14 22:38:55 (11 years ago)
Author:
epyon
Message:
  • fixed and corrected the transformation mess in the assimp loader
  • fixed set_opt_uniform_array
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/assimp_loader.cc

    r250 r277  
    1313using namespace nv;
    1414
     15const int MAX_BONES = 64;
    1516
    1617nv::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 )
     
    3536}
    3637
    37 
     38nv::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}
    3858bool nv::assimp_loader::load( stream& source )
    3959{
     
    6888        mat3 scaled_rotatation = glm::mat3( glm::scale( m_scale, m_scale, m_scale ) * m_rotate_transform );
    6989        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 );
    7392
    7493        bool skinned = mesh->mNumBones > 0;
     
    104123                {
    105124                        aiBone* bone  = mesh->mBones[m];
    106                         nv::mat4 offset = nv::assimp_mat4_cast( bone->mOffsetMatrix ) * bone_transform;
    107125                        for (unsigned int w=0; w<bone->mNumWeights; w++)
    108126                        {
     
    151169        if ( mesh->mNumBones == 0 ) return false;
    152170
    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;
    154172
    155173        for (unsigned int m=0; m<mesh->mNumBones; m++)
     
    250268        for ( unsigned int m = 0; m < model->meshes.size(); ++m )
    251269        {
    252                 nv::sint16 translate[64];
     270                sint16 translate[MAX_BONES];
    253271                std::vector< assimp_bone > bones;
    254272                load_bones( m, bones );
     
    256274                {
    257275
    258                         nv::assimp_bone& bone = bones[b];
     276                        assimp_bone& bone = bones[b];
    259277                        auto iname = names.find( bone.name );
    260278                        if ( iname == names.end() )
    261279                        {
    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();
    264282                                model->bones.push_back( bone );
    265283                                names[ bone.name ] = index;
     
    268286                        else
    269287                        {
    270                                 translate[b] = (nv::sint16)iname->second;
     288                                translate[b] = (sint16)iname->second;
    271289                        }
    272290                }
     
    274292                {
    275293                        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;
    278296                        for ( unsigned v = 0; v < channel->count; ++v )
    279297                        {
    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)
    283301                                {
    284302                                        if ( vertex.boneweight[i] > 0.0f )
Note: See TracChangeset for help on using the changeset viewer.