# How to get vertex positions of spline mesh component in world space?

Vertex positions of static mesh component can be calculated by applying component’s transform to position buffer of static mesh (as showed and explained in this thread: Accessing Vertex Positions of static mesh - C++ Gameplay Programming - Unreal Engine Forums).

Do I have to manually apply spline transformations to vertices of a static mesh or world positions are stored somewhere?

Figured out how to convert vertex poistions from asset (static mesh) to spline. The following method is used in StaticMesh.cpp, in function static void GetStaticLightingVertex (https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Programs/UnrealLightmass/Private/Lighting/StaticMesh.cpp#L151) and also in vertex shader for spline meshes

this function transforms position in static mesh space to spline mesh space:

``````

FVector StaticMeshToSplineMeshVertexPosition(const FVector& StaticMeshVertexPosition, USplineMeshComponent* SplineMeshComponent)
{
const float VertexPositionAlongSpline = StaticMeshVertexPosition[SplineMeshComponent->ForwardAxis];
const FTransform StaticMeshToSplineMeshTransform = SplineMeshComponent->CalcSliceTransform(VertexPositionAlongSpline);
FVector SlicePos = StaticMeshVertexPosition;
SlicePos[SplineMeshComponent->ForwardAxis] = 0;
const FVector SplineMeshSpaceVector = StaticMeshToSplineMeshTransform.TransformPosition(SlicePos);
FVector ResultPos = SplineMeshSpaceVector;
return SplineMeshSpaceVector;
}

``````

this code gets positions of all vertices of USplineMeshComponent in world space:

``````

UStaticMesh* StaticMesh = SplineMeshComponent->GetStaticMesh();

const FStaticMeshLODResources& RenderData = StaticMesh->RenderData->LODResources[0];
for (uint32 Index = 0; Index < RenderData.PositionVertexBuffer.GetNumVertices(); Index++)
{
const FVector StaticMeshSpacePosition = RenderData.PositionVertexBuffer.VertexPosition(Index);
const FVector SplineMeshSpacePosition = StaticMeshToSplineMeshVertexPosition(StaticMeshSpacePosition, SplineMeshComponent);
const FVector WorldSpacePosition = SplineMeshComponent->GetComponentLocation() + SplineMeshComponent->GetComponentTransform().TransformVector(SplineMeshSpacePosition);

}

``````

I still have no idea why you have to do this

``````
SlicePos[SplineMeshComponent->ForwardAxis] = 0;

``````

but it works

3 Likes

Hi AlekseyIlin,

do you have any idea about how to do this using blueprints ?

Alright, just found it
With “get end position” and “Transform Location” nodes, I get the world location of the end point of my spline mesh component.

Hi Alekseyllin:

Is there still some code on github floating around, in regards to how to do this? Thanks

Thank you for this solution. I got a plugin out called Runtime Vertex Color Paint & Detection Plugin and thanks to you it now supports spline mesh components as well

I’ll gladly give you a copy of the plugin as a thank you! If you want it you can just send me the epic email account that should get it and i’ll hook you up

All the Best,
Alex.