Changeset 522
- Timestamp:
- 02/25/08 14:28:26 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/morph-targets/libx42make/include/x42make-modelbuilder.h
r521 r522 586 586 std::vector< size_t > count_bone_uses() const; 587 587 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 ); 589 591 590 592 void remove_unused_influences(); branches/morph-targets/libx42make/modelbuilder-animation.cpp
r521 r522 634 634 } 635 635 636 std::vector< affine > model_builder::compute_influence_matrices( float frame ) 636 void model_builder::compute_influence_matrices( float frame, 637 std::vector< ::x42::math::affine > &bone_mats, 638 std::vector< ::x42::math::affine > &inf_mats ) 637 639 { 638 640 if( _bone_update_count || _influence_update_count ) 639 641 throw error(); 640 642 641 std::vector< affine > bone_mats( bones.size(), affinei() );643 bone_mats.resize( bones.size() ); 642 644 643 645 for( size_t i = 0; i < bones.size(); i++ ) … … 651 653 } 652 654 653 std::vector< affine > ret( influences.size(), affinei() );655 inf_mats.resize( influences.size() ); 654 656 655 657 for( size_t i = 0; i < influences.size(); i++ ) … … 658 660 659 661 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; 661 663 else 662 ret[inf->_index] = inf->matrix; 663 } 664 665 return ret; 664 inf_mats[inf->_index] = inf->matrix; 665 } 666 666 } 667 667 branches/morph-targets/libx42make/modelbuilder-cull.cpp
r521 r522 217 217 } 218 218 219 template< typename InVec3IterTy, typename InWtIterTy, 220 typename InBoneMatIterTy, typename OutExtsIterTy > 221 void 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 } 219 251 /* 220 252 class model_builder … … 265 297 std::vector< sphere > spheres; 266 298 299 std::vector< float > extents( bones.size(), 0 ); 300 267 301 for( uint i = 0; i < _frame_count; i += frame_sample_stride ) 268 302 { 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 270 307 animate_positions( anim_pos.begin(), anim_pos.end(), 271 308 anim_weights.begin(), inf_mats.begin(), animed_pts.begin() ); 272 309 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 273 317 aabb box; 274 318 sphere sph; 275 319 276 320 bound_points( animed_pts.begin(), animed_pts.end(), sph, box ); 277 321 278 322 boxes.push_back( box ); 279 323 spheres.push_back( sph ); … … 282 326 bounding_box = bound_boxes( boxes.begin(), boxes.end() ); 283 327 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 } 284 333 } 285 334
