's C++ codes are incredible! But it seems they are no longer working in updated versions, need fixed.
You have to add those headers, it’s critical:
#include "Components/StaticMeshComponent.h"
#include "Rendering/PositionVertexBuffer.h"
#include "Engine/StaticMesh.h"
#include "StaticMeshResources.h"
header:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "GetStaticMeshVertexes.generated.h"
UCLASS()
class EXPERIMENT_2_24_VER_API AGetStaticMeshVertexes : public AActor
{
GENERATED_BODY()
UFUNCTION(BlueprintPure, Category = "Corridor", meta = (Keywords = "corridor vertex mesh meshdata", NativeBreakFunc))
TArray<FVector> MeshData(const UStaticMeshComponent* StaticMeshComponent);
public:
// Sets default values for this actor's properties
AGetStaticMeshVertexes();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
cpp:
#include "GetStaticMeshVertexes.h"
#include "Components/StaticMeshComponent.h"
#include "Rendering/PositionVertexBuffer.h"
#include "Engine/StaticMesh.h"
#include "StaticMeshResources.h"
#include "UObject/ConstructorHelpers.h"
#include "DrawDebugHelpers.h"
TArray<FVector> AGetStaticMeshVertexes::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->GetStaticMesh()) return vertices;
if (!StaticMeshComponent->GetStaticMesh()->RenderData) return vertices;
if (StaticMeshComponent->GetStaticMesh()->RenderData->LODResources.Num() > 0)
{
FPositionVertexBuffer* VertexBuffer = &StaticMeshComponent->GetStaticMesh()->RenderData->LODResources[0].VertexBuffers.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;
}
Thanks for everyone’s idea under this topic! Especially !!!