Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebukam committed Nov 20, 2024
1 parent 3f7226f commit 76ad6ac
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool FPCGExAssetStagingElement::Boot(FPCGExContext* InContext) const
PCGE_LOG(Error, GraphAndLog, FTEXT("Collection Map output is not supported with collections built from attribute sets."));
return false;
}

Context->MainCollection = Settings->AttributeSetDetails.TryBuildCollection(Context, PCGExAssetCollection::SourceAssetCollection, false);
if (!Context->MainCollection)
{
Expand All @@ -72,7 +72,7 @@ bool FPCGExAssetStagingElement::Boot(FPCGExContext* InContext) const

if (Settings->OutputMode == EPCGExStagingOutputMode::CollectionMap)
{
Context->CollectionPickDatasetPacker = MakeShared<PCGExStaging::FCollectionPickDatasetPacker>();
Context->CollectionPickDatasetPacker = MakeShared<PCGExStaging::FPickPacker>(Context);
}

return true;
Expand Down Expand Up @@ -193,15 +193,17 @@ namespace PCGExAssetStaging

if (Settings->OutputMode == EPCGExStagingOutputMode::Attributes)
{
bInherit = PointDataFacade->GetIn()->Metadata->HasAttribute(Settings->AssetPathAttributeName);
#if PCGEX_ENGINE_VERSION > 503
PathWriter = PointDataFacade->GetWritable<FSoftObjectPath>(Settings->AssetPathAttributeName, PCGExData::EBufferInit::New);
PathWriter = PointDataFacade->GetWritable<FSoftObjectPath>(Settings->AssetPathAttributeName, bInherit ? PCGExData::EBufferInit::Inherit : PCGExData::EBufferInit::New);
#else
PathWriter = PointDataFacade->GetWritable<FString>(Settings->AssetPathAttributeName, PCGExData::EBufferInit::New);
PathWriter = PointDataFacade->GetWritable<FString>(Settings->AssetPathAttributeName, bInherit ? PCGExData::EBufferInit::Inherit : PCGExData::EBufferInit::New);
#endif
}
else
{
HashWriter = PointDataFacade->GetWritable<int64>(PCGExStaging::Tag_EntryIdx, PCGExData::EBufferInit::New);
bInherit = PointDataFacade->GetIn()->Metadata->HasAttribute(PCGExStaging::Tag_EntryIdx);
HashWriter = PointDataFacade->GetWritable<int64>(PCGExStaging::Tag_EntryIdx, bInherit ? PCGExData::EBufferInit::Inherit : PCGExData::EBufferInit::New);
}

StartParallelLoopForPoints();
Expand All @@ -219,6 +221,8 @@ namespace PCGExAssetStaging
{
auto InvalidPoint = [&]()
{
if (bInherit) { return; }

if (Settings->bPruneEmptyPoints)
{
Point.MetadataEntry = -2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,34 @@
#include "Metadata/Accessors/PCGAttributeAccessorHelpers.h"

#include "Algo/AnyOf.h"
#include "Collections/PCGExStaging.h"
#include "AssetStaging/PCGExStaging.h"
#include "Collections/PCGExMeshCollection.h"
#include "Engine/StaticMesh.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(PCGExMeshSelectorStaged)

#define LOCTEXT_NAMESPACE "PCGExMeshSelectorStaged"

namespace PCGMeshSelectorAttribute
namespace PCGExMeshSelectorStaged
{
// Returns variation based on mesh, material overrides and reverse culling
FPCGMeshInstanceList& GetInstanceList(
TArray<FPCGMeshInstanceList>& InstanceLists,
const FPCGSoftISMComponentDescriptor& TemplateDescriptor,
TSoftObjectPtr<UStaticMesh> Mesh,
const FPCGExMeshCollectionEntry* Entry,
const TArray<TSoftObjectPtr<UMaterialInterface>>& MaterialOverrides,
bool bReverseCulling,
const UPCGPointData* InPointData,
const int AttributePartitionIndex = INDEX_NONE)
const UPCGPointData* InPointData)
{
for (FPCGMeshInstanceList& InstanceList : InstanceLists)
{
if (InstanceList.Descriptor.StaticMesh == Mesh &&
InstanceList.Descriptor.bReverseCulling == bReverseCulling &&
InstanceList.Descriptor.OverrideMaterials == MaterialOverrides &&
InstanceList.AttributePartitionIndex == AttributePartitionIndex)
if (InstanceList.Descriptor == Entry->ISMDescriptor)
{
return InstanceList;
}
}

FPCGSoftISMComponentDescriptor TemplateDescriptor = FPCGSoftISMComponentDescriptor(Entry->ISMDescriptor);
FPCGMeshInstanceList& NewInstanceList = InstanceLists.Emplace_GetRef(TemplateDescriptor);
NewInstanceList.Descriptor.StaticMesh = Mesh;
NewInstanceList.Descriptor.OverrideMaterials = MaterialOverrides;
NewInstanceList.Descriptor.bReverseCulling = bReverseCulling;
NewInstanceList.AttributePartitionIndex = AttributePartitionIndex;
NewInstanceList.Descriptor = TemplateDescriptor;
NewInstanceList.PointData = InPointData;

return NewInstanceList;
Expand All @@ -66,13 +59,32 @@ bool UPCGExMeshSelectorStaged::SelectInstances(

if (!InPointData)
{
PCGE_LOG_C(Error, GraphAndLog, &Context, LOCTEXT("InputMissingData", "Missing input data"));
PCGE_LOG_C(Error, GraphAndLog, &Context, FTEXT( "Missing input data"));
return true;
}

if (!InPointData->Metadata)
{
PCGE_LOG_C(Error, GraphAndLog, &Context, LOCTEXT("InputMissingMetadata", "Unable to get metadata from input"));
PCGE_LOG_C(Error, GraphAndLog, &Context, FTEXT( "Unable to get metadata from input"));
return true;
}

const FPCGMetadataAttribute<int64>* HashAttribute = InPointData->Metadata->GetConstTypedAttribute<int64>(PCGExStaging::Tag_EntryIdx);

if (!HashAttribute)
{
PCGE_LOG_C(Error, GraphAndLog, &Context, FTEXT( "Unable to get hash attribute from input"));
return true;
}

TSharedPtr<PCGExStaging::TPickUnpacker<UPCGExMeshCollection, FPCGExMeshCollectionEntry>> CollectionMap =
MakeShared<PCGExStaging::TPickUnpacker<UPCGExMeshCollection, FPCGExMeshCollectionEntry>>();

CollectionMap->UnpackPin(&Context, PCGPinConstants::DefaultParamsLabel);

if (!CollectionMap->HasValidMapping())
{
PCGE_LOG_C(Error, GraphAndLog, &Context, FTEXT( "Unable to find Staging Map data in overrides"));
return true;
}

Expand All @@ -84,7 +96,7 @@ bool UPCGExMeshSelectorStaged::SelectInstances(

if (!MaterialOverrideHelper.IsValid())
{
return true;
//return true;
}

if (Context.CurrentPointIndex == 0 && OutPointData)
Expand All @@ -93,67 +105,35 @@ bool UPCGExMeshSelectorStaged::SelectInstances(
OutPointData->SetPoints(InPointData->GetPoints());
}

TRACE_CPUPROFILER_EVENT_SCOPE(UPCGExMeshSelectorStaged::SelectEntries);
const TArray<FPCGPoint>& InPoints = InPointData->GetPoints();
const int32 NumPoints = InPoints.Num();

// Assign points to entries
int32 CurrentPartitionIndex = Context.CurrentPointIndex; // misnomer but we're reusing another concept from the context
const TArray<FPCGPoint>& Points = InPointData->GetPoints();
const int32 NumPoints = Points.Num();
{
TRACE_CPUPROFILER_EVENT_SCOPE(UPCGExMeshSelectorStaged::SelectEntries::PushingPointsToInstanceLists);
TRACE_CPUPROFILER_EVENT_SCOPE(UPCGExMeshSelectorStaged::SelectEntries);

// TODO: Revisit this when attribute partitioning is returned in a more optimized form
// The partition index is used to assign the point to the correct partition's instance
while (CurrentPartitionIndex < NumPoints)
while (Context.CurrentPointIndex < NumPoints)
{
// TODO : Get collection mapping from Overrides pin, find a suitable collection. If there are multiple, throw.
// Get per-point Idx from PCGExStaging::Tag_EntryIdx
// Build a temp PCGExStaging::TCollectionPickDatasetUnpacker; a bit unelegant but will do as it stores very little data
const FPCGPoint& Point = InPoints[Context.CurrentPointIndex++];

/*
if (MaterialOverrideHelper.OverridesMaterials())
{
for (int32 PointIndex = 0; PointIndex < NumPoints; ++PointIndex)
{
const FPCGPoint& Point = Points[PointIndices[PointIndex]];
FPCGMeshInstanceList& InstanceList = PCGMeshSelectorAttribute::GetInstanceList(OutMeshInstances, CurrentPartitionDescriptor, CurrentPartitionDescriptor.StaticMesh, MaterialOverrideHelper.GetMaterialOverrides(Point.MetadataEntry), bReverseTransform, InPointData, PartitionIndex);
InstanceList.Instances.Emplace(Point.Transform);
InstanceList.InstancesIndices.Emplace(PointIndex);
}
}
else
{
TArray<TSoftObjectPtr<UMaterialInterface>> DummyMaterialList;
FPCGMeshInstanceList& InstanceList = PCGMeshSelectorAttribute::GetInstanceList(OutMeshInstances, CurrentPartitionDescriptor, CurrentPartitionDescriptor.StaticMesh, DummyMaterialList, bReverseTransform, InPointData, PartitionIndex);
check(InstanceList.Instances.Num() == InstanceList.InstancesIndices.Num());
const int32 InstanceOffset = InstanceList.Instances.Num();
InstanceList.Instances.SetNum(InstanceOffset + PointIndices.Num());
InstanceList.InstancesIndices.Append(PointIndices);
for (int32 PointIndex = 0; PointIndex < PointIndices.Num(); ++PointIndex)
{
const FPCGPoint& Point = Points[PointIndices[PointIndex]];
InstanceList.Instances[InstanceOffset + PointIndex] = Point.Transform;
}
}
int64 EntryHash = HashAttribute->GetValueFromItemKey(Point.MetadataEntry);

{
TRACE_CPUPROFILER_EVENT_SCOPE(UPCGExMeshSelectorStaged::SelectEntries::AddPointsToInstanceList);
AddPointsToInstanceList(Partition, false);
AddPointsToInstanceList(ReverseInstances, true);
}
const FPCGExMeshCollectionEntry* Entry = nullptr;
if (!CollectionMap->ResolveEntry(EntryHash, Entry)) { continue; }

if (Context.ShouldStop())
{
break;
}
*/
TArray<TSoftObjectPtr<UMaterialInterface>> DummyMaterialList;
FPCGMeshInstanceList& InstanceList = PCGExMeshSelectorStaged::GetInstanceList(OutMeshInstances, Entry, DummyMaterialList, InPointData);
InstanceList.Instances.Add(Point.Transform);

if (Context.ShouldStop()) { break; }
}
}

Context.CurrentPointIndex = CurrentPartitionIndex; // misnomer, but we're using the same context
return CurrentPartitionIndex == Context.AttributeOverridePartition.Num();
if (Context.CurrentPointIndex == NumPoints && OutPointData)
{
OutPointData->Metadata->DeleteAttribute(PCGExStaging::Tag_EntryIdx);
}

return Context.CurrentPointIndex == NumPoints;
}

#undef LOCTEXT_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ void FPCGExPrimitiveComponentDescriptor::InitFrom(const UPrimitiveComponent* Com
HLODBatchingPolicy = SourceComponent->HLODBatchingPolicy;
bEnableAutoLODGeneration = SourceComponent->bEnableAutoLODGeneration;
bNeverDistanceCull = SourceComponent->bNeverDistanceCull;

if (bInitBodyInstance) { BodyInstance.CopyBodyInstancePropertiesFrom(SourceComponent->GetBodyInstance()); }
else { BodyInstance.SetCollisionEnabled(ECollisionEnabled::Type::NoCollision); }

bAlwaysCreatePhysicsState = SourceComponent->bAlwaysCreatePhysicsState;
bMultiBodyOverlap = SourceComponent->bMultiBodyOverlap;
bTraceComplexOnMove = SourceComponent->bTraceComplexOnMove;
Expand Down Expand Up @@ -94,7 +97,7 @@ void FPCGExPrimitiveComponentDescriptor::InitComponent(UPrimitiveComponent* InCo

// Only update visibility if it's set to false to avoid massive overhead.
if (!bVisible) { TargetComponent->SetVisibility(false, false); }

TargetComponent->MinDrawDistance = MinDrawDistance;
TargetComponent->LDMaxDrawDistance = LDMaxDrawDistance;
TargetComponent->IndirectLightingCacheQuality = IndirectLightingCacheQuality;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ bool FPCGExMeshCollectionEntry::Validate(const UPCGExAssetCollection* ParentColl

void FPCGExMeshCollectionEntry::UpdateStaging(const UPCGExAssetCollection* OwningCollection, const int32 InInternalIndex, const bool bRecursive)
{

if(Staging.InternalIndex == -1 && GetDefault<UPCGExGlobalSettings>()->bDisableCollisionByDefault)
{
ISMDescriptor.BodyInstance.SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
SMDescriptor.BodyInstance.SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
}

if (bIsSubCollection)
{
Staging.Path = SubCollection.ToSoftObjectPath();
Expand Down Expand Up @@ -63,6 +70,22 @@ void UPCGExMeshCollection::EDITOR_RefreshDisplayNames()
Entry.DisplayName = FName(DisplayName);
}
}

void UPCGExMeshCollection::EDITOR_DisableCollisions()
{
Modify(true);

for (FPCGExMeshCollectionEntry& Entry : Entries)
{
Entry.ISMDescriptor.BodyInstance.SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
Entry.SMDescriptor.BodyInstance.SetCollisionEnabled(ECollisionEnabled::Type::NoCollision);
}

FPropertyChangedEvent EmptyEvent(nullptr);
PostEditChangeProperty(EmptyEvent);
MarkPackageDirty();
}

#endif

void UPCGExMeshCollection::GetAssetPaths(TSet<FSoftObjectPath>& OutPaths, const PCGExAssetCollection::ELoadingFlags Flags) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "PCGExPointsProcessor.h"
#include "Collections/PCGExMeshCollection.h"
#include "PCGExFitting.h"
#include "Collections/PCGExStaging.h"
#include "PCGExStaging.h"

#include "PCGExAssetStaging.generated.h"

Expand Down Expand Up @@ -59,7 +59,7 @@ class /*PCGEXTENDEDTOOLKIT_API*/ UPCGExAssetStagingSettings : public UPCGExPoint
EPCGExStagingOutputMode OutputMode = EPCGExStagingOutputMode::Attributes;

/** The name of the attribute to write asset path to.*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable, EditCondition="OutputMode==EPCGExStagingOutputMode::AssetData"))
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable, EditCondition="OutputMode==EPCGExStagingOutputMode::Attributes"))
FName AssetPathAttributeName = "AssetPath";

/** Distribution details */
Expand Down Expand Up @@ -100,7 +100,7 @@ struct /*PCGEXTENDEDTOOLKIT_API*/ FPCGExAssetStagingContext final : FPCGExPoints

TObjectPtr<UPCGExAssetCollection> MainCollection;

TSharedPtr<PCGExStaging::FCollectionPickDatasetPacker> CollectionPickDatasetPacker;
TSharedPtr<PCGExStaging::FPickPacker> CollectionPickDatasetPacker;
};

class /*PCGEXTENDEDTOOLKIT_API*/ FPCGExAssetStagingElement final : public FPCGExPointsProcessorElement
Expand All @@ -124,6 +124,7 @@ namespace PCGExAssetStaging
{
int32 NumPoints = 0;

bool bInherit = false;
bool bOutputWeight = false;
bool bOneMinusWeight = false;
bool bNormalizedWeight = false;
Expand Down
Loading

0 comments on commit 76ad6ac

Please sign in to comment.