Changeset 282 for trunk/src/formats
- Timestamp:
- 07/10/14 00:29:34 (11 years ago)
- Location:
- trunk/src/formats
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/formats/assimp_loader.cc
r280 r282 314 314 } 315 315 316 assimp_animation* nv::assimp_loader::release_animation( size_t, bool pre_transform , const std::vector< assimp_bone >* bone_data)316 assimp_animation* nv::assimp_loader::release_animation( size_t, bool pre_transform ) 317 317 { 318 318 if ( m_scene == nullptr ) return nullptr; … … 332 332 333 333 load_node( result, root, 0, -1 ); 334 // TODO: this is not used when pretransformed, is it used otherwise?335 336 if ( bone_data )337 {338 std::unordered_map< std::string, uint16 > names;339 for ( uint16 bi = 0; bi < bone_data->size(); ++bi )340 {341 names[ (*bone_data)[bi].name ] = bi;342 }343 344 for ( unsigned i = 0; i < result->nodes.size(); ++i )345 {346 assimp_animated_node_data& node = result->nodes[i];347 node.bone_id = -1;348 auto bi = names.find( node.name );349 if ( bi != names.end() )350 {351 node.bone_id = bi->second;352 }353 if ( node.parent_id != -1 )354 {355 result->nodes[ node.parent_id ].children.push_back( &node );356 }357 }358 }359 360 334 return result; 361 335 } … … 391 365 a_data.name = name; 392 366 a_data.parent_id = parent_id; 393 a_data.bone_id = -1;394 367 // This value is ignored by the create_transformed_keys, but needed by create_direct_keys! 395 368 // TODO: find a common solution! … … 397 370 // node's without keys 398 371 a_data.transform = nv::assimp_mat4_cast( node->mTransformation ); 372 a_data.channel_count = 0; 399 373 400 374 if (anode) … … 402 376 if ( data->pretransformed ) 403 377 { 404 a_data.keys = create_transformed_keys( anode, parent_id >= 0 ? data->nodes[ parent_id ].keys: nullptr );378 create_transformed_keys( &a_data, anode, parent_id >= 0 ? &(data->nodes[ parent_id ]) : nullptr ); 405 379 } 406 380 else 407 381 { 408 a_data.keys = create_direct_keys(anode );382 create_direct_keys( &a_data, anode ); 409 383 } 410 384 } … … 418 392 } 419 393 420 key_animation_data* nv::assimp_loader::create_transformed_keys( const void* vnode, const key_animation_data* parent_keys)394 void nv::assimp_loader::create_transformed_keys( assimp_animated_node_data* data, const void* vnode, const assimp_animated_node_data* parent ) 421 395 { 422 396 const aiNodeAnim* node = (const aiNodeAnim*)vnode; 423 397 size_t max_keys = glm::max( node->mNumPositionKeys, node->mNumRotationKeys ); 424 nv::transform_vector* keys = new nv::transform_vector; 398 399 data->channel_count = 1; 400 data->channels[0] = key_raw_channel::create<assimp_key_tr>( max_keys ); 401 assimp_key_tr* channel = ((assimp_key_tr*)(data->channels[0]->data)); 402 425 403 for ( unsigned n = 0; n < max_keys; ++n ) 426 404 { … … 431 409 // TODO: only do the calculation when a rotate transform is present! 432 410 nv::transform ptr( vec3(), glm::quat_cast( m_rotate_transform ) ); 433 if ( parent_keys ) 434 { 435 const nv::transform_vector* pv = (const nv::transform_vector*)parent_keys; 436 if ( pv && pv->size() > 0 ) ptr = pv->get( glm::min( n, pv->size()-1 ) ); 411 if ( parent ) 412 { 413 key_raw_channel* pchannel = parent->channels[0]; 414 if ( parent->channels[0] && parent->channels[0]->count > 0 ) 415 { 416 ptr = ((assimp_key_tr*)pchannel->data)[ glm::min( n, parent->channels[0]->count-1 ) ].tform; 417 } 437 418 } 438 419 nv::transform key( ptr * nv::transform( pos * m_scale, rot ) ); 439 keys->insert( key );440 } 441 return keys; 442 } 443 444 key_animation_data* nv::assimp_loader::create_direct_keys( const void* vnode ) 445 { 420 channel[n].tform = key; 421 } 422 } 423 424 void nv::assimp_loader::create_direct_keys( assimp_animated_node_data* data, const void* vnode ) 425 { 426 data->channel_count = 0; 446 427 // TODO : support for m_rotate_transform and m_scale! ( should be easy ) 447 428 const aiNodeAnim* node = (const aiNodeAnim*)vnode; 448 if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) return nullptr; 449 key_vectors_prs* keys = new key_vectors_prs; 429 if ( node->mNumPositionKeys == 0 && node->mNumRotationKeys == 0 && node->mNumScalingKeys == 0 ) 430 { 431 return; 432 } 433 434 data->channel_count = 3; 435 data->channels[0] = key_raw_channel::create<assimp_key_p>( node->mNumPositionKeys ); 436 data->channels[1] = key_raw_channel::create<assimp_key_r>( node->mNumRotationKeys ); 437 data->channels[2] = key_raw_channel::create<assimp_key_s>( node->mNumScalingKeys ); 438 assimp_key_p* pchannel = ((assimp_key_p*)(data->channels[0]->data)); 439 assimp_key_r* rchannel = ((assimp_key_r*)(data->channels[1]->data)); 440 assimp_key_s* schannel = ((assimp_key_s*)(data->channels[2]->data)); 450 441 451 442 for ( unsigned np = 0; np < node->mNumPositionKeys; ++np ) 452 443 { 453 keys->insert_position( (float)node->mPositionKeys[np].mTime, m_scale * assimp_vec3_cast(node->mPositionKeys[np].mValue) ); 444 pchannel[np].time = (float)node->mPositionKeys[np].mTime; 445 pchannel[np].position = assimp_vec3_cast(node->mPositionKeys[np].mValue); 454 446 } 455 447 for ( unsigned np = 0; np < node->mNumRotationKeys; ++np ) 456 448 { 457 keys->insert_rotation( (float)node->mRotationKeys[np].mTime, assimp_quat_cast(node->mRotationKeys[np].mValue) ); 449 rchannel[np].time = (float)node->mRotationKeys[np].mTime; 450 rchannel[np].rotation = assimp_quat_cast(node->mRotationKeys[np].mValue); 458 451 } 459 452 if ( node->mNumScalingKeys > 0 ) … … 466 459 for ( unsigned np = 0; np < node->mNumRotationKeys; ++np ) 467 460 { 468 keys->insert_scale( (float)node->mScalingKeys[np].mTime, assimp_vec3_cast(node->mScalingKeys[np].mValue) );469 }470 }471 }472 return keys;473 } 474 461 schannel[np].time = (float)node->mScalingKeys[np].mTime; 462 schannel[np].scale = assimp_vec3_cast(node->mScalingKeys[np].mValue); 463 } 464 } 465 } 466 } 467 -
trunk/src/formats/md3_loader.cc
r280 r282 275 275 bool nv::md3_loader::load( stream& source ) 276 276 { 277 m_tags.clear();278 279 277 m_md3 = (void*)(new md3_t); 280 278 if ( !read_md3( (md3_t*)m_md3, source ) ) … … 285 283 } 286 284 287 void nv::md3_loader::load_tags( transform_vector& t,const std::string& tag )285 nv::key_raw_channel* nv::md3_loader::load_tags( const std::string& tag ) 288 286 { 289 287 md3_t* md3 = (md3_t*)m_md3; 288 key_raw_channel* result = key_raw_channel::create<md3_key>( md3->header.num_frames ); 289 // TODO: is this brain damaged in efficiency (loop nest order) or what? 290 290 for ( sint32 f = 0; f < md3->header.num_frames; ++f ) 291 291 { … … 300 300 vec3 axisy ( md3_vec3( rtag.axis[2] ) ); 301 301 vec3 origin ( md3_vec3( rtag.origin ) ); 302 t.insert( transform( origin, quat( mat3( axisx, axisy, axisz )) ) );302 ((md3_key*)(result->data))[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) ); 303 303 } 304 304 } 305 305 306 306 } 307 return result; 307 308 } 308 309 … … 408 409 const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags]; 409 410 std::string name( (char*)(rtag.name) ); 410 load_tags( result->get_map()[ name ], name ); 411 nv::key_raw_channel* keys = load_tags( name ); 412 result->insert( name, keys ); 411 413 } 412 414 return result; -
trunk/src/formats/md5_loader.cc
r280 r282 397 397 remove_quotes( joint.name ); 398 398 joint_infos.push_back( joint ); 399 m_joints. push_back( md5_joint( joint.parent_id, m_num_frames ));399 m_joints.emplace_back( joint.parent_id ); 400 400 next_line( sstream ); 401 401 } … … 490 490 for ( size_t i = 0; i < m_num_joints; ++i ) 491 491 { 492 const transform_vector& keys = m_joints[i].keys;493 skeleton[i] = interpolate( keys .get(frame0), keys.get(frame1), interpolation );492 const std::vector< transform >& keys = m_joints[i].keys; 493 skeleton[i] = interpolate( keys[frame0], keys[frame1], interpolation ); 494 494 } 495 495 } … … 519 519 if ( parent_id >= 0 ) // Has a parent joint 520 520 { 521 const transform_vector& ptv = m_joints[ size_t( parent_id ) ].keys;521 const std::vector< transform >& ptv = m_joints[ size_t( parent_id ) ].keys; 522 522 transform ptr; 523 if ( ptv.size() > index ) ptr = ptv .get( index );523 if ( ptv.size() > index ) ptr = ptv[ index ]; 524 524 glm::vec3 rot_pos = ptr.get_orientation() * pos; 525 525 … … 530 530 } 531 531 532 m_joints[i].keys. insert( transform( pos, orient ) );532 m_joints[i].keys.push_back( transform( pos, orient ) ); 533 533 } 534 534 }
Note: See TracChangeset
for help on using the changeset viewer.