Changeset 278 for trunk/src


Ignore:
Timestamp:
07/08/14 03:20:06 (11 years ago)
Author:
epyon
Message:
  • assimp module now creates fully pre-transformed meshes with both merged and separate animation
File:
1 edited

Legend:

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

    r277 r278  
    8787
    8888        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 );
    8990        vec3 vertex_offset     = glm::vec3();
    9091        mat3 vertex_transform  = scaled_rotatation;
     
    169170        if ( mesh->mNumBones == 0 ) return false;
    170171
    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;
     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 );
    172174
    173175        for (unsigned int m=0; m<mesh->mNumBones; m++)
    174176        {
    175177                aiBone* bone   = mesh->mBones[m];
    176                 mat4    offset = assimp_mat4_cast( bone->mOffsetMatrix ) * bone_transform;
     178                mat4    offset = bone_pre_transform * assimp_mat4_cast( bone->mOffsetMatrix ) * bone_transform;
    177179                bones.emplace_back( bone->mName.data, offset );
    178180        }
     
    211213                        aiMesh* mesh = scene->mMeshes[mc];
    212214
    213                         NV_LOG( nv::LOG_NOTICE, "Mesh #"<<mc<<"   - " << mesh->mName.data );
     215                        NV_LOG( nv::LOG_NOTICE, "Mesh #"<<mc<<"   - " << std::string( mesh->mName.data ) );
    214216                        NV_LOG( nv::LOG_NOTICE, "  bones   - " << mesh->mNumBones );
    215217                        NV_LOG( nv::LOG_NOTICE, "  uvs     - " << mesh->mNumUVComponents[0] );
     
    329331
    330332        load_node( result, root, 0, -1 );
    331         result->nodes[0].transform = glm::scale( m_scale, m_scale, m_scale ) * result->nodes[0].transform;
     333        // TODO: this is not used when pretransformed, is it used otherwise?
    332334
    333335        if ( bone_data )
     
    422424                nv::vec3 pos = nv::assimp_vec3_cast(node->mPositionKeys[pn].mValue);
    423425                nv::quat rot = nv::assimp_quat_cast(node->mRotationKeys[rn].mValue);
    424                 nv::transform ptr;
     426                // TODO: only do the calculation when a rotate transform is present!
     427                nv::transform ptr( vec3(), glm::quat_cast( m_rotate_transform ) );
    425428                if ( parent_keys )
    426429                {
     
    428431                        if ( pv && pv->size() > 0 ) ptr = pv->get( glm::min( n, pv->size()-1 ) );
    429432                }
    430 
    431                 nv::vec3 rot_pos = ptr.get_orientation() * pos;
    432                 pos = ptr.get_position() + rot_pos;
    433                 rot = glm::normalize( ptr.get_orientation() * rot );
    434                 keys->insert( nv::transform( pos, rot ) );
     433                nv::transform key( ptr * nv::transform( pos * m_scale, rot ) );
     434                keys->insert( key );
    435435        }
    436436        return keys;
     
    439439key_animation_data* nv::assimp_loader::create_direct_keys( const void* vnode )
    440440{
     441        // TODO : support for m_rotate_transform and m_scale! ( should be easy )
    441442        const aiNodeAnim* node = (const aiNodeAnim*)vnode;
    442443        if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) return nullptr;
     
    445446        for ( unsigned np = 0; np < node->mNumPositionKeys; ++np )
    446447        {
    447                 keys->insert_position( (float)node->mPositionKeys[np].mTime, assimp_vec3_cast(node->mPositionKeys[np].mValue) );
     448                keys->insert_position( (float)node->mPositionKeys[np].mTime, m_scale * assimp_vec3_cast(node->mPositionKeys[np].mValue) );
    448449        }
    449450        for ( unsigned np = 0; np < node->mNumRotationKeys; ++np )
Note: See TracChangeset for help on using the changeset viewer.