Skip to content
Snippets Groups Projects
Commit e4afd3b0 authored by David Gilbert's avatar David Gilbert :bug:
Browse files

Merge branch 'feature/better_serialization' into 'develop'

Feature/better serialization

See merge request VR-Group/unreal-development/line-plugin!1
parents e440deb9 bdf32397
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -37,8 +37,7 @@ public class InstancedMeshLineRendering : ModuleRules ...@@ -37,8 +37,7 @@ public class InstancedMeshLineRendering : ModuleRules
{ {
"CoreUObject", "CoreUObject",
"Engine", "Engine",
"Slate", "RenderCore"
"SlateCore",
// ... add private dependencies that you statically link with here ... // ... add private dependencies that you statically link with here ...
} }
); );
......
...@@ -6,20 +6,6 @@ ...@@ -6,20 +6,6 @@
#include "Components/InstancedStaticMeshComponent.h" #include "Components/InstancedStaticMeshComponent.h"
#include "GPUInstancedLineComponent.generated.h" #include "GPUInstancedLineComponent.generated.h"
/**
*
*/
//typedef TPair<FVector, TTuple<int32, int32, int32>> GPULineSegment;
// Pair of InstanceId and LinearData index.
typedef TPair<int32, int32> GPULineIndices;
// LineArray that contains indices into the instance list and the linear data.
typedef TArray<GPULineIndices> GPULineArray;
// Maps a LineId to a LineArray.
typedef TMap<int32, GPULineArray> GPULinesMap;
USTRUCT(BlueprintType) USTRUCT(BlueprintType)
struct FEditorPoint struct FEditorPoint
...@@ -55,6 +41,7 @@ struct FEditorLineData ...@@ -55,6 +41,7 @@ struct FEditorLineData
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
FColor Color; FColor Color;
UPROPERTY(VisibleAnywhere)
int32 RespectiveLineId = -1; int32 RespectiveLineId = -1;
FEditorLineData() FEditorLineData()
...@@ -74,51 +61,42 @@ struct FEditorLineData ...@@ -74,51 +61,42 @@ struct FEditorLineData
} }
}; };
USTRUCT()
UCLASS(Blueprintable, BlueprintType, meta = (BlueprintSpawnableComponent), HideCategories=("Instances", "Object", "LOD", "Physics", "Activation", "Materials", "Cooking", "Sockets", "Collision", "Mobile", "HLOD")) struct FGPULineIndices
class INSTANCEDMESHLINERENDERING_API UGPUInstancedLineComponent : public UInstancedStaticMeshComponent
{ {
GENERATED_BODY() GENERATED_USTRUCT_BODY()
private:
void MoveTextureMarker()
{
CurrentTextureMarker.X++;
if (CurrentTextureMarker.X == TextureWidth)
{
// move marker down one row:
CurrentTextureMarker.X = 0;
CurrentTextureMarker.Y = CurrentTextureMarker.Y + 1;
}
}
void UpdateWholeTexture();
void Init(); UPROPERTY()
int32 InstanceIndex;
void RegisterSerializedEditorLines(); UPROPERTY()
int32 TextureIndex;
void UpdateAllEditorLines(); FGPULineIndices() = default;
FUpdateTextureRegion2D* CalculateTextureRegions(const FIntPoint& StartIndex, int32 NumberOfPoints, int32& NumberOfRegionsOut); FGPULineIndices(int32 InstanceIndex, int32 TextureIndex)
: InstanceIndex(InstanceIndex), TextureIndex(TextureIndex) {}
};
GPULinesMap LineMap; USTRUCT()
struct FGPULineArray
{
GENERATED_USTRUCT_BODY()
TArray<FVector4> LinearLineData; UPROPERTY()
TArray<FGPULineIndices> IndexArray;
};
// Array that keeps track of editor lines. This is ONLY needed because the array can be cleared by a simple stupid button press in the UCLASS(Blueprintable, BlueprintType, meta = (BlueprintSpawnableComponent), HideCategories=(Object, LOD, Physics, Activation, Materials, "Cooking", "Sockets", "Collision", "Mobile", "HLOD"))
// details panel, circumventing the PostEditChangeChainProperty function by clearing the array first. The change callback gets called, but class INSTANCEDMESHLINERENDERING_API UGPUInstancedLineComponent : public UInstancedStaticMeshComponent
// as the EditorLines array has already been cleared, it's not possible to backtrack the removed lines. {
TArray<int32> EditorLineIds; GENERATED_BODY()
int32 NextFreeId = 0; public:
int32 CurrentTextureIndex;
FIntPoint CurrentTextureMarker;
bool bIsInitialized = false; UGPUInstancedLineComponent(const FObjectInitializer& ObjectInitializer);
virtual ~UGPUInstancedLineComponent();
protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void PostInitProperties() override; virtual void PostInitProperties() override;
...@@ -127,21 +105,48 @@ protected: ...@@ -127,21 +105,48 @@ protected:
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; // need this for the widget as for some godforsaken reason the Chain event doesn't fire... virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; // need this for the widget as for some godforsaken reason the Chain event doesn't fire...
// This is ABSURDLY hacky // This is ABSURDLY hacky
virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport = ETeleportType::None) override; virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport = ETeleportType::None) override;
#endif #endif
//virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override;
/** Applies the cached component instance data to a newly blueprint constructed component. */
//virtual void ApplyComponentInstanceData(struct FUGPUInstancedLineComponentInstanceData* ComponentInstanceData);
virtual void PostLoad() override; virtual void PostLoad() override;
virtual void OnComponentCreated() override; virtual void OnComponentCreated() override;
virtual void BeginDestroy() override; virtual void BeginDestroy() override;
public: virtual void Serialize(FArchive& Ar) override;
UGPUInstancedLineComponent(const FObjectInitializer& ObjectInitializer); private:
~UGPUInstancedLineComponent();
void MoveTextureMarker()
{
CurrentTextureMarker.X++;
if (CurrentTextureMarker.X == TextureWidth)
{
// move marker down one row:
CurrentTextureMarker.X = 0;
CurrentTextureMarker.Y = CurrentTextureMarker.Y + 1;
}
}
void Init();
//void RegisterSerializedEditorLines();
void UpdateAllEditorLines();
FUpdateTextureRegion2D* CalculateTextureRegions(const FIntPoint& StartIndex, int32 NumberOfPoints, int32& NumberOfRegionsOut);
public:
// todo // todo
void ReleaseData(); void ReleaseData();
void UpdateWholeTexture();
/** /**
* Reserves internal memory for a given amount of Lines and Segments per Line. * Reserves internal memory for a given amount of Lines and Segments per Line.
*/ */
...@@ -315,6 +320,13 @@ public: ...@@ -315,6 +320,13 @@ public:
*/ */
bool DrawLinesDirectly(int32 LineIdStart, TArray<FVector4>& Points); bool DrawLinesDirectly(int32 LineIdStart, TArray<FVector4>& Points);
bool DrawLinesDirectly(int32 LineIdStart, const TArray<FVector4>& Points);
bool DrawLinesDirectly(int32 LineIdStart, TArray<FVector4>* Points);
bool DrawLinesDirectly(int32 LineIdStart, uint8* SrcData, int32 Num);
/** /**
* This function updates the location of a given point in an existing line. * This function updates the location of a given point in an existing line.
* *
...@@ -423,7 +435,7 @@ public: ...@@ -423,7 +435,7 @@ public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Components|InstancedLineComponent") UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Components|InstancedLineComponent")
int32 GetNumberOfPointsInLine(int32 LineId) const int32 GetNumberOfPointsInLine(int32 LineId) const
{ {
return LineMap[LineId].Num(); return LineMap[LineId].IndexArray.Num();
} }
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
...@@ -438,10 +450,83 @@ public: ...@@ -438,10 +450,83 @@ public:
UPROPERTY(BlueprintReadOnly, EditAnywhere) UPROPERTY(BlueprintReadOnly, EditAnywhere)
int32 TextureHeight; int32 TextureHeight;
UPROPERTY(BlueprintReadOnly, VisibleAnywhere) UPROPERTY(Transient)
UMaterialInstanceDynamic* DynamicLineMaterial; UMaterialInstanceDynamic* DynamicLineMaterial;
UPROPERTY(EditAnywhere, DisplayName = "Lines", meta = (MakeEditWidget = true, EditFixedOrder)) UPROPERTY(EditAnywhere, DisplayName = "Lines", meta = (MakeEditWidget = true, EditFixedOrder))
TArray<FEditorLineData> EditorLines; TArray<FEditorLineData> EditorLines;
UPROPERTY()
UMaterialInterface* LineMaterialInterface;
UPROPERTY()
TMap<int32, FGPULineArray> LineMap;
//private:
UPROPERTY()
TArray<FVector4> LinearLineData;
// Array that keeps track of editor lines. This is ONLY needed because the array can be cleared by a simple stupid button press in the
// details panel, circumventing the PostEditChangeChainProperty function by clearing the array first. The change callback gets called, but
// as the EditorLines array has already been cleared, it's not possible to backtrack the removed lines.
UPROPERTY()
TArray<int32> EditorLineIds;
UPROPERTY()
int32 NextFreeId;
UPROPERTY()
int32 CurrentTextureIndex;
UPROPERTY()
FIntPoint CurrentTextureMarker;
UPROPERTY(Transient)
bool bIsInitialized = false;
}; };
/** Helper class used to preserve texture pointer across blueprint reinstancing */
//USTRUCT()
//struct FUGPUInstancedLineComponentInstanceData : public FSceneComponentInstanceData
//{
// GENERATED_BODY()
//public:
// FUGPUInstancedLineComponentInstanceData() = default;
// FUGPUInstancedLineComponentInstanceData(const UGPUInstancedLineComponent* InComponent)
// : FSceneComponentInstanceData(InComponent)
// , PositionTexture(InComponent->PositionTexture), LineMap(InComponent->LineMap)
// {}
// virtual ~FUGPUInstancedLineComponentInstanceData() = default;
//
// virtual bool ContainsData() const override
// {
// return true;
// }
//
// virtual void ApplyToComponent(UActorComponent* Component, const ECacheApplyPhase CacheApplyPhase) override
// {
// Super::ApplyToComponent(Component, CacheApplyPhase);
// CastChecked<UGPUInstancedLineComponent>(Component)->ApplyComponentInstanceData(this);
// }
//
// virtual void AddReferencedObjects(FReferenceCollector& Collector) override
// {
// Super::AddReferencedObjects(Collector);
// Collector.AddReferencedObject(PositionTexture);
// }
//
//public:
//
//
//
// //UPROPERTY()
// UTexture2D* PositionTexture;
//
// //UPROPERTY()
// UMaterialInstanceDynamic* DynamicMaterial;
//
// //UPROPERTY()
// TMap<int32, FGPULineArray> LineMap;
//};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment