Changeset 510

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

o Bone list validation.

Files:

Legend:

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

    r509 r510  
    3232{ 
    3333 
     34class error : public std::exception 
     35{ 
     36public: 
     37        error() : exception() { } 
     38        error( const char *why ) : exception( why ) { } 
     39        error( const error &other ) : exception( other ) { } 
     40}; 
     41 
     42class validation_error : public error 
     43{ 
     44public: 
     45        validation_error() : error() { } 
     46        validation_error( const char *why ) : error( why ) { } 
     47        validation_error( const error &other ) : error( other ) { } 
     48}; 
     49 
    3450class ref_obj; 
    3551typedef ::boost::intrusive_ptr< ref_obj > ref_obj_ptr; 
  • branches/morph-targets/libx42make/modelbuilder-skeleton.cpp

    r509 r510  
    8787void model_builder::validate_bone_parent( bone *bone, const bone_ptr &new_parent ) const 
    8888{ 
    89 
     89        if( _bone_update_count ) 
     90                return; 
     91 
     92        //check if this would cause a cycle 
     93        for( bone_ptr p = new_parent; p; p = p->_parent ) 
     94        { 
     95                if( p == bone ) 
     96                        throw validation_error( "Bone parent causes a cycle." ); 
     97        } 
     98
     99 
    90100void model_builder::validate_bone_anim_group( bone *bone, uint new_anim_group ) const 
    91101{ 
    92 
    93  
    94 void model_builder::notify_bone_parent( bone *bone ) 
     102        if( _bone_update_count ) 
     103                return; 
     104 
     105        if( bone->_parent && bone->_parent->_anim_group > new_anim_group ) 
     106                throw validation_error( "Animation group number treater than parent's value." ); 
     107
     108 
     109void model_builder::notify_bone_parent( bone * /* bone */ ) 
    95110{ 
    96111        sort_bones(); 
    97112} 
    98 void model_builder::notify_bone_anim_group( bone *bone
     113void model_builder::notify_bone_anim_group( bone * /* bone */
    99114{ 
    100115        sort_bones(); 
     
    105120        if( _bone_update_count ) 
    106121                return; 
     122 
     123        for( size_t i = 0; i < bones.size(); i++ ) 
     124        { 
     125                bone_ptr b = bones[i]; 
     126 
     127                if( b->owner != this ) 
     128                        throw validation_error( "Bones includes a bone that does not belong to this model_builder." ); 
     129 
     130                if( b->_parent ) 
     131                { 
     132                        if( b->_parent->owner != this ) 
     133                                throw validation_error( "Bones includes a bone with a parent that does not belong to this model_builder." ); 
     134 
     135                        if( b->_parent->_index >= bones.size() || bones[b->_parent->_index] != b->_parent ) 
     136                                throw validation_error( "Bones includes a bone with a parent that does not belong to this model_builder." ); 
     137                } 
     138 
     139                validate_bone_parent( b.get(), b->_parent.get() ); 
     140                validate_bone_anim_group( b.get(), b->_anim_group ); 
     141 
     142                //check for duplicates 
     143                for( size_t j = i + 1; j < bones.size(); j++ ) 
     144                { 
     145                        if( bones[j] == b ) 
     146                                throw validation_error( "Duplicate bone." ); 
     147                } 
     148        } 
    107149} 
    108150