Skip to content

Commit 85ac909

Browse files
committed
Swapped MeshCollection for AssetCollection on new grammar code
1 parent cd63673 commit 85ac909

15 files changed

+168
-166
lines changed

Source/PCGExtendedToolkit/Private/AssetStaging/PCGExMeshCollectionToGrammar.cpp renamed to Source/PCGExtendedToolkit/Private/AssetStaging/PCGExCollectionToModuleInfos.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
// Copyright 2025 Timothé Lapetite and contributors
22
// Released under the MIT license https://opensource.org/license/MIT/
33

4-
#include "AssetStaging/PCGExMeshCollectionToGrammar.h"
4+
#include "AssetStaging/PCGExCollectionToModuleInfos.h"
55

66

77
#include "PCGGraph.h"
88
#include "PCGPin.h"
99
#include "AssetStaging/PCGExStaging.h"
1010
#include "Collections/PCGExActorCollection.h"
11-
#include "Collections/PCGExMeshCollection.h"
11+
#include "Collections/PCGExAssetCollection.h"
1212
#include "Elements/Grammar/PCGSubdivisionBase.h"
1313

1414
#define LOCTEXT_NAMESPACE "PCGExGraphSettings"
15-
#define PCGEX_NAMESPACE MeshCollectionToGrammar
15+
#define PCGEX_NAMESPACE CollectionToModuleInfos
1616

1717
#pragma region UPCGSettings interface
1818

19-
TArray<FPCGPinProperties> UPCGExMeshCollectionToGrammarSettings::InputPinProperties() const
19+
TArray<FPCGPinProperties> UPCGExCollectionToModuleInfosSettings::InputPinProperties() const
2020
{
2121
TArray<FPCGPinProperties> PinProperties;
2222
return PinProperties;
2323
}
2424

25-
TArray<FPCGPinProperties> UPCGExMeshCollectionToGrammarSettings::OutputPinProperties() const
25+
TArray<FPCGPinProperties> UPCGExCollectionToModuleInfosSettings::OutputPinProperties() const
2626
{
2727
TArray<FPCGPinProperties> PinProperties;
2828
PCGEX_PIN_PARAM(FName("ModuleInfos"), TEXT("Module infos generated from the selected collection"), Normal)
2929
PCGEX_PIN_PARAM(PCGExStaging::OutputCollectionMapLabel, "Collection map", Normal)
3030
return PinProperties;
3131
}
3232

33-
FPCGElementPtr UPCGExMeshCollectionToGrammarSettings::CreateElement() const { return MakeShared<FPCGExMeshCollectionToGrammarElement>(); }
33+
FPCGElementPtr UPCGExCollectionToModuleInfosSettings::CreateElement() const { return MakeShared<FPCGExCollectionToModuleInfosElement>(); }
3434

3535
#pragma endregion
3636

@@ -42,17 +42,17 @@ MACRO(DebugColor, FVector4, Infos.DebugColor, FVector4(1,1,1,1))\
4242
MACRO(Entry, int64, Idx, 0)\
4343
MACRO(Category, FName, Entry->Category, NAME_None)
4444

45-
bool FPCGExMeshCollectionToGrammarElement::IsCacheable(const UPCGSettings* InSettings) const
45+
bool FPCGExCollectionToModuleInfosElement::IsCacheable(const UPCGSettings* InSettings) const
4646
{
47-
const UPCGExMeshCollectionToGrammarSettings* Settings = static_cast<const UPCGExMeshCollectionToGrammarSettings*>(InSettings);
47+
const UPCGExCollectionToModuleInfosSettings* Settings = static_cast<const UPCGExCollectionToModuleInfosSettings*>(InSettings);
4848
PCGEX_GET_OPTION_STATE(Settings->CacheData, bDefaultCacheNodeOutput)
4949
}
5050

