2023-03-31 02:58:27 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
# include "GeometryCollection/GeometryCollectionExternalRenderInterface.h"
# include "GeometryCollectionISMPoolRenderer.generated.h"
2023-04-04 19:18:34 -04:00
class UGeometryCollectionISMPoolComponent ;
2023-08-25 13:36:52 -04:00
class UGeometryCollectionComponent ;
class ULevel ;
2023-03-31 02:58:27 -04:00
2023-04-03 10:06:24 -04:00
/** Implementation of a geometry collection custom renderer that pushes AutoInstanceMeshes to an ISMPool. */
2023-03-31 02:58:27 -04:00
UCLASS ( )
2023-04-03 10:06:24 -04:00
class UGeometryCollectionISMPoolRenderer : public UObject , public IGeometryCollectionExternalRenderInterface
2023-03-31 02:58:27 -04:00
{
GENERATED_BODY ( )
2024-04-22 10:52:10 -04:00
/** Instanced Static Mesh Pool component that is used to render our meshes. */
UPROPERTY ( Transient )
TObjectPtr < UGeometryCollectionISMPoolComponent > CachedISMPoolComponent ;
/** Set if we have an Instanced Static Mesh Pool component owned by this renderer (ie when in Editor mode). Non-transient to behave correctly under actor duplication. */
UPROPERTY ( )
TObjectPtr < UGeometryCollectionISMPoolComponent > LocalISMPoolComponent ;
2023-03-31 02:58:27 -04:00
public :
//~ Begin IGeometryCollectionExternalRenderInterface Interface.
2024-04-02 07:56:31 -04:00
virtual void OnRegisterGeometryCollection ( UGeometryCollectionComponent & InComponent ) override ;
2023-04-03 10:06:24 -04:00
virtual void OnUnregisterGeometryCollection ( ) override ;
2023-10-12 20:59:48 -04:00
virtual void UpdateState ( UGeometryCollection const & InGeometryCollection , FTransform const & InComponentTransform , uint32 InStateFlags ) override ;
2023-04-06 17:29:18 -04:00
virtual void UpdateRootTransform ( UGeometryCollection const & InGeometryCollection , FTransform const & InRootTransform ) override ;
2024-02-27 23:05:17 -05:00
virtual void UpdateRootTransforms ( UGeometryCollection const & InGeometryCollection , FTransform const & InRootTransform , TArrayView < const FTransform3f > InRootLocalTransforms ) override ;
2023-10-16 12:20:18 -04:00
virtual void UpdateTransforms ( UGeometryCollection const & InGeometryCollection , TArrayView < const FTransform3f > InTransforms ) override ;
2023-03-31 02:58:27 -04:00
//~ End IGeometryCollectionExternalRenderInterface Interface.
2024-04-22 10:52:10 -04:00
protected :
2023-03-31 02:58:27 -04:00
/** Description for a group of meshes that are added/updated together. */
struct FISMPoolGroup
{
int32 GroupIndex = INDEX_NONE ;
TArray < int32 > MeshIds ;
} ;
2023-04-06 17:29:18 -04:00
/** Cached component transform. */
FTransform ComponentTransform = FTransform : : Identity ;
2023-03-31 02:58:27 -04:00
/** ISM pool groups per rendering element type. */
FISMPoolGroup MergedMeshGroup ;
FISMPoolGroup InstancesGroup ;
2024-04-22 10:52:10 -04:00
/** Level of the owning component of this renderer */
TWeakObjectPtr < ULevel > OwningLevel ;
2023-08-25 13:36:52 -04:00
2024-05-24 10:31:28 -04:00
/** Registered flag set true in between calls to OnRegister() and OnUnregister(). */
bool bIsRegistered = false ;
2023-03-31 02:58:27 -04:00
private :
2024-04-02 07:56:31 -04:00
UGeometryCollectionISMPoolComponent * GetISMPoolComponent ( ) const ;
2023-04-04 19:18:34 -04:00
UGeometryCollectionISMPoolComponent * GetOrCreateISMPoolComponent ( ) ;
2023-03-31 02:58:27 -04:00
void InitMergedMeshFromGeometryCollection ( UGeometryCollection const & InGeometryCollection ) ;
void InitInstancesFromGeometryCollection ( UGeometryCollection const & InGeometryCollection ) ;
2024-04-22 10:52:10 -04:00
void UpdateMergedMeshTransforms ( FTransform const & InBaseTransform , TArrayView < const FTransform3f > InLocalTransforms ) ;
2023-10-16 12:20:18 -04:00
void UpdateInstanceTransforms ( UGeometryCollection const & InGeometryCollection , FTransform const & InBaseTransform , TArrayView < const FTransform3f > InTransforms ) ;
2023-03-31 02:58:27 -04:00
void ReleaseGroup ( FISMPoolGroup & InOutGroup ) ;
} ;