Changeset 521
- Timestamp:
- 02/25/08 13:23:50 (11 months ago)
- Files:
-
- branches/morph-targets/libx42make/include/x42make-modelbuilder.h (modified) (6 diffs)
- branches/morph-targets/libx42make/libx42make.vcproj (modified) (1 diff)
- branches/morph-targets/libx42make/modelbuilder-animation.cpp (modified) (3 diffs)
- branches/morph-targets/libx42make/modelbuilder-cull.cpp (added)
- branches/morph-targets/libx42make/modelbuilder-geometry.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/morph-targets/libx42make/include/x42make-modelbuilder.h
r519 r521 188 188 void offset_local( const ::x42::math::affine &offset ); 189 189 190 ::x42::math::affine compute_local_matrix( float frame ); 190 191 void resample_tracks( const std::vector< uint > &frames ); 191 192 … … 322 323 }; 323 324 325 class vertex_weight; 324 326 class vertex_weights; 325 327 328 bool equal( const vertex_weight &a, const vertex_weight &b, float tol ); 329 326 330 class vertex_weight 327 331 { 328 332 public: 329 vertex_weight( influence_ptr influence = influence_ptr(), float weight = 0 ) 330 : _influence( influence ), _weight( ::x42::math::saturate( weight ) ) 331 { 332 } 333 vertex_weight( influence_ptr influence = influence_ptr(), float weight = 0 ); 333 334 334 335 influence_ptr influence() const { return _influence; } … … 337 338 bool is_empty() const { return !_influence || _weight == 0; } 338 339 340 bool operator == ( const vertex_weight &other ) const; 341 bool operator != ( const vertex_weight &other ) const 342 { 343 return !operator == ( other ); 344 } 345 339 346 private: 340 347 influence_ptr _influence; … … 342 349 343 350 friend class vertex_weights; 344 }; 351 friend bool equal( const vertex_weight &a, const vertex_weight &b, float tol ); 352 }; 353 354 bool equal( const vertex_weights &a, const vertex_weights &b, float tol ); 345 355 346 356 class vertex_weights … … 360 370 const vertex_weight& operator[] ( size_t index ) const { if( index >= max_weights ) throw error(); return _weights[index]; } 361 371 372 bool operator == ( const vertex_weights &other ) const; 373 bool operator != ( const vertex_weights &other ) const 374 { 375 return !operator == ( other ); 376 } 377 362 378 private: 363 379 vertex_weight _weights[max_weights]; 380 381 friend bool equal( const vertex_weights &a, const vertex_weights &b, float tol ); 364 382 }; 365 383 … … 568 586 std::vector< size_t > count_bone_uses() const; 569 587 588 std::vector< ::x42::math::affine > compute_influence_matrices( float frame ); 589 570 590 void remove_unused_influences(); 571 591 void remove_unused_bones(); 592 593 void compute_culling_info( uint frame_sample_stride = 1 ); 572 594 573 595 model to_model( void ) const; branches/morph-targets/libx42make/libx42make.vcproj
r519 r521 661 661 </File> 662 662 <File 663 RelativePath=".\modelbuilder-cull.cpp" 664 > 665 </File> 666 <File 663 667 RelativePath=".\modelbuilder-enumerators.cpp" 664 668 > branches/morph-targets/libx42make/modelbuilder-animation.cpp
r517 r521 264 264 } 265 265 266 affine animation_tracks::compute_local_matrix( float frame ) 267 { 268 require_tracks(); 269 270 if( owner->flags & bone_flags::use_inverse_parent_scale && owner->_parent ) 271 owner->_parent->anim_tracks.require_tracks(); 272 273 vec3 pos = sample_track( position, frame ); 274 quat rot = sample_track( rotation, frame ); 275 vec3 scl = sample_track( scale, frame ); 276 277 affine ret = quat_to_affine( rot ); 278 ret.col( 0 ) *= scl.x; 279 ret.col( 1 ) *= scl.y; 280 ret.col( 2 ) *= scl.z; 281 282 if( owner->flags & bone_flags::use_inverse_parent_scale && owner->_parent ) 283 { 284 const vec3 ps = sample_track( owner->_parent->anim_tracks.scale, frame ); 285 const vec3 ips = rcp( ps ); 286 287 ret.col( 0 ) *= ips; 288 ret.col( 1 ) *= ips; 289 ret.col( 2 ) *= ips; 290 } 291 292 ret.col( 3 ) = pos; 293 294 return ret; 295 } 296 266 297 void animation_tracks::make_local_from_tracks() 267 298 { 299 if( owner->flags & bone_flags::use_inverse_parent_scale && owner->_parent ) 300 owner->_parent->anim_tracks.require_tracks(); 301 268 302 local_matrices.resize( position.size() ); 269 303 … … 284 318 le.value.col( 2 ) *= se.value.z; 285 319 320 if( owner->flags & bone_flags::use_inverse_parent_scale && owner->_parent ) 321 { 322 const vec3 ps = sample_track( owner->_parent->anim_tracks.scale, (float)pe.frame ); 323 vec3 ips = rcp( ps ); 324 325 le.value.col( 0 ) *= ips; 326 le.value.col( 1 ) *= ips; 327 le.value.col( 2 ) *= ips; 328 } 329 286 330 le.value.col( 3 ) = pe.value; 287 331 } … … 590 634 } 591 635 636 std::vector< affine > model_builder::compute_influence_matrices( float frame ) 637 { 638 if( _bone_update_count || _influence_update_count ) 639 throw error(); 640 641 std::vector< affine > bone_mats( bones.size(), affinei() ); 642 643 for( size_t i = 0; i < bones.size(); i++ ) 644 { 645 bone_ptr b = bones[i]; 646 647 bone_mats[i] = b->anim_tracks.compute_local_matrix( frame ); 648 649 if( b->_parent ) 650 bone_mats[i] = bone_mats[b->_parent->_index] * bone_mats[i]; 651 } 652 653 std::vector< affine > ret( influences.size(), affinei() ); 654 655 for( size_t i = 0; i < influences.size(); i++ ) 656 { 657 influence_ptr inf = influences[i]; 658 659 if( inf->_bone ) 660 ret[inf->_index] = bone_mats[inf->_bone->_index] * inf->matrix; 661 else 662 ret[inf->_index] = inf->matrix; 663 } 664 665 return ret; 666 } 667 592 668 }; 593 669 }; branches/morph-targets/libx42make/modelbuilder-geometry.cpp
r519 r521 29 29 30 30 /* 31 class vertex_weight 32 */ 33 vertex_weight::vertex_weight( influence_ptr influence, float weight ) 34 : _influence( influence ), _weight( ::x42::math::saturate( weight ) ) 35 { 36 if( weight < 0 ) 37 throw validation_error( "negative influence weight" ); 38 39 if( !influence && weight ) 40 throw validation_error( "attempting to create weight to null influence" ); 41 42 if( !weight ) 43 //don't store pointers when there's no weight 44 _influence = influence_ptr(); 45 } 46 47 bool vertex_weight::operator == ( const vertex_weight &other ) const 48 { 49 return _influence == other._influence && _weight == other._weight; 50 } 51 52 bool equal( const vertex_weight &a, const vertex_weight &b, float tol ) 53 { 54 return a._influence == b._influence && fabsf( a._weight - b._weight ) <= tol; 55 } 56 57 58 /* 31 59 class vertex_weights 32 60 */ … … 143 171 } 144 172 return count; 173 } 174 175 bool vertex_weights::operator == ( const vertex_weights &other ) const 176 { 177 for( size_t i = 0; i < vertex_weights::max_weights; i++ ) 178 { 179 if( _weights[i] != other._weights[i] ) 180 return false; 181 } 182 183 return true; 184 } 185 186 bool equal( const vertex_weights &a, const vertex_weights &b, float tol ) 187 { 188 for( size_t i = 0; i < vertex_weights::max_weights; i++ ) 189 { 190 if( !equal( a._weights[i], b._weights[i], tol ) ) 191 return false; 192 } 193 194 return true; 145 195 } 146 196 … … 388 438 { 389 439 ret = max( ret, weights[i].count() ); 390 } 440 441 if( ret == vertex_weights::max_weights ) 442 //can't grow more than this, we're done 443 break; 444 } 445 446 return ret; 391 447 } 392 448 … … 429 485 430 486 affine m = affinez(); 431 for( uint j = 0; j < vertex_weights::max_weights; j++ )432 { 433 const vertex_weight wt = w[j];487 for( size_t j = 0; j < vertex_weights::max_weights; j++ ) 488 { 489 const vertex_weight &wt = w[j]; 434 490 435 491 if( wt.is_empty() )
