UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MeshElementContainer.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
9#include "CoreMinimal.h"
10#include "CoreTypes.h"
11#include "MeshAttributeArray.h"
14#include "Templates/UniquePtr.h"
16
17
25{
26public:
30
33 {
34 BitArray = MoveTemp(Other.BitArray);
35 Attributes = MoveTemp(Other.Attributes);
36 NumHoles = Other.NumHoles;
37 Other.NumHoles = 0;
38 }
39
42 {
43 if (this != &Other)
44 {
45 BitArray = MoveTemp(Other.BitArray);
46 Attributes = MoveTemp(Other.Attributes);
47 NumHoles = Other.NumHoles;
48 Other.NumHoles = 0;
49 }
50 return *this;
51 }
52
54 void Reset(const int32 Elements = 0)
55 {
56 BitArray.Empty(Elements);
58 NumHoles = 0;
59 }
60
62 void Reserve(const int32 Elements) { BitArray.Reserve(Elements); }
63
66 {
67 if (NumHoles > 0)
68 {
69 // If there are holes, use those up first.
72 NumHoles--;
73 return Index;
74 }
75 else
76 {
77 // Otherwise add a new element, and insert a corresponding attribute slot.
78 const int32 Index = BitArray.Add(true);
80 return Index;
81 }
82 }
83
85 void Insert(const int32 Index)
86 {
87 checkSlow(Index >= 0);
88 if (Index >= BitArray.Num())
89 {
90 // If the index is beyond the current bit array size, create a new one, padded out with zeroes.
95 BitArray[Index] = true;
98 }
99 else
100 {
101 // Can't insert an index over an existing one.
102 // If we get here, we assume this is a hole, so decrement the number of holes.
104 BitArray[Index] = true;
105 NumHoles--;
106 }
107 }
108
110 void Remove(const int32 Index)
111 {
112 // We can't remove an element which is already a hole.
114 BitArray[Index] = false;
115 NumHoles++;
117 }
118
120 int32 Num() const { return BitArray.Num() - NumHoles; }
121
123 int32 GetArraySize() const { return BitArray.Num(); }
124
127 {
128 return BitArray.Find(true);
129 }
130
132 bool IsValid(const int32 Index) const
133 {
134 return Index >= 0 && Index < BitArray.Num() && BitArray[Index];
135 }
136
139 inline const FAttributesSetBase& GetAttributes() const { return Attributes; }
140
143
145 MESHDESCRIPTION_API void Remap(const TSparseArray<int32>& IndexRemap);
146
149 {
150 Ar << Container.BitArray;
151 // We could count the number of holes in the BitArray, but it is quicker for serialization purposes (particularly in transactions) to just store it.
152 Ar << Container.NumHoles;
153 Ar << Container.Attributes;
154 return Ar;
155 }
156
168 {
169 public:
170 explicit inline FElementIDs(const TBitArray<>& InArray)
171 : Array(InArray)
172 {}
173
175 {
176 public:
178 : Iterator(MoveTemp(It))
179 {}
180
182 {
183 ++Iterator;
184 return *this;
185 }
186
187 inline int32 operator*() const
188 {
189 return Iterator ? Iterator.GetIndex() : INDEX_NONE;
190 }
191
192 friend inline bool operator==(const FConstIterator& Lhs, const FConstIterator& Rhs)
193 {
194 return Lhs.Iterator == Rhs.Iterator;
195 }
196
197 friend inline bool operator!=(const FConstIterator& Lhs, const FConstIterator& Rhs)
198 {
199 return Lhs.Iterator != Rhs.Iterator;
200 }
201
202 private:
203 TConstSetBitIterator<> Iterator;
204 };
205
207 {
209 }
210
211 public:
212 inline FConstIterator begin() const
213 {
215 }
216
217 inline FConstIterator end() const
218 {
219 return FConstIterator(TConstSetBitIterator<>(Array, Array.Num()));
220 }
221
222 private:
223 const TBitArray<>& Array;
224 };
225
227 FElementIDs inline GetElementIDs() const { return FElementIDs(BitArray); }
228
229protected:
232
235
238};
239
240
244template <typename ElementIDType>
246{
247public:
253
256 {
258 }
259
262 {
264 }
265
271
273 bool IsValid(const ElementIDType Index) const
274 {
275 return FMeshElementContainer::IsValid(Index.GetValue());
276 }
277
280 inline const TAttributesSet<ElementIDType>& GetAttributes() const { return static_cast<const TAttributesSet<ElementIDType>&>(Attributes); }
281
288
300 {
301 public:
302 explicit inline TElementIDs(const TBitArray<>& InArray)
303 : Array(InArray)
304 {}
305
307 {
308 public:
310 : Iterator(MoveTemp(It))
311 {}
312
314 {
315 ++Iterator;
316 return *this;
317 }
318
320 {
321 return ElementIDType{Iterator ? Iterator.GetIndex() : INDEX_NONE};
322 }
323
324 friend inline bool operator==(const TConstIterator& Lhs, const TConstIterator& Rhs)
325 {
326 return Lhs.Iterator == Rhs.Iterator;
327 }
328
329 friend inline bool operator!=(const TConstIterator& Lhs, const TConstIterator& Rhs)
330 {
331 return Lhs.Iterator != Rhs.Iterator;
332 }
333
334 private:
335 TConstSetBitIterator<> Iterator;
336 };
337
339 {
341 }
342
343 public:
344 inline TConstIterator begin() const
345 {
347 }
348
349 inline TConstIterator end() const
350 {
351 return TConstIterator(TConstSetBitIterator<>(Array, Array.Num()));
352 }
353
354 private:
355 const TBitArray<>& Array;
356 };
357
359 TElementIDs inline GetElementIDs() const { return TElementIDs(BitArray); }
360};
361
362
367{
368public:
371 {
372 Channels.SetNum(NumberOfIndices);
373 }
374
376 inline const FMeshElementContainer& Get(const int32 Index = 0) const { return Channels[Index]; }
377 inline const FMeshElementContainer& operator[](const int32 Index) const { return Channels[Index]; }
378 inline const FMeshElementContainer& operator*() const { return Channels[0]; }
379 inline const FMeshElementContainer* operator->() const { return &Channels[0]; }
380 inline FMeshElementContainer& Get(const int32 Index = 0) { return Channels[Index]; }
381 inline FMeshElementContainer& operator[](const int32 Index) { return Channels[Index]; }
382 inline FMeshElementContainer& operator*() { return Channels[0]; }
383 inline FMeshElementContainer* operator->() { return &Channels[0]; }
384
386 void SetNumChannels(const int32 NumIndices) { Channels.SetNum(NumIndices); }
387
389 int32 GetNumChannels() const { return Channels.Num(); }
390
392 void Reset()
393 {
394 for (FMeshElementContainer& Channel : Channels)
395 {
396 Channel.Reset();
397 }
398 }
399
401 bool IsEmpty() const
402 {
403 for (const FMeshElementContainer& Channel : Channels)
404 {
405 if (Channel.GetArraySize() != 0) { return false; }
406 }
407
408 return true;
409 }
410
413 {
414 Ar << ElementType.Channels;
415 return Ar;
416 }
417
418private:
419 // The usual thing is that a MeshElementType has exactly one channel, so we specially reserve a single element inline to save extra allocations
421};
422
423
429{
430public:
437
444
447 {
449 Swap(*this, Temp);
450 return *this;
451 }
452
455
458
460 const FMeshElementChannels* Get() const { return Ptr.Get(); }
461 const FMeshElementChannels* operator->() const { return Ptr.Get(); }
462 const FMeshElementChannels& operator*() const { return *Ptr; }
463 FMeshElementChannels* Get() { return Ptr.Get(); }
465 FMeshElementChannels& operator*() { return *Ptr; }
466
469 {
470 Ar << *Wrapper.Ptr;
471 return Ar;
472 }
473
474private:
476};
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
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_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Archive.h:1208
Definition MeshAttributeArray.h:1557
void Insert(const int32 Index)
Definition MeshAttributeArray.h:1759
void Initialize(const int32 Count)
Definition MeshAttributeArray.h:1689
void Remove(const int32 Index)
Definition MeshAttributeArray.h:1792
Definition MeshElementContainer.h:367
int32 GetNumChannels() const
Definition MeshElementContainer.h:389
void SetNumChannels(const int32 NumIndices)
Definition MeshElementContainer.h:386
const FMeshElementContainer & operator[](const int32 Index) const
Definition MeshElementContainer.h:377
FMeshElementContainer & operator[](const int32 Index)
Definition MeshElementContainer.h:381
friend FArchive & operator<<(FArchive &Ar, FMeshElementChannels &ElementType)
Definition MeshElementContainer.h:412
const FMeshElementContainer & Get(const int32 Index=0) const
Definition MeshElementContainer.h:376
FMeshElementContainer & operator*()
Definition MeshElementContainer.h:382
FMeshElementContainer * operator->()
Definition MeshElementContainer.h:383
bool IsEmpty() const
Definition MeshElementContainer.h:401
FMeshElementContainer & Get(const int32 Index=0)
Definition MeshElementContainer.h:380
const FMeshElementContainer * operator->() const
Definition MeshElementContainer.h:379
const FMeshElementContainer & operator*() const
Definition MeshElementContainer.h:378
FMeshElementChannels(const int32 NumberOfIndices=1)
Definition MeshElementContainer.h:370
void Reset()
Definition MeshElementContainer.h:392
Definition MeshElementContainer.h:175
friend bool operator==(const FConstIterator &Lhs, const FConstIterator &Rhs)
Definition MeshElementContainer.h:192
int32 operator*() const
Definition MeshElementContainer.h:187
friend bool operator!=(const FConstIterator &Lhs, const FConstIterator &Rhs)
Definition MeshElementContainer.h:197
FConstIterator(TConstSetBitIterator<> &&It)
Definition MeshElementContainer.h:177
FConstIterator & operator++()
Definition MeshElementContainer.h:181
Definition MeshElementContainer.h:168
FElementIDs(const TBitArray<> &InArray)
Definition MeshElementContainer.h:170
FConstIterator begin() const
Definition MeshElementContainer.h:212
FConstIterator CreateConstIterator() const
Definition MeshElementContainer.h:206
FConstIterator end() const
Definition MeshElementContainer.h:217
Definition MeshElementContainer.h:25
void Remove(const int32 Index)
Definition MeshElementContainer.h:110
MESHDESCRIPTION_API void Remap(const TSparseArray< int32 > &IndexRemap)
Definition MeshElementContainer.cpp:26
void Insert(const int32 Index)
Definition MeshElementContainer.h:85
FMeshElementContainer(FMeshElementContainer &&Other)
Definition MeshElementContainer.h:32
int32 Add()
Definition MeshElementContainer.h:65
void Reserve(const int32 Elements)
Definition MeshElementContainer.h:62
FMeshElementContainer(const FMeshElementContainer &)=default
FMeshElementContainer & operator=(FMeshElementContainer &&Other)
Definition MeshElementContainer.h:41
const FAttributesSetBase & GetAttributes() const
Definition MeshElementContainer.h:139
TBitArray BitArray
Definition MeshElementContainer.h:231
FAttributesSetBase & GetAttributes()
Definition MeshElementContainer.h:138
int32 GetFirstValidID() const
Definition MeshElementContainer.h:126
int32 NumHoles
Definition MeshElementContainer.h:237
bool IsValid(const int32 Index) const
Definition MeshElementContainer.h:132
int32 GetArraySize() const
Definition MeshElementContainer.h:123
void Reset(const int32 Elements=0)
Definition MeshElementContainer.h:54
FElementIDs GetElementIDs() const
Definition MeshElementContainer.h:227
MESHDESCRIPTION_API void Compact(TSparseArray< int32 > &OutIndexRemap)
Definition MeshElementContainer.cpp:7
FMeshElementContainer()=default
friend FArchive & operator<<(FArchive &Ar, FMeshElementContainer &Container)
Definition MeshElementContainer.h:148
FMeshElementContainer & operator=(const FMeshElementContainer &)=default
FAttributesSetBase Attributes
Definition MeshElementContainer.h:234
int32 Num() const
Definition MeshElementContainer.h:120
Definition MeshElementContainer.h:429
FMeshElementTypeWrapper & operator=(const FMeshElementTypeWrapper &Other)
Definition MeshElementContainer.h:446
FMeshElementTypeWrapper(const FMeshElementTypeWrapper &Other)
Definition MeshElementContainer.h:439
FMeshElementChannels * operator->()
Definition MeshElementContainer.h:464
const FMeshElementChannels & operator*() const
Definition MeshElementContainer.h:462
const FMeshElementChannels * operator->() const
Definition MeshElementContainer.h:461
FMeshElementChannels & operator*()
Definition MeshElementContainer.h:465
FMeshElementChannels * Get()
Definition MeshElementContainer.h:463
const FMeshElementChannels * Get() const
Definition MeshElementContainer.h:460
FMeshElementTypeWrapper(const int32 NumberOfChannels=1)
Definition MeshElementContainer.h:432
friend FArchive & operator<<(FArchive &Ar, FMeshElementTypeWrapper &Wrapper)
Definition MeshElementContainer.h:468
FMeshElementTypeWrapper & operator=(FMeshElementTypeWrapper &&)=default
FMeshElementTypeWrapper(FMeshElementTypeWrapper &&)=default
Definition Array.h:670
Definition MeshAttributeArray.h:1873
UE_FORCEINLINE_HINT int32 Num() const
Definition BitArray.h:1466
int32 Add(const bool Value)
Definition BitArray.h:615
void Empty(int32 ExpectedNumBits=0)
Definition BitArray.h:779
int32 Find(bool bValue) const
Definition BitArray.h:1084
int32 FindAndSetFirstZeroBit(int32 StartIndex=0)
Definition BitArray.h:1258
void SetNumUninitialized(int32 InNumBits)
Definition BitArray.h:849
FORCENOINLINE void SetRange(int32 Index, int32 NumBitsToSet, bool Value)
Definition BitArray.h:887
void Reserve(int32 Number)
Definition BitArray.h:800
Definition BitArray.h:1944
UE_FORCEINLINE_HINT int32 GetIndex() const
Definition BitArray.h:2011
Definition MeshElementContainer.h:307
friend bool operator==(const TConstIterator &Lhs, const TConstIterator &Rhs)
Definition MeshElementContainer.h:324
TConstIterator & operator++()
Definition MeshElementContainer.h:313
ElementIDType operator*() const
Definition MeshElementContainer.h:319
TConstIterator(TConstSetBitIterator<> &&It)
Definition MeshElementContainer.h:309
friend bool operator!=(const TConstIterator &Lhs, const TConstIterator &Rhs)
Definition MeshElementContainer.h:329
Definition MeshElementContainer.h:300
TConstIterator CreateConstIterator() const
Definition MeshElementContainer.h:338
TElementIDs(const TBitArray<> &InArray)
Definition MeshElementContainer.h:302
TConstIterator end() const
Definition MeshElementContainer.h:349
TConstIterator begin() const
Definition MeshElementContainer.h:344
Definition MeshElementContainer.h:246
ElementIDType Add()
Definition MeshElementContainer.h:249
ElementIDType GetFirstValidID() const
Definition MeshElementContainer.h:267
bool IsValid(const ElementIDType Index) const
Definition MeshElementContainer.h:273
void Remove(const ElementIDType Index)
Definition MeshElementContainer.h:261
friend FArchive & operator<<(FArchive &Ar, TMeshElementContainer &Container)
Definition MeshElementContainer.h:283
TAttributesSet< ElementIDType > & GetAttributes()
Definition MeshElementContainer.h:279
const TAttributesSet< ElementIDType > & GetAttributes() const
Definition MeshElementContainer.h:280
void Insert(const ElementIDType Index)
Definition MeshElementContainer.h:255
TElementIDs GetElementIDs() const
Definition MeshElementContainer.h:359
Definition SparseArray.h:524
Definition UniquePtr.h:107
UE_FORCEINLINE_HINT T * Get() const
Definition UniquePtr.h:324
U16 Index
Definition radfft.cpp:71