From 63ac80c7ffdd65714816682a5d9c5e616b48d2ad Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:46:44 +0200 Subject: [PATCH 1/6] Utility/Mesh: Replace scale by transform matrix Former-commit-id: b02de61fe0213f5fdd074dfa868db415e9c770c3 [formerly e185f2b410f2a3e04a0f11be28665cf6e8dcb617] Former-commit-id: d0c7e88fe2b5f8a4aa97640d050751def83f3783 --- SDK/include/NDK/LuaAPI.inl | 2 +- include/Nazara/Utility/Mesh.hpp | 4 ++-- plugins/Assimp/Plugin.cpp | 2 +- src/Nazara/Utility/Formats/MD2Loader.cpp | 13 +++++++------ src/Nazara/Utility/Formats/MD5MeshLoader.cpp | 5 +++-- src/Nazara/Utility/Formats/OBJLoader.cpp | 3 +-- src/Nazara/Utility/Mesh.cpp | 6 +++--- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/SDK/include/NDK/LuaAPI.inl b/SDK/include/NDK/LuaAPI.inl index a42479cae..a09d6c459 100644 --- a/SDK/include/NDK/LuaAPI.inl +++ b/SDK/include/NDK/LuaAPI.inl @@ -100,8 +100,8 @@ namespace Nz params->animated = instance.CheckField("Animated", params->animated); params->center = instance.CheckField("Center", params->center); params->flipUVs = instance.CheckField("FlipUVs", params->flipUVs); + //params->matrix = instance.CheckField("Matrix", params->matrix); params->optimizeIndexBuffers = instance.CheckField("OptimizeIndexBuffers", params->optimizeIndexBuffers); - params->scale = instance.CheckField("Scale", params->scale); return 1; } diff --git a/include/Nazara/Utility/Mesh.hpp b/include/Nazara/Utility/Mesh.hpp index ff11b5d4d..865a228a9 100644 --- a/include/Nazara/Utility/Mesh.hpp +++ b/include/Nazara/Utility/Mesh.hpp @@ -29,8 +29,8 @@ namespace Nz { MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement) - // La mise à l'échelle éventuelle que subira le mesh - Vector3f scale = Vector3f::Unit(); + // La transformation appliquée à tous les sommets du mesh + Matrix4f matrix = Matrix4f::Identity(); // Si ceci sera le stockage utilisé par les buffers UInt32 storage = DataStorage_Hardware; diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index 68c443b29..d571e1ef6 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -209,7 +209,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) aiVector3D tangent = (iMesh->HasTangentsAndBitangents()) ? iMesh->mTangents[j] : aiVector3D(0.f, 1.f, 0.f); aiVector3D uv = (iMesh->HasTextureCoords(0)) ? iMesh->mTextureCoords[0][j] : aiVector3D(0.f); - vertex->position = parameters.scale * Vector3f(position.x, position.y, position.z); + vertex->position = parameters.matrix * Vector3f(position.x, position.y, position.z); vertex->normal.Set(normal.x, normal.y, normal.z); vertex->tangent.Set(tangent.x, tangent.y, tangent.z); vertex->uv.Set(uv.x, uv.y); diff --git a/src/Nazara/Utility/Formats/MD2Loader.cpp b/src/Nazara/Utility/Formats/MD2Loader.cpp index eef4ac63d..126eeaa35 100644 --- a/src/Nazara/Utility/Formats/MD2Loader.cpp +++ b/src/Nazara/Utility/Formats/MD2Loader.cpp @@ -188,11 +188,10 @@ namespace Nz SwapBytes(&translate.z, sizeof(float)); #endif - // Un personnage de taille moyenne fait ~50 unités de haut dans Quake 2 - // Avec Nazara, 1 unité = 1 mètre, nous devons donc adapter l'échelle - Vector3f s(parameters.scale/29.f); // 50/29 = 1.72 (Soit 1.72 mètre, proche de la taille moyenne d'un individu) - scale *= s; - translate *= s; + constexpr float ScaleAdjust = 1.f / 27.8f; // Make a 50 Quake 2 units character a 1.8 unit long + + scale *= ScaleAdjust; + translate *= ScaleAdjust; BufferMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite); MeshVertex* vertex = static_cast(vertexMapper.GetPointer()); @@ -215,11 +214,13 @@ namespace Nz /// Chargement des positions // Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices Quaternionf rotationQuat = EulerAnglesf(-90.f, 90.f, 0.f); + Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale); + matrix *= parameters.matrix; for (unsigned int v = 0; v < header.num_vertices; ++v) { const MD2_Vertex& vert = vertices[v]; - Vector3f position = rotationQuat * Vector3f(vert.x*scale.x + translate.x, vert.y*scale.y + translate.y, vert.z*scale.z + translate.z); + Vector3f position = matrix * Vector3f(vert.x, vert.y, vert.z); vertex->position = position; vertex->normal = rotationQuat * md2Normals[vert.n]; diff --git a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp index cda183313..ce56b136a 100644 --- a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp @@ -48,7 +48,8 @@ namespace Nz // Le hellknight de Doom 3 fait ~120 unités, et il est dit qu'il fait trois mètres // Nous réduisons donc la taille générale des fichiers MD5 de 1/40 - Vector3f scale(parameters.scale/40.f); + Matrix4f matrix = Matrix4f::Transform(Nz::Vector3f::Zero(), rotationQuat, Vector3f(1.f / 40.f)); + matrix *= parameters.matrix; const MD5MeshParser::Joint* joints = parser.GetJoints(); const MD5MeshParser::Mesh* meshes = parser.GetMeshes(); @@ -267,7 +268,7 @@ namespace Nz } // On retourne le modèle dans le bon sens - vertex->position = scale * (rotationQuat * finalPos); + vertex->position = matrix * finalPos; vertex->uv.Set(md5Vertex.uv.x, (parameters.flipUVs) ? 1.f - md5Vertex.uv.y : md5Vertex.uv.y); // Inversion des UV si demandé vertex++; } diff --git a/src/Nazara/Utility/Formats/OBJLoader.cpp b/src/Nazara/Utility/Formats/OBJLoader.cpp index 75b5ba22f..05b39f81f 100644 --- a/src/Nazara/Utility/Formats/OBJLoader.cpp +++ b/src/Nazara/Utility/Formats/OBJLoader.cpp @@ -234,8 +234,7 @@ namespace Nz MeshVertex& vertex = meshVertices[index]; const Vector4f& vec = positions[vertexIndices.position]; - vertex.position.Set(vec.x, vec.y, vec.z); - vertex.position *= parameters.scale/vec.w; + vertex.position = Vector3f(parameters.matrix * vec); if (vertexIndices.normal >= 0) vertex.normal = normals[vertexIndices.normal]; diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index fca38e415..f41f67440 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -39,9 +39,9 @@ namespace Nz return false; } - if (scale == Vector3f::Zero()) + if (matrix == Matrix4f::Zero()) { - NazaraError("Invalid scale"); + NazaraError("Invalid matrix"); return false; } @@ -111,7 +111,7 @@ namespace Nz VertexBufferRef vertexBuffer; Matrix4f matrix(primitive.matrix); - matrix.ApplyScale(params.scale); + matrix *= params.matrix; VertexDeclaration* declaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent); From cc49b559c3ff11471c841f143af056741dd4c9dc Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:47:08 +0200 Subject: [PATCH 2/6] Utility/MaterialData: Add Material name information Former-commit-id: f680fd0d6e8c4a10a44ee8393e6b08e164fceabf [formerly b906d2ed5d98ee0bc0199f71d4955a93c18657f7] Former-commit-id: 50620f9c773ecadec81a257b9c3ad280a97f0c24 --- include/Nazara/Utility/MaterialData.hpp | 1 + plugins/Assimp/Plugin.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/Nazara/Utility/MaterialData.hpp b/include/Nazara/Utility/MaterialData.hpp index 0f69c9846..ea8ffd0f5 100644 --- a/include/Nazara/Utility/MaterialData.hpp +++ b/include/Nazara/Utility/MaterialData.hpp @@ -41,6 +41,7 @@ namespace Nz static constexpr const char* HeightTexturePath = "MatHeightTexturePath"; static constexpr const char* Lighting = "MatLighting"; static constexpr const char* LineWidth = "MatLineWidth"; + static constexpr const char* Name = "MatName"; static constexpr const char* NormalTexturePath = "MatNormalTexturePath"; static constexpr const char* PointSize = "MatPointSize"; static constexpr const char* ScissorTest = "MatScissorTest"; diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index d571e1ef6..f82d51f7b 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -291,6 +291,10 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) ConvertTexture(aiTextureType_OPACITY, MaterialData::AlphaTexturePath); ConvertTexture(aiTextureType_SPECULAR, MaterialData::SpecularTexturePath, MaterialData::SpecularWrap); + aiString name; + if (aiGetMaterialString(aiMat, AI_MATKEY_NAME, &name) == aiReturn_SUCCESS) + matData.SetParameter(MaterialData::Name, String(name.data, name.length)); + int iValue; if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue)) matData.SetParameter(MaterialData::FaceCulling, !iValue); From 91be8bf6ed12b6f971c03c91b9b941ef7447d90c Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:47:43 +0200 Subject: [PATCH 3/6] Plugins/Assimp: Fix FaceCulling parameter retrieval Former-commit-id: d7390465f872eec27db9dab9b48219187b0a1b84 [formerly 874eaee9651cf2550fb6870da98725b556233acd] Former-commit-id: 7219679c217dd39aaac18d918a454af1f9a7e134 --- plugins/Assimp/Plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index f82d51f7b..312bbf48e 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -296,7 +296,7 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters) matData.SetParameter(MaterialData::Name, String(name.data, name.length)); int iValue; - if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue)) + if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS) matData.SetParameter(MaterialData::FaceCulling, !iValue); matIt = materials.insert(std::make_pair(iMesh->mMaterialIndex, std::make_pair(materials.size(), std::move(matData)))).first; From 0e01bdaa3e09f607ee36ef24f1ac488f67b2e45b Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:48:04 +0200 Subject: [PATCH 4/6] Graphics/Material: Ugly spaces to tabs Former-commit-id: 05162affc594bfa6e72bb32b4c49c3d322fd42ab [formerly 71fa5849249e9770184d693176c3e50393988f4d] Former-commit-id: d0042378fa707d7e42303ffe3445a847596a482d --- src/Nazara/Graphics/Material.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Nazara/Graphics/Material.cpp b/src/Nazara/Graphics/Material.cpp index 44ec0310d..0b4b887c3 100644 --- a/src/Nazara/Graphics/Material.cpp +++ b/src/Nazara/Graphics/Material.cpp @@ -442,22 +442,22 @@ namespace Nz s_defaultMaterial->SetFaceFilling(FaceFilling_Line); MaterialLibrary::Register("Default", s_defaultMaterial); - MaterialRef mat; + MaterialRef mat; - mat = New(); - mat->Enable(RendererParameter_DepthWrite, false); - mat->Enable(RendererParameter_FaceCulling, false); - mat->EnableLighting(false); - MaterialLibrary::Register("Basic2D", std::move(mat)); + mat = New(); + mat->Enable(RendererParameter_DepthWrite, false); + mat->Enable(RendererParameter_FaceCulling, false); + mat->EnableLighting(false); + MaterialLibrary::Register("Basic2D", std::move(mat)); - mat = New(); - mat->Enable(RendererParameter_Blend, true); - mat->Enable(RendererParameter_DepthWrite, false); - mat->Enable(RendererParameter_FaceCulling, false); - mat->EnableLighting(false); - mat->SetDstBlend(BlendFunc_InvSrcAlpha); - mat->SetSrcBlend(BlendFunc_SrcAlpha); - MaterialLibrary::Register("Translucent2D", std::move(mat)); + mat = New(); + mat->Enable(RendererParameter_Blend, true); + mat->Enable(RendererParameter_DepthWrite, false); + mat->Enable(RendererParameter_FaceCulling, false); + mat->EnableLighting(false); + mat->SetDstBlend(BlendFunc_InvSrcAlpha); + mat->SetSrcBlend(BlendFunc_SrcAlpha); + MaterialLibrary::Register("Translucent2D", std::move(mat)); return true; } From a2b4146645b562453e718b589acf43d3c269f884 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:48:35 +0200 Subject: [PATCH 5/6] Sdk/Application: Add MakeExitOnLastWindowClosed At least it's explicit Former-commit-id: 1db6523fe5ad0085056b1192cbf8ff8b714dd795 [formerly 1e02bb893158e39d69201c6044501149722bc308] Former-commit-id: eee14cb25425b7a368d084fcb552996784e4a70e --- SDK/include/NDK/Application.hpp | 4 ++++ SDK/include/NDK/Application.inl | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/SDK/include/NDK/Application.hpp b/SDK/include/NDK/Application.hpp index 5d918ef8e..6a375776c 100644 --- a/SDK/include/NDK/Application.hpp +++ b/SDK/include/NDK/Application.hpp @@ -33,6 +33,10 @@ namespace Ndk bool Run(); + #ifndef NDK_SERVER + inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows); + #endif + inline void Quit(); Application& operator=(const Application&) = delete; diff --git a/SDK/include/NDK/Application.inl b/SDK/include/NDK/Application.inl index f44ff9e8c..96e8768ce 100644 --- a/SDK/include/NDK/Application.inl +++ b/SDK/include/NDK/Application.inl @@ -61,6 +61,13 @@ namespace Ndk return m_updateTime; } + #ifndef NDK_SERVER + inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows) + { + m_exitOnClosedWindows = exitOnClosedWindows; + } + #endif + inline void Application::Quit() { m_shouldQuit = true; From f80dc7cf45d69e544c01e6ea4978e2eb095dc336 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 9 Jun 2016 08:49:01 +0200 Subject: [PATCH 6/6] Graphics/Material: Add errors when failed to query texture Former-commit-id: b848a6552b442edf87260bbbb6b3703bf155a4b7 [formerly b4720a11771bd5f2e61f54afc69c361b7c412555] Former-commit-id: b3aa1119d7ca9efe3030f40f1f5d1f0c79b416fd --- include/Nazara/Graphics/Material.inl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/Nazara/Graphics/Material.inl b/include/Nazara/Graphics/Material.inl index c8559e11f..d348d7581 100644 --- a/include/Nazara/Graphics/Material.inl +++ b/include/Nazara/Graphics/Material.inl @@ -289,7 +289,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get alpha map \"" + textureName + "\""); return false; + } } SetAlphaMap(std::move(texture)); @@ -335,7 +338,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get diffuse map \"" + textureName + "\""); return false; + } } SetDiffuseMap(std::move(texture)); @@ -366,7 +372,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get emissive map \"" + textureName + "\""); return false; + } } SetEmissiveMap(std::move(texture)); @@ -397,7 +406,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get height map \"" + textureName + "\""); return false; + } } SetHeightMap(std::move(texture)); @@ -418,7 +430,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get normal map \"" + textureName + "\""); return false; + } } SetNormalMap(std::move(texture)); @@ -471,7 +486,10 @@ namespace Nz { texture = TextureManager::Get(textureName); if (!texture) + { + NazaraError("Failed to get specular map \"" + textureName + "\""); return false; + } } SetSpecularMap(std::move(texture));