Upgrade Utility

This commit is contained in:
Jérôme Leclercq
2021-05-24 19:10:53 +02:00
parent b936946154
commit cce32a64d4
120 changed files with 2328 additions and 2971 deletions

View File

@@ -20,7 +20,7 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string& extension)
bool IsSupported(const std::string_view& extension)
{
return (extension == "md2");
}
@@ -46,7 +46,7 @@ namespace Nz
return Ternary::False;
}
MeshRef Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
{
MD2_Header header;
if (stream.Read(&header, sizeof(MD2_Header)) != sizeof(MD2_Header))
@@ -80,7 +80,7 @@ namespace Nz
}
// Since the engine no longer supports keyframe animations, let's make a static mesh
MeshRef mesh = Nz::Mesh::New();
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
if (!mesh->CreateStatic())
{
NazaraInternalError("Failed to create mesh");
@@ -107,7 +107,7 @@ namespace Nz
}
}
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, parameters.indexBufferFlags);
std::shared_ptr<IndexBuffer> indexBuffer = std::make_shared<IndexBuffer>(false, header.num_tris*3, parameters.storage, parameters.indexBufferFlags);
// Extract triangles data
std::vector<MD2_Triangle> triangles(header.num_tris);
@@ -116,7 +116,7 @@ namespace Nz
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
// And convert them into an index buffer
BufferMapper<IndexBuffer> indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
BufferMapper<IndexBuffer> indexMapper(*indexBuffer, BufferAccess::DiscardAndWrite);
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
for (unsigned int i = 0; i < header.num_tris; ++i)
@@ -158,8 +158,8 @@ namespace Nz
}
#endif
VertexBufferRef vertexBuffer = VertexBuffer::New(parameters.vertexDeclaration, header.num_vertices, parameters.storage, parameters.vertexBufferFlags);
StaticMeshRef subMesh = StaticMesh::New(vertexBuffer, indexBuffer);
std::shared_ptr<VertexBuffer> vertexBuffer = std::make_shared<VertexBuffer>(parameters.vertexDeclaration, header.num_vertices, parameters.storage, parameters.vertexBufferFlags);
std::shared_ptr<StaticMesh> subMesh = std::make_shared<StaticMesh>(vertexBuffer, indexBuffer);
// Extracting vertices
stream.SetCursorPos(header.offset_frames);
@@ -186,10 +186,10 @@ namespace Nz
scale *= ScaleAdjust;
translate *= ScaleAdjust;
VertexMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
VertexMapper vertexMapper(*vertexBuffer, BufferAccess::DiscardAndWrite);
// Loading texture coordinates
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord))
if (auto uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent::TexCoord))
{
const unsigned int indexFix[3] = {0, 2, 1};
@@ -214,7 +214,7 @@ namespace Nz
Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale);
matrix *= parameters.matrix;
if (auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal))
if (auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal))
{
Nz::Matrix4f normalMatrix = Matrix4f::Rotate(rotationQuat);
normalMatrix *= parameters.matrix;
@@ -227,7 +227,7 @@ namespace Nz
}
}
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
auto posPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Position);
assert(posPtr);
for (unsigned int v = 0; v < header.num_vertices; ++v)
@@ -244,7 +244,7 @@ namespace Nz
subMesh->GenerateAABB();
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Tangent))
if (parameters.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent::Tangent))
subMesh->GenerateTangents();
mesh->AddSubMesh(subMesh);
@@ -258,14 +258,14 @@ namespace Nz
namespace Loaders
{
void RegisterMD2()
MeshLoader::Entry GetMeshLoader_MD2()
{
MeshLoader::RegisterLoader(IsSupported, Check, Load);
}
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
void UnregisterMD2()
{
MeshLoader::UnregisterLoader(IsSupported, Check, Load);
return loader;
}
}
}