51-
bool FPCGExMeshCollectionToGrammarElement::ExecuteInternal(FPCGContext* Context) const
51+
bool FPCGExCollectionToModuleInfosElement::ExecuteInternal(FPCGContext* Context) const
5252
{
53-
PCGEX_SETTINGS(MeshCollectionToGrammar)
53+
PCGEX_SETTINGS(CollectionToModuleInfos)
5454

55-
UPCGExMeshCollection* MainCollection = PCGExHelpers::LoadBlocking_AnyThread(Settings->MeshCollection);
55+
UPCGExAssetCollection* MainCollection = PCGExHelpers::LoadBlocking_AnyThread(Settings->AssetCollection);
5656

5757
if (!MainCollection)
5858
{
@@ -76,15 +76,15 @@ bool FPCGExMeshCollectionToGrammarElement::ExecuteInternal(FPCGContext* Context)
7676
TSet<FName> UniqueSymbols;
7777
UniqueSymbols.Reserve(100);
7878

79-
TMap<const FPCGExMeshCollectionEntry*, double> SizeCache;
79+
TMap<const FPCGExAssetCollectionEntry*, double> SizeCache;
8080
SizeCache.Reserve(100);
8181

82-
TArray<PCGExMeshCollectionToGrammar::FModule> Modules;
82+
TArray<PCGExCollectionToGrammar::FModule> Modules;
8383
Modules.Reserve(100);
8484

8585
FlattenCollection(Packer, MainCollection, Settings, Modules, UniqueSymbols, SizeCache);
8686

87-
for (const PCGExMeshCollectionToGrammar::FModule& Module : Modules)
87+
for (const PCGExCollectionToGrammar::FModule& Module : Modules)
8888
{
8989
const int64 Key = Metadata->AddEntry();
9090
#define PCGEX_MODULE_OUT(_NAME, _TYPE, _GETTER, _DEFAULT) _NAME##Attribute->SetValue(Key, Module._GETTER);
@@ -106,20 +106,20 @@ bool FPCGExMeshCollectionToGrammarElement::ExecuteInternal(FPCGContext* Context)
106106
return true;
107107
}
108108

109-
void FPCGExMeshCollectionToGrammarElement::FlattenCollection(
109+
void FPCGExCollectionToModuleInfosElement::FlattenCollection(
110110
const TSharedPtr<PCGExStaging::FPickPacker>& Packer,
111-
UPCGExMeshCollection* Collection,
112-
const UPCGExMeshCollectionToGrammarSettings* Settings,
113-
TArray<PCGExMeshCollectionToGrammar::FModule>& OutModules,
111+
UPCGExAssetCollection* Collection,
112+
const UPCGExCollectionToModuleInfosSettings* Settings,
113+
TArray<PCGExCollectionToGrammar::FModule>& OutModules,
114114
TSet<FName>& UniqueSymbols,
115-
TMap<const FPCGExMeshCollectionEntry*, double>& SizeCache) const
115+
TMap<const FPCGExAssetCollectionEntry*, double>& SizeCache) const
116116
{
117117
if (!Collection) { return; }
118118

119119
const PCGExAssetCollection::FCache* Cache = Collection->LoadCache();
120120
const int32 NumEntries = Cache->Main->Order.Num();
121121

122-
const FPCGExMeshCollectionEntry* Entry = nullptr;
122+
const FPCGExAssetCollectionEntry* Entry = nullptr;
123123
const UPCGExAssetCollection* EntryHost = nullptr;
124124

125125
for (int i = 0; i < NumEntries; i++)
@@ -129,11 +129,11 @@ void FPCGExMeshCollectionToGrammarElement::FlattenCollection(
129129

130130
if (Entry->bIsSubCollection && Entry->SubGrammarMode == EPCGExGrammarSubCollectionMode::Flatten)
131131
{
132-
FlattenCollection(Packer, Entry->SubCollection, Settings, OutModules, UniqueSymbols, SizeCache);
132+
FlattenCollection(Packer, Entry->GetSubCollection<UPCGExAssetCollection>(), Settings, OutModules, UniqueSymbols, SizeCache);
133133
continue;
134134
}
135135

136-
PCGExMeshCollectionToGrammar::FModule& Module = OutModules.Emplace_GetRef();
136+
PCGExCollectionToGrammar::FModule& Module = OutModules.Emplace_GetRef();
137137
if (!Entry->FixModuleInfos(Collection, Module.Infos)
138138
|| (Settings->bSkipEmptySymbol && Module.Infos.Symbol.IsNone()) )
139139
{

Source/PCGExtendedToolkit/Private/Collections/PCGExAssetCollection.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,49 @@ const FPCGExFittingVariations& FPCGExAssetCollectionEntry::GetVariations(const U
168168
return Variations;
169169
}
170170

171+
double FPCGExAssetCollectionEntry::GetGrammarSize(const UPCGExAssetCollection* Host) const
172+
{
173+
if (!bIsSubCollection)
174+
{
175+
if (GrammarSource == EPCGExEntryVariationMode::Local) { return AssetGrammar.GetSize(Staging.Bounds); }
176+
return Host->GlobalAssetGrammar.GetSize(Staging.Bounds);
177+
}
178+
179+
if (InternalSubCollection)
180+
{
181+
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Flatten) { return 0; }
182+
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Inherit) { return InternalSubCollection->CollectionGrammar.GetSize(InternalSubCollection); }
183+
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Override) { return CollectionGrammar.GetSize(InternalSubCollection); }
184+
}
185+
186+
return 0;
187+
}
188+
189+
double FPCGExAssetCollectionEntry::GetGrammarSize(const UPCGExAssetCollection* Host, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
190+
{
191+
if (!SizeCache) { return GetGrammarSize(Host); }
192+
if (double* CachedSize = SizeCache->Find(this)) { return *CachedSize; }
193+
return SizeCache->Add(this, GetGrammarSize(Host));
194+
}
195+
196+
bool FPCGExAssetCollectionEntry::FixModuleInfos(const UPCGExAssetCollection* Host, FPCGSubdivisionSubmodule& OutModule, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
197+
{
198+
if (!bIsSubCollection)
199+
{
200+
if (GrammarSource == EPCGExEntryVariationMode::Local) { AssetGrammar.Fix(Staging.Bounds, OutModule); }
201+
else { Host->GlobalAssetGrammar.Fix(Staging.Bounds, OutModule); }
202+
}
203+
204+
if (InternalSubCollection)
205+
{
206+
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Inherit) { InternalSubCollection->CollectionGrammar.Fix(InternalSubCollection, OutModule); }
207+
else if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Override) { CollectionGrammar.Fix(InternalSubCollection, OutModule); }
208+
else { return false; }
209+
}
210+
211+
return true;
212+
}
213+
171214
#if WITH_EDITOR
172215
void FPCGExAssetCollectionEntry::EDITOR_Sanitize()
173216
{

Source/PCGExtendedToolkit/Private/Collections/PCGExDetailsGrammar.cpp renamed to Source/PCGExtendedToolkit/Private/Collections/PCGExAssetGrammar.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Released under the MIT license https://opensource.org/license/MIT/
33

44

5-
#include "Collections/PCGExMeshGrammar.h"
5+
#include "Collections/PCGExAssetGrammar.h"
66

77
#include "UObject/Object.h"
88
#include "UObject/Package.h"
99
#include "Collections/PCGExAssetCollection.h"
1010
#include "Collections/PCGExMeshCollection.h"
1111
#include "Elements/Grammar/PCGSubdivisionBase.h"
1212

13-
double FPCGExMeshGrammarDetails::GetSize(const FBox& InBounds, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
13+
double FPCGExAssetGrammarDetails::GetSize(const FBox& InBounds, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
1414
{
1515
const FVector S = InBounds.GetSize();
1616

@@ -27,26 +27,26 @@ double FPCGExMeshGrammarDetails::GetSize(const FBox& InBounds, TMap<const FPCGEx
2727
return 0;
2828
}
2929

30-
void FPCGExMeshGrammarDetails::Fix(const FBox& InBounds, FPCGSubdivisionSubmodule& OutSubmodule, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
30+
void FPCGExAssetGrammarDetails::Fix(const FBox& InBounds, FPCGSubdivisionSubmodule& OutSubmodule, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
3131
{
3232
OutSubmodule.Symbol = Symbol;
3333
OutSubmodule.DebugColor = DebugColor;
3434
OutSubmodule.bScalable = ScaleMode == EPCGExGrammarScaleMode::Flex;
3535
OutSubmodule.Size = GetSize(InBounds);
3636
}
3737

38-
double FPCGExMeshCollectionGrammarDetails::GetSize(const UPCGExMeshCollection* InCollection, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
38+
double FPCGExCollectionGrammarDetails::GetSize(const UPCGExAssetCollection* InCollection, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
3939
{
4040
if (SizeMode == EPCGExCollectionGrammarSize::Fixed)
4141
{
4242
return Size;
4343
}
4444

45-
UPCGExMeshCollection* Collection = const_cast<UPCGExMeshCollection*>(InCollection);
45+
UPCGExAssetCollection* Collection = const_cast<UPCGExAssetCollection*>(InCollection);
4646
const PCGExAssetCollection::FCache* Cache = Collection->LoadCache();
4747
const int32 NumEntries = Cache->Main->Order.Num();
4848

49-
const FPCGExMeshCollectionEntry* Entry = nullptr;
49+
const FPCGExAssetCollectionEntry* Entry = nullptr;
5050
const UPCGExAssetCollection* EntryHost = nullptr;
5151

5252
double CompoundSize = 0;
@@ -58,7 +58,7 @@ double FPCGExMeshCollectionGrammarDetails::GetSize(const UPCGExMeshCollection* I
5858
{
5959
Collection->GetEntryAt(Entry, i, EntryHost);
6060
if (!Entry) { continue; }
61-
CompoundSize = FMath::Min(CompoundSize, Entry->GetGrammarSize(static_cast<const UPCGExMeshCollection*>(EntryHost), SizeCache));
61+
CompoundSize = FMath::Min(CompoundSize, Entry->GetGrammarSize(static_cast<const UPCGExAssetCollection*>(EntryHost), SizeCache));
6262
}
6363
}
6464
else if (SizeMode == EPCGExCollectionGrammarSize::Max)
@@ -69,7 +69,7 @@ double FPCGExMeshCollectionGrammarDetails::GetSize(const UPCGExMeshCollection* I
6969
{
7070
Collection->GetEntryAt(Entry, i, EntryHost);
7171
if (!Entry) { continue; }
72-
CompoundSize = FMath::Max(CompoundSize, Entry->GetGrammarSize(static_cast<const UPCGExMeshCollection*>(EntryHost), SizeCache));
72+
CompoundSize = FMath::Max(CompoundSize, Entry->GetGrammarSize(static_cast<const UPCGExAssetCollection*>(EntryHost), SizeCache));
7373
}
7474
}
7575
else if (SizeMode == EPCGExCollectionGrammarSize::Average)
@@ -81,7 +81,7 @@ double FPCGExMeshCollectionGrammarDetails::GetSize(const UPCGExMeshCollection* I
8181
Collection->GetEntryAt(Entry, i, EntryHost);
8282
if (!Entry) { continue; }
8383

84-
CompoundSize += Entry->GetGrammarSize(static_cast<const UPCGExMeshCollection*>(EntryHost), SizeCache);
84+
CompoundSize += Entry->GetGrammarSize(static_cast<const UPCGExAssetCollection*>(EntryHost), SizeCache);
8585
NumSamples++;
8686
}
8787

@@ -91,7 +91,7 @@ double FPCGExMeshCollectionGrammarDetails::GetSize(const UPCGExMeshCollection* I
9191
return CompoundSize;
9292
}
9393

94-
void FPCGExMeshCollectionGrammarDetails::Fix(const UPCGExMeshCollection* InCollection, FPCGSubdivisionSubmodule& OutSubmodule, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
94+
void FPCGExCollectionGrammarDetails::Fix(const UPCGExAssetCollection* InCollection, FPCGSubdivisionSubmodule& OutSubmodule, TMap<const FPCGExAssetCollectionEntry*, double>* SizeCache) const
9595
{
9696
OutSubmodule.Symbol = Symbol;
9797
OutSubmodule.DebugColor = DebugColor;

Source/PCGExtendedToolkit/Private/Collections/PCGExMeshCollection.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,7 @@ bool FPCGExMeshCollectionEntry::Validate(const UPCGExAssetCollection* ParentColl
262262
return Super::Validate(ParentCollection);
263263
}
264264

265-
double FPCGExMeshCollectionEntry::GetGrammarSize(const UPCGExMeshCollection* Host) const
266-
{
267-
if (!bIsSubCollection)
268-
{
269-
if (GrammarSource == EPCGExEntryVariationMode::Local) { return MeshGrammar.GetSize(Staging.Bounds); }
270-
return Host->GlobalMeshGrammar.GetSize(Staging.Bounds);
271-
}
272265

273-
if (SubCollection)
274-
{
275-
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Flatten) { return 0; }
276-
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Inherit) { return SubCollection->CollectionGrammar.GetSize(SubCollection); }
277-
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Override) { return CollectionGrammar.GetSize(SubCollection); }
278-
}
279-
280-
return 0;
281-
}
282-
283-
double FPCGExMeshCollectionEntry::GetGrammarSize(const UPCGExMeshCollection* Host, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
284-
{
285-
if (!SizeCache) { return GetGrammarSize(Host); }
286-
if (double* CachedSize = SizeCache->Find(this)) { return *CachedSize; }
287-
return SizeCache->Add(this, GetGrammarSize(Host));
288-
}
289266

290267
#if WITH_EDITOR
291268
void FPCGExMeshCollectionEntry::EDITOR_Sanitize()
@@ -325,25 +302,6 @@ void FPCGExMeshCollectionEntry::BuildMicroCache()
325302
MicroCache = NewCache;
326303
}
327304

328-
329-
bool FPCGExMeshCollectionEntry::FixModuleInfos(const UPCGExMeshCollection* Host, FPCGSubdivisionSubmodule& OutModule, TMap<const FPCGExMeshCollectionEntry*, double>* SizeCache) const
330-
{
331-
if (!bIsSubCollection)
332-
{
333-
if (GrammarSource == EPCGExEntryVariationMode::Local) { MeshGrammar.Fix(Staging.Bounds, OutModule); }
334-
else { Host->GlobalMeshGrammar.Fix(Staging.Bounds, OutModule); }
335-
}
336-
337-
if (SubCollection)
338-
{
339-
if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Inherit) { SubCollection->CollectionGrammar.Fix(SubCollection, OutModule); }
340-
else if (SubGrammarMode == EPCGExGrammarSubCollectionMode::Override) { CollectionGrammar.Fix(SubCollection, OutModule); }
341-
else { return false; }
342-
}
343-
344-
return true;
345-
}
346-
347305
void FPCGExMeshCollectionEntry::UpdateStaging(const UPCGExAssetCollection* OwningCollection, const int32 InInternalIndex, const bool bRecursive)
348306
{
349307
ClearManagedSockets();

Source/PCGExtendedToolkit/Public/AssetStaging/PCGExMeshCollectionToGrammar.h renamed to Source/PCGExtendedToolkit/Public/AssetStaging/PCGExCollectionToModuleInfos.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
#include "PCGExPointsProcessor.h"
88
#include "PCGExStaging.h"
99
#include "Elements/Grammar/PCGSubdivisionBase.h"
10-
#include "PCGExMeshCollectionToGrammar.generated.h"
10+
#include "PCGExCollectionToModuleInfos.generated.h"
1111

12-
class UPCGExMeshCollection;
12+
class UPCGExAssetCollection;
1313

14-
namespace PCGExMeshCollectionToGrammar
14+
namespace PCGExCollectionToGrammar
1515
{
1616
struct FModule
1717
{
1818
FModule() = default;
1919
FPCGSubdivisionSubmodule Infos;
20-
const FPCGExMeshCollectionEntry* Entry = nullptr;
20+
const FPCGExAssetCollectionEntry* Entry = nullptr;
2121
int64 Idx;
2222
};
2323
}
2424

2525
UCLASS(MinimalAPI, BlueprintType, ClassGroup = (Procedural), meta=(PCGExNodeLibraryDoc="assets-management/asset-collection-to-set"))
26-
class UPCGExMeshCollectionToGrammarSettings : public UPCGSettings
26+
class UPCGExCollectionToModuleInfosSettings : public UPCGSettings
2727
{
2828
GENERATED_BODY()
2929

30-
friend class FPCGExMeshCollectionToGrammarElement;
30+
friend class FPCGExCollectionToModuleInfosElement;
3131

3232
public:
3333
//~Begin UPCGSettings
3434
#if WITH_EDITOR
3535
PCGEX_DUMMY_SETTINGS_MEMBERS
36-
PCGEX_NODE_INFOS(MeshCollectionToGrammar, "Collection to Module Infos", "Converts a mesh collection to a grammar-friendly attribute set that can be used as module infos.");
36+
PCGEX_NODE_INFOS(CollectionToModuleInfos, "Collection to Module Infos", "Converts an asset collection to a grammar-friendly attribute set that can be used as module infos.");
3737
virtual EPCGSettingsType GetType() const override { return EPCGSettingsType::Param; }
3838
#endif
3939

@@ -45,7 +45,7 @@ class UPCGExMeshCollectionToGrammarSettings : public UPCGSettings
4545

4646
/** The mesh collection to read module infos from */
4747
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable))
48-
TSoftObjectPtr<UPCGExMeshCollection> MeshCollection;
48+
TSoftObjectPtr<UPCGExAssetCollection> AssetCollection;
4949

5050
/** If enabled, allows duplicate entries (duplicate is same symbol) */
5151
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta=(PCG_Overridable))
@@ -88,7 +88,7 @@ class UPCGExMeshCollectionToGrammarSettings : public UPCGSettings
8888
EPCGExOptionState CacheData = EPCGExOptionState::Default;
8989
};
9090

91-
class FPCGExMeshCollectionToGrammarElement final : public IPCGElement
91+
class FPCGExCollectionToModuleInfosElement final : public IPCGElement
9292
{
9393
public:
9494
virtual bool IsCacheable(const UPCGSettings* InSettings) const override;
@@ -101,9 +101,9 @@ class FPCGExMeshCollectionToGrammarElement final : public IPCGElement
101101

102102
void FlattenCollection(
103103
const TSharedPtr<PCGExStaging::FPickPacker>& Packer,
104-
UPCGExMeshCollection* Collection,
105-
const UPCGExMeshCollectionToGrammarSettings* Settings,
106-
TArray<PCGExMeshCollectionToGrammar::FModule>& OutModules,
104+
UPCGExAssetCollection* Collection,
105+
const UPCGExCollectionToModuleInfosSettings* Settings,
106+
TArray<PCGExCollectionToGrammar::FModule>& OutModules,
107107
TSet<FName>& OutSymbols,
108-
TMap<const FPCGExMeshCollectionEntry*, double>& SizeCache) const;
108+
TMap<const FPCGExAssetCollectionEntry*, double>& SizeCache) const;
109109
};

0 commit comments

Comments
 (0)