UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Model.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 Model.h: Unreal UModel definition.
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
13#include "UObject/Object.h"
14#include "Misc/Guid.h"
15#include "Engine/EngineTypes.h"
16#include "RenderCommandFence.h"
17#include "RenderResource.h"
18#include "PackedNormal.h"
20#include "RawIndexBuffer.h"
21#include "LocalVertexFactory.h"
22#include "Templates/UniquePtr.h"
23#include "StaticMeshResources.h"
24
25#include "Model.generated.h"
26
27class AActor;
28class ABrush;
29class FBlake3;
31class ULevel;
32class ULightComponent;
34class UModel;
35class UModelComponent;
36class UPolys;
38
39//
40// One vertex associated with a Bsp node's polygon. Contains a vertex index
41// into the level's FPoints table, and a unique number which is common to all
42// other sides in the level which are cospatial with this side.
43//
44class FVert
45{
46public:
47 // Variables.
48 int32 pVertex; // Index of vertex.
49 int32 iSide; // If shared, index of unique side. Otherwise INDEX_NONE.
50
53
56
57 // Functions.
58 friend FArchive& operator<< (FArchive &Ar, FVert &Vert)
59 {
60 // @warning BulkSerialize: FVert is serialized as memory dump
61 // See TArray::BulkSerialize for detailed description of implied limitations.
62 Ar << Vert.pVertex << Vert.iSide;
63 Ar << Vert.ShadowTexCoord;
64 Ar << Vert.BackfaceShadowTexCoord;
65 return Ar;
66 }
67};
68
69//
70// FBspNode
71//
72
73// Flags associated with a Bsp node.
75{
76 // Flags.
77 NF_NotCsg = 0x01, // Node is not a Csg splitter, i.e. is a transparent poly.
78 NF_NotVisBlocking = 0x04, // Node does not block visibility, i.e. is an invisible collision hull.
79 NF_BrightCorners = 0x10, // Temporary.
80 NF_IsNew = 0x20, // Editor: Node was newly-added.
81 NF_IsFront = 0x40, // Filter operation bounding-sphere precomputed and guaranteed to be front.
82 NF_IsBack = 0x80, // Guaranteed back.
83};
84
85//
86// FBspNode defines one node in the Bsp, including the front and back
87// pointers and the polygon data itself. A node may have 0 or 3 to (MAX_NODE_VERTICES-1)
88// vertices. If the node has zero vertices, it's only used for splitting and
89// doesn't contain a polygon (this happens in the editor).
90//
91// vNormal, vTextureU, vTextureV, and others are indices into the level's
92// vector table. iFront,iBack should be INDEX_NONE to indicate no children.
93//
94// If iPlane==INDEX_NONE, a node has no coplanars. Otherwise iPlane
95// is an index to a coplanar polygon in the Bsp. All polygons that are iPlane
96// children can only have iPlane children themselves, not fronts or backs.
97//
98struct FBspNode // 62 bytes
99{
100 enum {MAX_NODE_VERTICES=255}; // Max vertices in a Bsp node.
101 enum {MAX_ZONES=64}; // Max zones per level.
102
103 // Persistent information.
104 FPlane4f Plane; // 16 Plane the node falls into (X, Y, Z, W).
105 int32 iVertPool; // 4 Index of first vertex in vertex pool, =iTerrain if NumVertices==0 and NF_TerrainFront.
106 int32 iSurf; // 4 Index to surface information.
107
110
113
116
119
120 // iBack: 4 Index to node in front (in direction of Normal).
121 // iFront: 4 Index to node in back (opposite direction as Normal).
122 // iPlane: 4 Index to next coplanar poly in coplanar list.
123 union { int32 iBack; int32 iChild[1]; };
126
127 int32 iCollisionBound;// 4 Collision bound.
128
129 uint8 iZone[2]; // 2 Visibility zone in 1=front, 0=back.
130 uint8 NumVertices; // 1 Number of vertices in node.
131 uint8 NodeFlags; // 1 Node flags.
132 int32 iLeaf[2]; // 8 Leaf in back and front, INDEX_NONE=not a leaf.
133
134 // Functions.
135 bool IsCsg( uint32 ExtraFlags=0 ) const
136 {
137 return (NumVertices>0) && !(NodeFlags & (NF_IsNew | NF_NotCsg | ExtraFlags));
138 }
139 bool ChildOutside( int32 IniChild, bool Outside, uint32 ExtraFlags=0 ) const
140 {
141 return IniChild ? (Outside || IsCsg(ExtraFlags)) : (Outside && !IsCsg(ExtraFlags));
142 }
144};
145
146//
147// FZoneProperties
148//
149
151{
152 FZoneSet(): MaskBits(0) {}
154
156 {
157 return Ar << S.MaskBits;
158 }
159
160private:
161
162 uint64 MaskBits;
163};
164
165
167{
168public:
169 // Variables.
170 class AActor* ZoneActor; // Optional actor defining the zone's property. @todo UE4 obsolete/unused - remove.
171 float LastRenderTime; // Most recent level TimeSeconds when rendered.
172 FZoneSet Connectivity; // (Connect[i]&(1<<j))==1 if zone i is adjacent to zone j.
173 FZoneSet Visibility; // (Connect[i]&(1<<j))==1 if zone i can see zone j.
174};
175
176//
177// FLeaf
178//
179
180struct FLeaf
181{
182 int32 iZone; // The zone this convex volume is in.
183
184 // Functions.
186 {}
191 {
192 // @warning BulkSerialize: FLeaf is serialized as memory dump
193 // See TArray::BulkSerialize for detailed description of implied limitations.
194 Ar << L.iZone;
195 return Ar;
196 }
197};
198
199//
200// FBspSurf
201//
202
203//
204// One Bsp polygon. Lists all of the properties associated with the
205// polygon's plane. Does not include a point list; the actual points
206// are stored along with Bsp nodes, since several nodes which lie in the
207// same plane may reference the same poly.
208//
209USTRUCT()
211{
213
214 UPROPERTY()
216 uint32 PolyFlags; // 4 Polygon flags.
217 int32 pBase; // 4 Polygon & texture base point index (where U,V==0,0).
218 int32 vNormal; // 4 Index to polygon normal.
219 int32 vTextureU; // 4 Texture U-vector index.
220 int32 vTextureV; // 4 Texture V-vector index.
221 int32 iBrushPoly; // 4 Editor brush polygon index.
222 UPROPERTY()
223 TObjectPtr<ABrush> Actor; // 4 Brush actor owning this Bsp surface.
224 FPlane4f Plane; // 16 The plane this surface lies on.
225 float LightMapScale; // 4 The number of units/lightmap texel on this surface.
226 int32 iLightmassIndex;// 4 Index to the lightmass settings
227
228 bool bHiddenEdTemporary; // 1 Marks whether this surface is temporarily hidden in the editor or not. Not serialized.
229 bool bHiddenEdLevel; // 1 Marks whether this surface is hidden by the level browser or not. Not serialized.
230 bool bHiddenEdLayer; // 1 Marks whether this surface is hidden by the layer browser or not. Not serialized.
231 // Functions.
232
233
234#if WITH_EDITOR
236 ENGINE_API bool IsHiddenEd() const;
237
239 ENGINE_API bool IsHiddenEdAtStartup() const;
240#endif
241
243
244 void AddReferencedObjects( FReferenceCollector& Collector );
245};
246
247// Flags describing effects and properties of a Bsp polygon.
249{
250 // Regular in-game flags.
251 PF_Invisible = 0x00000001, // Poly is invisible.
252 PF_NotSolid = 0x00000008, // Poly is not solid, doesn't block.
253 PF_Semisolid = 0x00000020, // Poly is semi-solid = collision solid, Csg nonsolid.
254 PF_GeomMarked = 0x00000040, // Geometry mode sometimes needs to mark polys for processing later.
255 PF_TwoSided = 0x00000100, // Poly is visible from both sides.
256 PF_Portal = 0x04000000, // Portal between iZones.
257
258 // Editor flags.
259 PF_Memorized = 0x01000000, // Editor: Poly is remembered.
260 PF_Selected = 0x02000000, // Editor: Poly is selected.
261 PF_HiddenEd = 0x08000000, // Editor: Poly is hidden in the editor at startup.
262 PF_Hovered = 0x10000000, // Editor: Poly is currently hovered over in editor.
263
264 // Internal.
265 PF_EdProcessed = 0x40000000, // FPoly was already processed in editorBuildFPolys.
266 PF_EdCut = 0x80000000, // FPoly has been split by SplitPolyWithPlane.
267
268 // Combinations of flags.
274
276};
277
302
303
325
330{
331public:
332 // Number of FModelSceneProxy's using this
333 // Only access in CreateRenderState_Concurrent and DestroyRenderState_Concurrent
335
338
341
344
351#if WITH_EDITOR
352 friend void UpdateHash(FBlake3& Builder, const FModelVertexBuffer& B);
353#endif
354
355private:
356 UModel* Model;
357 uint32 NumVerticesRHI;
358};
359
392
393//
394// UModel
395//
396
397enum {MAX_NODES = 65536};
398enum {MAX_POINTS = 128000};
399UCLASS(MinimalAPI)
401{
403public:
404 UModel(FVTableHelper& Helper);
405
406#if WITH_EDITORONLY_DATA
407 // Arrays and subobjects.
408 UPROPERTY(SkipSerialization)
409 TObjectPtr<UPolys> Polys;
410#endif // WITH_EDITOR
411
416
417 UPROPERTY(SkipSerialization)
419
420#if WITH_EDITOR
422 TArray<FLeaf> Leaves;
423#endif // WITH_EDITOR
424
426
429
432
435
438
441
444
447
450
451#if WITH_EDITOR
454
457
460
463
468
471#endif // WITH_EDITOR
472
473 // Other variables.
475 bool Linked;
478private:
479 ENGINE_API static float BSPTexelScale;
480public:
481
482 // Constructors.
484 ENGINE_API void Initialize();
485 ENGINE_API void Initialize(ABrush* Owner, bool InRootOutside = true);
486
487 // UObject interface.
488 virtual void Serialize( FArchive& Ar ) override;
489 virtual void PostLoad() override;
490 virtual void PreSave(FObjectPreSaveContext SaveContext) override;
491#if WITH_EDITOR
492 virtual void PostEditUndo() override;
493 virtual bool Modify(bool bAlwaysMarkDirty = true) override;
494#endif // WITH_EDITOR
495 virtual bool Rename( const TCHAR* InName=NULL, UObject* NewOuter=NULL, ERenameFlags Flags=REN_None ) override;
496 static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
497
501 static float GetGlobalBSPTexelScale() { return BSPTexelScale; }
502
508 static void SetGlobalBSPTexelScale( float InBSPTexelScale ) { BSPTexelScale = InBSPTexelScale; }
509
514 virtual void PostDuplicate(bool bDuplicateForPIE) override;
515 virtual void BeginDestroy() override;
516 virtual bool IsReadyForFinishDestroy() override;
517
518 virtual bool IsAsset() const override { return false; }
519
523 virtual void GetResourceSizeEx(FResourceSizeEx& CumulativeResourceSize) override;
524
525 // UModel interface.
526 ENGINE_API void EmptyModel( int32 EmptySurfInfo, int32 EmptyPolys );
527
529 ENGINE_API void BeginReleaseResources();
530
532 ENGINE_API void UpdateVertices();
533
535 FVector GetCenter();
536
537 ENGINE_API void GetSurfacePlanes(
538 const AActor* Owner,
540
541#if WITH_EDITOR
543 ENGINE_API void BuildBound();
544
546 void Transform( ABrush* Owner );
547
549 ENGINE_API void ShrinkModel();
550
556
557 // UModel transactions.
559 void ModifyAllSurfs( bool UpdateBrushes );
561 ENGINE_API bool HasSelectedSurfaces() const;
562#endif
563
564 ENGINE_API float FindNearestVertex
565 (
566 const FVector3f &SourcePoint,
568 float MinRadius,
569 int32 &pVertex
570 ) const;
571 void PrecomputeSphereFilter
572 (
573 const FPlane &Sphere
574 );
575
576 /* Find the source brush actor associated with this point, or NULL if the point does not lie on a BSP surface. */
577 ENGINE_API ABrush* FindBrush(const FVector3f &SourcePoint) const;
578
585 ENGINE_API void GetNodeBoundingBox( const FBspNode& Node, FBox& OutBox ) const;
586
593 ENGINE_API void GroupAllNodes(ULevel* Level, const TArray<class ULightComponentBase*>& Lights);
594
598 void ApplyStaticLighting(const FStaticLightingBuildContext* LightingContext);
599
603 void ApplyWorldOffset(const FVector& InOffset, bool bWorldShift);
604
608 ENGINE_API void ClearLocalMaterialIndexBuffersData();
609
611
612 friend class UWorld;
613 friend class UBrushComponent;
614 friend class UStaticMeshComponent;
615 friend class AActor;
616 friend class AVolume;
617
618private:
619 FGuid ConstructLightingGuid() const;
620};
621
#define NULL
Definition oodle2base.h:134
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ MAX_POINTS
Definition Model.h:398
EBspNodeFlags
Definition Model.h:75
@ NF_IsBack
Definition Model.h:82
@ NF_NotCsg
Definition Model.h:77
@ NF_BrightCorners
Definition Model.h:79
@ NF_NotVisBlocking
Definition Model.h:78
@ NF_IsNew
Definition Model.h:80
@ NF_IsFront
Definition Model.h:81
@ MAX_NODES
Definition Model.h:397
EPolyFlags
Definition Model.h:249
@ PF_ModelComponentMask
Definition Model.h:273
@ PF_DefaultFlags
Definition Model.h:275
@ PF_NoImport
Definition Model.h:270
@ PF_EdProcessed
Definition Model.h:265
@ PF_TwoSided
Definition Model.h:255
@ PF_Semisolid
Definition Model.h:253
@ PF_AddLast
Definition Model.h:271
@ PF_Portal
Definition Model.h:256
@ PF_EdCut
Definition Model.h:266
@ PF_Memorized
Definition Model.h:259
@ PF_NoAddToBSP
Definition Model.h:272
@ PF_Invisible
Definition Model.h:251
@ PF_HiddenEd
Definition Model.h:261
@ PF_Selected
Definition Model.h:260
@ PF_GeomMarked
Definition Model.h:254
@ PF_Hovered
Definition Model.h:262
@ PF_NoEdit
Definition Model.h:269
@ PF_NotSolid
Definition Model.h:252
FArchive & operator<<(FArchive &Ar, FEnvQueryDebugProfileData::FStep &Data)
Definition EnvQueryTypes.cpp:489
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
uint32 ERenameFlags
Definition ObjectMacros.h:2302
#define REN_None
Definition ObjectMacros.h:2305
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition Volume.h:18
Definition Archive.h:1208
Definition Blake3.h:94
Definition PackedNormal.h:66
Definition MapBuildDataRegistry.h:56
Definition Model.h:626
FMeshMapBuildData * LegacyMapBuildData
Definition Model.h:638
TArray< uint16 > Nodes
Definition Model.h:636
ENGINE_API FModelElement()
Definition ModelComponent.cpp:39
FRawIndexBuffer16or32 * IndexBuffer
Definition Model.h:644
virtual ENGINE_API ~FModelElement()
Definition ModelComponent.cpp:52
uint32 FirstIndex
Definition Model.h:647
friend FArchive & operator<<(FArchive &Ar, FModelElement &Element)
Definition ModelComponent.cpp:74
uint32 MaxVertexIndex
Definition Model.h:656
ENGINE_API const FMeshMapBuildData * GetMeshMapBuildData() const
Definition ModelComponent.cpp:55
TObjectPtr< class UModelComponent > Component
Definition Model.h:630
FBox BoundingBox
Definition Model.h:659
TObjectPtr< class UMaterialInterface > Material
Definition Model.h:633
uint32 MinVertexIndex
Definition Model.h:653
FGuid MapBuildDataId
Definition Model.h:641
uint32 NumTriangles
Definition Model.h:650
Definition Model.h:330
FStaticMeshVertexBuffers Buffers
Definition Model.h:340
TArray< FModelVertex > Vertices
Definition Model.h:337
friend FArchive & operator<<(FArchive &Ar, FModelVertexBuffer &B)
Definition ModelRender.cpp:59
uint32 RefCount
Definition Model.h:334
Definition UObjectGlobals.h:1292
static COREUOBJECT_API FObjectInitializer & Get()
Definition UObjectGlobals.cpp:5001
Definition ObjectSaveContext.h:244
Definition RawIndexBuffer.h:36
Definition UObjectGlobals.h:2492
Definition RenderCommandFence.h:15
Definition ObjectMacros.h:180
Definition Model.h:45
FVector2f BackfaceShadowTexCoord
Definition Model.h:55
int32 iSide
Definition Model.h:49
FVector2f ShadowTexCoord
Definition Model.h:52
friend FArchive & operator<<(FArchive &Ar, FVert &Vert)
Definition Model.h:58
int32 pVertex
Definition Model.h:48
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition Level.h:423
Definition MaterialInterface.h:296
Definition ModelComponent.h:34
Definition Model.h:401
FBoxSphereBounds Bounds
Definition Model.h:477
static float GetGlobalBSPTexelScale()
Definition Model.h:501
uint32 NumUniqueVertices
Definition Model.h:446
FGuid LightingGuid
Definition Model.h:449
TArray< FVector3f > Points
Definition Model.h:415
bool RootOutside
Definition Model.h:474
TArray< FBspNode > Nodes
Definition Model.h:412
TArray< FLightmassPrimitiveSettings > LightmassSettings
Definition Model.h:425
bool InvalidSurfaces
Definition Model.h:437
static void SetGlobalBSPTexelScale(float InBSPTexelScale)
Definition Model.h:508
void ApplyWorldOffset(const FVector &InOffset, bool bWorldShift)
FModelVertexBuffer VertexBuffer
Definition Model.h:431
void CalculateUniqueVertCount()
TArray< FVert > Verts
Definition Model.h:413
TArray< FVector3f > Vectors
Definition Model.h:414
bool Linked
Definition Model.h:475
int32 NumSharedSides
Definition Model.h:476
bool bInvalidForStaticLighting
Definition Model.h:443
bool bOnlyRebuildMaterialIndexBuffers
Definition Model.h:440
TMap< UMaterialInterface *, TUniquePtr< FRawIndexBuffer16or32 > > MaterialIndexBuffers
Definition Model.h:428
virtual bool IsAsset() const override
Definition Model.h:518
FRenderCommandFence ReleaseResourcesFence
Definition Model.h:434
Definition Object.h:95
Definition Polys.h:413
Definition World.h:918
Definition Model.h:99
int32 iPlane
Definition Model.h:125
int32 iVertPool
Definition Model.h:105
@ MAX_ZONES
Definition Model.h:101
int32 iBack
Definition Model.h:123
uint8 NodeFlags
Definition Model.h:131
int32 iCollisionBound
Definition Model.h:127
int32 iVertexIndex
Definition Model.h:109
@ MAX_NODE_VERTICES
Definition Model.h:100
int32 iLeaf[2]
Definition Model.h:132
uint8 iZone[2]
Definition Model.h:129
bool IsCsg(uint32 ExtraFlags=0) const
Definition Model.h:135
uint16 ComponentIndex
Definition Model.h:112
int32 iFront
Definition Model.h:124
FPlane4f Plane
Definition Model.h:104
int32 iSurf
Definition Model.h:106
int32 ComponentElementIndex
Definition Model.h:118
bool ChildOutside(int32 IniChild, bool Outside, uint32 ExtraFlags=0) const
Definition Model.h:139
int32 iChild[1]
Definition Model.h:123
uint16 ComponentNodeIndex
Definition Model.h:115
uint8 NumVertices
Definition Model.h:130
friend ENGINE_API FArchive & operator<<(FArchive &Ar, FBspNode &N)
Definition Model.cpp:146
Definition Model.h:211
Definition Model.h:305
FVector2f TexCoord
Definition Model.h:309
friend FArchive & operator<<(FArchive &Ar, FDepecatedModelVertex &V)
Definition Model.cpp:220
FDeprecatedSerializedPackedNormal TangentX
Definition Model.h:307
FVector2f ShadowTexCoord
Definition Model.h:310
FDeprecatedSerializedPackedNormal TangentZ
Definition Model.h:308
FVector3f Position
Definition Model.h:306
Definition Guid.h:109
Definition Model.h:181
FLeaf(int32 iInZone)
Definition Model.h:187
friend FArchive & operator<<(FArchive &Ar, FLeaf &L)
Definition Model.h:190
FLeaf()
Definition Model.h:185
int32 iZone
Definition Model.h:182
Definition Model.h:279
FVector3f Position
Definition Model.h:280
FVector4f TangentZ
Definition Model.h:282
FVector3f GetTangentY() const
Definition Model.h:286
friend FArchive & operator<<(FArchive &Ar, FModelVertex &V)
Definition Model.cpp:196
FVector2f ShadowTexCoord
Definition Model.h:284
FVector2f TexCoord
Definition Model.h:283
FVector3f TangentX
Definition Model.h:281
Definition Model.h:362
FMatrix MapToWorld
Definition Model.h:375
FVector3f TangentY
Definition Model.h:372
TArray< FStaticLightingVertex > Vertices
Definition Model.h:384
TArray< ULightComponent * > RelevantLights
Definition Model.h:369
FVector3f TangentX
Definition Model.h:371
FVector3f TangentZ
Definition Model.h:373
int32 SizeY
Definition Model.h:381
TArray< int32 > TriangleSurfaceMap
Definition Model.h:390
int32 SizeX
Definition Model.h:380
TArray< int32 > TriangleVertexIndices
Definition Model.h:387
FBox BoundingBox
Definition Model.h:378
ENGINE_API ~FNodeGroup()
FMatrix WorldToMap
Definition Model.h:376
TArray< int32 > Nodes
Definition Model.h:366
Definition ResourceSize.h:31
Definition StaticLighting.h:23
Definition StaticMeshResources.h:320
Definition Model.h:167
class AActor * ZoneActor
Definition Model.h:170
float LastRenderTime
Definition Model.h:171
FZoneSet Connectivity
Definition Model.h:172
FZoneSet Visibility
Definition Model.h:173
Definition Model.h:151
FZoneSet()
Definition Model.h:152
friend FArchive & operator<<(FArchive &Ar, FZoneSet &S)
Definition Model.h:155
FZoneSet(uint64 InMaskBits)
Definition Model.h:153
Definition ObjectPtr.h:488
Definition BoxSphereBounds.h:25
T W
Definition Vector4.h:52