2019-12-26 14:45:42 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-12-12 11:25:29 -05:00
# pragma once
# include "GameFramework/Actor.h"
# include "GeometryCollection/GeometryCollectionSimulationTypes.h"
2019-06-08 17:15:34 -04:00
# include "Chaos/ChaosNotifyHandlerInterface.h"
2018-12-12 11:25:29 -05:00
# include "StaticMeshSimulationComponent.generated.h"
2019-08-02 09:01:58 -04:00
class FStaticMeshPhysicsProxy ;
2020-04-08 11:35:04 -04:00
class AChaosSolverActor ;
class UChaosPhysicalMaterial ;
2020-04-08 13:25:48 -04:00
class FPhysScene_Chaos ;
2020-04-08 11:35:04 -04:00
namespace Chaos
{
class FChaosPhysicsMaterial ;
}
2018-12-12 11:25:29 -05:00
/**
* UStaticMeshSimulationComponent
*/
UCLASS ( ClassGroup = Physics , Experimental , meta = ( BlueprintSpawnableComponent ) )
2019-06-08 17:15:34 -04:00
class GEOMETRYCOLLECTIONENGINE_API UStaticMeshSimulationComponent : public UActorComponent , public IChaosNotifyHandlerInterface
2018-12-12 11:25:29 -05:00
{
GENERATED_UCLASS_BODY ( )
2020-04-08 11:35:04 -04:00
UStaticMeshSimulationComponent ( FVTableHelper & Helper ) ;
virtual ~ UStaticMeshSimulationComponent ( ) ;
2018-12-12 11:25:29 -05:00
public :
2019-06-08 17:15:34 -04:00
virtual void TickComponent ( float DeltaTime , enum ELevelTick TickType , FActorComponentTickFunction * ThisTickFunction ) ;
2018-12-12 11:25:29 -05:00
/** When Simulating is enabled the Component will initialize its rigid bodies within the solver. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|General " )
bool Simulating ;
2019-06-08 17:15:34 -04:00
/** If true, this component will get collision notification events (@see IChaosNotifyHandlerInterface) */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|General " )
bool bNotifyCollisions ;
2018-12-12 11:25:29 -05:00
/** ObjectType defines how to initialize the rigid collision structures. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|General " )
2019-06-08 17:15:34 -04:00
EObjectStateTypeEnum ObjectType ;
2018-12-12 11:25:29 -05:00
2019-06-08 17:15:34 -04:00
/** Mass in Kg */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|General " , meta = ( Units = kg ) )
2018-12-12 11:25:29 -05:00
float Mass ;
/** CollisionType defines how to initialize the rigid collision structures. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Collisions " )
ECollisionTypeEnum CollisionType ;
2019-06-08 17:15:34 -04:00
/** CollisionType defines how to initialize the rigid collision structures. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Collisions " )
EImplicitTypeEnum ImplicitType ;
/*
* Resolution on the smallest axes for the level set . ( def : 5 )
*/
UPROPERTY ( EditAnywhere , BlueprintReadOnly , Category = " ChaosPhysics|Collisions " )
int32 MinLevelSetResolution ;
/*
* Resolution on the smallest axes for the level set . ( def : 10 )
*/
UPROPERTY ( EditAnywhere , BlueprintReadOnly , Category = " ChaosPhysics|Collisions " )
int32 MaxLevelSetResolution ;
2018-12-12 11:25:29 -05:00
/** */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Initial Velocity " )
EInitialVelocityTypeEnum InitialVelocityType ;
/** */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Initial Velocity " )
FVector InitialLinearVelocity ;
/** */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Initial Velocity " )
FVector InitialAngularVelocity ;
/** Damage threshold for clusters. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " ChaosPhysics|Collisions " )
float DamageThreshold ;
2019-06-08 17:15:34 -04:00
/**
* Physical Properties
*/
UPROPERTY ( EditAnywhere , BlueprintReadOnly , Category = " ChaosPhysics " )
2021-01-27 17:40:25 -04:00
TObjectPtr < const UChaosPhysicalMaterial > PhysicalMaterial ;
2018-12-12 11:25:29 -05:00
/** Chaos RBD Solver */
UPROPERTY ( EditAnywhere , Category = " ChaosPhysics " , meta = ( DisplayName = " Chaos Solver " ) )
2021-01-27 17:40:25 -04:00
TObjectPtr < AChaosSolverActor > ChaosSolverActor ;
2018-12-12 11:25:29 -05:00
const TSharedPtr < FPhysScene_Chaos > GetPhysicsScene ( ) const ;
2019-06-08 17:15:34 -04:00
public :
UPROPERTY ( BlueprintAssignable , Category = " Collision " )
FOnChaosPhysicsCollision OnChaosPhysicsCollision ;
UFUNCTION ( BlueprintImplementableEvent , meta = ( DisplayName = " Physics Collision " ) , Category = " Collision " )
void ReceivePhysicsCollision ( const FChaosPhysicsCollisionInfo & CollisionInfo ) ;
// IChaosNotifyHandlerInterface
virtual void DispatchChaosPhysicsCollisionBlueprintEvents ( const FChaosPhysicsCollisionInfo & CollisionInfo ) override ;
/** Changes whether or not this component will get future break notifications. */
UFUNCTION ( BlueprintCallable , Category = " Physics " )
void ForceRecreatePhysicsState ( ) ;
2018-12-12 11:25:29 -05:00
private :
2019-06-08 17:15:34 -04:00
/** List of physics objects this simulation component created. */
2019-08-02 09:01:58 -04:00
TArray < FStaticMeshPhysicsProxy * > PhysicsProxies ;
2018-12-12 11:25:29 -05:00
2019-08-02 09:01:58 -04:00
/** List of component for which this simulation component created a physics object. Parallel array to PhysicsProxy, so PhysicsProxies[i] corresponds to SimulatedComponents[i] */
2019-06-08 17:15:34 -04:00
UPROPERTY ( )
2021-01-27 17:40:25 -04:00
TArray < TObjectPtr < UPrimitiveComponent > > SimulatedComponents ;
2019-06-08 17:15:34 -04:00
//@todo(mlentine): Don't have one per static mesh
2019-11-06 08:55:27 -05:00
TUniquePtr < Chaos : : FChaosPhysicsMaterial > ChaosMaterial ;
2019-06-08 17:15:34 -04:00
2018-12-12 11:25:29 -05:00
protected :
virtual void OnCreatePhysicsState ( ) override ;
virtual void OnDestroyPhysicsState ( ) override ;
virtual bool ShouldCreatePhysicsState ( ) const override ;
virtual bool HasValidPhysicsState ( ) const override ;
} ;