Utility/Mesh: Replace scale by transform matrix
Former-commit-id: 28cf57d1fe300b78e60c5f9301678a25533df29f [formerly d7b8edd11e99de396d40cf09c58cb94c5e03015c] Former-commit-id: e5915c2a5795900077bdb5229638962fade7f352
This commit is contained in:
parent
48a7ba0114
commit
b0c4bcff67
|
|
@ -100,8 +100,8 @@ namespace Nz
|
|||
params->animated = instance.CheckField<bool>("Animated", params->animated);
|
||||
params->center = instance.CheckField<bool>("Center", params->center);
|
||||
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->scale = instance.CheckField<Vector3f>("Scale", params->scale);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
|
||||
MeshVertex* vertex = static_cast<MeshVertex*>(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];
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue