Commit current work
This commit is contained in:
committed by
Jérôme Leclercq
parent
a7ab2fbaf4
commit
b8ea79c40e
@@ -1131,32 +1131,4 @@ namespace Nz
|
||||
skinningInfos.outputUv[i] = skinningInfos.inputUv[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************Transform*********************************/
|
||||
|
||||
void TransformVertices(VertexPointers vertexPointers, UInt64 vertexCount, const Matrix4f& matrix)
|
||||
{
|
||||
if (vertexPointers.positionPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.positionPtr++ = matrix.Transform(*vertexPointers.positionPtr);
|
||||
}
|
||||
|
||||
if (vertexPointers.normalPtr || vertexPointers.tangentPtr)
|
||||
{
|
||||
Vector3f scale = matrix.GetScale();
|
||||
|
||||
if (vertexPointers.normalPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.normalPtr++ = matrix.Transform(*vertexPointers.normalPtr, 0.f) / scale;
|
||||
}
|
||||
|
||||
if (vertexPointers.tangentPtr)
|
||||
{
|
||||
for (UInt64 i = 0; i < vertexCount; ++i)
|
||||
*vertexPointers.tangentPtr++ = matrix.Transform(*vertexPointers.tangentPtr, 0.f) / scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,14 @@ namespace Nz
|
||||
constexpr float ScaleAdjust = 1.f / 27.8f; // Make a 50 Quake 2 units character a 1.8 unit long
|
||||
|
||||
scale *= ScaleAdjust;
|
||||
scale *= parameters.vertexScale;
|
||||
|
||||
translate *= ScaleAdjust;
|
||||
translate += parameters.vertexOffset;
|
||||
|
||||
// Align the model to our coordinates system
|
||||
Quaternionf rotation = EulerAnglesf(-90.f, 90.f, 0.f);
|
||||
rotation *= parameters.vertexRotation;
|
||||
|
||||
VertexMapper vertexMapper(*vertexBuffer);
|
||||
|
||||
@@ -208,22 +215,14 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
// Align the model to our coordinates system
|
||||
Quaternionf rotationQuat = EulerAnglesf(-90.f, 90.f, 0.f);
|
||||
Nz::Matrix4f matrix = Matrix4f::Transform(translate, rotationQuat, scale);
|
||||
matrix *= parameters.matrix;
|
||||
|
||||
// Vertex normals
|
||||
if (auto normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent::Normal))
|
||||
{
|
||||
Nz::Matrix4f normalMatrix = Matrix4f::Rotate(rotationQuat);
|
||||
normalMatrix *= parameters.matrix;
|
||||
|
||||
for (UInt32 v = 0; v < header.num_vertices; ++v)
|
||||
{
|
||||
const MD2_Vertex& vert = vertices[v];
|
||||
|
||||
*normalPtr++ = normalMatrix.Transform(md2Normals[vert.n], 0.f);
|
||||
*normalPtr++ = TransformNormalTRS(rotation, scale, md2Normals[vert.n]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +233,7 @@ namespace Nz
|
||||
{
|
||||
const MD2_Vertex& vert = vertices[v];
|
||||
|
||||
*posPtr++ = matrix * Vector3f(vert.x, vert.y, vert.z);
|
||||
*posPtr++ = TransformPositionTRS(translate, rotation, scale, Vector3f(vert.x, vert.y, vert.z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@ 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
|
||||
Matrix4f matrix = Matrix4f::Transform(Nz::Vector3f::Zero(), rotationQuat, Vector3f(1.f / 40.f));
|
||||
matrix *= parameters.matrix;
|
||||
|
||||
rotationQuat = Quaternionf::Identity();
|
||||
|
||||
@@ -216,7 +215,7 @@ namespace Nz
|
||||
|
||||
// Material
|
||||
ParameterList matData;
|
||||
matData.SetParameter(MaterialData::FilePath, (baseDir / md5Mesh.shader).generic_u8string());
|
||||
matData.SetParameter(MaterialData::DiffuseTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
|
||||
|
||||
mesh->SetMaterialData(i, std::move(matData));
|
||||
|
||||
@@ -342,7 +341,7 @@ namespace Nz
|
||||
|
||||
// Material
|
||||
ParameterList matData;
|
||||
matData.SetParameter(MaterialData::FilePath, (baseDir / md5Mesh.shader).generic_u8string());
|
||||
matData.SetParameter(MaterialData::DiffuseTexturePath, (baseDir / md5Mesh.shader).generic_u8string());
|
||||
|
||||
mesh->SetMaterialData(i, std::move(matData));
|
||||
}
|
||||
|
||||
@@ -271,11 +271,6 @@ namespace Nz
|
||||
|
||||
// Remplissage des vertices
|
||||
|
||||
// Make sure the normal matrix won't rescale our normals
|
||||
Nz::Matrix4f normalMatrix = parameters.matrix;
|
||||
if (normalMatrix.HasScale())
|
||||
normalMatrix.ApplyScale(1.f / normalMatrix.GetScale());
|
||||
|
||||
bool hasNormals = true;
|
||||
bool hasTexCoords = true;
|
||||
|
||||
@@ -299,13 +294,13 @@ namespace Nz
|
||||
if (posPtr)
|
||||
{
|
||||
const Vector4f& vec = positions[vertexIndices.position - 1];
|
||||
posPtr[index] = Vector3f(parameters.matrix * vec);
|
||||
posPtr[index] = TransformPositionTRS(parameters.vertexOffset, parameters.vertexRotation, parameters.vertexScale, Vector3f(vec));
|
||||
}
|
||||
|
||||
if (hasNormals)
|
||||
{
|
||||
if (vertexIndices.normal > 0)
|
||||
normalPtr[index] = normalMatrix.Transform(normals[vertexIndices.normal - 1], 0.f);
|
||||
normalPtr[index] = TransformNormalTRS(parameters.vertexRotation, parameters.vertexScale, normals[vertexIndices.normal - 1]);
|
||||
else
|
||||
hasNormals = false;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,6 @@ namespace Nz
|
||||
{
|
||||
bool MeshParams::IsValid() const
|
||||
{
|
||||
if (matrix == Matrix4f::Zero())
|
||||
{
|
||||
NazaraError("Invalid matrix");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!vertexDeclaration)
|
||||
{
|
||||
NazaraError("The vertex declaration can't be null");
|
||||
@@ -87,8 +81,7 @@ namespace Nz
|
||||
std::shared_ptr<IndexBuffer> indexBuffer;
|
||||
std::shared_ptr<VertexBuffer> vertexBuffer;
|
||||
|
||||
Matrix4f matrix(primitive.matrix);
|
||||
matrix *= params.matrix;
|
||||
Matrix4f matrix = Matrix4f::ConcatenateTransform(primitive.matrix, Matrix4f::Transform(params.vertexOffset, params.vertexRotation, params.vertexScale));
|
||||
|
||||
const std::shared_ptr<VertexDeclaration>& declaration = params.vertexDeclaration;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user