2021-06-21 18:08:56 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "DynamicMeshActor.h"
|
2022-10-26 12:57:32 -04:00
|
|
|
#include "Engine/CollisionProfile.h"
|
2022-12-15 16:01:51 -05:00
|
|
|
#include "MaterialDomain.h"
|
2021-06-22 12:10:24 -04:00
|
|
|
#include "Materials/Material.h"
|
2021-06-21 18:08:56 -04:00
|
|
|
|
2022-09-24 13:57:58 -04:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(DynamicMeshActor)
|
|
|
|
|
|
2021-06-21 18:08:56 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "ADynamicMeshActor"
|
|
|
|
|
|
|
|
|
|
ADynamicMeshActor::ADynamicMeshActor(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
|
|
|
|
{
|
|
|
|
|
DynamicMeshComponent = CreateDefaultSubobject<UDynamicMeshComponent>(TEXT("DynamicMeshComponent"));
|
|
|
|
|
DynamicMeshComponent->SetMobility(EComponentMobility::Movable);
|
|
|
|
|
DynamicMeshComponent->SetGenerateOverlapEvents(false);
|
|
|
|
|
DynamicMeshComponent->SetCollisionProfileName(UCollisionProfile::BlockAll_ProfileName);
|
|
|
|
|
|
|
|
|
|
DynamicMeshComponent->CollisionType = ECollisionTraceFlag::CTF_UseDefault;
|
|
|
|
|
|
2021-06-22 12:10:24 -04:00
|
|
|
DynamicMeshComponent->SetMaterial(0, UMaterial::GetDefaultMaterial(MD_Surface)); // is this necessary?
|
2021-06-21 18:08:56 -04:00
|
|
|
|
|
|
|
|
SetRootComponent(DynamicMeshComponent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-09-08 21:48:52 -04:00
|
|
|
UDynamicMeshPool* ADynamicMeshActor::GetComputeMeshPool()
|
|
|
|
|
{
|
|
|
|
|
if (DynamicMeshPool == nullptr && bEnableComputeMeshPool)
|
|
|
|
|
{
|
|
|
|
|
DynamicMeshPool = NewObject<UDynamicMeshPool>();
|
|
|
|
|
}
|
|
|
|
|
return DynamicMeshPool;
|
|
|
|
|
}
|
2021-06-21 18:08:56 -04:00
|
|
|
|
|
|
|
|
|
2021-09-08 21:48:52 -04:00
|
|
|
UDynamicMesh* ADynamicMeshActor::AllocateComputeMesh()
|
|
|
|
|
{
|
|
|
|
|
if (bEnableComputeMeshPool)
|
|
|
|
|
{
|
|
|
|
|
UDynamicMeshPool* UsePool = GetComputeMeshPool();
|
|
|
|
|
if (UsePool)
|
|
|
|
|
{
|
|
|
|
|
return UsePool->RequestMesh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we could not return a pool mesh, allocate a new mesh that isn't owned by the pool
|
|
|
|
|
return NewObject<UDynamicMesh>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ADynamicMeshActor::ReleaseComputeMesh(UDynamicMesh* Mesh)
|
|
|
|
|
{
|
|
|
|
|
if (bEnableComputeMeshPool && Mesh)
|
|
|
|
|
{
|
|
|
|
|
UDynamicMeshPool* UsePool = GetComputeMeshPool();
|
|
|
|
|
if (UsePool != nullptr)
|
|
|
|
|
{
|
|
|
|
|
UsePool->ReturnMesh(Mesh);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ADynamicMeshActor::ReleaseAllComputeMeshes()
|
|
|
|
|
{
|
|
|
|
|
UDynamicMeshPool* UsePool = GetComputeMeshPool();
|
|
|
|
|
if (UsePool)
|
|
|
|
|
{
|
|
|
|
|
UsePool->ReturnAllMeshes();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ADynamicMeshActor::FreeAllComputeMeshes()
|
|
|
|
|
{
|
|
|
|
|
UDynamicMeshPool* UsePool = GetComputeMeshPool();
|
|
|
|
|
if (UsePool)
|
|
|
|
|
{
|
|
|
|
|
UsePool->FreeAllMeshes();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-21 18:08:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-20 22:15:01 -04:00
|
|
|
|
2022-09-24 13:57:58 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|