1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| void FBevelCubeBuilder::GenerateEdgeBevels(const TArray<FVector>& CorePoints) { struct FEdgeBevelDef { int32 Core1Idx; int32 Core2Idx; FVector Normal1; FVector Normal2; };
TArray<FEdgeBevelDef> EdgeDefs = { { 0, 1, FVector(0,-1,0), FVector(0,0,-1) }, { 2, 3, FVector(0,0,-1), FVector(0,1,0) }, { 4, 5, FVector(0,0,1), FVector(0,-1,0) }, { 6, 7, FVector(0,1,0), FVector(0,0,1) },
{ 0, 2, FVector(0,0,-1), FVector(-1,0,0) }, { 1, 3, FVector(1,0,0), FVector(0,0,-1) }, { 4, 6, FVector(-1,0,0), FVector(0,0,1) }, { 5, 7, FVector(0,0,1), FVector(1,0,0) },
{ 0, 4, FVector(-1,0,0), FVector(0,-1,0) }, { 1, 5, FVector(0,-1,0), FVector(1,0,0) }, { 2, 6, FVector(0,1,0), FVector(-1,0,0) }, { 3, 7, FVector(1,0,0), FVector(0,1,0) } };
for (int32 EdgeIndex = 0; EdgeIndex < EdgeDefs.Num(); ++EdgeIndex) { const FEdgeBevelDef& EdgeDef = EdgeDefs[EdgeIndex]; EdgeIndex, EdgeDef.Core1Idx, EdgeDef.Core2Idx); GenerateEdgeStrip(CorePoints, EdgeDef.Core1Idx, EdgeDef.Core2Idx, EdgeDef.Normal1, EdgeDef.Normal2); EdgeIndex, MeshData.GetVertexCount()); } MeshData.GetVertexCount(), MeshData.GetTriangleCount()); }
void FBevelCubeBuilder::GenerateEdgeStrip(const TArray<FVector>& CorePoints, int32 Core1Idx, int32 Core2Idx, const FVector& Normal1, const FVector& Normal2) { Core1Idx, Core2Idx); TArray<int32> PrevStripStartIndices; TArray<int32> PrevStripEndIndices;
for (int32 s = 0; s <= Params.BevelSections; ++s) { const float Alpha = static_cast<float>(s) / Params.BevelSections; FVector CurrentNormal = FMath::Lerp(Normal1, Normal2, Alpha).GetSafeNormal();
FVector PosStart = CorePoints[Core1Idx] + CurrentNormal * Params.BevelSize; FVector PosEnd = CorePoints[Core2Idx] + CurrentNormal * Params.BevelSize;
FVector2D UV1(Alpha, 0.0f); FVector2D UV2(Alpha, 1.0f);
int32 VtxStart = GetOrAddVertex(PosStart, CurrentNormal, UV1); int32 VtxEnd = GetOrAddVertex(PosEnd, CurrentNormal, UV2);
if (s > 0 && PrevStripStartIndices.Num() > 0 && PrevStripEndIndices.Num() > 0) { AddQuad(PrevStripStartIndices[0], PrevStripEndIndices[0], VtxEnd, VtxStart); }
PrevStripStartIndices = { VtxStart }; PrevStripEndIndices = { VtxEnd }; } }
|