Accessing Vertex Positions of static mesh

You want the PositionVertex not the Painted, that’s why its all cats and dogs :slight_smile:

Also you need to convert the verticies from UStaticMesh asset space into World Actor space, including scaling and rotation!


**Code For You**

Here's my code which I put together for you



```


//~~~~~~~~~~~~~~~~~~~~
//				Vertex Buffer
if(!IsValidLowLevel()) return;
if(!StaticMeshComponent) return;
if(!StaticMeshComponent->StaticMesh) return;
if(!StaticMeshComponent->StaticMesh->RenderData) return;

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
		}
	}
}


```



The Critical Part

This is the critical part that took me long time to figure out on my own during the Beta

converts the UStaticMesh vertex into world actor space including Translation, Rotation, and Scaling!!


const FVector WorldSpaceVertexLocation = **GetActorLocation() + GetTransform().TransformVector(VertexBuffer->VertexPosition(Index));**

:slight_smile:

5 Likes