Ignore:
Timestamp:
06/15/14 13:07:02 (11 years ago)
Author:
epyon
Message:
  • md5 - algorithmic reduction and reweighting of loaded weights to 4 per vertex (no structure change yet)
File:
1 edited

Legend:

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

    r241 r258  
    1010#include "nv/logging.hh"
    1111#include "nv/io/std_stream.hh"
     12#include "nv/profiler.hh"
    1213#include <cstring>
    1314
     
    211212                vtc.tangent  = glm::vec3(0);
    212213
     214                std::sort( mdata->m_weights.begin() + vdata.start_weight, mdata->m_weights.begin() + vdata.start_weight + vdata.weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } );
     215
     216                if ( vdata.weight_count > 4 )
     217                {
     218                        float sum = 0.0f;
     219                        for ( size_t j = 0; j < 4; ++j )
     220                        {
     221                                sum += mdata->m_weights[vdata.start_weight + j].bias;
     222                        }
     223                        float ratio = 1.0f / sum;
     224                        for ( size_t j = 0; j < 4; ++j )
     225                        {
     226                                mdata->m_weights[vdata.start_weight + j].bias =
     227                                        ratio * mdata->m_weights[vdata.start_weight + j].bias;
     228                        }
     229                        vdata.weight_count = 4;
     230                }
     231
    213232                for ( size_t j = 0; j < vdata.weight_count; ++j )
    214233                {
     
    517536void nv::md5_mesh_instance::apply( const std::vector< transform >& skeleton )
    518537{
     538        NV_PROFILE("md5::apply");
     539        char* fill_ptr = (char*)&(m_pntdata[0]);
     540        std::fill( fill_ptr, fill_ptr + m_size * ( sizeof( md5_vtx_pnt ) ), 0 );
    519541        for ( unsigned int i = 0; i < m_size; ++i )
    520542        {
     
    522544                md5_vtx_pnt& result = m_pntdata[i];
    523545
    524                 result.position = glm::vec3(0);
    525                 result.normal   = glm::vec3(0);
    526                 result.tangent  = glm::vec3(0);
    527 
    528546                for ( size_t j = 0; j < vert.weight_count; ++j )
    529547                {
Note: See TracChangeset for help on using the changeset viewer.