Added support for receiving collections

This commit is contained in:
Jedd Morgan 2023-08-30 18:33:36 +01:00
Родитель 6aa4afbd84
Коммит a60d4fef56
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 14CD372253EDE9E2
9 изменённых файлов: 172 добавлений и 3 удалений

Двоичные данные
Content/Converters/DefaultCollectionConverter.uasset Normal file

Двоичный файл не отображается.

Двоичные данные
Content/Examples/BlueprintReceiving.uasset

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,53 @@
#include "Conversion/Converters/CollectionConverter.h"
#include "Objects/Collection.h"
UCollectionConverter::UCollectionConverter()
{
SpeckleTypes.Add(UCollection::StaticClass());
ActorType = AActor::StaticClass();
ActorMobility = EComponentMobility::Static;
}
UObject* UCollectionConverter::ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World,
TScriptInterface<ISpeckleConverter>& AvailableConverters )
{
const UCollection* p = Cast<UCollection>(SpeckleBase);
if(p == nullptr) return nullptr;
return CollectionToNative(p, World);
}
AActor* UCollectionConverter::CollectionToNative(const UCollection*, UWorld* World)
{
AActor* MeshActor = CreateEmptyActor(World);
return MeshActor;
}
AActor* UCollectionConverter::CreateEmptyActor(UWorld* World, const FActorSpawnParameters& SpawnParameters)
{
AActor* Actor = World->SpawnActor<AActor>(ActorType, SpawnParameters);
USceneComponent* Scene = NewObject<USceneComponent>(Actor, "Root");
Actor->SetRootComponent(Scene);
Scene->RegisterComponent();
Scene->SetMobility(ActorMobility);
return Actor;
}
UBase* UCollectionConverter::ConvertToSpeckle_Implementation(const UObject* Object)
{
return nullptr; //TODO implement ToSpeckle function
}
UCollection* UCollectionConverter::CollectionToSpeckle(const AActor* Object)
{
return nullptr; //TODO implement ToSpeckle function
}

Просмотреть файл

@ -5,6 +5,7 @@
#include "API/SpeckleSerializer.h"
#include "Conversion/Converters/AggregateConverter.h"
#include "Conversion/Converters/BlockConverter.h"
#include "Conversion/Converters/CollectionConverter.h"
#include "Conversion/Converters/PointCloudConverter.h"
#include "Conversion/Converters/StaticMeshConverter.h"
#include "Conversion/Converters/MaterialConverter.h"
@ -22,6 +23,7 @@ USpeckleConverterComponent::USpeckleConverterComponent()
static ConstructorHelpers::FObjectFinder<UPointCloudConverter> PointCloudConverter(TEXT("PointCloudConverter'/SpeckleUnreal/Converters/DefaultPointCloudConverter.DefaultPointCloudConverter'"));
static ConstructorHelpers::FObjectFinder<UBlockConverter> BlockConverter(TEXT("BlockConverter'/SpeckleUnreal/Converters/DefaultBlockConverter.DefaultBlockConverter'"));
static ConstructorHelpers::FObjectFinder<UMaterialConverter> MaterialConverter(TEXT("MaterialConverter'/SpeckleUnreal/Converters/DefaultMaterialConverter.DefaultMaterialConverter'"));
static ConstructorHelpers::FObjectFinder<UCollectionConverter> CollectionConverter(TEXT("CollectionConverter'/SpeckleUnreal/Converters/DefaultCollectionConverter.DefaultCollectionConverter'"));
static ConstructorHelpers::FObjectFinder<UObject> CameraConverter(TEXT("CameraConverter'/SpeckleUnreal/Converters/DefaultCameraConverter.DefaultCameraConverter'"));
//static ConstructorHelpers::FObjectFinder<ULightConverter> LightConverter(TEXT("LightConverter'/SpeckleUnreal/Converters/DefaultLightConverter.DefaultLightConverter'"));
@ -31,6 +33,7 @@ USpeckleConverterComponent::USpeckleConverterComponent()
SpeckleConverter->SpeckleConverters.Add(PointCloudConverter.Object);
SpeckleConverter->SpeckleConverters.Add(BlockConverter.Object);
SpeckleConverter->SpeckleConverters.Add(MaterialConverter.Object);
SpeckleConverter->SpeckleConverters.Add(CollectionConverter.Object);
SpeckleConverter->SpeckleConverters.Add(CameraConverter.Object);
//SpeckleConverter->SpeckleConverters.Add(LightConverter.Object);
@ -41,8 +44,19 @@ AActor* USpeckleConverterComponent::RecursivelyConvertToNative(AActor* AOwner, c
const TScriptInterface<ITransport>& LocalTransport, bool DisplayProgressBar, TArray<AActor*>& OutActors)
{
float ObjectsToConvert{};
Base->TryGetDynamicNumber("totalChildrenCount", ObjectsToConvert);
if(Base->TotalChildrenCount > 0)
{
ObjectsToConvert = Base->TotalChildrenCount;
}
else
{
Base->TryGetDynamicNumber("totalChildrenCount", ObjectsToConvert);
}
if(ObjectsToConvert <= 1)
{
ObjectsToConvert = 99999; //A large number
}
// Progress bar
FScopedSlowTask Progress(ObjectsToConvert + 2,
LOCTEXT("SpeckleConvertoNative","Converting Speckle Objects to Native"), DisplayProgressBar);

Просмотреть файл

@ -0,0 +1,20 @@
#include "Objects/Collection.h"
bool UCollection::Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport)
{
if(!Super::Parse(Obj, ReadTransport)) return false;
// Parse Name property
if(!Obj->TryGetStringField("name", Name)) return false;
//DynamicProperties.Remove("name"); //Don't remove from dynamic, as we pick this up to name the actor
// Parse collectionType
if(!Obj->TryGetStringField("collectionType", CollectionType)) return false;
DynamicProperties.Remove("collectionType");
return true;
}

