20 #define CREATEBOX_NUMVERTS 24 21 #define CREATEBOX_NUMTRIS 36 22 #define CREATEGRIDMESHTRIANGLES_NUMVERTS(NumX, NumY) (((NumX) + 1) * ((NumY) + 1)) 23 #define CREATEGRIDMESHTRIANGLES_NUMTRIS(NumX, NumY) ((NumX) * (NumY) * 2 * 3) 37 Vertices.Add(Position);
39 Tangents.Add(Tangent);
76 Vertices.Add(FRuntimeMeshVertexSimple(Position, Normal, Tangent, UV0));
93 int32 NewVertex = MeshBuilder->AddVertex(Position);
94 MeshBuilder->SetNormalTangent(NewVertex, Normal, Tangent);
95 MeshBuilder->SetUV(NewVertex, UV0);
100 MeshBuilder->AddIndex(
Index);
112 int32 NewVertex = MeshBuilder.
AddVertex(Position);
114 MeshBuilder.
SetUV(NewVertex, UV0);
132 Triangles.Add(
Index);
140 void URuntimeMeshShapeGenerator::CreateGridMesh(
float Width,
float Height, int32 NumSubdivisionsX, int32 NumSubdivisionsY, TArray<FVector>& Vertices, TArray<int32>& Triangles, TArray<FVector>& Normals, TArray<FVector2D>& UVs, TArray<FRuntimeMeshTangent>& Tangents)
150 Vertices.Add(Position);
152 Tangents.Add(Tangent);
158 Triangles.Add(
Index);
161 CreateGridMesh(Width, Height, NumSubdivisionsX, NumSubdivisionsY, VerticesBuilder, TrianglesBuilder);
176 Triangles.Add(
Index);
179 CreateGridMesh(Width, Height, NumSubdivisionsX, NumSubdivisionsY, VerticesBuilder, TrianglesBuilder);
189 Vertices.Add(FRuntimeMeshVertexSimple(Position, Normal, Tangent, UV0));
194 Triangles.Add(
Index);
197 CreateGridMesh(Width, Height, NumSubdivisionsX, NumSubdivisionsY, VerticesBuilder, TrianglesBuilder);
206 int32 NewVertex = MeshBuilder->AddVertex(Position);
207 MeshBuilder->SetNormalTangent(NewVertex, Normal, Tangent);
208 MeshBuilder->SetUV(NewVertex, UV0);
213 MeshBuilder->AddIndex(
Index);
216 CreateGridMesh(Width, Height, NumSubdivisionsX, NumSubdivisionsY, VerticesBuilder, TrianglesBuilder);
221 TrianglesBuilder(Vert0);
222 TrianglesBuilder(Vert1);
223 TrianglesBuilder(Vert3);
225 TrianglesBuilder(Vert1);
226 TrianglesBuilder(Vert2);
227 TrianglesBuilder(Vert3);
234 BoxVerts[0] = FVector(-BoxRadius.X, BoxRadius.Y, BoxRadius.Z);
235 BoxVerts[1] = FVector(BoxRadius.X, BoxRadius.Y, BoxRadius.Z);
236 BoxVerts[2] = FVector(BoxRadius.X, -BoxRadius.Y, BoxRadius.Z);
237 BoxVerts[3] = FVector(-BoxRadius.X, -BoxRadius.Y, BoxRadius.Z);
239 BoxVerts[4] = FVector(-BoxRadius.X, BoxRadius.Y, -BoxRadius.Z);
240 BoxVerts[5] = FVector(BoxRadius.X, BoxRadius.Y, -BoxRadius.Z);
241 BoxVerts[6] = FVector(BoxRadius.X, -BoxRadius.Y, -BoxRadius.Z);
242 BoxVerts[7] = FVector(-BoxRadius.X, -BoxRadius.Y, -BoxRadius.Z);
248 Normal = FVector(0.0
f, 0.0
f, 1.0
f);
250 VerticesBuilder(BoxVerts[0], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
251 VerticesBuilder(BoxVerts[1], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
252 VerticesBuilder(BoxVerts[2], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
253 VerticesBuilder(BoxVerts[3], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
257 Normal = FVector(-1.0
f, 0.0
f, 0.0
f);
259 VerticesBuilder(BoxVerts[4], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
260 VerticesBuilder(BoxVerts[0], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
261 VerticesBuilder(BoxVerts[3], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
262 VerticesBuilder(BoxVerts[7], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
266 Normal = FVector(0.0
f, 1.0
f, 0.0
f);
268 VerticesBuilder(BoxVerts[5], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
269 VerticesBuilder(BoxVerts[1], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
270 VerticesBuilder(BoxVerts[0], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
271 VerticesBuilder(BoxVerts[4], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
275 Normal = FVector(1.0
f, 0.0
f, 0.0
f);
277 VerticesBuilder(BoxVerts[6], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
278 VerticesBuilder(BoxVerts[2], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
279 VerticesBuilder(BoxVerts[1], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
280 VerticesBuilder(BoxVerts[5], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
284 Normal = FVector(0.0
f, -1.0
f, 0.0
f);
286 VerticesBuilder(BoxVerts[7], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
287 VerticesBuilder(BoxVerts[3], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
288 VerticesBuilder(BoxVerts[2], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
289 VerticesBuilder(BoxVerts[6], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
293 Normal = FVector(0.0
f, 0.0
f, -1.0
f);
295 VerticesBuilder(BoxVerts[7], Normal, Tangent, FVector2D(0.0
f, 0.0
f));
296 VerticesBuilder(BoxVerts[6], Normal, Tangent, FVector2D(0.0
f, 1.0
f));
297 VerticesBuilder(BoxVerts[5], Normal, Tangent, FVector2D(1.0
f, 1.0
f));
298 VerticesBuilder(BoxVerts[4], Normal, Tangent, FVector2D(1.0
f, 0.0
f));
304 if (NumX >= 2 && NumY >= 2)
307 for (
int XIdx = 0; XIdx < NumX - 1; XIdx++)
309 for (
int YIdx = 0; YIdx < NumY - 1; YIdx++)
311 const int32 I0 = (XIdx + 0)*NumY + (YIdx + 0);
312 const int32 I1 = (XIdx + 1)*NumY + (YIdx + 0);
313 const int32 I2 = (XIdx + 1)*NumY + (YIdx + 1);
314 const int32 I3 = (XIdx + 0)*NumY + (YIdx + 1);
331 static const FVector Normal(0.0
f, 0.0
f, 1.0
f);
332 static const FVector Tangent(0.0
f, -1.0
f, 0.0
f);
335 const float HalfX = Width * 0.5f;
336 const float HalfY = Height * 0.5f;
338 int32 NumVerticesX = NumSubdivisionsX + 1;
339 int32 NumVerticesY = NumSubdivisionsY + 1;
341 for (int32
X = 0;
X < NumVerticesX;
X++)
343 for (int32
Y = 0;
Y < NumVerticesY;
Y++)
346 Position.X = -HalfX + ((
X / (float)NumSubdivisionsX) * Width);
347 Position.Y = -HalfY + ((
Y / (float)NumSubdivisionsY) * Height);
350 UV.X =
X / (float)NumSubdivisionsX;
351 UV.Y =
Y / (float)NumSubdivisionsY;
353 VerticesBuilder(FVector(Position, 0.0
f), Normal, Tangent, UV);
static void CreateGridMesh(float Width, float Height, int32 NumSubdivisionsX, int32 NumSubdivisionsY, TArray< FVector > &Vertices, TArray< int32 > &Triangles, TArray< FVector > &Normals, TArray< FVector2D > &UVs, TArray< FRuntimeMeshTangent > &Tangents)
static void CreateGridMeshTriangles(int32 NumX, int32 NumY, bool bWinding, TArray< int32 > &Triangles)
static void CreateBoxMeshPacked(FVector BoxRadius, TArray< FRuntimeMeshBlueprintVertexSimple > &Vertices, TArray< int32 > &Triangles)
TFunction< void(const FVector &Position, const FVector &Normal, const FRuntimeMeshTangent &Tangent, const FVector2D &UV0)> FVerticesBuilderFunction
int32 AddVertex(FVector InPosition)
void EmptyIndices(int32 Slack=0)
#define CREATEGRIDMESHTRIANGLES_NUMVERTS(NumX, NumY)
#define CREATEGRIDMESHTRIANGLES_NUMTRIS(NumX, NumY)
void EmptyVertices(int32 Slack=0)
static void CreateBoxMesh(FVector BoxRadius, TArray< FVector > &Vertices, TArray< int32 > &Triangles, TArray< FVector > &Normals, TArray< FVector2D > &UVs, TArray< FRuntimeMeshTangent > &Tangents)
static void ConvertQuadToTriangles(UPARAM(ref) TArray< int32 > &Triangles, int32 Vert0, int32 Vert1, int32 Vert2, int32 Vert3)
TFunction< void(int32 Index)> FTrianglesBuilderFunction
#define CREATEBOX_NUMTRIS
void SetNormalTangent(int32 Index, FVector Normal, FRuntimeMeshTangent Tangent)
void SetUV(int32 Index, const FVector2D &Value)
#define CREATEBOX_NUMVERTS
static void CreateGridMeshPacked(float Width, float Height, int32 NumSubdivisionsX, int32 NumSubdivisionsY, TArray< FRuntimeMeshBlueprintVertexSimple > &Vertices, TArray< int32 > &Triangles)
int32 AddIndex(int32 NewIndex)