mirror of
https://github.com/sinbad/StevesUEHelpers.git
synced 2025-02-23 17:45:23 +00:00
Add mesh support to visualisation component
This commit is contained in:
parent
cf0c34a677
commit
e210759e7b
@ -9,7 +9,6 @@ void FStevesDebugRenderSceneProxy::GetDynamicMeshElements(const TArray<const FSc
|
|||||||
{
|
{
|
||||||
FDebugRenderSceneProxy::GetDynamicMeshElements(Views, ViewFamily, VisibilityMap, Collector);
|
FDebugRenderSceneProxy::GetDynamicMeshElements(Views, ViewFamily, VisibilityMap, Collector);
|
||||||
|
|
||||||
|
|
||||||
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
|
||||||
{
|
{
|
||||||
if (VisibilityMap & (1 << ViewIndex))
|
if (VisibilityMap & (1 << ViewIndex))
|
||||||
@ -60,6 +59,24 @@ void FStevesDebugRenderSceneProxy::GetDynamicMeshElements(const TArray<const FSc
|
|||||||
16,
|
16,
|
||||||
SDPG_Foreground);
|
SDPG_Foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (const auto& Mesh : MeshesImproved)
|
||||||
|
{
|
||||||
|
FDynamicMeshBuilder MeshBuilder(View->GetFeatureLevel());
|
||||||
|
MeshBuilder.AddVertices(Mesh.Vertices);
|
||||||
|
MeshBuilder.AddTriangles(Mesh.Indices);
|
||||||
|
|
||||||
|
// Parent caches these (only within this function) but let's assume that's not worth it. Will people really
|
||||||
|
// have lots of meshes with a shared colour in this single context to make it worth it?
|
||||||
|
const auto MatRenderProxy = new(FMemStack::Get()) FColoredMaterialRenderProxy(GEngine->WireframeMaterial->GetRenderProxy(), Mesh.Color);
|
||||||
|
FDynamicMeshBuilderSettings Settings;
|
||||||
|
Settings.bWireframe = true;
|
||||||
|
Settings.bUseSelectionOutline = false;
|
||||||
|
Settings.bUseWireframeSelectionColoring = true;
|
||||||
|
MeshBuilder.GetMesh(Mesh.LocalToWorld, MatRenderProxy, SDPG_World, Settings, nullptr, ViewIndex, Collector);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "StevesEditorVisComponent.h"
|
#include "StevesEditorVisComponent.h"
|
||||||
|
#include "StaticMeshResources.h"
|
||||||
#include "StevesDebugRenderSceneProxy.h"
|
#include "StevesDebugRenderSceneProxy.h"
|
||||||
|
|
||||||
UStevesEditorVisComponent::UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer)
|
UStevesEditorVisComponent::UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer)
|
||||||
@ -104,6 +105,31 @@ FPrimitiveSceneProxy* UStevesEditorVisComponent::CreateSceneProxy()
|
|||||||
LocalX, LocalY, LocalZ,
|
LocalX, LocalY, LocalZ,
|
||||||
HalfH, Capsule.Colour));
|
HalfH, Capsule.Colour));
|
||||||
}
|
}
|
||||||
|
for (auto& Mesh : Meshes)
|
||||||
|
{
|
||||||
|
// Apply local rotation first then parent transform
|
||||||
|
if (IsValid(Mesh.Mesh))
|
||||||
|
{
|
||||||
|
const FTransform CombinedXForm = FTransform(Mesh.Rotation, Mesh.Location, Mesh.Scale) * XForm;
|
||||||
|
const FStaticMeshLODResources& Lod = Mesh.Mesh->GetLODForExport(0);
|
||||||
|
TArray<FDynamicMeshVertex> Vertices;
|
||||||
|
TArray<uint32> Indices;
|
||||||
|
|
||||||
|
Lod.IndexBuffer.GetCopy(Indices);
|
||||||
|
auto& PosBuffer = Lod.VertexBuffers.PositionVertexBuffer;
|
||||||
|
uint32 NumVerts = PosBuffer.GetNumVertices();
|
||||||
|
Vertices.Reserve(NumVerts);
|
||||||
|
for (uint32 i = 0; i < NumVerts; ++i)
|
||||||
|
{
|
||||||
|
Vertices.Add(FDynamicMeshVertex(PosBuffer.VertexPosition(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ret->MeshesImproved.Add(FStevesDebugRenderSceneProxy::FDebugMesh(CombinedXForm.ToMatrixWithScale(), Vertices, Indices, Mesh.Colour));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
|
|
||||||
@ -166,6 +192,15 @@ FBoxSphereBounds UStevesEditorVisComponent::CalcBounds(const FTransform& LocalTo
|
|||||||
DBox = DBox.TransformBy(XForm);
|
DBox = DBox.TransformBy(XForm);
|
||||||
B = B + FBoxSphereBounds(DBox);
|
B = B + FBoxSphereBounds(DBox);
|
||||||
}
|
}
|
||||||
|
for (auto& Mesh : Meshes)
|
||||||
|
{
|
||||||
|
if (IsValid(Mesh.Mesh))
|
||||||
|
{
|
||||||
|
const FTransform XForm = FTransform(Mesh.Rotation, Mesh.Location, Mesh.Scale);
|
||||||
|
B = B + Mesh.Mesh->GetBounds().TransformBy(XForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return B.TransformBy(LocalToWorld);
|
return B.TransformBy(LocalToWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,11 +92,30 @@ public:
|
|||||||
int NumSegments;
|
int NumSegments;
|
||||||
FColor Color;
|
FColor Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FDebugMesh
|
||||||
|
{
|
||||||
|
FDebugMesh(const FMatrix& InLocalToWorld,
|
||||||
|
const TArray<FDynamicMeshVertex>& InVertices,
|
||||||
|
const TArray<uint32>& InIndices,
|
||||||
|
const FColor& InColor)
|
||||||
|
: LocalToWorld(InLocalToWorld),
|
||||||
|
Vertices(InVertices),
|
||||||
|
Indices(InIndices),
|
||||||
|
Color(InColor)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FMatrix LocalToWorld;
|
||||||
|
TArray<FDynamicMeshVertex> Vertices;
|
||||||
|
TArray <uint32> Indices;
|
||||||
|
FColor Color;
|
||||||
|
};
|
||||||
|
|
||||||
TArray<FDebugCircle> Circles;
|
TArray<FDebugCircle> Circles;
|
||||||
TArray<FDebugArc> Arcs;
|
TArray<FDebugArc> Arcs;
|
||||||
TArray<FDebugCylinder> CylindersImproved; // Because we need our own
|
TArray<FDebugCylinder> CylindersImproved; // Because we need our own
|
||||||
TArray<FCapsule> CapsulesImproved; // Because we need our own
|
TArray<FCapsule> CapsulesImproved; // Because we need our own
|
||||||
|
TArray<FDebugMesh> MeshesImproved; // Because we need our own
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -242,6 +242,50 @@ struct STEVESUEHELPERS_API FStevesEditorVisCapsule : public FStevesEditorVisCyli
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct STEVESUEHELPERS_API FStevesEditorVisMesh
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
/// The mesh do display
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UStaticMesh* Mesh;
|
||||||
|
/// Location relative to component
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FVector Location;
|
||||||
|
/// Scale of the mesh compared to component scale
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FVector Scale;
|
||||||
|
/// Rotation relative to component
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FRotator Rotation;
|
||||||
|
/// The colour of the line render
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FColor Colour;
|
||||||
|
|
||||||
|
FStevesEditorVisMesh(UStaticMesh* InMesh,
|
||||||
|
const FVector& InLocation,
|
||||||
|
const FVector& InScale,
|
||||||
|
const FRotator& InRot,
|
||||||
|
const FColor& InColour) :
|
||||||
|
Mesh(InMesh),
|
||||||
|
Location(InLocation),
|
||||||
|
Scale(InScale),
|
||||||
|
Rotation(InRot),
|
||||||
|
Colour(InColour)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FStevesEditorVisMesh() : Mesh(nullptr),
|
||||||
|
Location(FVector::ZeroVector),
|
||||||
|
Scale(FVector::OneVector),
|
||||||
|
Rotation(FRotator::ZeroRotator),
|
||||||
|
Colour(FColor::White)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A component that solely exists to provide arbitrary editor visualisation when not selected.
|
* A component that solely exists to provide arbitrary editor visualisation when not selected.
|
||||||
@ -277,6 +321,8 @@ public:
|
|||||||
TArray<FStevesEditorVisCylinder> Cylinders;
|
TArray<FStevesEditorVisCylinder> Cylinders;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
TArray<FStevesEditorVisCapsule> Capsules;
|
TArray<FStevesEditorVisCapsule> Capsules;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<FStevesEditorVisMesh> Meshes;
|
||||||
|
|
||||||
UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);
|
UStevesEditorVisComponent(const FObjectInitializer& ObjectInitializer);
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ public class StevesUEHelpers : ModuleRules
|
|||||||
PrivateDependencyModuleNames.AddRange(
|
PrivateDependencyModuleNames.AddRange(
|
||||||
new string[]
|
new string[]
|
||||||
{
|
{
|
||||||
|
"RenderCore"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user