Former-commit-id: 05911276c1658a2c52589da7890e22c4d188dca3 [formerly d247d95d9c5fa89babb1eaabf1e67de5ad2752dd]
Former-commit-id: 8fcf7fe42b04b7c0f0059fc41a1dea79d24ff1ba
This commit is contained in:
Lynix 2016-06-09 12:32:08 +02:00
commit dce978aa51
12 changed files with 67 additions and 32 deletions

View File

@ -33,6 +33,10 @@ namespace Ndk
bool Run(); bool Run();
#ifndef NDK_SERVER
inline void MakeExitOnLastWindowClosed(bool exitOnClosedWindows);
#endif
inline void Quit(); inline void Quit();
Application& operator=(const Application&) = delete; Application& operator=(const Application&) = delete;

View File

@ -61,6 +61,13 @@ namespace Ndk
return m_updateTime; return m_updateTime;
} }
#ifndef NDK_SERVER
inline void Application::MakeExitOnLastWindowClosed(bool exitOnClosedWindows)
{
m_exitOnClosedWindows = exitOnClosedWindows;
}
#endif
inline void Application::Quit() inline void Application::Quit()
{ {
m_shouldQuit = true; m_shouldQuit = true;

View File

@ -100,8 +100,8 @@ namespace Nz
params->animated = instance.CheckField<bool>("Animated", params->animated); params->animated = instance.CheckField<bool>("Animated", params->animated);
params->center = instance.CheckField<bool>("Center", params->center); params->center = instance.CheckField<bool>("Center", params->center);
params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs); params->flipUVs = instance.CheckField<bool>("FlipUVs", params->flipUVs);
//params->matrix = instance.CheckField<Matrix4f>("Matrix", params->matrix);
params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers); params->optimizeIndexBuffers = instance.CheckField<bool>("OptimizeIndexBuffers", params->optimizeIndexBuffers);
params->scale = instance.CheckField<Vector3f>("Scale", params->scale);
return 1; return 1;
} }

View File

@ -586,7 +586,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get alpha map \"" + textureName + "\"");
return false; return false;
}
} }
SetAlphaMap(std::move(texture)); SetAlphaMap(std::move(texture));
@ -679,7 +682,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get diffuse map \"" + textureName + "\"");
return false; return false;
}
} }
SetDiffuseMap(std::move(texture)); SetDiffuseMap(std::move(texture));
@ -738,7 +744,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get emissive map \"" + textureName + "\"");
return false; return false;
}
} }
SetEmissiveMap(std::move(texture)); SetEmissiveMap(std::move(texture));
@ -797,7 +806,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get height map \"" + textureName + "\"");
return false; return false;
}
} }
SetHeightMap(std::move(texture)); SetHeightMap(std::move(texture));
@ -834,7 +846,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get normal map \"" + textureName + "\"");
return false; return false;
}
} }
SetNormalMap(std::move(texture)); SetNormalMap(std::move(texture));
@ -936,7 +951,10 @@ namespace Nz
{ {
texture = TextureManager::Get(textureName); texture = TextureManager::Get(textureName);
if (!texture) if (!texture)
{
NazaraError("Failed to get specular map \"" + textureName + "\"");
return false; return false;
}
} }
SetSpecularMap(std::move(texture)); SetSpecularMap(std::move(texture));

View File

@ -41,6 +41,7 @@ namespace Nz
static constexpr const char* HeightTexturePath = "MatHeightTexturePath"; static constexpr const char* HeightTexturePath = "MatHeightTexturePath";
static constexpr const char* Lighting = "MatLighting"; static constexpr const char* Lighting = "MatLighting";
static constexpr const char* LineWidth = "MatLineWidth"; static constexpr const char* LineWidth = "MatLineWidth";
static constexpr const char* Name = "MatName";
static constexpr const char* NormalTexturePath = "MatNormalTexturePath"; static constexpr const char* NormalTexturePath = "MatNormalTexturePath";
static constexpr const char* PointSize = "MatPointSize"; static constexpr const char* PointSize = "MatPointSize";
static constexpr const char* ScissorTest = "MatScissorTest"; static constexpr const char* ScissorTest = "MatScissorTest";

View File

@ -29,8 +29,8 @@ namespace Nz
{ {
MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement) MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
// La mise à l'échelle éventuelle que subira le mesh // La transformation appliquée à tous les sommets du mesh
Vector3f scale = Vector3f::Unit(); Matrix4f matrix = Matrix4f::Identity();
// Si ceci sera le stockage utilisé par les buffers // Si ceci sera le stockage utilisé par les buffers
UInt32 storage = DataStorage_Hardware; UInt32 storage = DataStorage_Hardware;

View File

@ -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 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); 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->normal.Set(normal.x, normal.y, normal.z);
vertex->tangent.Set(tangent.x, tangent.y, tangent.z); vertex->tangent.Set(tangent.x, tangent.y, tangent.z);
vertex->uv.Set(uv.x, uv.y); vertex->uv.Set(uv.x, uv.y);
@ -291,8 +291,12 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
ConvertTexture(aiTextureType_OPACITY, MaterialData::AlphaTexturePath); ConvertTexture(aiTextureType_OPACITY, MaterialData::AlphaTexturePath);
ConvertTexture(aiTextureType_SPECULAR, MaterialData::SpecularTexturePath, MaterialData::SpecularWrap); 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; int iValue;
if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue)) if (aiGetMaterialInteger(aiMat, AI_MATKEY_TWOSIDED, &iValue) == aiReturn_SUCCESS)
matData.SetParameter(MaterialData::FaceCulling, !iValue); matData.SetParameter(MaterialData::FaceCulling, !iValue);
matIt = materials.insert(std::make_pair(iMesh->mMaterialIndex, std::make_pair(materials.size(), std::move(matData)))).first; matIt = materials.insert(std::make_pair(iMesh->mMaterialIndex, std::make_pair(materials.size(), std::move(matData)))).first;

