Changeset 509

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

o Lots more work on the new exporter.

Files:

Legend:

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

    r507 r509  
    3333 
    3434class ref_obj; 
     35typedef ::boost::intrusive_ptr< ref_obj > ref_obj_ptr; 
     36typedef ::boost::intrusive_ptr< const ref_obj > const_ref_obj_ptr; 
     37 
     38class api_tag; 
     39typedef ::boost::intrusive_ptr< api_tag > api_tag_ptr; 
     40typedef ::boost::intrusive_ptr< const api_tag > const_api_tag_ptr; 
    3541 
    3642namespace _impl 
     
    4349{ 
    4450public: 
    45         size_t ref_count() const { return _ref_count; } 
     51        api_tag_ptr user_tag; 
    4652 
    4753        ref_obj() : _ref_count( 0 ) { } 
    4854        virtual ~ref_obj() { } 
    4955 
     56        size_t ref_count() const { return _ref_count; } 
     57 
    5058private: 
    5159        size_t _ref_count; 
    52  
     60         
    5361        friend void _impl::intrusive_ptr_add_ref( ref_obj *r ); 
    5462        friend void _impl::intrusive_ptr_release( ref_obj *r ); 
    5563}; 
    5664 
    57 class api_tag : ref_obj 
     65class api_tag : public ref_obj 
    5866{ 
    5967public: 
     
    6371 
    6472class lod; 
    65 class bone; 
    66 class influence; 
    67 class group; 
    68 class morph_target; 
    69 class model_builder; 
    70  
    71 typedef ::boost::intrusive_ptr< ref_obj > ref_obj_ptr; 
    72 typedef ::boost::intrusive_ptr< const ref_obj > const_ref_obj_ptr; 
    73 typedef ::boost::intrusive_ptr< api_tag > api_tag_ptr; 
    74 typedef ::boost::intrusive_ptr< const api_tag > const_api_tag_ptr; 
    7573typedef ::boost::intrusive_ptr< lod > lod_ptr; 
    7674typedef ::boost::intrusive_ptr< const lod > const_lod_ptr; 
     75 
     76class bone; 
    7777typedef ::boost::intrusive_ptr< bone > bone_ptr; 
    7878typedef ::boost::intrusive_ptr< const bone > const_bone_ptr; 
     79 
     80class influence; 
    7981typedef ::boost::intrusive_ptr< influence > influence_ptr; 
    8082typedef ::boost::intrusive_ptr< const influence > const_influence_ptr; 
     83 
     84class group; 
    8185typedef ::boost::intrusive_ptr< group > group_ptr; 
    8286typedef ::boost::intrusive_ptr< const group > const_group_ptr; 
     87 
     88class morph_target; 
    8389typedef ::boost::intrusive_ptr< morph_target > morph_target_ptr; 
    8490typedef ::boost::intrusive_ptr< const morph_target > const_morph_target_ptr; 
     91 
     92 
     93class model_builder; 
    8594typedef ::boost::intrusive_ptr< model_builder > model_builder_ptr; 
    8695typedef ::boost::intrusive_ptr< const model_builder > const_model_builder_ptr; 
    8796 
     97template< typename T > 
     98struct anim_track_elem 
     99{ 
     100        uint                            frame; 
     101        T                                       value; 
     102}; 
     103 
     104typedef anim_track_elem< ::x42::math::vec3 > vec3_track_elem; 
     105typedef anim_track_elem< ::x42::math::quat > quat_track_elem; 
     106typedef anim_track_elem< ::x42::math::affine > affine_track_elem; 
     107 
     108class animation_tracks 
     109{ 
     110public: 
     111        std::vector< vec3_track_elem >          position; 
     112        std::vector< quat_track_elem >          rotation; 
     113        std::vector< vec3_track_elem >          scale; 
     114 
     115        std::vector< affine_track_elem >        world_matrices; 
     116        std::vector< affine_track_elem >        local_matrices; 
     117}; 
     118 
     119struct animation_tolerances 
     120{ 
     121        float                           position; 
     122        float                           rotation; 
     123        float                           scale; 
     124 
     125        animation_tolerances() 
     126                : position( 0 ), rotation( 0 ), scale( 0 ) 
     127        { 
     128        } 
     129 
     130        animation_tolerances( float position, float rotation, float scale ) 
     131                : position( position ), rotation( rotation ), scale( scale ) 
     132        { 
     133        } 
     134 
     135        animation_tolerances( const animation_tolerances &src ) 
     136                : position( src.position ), rotation( src.rotation ), scale( src.scale ) 
     137        { 
     138        } 
     139 
     140        static animation_tolerances resolve_inherited_values( const animation_tolerances &tol, const animation_tolerances &def ) 
     141        { 
     142                return animation_tolerances( 
     143                        tol.position >= 0 ? tol.position : def.position, 
     144                        tol.rotation >= 0 ? tol.rotation : def.rotation, 
     145                        tol.scale >= 0 ? tol.scale : def.scale ); 
     146        } 
     147 
     148        static animation_tolerances inherit_defaults() { return animation_tolerances( -1, -1, -1 ); } 
     149        static animation_tolerances loose_defaults() { return animation_tolerances( 0.01F, 0.003F, 0.02F ); } 
     150        static animation_tolerances tight_defaults() { return animation_tolerances( 1e-4F, 1e-3F, 1e-3F ); } 
     151}; 
     152 
     153class bone : public ref_obj 
     154{ 
     155public: 
     156        std::string                             name; 
     157 
     158        bone_flags                              flags; 
     159 
     160        animation_tolerances    loose_tolerances; 
     161        animation_tolerances    tight_tolerances; 
     162 
     163        bone_ptr                                parent() const { return _parent; } 
     164        void                                    parent( const bone_ptr &new_parent ); 
     165 
     166        uint                                    anim_group() const { return _anim_group; } 
     167        void                                    anim_group( uint new_anim_group ); 
     168 
     169        size_t                                  index() const { return _index; } 
     170 
     171private: 
     172        model_builder                   *owner; 
     173 
     174        size_t                                  _index; 
     175 
     176        uint                                    _anim_group; 
     177        bone_ptr                                _parent; 
     178         
     179        float                                   extent;                         //computed value 
     180        animation_tracks                anim_tracks; 
     181 
     182        bone( model_builder *owner ) 
     183                : owner( owner ), _anim_group( 0 ), extent( 0 ), 
     184                loose_tolerances( animation_tolerances::inherit_defaults() ), 
     185                tight_tolerances( animation_tolerances::inherit_defaults() ) 
     186        { 
     187        } 
     188 
     189        friend class model_builder; 
     190}; 
     191 
     192class influence : public ref_obj 
     193{ 
     194public: 
     195        bone_ptr                        bone; 
     196        ::x42::math::affine     matrix; 
     197 
     198private: 
     199        influence() { } 
     200 
     201        friend class model_builder; 
     202}; 
     203 
     204class tag : public ref_obj 
     205{ 
     206public: 
     207        std::string                     name; 
     208        bone_ptr                        bone; 
     209        ::x42::math::affine     matrix; 
     210 
     211private: 
     212        tag() { } 
     213 
     214        friend class model_builder; 
     215}; 
     216 
     217class animation : public ref_obj 
     218{ 
     219public: 
     220        std::string                     name; 
     221 
     222        uint                            first_frame; 
     223        uint                            last_frame; 
     224        uint                            loop_start; 
     225        uint                            loop_end; 
     226 
     227        float                           frame_rate; 
     228 
     229private: 
     230        animation() { } 
     231 
     232        friend class model_builder; 
     233}; 
     234 
    88235class vertex_weights; 
    89236 
     
    91238{ 
    92239public: 
    93         vertex_weight( influence_ptr influence = 0, float weight = 0 ) 
     240        vertex_weight( influence_ptr influence = influence_ptr(), float weight = 0 ) 
    94241                : _influence( influence ), _weight( ::x42::math::saturate( weight ) ) 
    95242        { 
     
    160307{ 
    161308public: 
     309        api_tag_ptr                                                     user_tag; 
     310 
     311        primitive_type                                          prim_type; 
    162312        std::vector< vertex_geometry >          base_shape; 
    163313        std::vector< morph_target_ptr >         morph_targets; 
     
    166316        std::vector< index >                            indices; 
    167317 
     318        geometry() 
     319                : prim_type( primitive_type::triangle_list ) 
     320        { 
     321        } 
     322 
    168323        morph_target_ptr find_morph_target( const std::string &name ) const; 
    169324        morph_target_ptr create_morph_target( const std::string &name ); 
    170325 
     326        /* 
     327                Reorders the group's vertices based on a remapping table. 
     328 
     329                The remapping table is a simple push mapping (value at index i is 
     330                the target position of the element currently at index i). 
     331        */ 
     332        void remap_vertices( const std::vector< index > &remap ); 
     333 
    171334        bool is_valid() const; 
    172335}; 
     
    175338{ 
    176339public: 
    177         geometry        group_geometry; 
    178 }; 
    179  
    180 class influence : public ref_obj 
    181 
     340        std::string             surface_name; 
     341        std::string             material_name; 
     342        geometry                group_geometry; 
     343 
     344private: 
     345        group() { } 
     346 
     347        friend class lod; 
     348}; 
     349 
     350class lod : public ref_obj 
     351
     352public: 
     353        uint                                            lod_number; 
     354        std::vector< group_ptr >        groups; 
     355 
     356        group_ptr create_group( const std::string &surface_name = std::string(), 
     357                const std::string &material_name = std::string() ); 
     358 
     359private: 
     360        lod() { } 
     361 
     362        friend class model_builder; 
     363}; 
     364 
     365class model_builder : public ref_obj 
     366
     367public: 
     368        std::vector< lod_ptr >          lods; 
     369        std::vector< bone_ptr >         bones; 
     370 
     371        animation_tolerances            loose_tolerances; 
     372        animation_tolerances            tight_tolerances; 
     373 
     374        model_builder() 
     375                : loose_tolerances( animation_tolerances::loose_defaults() ), 
     376                tight_tolerances( animation_tolerances::tight_defaults() ), 
     377                _bone_update_count( 0 ) 
     378        { 
     379        } 
     380 
     381        lod_ptr find_lod( uint lod_number ); 
     382        lod_ptr find_or_create_lod( uint lod_number ); 
     383 
     384        bone_ptr create_bone( const std::string &name = std::string(), const bone_ptr &parent = bone_ptr() ); 
     385 
     386        void begin_bone_update(); //suspends bone validation and sorting 
     387        void end_bone_update(); //resumes bone validation and sorting 
     388 
     389private: 
     390        int _bone_update_count; 
     391 
     392        void validate_bone_parent( bone *bone, const bone_ptr &new_parent ) const; 
     393        void validate_bone_anim_group( bone *bone, uint new_anim_group ) const; 
     394 
     395        void notify_bone_parent( bone *bone ); 
     396        void notify_bone_anim_group( bone *bone ); 
     397 
     398        void validate_bones(); 
     399        void sort_bones(); 
     400 
     401        friend class bone; 
    182402}; 
    183403 
  • branches/morph-targets/libx42make/include/x42make.h

    r507 r509  
    3333#include "x42make-modeldata.h" 
    3434#include "x42make-modelbuilder.h" 
     35#include "x42make-helpers.h" 
    3536 
    3637#endif 
  • branches/morph-targets/libx42make/libx42make.vcproj

    r507 r509  
    492492                        > 
    493493                        <File 
     494                                RelativePath=".\include\x42make-helpers.h" 
     495                                > 
     496                        </File> 
     497                        <File 
    494498                                RelativePath=".\include\x42make-modelbuilder.h" 
    495499                                > 
     
    654658                <File 
    655659                        RelativePath=".\modelbuilder-geometry.cpp" 
     660                        > 
     661                </File> 
     662                <File 
     663                        RelativePath=".\modelbuilder-skeleton.cpp" 
    656664                        > 
    657665                </File> 
  • branches/morph-targets/libx42make/modelbuilder-geometry.cpp

    r507 r509  
    2727namespace make 
    2828{ 
     29 
     30/* 
     31        class vertex_weights 
     32*/ 
    2933 
    3034void vertex_weights::add( const vertex_weight &weight, bool renormalize_weights ) 
     
    103107} 
    104108 
     109/* 
     110        class geometry 
     111*/ 
     112 
    105113morph_target_ptr geometry::find_morph_target( const std::string &name ) const 
    106114{ 
     
    127135} 
    128136 
     137void geometry::remap_vertices( const std::vector< index > &remap ) 
     138{ 
     139        apply_push_mapping( base_shape, remap ); 
     140         
     141        for( size_t i = 0; i < morph_targets.size(); i++ ) 
     142        { 
     143                apply_push_mapping( morph_targets[i]->vertices, remap ); 
     144        } 
     145 
     146        apply_push_mapping( weights, remap ); 
     147        apply_push_mapping( indices, remap ); 
     148 
     149        for( size_t i = 0; i < indices.size(); i++ ) 
     150                indices[i] = remap[indices[i]]; 
     151} 
     152 
     153bool geometry::is_valid() const 
     154{ 
     155        size_t num_verts = base_shape.size(); 
     156 
     157        if( weights.size() != num_verts || 
     158                attributes.size() != num_verts ) 
     159                return false; 
     160 
     161        for( size_t i = 0; i < morph_targets.size(); i++ ) 
     162        { 
     163                if( morph_targets[i]->vertices.size() != num_verts ) 
     164                        return false; 
     165        } 
     166 
     167        for( size_t i = 0; i < indices.size(); i++ ) 
     168        { 
     169                if( indices[i] >= num_verts ) 
     170                        return false; 
     171        } 
     172 
     173        return true; 
     174} 
     175 
    129176}; 
    130177}; 
  • branches/morph-targets/libx42make/modelbuilder.cpp

    r507 r509  
    2828{ 
    2929 
     30/* 
     31        class ref_obj 
     32*/ 
     33 
    3034namespace _impl 
    3135{ 
     
    4448}; 
    4549 
     50/* 
     51        class lod 
     52*/ 
     53 
     54group_ptr lod::create_group( const std::string &surface_name, 
     55        const std::string &material_name ) 
     56{ 
     57        group_ptr ret( new group ); 
     58 
     59        ret->surface_name = surface_name; 
     60        ret->material_name = material_name; 
     61 
     62        groups.push_back( ret ); 
     63 
     64        return ret; 
     65} 
     66 
     67/* 
     68        class model_builder 
     69*/ 
     70 
     71lod_ptr model_builder::find_lod( uint lod_number ) 
     72{ 
     73        for( size_t i = 0; i < lods.size(); i++ ) 
     74        { 
     75                if( lods[i]->lod_number == lod_number ) 
     76                        return lods[i]; 
     77        } 
     78 
     79        return lod_ptr(); 
     80} 
     81 
     82lod_ptr model_builder::find_or_create_lod( uint lod_number ) 
     83{ 
     84        size_t i; 
     85        for( i = 0; i < lods.size(); i++ ) 
     86        { 
     87                if( lods[i]->lod_number == lod_number ) 
     88                        return lods[i]; 
     89 
     90                if( lods[i]->lod_number > lod_number ) 
     91                        break; 
     92        } 
     93 
     94        lod_ptr ret( new lod() ); 
     95 
     96        ret->lod_number = lod_number; 
     97 
     98        lods.insert( lods.begin() + i, ret ); 
     99 
     100        return ret; 
     101} 
     102 
    46103}; 
    47104};