Changeset 521

Show
Ignore:
Timestamp:
02/25/08 13:23:50 (11 months ago)
Author:
phill
Message:

o Culling infos!

Files:

Legend:

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

    r519 r521  
    188188        void offset_local( const ::x42::math::affine &offset ); 
    189189 
     190        ::x42::math::affine compute_local_matrix( float frame ); 
    190191        void resample_tracks( const std::vector< uint > &frames ); 
    191192 
     
    322323}; 
    323324 
     325class vertex_weight; 
    324326class vertex_weights; 
    325327 
     328bool equal( const vertex_weight &a, const vertex_weight &b, float tol ); 
     329 
    326330class vertex_weight 
    327331{ 
    328332public: 
    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 ); 
    333334 
    334335        influence_ptr influence() const { return _influence; } 
     
    337338        bool is_empty() const { return !_influence || _weight == 0; } 
    338339 
     340        bool operator == ( const vertex_weight &other ) const; 
     341        bool operator != ( const vertex_weight &other ) const 
     342        { 
     343                return !operator == ( other ); 
     344        } 
     345 
    339346private: 
    340347        influence_ptr _influence; 
     
    342349 
    343350        friend class vertex_weights; 
    344 }; 
     351        friend bool equal( const vertex_weight &a, const vertex_weight &b, float tol ); 
     352}; 
     353 
     354bool equal( const vertex_weights &a, const vertex_weights &b, float tol ); 
    345355 
    346356class vertex_weights 
     
    360370        const vertex_weight& operator[] ( size_t index ) const { if( index >= max_weights ) throw error(); return _weights[index]; } 
    361371 
     372        bool operator == ( const vertex_weights &other ) const; 
     373        bool operator != ( const vertex_weights &other ) const 
     374        { 
     375                return !operator == ( other ); 
     376        } 
     377 
    362378private: 
    363379        vertex_weight _weights[max_weights]; 
     380 
     381        friend bool equal( const vertex_weights &a, const vertex_weights &b, float tol ); 
    364382}; 
    365383 
     
    568586        std::vector< size_t > count_bone_uses() const; 
    569587 
     588        std::vector< ::x42::math::affine > compute_influence_matrices( float frame ); 
     589 
    570590        void remove_unused_influences(); 
    571591        void remove_unused_bones(); 
     592 
     593        void compute_culling_info( uint frame_sample_stride = 1 ); 
    572594 
    573595        model to_model( void ) const; 
  • branches/morph-targets/libx42make/libx42make.vcproj

    r519 r521  
    661661                </File> 
    662662                <File 
     663                        RelativePath=".\modelbuilder-cull.cpp" 
     664                        > 
     665                </File> 
     666                <File 
    663667                        RelativePath=".\modelbuilder-enumerators.cpp" 
    664668                        > 
  • branches/morph-targets/libx42make/modelbuilder-animation.cpp

    r517 r521  
    264264} 
    265265 
     266affine 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 
    266297void animation_tracks::make_local_from_tracks() 
    267298{ 
     299        if( owner->flags & bone_flags::use_inverse_parent_scale && owner->_parent ) 
     300                owner->_parent->anim_tracks.require_tracks(); 
     301 
    268302        local_matrices.resize( position.size() ); 
    269303 
     
    284318                le.value.col( 2 ) *= se.value.z; 
    285319 
     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 
    286330                le.value.col( 3 ) = pe.value; 
    287331        } 
     
    590634} 
    591635 
     636std::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 
    592668}; 
    593669}; 
  • branches/morph-targets/libx42make/modelbuilder-geometry.cpp

    r519 r521  
    2929 
    3030/* 
     31        class vertex_weight 
     32*/ 
     33vertex_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 
     47bool vertex_weight::operator == ( const vertex_weight &other ) const 
     48{ 
     49        return _influence == other._influence && _weight == other._weight; 
     50} 
     51 
     52bool 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/* 
    3159        class vertex_weights 
    3260*/ 
     
    143171        } 
    144172        return count; 
     173} 
     174 
     175bool 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 
     186bool 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; 
    145195} 
    146196 
     
    388438        { 
    389439                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; 
    391447} 
    392448 
     
    429485                 
    430486                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]; 
    434490 
    435491                        if( wt.is_empty() )