Просмотреть файл

@ -0,0 +1,53 @@
#pragma once
#include "CoreMinimal.h"
#include "Conversion/SpeckleConverter.h"
#include "Engine/EngineTypes.h"
#include "Engine/World.h"
#include "CollectionConverter.generated.h"
class UCollection;
/**
* Converts Speckle Mesh objects into native actors with a procedural mesh component.
*
* Compared with the StaticMeshConverter, this converter has some serious limitations
* - Cannot convert displayValues,
* - N-gon faces will be ignored,
* - Meshes are transient, and won't persist on level reload
*/
UCLASS()
class SPECKLEUNREAL_API UCollectionConverter : public UObject, public ISpeckleConverter
{
GENERATED_BODY()
CONVERTS_SPECKLE_TYPES()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
TSubclassOf<AActor> ActorType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ToNative")
TEnumAsByte<EComponentMobility::Type> ActorMobility;
// Sets default values for this actor's properties
UCollectionConverter();
virtual UObject* ConvertToNative_Implementation(const UBase* SpeckleBase, UWorld* World,
TScriptInterface<ISpeckleConverter>& AvailableConverters) override;
virtual UBase* ConvertToSpeckle_Implementation(const UObject* Object) override;
UFUNCTION(BlueprintCallable, Category="ToNative")
virtual AActor* CollectionToNative(const UCollection* SpeckleCollection, UWorld* World);
UFUNCTION(BlueprintCallable, Category="ToNative")
virtual UCollection* CollectionToSpeckle(const AActor* Object);
virtual AActor* CreateEmptyActor(UWorld* World, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());
};

Просмотреть файл

@ -34,6 +34,7 @@ public:
UObject* ConvertToNative(const UBase* SpeckleBase, UWorld* World, UPARAM(ref) TScriptInterface<ISpeckleConverter>& AvailableConverters);
/// Tries to convert a given Actor or Component into a Speckle Base
/// NOT IMPLEMENTED!!!
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="ToSpeckle")
UBase* ConvertToSpeckle(const UObject* Object);

Просмотреть файл

@ -33,7 +33,7 @@ public:
FString Id;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Speckle|Objects")
int64 TotalChildrenCount;
int64 TotalChildrenCount = 0;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Speckle|Objects")
FString ApplicationId;

Просмотреть файл

@ -0,0 +1,28 @@
#pragma once
#include "CoreMinimal.h"
#include "Objects/Base.h"
#include "Collection.generated.h"
/**
*
*/
UCLASS()
class SPECKLEUNREAL_API UCollection : public UBase
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
FString Name;
UPROPERTY(BlueprintReadWrite, Category="Speckle|Objects")
FString CollectionType;
UCollection() : UBase(TEXT("Speckle.Core.Models.Collection")) {}
virtual bool Parse(const TSharedPtr<FJsonObject> Obj, const TScriptInterface<ITransport> ReadTransport) override;
};