You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
- remove FDynamicMesh3::Timestamp (unused), rename Shape/Topology Timestamps to Shape/TopologyChangeStamp, change to atomic<uint32> - add FDynamicMesh3::bEnableShapeChangeStamp, default to false, to disable ShapeChange tracking. Add ::SetShapeChangeStampEnabled() and ::HasShapeChangeStampEnabled() to configure. - replace FDynamicMesh3::UpdateTimestamps() with UpdateChangeStamps() - add bTrackChange param to FDynamicMesh3::SetVertex(), optionally updates ShapeChangeStamp (if enabled). Default true. Remove SetVertex_NoTimeStampUpdate(), update call sites. - add FDynamicMesh3::GetChangeStamp(), returns combination of Shape and Topology stamps as uint64 - rename TTriangleMeshAdapter::GetTimestamp() to GetChangeStamp(), update usages - remove TPointSetAdapter::Timestamp() (was not used in code) - update TMeshAABBTree3 to use GetChangeStamp(), update internal checks to call IsValid() instead - update TFastWindingTree w/ similar changes - update calls in UVEditor, may require further updates #rb semion.piskarev #rnx #jira none #preflight 6126904c72e9eb00011434fe #ROBOMERGE-SOURCE: CL 17310271 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v861-17282326) [CL 17315112 by ryan schmidt in ue5-release-engine-test branch]
231 lines
6.3 KiB
C++
231 lines
6.3 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
|
|
{
|
|
|
|
/**
|
|
* 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<FVector3<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 FVector3<OutRealType> GetVertex(int32 Index) const
|
|
{
|
|
return FVector3<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 = FVector3<OutRealType>((*SourceVertices)[(*SourceTriangles)[Start]]);
|
|
V1 = FVector3<OutRealType>((*SourceVertices)[(*SourceTriangles)[Start+1]]);
|
|
V2 = FVector3<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 FVector3<OutRealType> GetVertex(int32 Index) const
|
|
{
|
|
return FVector3<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 = FVector3<OutRealType>((*SourceVertices)[Tri[0]]);
|
|
V1 = FVector3<OutRealType>((*SourceVertices)[Tri[1]]);
|
|
V2 = FVector3<OutRealType>((*SourceVertices)[Tri[2]]);
|
|
}
|
|
|
|
};
|
|
|
|
typedef TIndexMeshArrayAdapter<uint32, double> FIndexMeshArrayAdapterd;
|
|
|
|
|
|
} // end namespace UE::Geometry
|
|
} // end namespace UE
|