MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SaveHeader

Method SaveHeader

Source/Engine/Content/Assets/Animation.cpp:480–536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480bool Animation::SaveHeader(const ModelData& modelData, WriteStream& stream, int32 animIndex)
481{
482 // Validate input
483 if (animIndex < 0 || animIndex >= modelData.Animations.Count())
484 {
485 Log::ArgumentOutOfRangeException(TEXT("animIndex"));
486 return true;
487 }
488 auto& anim = modelData.Animations.Get()[animIndex];
489 if (anim.Duration <= ZeroTolerance || anim.FramesPerSecond <= ZeroTolerance)
490 {
491 Log::ArgumentOutOfRangeException(TEXT("Invalid animation duration."));
492 return true;
493 }
494 if (anim.Channels.IsEmpty())
495 {
496 Log::ArgumentOutOfRangeException(TEXT("Channels"), TEXT("Animation channels collection cannot be empty."));
497 return true;
498 }
499
500 // Info
501 stream.Write(103); // Header version (for fast version upgrades without serialization format change)
502 stream.Write(anim.Duration);
503 stream.Write(anim.FramesPerSecond);
504 stream.Write((byte)anim.RootMotionFlags);
505 stream.Write(anim.RootNodeName, 13);
506
507 // Animation channels
508 stream.WriteInt32(anim.Channels.Count());
509 for (const auto& channel : anim.Channels)
510 {
511 stream.Write(channel.NodeName, 172);
512 Serialization::Serialize(stream, channel.Position);
513 Serialization::Serialize(stream, channel.Rotation);
514 Serialization::Serialize(stream, channel.Scale);
515 }
516
517 // Animation events
518 stream.WriteInt32(anim.Events.Count());
519 for (auto& e : anim.Events)
520 {
521 stream.Write(e.First, 172);
522 stream.Write(e.Second.GetKeyframes().Count());
523 for (const auto& k : e.Second.GetKeyframes())
524 {
525 stream.Write(k.Time);
526 stream.Write(k.Value.Duration);
527 stream.Write(k.Value.TypeName, 17);
528 stream.WriteJson(k.Value.JsonData);
529 }
530 }
531
532 // Nested animations
533 stream.WriteInt32(0); // Empty list
534
535 return stream.HasError();
536}
537

Callers

nothing calls this directly

Calls 9

SerializeFunction · 0.50
CountMethod · 0.45
GetMethod · 0.45
IsEmptyMethod · 0.45
WriteMethod · 0.45
WriteInt32Method · 0.45
GetKeyframesMethod · 0.45
WriteJsonMethod · 0.45

Tested by

no test coverage detected