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

- Started working on better editor lines:

- Changed default constructors for FEditorLineData to always consist of at least 2 points.
- Adding lines should work now.
parent 994f2088
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
...@@ -101,14 +101,30 @@ void UGPUInstancedLineComponent::Init() ...@@ -101,14 +101,30 @@ void UGPUInstancedLineComponent::Init()
CurrentTextureMarker = FIntPoint(0, 0); CurrentTextureMarker = FIntPoint(0, 0);
ClearInstances(); ClearInstances();
RegisterSerializedEditorLines();
bIsInitialized = true; bIsInitialized = true;
// Add serialized lines to be rendered immediately - pretty sure this could and should be done differently. //// Add serialized lines to be rendered immediately - pretty sure this could and should be done differently.
//for (FEditorLineData& EditorLine : EditorLines)
//{
// AddLineFromEditorData(EditorLine);
//}
}
void UGPUInstancedLineComponent::RegisterSerializedEditorLines()
{
// Here's to hoping the respective id field doesn't get serialized...
for (FEditorLineData& EditorLine : EditorLines) for (FEditorLineData& EditorLine : EditorLines)
{
if(EditorLine.RespectiveLineId == -1)
{ {
AddLineFromEditorData(EditorLine); AddLineFromEditorData(EditorLine);
} }
}
} }
FUpdateTextureRegion2D* UGPUInstancedLineComponent::CalculateTextureRegions(const FIntPoint& StartIndex, FUpdateTextureRegion2D* UGPUInstancedLineComponent::CalculateTextureRegions(const FIntPoint& StartIndex,
...@@ -173,6 +189,9 @@ void UGPUInstancedLineComponent::BeginPlay() ...@@ -173,6 +189,9 @@ void UGPUInstancedLineComponent::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
// todo don't think this is needed here
RegisterSerializedEditorLines();
//Init(); //Init();
if(!bIsInitialized) if(!bIsInitialized)
{ {
...@@ -196,8 +215,15 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha ...@@ -196,8 +215,15 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha
{ {
if (PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(UGPUInstancedLineComponent, EditorLines)) if (PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(UGPUInstancedLineComponent, EditorLines))
{ {
if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ArrayAdd // A new entry has been added
|| PropertyChangedEvent.ChangeType == EPropertyChangeType::Duplicate) if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ArrayAdd)
{
const int32 AddedAtIndex = PropertyChangedEvent.GetArrayIndex(PropertyChangedEvent.Property->GetFName().ToString());
check(AddedAtIndex != INDEX_NONE);
AddLineFromEditorData(EditorLines[AddedAtIndex]);
}
// An entry has been duplicated
else if (PropertyChangedEvent.ChangeType == EPropertyChangeType::Duplicate)
{ {
const int32 AddedAtIndex = PropertyChangedEvent.GetArrayIndex(PropertyChangedEvent.Property->GetFName().ToString()); const int32 AddedAtIndex = PropertyChangedEvent.GetArrayIndex(PropertyChangedEvent.Property->GetFName().ToString());
check(AddedAtIndex != INDEX_NONE); check(AddedAtIndex != INDEX_NONE);
...@@ -208,6 +234,7 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha ...@@ -208,6 +234,7 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha
const int32 RemovedAtIndex = PropertyChangedEvent.GetArrayIndex(PropertyChangedEvent.Property->GetFName().ToString()); const int32 RemovedAtIndex = PropertyChangedEvent.GetArrayIndex(PropertyChangedEvent.Property->GetFName().ToString());
check(RemovedAtIndex != INDEX_NONE); check(RemovedAtIndex != INDEX_NONE);
RemoveLine(EditorLines[RemovedAtIndex].RespectiveLineId); // todo test me, depends on if the data was removed already or not
} }
else if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ArrayClear) else if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ArrayClear)
{ {
...@@ -221,6 +248,14 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha ...@@ -221,6 +248,14 @@ void UGPUInstancedLineComponent::PostEditChangeChainProperty(FPropertyChangedCha
check(SetValueAtIndex != INDEX_NONE); check(SetValueAtIndex != INDEX_NONE);
} }
} }
else if (PropertyChangedEvent.Property->GetName() == "X" || PropertyChangedEvent.Property->GetName() == "Y" || PropertyChangedEvent.Property->GetName() == "Z")
{
if (PropertyChangedEvent.ChangeType == EPropertyChangeType::ValueSet)
{
}
}
else if (PropertyChangedEvent.Property->GetFName() == "TextureWidth") else if (PropertyChangedEvent.Property->GetFName() == "TextureWidth")
{ {
...@@ -340,8 +375,8 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -340,8 +375,8 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
{ {
if (Line.Num() < 2) if (Line.Num() < 2)
{ {
UE_LOG(LogTemp, Error, TEXT("UGPUInstancedLineComponent::AddLine : Can't add line with less than 2 points.")); UE_LOG(LogTemp, Error, TEXT("UGPUInstancedLineComponent::AddLine : Can't add line with less than 2 points.")); // Actually we can!
return 0; return -1;
} }
// 1. // 1.
GPULineArray& NewLineArray = LineMap.Add(NextFreeId, GPULineArray()); GPULineArray& NewLineArray = LineMap.Add(NextFreeId, GPULineArray());
...@@ -350,6 +385,8 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -350,6 +385,8 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
const int32 LineId = NextFreeId; const int32 LineId = NextFreeId;
NextFreeId++; // TODO Fix Id system as this can possibly overflow. NextFreeId++; // TODO Fix Id system as this can possibly overflow.
const int32 NumberSegments = Line.Num() - 1; const int32 NumberSegments = Line.Num() - 1;
const FIntPoint InitialTextureMarker = CurrentTextureMarker; const FIntPoint InitialTextureMarker = CurrentTextureMarker;
...@@ -373,9 +410,6 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo ...@@ -373,9 +410,6 @@ int32 UGPUInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearCo
MoveTextureMarker(); MoveTextureMarker();
CurrentTextureIndex++; CurrentTextureIndex++;
// The line is longer than the remaining space on the row of the texture, so we need to update more than just one row.
const bool bMultiRow = InitialTextureMarker.Y != CurrentTextureMarker.Y;
// Recreate the data on the heap to allow asynchronous texture update. // Recreate the data on the heap to allow asynchronous texture update.
TArray<FVector4>* TextureData = new TArray<FVector4>(Line); TArray<FVector4>* TextureData = new TArray<FVector4>(Line);
// "Mark" the first entry with w=0 as first segment of the line, and the last with w=-1 // "Mark" the first entry with w=0 as first segment of the line, and the last with w=-1
...@@ -420,6 +454,8 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point) ...@@ -420,6 +454,8 @@ bool UGPUInstancedLineComponent::AddPoint(int32 LineId, const FVector& Point)
// Get color and width of the line // Get color and width of the line
GPULineArray& Line = LineMap[LineId]; GPULineArray& Line = LineMap[LineId];
const float R = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats]; const float R = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats];
const float G = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats + 1]; const float G = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats + 1];
const float B = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats + 2]; const float B = PerInstanceSMCustomData[Line[0].Key * NumCustomDataFloats + 2];
... ...
......
...@@ -31,6 +31,7 @@ struct FEditorPoint ...@@ -31,6 +31,7 @@ struct FEditorPoint
FEditorPoint() FEditorPoint()
{ {
Point = FVector(0, 0, 0);
} }
FEditorPoint(const FVector& InPoint) FEditorPoint(const FVector& InPoint)
...@@ -49,7 +50,7 @@ struct FEditorLineData ...@@ -49,7 +50,7 @@ struct FEditorLineData
TArray<FEditorPoint> Points; TArray<FEditorPoint> Points;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
float Width; float Width = 2.0;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
FColor Color; FColor Color;
...@@ -58,13 +59,19 @@ struct FEditorLineData ...@@ -58,13 +59,19 @@ struct FEditorLineData
FEditorLineData() FEditorLineData()
{ {
Points.SetNumZeroed(2);
Width = 2.0f;
Color = FColor::Red;
} }
FEditorLineData(const TArray<FVector>& InPoints, float InWidth, const FColor& InColor) FEditorLineData(const TArray<FVector>& InPoints, float InWidth, const FColor& InColor)
: Points(InPoints), Width(InWidth), Color(InColor) : Points(InPoints), Width(InWidth), Color(InColor)
{ {
if(Points.Num() < 2)
{
Points.SetNumZeroed(2);
}
} }
}; };
...@@ -90,6 +97,8 @@ private: ...@@ -90,6 +97,8 @@ private:
void Init(); void Init();
void RegisterSerializedEditorLines();
FUpdateTextureRegion2D* CalculateTextureRegions(const FIntPoint& StartIndex, int32 NumberOfPoints, int32& NumberOfRegionsOut); FUpdateTextureRegion2D* CalculateTextureRegions(const FIntPoint& StartIndex, int32 NumberOfPoints, int32& NumberOfRegionsOut);
GPULinesMap LineMap; GPULinesMap LineMap;
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment