@@ -459,6 +459,7 @@ RADIENT_STATUS InitializeAnimationCurve(const GLTF::AnimationSampler& Sample
459459 Uint32 AnimationIndex,
460460 Uint32 SamplerIndex,
461461 const char * CurveName,
462+ Uint32 ComponentCount,
462463 AnimationCurveStorage<ValueType>& Curve,
463464 ConvertValueType&& ConvertValue)
464465{
@@ -484,8 +485,17 @@ RADIENT_STATUS InitializeAnimationCurve(const GLTF::AnimationSampler& Sample
484485 }
485486
486487 const size_t ValuesPerKey = Interpolation == RADIENT_ANIMATION_INTERPOLATION_CUBIC_SPLINE ? 3u : 1u ;
487- if (Sampler.Inputs .size () > std::numeric_limits<size_t >::max () / ValuesPerKey ||
488- Sampler.OutputsVec4 .size () != Sampler.Inputs .size () * ValuesPerKey)
488+ if (Sampler.Inputs .size () > std::numeric_limits<size_t >::max () / ValuesPerKey)
489+ {
490+ LOG_ERROR_MESSAGE (" GLTF animation " , AnimationIndex, " sampler " , SamplerIndex,
491+ " has too many " , CurveName, " values" );
492+ return RADIENT_STATUS_INVALID_DATA ;
493+ }
494+
495+ const size_t ValueCount = Sampler.Inputs .size () * ValuesPerKey;
496+ if (Sampler.OutputComponentCount != ComponentCount ||
497+ Sampler.Outputs .size () % ComponentCount != 0 ||
498+ Sampler.Outputs .size () / ComponentCount != ValueCount)
489499 {
490500 LOG_ERROR_MESSAGE (" GLTF animation " , AnimationIndex, " sampler " , SamplerIndex,
491501 " has an invalid number of " , CurveName, " values" );
@@ -497,9 +507,9 @@ RADIENT_STATUS InitializeAnimationCurve(const GLTF::AnimationSampler& Sample
497507 std::transform (Sampler.Inputs .begin (), Sampler.Inputs .end (), Curve.Times .begin (),
498508 [AnimationStart](Float32 Time) { return Time - AnimationStart; });
499509
500- Curve.Values .reserve (Sampler. OutputsVec4 . size () );
501- for (const float4& Value : Sampler. OutputsVec4 )
502- Curve.Values .push_back (ConvertValue (Value ));
510+ Curve.Values .reserve (ValueCount );
511+ for (size_t ValueIndex = 0 ; ValueIndex < ValueCount; ++ValueIndex )
512+ Curve.Values .push_back (ConvertValue (Sampler. GetOutputElement (ValueIndex) ));
503513
504514 return RADIENT_STATUS_OK ;
505515}
@@ -553,22 +563,25 @@ RADIENT_STATUS CreateImportedSkeletonAnimation(const GLTF::Model&
553563 case GLTF ::AnimationChannel::PATH_TYPE ::TRANSLATION :
554564 Status = InitializeAnimationCurve (
555565 Sampler, AnimationStart, AnimationIndex, Channel.SamplerIndex , " translation" ,
566+ 3 ,
556567 Tracks[JointIndex].Translation ,
557- [](const float4& Value ) { return RadientFloat3{Value. x , Value. y , Value. z }; });
568+ [](const float * pValue ) { return RadientFloat3{pValue[ 0 ], pValue[ 1 ], pValue[ 2 ] }; });
558569 break ;
559570
560571 case GLTF ::AnimationChannel::PATH_TYPE ::ROTATION :
561572 Status = InitializeAnimationCurve (
562573 Sampler, AnimationStart, AnimationIndex, Channel.SamplerIndex , " rotation" ,
574+ 4 ,
563575 Tracks[JointIndex].Rotation ,
564- [](const float4& Value ) { return RadientQuaternion{Value. x , Value. y , Value. z , Value. w }; });
576+ [](const float * pValue ) { return RadientQuaternion{pValue[ 0 ], pValue[ 1 ], pValue[ 2 ], pValue[ 3 ] }; });
565577 break ;
566578
567579 case GLTF ::AnimationChannel::PATH_TYPE ::SCALE :
568580 Status = InitializeAnimationCurve (
569581 Sampler, AnimationStart, AnimationIndex, Channel.SamplerIndex , " scale" ,
582+ 3 ,
570583 Tracks[JointIndex].Scale ,
571- [](const float4& Value ) { return RadientFloat3{Value. x , Value. y , Value. z }; });
584+ [](const float * pValue ) { return RadientFloat3{pValue[ 0 ], pValue[ 1 ], pValue[ 2 ] }; });
572585 break ;
573586
574587 default :
0 commit comments