You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
149 lines
4.2 KiB
C
149 lines
4.2 KiB
C
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
/** An edge in 3D space, used by these utility functions. */
|
|
struct FUtilEdge3D
|
|
{
|
|
/** Start of edge in 3D space. */
|
|
FVector V0;
|
|
/** End of edge in 3D space. */
|
|
FVector V1;
|
|
};
|
|
|
|
/** An edge in 2D space, used by these utility functions. */
|
|
struct FUtilEdge2D
|
|
{
|
|
/** Start of edge in 2D space. */
|
|
FVector2D V0;
|
|
/** End of edge in 2D space. */
|
|
FVector2D V1;
|
|
};
|
|
|
|
/** A triangle vertex in 2D space, with UV information. */
|
|
struct FUtilVertex2D
|
|
{
|
|
FVector2D Pos;
|
|
FColor Color;
|
|
FVector2D UV;
|
|
bool bInteriorEdge;
|
|
|
|
FUtilVertex2D() {}
|
|
|
|
FUtilVertex2D(const FVector2D& InPos)
|
|
: Pos(InPos), Color(255,255,255,255), UV(0.f, 0.f), bInteriorEdge(false)
|
|
{}
|
|
|
|
FUtilVertex2D(const FVector2D& InPos, const FColor& InColor)
|
|
: Pos(InPos), Color(InColor), UV(0.f, 0.f), bInteriorEdge(false)
|
|
{}
|
|
};
|
|
|
|
/** A polygon in 2D space, used by utility function. */
|
|
struct FUtilPoly2D
|
|
{
|
|
/** Set of verts, in order, for polygon. */
|
|
TArray<FUtilVertex2D> Verts;
|
|
};
|
|
|
|
/** A set of 2D polygons, along with a transform for going into world space. */
|
|
struct FUtilPoly2DSet
|
|
{
|
|
TArray<FUtilPoly2D> Polys;
|
|
FMatrix PolyToWorld;
|
|
};
|
|
|
|
/** Triangle in 2D space. */
|
|
struct FUtilTri2D
|
|
{
|
|
FUtilVertex2D Verts[3];
|
|
};
|
|
|
|
/** Temp vertex struct for one vert of a static mesh triangle. */
|
|
struct FClipSMVertex
|
|
{
|
|
FVector Pos;
|
|
FVector TangentX;
|
|
FVector TangentY;
|
|
FVector TangentZ;
|
|
FVector2D UVs[8];
|
|
FColor Color;
|
|
};
|
|
|
|
/** Properties of a clipped static mesh face. */
|
|
struct FClipSMFace
|
|
{
|
|
int32 MaterialIndex;
|
|
uint32 SmoothingMask;
|
|
int32 NumUVs;
|
|
bool bOverrideTangentBasis;
|
|
|
|
FVector FaceNormal;
|
|
|
|
FMatrix TangentXGradient;
|
|
FMatrix TangentYGradient;
|
|
FMatrix TangentZGradient;
|
|
FMatrix UVGradient[8];
|
|
FMatrix ColorGradient;
|
|
|
|
void CopyFace(const FClipSMFace& OtherFace)
|
|
{
|
|
FMemory::Memcpy(this,&OtherFace,sizeof(FClipSMFace));
|
|
}
|
|
};
|
|
|
|
/** Properties of a clipped static mesh triangle. */
|
|
struct FClipSMTriangle : FClipSMFace
|
|
{
|
|
FClipSMVertex Vertices[3];
|
|
|
|
/** Compute the triangle's normal, and the gradients of the triangle's vertex attributes over XYZ. */
|
|
void ComputeGradientsAndNormal();
|
|
|
|
FClipSMTriangle(int32 Init)
|
|
{
|
|
FMemory::Memzero(this, sizeof(FClipSMTriangle));
|
|
}
|
|
};
|
|
|
|
/** Properties of a clipped static mesh polygon. */
|
|
struct FClipSMPolygon : FClipSMFace
|
|
{
|
|
TArray<FClipSMVertex> Vertices;
|
|
|
|
FClipSMPolygon(int32 Init)
|
|
{
|
|
FMemory::Memzero(this, sizeof(FClipSMPolygon));
|
|
}
|
|
};
|
|
|
|
/** Extracts the triangles from a static-mesh as clippable triangles. */
|
|
void GetClippableStaticMeshTriangles(TArray<FClipSMTriangle>& OutClippableTriangles,const UStaticMesh* StaticMesh);
|
|
|
|
|
|
/** Take the input mesh and cut it with supplied plane, creating new verts etc. Also outputs new edges created on the plane. */
|
|
void ClipMeshWithPlane( TArray<FClipSMTriangle>& OutTris, TArray<FUtilEdge3D>& OutClipEdges, const TArray<FClipSMTriangle>& InTriangles,const FPlane& Plane );
|
|
|
|
/** Take a set of 3D Edges and project them onto the supplied plane. Also returns matrix use to convert them back into 3D edges. */
|
|
void ProjectEdges( TArray<FUtilEdge2D>& Out2DEdges, FMatrix& ToWorld, const TArray<FUtilEdge3D>& In3DEdges, const FPlane& InPlane );
|
|
|
|
/** Given a set of edges, find the set of closed polygons created by them. */
|
|
void Buid2DPolysFromEdges(TArray<FUtilPoly2D>& OutPolys, const TArray<FUtilEdge2D>& InEdges, const FColor& VertColor);
|
|
|
|
/** Given a polygon, decompose into triangles and append to OutTris.
|
|
* @return true if the triangulation was successful.
|
|
*/
|
|
UNREALED_API bool TriangulatePoly(TArray<FClipSMTriangle>& OutTris, const FClipSMPolygon& InPoly, bool bKeepColinearVertices = false);
|
|
|
|
/** Transform triangle from 2D to 3D static-mesh triangle. */
|
|
FClipSMPolygon Transform2DPolygonToSMPolygon(const FUtilPoly2D& InTri, const FMatrix& InMatrix);
|
|
|
|
/** Does a simple box map onto this 2D polygon. */
|
|
void GeneratePolyUVs(FUtilPoly2D& Polygon);
|
|
|
|
/** Given a set of triangles, remove those which share an edge and could be collapsed into one triangle. */
|
|
UNREALED_API void RemoveRedundantTriangles(TArray<FClipSMTriangle>& Tris);
|
|
|
|
/** Split 2D polygons with a 3D plane. */
|
|
void Split2DPolysWithPlane(FUtilPoly2DSet& PolySet, const FPlane& Plane, const FColor& ExteriorVertColor, const FColor& InteriorVertColor);
|