Files
o3de/Gems/EMotionFX/Code/Tests/TestAssetCode/MeshFactory.cpp
T
lumberyard-employee-dm f3e9e41f4f Adding partial implementation of C++20 concepts and range functions for AZStd::span (#7102)
* Adding partial implementation of C++20 concepts and range functions for AZStd::span

The new concepts to discovered existing issues with the PathIterator and deque::iterator classes
PathIterator wasn't properly an input_iterator and therefore the Path classes weren't a range due to an incorrect const_iterator alias
The deque::iterator classes was missing the operator+ friend function that accepted a (ptrdiff_t, deque::iterator) to fulfill the random_access_iterator concepts

The AZStd implementations of (uninitialized_)copy(_n), (uninitialized_)move(_n) and (uninitialized_)file(_n) have been optimized to use memcpy and memset based on fulfilling the contiguous_iterator concept

Fixed invalid AZStd::vector inserts in FrameGraphExecuter.cpp and SliceditorEntityOwnershipService.cpp
The code was trying to copy the underlying addresses for vector<unique_ptr> to a vector<raw pointer> using insert, which it was doing by using memcpy.

relates to #6749

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed the `fixed_vector` emplace function to not move initialized
elements using uninitialized_move.

This was causing initialized elements of the fixed_vector to be
overwritten with the element at the emplace position.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Fixed clang warnings about variables that are set, but never read

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the `az_has_builtin_is_constant_evaluated` define to not have
"()" as is not a macro.

This helps prevent users from using `az_has_builtin_is_constant_evaluated`
define in a situation where they want to know if the function is being
evaluated in a compile time context.
In that case they need to use the `az_builtin_is_constant_evaluated()`
macro (which of course looks quite similiar) but does not have the word
"has" in it..

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Updated the AZStd span class to be C++20 compliant.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Changed phrase "DoesNotCompiles" to be more grammatically correct.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Added more unit test for AZStd span

Fixed an the the return type of the subspan template overload to account
for the source span having a dynamic extent.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Removed unused variable from span unit test.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
2022-01-24 17:09:08 -06:00

116 lines
4.6 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <Tests/TestAssetCode/MeshFactory.h>
#include <EMotionFX/Source/Mesh.h>
#include <EMotionFX/Source/SubMesh.h>
#include <EMotionFX/Source/SkinningInfoVertexAttributeLayer.h>
#include <EMotionFX/Source/VertexAttributeLayerAbstractData.h>
namespace EMotionFX
{
EMotionFX::Mesh* MeshFactory::Create(
const AZStd::vector<AZ::u32>& indices,
const AZStd::vector<AZ::Vector3>& vertices,
const AZStd::vector<AZ::Vector3>& normals,
const AZStd::vector<AZ::Vector2>& uvs,
const AZStd::vector<VertexSkinInfluences>& skinningInfo
) {
const AZ::u32 vertCount = aznumeric_cast<AZ::u32>(vertices.size());
const AZ::u32 faceCount = aznumeric_cast<AZ::u32>(indices.size()) / 3;
auto* mesh = EMotionFX::Mesh::Create(vertCount, aznumeric_caster(indices.size()), faceCount, vertCount, false);
// Skinning info
if (!skinningInfo.empty() && skinningInfo.size() == vertices.size())
{
auto* skinningLayer = EMotionFX::SkinningInfoVertexAttributeLayer::Create(vertCount);
for (size_t vertex = 0; vertex < skinningInfo.size(); ++vertex)
{
for (const auto& [nodeNr, weight] : skinningInfo[vertex])
{
skinningLayer->AddInfluence(static_cast<AZ::u32>(vertex), aznumeric_caster(nodeNr), weight, 0);
}
}
mesh->AddSharedVertexAttributeLayer(skinningLayer);
}
// Original vertex numbers
auto* orgVtxLayer = EMotionFX::VertexAttributeLayerAbstractData::Create(
vertCount,
EMotionFX::Mesh::ATTRIB_ORGVTXNUMBERS,
sizeof(AZ::u32),
true
);
mesh->AddVertexAttributeLayer(orgVtxLayer);
AZStd::copy(indices.begin(), indices.end(), static_cast<AZ::u32*>(orgVtxLayer->GetOriginalData()));
orgVtxLayer->ResetToOriginalData();
// The positions layer
auto* posLayer = EMotionFX::VertexAttributeLayerAbstractData::Create(
vertCount,
EMotionFX::Mesh::ATTRIB_POSITIONS,
sizeof(AZ::Vector3),
true
);
mesh->AddVertexAttributeLayer(posLayer);
AZStd::copy(vertices.begin(), vertices.end(), static_cast<AZ::Vector3*>(posLayer->GetOriginalData()));
posLayer->ResetToOriginalData();
// The normals layer
auto* normalsLayer = EMotionFX::VertexAttributeLayerAbstractData::Create(
vertCount,
EMotionFX::Mesh::ATTRIB_NORMALS,
sizeof(AZ::Vector3),
true
);
mesh->AddVertexAttributeLayer(normalsLayer);
AZStd::copy(normals.begin(), normals.end(), static_cast<AZ::Vector3*>(normalsLayer->GetOriginalData()));
normalsLayer->ResetToOriginalData();
// The UVs layer.
EMotionFX::VertexAttributeLayerAbstractData* uvsLayer = nullptr;
if (!uvs.empty() && uvs.size() == vertices.size())
{
uvsLayer = EMotionFX::VertexAttributeLayerAbstractData::Create(vertCount, EMotionFX::Mesh::ATTRIB_UVCOORDS, sizeof(AZ::Vector2), true);
mesh->AddVertexAttributeLayer(uvsLayer);
AZStd::copy(uvs.begin(), uvs.end(), static_cast<AZ::Vector2*>(uvsLayer->GetOriginalData()));
uvsLayer->ResetToOriginalData();
}
auto* subMesh = EMotionFX::SubMesh::Create(
/*parentMesh=*/ mesh,
/*startVertex=*/ 0,
/*startIndex=*/ 0,
/*startPolygon=*/ 0,
/*numVerts=*/ mesh->GetNumVertices(),
/*numIndices=*/ mesh->GetNumIndices(),
/*numPolygons=*/ mesh->GetNumPolygons(),
/*materialIndex=*/ 0,
/*numBones=*/ aznumeric_caster(skinningInfo.size())
);
mesh->AddSubMesh(subMesh);
if (!skinningInfo.empty() && skinningInfo.size() == vertices.size())
{
for (size_t vertex = 0; vertex < skinningInfo.size(); ++vertex)
{
subMesh->SetBone(aznumeric_caster(vertex), aznumeric_caster(vertex));
}
}
AZ_PUSH_DISABLE_WARNING_MSVC(4244); // warning C4244: '=': conversion from 'const int' to 'uint8', possible loss of data
AZStd::fill(mesh->GetPolygonVertexCounts(), mesh->GetPolygonVertexCounts() + faceCount, 3);
AZ_POP_DISABLE_WARNING_MSVC
AZStd::copy(indices.begin(), indices.end(), mesh->GetIndices());
return mesh;
}
} // namespace EMotionFX