Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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: https://forums.unrealengine.com/show...of-static-mesh).

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

  • #2
    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/UnrealE...cMesh.cpp#L151) and also in vertex shader for spline meshes

    this function transforms position in static mesh space to spline mesh space:
    Code:
    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:
    Code:
    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
    Code:
     SlicePos[SplineMeshComponent->ForwardAxis] = 0;
    but it works

    Comment


    • #3
      Hi AlekseyIlin,

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

      Comment


      • #4
        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.

        Comment

        Working...
        X