| | 258 | void geometry::append( const geometry &geom ) |
|---|
| | 259 | { |
|---|
| | 260 | if( !are_vert_arrays_parallell() ) |
|---|
| | 261 | throw error( "Can't append to an invalid group." ); |
|---|
| | 262 | |
|---|
| | 263 | if( !geom.are_vert_arrays_parallell() ) |
|---|
| | 264 | throw error( "Can't append an invalid group." ); |
|---|
| | 265 | |
|---|
| | 266 | if( geom.prim_type.to_list_type() != prim_type.to_list_type() ) |
|---|
| | 267 | throw error( "Can't append a group with an incompatible primitive type." ); |
|---|
| | 268 | |
|---|
| | 269 | size_t base_vert = base_shape.size(); |
|---|
| | 270 | |
|---|
| | 271 | base_shape.insert( base_shape.end(), |
|---|
| | 272 | geom.base_shape.begin(), geom.base_shape.end() ); |
|---|
| | 273 | weights.insert( weights.end(), |
|---|
| | 274 | geom.weights.begin(), geom.weights.end() ); |
|---|
| | 275 | attributes.insert( attributes.end(), |
|---|
| | 276 | geom.attributes.begin(), geom.attributes.end() ); |
|---|
| | 277 | |
|---|
| | 278 | std::vector< bool > targets_appended( geom.morph_targets.size(), false ); |
|---|
| | 279 | for( size_t i = 0; i < morph_targets.size(); i++ ) |
|---|
| | 280 | { |
|---|
| | 281 | morph_target_ptr dst = morph_targets[i]; |
|---|
| | 282 | const_morph_target_ptr src; |
|---|
| | 283 | |
|---|
| | 284 | for( size_t j = 0; !src && j < geom.morph_targets.size(); j++ ) |
|---|
| | 285 | { |
|---|
| | 286 | if( geom.morph_targets[j]->name() == dst->name() ) |
|---|
| | 287 | { |
|---|
| | 288 | src = geom.morph_targets[j]; |
|---|
| | 289 | targets_appended[j] = true; |
|---|
| | 290 | } |
|---|
| | 291 | } |
|---|
| | 292 | |
|---|
| | 293 | if( src ) |
|---|
| | 294 | { |
|---|
| | 295 | dst->vertices.insert( dst->vertices.end(), |
|---|
| | 296 | src->vertices.begin(), src->vertices.end() ); |
|---|
| | 297 | } |
|---|
| | 298 | else |
|---|
| | 299 | { |
|---|
| | 300 | //pull in an identity target (copy the base shape) |
|---|
| | 301 | dst->vertices.insert( dst->vertices.end(), |
|---|
| | 302 | geom.base_shape.begin(), geom.base_shape.end() ); |
|---|
| | 303 | } |
|---|
| | 304 | } |
|---|
| | 305 | |
|---|
| | 306 | //add in any morph targets that haven't already been merged in |
|---|
| | 307 | for( size_t i = 0; i < geom.morph_targets.size(); i++ ) |
|---|
| | 308 | { |
|---|
| | 309 | if( targets_appended[i] ) |
|---|
| | 310 | //already handled |
|---|
| | 311 | continue; |
|---|
| | 312 | |
|---|
| | 313 | const_morph_target_ptr src = geom.morph_targets[i]; |
|---|
| | 314 | morph_target_ptr dst = create_morph_target( src->name() ); |
|---|
| | 315 | |
|---|
| | 316 | dst->vertices.insert( dst->vertices.end(), |
|---|
| | 317 | base_shape.begin(), base_shape.begin() + base_vert ); |
|---|
| | 318 | dst->vertices.insert( dst->vertices.end(), |
|---|
| | 319 | src->vertices.begin(), src->vertices.end() ); |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | if( geom.prim_type == prim_type ) |
|---|
| | 323 | { |
|---|
| | 324 | indices.reserve( indices.size() + geom.indices.size() ); |
|---|
| | 325 | for( size_t i = 0; i < geom.indices.size(); i++ ) |
|---|
| | 326 | indices.push_back( checked_int_cast< index >( geom.indices[i] + base_vert ) ); |
|---|
| | 327 | } |
|---|
| | 328 | else |
|---|
| | 329 | { |
|---|
| | 330 | std::vector< index > list_indices = geom.get_list_indices(); |
|---|
| | 331 | indices.reserve( indices.size() + list_indices.size() ); |
|---|
| | 332 | for( size_t i = 0; i < list_indices.size(); i++ ) |
|---|
| | 333 | indices.push_back( checked_int_cast< index >( list_indices[i] + base_vert ) ); |
|---|
| | 334 | } |
|---|
| | 335 | } |
|---|
| | 336 | |
|---|