Changeset 522

Show
Ignore:
Timestamp:
02/25/08 14:28:26 (11 months ago)
Author:
phill
Message:

o Now with bone extents.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42make/include/x42make-modelbuilder.h

    r521 r522  
    586586        std::vector< size_t > count_bone_uses() const; 
    587587 
    588         std::vector< ::x42::math::affine > compute_influence_matrices( float frame ); 
     588        void compute_influence_matrices( float frame, 
     589                std::vector< ::x42::math::affine > &bone_mats, 
     590                std::vector< ::x42::math::affine > &inf_mats ); 
    589591 
    590592        void remove_unused_influences(); 
  • branches/morph-targets/libx42make/modelbuilder-animation.cpp

    r521 r522  
    634634} 
    635635 
    636 std::vector< affine > model_builder::compute_influence_matrices( float frame ) 
     636void model_builder::compute_influence_matrices( float frame, 
     637                std::vector< ::x42::math::affine > &bone_mats, 
     638                std::vector< ::x42::math::affine > &inf_mats ) 
    637639{ 
    638640        if( _bone_update_count || _influence_update_count ) 
    639641                throw error(); 
    640642 
    641         std::vector< affine > bone_mats( bones.size(), affinei() ); 
     643        bone_mats.resize( bones.size() ); 
    642644          
    643645        for( size_t i = 0; i < bones.size(); i++ ) 
     
    651653        } 
    652654 
    653         std::vector< affine > ret( influences.size(), affinei() ); 
     655        inf_mats.resize( influences.size() ); 
    654656 
    655657        for( size_t i = 0; i < influences.size(); i++ ) 
     
    658660 
    659661                if( inf->_bone ) 
    660                         ret[inf->_index] = bone_mats[inf->_bone->_index] * inf->matrix; 
     662                        inf_mats[inf->_index] = bone_mats[inf->_bone->_index] * inf->matrix; 
    661663                else 
    662                         ret[inf->_index] = inf->matrix; 
    663         } 
    664  
    665         return ret; 
     664                        inf_mats[inf->_index] = inf->matrix; 
     665        } 
    666666} 
    667667 
  • branches/morph-targets/libx42make/modelbuilder-cull.cpp

    r521 r522  
    217217} 
    218218 
     219template< typename InVec3IterTy, typename InWtIterTy, 
     220        typename InBoneMatIterTy, typename OutExtsIterTy > 
     221void update_bone_extents( InVec3IterTy pos_beg, InVec3IterTy pos_end, 
     222        InWtIterTy wt_beg, InBoneMatIterTy bone_mats_beg, OutExtsIterTy extents_begin ) 
     223{ 
     224        InVec3IterTy pos = pos_beg; 
     225        InWtIterTy wt = wt_beg; 
     226 
     227        for( ; pos != pos_end; ++pos, ++wt ) 
     228        { 
     229                for( size_t i = 0; i < vertex_weights::max_weights; i++ ) 
     230                { 
     231                        const vertex_weight &w = (*wt)[i]; 
     232 
     233                        if( w.is_empty() ) 
     234                                break; 
     235 
     236                        bone_ptr bone = w.influence()->bone(); 
     237                         
     238                        if( !bone ) 
     239                                continue; 
     240 
     241                        InBoneMatIterTy mat = bone_mats_beg; 
     242                        std::advance( mat, bone->index() ); 
     243 
     244                        OutExtsIterTy ext = extents_begin; 
     245                        std::advance( ext, bone->index() ); 
     246 
     247                        *ext = max( *ext, dist( *pos, mat->col( 3 ) ) ); 
     248                } 
     249        } 
     250} 
    219251/* 
    220252        class model_builder 
     
    265297        std::vector< sphere > spheres; 
    266298 
     299        std::vector< float > extents( bones.size(), 0 ); 
     300 
    267301        for( uint i = 0; i < _frame_count; i += frame_sample_stride ) 
    268302        { 
    269                 std::vector< affine > inf_mats = compute_influence_matrices( (float)i ); 
     303                std::vector< affine > inf_mats; 
     304                std::vector< affine > bone_mats; 
     305                compute_influence_matrices( (float)i, bone_mats, inf_mats ); 
     306 
    270307                animate_positions( anim_pos.begin(), anim_pos.end(), 
    271308                        anim_weights.begin(), inf_mats.begin(), animed_pts.begin() ); 
    272309 
     310                if( !i ) 
     311                { 
     312                        //only need to do this the first time 
     313                        update_bone_extents( anim_pos.begin(), anim_pos.end(), 
     314                                anim_weights.begin(), bone_mats.begin(), extents.begin() ); 
     315                } 
     316 
    273317                aabb box; 
    274318                sphere sph; 
    275319 
    276320                bound_points( animed_pts.begin(), animed_pts.end(), sph, box ); 
    277  
     321                 
    278322                boxes.push_back( box ); 
    279323                spheres.push_back( sph ); 
     
    282326        bounding_box = bound_boxes( boxes.begin(), boxes.end() ); 
    283327        bounding_sphere = bound_spheres( spheres.begin(), spheres.end() ); 
     328 
     329        for( size_t i = 0; i < bones.size(); i++ ) 
     330        { 
     331                bones[i]->extent = extents[i]; 
     332        } 
    284333} 
    285334