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

Function Load

src/Nazara/Utility/Formats/MD5MeshLoader.cpp:37–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 }
36
37 bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
38 {
39 MD5MeshParser parser(stream);
40 if (!parser.Parse())
41 {
42 NazaraError("MD5Mesh parser failed");
43 return false;
44 }
45
46 // Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
47 Quaternionf rotationQuat = Quaternionf::RotationBetween(Vector3f::UnitX(), Vector3f::Forward()) *
48 Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
49
50 String baseDir = stream.GetDirectory();
51
52 // Le hellknight de Doom 3 fait ~120 unités, et il est dit qu'il fait trois mètres
53 // Nous réduisons donc la taille générale des fichiers MD5 de 1/40
54 Matrix4f matrix = Matrix4f::Transform(Nz::Vector3f::Zero(), rotationQuat, Vector3f(1.f / 40.f));
55 matrix *= parameters.matrix;
56
57 const MD5MeshParser::Joint* joints = parser.GetJoints();
58 const MD5MeshParser::Mesh* meshes = parser.GetMeshes();
59 UInt32 jointCount = parser.GetJointCount();
60 UInt32 meshCount = parser.GetMeshCount();
61
62 if (parameters.animated)
63 {
64 mesh->CreateSkeletal(jointCount);
65
66 Skeleton* skeleton = mesh->GetSkeleton();
67 for (UInt32 i = 0; i < jointCount; ++i)
68 {
69 Joint* joint = skeleton->GetJoint(i);
70
71 int parent = joints[i].parent;
72 if (parent >= 0)
73 joint->SetParent(skeleton->GetJoint(parent));
74
75 joint->SetName(joints[i].name);
76
77 Matrix4f bindMatrix;
78
79 if (parent >= 0)
80 bindMatrix.MakeTransform(joints[i].bindPos, joints[i].bindOrient);
81 else
82 bindMatrix.MakeTransform(rotationQuat * joints[i].bindPos, rotationQuat * joints[i].bindOrient);
83
84 joint->SetInverseBindMatrix(bindMatrix.InverseAffine());
85 }
86
87 mesh->SetMaterialCount(meshCount);
88 for (UInt32 i = 0; i < meshCount; ++i)
89 {
90 const MD5MeshParser::Mesh& md5Mesh = meshes[i];
91
92 std::size_t indexCount = md5Mesh.triangles.size()*3;
93 std::size_t vertexCount = md5Mesh.vertices.size();
94

Callers

nothing calls this directly

Calls 15

GetMeshesMethod · 0.80
GetMeshCountMethod · 0.80
GetJointMethod · 0.80
SetParentMethod · 0.80
SetInverseBindMatrixMethod · 0.80
SetMaterialCountMethod · 0.80
SetParameterMethod · 0.80
SetMaterialDataMethod · 0.80
SetMaterialIndexMethod · 0.80
SetPrimitiveModeMethod · 0.80
AddSubMeshMethod · 0.80
IsEmptyMethod · 0.80

Tested by

no test coverage detected