UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SurfaceIterators.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 SurfaceIterators.h: Model surface iterators.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "Engine/Level.h"
11#include "Engine/World.h"
12#include "Model.h"
13
15//
16// Level filters
17//
19
24{
25public:
26 static inline bool IsSuitable(const ULevel* Level)
27 {
28 return true;
29 }
30};
31
36{
37public:
38 static inline bool IsSuitable(const ULevel* Level)
39 {
40 return Level->IsCurrentLevel();
41 }
42};
43
44
47
49//
50// TSurfaceIteratorBase
51//
53
57template< class SurfaceFilter, class LevelFilter=DefaultSurfaceLevelFilter >
59{
60public:
63
65 {
66 check( CurrentSurface );
67 return CurrentSurface;
68 }
70 {
71 check( CurrentSurface );
72 return CurrentSurface;
73 }
74 inline explicit operator bool() const
75 {
76 return !bReachedEnd;
77 }
78
79 inline UModel* GetModel()
80 {
81 check( !bReachedEnd );
82 return World->GetLevel(LevelIndex)->Model;
83 }
84
85 inline int32 GetSurfaceIndex() const
86 {
87 check( !bReachedEnd );
88 return SurfaceIndex;
89 }
90
91 inline int32 GetLevelIndex() const
92 {
93 check( !bReachedEnd );
94 return LevelIndex;
95 }
96
97 inline UWorld* GetWorld()
98 {
99 check( !bReachedEnd );
100 return World;
101 }
102 inline ULevel* GetLevel() const
103 {
104 check( !bReachedEnd );
105 return World->GetLevel(LevelIndex);
106 }
108 {
109 CurrentSurface = NULL;
110
111 ULevel* Level = World->GetLevel(LevelIndex);
112 while ( !bReachedEnd && !CurrentSurface )
113 {
114 // Skip over unsuitable levels or levels for whom all surfaces have been visited.
115 if ( !LevelFilter::IsSuitable( Level ) || ++SurfaceIndex >= Level->Model->Surfs.Num() )
116 {
117 if ( ++LevelIndex >= World->GetNumLevels() )
118 {
119 // End of level list.
120 bReachedEnd = true;
121 LevelIndex = 0;
122 SurfaceIndex = 0;
123 CurrentSurface = NULL;
124 break;
125 }
126 else
127 {
128 // Get the next level.
129 Level = World->GetLevel(LevelIndex);
130 if ( !LevelFilter::IsSuitable( Level ) )
131 {
132 continue;
133 }
134
135 SurfaceIndex = 0;
136 // Gracefully handle levels with no surfaces.
137 if ( SurfaceIndex >= Level->Model->Surfs.Num() )
138 {
139 continue;
140 }
141 }
142 }
143 CurrentSurface = &Level->Model->Surfs[SurfaceIndex];
144 if ( !SurfaceFilterType::IsSuitable( CurrentSurface ) )
145 {
146 CurrentSurface = NULL;
147 }
148 }
149 }
150
151protected:
153 : bReachedEnd( false )
154 , World( InWorld )
155 , LevelIndex( 0 )
156 , SurfaceIndex( -1 )
157 , CurrentSurface( NULL )
158 {}
159
160private:
162 bool bReachedEnd;
163
165 UWorld* World;
166
168 int32 LevelIndex;
169
171 int32 SurfaceIndex;
172
174 FBspSurf* CurrentSurface;
175};
176
178//
179// TSurfaceIterator
180//
182
187{
188public:
189 static inline bool IsSuitable(const FBspSurf* Surface)
190 {
191 return true;
192 }
193};
194
198template< class LevelFilter=DefaultSurfaceLevelFilter >
199class TSurfaceIterator : public TSurfaceIteratorBase<FAllSurfaceFilter, LevelFilter>
200{
201public:
203
205 : Super( InWorld )
206 {
207 // Initialize members by advancing to the first valid surface.
208 ++(*this);
209 }
210};
211
213//
214// TSelectedSurfaceIterator
215//
217
222{
223public:
224 static inline bool IsSuitable(const FBspSurf* Surface)
225 {
226 return (Surface->PolyFlags & PF_Selected) ? true : false;
227 }
228};
229
233template< class LevelFilter=DefaultSurfaceLevelFilter >
234class TSelectedSurfaceIterator : public TSurfaceIteratorBase<FSelectedSurfaceFilter, LevelFilter>
235{
236public:
238
240 : Super( InWorld )
241 {
242 // Initialize members by advancing to the first valid surface.
243 ++(*this);
244 }
245};
246
#define NULL
Definition oodle2base.h:134
#define check(expr)
Definition AssertionMacros.h:314
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
@ PF_Selected
Definition Model.h:260
return true
Definition ExternalRpcRegistry.cpp:601
const bool
Definition NetworkReplayStreaming.h:178
FAllSurfaceLevelFilter DefaultSurfaceLevelFilter
Definition SurfaceIterators.h:46
Definition SurfaceIterators.h:187
static bool IsSuitable(const FBspSurf *Surface)
Definition SurfaceIterators.h:189
Definition SurfaceIterators.h:24
static bool IsSuitable(const ULevel *Level)
Definition SurfaceIterators.h:26
Definition SurfaceIterators.h:36
static bool IsSuitable(const ULevel *Level)
Definition SurfaceIterators.h:38
Definition SurfaceIterators.h:222
static bool IsSuitable(const FBspSurf *Surface)
Definition SurfaceIterators.h:224
Definition SurfaceIterators.h:235
TSelectedSurfaceIterator(UWorld *InWorld)
Definition SurfaceIterators.h:239
TSurfaceIteratorBase< FSelectedSurfaceFilter, LevelFilter > Super
Definition SurfaceIterators.h:237
Definition SurfaceIterators.h:59
int32 GetLevelIndex() const
Definition SurfaceIterators.h:91
TSurfaceIteratorBase(UWorld *InWorld)
Definition SurfaceIterators.h:152
UModel * GetModel()
Definition SurfaceIterators.h:79
int32 GetSurfaceIndex() const
Definition SurfaceIterators.h:85
UWorld * GetWorld()
Definition SurfaceIterators.h:97
ULevel * GetLevel() const
Definition SurfaceIterators.h:102
SurfaceFilter SurfaceFilterType
Definition SurfaceIterators.h:61
FBspSurf * operator*()
Definition SurfaceIterators.h:64
FBspSurf * operator->()
Definition SurfaceIterators.h:69
void operator++()
Definition SurfaceIterators.h:107
LevelFilter LevelFilterType
Definition SurfaceIterators.h:62
Definition SurfaceIterators.h:200
TSurfaceIteratorBase< FAllSurfaceFilter, LevelFilter > Super
Definition SurfaceIterators.h:202
TSurfaceIterator(UWorld *InWorld)
Definition SurfaceIterators.h:204
Definition Level.h:423
TObjectPtr< class UModel > Model
Definition Level.h:461
Definition Model.h:401
Definition World.h:918
UE_API ULevel * GetLevel(int32 InLevelIndex) const
Definition World.cpp:9093
UE_API int32 GetNumLevels() const
Definition World.cpp:9105
@ false
Definition radaudio_common.h:23
Definition Model.h:211