Make mesh able to carry material informations
- Move OBJ Loader to Utility module, where it belongs - Change Mesh material informations from a path to a parameterlist - Improve Mesh code Former-commit-id: f16f48f8b6399188a09797cec3707ab6726bdbca
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/Formats/MeshLoader.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Graphics/Material.hpp>
|
||||
#include <Nazara/Graphics/Model.hpp>
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <Nazara/Utility/MaterialData.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
@@ -14,6 +16,33 @@ namespace Nz
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void LoadMaterials(Model* model, const ModelParameters& parameters)
|
||||
{
|
||||
unsigned int matCount = model->GetMaterialCount();
|
||||
|
||||
for (unsigned int i = 0; i < matCount; ++i)
|
||||
{
|
||||
const ParameterList& matData = model->GetMesh()->GetMaterialData(i);
|
||||
|
||||
String filePath;
|
||||
if (matData.GetStringParameter(MaterialData::FilePath, &filePath))
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
if (material->LoadFromFile(filePath, parameters.material))
|
||||
model->SetMaterial(i, std::move(material));
|
||||
else
|
||||
NazaraWarning("Failed to load material from file " + String::Number(i));
|
||||
}
|
||||
else if (matData.HasParameter(MaterialData::CustomDefined))
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
material->BuildFromParameters(matData, parameters.material);
|
||||
|
||||
model->SetMaterial(i, std::move(material));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ternary CheckStatic(Stream& stream, const ModelParameters& parameters)
|
||||
{
|
||||
NazaraUnused(stream);
|
||||
@@ -46,22 +75,7 @@ namespace Nz
|
||||
model->SetMesh(mesh);
|
||||
|
||||
if (parameters.loadMaterials)
|
||||
{
|
||||
unsigned int matCount = model->GetMaterialCount();
|
||||
|
||||
for (unsigned int i = 0; i < matCount; ++i)
|
||||
{
|
||||
String mat = mesh->GetMaterial(i);
|
||||
if (!mat.IsEmpty())
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
if (material->LoadFromFile(mat, parameters.material))
|
||||
model->SetMaterial(i, material);
|
||||
else
|
||||
NazaraWarning("Failed to load material #" + String::Number(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
LoadMaterials(model, parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -98,22 +112,7 @@ namespace Nz
|
||||
model->SetMesh(mesh);
|
||||
|
||||
if (parameters.loadMaterials)
|
||||
{
|
||||
unsigned int matCount = model->GetMaterialCount();
|
||||
|
||||
for (unsigned int i = 0; i < matCount; ++i)
|
||||
{
|
||||
String mat = mesh->GetMaterial(i);
|
||||
if (!mat.IsEmpty())
|
||||
{
|
||||
MaterialRef material = Material::New();
|
||||
if (material->LoadFromFile(mat, parameters.material))
|
||||
model->SetMaterial(i, material);
|
||||
else
|
||||
NazaraWarning("Failed to load material #" + String::Number(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
LoadMaterials(model, parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user