MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Load

Function Load

src/Nazara/Utility/Formats/MD5AnimLoader.cpp:31–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 }
30
31 bool Load(Animation* animation, Stream& stream, const AnimationParams& /*parameters*/)
32 {
33 ///TODO: Utiliser les paramètres
34 MD5AnimParser parser(stream);
35
36 if (!parser.Parse())
37 {
38 NazaraError("MD5Anim parser failed");
39 return false;
40 }
41
42 const MD5AnimParser::Frame* frames = parser.GetFrames();
43 UInt32 frameCount = parser.GetFrameCount();
44 UInt32 frameRate = parser.GetFrameRate();
45 const MD5AnimParser::Joint* joints = parser.GetJoints();
46 UInt32 jointCount = parser.GetJointCount();
47
48 // À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
49 animation->CreateSkeletal(frameCount, jointCount);
50
51 Sequence sequence;
52 sequence.firstFrame = 0;
53 sequence.frameCount = frameCount;
54 sequence.frameRate = frameRate;
55 sequence.name = stream.GetPath().SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true);
56
57 animation->AddSequence(sequence);
58
59 SequenceJoint* sequenceJoints = animation->GetSequenceJoints();
60
61 // Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
62 Quaternionf rotationQuat = Quaternionf::RotationBetween(Vector3f::UnitX(), Vector3f::Forward()) *
63 Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
64
65 for (UInt32 i = 0; i < jointCount; ++i)
66 {
67 int parent = joints[i].parent;
68 for (UInt32 j = 0; j < frameCount; ++j)
69 {
70 SequenceJoint& sequenceJoint = sequenceJoints[j*jointCount + i];
71
72 if (parent >= 0)
73 {
74 sequenceJoint.position = frames[j].joints[i].pos;
75 sequenceJoint.rotation = frames[j].joints[i].orient;
76 }
77 else
78 {
79 sequenceJoint.position = rotationQuat * frames[j].joints[i].pos;
80 sequenceJoint.rotation = rotationQuat * frames[j].joints[i].orient;
81 }
82
83 sequenceJoint.scale.Set(1.f);
84 }
85 }
86
87 return true;
88 }

Callers

nothing calls this directly

Calls 12

GetFramesMethod · 0.80
GetFrameRateMethod · 0.80
SubStringFromMethod · 0.80
AddSequenceMethod · 0.80
GetSequenceJointsMethod · 0.80
ParseMethod · 0.45
GetFrameCountMethod · 0.45
GetJointsMethod · 0.45
GetJointCountMethod · 0.45
CreateSkeletalMethod · 0.45
GetPathMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected