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

Removed unused and deprecated classes and content.

parent db1fe6c3
No related branches found
No related tags found
No related merge requests found
File deleted
File deleted
// Fill out your copyright notice in the Description page of Project Settings.
#include "BasicInstancedLineComponent.h"
UBasicInstancedLineComponent::UBasicInstancedLineComponent(const FObjectInitializer& ObjectInitializer)
{
SetCastShadow(false);
SetCollisionEnabled(ECollisionEnabled::NoCollision);
SetGenerateOverlapEvents(false);
static ConstructorHelpers::FObjectFinder<UStaticMesh>LineMeshAsset(TEXT("StaticMesh'/InstancedMeshLineRendering/line.line'"));
UStaticMesh* LineAsset = LineMeshAsset.Object;
SetStaticMesh(LineAsset);
// Three color values for now;
NumCustomDataFloats = 3;
}
int32 UBasicInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearColor Color)
{
// 1. Initialize LinesMap with new Line
// 2. Get the transform for each line segment (scale, position and rotation)
// 3. Create an instance for each segment and set the transform correctly
// 4. Mark the state dirty for rendering
// 1.
LineArray& NewLineArray = LineMap.Add(NextFreeId, LineArray());
NewLineArray.Reserve(Line.Num());
const int32 LineId = NextFreeId;
NextFreeId++; // TODO Fix Id system as this can possibly overflow.
const int32 NumberSegments = Line.Num() - 1;
for (int PointIndex = 0; PointIndex < NumberSegments; ++PointIndex)
{
// 2.
const FTransform& Transform = GetTransformForSegment(Line[PointIndex], Line[PointIndex + 1]);
// 3.
int32 InstanceId = AddInstanceWorldSpace(Transform);
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, true);
const LineSegment NewSegment(Line[PointIndex], InstanceId);
NewLineArray.Add(NewSegment);
}
// Add the last point which does not correspond to a transform:
const LineSegment LastSegment(Line.Last(), MAX_int32);
NewLineArray.Add(LastSegment);
// Might be not needed, as adding an instance auto-rebuilds everything. Slightly annoying.
MarkRenderStateDirty();
return LineId;
}
bool UBasicInstancedLineComponent::AddPoint(int32 LineId, int32 SegmentId, const FVector& Point)
{
return false;
}
bool UBasicInstancedLineComponent::AddPoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points)
{
return false;
}
bool UBasicInstancedLineComponent::UpdateLine(int32 LineId, const TArray<FVector>& Points, bool bMarkRenderStateDirty)
{
// TODO: For now assume a line always consists of consecutive instance ids - this is not the case if a point is inserted or added and multiple lines exist.
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UBasicInstancedLineComponent::UpdateLine"))
// Get the correct ref if it exists.
// As this might be called often, don't do a Contains() check for now.
LineArray& Line = LineMap[LineId];
if (Points.Num() != Line.Num())
{
// For now no addition/removal of points as this breaks instance id numbering
return false;
}
LineSegment& FirstSegment = Line[0];
const int32 StartSegmentId = FirstSegment.Value;
TArray<FTransform> NewTransforms;
NewTransforms.Reserve((Points.Num() - 1));
// Calculate new transforms:
const int32 NumberSegments = Points.Num() - 1;
for (int PointIndex = 0; PointIndex < NumberSegments; ++PointIndex)
{
const FTransform& Transform = GetTransformForSegment(Points[PointIndex], Points[PointIndex + 1]);
NewTransforms.Add(Transform);
Line[PointIndex].Key = Points[PointIndex];
}
Line.Last().Key = Points.Last();
{
TRACE_CPUPROFILER_EVENT_SCOPE(TEXT("UBasicInstancedLineComponent::UpdateLine - BatchUpdateInstancesTransforms"))
BatchUpdateInstancesTransforms(StartSegmentId, NewTransforms, true, bMarkRenderStateDirty);
}
return true;
}
bool UBasicInstancedLineComponent::UpdateLines(int32 LineIdStart, const TArray<TArray<FVector>>& Points, bool bMarkRenderStateDirty)
{
LineArray& FirstLine = LineMap[LineIdStart];
if (Points[0].Num() != FirstLine.Num())
{
// For now no addition/removal of points as this breaks instance id numbering
return false;
}
const int32 NumberSegments = Points[0].Num() - 1;
TArray<FTransform> NewTransforms;
NewTransforms.Reserve(Points.Num() * NumberSegments);
// Calculate new transforms:
for (int LineIndex = 0; LineIndex < Points.Num(); ++LineIndex)
{
// Get the correct ref if it exists.
// As this might be called often, don't do a Contains() check for now.
LineArray& Line = LineMap[LineIndex];
if (Points[LineIndex].Num() != Line.Num())
{
// For now no addition/removal of points as this breaks instance id numbering
return false;
}
LineSegment& FirstSegment = Line[0];
// Calculate new transforms:
for (int PointIndex = 0; PointIndex < NumberSegments; ++PointIndex)
{
const FTransform& Transform = GetTransformForSegment(Points[LineIndex][PointIndex], Points[LineIndex][PointIndex + 1]);
NewTransforms.Add(Transform);
Line[PointIndex].Key = Points[LineIndex][PointIndex];
}
Line.Last().Key = Points[LineIndex].Last();
}
BatchUpdateInstancesTransforms(LineIdStart, NewTransforms, true, bMarkRenderStateDirty);
return true;
}
bool UBasicInstancedLineComponent::UpdatePoint(int32 LineId, int32 PointId, const FVector& Point, bool bMarkRenderStateDirty)
{
// Get the correct ref if it exists.
// As this might be called often, don't do a Contains() check for now.
LineArray& Line = LineMap[LineId];
// If we're updating the start of the line, only one segment needs to be updated.
if (PointId == 0 && PointId < Line.Num())
{
LineSegment& Segment = Line[PointId];
Segment.Key = Point;
const FVector TargetPoint = Line[PointId + 1].Key;
const FVector StartPoint = Point;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(Segment.Value, Transform, true, bMarkRenderStateDirty);
return true;
}
// If we're updating the end of the line, only the previous segment needs to be adjusted.
if (PointId == Line.Num() - 1)
{
// Update last dummy segment
Line[PointId].Key = Point;
// Get the previous segment
const LineSegment& Segment = Line[PointId - 1];
const FVector TargetPoint = Point;
const FVector StartPoint = Segment.Key;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(Segment.Value, Transform, true, bMarkRenderStateDirty);
return true;
}
// We're in the middle of the line and need to update both adjacent segments.
else
{
const LineSegment& FirstSegment = Line[PointId - 1];
LineSegment& SecondSegment = Line[PointId];
// First segment
{
const FVector TargetPoint = Point;
const FVector StartPoint = FirstSegment.Key;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(FirstSegment.Value, Transform, true, bMarkRenderStateDirty);
}
// Second segment
{
SecondSegment.Key = Point;
const FVector TargetPoint = SecondSegment.Key;
const FVector StartPoint = Point;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(SecondSegment.Value, Transform, true, bMarkRenderStateDirty);
}
return true;
}
return false;
}
bool UBasicInstancedLineComponent::OffsetPoint(int32 LineId, int32 PointId, const FVector& Point)
{
return UpdatePoint(LineId, PointId, LineMap[LineId][PointId].Key + Point);
}
bool UBasicInstancedLineComponent::UpdatePoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points, bool bMarkRenderStateDirty)
{
return false;
}
bool UBasicInstancedLineComponent::RemoveLine(int32 LineId)
{
return false;
}
bool UBasicInstancedLineComponent::RemovePoint(int32 LineId, int32 PointId)
{
return false;
}
bool UBasicInstancedLineComponent::RemovePoints(int32 LineId, int32 StartingPointId, int32 NumberOfPoints)
{
return false;
}
FTransform UBasicInstancedLineComponent::GetTransformForSegment(const FVector& SegmentStart, const FVector& SegmentEnd) const
{
FTransform LineTransform;
//const FVector DistanceVector = SegmentEnd - SegmentStart;
const float Distance = FVector::Distance(SegmentEnd, SegmentStart);
const float DistanceScaled = Distance / SegmentLengthScale;
float Width = LineWidth;
// Align transform such that Z points to Segment End
// Y needs to point to the camera, but this needs to be done in the shader, as updating it on the cpu for each frame would kill performance.
FQuat Rotation = FRotationMatrix::MakeFromZ(SegmentEnd - SegmentStart).ToQuat();
if (DistanceScaled == 0)
{
Width = 0;
Rotation = FRotationMatrix::Identity.ToQuat();
}
LineTransform.SetScale3D({ Width, Width, DistanceScaled });
LineTransform.SetLocation(SegmentStart);
LineTransform.SetRotation(Rotation);
return LineTransform;
}
\ No newline at end of file
// Fill out your copyright notice in the Description page of Project Settings.
#include "InstancedLineComponent.h"
UInstancedLineComponent::UInstancedLineComponent(const FObjectInitializer& ObjectInitializer)
{
SetCastShadow(false);
SetCollisionEnabled(ECollisionEnabled::NoCollision);
SetGenerateOverlapEvents(false);
static ConstructorHelpers::FObjectFinder<UStaticMesh>LineMeshAsset(TEXT("StaticMesh'/InstancedMeshLineRendering/cylinder_low.cylinder_low'"));
UStaticMesh* LineAsset = LineMeshAsset.Object;
SetStaticMesh(LineAsset);
// Three color values for now;
NumCustomDataFloats = 3;
}
int32 UInstancedLineComponent::AddLine(const TArray<FVector>& Line, FLinearColor Color)
{
// 1. Initialize LinesMap with new Line
// 2. Get the transform for each line segment (scale, position and rotation)
// 3. Create an instance for each segment and set the transform correctly
// 4. Mark the state dirty for rendering
// 1.
LineArray& NewLineArray = LineMap.Add(NextFreeId, LineArray());
NewLineArray.Reserve(Line.Num());
const int32 LineId = NextFreeId;
NextFreeId++; // TODO Fix Id system as this can possibly overflow.
const int32 NumberSegments = Line.Num() - 1;
for (int PointIndex = 0; PointIndex < NumberSegments; ++PointIndex)
{
// 2.
const FTransform& Transform = GetTransformForSegment(Line[PointIndex], Line[PointIndex + 1]);
// 3.
int32 InstanceId = AddInstanceWorldSpace(Transform);
SetCustomDataValue(InstanceId, 0, Color.R, false);
SetCustomDataValue(InstanceId, 1, Color.G, false);
SetCustomDataValue(InstanceId, 2, Color.B, true);
const LineSegment NewSegment(Line[PointIndex], InstanceId);
NewLineArray.Add(NewSegment);
}
// Add the last point which does not correspond to a transform:
const LineSegment LastSegment(Line.Last(), MAX_int32);
NewLineArray.Add(LastSegment);
// Might be not needed, as adding an instance auto-rebuilds everything. Slightly annoying.
MarkRenderStateDirty();
return LineId;
}
bool UInstancedLineComponent::AddPoint(int32 LineId, int32 SegmentId, const FVector& Point)
{
return false;
}
bool UInstancedLineComponent::AddPoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points)
{
return false;
}
bool UInstancedLineComponent::UpdateLine(int32 LineId, const TArray<FVector>& Points)
{
return false;
}
bool UInstancedLineComponent::UpdatePoint(int32 LineId, int32 PointId, const FVector& Point)
{
// Get the correct ref if it exists.
// As this might be called often, don't do a Contains() check for now.
LineArray& Line = LineMap[LineId];
// If we're updating the start of the line, only one segment needs to be updated.
if(PointId == 0 && PointId < Line.Num())
{
LineSegment& Segment = Line[PointId];
Segment.Key = Point;
const FVector TargetPoint = Line[PointId + 1].Key;
const FVector StartPoint = Point;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(Segment.Value, Transform, true, true);
return true;
}
// If we're updating the end of the line, only the previous segment needs to be adjusted.
if (PointId == Line.Num() - 1)
{
// Update last dummy segment
Line[PointId].Key = Point;
// Get the previous segment
const LineSegment& Segment = Line[PointId - 1];
const FVector TargetPoint = Point;
const FVector StartPoint = Segment.Key;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(Segment.Value, Transform, true, true);
return true;
}
// We're in the middle of the line and need to update both adjacent segments.
else
{
const LineSegment& FirstSegment = Line[PointId - 1];
LineSegment& SecondSegment = Line[PointId];
// First segment
{
const FVector TargetPoint = Point;
const FVector StartPoint = FirstSegment.Key;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(FirstSegment.Value, Transform, true, true);
}
// Second segment
{
SecondSegment.Key = Point;
const FVector TargetPoint = SecondSegment.Key;
const FVector StartPoint = Point;
const FTransform& Transform = GetTransformForSegment(StartPoint, TargetPoint);
UpdateInstanceTransform(SecondSegment.Value, Transform, true, true);
}
return true;
}
return false;
}
bool UInstancedLineComponent::UpdatePoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points)
{
return false;
}
bool UInstancedLineComponent::RemoveLine(int32 LineId)
{
return false;
}
bool UInstancedLineComponent::RemovePoint(int32 LineId, int32 PointId)
{
return false;
}
bool UInstancedLineComponent::RemovePoints(int32 LineId, int32 StartingPointId, int32 NumberOfPoints)
{
return false;
}
FTransform UInstancedLineComponent::GetTransformForSegment(const FVector& SegmentStart, const FVector& SegmentEnd) const
{
FTransform LineTransform;
//const FVector DistanceVector = SegmentEnd - SegmentStart;
const float Distance = FVector::Distance(SegmentEnd, SegmentStart);
const float DistanceScaled = Distance / SegmentLengthScale;
float Width = LineWidth;
// Align transform such that Z points to Segment End
// Y needs to point to the camera, but this needs to be done in the shader, as updating it on the cpu for each frame would kill performance.
FQuat Rotation = FRotationMatrix::MakeFromZ(SegmentEnd - SegmentStart).ToQuat();
if (DistanceScaled == 0)
{
Width = 0;
Rotation = FRotationMatrix::Identity.ToQuat();
}
LineTransform.SetScale3D({ Width, Width, DistanceScaled });
LineTransform.SetLocation(SegmentStart);
LineTransform.SetRotation(Rotation);
return LineTransform;
}
\ No newline at end of file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/HierarchicalInstancedStaticMeshComponent.h"
#include "BasicInstancedLineComponent.generated.h"
/**
*
*/
typedef TPair<FVector, int32> LineSegment;
typedef TArray<LineSegment> LineArray;
typedef TMap<int32, LineArray> LinesMap;
UCLASS(Blueprintable, BlueprintType, meta = (BlueprintSpawnableComponent))
class INSTANCEDMESHLINERENDERING_API UBasicInstancedLineComponent : public UInstancedStaticMeshComponent
{
GENERATED_BODY()
public:
UBasicInstancedLineComponent(const FObjectInitializer& ObjectInitializer);
// Add functions
//UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
//int32 AddLine(const TArray<FVector>& Line);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
int32 AddLine(const TArray<FVector>& Line, FLinearColor Color);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool AddPoint(int32 LineId, int32 SegmentId, const FVector& Point);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool AddPoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points);
// Update Functions
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdateLine(int32 LineId, const TArray<FVector>& Points, bool bMarkRenderStateDirty = true);
//UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdateLines(int32 LineIdStart, const TArray<TArray<FVector>>& Points, bool bMarkRenderStateDirty = true);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdatePoint(int32 LineId, int32 PointId, const FVector& Point, bool bMarkRenderStateDirty = true);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool OffsetPoint(int32 LineId, int32 PointId, const FVector& Offset);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdatePoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points, bool bMarkRenderStateDirty = true);
// Removal Functions
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemoveLine(int32 LineId);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemovePoint(int32 LineId, int32 PointId);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemovePoints(int32 LineId, int32 StartingPointId, int32 NumberOfPoints);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool ClearAllLines()
{
return false;
}
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Components|InstancedLineComponent")
int32 GetNumberOfLines() const
{
return LineMap.Num();
}
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Components|InstancedLineComponent")
int32 GetNumberOfPointsInLine(int32 LineId) const
{
return LineMap[LineId].Num();
}
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float SegmentLengthScale = 100;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float LineWidth = 1.0;
private:
LinesMap LineMap;
int32 NextFreeId = 0;
FTransform GetTransformForSegment(const FVector& SegmentStart, const FVector& SegmentEnd) const;
};
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/HierarchicalInstancedStaticMeshComponent.h"
#include "InstancedLineComponent.generated.h"
/**
*
*/
typedef TPair<FVector, int32> LineSegment;
typedef TArray<LineSegment> LineArray;
typedef TMap<int32, LineArray> LinesMap;
UCLASS(Blueprintable, BlueprintType, meta = (BlueprintSpawnableComponent))
class INSTANCEDMESHLINERENDERING_API UInstancedLineComponent : public UHierarchicalInstancedStaticMeshComponent
{
GENERATED_BODY()
public:
UInstancedLineComponent(const FObjectInitializer& ObjectInitializer);
// Add functions
//UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
//int32 AddLine(const TArray<FVector>& Line);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
int32 AddLine(const TArray<FVector>& Line, FLinearColor Color);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool AddPoint(int32 LineId, int32 SegmentId, const FVector& Point);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool AddPoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points);
// Update Functions
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdateLine(int32 LineId, const TArray<FVector>& Points);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdatePoint(int32 LineId, int32 PointId, const FVector& Point);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool UpdatePoints(int32 LineId, int32 StartingPointId, const TArray<FVector>& Points);
// Removal Functions
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemoveLine(int32 LineId);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemovePoint(int32 LineId, int32 PointId);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool RemovePoints(int32 LineId, int32 StartingPointId, int32 NumberOfPoints);
UFUNCTION(BlueprintCallable, Category = "Components|InstancedLineComponent")
bool ClearAllLines()
{
return false;
}
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float SegmentLengthScale = 100;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float LineWidth = 1.0;
private:
LinesMap LineMap;
int32 NextFreeId = 0;
FTransform GetTransformForSegment(const FVector& SegmentStart, const FVector& SegmentEnd) const;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment