Changeset 517

Show
Ignore:
Timestamp:
02/22/08 18:01:54 (11 months ago)
Author:
phill
Message:

o More WIP stuff.

Files:

Legend:

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

    r516 r517  
    430430 
    431431        void optimize( optimize_type opt_type = optimize_type::match_current ); 
     432         
     433        void bake_vertices( const std::vector< ::x42::math::affine > &inf_mats ); 
    432434 
    433435        size_t vertex_count() const { return base_shape.size(); } 
     
    435437 
    436438        bool is_valid() const; 
     439 
     440private: 
     441        bool are_vert_arrays_parallell() const; 
    437442}; 
    438443 
     
    522527        void apply_root_scale( const ::x42::math::vec3 &pos_ofs, const ::x42::math::quat &rot_ofs, 
    523528                const ::x42::math::vec3 &inner_scale_ofs, const ::x42::math::vec3 &outer_scale_ofs ); 
     529 
     530        void collapse_constant_bones(); 
    524531 
    525532        //unbinds all vertices from influence 
     
    534541        void rebind_duplicate_influences(); 
    535542 
     543        void collapse_static_influences(); 
     544 
    536545        void unbind_weak_influences( float min_weight, bool renormalize_weights = true ); 
    537546        void unbind_excess_influences( size_t max_influences, bool renormalize_weights = true ); 
  • branches/morph-targets/libx42make/modelbuilder-animation.cpp

    r516 r517  
    420420        std::swap( rotation, new_rot ); 
    421421        std::swap( scale, new_scale ); 
     422 
     423        local_matrices.clear(); 
     424        world_matrices.clear(); 
    422425} 
    423426 
     
    453456        clean_track( rotation, tight_tol.rotation ); 
    454457        clean_track( scale, tight_tol.scale ); 
     458 
     459        local_matrices.clear(); 
     460        world_matrices.clear(); 
    455461} 
    456462 
  • branches/morph-targets/libx42make/modelbuilder-geometry.cpp

    r516 r517  
    348348} 
    349349 
    350 bool geometry::is_valid() const 
     350bool geometry::are_vert_arrays_parallell() const 
    351351{ 
    352352        size_t num_verts = base_shape.size(); 
     
    362362        } 
    363363 
     364        return true; 
     365} 
     366 
     367bool geometry::is_valid() const 
     368{ 
     369        size_t num_verts = base_shape.size(); 
     370 
     371        if( !are_vert_arrays_parallell() ) 
     372                return false; 
     373 
    364374        for( size_t i = 0; i < indices.size(); i++ ) 
    365375        { 
     
    369379 
    370380        return true; 
     381} 
     382 
     383void geometry::bake_vertices( const std::vector< ::x42::math::affine > &inf_mats ) 
     384{ 
     385        if( !are_tracks_parallell() ) 
     386                throw validation_error( "Can't bake non-parallell vertex arrays." ); 
     387 
     388        std::vector< vertex_geometry > new_shape( base_shape.size() ); 
     389        std::vector< morph_target_ptr > new_morph_targets( morph_targets.size() ); 
     390 
     391        DO NOT LET THIS COMPILE UNTIL I FIX THIS SHIT 
    371392} 
    372393 
  • branches/morph-targets/libx42make/modelbuilder-influences.cpp

    r516 r517  
    205205} 
    206206 
     207void model_builder::collapse_static_influences() 
     208{ 
     209        std::vector< affine > static_mats( influences.size(), affinei() ); 
     210 
     211        for( size_t i = 0; i < influences.size(); i++ ) 
     212        { 
     213                influence_ptr inf = influences[i]; 
     214 
     215                if( !inf->_bone ) 
     216                        static_mats[i] = inf->matrix; 
     217        } 
     218 
     219        for( group_enumerator iter( *this ); iter.next(); ) 
     220        { 
     221                group_ptr g = iter.current(); 
     222                std::vector< influence_ptr > grp_infs = g->get_influences(); 
     223 
     224                bool is_static = true; 
     225                for( size_t i = 0; i < grp_infs.size(); i++ ) 
     226                { 
     227                        if( grp_infs[i]->_bone ) 
     228                        { 
     229                                is_static = false; 
     230                                break; 
     231                        } 
     232                } 
     233 
     234                if( !is_static ) 
     235                        continue; 
     236 
     237                g->geometry.bake_vertices( static_mats ); 
     238        } 
     239} 
     240 
    207241void model_builder::erase_influence( const influence_ptr &influence ) 
    208242{ 
  • branches/morph-targets/libx42make/modelbuilder-skeleton.cpp

    r516 r517  
    344344} 
    345345 
     346void model_builder::collapse_constant_bones() 
     347{ 
     348        if( _bone_update_count ) 
     349                throw error( "Can't do bone collapse while updating bones." ); 
     350 
     351        for( size_t i = 0; i < bones.size(); i++ ) 
     352        { 
     353                bone_ptr b = bones[i]; 
     354                animation_tracks &anim = b->anim_tracks; 
     355 
     356                anim.require_tracks(); 
     357                anim.require_local(); 
     358 
     359                if( i > 0 && anim.local_matrices.size() != 
     360                        bones[i - 1]->anim_tracks.local_matrices.size() ) 
     361                        throw error( "Mismatched local matrix representation size." ); 
     362 
     363                if( b->flags & bone_flags::use_inverse_parent_scale ) 
     364                        throw error( "Can't do bone collapse if bones include use_inverse_parent_scale." ); 
     365        } 
     366 
     367        begin_bone_update(); 
     368 
     369        for( size_t i = 0; i < bones.size(); i++ ) 
     370        { 
     371                bone_ptr bi = bones[i]; 
     372 
     373                if( bi->no_remove ) 
     374                        continue; 
     375 
     376                const animation_tracks &anim = bi->anim_tracks; 
     377 
     378                if( anim.position.size() != 1 || anim.rotation.size() != 1 || 
     379                        anim.scale.size() != 1 ) 
     380                        //not constant, skip 
     381                        continue; 
     382 
     383                const affine &m = anim.local_matrices[0].value; 
     384 
     385                //push it through to its child bones 
     386                for( size_t j = i + 1; j < bones.size(); j++ ) 
     387                { 
     388                        bone_ptr bj = bones[j]; 
     389 
     390                        if( bj->_parent == bi ) 
     391                        { 
     392                                bj->anim_tracks.offset_local( m ); 
     393                                bj->_parent = bi->_parent; 
     394 
     395                                bj->anim_tracks.clean_tracks(); 
     396                        } 
     397                } 
     398 
     399                //push it to its influences 
     400                for( size_t j = 0; j < influences.size(); j++ ) 
     401                { 
     402                        influence_ptr inf = influences[j]; 
     403 
     404                        if( inf->_bone == bi ) 
     405                        { 
     406                                inf->matrix = m * inf->matrix; 
     407                                inf->_bone = bi->_parent; 
     408                        } 
     409                } 
     410 
     411                //push it to its tags 
     412                for( size_t j = 0; j < tags.size(); j++ ) 
     413                { 
     414                        tag_ptr tag = tags[j]; 
     415 
     416                        if( tag->_bone == bi ) 
     417                        { 
     418                                tag->matrix = m * tag->matrix; 
     419                                tag->_bone = bi->_parent; 
     420                        } 
     421                } 
     422        } 
     423 
     424        end_bone_update(); 
     425} 
     426 
    346427}; 
    347428};