Merged MeshParameters into ModelParameters

Former-commit-id: 187541bd30255f64758d96b80e6280842699124d
This commit is contained in:
Lynix 2013-03-05 10:42:18 +01:00
parent 078e590f9b
commit a97da928a2
2 changed files with 15 additions and 14 deletions

View File

@ -18,8 +18,9 @@ struct NzModelParameters
{ {
bool loadAnimation = true; bool loadAnimation = true;
bool loadMaterials = true; bool loadMaterials = true;
NzAnimationParams animationParams; NzAnimationParams animation;
NzMaterialParams materialParams; NzMaterialParams material;
NzMeshParams mesh;
}; };
class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
@ -55,9 +56,9 @@ class NAZARA_API NzModel : public NzSceneNode, public NzUpdatable
bool IsDrawEnabled() const; bool IsDrawEnabled() const;
bool IsVisible(const NzFrustumf& frustum) const override; bool IsVisible(const NzFrustumf& frustum) const override;
bool LoadFromFile(const NzString& meshPath, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters()); bool LoadFromFile(const NzString& meshPath, const NzModelParameters& modelParameters = NzModelParameters());
bool LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters()); bool LoadFromMemory(const void* data, std::size_t size, const NzModelParameters& modelParameters = NzModelParameters());
bool LoadFromStream(NzInputStream& stream, const NzMeshParams& meshParameters = NzMeshParams(), const NzModelParameters& modelParameters = NzModelParameters()); bool LoadFromStream(NzInputStream& stream, const NzModelParameters& modelParameters = NzModelParameters());
void Reset(); void Reset();

View File

@ -277,11 +277,11 @@ bool NzModel::IsVisible(const NzFrustumf& frustum) const
return frustum.Contains(m_boundingBox); return frustum.Contains(m_boundingBox);
} }
bool NzModel::LoadFromFile(const NzString& meshPath, const NzMeshParams& meshParameters, const NzModelParameters& modelParameters) bool NzModel::LoadFromFile(const NzString& meshPath, const NzModelParameters& modelParameters)
{ {
///TODO: ResourceManager ///TODO: ResourceManager
std::unique_ptr<NzMesh> mesh(new NzMesh); std::unique_ptr<NzMesh> mesh(new NzMesh);
if (!mesh->LoadFromFile(meshPath, meshParameters)) if (!mesh->LoadFromFile(meshPath, modelParameters.mesh))
{ {
NazaraError("Failed to load mesh"); NazaraError("Failed to load mesh");
return false; return false;
@ -293,10 +293,10 @@ bool NzModel::LoadFromFile(const NzString& meshPath, const NzMeshParams& meshPar
return true; return true;
} }
bool NzModel::LoadFromMemory(const void* data, std::size_t size, const NzMeshParams& meshParameters, const NzModelParameters& modelParameters) bool NzModel::LoadFromMemory(const void* data, std::size_t size, const NzModelParameters& modelParameters)
{ {
std::unique_ptr<NzMesh> mesh(new NzMesh); std::unique_ptr<NzMesh> mesh(new NzMesh);
if (!mesh->LoadFromMemory(data, size, meshParameters)) if (!mesh->LoadFromMemory(data, size, modelParameters.mesh))
{ {
NazaraError("Failed to load mesh"); NazaraError("Failed to load mesh");
return false; return false;
@ -308,10 +308,10 @@ bool NzModel::LoadFromMemory(const void* data, std::size_t size, const NzMeshPar
return true; return true;
} }
bool NzModel::LoadFromStream(NzInputStream& stream, const NzMeshParams& meshParameters, const NzModelParameters& modelParameters) bool NzModel::LoadFromStream(NzInputStream& stream, const NzModelParameters& modelParameters)
{ {
std::unique_ptr<NzMesh> mesh(new NzMesh); std::unique_ptr<NzMesh> mesh(new NzMesh);
if (!mesh->LoadFromStream(stream, meshParameters)) if (!mesh->LoadFromStream(stream, modelParameters.mesh))
{ {
NazaraError("Failed to load mesh"); NazaraError("Failed to load mesh");
return false; return false;
@ -457,6 +457,7 @@ void NzModel::SetMesh(NzMesh* mesh, const NzModelParameters& modelParameters)
if (mesh) if (mesh)
{ {
m_boundingBoxUpdated = false;
m_mesh = mesh; m_mesh = mesh;
m_mesh->AddResourceReference(); m_mesh->AddResourceReference();
@ -469,7 +470,7 @@ void NzModel::SetMesh(NzMesh* mesh, const NzModelParameters& modelParameters)
if (!animationPath.IsEmpty()) if (!animationPath.IsEmpty())
{ {
std::unique_ptr<NzAnimation> animation(new NzAnimation); std::unique_ptr<NzAnimation> animation(new NzAnimation);
if (animation->LoadFromFile(animationPath, modelParameters.animationParams) && SetAnimation(animation.get())) if (animation->LoadFromFile(animationPath, modelParameters.animation) && SetAnimation(animation.get()))
{ {
animation->SetPersistent(false); animation->SetPersistent(false);
animation.release(); animation.release();
@ -479,7 +480,6 @@ void NzModel::SetMesh(NzMesh* mesh, const NzModelParameters& modelParameters)
} }
} }
m_boundingBoxUpdated = false;
m_matCount = mesh->GetMaterialCount(); m_matCount = mesh->GetMaterialCount();
m_materials.resize(m_matCount, NzMaterial::GetDefault()); m_materials.resize(m_matCount, NzMaterial::GetDefault());
if (modelParameters.loadMaterials) if (modelParameters.loadMaterials)
@ -490,7 +490,7 @@ void NzModel::SetMesh(NzMesh* mesh, const NzModelParameters& modelParameters)
if (!mat.IsEmpty()) if (!mat.IsEmpty())
{ {
std::unique_ptr<NzMaterial> material(new NzMaterial); std::unique_ptr<NzMaterial> material(new NzMaterial);
if (material->LoadFromFile(mat, modelParameters.materialParams)) if (material->LoadFromFile(mat, modelParameters.material))
{ {
material->SetPersistent(false, false); // Pas de vérification des références car nous n'y avons pas encore accroché de référence material->SetPersistent(false, false); // Pas de vérification des références car nous n'y avons pas encore accroché de référence
m_materials[i] = material.release(); m_materials[i] = material.release();