Agrarsense
|
#include <InstancedRenderer.h>
Public Member Functions | |
AInstancedRenderer (const FObjectInitializer &ObjectInitializer) | |
bool | AddActorToInstancedRendering (AInstancedActor *InstancedActor) |
void | RemoveInstance (int32 ComponentIndex, int32 InstanceNumber) |
void | UpdateInstanceTransform (int32 ComponentIndex, int32 InstanceNumber, const FTransform &NewTransform) |
bool | IsRendering () const |
int32 | GetTotalInstanceCount () const |
int32 | GetUniqueInstancesCount () const |
TArray< FInstanceEntry > | GetInstanceEntries () const |
void | SetInstancedRendering (bool ShouldRender) |
void | SetComponentIndexVisibility (int32 Index, bool Visible) |
void | SetRenderCustomDepth (bool Enabled) |
void | SetWorldPositionOffsetDistance (int32 NewWPODistance) |
void | SetShadowCacheBehaviour (EShadowCacheInvalidationBehavior ShadowCacheInvalidationBehaviour) |
void | SetRenderWorldPositionOffet (bool RenderWPO) |
void | LogInfo () const |
void | DebugMaterialImpact (bool SetUnrealDefaultMaterial) |
void | ToggleProxyMesh () |
void | SpawnAllInstancesBackActors () |
void | UpdateRenderDistances () |
void | DestroyOverlappingInstancesBox (UInstancedStaticMeshComponent *ISM, FBox AreaBox, bool OnlyTrees) |
bool | SpawnInstanceBackToActor (UInstancedStaticMeshComponent *ISM, int32 Index, bool OnlyTree) |
Static Public Member Functions | |
static AInstancedRenderer * | Get () |
Protected Attributes | |
TArray< FInstanceEntry > | InstanceEntries |
TArray< UInstancedStaticMeshComponent * > | InstancesStaticMeshComponents |
int32 | TotalInstanceCount = 0 |
Private Member Functions | |
virtual void | BeginPlay () override |
virtual void | EndPlay (const EEndPlayReason::Type EndPlayReason) override |
void | OnGraphicsSettingsChanged (FGlobalGraphicsSettings GraphicsSettings) |
void | OnWeatherParametersChanged (FWeatherParameters WeatherParameters) |
bool | FindOrAddUniqueMesh (UStaticMeshComponent *StaticMeshComponent, AInstancedActor *InstancedActor, int32 &InstanceNum) |
Private Attributes | |
TWeakObjectPtr< UStaticMesh > | CubeMesh |
int32 | WorldPositionOffsetDistance = 30000 |
FWeatherParameters | CurrentWeatherParameters |
bool | Rendering = true |
bool | RenderingWPO = false |
Static Private Attributes | |
static AInstancedRenderer * | Instance = nullptr |
This Actor is responsible for managing all Instanced Static Mesh Components in the level.
The way this works is by creating blueprint based on AInstancedActor in Unreal Editor, setup the desired mesh and material in the blueprint and placing them in the level in any way. Then at runtime (AInstancedActor BeginPlay), its Mesh and Material is added to this Renderer.
Or you can setup AInstancedActor based actors in your level and then go to BP_InstancedRenderer Actor and click "AddExistingActorsToRenderer" button to turn AInstancedActors into BP_InstancedRenderer ISM instances in Editor. This reduces the amount of Actors in the level and should speed up loading and Editor play times.
AInstancedActors marked as "TreeActor" can be turned back into regular Actor at runtime when vehicle gets close.
Note. Mesh material(s) need to have bUsedWithInstancedStaticMeshes set to True to work with UInstancedStaticMeshComponent.
Definition at line 76 of file InstancedRenderer.h.
AInstancedRenderer::AInstancedRenderer | ( | const FObjectInitializer & | ObjectInitializer | ) |
Definition at line 22 of file InstancedRenderer.cpp.
References CubeMesh.
bool AInstancedRenderer::AddActorToInstancedRendering | ( | AInstancedActor * | InstancedActor | ) |
Definition at line 138 of file InstancedRenderer.cpp.
References FindOrAddUniqueMesh(), AInstancedActor::GetStaticMeshComponent(), AInstancedActor::InstanceAdded(), InstanceEntries, TotalInstanceCount, and AInstancedActor::UpdateTransformAutomatically().
Referenced by AInstancedActor::AddToInstancedRendering().
|
overrideprivatevirtual |
Definition at line 37 of file InstancedRenderer.cpp.
References CurrentWeatherParameters, Destroy, UAgrarsenseStatics::GetAgrarsenseSettings(), AWeather::GetCurrentWeather(), UAgrarsenseStatics::GetWeatherActor(), UAgrarsenseSettings::GetWorldPositionOffsetRenderDistance(), Instance, InstanceEntries, LogInfo(), OnGraphicsSettingsChanged(), UAgrarsenseSettings::OnGraphicsSettingsChanged, AWeather::OnWeatherChanged, OnWeatherParametersChanged(), ToggleProxyMesh(), and WorldPositionOffsetDistance.
void AInstancedRenderer::DebugMaterialImpact | ( | bool | SetUnrealDefaultMaterial | ) |
Definition at line 534 of file InstancedRenderer.cpp.
References InstanceEntries.
void AInstancedRenderer::DestroyOverlappingInstancesBox | ( | UInstancedStaticMeshComponent * | ISM, |
FBox | AreaBox, | ||
bool | OnlyTrees | ||
) |
Destroys all instances overlapping the specified Box area.
ISM | - The instanced static mesh component. |
AreaBox | - The bounding box defining the area to check. |
OnlyTrees | - Whether to limit destruction to tree instances only. |
Definition at line 738 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, and FInstanceEntry::IsTree.
Referenced by ADeletionVolume::DestroyOverlappingActors().
|
overrideprivatevirtual |
Definition at line 92 of file InstancedRenderer.cpp.
References UAgrarsenseStatics::GetAgrarsenseSettings(), UAgrarsenseStatics::GetWeatherActor(), Instance, InstanceEntries, OnGraphicsSettingsChanged(), UAgrarsenseSettings::OnGraphicsSettingsChanged, AWeather::OnWeatherChanged, and OnWeatherParametersChanged().
|
private |
Definition at line 211 of file InstancedRenderer.cpp.
References FInstanceEntry::ActorClass, FInstanceEntry::AllowWorldPositionOffsetDisable, CurrentWeatherParameters, FInstanceEntry::CustomDepthStencilValue, AInstancedActor::GetAllowWorldPositionOffsetDisable(), AInstancedActor::GetInstanceEndCullDistance(), AInstancedActor::GetInstanceStartCullDistance(), AInstancedActor::HasAlternativeMaterial(), FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, FInstanceEntry::InstanceEntryIndex, FInstanceEntry::IsTree, AInstancedActor::IsTreeActor(), FInstanceEntry::Materials, FInstanceEntry::Mesh, FWeatherParameters::WindIntensity, and WorldPositionOffsetDistance.
Referenced by AddActorToInstancedRendering().
|
inlinestatic |
Definition at line 239 of file InstancedRenderer.h.
|
inline |
Definition at line 141 of file InstancedRenderer.h.
|
inline |
Definition at line 121 of file InstancedRenderer.h.
|
inline |
Definition at line 131 of file InstancedRenderer.h.
|
inline |
Definition at line 111 of file InstancedRenderer.h.
void AInstancedRenderer::LogInfo | ( | ) | const |
Definition at line 85 of file InstancedRenderer.cpp.
References InstanceEntries, and TotalInstanceCount.
Referenced by BeginPlay().
|
private |
Definition at line 460 of file InstancedRenderer.cpp.
References FGlobalGraphicsSettings::FoliageShadowCacheInvalidationBehaviour, SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), and FGlobalGraphicsSettings::WorldPositionOffsetDistance.
Referenced by BeginPlay(), and EndPlay().
|
private |
Definition at line 466 of file InstancedRenderer.cpp.
References CurrentWeatherParameters, FWeatherParameters::IsWinterSeason(), RenderingWPO, SetRenderWorldPositionOffet(), and FWeatherParameters::WindIntensity.
Referenced by BeginPlay(), and EndPlay().
void AInstancedRenderer::RemoveInstance | ( | int32 | ComponentIndex, |
int32 | InstanceNumber | ||
) |
Definition at line 406 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, and TotalInstanceCount.
Referenced by AInstancedActor::RemoveFromInstancedRendering().
void AInstancedRenderer::SetComponentIndexVisibility | ( | int32 | Index, |
bool | Visible | ||
) |
Set the visibility of a specific UInstancedStaticMeshComponent at the given index. Debugging purposes.
Index | The index of the UInstancedStaticMeshComponent to modify. |
Visible | Whether to make the component visible (true) or hidden (false). |
Definition at line 442 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
void AInstancedRenderer::SetInstancedRendering | ( | bool | ShouldRender | ) |
Definition at line 426 of file InstancedRenderer.cpp.
References InstanceEntries, and Rendering.
Referenced by UAgrarsenseSettings::SetInstancedRenderingVisibility().
void AInstancedRenderer::SetRenderCustomDepth | ( | bool | Enabled | ) |
Sets whether the custom depth rendering is enabled or disabled.
Enabled | True to enable custom depth rendering, false to disable. |
Definition at line 482 of file InstancedRenderer.cpp.
References InstanceEntries.
void AInstancedRenderer::SetRenderWorldPositionOffet | ( | bool | RenderWPO | ) |
Sets whether the World Position Offset (WPO) rendering is enabled or disabled.
RenderWPO | True to enable World Position Offset rendering, false to disable. |
Definition at line 522 of file InstancedRenderer.cpp.
References InstanceEntries.
Referenced by OnWeatherParametersChanged().
void AInstancedRenderer::SetShadowCacheBehaviour | ( | EShadowCacheInvalidationBehavior | ShadowCacheInvalidationBehaviour | ) |
Sets the behavior for shadow cache invalidation. Default Rigid.
ShadowCacheInvalidationBehaviour | The new behavior for shadow cache invalidation. |
Definition at line 511 of file InstancedRenderer.cpp.
References InstanceEntries.
Referenced by OnGraphicsSettingsChanged().
void AInstancedRenderer::SetWorldPositionOffsetDistance | ( | int32 | NewWPODistance | ) |
Sets the distance for the World Position Offset (WPO) effect.
NewWPODistance | The new distance for the World Position Offset. |
Definition at line 493 of file InstancedRenderer.cpp.
References InstanceEntries, and WorldPositionOffsetDistance.
Referenced by OnGraphicsSettingsChanged().
void AInstancedRenderer::SpawnAllInstancesBackActors | ( | ) |
Definition at line 597 of file InstancedRenderer.cpp.
References InstanceEntries, and Transform.
bool AInstancedRenderer::SpawnInstanceBackToActor | ( | UInstancedStaticMeshComponent * | ISM, |
int32 | Index, | ||
bool | OnlyTree | ||
) |
Spawns a specific ISM instance back to its original Actor. Cannot be added back to ISM instance afterwards.
ISM | The instanced static mesh component containing the instance. |
Index | The index of the instance to spawn back. |
Definition at line 685 of file InstancedRenderer.cpp.
References FInstanceEntry::ActorClass, AInstancedActor::AddToInstancedRenderer, FInstanceEntry::InstancedStaticMeshComponent, InstanceEntries, and FInstanceEntry::IsTree.
void AInstancedRenderer::ToggleProxyMesh | ( | ) |
Definition at line 573 of file InstancedRenderer.cpp.
References CubeMesh, and InstanceEntries.
Referenced by BeginPlay().
void AInstancedRenderer::UpdateInstanceTransform | ( | int32 | ComponentIndex, |
int32 | InstanceNumber, | ||
const FTransform & | NewTransform | ||
) |
Definition at line 391 of file InstancedRenderer.cpp.
References FInstanceEntry::InstancedStaticMeshComponent, and InstanceEntries.
Referenced by AInstancedActor::UpdateTransformPosition().
void AInstancedRenderer::UpdateRenderDistances | ( | ) |
Definition at line 645 of file InstancedRenderer.cpp.
References AInstancedActor::GetInstanceEndCullDistance(), AInstancedActor::GetInstanceStartCullDistance(), InstanceEntries, and Transform.
|
private |
Definition at line 261 of file InstancedRenderer.h.
Referenced by AInstancedRenderer(), and ToggleProxyMesh().
|
private |
Definition at line 286 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and OnWeatherParametersChanged().
|
staticprivate |
Definition at line 263 of file InstancedRenderer.h.
Referenced by BeginPlay(), and EndPlay().
|
protected |
Array containing instance entries for each unique mesh and material combination. Each entry represents an instance of a mesh with associated actors and properties.
Definition at line 251 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), BeginPlay(), DebugMaterialImpact(), DestroyOverlappingInstancesBox(), EndPlay(), FindOrAddUniqueMesh(), LogInfo(), RemoveInstance(), SetComponentIndexVisibility(), SetInstancedRendering(), SetRenderCustomDepth(), SetRenderWorldPositionOffet(), SetShadowCacheBehaviour(), SetWorldPositionOffsetDistance(), SpawnAllInstancesBackActors(), SpawnInstanceBackToActor(), ToggleProxyMesh(), UpdateInstanceTransform(), and UpdateRenderDistances().
|
protected |
Definition at line 254 of file InstancedRenderer.h.
|
private |
Definition at line 288 of file InstancedRenderer.h.
Referenced by SetInstancedRendering().
|
private |
Definition at line 290 of file InstancedRenderer.h.
Referenced by OnWeatherParametersChanged().
|
protected |
Definition at line 257 of file InstancedRenderer.h.
Referenced by AddActorToInstancedRendering(), LogInfo(), and RemoveInstance().
|
private |
World Position Offset (WPO) render distance in cm
Definition at line 284 of file InstancedRenderer.h.
Referenced by BeginPlay(), FindOrAddUniqueMesh(), and SetWorldPositionOffsetDistance().