2022-05-26 19:00:40 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2022-06-01 21:41:57 -04:00
|
|
|
#include "Dataflow/GeometryCollectionNodes.h"
|
2022-05-26 19:00:40 -04:00
|
|
|
|
2022-06-02 10:52:24 -04:00
|
|
|
#include "Engine/StaticMesh.h"
|
|
|
|
|
#include "GeometryCollection/GeometryCollectionObject.h"
|
|
|
|
|
#include "GeometryCollection/ManagedArrayCollection.h"
|
|
|
|
|
#include "GeometryCollection/GeometryCollection.h"
|
|
|
|
|
#include "GeometryCollection/GeometryCollectionEngineUtility.h"
|
|
|
|
|
#include "GeometryCollection/GeometryCollectionEngineConversion.h"
|
|
|
|
|
#include "Logging/LogMacros.h"
|
|
|
|
|
#include "Templates/SharedPointer.h"
|
|
|
|
|
#include "UObject/UnrealTypePrivate.h"
|
|
|
|
|
|
2022-05-26 19:00:40 -04:00
|
|
|
namespace Dataflow
|
|
|
|
|
{
|
|
|
|
|
void GeometryCollectionEngineAssetNodes()
|
|
|
|
|
{
|
2022-06-09 02:36:29 -04:00
|
|
|
DATAFLOW_NODE_REGISTER_CREATION_FACTORY(FGetCollectionAssetDataflowNode);
|
|
|
|
|
DATAFLOW_NODE_REGISTER_CREATION_FACTORY(FExampleCollectionEditDataflowNode);
|
|
|
|
|
DATAFLOW_NODE_REGISTER_CREATION_FACTORY(FSetCollectionAssetDataflowNode);
|
|
|
|
|
DATAFLOW_NODE_REGISTER_CREATION_FACTORY(FResetGeometryCollectionDataflowNode);
|
2022-05-26 19:00:40 -04:00
|
|
|
}
|
2022-06-09 02:36:29 -04:00
|
|
|
}
|
2022-06-02 10:52:24 -04:00
|
|
|
|
2022-06-09 02:36:29 -04:00
|
|
|
void FGetCollectionAssetDataflowNode::Evaluate(const Dataflow::FContext& Context, Dataflow::FConnection* Out) const
|
|
|
|
|
{
|
2022-06-13 18:01:11 -04:00
|
|
|
if (&Output == Out)
|
2022-06-02 10:52:24 -04:00
|
|
|
{
|
2022-06-10 16:06:26 -04:00
|
|
|
if (const Dataflow::FEngineContext* EngineContext = Context.AsType<Dataflow::FEngineContext>())
|
2022-06-02 10:52:24 -04:00
|
|
|
{
|
2022-06-09 02:36:29 -04:00
|
|
|
if (UGeometryCollection* CollectionAsset = Cast<UGeometryCollection>(EngineContext->Owner))
|
2022-06-02 10:52:24 -04:00
|
|
|
{
|
2022-06-09 02:36:29 -04:00
|
|
|
if (const TSharedPtr<FGeometryCollection, ESPMode::ThreadSafe> AssetCollection = CollectionAsset->GetGeometryCollection())
|
2022-06-02 10:52:24 -04:00
|
|
|
{
|
|
|
|
|
FManagedArrayCollection* NewCollection = AssetCollection->NewCopy<FManagedArrayCollection>();
|
2022-06-13 18:01:11 -04:00
|
|
|
Output.SetValue(DataType(NewCollection), Context);
|
2022-06-02 10:52:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-26 19:00:40 -04:00
|
|
|
}
|
|
|
|
|
|
2022-06-09 02:36:29 -04:00
|
|
|
void FExampleCollectionEditDataflowNode::Evaluate(const Dataflow::FContext& Context, Dataflow::FConnection* Out) const
|
|
|
|
|
{
|
2022-06-13 18:01:11 -04:00
|
|
|
if (&Output == Out)
|
2022-06-09 02:36:29 -04:00
|
|
|
{
|
2022-06-13 18:01:11 -04:00
|
|
|
DataType Collection = Input.GetValue(Context);
|
2022-06-09 02:36:29 -04:00
|
|
|
if (Active)
|
|
|
|
|
{
|
|
|
|
|
TManagedArray<FVector3f>* Vertex = Collection->FindAttribute<FVector3f>("Vertex", "Vertices");
|
|
|
|
|
for (int i = 0; i < Vertex->Num(); i++)
|
|
|
|
|
{
|
|
|
|
|
(*Vertex)[i][1] *= Scale;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-13 18:01:11 -04:00
|
|
|
Output.SetValue(Collection, Context);
|
2022-06-09 02:36:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FSetCollectionAssetDataflowNode::Evaluate(const Dataflow::FContext& Context, Dataflow::FConnection* Out) const
|
|
|
|
|
{
|
|
|
|
|
if (Out == nullptr)
|
|
|
|
|
{
|
2022-06-13 18:01:11 -04:00
|
|
|
DataType Collection = Input.GetValue(Context);
|
2022-06-10 16:06:26 -04:00
|
|
|
if (const Dataflow::FEngineContext* EngineContext = Context.AsType<Dataflow::FEngineContext>())
|
2022-06-09 02:36:29 -04:00
|
|
|
{
|
|
|
|
|
if (UGeometryCollection* CollectionAsset = Cast<UGeometryCollection>(EngineContext->Owner))
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FGeometryCollection, ESPMode::ThreadSafe> NewCollection(Collection->NewCopy<FGeometryCollection>());
|
|
|
|
|
CollectionAsset->SetGeometryCollection(NewCollection);
|
|
|
|
|
CollectionAsset->InvalidateCollection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FResetGeometryCollectionDataflowNode::Evaluate(const Dataflow::FContext& Context, Dataflow::FConnection* Out) const
|
|
|
|
|
{
|
2022-06-13 18:01:11 -04:00
|
|
|
ManagedArrayOut.SetValue(TSharedPtr<FManagedArrayCollection>(nullptr), Context);
|
2022-06-09 02:36:29 -04:00
|
|
|
|
2022-06-10 16:06:26 -04:00
|
|
|
if (const Dataflow::FEngineContext* EngineContext = Context.AsType<Dataflow::FEngineContext>())
|
2022-06-09 02:36:29 -04:00
|
|
|
{
|
|
|
|
|
if (UGeometryCollection* GeometryCollectionObject = Cast<UGeometryCollection>(EngineContext->Owner))
|
|
|
|
|
{
|
|
|
|
|
GeometryCollectionObject->Reset();
|
|
|
|
|
|
|
|
|
|
const UObject* Owner = EngineContext->Owner;
|
|
|
|
|
FName AName("GeometrySource");
|
|
|
|
|
if (Owner && Owner->GetClass())
|
|
|
|
|
{
|
|
|
|
|
if (const ::FProperty* UEProperty = Owner->GetClass()->FindPropertyByName(AName))
|
|
|
|
|
{
|
|
|
|
|
if (const FArrayProperty* ArrayProperty = CastField<FArrayProperty>(UEProperty))
|
|
|
|
|
{
|
|
|
|
|
FScriptArrayHelper_InContainer ArrayHelper(ArrayProperty, Owner);
|
|
|
|
|
const int32 ArraySize = ArrayHelper.Num();
|
|
|
|
|
for (int32 Index = 0; Index < ArraySize; ++Index)
|
|
|
|
|
{
|
|
|
|
|
if (FGeometryCollectionSource* SourceObject = (FGeometryCollectionSource*)(ArrayHelper.GetRawPtr(Index)))
|
|
|
|
|
{
|
|
|
|
|
if (UObject* ResolvedObject = SourceObject->SourceGeometryObject.ResolveObject())
|
|
|
|
|
{
|
|
|
|
|
if (UStaticMesh* StaticMesh = Cast<UStaticMesh>(ResolvedObject))
|
|
|
|
|
{
|
|
|
|
|
TArray<UMaterialInterface*> Materials;
|
|
|
|
|
Materials.Reserve(StaticMesh->GetStaticMaterials().Num());
|
|
|
|
|
|
|
|
|
|
for (int32 Index2 = 0; Index2 < StaticMesh->GetStaticMaterials().Num(); ++Index2)
|
|
|
|
|
{
|
|
|
|
|
UMaterialInterface* CurrMaterial = StaticMesh->GetMaterial(Index2);
|
|
|
|
|
Materials.Add(CurrMaterial);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Geometry collections usually carry the selection material, which we'll delete before appending
|
|
|
|
|
UMaterialInterface* BoneSelectedMaterial = LoadObject<UMaterialInterface>(nullptr, UGeometryCollection::GetSelectedMaterialPath(), nullptr, LOAD_None, nullptr);
|
|
|
|
|
GeometryCollectionObject->Materials.Remove(BoneSelectedMaterial);
|
|
|
|
|
Materials.Remove(BoneSelectedMaterial);
|
|
|
|
|
|
|
|
|
|
FGeometryCollectionEngineConversion::AppendStaticMesh(StaticMesh, Materials, FTransform(), GeometryCollectionObject);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
GeometryCollectionObject->UpdateConvexGeometry();
|
|
|
|
|
GeometryCollectionObject->InitializeMaterials();
|
|
|
|
|
GeometryCollectionObject->InvalidateCollection();
|
|
|
|
|
|
|
|
|
|
if (const TSharedPtr<FGeometryCollection, ESPMode::ThreadSafe> AssetCollection = GeometryCollectionObject->GetGeometryCollection())
|
|
|
|
|
{
|
|
|
|
|
FManagedArrayCollection* NewCollection = AssetCollection->NewCopy<FManagedArrayCollection>();
|
2022-06-13 18:01:11 -04:00
|
|
|
ManagedArrayOut.SetValue(DataType(NewCollection), Context);
|
2022-06-09 02:36:29 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|