-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProceduralMeshGeneratorSubsystem.h
More file actions
53 lines (47 loc) · 1.35 KB
/
Copy pathProceduralMeshGeneratorSubsystem.h
File metadata and controls
53 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include "CoreMinimal.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "PTG/Generation/Terrain/ChunkData.h"
#include "ProceduralMeshGeneratorSubsystem.generated.h"
//////// CLASS ////////
/// System managing the generation and update of procedural meshes
UCLASS()
class PTG_API UProceduralMeshGeneratorSubsystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
//////// UNREAL LIFECYCLE ////////
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
//////// FIELDS ////////
/// Grid node structure
struct FSquareIndices
{
int32 bottomLeft;
int32 bottomRight;
int32 topLeft;
int32 topRight;
};
//////// METHODS ////////
/// Mesh generation
UFUNCTION()
void CreateChunkMesh(UProceduralMeshComponent* ProceduralMesh, const FChunk& Chunk, int32 SectionIndex = 0);
/// Helpers
/**
* @brief Utility function to calculate indices for a grid square
* @param x X coordinate in the grid
* @param y Y coordinate in the grid
* @param gridSize Size of the complete grid
* @return FSquareIndices Structure containing vertex indices for the square
*/
FORCEINLINE FSquareIndices GetSquareIndices(int32 x, int32 y, int32 gridSize)
{
return
{
x + y * gridSize,
(x + 1) + y * gridSize,
x + (y + 1) * gridSize,
(x + 1) + (y + 1) * gridSize
};
}
};