From b0c4bcff6716d1aa6a7a1d78ef3a50aa8d2dbded 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: 28cf57d1fe300b78e60c5f9301678a25533df29f [formerly d7b8edd11e99de396d40cf09c58cb94c5e03015c] Former-commit-id: e5915c2a5795900077bdb5229638962fade7f352 --- 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 eadd21c52abc72463a85f7dc6682c35224d86cb0 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: ac5a76bc840c2a826af196a9c55c4c390b17770b [formerly 74fa853856dc4720d97b4f66b60dda49d81047a9] Former-commit-id: 83bc618ad6cb7ee4fe420d8acffe496cd3157742 --- 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 e43773f2aef19e86183ab752b4ed7c7b5dc3ee79 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: ecee810d06d9a75a9a270efc2becf0c879a8e0ab [formerly 30686c841913edaea70d1dfdc8fae7eb94c7cfc0] Former-commit-id: b0a0f965b1c4ca411a400ffa56bfa392297b71b4 --- 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 296be70a5c29f9b5cc27f965c9ea8d126bedb17b 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: fe691ce50ec143681c8a916bab2f85270cedec06 [formerly c45aba3d7b6d8b47a90e5f8120c278785d68773b] Former-commit-id: 04596ea0ca1bb7f1575a4db6a5ef309328922938 --- 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 18eab1045d82524d63a93dfdcfcf98872520e6d8 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: 9118daeb3b33768697d502113e80b97c883ff9f5 [formerly aebc375bf0865d94103a16e7cb9540f7c54cfc88] Former-commit-id: 8a8ef252c1ddbc0838b6d5cbf1d48917bf0d5b50 --- 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 2ace255d170404eccd4830813fa88df36173574a 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: a28cd9537b7155f461a0e0dc761225c5e8758c77 [formerly e9c6cf2e48766eb3ef99c4711567d4da2e4e30ce] Former-commit-id: d00448a69f391c0e9b17fcce85e48f968b0de143 --- 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));