Hi, there is a method for extract in real-time the mesh of a object? I need it for a Flex-Mesh for view the deformation paramter.
You can do this at runtime:
// Grab the static mesh from your Static Mesh Actor
UStaticMeshComponent* StaticMeshComponent = MeshActor->GetStaticMeshComponent();
if (!StaticMeshComponent) return;
UStaticMesh* StaticMesh = StaticMeshComponent->GetStaticMesh();
if (!StaticMesh || !StaticMesh->RenderData) return;
if (StaticMesh->RenderData->LODResources.Num() == 0) return;
const FStaticMeshVertexBuffer& VertexBuffer = StaticMesh->RenderData->LODResources[0].VertexBuffer;
const FPositionVertexBuffer& PositionVertexBuffer = StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
// Build the vertex list
TArray<FVector> Vertices;
const int32 VertexCount = PositionVertexBuffer.GetNumVertices();
for (int32 i = 0; i < VertexCount; i++)
{
FVector Vertex = PositionVertexBuffer.VertexPosition(i);
FVector Normal = VertexBuffer.VertexTangentZ(i);
// save in your vertex array
Vertices.Add(Vertex);
}
// Build the index list
TArray<uint32> Indices; // << Result saved here
const FRawStaticIndexBuffer& IndexBuffer = StaticMesh->RenderData->LODResources[0].IndexBuffer;
IndexBuffer.GetCopy(Indices);
// Optional: If you want the triangle vertices
{
int NumIndices = Indices.Num();
for (int i = 0; i < NumIndices; i += 3) {
uint32 i0 = Indices[i + 0];
uint32 i1 = Indices[i + 1];
uint32 i2 = Indices[i + 2];
const FVector& v0 = Vertices[i0];
const FVector& v1 = Vertices[i1];
const FVector& v2 = Vertices[i2];
/// ...
}
}
where I must insert this code?
sorry for the banal question.
Create these two files and place the source folder
Open the *.Build.cs file on your code project and add “RenderCore” in the PublicDependencyModuleNames list to avoid linker errors
using UnrealBuildTool;
public class DA418X : ModuleRules
{
public DA418X(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "RenderCore" });
}
}
Call it from your blueprint when you want to export it during runtime
it´s works thanks a lot… where can i find the saved mesh?
It gives you raw data about the mesh at runtime so you can do your processing on it
If you want the saved mesh, you can directly export it from the content browser (right click on the mesh and click export) to save it somewhere on disk
mmm when i press S i cant see the mesh in content browser.
I have a deformable mesh so i need export in real time for see deformation during test.
(I’m sorry for all these questions)