1.绘制线
UWorld* World = GetWorld();
if (World)
{
FlushPersistentDebugLines(World);
for (int i = 0; i < PointLocationArr.Num() - 1; ++i)
{
//画线
DrawDebugLine(
World,
PointLocationArr[i],
PointLocationArr[i + 1],
FColor::Yellow,
true,
0.0f,
SDPG_MAX,
0.0f
);
}
}
2.绘制平面(代码是逆时针画)
得先在Actor里创建一个Component
//Procedural Mesh Component
UPROPERTY(VisibleAnywhere)
UProceduralMeshComponent* ProceduralMeshComponent;
.h
/**
* Triangulate a polygon as projected to the XY plane, using ear clipping. Orientation of triangles will match orientation of input curve
* Adapted from TriangulateSimplePolygon in GeometryProcessing's PolygonTriangulation.cpp, to avoid using any types/functions in GeometryProcessing
*
* @return bool indicating orientation of output triangles
*/
bool TriangulateSimpleXYPlanarPolygon(const TArray<FVector>& VertexPositions, TArray<FIntVector>& OutTriangles);
.cpp
bool FSplineMakerEdMode::TriangulateSimpleXYPlanarPolygon(const TArray<FVector>& VertexPositions, TArray<FIntVector>& OutTriangles)
{
// helper functions for analyzing XY-projected triangles
struct Local
{
// returns 2*signed_area of the triangle formed by pts A, B, C
static inline float XYArea2(const FVector& A, const FVector& B, const FVector& C)
{
return (A.X * B.Y - A.Y * B.X) + (B.X * C.Y - B.Y * C.X) + (C.X * A.Y - C.Y * A.X);
}
static inline bool XYIsTriangleFlipped(float OrientationSign, const FVector& A, const FVector& B, const FVector& C)
{
float XYSignedDoubleArea = XYArea2(A, B, C);
return XYSignedDoubleArea * OrientationSign < 0;
}
static inline bool XYIsInsideTriangle(const FVector& A, const FV