2020-12-03 02:35:44 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "Polygroups/PolygroupSet.h"
|
|
|
|
|
#include "Polygroups/PolygroupUtil.h"
|
|
|
|
|
|
2021-03-09 19:33:56 -04:00
|
|
|
#include "ExplicitUseGeometryMathTypes.h" // using UE::Geometry::(math types)
|
2020-12-03 02:35:44 -04:00
|
|
|
using namespace UE::Geometry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FPolygroupSet::FPolygroupSet(const FPolygroupSet* CopyIn)
|
|
|
|
|
{
|
|
|
|
|
Mesh = CopyIn->Mesh;
|
|
|
|
|
PolygroupAttrib = CopyIn->PolygroupAttrib;
|
|
|
|
|
GroupLayerIndex = CopyIn->GroupLayerIndex;
|
|
|
|
|
MaxGroupID = CopyIn->MaxGroupID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FPolygroupSet::FPolygroupSet(FDynamicMesh3* MeshIn)
|
|
|
|
|
{
|
|
|
|
|
Mesh = MeshIn;
|
|
|
|
|
GroupLayerIndex = -1;
|
|
|
|
|
RecalculateMaxGroupID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FPolygroupSet::FPolygroupSet(FDynamicMesh3* MeshIn, FDynamicMeshPolygroupAttribute* PolygroupAttribIn)
|
|
|
|
|
{
|
|
|
|
|
Mesh = MeshIn;
|
|
|
|
|
PolygroupAttrib = PolygroupAttribIn;
|
|
|
|
|
GroupLayerIndex = UE::Geometry::FindPolygroupLayerIndex(*MeshIn, PolygroupAttrib);
|
|
|
|
|
RecalculateMaxGroupID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FPolygroupSet::FPolygroupSet(FDynamicMesh3* MeshIn, int32 PolygroupLayerIndex)
|
|
|
|
|
{
|
|
|
|
|
Mesh = MeshIn;
|
|
|
|
|
if (ensure(Mesh->Attributes()))
|
|
|
|
|
{
|
|
|
|
|
if (PolygroupLayerIndex < Mesh->Attributes()->NumPolygroupLayers())
|
|
|
|
|
{
|
|
|
|
|
PolygroupAttrib = Mesh->Attributes()->GetPolygroupLayer(PolygroupLayerIndex);
|
|
|
|
|
GroupLayerIndex = PolygroupLayerIndex;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
RecalculateMaxGroupID();
|
|
|
|
|
ensureMsgf(false, TEXT("FPolygroupSet: Attribute index missing!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FPolygroupSet::FPolygroupSet(FDynamicMesh3* MeshIn, FName AttribName)
|
|
|
|
|
{
|
|
|
|
|
Mesh = MeshIn;
|
|
|
|
|
PolygroupAttrib = UE::Geometry::FindPolygroupLayerByName(*MeshIn, AttribName);
|
|
|
|
|
GroupLayerIndex = UE::Geometry::FindPolygroupLayerIndex(*MeshIn, PolygroupAttrib);
|
|
|
|
|
RecalculateMaxGroupID();
|
|
|
|
|
ensureMsgf(PolygroupAttrib != nullptr, TEXT("FPolygroupSet: Attribute set missing!"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FPolygroupSet::RecalculateMaxGroupID()
|
|
|
|
|
{
|
|
|
|
|
MaxGroupID = 0;
|
|
|
|
|
if (PolygroupAttrib)
|
|
|
|
|
{
|
|
|
|
|
for (int32 tid : Mesh->TriangleIndicesItr())
|
|
|
|
|
{
|
2021-01-12 17:35:51 -04:00
|
|
|
MaxGroupID = FMath::Max(MaxGroupID, PolygroupAttrib->GetValue(tid) + 1);
|
2020-12-03 02:35:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int32 tid : Mesh->TriangleIndicesItr())
|
|
|
|
|
{
|
2021-01-12 17:35:51 -04:00
|
|
|
MaxGroupID = FMath::Max(MaxGroupID, Mesh->GetTriangleGroup(tid) + 1);
|
2020-12-03 02:35:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|