| 2369 | } |
| 2370 | |
| 2371 | std::pair<const Float4x3*, size_t> Tr2AnimationMeshBinding::GetBoneTransforms() const |
| 2372 | { |
| 2373 | if( m_animation->IsUsingCMF() ) |
| 2374 | { |
| 2375 | if( !m_cmfSkeleton || !m_boneTransforms ) |
| 2376 | { |
| 2377 | return std::make_pair( nullptr, 0 ); |
| 2378 | } |
| 2379 | |
| 2380 | auto boneCount = m_geometryRes->GetCMFData()->meshes[m_meshIndex].boneBindings.size(); |
| 2381 | |
| 2382 | if( m_boneTransforms && m_bindBoneIndices.size() && boneCount ) |
| 2383 | { |
| 2384 | auto& worldTransforms = m_animation->GetWorldTransforms(); |
| 2385 | if( m_cmfSkeleton != m_animation->GetSkeleton() ) |
| 2386 | { |
| 2387 | CCP_ASSERT( boneCount <= m_animBoneIndices.size() ); |
| 2388 | for( int32_t i = 0; i < boneCount; ++i ) |
| 2389 | { |
| 2390 | if( m_animBoneIndices[i] == -1 ) |
| 2391 | { |
| 2392 | m_boneTransforms[i] = Float4x3( Matrix() ); |
| 2393 | continue; |
| 2394 | } |
| 2395 | CCP_ASSERT( m_bindBoneIndices[i] < m_cmfSkeleton->invBindTransforms.size() ); |
| 2396 | CCP_ASSERT( m_animBoneIndices[i] < worldTransforms.size() ); |
| 2397 | Matrix skinMatrix = m_cmfSkeleton->invBindTransforms[m_bindBoneIndices[i]] * worldTransforms[m_animBoneIndices[i]]; |
| 2398 | m_boneTransforms[i] = Float4x3( skinMatrix ); |
| 2399 | } |
| 2400 | } |
| 2401 | else |
| 2402 | { |
| 2403 | for( int32_t i = 0; i < boneCount; i++ ) |
| 2404 | { |
| 2405 | int32_t boneIdx = m_bindBoneIndices[i]; |
| 2406 | if( boneIdx >= 0 ) |
| 2407 | { |
| 2408 | Matrix skinMatrix = m_cmfSkeleton->invBindTransforms[boneIdx] * worldTransforms[boneIdx]; |
| 2409 | m_boneTransforms[i] = Float4x3( skinMatrix ); |
| 2410 | } |
| 2411 | } |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | return { m_boneTransforms.get(), boneCount }; |
| 2416 | } |
| 2417 | #if WITH_GRANNY |
| 2418 | else |
| 2419 | { |
| 2420 | if( !m_meshBinding || !m_boneTransforms ) |
| 2421 | { |
| 2422 | return std::make_pair( nullptr, 0 ); |
| 2423 | } |
| 2424 | |
| 2425 | auto boneCount = GrannyGetMeshBindingBoneCount( m_meshBinding.get() ); |
| 2426 | |
| 2427 | auto meshToBone = GrannyGetMeshBindingFromBoneIndices( m_meshBinding.get() ); |
| 2428 | if( m_boneTransforms && meshToBone && boneCount ) |
nothing calls this directly
no test coverage detected