You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none #rnx #jira none #preflight 614ce33574f7e70001ea822b #ROBOMERGE-AUTHOR: ryan.schmidt #ROBOMERGE-SOURCE: CL 17617027 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v871-17566257) #ROBOMERGE[STARSHIP]: UE5-Release-Engine-Staging Release-5.0 [CL 17617043 by ryan schmidt in ue5-release-engine-test branch]
233 lines
6.4 KiB
C++
233 lines
6.4 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "TriangleTypes.h"
|
|
#include "VectorTypes.h"
|
|
|
|
#include "Math/IntVector.h"
|
|
#include "Math/Vector.h"
|
|
#include "IndexTypes.h"
|
|
|
|
namespace UE
|
|
{
|
|
namespace Geometry
|
|
{
|
|
|
|
using namespace UE::Math;
|
|
|
|
/**
|
|
* Most generic / lazy example of a triangle mesh adapter; possibly useful for prototyping / building on top of (but slower than making a more specific-case adapter)
|
|
*/
|
|
template <typename RealType>
|
|
struct TTriangleMeshAdapter
|
|
{
|
|
TFunction<bool(int32 index)> IsTriangle;
|
|
TFunction<bool(int32 index)> IsVertex;
|
|
TFunction<int32()> MaxTriangleID;
|
|
TFunction<int32()> MaxVertexID;
|
|
TFunction<int32()> TriangleCount;
|
|
TFunction<int32()> VertexCount;
|
|
TFunction<uint64()> GetChangeStamp;
|
|
TFunction<FIndex3i(int32)> GetTriangle;
|
|
TFunction<TVector<RealType>(int32)> GetVertex;
|
|
|
|
inline void GetTriVertices(int TID, UE::Math::TVector<RealType>& V0, UE::Math::TVector<RealType>& V1, UE::Math::TVector<RealType>& V2) const
|
|
{
|
|
FIndex3i TriIndices = GetTriangle(TID);
|
|
V0 = GetVertex(TriIndices.A);
|
|
V1 = GetVertex(TriIndices.B);
|
|
V2 = GetVertex(TriIndices.C);
|
|
}
|
|
};
|
|
|
|
typedef TTriangleMeshAdapter<double> FTriangleMeshAdapterd;
|
|
typedef TTriangleMeshAdapter<float> FTriangleMeshAdapterf;
|
|
|
|
/**
|
|
* Example function to generate a generic mesh adapter from arrays
|
|
* @param Vertices Array of mesh vertices
|
|
* @param Triangles Array of int-vectors, one per triangle, indexing into the vertices array
|
|
*/
|
|
inline FTriangleMeshAdapterd GetArrayMesh(TArray<FVector>& Vertices, TArray<FIntVector>& Triangles)
|
|
{
|
|
return {
|
|
[&](int) { return true; },
|
|
[&](int) { return true; },
|
|
[&]() { return Triangles.Num(); },
|
|
[&]() { return Vertices.Num(); },
|
|
[&]() { return Triangles.Num(); },
|
|
[&]() { return Vertices.Num(); },
|
|
[&]() { return 0; },
|
|
[&](int Idx) { return FIndex3i(Triangles[Idx]); },
|
|
[&](int Idx) { return FVector3d(Vertices[Idx]); }};
|
|
}
|
|
|
|
|
|
/**
|
|
* Faster adapter specifically for the common index mesh case
|
|
*/
|
|
template<typename IndexType, typename OutRealType, typename InVectorType=FVector>
|
|
struct TIndexMeshArrayAdapter
|
|
{
|
|
const TArray<InVectorType>* SourceVertices;
|
|
const TArray<IndexType>* SourceTriangles;
|
|
|
|
void SetSources(const TArray<InVectorType>* SourceVerticesIn, const TArray<IndexType>* SourceTrianglesIn)
|
|
{
|
|
SourceVertices = SourceVerticesIn;
|
|
SourceTriangles = SourceTrianglesIn;
|
|
}
|
|
|
|
TIndexMeshArrayAdapter() : SourceVertices(nullptr), SourceTriangles(nullptr)
|
|
{
|
|
}
|
|
|
|
TIndexMeshArrayAdapter(const TArray<InVectorType>* SourceVerticesIn, const TArray<IndexType>* SourceTrianglesIn) : SourceVertices(SourceVerticesIn), SourceTriangles(SourceTrianglesIn)
|
|
{
|
|
}
|
|
|
|
FORCEINLINE bool IsTriangle(int32 Index) const
|
|
{
|
|
return SourceTriangles->IsValidIndex(Index * 3);
|
|
}
|
|
|
|
FORCEINLINE bool IsVertex(int32 Index) const
|
|
{
|
|
return SourceVertices->IsValidIndex(Index);
|
|
}
|
|
|
|
FORCEINLINE int32 MaxTriangleID() const
|
|
{
|
|
return SourceTriangles->Num() / 3;
|
|
}
|
|
|
|
FORCEINLINE int32 MaxVertexID() const
|
|
{
|
|
return SourceVertices->Num();
|
|
}
|
|
|
|
// Counts are same as MaxIDs, because these are compact meshes
|
|
FORCEINLINE int32 TriangleCount() const
|
|
{
|
|
return SourceTriangles->Num() / 3;
|
|
}
|
|
|
|
FORCEINLINE int32 VertexCount() const
|
|
{
|
|
return SourceVertices->Num();
|
|
}
|
|
|
|
FORCEINLINE uint64 GetChangeStamp() const
|
|
{
|
|
return 1; // source data doesn't have a timestamp concept
|
|
}
|
|
|
|
FORCEINLINE FIndex3i GetTriangle(int32 Index) const
|
|
{
|
|
int32 Start = Index * 3;
|
|
return FIndex3i((int)(*SourceTriangles)[Start], (int)(*SourceTriangles)[Start+1], (int)(*SourceTriangles)[Start+2]);
|
|
}
|
|
|
|
FORCEINLINE TVector<OutRealType> GetVertex(int32 Index) const
|
|
{
|
|
return TVector<OutRealType>((*SourceVertices)[Index]);
|
|
}
|
|
|
|
FORCEINLINE void GetTriVertices(int32 TriIndex, UE::Math::TVector<OutRealType>& V0, UE::Math::TVector<OutRealType>& V1, UE::Math::TVector<OutRealType>& V2) const
|
|
{
|
|
int32 Start = TriIndex * 3;
|
|
V0 = TVector<OutRealType>((*SourceVertices)[(*SourceTriangles)[Start]]);
|
|
V1 = TVector<OutRealType>((*SourceVertices)[(*SourceTriangles)[Start+1]]);
|
|
V2 = TVector<OutRealType>((*SourceVertices)[(*SourceTriangles)[Start+2]]);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
* Second version of the above faster adapter
|
|
* -- for the case where triangle indices are packed into an integer vector type instead of flat
|
|
*/
|
|
template<typename IndexVectorType, typename OutRealType, typename InVectorType = FVector>
|
|
struct TIndexVectorMeshArrayAdapter
|
|
{
|
|
const TArray<InVectorType>* SourceVertices;
|
|
const TArray<IndexVectorType>* SourceTriangles;
|
|
|
|
void SetSources(const TArray<InVectorType>* SourceVerticesIn, const TArray<IndexVectorType>* SourceTrianglesIn)
|
|
{
|
|
SourceVertices = SourceVerticesIn;
|
|
SourceTriangles = SourceTrianglesIn;
|
|
}
|
|
|
|
TIndexVectorMeshArrayAdapter() : SourceVertices(nullptr), SourceTriangles(nullptr)
|
|
{
|
|
}
|
|
|
|
TIndexVectorMeshArrayAdapter(const TArray<InVectorType>* SourceVerticesIn, const TArray<IndexVectorType>* SourceTrianglesIn) : SourceVertices(SourceVerticesIn), SourceTriangles(SourceTrianglesIn)
|
|
{
|
|
}
|
|
|
|
FORCEINLINE bool IsTriangle(int32 Index) const
|
|
{
|
|
return SourceTriangles->IsValidIndex(Index);
|
|
}
|
|
|
|
FORCEINLINE bool IsVertex(int32 Index) const
|
|
{
|
|
return SourceVertices->IsValidIndex(Index);
|
|
}
|
|
|
|
FORCEINLINE int32 MaxTriangleID() const
|
|
{
|
|
return SourceTriangles->Num();
|
|
}
|
|
|
|
FORCEINLINE int32 MaxVertexID() const
|
|
{
|
|
return SourceVertices->Num();
|
|
}
|
|
|
|
// Counts are same as MaxIDs, because these are compact meshes
|
|
FORCEINLINE int32 TriangleCount() const
|
|
{
|
|
return SourceTriangles->Num();
|
|
}
|
|
|
|
FORCEINLINE int32 VertexCount() const
|
|
{
|
|
return SourceVertices->Num();
|
|
}
|
|
|
|
FORCEINLINE uint64 GetChangeStamp() const
|
|
{
|
|
return 1; // source data doesn't have a timestamp concept
|
|
}
|
|
|
|
FORCEINLINE FIndex3i GetTriangle(int32 Index) const
|
|
{
|
|
const IndexVectorType& Tri = (*SourceTriangles)[Index];
|
|
return FIndex3i((int)Tri[0], (int)Tri[1], (int)Tri[2]);
|
|
}
|
|
|
|
FORCEINLINE TVector<OutRealType> GetVertex(int32 Index) const
|
|
{
|
|
return TVector<OutRealType>((*SourceVertices)[Index]);
|
|
}
|
|
|
|
FORCEINLINE void GetTriVertices(int32 TriIndex, UE::Math::TVector<OutRealType>& V0, UE::Math::TVector<OutRealType>& V1, UE::Math::TVector<OutRealType>& V2) const
|
|
{
|
|
const IndexVectorType& Tri = (*SourceTriangles)[TriIndex];
|
|
V0 = TVector<OutRealType>((*SourceVertices)[Tri[0]]);
|
|
V1 = TVector<OutRealType>((*SourceVertices)[Tri[1]]);
|
|
V2 = TVector<OutRealType>((*SourceVertices)[Tri[2]]);
|
|
}
|
|
|
|
};
|
|
|
|
typedef TIndexMeshArrayAdapter<uint32, double> FIndexMeshArrayAdapterd;
|
|
|
|
|
|
} // end namespace UE::Geometry
|
|
} // end namespace UE
|