EM_Task/UnrealEd/Private/Fbx/AdjacentInfo.h
Boshuang Zhao 5144a49c9b add
2026-02-13 16:18:33 +08:00

140 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <assert.h>
#include "CoreMinimal.h"
// 邻接顶点
class FAdjacentVertex
{
public:
FAdjacentVertex(const FAdjacentVertex& Vertex) = default;
FAdjacentVertex(uint32 index): index(index), inBorder(false), angle(0.0f) {}
uint32 Index() const { return index; }
FVector& Pos() { return pos; }
bool& InBorder() { return inBorder; }
FVector& Normal() { return normal; }
FVector& SoftNormal() { return softNormal; }
float& Angle() { return angle; }
float Type() const { return type; }
TArray<FAdjacentVertex*>& AdjVertice() { return adjVertice; }
void CalculateType();
void CalculateSoftNormalByAdjVertice();
void ProjectSoftNormalOnNormalPlane();
private:
// 此顶点索引
uint32 index;
// 顶点位置
FVector pos;
// 此顶点是否处于边界位置
bool inBorder;
FVector normal;
// 在边缘的话,软法线指向边界延伸方向
FVector softNormal;
// 邻接三角形角度和
float angle;
// 0表示非边界点内部点1表示普通边界点2表示angle大于270°的分叉点3表示angle小于90°的尖端点
float type;
TArray<FAdjacentVertex*> adjVertice;
};
bool operator==(const FAdjacentVertex& Left, const FAdjacentVertex& Right);
FORCEINLINE uint32 GetTypeHash(FAdjacentVertex Vertex)
{
return GetTypeHash(Vertex.Index());
}
// 邻接边
class FAdjacentEdge
{
public:
FAdjacentEdge(const FAdjacentEdge& Edge) = default;
FAdjacentEdge(FAdjacentVertex& V1, FAdjacentVertex& V2);
FAdjacentVertex& V1() { return v1; }
const FAdjacentVertex& V1() const { return v1; }
FAdjacentVertex& V2() { return v2; }
const FAdjacentVertex& V2() const { return v2; }
float Length() { return length; }
uint32& Count() { return count; }
// 设置此边连接的两个顶点位于边界
void SetInBorder();
void AddVertexToEdge();
private:
// 连接的两个顶点
FAdjacentVertex &v1, &v2;
float length;
uint32 count;
};
bool operator==(const FAdjacentEdge& Left, const FAdjacentEdge& Right);
// 顶点相同(顺序可以相反)的边,哈希值相同
FORCEINLINE uint32 GetTypeHash(FAdjacentEdge Edge)
{
return GetTypeHash(Edge.V1()) + GetTypeHash(Edge.V2());
}
// 邻接多边形
class FAdjacentPolygon
{
public:
FAdjacentPolygon(const FAdjacentPolygon& Triangle) = default;
FAdjacentPolygon(const TArray<FAdjacentVertex*>& Vertices, const TArray<FAdjacentEdge*>& Edges, int32 n);
FAdjacentVertex& V(uint32 i)
{
assert(0 <= i && i < n);
return *v[i];
}
FAdjacentEdge& E(uint32 i)
{
assert(0 <= i && i < n);
return *e[i];
}
// 计算三角形对每个顶点法线的贡献度
void CalculateVertexNormal();
private:
TArray<FAdjacentVertex*> v;
TArray<FAdjacentEdge*> e;
int32 n;
FVector normal;
};