|
@@ -7,6 +7,8 @@
|
|
|
#include <Jolt/Skeleton/SkeletalAnimation.h>
|
|
|
#include <Jolt/Skeleton/SkeletonPose.h>
|
|
|
#include <Jolt/ObjectStream/TypeDeclarations.h>
|
|
|
+#include <Jolt/Core/StreamIn.h>
|
|
|
+#include <Jolt/Core/StreamOut.h>
|
|
|
|
|
|
JPH_NAMESPACE_BEGIN
|
|
|
|
|
@@ -107,4 +109,57 @@ void SkeletalAnimation::Sample(float inTime, SkeletonPose &ioPose) const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void SkeletalAnimation::SaveBinaryState(StreamOut &inStream) const
|
|
|
+{
|
|
|
+ inStream.Write((uint32)mAnimatedJoints.size());
|
|
|
+ for (const AnimatedJoint &j : mAnimatedJoints)
|
|
|
+ {
|
|
|
+ // Write Joint name and number of keyframes
|
|
|
+ inStream.Write(j.mJointName);
|
|
|
+ inStream.Write((uint32)j.mKeyframes.size());
|
|
|
+ for (const Keyframe &k : j.mKeyframes)
|
|
|
+ {
|
|
|
+ inStream.Write(k.mTime);
|
|
|
+ inStream.Write(k.mRotation);
|
|
|
+ inStream.Write(k.mTranslation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save additional parameters
|
|
|
+ inStream.Write(mIsLooping);
|
|
|
+}
|
|
|
+
|
|
|
+SkeletalAnimation::AnimationResult SkeletalAnimation::sRestoreFromBinaryState(StreamIn &inStream)
|
|
|
+{
|
|
|
+ AnimationResult result;
|
|
|
+
|
|
|
+ Ref<SkeletalAnimation> animation = new SkeletalAnimation;
|
|
|
+
|
|
|
+ // Restore animated joints
|
|
|
+ uint32 len = 0;
|
|
|
+ inStream.Read(len);
|
|
|
+ animation->mAnimatedJoints.resize(len);
|
|
|
+ for (AnimatedJoint &j : animation->mAnimatedJoints)
|
|
|
+ {
|
|
|
+ // Read joint name
|
|
|
+ inStream.Read(j.mJointName);
|
|
|
+
|
|
|
+ // Read keyframes
|
|
|
+ len = 0;
|
|
|
+ inStream.Read(len);
|
|
|
+ j.mKeyframes.resize(len);
|
|
|
+ for (Keyframe &k : j.mKeyframes)
|
|
|
+ {
|
|
|
+ inStream.Read(k.mTime);
|
|
|
+ inStream.Read(k.mRotation);
|
|
|
+ inStream.Read(k.mTranslation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Read additional parameters
|
|
|
+ inStream.Read(animation->mIsLooping);
|
|
|
+ result.Set(animation);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
JPH_NAMESPACE_END
|