Agrarsense
InstancedActorRenderer.h
Go to the documentation of this file.
1// Copyright (c) 2025 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10#include "Components/InstancedStaticMeshComponent.h"
11
15#include "InstancedActor.h"
16
17#include "InstancedActorRenderer.generated.h"
18
19/*
20* AInstancedActor parameters.
21*/
22USTRUCT(Blueprintable)
23struct AGRARSENSE_API FInstancedActorParameters
24{
25 GENERATED_BODY()
26
27 UPROPERTY(EditAnywhere, BlueprintReadWrite)
28 TSubclassOf<AActor> ActorClass;
29
30 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
31 TWeakObjectPtr<UStaticMesh> Mesh;
32
33 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
34 TArray<UMaterialInterface*> Materials;
35
36 UPROPERTY(EditAnywhere, BlueprintReadWrite)
37 int32 CustomDepthStencilValue = 0;
38
39 UPROPERTY(EditAnywhere, BlueprintReadWrite)
40 bool AllowWorldPositionOffsetDisable = false;
41
42 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
43 bool IsTree = false;
44};
45
46/*
47* This Actor handles rendering each unique AInstancedActor with UInstancedStaticMeshComponent.
48*/
49UCLASS()
50class AGRARSENSE_API AInstancedActorRenderer : public AActor
51{
52 GENERATED_BODY()
53
54public:
55
56 AInstancedActorRenderer(const FObjectInitializer& ObjectInitializer);
57
58 virtual void BeginPlay() override;
59
60 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
61
62 UFUNCTION(BlueprintCallable)
63 void SetupFromInstancedActor(AInstancedActor* InstancedActor);
64
65 UFUNCTION(BlueprintCallable)
66 bool SpawnInstanceBackToActor(UInstancedStaticMeshComponent* ISM, int32 Index, bool OnlyTree);
67
68 bool Matches(UStaticMeshComponent* StaticMeshComponent, const bool CanHaveAlternativeMaterial) const;
69
70 bool Matches(UInstancedStaticMeshComponent* ISM) const;
71
72 UFUNCTION(BlueprintCallable)
73 bool SpawnInstancesBackActors();
74
75 UFUNCTION(BlueprintPure)
76 UInstancedStaticMeshComponent* GetInstancedStaticMeshComponent() const
77 {
78 return InstancedStaticMeshComponent;
79 }
80
81 UFUNCTION(BlueprintPure)
82 FInstancedActorParameters GetInstancedActorParameters() const
83 {
84 return InstancedActorParameters;
85 }
86
87 UFUNCTION(BlueprintPure)
88 UStaticMesh* GetStaticMesh() const;
89
90 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "InstancedActorRenderer")
91 UInstancedStaticMeshComponent* InstancedStaticMeshComponent = nullptr;
92
93protected:
94
95 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "InstancedActorRenderer")
96 FInstancedActorParameters InstancedActorParameters;
97
102 UFUNCTION(BlueprintCallable, Category = "InstancedActorRenderer")
103 void SetWorldPositionOffsetDistance(int32 NewWPODistance);
104
109 UFUNCTION(BlueprintCallable, Category = "InstancedActorRenderer")
110 void SetShadowCacheBehaviour(EShadowCacheInvalidationBehavior ShadowCacheInvalidationBehaviour);
111
116 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
117 void SetRenderWorldPositionOffet(bool RenderWPO);
118
119private:
120
121 UFUNCTION()
122 void OnGraphicsSettingsChanged(FGlobalGraphicsSettings GraphicsSettings);
123
124 UFUNCTION()
125 void OnWeatherParametersChanged(FWeatherParameters WeatherParameters);
126
127 FWeatherParameters CurrentWeatherParameters;
128
132 int32 WorldPositionOffsetDistance = 30000;
133
134 bool Rendering = true;
135
136 bool RenderingWPO = false;
137
138};