| 2477 | #endif |
| 2478 | |
| 2479 | void Tr2AnimationMeshBinding::CreateBinding() |
| 2480 | { |
| 2481 | if( m_geometryRes && m_geometryRes->IsGood() && m_animation && m_animation->IsInitialized() ) |
| 2482 | { |
| 2483 | if( m_animation->IsUsingCMF() ) |
| 2484 | { |
| 2485 | auto cmfData = m_geometryRes->GetCMFData(); |
| 2486 | if( !cmfData ) |
| 2487 | { |
| 2488 | return; |
| 2489 | } |
| 2490 | if( int( m_meshIndex ) >= cmfData->meshes.size() || int( m_meshIndex ) < 0 ) |
| 2491 | { |
| 2492 | return; |
| 2493 | } |
| 2494 | auto& mesh = cmfData->meshes[m_meshIndex]; |
| 2495 | |
| 2496 | // prefer m_geometryRes skeleton, use m_animation skeleton as fallback |
| 2497 | m_cmfSkeleton = mesh.skeleton < cmfData->skeletons.size() ? &cmfData->skeletons[mesh.skeleton] : m_animation->GetSkeleton(); |
| 2498 | |
| 2499 | if( m_cmfSkeleton ) |
| 2500 | { |
| 2501 | if( mesh.boneBindings.size() > 0 ) |
| 2502 | { |
| 2503 | m_boneTransforms.reset( new Float4x3[mesh.boneBindings.size()] ); |
| 2504 | } |
| 2505 | |
| 2506 | m_bindBoneIndices = Tr2GrannyAnimationUtils::CreateMapping( *m_cmfSkeleton, mesh.boneBindings, (uint32_t)mesh.boneBindings.size() ); |
| 2507 | m_animBoneIndices = Tr2GrannyAnimationUtils::CreateMapping( *m_animation->GetSkeleton(), mesh.boneBindings, (uint32_t)mesh.boneBindings.size() ); |
| 2508 | } |
| 2509 | } |
| 2510 | #if WITH_GRANNY |
| 2511 | else |
| 2512 | { |
| 2513 | auto fi = m_geometryRes->GetGrannyInfo(); |
| 2514 | if( !fi ) |
| 2515 | { |
| 2516 | return; |
| 2517 | } |
| 2518 | if( int( m_meshIndex ) >= fi->MeshCount || int( m_meshIndex ) < 0 ) |
| 2519 | { |
| 2520 | return; |
| 2521 | } |
| 2522 | auto mesh = fi->Meshes[m_meshIndex]; |
| 2523 | auto meshSkeleton = m_animation->m_skeleton; |
| 2524 | for( int32_t i = 0; i < fi->ModelCount; ++i ) |
| 2525 | { |
| 2526 | auto model = fi->Models[i]; |
| 2527 | if( model && model->Skeleton ) |
| 2528 | { |
| 2529 | auto found = std::find_if( model->MeshBindings, model->MeshBindings + model->MeshBindingCount, [mesh]( const auto& binding ) { return binding.Mesh == mesh; } ); |
| 2530 | if( found != model->MeshBindings + model->MeshBindingCount ) |
| 2531 | { |
| 2532 | meshSkeleton = model->Skeleton; |
| 2533 | break; |
| 2534 | } |
| 2535 | } |
| 2536 | } |
no test coverage detected