Thanks a lot , that worked!
Next sushi is on me!
Here’s the code for everyone:
Header:
#pragma once
#include "Components/StaticMeshComponent.h"
#include "CorridorBlueprintFunctionLib.generated.h"
UCLASS(MinimalAPI)
class ACorridorBlueprintFunctionLib : public AActor
{
GENERATED_UCLASS_BODY()
UFUNCTION(BlueprintPure, Category = "Corridor", meta = (Keywords = "corridor vertex mesh meshdata", NativeBreakFunc))
TArray<FVector> MeshData(const UStaticMeshComponent* StaticMeshComponent);
};
and the cpp:
#include "UObjectPluginPrivatePCH.h"
#include "CorridorBlueprintFunctionLib.h"
#include "Components/StaticMeshComponent.h"
ACorridorBlueprintFunctionLib::ACorridorBlueprintFunctionLib(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
TArray<FVector> ACorridorBlueprintFunctionLib::MeshData(const UStaticMeshComponent* StaticMeshComponent)
{
TArray<FVector> vertices = TArray<FVector>();
//~~~~~~~~~~~~~~~~~~~~
// Many thanks to for this solution! :)
//
// Vertex Buffer
if (!IsValidLowLevel()) return vertices;
if (!StaticMeshComponent) return vertices;
if (!StaticMeshComponent->StaticMesh) return vertices;
if (!StaticMeshComponent->StaticMesh->RenderData) return vertices;
if (StaticMeshComponent->StaticMesh->RenderData->LODResources.Num() > 0)
{
FPositionVertexBuffer* VertexBuffer = &StaticMeshComponent->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
if (VertexBuffer)
{
const int32 VertexCount = VertexBuffer->GetNumVertices();
for (int32 Index = 0; Index < VertexCount; Index++)
{
//This is in the Static Mesh Actor Class, so it is location and tranform of the SMActor
const FVector WorldSpaceVertexLocation = GetActorLocation() + GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));
//add to output FVector array
vertices.Add(WorldSpaceVertexLocation);
}
}
}
return vertices;
}
Many thanks again . Now we can continue with our corridors YAY
Happy coding.
Ruben