View File

@ -492,22 +492,22 @@ namespace Nz
s_defaultMaterial->SetFaceFilling(FaceFilling_Line); s_defaultMaterial->SetFaceFilling(FaceFilling_Line);
MaterialLibrary::Register("Default", s_defaultMaterial); MaterialLibrary::Register("Default", s_defaultMaterial);
MaterialRef mat; MaterialRef mat;
mat = New(); mat = New();
mat->Enable(RendererParameter_DepthWrite, false); mat->Enable(RendererParameter_DepthWrite, false);
mat->Enable(RendererParameter_FaceCulling, false); mat->Enable(RendererParameter_FaceCulling, false);
mat->EnableLighting(false); mat->EnableLighting(false);
MaterialLibrary::Register("Basic2D", std::move(mat)); MaterialLibrary::Register("Basic2D", std::move(mat));
mat = New(); mat = New();
mat->Enable(RendererParameter_Blend, true); mat->Enable(RendererParameter_Blend, true);
mat->Enable(RendererParameter_DepthWrite, false); mat->Enable(RendererParameter_DepthWrite, false);
mat->Enable(RendererParameter_FaceCulling, false); mat->Enable(RendererParameter_FaceCulling, false);
mat->EnableLighting(false); mat->EnableLighting(false);
mat->SetDstBlend(BlendFunc_InvSrcAlpha); mat->SetDstBlend(BlendFunc_InvSrcAlpha);
mat->SetSrcBlend(BlendFunc_SrcAlpha); mat->SetSrcBlend(BlendFunc_SrcAlpha);
MaterialLibrary::Register("Translucent2D", std::move(mat)); MaterialLibrary::Register("Translucent2D", std::move(mat));
return true; return true;
} }

View File

@ -188,11 +188,10 @@ namespace Nz
SwapBytes(&translate.z, sizeof(float)); SwapBytes(&translate.z, sizeof(float));
#endif #endif
// Un personnage de taille moyenne fait ~50 unités de haut dans Quake 2 constexpr float ScaleAdjust = 1.f / 27.8f; // Make a 50 Quake 2 units character a 1.8 unit long
// 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 *= ScaleAdjust;
scale *= s; translate *= ScaleAdjust;
translate *= s;
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite); BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer()); MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer());
@ -215,11 +214,13 @@ namespace Nz
/// Chargement des positions /// Chargement des positions
// Pour que le modèle soit correctement aligné, on génère un quaternion que nous appliquerons à chacune des vertices // 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); 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) for (unsigned int v = 0; v < header.num_vertices; ++v)
{ {
const MD2_Vertex& vert = 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->position = position;
vertex->normal = rotationQuat * md2Normals[vert.n]; vertex->normal = rotationQuat * md2Normals[vert.n];

View File

@ -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 // 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 // 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::Joint* joints = parser.GetJoints();
const MD5MeshParser::Mesh* meshes = parser.GetMeshes(); const MD5MeshParser::Mesh* meshes = parser.GetMeshes();
@ -267,7 +268,7 @@ namespace Nz
} }
// On retourne le modèle dans le bon sens // 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->uv.Set(md5Vertex.uv.x, (parameters.flipUVs) ? 1.f - md5Vertex.uv.y : md5Vertex.uv.y); // Inversion des UV si demandé
vertex++; vertex++;
} }

View File

@ -234,8 +234,7 @@ namespace Nz
MeshVertex& vertex = meshVertices[index]; MeshVertex& vertex = meshVertices[index];
const Vector4f& vec = positions[vertexIndices.position]; const Vector4f& vec = positions[vertexIndices.position];
vertex.position.Set(vec.x, vec.y, vec.z); vertex.position = Vector3f(parameters.matrix * vec);
vertex.position *= parameters.scale/vec.w;
if (vertexIndices.normal >= 0) if (vertexIndices.normal >= 0)
vertex.normal = normals[vertexIndices.normal]; vertex.normal = normals[vertexIndices.normal];

View File

@ -39,9 +39,9 @@ namespace Nz
return false; return false;
} }
if (scale == Vector3f::Zero()) if (matrix == Matrix4f::Zero())
{ {
NazaraError("Invalid scale"); NazaraError("Invalid matrix");
return false; return false;
} }
@ -111,7 +111,7 @@ namespace Nz
VertexBufferRef vertexBuffer; VertexBufferRef vertexBuffer;
Matrix4f matrix(primitive.matrix); Matrix4f matrix(primitive.matrix);
matrix.ApplyScale(params.scale); matrix *= params.matrix;
VertexDeclaration* declaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent); VertexDeclaration* declaration = VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent);