UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SweepGenerator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3Sharp CylinderGenerator
4
5#pragma once
6
7
8#include "Containers/Array.h"
10#include "Containers/Set.h"
11#include "FrameTypes.h"
12#include "Math/Vector.h"
13#include "Math/Vector2D.h"
14#include "MeshShapeGenerator.h"
15#include "Polygon2.h"
16#include "Util/ProgressCancel.h"
17#include "VectorTypes.h"
18
19class FProgressCancel;
20
21namespace UE
22{
23namespace Geometry
24{
25
29enum class ECapType
30{
31 None = 0,
34 // TODO: Cone, other caps ...
35};
36
38{
39public:
41 {
42 }
43
45 bool bPolygroupPerQuad = false;
46
49
50protected:
52
57 GEOMETRYCORE_API void ConstructMeshTopology(const FPolygon2d& CrossSection,
61 bool bEvenlySpaceUVs,
62 const TArrayView<const FVector3d>& Path, // can be empty unless bEvenlySpaceUVs is true
64 bool bLoop,
65 const ECapType Caps[2],
69 const TArrayView<const float>& CustomCrossSectionTexCoord = {}, // if specified and valid, we use custom UVs instead of automatically generating them
71};
72
88
93{
94public:
95 float Radius[2] = {1.0f, 1.0f};
96 float Height = 1.0f;
98
99public:
102};
103
108{
109public:
110 float StickRadius = 0.5f;
111 float StickLength = 1.0f;
112 float HeadBaseRadius = 1.0f;
113 float HeadTipRadius = 0.01f;
114 float HeadLength = 0.5f;
115
116 int AdditionalLengthSamples[3]{ 0,0,0 }; // additional length-wise samples on the three segments (along stick, along arrow base, along arrow cone)
117
119 {
123 float LenAlong = ComputeSegLengths(Radii, Heights, AlongPercents);
124 for (int Idx = 0; Idx < 3; Idx++)
125 {
126 AdditionalLengthSamples[Idx] = (int)(.5f+AlongPercents[Idx + 1] * float(TargetSamples));
127 }
128 }
129
130public:
133};
134
135
136
144{
145public:
148
150 // If PathFrames.Num == Path.Num, then PathFrames[k] is used for each step instead of the propagated InitialFrame.
152 // If PathScales.Num == Path.Num, then PathScales[k] is applied to the CrossSection at each step (this is combined with StartScale/EndScale, but ignored if bLoop=true)
154
155 bool bCapped = false;
156 bool bLoop = false;
158
159 // 2D uniform scale of the CrossSection, interpolated along the Path (via arc length) from StartScale to EndScale
160 double StartScale = 1.0;
161 double EndScale = 1.0;
162
163 // Maximum factor by which mitering can expand the cross section at sharp turns, to give the appearance of a consistent cross section width. Only used if > 1.0.
164 // Note: If PathFrames are specified, then bAlignFramesToSampledTangents must be true for mitering to be performed.
165 // (Similar to the MiterLimit concept in SVG / CSS)
166 double MiterLimit = 1.0;
167
168 // Whether to align the frames to the path tangents. Only relevant if PathFrames is specified.
170
171 // Configure settings to support mitering -- i.e., scaling the cross sections as needed to maintain consistent cross section size through sharp corners, up to the specified scale limit
172 void EnableMitering(double InMiterLimit = 10)
173 {
176 }
177
178 // Set the MiterLimit based on the maximum turn angle at which a correct miter should be applied. For turns sharper than this angle, the cross section will appear to shrink at the turn.
179 // @param MiterAngleLimitInDeg Maximum turn angle for correct mitering; should be >= 0 and < 180
181 {
182 MiterAngleLimitInDeg = FMath::Clamp(MiterAngleLimitInDeg, 0, 180 - FMathd::ZeroTolerance);
183 MiterLimit = 1.0/FMath::Sin(MiterAngleLimitInDeg * FMathd::DegToRad * .5);
184 }
185
186 // When true, the generator attempts to scale UV's in a way that preserves scaling across different mesh
187 // results, aiming for 1.0 in UV space to be equal to UnitUVInWorldCoordinates in world space. This in
188 // practice means adjusting the U scale relative to the CrossSection curve length and V scale relative
189 // to the distance between vertices on the Path.
191
192 // Only relevant if bUVScaleRelativeWorld is true (see that description)
194
195 // Optional custom UV values:
196
197 // -If FSweepGeneratorBase::bProfileCurveIsClosed == true and CrossSectionTexCoord.Num() >= CrossSection.VertexCount() + 1
198 // then the first CrossSection.VertexCount() + 1 values will be used as U coordinates.
199 //
200 // -If FSweepGeneratorBase::bProfileCurveIsClosed == true and CrossSectionTexCoord.Num() == CrossSection.VertexCount()
201 // then the CrossSectionTexCoord[0] will be used as the value for the last element.
202 //
203 // -If FSweepGeneratorBase::bProfileCurveIsClosed == false and CrossSectionTexCoord.Num() >= CrossSection.VertexCount()
204 // then the first CrossSection.VertexCount() values will be used as U coordinates.
205 //
206 // -Otherwise, the U coordinates will be automatically generated.
208
209 // -If bLoop == true and PathTexCoord.Num() >= Path.Num() + 1 then the first Path.Num() + 1 values will be used as
210 // V coordinates.
211 //
212 // -If bLoop == true and PathTexCoord.Num() == Path.Num() then the PathTexCoord[0] will be used as the value for the
213 // last element.
214 //
215 // -If bLoop == false and PathTexCoord.Num() >= Path.Num() then the first Path.Num() values will be used as V
216 // coordinates.
217 //
218 // -Otherwise, the V coordinates will be automatically generated.
220
221public:
224};
225
227{
229 Single,
231 PerFace,
232
233 /* One polygroup per strip that represents a step along the sweep curve. */
235 /* One polygroup per strip coming from each individual edge of the profile curve. */
237};
238
240{
242 Uniform,
245};
246
257{
258public:
259
260 // Curve that will be swept along the curve, given in coordinates of the frames used in the sweep curve.
262
263 // Curve along which to sweep the profile curve.
265
266 // (Optional) Curve along which to scale the profile curve, corresponding to each frame in SweepCurve.
268
269 // Indices into ProfileCurve that should not be swept along the curve, instead being instantiated
270 // just once. This is useful for welding vertices on an axis of rotation if the sweep curve denotes
271 // a revolution.
273
274 // Generated UV coordinates will be multiplied by these values.
276
277 // These values will be added to the generated UV coordinates after applying UVScale.
279
280 // When true, the generator attempts to scale UV's in a way that preserves scaling across different mesh
281 // results, aiming for 1.0 in UV space to be equal to UnitUVInWorldCoordinates in world space. This is
282 // generally speaking unrealistic because UV's are going to be variably stretched no matter what, but
283 // in practice it means adjusting the V scale relative to the profile curve length and U scale relative
284 // to a very crude measurement of movement across sweep frames.
286
287 // Only relevant if bUVScaleRelativeWorld is true (see that description)
289
290 // If true, the last point of the sweep curve is considered to be connected to the first.
292
293 // If true, the last point of the profile curve is considered to be connected to the first.
295
296 // If true, each triangle will have its own normals at each vertex, rather than sharing averaged
297 // ones with nearby triangles.
298 bool bSharpNormals = true;
299
300 // If true, welded-to-welded connections in the profile curve (which can't result in triangles)
301 // do not affect the UV layout.
303
305
306 // When QuadSplitMode is ShortestDiagonal, biases one of the diagonals so that symmetric
307 // quads are split uniformly. The tolerance is a proportion allowable difference.
308 double DiagonalTolerance = 0.01;
309
311
312 // If not null, this pointer is intermittently used to check whether the current operation should stop early
314
315 // TODO: We could allow the user to dissallow bowtie vertex creation, which currently could
316 // happen depending on which vertices are welded.
317
318public:
319
322
330
331 // TODO: We could output other boundaries too, but that's probably only worth doing once we find
332 // a case where we would actually use them.
333protected:
334
341};
342
343
344} // end namespace UE::Geometry
345} // end namespace UE
346
347#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
348#include "BoxTypes.h"
349#include "IndexTypes.h"
350#include "MatrixTypes.h"
351#include "Math/UnrealMathSSE.h"
354#include "HAL/PlatformCrt.h"
355#include "CoreMinimal.h"
357#include "Curve/CurveUtil.h"
358#include "MathUtil.h"
359#include "Misc/AssertionMacros.h"
360#endif
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TVector2< double > FVector2d
Definition MathFwd.h:61
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition ProgressCancel.h:187
Definition ArrayView.h:139
Definition Array.h:670
Definition SweepGenerator.h:108
float StickRadius
Definition SweepGenerator.h:110
int AdditionalLengthSamples[3]
Definition SweepGenerator.h:116
virtual GEOMETRYCORE_API FMeshShapeGenerator & Generate() override
Definition SweepGenerator.cpp:561
void DistributeAdditionalLengthSamples(int TargetSamples)
Definition SweepGenerator.h:118
float HeadTipRadius
Definition SweepGenerator.h:113
float HeadLength
Definition SweepGenerator.h:114
float HeadBaseRadius
Definition SweepGenerator.h:112
float StickLength
Definition SweepGenerator.h:111
Definition SweepGenerator.h:93
float Height
Definition SweepGenerator.h:96
int LengthSamples
Definition SweepGenerator.h:97
virtual GEOMETRYCORE_API FMeshShapeGenerator & Generate() override
Definition SweepGenerator.cpp:536
float Radius[2]
Definition SweepGenerator.h:95
Definition SweepGenerator.h:144
FFrame3d InitialFrame
Definition SweepGenerator.h:149
bool bAlignFramesToSampledTangents
Definition SweepGenerator.h:169
bool bUVScaleRelativeWorld
Definition SweepGenerator.h:190
double EndScale
Definition SweepGenerator.h:161
void EnableMitering(double InMiterLimit=10)
Definition SweepGenerator.h:172
bool bCapped
Definition SweepGenerator.h:155
TArray< float > PathTexCoord
Definition SweepGenerator.h:219
void SetMiterLimitByAngle(double MiterAngleLimitInDeg)
Definition SweepGenerator.h:180
FPolygon2d CrossSection
Definition SweepGenerator.h:146
TArray< FFrame3d > PathFrames
Definition SweepGenerator.h:151
float UnitUVInWorldCoordinates
Definition SweepGenerator.h:193
virtual GEOMETRYCORE_API FMeshShapeGenerator & Generate() override
Definition SweepGenerator.cpp:603
bool bLoop
Definition SweepGenerator.h:156
TArray< FVector2d > PathScales
Definition SweepGenerator.h:153
double MiterLimit
Definition SweepGenerator.h:166
double StartScale
Definition SweepGenerator.h:160
ECapType CapType
Definition SweepGenerator.h:157
TArray< FVector3d > Path
Definition SweepGenerator.h:147
TArray< float > CrossSectionTexCoord
Definition SweepGenerator.h:207
Definition MeshShapeGenerator.h:19
Definition SweepGenerator.h:257
FVector2d UVOffset
Definition SweepGenerator.h:278
bool bSharpNormals
Definition SweepGenerator.h:298
GEOMETRYCORE_API void AdjustNormalsForTriangle(int32 TriIndex, int32 FirstIndex, int32 SecondIndex, int32 ThirdIndex, TArray< FVector3d > &WeightedNormals)
Definition SweepGenerator.cpp:780
FVector2d UVScale
Definition SweepGenerator.h:275
float UnitUVInWorldCoordinates
Definition SweepGenerator.h:288
EProfileSweepQuadSplit QuadSplitMethod
Definition SweepGenerator.h:304
bool bSweepCurveIsClosed
Definition SweepGenerator.h:291
TArray< int32 > EndProfiles[2]
Definition SweepGenerator.h:329
bool bProfileCurveIsClosed
Definition SweepGenerator.h:294
double DiagonalTolerance
Definition SweepGenerator.h:308
TArray< FVector3d > ProfileCurve
Definition SweepGenerator.h:261
bool bUVsSkipFullyWeldedEdges
Definition SweepGenerator.h:302
FProgressCancel * Progress
Definition SweepGenerator.h:313
TArray< FVector3d > SweepScaleCurve
Definition SweepGenerator.h:267
virtual GEOMETRYCORE_API FMeshShapeGenerator & Generate() override
Definition SweepGenerator.cpp:817
GEOMETRYCORE_API void InitializeUvBuffer(const TArray< int32 > &VertPositionOffsets, int32 &NumUvRowsOut, int32 &NumUvColumnsOut)
Definition SweepGenerator.cpp:1167
EProfileSweepPolygonGrouping PolygonGroupingMode
Definition SweepGenerator.h:310
bool bUVScaleRelativeWorld
Definition SweepGenerator.h:285
TArray< FFrame3d > SweepCurve
Definition SweepGenerator.h:264
TSet< int32 > WeldedVertices
Definition SweepGenerator.h:272
Definition SweepGenerator.h:38
int32 CapPolygonStart[2]
Definition SweepGenerator.h:51
int32 CapNormalStart[2]
Definition SweepGenerator.h:51
int32 CapVertStart[2]
Definition SweepGenerator.h:51
bool bPolygroupPerQuad
Definition SweepGenerator.h:45
int32 CapTriangleStart[2]
Definition SweepGenerator.h:51
virtual ~FSweepGeneratorBase()
Definition SweepGenerator.h:40
int32 CapUVStart[2]
Definition SweepGenerator.h:51
bool bProfileCurveIsClosed
Definition SweepGenerator.h:48
GEOMETRYCORE_API void ConstructMeshTopology(const FPolygon2d &CrossSection, const TArrayView< const int32 > &UVSections, const TArrayView< const int32 > &NormalSections, const TArrayView< const int32 > &SharpNormalsAlongLength, bool bEvenlySpaceUVs, const TArrayView< const FVector3d > &Path, int32 NumCrossSections, bool bLoop, const ECapType Caps[2], FVector2f SectionsUVScale, FVector2f CapUVScale, FVector2f CapUVOffset, const TArrayView< const float > &CustomCrossSectionTexCoord={}, const TArrayView< const float > &CustomPathTexCoord={})
Definition SweepGenerator.cpp:13
Definition SweepGenerator.h:77
bool bUVScaleMatchSidesAndCaps
Definition SweepGenerator.h:81
int AngleSamples
Definition SweepGenerator.h:79
GEOMETRYCORE_API bool GenerateVerticalCircleSweep(const TArrayView< float > &Radii, const TArrayView< float > &Heights, const TArrayView< int > &SharpNormalsAlongLength)
Definition SweepGenerator.cpp:400
bool bCapped
Definition SweepGenerator.h:80
static GEOMETRYCORE_API float ComputeSegLengths(const TArrayView< float > &Radii, const TArrayView< float > &Heights, TArray< float > &AlongPercents)
Definition SweepGenerator.cpp:381
ECapType CapType
Definition SweepGenerator.h:82
EProfileSweepQuadSplit
Definition SweepGenerator.h:240
EProfileSweepPolygonGrouping
Definition SweepGenerator.h:227
ECapType
Definition SweepGenerator.h:30
Definition AdvancedWidgetsModule.cpp:13
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592