Changeset 509
- Timestamp:
- 02/19/08 19:23:19 (11 months ago)
- Files:
-
- branches/morph-targets/libx42make/include/x42make-helpers.h (added)
- branches/morph-targets/libx42make/include/x42make-modelbuilder.h (modified) (7 diffs)
- branches/morph-targets/libx42make/include/x42make.h (modified) (1 diff)
- branches/morph-targets/libx42make/libx42make.vcproj (modified) (2 diffs)
- branches/morph-targets/libx42make/modelbuilder-geometry.cpp (modified) (3 diffs)
- branches/morph-targets/libx42make/modelbuilder-skeleton.cpp (added)
- branches/morph-targets/libx42make/modelbuilder.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/morph-targets/libx42make/include/x42make-modelbuilder.h
r507 r509 33 33 34 34 class ref_obj; 35 typedef ::boost::intrusive_ptr< ref_obj > ref_obj_ptr; 36 typedef ::boost::intrusive_ptr< const ref_obj > const_ref_obj_ptr; 37 38 class api_tag; 39 typedef ::boost::intrusive_ptr< api_tag > api_tag_ptr; 40 typedef ::boost::intrusive_ptr< const api_tag > const_api_tag_ptr; 35 41 36 42 namespace _impl … … 43 49 { 44 50 public: 45 size_t ref_count() const { return _ref_count; }51 api_tag_ptr user_tag; 46 52 47 53 ref_obj() : _ref_count( 0 ) { } 48 54 virtual ~ref_obj() { } 49 55 56 size_t ref_count() const { return _ref_count; } 57 50 58 private: 51 59 size_t _ref_count; 52 60 53 61 friend void _impl::intrusive_ptr_add_ref( ref_obj *r ); 54 62 friend void _impl::intrusive_ptr_release( ref_obj *r ); 55 63 }; 56 64 57 class api_tag : ref_obj65 class api_tag : public ref_obj 58 66 { 59 67 public: … … 63 71 64 72 class 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;75 73 typedef ::boost::intrusive_ptr< lod > lod_ptr; 76 74 typedef ::boost::intrusive_ptr< const lod > const_lod_ptr; 75 76 class bone; 77 77 typedef ::boost::intrusive_ptr< bone > bone_ptr; 78 78 typedef ::boost::intrusive_ptr< const bone > const_bone_ptr; 79 80 class influence; 79 81 typedef ::boost::intrusive_ptr< influence > influence_ptr; 80 82 typedef ::boost::intrusive_ptr< const influence > const_influence_ptr; 83 84 class group; 81 85 typedef ::boost::intrusive_ptr< group > group_ptr; 82 86 typedef ::boost::intrusive_ptr< const group > const_group_ptr; 87 88 class morph_target; 83 89 typedef ::boost::intrusive_ptr< morph_target > morph_target_ptr; 84 90 typedef ::boost::intrusive_ptr< const morph_target > const_morph_target_ptr; 91 92 93 class model_builder; 85 94 typedef ::boost::intrusive_ptr< model_builder > model_builder_ptr; 86 95 typedef ::boost::intrusive_ptr< const model_builder > const_model_builder_ptr; 87 96 97 template< typename T > 98 struct anim_track_elem 99 { 100 uint frame; 101 T value; 102 }; 103 104 typedef anim_track_elem< ::x42::math::vec3 > vec3_track_elem; 105 typedef anim_track_elem< ::x42::math::quat > quat_track_elem; 106 typedef anim_track_elem< ::x42::math::affine > affine_track_elem; 107 108 class animation_tracks 109 { 110 public: 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 119 struct 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 153 class bone : public ref_obj 154 { 155 public: 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 171 private: 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 192 class influence : public ref_obj 193 { 194 public: 195 bone_ptr bone; 196 ::x42::math::affine matrix; 197 198 private: 199 influence() { } 200 201 friend class model_builder; 202 }; 203 204 class tag : public ref_obj 205 { 206 public: 207 std::string name; 208 bone_ptr bone; 209 ::x42::math::affine matrix; 210 211 private: 212 tag() { } 213 214 friend class model_builder; 215 }; 216 217 class animation : public ref_obj 218 { 219 public: 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 229 private: 230 animation() { } 231 232 friend class model_builder; 233 }; 234 88 235 class vertex_weights; 89 236 … … 91 238 { 92 239 public: 93 vertex_weight( influence_ptr influence = 0, float weight = 0 )240 vertex_weight( influence_ptr influence = influence_ptr(), float weight = 0 ) 94 241 : _influence( influence ), _weight( ::x42::math::saturate( weight ) ) 95 242 { … … 160 307 { 161 308 public: 309 api_tag_ptr user_tag; 310 311 primitive_type prim_type; 162 312 std::vector< vertex_geometry > base_shape; 163 313 std::vector< morph_target_ptr > morph_targets; … … 166 316 std::vector< index > indices; 167 317 318 geometry() 319 : prim_type( primitive_type::triangle_list ) 320 { 321 } 322 168 323 morph_target_ptr find_morph_target( const std::string &name ) const; 169 324 morph_target_ptr create_morph_target( const std::string &name ); 170 325 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 171 334 bool is_valid() const; 172 335 }; … … 175 338 { 176 339 public: 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 344 private: 345 group() { } 346 347 friend class lod; 348 }; 349 350 class lod : public ref_obj 351 { 352 public: 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 359 private: 360 lod() { } 361 362 friend class model_builder; 363 }; 364 365 class model_builder : public ref_obj 366 { 367 public: 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 389 private: 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; 182 402 }; 183 403 branches/morph-targets/libx42make/include/x42make.h
r507 r509 33 33 #include "x42make-modeldata.h" 34 34 #include "x42make-modelbuilder.h" 35 #include "x42make-helpers.h" 35 36 36 37 #endif branches/morph-targets/libx42make/libx42make.vcproj
r507 r509 492 492 > 493 493 <File 494 RelativePath=".\include\x42make-helpers.h" 495 > 496 </File> 497 <File 494 498 RelativePath=".\include\x42make-modelbuilder.h" 495 499 > … … 654 658 <File 655 659 RelativePath=".\modelbuilder-geometry.cpp" 660 > 661 </File> 662 <File 663 RelativePath=".\modelbuilder-skeleton.cpp" 656 664 > 657 665 </File> branches/morph-targets/libx42make/modelbuilder-geometry.cpp
r507 r509 27 27 namespace make 28 28 { 29 30 /* 31 class vertex_weights 32 */ 29 33 30 34 void vertex_weights::add( const vertex_weight &weight, bool renormalize_weights ) … … 103 107 } 104 108 109 /* 110 class geometry 111 */ 112 105 113 morph_target_ptr geometry::find_morph_target( const std::string &name ) const 106 114 { … … 127 135 } 128 136 137 void 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 153 bool 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 129 176 }; 130 177 }; branches/morph-targets/libx42make/modelbuilder.cpp
r507 r509 28 28 { 29 29 30 /* 31 class ref_obj 32 */ 33 30 34 namespace _impl 31 35 { … … 44 48 }; 45 49 50 /* 51 class lod 52 */ 53 54 group_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 71 lod_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 82 lod_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 46 103 }; 47 104 };
