feat: add whitebox module support for linux(#4654) (#5075)

* feat: fix whitebox module to work on linux(#4654)

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* update with AZStl

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* feat: update format

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: minor changes

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: update clang warnings

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: fix clang errors

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: remove unused refrence for g_indices and address range based for loop warnings

Signed-off-by: Michael Pollind <mpollind@gmail.com>

* chore: fix clang warnings for test cases

Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
Michael Pollind
2021-11-15 01:21:50 -08:00
committed by GitHub
parent 57adfd795e
commit 0ada8b335b
12 changed files with 78 additions and 88 deletions
@@ -180,11 +180,11 @@ namespace WhiteBox
// fill vertex position array
size_t index = 0;
const auto faceHandles = Api::MeshFaceHandles(whiteBox);
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
const auto faceHalfedgeHandles = Api::FaceHalfedgeHandles(whiteBox, faceHandle);
for (const auto halfEdgeHandle : faceHalfedgeHandles)
for (const auto& halfEdgeHandle : faceHalfedgeHandles)
{
const auto vh = Api::HalfedgeVertexHandleAtTip(whiteBox, halfEdgeHandle);
vertices[index] = Api::VertexPosition(whiteBox, vh);
@@ -426,10 +426,6 @@ namespace WhiteBox
Mesh::TexCoord2D(0.0f, 0.0f),
};
// indices related to halfedges - start iterating on first halfedge, pointing to
// vertex 0, then follow next to get vertex 2 and then 3 (anti-clockwise winding)
const int g_indices[] = {0, 1, 2, 0, 2, 3};
// conversion functions between OpenMesh and AZ types
// convert WhiteBox face handle to OpenMesh face handle
@@ -600,7 +596,7 @@ namespace WhiteBox
VertexHandles vertexHandles;
vertexHandles.reserve(whiteBox.mesh.n_vertices());
for (const auto vertexHandle : whiteBox.mesh.vertices())
for (const auto& vertexHandle : whiteBox.mesh.vertices())
{
vertexHandles.push_back(wb_vh(vertexHandle));
}
@@ -614,7 +610,7 @@ namespace WhiteBox
FaceHandles faceHandles;
faceHandles.reserve(whiteBox.mesh.n_faces());
for (const auto faceHandle : whiteBox.mesh.faces())
for (const auto& faceHandle : whiteBox.mesh.faces())
{
faceHandles.push_back(wb_fh(faceHandle));
}
@@ -660,7 +656,7 @@ namespace WhiteBox
EdgeHandles orderedEdgeHandles;
orderedEdgeHandles.reserve(halfedgeHandles.size());
for (const auto halfedgeHandle : halfedgeHandles)
for (const auto& halfedgeHandle : halfedgeHandles)
{
orderedEdgeHandles.push_back(HalfedgeEdgeHandle(whiteBox, halfedgeHandle));
}
@@ -712,7 +708,7 @@ namespace WhiteBox
EdgeHandles edgeHandles;
edgeHandles.reserve(whiteBox.mesh.n_edges());
for (const auto edgeHandle : whiteBox.mesh.edges())
for (const auto& edgeHandle : whiteBox.mesh.edges())
{
edgeHandles.push_back(wb_eh(edgeHandle));
}
@@ -771,7 +767,7 @@ namespace WhiteBox
EdgeHandles edgeHandles;
edgeHandles.reserve(3);
for (const auto halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
for (const auto& halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
{
edgeHandles.push_back(HalfedgeEdgeHandle(whiteBox, halfedgeHandle));
}
@@ -789,7 +785,7 @@ namespace WhiteBox
VertexHandles vertexHandles;
vertexHandles.reserve(3);
for (const auto halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
for (const auto& halfedgeHandle : FaceHalfedgeHandles(whiteBox, faceHandle))
{
vertexHandles.emplace_back(HalfedgeVertexHandleAtTip(whiteBox, halfedgeHandle));
}
@@ -809,7 +805,7 @@ namespace WhiteBox
AZStd::vector<AZ::Vector3> triangles;
triangles.reserve(faceHandles.size() * 3);
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
const auto corners = FaceVertexPositions(whiteBox, faceHandle);
triangles.insert(triangles.end(), corners.begin(), corners.end());
@@ -953,7 +949,7 @@ namespace WhiteBox
// all halfedges for a given face
const auto halfedges = FaceHalfedgeHandles(whiteBox, faceHandle);
for (const HalfedgeHandle halfedgeHandle : halfedges)
for (const HalfedgeHandle& halfedgeHandle : halfedges)
{
const FaceHandle oppositeFaceHandle = OppositeFaceHandle(whiteBox, halfedgeHandle);
@@ -983,15 +979,15 @@ namespace WhiteBox
// build all possible halfedge handles
HalfedgeHandles halfedgeHandles;
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
// find all vertices for a given face
const auto vertexHandles = FaceVertexHandles(whiteBox, faceHandle);
for (const auto vertexHandle : vertexHandles)
for (const auto& vertexHandle : vertexHandles)
{
// find all outgoing halfedges from vertex
const auto outgoingHalfedgeHandles = VertexOutgoingHalfedgeHandles(whiteBox, vertexHandle);
for (const auto halfedgeHandle : outgoingHalfedgeHandles)
for (const auto& halfedgeHandle : outgoingHalfedgeHandles)
{
// find what face corresponds to this halfedge
const FaceHandle halfedgeFaceHandle = HalfedgeFaceHandle(whiteBox, halfedgeHandle);
@@ -1098,7 +1094,7 @@ namespace WhiteBox
VertexHandles orderedVertexHandles;
orderedVertexHandles.reserve(halfedgeHandles.size());
for (const auto halfedgeHandle : halfedgeHandles)
for (const auto& halfedgeHandle : halfedgeHandles)
{
orderedVertexHandles.push_back(HalfedgeVertexHandleAtTip(whiteBox, halfedgeHandle));
}
@@ -1121,10 +1117,10 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
VertexHandles vertexHandles;
for (const FaceHandle faceHandle : faceHandles)
for (const FaceHandle& faceHandle : faceHandles)
{
const auto faceVertexHandles = FaceVertexHandles(whiteBox, faceHandle);
for (const VertexHandle faceVertexHandle : faceVertexHandles)
for (const VertexHandle& faceVertexHandle : faceVertexHandles)
{
const auto* const vertexIt =
AZStd::find(vertexHandles.cbegin(), vertexHandles.cend(), faceVertexHandle);
@@ -1318,10 +1314,10 @@ namespace WhiteBox
visitedVertexHandles.push_back(vertexHandle);
// for all connected vertex handles to this edge
for (const auto vertexEdgeHandle : VertexEdgeHandles(whiteBox, vertexHandle))
for (const auto& vertexEdgeHandle : VertexEdgeHandles(whiteBox, vertexHandle))
{
// check all halfedges in the edge
for (const auto halfedgeHandle : EdgeHalfedgeHandles(whiteBox, vertexEdgeHandle))
for (const auto& halfedgeHandle : EdgeHalfedgeHandles(whiteBox, vertexEdgeHandle))
{
// only track the edge if it's a 'user' edge (selectable - not a 'mesh' edge)
if (!EdgeIsUser(whiteBox, halfedgeHandle, vertexEdgeHandle))
@@ -1339,7 +1335,7 @@ namespace WhiteBox
// store the edge to the grouping
edgeGrouping.push_back(vertexEdgeHandle);
for (const auto nextVertexHandle : Api::EdgeVertexHandles(whiteBox, vertexEdgeHandle))
for (const auto& nextVertexHandle : Api::EdgeVertexHandles(whiteBox, vertexEdgeHandle))
{
// if we haven't seen this vertex yet, add it to
// the vertex handles to explore
@@ -1978,7 +1974,7 @@ namespace WhiteBox
Faces faces;
faces.reserve(MeshFaceCount(whiteBox));
for (const auto faceHandle : MeshFaceHandles(whiteBox))
for (const auto& faceHandle : MeshFaceHandles(whiteBox))
{
const auto halfEdgeHandles = FaceHalfedgeHandles(whiteBox, faceHandle);
@@ -2002,14 +1998,13 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
auto& mesh = whiteBox.mesh;
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
for (Mesh::ConstFaceHalfedgeCCWIter faceHalfedgeIt = mesh.fh_ccwiter(om_fh(faceHandle));
faceHalfedgeIt.is_valid(); ++faceHalfedgeIt)
{
const Mesh::HalfedgeHandle heh = *faceHalfedgeIt;
const Mesh::VertexHandle vh = mesh.to_vertex_handle(heh);
const Mesh::FaceHandle fh = mesh.face_handle(heh);
const AZ::Vector3 position = mesh.point(vh);
const AZ::Vector3 normal = FaceNormal(whiteBox, faceHandle);
@@ -2064,7 +2059,7 @@ namespace WhiteBox
polygonHandle.m_faceHandles.push_back(faceHandleToVisit);
// for all halfedges
for (const auto faceHalfedgeHandle : faceHalfedges)
for (const auto& faceHalfedgeHandle : faceHalfedges)
{
const EdgeHandle edgeHandle = HalfedgeEdgeHandle(whiteBox, faceHalfedgeHandle);
// if we haven't seen this halfedge before and we want to track it,
@@ -2092,10 +2087,10 @@ namespace WhiteBox
static void PopulatePolygonProps(FaceHandlePolygonMapping& polygonProps, const FaceHandles& faceHandles)
{
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
auto polygonIt = polygonProps.find(om_fh(faceHandle));
for (const auto innerFaceHandle : faceHandles)
for (const auto& innerFaceHandle : faceHandles)
{
polygonIt->second.push_back(om_fh(innerFaceHandle));
}
@@ -2104,7 +2099,7 @@ namespace WhiteBox
static void ClearPolygonProps(FaceHandlePolygonMapping& polygonProps, const FaceHandles& faceHandles)
{
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
if (auto polygonIt = polygonProps.find(om_fh(faceHandle)); polygonIt != polygonProps.end())
{
@@ -2116,9 +2111,9 @@ namespace WhiteBox
// restore all vertices along the restored edges (after creating a new polygon)
static void RestoreVertexHandlesForEdges(WhiteBoxMesh& whiteBox, const EdgeHandles& restoredEdgeHandles)
{
for (const auto edgeHandle : restoredEdgeHandles)
for (const auto& edgeHandle : restoredEdgeHandles)
{
for (const auto vertexHandle : EdgeVertexHandles(whiteBox, edgeHandle))
for (const auto& vertexHandle : EdgeVertexHandles(whiteBox, edgeHandle))
{
RestoreVertex(whiteBox, vertexHandle);
}
@@ -2280,19 +2275,19 @@ namespace WhiteBox
auto& polygonProps = whiteBox.mesh.property(polygonPropsHandle);
// update all face handles to refer to the new face handles in the group
for (const auto faceHandle : combinedFaceHandles)
for (const auto& faceHandle : combinedFaceHandles)
{
auto polygonIt = polygonProps.find(om_fh(faceHandle));
polygonIt->second.clear();
for (const auto innerFaceHandle : combinedFaceHandles)
for (const auto& innerFaceHandle : combinedFaceHandles)
{
polygonIt->second.push_back(om_fh(innerFaceHandle));
}
}
// hide any vertices that are not connected to a 'user' edge
for (const auto vertexHandle : firstPolygonVertexHandles)
for (const auto& vertexHandle : firstPolygonVertexHandles)
{
if (VertexIsIsolated(whiteBox, vertexHandle))
{
@@ -2339,7 +2334,7 @@ namespace WhiteBox
omFaceHandles.erase(AZStd::unique(omFaceHandles.begin(), omFaceHandles.end()), omFaceHandles.end());
// update all face handles to point to the new polygon grouping
for (const auto omFaceHandle2 : omFaceHandles)
for (const auto& omFaceHandle2 : omFaceHandles)
{
polygonProps[omFaceHandle2] = omFaceHandles;
}
@@ -2413,7 +2408,7 @@ namespace WhiteBox
omExistingPolygonHandle.push_back(om_fh(newFaceHandle));
// update all face handles to point to the new polygon grouping
for (const Mesh::FaceHandle faceHandle : omExistingPolygonHandle)
for (const Mesh::FaceHandle& faceHandle : omExistingPolygonHandle)
{
polygonProps[faceHandle] = omExistingPolygonHandle;
}
@@ -2510,7 +2505,7 @@ namespace WhiteBox
auto& polygonProps = whiteBox.mesh.property(polygonPropsHandle);
// multiple face handles map to a polygon handle
for (const auto faceHandle : polygon)
for (const auto& faceHandle : polygon)
{
polygonProps[faceHandle] = polygon;
}
@@ -2658,7 +2653,7 @@ namespace WhiteBox
{
AZ_PROFILE_FUNCTION(AzToolsFramework);
for (const Mesh::FaceHandle faceHandle : whiteBox.mesh.faces())
for (const Mesh::FaceHandle& faceHandle : whiteBox.mesh.faces())
{
for (Mesh::FaceHalfedgeCCWIter faceHalfedgeIt = whiteBox.mesh.fh_ccwiter(faceHandle);
faceHalfedgeIt.is_valid(); ++faceHalfedgeIt)
@@ -2705,7 +2700,7 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
AzToolsFramework::MidpointCalculator midpointCalculator;
for (const auto vertexHandle : vertexHandles)
for (const auto& vertexHandle : vertexHandles)
{
midpointCalculator.AddPosition(VertexPosition(whiteBox, vertexHandle));
}
@@ -2723,7 +2718,7 @@ namespace WhiteBox
const auto adjacentPolygonEdgeHandles = PolygonBorderEdgeHandlesFlattened(whiteBox, adjacentPolygonHandle);
// iterate over all halfedges in the adjacent polygon
for (const auto edgeHandle : adjacentPolygonEdgeHandles)
for (const auto& edgeHandle : adjacentPolygonEdgeHandles)
{
const auto* const foundEdgeHandleInSelectedPolygon =
AZStd::find(selectedPolygonEdgeHandles.cbegin(), selectedPolygonEdgeHandles.cend(), edgeHandle);
@@ -2732,7 +2727,7 @@ namespace WhiteBox
if (foundEdgeHandleInSelectedPolygon == selectedPolygonEdgeHandles.cend())
{
// find outgoing edge handles
for (const auto halfedgeHandle :
for (const auto& halfedgeHandle :
VertexOutgoingHalfedgeHandles(whiteBox, vertexHandlePair.m_existing))
{
// attempt to find one of the outgoing halfedge handles in the adjacent polygon
@@ -2793,7 +2788,7 @@ namespace WhiteBox
FaceVertHandlesCollection& vertsForLinkingAdjacentPolygons)
{
// find all faces connected to this edge
for (const auto faceHandle : EdgeFaceHandles(whiteBox, edgeHandle))
for (const auto& faceHandle : EdgeFaceHandles(whiteBox, edgeHandle))
{
// find a face that is _not_ part of the polygon being appended/selected
if (AZStd::find(
@@ -2934,7 +2929,7 @@ namespace WhiteBox
// erase face handles from the polygon map and
// delete the faces from OpenMesh
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
polygonProps.erase(om_fh(faceHandle));
whiteBox.mesh.delete_face(om_fh(faceHandle), false);
@@ -2975,10 +2970,9 @@ namespace WhiteBox
using ModifiedFaceHandle = AZStd::pair<Mesh::FaceHandle, Mesh::FaceHandle>;
using ModifiedFaceHandles = AZStd::vector<ModifiedFaceHandle>;
// find all face handles that no longer match (where garbage_collect has invalidated the handles)
const ModifiedFaceHandles modifiedFaceHandles = std::transform_reduce(
faceHandlesCopy.cbegin(), faceHandlesCopy.cend(), faceHandlePtrs.cbegin(), ModifiedFaceHandles{},
// reduce
const ModifiedFaceHandles modifiedFaceHandles = AZStd::inner_product(
faceHandlesCopy.begin(), faceHandlesCopy.end(), faceHandlePtrs.begin(), ModifiedFaceHandles{},
//reduce
[](ModifiedFaceHandles modifiedFaceHandles, const ModifiedFaceHandle& fh)
{
if (fh.first.is_valid())
@@ -2988,7 +2982,7 @@ namespace WhiteBox
return modifiedFaceHandles;
},
// transform
//transform
[](const Mesh::FaceHandle lhs, const Mesh::FaceHandle* rhs)
{
// if any of the faceHandlePtrs differ, we know the handles
@@ -3030,14 +3024,14 @@ namespace WhiteBox
faces.reserve(existingFaces.size());
// for each face
for (const FaceHandle faceHandle : existingFaces)
for (const FaceHandle& faceHandle : existingFaces)
{
VertexHandles vertexHandlesForFace;
vertexHandlesForFace.reserve(3);
const auto vertexHandles = FaceVertexHandles(whiteBox, faceHandle);
// for each vertex handle
for (const VertexHandle vertexHandle : vertexHandles)
for (const VertexHandle& vertexHandle : vertexHandles)
{
// find vertex handle in vertices list
const auto* const vertexHandlePairIt = AZStd::find_if(
@@ -3092,11 +3086,11 @@ namespace WhiteBox
Internal::AppendedVerts appendedVerts;
appendedVerts.m_vertexHandlePairs.reserve(existingVertexHandles.size());
for (const VertexHandle existingVertexHandle : existingVertexHandles)
for (const VertexHandle& existingVertexHandle : existingVertexHandles)
{
bool vertexHandleAdded = false;
// visit all connected halfedge handles
for (const auto halfedgeHandle : VertexHalfedgeHandles(whiteBox, existingVertexHandle))
for (const auto& halfedgeHandle : VertexHalfedgeHandles(whiteBox, existingVertexHandle))
{
const auto edgeHandle = HalfedgeEdgeHandle(whiteBox, halfedgeHandle);
const bool boundaryEdge = EdgeIsBoundary(whiteBox, edgeHandle);
@@ -3372,7 +3366,7 @@ namespace WhiteBox
AZ_PROFILE_FUNCTION(AzToolsFramework);
const AZ::Transform polygonSpace = PolygonSpace(whiteBox, polygonHandle, pivot);
for (const auto vertexHandle : PolygonVertexHandles(whiteBox, polygonHandle))
for (const auto& vertexHandle : PolygonVertexHandles(whiteBox, polygonHandle))
{
SetVertexPosition(
whiteBox, vertexHandle,
@@ -92,7 +92,7 @@ namespace WhiteBox
};
const auto faceHandles = Api::MeshFaceHandles(whiteBox);
for (const auto faceHandle : faceHandles)
for (const auto& faceHandle : faceHandles)
{
faceData.push_back(createWhiteBoxFaceFromHandle(faceHandle));
}
@@ -817,7 +817,7 @@ namespace WhiteBox
debugDisplay.DepthTestOn();
for (const auto faceHandle : Api::MeshFaceHandles(whiteBoxMesh))
for (const auto& faceHandle : Api::MeshFaceHandles(whiteBoxMesh))
{
const auto faceHalfedgeHandles = Api::FaceHalfedgeHandles(whiteBoxMesh, faceHandle);
@@ -832,7 +832,7 @@ namespace WhiteBox
}) /
3.0f;
for (const auto halfedgeHandle : faceHalfedgeHandles)
for (const auto& halfedgeHandle : faceHalfedgeHandles)
{
const Api::VertexHandle vertexHandleAtTip =
Api::HalfedgeVertexHandleAtTip(whiteBoxMesh, halfedgeHandle);
@@ -887,7 +887,7 @@ namespace WhiteBox
if (cl_whiteBoxDebugEdgeHandles)
{
for (const auto edgeHandle : Api::MeshEdgeHandles(whiteBoxMesh))
for (const auto& edgeHandle : Api::MeshEdgeHandles(whiteBoxMesh))
{
const AZ::Vector3 localEdgeMidpoint = Api::EdgeMidpoint(whiteBoxMesh, edgeHandle);
const AZ::Vector3 worldEdgeMidpoint = worldFromLocal.TransformPoint(localEdgeMidpoint);
@@ -25,8 +25,6 @@ namespace WhiteBox
{
AZ_CLASS_ALLOCATOR_IMPL(EditorWhiteBoxComponentMode, AZ::SystemAllocator, 0)
static const int DefaultWidgetBottomMargin = 5;
// helper function to return what modifier keys move us to restore mode
static bool RestoreModifier(AzToolsFramework::ViewportInteraction::KeyboardModifiers modifiers)
{
@@ -410,7 +408,7 @@ namespace WhiteBox
}();
// all edges that are valid to interact with at this time
for (const auto edgeHandle : edgeHandles)
for (const auto& edgeHandle : edgeHandles)
{
const auto edge = Api::EdgeVertexPositions(*whiteBox, edgeHandle);
m_intersectionAndRenderData->m_whiteBoxIntersectionData.m_edgeBounds.emplace_back(
@@ -418,14 +416,14 @@ namespace WhiteBox
}
// handle drawing 'user' and 'mesh' edges slightly differently
for (const auto edgeHandle : edgeHandlesPair.m_user)
for (const auto& edgeHandle : edgeHandlesPair.m_user)
{
const auto edge = Api::EdgeVertexPositions(*whiteBox, edgeHandle);
m_intersectionAndRenderData->m_whiteBoxEdgeRenderData.m_bounds.m_user.emplace_back(
EdgeBoundWithHandle{EdgeBound{edge[0], edge[1], cl_whiteBoxEdgeSelectionWidth}, edgeHandle});
}
for (const auto edgeHandle : edgeHandlesPair.m_mesh)
for (const auto& edgeHandle : edgeHandlesPair.m_mesh)
{
const auto edge = Api::EdgeVertexPositions(*whiteBox, edgeHandle);
m_intersectionAndRenderData->m_whiteBoxEdgeRenderData.m_bounds.m_mesh.emplace_back(
@@ -6,4 +6,4 @@
#
#
set(PAL_TRAIT_WHITEBOX_SUPPORTED FALSE)
set(PAL_TRAIT_WHITEBOX_SUPPORTED TRUE)
@@ -10,6 +10,7 @@
#include "PackedFloat2.h"
#include <Atom/RPI.Public/Buffer/Buffer.h>
#include <Atom/RPI.Reflect/Buffer/BufferAsset.h>
#include <Atom/RPI.Reflect/Buffer/BufferAssetCreator.h>
#include <Atom/RPI.Reflect/Buffer/BufferAssetView.h>
@@ -155,7 +155,7 @@ namespace WhiteBox
// special handling for edges in the process of being restored - an edge may be clicked
// and remain 'orphaned' from a polygon until another connection (loop) can be made.
for (const Api::EdgeHandle edgeHandleRestore : m_edgeHandlesBeingRestored)
for (const Api::EdgeHandle& edgeHandleRestore : m_edgeHandlesBeingRestored)
{
if (AZStd::any_of(
interactiveEdgeHandles.begin(), interactiveEdgeHandles.end(),
@@ -14,7 +14,8 @@
#include "Viewport/WhiteBoxViewportConstants.h"
#include "WhiteBoxEdgeTranslationModifier.h"
#include "WhiteBoxManipulatorViews.h"
#include <AzCore/std/sort.h>
#include <AzCore/std/numeric.h>
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
#include <AzToolsFramework/Manipulators/ManipulatorView.h>
#include <AzToolsFramework/Manipulators/PlanarManipulator.h>
@@ -65,19 +66,17 @@ namespace WhiteBox
// (ensure to remove duplicates as vertices will be shared across edges)
static Api::VertexHandles VertexHandlesForEdges(const WhiteBoxMesh& whiteBox, const Api::EdgeHandles& edgeHandles)
{
auto vertexHandles = std::reduce(
Api::VertexHandles vertexHandles = AZStd::accumulate(
edgeHandles.cbegin(), edgeHandles.cend(), Api::VertexHandles{},
[&whiteBox](Api::VertexHandles vertexHandles, const Api::EdgeHandle edgeHandle)
[&whiteBox](Api::VertexHandles vertexHandles, const Api::EdgeHandle edgeHandle)
{
const auto edgeVertexHandles = Api::EdgeVertexHandles(whiteBox, edgeHandle);
vertexHandles.push_back(edgeVertexHandles[0]);
vertexHandles.push_back(edgeVertexHandles[1]);
vertexHandles.insert(vertexHandles.end(), edgeVertexHandles.begin(), edgeVertexHandles.end());
return vertexHandles;
});
std::sort(vertexHandles.begin(), vertexHandles.end());
vertexHandles.erase(std::unique(vertexHandles.begin(), vertexHandles.end()), vertexHandles.end());
AZStd::sort(vertexHandles.begin(), vertexHandles.end());
vertexHandles.erase(AZStd::unique(vertexHandles.begin(), vertexHandles.end()), vertexHandles.end());
return vertexHandles;
}
@@ -208,7 +207,7 @@ namespace WhiteBox
const AZ::Vector3 displacement = position - sharedState->m_prevPosition;
// have to make sure we don't move verts more than once
for (const auto vertexHandle : VertexHandlesForEdges(*whiteBox, m_edgeHandles))
for (const auto& vertexHandle : VertexHandlesForEdges(*whiteBox, m_edgeHandles))
{
SetVertexPosition(
*whiteBox, vertexHandle, VertexPosition(*whiteBox, vertexHandle) + displacement);
@@ -169,7 +169,7 @@ namespace WhiteBox
sharedState->m_appendStage == AppendStage::Complete)
{
size_t vertexIndex = 0;
for (const Api::VertexHandle vertexHandle : m_vertexHandles)
for (const Api::VertexHandle& vertexHandle : m_vertexHandles)
{
const AZ::Vector3 vertexPosition = sharedState->m_vertexPositions[vertexIndex++] +
action.LocalPositionOffset() - sharedState->m_activeAppendOffset;
@@ -148,7 +148,7 @@ namespace WhiteBox
m_localPositionAtMouseDown = m_translationManipulator->GetLocalPosition();
for (const auto edgeHandle : Api::VertexUserEdgeHandles(*whiteBox, m_vertexHandle))
for (const auto& edgeHandle : Api::VertexUserEdgeHandles(*whiteBox, m_vertexHandle))
{
const auto edgeVertexPositions = Api::EdgeVertexPositions(*whiteBox, edgeHandle);
sharedState->m_edgeBeginEnds.push_back(
+9 -9
View File
@@ -563,7 +563,7 @@ namespace UnitTest
const auto polygonHandle = Api::InitializeAsUnitQuad(*m_whiteBox);
const auto edgeHandles = Api::PolygonBorderEdgeHandlesFlattened(*m_whiteBox, polygonHandle);
for (const auto edgeHandle : edgeHandles)
for (const auto& edgeHandle : edgeHandles)
{
// when
const auto tail = Api::HalfedgeVertexPositionAtTail(
@@ -702,7 +702,7 @@ namespace UnitTest
// given
const auto edgeHandles = Api::MeshEdgeHandles(*m_whiteBox);
for (const auto edgeHandle : edgeHandles)
for (const auto& edgeHandle : edgeHandles)
{
const auto firstHalfedgeHandle = Api::EdgeHalfedgeHandle(*m_whiteBox, edgeHandle, Api::EdgeHalfedge::First);
const auto secondHalfedgeHandle =
@@ -992,7 +992,7 @@ namespace UnitTest
const auto polygonHandles = Api::InitializeAsUnitCube(*m_whiteBox);
// hide all 'logical'/'visible' edges (those that define the bounds of a polygon)
for (const auto edgeHandle :
for (const auto& edgeHandle :
{Api::EdgeHandle{1}, Api::EdgeHandle{3}, Api::EdgeHandle{4}, Api::EdgeHandle{0}, Api::EdgeHandle{6}})
{
Api::HideEdge(*m_whiteBox, edgeHandle);
@@ -1024,7 +1024,7 @@ namespace UnitTest
*m_whiteBox, Api::PolygonHandle{Api::FaceHandles{{Api::FaceHandle{4}, Api::FaceHandle{5}}}}, -0.25f);
// hide all 'logical'/'visible' edges for scale appended face
for (const auto edgeHandle : {Api::EdgeHandle{25}, Api::EdgeHandle{27}, Api::EdgeHandle{24}})
for (const auto& edgeHandle : {Api::EdgeHandle{25}, Api::EdgeHandle{27}, Api::EdgeHandle{24}})
{
Api::HideEdge(*m_whiteBox, edgeHandle);
}
@@ -1065,7 +1065,7 @@ namespace UnitTest
Api::InitializeAsUnitCube(*m_whiteBox);
// hide all vertical 'logical'/'visible' edges
for (const auto edgeHandle : {Api::EdgeHandle{13}, Api::EdgeHandle{15}, Api::EdgeHandle{12}})
for (const auto& edgeHandle : {Api::EdgeHandle{13}, Api::EdgeHandle{15}, Api::EdgeHandle{12}})
{
Api::HideEdge(*m_whiteBox, edgeHandle);
}
@@ -1138,7 +1138,7 @@ namespace UnitTest
int restoreCount = 0;
Api::EdgeHandles restoringEdgeHandles; // inout param
AZStd::optional<AZStd::array<Api::PolygonHandle, 2>> splitPolygons;
for (const Api::EdgeHandle edgeHandleToRestore : edgeHandlesToRestore)
for (const Api::EdgeHandle& edgeHandleToRestore : edgeHandlesToRestore)
{
splitPolygons = Api::RestoreEdge(*m_whiteBox, edgeHandleToRestore, restoringEdgeHandles);
restoreCount++;
@@ -1792,14 +1792,14 @@ namespace UnitTest
Api::InitializeAsUnitCube(*m_whiteBox);
// hide all top vertices
for (const auto vertexHandle :
for (const auto& vertexHandle :
{Api::VertexHandle{0}, Api::VertexHandle{1}, Api::VertexHandle{2}, Api::VertexHandle{3}})
{
Api::HideVertex(*m_whiteBox, vertexHandle);
}
// hide all vertical edges
for (const auto edgeHandle :
for (const auto& edgeHandle :
{Api::EdgeHandle{15}, Api::EdgeHandle{13}, Api::EdgeHandle{12}, Api::EdgeHandle{10}})
{
Api::HideEdge(*m_whiteBox, edgeHandle);
@@ -2116,7 +2116,7 @@ namespace UnitTest
bool edgeRestored = false;
Api::EdgeHandles restoringEdgeHandles; // inout param
for (const Api::EdgeHandle edgeHandleToRestore : edgeHandlesToRestore)
for (const Api::EdgeHandle& edgeHandleToRestore : edgeHandlesToRestore)
{
if (Api::RestoreEdge(*m_whiteBox, edgeHandleToRestore, restoringEdgeHandles))
{
@@ -158,8 +158,6 @@ namespace UnitTest
// the initial starting position of the entity (in front and to the left of the camera)
const AZ::Transform initialEntityTransformWorld =
AZ::Transform::CreateTranslation(AZ::Vector3(-10.0f, 10.0f, 0.0f));
// world space delta we will be moving the polygon face
const auto worldTranslationDelta = AZ::Vector3::CreateAxisX(20.0f);
// the face handle we will use to get the parent polygon from
const int faceHandle = 7;
// the polygon vertex handle we will be dragging