2020-05-05 11:41:40 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "ChaosSolversModule.h"
|
|
|
|
|
#include "Chaos/ParticleHandle.h"
|
|
|
|
|
#include "GeometryCollection/GeometryCollection.h"
|
|
|
|
|
#include "GeometryCollectionProxyData.h"
|
|
|
|
|
#include "PhysicsProxy/PhysicsProxies.h"
|
|
|
|
|
#include "Chaos/PBDRigidsEvolutionFwd.h"
|
|
|
|
|
#include "Chaos/Defines.h"
|
2021-02-03 14:57:28 -04:00
|
|
|
#include "PhysicsInterfaceDeclaresCore.h"
|
2020-05-05 11:41:40 -04:00
|
|
|
|
|
|
|
|
namespace GeometryCollectionTest
|
|
|
|
|
{
|
|
|
|
|
using namespace Chaos;
|
|
|
|
|
|
|
|
|
|
enum WrapperType
|
|
|
|
|
{
|
|
|
|
|
RigidBody,
|
|
|
|
|
GeometryCollection
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ESimplicialType
|
|
|
|
|
{
|
|
|
|
|
Chaos_Simplicial_Box,
|
|
|
|
|
Chaos_Simplicial_Sphere,
|
|
|
|
|
Chaos_Simplicial_GriddleBox,
|
|
|
|
|
Chaos_Simplicial_Tetrahedron,
|
|
|
|
|
Chaos_Simplicial_Imported_Sphere,
|
|
|
|
|
Chaos_Simplicial_None
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct WrapperBase
|
|
|
|
|
{
|
|
|
|
|
WrapperType Type;
|
|
|
|
|
WrapperBase(WrapperType TypeIn) : Type(TypeIn) {}
|
|
|
|
|
template<class AS_T> AS_T* As() { return AS_T::StaticType() == Type ? static_cast<AS_T*>(this) : nullptr; }
|
|
|
|
|
template<class AS_T> const AS_T* As() const { return AS_T::StaticType() == Type ? static_cast<const AS_T*>(this) : nullptr; }
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-18 15:20:03 -04:00
|
|
|
struct FGeometryCollectionWrapper : public WrapperBase
|
2020-05-05 11:41:40 -04:00
|
|
|
{
|
2021-03-18 15:20:03 -04:00
|
|
|
FGeometryCollectionWrapper() : WrapperBase(WrapperType::GeometryCollection) {}
|
|
|
|
|
FGeometryCollectionWrapper(
|
2020-05-05 11:41:40 -04:00
|
|
|
TSharedPtr<FGeometryCollection> RestCollectionIn,
|
|
|
|
|
TSharedPtr<FGeometryDynamicCollection> DynamicCollectionIn,
|
2020-09-24 00:43:27 -04:00
|
|
|
FGeometryCollectionPhysicsProxy* PhysObjectIn)
|
2020-05-05 11:41:40 -04:00
|
|
|
: WrapperBase(WrapperType::GeometryCollection)
|
|
|
|
|
, RestCollection(RestCollectionIn)
|
|
|
|
|
, DynamicCollection(DynamicCollectionIn)
|
|
|
|
|
, PhysObject(PhysObjectIn) {}
|
|
|
|
|
static WrapperType StaticType() { return WrapperType::GeometryCollection; }
|
|
|
|
|
TSharedPtr<FGeometryCollection> RestCollection;
|
|
|
|
|
TSharedPtr<FGeometryDynamicCollection> DynamicCollection;
|
2020-09-24 00:43:27 -04:00
|
|
|
FGeometryCollectionPhysicsProxy* PhysObject;
|
2020-05-05 11:41:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct RigidBodyWrapper : public WrapperBase
|
|
|
|
|
{
|
|
|
|
|
RigidBodyWrapper(
|
|
|
|
|
TSharedPtr<Chaos::FChaosPhysicsMaterial> PhysicalMaterialIn,
|
2021-02-03 14:57:28 -04:00
|
|
|
FPhysicsActorHandle ParticleIn)
|
2020-05-05 11:41:40 -04:00
|
|
|
: WrapperBase(WrapperType::RigidBody)
|
|
|
|
|
, PhysicalMaterial(PhysicalMaterialIn)
|
|
|
|
|
, Particle(ParticleIn) {}
|
|
|
|
|
static WrapperType StaticType() { return WrapperType::RigidBody; }
|
|
|
|
|
TSharedPtr<Chaos::FChaosPhysicsMaterial> PhysicalMaterial;
|
2021-02-03 14:57:28 -04:00
|
|
|
FPhysicsActorHandle Particle;
|
2020-05-05 11:41:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct CreationParameters
|
|
|
|
|
{
|
|
|
|
|
FTransform RootTransform = FTransform::Identity;
|
|
|
|
|
/**
|
|
|
|
|
* Implicit box uses Scale X, Y, Z for dimensions.
|
|
|
|
|
* Implicit sphere uses Scale X for radius.
|
|
|
|
|
*/
|
|
|
|
|
FVector InitialLinearVelocity = FVector::ZeroVector;
|
|
|
|
|
EObjectStateTypeEnum DynamicState = EObjectStateTypeEnum::Chaos_Object_Dynamic;
|
|
|
|
|
bool Simulating = true;
|
2021-02-03 14:57:28 -04:00
|
|
|
FReal Mass = 1.0;
|
2020-05-05 11:41:40 -04:00
|
|
|
bool bMassAsDensity = false;
|
|
|
|
|
ECollisionTypeEnum CollisionType = ECollisionTypeEnum::Chaos_Surface_Volumetric;
|
|
|
|
|
ESimplicialType SimplicialType = ESimplicialType::Chaos_Simplicial_Sphere;
|
|
|
|
|
EImplicitTypeEnum ImplicitType = EImplicitTypeEnum::Chaos_Implicit_Sphere;
|
2021-08-25 18:04:59 -04:00
|
|
|
float CollisionParticleFraction = 1.0f;
|
2020-05-05 11:41:40 -04:00
|
|
|
EInitialVelocityTypeEnum InitialVelocityType = EInitialVelocityTypeEnum::Chaos_Initial_Velocity_None;
|
|
|
|
|
TArray<FTransform> NestedTransforms;
|
|
|
|
|
bool EnableClustering = true;
|
|
|
|
|
FTransform GeomTransform = FTransform::Identity;
|
|
|
|
|
TSharedPtr<FGeometryCollection> RestCollection = nullptr;
|
|
|
|
|
int32 MaxClusterLevel = 100;
|
2021-05-05 15:07:25 -04:00
|
|
|
TArray<float> DamageThreshold = { 1000.0 };
|
2021-03-05 19:27:14 -04:00
|
|
|
Chaos::FClusterCreationParameters::EConnectionMethod ClusterConnectionMethod = Chaos::FClusterCreationParameters::EConnectionMethod::PointImplicit;
|
2020-05-05 11:41:40 -04:00
|
|
|
bool RemoveOnFractureEnabled = false;
|
|
|
|
|
int32 CollisionGroup = 0;
|
|
|
|
|
int32 MinLevelSetResolution = 5;
|
|
|
|
|
int32 MaxLevelSetResolution = 10;
|
|
|
|
|
int32 ClusterGroupIndex = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum GeometryType {
|
|
|
|
|
GeometryCollectionWithSingleRigid,
|
|
|
|
|
RigidFloor,
|
|
|
|
|
GeometryCollectionWithSuppliedRestCollection
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <GeometryType>
|
|
|
|
|
struct TNewSimulationObject
|
|
|
|
|
{
|
|
|
|
|
static WrapperBase* Init(const CreationParameters Params = CreationParameters());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct FrameworkParameters
|
|
|
|
|
{
|
|
|
|
|
FrameworkParameters() : Dt(1/60.) {}
|
2021-02-03 14:57:28 -04:00
|
|
|
FrameworkParameters(FReal dt) : Dt(Dt) {}
|
|
|
|
|
FReal Dt;
|
2020-05-05 11:41:40 -04:00
|
|
|
Chaos::EThreadingMode ThreadingMode = Chaos::EThreadingMode::SingleThread;
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-18 15:20:03 -04:00
|
|
|
class FFramework
|
2020-05-05 11:41:40 -04:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
2021-03-18 15:20:03 -04:00
|
|
|
FFramework(FrameworkParameters Properties = FrameworkParameters());
|
|
|
|
|
virtual ~FFramework();
|
2020-05-05 11:41:40 -04:00
|
|
|
|
|
|
|
|
void AddSimulationObject(WrapperBase* Object);
|
|
|
|
|
void Initialize();
|
|
|
|
|
void Advance();
|
|
|
|
|
FReal Dt;
|
|
|
|
|
FChaosSolversModule* Module = FChaosSolversModule::GetModule();
|
2021-03-18 15:20:03 -04:00
|
|
|
Chaos::FPBDRigidsSolver* Solver;
|
2020-05-05 11:41:40 -04:00
|
|
|
TArray< WrapperBase* > PhysicsObjects;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|